Search in sources :

Example 6 with ServiceAttributes

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

the class ServicesManagerBlImpl method getData.

private ServiceAttributes getData(PerunSession sess, Service service, Facility facility, Resource resource) throws InternalErrorException {
    ServiceAttributes resourceServiceAttributes = new ServiceAttributes();
    resourceServiceAttributes.addAttributes(getPerunBl().getAttributesManagerBl().getRequiredAttributes(sess, service, resource));
    List<Member> members;
    members = getPerunBl().getResourcesManagerBl().getAllowedMembers(sess, resource);
    HashMap<Member, List<Attribute>> attributes;
    try {
        attributes = getPerunBl().getAttributesManagerBl().getRequiredAttributes(sess, service, facility, resource, members, true);
    } catch (WrongAttributeAssignmentException ex) {
        throw new InternalErrorException(ex);
    }
    for (Member mem : attributes.keySet()) {
        ServiceAttributes serviceAttributes = new ServiceAttributes();
        serviceAttributes.addAttributes(attributes.get(mem));
        resourceServiceAttributes.addChildElement(serviceAttributes);
    }
    return resourceServiceAttributes;
}
Also used : ServiceAttributes(cz.metacentrum.perun.core.api.ServiceAttributes) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) List(java.util.List) ArrayList(java.util.ArrayList) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) Member(cz.metacentrum.perun.core.api.Member)

Example 7 with ServiceAttributes

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

the class ServicesManagerBlImpl method getFlatData.

public ServiceAttributes getFlatData(PerunSession sess, Service service, Facility facility) throws InternalErrorException {
    ServiceAttributes serviceAttributes = new ServiceAttributes();
    serviceAttributes.addAttributes(getPerunBl().getAttributesManagerBl().getRequiredAttributes(sess, service, facility));
    ServiceAttributes allResourcesServiceAttributes = new ServiceAttributes();
    List<Resource> facilityResources = getPerunBl().getFacilitiesManagerBl().getAssignedResources(sess, facility);
    facilityResources.retainAll(getAssignedResources(sess, service));
    for (Resource resource : facilityResources) {
        ServiceAttributes resourceServiceAttributes = new ServiceAttributes();
        resourceServiceAttributes.addAttributes(getPerunBl().getAttributesManagerBl().getRequiredAttributes(sess, service, resource));
        allResourcesServiceAttributes.addChildElement(resourceServiceAttributes);
    }
    ServiceAttributes allUsersServiceAttributes = new ServiceAttributes();
    List<User> facilityUsers = getPerunBl().getFacilitiesManagerBl().getAllowedUsers(sess, facility, null, service);
    // get attributes for all users at once !
    HashMap<User, List<Attribute>> userFacilityAttributes = getPerunBl().getAttributesManagerBl().getRequiredAttributes(sess, service, facility, facilityUsers);
    HashMap<User, List<Attribute>> userAttributes = getPerunBl().getAttributesManagerBl().getRequiredAttributes(sess, service, facilityUsers);
    for (User user : facilityUsers) {
        ServiceAttributes userServiceAttributes = new ServiceAttributes();
        // Depending on a service requirements we might get null user or user-facility attributes
        if (userAttributes.get(user) != null)
            userServiceAttributes.addAttributes(userAttributes.get(user));
        if (userFacilityAttributes.get(user) != null)
            userServiceAttributes.addAttributes(userFacilityAttributes.get(user));
        allUsersServiceAttributes.addChildElement(userServiceAttributes);
    }
    serviceAttributes.addChildElement(allResourcesServiceAttributes);
    serviceAttributes.addChildElement(allUsersServiceAttributes);
    return serviceAttributes;
}
Also used : User(cz.metacentrum.perun.core.api.User) ServiceAttributes(cz.metacentrum.perun.core.api.ServiceAttributes) Resource(cz.metacentrum.perun.core.api.Resource) List(java.util.List) ArrayList(java.util.ArrayList)

Example 8 with ServiceAttributes

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

the class ServicesManagerBlImpl method getHierarchicalData.

public ServiceAttributes getHierarchicalData(PerunSession sess, Service service, Facility facility) throws InternalErrorException {
    ServiceAttributes serviceAttributes = new ServiceAttributes();
    serviceAttributes.addAttributes(getPerunBl().getAttributesManagerBl().getRequiredAttributes(sess, service, facility));
    List<Resource> resources = getPerunBl().getFacilitiesManagerBl().getAssignedResources(sess, facility);
    resources.retainAll(getAssignedResources(sess, service));
    for (Resource resource : resources) {
        ServiceAttributes resourceServiceAttributes = getData(sess, service, facility, resource);
        serviceAttributes.addChildElement(resourceServiceAttributes);
    }
    return serviceAttributes;
}
Also used : ServiceAttributes(cz.metacentrum.perun.core.api.ServiceAttributes) Resource(cz.metacentrum.perun.core.api.Resource)

Example 9 with ServiceAttributes

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

