use of org.olat.core.util.vfs.VFSItem in project OpenOLAT by OpenOLAT.
the class VersionsFileManager method pruneHistory.
@Override
public void pruneHistory(long maxHistoryLength, ProgressDelegate progress) {
VFSContainer versionsContainer = getRootVersionsContainer();
if (!versionsContainer.exists()) {
return;
}
// delete folder without versioning first
int count = 0;
String[] excludedRootFolders = new String[] { "tmp", "scorm", "forum", "portfolio" };
for (String excludedRootFolder : excludedRootFolders) {
VFSItem excludedContainer = versionsContainer.resolve(excludedRootFolder);
if (excludedContainer instanceof LocalFolderImpl) {
File excludedFile = ((LocalFolderImpl) excludedContainer).getBasefile();
FileUtils.deleteQuietly(excludedFile);
if (progress != null)
progress.setInfo(excludedContainer.getName());
}
if (progress != null)
progress.setActual(++count);
}
if (maxHistoryLength < 0) {
// nothing to do
} else if (maxHistoryLength == 0 && versionsContainer instanceof LocalFolderImpl) {
// delete all the stuff
FileUtils.deleteQuietly(((LocalFolderImpl) versionsContainer).getBasefile());
} else {
pruneVersionHistory(versionsContainer, maxHistoryLength, progress, count);
}
if (progress != null)
progress.finished();
}
use of org.olat.core.util.vfs.VFSItem in project OpenOLAT by OpenOLAT.
the class VFSWebservice method resolveFile.
protected VFSItem resolveFile(List<PathSegment> path) {
VFSContainer directory = container;
VFSItem resolvedItem = directory;
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 (normalize(item.getName()).equals(segPath)) {
if (item instanceof VFSLeaf) {
if (path.get(path.size() - 1) == seg) {
resolvedItem = item;
break a_a;
}
} else if (item instanceof VFSContainer) {
resolvedItem = directory = (VFSContainer) item;
continue a_a;
}
}
}
notFound = true;
}
if (notFound) {
return null;
}
return resolvedItem;
}
use of org.olat.core.util.vfs.VFSItem in project OpenOLAT by OpenOLAT.
the class VFSWebservice method deleteItem.
@DELETE
@Path("{path:.*}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response deleteItem(@PathParam("path") List<PathSegment> path) {
if (container.getLocalSecurityCallback() != null && !container.getLocalSecurityCallback().canDelete()) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
VFSItem item = resolveFile(path);
if (item == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
VFSStatus status = item.delete();
if (status == VFSConstants.YES) {
return Response.ok().build();
}
// need something better
return Response.ok().build();
}
use of org.olat.core.util.vfs.VFSItem in project OpenOLAT by OpenOLAT.
the class VFSWebservice method get.
protected Response get(List<PathSegment> path, UriInfo uriInfo, Request request) {
VFSItem vItem = resolveFile(path);
if (vItem == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
} else if (vItem instanceof VFSContainer) {
VFSContainer directory = (VFSContainer) vItem;
List<VFSItem> items = directory.getItems(new SystemItemFilter());
int count = 0;
FileVO[] links = new FileVO[items.size()];
for (VFSItem item : items) {
UriBuilder builder = uriInfo.getAbsolutePathBuilder();
String uri = builder.path(normalize(item.getName())).build().toString();
if (item instanceof VFSLeaf) {
links[count++] = new FileVO("self", uri, item.getName(), ((VFSLeaf) item).getSize());
} else {
links[count++] = new FileVO("self", uri, item.getName());
}
}
return Response.ok(links).build();
} else if (vItem instanceof VFSLeaf) {
VFSLeaf leaf = (VFSLeaf) vItem;
Date lastModified = new Date(leaf.getLastModified());
Response.ResponseBuilder response = request.evaluatePreconditions(lastModified);
if (response == null) {
String mimeType = WebappHelper.getMimeType(leaf.getName());
if (mimeType == null) {
mimeType = MediaType.APPLICATION_OCTET_STREAM;
}
response = Response.ok(leaf.getInputStream(), mimeType).lastModified(lastModified).cacheControl(cc);
}
return response.build();
}
return Response.serverError().status(Status.BAD_REQUEST).build();
}
use of org.olat.core.util.vfs.VFSItem in project OpenOLAT by OpenOLAT.
the class VFSWebservice method getFMetadata.
protected Response getFMetadata(List<PathSegment> path, UriInfo uriInfo) {
VFSItem vItem = resolveFile(path);
if (vItem == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
} else if (vItem instanceof VFSContainer) {
return Response.serverError().status(Status.NOT_ACCEPTABLE).build();
} else if (vItem instanceof VFSLeaf) {
VFSLeaf leaf = (VFSLeaf) vItem;
UriBuilder builder = uriInfo.getAbsolutePathBuilder();
String uri = builder.build().toString();
String[] uriArray = uri.split("metadata/");
uri = uriArray[0] + uriArray[1];
FileMetadataVO metaVo = new FileMetadataVO(uri, leaf);
return Response.ok(metaVo).build();
}
return Response.serverError().status(Status.BAD_REQUEST).build();
}
Aggregations