Search in sources :

Example 41 with RepositoryEntryLifecycle

use of org.olat.repository.model.RepositoryEntryLifecycle in project OpenOLAT by OpenOLAT.

the class RepositoryEditDescriptionController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    setFormContextHelp("Info Page: Add Meta Data");
    formLayout.setElementCssClass("o_sel_edit_repositoryentry");
    String id = repositoryEntry.getResourceableId() == null ? "-" : repositoryEntry.getResourceableId().toString();
    uifactory.addStaticTextElement("cif.id", id, formLayout);
    String externalId = repositoryEntry.getExternalId();
    if (StringHelper.containsNonWhitespace(externalId)) {
        uifactory.addStaticTextElement("cif.externalid", externalId, formLayout);
    }
    String extRef = repositoryEntry.getExternalRef();
    if (StringHelper.containsNonWhitespace(repositoryEntry.getManagedFlagsString())) {
        if (StringHelper.containsNonWhitespace(extRef)) {
            uifactory.addStaticTextElement("cif.externalref", extRef, formLayout);
        }
    } else {
        externalRef = uifactory.addTextElement("cif.externalref", "cif.externalref", 100, extRef, formLayout);
        externalRef.setHelpText(translate("cif.externalref.hover"));
        externalRef.setHelpUrlForManualPage("Info Page#_identification");
        externalRef.setDisplaySize(30);
    }
    String initalAuthor = repositoryEntry.getInitialAuthor() == null ? "-" : repositoryEntry.getInitialAuthor();
    if (repositoryEntry.getInitialAuthor() != null) {
        initalAuthor = userManager.getUserDisplayName(initalAuthor);
    }
    initalAuthor = StringHelper.escapeHtml(initalAuthor);
    uifactory.addStaticTextElement("cif.initialAuthor", initalAuthor, formLayout);
    // Add resource type
    String typeName = null;
    OLATResource res = repositoryEntry.getOlatResource();
    if (res != null) {
        typeName = res.getResourceableTypeName();
    }
    String typeDisplay;
    if (typeName != null) {
        // add image and typename code
        typeDisplay = NewControllerFactory.translateResourceableTypeName(typeName, getLocale());
    } else {
        typeDisplay = translate("cif.type.na");
    }
    uifactory.addStaticTextElement("cif.type", typeDisplay, formLayout);
    uifactory.addSpacerElement("spacer1", formLayout, false);
    displayName = uifactory.addTextElement("cif.displayname", "cif.displayname", 100, repositoryEntry.getDisplayname(), formLayout);
    displayName.setDisplaySize(30);
    displayName.setMandatory(true);
    displayName.setEnabled(!RepositoryEntryManagedFlag.isManaged(repositoryEntry, RepositoryEntryManagedFlag.title));
    authors = uifactory.addTextElement("cif.authors", "cif.authors", 255, repositoryEntry.getAuthors(), formLayout);
    authors.setDisplaySize(60);
    if (licenseModule.isEnabled(licenseHandler)) {
        license = licenseService.loadOrCreateLicense(res);
        LicenseSelectionConfig licenseSelectionConfig = LicenseUIFactory.createLicenseSelectionConfig(licenseHandler, license.getLicenseType());
        licenseEl = uifactory.addDropdownSingleselect("cif.license", formLayout, licenseSelectionConfig.getLicenseTypeKeys(), licenseSelectionConfig.getLicenseTypeValues(getLocale()));
        licenseEl.setElementCssClass("o_sel_repo_license");
        licenseEl.setMandatory(licenseSelectionConfig.isLicenseMandatory());
        if (licenseSelectionConfig.getSelectionLicenseTypeKey() != null) {
            licenseEl.select(licenseSelectionConfig.getSelectionLicenseTypeKey(), true);
        }
        licenseEl.addActionListener(FormEvent.ONCHANGE);
        licensorEl = uifactory.addTextElement("cif.licensor", 1000, license.getLicensor(), formLayout);
        String freetext = licenseService.isFreetext(license.getLicenseType()) ? license.getFreetext() : "";
        licenseFreetextEl = uifactory.addTextAreaElement("cif.freetext", 4, 72, freetext, formLayout);
        LicenseUIFactory.updateVisibility(licenseEl, licensorEl, licenseFreetextEl);
    }
    language = uifactory.addTextElement("cif.mainLanguage", "cif.mainLanguage", 16, repositoryEntry.getMainLanguage(), formLayout);
    location = uifactory.addTextElement("cif.location", "cif.location", 255, repositoryEntry.getLocation(), formLayout);
    location.setEnabled(!RepositoryEntryManagedFlag.isManaged(repositoryEntry, RepositoryEntryManagedFlag.location));
    RepositoryHandler handler = repositoryHandlerFactory.getRepositoryHandler(repositoryEntry);
    mediaContainer = handler.getMediaContainer(repositoryEntry);
    if (mediaContainer != null && mediaContainer.getName().equals("media")) {
        mediaContainer = mediaContainer.getParentContainer();
        mediaContainer.setDefaultItemFilter(new MediaContainerFilter(mediaContainer));
    }
    String desc = (repositoryEntry.getDescription() != null ? repositoryEntry.getDescription() : " ");
    description = uifactory.addRichTextElementForStringData("cif.description", "cif.description", desc, 10, -1, false, mediaContainer, null, formLayout, ureq.getUserSession(), getWindowControl());
    description.setEnabled(!RepositoryEntryManagedFlag.isManaged(repositoryEntry, RepositoryEntryManagedFlag.description));
    description.getEditorConfiguration().setFileBrowserUploadRelPath("media");
    uifactory.addSpacerElement("spacer2", formLayout, false);
    if (CourseModule.getCourseTypeName().equals(repoEntryType)) {
        String[] dateValues = new String[] { translate("cif.dates.none"), translate("cif.dates.private"), translate("cif.dates.public") };
        dateTypesEl = uifactory.addRadiosVertical("cif.dates", formLayout, dateKeys, dateValues);
        dateTypesEl.setElementCssClass("o_sel_repo_lifecycle_type");
        if (repositoryEntry.getLifecycle() == null) {
            dateTypesEl.select("none", true);
        } else if (repositoryEntry.getLifecycle().isPrivateCycle()) {
            dateTypesEl.select("private", true);
        } else {
            dateTypesEl.select("public", true);
        }
        dateTypesEl.addActionListener(FormEvent.ONCHANGE);
        List<RepositoryEntryLifecycle> cycles = lifecycleDao.loadPublicLifecycle();
        List<RepositoryEntryLifecycle> filteredCycles = new ArrayList<>();
        // just make the upcomming and acutual running cycles or the pre-selected visible in the UI
        LocalDateTime now = LocalDateTime.now();
        for (RepositoryEntryLifecycle cycle : cycles) {
            if (cycle.getValidTo() == null || now.isBefore(LocalDateTime.ofInstant(cycle.getValidTo().toInstant(), ZoneId.systemDefault())) || (repositoryEntry.getLifecycle() != null && repositoryEntry.getLifecycle().equals(cycle))) {
                filteredCycles.add(cycle);
            }
        }
        String[] publicKeys = new String[filteredCycles.size()];
        String[] publicValues = new String[filteredCycles.size()];
        int count = 0;
        for (RepositoryEntryLifecycle cycle : filteredCycles) {
            publicKeys[count] = cycle.getKey().toString();
            StringBuilder sb = new StringBuilder(32);
            boolean labelAvailable = StringHelper.containsNonWhitespace(cycle.getLabel());
            if (labelAvailable) {
                sb.append(cycle.getLabel());
            }
            if (StringHelper.containsNonWhitespace(cycle.getSoftKey())) {
                if (labelAvailable)
                    sb.append(" - ");
                sb.append(cycle.getSoftKey());
            }
            publicValues[count++] = sb.toString();
        }
        publicDatesEl = uifactory.addDropdownSingleselect("cif.public.dates", formLayout, publicKeys, publicValues, null);
        String privateDatePage = velocity_root + "/cycle_dates.html";
        privateDatesCont = FormLayoutContainer.createCustomFormLayout("private.date", getTranslator(), privateDatePage);
        privateDatesCont.setRootForm(mainForm);
        privateDatesCont.setLabel("cif.private.dates", null);
        formLayout.add("private.date", privateDatesCont);
        startDateEl = uifactory.addDateChooser("date.start", "cif.date.start", null, privateDatesCont);
        startDateEl.setElementCssClass("o_sel_repo_lifecycle_validfrom");
        endDateEl = uifactory.addDateChooser("date.end", "cif.date.end", null, privateDatesCont);
        endDateEl.setElementCssClass("o_sel_repo_lifecycle_validto");
        if (repositoryEntry.getLifecycle() != null) {
            RepositoryEntryLifecycle lifecycle = repositoryEntry.getLifecycle();
            if (lifecycle.isPrivateCycle()) {
                startDateEl.setDate(lifecycle.getValidFrom());
                endDateEl.setDate(lifecycle.getValidTo());
            } else {
                String key = lifecycle.getKey().toString();
                for (String publicKey : publicKeys) {
                    if (key.equals(publicKey)) {
                        publicDatesEl.select(key, true);
                        break;
                    }
                }
            }
        }
        updateDatesVisibility();
        uifactory.addSpacerElement("spacer3", formLayout, false);
        expenditureOfWork = uifactory.addTextElement("cif.expenditureOfWork", "cif.expenditureOfWork", 100, repositoryEntry.getExpenditureOfWork(), formLayout);
        expenditureOfWork.setExampleKey("details.expenditureOfWork.example", null);
        String obj = (repositoryEntry.getObjectives() != null ? repositoryEntry.getObjectives() : " ");
        objectives = uifactory.addRichTextElementForStringData("cif.objectives", "cif.objectives", obj, 10, -1, false, mediaContainer, null, formLayout, ureq.getUserSession(), getWindowControl());
        objectives.setEnabled(!RepositoryEntryManagedFlag.isManaged(repositoryEntry, RepositoryEntryManagedFlag.objectives));
        objectives.getEditorConfiguration().setFileBrowserUploadRelPath("media");
        String req = (repositoryEntry.getRequirements() != null ? repositoryEntry.getRequirements() : " ");
        requirements = uifactory.addRichTextElementForStringData("cif.requirements", "cif.requirements", req, 10, -1, false, mediaContainer, null, formLayout, ureq.getUserSession(), getWindowControl());
        requirements.setEnabled(!RepositoryEntryManagedFlag.isManaged(repositoryEntry, RepositoryEntryManagedFlag.requirements));
        requirements.getEditorConfiguration().setFileBrowserUploadRelPath("media");
        requirements.setMaxLength(2000);
        String cred = (repositoryEntry.getCredits() != null ? repositoryEntry.getCredits() : " ");
        credits = uifactory.addRichTextElementForStringData("cif.credits", "cif.credits", cred, 10, -1, false, mediaContainer, null, formLayout, ureq.getUserSession(), getWindowControl());
        credits.setEnabled(!RepositoryEntryManagedFlag.isManaged(repositoryEntry, RepositoryEntryManagedFlag.credits));
        credits.getEditorConfiguration().setFileBrowserUploadRelPath("media");
        credits.setMaxLength(2000);
        uifactory.addSpacerElement("spacer4", formLayout, false);
    }
    boolean managed = RepositoryEntryManagedFlag.isManaged(repositoryEntry, RepositoryEntryManagedFlag.details);
    VFSLeaf img = repositoryManager.getImage(repositoryEntry);
    fileUpload = uifactory.addFileElement(getWindowControl(), "rentry.pic", "rentry.pic", formLayout);
    fileUpload.setExampleKey("rentry.pic.example", new String[] { RepositoryManager.PICTURE_WIDTH + "x" + (RepositoryManager.PICTURE_HEIGHT) });
    fileUpload.setMaxUploadSizeKB(picUploadlimitKB, null, null);
    fileUpload.setPreview(ureq.getUserSession(), true);
    fileUpload.addActionListener(FormEvent.ONCHANGE);
    fileUpload.setDeleteEnabled(!managed);
    if (img instanceof LocalFileImpl) {
        fileUpload.setPreview(ureq.getUserSession(), true);
        fileUpload.setInitialFile(((LocalFileImpl) img).getBasefile());
    }
    fileUpload.setVisible(!managed);
    fileUpload.limitToMimeType(imageMimeTypes, "cif.error.mimetype", new String[] { imageMimeTypes.toString() });
    VFSLeaf movie = repositoryService.getIntroductionMovie(repositoryEntry);
    movieUpload = uifactory.addFileElement(getWindowControl(), "rentry.movie", "rentry.movie", formLayout);
    movieUpload.setExampleKey("rentry.movie.example", new String[] { "3:2" });
    movieUpload.setMaxUploadSizeKB(movieUploadlimitKB, null, null);
    movieUpload.setPreview(ureq.getUserSession(), true);
    movieUpload.addActionListener(FormEvent.ONCHANGE);
    movieUpload.setDeleteEnabled(!managed);
    if (movie instanceof LocalFileImpl) {
        movieUpload.setPreview(ureq.getUserSession(), true);
        movieUpload.setInitialFile(((LocalFileImpl) movie).getBasefile());
    }
    movieUpload.setVisible(!managed);
    FormLayoutContainer buttonContainer = FormLayoutContainer.createButtonLayout("buttonContainer", getTranslator());
    formLayout.add("buttonContainer", buttonContainer);
    buttonContainer.setElementCssClass("o_sel_repo_save_details");
    submit = uifactory.addFormSubmitButton("submit", buttonContainer);
    submit.setVisible(!managed);
    uifactory.addFormCancelButton("cancel", buttonContainer, ureq, getWindowControl());
}
Also used : LocalDateTime(java.time.LocalDateTime) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) LicenseSelectionConfig(org.olat.core.commons.services.license.ui.LicenseSelectionConfig) ArrayList(java.util.ArrayList) OLATResource(org.olat.resource.OLATResource) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) RepositoryEntryLifecycle(org.olat.repository.model.RepositoryEntryLifecycle) RepositoryHandler(org.olat.repository.handlers.RepositoryHandler)

