use of org.olat.portfolio.model.structel.EPStructureElementToGroupRelation in project OpenOLAT by OpenOLAT.
the class EPPolicyManager method createBaseRelation.
private EPStructureElementToGroupRelation createBaseRelation(PortfolioStructureMap map, Group group, String role, Date from, Date to) {
// create security group
EPStructureElementToGroupRelation relation = new EPStructureElementToGroupRelation();
relation.setDefaultGroup(false);
relation.setCreationDate(new Date());
relation.setGroup(group);
relation.setStructureElement((EPStructureElement) map);
relation.setRole(role);
relation.setValidFrom(from);
relation.setValidTo(to);
map.getGroups().add(relation);
return relation;
}
use of org.olat.portfolio.model.structel.EPStructureElementToGroupRelation in project OpenOLAT by OpenOLAT.
the class EPPolicyManager method applyPolicyToUsers.
private EPStructureElementToGroupRelation applyPolicyToUsers(EPMapPolicy policy, PortfolioStructureMap map) {
List<EPStructureElementToGroupRelation> currentRelations = policy.getRelations();
EPStructureElementToGroupRelation relation = (currentRelations == null || currentRelations.isEmpty()) ? null : currentRelations.get(0);
if (relation == null) {
Group secGroup = groupDao.createGroup();
relation = createBaseRelation(map, secGroup, EPMapPolicy.Type.user.name(), policy.getFrom(), policy.getTo());
for (Identity identity : policy.getIdentities()) {
groupDao.addMembershipTwoWay(secGroup, identity, GroupRoles.participant.name());
}
} else {
EPStructureElementToGroupRelation currentPolicy = reusePolicyInSession(relation, map);
updatePolicy(currentPolicy, policy.getFrom(), policy.getTo());
Group secGroup = relation.getGroup();
List<Identity> currentMembers = groupDao.getMembers(secGroup, GroupRoles.participant.name());
List<Identity> newMembers = new ArrayList<>(policy.getIdentities());
for (Identity newMember : policy.getIdentities()) {
if (currentMembers.contains(newMember)) {
newMembers.remove(newMember);
currentMembers.remove(newMember);
}
}
// re-attach the session to lazy load the members
secGroup = dbInstance.getCurrentEntityManager().merge(secGroup);
for (Identity currentMember : currentMembers) {
groupDao.removeMembership(secGroup, currentMember);
}
for (Identity newMember : newMembers) {
groupDao.addMembershipTwoWay(secGroup, newMember, GroupRoles.participant.name());
}
}
return relation;
}
use of org.olat.portfolio.model.structel.EPStructureElementToGroupRelation in project OpenOLAT by OpenOLAT.
the class EPPolicyManager method applyPolicy.
private List<EPStructureElementToGroupRelation> applyPolicy(EPMapPolicy policy, PortfolioStructureMap map) {
List<EPStructureElementToGroupRelation> savedPolicies = new ArrayList<EPStructureElementToGroupRelation>();
switch(policy.getType()) {
case user:
savedPolicies.add(applyPolicyToUsers(policy, map));
break;
case group:
for (BusinessGroup group : policy.getGroups()) {
savedPolicies.add(applyPolicyToGroup(group.getBaseGroup(), policy, map));
}
break;
case invitation:
Invitation invitation = policy.getInvitation();
EPStructureElementToGroupRelation invitationPolicy = applyPolicyToInvitation(invitation, policy, map);
savedPolicies.add(invitationPolicy);
break;
case allusers:
EPStructureElementToGroupRelation allUsersPolicy = applyPolicyToAllUsers(policy, map);
savedPolicies.add(allUsersPolicy);
break;
}
return savedPolicies;
}
use of org.olat.portfolio.model.structel.EPStructureElementToGroupRelation in project openolat by klemens.
the class EPPolicyManager method applyPolicyToUsers.
private EPStructureElementToGroupRelation applyPolicyToUsers(EPMapPolicy policy, PortfolioStructureMap map) {
List<EPStructureElementToGroupRelation> currentRelations = policy.getRelations();
EPStructureElementToGroupRelation relation = (currentRelations == null || currentRelations.isEmpty()) ? null : currentRelations.get(0);
if (relation == null) {
Group secGroup = groupDao.createGroup();
relation = createBaseRelation(map, secGroup, EPMapPolicy.Type.user.name(), policy.getFrom(), policy.getTo());
for (Identity identity : policy.getIdentities()) {
groupDao.addMembershipTwoWay(secGroup, identity, GroupRoles.participant.name());
}
} else {
EPStructureElementToGroupRelation currentPolicy = reusePolicyInSession(relation, map);
updatePolicy(currentPolicy, policy.getFrom(), policy.getTo());
Group secGroup = relation.getGroup();
List<Identity> currentMembers = groupDao.getMembers(secGroup, GroupRoles.participant.name());
List<Identity> newMembers = new ArrayList<>(policy.getIdentities());
for (Identity newMember : policy.getIdentities()) {
if (currentMembers.contains(newMember)) {
newMembers.remove(newMember);
currentMembers.remove(newMember);
}
}
// re-attach the session to lazy load the members
secGroup = dbInstance.getCurrentEntityManager().merge(secGroup);
for (Identity currentMember : currentMembers) {
groupDao.removeMembership(secGroup, currentMember);
}
for (Identity newMember : newMembers) {
groupDao.addMembershipTwoWay(secGroup, newMember, GroupRoles.participant.name());
}
}
return relation;
}
use of org.olat.portfolio.model.structel.EPStructureElementToGroupRelation in project openolat by klemens.
the class EPPolicyManager method getMapPolicies.
/**
* Return a list of wrapper containing the read policies of the map
* @param map
*/
public List<EPMapPolicy> getMapPolicies(PortfolioStructureMapRef mapRef) {
EPMapShort map = dbInstance.getCurrentEntityManager().find(EPMapShort.class, mapRef.getKey());
List<EPMapPolicy> policies = new ArrayList<EPMapPolicy>();
Set<EPStructureElementToGroupRelation> relations = map.getGroups();
for (EPStructureElementToGroupRelation relation : relations) {
if (relation.isDefaultGroup()) {
continue;
}
EPMapPolicy policy = getEquivalentWrapper(relation, policies);
if (policy == null) {
policy = new EPMapPolicy();
policy.setTo(relation.getValidTo());
policy.setFrom(relation.getValidFrom());
policies.add(policy);
}
String role = relation.getRole();
if (role.startsWith(EPMapPolicy.Type.user.name())) {
List<Identity> identities = groupDao.getMembers(relation.getGroup(), GroupRoles.participant.name());
policy.addRelation(relation);
policy.setType(EPMapPolicy.Type.user);
policy.addIdentities(identities);
} else if (role.startsWith(EPMapPolicy.Type.group.name())) {
policy.addRelation(relation);
BusinessGroup group = businessGroupDao.findBusinessGroup(relation.getGroup());
policy.addGroup(group);
policy.setType(EPMapPolicy.Type.group);
} else if (role.startsWith(EPMapPolicy.Type.invitation.name())) {
policy.addRelation(relation);
Invitation invitation = invitationDao.findInvitation(relation.getGroup());
policy.setInvitation(invitation);
policy.setType(EPMapPolicy.Type.invitation);
} else if (role.startsWith(EPMapPolicy.Type.allusers.name())) {
policy.addRelation(relation);
policy.setType(EPMapPolicy.Type.allusers);
}
}
return policies;
}
Aggregations