public static Group toGroup(final SGroup sGroup) { final GroupImpl group = new GroupImpl(sGroup.getId(), sGroup.getName()); group.setParentPath(sGroup.getParentPath()); group.setCreatedBy(sGroup.getCreatedBy()); group.setCreationDate(new Date(sGroup.getCreationDate())); group.setDescription(sGroup.getDescription()); group.setDisplayName(sGroup.getDisplayName()); group.setIconId(sGroup.getIconId()); group.setLastUpdate(new Date(sGroup.getLastUpdate())); return group; }
public static SelectListDescriptor<SGroup> getChildrenOfGroup(final SGroup group, final QueryOptions queryOptions) { final Map<String, Object> parameters = Collections.singletonMap("groupPath", (Object) group.getPath()); return new SelectListDescriptor<SGroup>("getChildrenOfGroup", parameters, SGroup.class, queryOptions); }
private void addGroupToProfile() throws SGroupNotFoundException, SProfileMemberCreationException { final SGroup group = identityService.getGroup(groupId); if (group != null) { sProfileMember = profileService.addGroupToProfile(profileId, groupId, group.getName(), group.getParentPath()); } }
private static ExportedGroup toExportedGroup(final SGroup sGroup) { final ExportedGroup group = new ExportedGroup(); group.setName(sGroup.getName()); group.setParentPath(sGroup.getParentPath()); group.setDescription(sGroup.getDescription()); group.setDisplayName(sGroup.getDisplayName()); return group; }
private void checkPathUnicity(long groupId, GroupUpdater updater, IdentityService identityService) throws SGroupNotFoundException, AlreadyExistsException { final Serializable updatedName = updater.getFields().get(GroupField.NAME); SGroup sGroupToBeUpdated = identityService.getGroup(groupId); String name = updatedName != null ? updatedName.toString() : sGroupToBeUpdated.getName(); StringBuilder sb = new StringBuilder(); String parentPath = updater.getFields().get(GroupField.PARENT_PATH) != null ? updater.getFields().get(GroupField.PARENT_PATH).toString() : ""; sb.append(parentPath).append("/").append(name); try { if (updatedName != null) { SGroup group = identityService.getGroupByPath(sb.toString()); if (group.getId() != groupId) { throw new AlreadyExistsException("Group named \"" + name + "\" already exists"); } } } catch (final SGroupNotFoundException e) { } }
private void deleteActorMembersOfGroupChildren(final long groupId) throws SIdentityException, SActorMemberNotFoundException, SActorMemberDeletionException, SBonitaReadException { int i = 0; List<SGroup> childrenGroup; do { childrenGroup = identityService.getGroupChildren(groupId, i, BATCH_SIZE); i += BATCH_SIZE; for (final SGroup sGroup : childrenGroup) { deleteActorMembersOfGroup(sGroup.getId()); } } while (childrenGroup.size() == BATCH_SIZE); }
@Override public void deleteGroup(final SGroup group) throws SGroupDeletionException { final SGroupLogBuilder logBuilder = getGroupLog(ActionType.DELETED, "Deleting group " + group.getName()); try { if (group.getIconId() != null) { deleteIcon(group.getIconId()); } recorder.recordDelete(new DeleteRecord(group), GROUP); log(group.getId(), SQueriableLog.STATUS_OK, logBuilder, "deleteGroup"); } catch (final SRecorderException | SBonitaReadException re) { log(group.getId(), SQueriableLog.STATUS_FAIL, logBuilder, "deleteGroup"); throw new SGroupDeletionException(re); } }
continue; profileService.addGroupToProfile(profileId, group.getId(), group.getName(), group.getParentPath()); continue; profileService.addRoleAndGroupToProfile(profileId, role.getId(), group.getId(), role.getName(), group.getName(), group.getParentPath());
private Map<String, Long> importGroups(final List<ExportedGroup> groupCreators) throws ImportDuplicateInOrganizationException, SIdentityException { final Map<String, Long> groupPathToIdMap = new HashMap<>(groupCreators.size()); for (final ExportedGroup groupCreator : groupCreators) { SGroup sGroup; try { final String groupPath = getGroupPath(groupCreator); sGroup = identityService.getGroupByPath(groupPath); strategy.foundExistingGroup(sGroup, groupCreator); } catch (final SGroupNotFoundException e) { sGroup = addGroup(groupCreator); } groupPathToIdMap.put(sGroup.getPath(), sGroup.getId()); } return groupPathToIdMap; }
@Override public void execute() throws SBonitaException { userNames = new HashMap<>(20); final List<SCustomUserInfoDefinition> customUserInfoDefinitions = getAllCustomUserInfoDefinitions(); final List<ExportedUser> users = getAllUsers(getUserInfoDefinitionNames(customUserInfoDefinitions)); // improvement: user server object to avoid useless conversion; final List<ExportedRole> roles = getAllRoles(); final List<SGroup> groups = getAllGroups(); final Map<Long, String> groupIdParentPath = new HashMap<>(groups.size()); for (final SGroup group : groups) { groupIdParentPath.put(group.getId(), group.getParentPath()); } final List<SUserMembership> userMemberships = getAllUserMemberships(); // improvement: user server object to avoid useless conversion; final List<ExportedGroup> clientGroups = ModelConvertor.toExportedGroups(groups); // improvement: user server object to avoid useless conversion; final List<ExportedUserMembership> clientUserMemberships = ModelConvertor.toExportedUserMembership(userMemberships, userNames, groupIdParentPath); List<ExportedCustomUserInfoDefinition> customUserInfoDefinitionCreators = ModelConvertor.toExportedCustomUserInfoDefinition(customUserInfoDefinitions); final Organization organization = new Organization(users, roles, clientGroups, clientUserMemberships, customUserInfoDefinitionCreators); try { xmlOrganization = new OrganizationParser().convert(organization); } catch (JAXBException e) { throw new SBonitaReadException(e); } }
@Override public Group createGroup(final GroupCreator creator) throws CreationException { if (creator == null) { throw new CreationException("Cannot create a null group"); } String groupName = creator.getFields().get(GroupCreator.GroupField.NAME).toString(); if (groupName.contains("/")) { throw new InvalidGroupNameException("Cannot create a group with '/' in its name"); } final TenantServiceAccessor tenantAccessor = getTenantAccessor(); final IdentityService identityService = tenantAccessor.getIdentityService(); if (creator.getFields().containsKey(GroupCreator.GroupField.ICON_NAME) || creator.getFields().containsKey(GroupCreator.GroupField.ICON_PATH)) { tenantAccessor.getTechnicalLoggerService().log(IdentityAPIImpl.class, TechnicalLogSeverity.WARNING, "setIconName and setIconPath are deprecated, use setIcon instead"); } final SGroup sGroup = ModelConvertor.constructSGroup(creator); try { identityService.getGroupByPath(sGroup.getPath()); throw new AlreadyExistsException("Group named \"" + sGroup.getName() + "\" already exists"); } catch (final SGroupNotFoundException ignored) { } try { identityService.createGroup(sGroup, (String) creator.getFields().get(GroupCreator.GroupField.ICON_FILENAME), (byte[]) creator.getFields().get(GroupCreator.GroupField.ICON_CONTENT)); } catch (SGroupCreationException e) { throw new CreationException(e); } return ModelConvertor.toGroup(sGroup); }
private static ExportedGroup toExportedGroup(final SGroup sGroup) { final ExportedGroup group = new ExportedGroup(); group.setName(sGroup.getName()); group.setParentPath(sGroup.getParentPath()); group.setDescription(sGroup.getDescription()); group.setDisplayName(sGroup.getDisplayName()); return group; }
private void addGroupToProfile() throws SGroupNotFoundException, SProfileMemberCreationException { final SGroup group = identityService.getGroup(groupId); if (group != null) { sProfileMember = profileService.addGroupToProfile(profileId, groupId, group.getName(), group.getParentPath()); } }
private void checkPathUnicity(long groupId, GroupUpdater updater, IdentityService identityService) throws SGroupNotFoundException, AlreadyExistsException { final Serializable updatedName = updater.getFields().get(GroupField.NAME); SGroup sGroupToBeUpdated = identityService.getGroup(groupId); String name = updatedName != null ? updatedName.toString() : sGroupToBeUpdated.getName(); StringBuilder sb = new StringBuilder(); String parentPath = updater.getFields().get(GroupField.PARENT_PATH) != null ? updater.getFields().get(GroupField.PARENT_PATH).toString() : ""; sb.append(parentPath).append("/").append(name); try { if (updatedName != null) { SGroup group = identityService.getGroupByPath(sb.toString()); if (group.getId() != groupId) { throw new AlreadyExistsException("Group named \"" + name + "\" already exists"); } } } catch (final SGroupNotFoundException e) { } }
private void deleteProfileMembersOfGroupChildren(final long groupId) throws SIdentityException, SBonitaException { int i = 0; List<SGroup> childrenGroup; do { childrenGroup = identityService.getGroupChildren(groupId, i, BATCH_SIZE); i += BATCH_SIZE; for (final SGroup sGroup : childrenGroup) { deleteProfileMembersOfGroup(sGroup.getId()); } } while (childrenGroup.size() == BATCH_SIZE); }
@Override public void deleteGroup(final SGroup group) throws SGroupDeletionException { final SGroupLogBuilder logBuilder = getGroupLog(ActionType.DELETED, "Deleting group " + group.getName()); try { if (group.getIconId() != null) { deleteIcon(group.getIconId()); } recorder.recordDelete(new DeleteRecord(group), GROUP); log(group.getId(), SQueriableLog.STATUS_OK, logBuilder, "deleteGroup"); } catch (final SRecorderException | SBonitaReadException re) { log(group.getId(), SQueriableLog.STATUS_FAIL, logBuilder, "deleteGroup"); throw new SGroupDeletionException(re); } }
continue; profileService.addGroupToProfile(profileId, group.getId(), group.getName(), group.getParentPath()); continue; profileService.addRoleAndGroupToProfile(profileId, role.getId(), group.getId(), role.getName(), group.getName(), group.getParentPath());
private Map<String, Long> importGroups(final List<ExportedGroup> groupCreators) throws ImportDuplicateInOrganizationException, SIdentityException { final Map<String, Long> groupPathToIdMap = new HashMap<>(groupCreators.size()); for (final ExportedGroup groupCreator : groupCreators) { SGroup sGroup; try { final String groupPath = getGroupPath(groupCreator); sGroup = identityService.getGroupByPath(groupPath); strategy.foundExistingGroup(sGroup, groupCreator); } catch (final SGroupNotFoundException e) { sGroup = addGroup(groupCreator); } groupPathToIdMap.put(sGroup.getPath(), sGroup.getId()); } return groupPathToIdMap; }
@Override public void execute() throws SBonitaException { userNames = new HashMap<>(20); final List<SCustomUserInfoDefinition> customUserInfoDefinitions = getAllCustomUserInfoDefinitions(); final List<ExportedUser> users = getAllUsers(getUserInfoDefinitionNames(customUserInfoDefinitions)); // improvement: user server object to avoid useless conversion; final List<ExportedRole> roles = getAllRoles(); final List<SGroup> groups = getAllGroups(); final Map<Long, String> groupIdParentPath = new HashMap<>(groups.size()); for (final SGroup group : groups) { groupIdParentPath.put(group.getId(), group.getParentPath()); } final List<SUserMembership> userMemberships = getAllUserMemberships(); // improvement: user server object to avoid useless conversion; final List<ExportedGroup> clientGroups = ModelConvertor.toExportedGroups(groups); // improvement: user server object to avoid useless conversion; final List<ExportedUserMembership> clientUserMemberships = ModelConvertor.toExportedUserMembership(userMemberships, userNames, groupIdParentPath); List<ExportedCustomUserInfoDefinition> customUserInfoDefinitionCreators = ModelConvertor.toExportedCustomUserInfoDefinition(customUserInfoDefinitions); final Organization organization = new Organization(users, roles, clientGroups, clientUserMemberships, customUserInfoDefinitionCreators); try { xmlOrganization = new OrganizationParser().convert(organization); } catch (JAXBException e) { throw new SBonitaReadException(e); } }
@Override public Group createGroup(final GroupCreator creator) throws CreationException { if (creator == null) { throw new CreationException("Cannot create a null group"); } String groupName = creator.getFields().get(GroupCreator.GroupField.NAME).toString(); if (groupName.contains("/")) { throw new InvalidGroupNameException("Cannot create a group with '/' in its name"); } final TenantServiceAccessor tenantAccessor = getTenantAccessor(); final IdentityService identityService = tenantAccessor.getIdentityService(); if (creator.getFields().containsKey(GroupCreator.GroupField.ICON_NAME) || creator.getFields().containsKey(GroupCreator.GroupField.ICON_PATH)) { tenantAccessor.getTechnicalLoggerService().log(IdentityAPIImpl.class, TechnicalLogSeverity.WARNING, "setIconName and setIconPath are deprecated, use setIcon instead"); } final SGroup sGroup = ModelConvertor.constructSGroup(creator); try { identityService.getGroupByPath(sGroup.getPath()); throw new AlreadyExistsException("Group named \"" + sGroup.getName() + "\" already exists"); } catch (final SGroupNotFoundException ignored) { } try { identityService.createGroup(sGroup, (String) creator.getFields().get(GroupCreator.GroupField.ICON_FILENAME), (byte[]) creator.getFields().get(GroupCreator.GroupField.ICON_CONTENT)); } catch (SGroupCreationException e) { throw new CreationException(e); } return ModelConvertor.toGroup(sGroup); }