Example 42 with RepositoryEntryLifecycle

use of org.olat.repository.model.RepositoryEntryLifecycle in project OpenOLAT by OpenOLAT.

the class RepositoryManagerTest method setDescriptionAndName_lifecycle.

@Test
public void setDescriptionAndName_lifecycle() {
    RepositoryEntryLifecycle publicCycle = lifecycleDao.create("Public 1", "Soft public 1", false, new Date(), new Date());
    RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry();
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(re);
    String newName = "Brand new name";
    String newDesc = "Brand new description";
    re = repositoryManager.setDescriptionAndName(re, newName, null, null, newDesc, null, null, null, null, null, null, publicCycle);
    Assert.assertNotNull(re);
    dbInstance.commitAndCloseSession();
    RepositoryEntry reloaded = repositoryManager.lookupRepositoryEntry(re.getKey());
    Assert.assertNotNull(reloaded);
    Assert.assertEquals("Brand new name", reloaded.getDisplayname());
    Assert.assertEquals("Brand new description", reloaded.getDescription());
    Assert.assertEquals(publicCycle, reloaded.getLifecycle());
}
Also used : RepositoryEntryLifecycle(org.olat.repository.model.RepositoryEntryLifecycle) Date(java.util.Date) Test(org.junit.Test)

Example 43 with RepositoryEntryLifecycle

