Browse Source

fix setting id to entity

Kaoru FUZITA 9 years ago
parent
commit
113b794f16

+ 4 - 2
src/main/java/org/codelibs/fess/app/web/admin/group/AdminGroupAction.java

@@ -216,7 +216,10 @@ public class AdminGroupAction extends FessAdminAction {
         switch (form.crudMode) {
         case CrudMode.CREATE:
             if (form instanceof CreateForm) {
-                return OptionalEntity.of(new Group());
+                return OptionalEntity.of(new Group()).map(entity -> {
+                    entity.setId(Base64.getEncoder().encodeToString(form.name.getBytes(Constants.CHARSET_UTF_8)));
+                    return entity;
+                });
             }
             break;
         case CrudMode.EDIT:
@@ -233,7 +236,6 @@ public class AdminGroupAction extends FessAdminAction {
     protected OptionalEntity<Group> createGroup(final CreateForm form) {
         return getEntity(form).map(entity -> {
             copyBeanToBean(form, entity, op -> op.exclude(Constants.COMMON_CONVERSION_RULE));
-            entity.setId(Base64.getEncoder().encodeToString(entity.getName().getBytes(Constants.CHARSET_UTF_8)));
             return entity;
         });
     }

+ 4 - 2
src/main/java/org/codelibs/fess/app/web/admin/role/AdminRoleAction.java

@@ -216,7 +216,10 @@ public class AdminRoleAction extends FessAdminAction {
         switch (form.crudMode) {
         case CrudMode.CREATE:
             if (form instanceof CreateForm) {
-                return OptionalEntity.of(new Role());
+                return OptionalEntity.of(new Role()).map(entity -> {
+                    entity.setId(Base64.getEncoder().encodeToString(form.name.getBytes(Constants.CHARSET_UTF_8)));
+                    return entity;
+                });
             }
             break;
         case CrudMode.EDIT:
@@ -233,7 +236,6 @@ public class AdminRoleAction extends FessAdminAction {
     protected OptionalEntity<Role> createRole(final CreateForm form) {
         return getEntity(form).map(entity -> {
             copyBeanToBean(form, entity, op -> op.exclude(Constants.COMMON_CONVERSION_RULE));
-            entity.setId(Base64.getEncoder().encodeToString(entity.getName().getBytes(Constants.CHARSET_UTF_8)));
             return entity;
         });
     }

+ 4 - 2
src/main/java/org/codelibs/fess/app/web/admin/user/AdminUserAction.java

@@ -252,7 +252,10 @@ public class AdminUserAction extends FessAdminAction {
         switch (form.crudMode) {
         case CrudMode.CREATE:
             if (form instanceof CreateForm) {
-                return OptionalEntity.of(new User());
+                return OptionalEntity.of(new User()).map(entity -> {
+                    entity.setId(Base64.getEncoder().encodeToString(form.name.getBytes(Constants.CHARSET_UTF_8)));
+                    return entity;
+                });
             }
             break;
         case CrudMode.EDIT:
@@ -272,7 +275,6 @@ public class AdminUserAction extends FessAdminAction {
             sessionManager.getAttribute(TEMPORARY_PASSWORD, String.class).ifPresent(password -> {
                 entity.setPassword(password);
             });
-            entity.setId(Base64.getEncoder().encodeToString(entity.getName().getBytes(Constants.CHARSET_UTF_8)));
             return entity;
         });
     }