Search in sources :

Example 96 with Attribute

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

the class ModulesUtilsBlImpl method findCollisionGroupsWithSamgeGroupGid.

public List<Group> findCollisionGroupsWithSamgeGroupGid(PerunSessionImpl sess, Resource resource, String namespace) throws WrongAttributeAssignmentException, AttributeNotExistsException {
    Utils.notNull(sess, "perunSessionImpl");
    Utils.notNull(resource, "resource");
    Utils.notNull(namespace, "namespace");
    Attribute resourceUnixGid = getPerunBl().getAttributesManagerBl().getAttribute(sess, resource, A_R_unixGID_namespace + ":" + namespace);
    Attribute copyGroupUnixGid = new Attribute(getPerunBl().getAttributesManagerBl().getAttributeDefinition(sess, A_G_unixGID_namespace + ":" + namespace));
    copyGroupUnixGid.setValue(resourceUnixGid.getValue());
    return getPerunBl().getGroupsManagerBl().getGroupsByAttribute(sess, copyGroupUnixGid);
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute)

Example 97 with Attribute

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

the class ServicesManagerEntryIntegrationTest method getHierarchicalDataWithoutExpiredMembers.

@Test
public void getHierarchicalDataWithoutExpiredMembers() throws Exception {
    System.out.println(CLASS_NAME + "getHierarchicalDataWithoutExpiredMembers");
    vo = setUpVo();
    facility = setUpFacility();
    resource = setUpResource();
    service = setUpService();
    member = setUpMember();
    Member member2 = setUpMember();
    group = setUpGroup();
    perun.getGroupsManager().addMember(sess, group, member);
    perun.getGroupsManager().addMember(sess, group, member2);
    perun.getResourcesManager().assignGroupToResource(sess, group, resource, false, false, false);
    perun.getGroupsManager().setMemberGroupStatus(sess, member2, group, MemberGroupStatus.EXPIRED);
    // set element's name/id as required attributes to get some attributes for every element
    Attribute reqFacAttr;
    reqFacAttr = perun.getAttributesManager().getAttribute(sess, facility, "urn:perun:facility:attribute-def:core:name");
    perun.getServicesManager().addRequiredAttribute(sess, service, reqFacAttr);
    Attribute reqResAttr;
    reqResAttr = perun.getAttributesManager().getAttribute(sess, resource, "urn:perun:resource:attribute-def:core:name");
    perun.getServicesManager().addRequiredAttribute(sess, service, reqResAttr);
    Attribute reqMemAttr;
    reqMemAttr = perun.getAttributesManager().getAttribute(sess, member, "urn:perun:member:attribute-def:core:id");
    perun.getServicesManager().addRequiredAttribute(sess, service, reqMemAttr);
    // finally assign service
    perun.getResourcesManager().assignService(sess, resource, service);
    List<ServiceAttributes> facilities = new ArrayList<ServiceAttributes>();
    facilities.add(perun.getServicesManager().getHierarchicalData(sess, service, facility, false));
    assertEquals(2, facilities.get(0).getChildElements().get(0).getChildElements().size());
    // return only one member because the other one is expired
    facilities = new ArrayList<>();
    facilities.add(perun.getServicesManager().getHierarchicalData(sess, service, facility, true));
    assertEquals(1, facilities.get(0).getChildElements().get(0).getChildElements().size());
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) ServiceAttributes(cz.metacentrum.perun.core.api.ServiceAttributes) ArrayList(java.util.ArrayList) Member(cz.metacentrum.perun.core.api.Member) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 98 with Attribute

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

the class ServicesManagerEntryIntegrationTest method getHierarchicalData.

