use of org.olat.course.nodes.projectbroker.datamodel.Project in project OpenOLAT by OpenOLAT.
the class ProjectBrokerManagerTest method testPerformanceGetProjectList.
@Test
public void testPerformanceGetProjectList() throws Exception {
int FIRST_ITERATION = 10;
int SECOND_ITERATION = 90;
int THIRD_ITERATION = 400;
// create ProjectBroker C
ProjectBroker projectBrokerC = projectBrokerManager.createAndSaveProjectBroker();
Long idProjectBrokerC = projectBrokerC.getKey();
dbInstance.closeSession();
for (int i = 0; i < FIRST_ITERATION; i++) {
createProject("thema C1_" + i, id1, idProjectBrokerC, resourceableId);
}
dbInstance.closeSession();
long startTime = System.currentTimeMillis();
List<Project> projectListC = projectBrokerManager.getProjectListBy(idProjectBrokerC);
long endTime = System.currentTimeMillis();
assertEquals("Wrong projectList.size for project-broker C after first iteration", FIRST_ITERATION, projectListC.size());
long duration = endTime - startTime;
log.info("getProjectListBy takes " + duration + "ms with " + FIRST_ITERATION + " projects");
for (int i = 0; i < SECOND_ITERATION; i++) {
createProject("thema C1_" + i, id1, idProjectBrokerC, resourceableId);
}
dbInstance.closeSession();
startTime = System.currentTimeMillis();
projectListC = projectBrokerManager.getProjectListBy(idProjectBrokerC);
endTime = System.currentTimeMillis();
int numberOfProjects = FIRST_ITERATION + SECOND_ITERATION;
assertEquals("Wrong projectList.size for project-broker C", numberOfProjects, projectListC.size());
duration = endTime - startTime;
log.info("getProjectListBy takes " + duration + "ms with " + numberOfProjects + " projects");
for (int i = 0; i < THIRD_ITERATION; i++) {
createProject("thema C1_" + i, id1, idProjectBrokerC, resourceableId);
}
dbInstance.closeSession();
startTime = System.currentTimeMillis();
projectListC = projectBrokerManager.getProjectListBy(idProjectBrokerC);
endTime = System.currentTimeMillis();
numberOfProjects = FIRST_ITERATION + SECOND_ITERATION + THIRD_ITERATION;
assertEquals("Wrong projectList.size for project-broker C", numberOfProjects, projectListC.size());
duration = endTime - startTime;
log.info("getProjectListBy takes " + duration + "ms with " + numberOfProjects + " projects");
}
use of org.olat.course.nodes.projectbroker.datamodel.Project in project OpenOLAT by OpenOLAT.
the class ProjectBrokerManagerTest method testIsProjectManager.
@Test
public void testIsProjectManager() throws Exception {
ProjectBroker projectBrokerD = projectBrokerManager.createAndSaveProjectBroker();
Long idProjectBrokerD = projectBrokerD.getKey();
Project testProjectA = createProject("thema A", id1, idProjectBrokerD, resourceableId);
List<Identity> projectManagerList = new ArrayList<Identity>();
projectManagerList.add(id1);
Project testProjectB = createProject("thema B", id2, idProjectBrokerD, resourceableId);
// check project leader in ProjectA
assertTrue("Must be project-leader of project A", projectGroupManager.isProjectManager(id1, testProjectA));
assertFalse("Can not be project leader of project B", projectGroupManager.isProjectManager(id1, testProjectB));
assertTrue("Must be project-leader of project A", projectGroupManager.isProjectManager(id2, testProjectB));
CoreSpringFactory.getImpl(BusinessGroupService.class).removeOwners(id1, projectManagerList, testProjectA.getProjectGroup());
// check no project leader anymore
assertFalse("Can not be project leader of project A", projectGroupManager.isProjectManager(id1, testProjectA));
assertFalse("Can not be project leader of project B", projectGroupManager.isProjectManager(id1, testProjectB));
}
use of org.olat.course.nodes.projectbroker.datamodel.Project in project OpenOLAT by OpenOLAT.
the class ProjectBrokerManagerTest method testExistsProject.
@Test
public void testExistsProject() throws Exception {
// 1. test project does not exists
assertFalse("Wrong return value true, project does not exist", projectBrokerManager.existsProject(39927492743L));
// 2. test project exists
ProjectBroker projectBrokerD = projectBrokerManager.createAndSaveProjectBroker();
Long idProjectBrokerD = projectBrokerD.getKey();
Project testProjectA = createProject("thema existsProject-Test", id1, idProjectBrokerD, resourceableId);
dbInstance.closeSession();
assertTrue("Wrong return value false, project exists", projectBrokerManager.existsProject(testProjectA.getKey()));
}
use of org.olat.course.nodes.projectbroker.datamodel.Project in project OpenOLAT by OpenOLAT.
the class ProjectBrokerCourseNodeIndexer method doIndex.
@Override
public void doIndex(SearchResourceContext repositoryResourceContext, ICourse course, CourseNode courseNode, OlatFullIndexer indexWriter) throws IOException, InterruptedException {
SearchResourceContext courseNodeResourceContext = createSearchResourceContext(repositoryResourceContext, courseNode, TYPE);
Document nodeDocument = CourseNodeDocument.createDocument(courseNodeResourceContext, courseNode);
indexWriter.addDocument(nodeDocument);
// go further, index my projects
CoursePropertyManager cpm = course.getCourseEnvironment().getCoursePropertyManager();
ProjectBrokerManager projectBrokerManager = CoreSpringFactory.getImpl(ProjectBrokerManager.class);
Long projectBrokerId = projectBrokerManager.getProjectBrokerId(cpm, courseNode);
if (projectBrokerId != null) {
List<Project> projects = projectBrokerManager.getProjectListBy(projectBrokerId);
for (Project project : projects) {
Document document = ProjectBrokerProjectDocument.createDocument(courseNodeResourceContext, project);
indexWriter.addDocument(document);
}
} else {
log.debug("projectBrokerId is null, courseNode=" + courseNode + " , course=" + course);
}
}
use of org.olat.course.nodes.projectbroker.datamodel.Project 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