Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #490 from fcrepo4/kill-noncontroversial-methods
Kill noncontroversial methods
  • Loading branch information
Andrew Woods committed Sep 25, 2014
2 parents 46c1cb1 + e2066c2 commit 3e2e867
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 318 deletions.
Expand Up @@ -19,7 +19,6 @@
import static java.util.concurrent.TimeUnit.SECONDS;
import static javax.ws.rs.core.Response.Status.CREATED;
import static org.apache.http.impl.client.HttpClientBuilder.create;
import static org.fcrepo.jcr.FedoraJcrTypes.FEDORA_DATASTREAM;
import static org.junit.Assert.assertEquals;
import static org.slf4j.LoggerFactory.getLogger;

Expand Down Expand Up @@ -89,9 +88,25 @@ protected static HttpPost postDSMethod(final String pid, final String ds,
return post;
}

protected static HttpPut putDSMethod(final String pid, final String ds) {
return new HttpPut(serverAddress + pid + "/" + ds +
"?mixin=" + FEDORA_DATASTREAM);
protected HttpResponse createDatastream(final String pid, final String dsid, final String content)
throws IOException {
logger.trace(
"Attempting to create datastream for object: {} at datastream ID: {}",
pid, dsid);
final HttpResponse response =
client.execute(putDSMethod(pid, dsid, content));
assertEquals(CREATED.getStatusCode(), response.getStatusLine().getStatusCode());
return response;
}

protected static HttpPut putDSMethod(final String pid, final String ds,
final String content) throws UnsupportedEncodingException {
final HttpPut put =
new HttpPut(serverAddress + pid + "/" + ds +
"/fcr:content");

put.setEntity(new StringEntity(content));
return put;
}

protected int getStatus(final HttpUriRequest method)
Expand Down
Expand Up @@ -75,17 +75,11 @@ public void testWellKnownPathOaiDc() throws Exception {
final String pid = randomUUID().toString();

createObject(pid);

HttpResponse response = client.execute(postDSMethod(pid, "DC", "marbles for everyone"));
final int status = response.getStatusLine().getStatusCode();
if (status != 201) {
log.error(EntityUtils.toString(response.getEntity()));
}
assertEquals(201, status);
createDatastream(pid, "DC", "marbles for everyone");

final HttpGet getWorstCaseOaiMethod = new HttpGet(serverOAIAddress + pid + "/oai:dc");
getWorstCaseOaiMethod.setHeader("Accept", TEXT_XML);
response = client.execute(getWorstCaseOaiMethod);
final HttpResponse response = client.execute(getWorstCaseOaiMethod);
assertEquals(200, response.getStatusLine().getStatusCode());
final String content = EntityUtils.toString(response.getEntity());
assertTrue("Didn't find our datastream!", compile("marbles for everyone", DOTALL).matcher(content).find());
Expand Down
29 changes: 0 additions & 29 deletions fcrepo-http-api/src/main/java/org/fcrepo/http/api/FedoraBatch.java
Expand Up @@ -19,7 +19,6 @@
import static java.nio.charset.StandardCharsets.UTF_8;
import static javax.ws.rs.core.MediaType.MULTIPART_FORM_DATA;
import static javax.ws.rs.core.Response.created;
import static javax.ws.rs.core.Response.noContent;
import static javax.ws.rs.core.Response.notAcceptable;
import static javax.ws.rs.core.Response.ok;
import static javax.ws.rs.core.Response.status;
Expand All @@ -45,7 +44,6 @@
import javax.jcr.NodeIterator;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
Expand Down Expand Up @@ -308,33 +306,6 @@ public Response batchModify(@PathParam("path") final List<PathSegment> pathList,
}
}

/**
* Delete multiple child objects given by the child query parameter
*
* @param pathList
* @param childList
* @return response
* @throws RepositoryException
*/
@DELETE
@Timed
public Response batchDelete(@PathParam("path") final List<PathSegment> pathList,
@QueryParam("child") final List<String> childList) throws RepositoryException {
try {
final String path = toPath(pathList);
for (final String dsid : childList) {
final String dsPath = path + "/" + dsid;
LOGGER.debug("purging node {}", dsPath);
nodeService.getObject(session, dsPath).delete();
}
session.save();
versionService.nodeUpdated(session, path);
return noContent().build();
} finally {
session.logout();
}
}

/**
* Retrieve multiple datastream bitstreams in a single request as a
* multipart/mixed response.
Expand Down
Expand Up @@ -18,7 +18,6 @@
import static javax.ws.rs.core.Response.created;
import static javax.ws.rs.core.Response.noContent;
import static javax.ws.rs.core.Response.status;
import static org.apache.http.HttpStatus.SC_CONFLICT;
import static org.apache.http.HttpStatus.SC_MOVED_TEMPORARILY;
import static org.slf4j.LoggerFactory.getLogger;

Expand All @@ -34,7 +33,6 @@
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
Expand Down Expand Up @@ -79,95 +77,6 @@ public class FedoraContent extends ContentExposingResource {

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

/**
* Create an anonymous DS with a newly minted name and content from request
* body
*
* @param pathList
* @throws RepositoryException
*/
@POST
@Timed
public Response create(@PathParam("path") final List<PathSegment> pathList,
@HeaderParam("Slug") final String slug,
@HeaderParam("Content-Disposition") final String contentDisposition,
@QueryParam("checksum") final String checksum,
@HeaderParam("Content-Type") final MediaType requestContentType,
@ContentLocation final InputStream requestBodyStream)
throws InvalidChecksumException, ParseException {
final MediaType contentType = getSimpleContentType(requestContentType);


final String newDatastreamPath;
final String path = toPath(pathList);

if (nodeService.exists(session, path)) {
if ( nodeService.getObject(session, path).hasContent() ) {
return status(SC_CONFLICT)
.entity(path + " is an existing resource!").build();
}

final String pid;

if (slug != null) {
pid = slug;
} else {
pid = pidMinter.mintPid();
}

newDatastreamPath = path + "/" + pid;
} else {
newDatastreamPath = path;
}


LOGGER.trace("Attempting to ingest fcr:content with path: {}", newDatastreamPath);

try {

if (nodeService.exists(session, newDatastreamPath)) {
return status(SC_CONFLICT)
.entity(path + " is an existing resource!").build();
}

final URI checksumURI = checksumURI(checksum);
final String originalFileName = originalFileName(contentDisposition);


final Datastream datastream = datastreamService.findOrCreateDatastream(session, newDatastreamPath);

final FedoraBinary binary = datastream.getBinary();

binary.setContent(requestBodyStream,
contentType.toString(),
checksumURI,
originalFileName,
datastreamService.getStoragePolicyDecisionPoint());


final HttpIdentifierTranslator subjects =
new HttpIdentifierTranslator(session, FedoraNodes.class,
uriInfo);
final ResponseBuilder builder;
try {
session.save();
versionService.nodeUpdated(datastream.getNode());

builder = created(URI.create(subjects.getSubject(
binary.getPath()).getURI()));
} catch (final RepositoryException e) {
throw new RepositoryRuntimeException(e);
}

addCacheControlHeaders(servletResponse, binary, session);

return builder.build();

} finally {
session.logout();
}
}

/**
* Modify an existing datastream's content
*
Expand Down
Expand Up @@ -19,7 +19,6 @@
import static javax.ws.rs.core.Response.notModified;
import static javax.ws.rs.core.Response.Status.CREATED;
import static javax.ws.rs.core.Response.Status.NOT_MODIFIED;
import static javax.ws.rs.core.Response.Status.NO_CONTENT;
import static org.apache.jena.riot.WebContent.contentTypeSPARQLUpdate;
import static org.apache.jena.riot.WebContent.contentTypeTurtle;
import static org.fcrepo.http.commons.test.util.PathSegmentImpl.createPathList;
Expand All @@ -45,7 +44,6 @@
import java.security.NoSuchAlgorithmException;
import java.text.ParseException;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.jcr.Node;
Expand Down Expand Up @@ -316,24 +314,6 @@ public void testBatchDelete() throws Exception {
verify(mockSession).save();
}

@Test
public void testDeleteDatastreams() throws RepositoryException {
final String pid = "FedoraDatastreamsTest1";
final String path = "/" + pid;
final List<String> dsidList = asList("ds1", "ds2");

when(mockNodes.getObject(isA(Session.class), eq("/FedoraDatastreamsTest1/ds1"))).thenReturn(mockObject);
when(mockNodes.getObject(isA(Session.class), eq("/FedoraDatastreamsTest1/ds2"))).thenReturn(mockDatastream);

final Response actual =
testObj.batchDelete(createPathList(pid), dsidList);

assertEquals(NO_CONTENT.getStatusCode(), actual.getStatus());
verify(mockObject).delete();
verify(mockDatastream).delete();
verify(mockSession).save();
}

@Test
public void testGetDatastreamsContents() throws RepositoryException,
IOException,
Expand Down
Expand Up @@ -15,7 +15,6 @@
*/
package org.fcrepo.http.api;

import static javax.ws.rs.core.MediaType.TEXT_PLAIN_TYPE;
import static javax.ws.rs.core.Response.Status.CREATED;
import static javax.ws.rs.core.Response.Status.NO_CONTENT;
import static org.fcrepo.http.commons.test.util.PathSegmentImpl.createPathList;
Expand All @@ -33,7 +32,6 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
import static org.modeshape.jcr.api.JcrConstants.JCR_CONTENT;

import java.io.IOException;
import java.io.InputStream;
Expand All @@ -57,7 +55,6 @@
import org.apache.commons.io.IOUtils;
import org.fcrepo.kernel.Datastream;
import org.fcrepo.kernel.FedoraBinary;
import org.fcrepo.kernel.FedoraResource;
import org.fcrepo.kernel.exception.InvalidChecksumException;
import org.fcrepo.kernel.identifiers.PidMinter;
import org.fcrepo.kernel.services.DatastreamService;
Expand Down Expand Up @@ -164,91 +161,6 @@ public void testPutContent()
}
}

