Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Remove NodeService#findOrCreateObject
  • Loading branch information
cbeer committed Sep 20, 2014
1 parent b9f244b commit ad89147
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 47 deletions.
Expand Up @@ -233,13 +233,7 @@ public Response batchModify(@PathParam("path") final List<PathSegment> pathList,
final HttpIdentifierTranslator subjects =
new HttpIdentifierTranslator(session, FedoraNodes.class, uriInfo);

final FedoraResource resource;

if (nodeService.exists(session, objPath)) {
resource = nodeService.findOrCreateObject(session, objPath);
} else {
resource = objectService.findOrCreateObject(session, objPath);
}
final FedoraResource resource = objectService.findOrCreateObject(session, objPath);

if (contentTypeString.equals(contentTypeSPARQLUpdate)) {
resource.updatePropertiesDataset(subjects, IOUtils.toString(src));
Expand Down
Expand Up @@ -63,10 +63,11 @@
import org.apache.commons.io.IOUtils;
import org.fcrepo.kernel.Datastream;
import org.fcrepo.kernel.FedoraBinary;
import org.fcrepo.kernel.impl.FedoraResourceImpl;
import org.fcrepo.kernel.FedoraObject;
import org.fcrepo.kernel.rdf.IdentifierTranslator;
import org.fcrepo.kernel.services.DatastreamService;
import org.fcrepo.kernel.services.NodeService;
import org.fcrepo.kernel.services.ObjectService;
import org.fcrepo.kernel.services.VersionService;

import org.fcrepo.kernel.services.policy.StoragePolicyDecisionPoint;
Expand Down Expand Up @@ -99,14 +100,17 @@ public class FedoraBatchTest {
@Mock
private VersionService mockVersions;

@Mock
private ObjectService mockObjects;

@Mock
private Node mockDsNode;

@Mock
private NodeType mockDsNodeType;

@Mock
private FedoraResourceImpl mockObject;
private FedoraObject mockObject;

@Mock
private NodeIterator mockIterator;
Expand All @@ -126,6 +130,7 @@ public class FedoraBatchTest {
public void setUp() throws Exception {
initMocks(this);
testObj = new FedoraBatch();
setField(testObj, "objectService", mockObjects);
setField(testObj, "datastreamService", mockDatastreams);
setField(testObj, "nodeService", mockNodes);
setField(testObj, "uriInfo", getUriInfoImpl());
Expand All @@ -147,8 +152,7 @@ public void testBatchSparqlUpdate() throws Exception {
final String pid = "FedoraDatastreamsTest1";

when(mockNode.getPath()).thenReturn("/FedoraDatastreamsTest1");
when(mockNodes.exists(mockSession, "/{}FedoraDatastreamsTest1")).thenReturn(true);
when(mockNodes.findOrCreateObject(mockSession, "/{}FedoraDatastreamsTest1")).thenReturn(mockObject);
when(mockObjects.findOrCreateObject(mockSession, "/{}FedoraDatastreamsTest1")).thenReturn(mockObject);
when(mockSession.getNode("/FedoraDatastreamsTest1")).thenReturn(
mockNode);

Expand Down Expand Up @@ -180,8 +184,7 @@ public void testBatchRdfPost() throws Exception {

final String path = "/FedoraDatastreamsTest1";
when(mockNode.getPath()).thenReturn(path);
when(mockNodes.exists(mockSession, "/{}FedoraDatastreamsTest1")).thenReturn(true);
when(mockNodes.findOrCreateObject(mockSession, "/{}FedoraDatastreamsTest1")).thenReturn(mockObject);
when(mockObjects.findOrCreateObject(mockSession, "/{}FedoraDatastreamsTest1")).thenReturn(mockObject);
when(mockObject.getNode()).thenReturn(mockNode);
when(mockObject.getPath()).thenReturn(path);
when(mockSession.getNode(path)).thenReturn(mockNode);
Expand Down
Expand Up @@ -52,23 +52,6 @@ public class NodeServiceImpl extends AbstractService implements NodeService {

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

/**
* Find or create a new Fedora resource at the given path
*
* @param session a JCR session
* @param path a JCR path
* @return FedoraResource
* @throws RepositoryException
*/
@Override
public FedoraResource findOrCreateObject(final Session session, final String path) {
try {
return new FedoraResourceImpl(findOrCreateNode(session, path));
} catch (final RepositoryException e) {
throw new RepositoryRuntimeException(e);
}
}

/**
* Retrieve an existing Fedora resource at the given path
*
Expand Down
Expand Up @@ -137,13 +137,13 @@ private Node createGraphSubjectNode(final String absPath) {
@Test
public void testRandomNodeGraph() throws RepositoryException {
final FedoraResource object =
nodeService.findOrCreateObject(session, "/testNodeGraph");
objectService.findOrCreateObject(session, "/testNodeGraph");

logger.debug(object.getPropertiesDataset(
new DefaultIdentifierTranslator()).toString());
final Node s = createGraphSubjectNode("/testNodeGraph");
final Node p = createURI(REPOSITORY_NAMESPACE + "primaryType");
final Node o = createLiteral("nt:unstructured");
final Node o = createLiteral("nt:folder");
assertTrue(object.getPropertiesDataset(subjects).asDatasetGraph()
.contains(ANY, s, p, o));
}
Expand Down
Expand Up @@ -54,7 +54,7 @@ public class NodeServiceImplIT extends AbstractIT {
public void testDeleteObject() throws RepositoryException {
final Session session = repository.login();
final String pid = getRandomPid();
nodeService.findOrCreateObject(session, "/" + pid);
objectService.findOrCreateObject(session, "/" + pid);
session.save();

nodeService.deleteObject(session, "/" + pid);
Expand Down
Expand Up @@ -66,7 +66,7 @@ public class VersionServiceImplIT extends AbstractIT {
public void testCreateVersion() throws RepositoryException {
final Session session = repository.login();
final String pid = getRandomPid();
final FedoraResource resource = nodeService.findOrCreateObject(session, "/" + pid);
final FedoraResource resource = objectService.findOrCreateObject(session, "/" + pid);
session.save();

// create a version and make sure there are 2 versions (root + created)
Expand All @@ -79,7 +79,7 @@ public void testCreateVersion() throws RepositoryException {
public void testRemoveVersion() throws RepositoryException {
final Session session = repository.login();
final String pid = getRandomPid();
final FedoraResource resource = nodeService.findOrCreateObject(session, "/" + pid);
final FedoraResource resource = objectService.findOrCreateObject(session, "/" + pid);
session.save();

// create a version and make sure there are 2 versions (root + created)
Expand All @@ -102,7 +102,7 @@ public void testRemoveVersion() throws RepositoryException {
public void testRevertToVersion() throws RepositoryException {
final Session session = repository.login();
final String pid = getRandomPid();
final FedoraResource resource = nodeService.findOrCreateObject(session, "/" + pid);
final FedoraResource resource = objectService.findOrCreateObject(session, "/" + pid);
session.save();

// create a version and make sure there are 2 versions (root + created)
Expand All @@ -125,7 +125,7 @@ public void testRevertToVersion() throws RepositoryException {
public void testRevertToInvalidVersion() throws RepositoryException {
final Session session = repository.login();
final String pid = getRandomPid();
final FedoraResource resource = nodeService.findOrCreateObject(session, "/" + pid);
final FedoraResource resource = objectService.findOrCreateObject(session, "/" + pid);
session.save();

// create a version and make sure there are 2 versions (root + created)
Expand All @@ -142,7 +142,7 @@ public void testRevertToInvalidVersion() throws RepositoryException {
public void testRemoveInvalidVersion() throws RepositoryException {
final Session session = repository.login();
final String pid = getRandomPid();
final FedoraResource resource = nodeService.findOrCreateObject(session, "/" + pid);
final FedoraResource resource = objectService.findOrCreateObject(session, "/" + pid);
session.save();

// create a version and make sure there are 2 versions (root + created)
Expand Down
Expand Up @@ -30,15 +30,6 @@
*/
public interface NodeService extends Service {

/**
* Find or create a new Fedora resource at the given path
*
* @param session
* @param path
* @return FedoraResource for the given path
*/
FedoraResource findOrCreateObject(Session session, String path);

/**
* Retrieve an existing Fedora resource at the given path
*
Expand Down

0 comments on commit ad89147

Please sign in to comment.