@Test
public void getHierarchicalData() throws Exception {
    System.out.println(CLASS_NAME + "getHierarchicalData");
    vo = setUpVo();
    facility = setUpFacility();
    resource = setUpResource();
    service = setUpService();
    member = setUpMember();
    group = setUpGroup();
    perun.getGroupsManager().addMember(sess, group, member);
    perun.getResourcesManager().assignGroupToResource(sess, group, resource, false, false, false);
    // set element's name/id as required attributes to get some attributes for every element
    Attribute reqFacAttr;
    reqFacAttr = perun.getAttributesManager().getAttribute(sess, facility, "urn:perun:facility:attribute-def:core:name");
    perun.getServicesManager().addRequiredAttribute(sess, service, reqFacAttr);
    Attribute reqResAttr;
    reqResAttr = perun.getAttributesManager().getAttribute(sess, resource, "urn:perun:resource:attribute-def:core:name");
    perun.getServicesManager().addRequiredAttribute(sess, service, reqResAttr);
    Attribute reqMemAttr;
    reqMemAttr = perun.getAttributesManager().getAttribute(sess, member, "urn:perun:member:attribute-def:core:id");
    perun.getServicesManager().addRequiredAttribute(sess, service, reqMemAttr);
    // finally assign service
    perun.getResourcesManager().assignService(sess, resource, service);
    // create second (but same) resource
    resource.setName("HierarchDataResource");
    resource = perun.getResourcesManager().createResource(sess, resource, vo, facility);
    perun.getResourcesManager().assignGroupToResource(sess, group, resource, false, false, false);
    perun.getResourcesManager().assignService(sess, resource, service);
    // get it's required attribute with value for testing purpose
    Attribute reqResAttr2 = perun.getAttributesManager().getAttribute(sess, resource, "urn:perun:resource:attribute-def:core:name");
    // create third resource but without service
    resource.setName("HierarchDataResource2");
    resource = perun.getResourcesManager().createResource(sess, resource, vo, facility);
    // get it's required attribute with value for testing purpose
    Attribute reqResAttr3 = perun.getAttributesManager().getAttribute(sess, resource, "urn:perun:resource:attribute-def:core:name");
    /*
		 * expected returned structure is:
		 *
		 * facility(+attributes) - resource1(+attributes) - member(+attributes)
		 *                       - resource2(+attributes) - member(+attributes)
		 *                       - (third resource not returned = without service)
		 *
		 * etc...
		 *
		 */
    // get data for facility and service
    // = should be one node (facility)
    List<ServiceAttributes> facilities = new ArrayList<>();
    facilities.add(perun.getServicesManager().getHierarchicalData(sess, service, facility, false));
    assertNotNull("Unable to get hierarchical data", facilities);
    assertTrue("Only 1 facility shoud be returned", facilities.size() == 1);
    assertNotNull("returned facility shouldn't be null", facilities.get(0));
    // get all required facility attributes
    // = should be 1 required attribute for 1 facility
    List<Attribute> facAttr = facilities.get(0).getAttributes();
    assertNotNull("Unable to get facility attrbutes required by service", facAttr);
    assertTrue("Only 1 facility attribute should be returned", facAttr.size() == 1);
    assertTrue("Our facility required attribute not returned", facAttr.contains(reqFacAttr));
    // get all facility resources
    // = should be 2 resources for 1 facility (3rd resource is without proper service)
    List<ServiceAttributes> resources = facilities.get(0).getChildElements();
    assertNotNull("Unable to get facility resources", resources);
    assertTrue("Two resource should be returned", resources.size() == 2);
    assertNotNull("Our 1st resource shouldn't be null", resources.get(0));
    assertNotNull("Our 2nd resource shouldn't be null", resources.get(1));
    // get all required attributes for all resources on facility
    // should be 1 attribute per resource = total 2 for 2 resource
    List<Attribute> resAttr = resources.stream().map(ServiceAttributes::getAttributes).flatMap(List::stream).collect(Collectors.toList());
    assertNotNull("Unable to get required resource attrbutes", resAttr);
    assertTrue("Two required resource attributes should be returned for 2 resources", resAttr.size() == 2);
    assertTrue("Our 1st resource required attribute not returned", resAttr.contains(reqResAttr));
    assertTrue("Our 2nd resource required attribute not returned", resAttr.contains(reqResAttr2));
    assertFalse("Wrong resource returned with the others - resource without service", resAttr.contains(reqResAttr3));
    // get all members from all resources on facility
    // = we will get same attribute twice because member is on both resources
    List<ServiceAttributes> members = resources.stream().map(ServiceAttributes::getChildElements).flatMap(List::stream).collect(Collectors.toList());
    assertNotNull("Unable to get members from resource", members);
    assertTrue("There should be 1 member from each resource (all same)", members.size() == resources.size());
    assertNotNull("1st member shouldn't be null", members.get(0));
    assertNotNull("2nd member shouldn't be null", members.get(1));
    // get all required attributes for all members at all resources on facility
    // = there should be two same attributes, from same member on 2 resources
    List<Attribute> memAttr = members.stream().map(ServiceAttributes::getAttributes).flatMap(List::stream).collect(Collectors.toList());
    assertNotNull("Unable to get member attrbutes required for service", memAttr);
    assertTrue("Only one member attribute should be returned for each member", memAttr.size() == members.size());
    assertEquals("Wrong attribute returned for 1st member", memAttr.get(0), reqMemAttr);
    assertEquals("Wrong attribute returned for 2nd member", memAttr.get(1), reqMemAttr);
    assertEquals("Both attributes (members) should be same", memAttr.get(0), memAttr.get(1));
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) ServiceAttributes(cz.metacentrum.perun.core.api.ServiceAttributes) ArrayList(java.util.ArrayList) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 99 with Attribute

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