use of org.olat.repository.model.RepositoryEntryLifecycle in project OpenOLAT by OpenOLAT.

the class RepositoryEntryLifecycleDAOTest method loadLifeCycle_byEntry.

@Test
public void loadLifeCycle_byEntry() {
    RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry("", false);
    String label = "A life cycle";
    String softKey = UUID.randomUUID().toString();
    Calendar cal = Calendar.getInstance();
    cal.setTime(new Date());
    cal.add(Calendar.DATE, -1);
    Date from = cal.getTime();
    cal.add(Calendar.DATE, +2);
    Date to = cal.getTime();
    RepositoryEntryLifecycle cycle = reLifeCycleDao.create(label, softKey, true, from, to);
    re.setLifecycle(cycle);
    re = dbInstance.getCurrentEntityManager().merge(re);
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(cycle);
    Assert.assertNotNull(cycle.getKey());
    // check
    RepositoryEntryLifecycle loadedLifeCycle = reLifeCycleDao.loadByEntry(re);
    Assert.assertNotNull(loadedLifeCycle);
    Assert.assertNotNull(loadedLifeCycle.getCreationDate());
    Assert.assertNotNull(loadedLifeCycle.getLastModified());
    Assert.assertEquals(cycle.getKey(), loadedLifeCycle.getKey());
    Assert.assertEquals("A life cycle", loadedLifeCycle.getLabel());
    Assert.assertEquals(softKey, loadedLifeCycle.getSoftKey());
    Assert.assertTrue(loadedLifeCycle.isPrivateCycle());
    Assert.assertNotNull(loadedLifeCycle.getValidFrom());
    Assert.assertNotNull(loadedLifeCycle.getValidTo());
}
Also used : RepositoryEntryLifecycle(org.olat.repository.model.RepositoryEntryLifecycle) Calendar(java.util.Calendar) RepositoryEntry(org.olat.repository.RepositoryEntry) Date(java.util.Date) Test(org.junit.Test)

