use of org.olat.portfolio.model.structel.EPStructureElementToGroupRelation in project OpenOLAT by OpenOLAT.
the class EPPolicyManager method updateMapPolicies.
/**
* Update the map policies of a map. The missing policies are deleted!
* @param map
* @param policies
*/
public PortfolioStructureMap updateMapPolicies(PortfolioStructureMap map, List<EPMapPolicy> policies) {
map = dbInstance.getCurrentEntityManager().merge(map);
List<EPStructureElementToGroupRelation> savedPolicies = new ArrayList<EPStructureElementToGroupRelation>();
for (EPMapPolicy wrapper : policies) {
savedPolicies.addAll(applyPolicy(wrapper, map));
}
Collection<EPStructureElementToGroupRelation> currentRelations = new ArrayList<>(map.getGroups());
for (EPStructureElementToGroupRelation currentRelation : currentRelations) {
if (currentRelation.isDefaultGroup()) {
continue;
}
boolean inUse = savedPolicies.contains(currentRelation);
if (!inUse) {
map.getGroups().remove(currentRelation);
}
}
return dbInstance.getCurrentEntityManager().merge(map);
}
use of org.olat.portfolio.model.structel.EPStructureElementToGroupRelation in project OpenOLAT by OpenOLAT.
the class EPPolicyManager method applyPolicyToInvitation.
private EPStructureElementToGroupRelation applyPolicyToInvitation(Invitation invitation, EPMapPolicy policy, PortfolioStructureMap map) {
invitation = dbInstance.getCurrentEntityManager().merge(invitation);
Group secGroup = invitation.getBaseGroup();
Collection<EPStructureElementToGroupRelation> currentRelations = map.getGroups();
for (EPStructureElementToGroupRelation currentRelation : currentRelations) {
if (secGroup.equals(currentRelation.getGroup())) {
updatePolicy(currentRelation, policy.getFrom(), policy.getTo());
return currentRelation;
}
}
return createBaseRelation(map, secGroup, EPMapPolicy.Type.invitation.name(), policy.getFrom(), policy.getTo());
}
use of org.olat.portfolio.model.structel.EPStructureElementToGroupRelation in project OpenOLAT by OpenOLAT.
the class EPPolicyManager method getEquivalentWrapper.
private EPMapPolicy getEquivalentWrapper(EPStructureElementToGroupRelation relation, List<EPMapPolicy> policies) {
Date to = relation.getValidTo();
Date from = relation.getValidFrom();
String role = relation.getRole();
a_a: for (EPMapPolicy policy : policies) {
for (EPStructureElementToGroupRelation p : policy.getRelations()) {
if (!role.equals(p.getRole())) {
continue a_a;
}
if (from == null && p.getValidFrom() == null || (from != null && p.getValidFrom() != null && from.equals(p.getValidFrom()))) {
if (to == null && p.getValidTo() == null || (to != null && p.getValidTo() != null && to.equals(p.getValidTo()))) {
return policy;
}
}
}
}
return null;
}
use of org.olat.portfolio.model.structel.EPStructureElementToGroupRelation in project OpenOLAT by OpenOLAT.
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;
}
use of org.olat.portfolio.model.structel.EPStructureElementToGroupRelation in project OpenOLAT by OpenOLAT.
the class EPStructureManager method removeBaseGroup.
private void removeBaseGroup(EPAbstractMap map) {
Set<EPStructureElementToGroupRelation> relations = map.getGroups();
if (relations != null) {
for (EPStructureElementToGroupRelation relation : relations) {
Group group = relation.getGroup();
if (relation.isDefaultGroup()) {
groupDao.removeMemberships(group);
groupDao.removeGroup(group);
}
}
}
}
Aggregations