/** * @throws SrampException */ private Document addDocument(String name, String ... classifications) throws SrampException { InputStream contentStream = null; try { String artifactFileName = "s-ramp-press-release.pdf"; //$NON-NLS-1$ contentStream = this.getClass().getResourceAsStream("/sample-files/core/" + artifactFileName); //$NON-NLS-1$ Document document = new Document(); document.setName(name); document.setArtifactType(BaseArtifactEnum.DOCUMENT); for (String classification : classifications) { document.getClassifiedBy().add(classification); } return (Document) persistenceManager.persistArtifact(document, contentStream); } finally { IOUtils.closeQuietly(contentStream); } }
/** * @return a new artifact * @throws SrampException */ private BaseArtifactType createArtifact(Set<String> classifiers, String ... args) throws SrampException { String artifactFileName = "s-ramp-press-release.pdf"; //$NON-NLS-1$ InputStream pdf = this.getClass().getResourceAsStream("/sample-files/core/" + artifactFileName); //$NON-NLS-1$ Document document = new Document(); document.setName(artifactFileName); document.setArtifactType(BaseArtifactEnum.DOCUMENT); document.setDescription("Sample description."); //$NON-NLS-1$ if (classifiers != null) { for (String classifier : classifiers) { document.getClassifiedBy().add(classifier); } } if (args != null && args.length > 0) { for (int i = 0; i < args.length; i+=2) { String propName = args[i]; String propVal = args[i+1]; SrampModelUtils.setCustomProperty(document, propName, propVal); } } BaseArtifactType artifact = persistenceManager.persistArtifact(document, pdf); Assert.assertNotNull(artifact); log.info("persisted s-ramp-press-release.pdf to JCR, returned artifact uuid=" + artifact.getUuid()); //$NON-NLS-1$ return artifact; }
@Test public void testPersistClassifications() throws Exception { SrampOntology ontology = createOntology(); String artifactFileName = "s-ramp-press-release.pdf"; //$NON-NLS-1$ InputStream contentStream = this.getClass().getResourceAsStream("/sample-files/core/" + artifactFileName); //$NON-NLS-1$ Document document = new Document(); document.setName(artifactFileName); document.setArtifactType(BaseArtifactEnum.DOCUMENT); document.getClassifiedBy().add(ontology.findClass("China").getUri().toString()); //$NON-NLS-1$ BaseArtifactType artifact = persistenceManager.persistArtifact(document, contentStream); Assert.assertNotNull(artifact); if (log.isDebugEnabled()) { persistenceManager.printArtifactGraph(artifact.getUuid(), ArtifactType.Document()); } artifact = persistenceManager.getArtifact(artifact.getUuid(), ArtifactType.Document()); Assert.assertNotNull(artifact.getClassifiedBy()); Assert.assertEquals(1, artifact.getClassifiedBy().size()); Assert.assertEquals("urn:example.org/test2#China", artifact.getClassifiedBy().get(0)); //$NON-NLS-1$ }