@Test
public void testCreateContent() throws RepositoryException, IOException,
InvalidChecksumException, ParseException, URISyntaxException {
final String pid = "FedoraDatastreamsTest1";
final String dsId = "xyz";
final String dsContent = "asdf";
final String dsPath = "/" + pid + "/" + dsId;
try (final InputStream dsContentStream = IOUtils.toInputStream(dsContent)) {
when(mockNode.isNew()).thenReturn(true);
when(mockNode.getNode(JCR_CONTENT)).thenReturn(mockContentNode);
when(mockDatastreams.findOrCreateDatastream(any(Session.class), eq(dsPath))).thenReturn(mockDatastream);
when(mockDatastream.getBinary()).thenReturn(mockBinary);
when(mockBinary.getPath()).thenReturn(dsPath + "/jcr:content");
when(mockNodeService.exists(mockSession, dsPath)).thenReturn(false);
when(mockDatastreams.exists(mockSession, dsPath)).thenReturn(true);
final Response actual =
testObj.create(createPathList(pid, dsId), null, null, null, TEXT_PLAIN_TYPE,
dsContentStream);
assertEquals(CREATED.getStatusCode(), actual.getStatus());
verify(mockBinary).setContent(dsContentStream, "text/plain", null, null, null);
verify(mockSession).save();
}
}

