use of org.olat.core.util.vfs.VFSLeaf in project OpenOLAT by OpenOLAT.
the class VFSWebservice method resolveContainer.
protected VFSContainer resolveContainer(List<PathSegment> path, boolean create) {
VFSContainer directory = container;
boolean notFound = false;
// remove trailing segment if a trailing / is used
if (path.size() > 0 && !StringHelper.containsNonWhitespace(path.get(path.size() - 1).getPath())) {
path = path.subList(0, path.size() - 1);
}
a_a: for (PathSegment seg : path) {
String segPath = seg.getPath();
for (VFSItem item : directory.getItems(new SystemItemFilter())) {
if (item instanceof VFSLeaf) {
//
} else if (item instanceof VFSContainer && normalize(item.getName()).equals(segPath)) {
directory = (VFSContainer) item;
continue a_a;
}
}
if (create) {
directory = directory.createChildContainer(segPath);
} else if (path.get(path.size() - 1) == seg) {
break a_a;
} else {
notFound = true;
}
}
if (notFound) {
return null;
}
return directory;
}
use of org.olat.core.util.vfs.VFSLeaf in project OpenOLAT by OpenOLAT.
the class BulkAssessmentTask method processReturnFile.
private void processReturnFile(AssessableCourseNode courseNode, BulkAssessmentRow row, UserCourseEnvironment uce, File assessedFolder) {
String assessedId = row.getAssessedId();
Identity identity = uce.getIdentityEnvironment().getIdentity();
VFSContainer returnBox = getReturnBox(uce, courseNode, identity);
if (returnBox != null) {
for (String returnFilename : row.getReturnFiles()) {
File returnFile = new File(assessedFolder, returnFilename);
VFSItem currentReturnLeaf = returnBox.resolve(returnFilename);
if (currentReturnLeaf != null) {
// remove the current file (delete make a version if it is enabled)
currentReturnLeaf.delete();
}
VFSLeaf returnLeaf = returnBox.createChildLeaf(returnFilename);
if (returnFile.exists()) {
try {
InputStream inStream = new FileInputStream(returnFile);
VFSManager.copyContent(inStream, returnLeaf);
} catch (FileNotFoundException e) {
log.error("Cannot copy return file " + returnFilename + " from " + assessedId, e);
}
}
}
}
}
use of org.olat.core.util.vfs.VFSLeaf in project OpenOLAT by OpenOLAT.
the class CertificatesManagerImpl method addPdfTemplate.
private boolean addPdfTemplate(String name, File file, CertificateTemplateImpl template) {
String dir = templatesStorage.generateDir();
VFSContainer templateDir = templatesStorage.getContainer(dir);
VFSLeaf templateLeaf;
String renamedName = VFSManager.rename(templateDir, name);
if (renamedName != null) {
templateLeaf = templateDir.createChildLeaf(renamedName);
} else {
templateLeaf = templateDir.createChildLeaf(name);
}
try (InputStream inStream = Files.newInputStream(file.toPath())) {
if (VFSManager.copyContent(inStream, templateLeaf)) {
template.setName(name);
template.setPath(dir + templateLeaf.getName());
return true;
}
} catch (IOException ex) {
log.error("", ex);
}
return false;
}
use of org.olat.core.util.vfs.VFSLeaf in project OpenOLAT by OpenOLAT.
the class CertificationWebService method getCertificateInfo.
@HEAD
@Path("{identityKey}")
@Produces({ "application/pdf" })
public Response getCertificateInfo(@PathParam("identityKey") Long identityKey, @PathParam("resourceKey") Long resourceKey, @Context HttpServletRequest request) {
if (!isAdmin(request)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
CertificatesManager certificatesManager = CoreSpringFactory.getImpl(CertificatesManager.class);
BaseSecurity baseSecurity = CoreSpringFactory.getImpl(BaseSecurity.class);
Identity identity = baseSecurity.loadIdentityByKey(identityKey);
if (identity == null) {
return Response.serverError().status(Response.Status.NOT_FOUND).build();
}
OLATResourceable courseOres = OresHelper.createOLATResourceableInstance("CourseModule", resourceKey);
OLATResourceManager resourceManager = CoreSpringFactory.getImpl(OLATResourceManager.class);
OLATResource resource = resourceManager.findResourceable(courseOres);
if (resource == null) {
resource = resourceManager.findResourceById(resourceKey);
}
if (resource == null) {
return Response.serverError().status(Response.Status.NOT_FOUND).build();
}
Certificate certificate = certificatesManager.getLastCertificate(identity, resource.getKey());
if (certificate == null) {
return Response.serverError().status(Response.Status.NOT_FOUND).build();
}
VFSLeaf certificateFile = certificatesManager.getCertificateLeaf(certificate);
if (certificateFile == null || !certificateFile.exists()) {
return Response.serverError().status(Response.Status.NOT_FOUND).build();
}
return Response.ok().build();
}
use of org.olat.core.util.vfs.VFSLeaf in project OpenOLAT by OpenOLAT.
the class CollaborationTools method archiveWiki.
private void archiveWiki(String archivFilePath) {
VFSContainer wikiContainer = WikiManager.getInstance().getWikiRootContainer(ores);
VFSLeaf wikiZip = WikiToZipUtils.getWikiAsZip(wikiContainer);
String exportFileName = "del_wiki_" + ores.getResourceableId() + ".zip";
File archiveDir = new File(archivFilePath);
if (!archiveDir.exists()) {
archiveDir.mkdir();
}
String fullFilePath = archivFilePath + File.separator + exportFileName;
try {
FileUtils.bcopy(wikiZip.getInputStream(), new File(fullFilePath), "archive wiki");
} catch (FileNotFoundException e) {
log.warn("Can not archive wiki repoEntry=" + ores.getResourceableId());
} catch (IOException ioe) {
log.warn("Can not archive wiki repoEntry=" + ores.getResourceableId());
}
}
Aggregations