use of org.olat.repository.handlers.RepositoryHandler in project openolat by klemens.
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());
}
use of org.olat.repository.handlers.RepositoryHandler in project openolat by klemens.
the class CoursesWebService method copyCourse.
private static ICourse copyCourse(Long copyFrom, UserRequest ureq, Identity initialAuthor, String shortTitle, String longTitle, String displayName, String description, String softKey, int access, boolean membersOnly, String authors, String location, String externalId, String externalRef, String managedFlags, CourseConfigVO courseConfigVO) {
// String learningObjectives = name + " (Example of creating a new course)";
OLATResourceable originalOresTrans = OresHelper.createOLATResourceableInstance(CourseModule.class, copyFrom);
RepositoryEntry src = RepositoryManager.getInstance().lookupRepositoryEntry(originalOresTrans, false);
if (src == null) {
src = RepositoryManager.getInstance().lookupRepositoryEntry(copyFrom, false);
}
if (src == null) {
log.warn("Cannot find course to copy from: " + copyFrom);
return null;
}
OLATResource originalOres = OLATResourceManager.getInstance().findResourceable(src.getOlatResource());
boolean isAlreadyLocked = RepositoryHandlerFactory.getInstance().getRepositoryHandler(src).isLocked(originalOres);
LockResult lockResult = RepositoryHandlerFactory.getInstance().getRepositoryHandler(src).acquireLock(originalOres, ureq.getIdentity());
// check range of access
if (access < 1 || access > RepositoryEntry.ACC_USERS_GUESTS) {
access = RepositoryEntry.ACC_OWNERS;
}
if (lockResult == null || (lockResult != null && lockResult.isSuccess()) && !isAlreadyLocked) {
RepositoryService repositoryService = CoreSpringFactory.getImpl(RepositoryService.class);
// create new repo entry
String name;
if (description == null || description.trim().length() == 0) {
description = src.getDescription();
}
if (courseConfigVO != null && StringHelper.containsNonWhitespace(displayName)) {
name = displayName;
} else {
name = "Copy of " + src.getDisplayname();
}
String resName = src.getResourcename();
if (resName == null) {
resName = "";
}
OLATResource sourceResource = src.getOlatResource();
OLATResource copyResource = OLATResourceManager.getInstance().createOLATResourceInstance(sourceResource.getResourceableTypeName());
RepositoryEntry preparedEntry = repositoryService.create(initialAuthor, null, resName, name, description, copyResource, RepositoryEntry.ACC_OWNERS);
RepositoryHandler handler = RepositoryHandlerFactory.getInstance().getRepositoryHandler(src);
preparedEntry = handler.copy(initialAuthor, src, preparedEntry);
preparedEntry.setCanDownload(src.getCanDownload());
if (StringHelper.containsNonWhitespace(softKey)) {
preparedEntry.setSoftkey(softKey);
}
if (StringHelper.containsNonWhitespace(externalId)) {
preparedEntry.setExternalId(externalId);
}
if (StringHelper.containsNonWhitespace(externalRef)) {
preparedEntry.setExternalRef(externalRef);
}
if (StringHelper.containsNonWhitespace(authors)) {
preparedEntry.setAuthors(authors);
}
if (StringHelper.containsNonWhitespace(location)) {
preparedEntry.setLocation(location);
}
if (StringHelper.containsNonWhitespace(managedFlags)) {
preparedEntry.setManagedFlagsString(managedFlags);
}
if (membersOnly) {
preparedEntry.setMembersOnly(true);
preparedEntry.setAccess(RepositoryEntry.ACC_OWNERS);
} else {
preparedEntry.setAccess(access);
}
preparedEntry.setAllowToLeaveOption(src.getAllowToLeaveOption());
repositoryService.update(preparedEntry);
// copy image if available
RepositoryManager.getInstance().copyImage(src, preparedEntry);
ICourse course = prepareCourse(preparedEntry, shortTitle, longTitle, courseConfigVO);
RepositoryHandlerFactory.getInstance().getRepositoryHandler(src).releaseLock(lockResult);
return course;
}
return null;
}
use of org.olat.repository.handlers.RepositoryHandler in project openolat by klemens.
the class CoursesWebService method importCourse.
public static ICourse importCourse(UserRequest ureq, Identity identity, File fCourseImportZIP, String displayName, String softKey, int access, boolean membersOnly) {
log.info("REST Import course " + displayName + " START");
if (!StringHelper.containsNonWhitespace(displayName)) {
displayName = "import-" + UUID.randomUUID().toString();
}
RepositoryHandler handler = RepositoryHandlerFactory.getInstance().getRepositoryHandler(CourseModule.getCourseTypeName());
RepositoryEntry re = handler.importResource(identity, null, displayName, null, true, Locale.ENGLISH, fCourseImportZIP, null);
if (StringHelper.containsNonWhitespace(softKey)) {
re.setSoftkey(softKey);
}
// make the repository
if (membersOnly) {
re.setMembersOnly(true);
re.setAccess(RepositoryEntry.ACC_OWNERS);
} else {
re.setAccess(access);
}
CoreSpringFactory.getImpl(RepositoryService.class).update(re);
log.info("REST Import course " + displayName + " END");
// publish
log.info("REST Publish course " + displayName + " START");
ICourse course = CourseFactory.loadCourse(re);
CourseFactory.publishCourse(course, RepositoryEntry.ACC_USERS, false, identity, ureq.getLocale());
log.info("REST Publish course " + displayName + " END");
return course;
}
use of org.olat.repository.handlers.RepositoryHandler in project openolat by klemens.
the class AuthorListController method doOverrideCloseResource.
private void doOverrideCloseResource(UserRequest ureq, AuthoringEntryRow row) {
try {
RepositoryHandler handler = repositoryHandlerFactory.getRepositoryHandler(row.getResourceType());
if (handler != null) {
String businessPath = "[RepositoryEntry:" + row.getKey() + "]";
ureq.getUserSession().putEntry("override_readonly_" + row.getKey(), Boolean.TRUE);
if (!NewControllerFactory.getInstance().launch(businessPath, ureq, getWindowControl())) {
tableEl.reloadData();
}
}
} catch (CorruptedCourseException e) {
logError("Course corrupted: " + row.getKey() + " (" + row.getOLATResourceable().getResourceableId() + ")", e);
showError("cif.error.corrupted");
}
}
use of org.olat.repository.handlers.RepositoryHandler in project openolat by klemens.
the class AuthorListController method initTools.
protected void initTools() {
if (!withSearch && hasAuthorRight) {
importLink = LinkFactory.createLink("cmd.import.ressource", getTranslator(), this);
importLink.setDomReplacementWrapperRequired(false);
importLink.setIconLeftCSS("o_icon o_icon_import");
importLink.setElementCssClass("o_sel_author_import");
stackPanel.addTool(importLink, Align.left);
List<OrderedRepositoryHandler> handlers = repositoryHandlerFactory.getOrderRepositoryHandlers();
createDropdown = new Dropdown("cmd.create.ressource", "cmd.create.ressource", false, getTranslator());
createDropdown.setElementCssClass("o_sel_author_create");
createDropdown.setIconCSS("o_icon o_icon_add");
int lastGroup = 0;
for (OrderedRepositoryHandler orderedHandler : handlers) {
RepositoryHandler handler = orderedHandler.getHandler();
if (handler != null && handler.isCreate()) {
// for each 10-group, create a separator
int group = orderedHandler.getOrder() / 10;
if (group > lastGroup) {
createDropdown.addComponent(new Spacer("spacer" + orderedHandler.getOrder()));
lastGroup = group;
}
addCreateLink(handler, createDropdown);
}
}
stackPanel.addTool(createDropdown, Align.left);
}
}
Aggregations