use of org.olat.core.commons.modules.bc.meta.tagged.MetaTagged in project openolat by klemens.
the class FeedManagerImpl method createFeedMediaFile.
@Override
public VFSLeaf createFeedMediaFile(OLATResourceable feed, String fileName, Size thumbnailSize) {
VFSLeaf mediaResource = null;
// Brute force method for fast delivery
try {
VFSItem item = feedFileStorage.getOrCreateFeedMediaContainer(feed);
item = item.resolve(fileName);
if (thumbnailSize != null && thumbnailSize.getHeight() > 0 && thumbnailSize.getWidth() > 0 && item instanceof MetaTagged) {
item = ((MetaTagged) item).getMetaInfo().getThumbnail(thumbnailSize.getWidth(), thumbnailSize.getHeight(), false);
}
if (item instanceof VFSLeaf) {
mediaResource = (VFSLeaf) item;
}
} catch (NullPointerException e) {
log.debug("Media resource could not be created from file: ", fileName);
}
return mediaResource;
}
use of org.olat.core.commons.modules.bc.meta.tagged.MetaTagged 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.tagged.MetaTagged 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);
}
use of org.olat.core.commons.modules.bc.meta.tagged.MetaTagged in project openolat by klemens.
the class VersionManagerTest method testAuthorsAndCreators.
@Test
public void testAuthorsAndCreators() throws IOException {
// create a file
OlatRootFolderImpl rootTest = new OlatRootFolderImpl("/test2", null);
String filename = getRandomName();
VFSLeaf file = rootTest.createChildLeaf(filename);
OutputStream out = file.getOutputStream(false);
InputStream in = VersionManagerTest.class.getResourceAsStream("test.txt");
int byteCopied = IOUtils.copy(in, out);
IOUtils.closeQuietly(in);
assertFalse(byteCopied == 0);
assertTrue(file instanceof Versionable);
assertTrue(file instanceof MetaTagged);
// set the author
MetaTagged metaTagged = (MetaTagged) file;
MetaInfo metaInfo = metaTagged.getMetaInfo();
metaInfo.setAuthor(id1);
metaInfo.setCreator(id1.getName());
metaInfo.write();
// save a first version -> id2
Versionable versionedFile1 = (Versionable) file;
InputStream in1 = new ByteArrayInputStream("Hello version 1".getBytes());
versionedFile1.getVersions().addVersion(id2, "Version 1", in1);
IOUtils.closeQuietly(in1);
// save a second version -> id1
Versionable versionedFile2 = (Versionable) file;
InputStream in2 = new ByteArrayInputStream("Hello version 2".getBytes());
versionedFile2.getVersions().addVersion(id1, "Version 2", in2);
IOUtils.closeQuietly(in2);
// save a third version -> id2
Versionable versionedFile3 = (Versionable) file;
InputStream in3 = new ByteArrayInputStream("Hello version 3".getBytes());
versionedFile3.getVersions().addVersion(id2, "Version 3", in3);
IOUtils.closeQuietly(in3);
// make the checks
VFSItem retrievedFile = rootTest.resolve(filename);
assertTrue(retrievedFile instanceof Versionable);
Versions versions = versionManager.createVersionsFor((VFSLeaf) retrievedFile);
List<VFSRevision> revisions = versions.getRevisions();
assertNotNull(revisions);
assertEquals(3, revisions.size());
assertTrue(retrievedFile instanceof MetaTagged);
VFSRevision revision0 = revisions.get(0);
// we don't set an author for the original file
assertEquals(id1.getName(), revision0.getAuthor());
VFSRevision revision1 = revisions.get(1);
assertEquals(id2.getName(), revision1.getAuthor());
VFSRevision revision2 = revisions.get(2);
assertEquals(id1.getName(), revision2.getAuthor());
// current
assertEquals(id2.getName(), versions.getAuthor());
}
use of org.olat.core.commons.modules.bc.meta.tagged.MetaTagged in project openolat by klemens.
the class EditSolutionController method formOK.
@Override
protected void formOK(UserRequest ureq) {
solution.setTitle(titleEl.getValue());
if (fileEl.getUploadFile() != null) {
if (replaceFile && StringHelper.containsNonWhitespace(solution.getFilename())) {
File currentFile = new File(solutionDir, solution.getFilename());
if (currentFile.exists()) {
currentFile.delete();
}
}
String filename = fileEl.getUploadFileName();
if (!replaceFile) {
File currentFile = new File(solutionDir, filename);
if (currentFile.exists()) {
filename = VFSManager.rename(solutionContainer, filename);
}
}
solution.setFilename(filename);
try {
Path upload = fileEl.getUploadFile().toPath();
File newFile = new File(solutionDir, filename);
Files.move(upload, newFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
VFSItem uploadedItem = solutionContainer.resolve(filename);
if (uploadedItem instanceof MetaTagged) {
MetaInfo metaInfo = ((MetaTagged) uploadedItem).getMetaInfo();
metaInfo.setAuthor(ureq.getIdentity());
metaInfo.write();
}
} catch (Exception ex) {
logError("", ex);
}
}
fireEvent(ureq, Event.DONE_EVENT);
}
Aggregations