Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Rename GraphSubjects to idConverter
  • Loading branch information
cbeer committed Oct 21, 2014
1 parent f0e5de4 commit df6cb6a
Show file tree
Hide file tree
Showing 49 changed files with 272 additions and 272 deletions.
Expand Up @@ -41,17 +41,17 @@ abstract public class FedoraBaseResource extends AbstractResource {

private static final Logger LOGGER = getLogger(FedoraBaseResource.class);

protected IdentifierConverter<Resource, FedoraResource> identifierTranslator;
protected IdentifierConverter<Resource, FedoraResource> idTranslator;

protected abstract Session session();

protected IdentifierConverter<Resource, FedoraResource> translator() {
if (identifierTranslator == null) {
identifierTranslator = new HttpResourceConverter(session(),
if (idTranslator == null) {
idTranslator = new HttpResourceConverter(session(),
uriInfo.getBaseUriBuilder().clone().path(FedoraLdp.class));
}

return identifierTranslator;
return idTranslator;
}

/**
Expand Down
Expand Up @@ -65,12 +65,12 @@ public class HttpApiResources implements UriAwareResourceModelFactory {

@Override
public Model createModelForResource(final FedoraResource resource,
final UriInfo uriInfo, final IdentifierConverter<Resource,FedoraResource> graphSubjects) {
final UriInfo uriInfo, final IdentifierConverter<Resource,FedoraResource> idTranslator) {

final Model model = createDefaultModel();
try {

final Resource s = graphSubjects.reverse().convert(resource);
final Resource s = idTranslator.reverse().convert(resource);

if (resource.getNode().getPrimaryNodeType().isNodeType(ROOT)) {
addRepositoryStatements(uriInfo, model, s);
Expand Down
Expand Up @@ -114,7 +114,7 @@ public class FedoraLdpTest {
@Mock
private FedoraBinary mockBinary;

private IdentifierConverter<Resource, FedoraResource> identifierConverter;
private IdentifierConverter<Resource, FedoraResource> idTranslator;

@Mock
private NodeService mockNodeService;
Expand All @@ -138,13 +138,13 @@ public void setUp() throws Exception {
mockSession = mockSession(testObj);
setField(testObj, "session", mockSession);

identifierConverter = new HttpResourceConverter(mockSession,
idTranslator = new HttpResourceConverter(mockSession,
UriBuilder.fromUri("http://localhost/fcrepo/{path: .*}"));

setField(testObj, "request", mockRequest);
setField(testObj, "servletResponse", mockResponse);
setField(testObj, "uriInfo", getUriInfoImpl());
setField(testObj, "identifierTranslator", identifierConverter);
setField(testObj, "idTranslator", idTranslator);
setField(testObj, "nodeService", mockNodeService);
setField(testObj, "objectService", mockObjectService);
setField(testObj, "binaryService", mockBinaryService);
Expand Down Expand Up @@ -172,7 +172,7 @@ private FedoraResource setResource(final Class<? extends FedoraResource> klass)
when(mockResource.getPath()).thenReturn(path);
when(mockNode.getPath()).thenReturn(path);
when(mockResource.getEtagValue()).thenReturn("");
when(mockResource.getTriples(eq(identifierConverter), any(Class.class))).thenAnswer(new Answer<RdfStream>() {
when(mockResource.getTriples(eq(idTranslator), any(Class.class))).thenAnswer(new Answer<RdfStream>() {
@Override
public RdfStream answer(final InvocationOnMock invocationOnMock) throws Throwable {
return new RdfStream(Triple.create(createURI(invocationOnMock.getMock().toString()),
Expand Down Expand Up @@ -219,7 +219,7 @@ public void testHeadWithBinary() throws Exception {
assertFalse("Should not advertise Accept-Patch flavors", mockResponse.containsHeader("Accept-Patch"));
assertTrue("Should contain a link to the binary description",
mockResponse.getHeaders("Link")
.contains("<" + identifierConverter.toDomain(binaryDescriptionPath + "/fcr:metadata")
.contains("<" + idTranslator.toDomain(binaryDescriptionPath + "/fcr:metadata")
+ ">;rel=\"describedby\""));
}

Expand All @@ -235,7 +235,7 @@ public void testHeadWithBinaryDescription() throws Exception {
assertTrue("Should advertise Accept-Patch flavors", mockResponse.containsHeader("Accept-Patch"));
assertTrue("Should contain a link to the binary",
mockResponse.getHeaders("Link")
.contains("<" + identifierConverter.toDomain(binaryPath) + ">;rel=\"describes\""));
.contains("<" + idTranslator.toDomain(binaryPath) + ">;rel=\"describes\""));
}

@Test
Expand Down Expand Up @@ -265,7 +265,7 @@ public void testOptionWithBinary() throws Exception {
assertFalse("Should not advertise Accept-Patch flavors", mockResponse.containsHeader("Accept-Patch"));
assertTrue("Should contain a link to the binary description",
mockResponse.getHeaders("Link")
.contains("<" + identifierConverter.toDomain(binaryDescriptionPath + "/fcr:metadata")
.contains("<" + idTranslator.toDomain(binaryDescriptionPath + "/fcr:metadata")
+ ">;rel=\"describedby\""));
}

Expand All @@ -279,7 +279,7 @@ public void testOptionWithBinaryDescription() throws Exception {
assertTrue("Should advertise Accept-Patch flavors", mockResponse.containsHeader("Accept-Patch"));
assertTrue("Should contain a link to the binary",
mockResponse.getHeaders("Link")
.contains("<" + identifierConverter.toDomain(binaryPath) + ">;rel=\"describes\""));
.contains("<" + idTranslator.toDomain(binaryPath) + ">;rel=\"describes\""));
}


Expand Down Expand Up @@ -468,7 +468,7 @@ public void testGetWithBinary() throws Exception {
assertFalse("Should not advertise Accept-Patch flavors", mockResponse.containsHeader("Accept-Patch"));
assertTrue("Should contain a link to the binary description",
mockResponse.getHeaders("Link")
.contains("<" + identifierConverter.toDomain(binaryDescriptionPath + "/fcr:metadata")
.contains("<" + idTranslator.toDomain(binaryDescriptionPath + "/fcr:metadata")
+ ">;rel=\"describedby\""));
assertTrue(IOUtils.toString((InputStream)actual.getEntity()).equals("xyz"));
}
Expand All @@ -477,7 +477,7 @@ public void testGetWithBinary() throws Exception {
public void testGetWithBinaryDescription() throws Exception {
final Datastream mockResource = (Datastream)setResource(Datastream.class);
when(mockResource.getBinary()).thenReturn(mockBinary);
when(mockBinary.getTriples(identifierConverter, PropertiesRdfContext.class)).thenReturn(
when(mockBinary.getTriples(idTranslator, PropertiesRdfContext.class)).thenReturn(
new RdfStream(new Triple(createURI("mockBinary"), createURI("called"), createURI("child:properties"))));
final Response actual = testObj.describe(null);
assertEquals(OK.getStatusCode(), actual.getStatus());
Expand All @@ -487,7 +487,7 @@ public void testGetWithBinaryDescription() throws Exception {
assertTrue("Should advertise Accept-Patch flavors", mockResponse.containsHeader("Accept-Patch"));
assertTrue("Should contain a link to the binary",
mockResponse.getHeaders("Link")
.contains("<" + identifierConverter.toDomain(binaryPath) + ">;rel=\"describes\""));
.contains("<" + idTranslator.toDomain(binaryPath) + ">;rel=\"describes\""));

final RdfStream entity = (RdfStream) actual.getEntity();
final Model model = entity.asModel();
Expand Down Expand Up @@ -547,7 +547,7 @@ public void testPutNewObjectWithRdf() throws Exception {
toInputStream("_:a <info:x> _:c ."), null, null, null);

assertEquals(CREATED.getStatusCode(), actual.getStatus());
verify(mockObject).replaceProperties(eq(identifierConverter), any(Model.class), any(RdfStream.class));
verify(mockObject).replaceProperties(eq(idTranslator), any(Model.class), any(RdfStream.class));
}

@Test
Expand Down Expand Up @@ -579,7 +579,7 @@ public void testPutReplaceRdfObject() throws Exception {
toInputStream("_:a <info:x> _:c ."), null, null, null);

assertEquals(NO_CONTENT.getStatusCode(), actual.getStatus());
verify(mockObject).replaceProperties(eq(identifierConverter), any(Model.class), any(RdfStream.class));
verify(mockObject).replaceProperties(eq(idTranslator), any(Model.class), any(RdfStream.class));
}

@Test(expected = ClientErrorException.class)
Expand Down Expand Up @@ -612,7 +612,7 @@ public void testPatchBinaryDescription() throws Exception {
final Datastream mockObject = (Datastream)setResource(Datastream.class);
when(mockObject.getBinary()).thenReturn(mockBinary);

when(mockBinary.getTriples(identifierConverter, PropertiesRdfContext.class)).thenReturn(
when(mockBinary.getTriples(idTranslator, PropertiesRdfContext.class)).thenReturn(
new RdfStream(new Triple(createURI("mockBinary"), createURI("called"), createURI("child:properties"))));

doReturn(mockObject).when(testObj).resource();
Expand Down Expand Up @@ -662,7 +662,7 @@ public void testCreateNewObjectWithSparql() throws Exception {
MediaType.valueOf(contentTypeSPARQLUpdate), "b", toInputStream("x"));

assertEquals(CREATED.getStatusCode(), actual.getStatus());
verify(mockObject).updateProperties(eq(identifierConverter), eq("x"), any(RdfStream.class));
verify(mockObject).updateProperties(eq(idTranslator), eq("x"), any(RdfStream.class));
}

@Test
Expand All @@ -676,7 +676,7 @@ public void testCreateNewObjectWithRdf() throws Exception {
toInputStream("_:a <info:b> _:c ."));

assertEquals(CREATED.getStatusCode(), actual.getStatus());
verify(mockObject).replaceProperties(eq(identifierConverter), any(Model.class), any(RdfStream.class));
verify(mockObject).replaceProperties(eq(idTranslator), any(Model.class), any(RdfStream.class));
}


Expand Down
Expand Up @@ -153,7 +153,7 @@ public void setUp() throws Exception {
when(mockNode.getPrimaryNodeType()).thenReturn(mockNodeType);
when(mockSession.getNode(path)).thenReturn(mockNode);

setField(testObj, "identifierTranslator",
setField(testObj, "idTranslator",
new HttpResourceConverter(mockSession, UriBuilder.fromUri("http://localhost/fcrepo/{path: .*}")));
}

Expand Down
Expand Up @@ -104,7 +104,7 @@ public void setUp() throws Exception {
when(mockSession.getNode(path)).thenReturn(mockNode);
doReturn(mockResource).when(testObj).resource();

setField(testObj, "identifierTranslator",
setField(testObj, "idTranslator",
new HttpResourceConverter(mockSession, UriBuilder.fromUri("http://localhost/fcrepo/{path: .*}")));
}

Expand Down
Expand Up @@ -93,7 +93,7 @@ public void setUp() throws Exception {
when(mockNodeType.getName()).thenReturn("nt:folder");
when(mockNode.getPrimaryNodeType()).thenReturn(mockNodeType);

setField(testObj, "identifierTranslator",
setField(testObj, "idTranslator",
new HttpResourceConverter(mockSession, UriBuilder.fromUri("http://localhost/fcrepo/{path: .*}")));
}

Expand Down
Expand Up @@ -103,16 +103,16 @@ public abstract class AbstractResource {
/**
* Convert a JAX-RS list of PathSegments to a JCR path
*
* @param translator
* @param idTranslator
* @param originalPath
* @return String jcr path
*/
public static final String toPath(final IdentifierConverter<Resource, FedoraResource> translator,
public static final String toPath(final IdentifierConverter<Resource, FedoraResource> idTranslator,
final String originalPath) {

final Resource resource = translator.toDomain(originalPath);
final Resource resource = idTranslator.toDomain(originalPath);

final String path = translator.asString(resource);
final String path = idTranslator.asString(resource);

if (path.isEmpty()) {
return "/";
Expand Down
Expand Up @@ -55,11 +55,11 @@ public void setApplicationContext(final ApplicationContext applicationContext) {
* @param rdfStream the source stream we'll add named models to
* @param resource the FedoraResourceImpl in question
* @param uriInfo a JAX-RS UriInfo object to build URIs to resources
* @param graphSubjects
* @param idTranslator
*/
public void addHttpComponentModelsForResourceToStream(final RdfStream rdfStream,
final FedoraResource resource, final UriInfo uriInfo,
final IdentifierConverter<Resource,FedoraResource> graphSubjects) {
final IdentifierConverter<Resource,FedoraResource> idTranslator) {

LOGGER.debug("Adding additional HTTP context triples to stream");
for (final Map.Entry<String, UriAwareResourceModelFactory> e : getUriAwareTripleFactories()
Expand All @@ -71,7 +71,7 @@ public void addHttpComponentModelsForResourceToStream(final RdfStream rdfStream,

final Model m =
uriAwareResourceModelFactory.createModelForResource(
resource, uriInfo, graphSubjects);
resource, uriInfo, idTranslator);
rdfStream.concat(RdfStream.fromModel(m));
}

Expand Down
Expand Up @@ -38,9 +38,9 @@ public interface UriAwareResourceModelFactory {
*
* @param resource
* @param uriInfo
* @param graphSubjects
* @param idTranslator
* @return model containing triples for the given resource
*/
Model createModelForResource(final FedoraResource resource,
final UriInfo uriInfo, final IdentifierConverter<Resource,FedoraResource> graphSubjects);
final UriInfo uriInfo, final IdentifierConverter<Resource,FedoraResource> idTranslator);
}
Expand Up @@ -276,12 +276,12 @@ public String getFilename() {
}

@Override
public RdfStream getFixity(final IdentifierConverter<Resource, FedoraResource> graphSubjects) {
return getFixity(graphSubjects, getContentDigest(), getContentSize());
public RdfStream getFixity(final IdentifierConverter<Resource, FedoraResource> idTranslator) {
return getFixity(idTranslator, getContentDigest(), getContentSize());
}

@Override
public RdfStream getFixity(final IdentifierConverter<Resource, FedoraResource> graphSubjects,
public RdfStream getFixity(final IdentifierConverter<Resource, FedoraResource> idTranslator,
final URI digestUri,
final long size) {

Expand All @@ -299,7 +299,7 @@ public RdfStream getFixity(final IdentifierConverter<Resource, FedoraResource> g
final Collection<FixityResult> fixityResults
= CacheEntryFactory.forProperty(repo, getNode().getProperty(JCR_DATA)).checkFixity(algorithm);

return new FixityRdfContext(this, graphSubjects, fixityResults, digestUri, size);
return new FixityRdfContext(this, idTranslator, fixityResults, digestUri, size);
} catch (final RepositoryException e) {
throw new RepositoryRuntimeException(e);
} finally {
Expand Down
Expand Up @@ -355,31 +355,31 @@ public boolean hasType(final String type) {
* (org.fcrepo.kernel.identifiers.IdentifierConverter, java.lang.String, RdfStream)
*/
@Override
public void updateProperties(final IdentifierConverter<Resource, FedoraResource> subjects,
public void updateProperties(final IdentifierConverter<Resource, FedoraResource> idTranslator,
final String sparqlUpdateStatement, final RdfStream originalTriples) {

final Model model = originalTriples.asModel();

final JcrPropertyStatementListener listener =
new JcrPropertyStatementListener(subjects, getSession());
new JcrPropertyStatementListener(idTranslator, getSession());

model.register(listener);

final UpdateRequest request = create(sparqlUpdateStatement, subjects.reverse().convert(this).toString());
final UpdateRequest request = create(sparqlUpdateStatement, idTranslator.reverse().convert(this).toString());
model.setNsPrefixes(request.getPrefixMapping());
execute(request, model);

listener.assertNoExceptions();
}

@Override
public RdfStream getTriples(final IdentifierConverter<Resource, FedoraResource> graphSubjects,
public RdfStream getTriples(final IdentifierConverter<Resource, FedoraResource> idTranslator,
final Class<? extends RdfStream> context) {
return getTriples(graphSubjects, Collections.singleton(context));
return getTriples(idTranslator, Collections.singleton(context));
}

@Override
public RdfStream getTriples(final IdentifierConverter<Resource, FedoraResource> graphSubjects,
public RdfStream getTriples(final IdentifierConverter<Resource, FedoraResource> idTranslator,
final Iterable<? extends Class<? extends RdfStream>> contexts) {
final RdfStream stream = new RdfStream();

Expand All @@ -388,7 +388,7 @@ public RdfStream getTriples(final IdentifierConverter<Resource, FedoraResource>
final Constructor<? extends RdfStream> declaredConstructor
= context.getDeclaredConstructor(FedoraResource.class, IdentifierConverter.class);

final RdfStream rdfStream = declaredConstructor.newInstance(this, graphSubjects);
final RdfStream rdfStream = declaredConstructor.newInstance(this, idTranslator);

stream.concat(rdfStream);
} catch (final NoSuchMethodException |
Expand Down Expand Up @@ -460,7 +460,7 @@ public Boolean isNew() {
* (org.fcrepo.kernel.identifiers.IdentifierConverter, com.hp.hpl.jena.rdf.model.Model)
*/
@Override
public void replaceProperties(final IdentifierConverter<Resource, FedoraResource> graphSubjects,
public void replaceProperties(final IdentifierConverter<Resource, FedoraResource> idTranslator,
final Model inputModel, final RdfStream originalTriples) {

final RdfStream replacementStream = new RdfStream().namespaces(inputModel.getNsPrefixMap());
Expand All @@ -469,10 +469,10 @@ public void replaceProperties(final IdentifierConverter<Resource, FedoraResource
new GraphDifferencingIterator(inputModel, originalTriples);

try {
new RdfRemover(graphSubjects, getSession(), replacementStream
new RdfRemover(idTranslator, getSession(), replacementStream
.withThisContext(differencer)).consume();

new RdfAdder(graphSubjects, getSession(), replacementStream
new RdfAdder(idTranslator, getSession(), replacementStream
.withThisContext(differencer.notCommon())).consume();
} catch (final RepositoryException e) {
throw new RepositoryRuntimeException(e);
Expand Down

0 comments on commit df6cb6a

Please sign in to comment.