mirror of
https://github.com/dalbodeule/snap-admin.git
synced 2025-07-31 17:21:13 +00:00
Fixed issues related to UUID field (#13)
This commit is contained in:
@@ -292,13 +292,15 @@ public class DefaultDbAdminController {
|
||||
public String edit(Model model, @PathVariable String className, @PathVariable String id, RedirectAttributes attr) {
|
||||
DbObjectSchema schema = dbAdmin.findSchemaByClassName(className);
|
||||
|
||||
Object pkValue = schema.getPrimaryKey().getType().parseValue(id);
|
||||
|
||||
if (!schema.isEditEnabled()) {
|
||||
attr.addFlashAttribute("errorTitle", "Unauthorized");
|
||||
attr.addFlashAttribute("error", "EDIT operations have been disabled on this type (" + schema.getJavaClass().getSimpleName() + ").");
|
||||
return "redirect:/" + properties.getBaseUrl() + "/model/" + className;
|
||||
}
|
||||
|
||||
DbObject object = repository.findById(schema, id).orElseThrow(() -> {
|
||||
DbObject object = repository.findById(schema, pkValue).orElseThrow(() -> {
|
||||
return new DbAdminNotFoundException(
|
||||
"Object " + className + " with id " + id + " not found"
|
||||
);
|
||||
@@ -449,7 +451,9 @@ public class DefaultDbAdminController {
|
||||
attr.addFlashAttribute("message", "Item created successfully.");
|
||||
saveAction(new UserAction(schema.getTableName(), pkValue, "CREATE", schema.getClassName()));
|
||||
} else {
|
||||
Optional<DbObject> object = repository.findById(schema, pkValue);
|
||||
Object parsedPkValue = schema.getPrimaryKey().getType().parseValue(pkValue);
|
||||
|
||||
Optional<DbObject> object = repository.findById(schema, parsedPkValue);
|
||||
|
||||
if (!object.isEmpty()) {
|
||||
if (create) {
|
||||
@@ -458,9 +462,9 @@ public class DefaultDbAdminController {
|
||||
attr.addFlashAttribute("params", params);
|
||||
} else {
|
||||
repository.update(schema, params, files);
|
||||
repository.attachManyToMany(schema, pkValue, multiValuedParams);
|
||||
repository.attachManyToMany(schema, parsedPkValue, multiValuedParams);
|
||||
attr.addFlashAttribute("message", "Item saved successfully.");
|
||||
saveAction(new UserAction(schema.getTableName(), pkValue, "EDIT", schema.getClassName()));
|
||||
saveAction(new UserAction(schema.getTableName(), parsedPkValue.toString(), "EDIT", schema.getClassName()));
|
||||
}
|
||||
} else {
|
||||
Object newPrimaryKey = repository.create(schema, params, files, pkValue);
|
||||
|
@@ -39,6 +39,7 @@ import jakarta.validation.ConstraintViolation;
|
||||
import jakarta.validation.ConstraintViolationException;
|
||||
import jakarta.validation.Validation;
|
||||
import jakarta.validation.Validator;
|
||||
import tech.ailef.dbadmin.external.annotations.ReadOnly;
|
||||
import tech.ailef.dbadmin.external.dto.FacetedSearchRequest;
|
||||
import tech.ailef.dbadmin.external.dto.PaginatedResult;
|
||||
import tech.ailef.dbadmin.external.dto.PaginationInfo;
|
||||
@@ -142,14 +143,18 @@ public class DbAdminRepository {
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an existing object with new values
|
||||
* @param schema
|
||||
* @param params
|
||||
* Update an existing object with new values. We don't use the "standard"
|
||||
* JPA repository save method in this case (like we do on create) because
|
||||
* we need to handle several edge cases in terms of how missing values
|
||||
* are handled and also {@linkplain ReadOnly} fields. For this reason, we
|
||||
* also need to call the validation manually.
|
||||
* @param schema the schema where we need to update an item
|
||||
* @param params the String-valued params coming from the HTML form
|
||||
* @param files the file params coming from the HTML form
|
||||
*/
|
||||
@Transactional("transactionManager")
|
||||
public void update(DbObjectSchema schema, Map<String, String> params, Map<String, MultipartFile> files) {
|
||||
DbObject obj = schema.buildObject(params, files);
|
||||
|
||||
Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
|
||||
Set<ConstraintViolation<Object>> violations = validator.validate(obj.getUnderlyingInstance());
|
||||
|
||||
|
@@ -16,7 +16,6 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
package tech.ailef.dbadmin.external.exceptions;
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user