Search in sources :

Example 1 with ProjectBrokerManager

use of org.olat.course.nodes.projectbroker.service.ProjectBrokerManager 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 2 with ProjectBrokerManager

use of org.olat.course.nodes.projectbroker.service.ProjectBrokerManager in project OpenOLAT by OpenOLAT.

the class ProjectBrokerCourseNode method postImport.

@Override
public void postImport(File importDirectory, ICourse course, CourseEnvironmentMapper envMapper, Processing processType) {
    // initialize managers
    if (processType == Processing.editor && importDirectory != null) {
        ProjectBrokerManager projectBrokerManager = CoreSpringFactory.getImpl(ProjectBrokerManager.class);
        CoursePropertyManager cpm = course.getCourseEnvironment().getCoursePropertyManager();
        // create a new projectBroker
        ProjectBroker projectBroker = projectBrokerManager.createAndSaveProjectBroker();
        projectBrokerManager.saveProjectBrokerId(projectBroker.getKey(), cpm, this);
        // get the node folder inside of the importDirectory
        File folderNodeData = new File(importDirectory, getIdent());
        // for the broker prefs
        File projectBrokerFile = new File(folderNodeData, "projectbroker.xml");
        if (projectBrokerFile.exists()) {
            XStream xstream = XStreamHelper.createXStreamInstance();
            ProjectGroupManager projectGroupManager = CoreSpringFactory.getImpl(ProjectGroupManager.class);
            ProjectBrokerConfig brokerConfig = (ProjectBrokerConfig) XStreamHelper.readObject(xstream, projectBrokerFile);
            if (brokerConfig != null && brokerConfig.getAccountGroupKey() != null) {
                Long accountGroupKey = envMapper.toGroupKeyFromOriginalKey(brokerConfig.getAccountGroupKey());
                if (accountGroupKey != null) {
                    projectGroupManager.saveAccountManagerGroupKey(accountGroupKey, cpm, this);
                }
            }
        }
        // loop through the project directories
        if (folderNodeData.exists()) {
            for (File projectDir : folderNodeData.listFiles(DirectoryFilter.DIRECTORY_FILTER)) {
                for (File projectFile : projectDir.listFiles(new FileNameSuffixFilter("xml"))) {
                    importProject(projectDir, projectFile, projectBroker, course, envMapper);
                }
            }
        }
    }
    super.postImport(importDirectory, course, envMapper, processType);
}
Also used : ProjectGroupManager(org.olat.course.nodes.projectbroker.service.ProjectGroupManager) FileNameSuffixFilter(org.olat.core.util.FileNameSuffixFilter) ProjectBroker(org.olat.course.nodes.projectbroker.datamodel.ProjectBroker) XStream(com.thoughtworks.xstream.XStream) ProjectBrokerManager(org.olat.course.nodes.projectbroker.service.ProjectBrokerManager) File(java.io.File) CoursePropertyManager(org.olat.course.properties.CoursePropertyManager) PersistingCoursePropertyManager(org.olat.course.properties.PersistingCoursePropertyManager)

Example 3 with ProjectBrokerManager

use of org.olat.course.nodes.projectbroker.service.ProjectBrokerManager in project OpenOLAT by OpenOLAT.

the class ProjectBrokerCourseNode method cleanupOnDelete.

/**
 * @see org.olat.course.nodes.CourseNode#cleanupOnDelete(
 *      org.olat.course.ICourse)
 */
@Override
public void cleanupOnDelete(ICourse course) {
    CoursePropertyManager cpm = course.getCourseEnvironment().getCoursePropertyManager();
    ProjectBrokerManager projectBrokerManager = CoreSpringFactory.getImpl(ProjectBrokerManager.class);
    Long projectBrokerId = projectBrokerManager.getProjectBrokerId(cpm, this);
    File fDropBox = new File(FolderConfig.getCanonicalRoot() + DropboxController.getDropboxPathRelToFolderRoot(course.getCourseEnvironment(), this));
    if (fDropBox.exists()) {
        FileUtils.deleteDirsAndFiles(fDropBox, true, true);
    }
    File fReturnBox = new File(FolderConfig.getCanonicalRoot() + ReturnboxController.getReturnboxPathRelToFolderRoot(course.getCourseEnvironment(), this));
    if (fReturnBox.exists()) {
        FileUtils.deleteDirsAndFiles(fReturnBox, true, true);
    }
    File attachmentDir = new File(FolderConfig.getCanonicalRoot() + projectBrokerManager.getAttachmentBasePathRelToFolderRoot(course.getCourseEnvironment(), this));
    if (attachmentDir.exists()) {
        FileUtils.deleteDirsAndFiles(attachmentDir, true, true);
    }
    // Delete project-broker, projects and project-groups
    if (projectBrokerId != null) {
        projectBrokerManager.deleteProjectBroker(projectBrokerId, course.getCourseEnvironment(), this);
    }
    // Delete all properties...
    cpm.deleteNodeProperties(this, null);
    OLATResource resource = course.getCourseEnvironment().getCourseGroupManager().getCourseResource();
    CoreSpringFactory.getImpl(TaskExecutorManager.class).delete(resource, getIdent());
}
Also used : TaskExecutorManager(org.olat.core.commons.services.taskexecutor.TaskExecutorManager) OLATResource(org.olat.resource.OLATResource) ProjectBrokerManager(org.olat.course.nodes.projectbroker.service.ProjectBrokerManager) File(java.io.File) CoursePropertyManager(org.olat.course.properties.CoursePropertyManager) PersistingCoursePropertyManager(org.olat.course.properties.PersistingCoursePropertyManager)

