Search in sources :

Example 36 with ConsistencyErrorException

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

the class GroupsManagerBlImpl method setRequiredAttributes.

/**
 * Set required attributes when adding new direct or indirect members.
 * @param sess perun session
 * @param member member
 * @param group group
 * @throws InternalErrorException
 * @throws WrongAttributeValueException
 * @throws WrongReferenceAttributeValueException
 */
private void setRequiredAttributes(PerunSession sess, Member member, Group group) throws WrongAttributeValueException, WrongReferenceAttributeValueException {
    // setting required attributes
    User user = getPerunBl().getUsersManagerBl().getUserByMember(sess, member);
    List<Resource> resources = getPerunBl().getResourcesManagerBl().getAssignedResources(sess, group);
    for (Resource resource : resources) {
        Facility facility = getPerunBl().getResourcesManagerBl().getFacility(sess, resource);
        // check members attributes
        try {
            getPerunBl().getAttributesManagerBl().setRequiredAttributes(sess, facility, resource, user, member);
        } catch (WrongAttributeAssignmentException | AttributeNotExistsException | MemberResourceMismatchException ex) {
            throw new ConsistencyErrorException(ex);
        }
    }
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) User(cz.metacentrum.perun.core.api.User) RichUser(cz.metacentrum.perun.core.api.RichUser) MemberResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.MemberResourceMismatchException) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) AssignedResource(cz.metacentrum.perun.core.api.AssignedResource) Resource(cz.metacentrum.perun.core.api.Resource) Facility(cz.metacentrum.perun.core.api.Facility)

Example 37 with ConsistencyErrorException

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

the class ResourcesManagerBlImpl method copyAttributes.

@Override
public void copyAttributes(PerunSession sess, Resource sourceResource, Resource destinationResource) throws WrongReferenceAttributeValueException {
    List<Attribute> sourceAttributes = getPerunBl().getAttributesManagerBl().getAttributes(sess, sourceResource);
    List<Attribute> destinationAttributes = getPerunBl().getAttributesManagerBl().getAttributes(sess, destinationResource);
    // do not get virtual attributes from source resource, they can't be set to destination
    sourceAttributes.removeIf(attribute -> attribute.getNamespace().startsWith(AttributesManager.NS_RESOURCE_ATTR_VIRT));
    // create intersection of destination and source attributes
    List<Attribute> intersection = new ArrayList<>(destinationAttributes);
    intersection.retainAll(sourceAttributes);
    try {
        // delete all common attributes from destination resource
        getPerunBl().getAttributesManagerBl().removeAttributes(sess, destinationResource, intersection);
        // add all attributes from the source resource to the destination resource
        getPerunBl().getAttributesManagerBl().setAttributes(sess, destinationResource, sourceAttributes);
    } catch (WrongAttributeAssignmentException ex) {
        throw new InternalErrorException("Copying of attributes failed, wrong assignment.", ex);
    } catch (WrongAttributeValueException ex) {
        throw new ConsistencyErrorException("Copying of attributes failed.", 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) ArrayList(java.util.ArrayList) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)

Example 38 with ConsistencyErrorException

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

the class ModulesUtilsBlImpl method getCommonGIDOfGroupsWithSameNameInSameNamespace.

@Override
public Integer getCommonGIDOfGroupsWithSameNameInSameNamespace(PerunSessionImpl sess, List<Group> groupsWithSameGroupNameInSameNamespace, String gidNamespace, Integer commonGID) throws WrongAttributeAssignmentException {
    // If there are no groups, return commonGID from param (it can be null)
    if (groupsWithSameGroupNameInSameNamespace == null || groupsWithSameGroupNameInSameNamespace.isEmpty())
        return commonGID;
    Utils.notNull(gidNamespace, "gidNamespace");
    // only for more verbose exception messages
    Group commonGIDGroup = null;
    for (Group g : groupsWithSameGroupNameInSameNamespace) {
        try {
            Attribute attr = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, g, A_G_unixGID_namespace + ":" + gidNamespace);
            if (attr.getValue() != null) {
                if (commonGID == null) {
                    commonGIDGroup = g;
                    commonGID = (Integer) attr.getValue();
                } else {
                    if (!commonGID.equals(attr.getValue()))
                        throw new ConsistencyErrorException("There are at least 1 groups/resources with same GroupName in same namespace but with different GID in same namespaces. Conflict found: " + g + "(gid=" + attr.getValue() + ") and " + commonGIDGroup + "(gid=" + commonGID + ")");
                }
            }
        } catch (AttributeNotExistsException ex) {
            throw new ConsistencyErrorException(ex);
        }
    }
    return commonGID;
}
Also used : Group(cz.metacentrum.perun.core.api.Group) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) Attribute(cz.metacentrum.perun.core.api.Attribute) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)

Example 39 with ConsistencyErrorException

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

