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);
}
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();
}
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);
}
}
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);
}
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);
}
}
Aggregations