Search in sources :

Example 6 with ProjectEvent

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

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

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 8 with ProjectEvent

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

the class ProjectBrokerDropboxController 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 9 with ProjectEvent

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

the class ProjectBrokerManagerImpl method isEnrollmentDateOk.

private boolean isEnrollmentDateOk(Project project, ProjectBrokerModuleConfiguration moduleConfig) {
    if (moduleConfig.isProjectEventEnabled(EventType.ENROLLMENT_EVENT)) {
        ProjectEvent enrollmentEvent = project.getProjectEvent(EventType.ENROLLMENT_EVENT);
        Date now = new Date();
        if (enrollmentEvent.getStartDate() != null) {
            if (now.before(enrollmentEvent.getStartDate())) {
                return false;
            }
        }
        if (enrollmentEvent.getEndDate() != null) {
            if (now.after(enrollmentEvent.getEndDate())) {
                return false;
            }
        }
        if ((enrollmentEvent.getStartDate() == null) && (enrollmentEvent.getEndDate() == null)) {
            // no enrollment date define => access ok
            return true;
        }
    }
    return true;
}
Also used : Date(java.util.Date) ProjectEvent(org.olat.course.nodes.projectbroker.datamodel.ProjectEvent)

Example 10 with ProjectEvent

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

the class ProjectEditDetailsFormController method initForm.

