use of org.olat.course.nodes.projectbroker.datamodel.ProjectBroker 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.ProjectBroker 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.ProjectBroker 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");
}
use of org.olat.course.nodes.projectbroker.datamodel.ProjectBroker in project OpenOLAT by OpenOLAT.
the class ProjectBrokerManagerTest method testUpdateProject.
@Test
public void testUpdateProject() throws Exception {
ProjectBroker projectBroker = projectBrokerManager.createAndSaveProjectBroker();
Long idProjectBroker = projectBroker.getKey();
Project testProjectA = createProject("updateTest", id1, idProjectBroker, resourceableId);
DBFactory.getInstance().closeSession();
// testProjectA is now a detached-object
// Update 1
String updateTitle = "thema updateProject-Test update1";
testProjectA.setTitle(updateTitle);
String updateDescription = "description update1";
testProjectA.setDescription(updateDescription);
String updateState = "state update1";
testProjectA.setState(updateState);
projectBrokerManager.updateProject(testProjectA);
dbInstance.closeSession();
// testProjectA is now a detached-object again
Project reloadedProject = (Project) dbInstance.loadObject(testProjectA, true);
assertEquals("Wrong updated title 1", updateTitle, reloadedProject.getTitle());
// Update 2
String updateTitle2 = "thema updateProject-Test update2";
testProjectA.setTitle(updateTitle2);
int updateMaxMembers = 3;
testProjectA.setMaxMembers(updateMaxMembers);
String updateAttachmentFileName = "attachmentFile.txt";
testProjectA.setAttachedFileName(updateAttachmentFileName);
boolean updateMailNotification = Boolean.TRUE;
testProjectA.setMailNotificationEnabled(updateMailNotification);
String updateCustomField0 = "CustomField0";
testProjectA.setCustomFieldValue(0, updateCustomField0);
String updateCustomField1 = "CustomField1";
testProjectA.setCustomFieldValue(1, updateCustomField1);
projectBrokerManager.updateProject(testProjectA);
dbInstance.closeSession();
// Update 3
Calendar cal = Calendar.getInstance();
cal.clear();
cal.set(2010, 11, 15, 15, 30, 45);
Date startDate = cal.getTime();
cal.clear();
cal.set(2010, 11, 20, 15, 30, 45);
Date endDate = cal.getTime();
ProjectEvent projectEventEnroll = new ProjectEvent(Project.EventType.ENROLLMENT_EVENT, startDate, endDate);
testProjectA.setProjectEvent(projectEventEnroll);
ProjectEvent projectEventHandout = new ProjectEvent(Project.EventType.HANDOUT_EVENT, startDate, endDate);
testProjectA.setProjectEvent(projectEventHandout);
dbInstance.closeSession();
reloadedProject = (Project) DBFactory.getInstance().loadObject(testProjectA, true);
assertEquals("Wrong updated title 2", updateTitle2, reloadedProject.getTitle());
assertEquals("Wrong description", updateDescription, reloadedProject.getDescription());
assertEquals("Wrong state", updateState, reloadedProject.getState());
assertEquals("Wrong maxMembers", updateMaxMembers, reloadedProject.getMaxMembers());
assertEquals("Wrong AttachmentFileName", updateAttachmentFileName, reloadedProject.getAttachmentFileName());
assertEquals("Wrong MailNotification", updateMailNotification, reloadedProject.isMailNotificationEnabled());
assertEquals("Wrong CustomField 0", updateCustomField0, reloadedProject.getCustomFieldValue(0));
assertEquals("Wrong CustomField 1", updateCustomField1, reloadedProject.getCustomFieldValue(1));
assertEquals("Wrong customField Size", 2, reloadedProject.getCustomFieldSize());
assertEquals("Wrong event Type (Handout)", Project.EventType.HANDOUT_EVENT, reloadedProject.getProjectEvent(Project.EventType.HANDOUT_EVENT).getEventType());
assertEquals("Wrong event start-date (Handout)", startDate.getTime(), reloadedProject.getProjectEvent(Project.EventType.HANDOUT_EVENT).getStartDate().getTime());
assertEquals("Wrong event end-date (Handout)", endDate.getTime(), reloadedProject.getProjectEvent(Project.EventType.HANDOUT_EVENT).getEndDate().getTime());
assertEquals("Wrong event Type (Enroll)", Project.EventType.ENROLLMENT_EVENT, reloadedProject.getProjectEvent(Project.EventType.ENROLLMENT_EVENT).getEventType());
assertEquals("Wrong event start-date (Enroll)", startDate.getTime(), reloadedProject.getProjectEvent(Project.EventType.ENROLLMENT_EVENT).getStartDate().getTime());
assertEquals("Wrong event end-date (Enroll)", endDate.getTime(), reloadedProject.getProjectEvent(Project.EventType.ENROLLMENT_EVENT).getEndDate().getTime());
}
use of org.olat.course.nodes.projectbroker.datamodel.ProjectBroker in project OpenOLAT by OpenOLAT.
the class ProjectBrokerManagerImpl method createAndSaveProjectFor.
public Project createAndSaveProjectFor(String title, String description, final Long projectBrokerId, BusinessGroup projectGroup) {
OLATResourceable projectBrokerOres = OresHelper.createOLATResourceableInstance(this.getClass(), projectBrokerId);
final Project project = new ProjectImpl(title, description, projectGroup, getProjectBroker(projectBrokerId));
CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(projectBrokerOres, new SyncerExecutor() {
public void execute() {
dbInstance.saveObject(project);
ProjectBroker projectBroker = getOrLoadProjectBoker(projectBrokerId);
if (!projectBroker.getProjects().contains(project)) {
projectBroker.getProjects().add(project);
}
projectCache.update(projectBrokerId.toString(), projectBroker);
}
});
return project;
}
Aggregations