the class ServicesManagerBlImpl method getDataWithGroups.

private ServiceAttributes getDataWithGroups(PerunSession sess, Service service, Facility facility, Resource resource) throws InternalErrorException {
    ServiceAttributes resourceServiceAttributes = new ServiceAttributes();
    resourceServiceAttributes.addAttributes(getPerunBl().getAttributesManagerBl().getRequiredAttributes(sess, service, resource));
    //Add there also voRequiredAttributes for service
    try {
        Vo resourceVo = getPerunBl().getVosManagerBl().getVoById(sess, resource.getVoId());
        resourceServiceAttributes.addAttributes(getPerunBl().getAttributesManagerBl().getRequiredAttributes(sess, service, resourceVo));
    } catch (VoNotExistsException ex) {
        throw new ConsistencyErrorException("There is missing Vo for existing resource " + resource);
    }
    ServiceAttributes membersAbstractSA = new ServiceAttributes();
    Map<Member, ServiceAttributes> memberAttributes = new HashMap<Member, ServiceAttributes>();
    List<Member> members = getPerunBl().getResourcesManagerBl().getAllowedMembers(sess, resource);
    HashMap<Member, List<Attribute>> attributes;
    try {
        attributes = getPerunBl().getAttributesManagerBl().getRequiredAttributes(sess, service, facility, resource, members, true);
    } catch (WrongAttributeAssignmentException ex) {
        throw new InternalErrorException(ex);
    }
    for (Member mem : attributes.keySet()) {
        ServiceAttributes tmpAttributes = new ServiceAttributes();
        tmpAttributes.addAttributes(attributes.get(mem));
        memberAttributes.put(mem, tmpAttributes);
        membersAbstractSA.addChildElement(tmpAttributes);
    }
    ServiceAttributes groupsAbstractSA = new ServiceAttributes();
    List<Group> groups = getPerunBl().getResourcesManagerBl().getAssignedGroups(sess, resource);
    for (Group group : groups) {
        groupsAbstractSA.addChildElement(getData(sess, service, facility, resource, group, memberAttributes));
    }
    //assign abstract services attributes to resource service attributes
    resourceServiceAttributes.addChildElement(groupsAbstractSA);
    resourceServiceAttributes.addChildElement(membersAbstractSA);
    return resourceServiceAttributes;
}
Also used : Group(cz.metacentrum.perun.core.api.Group) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) HashMap(java.util.HashMap) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) VoNotExistsException(cz.metacentrum.perun.core.api.exceptions.VoNotExistsException) ServiceAttributes(cz.metacentrum.perun.core.api.ServiceAttributes) Vo(cz.metacentrum.perun.core.api.Vo) List(java.util.List) ArrayList(java.util.ArrayList) Member(cz.metacentrum.perun.core.api.Member)

Example 10 with ServiceAttributes

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

the class ServicesManagerBlImpl method getData.

private ServiceAttributes getData(PerunSession sess, Service service, Resource resource) throws InternalErrorException {
    ServiceAttributes resourceServiceAttributes = new ServiceAttributes();
    resourceServiceAttributes.addAttributes(getPerunBl().getAttributesManagerBl().getRequiredAttributes(sess, service, resource));
    List<Member> members;
    members = getPerunBl().getResourcesManagerBl().getAllowedMembers(sess, resource);
    HashMap<Member, List<Attribute>> attributes;
    try {
        attributes = getPerunBl().getAttributesManagerBl().getRequiredAttributes(sess, service, null, resource, members, true);
    } catch (WrongAttributeAssignmentException ex) {
        throw new InternalErrorException(ex);
    }
    for (Member mem : attributes.keySet()) {
        ServiceAttributes serviceAttributes = new ServiceAttributes();
        serviceAttributes.addAttributes(attributes.get(mem));
        resourceServiceAttributes.addChildElement(serviceAttributes);
    }
    return resourceServiceAttributes;
}
Also used : ServiceAttributes(cz.metacentrum.perun.core.api.ServiceAttributes) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) List(java.util.List) ArrayList(java.util.ArrayList) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) Member(cz.metacentrum.perun.core.api.Member)

Aggregations

ServiceAttributes (cz.metacentrum.perun.core.api.ServiceAttributes)12 ArrayList (java.util.ArrayList)7 Resource (cz.metacentrum.perun.core.api.Resource)5 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)5 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)5 Member (cz.metacentrum.perun.core.api.Member)4 List (java.util.List)4 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)2 Attribute (cz.metacentrum.perun.core.api.Attribute)2 Group (cz.metacentrum.perun.core.api.Group)2 User (cz.metacentrum.perun.core.api.User)2 Vo (cz.metacentrum.perun.core.api.Vo)2 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)2 Test (org.junit.Test)2 UserNotExistsException (cz.metacentrum.perun.core.api.exceptions.UserNotExistsException)1 VoNotExistsException (cz.metacentrum.perun.core.api.exceptions.VoNotExistsException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1