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