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;
}
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;
}
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);
}
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);
}
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;
}
Aggregations