@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(); }
private void testMultipleCenterSpaceSpace(Session session, Folder testFolder) { String name = "twocenter spaces.txt"; try { Document doc = createDocumentWithoutChecks(testFolder, name); if (doc.getName().equals(name)) { addResult(createInfoResult("Repository does supports document names with more than one successive spaces.")); } else { if (doc.getName().equals("twocenterspaces.txt")) { addResult(createInfoResult("Repository removes spaces from document name.")); } else if (doc.getName().equals("twocenter spaces.txt")) { addResult(createInfoResult("Repository combines multiple spaces into one in document names.")); } else { addResult(createInfoResult("Repository renames documents with a space.")); } } } catch (CmisBaseException e) { addResult(createInfoResult("Repository does not support document names with a space. Exception: " + e.toString())); } }
private void testTrailingSpace(Session session, Folder testFolder) { String name = "trailing.txt"; try { Document doc = createDocumentWithoutChecks(testFolder, name + " "); if (doc.getName().equals(name + " ")) { addResult(createInfoResult("Repository does supports document names with a trailing space.")); } else { if (doc.getName().equals(name)) { addResult(createInfoResult("Repository removes trailing space from document name.")); } else { addResult(createInfoResult("Repository renames documents with a trailing space.")); } } } catch (CmisBaseException e) { addResult(createInfoResult("Repository does not support document names with a trailing space. Exception: " + e.toString())); } }
private void testLeadingSpace(Session session, Folder testFolder) { String name = "leading.txt"; try { Document doc = createDocumentWithoutChecks(testFolder, " " + name); if (doc.getName().equals(" " + name)) { addResult(createInfoResult("Repository does supports document names with a leading space.")); } else { if (doc.getName().equals(name)) { addResult(createInfoResult("Repository removes leading space from document name.")); } else { addResult(createInfoResult("Repository renames documents with a leading space.")); } } } catch (CmisBaseException e) { addResult(createInfoResult("Repository does not support document names with a leading space. Exception: " + e.toString())); } }
private void testCenterSpaceSpace(Session session, Folder testFolder) { String name = "center space.txt"; try { Document doc = createDocumentWithoutChecks(testFolder, name); if (doc.getName().equals(name)) { addResult(createInfoResult("Repository does supports document names with a space.")); } else { if (doc.getName().equals("centerspace.txt")) { addResult(createInfoResult("Repository removes spaces from document name.")); } else { addResult(createInfoResult("Repository renames documents with a space.")); } } } catch (CmisBaseException e) { addResult(createInfoResult("Repository does not support document names with a space. Exception: " + e.toString())); } }
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(); } }
private Document createVersion(Session session, Document doc, String content, int version) { CmisTestResult f; // check out ObjectId pwcId = doc.checkOut(); Document pwc = (Document) session.getObject(pwcId, SELECT_ALL_NO_CACHE_OC); addResult(checkObject(session, pwc, getAllProperties(pwc), "PWC " + version + " compliance")); // check in byte[] contentBytes = IOUtils.toUTF8Bytes(content); ContentStream contentStream = new ContentStreamImpl(doc.getName(), BigInteger.valueOf(contentBytes.length), "text/plain", new ByteArrayInputStream(contentBytes)); ObjectId newVersionId = pwc.checkIn(true, null, contentStream, "test version " + version); IOUtils.closeQuietly(contentStream); Document newVersion = (Document) session.getObject(newVersionId, SELECT_ALL_NO_CACHE_OC); addResult(checkObject(session, newVersion, getAllProperties(newVersion), "Version " + version + " compliance")); // check version history List<Document> versions = doc.getAllVersions(); f = createResult(FAILURE, "Version series should have " + version + " versions but has " + versions.size() + "!"); addResult(assertEquals(version, versions.size(), null, f)); if (!versions.isEmpty()) { f = createResult(FAILURE, "Newly created version " + version + " is not the latest version!"); addResult(assertEquals(newVersion.getId(), versions.get(0).getId(), null, f)); if (versions.size() > 1) { f = createResult(FAILURE, "The previous version of version " + version + " is not the document it has been created from!"); addResult(assertEquals(doc.getId(), versions.get(1).getId(), null, f)); } } return newVersion; }
document.setName(doc.getName()); document.setLastModified(doc.getLastModificationDate().getTime()); document.setSize(doc.getContentStreamLength());
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()
addResult(assertEquals(name, result.getName(), null, f));
assertEquals(NAMES[i], doc2.getName(), null, f);
} else { addResult(checkObject(session, doc2, getAllProperties(doc2), "Moved document check. Id: + " + doc2.getName()));
org.apache.chemistry.opencmis.client.api.Document doc = (org.apache.chemistry.opencmis.client.api.Document) findObjectForId(session, document.getIdentifier()); document.setName(doc.getName()); document.addAttribute("location", getFolderName(doc.getParents()) + getPathAsString(doc.getPaths())); if (doc.getContentStream() != null) {
ContentStream contentStream = session.getObjectFactory().createContentStream(workDoc.getName(), contentBytes.length, "text/plain", new ByteArrayInputStream(contentBytes)); ContentStream contentStream = session.getObjectFactory().createContentStream(workDoc.getName(), contentBytes.length, "text/plain", new ByteArrayInputStream(contentBytes));
} else { addResult(checkObject(session, doc2, getAllProperties(doc2), "Copied document check. Id: + " + doc2.getName()));