Search in sources :

Example 36 with RepositoryEntryLifecycle

use of org.olat.repository.model.RepositoryEntryLifecycle in project openolat by klemens.

the class LecturesSearchFormController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    login = uifactory.addTextElement("login", "search.form.login", 128, "", formLayout);
    login.setVisible(adminProps);
    userPropertyHandlers = userManager.getUserPropertyHandlersFor(PROPS_IDENTIFIER, adminProps);
    for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
        if (userPropertyHandler != null) {
            FormItem fi = userPropertyHandler.addFormItem(getLocale(), null, PROPS_IDENTIFIER, false, formLayout);
            fi.setMandatory(false);
            // DO NOT validate email field => see OLAT-3324, OO-155, OO-222
            if (userPropertyHandler instanceof EmailProperty && fi instanceof TextElement) {
                TextElement textElement = (TextElement) fi;
                textElement.setItemValidatorProvider(null);
            }
            propFormItems.put(userPropertyHandler.getName(), fi);
        }
    }
    bulkEl = uifactory.addTextAreaElement("bulk", 4, 72, "", formLayout);
    bulkEl.setHelpText(translate("bulk.hint"));
    bulkEl.setExampleKey("bulk.example", null);
    List<RepositoryEntryLifecycle> cycles = lifecycleDao.loadPublicLifecycle();
    String[] dateKeys;
    String[] dateValues;
    if (cycles.isEmpty()) {
        dateKeys = new String[] { "none", "private" };
        dateValues = new String[] { translate("dates.none"), translate("dates.private") };
    } else {
        dateKeys = new String[] { "none", "private", "public" };
        dateValues = new String[] { translate("dates.none"), translate("dates.private"), translate("dates.public") };
    }
    dateTypesEl = uifactory.addRadiosVertical("dates", formLayout, dateKeys, dateValues);
    dateTypesEl.select(dateKeys[0], true);
    dateTypesEl.addActionListener(FormEvent.ONCHANGE);
    List<RepositoryEntryLifecycle> filteredCycles = new ArrayList<>();
    for (RepositoryEntryLifecycle cycle : cycles) {
        if (cycle.getValidTo() == null) {
            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("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("private.dates", null);
    formLayout.add("private.date", privateDatesCont);
    startDateEl = uifactory.addDateChooser("date.start", "date.start", null, privateDatesCont);
    startDateEl.setElementCssClass("o_sel_repo_lifecycle_validfrom");
    endDateEl = uifactory.addDateChooser("date.end", "date.end", null, privateDatesCont);
    endDateEl.setElementCssClass("o_sel_repo_lifecycle_validto");
    FormLayoutContainer buttonCont = FormLayoutContainer.createButtonLayout("buttons", getTranslator());
    formLayout.add(buttonCont);
    uifactory.addFormSubmitButton("search", buttonCont);
}
Also used : FormItem(org.olat.core.gui.components.form.flexible.FormItem) ArrayList(java.util.ArrayList) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) EmailProperty(org.olat.user.propertyhandlers.EmailProperty) TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement) RepositoryEntryLifecycle(org.olat.repository.model.RepositoryEntryLifecycle) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Example 37 with RepositoryEntryLifecycle

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

the class RepositoryEntryResource method updateEntry.

