Search in sources :

Example 56 with Service

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

the class AttributesManagerEntry method getRequiredAttributes.

public List<Attribute> getRequiredAttributes(PerunSession sess, List<Service> services, Facility facility) throws PrivilegeException, InternalErrorException, FacilityNotExistsException, ServiceNotExistsException {
    Utils.checkPerunSession(sess);
    getPerunBl().getFacilitiesManagerBl().checkFacilityExists(sess, facility);
    Set<Attribute> attributes = new HashSet<Attribute>();
    // TODO & FIXME: there should be a proper select in BL & Impl
    for (Service s : services) {
        getPerunBl().getServicesManagerBl().checkServiceExists(sess, s);
        attributes.addAll(getAttributesManagerBl().getRequiredAttributes(sess, s, facility));
    }
    List<Attribute> result = new ArrayList<Attribute>();
    Iterator<Attribute> attrIter = attributes.iterator();
    //Choose to which attributes has the principal access
    while (attrIter.hasNext()) {
        Attribute attrNext = attrIter.next();
        if (AuthzResolver.isAuthorizedForAttribute(sess, ActionType.READ, attrNext, facility, null)) {
            // if allowed to read, add it to result
            attrNext.setWritable(AuthzResolver.isAuthorizedForAttribute(sess, ActionType.WRITE, attrNext, facility, null));
            result.add(attrNext);
        }
    }
    return result;
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) Service(cz.metacentrum.perun.core.api.Service)

Example 57 with Service

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

the class ServicesManagerImpl method getServicesFromServicesPackage.

public List<Service> getServicesFromServicesPackage(PerunSession sess, ServicesPackage servicesPackage) throws InternalErrorException {
    try {
        List<Service> services = new ArrayList<Service>();
        List<Integer> servicesId = jdbc.query("select service_id as id from service_service_packages where package_id=?", Utils.ID_MAPPER, servicesPackage.getId());
        for (Integer serviceId : servicesId) {
            try {
                services.add(getServiceById(sess, serviceId));
            } catch (ServiceNotExistsException ex) {
                throw new InternalErrorException(ex);
            }
        }
        return services;
    } catch (RuntimeException ex) {
        throw new InternalErrorException(ex);
    }
}
Also used : ServiceNotExistsException(cz.metacentrum.perun.core.api.exceptions.ServiceNotExistsException) ArrayList(java.util.ArrayList) Service(cz.metacentrum.perun.core.api.Service) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 58 with Service

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

the class ServicesManagerEntryIntegrationTest method createServiceWhenServiceNotExists.

@Test(expected = InternalErrorException.class)
public void createServiceWhenServiceNotExists() throws Exception {
    System.out.println(CLASS_NAME + "createServiceWhenServiceNotExists");
    perun.getServicesManager().createService(sess, new Service());
// shouldn't be able to create service in DB (InternalError) when it's not valid Service object
}
Also used : Service(cz.metacentrum.perun.core.api.Service) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 59 with Service

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

the class ServicesManagerEntryIntegrationTest method getDestinationsWithPerunSession.

@Test
public void getDestinationsWithPerunSession() throws Exception {
    System.out.println(CLASS_NAME + "getDestinations");
    Service service1 = setUpService();
    Facility facility1 = setUpFacility();
    Destination destination = setUpDestination();
    perun.getServicesManager().addDestination(sess, service1, facility1, destination);
    List<Destination> destinations = perun.getServicesManager().getDestinations(sess);
    assertTrue("there should be at least one destination", destinations.size() >= 1);
    assertTrue("our destination should be between all destinations", destinations.contains(destination));
}
Also used : Destination(cz.metacentrum.perun.core.api.Destination) RichDestination(cz.metacentrum.perun.core.api.RichDestination) Service(cz.metacentrum.perun.core.api.Service) Facility(cz.metacentrum.perun.core.api.Facility) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 60 with Service

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

the class ServicesManagerEntryIntegrationTest method getDestinationsWhenServiceNotExists.

@Test(expected = ServiceNotExistsException.class)
public void getDestinationsWhenServiceNotExists() throws Exception {
    System.out.println(CLASS_NAME + "getDestinationsWhenServiceNotExists");
    facility = setUpFacility();
    perun.getServicesManager().getDestinations(sess, new Service(), facility);
// shouldn't find Service
}
Also used : Service(cz.metacentrum.perun.core.api.Service) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Aggregations

Service (cz.metacentrum.perun.core.api.Service)66 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)44 Test (org.junit.Test)44 ArrayList (java.util.ArrayList)11 Facility (cz.metacentrum.perun.core.api.Facility)10 Destination (cz.metacentrum.perun.core.api.Destination)9 Member (cz.metacentrum.perun.core.api.Member)8 ExecService (cz.metacentrum.perun.taskslib.model.ExecService)8 User (cz.metacentrum.perun.core.api.User)6 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)6 Attribute (cz.metacentrum.perun.core.api.Attribute)5 BanOnFacility (cz.metacentrum.perun.core.api.BanOnFacility)5 Group (cz.metacentrum.perun.core.api.Group)5 Host (cz.metacentrum.perun.core.api.Host)5 Resource (cz.metacentrum.perun.core.api.Resource)5 RichDestination (cz.metacentrum.perun.core.api.RichDestination)5 RichUser (cz.metacentrum.perun.core.api.RichUser)5 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)4 PerunClient (cz.metacentrum.perun.core.api.PerunClient)4 PerunPrincipal (cz.metacentrum.perun.core.api.PerunPrincipal)4