use of cz.metacentrum.perun.core.api.Member in project perun by CESNET.
the class ServicesManagerBlImpl method getData.
private ServiceAttributes getData(PerunSession sess, Service service, Facility facility, Resource resource) throws InternalErrorException {
ServiceAttributes resourceServiceAttributes = new ServiceAttributes();
resourceServiceAttributes.addAttributes(getPerunBl().getAttributesManagerBl().getRequiredAttributes(sess, service, resource));
List<Member> members;
members = getPerunBl().getResourcesManagerBl().getAllowedMembers(sess, resource);
HashMap<Member, List<Attribute>> attributes;
try {
attributes = getPerunBl().getAttributesManagerBl().getRequiredAttributes(sess, service, facility, resource, members, true);
} catch (WrongAttributeAssignmentException ex) {
throw new InternalErrorException(ex);
}
for (Member mem : attributes.keySet()) {
ServiceAttributes serviceAttributes = new ServiceAttributes();
serviceAttributes.addAttributes(attributes.get(mem));
resourceServiceAttributes.addChildElement(serviceAttributes);
}
return resourceServiceAttributes;
}
use of cz.metacentrum.perun.core.api.Member in project perun by CESNET.
the class Utils method generateAllGroupsToWriter.
/**
* Method generate all Groups to the text for using in LDIF.
* Write all these information to writer in perunInitializer object.
*
* @param perunInitializer need to be loaded to get all needed dependencies
*
* @throws InternalErrorException if some problem with initializer or objects in perun-core
* @throws IOException if some problem with writer
*/
public static void generateAllGroupsToWriter(PerunInitializer perunInitializer) throws InternalErrorException, IOException {
//Load basic variables
if (perunInitializer == null)
throw new InternalErrorException("PerunInitializer must be loaded before using in generating methods!");
PerunSession perunSession = perunInitializer.getPerunSession();
PerunBl perun = perunInitializer.getPerunBl();
BufferedWriter writer = perunInitializer.getOutputWriter();
//First get all vos
List<Vo> vos = perun.getVosManagerBl().getVos(perunSession);
//Then from all vos get all assigned groups and generate data about them to the writer
for (Vo vo : vos) {
List<Group> groups;
groups = perun.getGroupsManagerBl().getGroups(perunSession, vo);
for (Group group : groups) {
String dn = "dn: ";
String oc1 = "objectclass: top";
String oc3 = "objectclass: perunGroup";
String cn = "cn: ";
String perunVoId = "perunVoId: ";
String parentGroup = "perunParentGroup: ";
String parentGroupId = "perunParentGroupId: ";
String perunGroupId = "perunGroupId: ";
String owner = "owner: ";
String description = "description: ";
String perunUniqueGroupName = "perunUniqueGroupName: ";
List<Member> members;
members = perun.getGroupsManagerBl().getGroupMembers(perunSession, group, Status.VALID);
perunGroupId += String.valueOf(group.getId());
perunVoId += String.valueOf(group.getVoId());
dn += "perunGroupId=" + group.getId() + ",perunVoId=" + group.getVoId() + ",dc=perun,dc=cesnet,dc=cz";
cn += group.getName();
perunUniqueGroupName += vo.getShortName() + ":" + group.getName();
if (group.getDescription() != null)
description += group.getDescription();
if (group.getParentGroupId() != null) {
parentGroupId += group.getParentGroupId();
parentGroup += "perunGroupId=" + group.getParentGroupId() + ",perunVoId=" + group.getVoId() + ",dc=perun,dc=cesnet,dc=cz";
}
List<Member> admins = new ArrayList<>();
writer.write(dn + '\n');
writer.write(oc1 + '\n');
writer.write(oc3 + '\n');
writer.write(cn + '\n');
writer.write(perunUniqueGroupName + '\n');
writer.write(perunGroupId + '\n');
writer.write(perunVoId + '\n');
if (group.getDescription() != null)
writer.write(description + '\n');
if (group.getParentGroupId() != null) {
writer.write(parentGroupId + '\n');
writer.write(parentGroup + '\n');
}
//ADD Group Members
for (Member m : members) {
writer.write("uniqueMember: " + "perunUserId=" + m.getUserId() + ",ou=People,dc=perun,dc=cesnet,dc=cz");
writer.write('\n');
}
//ADD resources which group is assigned to
List<Resource> associatedResources;
associatedResources = perun.getResourcesManagerBl().getAssignedResources(perunSession, group);
for (Resource r : associatedResources) {
writer.write("assignedToResourceId: " + r.getId());
writer.write('\n');
}
//FOR NOW No groups has owner
writer.write(owner + '\n');
writer.write('\n');
}
}
}
use of cz.metacentrum.perun.core.api.Member in project perun by CESNET.
the class MembersManagerBlImpl method createSpecificMember.
public Member createSpecificMember(PerunSession sess, Vo vo, Candidate candidate, List<User> specificUserOwners, SpecificUserType specificUserType, List<Group> groups) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException, AlreadyMemberException, ExtendMembershipException, GroupOperationsException {
if (specificUserType.equals(SpecificUserType.SERVICE))
candidate.setFirstName("(Service)");
//Set organization only if user in sessione exists (in tests there is no user in session)
if (sess.getPerunPrincipal().getUser() != null) {
String userOrganization = AttributesManager.NS_USER_ATTR_DEF + ":organization";
String memberOrganization = AttributesManager.NS_MEMBER_ATTR_DEF + ":organization";
Map<String, String> candidateAttributes = new HashMap<>();
if (candidate.getAttributes() != null)
candidateAttributes.putAll(candidate.getAttributes());
if (candidateAttributes.get(memberOrganization) == null) {
Attribute actorUserOrganization;
String actorUserOrganizationValue;
try {
actorUserOrganization = perunBl.getAttributesManagerBl().getAttribute(sess, sess.getPerunPrincipal().getUser(), userOrganization);
actorUserOrganizationValue = (String) actorUserOrganization.getValue();
} catch (WrongAttributeAssignmentException | AttributeNotExistsException ex) {
throw new InternalErrorException(ex);
}
if (actorUserOrganizationValue != null) {
candidateAttributes.put(memberOrganization, actorUserOrganizationValue);
candidate.setAttributes(candidateAttributes);
}
}
}
//create member for service user from candidate
Member member = createMember(sess, vo, specificUserType, candidate, groups, null);
//set specific user owners or sponsors
User specificUser = getPerunBl().getUsersManagerBl().getUserByMember(sess, member);
for (User u : specificUserOwners) {
try {
getPerunBl().getUsersManagerBl().addSpecificUserOwner(sess, u, specificUser);
} catch (RelationExistsException ex) {
throw new InternalErrorException(ex);
}
}
return member;
}
use of cz.metacentrum.perun.core.api.Member in project perun by CESNET.
the class ServicesManagerBlImpl method getData.
private ServiceAttributes getData(PerunSession sess, Service service, Facility facility, Resource resource, Group group, Map<Member, ServiceAttributes> memberAttributes) throws InternalErrorException {
ServiceAttributes groupServiceAttributes = new ServiceAttributes();
try {
groupServiceAttributes.addAttributes(getPerunBl().getAttributesManagerBl().getRequiredAttributes(sess, service, resource, group, true));
} catch (WrongAttributeAssignmentException ex) {
throw new InternalErrorException(ex);
}
ServiceAttributes groupsSubGroupsElement = new ServiceAttributes();
// FIXME Do not get subgroups of the members group
if (!group.getName().equals(VosManager.MEMBERS_GROUP)) {
List<Group> subGroups = getPerunBl().getGroupsManagerBl().getSubGroups(sess, group);
for (Group subGroup : subGroups) {
groupsSubGroupsElement.addChildElement(getData(sess, service, facility, resource, subGroup, memberAttributes));
}
}
ServiceAttributes groupsMembersElement = new ServiceAttributes();
//Invalid and disabled are not allowed here
List<Member> members = getPerunBl().getGroupsManagerBl().getGroupMembersExceptInvalidAndDisabled(sess, group);
for (Member member : members) {
groupsMembersElement.addChildElement(memberAttributes.get(member));
}
groupServiceAttributes.addChildElement(groupsSubGroupsElement);
groupServiceAttributes.addChildElement(groupsMembersElement);
return groupServiceAttributes;
}
use of cz.metacentrum.perun.core.api.Member in project perun by CESNET.
the class FacilitiesManagerBlImpl method getAllowedFacilities.
public List<Facility> getAllowedFacilities(PerunSession sess, User user) throws InternalErrorException {
List<Member> members = perunBl.getMembersManagerBl().getMembersByUser(sess, user);
Set<Facility> assignedFacilities = new HashSet<Facility>();
for (Member member : members) {
if (!getPerunBl().getMembersManagerBl().haveStatus(sess, member, Status.INVALID)) {
assignedFacilities.addAll(this.getAssignedFacilities(sess, member));
}
}
return new ArrayList<Facility>(assignedFacilities);
}
Aggregations