Search in sources :

Example 81 with WrongReferenceAttributeValueException

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

the class urn_perun_facility_attribute_def_virt_minGID method checkAttributeValue.

public void checkAttributeValue(PerunSessionImpl sess, Facility facility, Attribute attribute) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException, WrongAttributeAssignmentException {
    try {
        Attribute gidNamespaceAttribute = getUnixGIDNamespaceAttribute(sess, facility);
        if (gidNamespaceAttribute.getValue() == null)
            throw new WrongReferenceAttributeValueException(attribute, gidNamespaceAttribute);
        Attribute namespaceMinGidAttribute = getNamespaceMinGidAttribute(sess, (String) gidNamespaceAttribute.getValue());
        sess.getPerunBl().getAttributesManagerBl().checkAttributeValue(sess, (String) gidNamespaceAttribute.getValue(), namespaceMinGidAttribute);
    } catch (WrongReferenceAttributeValueException ex) {
        throw new WrongReferenceAttributeValueException(attribute, ex.getReferenceAttribute());
    }
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)

Example 82 with WrongReferenceAttributeValueException

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

the class urn_perun_user_facility_attribute_def_virt_preferredUnixGroupName method checkAttributeValue.

@Override
public void checkAttributeValue(PerunSessionImpl sess, Facility facility, User user, Attribute attribute) throws WrongAttributeValueException, WrongReferenceAttributeValueException, InternalErrorException, WrongAttributeAssignmentException {
    try {
        Attribute facilityGroupNameNamespaceAttr = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, facility, A_FACILITY_DEF_UNIX_GROUPNAME_NAMESPACE);
        if (facilityGroupNameNamespaceAttr.getValue() == null) {
            throw new WrongReferenceAttributeValueException(attribute, facilityGroupNameNamespaceAttr, user, facility, facility, null, "GroupName-namespace for racility cannot be null.");
        }
        String namespace = (String) facilityGroupNameNamespaceAttr.getValue();
        Attribute preferredUnixGroupNameAttr = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, user, A_USER_DEF_PREFERRED_UNIX_GROUPNAME_NAMESPACE + namespace);
        if (attribute.getValue() != null) {
            preferredUnixGroupNameAttr.setValue(attribute.getValue());
            sess.getPerunBl().getAttributesManagerBl().checkAttributeValue(sess, user, preferredUnixGroupNameAttr);
        }
    // Null is ok, can be empty
    } catch (AttributeNotExistsException e) {
        throw new ConsistencyErrorException(e);
    }
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) Attribute(cz.metacentrum.perun.core.api.Attribute) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)

Example 83 with WrongReferenceAttributeValueException

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

the class urn_perun_user_facility_attribute_def_virt_preferredUnixGroupName method setAttributeValue.

@Override
public boolean setAttributeValue(PerunSessionImpl sess, Facility facility, User user, Attribute attribute) throws InternalErrorException, WrongReferenceAttributeValueException {
    AttributeDefinition userPreferredGroupNameDefinition;
    try {
        Attribute facilityGroupNameNamespaceAttr = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, facility, A_FACILITY_DEF_UNIX_GROUPNAME_NAMESPACE);
        if (facilityGroupNameNamespaceAttr.getValue() == null) {
            throw new WrongReferenceAttributeValueException(attribute, facilityGroupNameNamespaceAttr, facility, user, facility, null, "Facility need to have nonempty groupName-namespace attribute.");
        }
        String namespace = (String) facilityGroupNameNamespaceAttr.getValue();
        userPreferredGroupNameDefinition = sess.getPerunBl().getAttributesManagerBl().getAttributeDefinition(sess, A_USER_DEF_PREFERRED_UNIX_GROUPNAME_NAMESPACE + namespace);
    } catch (AttributeNotExistsException e) {
        throw new ConsistencyErrorException(e);
    } catch (WrongAttributeAssignmentException e) {
        throw new InternalErrorException(e);
    }
    Attribute userPreferredGroupName = new Attribute(userPreferredGroupNameDefinition);
    userPreferredGroupName.setValue(attribute.getValue());
    try {
        return sess.getPerunBl().getAttributesManagerBl().setAttributeWithoutCheck(sess, user, userPreferredGroupName);
    } catch (WrongAttributeValueException e) {
        throw new InternalErrorException(e);
    } catch (WrongAttributeAssignmentException e) {
        throw new InternalErrorException(e);
    }
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) Attribute(cz.metacentrum.perun.core.api.Attribute) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)

Example 84 with WrongReferenceAttributeValueException

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

the class urn_perun_group_resource_attribute_def_def_systemUnixGID method checkAttributeValue.