the class ServicesManagerEntryIntegrationTest method testGetHashedDataWithGroups.

@Test
public void testGetHashedDataWithGroups() throws Exception {
    System.out.println(CLASS_NAME + "testGetHashedDataWithGroups");
    vo = setUpVo();
    facility = setUpFacility();
    resource = setUpResource();
    service = setUpService();
    member = setUpMember();
    group = setUpGroup();
    perun.getGroupsManager().addMember(sess, group, member);
    perun.getResourcesManager().assignGroupToResource(sess, group, resource, false, false, false);
    // set element's name/id as required attributes to get some attributes for every element
    Attribute reqFacAttr;
    reqFacAttr = perun.getAttributesManager().getAttribute(sess, facility, A_F_C_NAME);
    perun.getServicesManager().addRequiredAttribute(sess, service, reqFacAttr);
    Attribute reqResAttr;
    reqResAttr = perun.getAttributesManager().getAttribute(sess, resource, A_R_C_NAME);
    perun.getServicesManager().addRequiredAttribute(sess, service, reqResAttr);
    Attribute reqGrpAttr;
    reqGrpAttr = perun.getAttributesManager().getAttribute(sess, group, A_G_C_NAME);
    perun.getServicesManager().addRequiredAttribute(sess, service, reqGrpAttr);
    Attribute reqMemAttr;
    reqMemAttr = perun.getAttributesManager().getAttribute(sess, member, A_M_C_ID);
    perun.getServicesManager().addRequiredAttribute(sess, service, reqMemAttr);
    Attribute reqVoAttr;
    reqVoAttr = perun.getAttributesManager().getAttribute(sess, vo, A_V_C_ID);
    perun.getServicesManager().addRequiredAttribute(sess, service, reqVoAttr);
    // finally assign service
    perun.getResourcesManager().assignService(sess, resource, service);
    // create second (but same) resource
    Resource resource2 = new Resource();
    resource2.setName("HierarchDataResource");
    resource2 = perun.getResourcesManager().createResource(sess, resource2, vo, facility);
    perun.getResourcesManager().assignGroupToResource(sess, group, resource2, false, false, false);
    perun.getResourcesManager().assignService(sess, resource2, service);
    // create third resource but without service
    Resource resource3 = new Resource();
    resource3.setName("HierarchDataResource2");
    resource3 = perun.getResourcesManager().createResource(sess, resource3, vo, facility);
    HashedGenData data = perun.getServicesManagerBl().getHashedDataWithGroups(sess, service, facility, false);
    assertThat(data.getAttributes()).isNotEmpty();
    Map<String, Map<String, Object>> attributes = data.getAttributes();
    String facilityAttrsHash = "f-" + facility.getId();
    String memberAttrsHash = "m-" + member.getId();
    String groupAttrsHash = "g-" + group.getId();
    String voAttrsHash = "v-" + vo.getId();
    String resource1AttrsHash = "r-" + resource.getId();
    String resource2AttrsHash = "r-" + resource2.getId();
    // Verify that the list of all attributes contains correct attributes
    assertThat(attributes).containsOnlyKeys(facilityAttrsHash, memberAttrsHash, resource1AttrsHash, groupAttrsHash, resource2AttrsHash, voAttrsHash);
    Map<String, Object> facilityAttributes = attributes.get(facilityAttrsHash);
    assertThat(facilityAttributes).hasSize(1);
    assertThat(facilityAttributes.get(A_F_C_NAME)).isEqualTo(facility.getName());
    Map<String, Object> memberAttributes = attributes.get(memberAttrsHash);
    assertThat(memberAttributes).hasSize(1);
    assertThat(memberAttributes.get(A_M_C_ID)).isEqualTo(member.getId());
    Map<String, Object> groupAttributes = attributes.get(groupAttrsHash);
    assertThat(groupAttributes).hasSize(1);
    assertThat(groupAttributes.get(A_G_C_NAME)).isEqualTo(group.getName());
    Map<String, Object> resource1Attributes = attributes.get(resource1AttrsHash);
    assertThat(resource1Attributes).hasSize(1);
    assertThat(resource1Attributes.get(A_R_C_NAME)).isEqualTo(resource.getName());
    Map<String, Object> voAttributes = attributes.get(voAttrsHash);
    assertThat(voAttributes).hasSize(1);
    assertThat(voAttributes.get(A_V_C_ID)).isEqualTo(vo.getId());
    Map<String, Object> resource2Attributes = attributes.get(resource2AttrsHash);
    assertThat(resource2Attributes).hasSize(1);
    assertThat(resource2Attributes.get(A_R_C_NAME)).isEqualTo(resource2.getName());
    // verify hierarchy
    GenDataNode facilityNode = data.getHierarchy().get(facility.getId());
    assertThat(facilityNode.getMembers()).hasSize(1);
    assertThat(facilityNode.getChildren()).hasSize(2);
    GenDataNode res1Node = facilityNode.getChildren().get(resource.getId());
    assertThat(res1Node.getMembers()).hasSize(1);
    assertThat(res1Node.getChildren()).hasSize(1);
    assertThat(((GenResourceDataNode) res1Node).getVoId()).isEqualTo(vo.getId());
    assertThat(res1Node.getMembers()).containsKey(member.getId());
    GenDataNode res2Node = facilityNode.getChildren().get(resource2.getId());
    assertThat(res2Node.getMembers()).hasSize(1);
    assertThat(res2Node.getChildren()).hasSize(1);
    assertThat(((GenResourceDataNode) res2Node).getVoId()).isEqualTo(vo.getId());
    assertThat(res2Node.getMembers()).containsKey(member.getId());
    GenDataNode res1GroupNode = res1Node.getChildren().get(group.getId());
    assertThat(res1GroupNode.getChildren()).isEmpty();
    assertThat(res1GroupNode.getMembers()).hasSize(1);
    assertThat(res1GroupNode.getMembers()).containsKey(member.getId());
    GenDataNode res2GroupNode = res2Node.getChildren().get(group.getId());
    assertThat(res2GroupNode.getChildren()).isEmpty();
    assertThat(res2GroupNode.getMembers()).hasSize(1);
    assertThat(res2GroupNode.getMembers()).containsKey(member.getId());
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) GenDataNode(cz.metacentrum.perun.core.api.GenDataNode) Resource(cz.metacentrum.perun.core.api.Resource) GenResourceDataNode(cz.metacentrum.perun.core.api.GenResourceDataNode) Map(java.util.Map) HashMap(java.util.HashMap) HashedGenData(cz.metacentrum.perun.core.api.HashedGenData) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 100 with Attribute

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