Example 44 with RepositoryEntryLifecycle

use of org.olat.repository.model.RepositoryEntryLifecycle in project OpenOLAT by OpenOLAT.

the class RepositoryEntryLifecycleDAOTest method createLifeCycle.

@Test
public void createLifeCycle() {
    String label = "My first life cycle";
    String softKey = UUID.randomUUID().toString();
    Calendar cal = Calendar.getInstance();
    cal.setTime(new Date());
    cal.add(Calendar.DATE, -1);
    Date from = cal.getTime();
    cal.add(Calendar.DATE, +2);
    Date to = cal.getTime();
    RepositoryEntryLifecycle relf = reLifeCycleDao.create(label, softKey, true, from, to);
    dbInstance.commitAndCloseSession();
    // check
    Assert.assertNotNull(relf);
    Assert.assertNotNull(relf.getKey());
    Assert.assertNotNull(relf.getCreationDate());
    Assert.assertNotNull(relf.getLastModified());
    Assert.assertEquals("My first life cycle", relf.getLabel());
    Assert.assertEquals(softKey, relf.getSoftKey());
    Assert.assertTrue(relf.isPrivateCycle());
    Assert.assertEquals(from, relf.getValidFrom());
    Assert.assertEquals(to, relf.getValidTo());
}
Also used : RepositoryEntryLifecycle(org.olat.repository.model.RepositoryEntryLifecycle) Calendar(java.util.Calendar) Date(java.util.Date) Test(org.junit.Test)