public void checkAttributeValue(PerunSessionImpl sess, Resource resource, Group group, Attribute attribute) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException, WrongAttributeAssignmentException {
    Integer gid = (Integer) attribute.getValue();
    //Gid should not be null if is system unix group or if less than 1
    Attribute isSystemGroup = new Attribute();
    if (gid == null) {
        try {
            isSystemGroup = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, resource, group, A_GR_systemIsUnixGroup);
        } catch (AttributeNotExistsException ex) {
            throw new ConsistencyErrorException("Not exist Attribute " + A_GR_systemIsUnixGroup + " for group " + group, ex);
        }
        if (isSystemGroup.getValue() != null && (Integer) isSystemGroup.getValue() == 1) {
            throw new WrongReferenceAttributeValueException(attribute, "Attribute cant be null if " + group + " on " + resource + " is system unix group.");
        }
    } else if (gid < 1) {
        throw new WrongAttributeValueException(attribute, "GID number less than 1 is not allowed value.");
    }
    //Get facility for the resource
    Facility facility = sess.getPerunBl().getResourcesManagerBl().getFacility(sess, resource);
    //List of pairs (group and resource) which has the attribute with the value
    List<Pair<Group, Resource>> listGroupPairsResource = sess.getPerunBl().getGroupsManagerBl().getGroupResourcePairsByAttribute(sess, attribute);
    //Searching through all pairs and if is not checking group/resource/attribute, then try for being on the same facility, if yes then throw exception but only if these groups have not the same GroupName too.
    for (Pair<Group, Resource> p : listGroupPairsResource) {
        if (!p.getLeft().equals(group) || !p.getRight().equals(resource)) {
            Facility facilityForTest = sess.getPerunBl().getResourcesManagerBl().getFacility(sess, p.getRight());
            Attribute group1GroupName = new Attribute();
            Attribute group2GroupName = new Attribute();
            try {
                group1GroupName = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, resource, group, A_GR_systemUnixGroupName);
            } catch (AttributeNotExistsException ex) {
                throw new ConsistencyErrorException("Attribute " + A_GR_systemUnixGroupName + " not exists for group " + group, ex);
            }
            try {
                group2GroupName = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, p.getRight(), p.getLeft(), A_GR_systemUnixGroupName);
            } catch (AttributeNotExistsException ex) {
                throw new ConsistencyErrorException("Attribute " + A_GR_systemUnixGroupName + " not exists for group " + p.getLeft(), ex);
            }
            if (facilityForTest.equals(facility) && !(group1GroupName.getValue().equals(group2GroupName.getValue())))
                throw new WrongAttributeValueException(attribute, "Gid " + gid + "is allready used by another group-resource.  " + p.getLeft() + " " + p.getRight());
        }
    }
}
Also used : Group(cz.metacentrum.perun.core.api.Group) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) Attribute(cz.metacentrum.perun.core.api.Attribute) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) Resource(cz.metacentrum.perun.core.api.Resource) Facility(cz.metacentrum.perun.core.api.Facility) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException) Pair(cz.metacentrum.perun.core.api.Pair)

Example 85 with WrongReferenceAttributeValueException

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

the class urn_perun_group_resource_attribute_def_virt_unixGroupName method checkAttributeValue.

@Override
public void checkAttributeValue(PerunSessionImpl sess, Resource resource, Group group, Attribute attribute) throws InternalErrorException, WrongAttributeValueException, WrongAttributeAssignmentException, WrongReferenceAttributeValueException {
    Attribute unixGroupNameNamespaceAttribute = sess.getPerunBl().getModulesUtilsBl().getUnixGroupNameNamespaceAttributeWithNotNullValue(sess, resource);
    Attribute groupNameAttribute;
    try {
        groupNameAttribute = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, group, AttributesManager.NS_GROUP_ATTR_DEF + ":unixGroupName-namespace:" + unixGroupNameNamespaceAttribute.getValue());
    } catch (AttributeNotExistsException ex) {
        throw new ConsistencyErrorException(ex);
    }
    groupNameAttribute.setValue(attribute.getValue());
    try {
        sess.getPerunBl().getAttributesManagerBl().checkAttributeValue(sess, group, groupNameAttribute);
    } catch (WrongAttributeValueException ex) {
        throw new WrongAttributeValueException(attribute, ex.getMessage(), ex);
    } catch (WrongReferenceAttributeValueException ex) {
        throw new WrongReferenceAttributeValueException(attribute, ex.getAttribute(), ex);
    }
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) Attribute(cz.metacentrum.perun.core.api.Attribute) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)

Aggregations

WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)109 Attribute (cz.metacentrum.perun.core.api.Attribute)101 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)83 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)70 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)64 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)62 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)51 RichAttribute (cz.metacentrum.perun.core.api.RichAttribute)27 Resource (cz.metacentrum.perun.core.api.Resource)13 ArrayList (java.util.ArrayList)13 Facility (cz.metacentrum.perun.core.api.Facility)12 Matcher (java.util.regex.Matcher)12 User (cz.metacentrum.perun.core.api.User)11 Group (cz.metacentrum.perun.core.api.Group)9 BigDecimal (java.math.BigDecimal)6 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)5 List (java.util.List)5 Pattern (java.util.regex.Pattern)5 Pair (cz.metacentrum.perun.core.api.Pair)3 LinkedHashMap (java.util.LinkedHashMap)3