Search in sources :

Example 26 with ProjectBroker

use of org.olat.course.nodes.projectbroker.datamodel.ProjectBroker in project OpenOLAT by OpenOLAT.

the class ProjectBrokerCourseNode method exportNode.

@Override
public void exportNode(File exportDirectory, ICourse course) {
    // initialize managers
    CoursePropertyManager cpm = course.getCourseEnvironment().getCoursePropertyManager();
    ProjectBrokerManager projectBrokerManager = CoreSpringFactory.getImpl(ProjectBrokerManager.class);
    ProjectBroker pb = projectBrokerManager.getProjectBroker(projectBrokerManager.getProjectBrokerId(cpm, this));
    ProjectGroupManager projectGroupManager = CoreSpringFactory.getImpl(ProjectGroupManager.class);
    XStream xstream = XStreamHelper.createXStreamInstance();
    // folder for the pb node
    File pbNodeFolder = new File(exportDirectory, getIdent());
    pbNodeFolder.mkdirs();
    // for the broker prefs
    ProjectBrokerConfig brokerConfig = new ProjectBrokerConfig();
    brokerConfig.setAccountGroupKey(projectGroupManager.getAccountManagerGroupKey(cpm, this));
    File projectBrokerFile = new File(pbNodeFolder, "projectbroker.xml");
    XStreamHelper.writeObject(xstream, projectBrokerFile, brokerConfig);
    // get all the projects available in the pb
    List<Project> projects = projectBrokerManager.getProjectListBy(pb.getKey());
    for (Project project : projects) {
        File projectFolder = new File(pbNodeFolder, project.getKey().toString());
        projectFolder.mkdirs();
        // create a hashmap with the project configuration and insert the
        // project data
        File projectFile = new File(projectFolder, project.getKey() + ".xml");
        HashMap<String, Object> projectData = new HashMap<String, Object>();
        projectData.put("title", project.getTitle());
        projectData.put("description", project.getDescription());
        projectData.put("customFieldSize", project.getCustomFieldSize());
        projectData.put("maxMembers", project.getMaxMembers());
        projectData.put("mailNotificationEnabled", project.isMailNotificationEnabled());
        projectData.put("attachmentFileName", project.getAttachmentFileName());
        projectData.put("allowDeselection", projectGroupManager.isDeselectionAllowed(project));
        projectData.put("customeFieldSize", project.getCustomFieldSize());
        projectData.put("businessGroupKey", project.getProjectGroup().getKey());
        // iterate through the customFields
        for (int i = 0; i < project.getCustomFieldSize(); i++) {
            projectData.put("customFieldValue" + i, project.getCustomFieldValue(i));
        }
        // writeout the project data
        XStreamHelper.writeObject(xstream, projectFile, projectData);
        // add attachment file
        OlatRootFolderImpl rootFolder = new OlatRootFolderImpl(projectBrokerManager.getAttamchmentRelativeRootPath(project, course.getCourseEnvironment(), this), null);
        VFSItem item = rootFolder.resolve(project.getAttachmentFileName());
        if (item instanceof VFSLeaf) {
            VFSLeaf itemLeaf = (VFSLeaf) item;
            File attachmentFolder = new File(projectFolder, "attachment");
            File attachment = new File(attachmentFolder, Base64.encodeBase64String(project.getAttachmentFileName().getBytes()));
            try {
                attachmentFolder.mkdirs();
                attachment.createNewFile();
                FileOutputStream attachmentOutputStream = new FileOutputStream(attachment);
                InputStream leafInputStream = itemLeaf.getInputStream();
                FileUtils.copy(leafInputStream, attachmentOutputStream);
                attachmentOutputStream.close();
                leafInputStream.close();
            } catch (IOException e) {
                log.error("Error while exporting attachments for projectbroker " + project.getTitle(), e);
            }
        }
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) HashMap(java.util.HashMap) XStream(com.thoughtworks.xstream.XStream) InputStream(java.io.InputStream) VFSItem(org.olat.core.util.vfs.VFSItem) IOException(java.io.IOException) ProjectBrokerManager(org.olat.course.nodes.projectbroker.service.ProjectBrokerManager) ProjectGroupManager(org.olat.course.nodes.projectbroker.service.ProjectGroupManager) Project(org.olat.course.nodes.projectbroker.datamodel.Project) ProjectBroker(org.olat.course.nodes.projectbroker.datamodel.ProjectBroker) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) FileOutputStream(java.io.FileOutputStream) File(java.io.File) CoursePropertyManager(org.olat.course.properties.CoursePropertyManager) PersistingCoursePropertyManager(org.olat.course.properties.PersistingCoursePropertyManager)

