Search in sources :

Example 26 with VoNotExistsException

use of cz.metacentrum.perun.core.api.exceptions.VoNotExistsException in project perun by CESNET.

the class urn_perun_group_attribute_def_def_groupStructureResources method checkAttributeSemantics.

@Override
public void checkAttributeSemantics(PerunSessionImpl sess, Group group, Attribute attribute) throws WrongReferenceAttributeValueException, WrongAttributeAssignmentException {
    // Null value is ok, means no settings for group
    if (attribute.getValue() == null)
        return;
    LinkedHashMap<String, String> attrValues = attribute.valueAsMap();
    Vo vo;
    try {
        vo = sess.getPerunBl().getVosManagerBl().getVoById(sess, group.getVoId());
    } catch (VoNotExistsException e) {
        throw new InternalErrorException("Failed to find group's vo.", e);
    }
    List<Resource> voResources = sess.getPerunBl().getResourcesManagerBl().getResources(sess, vo);
    Set<Integer> voResourceIds = voResources.stream().map(Resource::getId).collect(Collectors.toSet());
    for (String rawId : attrValues.keySet()) {
        int id = Integer.parseInt(rawId);
        if (!voResourceIds.contains(id)) {
            throw new WrongReferenceAttributeValueException(attribute, "There is no resource with id '" + id + "' assigned to the groups vo: " + vo);
        }
    }
}
Also used : WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) Resource(cz.metacentrum.perun.core.api.Resource) Vo(cz.metacentrum.perun.core.api.Vo) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) VoNotExistsException(cz.metacentrum.perun.core.api.exceptions.VoNotExistsException)

Aggregations

VoNotExistsException (cz.metacentrum.perun.core.api.exceptions.VoNotExistsException)26 Vo (cz.metacentrum.perun.core.api.Vo)24 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)18 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)14 Member (cz.metacentrum.perun.core.api.Member)10 ArrayList (java.util.ArrayList)9 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)8 Attribute (cz.metacentrum.perun.core.api.Attribute)7 ExtSource (cz.metacentrum.perun.core.api.ExtSource)7 User (cz.metacentrum.perun.core.api.User)7 ExtendMembershipException (cz.metacentrum.perun.core.api.exceptions.ExtendMembershipException)7 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)7 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)7 Group (cz.metacentrum.perun.core.api.Group)6 AlreadyMemberException (cz.metacentrum.perun.core.api.exceptions.AlreadyMemberException)6 PerunBl (cz.metacentrum.perun.core.bl.PerunBl)6 MemberNotExistsException (cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException)5 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)5 Map (java.util.Map)5 BanOnVo (cz.metacentrum.perun.core.api.BanOnVo)4