@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response updateEntry(@PathParam("repoEntryKey") String repoEntryKey, RepositoryEntryVO vo, @Context HttpServletRequest request) {
    if (!RestSecurityHelper.isAuthor(request)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    final RepositoryEntry re = lookupRepositoryEntry(repoEntryKey);
    if (re == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    RepositoryEntryLifecycle lifecycle = null;
    RepositoryEntryLifecycleVO lifecycleVo = vo.getLifecycle();
    if (lifecycleVo != null) {
        RepositoryEntryLifecycleDAO lifecycleDao = CoreSpringFactory.getImpl(RepositoryEntryLifecycleDAO.class);
        if (lifecycleVo.getKey() != null) {
            lifecycle = lifecycleDao.loadById(lifecycleVo.getKey());
            if (lifecycle.isPrivateCycle()) {
                // check date
                String fromStr = lifecycleVo.getValidFrom();
                String toStr = lifecycleVo.getValidTo();
                String label = lifecycleVo.getLabel();
                String softKey = lifecycleVo.getSoftkey();
                Date from = ObjectFactory.parseDate(fromStr);
                Date to = ObjectFactory.parseDate(toStr);
                lifecycle.setLabel(label);
                lifecycle.setSoftKey(softKey);
                lifecycle.setValidFrom(from);
                lifecycle.setValidTo(to);
            }
        } else {
            String fromStr = lifecycleVo.getValidFrom();
            String toStr = lifecycleVo.getValidTo();
            String label = lifecycleVo.getLabel();
            String softKey = lifecycleVo.getSoftkey();
            Date from = ObjectFactory.parseDate(fromStr);
            Date to = ObjectFactory.parseDate(toStr);
            lifecycle = lifecycleDao.create(label, softKey, true, from, to);
        }
    }
    RepositoryEntry reloaded = repositoryManager.setDescriptionAndName(re, vo.getDisplayname(), vo.getDescription(), vo.getLocation(), vo.getAuthors(), vo.getExternalId(), vo.getExternalRef(), vo.getManagedFlags(), lifecycle);
    RepositoryEntryVO rvo = ObjectFactory.get(reloaded);
    return Response.ok(rvo).build();
}
Also used : RepositoryEntryVO(org.olat.restapi.support.vo.RepositoryEntryVO) RepositoryEntryLifecycle(org.olat.repository.model.RepositoryEntryLifecycle) RepositoryEntry(org.olat.repository.RepositoryEntry) RepositoryEntryLifecycleVO(org.olat.restapi.support.vo.RepositoryEntryLifecycleVO) RepositoryEntryLifecycleDAO(org.olat.repository.manager.RepositoryEntryLifecycleDAO) Date(java.util.Date) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes)

Example 38 with RepositoryEntryLifecycle

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

the class ReminderRuleEngineTest method afterBeginDate.

@Test
public void afterBeginDate() {
    // create a course with 3 members
    Identity id1 = JunitTestHelper.createAndPersistIdentityAsRndUser("before-begin-1");
    Identity id2 = JunitTestHelper.createAndPersistIdentityAsRndUser("before-begin-2");
    Identity id3 = JunitTestHelper.createAndPersistIdentityAsRndUser("before-begin-3");
    ICourse course = CoursesWebService.createEmptyCourse(null, "initial-launch-dates", "course long name", null);
    RepositoryEntry re = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    Calendar cal = Calendar.getInstance();
    // now
    cal.setTime(new Date());
    cal.add(Calendar.DATE, -21);
    Date validFrom = cal.getTime();
    cal.add(Calendar.DATE, 90);
    Date validTo = cal.getTime();
    RepositoryEntryLifecycle cycle = lifecycleDao.create("Cycle 1", "Cycle soft 1", false, validFrom, validTo);
    re = repositoryManager.setDescriptionAndName(re, null, null, null, null, null, null, null, cycle);
    repositoryEntryRelationDao.addRole(id1, re, GroupRoles.owner.name());
    repositoryEntryRelationDao.addRole(id2, re, GroupRoles.coach.name());
    repositoryEntryRelationDao.addRole(id3, re, GroupRoles.participant.name());
    dbInstance.commit();
    {
        // check after 2 days
        List<ReminderRule> rules = getRepositoryEntryLifecycleRuleValidFromRule(2, LaunchUnit.day);
        boolean match = ruleEngine.evaluateRepositoryEntryRule(re, rules);
        Assert.assertTrue(match);
    }
    {
        // check after 7 days (between begin and and date)
        List<ReminderRule> rules = getRepositoryEntryLifecycleRuleValidFromRule(7, LaunchUnit.day);
        boolean match = ruleEngine.evaluateRepositoryEntryRule(re, rules);
        Assert.assertTrue(match);
    }
    {
        // check after 2 week s
        List<ReminderRule> rules = getRepositoryEntryLifecycleRuleValidFromRule(2, LaunchUnit.week);
        boolean match = ruleEngine.evaluateRepositoryEntryRule(re, rules);
        Assert.assertTrue(match);
    }
    {
        // check after 21 days
        List<ReminderRule> rules = getRepositoryEntryLifecycleRuleValidFromRule(21, LaunchUnit.day);
        boolean match = ruleEngine.evaluateRepositoryEntryRule(re, rules);
        Assert.assertTrue(match);
    }
    {
        // check after 3 weeks
        List<ReminderRule> rules = getRepositoryEntryLifecycleRuleValidFromRule(3, LaunchUnit.week);
        boolean match = ruleEngine.evaluateRepositoryEntryRule(re, rules);
        Assert.assertTrue(match);
    }
    {
        // check after 22 days
        List<ReminderRule> rules = getRepositoryEntryLifecycleRuleValidFromRule(22, LaunchUnit.day);
        boolean match = ruleEngine.evaluateRepositoryEntryRule(re, rules);
        Assert.assertFalse(match);
    }
    {
        // check after 4 weeks
        List<ReminderRule> rules = getRepositoryEntryLifecycleRuleValidFromRule(4, LaunchUnit.week);
        boolean match = ruleEngine.evaluateRepositoryEntryRule(re, rules);
        Assert.assertFalse(match);
    }
    {
        // check after 1 month
        List<ReminderRule> rules = getRepositoryEntryLifecycleRuleValidFromRule(1, LaunchUnit.month);
        boolean match = ruleEngine.evaluateRepositoryEntryRule(re, rules);
        Assert.assertFalse(match);
    }
}
Also used : RepositoryEntryLifecycle(org.olat.repository.model.RepositoryEntryLifecycle) Calendar(java.util.Calendar) ICourse(org.olat.course.ICourse) List(java.util.List) ArrayList(java.util.ArrayList) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) Date(java.util.Date) Test(org.junit.Test)

