Search in sources :

Example 11 with ProjectEvent

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

the class ProjectEventColumnRenderer method render.

/**
 * Renderer for project-broker event-column.
 * For table-view render with HTML elements e.g. 'vom 10.04.2010 10:00<br>bis 11.04.2010 10:00' .
 * When the renderer is null, no HTML tags will be added e.g. 'vom 10.04.2010 10:00 bis 11.04.2010 10:00' .
 *
 * @param val  must be from type ProjectEvent
 * @see org.olat.core.gui.components.table.CustomCellRenderer#render(org.olat.core.gui.render.StringOutput, org.olat.core.gui.render.Renderer, java.lang.Object, java.util.Locale, int, java.lang.String)
 */
@Override
public void render(StringOutput sb, Renderer renderer, Object val, Locale locale, int alignment, String action) {
    ProjectEvent projectEvent;
    Translator translator = Util.createPackageTranslator(this.getClass(), locale);
    if (val == null) {
        // don't render nulls
        return;
    }
    if (val instanceof ProjectEvent) {
        projectEvent = (ProjectEvent) val;
    } else {
        throw new AssertException("ProjectEventColumnRenderer: Wrong object type, could only render ProjectEvent");
    }
    if (renderer == null) {
        // if no renderer is set, then we assume it's a table export - in which case we don't want the htmls (<br/>)
        if (projectEvent.getStartDate() != null) {
            sb.append(translator.translate("table.event.start.label"));
            sb.append(projectEvent.getFormattedStartDate());
            sb.append(" ");
        }
        if (projectEvent.getEndDate() != null) {
            sb.append(translator.translate("table.event.end.label"));
            sb.append(projectEvent.getFormattedEndDate());
        }
    } else {
        // add <br> between the dates
        if (projectEvent.getStartDate() != null) {
            sb.append(translator.translate("table.event.start.label"));
            sb.append(projectEvent.getFormattedStartDate());
            if (projectEvent.getEndDate() != null) {
                sb.append("<br>");
            }
        }
        if (projectEvent.getEndDate() != null) {
            sb.append(translator.translate("table.event.end.label"));
            sb.append(projectEvent.getFormattedEndDate());
        }
    }
}
Also used : AssertException(org.olat.core.logging.AssertException) Translator(org.olat.core.gui.translator.Translator) ProjectEvent(org.olat.course.nodes.projectbroker.datamodel.ProjectEvent)

Example 12 with ProjectEvent

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

the class ProjectFolderController method isDropboxAccessible.

private boolean isDropboxAccessible(Project project, ProjectBrokerModuleConfiguration moduleConfig) {
    if (moduleConfig.isProjectEventEnabled(EventType.HANDOUT_EVENT)) {
        ProjectEvent handoutEvent = project.getProjectEvent(EventType.HANDOUT_EVENT);
        Date now = new Date();
        if (handoutEvent.getStartDate() != null) {
            if (now.before(handoutEvent.getStartDate())) {
                return false;
            }
        }
        if (handoutEvent.getEndDate() != null) {
            if (now.after(handoutEvent.getEndDate())) {
                return false;
            }
        }
    }
    return true;
}
Also used : Date(java.util.Date) ProjectEvent(org.olat.course.nodes.projectbroker.datamodel.ProjectEvent)

Example 13 with ProjectEvent

use of org.olat.course.nodes.projectbroker.datamodel.ProjectEvent 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 14 with ProjectEvent

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

Example 15 with ProjectEvent

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

the class ProjectFolderController method isDropboxAccessible.

private boolean isDropboxAccessible(Project project, ProjectBrokerModuleConfiguration moduleConfig) {
    if (moduleConfig.isProjectEventEnabled(EventType.HANDOUT_EVENT)) {
        ProjectEvent handoutEvent = project.getProjectEvent(EventType.HANDOUT_EVENT);
        Date now = new Date();
        if (handoutEvent.getStartDate() != null) {
            if (now.before(handoutEvent.getStartDate())) {
                return false;
            }
        }
        if (handoutEvent.getEndDate() != null) {
            if (now.after(handoutEvent.getEndDate())) {
                return false;
            }
        }
    }
    return true;
}
Also used : Date(java.util.Date) ProjectEvent(org.olat.course.nodes.projectbroker.datamodel.ProjectEvent)

Aggregations

ProjectEvent (org.olat.course.nodes.projectbroker.datamodel.ProjectEvent)16 Date (java.util.Date)10 Project (org.olat.course.nodes.projectbroker.datamodel.Project)8 RichTextElement (org.olat.core.gui.components.form.flexible.elements.RichTextElement)4 SingleSelection (org.olat.core.gui.components.form.flexible.elements.SingleSelection)4 StaticTextElement (org.olat.core.gui.components.form.flexible.elements.StaticTextElement)4 TextElement (org.olat.core.gui.components.form.flexible.elements.TextElement)4 Identity (org.olat.core.id.Identity)4 File (java.io.File)2 ArrayList (java.util.ArrayList)2 Calendar (java.util.Calendar)2 StringTokenizer (java.util.StringTokenizer)2 Test (org.junit.Test)2 FormItem (org.olat.core.gui.components.form.flexible.FormItem)2 DateChooser (org.olat.core.gui.components.form.flexible.elements.DateChooser)2 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)2 Translator (org.olat.core.gui.translator.Translator)2 AssertException (org.olat.core.logging.AssertException)2 CustomField (org.olat.course.nodes.projectbroker.datamodel.CustomField)2 ProjectBroker (org.olat.course.nodes.projectbroker.datamodel.ProjectBroker)2