Example 4 with ProjectBrokerManager

use of org.olat.course.nodes.projectbroker.service.ProjectBrokerManager 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)

Example 5 with ProjectBrokerManager

use of org.olat.course.nodes.projectbroker.service.ProjectBrokerManager in project openolat by klemens.

the class ProjectBrokerCourseNode method cleanupOnDelete.

/**
 * @see org.olat.course.nodes.CourseNode#cleanupOnDelete(
 *      org.olat.course.ICourse)
 */
@Override
public void cleanupOnDelete(ICourse course) {
    CoursePropertyManager cpm = course.getCourseEnvironment().getCoursePropertyManager();
    ProjectBrokerManager projectBrokerManager = CoreSpringFactory.getImpl(ProjectBrokerManager.class);
    Long projectBrokerId = projectBrokerManager.getProjectBrokerId(cpm, this);
    File fDropBox = new File(FolderConfig.getCanonicalRoot() + DropboxController.getDropboxPathRelToFolderRoot(course.getCourseEnvironment(), this));
    if (fDropBox.exists()) {
        FileUtils.deleteDirsAndFiles(fDropBox, true, true);
    }
    File fReturnBox = new File(FolderConfig.getCanonicalRoot() + ReturnboxController.getReturnboxPathRelToFolderRoot(course.getCourseEnvironment(), this));
    if (fReturnBox.exists()) {
        FileUtils.deleteDirsAndFiles(fReturnBox, true, true);
    }
    File attachmentDir = new File(FolderConfig.getCanonicalRoot() + projectBrokerManager.getAttachmentBasePathRelToFolderRoot(course.getCourseEnvironment(), this));
    if (attachmentDir.exists()) {
        FileUtils.deleteDirsAndFiles(attachmentDir, true, true);
    }
    // Delete project-broker, projects and project-groups
    if (projectBrokerId != null) {
        projectBrokerManager.deleteProjectBroker(projectBrokerId, course.getCourseEnvironment(), this);
    }
    // Delete all properties...
    cpm.deleteNodeProperties(this, null);
    OLATResource resource = course.getCourseEnvironment().getCourseGroupManager().getCourseResource();
    CoreSpringFactory.getImpl(TaskExecutorManager.class).delete(resource, getIdent());
}
Also used : TaskExecutorManager(org.olat.core.commons.services.taskexecutor.TaskExecutorManager) OLATResource(org.olat.resource.OLATResource) ProjectBrokerManager(org.olat.course.nodes.projectbroker.service.ProjectBrokerManager) File(java.io.File) CoursePropertyManager(org.olat.course.properties.CoursePropertyManager) PersistingCoursePropertyManager(org.olat.course.properties.PersistingCoursePropertyManager)

Aggregations

ProjectBrokerManager (org.olat.course.nodes.projectbroker.service.ProjectBrokerManager)14 CoursePropertyManager (org.olat.course.properties.CoursePropertyManager)14 PersistingCoursePropertyManager (org.olat.course.properties.PersistingCoursePropertyManager)12 Project (org.olat.course.nodes.projectbroker.datamodel.Project)10 ProjectGroupManager (org.olat.course.nodes.projectbroker.service.ProjectGroupManager)10 File (java.io.File)8 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)8 XStream (com.thoughtworks.xstream.XStream)6 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)6 VFSItem (org.olat.core.util.vfs.VFSItem)6 ProjectBroker (org.olat.course.nodes.projectbroker.datamodel.ProjectBroker)6 BusinessGroup (org.olat.group.BusinessGroup)6 BusinessGroupService (org.olat.group.BusinessGroupService)6 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 Identity (org.olat.core.id.Identity)4 FileOutputStream (java.io.FileOutputStream)2 InputStream (java.io.InputStream)2 Document (org.apache.lucene.document.Document)2 TaskExecutorManager (org.olat.core.commons.services.taskexecutor.TaskExecutorManager)2