Skip to content

Commit

Permalink
Deprecating out GraphSubjects... first part.
Browse files Browse the repository at this point in the history
  • Loading branch information
ajs6f committed Apr 2, 2014
1 parent bca6ac2 commit f0ae47c
Show file tree
Hide file tree
Showing 23 changed files with 62 additions and 80 deletions.
Expand Up @@ -44,8 +44,9 @@ public class ExternalIdentifierTranslator extends IdentifierTranslator<Resource>
@Inject
private List<InternalIdentifierTranslator> translationChain;

private Converter<String, String> forward, reverse = identity();
private Converter<String, String> forward = identity();

private Converter<String, String> reverse = identity();
@Override
protected Resource doForward(final String a) {
return doRdfForward(forward.convert(a));
Expand Down
Expand Up @@ -33,6 +33,7 @@ public interface GraphSubjects {
* @return an RDF URI resource
* @throws RepositoryException
*/
@Deprecated
Resource getGraphSubject(final Node node) throws RepositoryException;

/**
Expand All @@ -41,6 +42,7 @@ public interface GraphSubjects {
* @return a JCR node, or null if one couldn't be found
* @throws RepositoryException
*/
@Deprecated
Node getNodeFromGraphSubject(final Resource subject)
throws RepositoryException;

Expand Down
Expand Up @@ -247,9 +247,7 @@ public Dataset getPropertiesDataset(final GraphSubjects graphSubjects,

dataset.addNamedModel(PROBLEMS_MODEL_NAME, problemsModel);

dataset.getContext().set(URI_SYMBOL,
graphSubjects.getGraphSubject(getNode()));

dataset.getContext().set(URI_SYMBOL, graphSubjects.getGraphSubject(getNode().getPath()));


return dataset;
Expand Down
Expand Up @@ -244,9 +244,8 @@ public RdfStream getJcrPropertiesModel(final Iterator<Node> nodeIterator,
results.concat(new PropertiesRdfContext(node, graphSubjects,
llstore));
if (iteratorSubject != null) {
results.concat(singleton(create(iteratorSubject.asNode(),
HAS_MEMBER_OF_RESULT.asNode(), graphSubjects
.getGraphSubject(node).asNode())));
results.concat(singleton(create(iteratorSubject.asNode(), HAS_MEMBER_OF_RESULT.asNode(), graphSubjects
.getGraphSubject(node.getPath()).asNode())));
}
}
return results;
Expand Down
Expand Up @@ -79,9 +79,8 @@ public Iterator<Triple> apply(final FixityResult blob) {
final ImmutableSet.Builder<Triple> b = builder();
try {
b.add(create(resultSubject, RDF.type.asNode(), FIXITY_TYPE.asNode()));
b.add(create(graphSubjects.getGraphSubject(node)
.asNode(), HAS_FIXITY_RESULT.asNode(),
resultSubject));
b.add(create(graphSubjects.getGraphSubject(node.getPath()).asNode(),
HAS_FIXITY_RESULT.asNode(), resultSubject));
final String storeIdentifier = blob.getStoreIdentifier();
final com.hp.hpl.jena.graph.Node contentLocation = createResource(storeIdentifier)
.asNode();
Expand Down
Expand Up @@ -114,8 +114,7 @@ private Triple[] containerContext(final Node pageContext) {

private Iterator<Triple> parentContext() throws RepositoryException {
final javax.jcr.Node parentNode = node().getParent();
final Node parentNodeSubject =
graphSubjects().getGraphSubject(parentNode).asNode();
final Node parentNodeSubject = graphSubjects().getGraphSubject(parentNode.getPath()).asNode();
return new PropertiesRdfContext(parentNode, graphSubjects(), lowLevelStorageService())
.concat(new Triple[] {
create(subject(), HAS_PARENT.asNode(),
Expand Down Expand Up @@ -146,8 +145,7 @@ private Function<javax.jcr.Node, Iterator<Triple>> child2triples(
@Override
public Iterator<Triple> apply(final javax.jcr.Node child) {
try {
final Node childSubject =
graphSubjects().getGraphSubject(child).asNode();
final Node childSubject = graphSubjects().getGraphSubject(child.getPath()).asNode();
LOGGER.trace("Creating triples for child node: {}", child);
return new PropertiesRdfContext(child, graphSubjects(),
lowLevelStorageService()).concat(new Triple[] {
Expand Down
Expand Up @@ -64,7 +64,7 @@ public Dataset getProperties(final Node node, final GraphSubjects subjects,
final Dataset dataset = DatasetFactory.create(model);
dataset.addNamedModel(MODEL_NAME, model);

final Resource subject = subjects.getGraphSubject(node);
final Resource subject = subjects.getGraphSubject(node.getPath());
final String uri = subject.getURI();
final com.hp.hpl.jena.sparql.util.Context context = dataset.getContext();
context.set(URI_SYMBOL,uri);
Expand Down
Expand Up @@ -72,7 +72,7 @@ public NodeRdfContext(final Node node, final GraphSubjects graphSubjects,
super();
this.node = node;
this.graphSubjects = graphSubjects;
this.subject = graphSubjects.getGraphSubject(node).asNode();
this.subject = graphSubjects.getGraphSubject(node.getPath()).asNode();

// TODO fix GraphProperties to allow for LowLevelStorageServices to pass
// through it
Expand Down
Expand Up @@ -97,10 +97,8 @@ private void putPropertiesIntoContext() throws RepositoryException {
LOGGER.trace("Access denied to content node", e);
}
if (contentNode != null) {
final Node contentSubject =
graphSubjects().getGraphSubject(contentNode).asNode();
final Node subject =
graphSubjects().getGraphSubject(node()).asNode();
final Node contentSubject = graphSubjects().getGraphSubject(contentNode.getPath()).asNode();
final Node subject = graphSubjects().getGraphSubject(node().getPath()).asNode();
// add triples representing parent-to-content-child relationship
concat(new Triple[] {
create(subject, HAS_CONTENT.asNode(), contentSubject),
Expand Down
Expand Up @@ -72,7 +72,7 @@ public VersionsRdfContext(final Node node, final GraphSubjects graphSubjects,
super();
this.lowLevelStorageService = lowLevelStorageService;
this.graphSubjects = graphSubjects;
this.subject = graphSubjects.getGraphSubject(node).asNode();
this.subject = graphSubjects.getGraphSubject(node.getPath()).asNode();
versionManager = node.getSession().getWorkspace().getVersionManager();
versionHistory = versionManager.getVersionHistory(node.getPath());

Expand All @@ -93,7 +93,7 @@ public Iterator<Triple> apply(final Version version) {
try {
final Node frozenNode = version.getFrozenNode();
final com.hp.hpl.jena.graph.Node versionSubject =
graphSubjects.getGraphSubject(frozenNode).asNode();
graphSubjects.getGraphSubject(frozenNode.getPath()).asNode();

final RdfStream results =
new RdfStream(new PropertiesRdfContext(frozenNode,
Expand Down
Expand Up @@ -173,7 +173,7 @@ private Node traverseLink(final Property p, final Value v)

private Node getGraphSubject(final javax.jcr.Node n)
throws RepositoryException {
return graphSubjects.getGraphSubject(n).asNode();
return graphSubjects.getGraphSubject(n.getPath()).asNode();
}

}
Expand Up @@ -205,7 +205,7 @@ public RdfStream getFixityResultsModel(final GraphSubjects subjects,
return JcrRdfTools.withContext(subjects,
datastream.getNode().getSession()).getJcrTriples(
datastream.getNode(), blobs).topic(
subjects.getGraphSubject(datastream.getNode()).asNode());
subjects.getGraphSubject(datastream.getNode().getPath()).asNode());
}

/**
Expand Down
Expand Up @@ -219,7 +219,7 @@ public void testGetPropertiesDataset() throws Exception {

when(JcrRdfTools.withContext(mockSubjects, mockSession)).thenReturn(mockJcrRdfTools);

when(mockSubjects.getGraphSubject(mockNode)).thenReturn(mockResource);
when(mockSubjects.getGraphSubject(mockNode.getPath())).thenReturn(mockResource);

final RdfStream propertiesStream = new RdfStream(mockTriple);
when(mockJcrRdfTools.getJcrTriples(mockNode)).thenReturn(
Expand Down Expand Up @@ -247,7 +247,7 @@ public void testGetPropertiesDatasetDefaultLimits()
mockStatic(JcrRdfTools.class);
final GraphSubjects mockSubjects = mock(GraphSubjects.class);
when(JcrRdfTools.withContext(mockSubjects, mockSession)).thenReturn(mockJcrRdfTools);
when(mockSubjects.getGraphSubject(mockNode)).thenReturn(mockResource);
when(mockSubjects.getGraphSubject(mockNode.getPath())).thenReturn(mockResource);

final RdfStream propertiesStream = new RdfStream(mockTriple);
when(mockJcrRdfTools.getJcrTriples(mockNode)).thenReturn(propertiesStream);
Expand All @@ -271,7 +271,7 @@ public void testGetVersionDataset() throws Exception {
final GraphSubjects mockSubjects = mock(GraphSubjects.class);

when(JcrRdfTools.withContext(mockSubjects, mockSession)).thenReturn(mockJcrRdfTools);
when(mockSubjects.getGraphSubject(mockNode)).thenReturn(mockResource);
when(mockSubjects.getGraphSubject(mockNode.getPath())).thenReturn(mockResource);

final RdfStream versionsStream = new RdfStream();
when(mockJcrRdfTools.getVersionTriples(any(Node.class)))
Expand Down
Expand Up @@ -194,12 +194,9 @@ public void setUp() throws RepositoryException {
when(mockNode.getNodes()).thenReturn(mockNodes);
when(mockParentNode.hasProperties()).thenReturn(false);
when(mockNode.hasProperties()).thenReturn(false);
when(mockGraphSubjects.getGraphSubject(mockNode)).thenReturn(
testSubject);
when(mockGraphSubjects.getGraphSubject(mockParentNode)).thenReturn(
testParentSubject);
when(mockGraphSubjects.getGraphSubject(mockChildNode)).thenReturn(
testChildSubject);
when(mockGraphSubjects.getGraphSubject(mockNode.getPath())).thenReturn(testSubject);
when(mockGraphSubjects.getGraphSubject(mockParentNode.getPath())).thenReturn(testParentSubject);
when(mockGraphSubjects.getGraphSubject(mockChildNode.getPath())).thenReturn(testChildSubject);
when(mockNodeType.isNodeType("mode:system")).thenReturn(false);
when(mockNodeType.getSupertypes()).thenReturn(new NodeType[] {mockNodeType});
when(mockSession.getRepository()).thenReturn(mockRepository);
Expand Down Expand Up @@ -251,19 +248,21 @@ private void buildChildNodes() throws RepositoryException {
when(mockChildNode4.getParent()).thenReturn(mockNode);
when(mockChildNode5.getParent()).thenReturn(mockNode);

when(mockChildNode.getPath()).thenReturn(MOCK_CHILD_NODE_PATH);
when(mockChildNode.getPath()).thenReturn(MOCK_NODE_PATH + "/1");
when(mockChildNode2.getPath()).thenReturn(MOCK_NODE_PATH + "/2");
when(mockChildNode3.getPath()).thenReturn(MOCK_NODE_PATH + "3");
when(mockChildNode4.getPath()).thenReturn(MOCK_NODE_PATH + "4");
when(mockChildNode5.getPath()).thenReturn(MOCK_NODE_PATH + "5");
when(mockChildNode3.getPath()).thenReturn(MOCK_NODE_PATH + "/3");
when(mockChildNode4.getPath()).thenReturn(MOCK_NODE_PATH + "/4");
when(mockChildNode5.getPath()).thenReturn(MOCK_NODE_PATH + "/5");

when(mockGraphSubjects.getGraphSubject(mockChildNode2)).thenReturn(
when(mockGraphSubjects.getGraphSubject(mockChildNode.getPath())).thenReturn(
createResource(RESOURCE_PREFIX + "/1"));
when(mockGraphSubjects.getGraphSubject(mockChildNode2.getPath())).thenReturn(
createResource(RESOURCE_PREFIX + "/2"));
when(mockGraphSubjects.getGraphSubject(mockChildNode3)).thenReturn(
when(mockGraphSubjects.getGraphSubject(mockChildNode3.getPath())).thenReturn(
createResource(RESOURCE_PREFIX + "/3"));
when(mockGraphSubjects.getGraphSubject(mockChildNode4)).thenReturn(
when(mockGraphSubjects.getGraphSubject(mockChildNode4.getPath())).thenReturn(
createResource(RESOURCE_PREFIX + "/4"));
when(mockGraphSubjects.getGraphSubject(mockChildNode5)).thenReturn(
when(mockGraphSubjects.getGraphSubject(mockChildNode5.getPath())).thenReturn(
createResource(RESOURCE_PREFIX + "/5"));

when(mockChildNode.getSession()).thenReturn(mockSession);
Expand Down
Expand Up @@ -80,7 +80,7 @@ public void testGetPropertiesDataset() throws Exception {

final Resource mockResource =
new DummyURIResource(RESTAPI_NAMESPACE + "xyz");
when(mockSubjects.getGraphSubject(mockNode)).thenReturn(mockResource);
when(mockSubjects.getGraphSubject(mockNode.getPath())).thenReturn(mockResource);

final RdfStream propertiesStream = new RdfStream();
when(mockJcrRdfTools.getJcrTriples(mockNode)).thenReturn(
Expand Down Expand Up @@ -110,7 +110,7 @@ public void testGetPropertiesDefaultLimits()
when(JcrRdfTools.withContext(mockSubjects, mockNode.getSession())).thenReturn(mockJcrRdfTools);
final Resource mockResource =
new DummyURIResource(RESTAPI_NAMESPACE + "xyz");
when(mockSubjects.getGraphSubject(mockNode)).thenReturn(mockResource);
when(mockSubjects.getGraphSubject(mockNode.getPath())).thenReturn(mockResource);

final RdfStream propertiesStream = new RdfStream();
when(mockJcrRdfTools.getJcrTriples(mockNode)).thenReturn(
Expand Down Expand Up @@ -142,10 +142,8 @@ public void testGetPropertiesDatasetDefaults() throws Exception {
when(JcrRdfTools.withContext(mockSubjects, mockNode.getSession()))
.thenReturn(mockJcrRdfTools);

final Resource mockResource =
new DummyURIResource(RESTAPI_NAMESPACE + "xyz");
when(mockSubjects.getGraphSubject(mockNode)).thenReturn(
mockResource);
final Resource mockResource = new DummyURIResource(RESTAPI_NAMESPACE + "xyz");
when(mockSubjects.getGraphSubject(mockNode.getPath())).thenReturn(mockResource);

final RdfStream propertiesStream = new RdfStream();
when(mockJcrRdfTools.getJcrTriples(mockNode))
Expand Down
Expand Up @@ -122,8 +122,7 @@ public void setUp() throws RepositoryException {
when(mockSession.getWorkspace()).thenReturn(mockWorkspace);
when(mockWorkspace.getNamespaceRegistry()).thenReturn(mockNamespaceRegistry);
when(mockNamespaceRegistry.getURI("jcr")).thenReturn(JCR_NAMESPACE);
when(mockGraphSubjects.getGraphSubject(mockNode)).thenReturn(
mockNodeSubject);
when(mockGraphSubjects.getGraphSubject(mockNode.getPath())).thenReturn(mockNodeSubject);
}

@Test
Expand Down
Expand Up @@ -73,6 +73,7 @@ public void testForLowLevelStorageTriples() throws RepositoryException,
public void setUp() throws RepositoryException {
initMocks(this);
when(mockNode.getSession()).thenReturn(mockSession);
when(mockNode.getPath()).thenReturn("/mockNode");
when(mockContentNode.getSession()).thenReturn(mockSession);
when(mockSession.getRepository()).thenReturn(mockRepository);
when(mockSession.getWorkspace()).thenReturn(mockWorkspace);
Expand All @@ -90,10 +91,8 @@ public void setUp() throws RepositoryException {
ImmutableSet.of(mockLowLevelCacheEntry));
when(mockLowLevelCacheEntry.getExternalIdentifier()).thenReturn(
MOCK_EXTERNAL_IDENTIFIER);
when(mockGraphSubjects.getGraphSubject(mockNode)).thenReturn(
mockSubject);
when(mockGraphSubjects.getGraphSubject(mockContentNode)).thenReturn(
mockContentSubject);
when(mockGraphSubjects.getGraphSubject(mockNode.getPath())).thenReturn(mockSubject);
when(mockGraphSubjects.getGraphSubject(mockContentNode.getPath())).thenReturn(mockContentSubject);
when(mockNode.getPrimaryNodeType()).thenReturn(mockNodeType);
when(mockContentNode.getPrimaryNodeType()).thenReturn(mockNodeType);
when(mockNodeType.getSupertypes()).thenReturn(new NodeType[] {mockNodeType});
Expand Down
Expand Up @@ -361,8 +361,7 @@ public void setUp() throws ValueFormatException, RepositoryException {
when(mockProperty.getName()).thenReturn(TEST_PROPERTY_NAME);
when(mockProperty.getSession()).thenReturn(mockSession);
when(mockNode.getPath()).thenReturn(TEST_NODE_PATH);
when(mockGraphSubjects.getGraphSubject(mockNode)).thenReturn(
TEST_NODE_SUBJECT);
when(mockGraphSubjects.getGraphSubject(mockNode.getPath())).thenReturn(TEST_NODE_SUBJECT);
when(mockNode.getNode(TEST_NODE_PATH)).thenReturn(mockNode);
}

Expand Down
Expand Up @@ -213,7 +213,7 @@ public void testGetFixityResultsModel() throws Exception {
.<Iterable<FixityResult>> any())).thenReturn(
new RdfStream());

when(mockSubjects.getGraphSubject(mockNode)).thenReturn(
when(mockSubjects.getGraphSubject(mockNode.getPath())).thenReturn(
createResource("abc"));
final RdfStream fixityResults =
testObj.getFixityResultsModel(mockSubjects, mockDatastream);
Expand Down
Expand Up @@ -44,7 +44,7 @@ public void tearDown() throws Exception {
clearProps();
}

private void clearProps() {
private static void clearProps() {
System.clearProperty(PROP_FLAG);
System.clearProperty(PROP_TEST);
System.clearProperty(HOME_PROP);
Expand Down Expand Up @@ -81,7 +81,7 @@ public void testCustomHomeDirWithRelativeSubdirs() {

loader.loadSystemProperties();

File home = new File(asTempPath("test"));
final File home = new File(asTempPath("test"));
Assert.assertTrue("Relative subdirs are within fcrepo.home directory.",
containsPath(System.getProperty(PROP_TEST),
home.getAbsolutePath()));
Expand All @@ -95,7 +95,7 @@ public void testCustomHomeDirWithAbsoluteSubdirs() {

loader.loadSystemProperties();

File home = new File(asTempPath("test"));
final File home = new File(asTempPath("test"));
Assert.assertFalse("Absolute subdirs are idependent of fcrepo.home.",
containsPath(System.getProperty(PROP_TEST),
home.getAbsolutePath()));
Expand All @@ -114,7 +114,7 @@ public void relativePathsWorkForFedoraHome() {
clearProps();
}

private boolean containsPath(String path, String parentPath) {
private static boolean containsPath(final String path, final String parentPath) {
final File parent = new File(parentPath);
for (File f = new File(path) ; f.getParentFile() != null ; f = f.getParentFile()) {
if (f.getParentFile().equals(parent)) {
Expand All @@ -124,7 +124,7 @@ private boolean containsPath(String path, String parentPath) {
return false;
}

private String asTempPath(final String file) {
private static String asTempPath(final String file) {
return System.getProperty("java.io.tmpdir") + System.getProperty("file.separator") + file;
}
}

0 comments on commit f0ae47c

Please sign in to comment.