Search in sources :

Example 16 with Attribute

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

the class AttributesManagerBlImpl method fillAttributes.

public List<Attribute> fillAttributes(PerunSession sess, Resource resource, Group group, List<Attribute> attributes) throws InternalErrorException, WrongAttributeAssignmentException {
    this.checkGroupIsFromTheSameVoLikeResource(sess, group, resource);
    getAttributesManagerImpl().checkNamespace(sess, attributes, AttributesManager.NS_GROUP_RESOURCE_ATTR);
    List<Attribute> filledAttributes = new ArrayList<Attribute>();
    for (Attribute attribute : attributes) {
        if (attribute.getValue() == null) {
            filledAttributes.add(getAttributesManagerImpl().fillAttribute(sess, resource, group, attribute));
        } else {
            //skip non-empty attribute
            filledAttributes.add(attribute);
        }
    }
    return filledAttributes;
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) ArrayList(java.util.ArrayList)

Example 17 with Attribute

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

the class AttributesManagerBlImpl method getAttributeById.

public Attribute getAttributeById(PerunSession sess, Facility facility, int id) throws InternalErrorException, AttributeNotExistsException, WrongAttributeAssignmentException {
    Attribute attribute = getAttributesManagerImpl().getAttributeById(sess, facility, id);
    getAttributesManagerImpl().checkNamespace(sess, attribute, NS_FACILITY_ATTR);
    return attribute;
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute)

Example 18 with Attribute

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

the class AttributesManagerBlImpl method removeAllAttributes.

public void removeAllAttributes(PerunSession sess, Host host) throws InternalErrorException, WrongAttributeValueException {
    List<Attribute> attributes = getAttributes(sess, host);
    getAttributesManagerImpl().removeAllAttributes(sess, host);
    getPerunBl().getAuditer().log(sess, "All attributes removed for {}", host);
    for (Attribute attribute : attributes) attribute.setValue(null);
    try {
        checkAttributesValue(sess, host, attributes);
        this.checkAttributesDependencies(sess, host, null, attributes);
    } catch (WrongAttributeAssignmentException ex) {
        throw new ConsistencyErrorException(ex);
    } catch (WrongReferenceAttributeValueException ex) {
        throw new WrongAttributeValueException(ex);
    }
//TODO HOOK FOR HOSTS
/*
			 for(Attribute attribute: attributes) {
			 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);
		}
		}*/
}
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) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)

Example 19 with Attribute

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

the class AttributesManagerBlImpl method fillAttributes.

public List<Attribute> fillAttributes(PerunSession sess, Group group, List<Attribute> groupReqAttributes) throws InternalErrorException, WrongAttributeAssignmentException {
    getAttributesManagerImpl().checkNamespace(sess, groupReqAttributes, AttributesManager.NS_GROUP_ATTR);
    List<Attribute> filledAttributes = new ArrayList<Attribute>();
    for (Attribute attribute : groupReqAttributes) {
        if (attribute.getValue() == null) {
            filledAttributes.add(getAttributesManagerImpl().fillAttribute(sess, group, attribute));
        } else {
            //skip non-empty attribute
            filledAttributes.add(attribute);
        }
    }
    return filledAttributes;
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) ArrayList(java.util.ArrayList)

Example 20 with Attribute

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

Aggregations

Attribute (cz.metacentrum.perun.core.api.Attribute)668 RichAttribute (cz.metacentrum.perun.core.api.RichAttribute)240 Test (org.junit.Test)178 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)157 ArrayList (java.util.ArrayList)150 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)134 User (cz.metacentrum.perun.core.api.User)131 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)121 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)121 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)110 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)102 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)101 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)96 Resource (cz.metacentrum.perun.core.api.Resource)82 Facility (cz.metacentrum.perun.core.api.Facility)79 Group (cz.metacentrum.perun.core.api.Group)34 PerunSession (cz.metacentrum.perun.core.api.PerunSession)33 LinkedHashMap (java.util.LinkedHashMap)24 PerunSessionImpl (cz.metacentrum.perun.core.impl.PerunSessionImpl)22 Vo (cz.metacentrum.perun.core.api.Vo)21