use of org.olat.core.util.vfs.VFSItem in project OpenOLAT by OpenOLAT.
the class ConvertToGTACourseNode method convertDropbox.
private void convertDropbox(TaskList taskList, TACourseNode sourceNode, GTACourseNode gtaNode, CourseEnvironment courseEnv) {
String dropbox = DropboxController.getDropboxPathRelToFolderRoot(courseEnv, sourceNode);
OlatRootFolderImpl dropboxContainer = new OlatRootFolderImpl(dropbox, null);
for (VFSItem userDropbox : dropboxContainer.getItems()) {
if (userDropbox instanceof VFSContainer) {
VFSContainer userDropContainer = (VFSContainer) userDropbox;
String username = userDropContainer.getName();
Identity assessedIdentity = securityManager.findIdentityByName(username);
if (assessedIdentity != null) {
VFSContainer sumbitContainer = gtaManager.getSubmitContainer(courseEnv, gtaNode, assessedIdentity);
boolean dropped = false;
for (VFSItem dropppedItem : userDropContainer.getItems()) {
if (dropppedItem instanceof VFSLeaf) {
VFSLeaf submittedDocument = sumbitContainer.createChildLeaf(dropppedItem.getName());
VFSManager.copyContent((VFSLeaf) dropppedItem, submittedDocument);
convertMetada(userDropContainer, sumbitContainer, dropppedItem.getName(), null, null);
dropped = true;
}
}
if (dropped) {
setTaskStatus(taskList, assessedIdentity, TaskProcess.submit, gtaNode);
}
}
}
}
}
use of org.olat.core.util.vfs.VFSItem in project OpenOLAT by OpenOLAT.
the class QTIQPoolServiceProvider method importBeecomItem.
public QuestionItemImpl importBeecomItem(Identity owner, ItemAndMetadata itemAndMetadata, VFSContainer sourceDir, Locale defaultLocale) {
QTIImportProcessor processor = new QTIImportProcessor(owner, defaultLocale);
String editor = null;
String editorVersion = null;
Item item = itemAndMetadata.getItem();
if (!item.isAlient()) {
editor = "OpenOLAT";
editorVersion = Settings.getVersion();
}
Document doc = QTIEditHelper.itemToXml(item);
Element itemEl = (Element) doc.selectSingleNode("questestinterop/item");
QuestionItemImpl qitem = processor.processItem(itemEl, "", null, editor, editorVersion, null, itemAndMetadata);
// save to file System
VFSContainer baseDir = qpoolFileStorage.getContainer(qitem.getDirectory());
VFSLeaf leaf = baseDir.createChildLeaf(qitem.getRootFilename());
QTIEditHelper.serialiazeDoc(doc, leaf);
if (sourceDir != null) {
List<String> materials = processor.getMaterials(itemEl);
// copy materials
for (String material : materials) {
VFSItem sourceItem = sourceDir.resolve(material);
if (sourceItem instanceof VFSLeaf) {
VFSLeaf targetItem = baseDir.createChildLeaf(material);
VFSManager.copyContent((VFSLeaf) sourceItem, targetItem);
}
}
}
return qitem;
}
use of org.olat.core.util.vfs.VFSItem in project OpenOLAT by OpenOLAT.
the class QTIQPoolServiceProvider method extractTextContent.
@Override
public String extractTextContent(QuestionItemFull item) {
String content = null;
if (item.getRootFilename() != null) {
String dir = item.getDirectory();
VFSContainer container = qpoolFileStorage.getContainer(dir);
VFSItem file = container.resolve(item.getRootFilename());
if (file instanceof VFSLeaf) {
VFSLeaf leaf = (VFSLeaf) file;
InputStream is = leaf.getInputStream();
QTI12SAXHandler handler = new QTI12SAXHandler();
try {
XMLReader parser = XMLReaderFactory.createXMLReader();
parser.setContentHandler(handler);
parser.setEntityResolver(new IMSEntityResolver());
parser.setFeature("http://xml.org/sax/features/validation", false);
parser.parse(new InputSource(is));
} catch (Exception e) {
log.error("", e);
} finally {
FileUtils.closeSafely(is);
}
return handler.toString();
}
}
return content;
}
use of org.olat.core.util.vfs.VFSItem in project OpenOLAT by OpenOLAT.
the class AssignmentEditController method updateAssignmentDocumentForm.
protected void updateAssignmentDocumentForm(UserRequest ureq) {
if (mapperUri == null) {
mapperUri = registerCacheableMapper(ureq, "assigment-" + CodeHelper.getRAMUniqueID(), new DocumentMapper());
filesLayout.contextPut("mapperUri", mapperUri);
}
List<VFSItem> files = new ArrayList<>();
if (assignment != null && StringHelper.containsNonWhitespace(assignment.getStorage())) {
documentContainer = fileStorage.getAssignmentContainer(assignment);
files.addAll(documentContainer.getItems(new SystemItemFilter()));
}
// add files from TempFolder
if (tempUploadFolder != null) {
files.addAll(tempUploadFolder.getItems(new SystemItemFilter()));
}
Collections.sort(files, new Comparator<VFSItem>() {
final Collator c = Collator.getInstance(getLocale());
@Override
public int compare(final VFSItem o1, final VFSItem o2) {
return c.compare((o1).getName(), (o2).getName());
}
});
filesLayout.contextPut("files", files);
// add delete links for each attachment if user is allowed to see them
int count = 0;
for (VFSItem file : files) {
FormLink deleteLink = uifactory.addFormLink("delete_" + (++count), filesLayout, Link.BUTTON_XSMALL);
deleteLink.setUserObject(file);
deleteLink.setI18nKey("delete");
}
boolean hasFile = files.size() > 0;
filesLayout.setVisible(files.size() > 0);
filesLayout.showLabel(hasFile);
documentUploadEl.showLabel(!hasFile);
}
use of org.olat.core.util.vfs.VFSItem in project OpenOLAT by OpenOLAT.
the class AssignmentEditController method persistUploadedFiles.
private void persistUploadedFiles() {
if (tempUploadFolder == null)
return;
VFSContainer container = portfolioFileStorage.getAssignmentContainer(assignment);
if (container != null) {
List<VFSItem> tmpFList = tempUploadFolder.getItems(new SystemItemFilter());
for (VFSItem file : tmpFList) {
try {
VFSLeaf leaf = (VFSLeaf) file;
VFSLeaf storedFile = container.createChildLeaf(leaf.getName());
FileUtils.bcopy(leaf.getInputStream(), storedFile.getOutputStream(false), "");
} catch (Exception e) {
logError("", e);
}
}
}
}
Aggregations