Search in sources :

Example 1 with EnrichedResource

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

the class ResourcesManagerEntry method getEnrichedResourceById.

@Override
public EnrichedResource getEnrichedResourceById(PerunSession sess, int id, List<String> attrNames) throws PrivilegeException, ResourceNotExistsException {
    Utils.checkPerunSession(sess);
    EnrichedResource eResource = resourcesManagerBl.getEnrichedResourceById(sess, id, attrNames);
    // Authorization
    if (!AuthzResolver.authorizedInternal(sess, "getEnrichedResourceById_int_List<String>_policy", eResource.getResource())) {
        throw new PrivilegeException(sess, "getEnrichedResourceById");
    }
    return resourcesManagerBl.filterOnlyAllowedAttributes(sess, eResource);
}
Also used : EnrichedResource(cz.metacentrum.perun.core.api.EnrichedResource) PrivilegeException(cz.metacentrum.perun.core.api.exceptions.PrivilegeException)

Example 2 with EnrichedResource

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

the class ResourcesManagerEntryIntegrationTest method getAssignedResourcesForMemberWithStatus.

@Test
public void getAssignedResourcesForMemberWithStatus() throws Exception {
    System.out.println(CLASS_NAME + "getAssignedResourcesForMemberWithStatus");
    vo = setUpVo();
    member = setUpMember(vo);
    group = setUpGroup(vo, member);
    facility = setUpFacility();
    resource = setUpResource();
    Resource resource2 = setUpResource2();
    // both the resources assign to the group
    resourcesManager.assignGroupToResource(sess, group, resource, false, false, false);
    resourcesManager.assignGroupToResource(sess, group, resource2, false, false, false);
    AssignedResource resource1Active = new AssignedResource(new EnrichedResource(resource, null), GroupResourceStatus.ACTIVE, null, null, facility, false);
    AssignedResource resource2Active = new AssignedResource(new EnrichedResource(resource2, null), GroupResourceStatus.ACTIVE, null, null, facility, false);
    AssignedResource resource2Inactive = new AssignedResource(new EnrichedResource(resource2, null), GroupResourceStatus.INACTIVE, null, null, facility, false);
    List<AssignedResource> resources = resourcesManager.getAssignedResourcesWithStatus(sess, member);
    assertEquals("member should be assigned to 2 resources", 2, resources.size());
    assertTrue("assigned resources should be in returned list", resources.containsAll(List.of(resource1Active, resource2Active)));
    // deactivating group on resource should make the status inactive
    resourcesManager.deactivateGroupResourceAssignment(sess, group, resource2);
    resources = resourcesManager.getAssignedResourcesWithStatus(sess, member);
    assertEquals("member should be assigned to 2 resources", 2, resources.size());
    assertTrue("assigned resources should be in returned list", resources.containsAll(List.of(resource1Active, resource2Inactive)));
    // removing group should remove the resource
    resourcesManager.removeGroupFromResource(sess, group, resource2);
    resources = resourcesManager.getAssignedResourcesWithStatus(sess, member);
    assertEquals("member should be assigned to a single resources", 1, resources.size());
    assertTrue("assigned resource should be in returned list", resources.contains(resource1Active));
}
Also used : EnrichedResource(cz.metacentrum.perun.core.api.EnrichedResource) AssignedResource(cz.metacentrum.perun.core.api.AssignedResource) Resource(cz.metacentrum.perun.core.api.Resource) BanOnResource(cz.metacentrum.perun.core.api.BanOnResource) RichResource(cz.metacentrum.perun.core.api.RichResource) EnrichedResource(cz.metacentrum.perun.core.api.EnrichedResource) AssignedResource(cz.metacentrum.perun.core.api.AssignedResource) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 3 with EnrichedResource

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

the class ResourcesManagerEntryIntegrationTest method getEnrichedResourceByIdWithAllAttributes.

