Search in sources :

Example 1 with Project

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");
}
Also used : Project(org.olat.course.nodes.projectbroker.datamodel.Project) ProjectBroker(org.olat.course.nodes.projectbroker.datamodel.ProjectBroker) Test(org.junit.Test)

Example 2 with Project

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));
}
Also used : Project(org.olat.course.nodes.projectbroker.datamodel.Project) ProjectBroker(org.olat.course.nodes.projectbroker.datamodel.ProjectBroker) BusinessGroupService(org.olat.group.BusinessGroupService) ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 3 with Project

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()));
}
Also used : Project(org.olat.course.nodes.projectbroker.datamodel.Project) ProjectBroker(org.olat.course.nodes.projectbroker.datamodel.ProjectBroker) Test(org.junit.Test)

Example 4 with Project

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);
    }
}
Also used : Project(org.olat.course.nodes.projectbroker.datamodel.Project) SearchResourceContext(org.olat.search.service.SearchResourceContext) Document(org.apache.lucene.document.Document) ProjectBrokerProjectDocument(org.olat.search.service.document.ProjectBrokerProjectDocument) CourseNodeDocument(org.olat.search.service.document.CourseNodeDocument) ProjectBrokerManager(org.olat.course.nodes.projectbroker.service.ProjectBrokerManager) CoursePropertyManager(org.olat.course.properties.CoursePropertyManager)

Example 5 with Project

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);
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) HashMap(java.util.HashMap) BusinessGroup(org.olat.group.BusinessGroup) XStream(com.thoughtworks.xstream.XStream) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) ProjectBrokerManager(org.olat.course.nodes.projectbroker.service.ProjectBrokerManager) AssertException(org.olat.core.logging.AssertException) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) IOException(java.io.IOException) ProjectGroupManager(org.olat.course.nodes.projectbroker.service.ProjectGroupManager) Project(org.olat.course.nodes.projectbroker.datamodel.Project) BusinessGroupService(org.olat.group.BusinessGroupService) BusinessGroupReference(org.olat.group.model.BusinessGroupReference) Identity(org.olat.core.id.Identity) File(java.io.File) CoursePropertyManager(org.olat.course.properties.CoursePropertyManager) PersistingCoursePropertyManager(org.olat.course.properties.PersistingCoursePropertyManager)

Aggregations

Project (org.olat.course.nodes.projectbroker.datamodel.Project)70 ProjectBroker (org.olat.course.nodes.projectbroker.datamodel.ProjectBroker)30 Identity (org.olat.core.id.Identity)22 OLATResourceable (org.olat.core.id.OLATResourceable)16 Test (org.junit.Test)14 ArrayList (java.util.ArrayList)12 CoursePropertyManager (org.olat.course.properties.CoursePropertyManager)12 ProjectEvent (org.olat.course.nodes.projectbroker.datamodel.ProjectEvent)10 ProjectBrokerManager (org.olat.course.nodes.projectbroker.service.ProjectBrokerManager)10 BusinessGroup (org.olat.group.BusinessGroup)10 BusinessGroupService (org.olat.group.BusinessGroupService)10 SyncerExecutor (org.olat.core.util.coordinate.SyncerExecutor)8 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)8 ProjectGroupManager (org.olat.course.nodes.projectbroker.service.ProjectGroupManager)8 PersistingCoursePropertyManager (org.olat.course.properties.PersistingCoursePropertyManager)8 File (java.io.File)6 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)6 VFSItem (org.olat.core.util.vfs.VFSItem)6 XStream (com.thoughtworks.xstream.XStream)4 IOException (java.io.IOException)4