Search in sources :

Example 26 with Project

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

the class ProjectBrokerExportGenerator method createProjectDataLine.

private static String createProjectDataLine(Translator t, Project project, ProjectBrokerModuleConfiguration moduleConfig, Translator translator) {
    StringBuilder line = new StringBuilder();
    line.append(project.getTitle());
    line.append(TABLE_DELIMITER);
    // loop over project leaders
    StringBuilder projectLeader = new StringBuilder();
    boolean firstElement = true;
    for (Identity identity : project.getProjectLeaders()) {
        if (!firstElement) {
            projectLeader.append(" , ");
        }
        String last = identity.getUser().getProperty(UserConstants.LASTNAME, t.getLocale());
        String first = identity.getUser().getProperty(UserConstants.FIRSTNAME, t.getLocale());
        projectLeader.append(first);
        projectLeader.append(" ");
        projectLeader.append(last);
        firstElement = false;
    }
    line.append(projectLeader.toString());
    line.append(TABLE_DELIMITER);
    line.append(t.translate(project.getState()));
    line.append(TABLE_DELIMITER);
    // loop over customfileds
    for (int customFieldIndex = 0; customFieldIndex < moduleConfig.getCustomFields().size(); customFieldIndex++) {
        String value = project.getCustomFieldValue(customFieldIndex);
        line.append(value);
        line.append(TABLE_DELIMITER);
    }
    line.append(project.getSelectedPlaces());
    line.append(TABLE_DELIMITER);
    // loop over all events
    for (Project.EventType eventType : Project.EventType.values()) {
        if (moduleConfig.isProjectEventEnabled(eventType)) {
            ProjectEvent projectEvent = project.getProjectEvent(eventType);
            if (projectEvent.getStartDate() != null) {
                line.append(translator.translate("export.event.start.prefix"));
                line.append(" ");
                line.append(projectEvent.getFormattedStartDate());
                line.append(" ");
            }
            if (projectEvent.getEndDate() != null) {
                line.append(translator.translate("export.event.end.prefix"));
                line.append(" ");
                line.append(projectEvent.getFormattedEndDate());
            }
            line.append(TABLE_DELIMITER);
        }
    }
    // loop over all paricipants
    StringBuilder participants = new StringBuilder();
    boolean firstParticipants = true;
    List<Identity> participantList = CoreSpringFactory.getImpl(BusinessGroupService.class).getMembers(project.getProjectGroup(), GroupRoles.participant.name());
    for (Identity identity : participantList) {
        if (!firstParticipants) {
            participants.append(" , ");
        }
        String last = identity.getUser().getProperty(UserConstants.LASTNAME, t.getLocale());
        String first = identity.getUser().getProperty(UserConstants.FIRSTNAME, t.getLocale());
        participants.append(first);
        participants.append(" ");
        participants.append(last);
        firstParticipants = false;
    }
    line.append(participants.toString());
    line.append(TABLE_DELIMITER);
    line.append(project.getKey().toString());
    line.append(END_OF_LINE);
    return line.toString();
}
Also used : Project(org.olat.course.nodes.projectbroker.datamodel.Project) BusinessGroupService(org.olat.group.BusinessGroupService) Identity(org.olat.core.id.Identity) ProjectEvent(org.olat.course.nodes.projectbroker.datamodel.ProjectEvent)

Example 27 with Project

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

the class ProjectBrokerGroupDeleteManager method deleteGroupDataFor.

@Override
public boolean deleteGroupDataFor(BusinessGroup group) {
    log.debug("deleteAllProjectGroupEntiresFor started.. group=" + group);
    List<Project> projectList = projectBrokerManager.getProjectsWith(group);
    for (Project project : projectList) {
        // no course-env, no course-node
        projectBrokerManager.deleteProject(project, false, null, null);
        ProjectBroker projectBroker = project.getProjectBroker();
        OLATResourceableDeletedEvent delEv = new OLATResourceableDeletedEvent(projectBroker);
        CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(delEv, projectBroker);
        log.debug("deleteProjectWith: group=" + group + " , project=" + project);
    }
    return true;
}
Also used : Project(org.olat.course.nodes.projectbroker.datamodel.Project) ProjectBroker(org.olat.course.nodes.projectbroker.datamodel.ProjectBroker) OLATResourceableDeletedEvent(org.olat.core.util.resource.OLATResourceableDeletedEvent)

Example 28 with Project

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

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)

Example 29 with Project

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

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 30 with Project

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

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)

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