use of org.nuxeo.ecm.core.api.DocumentModel in project nuxeo-filesystem-connectors by nuxeo.
the class RootResource method findResource.
@Path("{path:.+}")
public Object findResource(@PathParam("path") String path) {
try {
path = new String(path.getBytes(), "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new NuxeoException(e);
}
Backend backend = BackendHelper.getBackend(path, request);
if (backend == null) {
throw new WebApplicationException(Response.Status.NOT_FOUND);
}
if (backend.isVirtual()) {
return new VirtualFolderResource(path, request, backend.getVirtualFolderNames());
}
DocumentModel doc = null;
try {
doc = backend.getDocument(path);
} catch (DocumentNotFoundException e) {
log.error("Error during resolving path: " + path, e);
throw new WebApplicationException(Response.Status.CONFLICT);
}
if (doc == null) {
return new UnknownResource(path, request, backend);
}
// Send 401 error if not authorised to read.
if (!backend.hasPermission(doc.getRef(), SecurityConstants.READ)) {
throw new WebApplicationException(Response.Status.UNAUTHORIZED);
}
if (doc.isFolder()) {
return new FolderResource(getDocumentPath(doc), doc, request, backend);
} else {
return new FileResource(getDocumentPath(doc), doc, request, backend);
}
}
use of org.nuxeo.ecm.core.api.DocumentModel in project nuxeo-filesystem-connectors by nuxeo.
the class PathCache method get.
public DocumentModel get(String path) {
Value value = pathToUuidCache.get(path);
if (value == null) {
return null;
}
if (value.getExpiredTime() < System.currentTimeMillis()) {
pathToUuidCache.remove(path);
return null;
}
String uuid = value.getValue();
DocumentModel model = null;
try {
model = session.getDocument(new IdRef(uuid));
} catch (DocumentNotFoundException e) {
// do nothing
}
if (model == null) {
pathToUuidCache.remove(path);
}
return model;
}
use of org.nuxeo.ecm.core.api.DocumentModel in project nuxeo-filesystem-connectors by nuxeo.
the class SimpleBackend method getChildren.
@Override
public List<DocumentModel> getChildren(DocumentRef ref) {
List<DocumentModel> result = new ArrayList<DocumentModel>();
List<DocumentModel> children = getSession(true).getChildren(ref);
for (DocumentModel child : children) {
if (child.hasFacet(FacetNames.HIDDEN_IN_NAVIGATION)) {
continue;
}
if (child.isTrashed()) {
continue;
}
if (!child.hasSchema("dublincore")) {
continue;
}
if (child.hasFacet(FacetNames.FOLDERISH) || child.getAdapter(BlobHolder.class) != null) {
result.add(child);
}
}
return result;
}
use of org.nuxeo.ecm.core.api.DocumentModel in project nuxeo-filesystem-connectors by nuxeo.
the class SimpleBackend method createFolder.
@Override
public DocumentModel createFolder(String parentPath, String name) {
DocumentModel parent = resolveLocation(parentPath);
if (!parent.isFolder()) {
throw new NuxeoException("Can not create a child in a non folderish node");
}
String targetType = "Folder";
if ("WorkspaceRoot".equals(parent.getType())) {
targetType = "Workspace";
}
// name = cleanName(name);
cleanTrashPath(parent, name);
DocumentModel folder = getSession().createDocumentModel(parent.getPathAsString(), name, targetType);
folder.setPropertyValue("dc:title", name);
folder = getSession().createDocument(folder);
getPathCache().put(parseLocation(parentPath) + "/" + name, folder);
return folder;
}
use of org.nuxeo.ecm.core.api.DocumentModel in project nuxeo-filesystem-connectors by nuxeo.
the class SimpleBackend method removeItem.
@Override
public void removeItem(DocumentRef ref) {
DocumentModel doc = getSession().getDocument(ref);
if (doc != null) {
getTrashService().trashDocuments(Arrays.asList(doc));
getPathCache().remove(doc.getPathAsString());
} else {
log.warn("Can't move document " + ref.toString() + " to trash. Document did not found.");
}
}
Aggregations