/**
 * Initialize form.
 */
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    // create form elements
    projectTitle = uifactory.addTextElement("title", "detailsform.title.label", 100, project.getTitle(), formLayout);
    // account-Managers
    StringBuilder projectLeaderString = new StringBuilder();
    for (Iterator<Identity> iterator = project.getProjectLeaders().iterator(); iterator.hasNext(); ) {
        Identity identity = iterator.next();
        String last = identity.getUser().getProperty(UserConstants.LASTNAME, getLocale());
        String first = identity.getUser().getProperty(UserConstants.FIRSTNAME, getLocale());
        if (projectLeaderString.length() > 0) {
            projectLeaderString.append(",");
        }
        projectLeaderString.append(first);
        projectLeaderString.append(" ");
        projectLeaderString.append(last);
    }
    projectLeaders = uifactory.addTextElement("projectleaders", "detailsform.projectleaders.label", 100, projectLeaderString.toString(), formLayout);
    projectLeaders.setEnabled(false);
    // add the learning objectives rich text input element
    projectDescription = uifactory.addRichTextElementForStringData("description", "detailsform.description.label", project.getDescription(), 10, -1, false, null, null, formLayout, ureq.getUserSession(), getWindowControl());
    projectDescription.setMaxLength(2500);
    stateLayout = FormLayoutContainer.createHorizontalFormLayout("stateLayout", getTranslator());
    stateLayout.setLabel("detailsform.state.label", null);
    formLayout.add(stateLayout);
    String stateValue = getTranslator().translate(projectBrokerManager.getStateFor(project, ureq.getIdentity(), projectBrokerModuleConfiguration));
    projectState = uifactory.addStaticTextElement("detailsform.state", stateValue + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", stateLayout);
    projectState.setLabel(null, null);
    String keyDetailsformMax = null;
    if (projectBrokerModuleConfiguration.isAcceptSelectionManually()) {
        keyDetailsformMax = "detailsform.max.candidates.label";
    } else {
        keyDetailsformMax = "detailsform.max.members.label";
    }
    selectionMaxMembers = uifactory.addCheckboxesHorizontal(keyDetailsformMax, formLayout, keys, values);
    maxMembers = uifactory.addIntegerElement("form.options.number.of.participants.per.topic_nbr", project.getMaxMembers(), formLayout);
    maxMembers.setMinValueCheck(0, null);
    maxMembers.setDisplaySize(3);
    if (project.getMaxMembers() == Project.MAX_MEMBERS_UNLIMITED) {
        maxMembers.setVisible(false);
        selectionMaxMembers.select(keys[0], false);
    } else {
        selectionMaxMembers.select(keys[0], true);
    }
    selectionMaxMembers.addActionListener(FormEvent.ONCLICK);
    String[] deselectValues = new String[] { translate("detailsform.allow.deselection.hint") };
    allowDeselection = uifactory.addCheckboxesHorizontal("detailsform.allow.deselection", formLayout, keys, deselectValues);
    allowDeselection.select(keys[0], projectGroupManager.isDeselectionAllowed(project));
    allowDeselection.addActionListener(FormEvent.ONCLICK);
    uifactory.addSpacerElement("spacer_1", formLayout, false);
    // customfields
    List<CustomField> customFields = projectBrokerModuleConfiguration.getCustomFields();
    int customFieldIndex = 0;
    for (Iterator<CustomField> iterator = customFields.iterator(); iterator.hasNext(); ) {
        CustomField customField = iterator.next();
        getLogger().debug("customField: " + customField.getName() + "=" + customField.getValue());
        StringTokenizer tok = new StringTokenizer(customField.getValue(), ProjectBrokerManager.CUSTOMFIELD_LIST_DELIMITER);
        if (customField.getValue() == null || customField.getValue().equals("") || !tok.hasMoreTokens()) {
            // no value define => Text-input
            // Add StaticTextElement as workaroung for non translated label
            // null > no label
            uifactory.addStaticTextElement("customField_label" + customFieldIndex, null, customField.getName(), formLayout);
            TextElement textElement = uifactory.addTextElement("customField_" + customFieldIndex, "", 150, project.getCustomFieldValue(customFieldIndex), formLayout);
            textElement.setDisplaySize(60);
            // textElement.setTranslator(null);
            // textElement.setLabel(customField.getName(), null);
            textElement.showLabel(false);
            customfieldElementList.add(textElement);
        } else {
            // values define => dropdown selection
            List<String> valueList = new ArrayList<String>();
            while (tok.hasMoreTokens()) {
                String value = tok.nextToken();
                valueList.add(value);
                getLogger().debug("valueList add: " + value);
            }
            String[] theValues = new String[valueList.size() + 1];
            String[] theKeys = new String[valueList.size() + 1];
            int arrayIndex = 0;
            theValues[arrayIndex] = translate(DROPDOWN_NO_SELECETION);
            theKeys[arrayIndex] = DROPDOWN_NO_SELECETION;
            arrayIndex++;
            for (Iterator<String> iterator2 = valueList.iterator(); iterator2.hasNext(); ) {
                String value = iterator2.next();
                theValues[arrayIndex] = value;
                theKeys[arrayIndex] = Integer.toString(arrayIndex);
                arrayIndex++;
            }
            // Add StaticTextElement as workaround for non translated label
            // null > no label
            uifactory.addStaticTextElement("customField_label" + customFieldIndex, null, customField.getName(), formLayout);
            SingleSelection selectionElement = uifactory.addDropdownSingleselect("customField_" + customFieldIndex, null, formLayout, theKeys, theValues, null);
            if (project.getCustomFieldValue(customFieldIndex) != null && !project.getCustomFieldValue(customFieldIndex).equals("")) {
                if (valueList.contains(project.getCustomFieldValue(customFieldIndex))) {
                    // '+1' because no-selection at the beginning
                    String key = Integer.toString(valueList.indexOf(project.getCustomFieldValue(customFieldIndex)) + 1);
                    selectionElement.select(key, true);
                } else {
                    this.showInfo("warn.customfield.key.does.not.exist", project.getCustomFieldValue(customFieldIndex));
                }
            }
            customfieldElementList.add(selectionElement);
        }
        uifactory.addSpacerElement("customField_spacer" + customFieldIndex, formLayout, false);
        customFieldIndex++;
    }
    // Events
    for (Project.EventType eventType : Project.EventType.values()) {
        if (projectBrokerModuleConfiguration.isProjectEventEnabled(eventType)) {
            ProjectEvent projectEvent = project.getProjectEvent(eventType);
            DateChooser dateChooserStart = uifactory.addDateChooser(eventType + "start", eventType.getI18nKey() + ".start.label", null, formLayout);
            dateChooserStart.setDateChooserTimeEnabled(true);
            dateChooserStart.setDisplaySize(CUSTOM_DATE_FORMAT.length());
            getLogger().info("Event=" + eventType + ", startDate=" + projectEvent.getStartDate());
            dateChooserStart.setDate(projectEvent.getStartDate());
            eventStartElementList.put(eventType, dateChooserStart);
            DateChooser dateChooserEnd = uifactory.addDateChooser(eventType + "end", eventType.getI18nKey() + ".end.label", null, formLayout);
            dateChooserEnd.setDateChooserTimeEnabled(true);
            dateChooserEnd.setDisplaySize(CUSTOM_DATE_FORMAT.length());
            getLogger().debug("Event=" + eventType + ", endDate=" + projectEvent.getEndDate());
            dateChooserEnd.setDate(projectEvent.getEndDate());
            eventEndElementList.put(eventType, dateChooserEnd);
            uifactory.addSpacerElement(eventType + "spacer", formLayout, false);
        }
    }
    attachmentFileName = uifactory.addFileElement(getWindowControl(), "detailsform.attachmentfilename.label", formLayout);
    attachmentFileName.setLabel("detailsform.attachmentfilename.label", null);
    if (project.getAttachmentFileName() != null && !project.getAttachmentFileName().equals("")) {
        attachmentFileName.setInitialFile(new File(project.getAttachmentFileName()));
        removeAttachmentLink = uifactory.addFormLink("detailsform.remove.attachment", formLayout, Link.BUTTON_XSMALL);
    }
    attachmentFileName.addActionListener(FormEvent.ONCHANGE);
    mailNotification = uifactory.addCheckboxesHorizontal("detailsform.mail.notification.label", formLayout, keys, values);
    mailNotification.select(keys[0], project.isMailNotificationEnabled());
    FormLayoutContainer buttonGroupLayout = FormLayoutContainer.createButtonLayout("buttonGroupLayout", getTranslator());
    formLayout.add(buttonGroupLayout);
    uifactory.addFormSubmitButton("save", buttonGroupLayout);
    if (this.enableCancel) {
        // TODO: Frage an PB: Warum flc hier noetig ???
        uifactory.addFormCancelButton("cancel", buttonGroupLayout, ureq, getWindowControl());
    }
}
Also used : SingleSelection(org.olat.core.gui.components.form.flexible.elements.SingleSelection) ArrayList(java.util.ArrayList) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) Project(org.olat.course.nodes.projectbroker.datamodel.Project) StringTokenizer(java.util.StringTokenizer) 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) CustomField(org.olat.course.nodes.projectbroker.datamodel.CustomField) DateChooser(org.olat.core.gui.components.form.flexible.elements.DateChooser) Identity(org.olat.core.id.Identity) File(java.io.File) 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