use of org.olat.course.nodes.projectbroker.datamodel.Project in project openolat by klemens.
the class ProjectBrokerCourseNode method postCopy.
/**
* Do re-arrange the projects in a new project broker after the copy happened
*/
@Override
public void postCopy(CourseEnvironmentMapper envMapper, Processing processType, ICourse course, ICourse sourceCourse) {
super.postCopy(envMapper, processType, course, null);
if (processType.equals(Processing.runstructure)) {
// initialize the managers and services
ProjectBrokerManager projectBrokerManager = CoreSpringFactory.getImpl(ProjectBrokerManager.class);
ProjectGroupManager projectGroupManager = CoreSpringFactory.getImpl(ProjectGroupManager.class);
CoursePropertyManager oldCpm = sourceCourse.getCourseEnvironment().getCoursePropertyManager();
BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
// create new Project broker and get the old one
Long projectBrokerId = projectBrokerManager.createAndSaveProjectBroker().getKey();
projectBrokerManager.saveProjectBrokerId(projectBrokerId, course.getCourseEnvironment().getCoursePropertyManager(), this);
// find the group for account manager and remap the account group
CourseNode sourceCourseNode = sourceCourse.getRunStructure().getNode(getIdent());
Long sourceAccountGroupKey = projectGroupManager.getAccountManagerGroupKey(oldCpm, sourceCourseNode);
if (sourceAccountGroupKey != null) {
Long copiedGroupKey = envMapper.toGroupKeyFromOriginalKey(sourceAccountGroupKey);
CoursePropertyManager cpm = course.getCourseEnvironment().getCoursePropertyManager();
projectGroupManager.saveAccountManagerGroupKey(copiedGroupKey, cpm, this);
}
Long oldBrokerId = projectBrokerManager.getProjectBrokerId(oldCpm, this);
List<Project> projectsFromGroup = projectBrokerManager.getProjectListBy(oldBrokerId);
// loop create and configure the new Projects
for (Project project : projectsFromGroup) {
Long originalGroupKey = project.getProjectGroup().getKey();
Long copiedGroupKey = envMapper.toGroupKeyFromOriginalKey(originalGroupKey);
Identity author = envMapper.getAuthor();
BusinessGroup projectGroup = bgs.loadBusinessGroup(copiedGroupKey);
if (projectGroup == null) {
projectGroup = projectGroupManager.createProjectGroupFor(projectBrokerId, author, project.getTitle(), project.getDescription(), course.getResourceableId());
}
if (author != null) {
bgs.addOwners(author, null, Collections.singletonList(author), projectGroup, null);
}
Project newProject = projectBrokerManager.createAndSaveProjectFor(project.getTitle(), project.getDescription(), projectBrokerId, projectGroup);
// copy all project configurations
newProject.setMailNotificationEnabled(project.isMailNotificationEnabled());
newProject.setMaxMembers(project.getMaxMembers());
for (int i = 0; i < project.getCustomFieldSize(); i++) {
newProject.setCustomFieldValue(i, project.getCustomFieldValue(i));
}
projectGroupManager.setDeselectionAllowed(newProject, project.getProjectGroup().isAllowToLeave());
projectBrokerManager.updateProject(newProject);
// attachment file
OlatRootFolderImpl rootFolder = new OlatRootFolderImpl(projectBrokerManager.getAttamchmentRelativeRootPath(project, sourceCourse.getCourseEnvironment(), this), null);
VFSItem item = rootFolder.resolve(project.getAttachmentFileName());
if (item instanceof VFSLeaf) {
projectBrokerManager.saveAttachedFile(newProject, project.getAttachmentFileName(), (VFSLeaf) item, course.getCourseEnvironment(), this);
newProject.setAttachedFileName(project.getAttachmentFileName());
projectBrokerManager.updateProject(newProject);
}
}
}
}
use of org.olat.course.nodes.projectbroker.datamodel.Project in project openolat by klemens.
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);
}
}
use of org.olat.course.nodes.projectbroker.datamodel.Project in project OpenOLAT by OpenOLAT.
the class ProjectBrokerManagerTest method testCreateListDeleteProjects.
@Test
public void testCreateListDeleteProjects() throws Exception {
// create ProjectBroker A + B
ProjectBroker projectBrokerA = projectBrokerManager.createAndSaveProjectBroker();
Long idProjectBrokerA = projectBrokerA.getKey();
ProjectBroker projectBrokerB = projectBrokerManager.createAndSaveProjectBroker();
Long idProjectBrokerB = projectBrokerB.getKey();
// add project to ProjectBroker A
createProject("thema A1", id1, idProjectBrokerA, resourceableId);
createProject("thema A2", id1, idProjectBrokerA, resourceableId);
// add project to ProjectBroker B
createProject("thema B1", id1, idProjectBrokerB, resourceableId);
createProject("thema B2", id1, idProjectBrokerB, resourceableId);
dbInstance.commitAndCloseSession();
// get project list and check content
List<Project> projectListA = projectBrokerManager.getProjectListBy(idProjectBrokerA);
assertEquals("Wrong projectList.size for project-broker A", 2, projectListA.size());
assertTrue("Wrong thema in project list A, title must start with 'thema A'", projectListA.get(0).getTitle().startsWith("thema A"));
assertTrue("Wrong thema in project list A, title must start with 'thema A'", projectListA.get(1).getTitle().startsWith("thema A"));
List<Project> projectListB = projectBrokerManager.getProjectListBy(idProjectBrokerB);
assertEquals("Wrong projectList.size for project-broker B", 2, projectListB.size());
assertTrue("Wrong thema in project list B, title must start with 'thema B'", projectListB.get(0).getTitle().startsWith("thema B"));
assertTrue("Wrong thema in project list B, title must start with 'thema B'", projectListB.get(1).getTitle().startsWith("thema B"));
if (projectListA.get(0).getTitle().equals("thema A1")) {
assertTrue("Wrong thema in project list A, title must be 'thema A2'", projectListA.get(1).getTitle().equals("thema A2"));
} else if (projectListA.get(0).getTitle().equals("thema A2")) {
assertTrue("Wrong thema in project list A, title must be 'thema A1'", projectListA.get(1).getTitle().equals("thema A1"));
}
if (projectListB.get(0).getTitle().equals("thema B1")) {
assertTrue("Wrong thema in project list B, title must be 'thema B2'", projectListB.get(1).getTitle().equals("thema B2"));
} else if (projectListB.get(0).getTitle().equals("thema B2")) {
assertTrue("Wrong thema in project list B, title must be 'thema B1'", projectListB.get(1).getTitle().equals("thema B1"));
}
// delete project
long candiadteGroupKey = projectListA.get(0).getCandidateGroup().getKey();
long projectGroupKey = projectListA.get(0).getProjectGroup().getKey();
assertNotNull("CandidateGroup does not exist before delete project", dbInstance.getCurrentEntityManager().find(SecurityGroupImpl.class, candiadteGroupKey));
assertNotNull("ProjectGroup does not exist before delete project", dbInstance.getCurrentEntityManager().find(BusinessGroupImpl.class, projectGroupKey));
projectBrokerManager.deleteProject(projectListA.get(0), true, null, null);
assertNull("CandidateGroup still exists after delete project", dbInstance.getCurrentEntityManager().find(SecurityGroupImpl.class, candiadteGroupKey));
assertNull("ProjectGroup still exists after delete project", dbInstance.getCurrentEntityManager().find(BusinessGroupImpl.class, projectGroupKey));
// get project list and check content
projectListA = projectBrokerManager.getProjectListBy(idProjectBrokerA);
projectListB = projectBrokerManager.getProjectListBy(idProjectBrokerB);
assertEquals("Wrong projectList.size for project-broker A after delete 'thema A1'", 1, projectListA.size());
assertEquals("Wrong projectList.size for project-broker B after delete 'thema A1'", 2, projectListB.size());
// delete project
projectBrokerManager.deleteProject(projectListB.get(1), true, null, null);
// get project list and check content
projectListA = projectBrokerManager.getProjectListBy(idProjectBrokerA);
projectListB = projectBrokerManager.getProjectListBy(idProjectBrokerB);
assertEquals("Wrong projectList.size for project-broker A after delete 'thema B2'", 1, projectListA.size());
assertEquals("Wrong projectList.size for project-broker B after delete 'thema B2'", 1, projectListB.size());
// delete project
projectBrokerManager.deleteProject(projectListA.get(0), true, null, null);
projectListA = projectBrokerManager.getProjectListBy(idProjectBrokerA);
projectListB = projectBrokerManager.getProjectListBy(idProjectBrokerB);
log.info("testCreateListDeleteProjects: projectListA=" + projectListA);
assertEquals("Wrong projectList.size for project-broker A after delete all thema", 0, projectListA.size());
assertEquals("Wrong projectList.size for project-broker B after delete all thema", 1, projectListB.size());
}
use of org.olat.course.nodes.projectbroker.datamodel.Project in project OpenOLAT by OpenOLAT.
the class ProjectBrokerManagerTest method getProjectsWith.
@Test
public void getProjectsWith() {
ProjectBroker projectBroker = projectBrokerManager.createAndSaveProjectBroker();
BusinessGroup projectGroup = projectGroupManager.createProjectGroupFor(projectBroker.getKey(), id1, "getProjectsWith", "getProjectsWithGroupDescription", resourceableId);
Project project = projectBrokerManager.createAndSaveProjectFor("getProjectsWith", "getProjectsWith", projectBroker.getKey(), projectGroup);
dbInstance.commitAndCloseSession();
List<Project> projects = projectBrokerManager.getProjectsWith(projectGroup);
Assert.assertNotNull(projects);
Assert.assertEquals(1, projects.size());
Assert.assertEquals(project, projects.get(0));
}
use of org.olat.course.nodes.projectbroker.datamodel.Project in project OpenOLAT by OpenOLAT.
the class ProjectBrokerManagerTest method testPerformanceTableModel.
@Test
public void testPerformanceTableModel() throws Exception {
int ITERATION = 300;
int START_PAGE_INDEX = 100;
int PAGE_SIZE = 20;
Translator translator = Util.createPackageTranslator(this.getClass(), Locale.GERMAN);
ProjectBroker projectBrokerD = projectBrokerManager.createAndSaveProjectBroker();
Long idProjectBrokerD = projectBrokerD.getKey();
ProjectBrokerModuleConfiguration moduleConfig = new ProjectBrokerModuleConfiguration(new ModuleConfiguration());
for (int i = 0; i < ITERATION; i++) {
createProject("thema D1_" + i, id1, idProjectBrokerD, resourceableId);
}
List<Project> projectListD = projectBrokerManager.getProjectListBy(idProjectBrokerD);
ProjectListTableModel tableModel = new ProjectListTableModel(projectListD, id1, translator, moduleConfig, 0, 0, 0, false);
// loop over table like rendering loop
long startTime = System.currentTimeMillis();
for (int row = START_PAGE_INDEX; row < START_PAGE_INDEX + PAGE_SIZE; row++) {
for (int col = 0; col < tableModel.getColumnCount(); col++) {
Object element = tableModel.getValueAt(row, col);
Assert.assertNotNull(element);
}
}
long endTime = System.currentTimeMillis();
long duration = endTime - startTime;
log.info("tableModel.getValueAt(row, col) for " + PAGE_SIZE + "elements (of " + ITERATION + ") takes " + duration + "ms with " + ITERATION + " projects");
}
Aggregations