org.dspace.xmlworkflow.RoleMembers Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dspace-api Show documentation
Show all versions of dspace-api Show documentation
DSpace core data model and service APIs.
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.xmlworkflow;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.UUID;
import org.dspace.core.Context;
import org.dspace.eperson.EPerson;
import org.dspace.eperson.Group;
import org.dspace.eperson.factory.EPersonServiceFactory;
import org.dspace.eperson.service.GroupService;
/**
* The members from a role, can either
* contains a list of epersons or groups
*
* @author Bram De Schouwer (bram.deschouwer at dot com)
* @author Kevin Van de Velde (kevin at atmire dot com)
* @author Ben Bosman (ben at atmire dot com)
* @author Mark Diggory (markd at atmire dot com)
*/
public class RoleMembers {
protected GroupService groupService = EPersonServiceFactory.getInstance().getGroupService();
private final ArrayList groups;
private final ArrayList epersons;
public RoleMembers() {
this.groups = new ArrayList<>();
this.epersons = new ArrayList<>();
}
public ArrayList getGroups() {
return groups;
}
public ArrayList getEPersons() {
return epersons;
}
public void addGroup(Group group) {
groups.add(group);
}
public void addEPerson(EPerson eperson) {
epersons.add(eperson);
}
public void removeEperson(EPerson epersonToRemove) {
epersons.removeIf(eperson -> eperson.equals(epersonToRemove));
}
public ArrayList getAllUniqueMembers(Context context) throws SQLException {
HashMap epersonsMap = new HashMap();
for (EPerson eperson : epersons) {
epersonsMap.put(eperson.getID(), eperson);
}
for (Group group : groups) {
for (EPerson eperson : groupService.allMembers(context, group)) {
epersonsMap.put(eperson.getID(), eperson);
}
}
return new ArrayList<>(epersonsMap.values());
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy