Bug 4827: adjusted and fixed OwnershipMigrationDialog and associated

Updater in back end to work as defined
This commit is contained in:
Steffen Jacobs committed 2019-02-21 15:30:04 +01:00
1 parent 6a7a8f4463
commit 32e379b32c
9 files changed
+116 -16

No files matched your search

@@ -34,6 +34,10 @@ public class MigrateGroupOwnershipDialog extends DataEntryDialog<MigrateGroupOwn
private final RadioButton toNewGroup;
private final CheckBox migrateCompetitors;
private final CheckBox migrateBoats;
private final CheckBox copyMembersAndRoles;
private final Label lblCopyMembersAndRoles;
private UserGroupDTO oldUserGroup;
public static class MigrateGroupOwnerForHierarchyDialogDTO extends MigrateGroupOwnerForHierarchyDTO {
private static final long serialVersionUID = -7336625438188182079L;
@@ -41,8 +45,9 @@ public class MigrateGroupOwnershipDialog extends DataEntryDialog<MigrateGroupOwn
private boolean resolvingUserGroupName;
public MigrateGroupOwnerForHierarchyDialogDTO(UserGroupDTO existingUserGroup, boolean resolvingUserGroupName,
boolean createNewGroup, String newGroupName, boolean updateCompetitors, boolean updateBoats) {
super(existingUserGroup, createNewGroup, newGroupName, updateCompetitors, updateBoats);
boolean createNewGroup, String newGroupName, boolean updateCompetitors, boolean updateBoats,
boolean copyMembersAndRoles) {
super(existingUserGroup, createNewGroup, newGroupName, updateCompetitors, updateBoats, copyMembersAndRoles);
this.resolvingUserGroupName = resolvingUserGroupName;
}
@@ -94,16 +99,45 @@ public class MigrateGroupOwnershipDialog extends DataEntryDialog<MigrateGroupOwn
toExistingGroup = createRadioButton(radioGroupName, stringMessages.useExistingUserGroup());
toNewGroup = createRadioButton(radioGroupName, stringMessages.useNewUserGroup());
toExistingGroup.setValue(true);
copyMembersAndRoles = createCheckbox("");
copyMembersAndRoles.setVisible(false);
copyMembersAndRoles.setValue(true);
toNewGroup.addValueChangeHandler(v -> onRadioChange());
toExistingGroup.addValueChangeHandler(v -> onRadioChange());
migrateCompetitors = createCheckbox("");
migrateBoats = createCheckbox("");
this.stringMessages = stringMessages;
resolveUserGroup();
// TODO: i18n
lblCopyMembersAndRoles = new Label("Copy members and roles");
lblCopyMembersAndRoles.setVisible(false);
userManagementService.getUserGroupByName(tenant.getName(), new AsyncCallback<UserGroupDTO>() {
@Override
public void onFailure(Throwable caught) {
Notification.notify(stringMessages.errorObtainingUserGroup(caught.getMessage()),
NotificationType.ERROR);
}
@Override
public void onSuccess(UserGroupDTO result) {
oldUserGroup = result;
}
});
}
private void onRadioChange() {
copyMembersAndRoles.setVisible(toNewGroup.getValue());
lblCopyMembersAndRoles.setVisible(toNewGroup.getValue());
}
@Override
protected Widget getAdditionalWidget() {
final Grid result = new Grid(5, 2);
final Grid result = new Grid(6, 2);
result.setWidget(0, 0, new Label(stringMessages.currentGroupOwner()));
result.setWidget(0, 1, currentGroupLabel);
result.setWidget(1, 0, toExistingGroup);
@@ -114,6 +148,8 @@ public class MigrateGroupOwnershipDialog extends DataEntryDialog<MigrateGroupOwn
result.setWidget(3, 1, migrateCompetitors);
result.setWidget(4, 0, new Label(stringMessages.migrateBoats()));
result.setWidget(4, 1, migrateBoats);
result.setWidget(5, 0, lblCopyMembersAndRoles);
result.setWidget(5, 1, copyMembersAndRoles);
return result;
}
@@ -139,9 +175,9 @@ public class MigrateGroupOwnershipDialog extends DataEntryDialog<MigrateGroupOwn
@Override
protected MigrateGroupOwnerForHierarchyDialogDTO getResult() {
final boolean newGroup = toNewGroup.getValue();
return new MigrateGroupOwnerForHierarchyDialogDTO(newGroup ? null : resolvedUserGroup,
return new MigrateGroupOwnerForHierarchyDialogDTO(newGroup ? oldUserGroup : resolvedUserGroup,
newGroup ? false : resolvingUserGroupName, newGroup, groupnameBox.getValue().trim(),
migrateCompetitors.getValue(), migrateBoats.getValue());
migrateCompetitors.getValue(), migrateBoats.getValue(), copyMembersAndRoles.getValue());
}
/**
@@ -193,7 +229,8 @@ public class MigrateGroupOwnershipDialog extends DataEntryDialog<MigrateGroupOwn
boolean createNewGroup = editedObject.isCreateNewGroup();
updateCallback.accept(securedObject, new MigrateGroupOwnerForHierarchyDTO(editedObject.getExistingUserGroup(),
createNewGroup, createNewGroup ? editedObject.getGroupName() : null,
editedObject.isUpdateCompetitors(), editedObject.isUpdateBoats()));
editedObject.isUpdateCompetitors(), editedObject.isUpdateBoats(),
editedObject.isCopyMembersAndRoles()));
}
@Override
@@ -8917,7 +8917,8 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
migrateGroupOwnerForHierarchyDTO.isCreateNewGroup(),
migrateGroupOwnerForHierarchyDTO.getExistingUserGroupIdOrNull(),
migrateGroupOwnerForHierarchyDTO.getGroupName(), migrateGroupOwnerForHierarchyDTO.isUpdateCompetitors(),
migrateGroupOwnerForHierarchyDTO.isUpdateBoats(), getService());
migrateGroupOwnerForHierarchyDTO.isUpdateBoats(),
migrateGroupOwnerForHierarchyDTO.isCopyMembersAndRoles(), getService());
}
@Override
@@ -14,18 +14,20 @@ public class MigrateGroupOwnerForHierarchyDTO implements Serializable {
private String newGroupName;
private boolean updateCompetitors;
private boolean updateBoats;
private boolean copyMembersAndRoles;
@Deprecated // for GWT serialization only
protected MigrateGroupOwnerForHierarchyDTO() {
}
public MigrateGroupOwnerForHierarchyDTO(UserGroupDTO existingUserGroup, boolean createNewGroup, String newGroupName,
boolean updateCompetitors, boolean updateBoats) {
boolean updateCompetitors, boolean updateBoats, boolean copyMembersAndRoles) {
this.existingUserGroup = existingUserGroup;
this.createNewGroup = createNewGroup;
this.newGroupName = newGroupName;
this.updateCompetitors = updateCompetitors;
this.updateBoats = updateBoats;
this.copyMembersAndRoles = copyMembersAndRoles;
}
public UserGroupDTO getExistingUserGroup() {
@@ -55,4 +57,8 @@ public class MigrateGroupOwnerForHierarchyDTO implements Serializable {
}
return id;
}
public boolean isCopyMembersAndRoles() {
return copyMembersAndRoles;
}
}
@@ -118,10 +118,13 @@ public class EventsResource extends AbstractSailingServerResource {
@QueryParam("createNewGroup") Boolean createNewGroup,
@QueryParam("existingGroupId") UUID existingGroupIdOrNull, @QueryParam("newGroupName") String newGroupName,
@QueryParam("migrateCompetitors") Boolean migrateCompetitors,
@QueryParam("migrateBoats") Boolean migrateBoats) throws ParseException, JsonDeserializationException {
@QueryParam("migrateBoats") Boolean migrateBoats,
@QueryParam("copyMembersAndRoles") Boolean copyMembersAndRoles)
throws ParseException, JsonDeserializationException {
Event event = getService().getEvent(eventId);
SailingHierarchyOwnershipUpdater updater = SailingHierarchyOwnershipUpdater.createOwnershipUpdater(
createNewGroup, existingGroupIdOrNull, newGroupName, migrateCompetitors, migrateBoats, getService());
createNewGroup, existingGroupIdOrNull, newGroupName, migrateCompetitors, migrateBoats,
copyMembersAndRoles == null ? true : copyMembersAndRoles, getService());
updater.updateGroupOwnershipForEventHierarchy(event);
return Response.ok().build();
}
@@ -50,10 +50,13 @@ public class LeaderboardGroupsResource extends AbstractSailingServerResource {
@QueryParam("createNewGroup") Boolean createNewGroup,
@QueryParam("existingGroupId") UUID existingGroupIdOrNull, @QueryParam("newGroupName") String newGroupName,
@QueryParam("migrateCompetitors") Boolean migrateCompetitors,
@QueryParam("migrateBoats") Boolean migrateBoats) throws ParseException, JsonDeserializationException {
@QueryParam("migrateBoats") Boolean migrateBoats,
@QueryParam("copyMembersAndRoles") Boolean copyMembersAndRoles)
throws ParseException, JsonDeserializationException {
LeaderboardGroup leaderboardGroup = getService().getLeaderboardGroupByName(leaderboardGroupName);
SailingHierarchyOwnershipUpdater updater = SailingHierarchyOwnershipUpdater.createOwnershipUpdater(
createNewGroup, existingGroupIdOrNull, newGroupName, migrateCompetitors, migrateBoats, getService());
createNewGroup, existingGroupIdOrNull, newGroupName, migrateCompetitors, migrateBoats,
copyMembersAndRoles == null ? true : copyMembersAndRoles, getService());
updater.updateGroupOwnershipForLeaderboardGroupHierarchy(leaderboardGroup);
return Response.ok().build();
}
@@ -63,10 +63,13 @@ public class LeaderboardsResourceV2 extends AbstractLeaderboardsResource {
@QueryParam("createNewGroup") Boolean createNewGroup,
@QueryParam("existingGroupId") UUID existingGroupIdOrNull, @QueryParam("newGroupName") String newGroupName,
@QueryParam("migrateCompetitors") Boolean migrateCompetitors,
@QueryParam("migrateBoats") Boolean migrateBoats) throws ParseException, JsonDeserializationException {
@QueryParam("migrateBoats") Boolean migrateBoats,
@QueryParam("copyMembersAndRoles") Boolean copyMembersAndRoles)
throws ParseException, JsonDeserializationException {
Leaderboard leaderboardGroup = getService().getLeaderboardByName(leaderboardName);
SailingHierarchyOwnershipUpdater updater = SailingHierarchyOwnershipUpdater.createOwnershipUpdater(
createNewGroup, existingGroupIdOrNull, newGroupName, migrateCompetitors, migrateBoats, getService());
createNewGroup, existingGroupIdOrNull, newGroupName, migrateCompetitors, migrateBoats,
copyMembersAndRoles == null ? true : copyMembersAndRoles, getService());
updater.updateGroupOwnershipForLeaderboardHierarchy(leaderboardGroup);
return Response.ok().build();
}
@@ -33,6 +33,7 @@
<td>Optional parameters:</td>
<td>existingGroupId group that should be changed, required for createNewGroup = false</td>
<td>newGroupName name of the new group, required for createNewGroup = true</td>
<td>copyMembersAndRoles determines if the members and roles are copied (default: true)</td>
</tr>
<tr>
<td>Request method:</td>
@@ -33,6 +33,7 @@
<td>Optional parameters:</td>
<td>existingGroupId group that should be changed, required for createNewGroup = false</td>
<td>newGroupName name of the new group, required for createNewGroup = true</td>
<td>copyMembersAndRoles determines if the members and roles are copied (default: true)</td>
</tr>
<tr>
<td>Request method:</td>
@@ -35,6 +35,7 @@ import com.sap.sse.security.shared.impl.UserGroupImpl;
public class SailingHierarchyOwnershipUpdater {
public static SailingHierarchyOwnershipUpdater createOwnershipUpdater(boolean createNewGroup,
UUID existingGroupIdOrNull, String newGroupName, boolean migrateCompetitors, boolean migrateBoats,
boolean copyMembersAndRoles,
RacingEventService service) {
SecurityService securityService = service.getSecurityService();
@@ -42,9 +43,13 @@ public class SailingHierarchyOwnershipUpdater {
final GroupOwnerUpdateStrategy updateStrategy;
if (!createNewGroup) {
updateStrategy = createExitingGroupModifyingUpdate(sourceGroup);
updateStrategy = createExitingGroupModifyingUpdate(sourceGroup);
} else {
updateStrategy = createNewGroupUsingUpdate(newGroupName, securityService, sourceGroup, service);
if (copyMembersAndRoles) {
updateStrategy = createNewGroupUsingUpdate(newGroupName, securityService, sourceGroup, service);
} else {
updateStrategy = createNewGroupWithoutCopying(newGroupName, securityService);
}
}
return new SailingHierarchyOwnershipUpdater(service, securityService, updateStrategy, migrateCompetitors,
migrateBoats);
@@ -187,6 +192,44 @@ public class SailingHierarchyOwnershipUpdater {
return updateStrategy;
}
/**
* Creates a new group without copying the members and roles from an old group but add the current user to the new
* group.
*/
private static GroupOwnerUpdateStrategy createNewGroupWithoutCopying(final String newGroupName,
final SecurityService securityService) {
if (newGroupName == null || newGroupName.isEmpty()) {
throw new RuntimeException("No name for new Group given");
}
final GroupOwnerUpdateStrategy updateStrategy;
updateStrategy = new GroupOwnerUpdateStrategy() {
private UserGroup groupOwnerToSet;
@Override
public boolean needsUpdate(QualifiedObjectIdentifier identifier, OwnershipAnnotation currentOwnership) {
return true;
}
@Override
public UserGroup getNewGroupOwner() {
if (groupOwnerToSet == null) {
try {
groupOwnerToSet = securityService.createUserGroup(UUID.randomUUID(), newGroupName);
final QualifiedObjectIdentifier identifier = groupOwnerToSet.getIdentifier();
securityService.setDefaultOwnership(identifier, identifier.toString());
securityService.addUserToUserGroup(groupOwnerToSet, securityService.getCurrentUser());
} catch (UserGroupManagementException e) {
throw new RuntimeException("Could not create user group");
}
}
return groupOwnerToSet;
}
};
return updateStrategy;
}
private static GroupOwnerUpdateStrategy createNewGroupUsingUpdate(String newGroupName,
SecurityService securityService, final UserGroup sourceGroup, RacingEventService service) {
if (newGroupName == null || newGroupName.isEmpty()) {
@@ -215,6 +258,8 @@ public class SailingHierarchyOwnershipUpdater {
// The migration may start at an object that currently has no group owner (e.g. in case
// this owner was just deleted) -> in this case we just create a new group
groupOwnerToSet = securityService.createUserGroup(UUID.randomUUID(), newGroupName);
final QualifiedObjectIdentifier identifier = groupOwnerToSet.getIdentifier();
securityService.setDefaultOwnership(identifier, identifier.toString());
}
} catch (UserGroupManagementException e) {
throw new RuntimeException("Could not create user group");