use of cz.metacentrum.perun.core.api.Resource in project perun by CESNET.
the class FacilitiesManagerBlImpl method getAllowedGroups.
public List<Group> getAllowedGroups(PerunSession perunSession, Facility facility, Vo specificVo, Service specificService) throws InternalErrorException {
//Get all facilities resources
List<Resource> facilityResources = getPerunBl().getFacilitiesManagerBl().getAssignedResources(perunSession, facility, specificVo, specificService);
//GetAll Groups for resulted Resources
Set<Group> allowedGroups = new HashSet<Group>();
for (Resource r : facilityResources) {
allowedGroups.addAll(getPerunBl().getResourcesManagerBl().getAssignedGroups(perunSession, r));
}
return new ArrayList<Group>(allowedGroups);
}
use of cz.metacentrum.perun.core.api.Resource in project perun by CESNET.
the class AttributesManagerBlImpl method isTrulyRequiredAttribute.
public boolean isTrulyRequiredAttribute(PerunSession sess, Member member, AttributeDefinition attributeDefinition) throws InternalErrorException, WrongAttributeAssignmentException {
this.checkNamespace(sess, attributeDefinition, NS_MEMBER_ATTR);
List<Resource> allowedResources = getPerunBl().getResourcesManagerBl().getAllowedResources(sess, member);
for (Resource resource : allowedResources) {
if (getAttributesManagerImpl().isAttributeRequiredByResource(sess, resource, attributeDefinition))
return true;
}
return false;
}
use of cz.metacentrum.perun.core.api.Resource in project perun by CESNET.
the class AttributesManagerBlImpl method getRichAttributesWithHoldersForAttributeDefinition.
public List<RichAttribute> getRichAttributesWithHoldersForAttributeDefinition(PerunSession sess, AttributeDefinition attrDef, RichAttribute aidingAttr) throws InternalErrorException, AttributeNotExistsException, VoNotExistsException, WrongAttributeAssignmentException, WrongAttributeValueException, WrongReferenceAttributeValueException {
//Filling objects from aidingAttr
if (aidingAttr == null)
throw new InternalErrorException("Aiding attribute cant be null.");
if (attrDef == null)
throw new InternalErrorException("attrDef cant be null.");
List<RichAttribute> listOfRichAttributes = new ArrayList<RichAttribute>();
//All possible useful objects
Vo vo = null;
Facility facility = null;
Group group = null;
Member member = null;
User user = null;
Host host = null;
Resource resource = null;
String key = null;
Attribute attribute = null;
//Get object for primaryHolder of aidingAttr
if (aidingAttr.getPrimaryHolder() != null) {
if (aidingAttr.getPrimaryHolder() instanceof Vo)
vo = (Vo) aidingAttr.getPrimaryHolder();
else if (aidingAttr.getPrimaryHolder() instanceof Facility)
facility = (Facility) aidingAttr.getPrimaryHolder();
else if (aidingAttr.getPrimaryHolder() instanceof Group)
group = (Group) aidingAttr.getPrimaryHolder();
else if (aidingAttr.getPrimaryHolder() instanceof Member)
member = (Member) aidingAttr.getPrimaryHolder();
else if (aidingAttr.getPrimaryHolder() instanceof User)
user = (User) aidingAttr.getPrimaryHolder();
else if (aidingAttr.getPrimaryHolder() instanceof Host)
host = (Host) aidingAttr.getPrimaryHolder();
else if (aidingAttr.getPrimaryHolder() instanceof Resource)
resource = (Resource) aidingAttr.getPrimaryHolder();
else if (aidingAttr.getPrimaryHolder() instanceof String)
key = (String) aidingAttr.getPrimaryHolder();
else {
throw new InternalErrorException("There is unrecognized object in primaryHolder of aidingAttr.");
}
} else {
throw new InternalErrorException("Aiding attribute must have primaryHolder which is not null.");
}
//Get object for secondaryHolder of aidingAttr
if (aidingAttr.getSecondaryHolder() != null) {
if (aidingAttr.getSecondaryHolder() instanceof Vo)
vo = (Vo) aidingAttr.getSecondaryHolder();
else if (aidingAttr.getSecondaryHolder() instanceof Facility)
facility = (Facility) aidingAttr.getSecondaryHolder();
else if (aidingAttr.getSecondaryHolder() instanceof Group)
group = (Group) aidingAttr.getSecondaryHolder();
else if (aidingAttr.getSecondaryHolder() instanceof Member)
member = (Member) aidingAttr.getSecondaryHolder();
else if (aidingAttr.getSecondaryHolder() instanceof User)
user = (User) aidingAttr.getSecondaryHolder();
else if (aidingAttr.getSecondaryHolder() instanceof Host)
host = (Host) aidingAttr.getSecondaryHolder();
else if (aidingAttr.getSecondaryHolder() instanceof Resource)
resource = (Resource) aidingAttr.getSecondaryHolder();
else if (aidingAttr.getSecondaryHolder() instanceof String)
key = (String) aidingAttr.getSecondaryHolder();
else {
throw new InternalErrorException("There is unrecognized object in secondaryHolder of aidingAttr");
}
}
if (getAttributesManagerImpl().isFromNamespace(sess, attrDef, NS_VO_ATTR)) {
//Second on the fact what i really have in aidingAttr i try to find what i am looking for
if (resource != null && member != null) {
if (!getPerunBl().getMembersManagerBl().haveStatus(sess, member, Status.INVALID)) {
vo = getPerunBl().getVosManagerBl().getVoById(sess, member.getVoId());
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, vo, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(vo, null, attribute));
}
} else if (group != null && resource != null) {
vo = getPerunBl().getVosManagerBl().getVoById(sess, group.getVoId());
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, vo, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(vo, null, attribute));
} else if (user != null && facility != null) {
List<Vo> vosFromUser = new ArrayList<Vo>();
List<Member> membersFromUser = getPerunBl().getMembersManagerBl().getMembersByUser(sess, user);
List<Resource> resourcesFromUser = new ArrayList<Resource>();
for (Member memberElement : membersFromUser) {
resourcesFromUser.addAll(getPerunBl().getResourcesManagerBl().getAllowedResources(sess, memberElement));
}
for (Resource resourceElement : resourcesFromUser) {
vosFromUser.add(getPerunBl().getResourcesManagerBl().getVo(sess, resourceElement));
}
List<Vo> vosFromFacility = getPerunBl().getFacilitiesManagerBl().getAllowedVos(sess, facility);
vosFromFacility.retainAll(vosFromUser);
vosFromFacility = new ArrayList<Vo>(new HashSet<Vo>(vosFromFacility));
for (Vo voElement : vosFromFacility) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, voElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(voElement, null, attribute));
}
} else if (member != null && group != null) {
vo = getPerunBl().getVosManagerBl().getVoById(sess, group.getVoId());
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, vo, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(vo, null, attribute));
} else if (group != null) {
vo = getPerunBl().getVosManagerBl().getVoById(sess, group.getVoId());
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, vo, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(vo, null, attribute));
} else if (member != null) {
if (!getPerunBl().getMembersManagerBl().haveStatus(sess, member, Status.INVALID)) {
vo = getPerunBl().getMembersManagerBl().getMemberVo(sess, member);
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, vo, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(vo, null, attribute));
}
} else if (resource != null) {
vo = getPerunBl().getVosManagerBl().getVoById(sess, resource.getVoId());
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, vo, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(vo, null, attribute));
} else if (user != null) {
List<Member> membersFromUser = getPerunBl().getMembersManagerBl().getMembersByUser(sess, user);
List<Vo> vosFromMembers = new ArrayList<Vo>();
for (Member memberElement : membersFromUser) {
if (!getPerunBl().getMembersManagerBl().haveStatus(sess, memberElement, Status.INVALID)) {
vosFromMembers.add(getPerunBl().getMembersManagerBl().getMemberVo(sess, memberElement));
}
}
for (Vo voElement : vosFromMembers) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, voElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(voElement, null, attribute));
}
} else if (host != null) {
facility = getPerunBl().getFacilitiesManagerBl().getFacilityForHost(sess, host);
List<Vo> vos = getPerunBl().getFacilitiesManagerBl().getAllowedVos(sess, facility);
for (Vo voElement : vos) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, voElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(voElement, null, attribute));
}
} else if (facility != null) {
List<Vo> vos = getPerunBl().getFacilitiesManagerBl().getAllowedVos(sess, facility);
for (Vo voElement : vos) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, voElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(voElement, null, attribute));
}
} else if (vo != null) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, vo, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(vo, null, attribute));
} else if (key != null) {
List<Vo> vos = getPerunBl().getVosManagerBl().getVos(sess);
for (Vo voElement : vos) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, voElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(voElement, null, attribute));
}
}
} else if (getAttributesManagerImpl().isFromNamespace(sess, attrDef, NS_GROUP_ATTR)) {
if (resource != null && member != null) {
if (!getPerunBl().getMembersManagerBl().haveStatus(sess, member, Status.INVALID)) {
List<Group> groupsFromResource = getPerunBl().getResourcesManagerBl().getAssignedGroups(sess, resource);
List<Group> groupsFromMember = getPerunBl().getGroupsManagerBl().getAllMemberGroups(sess, member);
groupsFromResource.retainAll(groupsFromMember);
groupsFromResource = new ArrayList<Group>(new HashSet<Group>(groupsFromResource));
for (Group groupElement : groupsFromResource) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, groupElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(groupElement, null, attribute));
}
}
} else if (group != null && resource != null) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, group, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(group, null, attribute));
} else if (user != null && facility != null) {
List<Member> members = getPerunBl().getMembersManagerBl().getMembersByUser(sess, user);
Set<Group> groupsFromMembers = new HashSet<Group>();
for (Member memberElement : members) {
if (!getPerunBl().getMembersManagerBl().haveStatus(sess, memberElement, Status.INVALID)) {
groupsFromMembers.addAll(getPerunBl().getGroupsManagerBl().getAllMemberGroups(sess, memberElement));
}
}
groupsFromMembers.retainAll(getPerunBl().getGroupsManagerBl().getAssignedGroupsToFacility(sess, facility));
for (Group groupElement : groupsFromMembers) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, groupElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(groupElement, null, attribute));
}
} else if (member != null && group != null) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, group, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(group, null, attribute));
} else if (group != null) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, group, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(group, null, attribute));
} else if (member != null) {
if (!getPerunBl().getMembersManagerBl().haveStatus(sess, member, Status.INVALID)) {
List<Group> groupsFromMember = getPerunBl().getGroupsManagerBl().getAllMemberGroups(sess, member);
for (Group groupElement : groupsFromMember) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, groupElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(groupElement, null, attribute));
}
}
} else if (resource != null) {
List<Group> groupsFromResource = getPerunBl().getResourcesManagerBl().getAssignedGroups(sess, resource);
for (Group groupElement : groupsFromResource) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, groupElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(groupElement, null, attribute));
}
} else if (user != null) {
List<Member> members = getPerunBl().getMembersManagerBl().getMembersByUser(sess, user);
List<Group> groupsFromMembers = new ArrayList<Group>();
for (Member memberElement : members) {
if (!getPerunBl().getMembersManagerBl().haveStatus(sess, memberElement, Status.INVALID)) {
groupsFromMembers.addAll(getPerunBl().getGroupsManagerBl().getAllMemberGroups(sess, memberElement));
}
}
groupsFromMembers = new ArrayList<Group>(new HashSet<Group>(groupsFromMembers));
for (Group groupElement : groupsFromMembers) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, groupElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(groupElement, null, attribute));
}
} else if (host != null) {
facility = getPerunBl().getFacilitiesManagerBl().getFacilityForHost(sess, host);
List<Group> groupsFromFacility = getPerunBl().getGroupsManagerBl().getAssignedGroupsToFacility(sess, facility);
for (Group groupElement : groupsFromFacility) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, groupElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(groupElement, null, attribute));
}
} else if (facility != null) {
List<Group> groupsFromFacility = getPerunBl().getGroupsManagerBl().getAssignedGroupsToFacility(sess, facility);
for (Group groupElement : groupsFromFacility) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, groupElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(groupElement, null, attribute));
}
} else if (vo != null) {
List<Group> groups = getPerunBl().getGroupsManagerBl().getAllGroups(sess, vo);
for (Group groupElement : groups) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, groupElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(groupElement, null, attribute));
}
} else if (key != null) {
List<Vo> vos = getPerunBl().getVosManagerBl().getVos(sess);
List<Group> groupsFromVos = new ArrayList<Group>();
for (Vo voElement : vos) {
groupsFromVos.addAll(getPerunBl().getGroupsManagerBl().getAllGroups(sess, voElement));
}
groupsFromVos = new ArrayList<Group>(new HashSet<Group>(groupsFromVos));
for (Group groupElement : groupsFromVos) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, groupElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(groupElement, null, attribute));
}
}
} else if (getAttributesManagerImpl().isFromNamespace(sess, attrDef, NS_FACILITY_ATTR)) {
if (resource != null && member != null) {
if (!getPerunBl().getMembersManagerBl().haveStatus(sess, member, Status.INVALID)) {
facility = getPerunBl().getResourcesManagerBl().getFacility(sess, resource);
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, facility, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(facility, null, attribute));
}
} else if (group != null && resource != null) {
facility = getPerunBl().getResourcesManagerBl().getFacility(sess, resource);
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, facility, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(facility, null, attribute));
} else if (user != null && facility != null) {
List<Facility> facilitiesFromUser = getPerunBl().getFacilitiesManagerBl().getAllowedFacilities(sess, user);
if (facilitiesFromUser.contains(facility)) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, facility, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(facility, null, attribute));
}
} else if (member != null && group != null) {
List<Resource> resources = getPerunBl().getResourcesManagerBl().getAssignedResources(sess, group);
List<Facility> facilitiesFromResources = new ArrayList<>();
for (Resource resourceElement : resources) {
facilitiesFromResources.add(getPerunBl().getResourcesManagerBl().getFacility(sess, resourceElement));
}
facilitiesFromResources = new ArrayList<>(new HashSet<>(facilitiesFromResources));
for (Facility facilityElement : facilitiesFromResources) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, facilityElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(facilityElement, null, attribute));
}
} else if (group != null) {
List<Resource> resources = getPerunBl().getResourcesManagerBl().getAssignedResources(sess, group);
List<Facility> facilitiesFromResources = new ArrayList<Facility>();
for (Resource resourceElemenet : resources) {
facilitiesFromResources.add(getPerunBl().getResourcesManagerBl().getFacility(sess, resourceElemenet));
}
facilitiesFromResources = new ArrayList<Facility>(new HashSet<Facility>(facilitiesFromResources));
for (Facility facilityElement : facilitiesFromResources) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, facilityElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(facilityElement, null, attribute));
}
} else if (member != null) {
if (!getPerunBl().getMembersManagerBl().haveStatus(sess, member, Status.INVALID)) {
List<Group> groupsForMember = getPerunBl().getGroupsManagerBl().getAllMemberGroups(sess, member);
List<Resource> resourcesFromMember = new ArrayList<Resource>();
for (Group groupElement : groupsForMember) {
resourcesFromMember.addAll(getPerunBl().getResourcesManagerBl().getAssignedResources(sess, groupElement));
}
resourcesFromMember = new ArrayList<Resource>(new HashSet<Resource>(resourcesFromMember));
for (Resource resourceElement : resourcesFromMember) {
Facility facilityFromMember = getPerunBl().getResourcesManagerBl().getFacility(sess, resourceElement);
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, facilityFromMember, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(facilityFromMember, null, attribute));
}
}
} else if (resource != null) {
facility = getPerunBl().getResourcesManagerBl().getFacility(sess, resource);
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, facility, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(facility, null, attribute));
} else if (user != null) {
List<Facility> facilities = getPerunBl().getFacilitiesManagerBl().getAllowedFacilities(sess, user);
for (Facility facilityElement : facilities) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, facilityElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(facilityElement, null, attribute));
}
} else if (host != null) {
facility = getPerunBl().getFacilitiesManagerBl().getFacilityForHost(sess, host);
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, facility, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(facility, null, attribute));
} else if (facility != null) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, facility, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(facility, null, attribute));
} else if (vo != null) {
List<Resource> resources = getPerunBl().getResourcesManagerBl().getResources(sess, vo);
List<Facility> facilitiesFromResources = new ArrayList<Facility>();
for (Resource resourceElemenet : resources) {
facilitiesFromResources.add(getPerunBl().getResourcesManagerBl().getFacility(sess, resourceElemenet));
}
facilitiesFromResources = new ArrayList<Facility>(new HashSet<Facility>(facilitiesFromResources));
for (Facility facilityElement : facilitiesFromResources) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, facilityElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(facilityElement, null, attribute));
}
} else if (key != null) {
List<Facility> facilities = getPerunBl().getFacilitiesManagerBl().getFacilities(sess);
for (Facility facilityElement : facilities) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, facilityElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(facilityElement, null, attribute));
}
}
} else if (getAttributesManagerImpl().isFromNamespace(sess, attrDef, NS_MEMBER_ATTR)) {
if (resource != null && member != null) {
if (!getPerunBl().getMembersManagerBl().haveStatus(sess, member, Status.INVALID)) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, member, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(member, null, attribute));
}
} else if (group != null && resource != null) {
List<Member> membersFromResource = getPerunBl().getResourcesManagerBl().getAllowedMembers(sess, resource);
List<Member> membersFromGroup = getPerunBl().getGroupsManagerBl().getGroupMembers(sess, group);
membersFromResource.retainAll(membersFromGroup);
membersFromResource = new ArrayList<Member>(new HashSet<Member>(membersFromResource));
for (Member memberElement : membersFromResource) {
if (!getPerunBl().getMembersManagerBl().haveStatus(sess, memberElement, Status.INVALID)) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, memberElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(memberElement, null, attribute));
}
}
} else if (user != null && facility != null) {
List<Member> membersFromUser = getPerunBl().getMembersManagerBl().getMembersByUser(sess, user);
List<Member> membersFromFacility = getPerunBl().getFacilitiesManagerBl().getAllowedMembers(sess, facility);
membersFromUser.retainAll(membersFromFacility);
membersFromUser = new ArrayList<Member>(new HashSet<Member>(membersFromUser));
for (Member memberElement : membersFromUser) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, memberElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(memberElement, null, attribute));
}
} else if (member != null && group != null) {
if (!getPerunBl().getMembersManagerBl().haveStatus(sess, member, Status.INVALID)) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, member, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(member, null, attribute));
}
} else if (group != null) {
List<Member> membersFromGroup = getPerunBl().getGroupsManagerBl().getGroupMembers(sess, group);
for (Member memberElement : membersFromGroup) {
if (!getPerunBl().getMembersManagerBl().haveStatus(sess, memberElement, Status.INVALID)) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, memberElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(memberElement, null, attribute));
}
}
} else if (member != null) {
if (!getPerunBl().getMembersManagerBl().haveStatus(sess, member, Status.INVALID)) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, member, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(member, null, attribute));
}
} else if (resource != null) {
List<Member> membersFromResource = getPerunBl().getResourcesManagerBl().getAllowedMembers(sess, resource);
for (Member memberElement : membersFromResource) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, memberElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(memberElement, null, attribute));
}
} else if (user != null) {
List<Member> membersFromUser = getPerunBl().getMembersManagerBl().getMembersByUser(sess, user);
for (Member memberElement : membersFromUser) {
if (!getPerunBl().getMembersManagerBl().haveStatus(sess, memberElement, Status.INVALID)) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, memberElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(memberElement, null, attribute));
}
}
} else if (host != null) {
facility = getPerunBl().getFacilitiesManagerBl().getFacilityForHost(sess, host);
List<Member> membersFromHost = getPerunBl().getFacilitiesManagerBl().getAllowedMembers(sess, facility);
for (Member memberElement : membersFromHost) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, memberElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(memberElement, null, attribute));
}
} else if (facility != null) {
List<Member> membersFromFacility = getPerunBl().getFacilitiesManagerBl().getAllowedMembers(sess, facility);
for (Member memberElement : membersFromFacility) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, memberElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(memberElement, null, attribute));
}
} else if (vo != null) {
List<Member> membersFromVo = getPerunBl().getMembersManagerBl().getMembers(sess, vo);
for (Member memberElement : membersFromVo) {
if (!getPerunBl().getMembersManagerBl().haveStatus(sess, memberElement, Status.INVALID)) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, memberElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(memberElement, null, attribute));
}
}
} else if (key != null) {
List<Vo> vos = getPerunBl().getVosManagerBl().getVos(sess);
List<Member> allMembers = new ArrayList<Member>();
for (Vo voElement : vos) {
allMembers.addAll(getPerunBl().getMembersManagerBl().getMembers(sess, voElement));
}
allMembers = new ArrayList<Member>(new HashSet<Member>(allMembers));
for (Member memberElement : allMembers) {
if (!getPerunBl().getMembersManagerBl().haveStatus(sess, memberElement, Status.INVALID)) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, memberElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(memberElement, null, attribute));
}
}
}
} else if (getAttributesManagerImpl().isFromNamespace(sess, attrDef, NS_RESOURCE_ATTR)) {
if (resource != null && member != null) {
if (!getPerunBl().getMembersManagerBl().haveStatus(sess, member, Status.INVALID)) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, resource, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(resource, null, attribute));
}
} else if (group != null && resource != null) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, resource, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(resource, null, attribute));
} else if (user != null && facility != null) {
List<Member> members = getPerunBl().getMembersManagerBl().getMembersByUser(sess, user);
List<Resource> resourcesFromUser = new ArrayList<Resource>();
for (Member memberElement : members) {
if (!getPerunBl().getMembersManagerBl().haveStatus(sess, memberElement, Status.INVALID)) {
resourcesFromUser.addAll(getPerunBl().getResourcesManagerBl().getAllowedResources(sess, memberElement));
}
}
List<Resource> resourcesFromFacility = getPerunBl().getFacilitiesManagerBl().getAssignedResources(sess, facility);
resourcesFromUser.retainAll(resourcesFromFacility);
resourcesFromUser = new ArrayList<Resource>(new HashSet<Resource>(resourcesFromUser));
for (Resource resourceElement : resourcesFromUser) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, resourceElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(resourceElement, null, attribute));
}
} else if (member != null && group != null) {
List<Resource> resourcesFromGroup = new ArrayList<>(new HashSet<>(getPerunBl().getResourcesManagerBl().getAssignedResources(sess, group)));
for (Resource resourceElement : resourcesFromGroup) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, resourceElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(resourceElement, null, attribute));
}
} else if (group != null) {
List<Resource> resourcesFromGroup = getPerunBl().getResourcesManagerBl().getAssignedResources(sess, group);
for (Resource resourceElement : resourcesFromGroup) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, resourceElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(resourceElement, null, attribute));
}
} else if (member != null) {
if (!getPerunBl().getMembersManagerBl().haveStatus(sess, member, Status.INVALID)) {
List<Resource> resourcesFromMember = getPerunBl().getResourcesManagerBl().getAllowedResources(sess, member);
for (Resource resourceElement : resourcesFromMember) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, resourceElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(resourceElement, null, attribute));
}
}
} else if (resource != null) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, resource, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(resource, null, attribute));
} else if (user != null) {
List<Member> members = getPerunBl().getMembersManagerBl().getMembersByUser(sess, user);
List<Resource> resourcesFromUser = new ArrayList<Resource>();
for (Member memberElement : members) {
if (!getPerunBl().getMembersManagerBl().haveStatus(sess, memberElement, Status.INVALID)) {
resourcesFromUser.addAll(getPerunBl().getResourcesManagerBl().getAllowedResources(sess, memberElement));
}
}
resourcesFromUser = new ArrayList<Resource>(new HashSet<Resource>(resourcesFromUser));
for (Resource resourceElement : resourcesFromUser) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, resourceElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(resourceElement, null, attribute));
}
} else if (host != null) {
facility = getPerunBl().getFacilitiesManagerBl().getFacilityForHost(sess, host);
List<Resource> resourcesFromFacility = getPerunBl().getFacilitiesManagerBl().getAssignedResources(sess, facility);
for (Resource resourceElement : resourcesFromFacility) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, resourceElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(resourceElement, null, attribute));
}
} else if (facility != null) {
List<Resource> resourcesFromFacility = getPerunBl().getFacilitiesManagerBl().getAssignedResources(sess, facility);
for (Resource resourceElement : resourcesFromFacility) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, resourceElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(resourceElement, null, attribute));
}
} else if (vo != null) {
List<Resource> resourcesFromVo = getPerunBl().getResourcesManagerBl().getResources(sess, vo);
for (Resource resourceElement : resourcesFromVo) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, resourceElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(resourceElement, null, attribute));
}
} else if (key != null) {
List<Vo> vos = getPerunBl().getVosManagerBl().getVos(sess);
List<Resource> allResources = new ArrayList<Resource>();
for (Vo voElement : vos) {
allResources.addAll(getPerunBl().getResourcesManagerBl().getResources(sess, voElement));
}
allResources = new ArrayList<Resource>(new HashSet<Resource>(allResources));
for (Resource resourceElement : allResources) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, resourceElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(resourceElement, null, attribute));
}
}
} else if (getAttributesManagerImpl().isFromNamespace(sess, attrDef, NS_USER_ATTR)) {
if (resource != null && member != null) {
if (!getPerunBl().getMembersManagerBl().haveStatus(sess, member, Status.INVALID)) {
user = getPerunBl().getUsersManagerBl().getUserByMember(sess, member);
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, user, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(user, null, attribute));
}
} else if (group != null && resource != null) {
List<Member> members = getPerunBl().getGroupsManagerBl().getGroupMembers(sess, group);
List<Member> membersFromResource = getPerunBl().getResourcesManagerBl().getAllowedMembers(sess, resource);
members.retainAll(membersFromResource);
List<User> usersFromGroup = new ArrayList<User>();
for (Member memberElement : members) {
usersFromGroup.add(getPerunBl().getUsersManagerBl().getUserByMember(sess, memberElement));
}
usersFromGroup = new ArrayList<User>(new HashSet<User>(usersFromGroup));
for (User userElement : usersFromGroup) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, userElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(userElement, null, attribute));
}
} else if (user != null && facility != null) {
List<Facility> facilitiesFromUser = getPerunBl().getFacilitiesManagerBl().getAllowedFacilities(sess, user);
if (facilitiesFromUser.contains(user)) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, user, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(user, null, attribute));
}
} else if (member != null && group != null) {
if (!getPerunBl().getMembersManagerBl().haveStatus(sess, member, Status.INVALID)) {
user = getPerunBl().getUsersManagerBl().getUserByMember(sess, member);
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, user, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(user, null, attribute));
}
} else if (group != null) {
List<Member> members = getPerunBl().getGroupsManagerBl().getGroupMembers(sess, group);
List<User> usersFromGroup = new ArrayList<User>();
for (Member memberElement : members) {
if (!getPerunBl().getMembersManagerBl().haveStatus(sess, memberElement, Status.INVALID)) {
usersFromGroup.add(getPerunBl().getUsersManagerBl().getUserByMember(sess, memberElement));
}
}
usersFromGroup = new ArrayList<User>(new HashSet<User>(usersFromGroup));
for (User userElement : usersFromGroup) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, userElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(userElement, null, attribute));
}
} else if (member != null) {
if (!getPerunBl().getMembersManagerBl().haveStatus(sess, member, Status.INVALID)) {
user = getPerunBl().getUsersManagerBl().getUserByMember(sess, member);
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, user, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(user, null, attribute));
}
} else if (resource != null) {
List<User> usersFromResource = getPerunBl().getResourcesManagerBl().getAllowedUsers(sess, resource);
for (User userElement : usersFromResource) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, userElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(userElement, null, attribute));
}
} else if (user != null) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, user, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(user, null, attribute));
} else if (host != null) {
facility = getPerunBl().getFacilitiesManagerBl().getFacilityForHost(sess, host);
List<User> usersFromHost = getPerunBl().getFacilitiesManagerBl().getAllowedUsers(sess, facility);
for (User userElement : usersFromHost) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, userElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(userElement, null, attribute));
}
} else if (facility != null) {
List<User> usersFromFacility = getPerunBl().getFacilitiesManagerBl().getAllowedUsers(sess, facility);
for (User userElement : usersFromFacility) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, userElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(userElement, null, attribute));
}
} else if (vo != null) {
List<Member> members = getPerunBl().getMembersManagerBl().getMembers(sess, vo);
List<User> usersFromVo = new ArrayList<User>();
for (Member memberElement : members) {
if (!getPerunBl().getMembersManagerBl().haveStatus(sess, memberElement, Status.INVALID)) {
usersFromVo.add(getPerunBl().getUsersManagerBl().getUserByMember(sess, memberElement));
}
}
usersFromVo = new ArrayList<User>(new HashSet<User>(usersFromVo));
for (User userElement : usersFromVo) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, userElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(userElement, null, attribute));
}
} else if (key != null) {
List<User> allUsers = getPerunBl().getUsersManagerBl().getUsers(sess);
for (User userElement : allUsers) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, userElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(userElement, null, attribute));
}
}
} else if (getAttributesManagerImpl().isFromNamespace(sess, attrDef, AttributesManager.NS_HOST_ATTR)) {
if (resource != null && member != null) {
if (!getPerunBl().getMembersManagerBl().haveStatus(sess, member, Status.INVALID)) {
facility = getPerunBl().getResourcesManagerBl().getFacility(sess, resource);
List<Host> hostsFromResource = getPerunBl().getFacilitiesManagerBl().getHosts(sess, facility);
for (Host hostElement : hostsFromResource) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, hostElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(hostElement, null, attribute));
}
}
} else if (group != null && resource != null) {
facility = getPerunBl().getResourcesManagerBl().getFacility(sess, resource);
List<Host> hostsFromResource = getPerunBl().getFacilitiesManagerBl().getHosts(sess, facility);
for (Host hostElement : hostsFromResource) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, hostElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(hostElement, null, attribute));
}
} else if (user != null && facility != null) {
if (getPerunBl().getFacilitiesManagerBl().getAllowedFacilities(sess, user).contains(facility)) {
List<Host> hostsFromFacility = getPerunBl().getFacilitiesManagerBl().getHosts(sess, facility);
for (Host hostElement : hostsFromFacility) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, hostElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(hostElement, null, attribute));
}
}
} else if (member != null && group != null) {
List<Resource> resourcesFromGroup = getPerunBl().getResourcesManagerBl().getAssignedResources(sess, group);
List<Facility> facilitiesFromResources = new ArrayList<>();
for (Resource resourceElement : resourcesFromGroup) {
facilitiesFromResources.add(getPerunBl().getResourcesManagerBl().getFacility(sess, resourceElement));
}
facilitiesFromResources = new ArrayList<>(new HashSet<>(facilitiesFromResources));
List<Host> hostsFromFacilities = new ArrayList<>();
for (Facility facilityElement : facilitiesFromResources) {
hostsFromFacilities.addAll(getPerunBl().getFacilitiesManagerBl().getHosts(sess, facilityElement));
}
for (Host hostElement : hostsFromFacilities) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, hostElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(hostElement, null, attribute));
}
} else if (group != null) {
List<Resource> resources = getPerunBl().getResourcesManagerBl().getAssignedResources(sess, group);
List<Facility> facilities = new ArrayList<Facility>();
for (Resource resourceElement : resources) {
facilities.add(getPerunBl().getResourcesManagerBl().getFacility(sess, resourceElement));
}
List<Host> hostsFromGroup = new ArrayList<Host>();
for (Facility facilityElement : facilities) {
hostsFromGroup.addAll(getPerunBl().getFacilitiesManagerBl().getHosts(sess, facilityElement));
}
hostsFromGroup = new ArrayList<Host>(new HashSet<Host>(hostsFromGroup));
for (Host hostElement : hostsFromGroup) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, hostElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(hostElement, null, attribute));
}
} else if (member != null) {
if (!getPerunBl().getMembersManagerBl().haveStatus(sess, member, Status.INVALID)) {
List<Resource> resources = getPerunBl().getResourcesManagerBl().getAllowedResources(sess, member);
List<Facility> facilities = new ArrayList<Facility>();
for (Resource resourceElement : resources) {
facilities.add(getPerunBl().getResourcesManagerBl().getFacility(sess, resourceElement));
}
List<Host> hostsFromMembers = new ArrayList<Host>();
for (Facility facilityElement : facilities) {
hostsFromMembers.addAll(getPerunBl().getFacilitiesManagerBl().getHosts(sess, facilityElement));
}
hostsFromMembers = new ArrayList<Host>(new HashSet<Host>(hostsFromMembers));
for (Host hostElement : hostsFromMembers) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, hostElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(hostElement, null, attribute));
}
}
} else if (resource != null) {
facility = getPerunBl().getResourcesManagerBl().getFacility(sess, resource);
List<Host> hostsFromResource = getPerunBl().getFacilitiesManagerBl().getHosts(sess, facility);
for (Host hostElement : hostsFromResource) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, hostElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(hostElement, null, attribute));
}
} else if (user != null) {
List<Facility> facilities = getPerunBl().getFacilitiesManagerBl().getAllowedFacilities(sess, user);
List<Host> hostsFromUser = new ArrayList<Host>();
for (Facility facilityElement : facilities) {
hostsFromUser.addAll(getPerunBl().getFacilitiesManagerBl().getHosts(sess, facilityElement));
}
hostsFromUser = new ArrayList<Host>(new HashSet<Host>(hostsFromUser));
for (Host hostElement : hostsFromUser) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, hostElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(hostElement, null, attribute));
}
} else if (host != null) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, host, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(host, null, attribute));
} else if (facility != null) {
List<Host> hostsFromFacility = getPerunBl().getFacilitiesManagerBl().getHosts(sess, facility);
for (Host hostElement : hostsFromFacility) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, hostElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(hostElement, null, attribute));
}
} else if (vo != null) {
List<Resource> resources = getPerunBl().getResourcesManagerBl().getResources(sess, vo);
List<Facility> facilities = new ArrayList<Facility>();
for (Resource resourceElement : resources) {
facilities.add(getPerunBl().getResourcesManagerBl().getFacility(sess, resourceElement));
}
List<Host> hostsFromVo = new ArrayList<Host>();
for (Facility facilityElement : facilities) {
hostsFromVo.addAll(getPerunBl().getFacilitiesManagerBl().getHosts(sess, facilityElement));
}
hostsFromVo = new ArrayList<Host>(new HashSet<Host>(hostsFromVo));
for (Host hostElement : hostsFromVo) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, hostElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(hostElement, null, attribute));
}
} else if (key != null) {
List<Facility> facilities = getPerunBl().getFacilitiesManagerBl().getFacilities(sess);
List<Host> hostsFromVo = new ArrayList<Host>();
for (Facility facilityElement : facilities) {
hostsFromVo.addAll(getPerunBl().getFacilitiesManagerBl().getHosts(sess, facilityElement));
}
hostsFromVo = new ArrayList<Host>(new HashSet<Host>(hostsFromVo));
for (Host hostElement : hostsFromVo) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, hostElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(hostElement, null, attribute));
}
}
} else if (getAttributesManagerImpl().isFromNamespace(sess, attrDef, AttributesManager.NS_ENTITYLESS_ATTR)) {
if (key != null) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, key, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(key, null, attribute));
} else {
List<String> keys = this.getEntitylessKeys(sess, attrDef);
for (String keyElement : keys) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, keyElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(keyElement, null, attribute));
}
}
} else if (getAttributesManagerImpl().isFromNamespace(sess, attrDef, NS_GROUP_RESOURCE_ATTR)) {
if (resource != null && member != null) {
if (!getPerunBl().getMembersManagerBl().haveStatus(sess, member, Status.INVALID)) {
List<Group> groupsFromResource = getPerunBl().getResourcesManagerBl().getAssignedGroups(sess, resource);
List<Group> groupsFromMember = getPerunBl().getGroupsManagerBl().getAllMemberGroups(sess, member);
groupsFromResource.retainAll(groupsFromMember);
groupsFromResource = new ArrayList<Group>(new HashSet<Group>(groupsFromResource));
for (Group groupElement : groupsFromResource) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, resource, groupElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(resource, groupElement, attribute));
}
}
} else if (group != null && resource != null) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, resource, group, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(resource, group, attribute));
} else if (user != null && facility != null) {
//Groups from User
List<Member> members = getPerunBl().getMembersManagerBl().getMembersByUser(sess, user);
List<Group> groupsFromUser = new ArrayList<Group>();
for (Member memberElement : members) {
if (!getPerunBl().getMembersManagerBl().haveStatus(sess, memberElement, Status.INVALID)) {
groupsFromUser.addAll(getPerunBl().getGroupsManagerBl().getAllMemberGroups(sess, memberElement));
}
}
//Retain of Groups from facility
List<Group> groupsFromFacility = getPerunBl().getGroupsManagerBl().getAssignedGroupsToFacility(sess, facility);
groupsFromFacility.retainAll(groupsFromUser);
//Resources from user
List<Member> membersFromUser = getPerunBl().getMembersManagerBl().getMembersByUser(sess, user);
List<Resource> resourcesFromUser = new ArrayList<Resource>();
for (Member memberElement : membersFromUser) {
if (!getPerunBl().getMembersManagerBl().haveStatus(sess, memberElement, Status.INVALID)) {
resourcesFromUser.addAll(getPerunBl().getResourcesManagerBl().getAllowedResources(sess, memberElement));
}
}
//Resource from facility
List<Resource> resourcesFromFacility = getPerunBl().getFacilitiesManagerBl().getAssignedResources(sess, facility);
//Retain of Resources
resourcesFromFacility.retainAll(resourcesFromUser);
//All possibilities
resourcesFromFacility = new ArrayList<Resource>(new HashSet<Resource>(resourcesFromFacility));
for (Resource resourceElement : resourcesFromFacility) {
List<Group> groupsForResourceElement = getPerunBl().getResourcesManagerBl().getAssignedGroups(sess, resourceElement);
groupsForResourceElement.retainAll(groupsFromFacility);
groupsForResourceElement = new ArrayList<Group>(new HashSet<Group>(groupsForResourceElement));
for (Group groupElement : groupsForResourceElement) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, resourceElement, groupElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(resourceElement, groupElement, attribute));
}
}
} else if (member != null && group != null) {
// there is no need to get Resources from Member because Members are only in those groups
// from which we already took Resources
List<Resource> resourcesFromGroup = getPerunBl().getResourcesManagerBl().getAssignedResources(sess, group);
for (Resource resourceElement : resourcesFromGroup) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, resourceElement, group, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(resourceElement, group, attribute));
}
} else if (group != null) {
List<Resource> resourcesFromGroup = getPerunBl().getResourcesManagerBl().getAssignedResources(sess, group);
for (Resource resourceElement : resourcesFromGroup) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, resourceElement, group, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(resourceElement, group, attribute));
}
} else if (member != null) {
if (!getPerunBl().getMembersManagerBl().haveStatus(sess, member, Status.INVALID)) {
List<Group> groupsFromMember = getPerunBl().getGroupsManagerBl().getAllMemberGroups(sess, member);
List<Resource> resourcesFromMember = getPerunBl().getResourcesManagerBl().getAllowedResources(sess, member);
for (Resource resourceElement : resourcesFromMember) {
List<Group> groupsFromResourceElement = getPerunBl().getResourcesManagerBl().getAssignedGroups(sess, resourceElement);
groupsFromResourceElement.retainAll(groupsFromMember);
groupsFromResourceElement = new ArrayList<Group>(new HashSet<Group>(groupsFromResourceElement));
for (Group groupElement : groupsFromResourceElement) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, resourceElement, groupElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(resourceElement, groupElement, attribute));
}
}
}
} else if (resource != null) {
List<Group> groupsFromResource = getPerunBl().getResourcesManagerBl().getAssignedGroups(sess, resource);
for (Group groupElement : groupsFromResource) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, resource, groupElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(resource, groupElement, attribute));
}
} else if (user != null) {
List<Member> members = getPerunBl().getMembersManagerBl().getMembersByUser(sess, user);
List<Group> groupsFromUser = new ArrayList<Group>();
List<Resource> resourcesFromUser = new ArrayList<Resource>();
for (Member memberElement : members) {
if (!getPerunBl().getMembersManagerBl().haveStatus(sess, memberElement, Status.INVALID)) {
groupsFromUser.addAll(getPerunBl().getGroupsManagerBl().getAllMemberGroups(sess, memberElement));
resourcesFromUser.addAll(getPerunBl().getResourcesManagerBl().getAllowedResources(sess, memberElement));
}
}
groupsFromUser = new ArrayList<Group>(new HashSet<Group>(groupsFromUser));
for (Group groupElement : groupsFromUser) {
List<Resource> resourcesFromGroupElement = getPerunBl().getResourcesManagerBl().getAssignedResources(sess, groupElement);
resourcesFromGroupElement.retainAll(resourcesFromUser);
resourcesFromGroupElement = new ArrayList<Resource>(new HashSet<Resource>(resourcesFromGroupElement));
for (Resource resourceElement : resourcesFromGroupElement) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, resourceElement, groupElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(resourceElement, groupElement, attribute));
}
}
} else if (host != null) {
facility = getPerunBl().getFacilitiesManagerBl().getFacilityForHost(sess, host);
List<Resource> resourcesFromHost = getPerunBl().getFacilitiesManagerBl().getAssignedResources(sess, facility);
for (Resource resourceElement : resourcesFromHost) {
List<Group> groupsFromResourceElement = getPerunBl().getResourcesManagerBl().getAssignedGroups(sess, resourceElement);
for (Group groupElement : groupsFromResourceElement) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, resourceElement, groupElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(resourceElement, groupElement, attribute));
}
}
} else if (facility != null) {
List<Resource> resourcesFromHost = getPerunBl().getFacilitiesManagerBl().getAssignedResources(sess, facility);
for (Resource resourceElement : resourcesFromHost) {
List<Group> groupsFromResourceElement = getPerunBl().getResourcesManagerBl().getAssignedGroups(sess, resourceElement);
for (Group groupElement : groupsFromResourceElement) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, resourceElement, groupElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(resourceElement, groupElement, attribute));
}
}
} else if (vo != null) {
List<Resource> resources = getPerunBl().getResourcesManagerBl().getResources(sess, vo);
for (Resource resourceElement : resources) {
List<Group> groupsFromResourceElement = getPerunBl().getResourcesManagerBl().getAssignedGroups(sess, resourceElement);
for (Group groupElement : groupsFromResourceElement) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, resourceElement, groupElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(resourceElement, groupElement, attribute));
}
}
} else if (key != null) {
List<Facility> facilities = getPerunBl().getFacilitiesManagerBl().getFacilities(sess);
List<Resource> resources = new ArrayList<Resource>();
for (Facility facilityElement : facilities) {
resources.addAll(getPerunBl().getFacilitiesManagerBl().getAssignedResources(sess, facilityElement));
}
resources = new ArrayList<Resource>(new HashSet<Resource>(resources));
for (Resource resourceElement : resources) {
List<Group> groupsFromResourceElement = getPerunBl().getResourcesManagerBl().getAssignedGroups(sess, resourceElement);
for (Group groupElement : groupsFromResourceElement) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, resourceElement, groupElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(resourceElement, groupElement, attribute));
}
}
}
} else if (getAttributesManagerImpl().isFromNamespace(sess, attrDef, NS_MEMBER_GROUP_ATTR)) {
if (resource != null && member != null) {
List<Group> groupFromMembers = new ArrayList<>();
if (!getPerunBl().getMembersManagerBl().haveStatus(sess, member, Status.INVALID)) {
groupFromMembers = getPerunBl().getGroupsManagerBl().getAllMemberGroups(sess, member);
}
List<Group> groupsFromResources = getPerunBl().getResourcesManagerBl().getAssignedGroups(sess, resource);
groupsFromResources.retainAll(groupFromMembers);
groupsFromResources = new ArrayList<>(new HashSet<>(groupsFromResources));
for (Group groupElement : groupsFromResources) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, member, groupElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(member, group, attribute));
}
} else if (group != null && resource != null) {
// there is no need to get Members from Resource because needed Members are only from 'group' variable
// which we already have. Other Members (aquired from Resource) than from 'group' variable will be redundant because
// they will be not assigned to it.
List<Member> membersFromGroup = getPerunBl().getGroupsManagerBl().getGroupMembers(sess, group, Status.VALID);
for (Member memberElement : membersFromGroup) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, memberElement, group, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(memberElement, group, attribute));
}
} else if (user != null && facility != null) {
// get all groups from facility
List<Group> groupsFromFacility = getPerunBl().getGroupsManagerBl().getAssignedGroupsToFacility(sess, facility);
// get all groups from user
List<Member> membersFromUser = getPerunBl().getMembersManagerBl().getMembersByUser(sess, user);
Set<Group> groupsFromMembers = new HashSet<>();
for (Member memberElement : membersFromUser) {
groupsFromMembers.addAll(getPerunBl().getGroupsManagerBl().getAllMemberGroups(sess, memberElement));
}
// retain of groups
groupsFromMembers.retainAll(groupsFromFacility);
List<Group> retainedGroups = new ArrayList<>(groupsFromMembers);
// all possible groups
for (Group groupElement : retainedGroups) {
// get all members for 'groupElement' variable
List<Member> membersFromGroup = getPerunBl().getGroupsManagerBl().getGroupMembers(sess, group, Status.VALID);
// all possibilities
for (Member memberElement : membersFromGroup) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, memberElement, groupElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(memberElement, groupElement, attribute));
}
}
} else if (member != null && group != null) {
if (!getPerunBl().getMembersManagerBl().haveStatus(sess, member, Status.INVALID)) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, member, group, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(member, group, attribute));
}
} else if (group != null) {
List<Member> membersFromGroups = getPerunBl().getGroupsManagerBl().getGroupMembers(sess, group, Status.VALID);
for (Member memberElement : membersFromGroups) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, memberElement, group, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(memberElement, group, attribute));
}
} else if (member != null) {
if (!getPerunBl().getMembersManagerBl().haveStatus(sess, member, Status.INVALID)) {
List<Group> groupsFromMembers = getPerunBl().getGroupsManagerBl().getAllMemberGroups(sess, member);
for (Group groupElement : groupsFromMembers) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, member, groupElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(member, groupElement, attribute));
}
}
} else if (resource != null) {
List<Group> groupsFromResources = getPerunBl().getResourcesManagerBl().getAssignedGroups(sess, resource);
for (Group groupElement : groupsFromResources) {
// get all members for 'groupElement' variable
List<Member> membersFromGroup = getPerunBl().getGroupsManagerBl().getGroupMembers(sess, group, Status.VALID);
for (Member memberElement : membersFromGroup) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, memberElement, groupElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(memberElement, groupElement, attribute));
}
}
} else if (user != null) {
List<Member> membersFromUser = getPerunBl().getMembersManagerBl().getMembersByUser(sess, user);
for (Member memberElement : membersFromUser) {
if (!getPerunBl().getMembersManagerBl().haveStatus(sess, memberElement, Status.INVALID)) {
// get all groups for 'memberElement' variable
List<Group> groupsFromMember = getPerunBl().getGroupsManagerBl().getAllMemberGroups(sess, memberElement);
for (Group groupElement : groupsFromMember) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, memberElement, groupElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(memberElement, groupElement, attribute));
}
}
}
} else if (host != null) {
facility = getPerunBl().getFacilitiesManagerBl().getFacilityForHost(sess, host);
List<Group> groupsFromFacility = getPerunBl().getGroupsManagerBl().getAssignedGroupsToFacility(sess, facility);
for (Group groupElement : groupsFromFacility) {
// get all members for 'groupElement' variable
List<Member> membersFromGroup = getPerunBl().getGroupsManagerBl().getGroupMembers(sess, group, Status.VALID);
for (Member memberElement : membersFromGroup) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, memberElement, groupElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(memberElement, groupElement, attribute));
}
}
} else if (facility != null) {
List<Group> groupsFromFacility = getPerunBl().getGroupsManagerBl().getAssignedGroupsToFacility(sess, facility);
for (Group groupElement : groupsFromFacility) {
// get all members for 'groupElement' variable
List<Member> membersFromGroup = getPerunBl().getGroupsManagerBl().getGroupMembers(sess, group, Status.VALID);
for (Member memberElement : membersFromGroup) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, memberElement, groupElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(memberElement, groupElement, attribute));
}
}
} else if (vo != null) {
List<Group> groupsFromVo = getPerunBl().getGroupsManagerBl().getAllGroups(sess, vo);
for (Group groupElement : groupsFromVo) {
// get all members for 'groupElement' variable
List<Member> membersFromGroup = getPerunBl().getGroupsManagerBl().getGroupMembers(sess, group, Status.VALID);
for (Member memberElement : membersFromGroup) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, memberElement, groupElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(memberElement, groupElement, attribute));
}
}
} else if (key != null) {
List<Vo> vos = getPerunBl().getVosManagerBl().getVos(sess);
List<Group> groupsFromVo = new ArrayList<>();
for (Vo voElement : vos) {
groupsFromVo.addAll(getPerunBl().getGroupsManagerBl().getAllGroups(sess, voElement));
}
groupsFromVo = new ArrayList<>(new HashSet<>(groupsFromVo));
for (Group groupElement : groupsFromVo) {
// get all members for 'groupElement' variable
List<Member> membersFromGroup = getPerunBl().getGroupsManagerBl().getGroupMembers(sess, group, Status.VALID);
for (Member memberElement : membersFromGroup) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, memberElement, groupElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(memberElement, groupElement, attribute));
}
}
}
} else if (getAttributesManagerImpl().isFromNamespace(sess, attrDef, NS_MEMBER_RESOURCE_ATTR)) {
if (resource != null && member != null) {
if (!getPerunBl().getMembersManagerBl().haveStatus(sess, member, Status.INVALID)) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, resource, member, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(resource, member, attribute));
}
} else if (group != null && resource != null) {
List<Member> membersFromGroup = getPerunBl().getGroupsManagerBl().getGroupMembers(sess, group);
List<Member> membersFromResource = getPerunBl().getResourcesManagerBl().getAllowedMembers(sess, resource);
membersFromGroup.retainAll(membersFromResource);
membersFromGroup = new ArrayList<Member>(new HashSet<Member>(membersFromGroup));
for (Member memberElement : membersFromGroup) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, resource, memberElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(resource, memberElement, attribute));
}
} else if (user != null && facility != null) {
List<Member> membersFromUser = getPerunBl().getMembersManagerBl().getMembersByUser(sess, user);
List<Member> membersFromFacility = getPerunBl().getFacilitiesManagerBl().getAllowedMembers(sess, facility);
List<Resource> resourcesFromFacility = getPerunBl().getFacilitiesManagerBl().getAssignedResources(sess, facility);
List<Resource> resourcesFromUser = new ArrayList<Resource>();
for (Member memberElement : membersFromUser) {
if (!getPerunBl().getMembersManagerBl().haveStatus(sess, memberElement, Status.INVALID)) {
resourcesFromUser.addAll(getPerunBl().getResourcesManagerBl().getAllowedResources(sess, memberElement));
}
}
membersFromUser.retainAll(membersFromFacility);
resourcesFromUser.retainAll(resourcesFromFacility);
resourcesFromUser = new ArrayList<Resource>(new HashSet<Resource>(resourcesFromUser));
for (Resource resourceElement : resourcesFromUser) {
List<Member> membersForResourceElement = getPerunBl().getResourcesManagerBl().getAllowedMembers(sess, resourceElement);
membersForResourceElement.retainAll(membersFromUser);
membersForResourceElement = new ArrayList<Member>(new HashSet<Member>(membersForResourceElement));
for (Member memberElement : membersForResourceElement) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, resourceElement, memberElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(resourceElement, memberElement, attribute));
}
}
} else if (member != null && group != null) {
// there is no need to get Resources from Member because Members are only in those groups
// from which we already took Resources
List<Resource> resourcesFromGroup = getPerunBl().getResourcesManagerBl().getAssignedResources(sess, group);
for (Resource resourceElement : resourcesFromGroup) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, resourceElement, member, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(resourceElement, member, attribute));
}
} else if (group != null) {
List<Resource> resources = getPerunBl().getResourcesManagerBl().getAssignedResources(sess, group);
List<Member> members = getPerunBl().getGroupsManagerBl().getGroupMembers(sess, group);
for (Resource resourceElement : resources) {
List<Member> membersForResourceElement = getPerunBl().getResourcesManagerBl().getAllowedMembers(sess, resourceElement);
membersForResourceElement.retainAll(members);
membersForResourceElement = new ArrayList<Member>(new HashSet<Member>(membersForResourceElement));
for (Member memberElement : members) {
if (!getPerunBl().getMembersManagerBl().haveStatus(sess, memberElement, Status.INVALID)) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, resourceElement, memberElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(resourceElement, memberElement, attribute));
}
}
}
} else if (member != null) {
if (!getPerunBl().getMembersManagerBl().haveStatus(sess, member, Status.INVALID)) {
List<Resource> resources = getPerunBl().getResourcesManagerBl().getAllowedResources(sess, member);
for (Resource resourceElement : resources) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, resourceElement, member, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(resourceElement, member, attribute));
}
}
} else if (resource != null) {
List<Member> members = getPerunBl().getResourcesManagerBl().getAllowedMembers(sess, resource);
for (Member memberElement : members) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, resource, memberElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(resource, memberElement, attribute));
}
} else if (user != null) {
List<Member> members = getPerunBl().getMembersManagerBl().getMembersByUser(sess, user);
for (Member memberElement : members) {
if (!getPerunBl().getMembersManagerBl().haveStatus(sess, memberElement, Status.INVALID)) {
List<Resource> resources = getPerunBl().getResourcesManagerBl().getAllowedResources(sess, memberElement);
for (Resource resourceElement : resources) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, resourceElement, memberElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(resourceElement, memberElement, attribute));
}
}
}
} else if (host != null) {
facility = getPerunBl().getFacilitiesManagerBl().getFacilityForHost(sess, host);
List<Resource> resources = getPerunBl().getFacilitiesManagerBl().getAssignedResources(sess, facility);
for (Resource resourceElement : resources) {
List<Member> members = getPerunBl().getResourcesManagerBl().getAllowedMembers(sess, resourceElement);
for (Member memberElement : members) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, resourceElement, memberElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(resourceElement, memberElement, attribute));
}
}
} else if (facility != null) {
List<Resource> resources = getPerunBl().getFacilitiesManagerBl().getAssignedResources(sess, facility);
for (Resource resourceElement : resources) {
List<Member> members = getPerunBl().getResourcesManagerBl().getAllowedMembers(sess, resourceElement);
for (Member memberElement : members) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, resourceElement, memberElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(resourceElement, memberElement, attribute));
}
}
} else if (vo != null) {
List<Resource> resources = getPerunBl().getResourcesManagerBl().getResources(sess, vo);
List<Member> membersFromVo = getPerunBl().getMembersManagerBl().getMembers(sess, vo);
for (Resource resourceElement : resources) {
List<Member> membersFromResource = getPerunBl().getResourcesManagerBl().getAllowedMembers(sess, resource);
membersFromResource.retainAll(membersFromVo);
for (Member memberElement : membersFromResource) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, resourceElement, memberElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(resourceElement, memberElement, attribute));
}
}
} else if (key != null) {
List<Vo> vos = getPerunBl().getVosManagerBl().getVos(sess);
List<Resource> resources = new ArrayList<Resource>();
List<Member> membersFromVo = new ArrayList<Member>();
for (Vo voElement : vos) {
resources.addAll(getPerunBl().getResourcesManagerBl().getResources(sess, voElement));
membersFromVo.addAll(getPerunBl().getMembersManagerBl().getMembers(sess, voElement));
}
resources = new ArrayList<Resource>(new HashSet<Resource>(resources));
for (Resource resourceElement : resources) {
List<Member> membersFromResource = getPerunBl().getResourcesManagerBl().getAllowedMembers(sess, resourceElement);
membersFromResource.retainAll(membersFromVo);
membersFromResource = new ArrayList<Member>(new HashSet<Member>(membersFromResource));
for (Member memberElement : membersFromResource) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, resourceElement, memberElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(resourceElement, memberElement, attribute));
}
}
}
} else if (getAttributesManagerImpl().isFromNamespace(sess, attrDef, NS_USER_FACILITY_ATTR)) {
if (resource != null && member != null) {
if (!getPerunBl().getMembersManagerBl().haveStatus(sess, member, Status.INVALID)) {
facility = getPerunBl().getResourcesManagerBl().getFacility(sess, resource);
user = getPerunBl().getUsersManagerBl().getUserByMember(sess, member);
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, facility, user, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(facility, user, attribute));
}
} else if (group != null && resource != null) {
facility = getPerunBl().getResourcesManagerBl().getFacility(sess, resource);
//get Users from Group
List<Member> members = getPerunBl().getGroupsManagerBl().getGroupMembers(sess, group);
List<User> usersFromGroup = new ArrayList<User>();
for (Member memberElement : members) {
if (!getPerunBl().getMembersManagerBl().haveStatus(sess, memberElement, Status.INVALID)) {
usersFromGroup.add(getPerunBl().getUsersManagerBl().getUserByMember(sess, memberElement));
}
}
//get users from resource
List<Member> membersFromResource = getPerunBl().getResourcesManagerBl().getAllowedMembers(sess, resource);
List<User> usersFromResource = new ArrayList<User>();
for (Member memberElement : membersFromResource) {
if (!getPerunBl().getMembersManagerBl().haveStatus(sess, memberElement, Status.INVALID)) {
usersFromResource.add(getPerunBl().getUsersManagerBl().getUserByMember(sess, memberElement));
}
}
usersFromGroup.retainAll(usersFromResource);
usersFromGroup = new ArrayList<User>(new HashSet<User>(usersFromGroup));
for (User userElement : usersFromGroup) {
if (getPerunBl().getFacilitiesManagerBl().getAllowedFacilities(sess, userElement).contains(facility)) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, facility, userElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(facility, userElement, attribute));
}
}
} else if (user != null && facility != null) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, facility, user, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(facility, user, attribute));
} else if (member != null && group != null) {
List<Resource> resourcesFromGroup = getPerunBl().getResourcesManagerBl().getAssignedResources(sess, group);
List<Facility> facilitiesFromResources = new ArrayList<>();
for (Resource resourceElement : resourcesFromGroup) {
facilitiesFromResources.add(getPerunBl().getResourcesManagerBl().getFacility(sess, resourceElement));
}
facilitiesFromResources = new ArrayList<>(new HashSet<>(facilitiesFromResources));
User userFromMember = getPerunBl().getUsersManagerBl().getUserByMember(sess, member);
for (Facility facilityElement : facilitiesFromResources) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, facilityElement, userFromMember, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(facilityElement, userFromMember, attribute));
}
} else if (group != null) {
List<Member> members = getPerunBl().getGroupsManagerBl().getGroupMembers(sess, group);
List<User> users = new ArrayList<User>();
for (Member memberElement : members) {
if (!getPerunBl().getMembersManagerBl().haveStatus(sess, memberElement, Status.INVALID)) {
users.add(getPerunBl().getUsersManagerBl().getUserByMember(sess, memberElement));
}
}
List<Resource> resources = getPerunBl().getResourcesManagerBl().getAssignedResources(sess, group);
List<Facility> facilities = new ArrayList<Facility>();
for (Resource resourceElement : resources) {
facilities.add(getPerunBl().getResourcesManagerBl().getFacility(sess, resourceElement));
}
users = new ArrayList<User>(new HashSet<User>(users));
for (User userElement : users) {
List<Facility> facilitiesFromUser = getPerunBl().getFacilitiesManagerBl().getAllowedFacilities(sess, userElement);
facilities.retainAll(facilitiesFromUser);
facilities = new ArrayList<Facility>(new HashSet<Facility>(facilities));
for (Facility facilityElement : facilities) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, facilityElement, userElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(facilityElement, userElement, attribute));
}
}
} else if (member != null) {
if (!getPerunBl().getMembersManagerBl().haveStatus(sess, member, Status.INVALID)) {
user = getPerunBl().getUsersManagerBl().getUserByMember(sess, member);
List<Resource> memberResources = getPerunBl().getResourcesManagerBl().getAllowedResources(sess, member);
List<Facility> facilities = new ArrayList<Facility>();
for (Resource resourceElement : memberResources) {
facilities.add(getPerunBl().getResourcesManagerBl().getFacility(sess, resourceElement));
}
facilities = new ArrayList<Facility>(new HashSet<Facility>(facilities));
for (Facility facilityElement : facilities) {
if (getPerunBl().getFacilitiesManagerBl().getAllowedFacilities(sess, user).contains(facilityElement)) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, facilityElement, user, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(facilityElement, user, attribute));
}
}
}
} else if (resource != null) {
facility = getPerunBl().getResourcesManagerBl().getFacility(sess, resource);
List<User> usersFromResource = getPerunBl().getResourcesManagerBl().getAllowedUsers(sess, resource);
for (User userElement : usersFromResource) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, facility, userElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(facility, userElement, attribute));
}
} else if (user != null) {
List<Facility> facilities = getPerunBl().getFacilitiesManagerBl().getAllowedFacilities(sess, user);
for (Facility facilityElement : facilities) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, facilityElement, user, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(facilityElement, user, attribute));
}
} else if (host != null) {
facility = getPerunBl().getFacilitiesManagerBl().getFacilityForHost(sess, host);
List<User> users = getPerunBl().getFacilitiesManagerBl().getAllowedUsers(sess, facility);
for (User userElement : users) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, facility, userElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(facility, userElement, attribute));
}
} else if (facility != null) {
List<User> users = getPerunBl().getFacilitiesManagerBl().getAllowedUsers(sess, facility);
for (User userElement : users) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, facility, userElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(facility, userElement, attribute));
}
} else if (vo != null) {
List<Member> members = getPerunBl().getMembersManagerBl().getMembers(sess, vo);
List<User> users = new ArrayList<User>();
for (Member memberElement : members) {
if (!getPerunBl().getMembersManagerBl().haveStatus(sess, memberElement, Status.INVALID)) {
users.add(getPerunBl().getUsersManagerBl().getUserByMember(sess, memberElement));
}
}
List<Resource> resourcesFromVo = getPerunBl().getResourcesManagerBl().getResources(sess, vo);
List<Facility> facilitiesFromVo = new ArrayList<Facility>();
for (Resource resourceElement : resourcesFromVo) {
facilitiesFromVo.add(getPerunBl().getResourcesManagerBl().getFacility(sess, resourceElement));
}
users = new ArrayList<User>(new HashSet<User>(users));
for (User userElement : users) {
List<Facility> facilitiesFromUserElement = getPerunBl().getFacilitiesManagerBl().getAllowedFacilities(sess, userElement);
facilitiesFromUserElement.retainAll(facilitiesFromVo);
facilitiesFromUserElement = new ArrayList<Facility>(new HashSet<Facility>(facilitiesFromUserElement));
for (Facility facilityElement : facilitiesFromUserElement) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, facilityElement, userElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(facilityElement, userElement, attribute));
}
}
} else if (key != null) {
List<Facility> facilities = getPerunBl().getFacilitiesManagerBl().getFacilities(sess);
for (Facility facilityElement : facilities) {
List<User> users = getPerunBl().getFacilitiesManagerBl().getAllowedUsers(sess, facilityElement);
for (User userElement : users) {
attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, facilityElement, userElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute(facilityElement, userElement, attribute));
}
}
}
} else {
throw new InternalErrorException("There is unrecognized namespace in attribute " + attrDef);
}
return listOfRichAttributes;
}
use of cz.metacentrum.perun.core.api.Resource in project perun by CESNET.
the class FacilitiesManagerBlImpl method getFacilitiesByPerunBean.
public List<Facility> getFacilitiesByPerunBean(PerunSession sess, PerunBean perunBean) throws InternalErrorException {
List<Facility> facilities = new ArrayList<Facility>();
//All possible useful objects
Vo vo = null;
Facility facility = null;
Group group = null;
Member member = null;
User user = null;
Host host = null;
Resource resource = null;
if (perunBean != null) {
if (perunBean instanceof Vo)
vo = (Vo) perunBean;
else if (perunBean instanceof Facility)
facility = (Facility) perunBean;
else if (perunBean instanceof Group)
group = (Group) perunBean;
else if (perunBean instanceof Member)
member = (Member) perunBean;
else if (perunBean instanceof User)
user = (User) perunBean;
else if (perunBean instanceof Host)
host = (Host) perunBean;
else if (perunBean instanceof Resource)
resource = (Resource) perunBean;
else {
throw new InternalErrorException("There is unrecognized object in primaryHolder of aidingAttr.");
}
} else {
throw new InternalErrorException("Aiding attribtue must have primaryHolder which is not null.");
}
if (group != null) {
List<Resource> resources = getPerunBl().getResourcesManagerBl().getAssignedResources(sess, group);
for (Resource resourceElemenet : resources) {
facilities.add(getPerunBl().getResourcesManagerBl().getFacility(sess, resourceElemenet));
}
} else if (member != null) {
List<Group> groupsForMember = getPerunBl().getGroupsManagerBl().getAllMemberGroups(sess, member);
List<Resource> resourcesFromMember = new ArrayList<Resource>();
for (Group groupElement : groupsForMember) {
resourcesFromMember.addAll(getPerunBl().getResourcesManagerBl().getAssignedResources(sess, groupElement));
}
for (Resource resourceElement : resourcesFromMember) {
facilities.add(getPerunBl().getResourcesManagerBl().getFacility(sess, resourceElement));
}
} else if (resource != null) {
facilities.add(getPerunBl().getResourcesManagerBl().getFacility(sess, resource));
} else if (user != null) {
List<Member> membersFromUser = getPerunBl().getMembersManagerBl().getMembersByUser(sess, user);
List<Resource> resourcesFromMembers = new ArrayList<Resource>();
for (Member memberElement : membersFromUser) {
resourcesFromMembers.addAll(getPerunBl().getResourcesManagerBl().getAssignedResources(sess, member));
}
for (Resource resourceElement : resourcesFromMembers) {
facilities.add(getPerunBl().getResourcesManagerBl().getFacility(sess, resourceElement));
}
} else if (host != null) {
facilities.add(getPerunBl().getFacilitiesManagerBl().getFacilityForHost(sess, host));
} else if (vo != null) {
List<Resource> resources = getPerunBl().getResourcesManagerBl().getResources(sess, vo);
for (Resource resourceElemenet : resources) {
facilities.add(getPerunBl().getResourcesManagerBl().getFacility(sess, resourceElemenet));
}
}
facilities = new ArrayList<Facility>(new HashSet<Facility>(facilities));
return facilities;
}
use of cz.metacentrum.perun.core.api.Resource in project perun by CESNET.
the class FacilitiesManagerBlImpl method getAssignedFacilities.
public List<Facility> getAssignedFacilities(PerunSession sess, Service service) throws InternalErrorException {
List<Resource> resources = perunBl.getServicesManagerBl().getAssignedResources(sess, service);
Set<Facility> assignedFacilities = new HashSet<Facility>();
for (Resource resource : resources) {
assignedFacilities.add(perunBl.getResourcesManagerBl().getFacility(sess, resource));
}
return new ArrayList<Facility>(assignedFacilities);
}
Aggregations