Search in sources :

Example 6 with RichAttribute

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

the class AttributesManagerEntryIntegrationTest method getRichAttributesWithHoldersForAttributeDefinitionGetGroupFromResourceAndMember.

@Test
public void getRichAttributesWithHoldersForAttributeDefinitionGetGroupFromResourceAndMember() throws Exception {
    System.out.println(CLASS_NAME + "getRichAttributesWithHoldersForAttributeDefinitionGetGroupFromResourceAndMember");
    //Prepare attribute, create it and set it with testing value
    Attribute attribute = setAttributeInNamespace(AttributesManager.NS_GROUP_ATTR);
    perun.getAttributesManagerBl().setAttribute(sess, group1InVo2, attribute);
    perun.getAttributesManagerBl().setAttribute(sess, group2InVo2, attribute);
    //Prepare richAttribute with holders (attribute is not needed but holders are needed)
    RichAttribute richAttr = new RichAttribute();
    richAttr.setPrimaryHolder(resource1InVo2);
    richAttr.setSecondaryHolder(member2OfUser1);
    List<RichAttribute> listOfRichAttributes = perun.getAttributesManagerBl().getRichAttributesWithHoldersForAttributeDefinition(sess, new AttributeDefinition(attribute), richAttr);
    assertTrue("Return no group.", listOfRichAttributes.size() == 0);
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 7 with RichAttribute

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

the class AttributesManagerEntryIntegrationTest method getRichAttributesWithHoldersForAttributeDefinitionGetVosFromFacility.

@Test
public void getRichAttributesWithHoldersForAttributeDefinitionGetVosFromFacility() throws Exception {
    System.out.println(CLASS_NAME + "getRichAttributesWithHoldersForAttributeDefinitionGetVosFromFacility");
    //Prepare attribute, create it and set it with testing value
    Attribute attribute = setAttributeInNamespace(AttributesManager.NS_VO_ATTR);
    perun.getAttributesManagerBl().setAttribute(sess, vo2, attribute);
    //Prepare richAttribute with holders (attribute is not needed but holders are needed)
    RichAttribute richAttr = new RichAttribute();
    richAttr.setPrimaryHolder(facility3);
    List<RichAttribute> listOfRichAttributes = perun.getAttributesManagerBl().getRichAttributesWithHoldersForAttributeDefinition(sess, new AttributeDefinition(attribute), richAttr);
    //Return facilities Administrator too if exists
    assertTrue("return at least 1 vos", listOfRichAttributes.size() >= 1);
    assertTrue("return max 2 vos", listOfRichAttributes.size() <= 2);
    assertTrue("primary holder is type of vo", listOfRichAttributes.get(0).getPrimaryHolder() instanceof Vo);
    assertTrue("secondary holder is null", listOfRichAttributes.get(0).getSecondaryHolder() == null);
    List<Vo> returnedVos = new ArrayList<Vo>();
    for (RichAttribute ra : listOfRichAttributes) {
        returnedVos.add((Vo) ra.getPrimaryHolder());
    }
    assertTrue("returned vos contains vo2", returnedVos.contains(vo2));
    assertTrue("returned vos not contains vo1", !returnedVos.contains(vo1));
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) ArrayList(java.util.ArrayList) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) Vo(cz.metacentrum.perun.core.api.Vo) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 8 with RichAttribute

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

the class AttributesManagerEntryIntegrationTest method getRichAttributesWithHoldersForAttributeDefinitionGetVosFromVo.

