Search in sources :

Example 1 with BusinessGroupImpl

use of org.olat.group.BusinessGroupImpl in project OpenOLAT by OpenOLAT.

the class OLATUpgrade_9_4_0 method upgradeDisplayMembers.

private boolean upgradeDisplayMembers(UpgradeManager upgradeManager, UpgradeHistoryData uhd) {
    if (!uhd.getBooleanDataValue(TASK_DISPLAY_MEMBERS)) {
        int counter = 0;
        List<BusinessGroupImpl> groups;
        do {
            groups = findGroups(counter, BATCH_SIZE);
            for (BusinessGroupImpl group : groups) {
                Property prop = findProperty(group);
                if (prop != null) {
                    boolean changed = false;
                    Long internValue = prop.getLongValue();
                    if (internValue != null && internValue.longValue() > 0) {
                        long value = internValue.longValue();
                        boolean owners = (value & showOwnersVal) == showOwnersVal;
                        boolean participants = (value & showPartipsVal) == showPartipsVal;
                        boolean waiting = (value & showWaitingListVal) == showWaitingListVal;
                        group.setOwnersVisibleIntern(owners);
                        group.setParticipantsVisibleIntern(participants);
                        group.setWaitingListVisibleIntern(waiting);
                        changed = true;
                    }
                    String publicValue = prop.getStringValue();
                    if (publicValue != null && publicValue.length() > 0 && Character.isDigit(publicValue.toCharArray()[0])) {
                        try {
                            int value = Integer.parseInt(publicValue);
                            boolean owners = (value & showOwnersVal) == showOwnersVal;
                            boolean participants = (value & showPartipsVal) == showPartipsVal;
                            boolean waiting = (value & showWaitingListVal) == showWaitingListVal;
                            group.setOwnersVisiblePublic(owners);
                            group.setParticipantsVisiblePublic(participants);
                            group.setWaitingListVisiblePublic(waiting);
                        } catch (NumberFormatException e) {
                            log.error("", e);
                        }
                        changed = true;
                    }
                    Float downloadValue = prop.getFloatValue();
                    if (downloadValue != null && downloadValue != 0.0f) {
                        float value = downloadValue.floatValue();
                        // paranoid check
                        if (value > 0.9 && value < 1.1) {
                            group.setDownloadMembersLists(true);
                            changed = true;
                        } else if (value < -0.9 && value > -1.1) {
                            group.setDownloadMembersLists(true);
                            changed = true;
                        }
                    }
                    if (changed) {
                        prop.setCategory("configMoved");
                        dbInstance.getCurrentEntityManager().merge(group);
                    }
                }
            }
            counter += groups.size();
            log.audit("Business groups processed: " + groups.size());
            dbInstance.commitAndCloseSession();
        } while (groups.size() == BATCH_SIZE);
        uhd.setBooleanDataValue(TASK_DISPLAY_MEMBERS, true);
        upgradeManager.setUpgradesHistory(uhd, VERSION);
    }
    return true;
}
Also used : BusinessGroupImpl(org.olat.group.BusinessGroupImpl) Property(org.olat.properties.Property)

Example 2 with BusinessGroupImpl

use of org.olat.group.BusinessGroupImpl in project openolat by klemens.

the class BusinessGroupDAO method createAndPersist.

public BusinessGroup createAndPersist(Identity creator, String name, String description, String externalId, String managedFlags, Integer minParticipants, Integer maxParticipants, boolean waitingListEnabled, boolean autoCloseRanksEnabled, boolean showOwners, boolean showParticipants, boolean showWaitingList) {
    BusinessGroupImpl businessgroup = new BusinessGroupImpl(name, description);
    if (minParticipants != null && minParticipants.intValue() >= 0) {
        businessgroup.setMinParticipants(minParticipants);
    }
    if (maxParticipants != null && maxParticipants.intValue() >= 0) {
        businessgroup.setMaxParticipants(maxParticipants);
    }
    if (StringHelper.containsNonWhitespace(externalId)) {
        businessgroup.setExternalId(externalId);
    }
    if (StringHelper.containsNonWhitespace(managedFlags)) {
        businessgroup.setManagedFlagsString(managedFlags);
    }
    businessgroup.setOwnersVisibleIntern(showOwners);
    businessgroup.setParticipantsVisibleIntern(showParticipants);
    businessgroup.setWaitingListVisibleIntern(showWaitingList);
    // group members visibility
    businessgroup.setOwnersVisiblePublic(false);
    businessgroup.setParticipantsVisiblePublic(false);
    businessgroup.setWaitingListVisiblePublic(false);
    businessgroup.setDownloadMembersLists(false);
    if (creator == null) {
        businessgroup.setAllowToLeave(businessGroupModule.isAllowLeavingGroupCreatedByAuthors());
    } else {
        Roles roles = securityManager.getRoles(creator);
        if (roles.isAuthor()) {
            businessgroup.setAllowToLeave(businessGroupModule.isAllowLeavingGroupCreatedByAuthors());
        } else {
            businessgroup.setAllowToLeave(businessGroupModule.isAllowLeavingGroupCreatedByLearners());
        }
    }
    businessgroup.setWaitingListEnabled(waitingListEnabled);
    businessgroup.setAutoCloseRanksEnabled(autoCloseRanksEnabled);
    Group group = groupDao.createGroup();
    businessgroup.setBaseGroup(group);
    if (creator != null) {
        groupDao.addMembershipTwoWay(group, creator, GroupRoles.coach.name());
    }
    EntityManager em = dbInstance.getCurrentEntityManager();
    em.persist(businessgroup);
    OLATResource businessgroupOlatResource = olatResourceManager.createOLATResourceInstance(businessgroup);
    olatResourceManager.saveOLATResource(businessgroupOlatResource);
    businessgroup.setResource(businessgroupOlatResource);
    businessgroup = em.merge(businessgroup);
    // per default all collaboration-tools are disabled
    return businessgroup;
}
Also used : Group(org.olat.basesecurity.Group) BusinessGroup(org.olat.group.BusinessGroup) EntityManager(javax.persistence.EntityManager) OLATResource(org.olat.resource.OLATResource) GroupRoles(org.olat.basesecurity.GroupRoles) Roles(org.olat.core.id.Roles) BusinessGroupImpl(org.olat.group.BusinessGroupImpl)

