/** * Gets collections as map of collectionID => Group. * * @return Map of collection IDs to group. */ private Map<String, Group> getCollectionIDsToGroupsMap (PerunSession session, Perun perun, Group collectionsGroup) throws GroupNotExistsException, WrongAttributeAssignmentException, InternalErrorException, AttributeNotExistsException, PrivilegeException { Map<String, Group> collectionIDsToGroupMap = new HashMap<>(); for (Group group : perun.getGroupsManager().getSubGroups(session, collectionsGroup)) { for (Group subgroup : perun.getGroupsManager().getSubGroups(session, group)) { if (REPRESENTATIVES_GROUP_NAME.equals(subgroup.getShortName())) { Attribute collectionID = perun.getAttributesManager().getAttribute(session, subgroup, COLLECTION_ID_ATTR_NAME); collectionIDsToGroupMap.put(collectionID.valueAsString(), subgroup); } } } return collectionIDsToGroupMap; }
/** * Gets collections as map of collectionID => Group. * * @return Map of collection IDs to group. */ private Map<String, Group> getNetworkIDsToGroupsMap (PerunSession session, Perun perun, Group networksGroup) throws GroupNotExistsException, WrongAttributeAssignmentException, InternalErrorException, AttributeNotExistsException, PrivilegeException { Map<String, Group> networkIDsToGroupMap = new HashMap<>(); for (Group group : perun.getGroupsManager().getSubGroups(session, networksGroup)) { for (Group subgroup : perun.getGroupsManager().getSubGroups(session, group)) { if (REPRESENTATIVES_GROUP_NAME.equals(subgroup.getShortName())) { Attribute networkID = perun.getAttributesManager().getAttribute(session, subgroup, NETWORK_ID_ATTR_NAME); networkIDsToGroupMap.put(networkID.valueAsString(), subgroup); } } } return networkIDsToGroupMap; }
@Override public Application beforeApprove(PerunSession session, Application app) throws PerunException { Group group = app.getGroup(); if (group == null) { throw new CantBeApprovedException("This module can be set only for registration to Group."); } AttributesManager am = session.getPerun().getAttributesManager(); Attribute attestation = am.getAttribute(session, group, A_G_D_groupAttestation); if (attestation == null) { throw new CantBeApprovedException("Application cannot be approved: Group does not have attestation attribute set."); } String newValue = attestation.valueAsString(); if (newValue == null || newValue.isEmpty()) { throw new CantBeApprovedException("Application cannot be approved: Group does not have attestation value set."); } return app; }
/** * Add new bonaFideStatus to the user attribute. */ @Override public Application approveApplication(PerunSession session, Application app) throws PerunException { User user = app.getUser(); Group group = app.getGroup(); AttributesManager am = session.getPerun().getAttributesManager(); Attribute attestation = am.getAttribute(session, group, A_G_D_groupAttestation); String newValue = attestation.valueAsString(); Attribute bonaFideStatus = am.getAttribute(session, user, A_U_D_userBonaFideStatus); List<String> value = new ArrayList<>(); if (bonaFideStatus.getValue() != null && bonaFideStatus.valueAsList() != null) { value = bonaFideStatus.valueAsList(); } value.add(newValue); bonaFideStatus.setValue(value); am.setAttribute(session, user, bonaFideStatus); return app; }