Skip to content

Commit

Permalink
datastream api code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Apr 1, 2013
1 parent e3b4bbf commit 9f900dc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
31 changes: 13 additions & 18 deletions fcrepo-http-api/src/main/java/org/fcrepo/api/FedoraDatastreams.java
Expand Up @@ -22,7 +22,6 @@
import java.util.List;

import javax.inject.Inject;
import javax.jcr.LoginException;
import javax.jcr.NodeIterator;
import javax.jcr.PathNotFoundException;
import javax.jcr.RepositoryException;
Expand Down Expand Up @@ -65,7 +64,7 @@
@Path("/objects/{pid}/datastreams")
public class FedoraDatastreams extends AbstractResource {

final private Logger logger = getLogger(FedoraDatastreams.class);
private final Logger logger = getLogger(FedoraDatastreams.class);

@Inject
DatastreamService datastreamService;
Expand Down Expand Up @@ -200,8 +199,7 @@ public MultipartBody getDatastreamsContents(@PathParam("pid")
* @return 201 Created
* @throws RepositoryException
* @throws IOException
* @throws InvalidChecksumException
* @throws LoginException
* @throws InvalidChecksumException
*/
@POST
@Path("/{dsid}")
Expand All @@ -210,22 +208,19 @@ public Response addDatastream(@PathParam("pid")
final String checksumType, @QueryParam("checksum")
final String checksum, @PathParam("dsid")
final String dsid, @HeaderParam("Content-Type")
MediaType contentType, InputStream requestBodyStream) throws IOException,
MediaType requestContentType, InputStream requestBodyStream) throws IOException,
InvalidChecksumException, RepositoryException {
if (contentType == null) contentType = APPLICATION_OCTET_STREAM_TYPE;
final MediaType contentType =
requestContentType != null ? requestContentType
: APPLICATION_OCTET_STREAM_TYPE;

final Session session = repo.login();
try {
String dsPath = getDatastreamJcrNodePath(pid, dsid);
logger.info("addDatastream {}", dsPath);
if (!datastreamService.exists(pid, dsid, session)) {
datastreamService.createDatastreamNode(session, dsPath,
contentType.toString(), requestBodyStream,
checksumType, checksum);
} else {
datastreamService.createDatastreamNode(session, dsPath,
contentType.toString(), requestBodyStream,
checksumType, checksum);
}
datastreamService.createDatastreamNode(session, dsPath,
contentType.toString(), requestBodyStream,
checksumType, checksum);
session.save();
return created(uriInfo.getRequestUri()).build();
} finally {
Expand Down Expand Up @@ -284,12 +279,12 @@ public Response addDatastream(@PathParam("pid")
public Response modifyDatastream(@PathParam("pid")
final String pid, @PathParam("dsid")
final String dsid, @HeaderParam("Content-Type")
MediaType contentType, InputStream requestBodyStream)
MediaType requestContentType, InputStream requestBodyStream)
throws RepositoryException, IOException, InvalidChecksumException {
final Session session = repo.login();
try {
contentType =
contentType != null ? contentType
final MediaType contentType =
requestContentType != null ? requestContentType
: APPLICATION_OCTET_STREAM_TYPE;
String dsPath = getDatastreamJcrNodePath(pid, dsid);

Expand Down
Expand Up @@ -150,7 +150,6 @@ public void testAddDatastream() throws RepositoryException, IOException, Invalid
InputStream dsContentStream = IOUtils.toInputStream(dsContent);
Response actual = testObj.addDatastream(pid, dsId, null, dsContentStream);
assertEquals(Status.CREATED.getStatusCode(), actual.getStatus());
verify(mockDatastreams).exists(pid, dsId, mockSession);
verify(mockDatastreams).createDatastreamNode(
any(Session.class), eq(dsPath),
anyString(), any(InputStream.class),
Expand Down

0 comments on commit 9f900dc

Please sign in to comment.