Example 45 with RepositoryEntryLifecycle

use of org.olat.repository.model.RepositoryEntryLifecycle in project OpenOLAT by OpenOLAT.

the class GTAManagerImpl method getReferenceDate.

@Override
public DueDate getReferenceDate(int numOfDays, String relativeTo, TaskRef assignedTask, IdentityRef assessedIdentity, BusinessGroup assessedGroup, RepositoryEntry courseEntry) {
    DueDate dueDate = null;
    if (numOfDays >= 0 && StringHelper.containsNonWhitespace(relativeTo)) {
        GTARelativeToDates rel = GTARelativeToDates.valueOf(relativeTo);
        Date referenceDate = null;
        String messageKey = null;
        String messageArg = null;
        switch(rel) {
            case courseStart:
                {
                    RepositoryEntryLifecycle lifecycle = getRepositoryEntryLifecycle(courseEntry);
                    if (lifecycle != null && lifecycle.getValidFrom() != null) {
                        referenceDate = lifecycle.getValidFrom();
                    }
                    break;
                }
            case courseLaunch:
                {
                    if (assessedIdentity != null) {
                        referenceDate = userCourseInformationsManager.getInitialLaunchDate(courseEntry, assessedIdentity);
                    } else {
                        referenceDate = userCourseInformationsManager.getInitialParticipantLaunchDate(courseEntry, assessedGroup);
                    }
                    break;
                }
            case enrollment:
                {
                    if (assessedIdentity != null) {
                        referenceDate = repositoryService.getEnrollmentDate(courseEntry, assessedIdentity);
                    } else {
                        referenceDate = getEnrollmentDate(assessedGroup);
                    }
                    break;
                }
            case assignment:
                {
                    if (assignedTask != null) {
                        referenceDate = assignedTask.getAssignmentDate();
                    } else {
                        messageKey = "relative.to.assignment.message";
                        messageArg = Integer.toString(numOfDays);
                    }
                    break;
                }
        }
        if (referenceDate != null) {
            Calendar cal = Calendar.getInstance();
            cal.setTime(referenceDate);
            cal.add(Calendar.DATE, numOfDays);
            dueDate = new DueDate(true, cal.getTime());
        } else if (messageKey != null) {
            dueDate = new DueDate(true, messageKey, messageArg);
        }
    }
    return dueDate;
}
Also used : GTARelativeToDates(org.olat.course.nodes.gta.GTARelativeToDates) RepositoryEntryLifecycle(org.olat.repository.model.RepositoryEntryLifecycle) Calendar(java.util.Calendar) TaskDueDate(org.olat.course.nodes.gta.TaskDueDate) DueDate(org.olat.course.nodes.gta.model.DueDate) Date(java.util.Date) TaskDueDate(org.olat.course.nodes.gta.TaskDueDate) TaskRevisionDate(org.olat.course.nodes.gta.TaskRevisionDate) DueDate(org.olat.course.nodes.gta.model.DueDate)

Aggregations

RepositoryEntryLifecycle (org.olat.repository.model.RepositoryEntryLifecycle)54 Date (java.util.Date)34 Test (org.junit.Test)22 Calendar (java.util.Calendar)18 ArrayList (java.util.ArrayList)12 RepositoryEntry (org.olat.repository.RepositoryEntry)12 List (java.util.List)6 Identity (org.olat.core.id.Identity)6 RepositoryEntryLifecycleVO (org.olat.restapi.support.vo.RepositoryEntryLifecycleVO)6 Produces (javax.ws.rs.Produces)4 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)4 VFSContainer (org.olat.core.util.vfs.VFSContainer)4 ICourse (org.olat.course.ICourse)4 CourseEditorEnv (org.olat.course.editor.CourseEditorEnv)4 RepositoryEntryLifecycleDAO (org.olat.repository.manager.RepositoryEntryLifecycleDAO)4 LocalFileImpl (org.olat.core.util.vfs.LocalFileImpl)3 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)3 File (java.io.File)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2