use of org.olat.core.commons.modules.bc.meta.tagged.MetaTagged in project OpenOLAT by OpenOLAT.
the class RepositoryManager method setImage.
public boolean setImage(VFSLeaf newImageFile, RepositoryEntry re) {
VFSLeaf currentImage = getImage(re);
if (currentImage != null) {
if (currentImage instanceof MetaTagged) {
MetaInfo info = ((MetaTagged) currentImage).getMetaInfo();
if (info != null) {
info.clearThumbnails();
}
}
currentImage.delete();
}
if (newImageFile == null || !newImageFile.exists() || newImageFile.getSize() <= 0) {
return false;
}
String targetExtension = ".png";
String extension = FileUtils.getFileSuffix(newImageFile.getName());
if ("jpg".equalsIgnoreCase(extension) || "jpeg".equalsIgnoreCase(extension)) {
targetExtension = ".jpg";
}
VFSContainer repositoryHome = new LocalFolderImpl(new File(FolderConfig.getCanonicalRepositoryHome()));
VFSLeaf repoImage = repositoryHome.createChildLeaf(re.getResourceableId() + targetExtension);
if (targetExtension.equals(".png") || targetExtension.equals(".jpg")) {
Size newImageSize = imageHelper.getSize(newImageFile, extension);
if (newImageSize != null && newImageSize.getWidth() <= PICTURE_WIDTH && newImageSize.getHeight() <= PICTURE_HEIGHT) {
boolean success = VFSManager.copyContent(newImageFile, repoImage);
return success;
}
}
Size size = imageHelper.scaleImage(newImageFile, repoImage, PICTURE_WIDTH, PICTURE_WIDTH, false);
return size != null;
}
use of org.olat.core.commons.modules.bc.meta.tagged.MetaTagged in project OpenOLAT by OpenOLAT.
the class CatalogEntryImageMapper method handle.
@Override
public MediaResource handle(String relPath, HttpServletRequest request) {
if (relPath.startsWith("/")) {
relPath = relPath.substring(1, relPath.length());
}
VFSContainer categoryResources = catalogManager.getCatalogResourcesHome();
VFSItem image = categoryResources.resolve(relPath);
MediaResource resource = null;
if (image instanceof VFSLeaf) {
if (image instanceof MetaTagged) {
MetaInfo info = ((MetaTagged) image).getMetaInfo();
if (info != null) {
VFSLeaf thumbnail = info.getThumbnail(180, 180, true);
if (thumbnail != null) {
resource = new VFSMediaResource(thumbnail);
}
}
}
if (resource == null) {
resource = new VFSMediaResource((VFSLeaf) image);
}
} else {
resource = new NotFoundMediaResource();
}
return resource;
}
use of org.olat.core.commons.modules.bc.meta.tagged.MetaTagged in project OpenOLAT by OpenOLAT.
the class SubmitDocumentsController method doUpload.
private void doUpload(UserRequest ureq, File file, String filename) {
try {
Path documentPath = documentsDir.toPath().resolve(filename);
Files.move(file.toPath(), documentPath, StandardCopyOption.REPLACE_EXISTING);
VFSItem downloadedFile = documentsContainer.resolve(filename);
if (downloadedFile instanceof MetaTagged) {
MetaInfo metadata = ((MetaTagged) downloadedFile).getMetaInfo();
metadata.setAuthor(ureq.getIdentity());
metadata.write();
}
} catch (IOException e) {
logError("", e);
showError("");
}
updateModel();
}
use of org.olat.core.commons.modules.bc.meta.tagged.MetaTagged in project OpenOLAT by OpenOLAT.
the class FileArtefactDetailsController method initFileView.
private void initFileView(VFSItem file, UserRequest ureq) {
vC = createVelocityContainer("fileDetails");
DownloadComponent downlC = new DownloadComponent("download", (VFSLeaf) file);
vC.put("download", downlC);
vC.contextPut("filename", fArtefact.getFilename());
if (file instanceof MetaTagged) {
MetaInfo meta = ((MetaTagged) file).getMetaInfo();
vC.contextPut("meta", meta);
// show a preview thumbnail if possible
if (meta.isThumbnailAvailable()) {
VFSLeaf thumb = meta.getThumbnail(200, 200, false);
if (thumb != null) {
mr = new VFSMediaResource(thumb);
}
if (mr != null) {
String thumbMapper = registerMapper(ureq, new Mapper() {
@Override
public MediaResource handle(String relPath, HttpServletRequest request) {
return mr;
}
});
vC.contextPut("thumbMapper", thumbMapper);
}
}
}
if (!readOnlyMode) {
// allow to delete
delLink = LinkFactory.createLink("delete.file", vC, this);
delLink.setUserObject(file);
}
viewPanel.setContent(vC);
}
use of org.olat.core.commons.modules.bc.meta.tagged.MetaTagged in project openolat by klemens.
the class CmdMoveCopy method doMove.
private void doMove(UserRequest ureq) {
FolderTreeModel ftm = (FolderTreeModel) selTree.getTreeModel();
String selectedPath = ftm.getSelectedPath(selTree.getSelectedNode());
if (selectedPath == null) {
abortFailed(ureq, "failed");
return;
}
VFSStatus vfsStatus = VFSConstants.SUCCESS;
VFSContainer rootContainer = folderComponent.getRootContainer();
VFSItem vfsItem = rootContainer.resolve(selectedPath);
if (vfsItem == null || (vfsItem.canWrite() != VFSConstants.YES)) {
abortFailed(ureq, "failed");
return;
}
// copy the files
VFSContainer target = (VFSContainer) vfsItem;
List<VFSItem> sources = getSanityCheckedSourceItems(target, ureq);
if (sources == null)
return;
boolean targetIsRelPath = (target instanceof OlatRelPathImpl);
for (VFSItem vfsSource : sources) {
if (targetIsRelPath && (target instanceof OlatRelPathImpl) && (vfsSource instanceof MetaTagged)) {
// copy the metainfo first
MetaInfo meta = ((MetaTagged) vfsSource).getMetaInfo();
if (meta != null) {
meta.moveCopyToDir((OlatRelPathImpl) target, move);
}
}
VFSItem targetFile = target.resolve(vfsSource.getName());
if (vfsSource instanceof VFSLeaf && targetFile != null && targetFile instanceof Versionable && ((Versionable) targetFile).getVersions().isVersioned()) {
// add a new version to the file
((Versionable) targetFile).getVersions().addVersion(null, "", ((VFSLeaf) vfsSource).getInputStream());
} else {
vfsStatus = target.copyFrom(vfsSource);
}
if (vfsStatus != VFSConstants.SUCCESS) {
String errorKey = "failed";
if (vfsStatus == VFSConstants.ERROR_QUOTA_EXCEEDED)
errorKey = "QuotaExceeded";
abortFailed(ureq, errorKey);
return;
}
if (move) {
// if move, delete the source. Note that meta source
// has already been delete (i.e. moved)
vfsSource.delete();
}
}
// after a copy or a move, notify the subscribers
VFSSecurityCallback secCallback = VFSManager.findInheritedSecurityCallback(folderComponent.getCurrentContainer());
if (secCallback != null) {
SubscriptionContext subsContext = secCallback.getSubscriptionContext();
if (subsContext != null) {
NotificationsManager.getInstance().markPublisherNews(subsContext, ureq.getIdentity(), true);
}
}
fireEvent(ureq, new FolderEvent(move ? FolderEvent.MOVE_EVENT : FolderEvent.COPY_EVENT, fileSelection.renderAsHtml()));
notifyFinished(ureq);
}
Aggregations