Search in sources :

Example 1 with ServiceAssignedToResource

use of cz.metacentrum.perun.audit.events.ResourceManagerEvents.ServiceAssignedToResource in project perun by CESNET.

the class ResourcesManagerBlImpl method assignServices.

@Override
public void assignServices(PerunSession sess, Resource resource, List<Service> services) throws ServiceAlreadyAssignedException, WrongAttributeValueException, WrongReferenceAttributeValueException {
    for (Service service : services) {
        getResourcesManagerImpl().assignService(sess, resource, service);
        getPerunBl().getAuditer().log(sess, new ServiceAssignedToResource(service, resource));
    }
    boolean requiresAttributes = services.stream().anyMatch(s -> !getPerunBl().getAttributesManagerBl().getRequiredAttributesDefinition(sess, s).isEmpty());
    if (!requiresAttributes) {
        // there are new no attributes to check or add
        return;
    }
    try {
        fillAndSetRequiredAttributesForGroups(sess, services, resource);
        checkSemanticsOfFacilityAndResourceRequiredAttributes(sess, resource);
        updateAllRequiredAttributesForAllowedMembers(sess, resource, services);
    } catch (WrongAttributeAssignmentException | GroupResourceMismatchException | MemberResourceMismatchException | AttributeNotExistsException e) {
        throw new ConsistencyErrorException(e);
    }
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) MemberResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.MemberResourceMismatchException) ServiceAssignedToResource(cz.metacentrum.perun.audit.events.ResourceManagerEvents.ServiceAssignedToResource) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) Service(cz.metacentrum.perun.core.api.Service) GroupResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.GroupResourceMismatchException)

Example 2 with ServiceAssignedToResource

use of cz.metacentrum.perun.audit.events.ResourceManagerEvents.ServiceAssignedToResource in project perun by CESNET.

the class ResourcesManagerBlImplUnitTest method assignServices.

@Test
public void assignServices() throws Exception {
    System.out.println(CLASS_NAME + "assignServices");
    Resource resource = new Resource(1, "r1", "", -1);
    Service s1 = new Service(1, "s1");
    Service s2 = new Service(2, "s2");
    List<Service> services = Arrays.asList(s1, s2);
    doCallRealMethod().when(resourcesManagerBlMock).assignServices(sessionMock, resource, services);
    resourcesManagerBlMock.assignServices(sessionMock, resource, services);
    for (Service service : services) {
        verify(resourcesManagerImplMock, times(1)).assignService(sessionMock, resource, service);
        verify(auditerMock, times(1)).log(sessionMock, new ServiceAssignedToResource(service, resource));
    }
}
Also used : ServiceAssignedToResource(cz.metacentrum.perun.audit.events.ResourceManagerEvents.ServiceAssignedToResource) Resource(cz.metacentrum.perun.core.api.Resource) ServiceAssignedToResource(cz.metacentrum.perun.audit.events.ResourceManagerEvents.ServiceAssignedToResource) Service(cz.metacentrum.perun.core.api.Service) Test(org.junit.Test)

Aggregations

ServiceAssignedToResource (cz.metacentrum.perun.audit.events.ResourceManagerEvents.ServiceAssignedToResource)2 Service (cz.metacentrum.perun.core.api.Service)2 Resource (cz.metacentrum.perun.core.api.Resource)1 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)1 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)1 GroupResourceMismatchException (cz.metacentrum.perun.core.api.exceptions.GroupResourceMismatchException)1 MemberResourceMismatchException (cz.metacentrum.perun.core.api.exceptions.MemberResourceMismatchException)1 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)1 Test (org.junit.Test)1