use of org.olat.group.model.BusinessGroupReference in project OpenOLAT by OpenOLAT.
the class KeyAndNameConverterTest method convertBusinessGroupKeyToKey.
@Test
public void convertBusinessGroupKeyToKey() {
CourseEnvironmentMapper envMapper = new CourseEnvironmentMapper();
MockBusinessGroup newGroup = new MockBusinessGroup(567l, "Group 1");
BusinessGroupReference bgRef = new BusinessGroupReference(newGroup, 345l, "Group 1");
envMapper.getGroups().add(bgRef);
String convertedExp = convertExpressionKeyToKey("inRightGroup(\"345\")", envMapper);
Assert.assertEquals("inRightGroup(\"567\")", convertedExp);
}
use of org.olat.group.model.BusinessGroupReference in project OpenOLAT by OpenOLAT.
the class KeyAndNameConverterTest method convertGroupAndAreaKeyToKey_sameKey.
@Test
public void convertGroupAndAreaKeyToKey_sameKey() {
CourseEnvironmentMapper envMapper = new CourseEnvironmentMapper();
BGArea newArea = new MockArea(567l, "Area 1");
BGAreaReference areaRef = new BGAreaReference(newArea, 345l, "Area 1");
envMapper.getAreas().add(areaRef);
MockBusinessGroup newGroup = new MockBusinessGroup(568l, "Group 1");
BusinessGroupReference bgRef = new BusinessGroupReference(newGroup, 345l, "Group 1");
envMapper.getGroups().add(bgRef);
String convertedExp = convertExpressionKeyToKey("inLearningArea(\"345\") & inRightGroup(\"345\")", envMapper);
Assert.assertEquals("inLearningArea(\"567\") & inRightGroup(\"568\")", convertedExp);
}
use of org.olat.group.model.BusinessGroupReference in project OpenOLAT by OpenOLAT.
the class KeyAndNameConverterTest method convertGroupAndAreaNameToKey_sameName.
/**
* Test with same name for area and group
*/
@Test
public void convertGroupAndAreaNameToKey_sameName() {
CourseEnvironmentMapper envMapper = new CourseEnvironmentMapper();
BGArea newArea = new MockArea(567l, "Test 1");
BGAreaReference areaRef = new BGAreaReference(newArea, 345l, "Test 1");
envMapper.getAreas().add(areaRef);
MockBusinessGroup newGroup = new MockBusinessGroup(568l, "Test 1");
BusinessGroupReference bgRef = new BusinessGroupReference(newGroup, 346l, "Test 1");
envMapper.getGroups().add(bgRef);
String convertedExp = convertExpressionNameToKey("inLearningArea(\"Test 1\") & inLearningGroup(\"Test 1\")", envMapper);
Assert.assertEquals("inLearningArea(\"567\") & inLearningGroup(\"568\")", convertedExp);
}
use of org.olat.group.model.BusinessGroupReference in project OpenOLAT by OpenOLAT.
the class KeyAndNameConverterTest method convertGroupAndAreaKeyToName_sameKey.
@Test
public void convertGroupAndAreaKeyToName_sameKey() {
CourseEnvironmentMapper envMapper = new CourseEnvironmentMapper();
BGArea newArea = new MockArea(567l, "Area 1");
BGAreaReference areaRef = new BGAreaReference(newArea, null, null);
envMapper.getAreas().add(areaRef);
MockBusinessGroup newGroup = new MockBusinessGroup(567l, "Group 1");
BusinessGroupReference bgRef = new BusinessGroupReference(newGroup, null, null);
envMapper.getGroups().add(bgRef);
String convertedExp = convertExpressionKeyToName("inLearningArea(\"567\") & isLearningGroupFull(\"567\")", envMapper);
Assert.assertEquals("inLearningArea(\"Area 1\") & isLearningGroupFull(\"Group 1\")", convertedExp);
}
use of org.olat.group.model.BusinessGroupReference in project OpenOLAT by OpenOLAT.
the class ProjectBrokerCourseNode method importProject.
private void importProject(File projectDir, File projectFile, ProjectBroker projectBroker, ICourse course, CourseEnvironmentMapper envMapper) {
XStream xstream = XStreamHelper.createXStreamInstance();
BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
CoursePropertyManager cpm = course.getCourseEnvironment().getCoursePropertyManager();
ProjectGroupManager projectGroupManager = CoreSpringFactory.getImpl(ProjectGroupManager.class);
ProjectBrokerManager projectBrokerManager = CoreSpringFactory.getImpl(ProjectBrokerManager.class);
// read the projectConfiguration from the importDirectory
try {
@SuppressWarnings("unchecked") Map<String, Object> projectConfig = (HashMap<String, Object>) XStreamHelper.readObject(xstream, projectFile);
String projectTitle = (String) projectConfig.get("title");
Long originalGroupKey = null;
if (projectConfig.containsKey("businessGroupKey")) {
originalGroupKey = (Long) projectConfig.get("businessGroupKey");
} else {
for (BusinessGroupReference ref : envMapper.getGroups()) {
if (ref.getName().endsWith(projectTitle)) {
originalGroupKey = ref.getOriginalKey();
}
}
}
BusinessGroup projectGroup = null;
if (originalGroupKey != null) {
Long groupKey = envMapper.toGroupKeyFromOriginalKey(originalGroupKey);
projectGroup = bgs.loadBusinessGroup(groupKey);
}
if (projectGroup == null) {
projectGroup = projectGroupManager.createProjectGroupFor(projectBroker.getKey(), envMapper.getAuthor(), projectTitle, (String) projectConfig.get("description"), course.getResourceableId());
}
if (envMapper.getAuthor() != null) {
Identity author = envMapper.getAuthor();
bgs.addOwners(author, null, Collections.singletonList(author), projectGroup, null);
}
Project project = projectBrokerManager.createAndSaveProjectFor(projectTitle, (String) projectConfig.get("description"), projectBrokerManager.getProjectBrokerId(cpm, this), projectGroup);
projectGroupManager.setDeselectionAllowed(project, (boolean) projectConfig.get("allowDeselection"));
project.setMailNotificationEnabled((boolean) projectConfig.get("mailNotificationEnabled"));
project.setMaxMembers((int) projectConfig.get("maxMembers"));
project.setAttachedFileName(projectConfig.get("attachmentFileName").toString());
for (int i = 0; i < (int) projectConfig.get("customeFieldSize"); i++) {
project.setCustomFieldValue(i, projectConfig.get("customFieldValue" + i).toString());
}
projectBrokerManager.updateProject(project);
// get the attachment directory within the project
// directory
// .getParentFile().listFiles(attachmentFilter);
File attachmentDir = new File(projectDir, "attachment");
if (attachmentDir.exists()) {
File[] attachment = attachmentDir.listFiles();
if (attachment.length > 0) {
VFSLeaf attachmentLeaf = new LocalFileImpl(attachment[0]);
projectBrokerManager.saveAttachedFile(project, projectConfig.get("attachmentFileName").toString(), attachmentLeaf, course.getCourseEnvironment(), this);
}
}
} catch (Exception e) {
// handle/log error in case of FileIO exception or cast
// exception if import input is not correct
log.error("Error while importing a project into projectbroker", e);
}
}
Aggregations