/** * 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); }
/** * 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; } }
@Override public Boolean testConnection() { Session session = getSession(); if (session != null) { if (session.getRootFolder() != null) { return true; } } return 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; } }
Folder root = session.getRootFolder(); String name = "testCreateRelationship " + System.currentTimeMillis(); newFolderProps.put(PropertyIds.NAME, name); Folder folder = root.createFolder(newFolderProps, null, null, null, session.getDefaultContext()); System.out.println(folder.getName()); newDocProps1.put(PropertyIds.NAME, "Test Doc 1"); ContentStream contentStream1 = new ContentStreamImpl("xyz.txt", null, "plain/text", new ByteArrayInputStream("some content".getBytes())); Document doc1 = folder.createDocument(newDocProps1, contentStream1, VersioningState.MAJOR, null, null, null, session.getDefaultContext()); newDocProps2.put(PropertyIds.NAME, "Test Doc 2"); ContentStream contentStream2 = new ContentStreamImpl("xyz.txt", null, "plain/text", new ByteArrayInputStream("some content".getBytes())); Document doc2 = folder.createDocument(newDocProps2, contentStream2, VersioningState.MAJOR, null, null, null, session.getDefaultContext()); relProps.put("cmis:targetId", doc2.getId()); relProps.put("cmis:objectTypeId", "R:cmiscustom:assoc"); session.createRelationship(relProps, null, null, null); CmisObject object = session.getObject(doc1,operationContext);
ContentStream contentStream = session.getObjectFactory().createContentStream(name, size, mimetype, in); TypeDefinition type = session.getTypeDefinition(objectTypeId); if (!(type instanceof DocumentTypeDefinition)) { addResult(createResult(FAILURE, "Type is not a document type! Type: " + objectTypeId, true)); ObjectId id = session.createDocument(properties, testFolder, contentStream, versioningState); Document doc = (Document) session.getObject(id, SELECT_ALL_NO_CACHE_OC); addResult(assertIsTrue(paths != null && paths.size() > 0, null, f)); session.deleteByPath(paths.get(0)); } finally {
public ObjectId createFolder(String folderName, String parentObjectId) { ObjectId returnId = null; Session session = this.getSession(this.connectionParameters); if (session != null) { if (StringUtils.isEmpty(parentObjectId)) { parentObjectId = session.getRootFolder().getId(); } Map<String, Object> properties = new HashMap<String, Object>(); properties.put(PropertyIds.NAME, folderName); properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder"); try { returnId = session.createFolder(properties, session.getObject(session.createObjectId(parentObjectId))); } catch (CmisContentAlreadyExistsException e) { logger.debug("CMIS Content Already Exists ", e); CmisObject object = session.getObject(session.createObjectId(parentObjectId)); if (!(object instanceof Folder)) { throw new IllegalArgumentException(parentObjectId + " is not a folder"); } Folder folder = (Folder) object; for (CmisObject o : folder.getChildren()) { if (o.getName().equals(folderName)) { return session.createObjectId(o.getId()); } } } } return returnId; // End createFolder }
@Override public List<CMSContentSummary> getChildren(String id) { Session session = getSession(); if (session != null) { Folder folder = null; if (id == null || id.isEmpty()) { folder = session.getRootFolder(); } else { folder = (Folder) session.getObject(id); } ItemIterable<CmisObject> children = folder.getChildren(); Iterator<CmisObject> childrenItems = children.iterator(); List<CmisObject> documents = new ArrayList<CmisObject>(); while (childrenItems.hasNext()) { CmisObject item = childrenItems.next(); documents.add(item); } return this.transform(documents, folder); } return new ArrayList<CMSContentSummary>(); }
type = session.getTypeDefinition(objectTypeId); } catch (CmisObjectNotFoundException e) { addResult(createResult(UNEXPECTED_EXCEPTION, relId = session.createRelationship(properties); result = (Relationship) session.getObject(relId, SELECT_ALL_NO_CACHE_OC); } catch (Exception e) { addResult(createResult(UNEXPECTED_EXCEPTION,
Folder rootFolder = session.getRootFolder(); session.getObject(doc1); props.put(PropertyIds.TARGET_ID, doc2.getId()); session.createRelationship(props);
@Override public ContentStream getContentStream() { if (objectId == null || getStreamId() == null) { return null; } ContentStream contentStream; try { contentStream = session.getBinding().getObjectService() .getContentStream(session.getRepositoryInfo().getId(), objectId, getStreamId(), null, null, null); } catch (CmisConstraintException e) { // no content stream return null; } if (contentStream == null) { return null; } String filename = contentStream.getFileName(); if (filename == null) { filename = getTitle(); } BigInteger bigLength = contentStream.getBigLength(); if (bigLength == null) { bigLength = getBigLength(); } long length = bigLength == null ? -1 : bigLength.longValue(); return session.getObjectFactory().createContentStream(filename, length, contentStream.getMimeType(), contentStream.getStream()); }
ContentStream contentStream = cmisSession.getObjectFactory(). createContentStream( fileName, System.out.println("Created new document: " + document.getId()); } catch (CmisContentAlreadyExistsException ccaee) { document = (Document) cmisSession.getObjectByPath(parentFolder.getPath() + "/" + fileName); System.out.println("Document already exists: " + fileName);
Document document = (Document) session.getObject(objectId); InputStream input = new ByteArrayInputStream(content); ContentStream contentStream = session.getObjectFactory().createContentStream(document.getName(), content.length, type, input); try { if (((DocumentType)(document.getType())).isVersionable() && (mode.equals(UpdateMode.MAJOR) || mode.equals(UpdateMode.MINOR))) { Document pwc = (Document) session.getObject(document.checkOut()); boolean major = mode.equals(UpdateMode.MAJOR); try { ObjectId newObjectId = pwc.checkIn(major, null, contentStream, "Document update from process"); return (Document) session.getObject(newObjectId); } catch (CmisBaseException e) { pwc.cancelCheckOut();
Acl basicAcl = session.getAcl(doc, true); aces.add(session.getObjectFactory().createAce(principal, Collections.singletonList("cmis:write"))); session.applyAcl(doc, aces, null, null); if (session.getRepositoryInfo().getAclCapabilities().getAclPropagation() != AclPropagation.REPOSITORYDETERMINED) { aces.add(session.getObjectFactory().createAce(principal, Collections.singletonList("cmis:all"))); session.setAcl(doc, aces);
public RepositoryInfo repositoryInfo() { RepositoryInfo repoInfo = null; Session session = this.getSession(this.connectionParameters); if (session != null) { repoInfo = session.getRepositoryInfo(); } return repoInfo; }
@Override public Future<CmisObject> getObject(ObjectId objectId) { return getObject(objectId, session.getDefaultContext()); }
@Override public ObjectType call() throws Exception { return session.getTypeDefinition(typeId); } }
private void doQuery(Session session, String stmt) { for (QueryResult qr : session.query(stmt, false)) { qr.getPropertyByQueryName("cmis:name"); } }
public static void main(String args[]) { String serverUrl = args[0]; String username = args[1]; String password = args[2]; Session session = getSession(serverUrl, username, password); Folder root = session.getRootFolder(); Map<String, Object> properties = new HashMap<String, Object>(); properties.put(PropertyIds.OBJECT_TYPE_ID, BaseTypeId.CMIS_ DOCUMENT.value()); String name = "New Document (" + System.currentTimeMillis() + ").txt"; properties.put(PropertyIds.NAME, name); List<Ace> addAces = new LinkedList<Ace>(); List<Ace> removeAces = new LinkedList<Ace>(); List<Policy> policies = new LinkedList<Policy>(); String content = "The quick brown fox jumps over the lazy dog."; ContentStream contentStream = new ContentStreamImpl("text.txt", BigInteger.valueOf(content.length()), "text/plain", new ByteArrayInputStream(content. getBytes())); Document newDocument = root.createDocument(properties, contentStream, VersioningState.MAJOR, policies, addAces, removeAces, session.getDefaultContext()); System.out.println(newDocument.getId());}
ObjectFactory of = session.getObjectFactory(); relationships = new ArrayList<Relationship>(); for (ObjectData rod : objectData.getRelationships()) { CmisObject relationship = of.convertObject(rod, session.getDefaultContext()); if (relationship instanceof Relationship) { relationships.add((Relationship) relationship);