Search in sources :

Example 56 with Project

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

Example 57 with Project

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

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

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

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

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

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

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

the class ProjectEditDetailsFormController method formOK.

@Override
protected void formOK(UserRequest ureq) {
    boolean projectChanged = false;
    if (!project.getTitle().equals(projectTitle.getValue())) {
        // title has been changed => change project-group name too
        String newProjectGroupName = translate("project.member.groupname", projectTitle.getValue());
        String newProjectGroupDescription = translate("project.member.groupdescription", projectTitle.getValue());
        OLATResource courseResource = courseEnv.getCourseGroupManager().getCourseResource();
        projectGroupManager.changeProjectGroupName(getIdentity(), project.getProjectGroup(), newProjectGroupName, newProjectGroupDescription, courseResource);
        projectGroupManager.sendGroupChangeEvent(project, courseEnv.getCourseResourceableId(), ureq.getIdentity());
        projectChanged = true;
    }
    if (!project.getTitle().equals(projectTitle.getValue())) {
        project.setTitle(projectTitle.getValue());
        projectChanged = true;
    }
    if (!project.getDescription().equals(projectDescription.getValue())) {
        project.setDescription(projectDescription.getValue());
        projectChanged = true;
    }
    if (project.getMaxMembers() != maxMembers.getIntValue()) {
        project.setMaxMembers(maxMembers.getIntValue());
        projectGroupManager.setProjectGroupMaxMembers(getIdentity(), project.getProjectGroup(), maxMembers.getIntValue());
        projectChanged = true;
    }
    if (StringHelper.containsNonWhitespace(attachmentFileName.getUploadFileName())) {
        // First call uploadFiles than setAttachedFileName because uploadFiles needs old attachment name
        uploadFiles(attachmentFileName);
        project.setAttachedFileName(attachmentFileName.getUploadFileName());
        projectChanged = true;
    } else if (StringHelper.containsNonWhitespace(project.getAttachmentFileName()) && attachmentFileName.getInitialFile() == null) {
        // Attachment file has been removed
        project.setAttachedFileName("");
        projectChanged = true;
    }
    // store customfields
    int index = 0;
    for (Iterator<FormItem> iterator = customfieldElementList.iterator(); iterator.hasNext(); ) {
        FormItem element = iterator.next();
        String value = "";
        if (element instanceof TextElement) {
            TextElement textElement = (TextElement) element;
            value = textElement.getValue();
        } else if (element instanceof SingleSelection) {
            SingleSelection selectionElement = (SingleSelection) element;
            if (!selectionElement.getSelectedKey().equals(DROPDOWN_NO_SELECETION)) {
                value = selectionElement.getValue(selectionElement.getSelected());
            } else {
                value = "";
            }
        }
        getLogger().debug("customfield index=" + index + " value=" + value + " project.getCustomFieldValue(index)=" + project.getCustomFieldValue(index));
        if (!project.getCustomFieldValue(index).equals(value)) {
            project.setCustomFieldValue(index, value);
            projectChanged = true;
        }
        index++;
    }
    // store events
    for (Project.EventType eventType : eventStartElementList.keySet()) {
        Date startDate = eventStartElementList.get(eventType).getDate();
        Date endDate = eventEndElementList.get(eventType).getDate();
        // First handle startdate
        if (hasBeenChanged(project.getProjectEvent(eventType).getStartDate(), startDate) || hasBeenChanged(project.getProjectEvent(eventType).getEndDate(), endDate)) {
            project.setProjectEvent(new ProjectEvent(eventType, startDate, endDate));
            projectChanged = true;
        }
    }
    if (mailNotification.isSelected(0) != project.isMailNotificationEnabled()) {
        project.setMailNotificationEnabled(mailNotification.isSelected(0));
        projectChanged = true;
    }
    if (projectChanged) {
        if (projectBrokerManager.existsProject(project.getKey())) {
            projectBrokerManager.updateProject(project);
            projectBrokerMailer.sendProjectChangedEmailToParticipants(ureq.getIdentity(), project, this.getTranslator());
        } else {
            showInfo("info.project.nolonger.exist", project.getTitle());
        }
    }
    fireEvent(ureq, Event.DONE_EVENT);
}
Also used : Project(org.olat.course.nodes.projectbroker.datamodel.Project) RichTextElement(org.olat.core.gui.components.form.flexible.elements.RichTextElement) StaticTextElement(org.olat.core.gui.components.form.flexible.elements.StaticTextElement) TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement) SingleSelection(org.olat.core.gui.components.form.flexible.elements.SingleSelection) FormItem(org.olat.core.gui.components.form.flexible.FormItem) OLATResource(org.olat.resource.OLATResource) Date(java.util.Date) ProjectEvent(org.olat.course.nodes.projectbroker.datamodel.ProjectEvent)

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