Search in sources :

Example 81 with RichAttribute

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

the class AttributesManagerBlImpl method getUserExtSourceAttributes.

/**
 * Returns RichAttributes for all userExtSource.
 * Each rich attribute is returned only once.
 *
 * @param sess    session
 * @param attrDef type of attribute that will be returned
 * @return List of RichAttribute
 */
private List<RichAttribute> getUserExtSourceAttributes(PerunSession sess, AttributeDefinition attrDef) throws AttributeNotExistsException, WrongAttributeAssignmentException {
    List<RichAttribute> listOfRichAttributes = new ArrayList<>();
    List<Facility> facilities = getPerunBl().getFacilitiesManagerBl().getFacilities(sess);
    for (Facility facilityElement : facilities) {
        listOfRichAttributes.addAll(getUserExtSourceAttributes(sess, facilityElement, attrDef));
    }
    listOfRichAttributes = new ArrayList<>(new HashSet<>(listOfRichAttributes));
    return listOfRichAttributes;
}
Also used : RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) ArrayList(java.util.ArrayList) AttributeRemovedForFacility(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeRemovedForFacility) Facility(cz.metacentrum.perun.core.api.Facility) AttributeSetForFacility(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeSetForFacility) HashSet(java.util.HashSet)

Example 82 with RichAttribute

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

the class AttributesManagerBlImpl method removeAttribute.

@Override
public void removeAttribute(PerunSession sess, Resource resource, Group group, AttributeDefinition attribute) throws WrongAttributeAssignmentException, WrongAttributeValueException, WrongReferenceAttributeValueException, GroupResourceMismatchException {
    if (removeAttributeWithoutCheck(sess, resource, group, attribute)) {
        checkAttributeSemantics(sess, resource, group, new Attribute(attribute));
        checkAttributeDependencies(sess, new RichAttribute<>(resource, group, new Attribute(attribute)));
    }
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute)

Example 83 with RichAttribute

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

the class AttributesManagerBlImpl method getUserAttributes.

// --------------------------------USER----------------------------------------
/**
 * Returns all relevant User RichAttributes for given user.
 * Finds attributes for given user directly.
 * Each rich attribute is returned only once.
 *
 * @param sess    session
 * @param user    user
 * @param attrDef type of attribute that will be returned
 * @return List of RichAttributes
 */
private List<RichAttribute> getUserAttributes(PerunSession sess, User user, AttributeDefinition attrDef) throws AttributeNotExistsException, WrongAttributeAssignmentException {
    List<RichAttribute> listOfRichAttributes = new ArrayList<>();
    Attribute attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, user, attrDef.getName());
    listOfRichAttributes.add(new RichAttribute<>(user, null, attribute));
    return listOfRichAttributes;
}
Also used : RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) ArrayList(java.util.ArrayList)

Example 84 with RichAttribute

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

the class AttributesManagerBlImpl method getUserAttributes.

/**
 * Returns RichAttributes for all users.
 * Finds all users. Returns theirs rich attributes.
 * Each rich attribute is returned only once.
 *
 * @param sess    session
 * @param attrDef type of attribute that will be returned
 * @return List of RichAttributes
 */
private List<RichAttribute> getUserAttributes(PerunSession sess, AttributeDefinition attrDef) throws AttributeNotExistsException, WrongAttributeAssignmentException {
    List<RichAttribute> listOfRichAttributes = new ArrayList<>();
    List<User> allUsers = getPerunBl().getUsersManagerBl().getUsers(sess);
    for (User userElement : allUsers) {
        listOfRichAttributes.addAll(getUserAttributes(sess, userElement, attrDef));
    }
    listOfRichAttributes = new ArrayList<>(new HashSet<>(listOfRichAttributes));
    return listOfRichAttributes;
}
Also used : 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) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 85 with RichAttribute

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

the class AttributesManagerEntryIntegrationTest method getGroupAttributesByFacility.

@SuppressWarnings({ "unchecked" })
@Test
public void getGroupAttributesByFacility() throws Exception {
    System.out.println(CLASS_NAME + "getGroupAttributesByFacility");
    setAttributesForGroupAttributesTest();
    Method testedMethod = getPrivateMethodFromAtrManager("getGroupAttributes", PerunSession.class, Facility.class, AttributeDefinition.class);
    // find email group attributes by facility1
    List<RichAttribute> ra_facility1 = (List<RichAttribute>) testedMethod.invoke(attributesManagerBl, sess, facility1, group_fromEmail_atr_def);
    List<Attribute> attrs_facility1 = new ArrayList<>();
    ra_facility1.forEach(ra -> attrs_facility1.add(ra.getAttribute()));
    assertEquals("Invalid number of attributes found", 2, attrs_facility1.size());
    assertTrue(attrs_facility1.contains(group1InVo1_email_atr));
    assertTrue(attrs_facility1.contains(group2InVo1_email_atr));
    // find email group attributes by facility2
    List<RichAttribute> ra_facility2 = (List<RichAttribute>) testedMethod.invoke(attributesManagerBl, sess, facility2, group_fromEmail_atr_def);
    List<Attribute> attrs_facility2 = new ArrayList<>();
    ra_facility2.forEach(ra -> attrs_facility2.add(ra.getAttribute()));
    assertEquals("Invalid number of attributes found", 3, attrs_facility2.size());
    assertTrue(attrs_facility2.contains(group2InVo1_email_atr));
    assertTrue(attrs_facility2.contains(group1InVo2_email_atr));
    assertTrue(attrs_facility2.contains(group2InVo2_email_atr));
}
Also used : RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Aggregations

RichAttribute (cz.metacentrum.perun.core.api.RichAttribute)321 ArrayList (java.util.ArrayList)284 Attribute (cz.metacentrum.perun.core.api.Attribute)220 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)154 Test (org.junit.Test)154 Method (java.lang.reflect.Method)140 List (java.util.List)140 HashSet (java.util.HashSet)94 AllAttributesRemovedForMember (cz.metacentrum.perun.audit.events.AttributesManagerEvents.AllAttributesRemovedForMember)34 AllAttributesRemovedForResourceAndMember (cz.metacentrum.perun.audit.events.AttributesManagerEvents.AllAttributesRemovedForResourceAndMember)34 AttributeRemovedForMember (cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeRemovedForMember)34 AttributeRemovedForResourceAndMember (cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeRemovedForResourceAndMember)34 AttributeSetForMember (cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeSetForMember)34 AttributeSetForResourceAndMember (cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeSetForResourceAndMember)34 Member (cz.metacentrum.perun.core.api.Member)34 AttributeRemovedForFacility (cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeRemovedForFacility)32 AttributeSetForFacility (cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeSetForFacility)32 Facility (cz.metacentrum.perun.core.api.Facility)32 AllAttributesRemovedForFacilityAndUser (cz.metacentrum.perun.audit.events.AttributesManagerEvents.AllAttributesRemovedForFacilityAndUser)31 AllAttributesRemovedForUser (cz.metacentrum.perun.audit.events.AttributesManagerEvents.AllAttributesRemovedForUser)31