use of org.olat.core.util.vfs.LocalFileImpl 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);
}
}
use of org.olat.core.util.vfs.LocalFileImpl 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());
}
use of org.olat.core.util.vfs.LocalFileImpl in project OpenOLAT by OpenOLAT.
the class PdfExternalExtractor method extract.
@Override
public void extract(VFSLeaf document, File bufferFile) throws IOException, DocumentAccessException {
if (!(document instanceof LocalFileImpl)) {
log.warn("Can only index local file");
return;
}
List<String> cmds = new ArrayList<String>();
cmds.add(searchModule.getPdfExternalIndexerCmd());
cmds.add(((LocalFileImpl) document).getBasefile().getAbsolutePath());
cmds.add(bufferFile.getAbsolutePath());
CountDownLatch doneSignal = new CountDownLatch(1);
ProcessWorker worker = new ProcessWorker(cmds, doneSignal);
worker.start();
try {
doneSignal.await(3000, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
log.error("", e);
}
worker.destroyProcess();
}
use of org.olat.core.util.vfs.LocalFileImpl in project OpenOLAT by OpenOLAT.
the class ZipUtil method zip.
/**
* Add the set of files residing in root to the ZIP file named target.
* Files in subfolders will be compressed too.
* if target already exists, this will abort and return false.
*
* @param files Filenames to add to ZIP, relative to root
* @param root Base path.
* @param target Target ZIP file.
* @param compress to compress ot just store
* @return true if successfull, false otherwise.
*/
public static boolean zip(Set<String> files, File root, File target, boolean compress) {
// Create a buffer for reading the files
if (target.exists())
return false;
List<VFSItem> vfsFiles = new ArrayList<VFSItem>();
LocalFolderImpl vfsRoot = new LocalFolderImpl(root);
for (Iterator<String> iter = files.iterator(); iter.hasNext(); ) {
String fileName = iter.next();
VFSItem item = vfsRoot.resolve(fileName);
if (item == null)
return false;
vfsFiles.add(item);
}
return zip(vfsFiles, new LocalFileImpl(target), compress);
}
use of org.olat.core.util.vfs.LocalFileImpl in project OpenOLAT by OpenOLAT.
the class ProjectEditDetailsFormController method uploadFiles.
private void uploadFiles(FileElement attachmentFileElement) {
VFSLeaf uploadedItem = new LocalFileImpl(attachmentFileElement.getUploadFile());
projectBrokerManager.saveAttachedFile(project, attachmentFileElement.getUploadFileName(), uploadedItem, courseEnv, courseNode);
}
Aggregations