Example 3 with BusinessGroupImpl

use of org.olat.group.BusinessGroupImpl in project openolat by klemens.

the class BusinessGroupRelationDAOTest method addRelation_v2.

@Test
public void addRelation_v2() {
    // create a relation
    Identity coach = JunitTestHelper.createAndPersistIdentityAsRndUser("grp-v2-");
    BusinessGroup businessGroup = businessGroupDao.createAndPersist(null, "gdbo", "gdbo-desc", -1, -1, false, false, false, false, false);
    dbInstance.commitAndCloseSession();
    Group group = ((BusinessGroupImpl) businessGroup).getBaseGroup();
    groupDao.addMembershipTwoWay(group, coach, "coach");
    dbInstance.commitAndCloseSession();
    List<String> roles = businessGroupRelationDao.getRoles(coach, businessGroup);
    Assert.assertNotNull(roles);
    Assert.assertEquals(1, roles.size());
    dbInstance.commitAndCloseSession();
    businessGroupRelationDao.addRole(coach, businessGroup, "participant");
    dbInstance.commitAndCloseSession();
    List<String> multiRoles = businessGroupRelationDao.getRoles(coach, businessGroup);
    Assert.assertNotNull(multiRoles);
    Assert.assertEquals(2, multiRoles.size());
    dbInstance.commitAndCloseSession();
    businessGroupRelationDao.removeRole(coach, businessGroup, "participant");
    List<String> reducedRoles = businessGroupRelationDao.getRoles(coach, businessGroup);
    Assert.assertNotNull(reducedRoles);
    Assert.assertEquals(1, reducedRoles.size());
    Assert.assertEquals("coach", reducedRoles.get(0));
    dbInstance.commitAndCloseSession();
    int numOfCoaches = businessGroupRelationDao.countRoles(businessGroup, GroupRoles.coach.name());
    Assert.assertEquals(1, numOfCoaches);
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) Group(org.olat.basesecurity.Group) BusinessGroup(org.olat.group.BusinessGroup) Identity(org.olat.core.id.Identity) BusinessGroupImpl(org.olat.group.BusinessGroupImpl) Test(org.junit.Test)

Example 4 with BusinessGroupImpl

use of org.olat.group.BusinessGroupImpl in project OpenOLAT by OpenOLAT.

the class BusinessGroupRelationDAOTest method addRelation_v2.

