use of org.olat.repository.model.RepositoryEntryLifecycle in project OpenOLAT by OpenOLAT.
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 RepositoryEntryLifecycleDAO method deleteLifecycle.
public void deleteLifecycle(RepositoryEntryLifecycle lifecycle) {
RepositoryEntryLifecycle reloadedLifecycle = dbInstance.getCurrentEntityManager().getReference(RepositoryEntryLifecycle.class, lifecycle.getKey());
dbInstance.getCurrentEntityManager().remove(reloadedLifecycle);
}
use of org.olat.repository.model.RepositoryEntryLifecycle in project OpenOLAT by OpenOLAT.
the class RepositoryEntryLifecycleDAO method create.
public RepositoryEntryLifecycle create(String label, String softKey, boolean privateCycle, Date from, Date to) {
RepositoryEntryLifecycle reLifeCycle = new RepositoryEntryLifecycle();
reLifeCycle.setCreationDate(new Date());
reLifeCycle.setLastModified(new Date());
reLifeCycle.setLabel(label);
reLifeCycle.setSoftKey(softKey);
reLifeCycle.setPrivateCycle(privateCycle);
reLifeCycle.setValidFrom(from);
reLifeCycle.setValidTo(to);
dbInstance.getCurrentEntityManager().persist(reLifeCycle);
return reLifeCycle;
}
use of org.olat.repository.model.RepositoryEntryLifecycle in project OpenOLAT by OpenOLAT.
the class RepositoryManager method setDescriptionAndName.
/**
* The method updates empty and null values!
* @param re
* @param displayName
* @param externalRef
* @param authors
* @param description
* @param objectives
* @param requirements
* @param credits
* @param mainLanguage
* @param expenditureOfWork
* @param cycle
* @return
*/
public RepositoryEntry setDescriptionAndName(final RepositoryEntry re, String displayName, String externalRef, String authors, String description, String objectives, String requirements, String credits, String mainLanguage, String location, String expenditureOfWork, RepositoryEntryLifecycle cycle) {
RepositoryEntry reloadedRe = repositoryEntryDao.loadForUpdate(re);
if (reloadedRe == null) {
return null;
}
reloadedRe.setDisplayname(displayName);
reloadedRe.setAuthors(authors);
reloadedRe.setDescription(description);
reloadedRe.setExternalRef(externalRef);
reloadedRe.setObjectives(objectives);
reloadedRe.setRequirements(requirements);
reloadedRe.setCredits(credits);
reloadedRe.setMainLanguage(mainLanguage);
reloadedRe.setExpenditureOfWork(expenditureOfWork);
reloadedRe.setLocation(location);
RepositoryEntryLifecycle cycleToDelete = null;
RepositoryEntryLifecycle currentCycle = reloadedRe.getLifecycle();
if (currentCycle != null) {
// currently, it's a private cycle
if (currentCycle.isPrivateCycle()) {
// the new one is none or public, remove the private cycle
if (cycle == null || !cycle.isPrivateCycle()) {
cycleToDelete = currentCycle;
}
}
}
reloadedRe.setLifecycle(cycle);
reloadedRe.setLastModified(new Date());
RepositoryEntry updatedRe = dbInstance.getCurrentEntityManager().merge(reloadedRe);
if (cycleToDelete != null) {
dbInstance.getCurrentEntityManager().remove(cycleToDelete);
}
// fetch the values
updatedRe.getStatistics().getLaunchCounter();
if (updatedRe.getLifecycle() != null) {
updatedRe.getLifecycle().getCreationDate();
}
dbInstance.commit();
lifeIndexer.indexDocument(RepositoryEntryDocument.TYPE, updatedRe.getKey());
autoAccessManager.grantAccess(updatedRe);
return updatedRe;
}
use of org.olat.repository.model.RepositoryEntryLifecycle in project OpenOLAT by OpenOLAT.
the class RepositoryServiceImpl method isParticipantAllowedToLeave.
@Override
public boolean isParticipantAllowedToLeave(RepositoryEntry re) {
boolean allowed = false;
RepositoryEntryAllowToLeaveOptions setting = re.getAllowToLeaveOption();
if (setting == RepositoryEntryAllowToLeaveOptions.atAnyTime) {
allowed = true;
} else if (setting == RepositoryEntryAllowToLeaveOptions.afterEndDate) {
RepositoryEntryLifecycle lifecycle = re.getLifecycle();
if (lifecycle == null || lifecycle.getValidTo() == null) {
allowed = false;
} else {
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
Date now = cal.getTime();
if (now.compareTo(lifecycle.getValidTo()) >= 0) {
allowed = true;
} else {
allowed = false;
}
}
} else {
allowed = false;
}
return allowed;
}
Aggregations