Example 27 with ProjectBroker

use of org.olat.course.nodes.projectbroker.datamodel.ProjectBroker in project OpenOLAT by OpenOLAT.

the class ProjectBrokerCourseNode method createInstanceForCopy.

/**
 * @see org.olat.course.nodes.CourseNode#createInstanceForCopy()
 */
@Override
public CourseNode createInstanceForCopy(boolean isNewTitle, ICourse course, Identity author) {
    // create the instance for the copy
    CourseNode copyInstance = super.createInstanceForCopy(isNewTitle, course, author);
    // get all the different managers
    BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
    CoursePropertyManager cpm = course.getCourseEnvironment().getCoursePropertyManager();
    ProjectGroupManager projectGroupManager = CoreSpringFactory.getImpl(ProjectGroupManager.class);
    ProjectBrokerManager projectBrokerManager = CoreSpringFactory.getImpl(ProjectBrokerManager.class);
    // get the pbID from the source pb
    Long oldProjectBrokerId = projectBrokerManager.getProjectBrokerId(cpm, this);
    // create a new projectBroker for the copyInstance
    ProjectBroker newBroker = projectBrokerManager.createAndSaveProjectBroker();
    Long projectBrokerId = newBroker.getKey();
    projectBrokerManager.saveProjectBrokerId(projectBrokerId, cpm, copyInstance);
    // configure the new Project like the old one
    // copy the old accountManagergroup to preserve the
    // "persons in charge"
    Long originalAccountGroupKey = projectGroupManager.getAccountManagerGroupKey(cpm, this);
    if (originalAccountGroupKey != null) {
        BusinessGroup originalAccountGroup = projectGroupManager.getAccountManagerGroupFor(cpm, this, course, getShortTitle(), getShortTitle(), null);
        BusinessGroup newAccountManagerGroup = bgs.copyBusinessGroup(author, originalAccountGroup, originalAccountGroup.getName(), originalAccountGroup.getDescription(), originalAccountGroup.getMinParticipants(), originalAccountGroup.getMaxParticipants(), false, false, true, false, false, true, false, false);
        projectGroupManager.saveAccountManagerGroupKey(newAccountManagerGroup.getKey(), cpm, copyInstance);
        bgs.addResourceTo(newAccountManagerGroup, course.getCourseEnvironment().getCourseGroupManager().getCourseEntry());
    }
    if (oldProjectBrokerId != null) {
        List<Project> projects = projectBrokerManager.getProjectListBy(oldProjectBrokerId);
        for (Project project : projects) {
            // create projectGroup
            BusinessGroup projectGroup = projectGroupManager.createProjectGroupFor(projectBrokerId, author, project.getTitle(), project.getDescription(), course.getResourceableId());
            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, course.getCourseEnvironment(), this), null);
            VFSItem item = rootFolder.resolve(project.getAttachmentFileName());
            if (item instanceof VFSLeaf) {
                projectBrokerManager.saveAttachedFile(newProject, project.getAttachmentFileName(), (VFSLeaf) item, course.getCourseEnvironment(), copyInstance);
                newProject.setAttachedFileName(project.getAttachmentFileName());
                projectBrokerManager.updateProject(newProject);
            }
        }
    }
    return copyInstance;
}
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) ProjectBroker(org.olat.course.nodes.projectbroker.datamodel.ProjectBroker) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) BusinessGroupService(org.olat.group.BusinessGroupService) CoursePropertyManager(org.olat.course.properties.CoursePropertyManager) PersistingCoursePropertyManager(org.olat.course.properties.PersistingCoursePropertyManager)

Example 28 with ProjectBroker

use of org.olat.course.nodes.projectbroker.datamodel.ProjectBroker in project openolat by klemens.

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 29 with ProjectBroker

use of org.olat.course.nodes.projectbroker.datamodel.ProjectBroker in project openolat by klemens.

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

Example 30 with ProjectBroker

use of org.olat.course.nodes.projectbroker.datamodel.ProjectBroker in project openolat by klemens.

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)

Aggregations

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