Search in sources :

Example 1 with RepositoryEntryToGroupRelation

use of org.olat.repository.model.RepositoryEntryToGroupRelation in project OpenOLAT by OpenOLAT.

the class GTAReminderRuleTest method addEnrollmentDate.

private void addEnrollmentDate(RepositoryEntry entry, Identity id, GroupRoles role, int amount, int field) {
    RepositoryEntryToGroupRelation rel = entry.getGroups().iterator().next();
    rel.getGroup();
    Calendar cal = Calendar.getInstance();
    cal.setTime(new Date());
    cal.add(field, amount);
    GroupMembershipImpl membership = new GroupMembershipImpl();
    membership.setCreationDate(cal.getTime());
    membership.setLastModified(cal.getTime());
    membership.setGroup(rel.getGroup());
    membership.setIdentity(id);
    membership.setRole(role.name());
    dbInstance.getCurrentEntityManager().persist(membership);
    dbInstance.commit();
}
Also used : Calendar(java.util.Calendar) Date(java.util.Date) GroupMembershipImpl(org.olat.basesecurity.model.GroupMembershipImpl) RepositoryEntryToGroupRelation(org.olat.repository.model.RepositoryEntryToGroupRelation)

Example 2 with RepositoryEntryToGroupRelation

use of org.olat.repository.model.RepositoryEntryToGroupRelation in project OpenOLAT by OpenOLAT.

the class ReminderRuleEngineTest method addEnrollmentDate.

private void addEnrollmentDate(RepositoryEntry entry, Identity id, GroupRoles role, int amount, int field) {
    RepositoryEntryToGroupRelation rel = entry.getGroups().iterator().next();
    rel.getGroup();
    Calendar cal = Calendar.getInstance();
    cal.setTime(new Date());
    cal.add(field, amount);
    GroupMembershipImpl membership = new GroupMembershipImpl();
    membership.setCreationDate(cal.getTime());
    membership.setLastModified(cal.getTime());
    membership.setGroup(rel.getGroup());
    membership.setIdentity(id);
    membership.setRole(role.name());
    dbInstance.getCurrentEntityManager().persist(membership);
    dbInstance.commit();
}
Also used : Calendar(java.util.Calendar) Date(java.util.Date) GroupMembershipImpl(org.olat.basesecurity.model.GroupMembershipImpl) RepositoryEntryToGroupRelation(org.olat.repository.model.RepositoryEntryToGroupRelation)

Example 3 with RepositoryEntryToGroupRelation

use of org.olat.repository.model.RepositoryEntryToGroupRelation in project OpenOLAT by OpenOLAT.

the class RepositoryEntryRelationDAOTest method removeRelation_byGroup.

@Test
public void removeRelation_byGroup() {
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("re-member-lc-" + UUID.randomUUID().toString());
    RepositoryEntry re1 = JunitTestHelper.createAndPersistRepositoryEntry();
    RepositoryEntry re2 = JunitTestHelper.createAndPersistRepositoryEntry();
    BusinessGroup group = businessGroupService.createBusinessGroup(null, "remove relation by group", "tg", null, null, false, false, re1);
    businessGroupRelationDao.addRole(id, group, GroupRoles.coach.name());
    businessGroupService.addResourceTo(group, re2);
    dbInstance.commitAndCloseSession();
    int numOfRelations = repositoryEntryRelationDao.removeRelation(group.getBaseGroup());
    Assert.assertEquals(2, numOfRelations);
    dbInstance.commitAndCloseSession();
    List<Group> groups = Collections.singletonList(group.getBaseGroup());
    List<RepositoryEntryToGroupRelation> relations = repositoryEntryRelationDao.getRelations(groups);
    Assert.assertEquals(0, relations.size());
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) Group(org.olat.basesecurity.Group) BusinessGroup(org.olat.group.BusinessGroup) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) RepositoryEntryToGroupRelation(org.olat.repository.model.RepositoryEntryToGroupRelation) Test(org.junit.Test)

Example 4 with RepositoryEntryToGroupRelation

use of org.olat.repository.model.RepositoryEntryToGroupRelation in project OpenOLAT by OpenOLAT.

the class RepositoryEntryRelationDAO method removeRelation.

public int removeRelation(Group group, RepositoryEntryRef re) {
    EntityManager em = dbInstance.getCurrentEntityManager();
    List<RepositoryEntryToGroupRelation> rels = em.createNamedQuery("relationByRepositoryEntryAndGroup", RepositoryEntryToGroupRelation.class).setParameter("repoKey", re.getKey()).setParameter("groupKey", group.getKey()).getResultList();
    for (RepositoryEntryToGroupRelation rel : rels) {
        em.remove(rel);
    }
    return rels.size();
}
Also used : EntityManager(javax.persistence.EntityManager) RepositoryEntryToGroupRelation(org.olat.repository.model.RepositoryEntryToGroupRelation)

Example 5 with RepositoryEntryToGroupRelation

use of org.olat.repository.model.RepositoryEntryToGroupRelation in project OpenOLAT by OpenOLAT.

the class RepositoryEntryRelationDAO method removeRelations.

/**
 * This will remove all relations from the repository entry,
 * the default one too.
 *
 * @param re
 * @return
 */
public int removeRelations(RepositoryEntryRef re) {
    EntityManager em = dbInstance.getCurrentEntityManager();
    List<RepositoryEntryToGroupRelation> rels = em.createNamedQuery("relationByRepositoryEntry", RepositoryEntryToGroupRelation.class).setParameter("repoKey", re.getKey()).getResultList();
    for (RepositoryEntryToGroupRelation rel : rels) {
        em.remove(rel);
    }
    return rels.size();
}
Also used : EntityManager(javax.persistence.EntityManager) 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