Example 39 with RepositoryEntryLifecycle

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

the class RepositoryEntryLifecycleTest method testGetEntries.

@Test
public void testGetEntries() throws IOException, URISyntaxException {
    // create a public life cycle
    RepositoryEntryLifecycle reLifeCycle = reLifeCycleDao.create("REST life cycle", "Unique", false, null, null);
    Calendar cal = Calendar.getInstance();
    cal.setTime(new Date());
    cal.add(Calendar.DATE, -2);
    Date from = cal.getTime();
    cal.add(Calendar.DATE, 5);
    Date to = cal.getTime();
    RepositoryEntryLifecycle limitLifeCycle = reLifeCycleDao.create("REST life cycle", "Unique", false, from, to);
    dbInstance.commitAndCloseSession();
    // retrieve the public life cycles
    RestConnection conn = new RestConnection();
    assertTrue(conn.login("administrator", "openolat"));
    URI request = UriBuilder.fromUri(getContextURI()).path("repo/lifecycle").build();
    HttpGet method = conn.createGet(request, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    InputStream body = response.getEntity().getContent();
    List<RepositoryEntryLifecycleVO> entryVoes = parseRepoArray(body);
    assertNotNull(entryVoes);
    int found = 0;
    for (RepositoryEntryLifecycleVO entryVo : entryVoes) {
        if (reLifeCycle.getKey().equals(entryVo.getKey())) {
            found++;
        } else if (limitLifeCycle.getKey().equals(entryVo.getKey())) {
            found++;
        }
    }
    conn.shutdown();
    Assert.assertEquals(2, found);
}
Also used : RepositoryEntryLifecycle(org.olat.repository.model.RepositoryEntryLifecycle) InputStream(java.io.InputStream) Calendar(java.util.Calendar) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) RepositoryEntryLifecycleVO(org.olat.restapi.support.vo.RepositoryEntryLifecycleVO) URI(java.net.URI) Date(java.util.Date) Test(org.junit.Test)

Example 40 with RepositoryEntryLifecycle

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

the class RepositoryEditDescriptionController method formOK.