@Test
public void getEnrichedResourceByIdWithAllAttributes() throws Exception {
    System.out.println(CLASS_NAME + "getEnrichedResourceByIdWithAllAttributes");
    vo = setUpVo();
    facility = setUpFacility();
    Resource resource = setUpResource();
    EnrichedResource eResource = resourcesManager.getEnrichedResourceById(sess, resource.getId(), null);
    assertThat(eResource.getResource()).isEqualTo(resource);
    assertThat(eResource.getAttributes()).isNotEmpty();
}
Also used : EnrichedResource(cz.metacentrum.perun.core.api.EnrichedResource) AssignedResource(cz.metacentrum.perun.core.api.AssignedResource) Resource(cz.metacentrum.perun.core.api.Resource) BanOnResource(cz.metacentrum.perun.core.api.BanOnResource) RichResource(cz.metacentrum.perun.core.api.RichResource) EnrichedResource(cz.metacentrum.perun.core.api.EnrichedResource) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 4 with EnrichedResource

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

the class ResourcesManagerEntryIntegrationTest method getResourceAssignments.

@Test
public void getResourceAssignments() throws Exception {
    System.out.println(CLASS_NAME + "getResourceAssignments");
    vo = setUpVo();
    member = setUpMember(vo);
    group = setUpGroup(vo, member);
    facility = setUpFacility();
    resource = setUpResource();
    resourcesManager.assignGroupToResource(sess, group, resource, false, false, false);
    List<AssignedResource> resources = resourcesManager.getResourceAssignments(sess, group, null);
    AssignedResource expectedResource = new AssignedResource(new EnrichedResource(resource, null), GroupResourceStatus.ACTIVE, null, null, facility, false);
    assertThat(resources.size()).isEqualTo(1);
    assertThat(resources).containsExactly(expectedResource);
    assertThat(resources.get(0).getEnrichedResource().getAttributes()).containsExactlyInAnyOrderElementsOf(perun.getAttributesManager().getAttributes(sess, resource));
    assertThat(resources.get(0).getFacility().getName()).isEqualTo(facility.getName());
}
Also used : EnrichedResource(cz.metacentrum.perun.core.api.EnrichedResource) AssignedResource(cz.metacentrum.perun.core.api.AssignedResource) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 5 with EnrichedResource

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

the class ResourcesManagerEntryIntegrationTest method getEnrichedResourcesForVoWithAllAttributes.

@Test
public void getEnrichedResourcesForVoWithAllAttributes() throws Exception {
    System.out.println(CLASS_NAME + "getEnrichedResourcesForVoWithAllAttributes");
    vo = setUpVo();
    facility = setUpFacility();
    Resource resource = setUpResource();
    List<EnrichedResource> eResources = resourcesManager.getEnrichedResourcesForVo(sess, vo, null);
    assertThat(eResources).hasSize(1);
    assertThat(eResources.get(0).getResource()).isEqualTo(resource);
    assertThat(eResources.get(0).getAttributes()).isNotEmpty();
}
Also used : EnrichedResource(cz.metacentrum.perun.core.api.EnrichedResource) AssignedResource(cz.metacentrum.perun.core.api.AssignedResource) Resource(cz.metacentrum.perun.core.api.Resource) BanOnResource(cz.metacentrum.perun.core.api.BanOnResource) RichResource(cz.metacentrum.perun.core.api.RichResource) EnrichedResource(cz.metacentrum.perun.core.api.EnrichedResource) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Aggregations

EnrichedResource (cz.metacentrum.perun.core.api.EnrichedResource)8 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)7 AssignedResource (cz.metacentrum.perun.core.api.AssignedResource)7 Test (org.junit.Test)7 BanOnResource (cz.metacentrum.perun.core.api.BanOnResource)5 Resource (cz.metacentrum.perun.core.api.Resource)5 RichResource (cz.metacentrum.perun.core.api.RichResource)5 AssignedGroup (cz.metacentrum.perun.core.api.AssignedGroup)1 EnrichedGroup (cz.metacentrum.perun.core.api.EnrichedGroup)1 Group (cz.metacentrum.perun.core.api.Group)1 PrivilegeException (cz.metacentrum.perun.core.api.exceptions.PrivilegeException)1