public CmisObject getObject(ObjectId objectId) { try { return session.getObject(objectId); } catch (CmisObjectNotFoundException e) { //great idea Chemistry developers - use RUNTIME exceptions to control the flow return null; } }
T get(final String absolutePath, Class<T> clazz) throws IOException { Object object = null; try { object = ECMHelperImpl.this.openCMISSession.getObject(ECMHelperImpl.this.openCMISSession.getObjectByPath(absolutePath)); } catch (CmisObjectNotFoundException e) { throw new IOException("'"+absolutePath+"' not found"); } if (object == null) { throw new IOException("'"+absolutePath+"' is null"); } if (!(clazz.isInstance(object))) { throw new IOException("'"+absolutePath+"' is not an instance of "+clazz.getSimpleName()); } T t = clazz.cast(object); log.debug("Found {} @ '{}'.", clazz.getSimpleName(), absolutePath); return t; } }
/** * Finds Object (document or folder) by unique id. If not could exceptions is thrown * @param session * @param id * @return * @throws CmisObjectNotFoundException */ protected CmisObject findObjectForId(Session session, String id) { return session.getObject(id); }
@Override public CmisObject call() throws Exception { if (objectId != null) { if (context != null) { return session.getObject(objectId, context); } else { return session.getObject(objectId); } } else { if (context != null) { return session.getObject(objectIdStr, context); } else { return session.getObject(objectIdStr); } } } }
@Override public CmisObject call() throws Exception { if (objectId != null) { if (context != null) { return session.getObject(objectId, context); } else { return session.getObject(objectId); } } else { if (context != null) { return session.getObject(objectIdStr, context); } else { return session.getObject(objectIdStr); } } } }
Session session = getSession(serverUrl, username, password); Document targetFile = (Document) session.getObject(path); Map<String, Object> properties = new HashMap<>(); properties.put(PropertyIds.NAME, name); targetFile.updateProperties(properties);
/** * Deletes document identified by objectId. * @param session * @param objectId */ protected void deleteDocument(Session session, String objectId) { Document document = (Document) session.getObject(objectId); document.delete(false); }
public Folder getFolderById(String id) { try { return (Folder) session.getObject(session.createObjectId(id)); } catch (CmisObjectNotFoundException e) { //great idea Chemistry developers - use RUNTIME exceptions to control the flow return null; } }
/** * Get the Folder object where the demo folder is to be created. */ public Folder getParentFolder(Session cmisSession) throws Exception { String rootFolderId = getRootFolderId(this.requestFactory, HOME_NETWORK, SITE); Folder folder = (Folder) cmisSession.getObject(rootFolderId); return folder; }
Session session = getSession(serverUrl, username, password); CmisObject object = session.getObject(path); Document suppDoc = (Document) object; suppDoc.delete(true);
public ObjectId createDocumentById(@NotNull(value = "No folderId was specified in the request.") String folderId, @NotNull(value = "No filename was specified in the request.") String filename, @NotNull(value = "No document content was specified in the payload.") Object content, @NotNull(value = "No file mime type was specified in the request.") String mimeType, org.mule.modules.cmis.model.VersioningState versioningState, @NotNull(value = "No object type was specified in the request.") String objectType, Map<String, Object> properties) { ObjectId returnId = null; Session session = this.getSession(this.connectionParameters); if (session != null) { logger.debug("Preparing to create a document with file name \"" + filename + "\" in the folder with ID \"" + folderId + "\"."); returnId = createDocument(session.getObject(session.createObjectId(folderId)), filename, content, mimeType, versioningState, objectType, properties); logger.debug("The ID of the repository node after document creation is \"" + returnId.getId() + "\"."); } return returnId; }
@Override public Document getRenditionDocument(OperationContext context) { if (getRenditionDocumentId() == null) { return null; } CmisObject rendDoc = session.getObject(getRenditionDocumentId(), context); if (!(rendDoc instanceof Document)) { return null; } return (Document) rendDoc; }
@Override public Document getRenditionDocument(OperationContext context) { if (getRenditionDocumentId() == null) { return null; } CmisObject rendDoc = session.getObject(getRenditionDocumentId(), context); if (!(rendDoc instanceof Document)) { return null; } return (Document) rendDoc; }
@Override public InputStream getDocumentContent(String id) { Session session = getSession(); if (session != null) { if (id == null || id.isEmpty()) { throw new IllegalArgumentException("No id provided"); } Document document = (Document) session.getObject(id); if (document == null) { throw new IllegalArgumentException( "Document with this id does not exist"); } return document.getContentStream().getStream(); } return null; }
@Override public Collection<String> getDocumentPathsById( String id ) { CmisObject obj = session.getObject(id); // check that object exist if (obj instanceof Folder) { return Collections.singletonList(((Folder)obj).getPath()); } if (obj instanceof org.apache.chemistry.opencmis.client.api.Document) { org.apache.chemistry.opencmis.client.api.Document doc = (org.apache.chemistry.opencmis.client.api.Document)obj; List<Folder> parents = doc.getParents(); List<String> paths = new ArrayList<String>(parents.size()); for (Folder parent : doc.getParents()) { paths.add(parent.getPath() + "/" + doc.getName()); } return paths; } return Collections.emptyList(); }
public CmisObject getObjectById(String objectId) { CmisObject returnObj = null; Session session = this.getSession(this.connectionParameters); if (session != null) { returnObj = session.getObject(session.createObjectId(objectId), createOperationContext(null, null)); } return returnObj; }
@Override public ExternalBinaryValue getBinaryValue(String id) { org.apache.chemistry.opencmis.client.api.Document doc = (org.apache.chemistry.opencmis.client.api.Document)session.getObject(id); if (doc == null) { return null; } ContentStream contentStream = doc.getContentStream(); if (contentStream == null) { return null; } return new CmisConnectorBinary(contentStream, getSourceName(), id, getMimeTypeDetector()); }
@Override public CMSContentSummary getDocument(String id) { Session session = getSession(); if (session != null) { Document document = null; if (id != null && !id.isEmpty()) { document = (Document) session.getObject(id); } if (document.getParents() != null && document.getParents().size() > 0) { return this.transform(document, document.getParents().get(0)); } else { return this.transform(document, null); } } return new DocumentSummary(); }
private Document cmisAccessList(String id) { DocumentWriter writer = newDocument(ObjectId.toString(ObjectId.Type.ACL, id)); writer.setPrimaryType(ModeShapeLexicon.ACCESS_LIST_NODE_TYPE_STRING); writer.setParent(id); CmisObject obj = session.getObject(id); obj = session.getObject(obj, ctx); Acl acl = obj.getAcl(); List<Ace> entries = acl.getAces(); for (Ace entry : entries) { String entryId = AclObjectId.encode(id, entry.getPrincipalId()); writer.addChild(ObjectId.toString(ObjectId.Type.PERMISSIONS, entryId), ModeShapeLexicon.PERMISSION.toString()); } return writer.document(); }
private Document cmisPermission( String id ) { String cmisObjectId = AclObjectId.cmisObjectId(id); String entryId = AclObjectId.entryId(id); DocumentWriter writer = newDocument(ObjectId.toString(ObjectId.Type.PERMISSIONS, id)); writer.setPrimaryType(ModeShapeLexicon.PERMISSION.toString()); writer.setParent(id); Acl acl = session.getObject(cmisObjectId, ctx).getAcl(); List<Ace> entries = acl.getAces(); for (Ace entry : entries) { if (entry.getPrincipalId().equals(entryId)) { String name = entry.getPrincipal().getId(); name = Converter.jcrPrincipal(name); writer.addProperty(ModeShapeLexicon.PERMISSION_PRINCIPAL_NAME.getLocalName(), name); List<String> perms = entry.getPermissions(); writer.addProperty(ModeShapeLexicon.PERMISSION_PRIVILEGES_NAME.getLocalName(), Converter.jcrPermissions(perms)); } } return writer.document(); }