use of org.olat.core.commons.modules.bc.meta.MetaInfo 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.MetaInfo 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);
}
use of org.olat.core.commons.modules.bc.meta.MetaInfo in project openolat by klemens.
the class DocumentPoolNotificationsHandler method createSubscriptionInfo.
private void createSubscriptionInfo(VFSContainer container, String prefixBusinessPath, Date compareDate, SubscriptionInfo si, Publisher p, Translator translator) {
List<FileInfo> fInfos = FolderManager.getFileInfos(((OlatRelPathImpl) container).getRelPath(), compareDate);
for (FileInfo infos : fInfos) {
String title = infos.getRelPath();
// known exclude prefixes
if (title != null && title.indexOf("/.") != -1 && FileUtils.isMetaFilename(title)) {
// skip this file, continue with next item in folder
continue;
}
MetaInfo metaInfo = infos.getMetaInfo();
String iconCssClass = null;
if (metaInfo != null) {
if (metaInfo.getTitle() != null) {
title += " (" + metaInfo.getTitle() + ")";
}
iconCssClass = metaInfo.getIconCssClass();
}
Identity ident = infos.getAuthor();
Date modDate = infos.getLastModified();
String desc = translator.translate("notifications.document.entry", new String[] { title, NotificationHelper.getFormatedName(ident) });
String urlToSend = null;
String businessPath = null;
if (p.getBusinessPath() != null) {
businessPath = prefixBusinessPath + infos.getRelPath() + "]";
urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
}
si.addSubscriptionListItem(new SubscriptionListItem(desc, urlToSend, businessPath, modDate, iconCssClass));
}
}
use of org.olat.core.commons.modules.bc.meta.MetaInfo in project openolat by klemens.
the class FolderManager method getFileInfosRecursively.
private static void getFileInfosRecursively(OlatRelPathImpl relPath, List<FileInfo> fileInfos, long newerThan, int basePathlen) {
if (relPath instanceof VFSLeaf) {
// is a file
long lastModified = ((VFSLeaf) relPath).getLastModified();
if (lastModified > newerThan) {
MetaInfo meta = CoreSpringFactory.getImpl(MetaInfoFactory.class).createMetaInfoFor(relPath);
String bcrootPath = relPath.getRelPath();
String bcRelPath = bcrootPath.substring(basePathlen);
fileInfos.add(new FileInfo(bcRelPath, meta, new Date(lastModified)));
}
} else {
// is a folder
OlatRootFolderImpl container = (OlatRootFolderImpl) relPath;
for (VFSItem item : container.getItems(new SystemItemFilter())) {
getFileInfosRecursively((OlatRelPathImpl) item, fileInfos, newerThan, basePathlen);
}
}
}
use of org.olat.core.commons.modules.bc.meta.MetaInfo in project openolat by klemens.
the class CmdCreateFolder method formOK.
@Override
protected void formOK(UserRequest ureq) {
// create the folder
String name = textElement.getValue();
VFSContainer currentContainer = folderComponent.getCurrentContainer();
VFSItem item = currentContainer.createChildContainer(name);
if (item instanceof OlatRelPathImpl) {
// update meta data
MetaInfo meta = metaInfoFactory.createMetaInfoFor((OlatRelPathImpl) item);
meta.setAuthor(ureq.getIdentity());
meta.write();
status = FolderCommandStatus.STATUS_FAILED;
fireEvent(ureq, new FolderEvent(FolderEvent.NEW_FOLDER_EVENT, folderName));
fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
} else {
status = FolderCommandStatus.STATUS_FAILED;
fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
}
}
Aggregations