use of cz.metacentrum.perun.core.api.Vo in project perun by CESNET.
the class VosManagerEntry method getVoByShortName.
public Vo getVoByShortName(PerunSession sess, String shortName) throws VoNotExistsException, InternalErrorException, PrivilegeException {
Utils.notNull(shortName, "shortName");
Utils.notNull(sess, "sess");
Vo vo = vosManagerBl.getVoByShortName(sess, shortName);
// Authorization
if (!AuthzResolver.isAuthorized(sess, Role.VOADMIN, vo) && !AuthzResolver.isAuthorized(sess, Role.VOOBSERVER, vo) && !AuthzResolver.isAuthorized(sess, Role.GROUPADMIN, vo) && !AuthzResolver.isAuthorized(sess, Role.TOPGROUPCREATOR, vo) && !AuthzResolver.isAuthorized(sess, Role.ENGINE)) {
throw new PrivilegeException(sess, "getVoByShortName");
}
return vo;
}
use of cz.metacentrum.perun.core.api.Vo in project perun by CESNET.
the class VosManagerEntry method getVoById.
public Vo getVoById(PerunSession sess, int id) throws VoNotExistsException, InternalErrorException, PrivilegeException {
Utils.notNull(sess, "sess");
Vo vo = vosManagerBl.getVoById(sess, id);
// Authorization
if (!AuthzResolver.isAuthorized(sess, Role.VOADMIN, vo) && !AuthzResolver.isAuthorized(sess, Role.GROUPADMIN, vo) && !AuthzResolver.isAuthorized(sess, Role.VOOBSERVER, vo) && !AuthzResolver.isAuthorized(sess, Role.ENGINE) && !AuthzResolver.isAuthorized(sess, Role.RPC) && !AuthzResolver.isAuthorized(sess, Role.SELF)) {
throw new PrivilegeException(sess, "getVoById");
}
return vo;
}
use of cz.metacentrum.perun.core.api.Vo in project perun by CESNET.
the class urn_perun_resource_attribute_def_virt_voShortName method getAttributeValue.
public Attribute getAttributeValue(PerunSessionImpl sess, Resource resource, AttributeDefinition attributeDefinition) throws InternalErrorException {
Attribute attribute = new Attribute(attributeDefinition);
Vo vo = sess.getPerunBl().getResourcesManagerBl().getVo(sess, resource);
attribute.setValue(vo.getShortName());
return attribute;
}
use of cz.metacentrum.perun.core.api.Vo in project perun by CESNET.
the class AttributesManagerEntryIntegrationTest method getRichAttributesWithHoldersForAttributeDefinitionGetVosFromResource.
@Test
public void getRichAttributesWithHoldersForAttributeDefinitionGetVosFromResource() throws Exception {
System.out.println(CLASS_NAME + "getRichAttributesWithHoldersForAttributeDefinitionGetVosFromResource");
//Prepare attribute, create it and set it with testing value
Attribute attribute = setAttributeInNamespace(AttributesManager.NS_VO_ATTR);
perun.getAttributesManagerBl().setAttribute(sess, vo2, attribute);
//Prepare richAttribute with holders (attribute is not needed but holders are needed)
RichAttribute richAttr = new RichAttribute();
richAttr.setPrimaryHolder(resource2InVo2);
List<RichAttribute> listOfRichAttributes = perun.getAttributesManagerBl().getRichAttributesWithHoldersForAttributeDefinition(sess, new AttributeDefinition(attribute), richAttr);
assertTrue("return only 1 vo", listOfRichAttributes.size() == 1);
assertTrue("primary holder is type of vo", listOfRichAttributes.get(0).getPrimaryHolder() instanceof Vo);
assertTrue("secondary holder is null", listOfRichAttributes.get(0).getSecondaryHolder() == null);
assertTrue("the Vo is vo2", vo2.equals(listOfRichAttributes.get(0).getPrimaryHolder()));
assertTrue("attribute in richAttribute is equals to our attribute", (listOfRichAttributes.get(0).getAttribute()).equals(attribute));
}
use of cz.metacentrum.perun.core.api.Vo in project perun by CESNET.
the class AttributesManagerEntryIntegrationTest method getRichAttributesWithHoldersForAttributeDefinitionGetVosFromHost.
@Test
public void getRichAttributesWithHoldersForAttributeDefinitionGetVosFromHost() throws Exception {
System.out.println(CLASS_NAME + "getRichAttributesWithHoldersForAttributeDefinitionGetVosFromHost");
//Prepare attribute, create it and set it with testing value
Attribute attribute = setAttributeInNamespace(AttributesManager.NS_VO_ATTR);
perun.getAttributesManagerBl().setAttribute(sess, vo2, attribute);
perun.getAttributesManagerBl().setAttribute(sess, vo1, attribute);
//Prepare richAttribute with holders (attribute is not needed but holders are needed)
RichAttribute richAttr = new RichAttribute();
richAttr.setPrimaryHolder(host1OnFacility2);
List<RichAttribute> listOfRichAttributes = perun.getAttributesManagerBl().getRichAttributesWithHoldersForAttributeDefinition(sess, new AttributeDefinition(attribute), richAttr);
//Return facilities Administrator too if exists
assertTrue("return at least 2 vos", listOfRichAttributes.size() >= 2);
assertTrue("return maximum of 3 vos", listOfRichAttributes.size() <= 3);
assertTrue("primary holder is type of vo", listOfRichAttributes.get(0).getPrimaryHolder() instanceof Vo);
assertTrue("secondary holder is null", listOfRichAttributes.get(0).getSecondaryHolder() == null);
List<Vo> returnedVos = new ArrayList<Vo>();
for (RichAttribute ra : listOfRichAttributes) {
returnedVos.add((Vo) ra.getPrimaryHolder());
}
assertTrue("returned vos contains vo1", returnedVos.contains(vo1));
assertTrue("returned vos contains vo2", returnedVos.contains(vo2));
}
Aggregations