public Object read(ObjectInputStream os) throws IOException, ClassNotFoundException { String objectId = os.readUTF(); String canonicalName = os.readUTF(); Session session = getRepositorySession(user, password, url, repository); try { org.apache.chemistry.opencmis.client.api.Document doc = (org.apache.chemistry.opencmis.client.api.Document) findObjectForId(session, objectId); Document document = (Document) Class.forName(canonicalName).newInstance(); document.setIdentifier(objectId); document.setName(doc.getName()); document.addAttribute("location", getFolderName(doc.getParents()) + getPathAsString(doc.getPaths())); if (doc.getContentStream() != null) { ContentStream stream = doc.getContentStream(); document.setContent(IOUtils.toByteArray(stream.getStream())); document.addAttribute("updated", "false"); document.addAttribute("type", stream.getMimeType()); } return document; } catch(Exception e) { throw new RuntimeException("Cannot read document from CMIS", e); } finally { session.clear(); } }
try { document = parentFolder.createDocument(props, contentStream, null); System.out.println("Created new document: " + document.getId()); } catch (CmisContentAlreadyExistsException ccaee) { document = (Document) cmisSession.getObjectByPath(parentFolder.getPath() + "/" + fileName);
/** * 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); }
private void updateDoc(Database database, String documentId) { Document document = database.getDocument(documentId); try { // Update the document with more data Map<String, Object> updatedProperties = new HashMap<String, Object>(); updatedProperties.putAll(document.getProperties()); updatedProperties.put("eventDescription", "Everyone is invited!"); updatedProperties.put("address", "123 Elm St."); // Save to the Couchbase local Couchbase Lite DB document.putProperties(updatedProperties); } catch (CouchbaseLiteException e) { Log.e(TAG, "Error putting", e); } }
doc.getProperties().putValue("DocumentTitle", "New Document via Java API"); doc.set_MimeType("text/plain"); // if its your pdf then set mimetype for PDF doc.save(RefreshMode.NO_REFRESH); doc.checkin(AutoClassify.DO_NOT_AUTO_CLASSIFY, CheckinType.MAJOR_VERSION); doc.save(RefreshMode.NO_REFRESH);
@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(); }
Document doc = createDocument(session, testFolder, "contenttest.txt", CONTENT1); Document workDoc = doc; DocumentTypeDefinition docType = (DocumentTypeDefinition) doc.getType(); if (!doc.getAllowableActions().getAllowableActions().contains(Action.CAN_SET_CONTENT_STREAM)) { if (!docType.isVersionable()) { addResult(createResult(SKIPPED, "The test document does not accept a new content stream. Test skipped!")); doc.delete(true); return; } else { workDoc = (Document) session.getObject(doc.checkOut(), SELECT_ALL_NO_CACHE_OC); checkedout = true; if (!workDoc.getAllowableActions().getAllowableActions().contains(Action.CAN_SET_CONTENT_STREAM)) { addResult(createResult(SKIPPED, "The test PWC does not accept a new content stream. Test skipped!")); workDoc.cancelCheckOut(); doc.delete(true); return; ObjectId newObjectId = workDoc.deleteContentStream(true); addResult(assertNull(contentDoc.getContentStream(), null, f)); + contentDoc.getContentStreamMimeType()); addResult(assertNull(contentDoc.getContentStreamMimeType(), null, f)); + contentDoc.getContentStreamLength());
@Override public InputStream getStream() { ContentStream cs = doc.getContentStream(); return cs.getStream(); } }, name, getApplication());
DocumentTypeDefinition docType = (DocumentTypeDefinition) doc.getType(); doc.delete(true); return; String[] propertiesToCheck = new String[doc.getType().getPropertyDefinitions().size()]; for (String propId : doc.getType().getPropertyDefinitions().keySet()) { propertiesToCheck[i++] = propId; for (Property<?> property : doc.getProperties()) { if (property.getDefinition().getUpdatability() == Updatability.READWRITE) { writableProperties.put(property.getId(), property.getValue()); ObjectId pwcId = doc.checkOut(); Document pwc = (Document) session.getObject(pwcId, SELECT_ALL_NO_CACHE_OC); addResult(checkVersionSeries(session, pwc.getAllVersions(SELECT_ALL_NO_CACHE_OC), propertiesToCheck, "Test version series after check out")); pwc.cancelCheckOut(); doc.refresh(); checkCheckedIn(doc); pwcId = doc.checkOut(); pwc = (Document) session.getObject(pwcId, SELECT_ALL_NO_CACHE_OC); ObjectId newVersionId = pwc.checkIn(true, null, null, "Test Version 2");
documents.put(newDocument.getId(), newDocument); versionSeriesIds.add(newDocument.getVersionSeriesId()); if (!childrenIds.contains(document.getId())) { addResult(createResult(FAILURE, "Created document not found in test folder children! Id: " + document.getId())); if (Boolean.TRUE.equals(((DocumentType) documents.values().iterator().next().getType()).isVersionable())) { f = createResult(FAILURE, "Although the created documents are independent, some documents share a Version Series Id!"); ContentStream contentStream = document.getContentStream(); if (contentStream == null || contentStream.getStream() == null) { addResult(createResult(FAILURE, "Document has no content! Id: " + document.getId())); continue; f = createResult(FAILURE, "Unexpected document content! Id: " + document.getId()); addResult(assertEquals(CONTENT, contentStr, null, f)); f = createResult(FAILURE, "Unexpected document content! Id: " + document.getId()); addResult(assertEquals(CONTENT, contentStr2, null, f)); List<String> paths = document.getPaths(); + document.getId()); addResult(assertIsTrue(paths != null && paths.size() > 0, null, f)); f = createResult(FAILURE, "Unexpected document content! Id: " + document.getId()); addResult(assertEquals(CONTENT, contentStr3, null, f));
document.setName(doc.getName()); document.setLastModified(doc.getLastModificationDate().getTime()); document.setSize(doc.getContentStreamLength()); document.addAttribute("location", getFolderName(doc.getParents()) + getPathAsString(doc.getPaths())); if (doc.getContentStream() != null && contentUrl == null) { ContentStream stream = doc.getContentStream(); document.setContent(IOUtils.toByteArray(stream.getStream())); document.addAttribute("updated", "false");
public void testDownloadEvent() throws InterruptedException { Repository repository = getRepository("admin", "admin"); Session session = repository.createSession(); Folder rootFolder = session.getRootFolder(); String docname = "mydoc-" + GUID.generate() + ".txt"; Map<String, String> props = new HashMap<String, String>(); { props.put(PropertyIds.OBJECT_TYPE_ID, "D:cmiscustom:document"); props.put(PropertyIds.NAME, docname); } // content byte[] byteContent = "Hello from Download testing class".getBytes(); InputStream stream = new ByteArrayInputStream(byteContent); ContentStream contentStream = new ContentStreamImpl(docname, BigInteger.valueOf(byteContent.length), "text/plain", stream); Document doc1 = rootFolder.createDocument(props, contentStream, VersioningState.MAJOR); NodeRef doc1NodeRef = cmisIdToNodeRef(doc1.getId()); ContentStream content = doc1.getContentStream(); assertNotNull(content); //range request content = doc1.getContentStream(BigInteger.valueOf(2),BigInteger.valueOf(4)); assertNotNull(content); }
DocumentTypeDefinition docType = (DocumentTypeDefinition) doc.getType(); workDoc = (Document) session.getObject(doc.checkOut(), SELECT_ALL_NO_CACHE_OC); checkedout = true; OutputStream out1 = workDoc.createOverwriteOutputStream("appendstreamtest", "text/plain", bufferSize); workDoc.refresh(); String content1 = getStringFromContentStream(workDoc.getContentStream()); OutputStream out2 = workDoc.createAppendOutputStream(bufferSize); workDoc.refresh(); String content2 = getStringFromContentStream(workDoc.getContentStream()); workDoc.cancelCheckOut();
addResult(assertEquals(DOC_NAME1, doc1.getName(), null, f)); DocumentTypeDefinition type = (DocumentTypeDefinition) doc1.getType(); PropertyDefinition<?> namePropDef = type.getPropertyDefinitions().get(PropertyIds.NAME); if (namePropDef.getUpdatability() == Updatability.WHENCHECKEDOUT || (!doc1.getAllowableActions().getAllowableActions().contains(Action.CAN_UPDATE_PROPERTIES) && Boolean.TRUE .equals(type.isVersionable()))) { workDoc = (Document) session.getObject(doc1.checkOut(), SELECT_ALL_NO_CACHE_OC); checkedout = true; properties.put(PropertyIds.NAME, DOC_NAME2); ObjectId newId = workDoc.updateProperties(properties, false); Document doc2 = (Document) session.getObject(newId, SELECT_ALL_NO_CACHE_OC); addResult(assertEquals(DOC_NAME2, doc2.getName(), null, f)); if (!workDoc.getId().equals(doc2.getId())) { deleteObject(doc2); workDoc.cancelCheckOut(); if (!doc1.getId().equals(doc2.getId())) { if (exists(doc1)) { deleteObject(doc1);
String versionSeriesId = doc.getVersionSeriesId(); List<Document> versions = doc.getAllVersions(SELECT_ALL_NO_CACHE_OC); Document lastestVersion = doc.getObjectOfLatestVersion(false, SELECT_ALL_NO_CACHE_OC); addResult(results, checkObject(session, lastestVersion, properties, "Latest version check: " + lastestVersion.getId())); f = createResult(FAILURE, "Latest version is not flagged as latest version! ID: " + lastestVersion.getId()); addResult(results, assertIsTrue(lastestVersion.isLatestVersion(), null, f)); lastestMajorVersion = doc.getObjectOfLatestVersion(true, SELECT_ALL_NO_CACHE_OC); "Latest major version check: " + lastestMajorVersion.getId())); + lastestMajorVersion.getId()); addResult(results, assertIsTrue(lastestMajorVersion.isLatestMajorVersion(), null, f)); addResult(results, checkObject(session, version, properties, "Version check: " + version.getId())); if (version.isVersionSeriesCheckedOut()) { f = createResult(WARNING, "Version series is checked-out and the PWC is not the latest version! ID: " + version.getId() + " (Note: The words of the CMIS specification define that the PWC is the latest version." + " But that is not the intention of the spec and will be changed in CMIS 1.1." + " Thus this a warning, not an error.)"); addResult(results, assertIsTrue(version.isLatestVersion(), null, f)); } else {
String path = doc.getPaths().get(0); doc2 = (Document) session.getObjectByPath(path, SELECT_ALL_NO_CACHE_OC); addResult(checkObject(session, doc2, getAllProperties(doc2), "New document object spec compliance")); assertEquals(NAMES[i], doc2.getName(), null, f); ContentStream contentStream = doc.getContentStream(); doc.delete(true); } catch (Exception e) {
if (doc.getChangeToken() == null) { addResult(createResult(SKIPPED, "Repository does not provide change tokens for documents. Test skipped!")); if (!doc.getAllowableActions().getAllowableActions().contains(Action.CAN_SET_CONTENT_STREAM)) { addResult(createResult(SKIPPED, "Document content can't be changed. Test skipped!")); return; BigInteger.valueOf(contentBytes.length), "text/plain", new ByteArrayInputStream(contentBytes)); ObjectId newId = doc.setContentStream(contentStream, true, false); if (Boolean.TRUE.equals(((DocumentTypeDefinition) doc.getType()).isVersionable())) { List<Document> versions = doc.getAllVersions(); if (versions == null || versions.size() < 1) { addResult(createResult(FAILURE, "Repository returned an empty list of document versions!")); if (!doc.getId().equals(newId.getId())) { } else { try { doc.setContentStream(contentStream, true, false);
DocumentTypeDefinition type = (DocumentTypeDefinition) doc.getType(); boolean hasContentProperties = (doc.getContentStreamFileName() != null) || (doc.getContentStreamId() != null) || (doc.getContentStreamLength() > -1) || (doc.getContentStreamMimeType() != null); ContentStream contentStream = doc.getContentStream(); if (hasContentProperties && doc.getContentStreamLength() > 0) { addResult(results, createResult(FAILURE, "Content properties have values but the document has no content!")); addResult(results, assertEquals(doc.getContentStreamFileName(), contentStream.getFileName(), null, f)); if (doc.getContentStreamLength() > -1 && contentStream.getLength() > -1) { f = createResult(FAILURE, "Content lengths don't match!"); addResult(results, assertEquals(doc.getContentStreamLength(), contentStream.getLength(), null, f)); String docMimeType = doc.getContentStreamMimeType(); if (docMimeType != null) { int x = docMimeType.indexOf(';'); if (contentMimeType.equals(docMimeType)) { f = createResult(WARNING, "Content MIME types don't match!"); addResult(results, assertEquals(doc.getContentStreamMimeType(), contentStream.getMimeType(), null, f)); List<ContentStreamHash> hashes = doc.getContentStreamHashes(); List<MessageDigest> messageDigests = null; List<String> algorithms = null;
addResult(assertEquals(name, result.getName(), null, f)); addResult(assertEquals((long) contentBytes.length, result.getContentStreamLength(), null, f)); List<ContentStreamHash> hashes = result.getContentStreamHashes(); if (docType.getPropertyDefinitions() != null && docType.getPropertyDefinitions().containsKey(PropertyIds.CONTENT_STREAM_HASH)) { ContentStream contentStream = result.getContentStream(); addResult(assertEquals(result.getContentStreamFileName(), contentStream.getFileName(), null, f)); String fetchedContent = getStringFromContentStream(result.getContentStream()); if (!content.equals(fetchedContent)) { addResult(createResult(FAILURE, List<Folder> parents = result.getParents(SELECT_ALL_NO_CACHE_OC); boolean found = false; for (Folder folder : parents) {
this.filename = doc.getContentStreamFileName(); } else { this.filename = filename; this.mimeType = doc.getContentStreamMimeType(); } else { this.mimeType = mimeType; this.documentId = doc.getId(); this.changeToken = doc.getChangeToken(); this.overwrite = overwrite; this.buffer = new byte[bufferSize];