@Test
public void testCreateContentAtMintedPath() throws RepositoryException, InvalidChecksumException,
ParseException, IOException {
final String pid = "FedoraDatastreamsTest1";
final String dsContent = "asdf";
final String dsPath = "/" + pid;
try (final InputStream dsContentStream = IOUtils.toInputStream(dsContent)) {
when(mockNodeService.exists(mockSession, dsPath)).thenReturn(true);
when(mockMinter.mintPid()).thenReturn("xyz");
setField(testObj, "pidMinter", mockMinter);
when(mockNode.isNew()).thenReturn(true);

when(mockDatastreams.findOrCreateDatastream(any(Session.class), eq(dsPath + "/xyz")))
.thenReturn(mockDatastream);
when(mockDatastream.getBinary()).thenReturn(mockBinary);
when(mockBinary.getPath()).thenReturn(dsPath + "/jcr:content");

when(mockDatastreams.exists(mockSession, dsPath)).thenReturn(true);
final FedoraResource mockResource = mock(FedoraResource.class);
when(mockNodeService.getObject(mockSession, dsPath)).thenReturn(mockResource);
when(mockResource.hasContent()).thenReturn(false);

final Response actual =
testObj.create(createPathList(pid), null, null, null, TEXT_PLAIN_TYPE,
dsContentStream);
assertEquals(CREATED.getStatusCode(), actual.getStatus());
verify(mockBinary).setContent(dsContentStream, "text/plain", null, null, null);
verify(mockSession).save();
}
}


@Test
public void testCreateContentWithSlug() throws RepositoryException, InvalidChecksumException,
ParseException, IOException {
final String pid = "FedoraDatastreamsTest1";
final String dsid = "slug";
final String dsContent = "asdf";
final String dsPath = "/" + pid;
try (final InputStream dsContentStream = IOUtils.toInputStream(dsContent)) {
when(mockNodeService.exists(mockSession, dsPath)).thenReturn(true);
setField(testObj, "pidMinter", mockMinter);
when(mockNode.isNew()).thenReturn(true);
when(mockNode.getNode(JCR_CONTENT)).thenReturn(mockContentNode);
when(mockDatastreams.findOrCreateDatastream(any(Session.class), eq(dsPath + "/slug")))
.thenReturn(mockDatastream);
when(mockDatastream.getBinary()).thenReturn(mockBinary);
when(mockBinary.getPath()).thenReturn(dsPath + "/jcr:content");
when(mockDatastreams.exists(mockSession, dsPath)).thenReturn(true);
final FedoraResource mockResource = mock(FedoraResource.class);
when(mockNodeService.getObject(mockSession, dsPath)).thenReturn(mockResource);
when(mockResource.hasContent()).thenReturn(false);
final Response actual =
testObj.create(createPathList(pid), dsid, null, null, TEXT_PLAIN_TYPE,
dsContentStream);
assertEquals(CREATED.getStatusCode(), actual.getStatus());
verify(mockBinary).setContent(dsContentStream, "text/plain", null, null, null);
verify(mockSession).save();
}
}

@Test
public void testModifyContent()
throws RepositoryException, InvalidChecksumException, ParseException, IOException {
Expand Down

0 comments on commit 3e2e867

Please sign in to comment.