public CmisObject getObjectByPath(String path) { try { return session.getObjectByPath(path); } catch (CmisObjectNotFoundException e) { //great idea Chemistry developers - use RUNTIME exceptions to control the flow return null; } }
/** * Finds folder by path and if not found returns null. * @param session * @param path * @return */ protected Folder findFolderForPath(Session session, String path) { try { return (Folder) session.getObjectByPath(path); } catch (CmisObjectNotFoundException e) { return null; } }
public Folder getParentFolder(Session cmisSession) { Folder folder = (Folder) cmisSession.getObjectByPath(FOLDER_PATH); return folder; }
/** * Utility method for checking if CMIS object exists at defined path * @param path path for object * @return <code>true</code> if exists, <code>false</code> otherwise */ private boolean isExistCmisObject(String path) { try { session.getObjectByPath(path); return true; } catch (CmisObjectNotFoundException e) { return false; } }
@Override public CmisObject call() throws Exception { if (parentPath != null) { if (context != null) { return session.getObjectByPath(parentPath, name, context); } else { return session.getObjectByPath(parentPath, name); } } else { if (context != null) { return session.getObjectByPath(path, context); } else { return session.getObjectByPath(path); } } } }
@Override public CmisObject call() throws Exception { if (parentPath != null) { if (context != null) { return session.getObjectByPath(parentPath, name, context); } else { return session.getObjectByPath(parentPath, name); } } else { if (context != null) { return session.getObjectByPath(path, context); } else { return session.getObjectByPath(path); } } } }
Session session = getSession(serverUrl, username, password); // Get the session object = session.getObjectByPath(idObject); // get the object if (object.getAllowableActions().getAllowableActions().contains(Action.CAN_DELETE_OBJECT)) { //// You can delete } else { //// You can't delete System.out.println("I can't "); }
@Override public String getDocumentId( String path ) { // establish relation between path and object identifier return session.getObjectByPath(path).getId(); }
// For how to get a Session see: // http://chemistry.apache.org/java/opencmis-client-api.html#sessions Session session = getSession(); CmisObject object = session.getObjectByPath("/path/to/object"); ObjectType type = object.getType(); Boolean isVersionable = type instanceOf DocumentType && ((DocumentType)type).isVersionable();
protected Document getDocumentFromFolder(String folderPath, String documentName) { try { Session cmisSession = getCmisSession(); Folder workflowDefinitionFolder = (Folder) cmisSession.getObjectByPath(folderPath); String path = workflowDefinitionFolder.getPath() + "/" + documentName; return (Document) cmisSession.getObjectByPath(path); } catch (CmisObjectNotFoundException e) { 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; } }
public CmisObject getOrCreateFolderByPath(@NotNull(value = "No folderPath was specified in the request.") String folderPath) { CmisObject returnObj = null; Session session = this.getSession(this.connectionParameters); if (session != null) { try { returnObj = session.getObjectByPath(folderPath); } catch (CmisObjectNotFoundException e) { logger.debug("CMIS Object Not Found, Creating a Folder Structure: ", e); return createFolderStructure(folderPath); } } return returnObj; }
public ObjectId createDocumentByPath(@NotNull(value = "No folderPath was specified in the request.") String folderPath, @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, boolean force) { ObjectId returnId = null; Session session = this.getSession(this.connectionParameters); if (session != null) { logger.debug("Preparing to create a document with file name \"" + filename + "\" in folder \"" + folderPath + "\"."); returnId = createDocument(force ? getOrCreateFolderByPath(folderPath) : session.getObjectByPath(folderPath), filename, content, mimeType, versioningState, objectType, properties); logger.debug("The ID of the repository node after document creation is \"" + returnId.getId() + "\"."); } return returnId; }
public CmisObject getObjectByPath(String path) { CmisObject returnObj = null; Session session = this.getSession(this.connectionParameters); if (session != null) { returnObj = session.getObjectByPath(path, createOperationContext(null, null)); } return returnObj; }
public InputStream getProcessImage(String processDefinitionId) { Session cmisSession = getCmisSession(); Folder workflowDefinitionFolder = (Folder) cmisSession.getObjectByPath(WORKFLOW_DEFINITION_FOLDER); Document imageDocument = (Document) cmisSession.getObjectByPath(workflowDefinitionFolder.getPath() + "/" + processDefinitionIdToProcessImage(processDefinitionId)); return imageDocument.getContentStream().getStream(); }
protected void uploadStringToDocument(String string, String folderPath, String documentName, String mimetype) { Session cmisSession = getCmisSession(); Folder folder = (Folder) cmisSession.getObjectByPath(folderPath); ContentStream contentStream = new ContentStreamImpl(documentName, null, mimetype, new ByteArrayInputStream(string.getBytes())); Document document = getDocumentFromFolder(folder.getPath(), documentName); if (document == null) { HashMap<String, Object> properties = new HashMap<String, Object>(); properties.put("cmis:name", documentName); properties.put("cmis:objectTypeId", "cmis:document"); folder.createDocument(properties, contentStream, VersioningState.MAJOR); } else { document.setContentStream(contentStream, true); } }
private void testDeepHierarchy(Session session, Folder testFolder, int depth) { String folderName = "depth"; StringBuilder path = new StringBuilder(testFolder.getPath()); for (int i = 0; i < depth; i++) { path.append('/'); path.append(folderName + i); } session.createPath(testFolder, path.toString(), getFolderTestTypeId()); for (int i = 0; i < depth; i++) { CmisObject folderObj = session.getObjectByPath(path.toString(), SELECT_ALL_NO_CACHE_OC); if (folderObj instanceof Folder) { session.deleteByPath(((Folder) folderObj).getPath()); } else { addResult(createResult(FAILURE, "Just created folder is not a folder! Id: " + folderObj.getId())); } path.delete(path.lastIndexOf("/"), path.length()); } addResult(createInfoResult("Tested the creation of a folder hierarchy with a depth of " + (depth + 1) + " below the test folder.")); } }
protected void deployProcess(KickstartWorkflow kickstartWorkflow, String baseFileName,String jsonSource) { Session cmisSession = getCmisSession(); Folder workflowDefinitionFolder = (Folder) cmisSession.getObjectByPath(WORKFLOW_DEFINITION_FOLDER); uploadDiagramFile(kickstartWorkflow, baseFileName, workflowDefinitionFolder); // Process image (must go first, since it will add DI to the process xml) uploadJsonFile(baseFileName, jsonSource, workflowDefinitionFolder); uploadProcessFile(kickstartWorkflow, baseFileName, workflowDefinitionFolder); }
public void setProcessImage(String processDefinitionId, InputStream processImageStream) { Session cmisSession = getCmisSession(); Folder workflowDefinitionFolder = (Folder) cmisSession.getObjectByPath(WORKFLOW_DEFINITION_FOLDER); String fileName = processDefinitionIdToProcessImage(processDefinitionId); ContentStream contentStream = new ContentStreamImpl(fileName, null, "image/png", processImageStream); Document imageDocument = getDocumentFromFolder(workflowDefinitionFolder.getPath(), fileName); if (imageDocument == null) { HashMap<String, Object> properties = new HashMap<String, Object>(); properties.put("cmis:name", fileName); properties.put("cmis:objectTypeId", "cmis:document"); workflowDefinitionFolder.createDocument(properties, contentStream, VersioningState.MAJOR); } else { imageDocument.setContentStream(contentStream, true); } }
@Override public void createDocument(DocumentSummary doc) { Session session = getSession(); if (session != null) { Map<String, Object> properties = new HashMap<String, Object>(); properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document"); properties.put(PropertyIds.NAME, doc.getName()); InputStream stream = new ByteArrayInputStream(doc.getContent()); ContentStream contentStream = new ContentStreamImpl(doc.getName(), BigInteger.valueOf(doc.getContent().length), MimeTypes.getMIMEType(doc.getName()), stream); Document createdDoc = ((Folder) session.getObjectByPath(doc.getPath())).createDocument( properties, contentStream, VersioningState.NONE); doc.setId(createdDoc.getId()); } else { throw new IllegalStateException("Could not get CMIS session"); } }