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);
}
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));
}
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();
}
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());
}
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();
}
Aggregations