Search in sources :

Example 56 with WrongAttributeAssignmentException

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

the class AttributesManagerBlImpl method setAttributes.

public void setAttributes(PerunSession sess, Resource resource, Member member, List<Attribute> attributes, boolean workWithUserAttributes) throws InternalErrorException, WrongAttributeValueException, WrongAttributeAssignmentException, WrongReferenceAttributeValueException {
    // clasification of attributes to attributes to remove and attributes to set
    List<Attribute> attributesToRemove = new ArrayList<Attribute>();
    List<Attribute> attributesToSet = new ArrayList<Attribute>();
    for (Attribute attribute : attributes) {
        if (attribute.getValue() == null) {
            attributesToRemove.add(attribute);
        } else {
            attributesToSet.add(attribute);
        }
    }
    removeAttributes(sess, resource, member, attributesToRemove, workWithUserAttributes);
    //fist we have to store attributes into DB because checkAttributesValue can be preformed only on stored attributes.
    if (!workWithUserAttributes) {
        long timer = Utils.startTimer();
        for (Attribute attribute : attributesToSet) {
            //skip core attributes
            if (!getAttributesManagerImpl().isCoreAttribute(sess, attribute)) {
                setAttributeWithoutCheck(sess, resource, member, attribute, false);
            }
        }
        log.debug("addMember timer: setAttributes (for(Attribute attribute : attributes)) [{}].", Utils.getRunningTime(timer));
    } else {
        long timer = Utils.startTimer();
        Facility facility = getPerunBl().getResourcesManagerBl().getFacility(sess, resource);
        User user = getPerunBl().getUsersManagerBl().getUserByMember(sess, member);
        log.debug("addMember timer: getFacility and User [{}].", Utils.getRunningTime(timer));
        for (Attribute attribute : attributesToSet) {
            boolean changed = false;
            //skip core attributes
            if (!getAttributesManagerImpl().isCoreAttribute(sess, attribute)) {
                if (getAttributesManagerImpl().isFromNamespace(sess, attribute, AttributesManager.NS_MEMBER_RESOURCE_ATTR)) {
                    timer = Utils.startTimer();
                    changed = setAttributeWithoutCheck(sess, resource, member, attribute, false);
                    if (changed) {
                        log.debug("addMember timer: setAttribute rm [{}] [{}].", attribute, Utils.getRunningTime(timer));
                    }
                } else if (getAttributesManagerImpl().isFromNamespace(sess, attribute, AttributesManager.NS_USER_FACILITY_ATTR)) {
                    timer = Utils.startTimer();
                    changed = setAttributeWithoutCheck(sess, facility, user, attribute);
                    if (changed) {
                        log.debug("addMember timer: setAttribute uf [{}] [{}].", attribute, Utils.getRunningTime(timer));
                    }
                } else if (getAttributesManagerImpl().isFromNamespace(sess, attribute, AttributesManager.NS_USER_ATTR)) {
                    timer = Utils.startTimer();
                    changed = setAttributeWithoutCheck(sess, user, attribute);
                    if (changed) {
                        log.debug("addMember timer: setAttribute u [{}] [{}].", attribute, Utils.getRunningTime(timer));
                    }
                } else if (getAttributesManagerImpl().isFromNamespace(sess, attribute, AttributesManager.NS_MEMBER_ATTR)) {
                    timer = Utils.startTimer();
                    changed = setAttributeWithoutCheck(sess, member, attribute);
                    if (changed) {
                        log.debug("addMember timer: setAttribute m [{}] [{}].", attribute, Utils.getRunningTime(timer));
                    }
                } else {
                    throw new WrongAttributeAssignmentException(attribute);
                }
            }
        }
    }
    //if checkAttributesValue fails it causes rollback so no attribute will be stored
    checkAttributesValue(sess, resource, member, attributesToSet, workWithUserAttributes);
    this.checkAttributesDependencies(sess, resource, member, attributesToSet, workWithUserAttributes);
}
Also used : User(cz.metacentrum.perun.core.api.User) Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) ArrayList(java.util.ArrayList) Facility(cz.metacentrum.perun.core.api.Facility)

Example 57 with WrongAttributeAssignmentException

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

the class AttributesManagerBlImpl method setAttributeWithoutCheck.

public boolean setAttributeWithoutCheck(PerunSession sess, User user, Attribute attribute) throws InternalErrorException, WrongAttributeAssignmentException, WrongAttributeValueException, WrongReferenceAttributeValueException {
    getAttributesManagerImpl().checkNamespace(sess, attribute, AttributesManager.NS_USER_ATTR);
    if (getAttributesManagerImpl().isCoreAttribute(sess, attribute))
        throw new WrongAttributeAssignmentException(attribute);
    boolean changed = true;
    if (isVirtAttribute(sess, attribute)) {
        return getAttributesManagerImpl().setVirtualAttribute(sess, user, attribute);
    } else {
        changed = getAttributesManagerImpl().setAttribute(sess, user, attribute);
    }
    if (changed) {
        getPerunBl().getAuditer().log(sess, "{} set for {}.", attribute, user);
        getAttributesManagerImpl().changedAttributeHook(sess, user, attribute);
    }
    return changed;
}
Also used : WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)

Example 58 with WrongAttributeAssignmentException

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

the class AttributesManagerBlImpl method setAttributeWithoutCheck.

