Search in sources :

Example 96 with WrongAttributeValueException

use of cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException 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 97 with WrongAttributeValueException

use of cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException 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 98 with WrongAttributeValueException

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

the class urn_perun_group_resource_attribute_def_def_projectOwnerLogin method checkAttributeValue.

public void checkAttributeValue(PerunSessionImpl sess, Resource resource, Group group, Attribute attribute) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException, WrongAttributeAssignmentException {
    String ownerLogin = (String) attribute.getValue();
    if (ownerLogin == null)
        return;
    Pattern pattern = Pattern.compile("^[a-zA-Z0-9][-A-z0-9_.@/]*$");
    Matcher match = pattern.matcher(ownerLogin);
    if (!match.matches()) {
        throw new WrongAttributeValueException(attribute, group, resource, "Bad format of attribute projectOwnerLogin (expected something like 'alois25').");
    }
    //Get Facility from resource
    Facility facility = sess.getPerunBl().getResourcesManagerBl().getFacility(sess, resource);
    //Get all users
    List<User> users = sess.getPerunBl().getUsersManagerBl().getUsers(sess);
    //Check if exists any user with this login
    for (User u : users) {
        Attribute userLogin = null;
        try {
            userLogin = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, facility, u, AttributesManager.NS_USER_FACILITY_ATTR_VIRT + ":login");
        } catch (AttributeNotExistsException ex) {
            throw new ConsistencyErrorException("Not existing attribute user_login", ex);
        }
        if (ownerLogin.equals(userLogin.getValue()))
            return;
    }
    throw new WrongAttributeValueException(attribute, group, resource, "There is no user with this login:'" + ownerLogin);
}
Also used : Pattern(java.util.regex.Pattern) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) User(cz.metacentrum.perun.core.api.User) Matcher(java.util.regex.Matcher) Attribute(cz.metacentrum.perun.core.api.Attribute) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) Facility(cz.metacentrum.perun.core.api.Facility) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)

Example 99 with WrongAttributeValueException

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

the class urn_perun_group_resource_attribute_def_virt_googleGroupName method setAttributeValue.

@Override
public boolean setAttributeValue(PerunSessionImpl sess, Resource resource, Group group, Attribute attribute) throws InternalErrorException, WrongReferenceAttributeValueException {
    Attribute googleGroupNameNamespaceAttribute = sess.getPerunBl().getModulesUtilsBl().getGoogleGroupNameNamespaceAttributeWithNotNullValue(sess, resource);
    try {
        Attribute groupNameAttribute = new Attribute(sess.getPerunBl().getAttributesManagerBl().getAttributeDefinition(sess, AttributesManager.NS_GROUP_ATTR_DEF + ":googleGroupName-namespace:" + googleGroupNameNamespaceAttribute.getValue()));
        groupNameAttribute.setValue(attribute.getValue());
        return sess.getPerunBl().getAttributesManagerBl().setAttributeWithoutCheck(sess, group, groupNameAttribute);
    } catch (AttributeNotExistsException ex) {
        throw new ConsistencyErrorException(ex);
    } catch (WrongAttributeValueException ex) {
        throw new InternalErrorException(ex);
    } catch (WrongAttributeAssignmentException ex) {
        throw new InternalErrorException(ex);
    }
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) Attribute(cz.metacentrum.perun.core.api.Attribute) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) 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 100 with WrongAttributeValueException

use of cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException 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

WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)135 Attribute (cz.metacentrum.perun.core.api.Attribute)100 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)83 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)82 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)75 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)66 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)54 Matcher (java.util.regex.Matcher)31 RichAttribute (cz.metacentrum.perun.core.api.RichAttribute)27 ArrayList (java.util.ArrayList)17 LinkedHashMap (java.util.LinkedHashMap)16 Facility (cz.metacentrum.perun.core.api.Facility)14 Map (java.util.Map)14 Resource (cz.metacentrum.perun.core.api.Resource)12 User (cz.metacentrum.perun.core.api.User)11 Group (cz.metacentrum.perun.core.api.Group)9 Pattern (java.util.regex.Pattern)8 BigDecimal (java.math.BigDecimal)7 List (java.util.List)7 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)5