@Test
public void getRichAttributesWithHoldersForAttributeDefinitionGetVosFromVo() throws Exception {
    System.out.println(CLASS_NAME + "getRichAttributesWithHoldersForAttributeDefinitionGetVosFromVo");
    //Prepare attribute, create it and set it with testing value
    Attribute attribute = setAttributeInNamespace(AttributesManager.NS_VO_ATTR);
    perun.getAttributesManagerBl().setAttribute(sess, vo2, attribute);
    //Prepare richAttribute with holders (attribute is not needed but holders are needed)
    RichAttribute richAttr = new RichAttribute();
    richAttr.setPrimaryHolder(vo2);
    List<RichAttribute> listOfRichAttributes = perun.getAttributesManagerBl().getRichAttributesWithHoldersForAttributeDefinition(sess, new AttributeDefinition(attribute), richAttr);
    //Return facilities Administrator too if exists
    assertTrue("return 1 specific vo", listOfRichAttributes.size() == 1);
    assertTrue("primary holder is type of vo", listOfRichAttributes.get(0).getPrimaryHolder() instanceof Vo);
    assertTrue("secondary holder is null", listOfRichAttributes.get(0).getSecondaryHolder() == null);
    assertTrue("returned vos contains vo2", listOfRichAttributes.get(0).getPrimaryHolder().equals(vo2));
    assertTrue("attribute in richAttribute is equals to our attribute", (listOfRichAttributes.get(0).getAttribute()).equals(attribute));
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) Vo(cz.metacentrum.perun.core.api.Vo) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 9 with RichAttribute

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

the class AttributesManagerEntryIntegrationTest method getRichAttributesWithHoldersForAttributeDefinitionGetVosFromResourceAndMember.

@Test
public void getRichAttributesWithHoldersForAttributeDefinitionGetVosFromResourceAndMember() throws Exception {
    System.out.println(CLASS_NAME + "getRichAttributesWithHoldersForAttributeDefinitionGetVosFromResourceAndMember");
    //Prepare attribute, create it and set it with testing value
    Attribute attribute = setAttributeInNamespace(AttributesManager.NS_VO_ATTR);
    perun.getAttributesManagerBl().setAttribute(sess, vo1, attribute);
    //Prepare richAttribute with holders (attribute is not needed but holders are needed)
    RichAttribute richAttr = new RichAttribute<Resource, Member>(resource1InVo1, member1OfUser1, null);
    List<RichAttribute> listOfRichAttributes = perun.getAttributesManagerBl().getRichAttributesWithHoldersForAttributeDefinition(sess, new AttributeDefinition(attribute), richAttr);
    assertTrue("return only 1 vo", listOfRichAttributes.size() == 1);
    assertTrue("primary holder is type of vo", listOfRichAttributes.get(0).getPrimaryHolder() instanceof Vo);
    assertTrue("the Vo is vo1", vo1.equals(listOfRichAttributes.get(0).getPrimaryHolder()));
    assertTrue("secondary holder is null", listOfRichAttributes.get(0).getSecondaryHolder() == null);
    assertTrue("attribute in richAttribute is equals to our attribute", (listOfRichAttributes.get(0).getAttribute()).equals(attribute));
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) Vo(cz.metacentrum.perun.core.api.Vo) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 10 with RichAttribute

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

the class AttributesManagerBlImpl method setAttribute.

public void setAttribute(PerunSession sess, String key, Attribute attribute) throws InternalErrorException, WrongAttributeValueException, WrongAttributeAssignmentException, WrongReferenceAttributeValueException {
    if (attribute.getValue() == null) {
        removeAttribute(sess, key, attribute);
        return;
    }
    if (setAttributeWithoutCheck(sess, key, attribute)) {
        checkAttributeValue(sess, key, attribute);
        this.checkAttributeDependencies(sess, new RichAttribute(key, null, attribute));
    }
}
Also used : RichAttribute(cz.metacentrum.perun.core.api.RichAttribute)

Aggregations

RichAttribute (cz.metacentrum.perun.core.api.RichAttribute)42 Attribute (cz.metacentrum.perun.core.api.Attribute)29 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)14 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)14 Test (org.junit.Test)14 Vo (cz.metacentrum.perun.core.api.Vo)11 ArrayList (java.util.ArrayList)6 Group (cz.metacentrum.perun.core.api.Group)3 Facility (cz.metacentrum.perun.core.api.Facility)2 User (cz.metacentrum.perun.core.api.User)2 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)2 Host (cz.metacentrum.perun.core.api.Host)1 Member (cz.metacentrum.perun.core.api.Member)1 Resource (cz.metacentrum.perun.core.api.Resource)1 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)1 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)1 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)1 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)1 HashSet (java.util.HashSet)1 List (java.util.List)1