use of org.olat.repository.model.RepositoryEntryToGroupRelation in project openolat by klemens.
the class RepositoryServiceImpl method deleteSoftly.
@Override
public RepositoryEntry deleteSoftly(RepositoryEntry re, Identity deletedBy, boolean owners) {
RepositoryEntry reloadedRe = repositoryEntryDAO.loadForUpdate(re);
reloadedRe.setAccess(RepositoryEntry.DELETED);
if (reloadedRe.getDeletionDate() == null) {
// don't write the name of an admin which make a restore -> delete operation
reloadedRe.setDeletedBy(deletedBy);
reloadedRe.setDeletionDate(new Date());
}
reloadedRe = dbInstance.getCurrentEntityManager().merge(reloadedRe);
dbInstance.commit();
// remove from catalog
catalogManager.resourceableDeleted(reloadedRe);
// remove participant and coach
if (owners) {
removeMembers(reloadedRe, GroupRoles.owner.name(), GroupRoles.coach.name(), GroupRoles.participant.name(), GroupRoles.waiting.name());
} else {
removeMembers(reloadedRe, GroupRoles.coach.name(), GroupRoles.participant.name(), GroupRoles.waiting.name());
}
// remove relation to business groups
List<RepositoryEntryToGroupRelation> relations = reToGroupDao.getRelations(reloadedRe);
for (RepositoryEntryToGroupRelation relation : relations) {
if (!relation.isDefaultGroup()) {
reToGroupDao.removeRelation(relation);
}
}
dbInstance.commit();
return reloadedRe;
}
use of org.olat.repository.model.RepositoryEntryToGroupRelation in project OpenOLAT by OpenOLAT.
the class RepositoryEntryRelationDAO method removeRelation.
public int removeRelation(Group group) {
EntityManager em = dbInstance.getCurrentEntityManager();
List<RepositoryEntryToGroupRelation> rels = em.createNamedQuery("relationByGroup", RepositoryEntryToGroupRelation.class).setParameter("groupKey", group.getKey()).getResultList();
int count = 0;
for (RepositoryEntryToGroupRelation rel : rels) {
if (!rel.isDefaultGroup()) {
em.remove(rel);
count++;
}
}
return count;
}
use of org.olat.repository.model.RepositoryEntryToGroupRelation 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;
}
use of org.olat.repository.model.RepositoryEntryToGroupRelation in project OpenOLAT by OpenOLAT.
the class RepositoryServiceImpl method deleteSoftly.
@Override
public RepositoryEntry deleteSoftly(RepositoryEntry re, Identity deletedBy, boolean owners) {
RepositoryEntry reloadedRe = repositoryEntryDAO.loadForUpdate(re);
reloadedRe.setAccess(RepositoryEntry.DELETED);
if (reloadedRe.getDeletionDate() == null) {
// don't write the name of an admin which make a restore -> delete operation
reloadedRe.setDeletedBy(deletedBy);
reloadedRe.setDeletionDate(new Date());
}
reloadedRe = dbInstance.getCurrentEntityManager().merge(reloadedRe);
dbInstance.commit();
// remove from catalog
catalogManager.resourceableDeleted(reloadedRe);
// remove participant and coach
if (owners) {
removeMembers(reloadedRe, GroupRoles.owner.name(), GroupRoles.coach.name(), GroupRoles.participant.name(), GroupRoles.waiting.name());
} else {
removeMembers(reloadedRe, GroupRoles.coach.name(), GroupRoles.participant.name(), GroupRoles.waiting.name());
}
// remove relation to business groups
List<RepositoryEntryToGroupRelation> relations = reToGroupDao.getRelations(reloadedRe);
for (RepositoryEntryToGroupRelation relation : relations) {
if (!relation.isDefaultGroup()) {
reToGroupDao.removeRelation(relation);
}
}
dbInstance.commit();
return reloadedRe;
}
use of org.olat.repository.model.RepositoryEntryToGroupRelation in project OpenOLAT by OpenOLAT.
the class RepositoryServiceImpl method unpublishRepositoryEntry.
@Override
public RepositoryEntry unpublishRepositoryEntry(RepositoryEntry entry) {
RepositoryEntry reloadedEntry = repositoryEntryDAO.loadForUpdate(entry);
reloadedEntry.setStatusCode(RepositoryEntryStatus.REPOSITORY_STATUS_UNPUBLISHED);
reloadedEntry = dbInstance.getCurrentEntityManager().merge(reloadedEntry);
dbInstance.commit();
// remove catalog entries
catalogManager.resourceableDeleted(reloadedEntry);
// remove users and participants
// remove participant and coach
removeMembers(reloadedEntry, GroupRoles.coach.name(), GroupRoles.participant.name(), GroupRoles.waiting.name());
// remove relation to business groups
List<RepositoryEntryToGroupRelation> relations = reToGroupDao.getRelations(reloadedEntry);
for (RepositoryEntryToGroupRelation relation : relations) {
if (!relation.isDefaultGroup()) {
reToGroupDao.removeRelation(relation);
}
}
return reloadedEntry;
}
Aggregations