use of org.olat.basesecurity.Group in project OpenOLAT by OpenOLAT.
the class EPStructureManager method importPortfolioMapTemplate.
/**
* Import the structure.
* @param root
* @param identity
* @return
*/
public PortfolioStructureMap importPortfolioMapTemplate(PortfolioStructure root, OLATResource resource) {
EPStructuredMapTemplate el = new EPStructuredMapTemplate();
fillStructureElement(el, root.getTitle(), root.getDescription(), resource);
EPStructuredMapTemplate rootTemp = (EPStructuredMapTemplate) root;
rootTemp.setStructureElSource(null);
el.setStyle(((EPStructureElement) root).getStyle());
importEPStructureElementRecursively((EPStructureElement) root, el);
// create an empty group
Group ownerGroup = groupDao.createGroup();
EPStructureElementToGroupRelation relation = createBaseRelation(el, ownerGroup);
Set<EPStructureElementToGroupRelation> relations = new HashSet<>();
relations.add(relation);
el.setGroups(relations);
return el;
}
use of org.olat.basesecurity.Group 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.basesecurity.Group in project OpenOLAT by OpenOLAT.
the class InvitationDAO method createAndPersistInvitation.
/**
* Create and persist an invitation with its security group and security token.
* @return
*/
public Invitation createAndPersistInvitation() {
Group group = groupDao.createGroup();
InvitationImpl invitation = new InvitationImpl();
invitation.setToken(UUID.randomUUID().toString());
invitation.setBaseGroup(group);
dbInstance.getCurrentEntityManager().persist(invitation);
return invitation;
}
use of org.olat.basesecurity.Group in project OpenOLAT by OpenOLAT.
the class RepositoryEntryRelationDAO method addRole.
public void addRole(Identity identity, RepositoryEntryRef re, String role) {
Group group = getDefaultGroup(re);
groupDao.addMembershipOneWay(group, identity, role);
}
use of org.olat.basesecurity.Group in project OpenOLAT by OpenOLAT.
the class RepositoryServiceImpl method create.
private RepositoryEntry create(String initialAuthorName, Identity initialAuthor, String resourceName, String displayname, String description, OLATResource resource, int access) {
Date now = new Date();
RepositoryEntry re = new RepositoryEntry();
if (StringHelper.containsNonWhitespace(initialAuthorName)) {
re.setInitialAuthor(initialAuthorName);
} else if (initialAuthor != null) {
re.setInitialAuthor(initialAuthor.getName());
} else {
re.setInitialAuthor("-");
}
re.setCreationDate(now);
re.setLastModified(now);
re.setAccess(access);
re.setCanDownload(false);
re.setCanCopy(false);
re.setCanReference(false);
re.setCanLaunch(true);
re.setDisplayname(displayname);
re.setResourcename(StringHelper.containsNonWhitespace(resourceName) ? resourceName : "-");
re.setDescription(description == null ? "" : description);
re.setAllowToLeaveOption(repositoryModule.getAllowToLeaveDefaultOption());
if (resource == null) {
OLATResourceable ores = OresHelper.createOLATResourceableInstance("RepositoryEntry", CodeHelper.getForeverUniqueID());
resource = resourceManager.createAndPersistOLATResourceInstance(ores);
} else if (resource != null && resource.getKey() == null) {
dbInstance.getCurrentEntityManager().persist(resource);
}
re.setOlatResource(resource);
RepositoryEntryStatistics statistics = new RepositoryEntryStatistics();
statistics.setLastUsage(now);
statistics.setCreationDate(now);
statistics.setLastModified(now);
statistics.setDownloadCounter(0l);
statistics.setLaunchCounter(0l);
statistics.setNumOfRatings(0l);
statistics.setNumOfComments(0l);
dbInstance.getCurrentEntityManager().persist(statistics);
re.setStatistics(statistics);
Group group = groupDao.createGroup();
RepositoryEntryToGroupRelation rel = new RepositoryEntryToGroupRelation();
rel.setCreationDate(new Date());
rel.setDefaultGroup(true);
rel.setGroup(group);
rel.setEntry(re);
Set<RepositoryEntryToGroupRelation> rels = new HashSet<>(2);
rels.add(rel);
re.setGroups(rels);
if (initialAuthor != null) {
groupDao.addMembershipTwoWay(group, initialAuthor, GroupRoles.owner.name());
}
dbInstance.getCurrentEntityManager().persist(re);
autoAccessManager.grantAccess(re);
return re;
}
Aggregations