diff --git a/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/GroupHandler.java b/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/GroupHandler.java index 00e0645d1..284d37fb7 100644 --- a/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/GroupHandler.java +++ b/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/GroupHandler.java @@ -295,4 +295,19 @@ default void clearGroupCache(String groupId) { throw new UnsupportedOperationException(); } + /** + * Updates an existing group with the provided data. + * This method performs a full update of the group including: + * group properties update(label, description, ...), Management of enclosing (inherited) memberships changes + * @param group the group object containing the updated data. Must not be null and must have a valid ID. + * @param broadcast if {@code true}, pre-save and post-save events will be triggered + * + * @throws IllegalArgumentException if the group or its ID is null + * @throws Exception if the group does not exist, or if any persistence operation fails + * + */ + default void updateGroup(Group group, boolean broadcast) throws Exception { + throw new UnsupportedOperationException(); + } + } diff --git a/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/OrganizationDatabaseInitializer.java b/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/OrganizationDatabaseInitializer.java index 8d5f4d22f..69ddc7958 100644 --- a/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/OrganizationDatabaseInitializer.java +++ b/exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/OrganizationDatabaseInitializer.java @@ -47,6 +47,8 @@ public class OrganizationDatabaseInitializer extends BaseComponentPlugin impleme private boolean updateUsers_; + private boolean updateGroups; + public OrganizationDatabaseInitializer(InitParams params) throws Exception { String checkConfig = params.getValueParam("checkDatabaseAlgorithm").getValue(); if (checkConfig.trim().equalsIgnoreCase("entry")) { @@ -61,6 +63,11 @@ public OrganizationDatabaseInitializer(InitParams params) throws Exception { String updateUsersParam = usParam.getValue(); updateUsers_ = (updateUsersParam != null && updateUsersParam.trim().equalsIgnoreCase("true")); } + ValueParam gpParam = params.getValueParam("updateGroups"); + if (gpParam != null) { + String updateGroupsParam = gpParam.getValue(); + updateGroups = (updateGroupsParam != null && updateGroupsParam.trim().equalsIgnoreCase("true")); + } config_ = params.getObjectParamValues(OrganizationConfig.class).get(0); } @@ -100,8 +107,8 @@ protected void createGroups(OrganizationService orgService) throws Exception { groupId = "/" + data.getName(); else groupId = data.getParentId() + "/" + data.getName(); - - if (orgService.getGroupHandler().findGroupById(groupId) == null) { + Group existingGroup = orgService.getGroupHandler().findGroupById(groupId); + if (existingGroup == null) { Group group = orgService.getGroupHandler().createGroupInstance(); group.setGroupName(data.getName()); group.setDescription(data.getDescription()); @@ -113,6 +120,18 @@ protected void createGroups(OrganizationService orgService) throws Exception { orgService.getGroupHandler().addChild(parentGroup, group, true); } printInfo(" Create Group " + groupId); + } else if (updateGroups) { + // Keep the existing value when the configuration doesn't define one, + // to avoid wiping an administrator defined label/description on each restart + String label = data.getLabel() == null ? existingGroup.getLabel() : data.getLabel(); + String description = data.getDescription() == null ? existingGroup.getDescription() : data.getDescription(); + if (!StringUtils.equals(existingGroup.getLabel(), label) + || !StringUtils.equals(existingGroup.getDescription(), description)) { + existingGroup.setLabel(label); + existingGroup.setDescription(description); + orgService.getGroupHandler().saveGroup(existingGroup, true); + printInfo(String.format("Update Group: %s", groupId)); + } } else { printInfo(" Group " + groupId + " already exists, ignoring the entry"); }