Search in sources :

Example 86 with WrongReferenceAttributeValueException

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

the class urn_perun_member_attribute_def_def_address method changedAttributeHook.

@Override
public void changedAttributeHook(PerunSessionImpl session, Member member, Attribute attribute) throws InternalErrorException, WrongReferenceAttributeValueException {
    User user = session.getPerunBl().getUsersManagerBl().getUserByMember(session, member);
    if (attribute.getValue() != null) {
        Attribute userAddress = null;
        try {
            userAddress = session.getPerunBl().getAttributesManagerBl().getAttribute(session, user, A_U_address);
            if (userAddress.getValue() == null) {
                userAddress.setValue(attribute.getValue());
                session.getPerunBl().getAttributesManagerBl().setAttribute(session, user, userAddress);
            }
        } catch (WrongAttributeAssignmentException ex) {
            throw new InternalErrorException(ex);
        } catch (AttributeNotExistsException ex) {
            throw new ConsistencyErrorException(ex);
        } catch (WrongAttributeValueException ex) {
            throw new WrongReferenceAttributeValueException(attribute, userAddress, "Mismatch in checking of member address and user address (different checking rules)", ex);
        }
    }
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) User(cz.metacentrum.perun.core.api.User) Attribute(cz.metacentrum.perun.core.api.Attribute) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)

Example 87 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_projectName method checkAttributeValue.

public void checkAttributeValue(PerunSessionImpl sess, Resource resource, Group group, Attribute attribute) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException, WrongAttributeAssignmentException {
    String name = (String) attribute.getValue();
    if (name == null)
        return;
    Pattern pattern = Pattern.compile("^[-_a-zA-Z0-9]+$");
    Matcher match = pattern.matcher(name);
    if (!match.matches()) {
        throw new WrongAttributeValueException(attribute, group, resource, "Bad format of attribute projectName (expected something like 'project_name-24').");
    }
    //Prepare this resource projectsBasePath
    Attribute thisResourceProjectsBasePath = null;
    try {
        thisResourceProjectsBasePath = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, resource, AttributesManager.NS_RESOURCE_ATTR_DEF + ":projectsBasePath");
    } catch (AttributeNotExistsException ex) {
        throw new ConsistencyErrorException("Attribute projectBasePath not exists!", ex);
    }
    //Prepare value of this resource projectsBasePath
    String thisResourceProjectBasePathValue = null;
    if (thisResourceProjectsBasePath.getValue() != null) {
        thisResourceProjectBasePathValue = (String) thisResourceProjectsBasePath.getValue();
    } else {
        throw new WrongReferenceAttributeValueException(attribute, thisResourceProjectsBasePath, group, resource, resource, null, "Resource must have set projectsBasePath if attribute projectName for it's group need to be set.");
    }
    //Get All Resources with the same project_base_path
    Facility facility = sess.getPerunBl().getResourcesManagerBl().getFacility(sess, resource);
    List<Resource> resources = sess.getPerunBl().getFacilitiesManagerBl().getAssignedResources(sess, facility);
    resources.remove(resource);
    //Remove all resources which has other
    Iterator<Resource> iterator = resources.iterator();
    while (iterator.hasNext()) {
        Resource r = iterator.next();
        Attribute otherResourceProjectsBasePath = null;
        try {
            otherResourceProjectsBasePath = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, r, AttributesManager.NS_RESOURCE_ATTR_DEF + ":projectsBasePath");
        } catch (AttributeNotExistsException ex) {
            throw new ConsistencyErrorException("Attribute projectBasePath not exists!", ex);
        }
        if (otherResourceProjectsBasePath.getValue() != null) {
            String otherResourceProjectsBasePathValue = (String) otherResourceProjectsBasePath.getValue();
            if (!thisResourceProjectBasePathValue.equals(otherResourceProjectsBasePathValue))
                iterator.remove();
        } else {
            //If projectsBasePath is null, also remove resource
            iterator.remove();
        }
    }
    //For all resources with the same project_base_path look for groups with the same projectName
    for (Resource r : resources) {
        List<Group> groups = sess.getPerunBl().getGroupsManagerBl().getAssignedGroupsToResource(sess, r);
        //Our group may aslo be part of assigned Group, need to be removed
        groups.remove(group);
        for (Group g : groups) {
            Attribute groupProjectName = null;
            try {
                groupProjectName = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, r, g, AttributesManager.NS_GROUP_RESOURCE_ATTR_DEF + ":projectName");
            } catch (AttributeNotExistsException ex) {
                throw new ConsistencyErrorException("Attribute projectName not exists!", ex);
            }
            String groupProjectNameValue = null;
            if (groupProjectName.getValue() != null) {
                groupProjectNameValue = (String) groupProjectName.getValue();
            }
            //If the name is somewhere same, exception must be thrown
            if (name.equals(groupProjectNameValue)) {
                throw new WrongReferenceAttributeValueException(attribute, groupProjectName, group, resource, g, r, "Group " + group + " and " + g + " have the same projectName in the same projectsBasePath.");
            }
        }
    }
}
Also used : Pattern(java.util.regex.Pattern) Group(cz.metacentrum.perun.core.api.Group) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) Matcher(java.util.regex.Matcher) Attribute(cz.metacentrum.perun.core.api.Attribute) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) Resource(cz.metacentrum.perun.core.api.Resource) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) Facility(cz.metacentrum.perun.core.api.Facility) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)