the class ModulesUtilsBlImpl method getCommonGIDOfResourcesWithSameNameInSameNamespace.

@Override
public Integer getCommonGIDOfResourcesWithSameNameInSameNamespace(PerunSessionImpl sess, List<Resource> resourcesWithSameGroupNameInSameNamespace, String gidNamespace, Integer commonGID) throws WrongAttributeAssignmentException {
    // If there are no resources, return commonGID from param (it can be null)
    if (resourcesWithSameGroupNameInSameNamespace == null || resourcesWithSameGroupNameInSameNamespace.isEmpty())
        return commonGID;
    Utils.notNull(gidNamespace, "gidNamespace");
    // only for more verbose exception messages
    Resource commonGIDResource = null;
    for (Resource r : resourcesWithSameGroupNameInSameNamespace) {
        try {
            Attribute attr = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, r, A_R_unixGID_namespace + ":" + gidNamespace);
            if (attr.getValue() != null) {
                if (commonGID == null) {
                    commonGIDResource = r;
                    commonGID = (Integer) attr.getValue();
                } else {
                    if (!commonGID.equals(attr.getValue()))
                        throw new ConsistencyErrorException("There are at least 1 groups/resources with same GroupName in same namespace but with different GID in same namespaces. Conflict found: " + r + "(gid=" + attr.getValue() + ") and " + commonGIDResource + "(gid=" + commonGID + ")");
                }
            }
        } catch (AttributeNotExistsException ex) {
            throw new ConsistencyErrorException(ex);
        }
    }
    return commonGID;
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) Attribute(cz.metacentrum.perun.core.api.Attribute) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) Resource(cz.metacentrum.perun.core.api.Resource)

Example 40 with ConsistencyErrorException

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

the class AttributesManagerBlImpl method removeAllAttributes.

@Override
public void removeAllAttributes(PerunSession sess, Facility facility, boolean removeAlsoUserFacilityAttributes) throws WrongAttributeValueException, WrongReferenceAttributeValueException {
    removeAllAttributes(sess, facility);
    if (removeAlsoUserFacilityAttributes) {
        List<Attribute> userFacilityAttributes = getUserFacilityAttributesForAnyUser(sess, facility);
        if (getAttributesManagerImpl().removeAllUserFacilityAttributesForAnyUser(sess, facility)) {
            getPerunBl().getAuditer().log(sess, new AllUserFacilityAttributesRemoved(facility));
        }
        log.info("{} removed all attributes from any user on facility {}.", sess.getLogId(), facility.getId());
        for (Attribute attribute : userFacilityAttributes) attribute.setValue(null);
        List<User> facilityUsers = perunBl.getFacilitiesManagerBl().getAllowedUsers(sess, facility);
        for (User user : facilityUsers) {
            try {
                checkAttributesSemantics(sess, facility, user, userFacilityAttributes);
                checkAttributesDependencies(sess, facility, user, userFacilityAttributes);
            } catch (WrongAttributeAssignmentException ex) {
                throw new ConsistencyErrorException(ex);
            }
            for (Attribute attribute : userFacilityAttributes) {
                getAttributesManagerImpl().changedAttributeHook(sess, facility, user, new Attribute(attribute));
            }
        }
    }
}
Also used : AllUserFacilityAttributesRemoved(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AllUserFacilityAttributesRemoved) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) User(cz.metacentrum.perun.core.api.User) AllUserFacilityAttributesRemovedForFacilitiesAndUser(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AllUserFacilityAttributesRemovedForFacilitiesAndUser) AttributeRemovedForFacilityAndUser(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeRemovedForFacilityAndUser) AttributeSetForUser(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeSetForUser) AllAttributesRemovedForFacilityAndUser(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AllAttributesRemovedForFacilityAndUser) AttributeSetForFacilityAndUser(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeSetForFacilityAndUser) AttributeRemovedForUser(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeRemovedForUser) AllAttributesRemovedForUser(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AllAttributesRemovedForUser) Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)

Aggregations

ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)281 Attribute (cz.metacentrum.perun.core.api.Attribute)212 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)162 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)120 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)111 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)102 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)84 User (cz.metacentrum.perun.core.api.User)60 ArrayList (java.util.ArrayList)51 Group (cz.metacentrum.perun.core.api.Group)44 Facility (cz.metacentrum.perun.core.api.Facility)41 Resource (cz.metacentrum.perun.core.api.Resource)37 Member (cz.metacentrum.perun.core.api.Member)30 LinkedHashMap (java.util.LinkedHashMap)23 Vo (cz.metacentrum.perun.core.api.Vo)22 RichAttribute (cz.metacentrum.perun.core.api.RichAttribute)21 GroupResourceMismatchException (cz.metacentrum.perun.core.api.exceptions.GroupResourceMismatchException)20 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)19 MemberNotExistsException (cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException)17 VoNotExistsException (cz.metacentrum.perun.core.api.exceptions.VoNotExistsException)17