Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -295,4 +295,19 @@
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 {

Check warning on line 309 in exo.core.component.organization.api/src/main/java/org/exoplatform/services/organization/GroupHandler.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace generic exceptions with specific library exceptions or a custom exception.

See more on https://sonarcloud.io/project/issues?id=io.meeds.core&issues=AZ_wVRuos07wxPxyelEq&open=AZ_wVRuos07wxPxyelEq&pullRequest=138
throw new UnsupportedOperationException();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand All @@ -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);
}

Expand Down Expand Up @@ -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());
Expand All @@ -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");
}
Expand Down
Loading