Search in sources :

Example 11 with RepositoryEntryToGroupRelation

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;
}
Also used : RepositoryEntry(org.olat.repository.RepositoryEntry) Date(java.util.Date) RepositoryEntryToGroupRelation(org.olat.repository.model.RepositoryEntryToGroupRelation)

Example 12 with RepositoryEntryToGroupRelation

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;
}
Also used : EntityManager(javax.persistence.EntityManager) RepositoryEntryToGroupRelation(org.olat.repository.model.RepositoryEntryToGroupRelation)

Example 13 with RepositoryEntryToGroupRelation

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;
}
Also used : RepositoryEntryStatistics(org.olat.repository.model.RepositoryEntryStatistics) Group(org.olat.basesecurity.Group) OLATResourceable(org.olat.core.id.OLATResourceable) RepositoryEntry(org.olat.repository.RepositoryEntry) Date(java.util.Date) RepositoryEntryToGroupRelation(org.olat.repository.model.RepositoryEntryToGroupRelation) HashSet(java.util.HashSet)

Example 14 with RepositoryEntryToGroupRelation

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;
}
Also used : RepositoryEntry(org.olat.repository.RepositoryEntry) Date(java.util.Date) RepositoryEntryToGroupRelation(org.olat.repository.model.RepositoryEntryToGroupRelation)

Example 15 with RepositoryEntryToGroupRelation

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;
}
Also used : RepositoryEntry(org.olat.repository.RepositoryEntry) RepositoryEntryToGroupRelation(org.olat.repository.model.RepositoryEntryToGroupRelation)

Aggregations

RepositoryEntryToGroupRelation (org.olat.repository.model.RepositoryEntryToGroupRelation)28 RepositoryEntry (org.olat.repository.RepositoryEntry)16 Group (org.olat.basesecurity.Group)12 Date (java.util.Date)10 BusinessGroup (org.olat.group.BusinessGroup)10 Test (org.junit.Test)8 Identity (org.olat.core.id.Identity)8 EntityManager (javax.persistence.EntityManager)6 Calendar (java.util.Calendar)4 GroupMembershipImpl (org.olat.basesecurity.model.GroupMembershipImpl)4 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 SecurityGroup (org.olat.basesecurity.SecurityGroup)2 OLATResourceable (org.olat.core.id.OLATResourceable)2 RepositoryEntryStatistics (org.olat.repository.model.RepositoryEntryStatistics)2