the class UsersManagerEntryIntegrationTest method removeUserExtSourceWithAttribute.

@Test(expected = UserExtSourceNotExistsException.class)
public void removeUserExtSourceWithAttribute() throws Exception {
    System.out.println(CLASS_NAME + "removeUserExtSourceWithAttribute");
    // Attribute 1
    String name = "testingUEAttribute1";
    Attribute userExtSourceAttribute1 = this.createUserExtSourceAttribute(name);
    userExtSourceAttribute1.setValue(name);
    perun.getAttributesManagerBl().setAttribute(sess, userExtSource, userExtSourceAttribute1);
    // Attribute 1
    name = "testingUEAttribute2";
    Attribute userExtSourceAttribute2 = this.createUserExtSourceAttribute(name);
    userExtSourceAttribute2.setValue(name);
    perun.getAttributesManagerBl().setAttribute(sess, userExtSource, userExtSourceAttribute2);
    usersManager.removeUserExtSource(sess, user, userExtSource);
    usersManager.getUserExtSourceById(sess, userExtSource.getId());
// shloudn't get removed user ext source from DB
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Aggregations

Attribute (cz.metacentrum.perun.core.api.Attribute)1689 Test (org.junit.Test)615 ArrayList (java.util.ArrayList)492 RichAttribute (cz.metacentrum.perun.core.api.RichAttribute)489 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)478 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)313 User (cz.metacentrum.perun.core.api.User)301 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)280 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)231 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)221 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)218 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)197 Facility (cz.metacentrum.perun.core.api.Facility)190 Resource (cz.metacentrum.perun.core.api.Resource)187 PerunSessionImpl (cz.metacentrum.perun.core.impl.PerunSessionImpl)180 List (java.util.List)177 LinkedHashMap (java.util.LinkedHashMap)158 Before (org.junit.Before)156 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)145 Method (java.lang.reflect.Method)140