public boolean setAttributeWithoutCheck(PerunSession sess, Resource resource, Group group, Attribute attribute) throws InternalErrorException, WrongAttributeAssignmentException, WrongAttributeValueException, WrongReferenceAttributeValueException {
    this.checkGroupIsFromTheSameVoLikeResource(sess, group, resource);
    getAttributesManagerImpl().checkNamespace(sess, attribute, AttributesManager.NS_GROUP_RESOURCE_ATTR);
    if (getAttributesManagerImpl().isCoreAttribute(sess, attribute))
        throw new WrongAttributeAssignmentException(attribute);
    boolean changed = true;
    if (isVirtAttribute(sess, attribute)) {
        //FIXME Zatim je zakazane nastavovani virtualnich atributu group_resource
        Attribute storedAttribute;
        try {
            storedAttribute = getAttribute(sess, resource, group, attribute.getName());
        } catch (AttributeNotExistsException ex) {
            throw new ConsistencyErrorException(ex);
        }
        if (!(storedAttribute.getValue() == null ? attribute.getValue() == null : storedAttribute.getValue().equals(attribute.getValue()))) {
            //FIXME
            if (attribute.getName().equals(AttributesManager.NS_GROUP_RESOURCE_ATTR_VIRT + ":unixGID") || attribute.getName().equals(AttributesManager.NS_GROUP_RESOURCE_ATTR_VIRT + ":unixGroupName")) {
                return getAttributesManagerImpl().setVirtualAttribute(sess, resource, group, attribute);
            } else {
                throw new InternalErrorException("Virtual attribute can't be set this way yet. Please set physical attribute. " + attribute);
            }
        } else {
            return false;
        }
    } else {
        changed = getAttributesManagerImpl().setAttribute(sess, resource, group, attribute);
    }
    if (changed) {
        getPerunBl().getAuditer().log(sess, "{} set for {} and {}.", attribute, group, resource);
        getAttributesManagerImpl().changedAttributeHook(sess, resource, group, attribute);
    }
    return changed;
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) 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 59 with WrongAttributeAssignmentException

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

the class AttributesManagerBlImpl method removeAllAttributes.

public void removeAllAttributes(PerunSession sess, Resource resource) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException {
    List<Attribute> attributes = getAttributes(sess, resource);
    getAttributesManagerImpl().removeAllAttributes(sess, resource);
    //remove all virtual attributes
    /*for(Attribute attribute : getVirtualAttributes(sess, resource)) {
			getAttributesManagerImpl().removeVirtualAttribute(sess, resource, attribute);
			}*/
    getPerunBl().getAuditer().log(sess, "All attributes removed for {}", resource);
    for (Attribute attribute : attributes) attribute.setValue(null);
    try {
        checkAttributesValue(sess, resource, attributes);
        this.checkAttributesDependencies(sess, resource, null, attributes);
    } catch (WrongAttributeAssignmentException ex) {
        throw new ConsistencyErrorException(ex);
    }
    for (Attribute attribute : attributes) {
        try {
            getAttributesManagerImpl().changedAttributeHook(sess, resource, new Attribute(attribute));
        } catch (WrongAttributeValueException ex) {
            //TODO better exception here
            throw new InternalErrorException(ex);
        } catch (WrongReferenceAttributeValueException ex) {
            //TODO better exception here
            throw new InternalErrorException(ex);
        }
    }
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)

Example 60 with WrongAttributeAssignmentException

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

the class AttributesManagerBlImpl method removeAttributeWithoutCheck.

public boolean removeAttributeWithoutCheck(PerunSession sess, Host host, AttributeDefinition attribute) throws InternalErrorException, WrongAttributeAssignmentException {
    getAttributesManagerImpl().checkNamespace(sess, attribute, AttributesManager.NS_HOST_ATTR);
    if (getAttributesManagerImpl().isCoreAttribute(sess, attribute))
        throw new WrongAttributeAssignmentException(attribute);
    boolean changed = getAttributesManagerImpl().removeAttribute(sess, host, attribute);
    if (changed) {
        //TODO HOOK FOR HOSTS!
        /*try {
				getAttributesManagerImpl().changedAttributeHook(sess, host, new Attribute(attribute));
				} catch (WrongAttributeValueException ex) {
			//TODO better exception here
			throw new InternalErrorException(ex);
			} catch (WrongReferenceAttributeValueException ex) {
			//TODO better exception here
			throw new InternalErrorException(ex);
			}*/
        getPerunBl().getAuditer().log(sess, "{} removed for {}", attribute, host);
    }
    return changed;
}
Also used : WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)

Aggregations

WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)127 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)97 Attribute (cz.metacentrum.perun.core.api.Attribute)95 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)61 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)59 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)55 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)52 RichAttribute (cz.metacentrum.perun.core.api.RichAttribute)42 User (cz.metacentrum.perun.core.api.User)31 ArrayList (java.util.ArrayList)31 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)14 Facility (cz.metacentrum.perun.core.api.Facility)14 LinkedHashMap (java.util.LinkedHashMap)11 Member (cz.metacentrum.perun.core.api.Member)10 Map (java.util.Map)9 Group (cz.metacentrum.perun.core.api.Group)8 List (java.util.List)8 Resource (cz.metacentrum.perun.core.api.Resource)7 Vo (cz.metacentrum.perun.core.api.Vo)6 HashMap (java.util.HashMap)6