Search in sources :

Example 31 with Project

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);
            }
        }
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) BusinessGroup(org.olat.group.BusinessGroup) VFSItem(org.olat.core.util.vfs.VFSItem) ProjectBrokerManager(org.olat.course.nodes.projectbroker.service.ProjectBrokerManager) ProjectGroupManager(org.olat.course.nodes.projectbroker.service.ProjectGroupManager) Project(org.olat.course.nodes.projectbroker.datamodel.Project) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) BusinessGroupService(org.olat.group.BusinessGroupService) Identity(org.olat.core.id.Identity) CoursePropertyManager(org.olat.course.properties.CoursePropertyManager) PersistingCoursePropertyManager(org.olat.course.properties.PersistingCoursePropertyManager)

Example 32 with Project

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);
    }
}
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)

Example 33 with Project

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

Example 34 with Project

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

Example 35 with Project

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");
}
Also used : Project(org.olat.course.nodes.projectbroker.datamodel.Project) ProjectBroker(org.olat.course.nodes.projectbroker.datamodel.ProjectBroker) ProjectBrokerModuleConfiguration(org.olat.course.nodes.projectbroker.service.ProjectBrokerModuleConfiguration) ProjectBrokerModuleConfiguration(org.olat.course.nodes.projectbroker.service.ProjectBrokerModuleConfiguration) ModuleConfiguration(org.olat.modules.ModuleConfiguration) Translator(org.olat.core.gui.translator.Translator) Test(org.junit.Test)

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