private void handlePropertySubclassOf(OntProperty p) { List<RDFNode> list = p.listPropertyValues(RDFS.subClassOf).toList(); for (RDFNode node : list) { if (!node.canAs(Resource.class)) continue; Resource resource = node.asResource(); Resource onPropertyValue = resource.getPropertyResourceValue(OWL.onProperty); if (!RDFS.domain.equals(onPropertyValue)) continue; Resource someValuesFrom = resource.getPropertyResourceValue(OWL.someValuesFrom); if (someValuesFrom == null) continue; String uri = someValuesFrom.getURI(); if (uri != null) { OntResource type = someValuesFrom.as(OntResource.class); addField(type, p, null); } else { Resource unionList = someValuesFrom.getPropertyResourceValue(OWL.unionOf); while (unionList != null) { Resource first = unionList.getPropertyResourceValue(RDF.first); if (first != null) { String typeURI = first.getURI(); if (typeURI == null) { logger.warn( "Cannot handle union that contains an anonymous class in the domain of " + p.getURI()); } else { OntResource type = first.as(OntResource.class); addField(type, p, null); } } unionList = unionList.getPropertyResourceValue(RDF.rest); if (RDF.nil.equals(unionList)) { break; } } } } }
private List<OntResource> getEnumeratedIndividuals(OntClass type) { Resource equivalentClass = type.getPropertyResourceValue(OWL.equivalentClass); if (equivalentClass == null) { return null; } Resource oneOf = equivalentClass.getPropertyResourceValue(OWL.oneOf); if (oneOf == null) return null; List<RDFNode> nodeList = oneOf.as(RDFList.class).asJavaList(); List<OntResource> result = new ArrayList<OntResource>(); for (RDFNode node : nodeList) { result.add(node.as(OntResource.class)); } return result; }
@Test public void testConversion() throws Exception { status.put(DepositField.sourcePath.name(), "src/test/resources/paths/valid-bag"); status.put(DepositField.fileName.name(), "Test File"); status.put( DepositField.extras.name(), "{\"accessionNumber\" : \"123456\", \"mediaId\" : \"789\"}"); when(stages.getStagedURI(any(URI.class))) .thenAnswer( new Answer<URI>() { public URI answer(InvocationOnMock invocation) throws URISyntaxException { Object[] args = invocation.getArguments(); URI uri = (URI) args[0]; String path = uri.toString(); int index = path.lastIndexOf("/paths"); path = path.substring(index + 6); return new URI("tag:" + path); } }); job.run(); Model model = job.getReadOnlyModel(); Bag depositBag = model.getBag(job.getDepositPID().getURI()); assertEquals(depositBag.size(), 1); Bag bagFolder = model.getBag((Resource) depositBag.iterator().next()); assertEquals( "Bag folder label was not set", "Test File", bagFolder.getProperty(dprop(model, label)).getString()); assertEquals( "Content model was not set", CONTAINER.toString(), bagFolder.getPropertyResourceValue(fprop(model, hasModel)).getURI()); Resource folder = (Resource) bagFolder.iterator().next(); assertEquals( "Folder label was not set", folder.getProperty(dprop(model, label)).getString(), "test"); assertEquals( "Content model was not set", CONTAINER.toString(), folder.getPropertyResourceValue(fprop(model, hasModel)).getURI()); Bag childrenBag = model.getBag(folder.getURI()); assertEquals(childrenBag.size(), 2); // Put children into a map since we can't guarantee order from jena Map<String, Resource> children = new HashMap<>(2); NodeIterator childIt = childrenBag.iterator(); while (childIt.hasNext()) { Resource file = (Resource) childIt.next(); children.put(file.getProperty(dprop(model, label)).getString(), file); } ArgumentCaptor<String> filePathCaptor = ArgumentCaptor.forClass(String.class); verify(depositStatusFactory, times(2)).addManifest(anyString(), filePathCaptor.capture()); List<String> capturedFilePaths = Arrays.asList("tag:/valid-bag/bagit.txt", "tag:/valid-bag/manifest-md5.txt"); assertEquals(capturedFilePaths, filePathCaptor.getAllValues()); Resource file = children.get("lorem.txt"); assertEquals( "Content model was not set", SIMPLE.toString(), file.getPropertyResourceValue(fprop(model, hasModel)).getURI()); assertEquals( "Checksum was not set", "fa5c89f3c88b81bfd5e821b0316569af", file.getProperty(dprop(model, md5sum)).getString()); assertEquals( "File location not set", "tag:/valid-bag/data/test/lorem.txt", file.getProperty(dprop(model, stagingLocation)).getString()); Resource file2 = children.get("ipsum.txt"); assertEquals( "Content model was not set", SIMPLE.toString(), file2.getPropertyResourceValue(fprop(model, hasModel)).getURI()); assertEquals( "Checksum was not set", "e78f5438b48b39bcbdea61b73679449d", file2.getProperty(dprop(model, md5sum)).getString()); assertEquals( "File location not set", "tag:/valid-bag/data/test/ipsum.txt", file2.getProperty(dprop(model, stagingLocation)).getString()); File modsFile = new File(job.getDescriptionDir(), new PID(bagFolder.getURI()).getUUID() + ".xml"); assertTrue(modsFile.exists()); Set<String> cleanupSet = new HashSet<>(); StmtIterator it = depositBag.listProperties(dprop(model, cleanupLocation)); while (it.hasNext()) { Statement stmt = it.nextStatement(); cleanupSet.add(stmt.getString()); } assertEquals("Incorrect number of objects identified for cleanup", 3, cleanupSet.size()); assertTrue("Cleanup of bag not set", cleanupSet.contains("tag:/valid-bag/")); assertTrue("Cleanup of manifest not set", cleanupSet.contains("tag:/valid-bag/bagit.txt")); assertTrue( "Cleanup of manifest not set", cleanupSet.contains("tag:/valid-bag/manifest-md5.txt")); }