use of cz.metacentrum.perun.core.api.CandidateGroup in project perun by CESNET.
the class GroupsManagerBlImpl method addMissingGroupsWhileSynchronization.
/**
* Add missing groups under base group in Perun
*
* If some problem occurs, add candidateGroup to skippedGroups and skip it.
*
* Method is used by group structure synchronization.
*
* @param sess
* @param baseGroup under which we will be synchronizing groups
* @param candidateGroupsToAdd list of new groups (candidateGroups)
* @param loginAttributeDefinition attribute definition for login of group
* @param skippedGroups groups to be skipped because of any expected problem
*
* @throws InternalErrorException if some internal error occurs
*/
private void addMissingGroupsWhileSynchronization(PerunSession sess, Group baseGroup, List<CandidateGroup> candidateGroupsToAdd, AttributeDefinition loginAttributeDefinition, List<String> skippedGroups, List<String> mergeAttributes) {
Map<CandidateGroup, Group> groupsToUpdate = new HashMap<>();
// create all groups under base group first
for (CandidateGroup candidateGroup : candidateGroupsToAdd) {
try {
// create group
Group createdGroup = createGroup(sess, baseGroup, candidateGroup.asGroup());
groupsToUpdate.put(candidateGroup, createdGroup);
log.info("Group structure synchronization under base group {}: New Group id {} created during synchronization.", baseGroup, createdGroup.getId());
// set login for group
String login = candidateGroup.getLogin();
if (login == null)
throw new InternalErrorException("Login of candidate group " + candidateGroup + " can't be null!");
Attribute loginAttribute = new Attribute(loginAttributeDefinition);
loginAttribute.setValue(login);
getPerunBl().getAttributesManagerBl().setAttribute(sess, createdGroup, loginAttribute);
} catch (GroupExistsException e) {
log.warn("Group {} was added to group structure {} before adding process. Skip this group.", candidateGroup, baseGroup);
skippedGroups.add("GroupEntry:[" + candidateGroup + "] was skipped because it was added to group structure before adding process: Exception: " + e.getName() + " => " + e.getMessage() + "]");
} catch (GroupRelationNotAllowed e) {
log.warn("Can't create group from candidate group {} due to group relation not allowed exception {}.", candidateGroup, e);
skippedGroups.add("GroupEntry:[" + candidateGroup + "] was skipped because group relation was not allowed: Exception: " + e.getName() + " => " + e.getMessage() + "]");
} catch (GroupRelationAlreadyExists e) {
log.warn("Can't create group from candidate group {} due to group relation already exists exception {}.", candidateGroup, e);
skippedGroups.add("GroupEntry:[" + candidateGroup + "] was skipped because group relation already exists: Exception: " + e.getName() + " => " + e.getMessage() + "]");
} catch (WrongAttributeAssignmentException ex) {
// this means wrong setting of login attribute
throw new InternalErrorException(ex);
} catch (WrongAttributeValueException | WrongReferenceAttributeValueException ex) {
throw new InternalErrorException("Group login can't be set because of wrong value!", ex);
}
}
// update newly added groups cause the hierarchy could be incorrect
// no need to send list of removed parent groups here, because it is no need to resolve it for new groups at all
updateExistingGroupsWhileSynchronization(sess, baseGroup, groupsToUpdate, Collections.emptyList(), loginAttributeDefinition, skippedGroups, mergeAttributes);
}
use of cz.metacentrum.perun.core.api.CandidateGroup in project perun by CESNET.
the class ExtSourcesManagerBlImpl method generateCandidateGroup.
@Override
public CandidateGroup generateCandidateGroup(PerunSession perunSession, Map<String, String> groupSubjectData, ExtSource source, String loginPrefix) {
if (groupSubjectData == null)
throw new InternalErrorException("Group subject data cannot be null.");
if (groupSubjectData.isEmpty())
throw new InternalErrorException("Group subject data cannot be empty, at least group name has to exists.");
if (source == null)
throw new InternalErrorException("ExtSource cannot be null while generating CandidateGroup");
CandidateGroup candidateGroup = new CandidateGroup();
candidateGroup.setExtSource(source);
candidateGroup.asGroup().setName(groupSubjectData.get(GroupsManagerBlImpl.GROUP_NAME));
candidateGroup.setLogin(loginPrefix + groupSubjectData.get(GroupsManagerBlImpl.GROUP_LOGIN));
if (candidateGroup.getLogin() == null || candidateGroup.getLogin().isEmpty()) {
throw new InternalErrorException("Group subject data has to contain valid group login!");
}
// Check if the group name is not null and if it is in valid format.
if (candidateGroup.asGroup().getName() != null) {
try {
Utils.validateGroupName(candidateGroup.asGroup().getName());
} catch (IllegalArgumentException e) {
throw new InternalErrorException("Group subject data has to contain valid group name!", e);
}
} else {
throw new InternalErrorException("group name cannot be null in Group subject data!");
}
if (groupSubjectData.get(GroupsManagerBlImpl.PARENT_GROUP_LOGIN) != null) {
candidateGroup.setParentGroupLogin(loginPrefix + groupSubjectData.get(GroupsManagerBlImpl.PARENT_GROUP_LOGIN));
}
candidateGroup.asGroup().setDescription(groupSubjectData.get(GroupsManagerBlImpl.GROUP_DESCRIPTION));
groupSubjectData.entrySet().stream().filter(entry -> !GROUP_SYNC_DEFAULT_DATA.contains(entry.getKey())).forEach(entry -> candidateGroup.addAdditionalAttribute(entry.getKey(), entry.getValue()));
return candidateGroup;
}
Aggregations