Example 88 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_googleGroupName method getAttributeValue.

@Override
public Attribute getAttributeValue(PerunSessionImpl sess, Resource resource, Group group, AttributeDefinition attributeDefinition) throws InternalErrorException {
    Attribute attribute = new Attribute(attributeDefinition);
    Attribute googleGroupNameNamespaceAttribute;
    try {
        googleGroupNameNamespaceAttribute = sess.getPerunBl().getModulesUtilsBl().getGoogleGroupNameNamespaceAttributeWithNotNullValue(sess, resource);
    } catch (WrongReferenceAttributeValueException ex) {
        return attribute;
    }
    try {
        Attribute groupNameAttribute = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, group, AttributesManager.NS_GROUP_ATTR_DEF + ":googleGroupName-namespace:" + googleGroupNameNamespaceAttribute.getValue());
        attribute = Utils.copyAttributeToVirtualAttributeWithValue(groupNameAttribute, attribute);
        return attribute;
    } catch (WrongAttributeAssignmentException ex) {
        throw new InternalErrorException(ex);
    } catch (AttributeNotExistsException ex) {
        throw new ConsistencyErrorException(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) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 89 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_unixGID method getAttributeValue.

@Override
public Attribute getAttributeValue(PerunSessionImpl sess, Resource resource, Group group, AttributeDefinition attributeDefinition) throws InternalErrorException {
    Attribute attribute = new Attribute(attributeDefinition);
    Attribute unixGIDNamespaceAttribute;
    try {
        unixGIDNamespaceAttribute = sess.getPerunBl().getModulesUtilsBl().getUnixGIDNamespaceAttributeWithNotNullValue(sess, resource);
    } catch (WrongReferenceAttributeValueException ex) {
        return attribute;
    }
    try {
        Attribute gidAttribute = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, group, AttributesManager.NS_GROUP_ATTR_DEF + ":unixGID-namespace:" + unixGIDNamespaceAttribute.getValue());
        attribute = Utils.copyAttributeToVirtualAttributeWithValue(gidAttribute, attribute);
        return attribute;
    } catch (WrongAttributeAssignmentException ex) {
        throw new InternalErrorException(ex);
    } catch (AttributeNotExistsException ex) {
        throw new ConsistencyErrorException(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) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 90 with WrongReferenceAttributeValueException

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

the class urn_perun_member_attribute_def_def_organization method changedAttributeHook.

@Override
public void changedAttributeHook(PerunSessionImpl session, Member member, Attribute attribute) throws InternalErrorException, WrongReferenceAttributeValueException {
    User user = session.getPerunBl().getUsersManagerBl().getUserByMember(session, member);
    if (attribute.getValue() != null) {
        Attribute userOrganization = null;
        try {
            userOrganization = session.getPerunBl().getAttributesManagerBl().getAttribute(session, user, A_U_organization);
            if (userOrganization.getValue() == null) {
                userOrganization.setValue(attribute.getValue());
                session.getPerunBl().getAttributesManagerBl().setAttribute(session, user, userOrganization);
            }
        } catch (WrongAttributeAssignmentException ex) {
            throw new InternalErrorException(ex);
        } catch (AttributeNotExistsException ex) {
            throw new ConsistencyErrorException(ex);
        } catch (WrongAttributeValueException ex) {
            throw new WrongReferenceAttributeValueException(attribute, userOrganization, "Mismatch in checking of member organization and user organization (different checking rules)", ex);
        }
    }
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) User(cz.metacentrum.perun.core.api.User) Attribute(cz.metacentrum.perun.core.api.Attribute) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) 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