@Override
protected void formOK(UserRequest ureq) {
    if (licenseModule.isEnabled(licenseHandler)) {
        if (licenseEl != null && licenseEl.isOneSelected()) {
            String licenseTypeKey = licenseEl.getSelectedKey();
            LicenseType licneseType = licenseService.loadLicenseTypeByKey(licenseTypeKey);
            license.setLicenseType(licneseType);
        }
        String licensor = null;
        String freetext = null;
        if (licensorEl != null && licensorEl.isVisible()) {
            licensor = StringHelper.containsNonWhitespace(licensorEl.getValue()) ? licensorEl.getValue() : null;
        }
        if (licenseFreetextEl != null && licenseFreetextEl.isVisible()) {
            freetext = StringHelper.containsNonWhitespace(licenseFreetextEl.getValue()) ? licenseFreetextEl.getValue() : null;
        }
        license.setLicensor(licensor);
        license.setFreetext(freetext);
        license = licenseService.update(license);
        licensorEl.setValue(license.getLicensor());
        licenseFreetextEl.setValue(license.getFreetext());
    }
    File uploadedImage = fileUpload.getUploadFile();
    if (uploadedImage != null && uploadedImage.exists()) {
        VFSContainer tmpHome = new LocalFolderImpl(new File(WebappHelper.getTmpDir()));
        VFSContainer container = tmpHome.createChildContainer(UUID.randomUUID().toString());
        // give it it's real name and extension
        VFSLeaf newFile = fileUpload.moveUploadFileTo(container);
        boolean ok = repositoryManager.setImage(newFile, repositoryEntry);
        if (!ok) {
            showWarning("cif.error.image");
        } else {
            VFSLeaf image = repositoryManager.getImage(repositoryEntry);
            if (image instanceof LocalFileImpl) {
                fileUpload.setInitialFile(((LocalFileImpl) image).getBasefile());
            }
        }
        container.delete();
    }
    File uploadedMovie = movieUpload.getUploadFile();
    if (uploadedMovie != null && uploadedMovie.exists()) {
        VFSContainer m = (VFSContainer) mediaContainer.resolve("media");
        VFSLeaf newFile = movieUpload.moveUploadFileTo(m);
        if (newFile == null) {
            showWarning("cif.error.movie");
        } else {
            String filename = movieUpload.getUploadFileName();
            String extension = FileUtils.getFileSuffix(filename);
            newFile.rename(repositoryEntry.getKey() + "." + extension);
        }
    }
    String displayname = displayName.getValue().trim();
    repositoryEntry.setDisplayname(displayname);
    String mainLanguage = language.getValue();
    if (StringHelper.containsNonWhitespace(mainLanguage)) {
        repositoryEntry.setMainLanguage(mainLanguage);
    } else {
        repositoryEntry.setMainLanguage(null);
    }
    if (dateTypesEl != null) {
        String type = "none";
        if (dateTypesEl.isOneSelected()) {
            type = dateTypesEl.getSelectedKey();
        }
        if ("none".equals(type)) {
            repositoryEntry.setLifecycle(null);
        } else if ("public".equals(type)) {
            String key = publicDatesEl.getSelectedKey();
            if (StringHelper.isLong(key)) {
                Long cycleKey = Long.parseLong(key);
                RepositoryEntryLifecycle cycle = lifecycleDao.loadById(cycleKey);
                repositoryEntry.setLifecycle(cycle);
            }
        } else if ("private".equals(type)) {
            Date start = startDateEl.getDate();
            Date end = endDateEl.getDate();
            RepositoryEntryLifecycle cycle = repositoryEntry.getLifecycle();
            if (cycle == null || !cycle.isPrivateCycle()) {
                String softKey = "lf_" + repositoryEntry.getSoftkey();
                cycle = lifecycleDao.create(displayname, softKey, true, start, end);
            } else {
                cycle.setValidFrom(start);
                cycle.setValidTo(end);
                cycle = lifecycleDao.updateLifecycle(cycle);
            }
            repositoryEntry.setLifecycle(cycle);
        }
    }
    if (externalRef != null && externalRef.isEnabled()) {
        String ref = externalRef.getValue().trim();
        repositoryEntry.setExternalRef(ref);
    }
    String desc = description.getValue().trim();
    repositoryEntry.setDescription(desc);
    if (authors != null) {
        String auth = authors.getValue().trim();
        repositoryEntry.setAuthors(auth);
    }
    if (objectives != null) {
        String obj = objectives.getValue().trim();
        repositoryEntry.setObjectives(obj);
    }
    if (requirements != null) {
        String req = requirements.getValue().trim();
        repositoryEntry.setRequirements(req);
    }
    if (credits != null) {
        String cred = credits.getValue().trim();
        repositoryEntry.setCredits(cred);
    }
    if (expenditureOfWork != null) {
        String exp = expenditureOfWork.getValue().trim();
        repositoryEntry.setExpenditureOfWork(exp);
    }
    if (location != null) {
        String loc = location.getValue().trim();
        repositoryEntry.setLocation(loc);
    }
    repositoryEntry = repositoryManager.setDescriptionAndName(repositoryEntry, repositoryEntry.getDisplayname(), repositoryEntry.getExternalRef(), repositoryEntry.getAuthors(), repositoryEntry.getDescription(), repositoryEntry.getObjectives(), repositoryEntry.getRequirements(), repositoryEntry.getCredits(), repositoryEntry.getMainLanguage(), repositoryEntry.getLocation(), repositoryEntry.getExpenditureOfWork(), repositoryEntry.getLifecycle());
    if (repositoryEntry == null) {
        showWarning("repositoryentry.not.existing");
        fireEvent(ureq, Event.CLOSE_EVENT);
    } else {
        fireEvent(ureq, Event.CHANGED_EVENT);
        MultiUserEvent modifiedEvent = new EntryChangedEvent(repositoryEntry, getIdentity(), Change.modifiedDescription, "authoring");
        CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(modifiedEvent, RepositoryService.REPOSITORY_EVENT_ORES);
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) Date(java.util.Date) LicenseType(org.olat.core.commons.services.license.LicenseType) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl) EntryChangedEvent(org.olat.repository.controllers.EntryChangedEvent) RepositoryEntryLifecycle(org.olat.repository.model.RepositoryEntryLifecycle) File(java.io.File) MultiUserEvent(org.olat.core.util.event.MultiUserEvent)

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