@Test
public void addRelation_v2() {
    // create a relation
    Identity coach = JunitTestHelper.createAndPersistIdentityAsRndUser("grp-v2-");
    BusinessGroup businessGroup = businessGroupDao.createAndPersist(null, "gdbo", "gdbo-desc", -1, -1, false, false, false, false, false);
    dbInstance.commitAndCloseSession();
    Group group = ((BusinessGroupImpl) businessGroup).getBaseGroup();
    groupDao.addMembershipTwoWay(group, coach, "coach");
    dbInstance.commitAndCloseSession();
    List<String> roles = businessGroupRelationDao.getRoles(coach, businessGroup);
    Assert.assertNotNull(roles);
    Assert.assertEquals(1, roles.size());
    dbInstance.commitAndCloseSession();
    businessGroupRelationDao.addRole(coach, businessGroup, "participant");
    dbInstance.commitAndCloseSession();
    List<String> multiRoles = businessGroupRelationDao.getRoles(coach, businessGroup);
    Assert.assertNotNull(multiRoles);
    Assert.assertEquals(2, multiRoles.size());
    dbInstance.commitAndCloseSession();
    businessGroupRelationDao.removeRole(coach, businessGroup, "participant");
    List<String> reducedRoles = businessGroupRelationDao.getRoles(coach, businessGroup);
    Assert.assertNotNull(reducedRoles);
    Assert.assertEquals(1, reducedRoles.size());
    Assert.assertEquals("coach", reducedRoles.get(0));
    dbInstance.commitAndCloseSession();
    int numOfCoaches = businessGroupRelationDao.countRoles(businessGroup, GroupRoles.coach.name());
    Assert.assertEquals(1, numOfCoaches);
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) Group(org.olat.basesecurity.Group) BusinessGroup(org.olat.group.BusinessGroup) Identity(org.olat.core.id.Identity) BusinessGroupImpl(org.olat.group.BusinessGroupImpl) Test(org.junit.Test)

Example 5 with BusinessGroupImpl

use of org.olat.group.BusinessGroupImpl in project OpenOLAT by OpenOLAT.

the class BusinessGroupDAO method createAndPersist.

public BusinessGroup createAndPersist(Identity creator, String name, String description, String externalId, String managedFlags, Integer minParticipants, Integer maxParticipants, boolean waitingListEnabled, boolean autoCloseRanksEnabled, boolean showOwners, boolean showParticipants, boolean showWaitingList) {
    BusinessGroupImpl businessgroup = new BusinessGroupImpl(name, description);
    if (minParticipants != null && minParticipants.intValue() >= 0) {
        businessgroup.setMinParticipants(minParticipants);
    }
    if (maxParticipants != null && maxParticipants.intValue() >= 0) {
        businessgroup.setMaxParticipants(maxParticipants);
    }
    if (StringHelper.containsNonWhitespace(externalId)) {
        businessgroup.setExternalId(externalId);
    }
    if (StringHelper.containsNonWhitespace(managedFlags)) {
        businessgroup.setManagedFlagsString(managedFlags);
    }
    businessgroup.setOwnersVisibleIntern(showOwners);
    businessgroup.setParticipantsVisibleIntern(showParticipants);
    businessgroup.setWaitingListVisibleIntern(showWaitingList);
    // group members visibility
    businessgroup.setOwnersVisiblePublic(false);
    businessgroup.setParticipantsVisiblePublic(false);
    businessgroup.setWaitingListVisiblePublic(false);
    businessgroup.setDownloadMembersLists(false);
    if (creator == null) {
        businessgroup.setAllowToLeave(businessGroupModule.isAllowLeavingGroupCreatedByAuthors());
    } else {
        Roles roles = securityManager.getRoles(creator);
        if (roles.isAuthor()) {
            businessgroup.setAllowToLeave(businessGroupModule.isAllowLeavingGroupCreatedByAuthors());
        } else {
            businessgroup.setAllowToLeave(businessGroupModule.isAllowLeavingGroupCreatedByLearners());
        }
    }
    businessgroup.setWaitingListEnabled(waitingListEnabled);
    businessgroup.setAutoCloseRanksEnabled(autoCloseRanksEnabled);
    Group group = groupDao.createGroup();
    businessgroup.setBaseGroup(group);
    if (creator != null) {
        groupDao.addMembershipTwoWay(group, creator, GroupRoles.coach.name());
    }
    EntityManager em = dbInstance.getCurrentEntityManager();
    em.persist(businessgroup);
    OLATResource businessgroupOlatResource = olatResourceManager.createOLATResourceInstance(businessgroup);
    olatResourceManager.saveOLATResource(businessgroupOlatResource);
    businessgroup.setResource(businessgroupOlatResource);
    businessgroup = em.merge(businessgroup);
    // per default all collaboration-tools are disabled
    return businessgroup;
}
Also used : Group(org.olat.basesecurity.Group) BusinessGroup(org.olat.group.BusinessGroup) EntityManager(javax.persistence.EntityManager) OLATResource(org.olat.resource.OLATResource) GroupRoles(org.olat.basesecurity.GroupRoles) Roles(org.olat.core.id.Roles) BusinessGroupImpl(org.olat.group.BusinessGroupImpl)

Aggregations

BusinessGroupImpl (org.olat.group.BusinessGroupImpl)6 Group (org.olat.basesecurity.Group)4 BusinessGroup (org.olat.group.BusinessGroup)4 EntityManager (javax.persistence.EntityManager)2 Test (org.junit.Test)2 GroupRoles (org.olat.basesecurity.GroupRoles)2 Identity (org.olat.core.id.Identity)2 Roles (org.olat.core.id.Roles)2 Property (org.olat.properties.Property)2 OLATResource (org.olat.resource.OLATResource)2