use of org.olat.core.commons.modules.bc.meta.MetaInfo 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);
}
use of org.olat.core.commons.modules.bc.meta.MetaInfo in project openolat by klemens.
the class OlatRootFolderTreeModel method createNode.
/**
* Create a node out of a relative path vfs item. The user object is set to
* the relative path.
*
* @param item
*/
private OlatRootFolderTreeNode createNode(OlatRelPathImpl item) {
OlatRootFolderTreeNode node = new OlatRootFolderTreeNode(item, this);
MetaInfo meta = metaInfoFactory.createMetaInfoFor(item);
if (meta != null) {
String title = meta.getTitle();
if (StringHelper.containsNonWhitespace(title)) {
node.setTitle(title);
} else {
node.setTitle(meta.getName());
}
} else {
// TODO:GW log warning that
// "metadate couldn't be loaded for folder relpath: " +
// folder.getRelPath();
}
node.setUserObject(item.getRelPath());
return node;
}
use of org.olat.core.commons.modules.bc.meta.MetaInfo in project openolat by klemens.
the class PFNotifications method gatherItems.
private void gatherItems(Identity participant, Publisher p, CourseEnvironment courseEnv, CourseNode node) {
Path folderRoot = Paths.get(courseEnv.getCourseBaseContainer().getRelPath(), PFManager.FILENAME_PARTICIPANTFOLDER, node.getIdent(), pfManager.getIdFolderName(participant));
final List<FileInfo> fInfos = FolderManager.getFileInfos(folderRoot.toString(), compareDate);
SubscriptionListItem subListItem;
for (Iterator<FileInfo> it_infos = fInfos.iterator(); it_infos.hasNext(); ) {
FileInfo fi = it_infos.next();
MetaInfo metaInfo = fi.getMetaInfo();
String filePath = fi.getRelPath();
Date modDate = fi.getLastModified();
String action = "upload";
try {
Path basepath = courseEnv.getCourseBaseContainer().getBasefile().toPath();
Path completepath = Paths.get(basepath.toString(), PFManager.FILENAME_PARTICIPANTFOLDER, node.getIdent(), pfManager.getIdFolderName(participant), filePath);
BasicFileAttributes attrs = Files.readAttributes(completepath, BasicFileAttributes.class);
if (attrs.creationTime().toMillis() < attrs.lastModifiedTime().toMillis()) {
action = "modify";
}
} catch (IOException ioe) {
log.error("IOException", ioe);
}
String forby = translator.translate("notifications.entry." + (filePath.contains(PFManager.FILENAME_DROPBOX) ? "by" : "for"));
String userDisplayName = userManager.getUserDisplayName(participant);
String desc = translator.translate("notifications.entry." + action, new String[] { filePath, forby, userDisplayName });
String businessPath = p.getBusinessPath();
String urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
String iconCssClass = null;
if (metaInfo != null) {
iconCssClass = metaInfo.getIconCssClass();
}
if (metaInfo != null && !metaInfo.getName().startsWith(".")) {
subListItem = new SubscriptionListItem(desc, urlToSend, businessPath, modDate, iconCssClass);
items.add(subListItem);
}
}
}
use of org.olat.core.commons.modules.bc.meta.MetaInfo in project openolat by klemens.
the class FileDocument method init.
protected void init(SearchResourceContext leafResourceContext, VFSLeaf leaf) throws IOException, DocumentException, DocumentAccessException {
// Load metadata for this file
MetaInfo meta = null;
if (leaf instanceof MetaTagged) {
meta = ((MetaTagged) leaf).getMetaInfo();
}
// Set all know attributes
setResourceUrl(leafResourceContext.getResourceUrl());
setLastChange(new Date(leaf.getLastModified()));
// Check if there are documents attributes set in resource context
if (StringHelper.containsNonWhitespace(leafResourceContext.getDocumentType())) {
// document-type in context is set => get from there
setDocumentType(leafResourceContext.getDocumentType());
} else {
setDocumentType(TYPE);
}
FileContent content = readContent(leaf);
String metaTitle;
if (meta != null && StringHelper.containsNonWhitespace(meta.getTitle())) {
metaTitle = meta.getTitle();
} else if (content != null && StringHelper.containsNonWhitespace(content.getTitle())) {
metaTitle = content.getTitle();
} else {
String beautfiedName = leaf.getName();
int dotpos = beautfiedName.lastIndexOf('.');
if (dotpos > 0) {
beautfiedName = beautfiedName.substring(0, dotpos);
}
metaTitle = beautfiedName.replace('_', ' ');
}
StringBuilder title = new StringBuilder();
if (StringHelper.containsNonWhitespace(leafResourceContext.getTitle())) {
// Title in context is set => get from there and add filename
title.append(leafResourceContext.getTitle()).append(", ");
}
if (metaTitle != null) {
title.append(metaTitle).append(" ( ");
}
title.append(leaf.getName());
if (metaTitle != null) {
title.append(" )");
}
setTitle(title.toString());
String metaDesc = (meta == null ? null : meta.getComment());
if (StringHelper.containsNonWhitespace(leafResourceContext.getDescription())) {
// Title in context is set => get from there
setDescription(leafResourceContext.getDescription() + (metaDesc == null ? "" : " " + metaDesc));
} else if (metaDesc != null) {
setDescription(metaDesc);
}
setParentContextType(leafResourceContext.getParentContextType());
setParentContextName(leafResourceContext.getParentContextName());
setContent(content.getContent());
// Add other metadata from meta info
if (meta != null) {
addMetadata(SimpleDublinCoreMetadataFieldsProvider.DC_DESCRIPTION, meta.getComment());
addMetadata(SimpleDublinCoreMetadataFieldsProvider.DC_LANGUAGE, meta.getLanguage());
// Date is 2009 200902 or 20090228
String[] pubDateArray = meta.getPublicationDate();
if (pubDateArray != null) {
StringBuilder pubDate = new StringBuilder();
for (String d : pubDateArray) {
if (d != null) {
pubDate.append(d);
}
}
addMetadata(SimpleDublinCoreMetadataFieldsProvider.DC_DATE, pubDate.toString());
Date publicationDate = getDateFromPublicationDateArray(pubDateArray);
if (publicationDate != null) {
setPublicationDate(publicationDate);
}
}
addMetadata(SimpleDublinCoreMetadataFieldsProvider.DC_PUBLISHER, meta.getPublisher());
addMetadata(SimpleDublinCoreMetadataFieldsProvider.DC_SOURCE, meta.getSource());
addMetadata(SimpleDublinCoreMetadataFieldsProvider.DC_SOURCE, meta.getUrl());
// use creator and author as olat author
setAuthor((meta.getCreator() == null ? meta.getAuthor() : meta.getAuthor() + " " + meta.getCreator()));
addMetadata(SimpleDublinCoreMetadataFieldsProvider.DC_CREATOR, meta.getCreator());
}
// Add file type
String mimeType = WebappHelper.getMimeType(leaf.getName());
addMetadata(SimpleDublinCoreMetadataFieldsProvider.DC_FORMAT, mimeType);
// License
String licenseTypeKey = "";
if (meta != null && StringHelper.containsNonWhitespace(meta.getLicenseTypeKey())) {
licenseTypeKey = meta.getLicenseTypeKey();
}
setLicenseTypeKey(licenseTypeKey);
}
use of org.olat.core.commons.modules.bc.meta.MetaInfo in project openolat by klemens.
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);
}
Aggregations