use of org.olat.modules.portfolio.PortfolioService in project openolat by klemens.
the class CmdAddToEPortfolioImpl method execute.
/**
* might return NULL!, if item clicked was removed meanwhile or if portfolio is disabled or if only the folder-artefact-handler is disabled.
*
* @see org.olat.core.commons.modules.bc.commands.FolderCommand#execute(org.olat.core.commons.modules.bc.components.FolderComponent,
* org.olat.core.gui.UserRequest,
* org.olat.core.gui.control.WindowControl,
* org.olat.core.gui.translator.Translator)
*/
@Override
public Controller execute(FolderComponent folderComponent, UserRequest ureq, WindowControl wControl, Translator translator) {
String pos = ureq.getParameter(ListRenderer.PARAM_EPORT);
if (!StringHelper.containsNonWhitespace(pos)) {
// somehow parameter did not make it to us
status = FolderCommandStatus.STATUS_FAILED;
getWindowControl().setError(translator.translate("failed"));
return null;
}
status = FolderCommandHelper.sanityCheck(wControl, folderComponent);
if (status == FolderCommandStatus.STATUS_SUCCESS) {
currentItem = folderComponent.getCurrentContainerChildren().get(Integer.parseInt(pos));
status = FolderCommandHelper.sanityCheck2(wControl, folderComponent, currentItem);
}
if (status == FolderCommandStatus.STATUS_FAILED) {
return null;
}
if (portfolioV2Module.isEnabled()) {
PortfolioService portfolioService = CoreSpringFactory.getImpl(PortfolioService.class);
MediaHandler handler = null;
String extension = FileUtils.getFileSuffix(currentItem.getName());
if (StringHelper.containsNonWhitespace(extension)) {
if ("jpg".equalsIgnoreCase(extension) || "jpeg".equalsIgnoreCase(extension) || "png".equalsIgnoreCase(extension) || "gif".equalsIgnoreCase(extension)) {
handler = portfolioService.getMediaHandler(ImageHandler.IMAGE_TYPE);
}
// TODO video
}
if (handler == null) {
handler = portfolioService.getMediaHandler(FileHandler.FILE_TYPE);
}
collectStepsCtrl = new CollectArtefactController(ureq, wControl, currentItem, handler, "");
} else {
EPArtefactHandler<?> artHandler = portfolioModule.getArtefactHandler(FileArtefact.FILE_ARTEFACT_TYPE);
AbstractArtefact artefact = artHandler.createArtefact();
artHandler.prefillArtefactAccordingToSource(artefact, currentItem);
artefact.setAuthor(getIdentity());
collectStepsCtrl = new ArtefactWizzardStepsController(ureq, wControl, artefact, currentItem.getParentContainer());
}
return collectStepsCtrl;
}
use of org.olat.modules.portfolio.PortfolioService in project openolat by klemens.
the class BinderTemplateHandler method copy.
@Override
public RepositoryEntry copy(Identity author, RepositoryEntry source, RepositoryEntry target) {
PortfolioService portfolioService = CoreSpringFactory.getImpl(PortfolioService.class);
Binder templateSource = portfolioService.getBinderByResource(source.getOlatResource());
portfolioService.copyBinder(templateSource, target);
return target;
}
use of org.olat.modules.portfolio.PortfolioService in project openolat by klemens.
the class BinderTemplateHandler method importResource.
@Override
public RepositoryEntry importResource(Identity initialAuthor, String initialAuthorAlt, String displayname, String description, boolean withReferences, Locale locale, File file, String filename) {
RepositoryService repositoryService = CoreSpringFactory.getImpl(RepositoryService.class);
PortfolioService portfolioService = CoreSpringFactory.getImpl(PortfolioService.class);
try {
// create resource
OLATResource resource = portfolioService.createBinderTemplateResource();
OlatRootFolderImpl fResourceRootContainer = FileResourceManager.getInstance().getFileResourceRootImpl(resource);
File fResourceFileroot = fResourceRootContainer.getBasefile();
File zipRoot = new File(fResourceFileroot, FileResourceManager.ZIPDIR);
FileResource.copyResource(file, filename, zipRoot);
// create repository entry
RepositoryEntry re = repositoryService.create(initialAuthor, initialAuthorAlt, "", displayname, description, resource, RepositoryEntry.ACC_OWNERS);
// import binder
File binderFile = new File(zipRoot, BinderTemplateResource.BINDER_XML);
Binder transientBinder = BinderXStream.fromPath(binderFile.toPath());
File posterImage = null;
if (StringHelper.containsNonWhitespace(transientBinder.getImagePath())) {
posterImage = new File(zipRoot, transientBinder.getImagePath());
}
portfolioService.importBinder(transientBinder, re, posterImage);
RepositoryEntryImportExport rei = new RepositoryEntryImportExport(re, zipRoot);
if (rei.anyExportedPropertiesAvailable()) {
re = rei.importContent(re, fResourceRootContainer.createChildContainer("media"));
}
// delete the imported files
FileUtils.deleteDirsAndFiles(zipRoot, true, true);
return re;
} catch (IOException e) {
log.error("", e);
return null;
}
}
use of org.olat.modules.portfolio.PortfolioService in project openolat by klemens.
the class BinderTemplateHandler method createResource.
@Override
public RepositoryEntry createResource(Identity initialAuthor, String displayname, String description, Object createObject, Locale locale) {
RepositoryService repositoryService = CoreSpringFactory.getImpl(RepositoryService.class);
PortfolioService portfolioService = CoreSpringFactory.getImpl(PortfolioService.class);
OLATResource resource = portfolioService.createBinderTemplateResource();
RepositoryEntry re = repositoryService.create(initialAuthor, null, "", displayname, description, resource, RepositoryEntry.ACC_OWNERS);
portfolioService.createAndPersistBinderTemplate(initialAuthor, re, locale);
DBFactory.getInstance().commit();
return re;
}
use of org.olat.modules.portfolio.PortfolioService in project openolat by klemens.
the class BinderTemplateMediaResource method prepare.
@Override
public void prepare(HttpServletResponse hres) {
try {
hres.setCharacterEncoding("UTF-8");
} catch (Exception e) {
log.error("", e);
}
try (ZipOutputStream zout = new ZipOutputStream(hres.getOutputStream())) {
PortfolioService portfolioService = CoreSpringFactory.getImpl(PortfolioService.class);
Binder loadedTemplate = portfolioService.getBinderByKey(template.getKey());
String label = loadedTemplate.getTitle();
String secureLabel = StringHelper.transformDisplayNameToFileSystemName(label);
String file = secureLabel + ".zip";
hres.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + StringHelper.urlEncodeUTF8(file));
hres.setHeader("Content-Description", StringHelper.urlEncodeUTF8(label));
zout.setLevel(9);
zout.putNextEntry(new ZipEntry("binder.xml"));
BinderXStream.toStream(loadedTemplate, zout);
zout.closeEntry();
if (StringHelper.containsNonWhitespace(loadedTemplate.getImagePath())) {
File posterImage = portfolioService.getPosterImageFile(loadedTemplate);
if (posterImage.exists()) {
zout.putNextEntry(new ZipEntry(loadedTemplate.getImagePath()));
FileUtils.copyFile(posterImage, new ShieldOutputStream(zout));
zout.closeEntry();
}
}
OLATResource resource = templateEntry.getOlatResource();
File baseContainer = FileResourceManager.getInstance().getFileResource(resource);
RepositoryEntryImportExport importExport = new RepositoryEntryImportExport(templateEntry, baseContainer);
importExport.exportDoExportProperties(zout);
} catch (Exception e) {
log.error("", e);
}
}
Aggregations