Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ajs6f committed Feb 11, 2014
1 parent c1bb4d1 commit f4daad5
Show file tree
Hide file tree
Showing 100 changed files with 314 additions and 492 deletions.
Expand Up @@ -63,6 +63,7 @@
import javax.ws.rs.core.Response.ResponseBuilder;

import com.hp.hpl.jena.rdf.model.Model;

import org.apache.commons.io.IOUtils;
import org.apache.jena.riot.Lang;
import org.fcrepo.http.commons.AbstractResource;
Expand Down Expand Up @@ -156,7 +157,7 @@ public Response batchModify(@PathParam("path") final List<PathSegment> pathList,

try {

final Set<Node> nodesChanged = new HashSet<Node>();
final Set<Node> nodesChanged = new HashSet<>();

// iterate through the multipart entities
for (final BodyPart part : multipart.getBodyParts()) {
Expand Down Expand Up @@ -340,18 +341,17 @@ public Response batchDelete(@PathParam("path") final List<PathSegment> pathList,
* @param request
* @return
* @throws RepositoryException
* @throws IOException
* @throws NoSuchAlgorithmException
*/
@GET
@Produces("multipart/mixed")
@Timed
public Response getBinaryContents(@PathParam("path") final List<PathSegment> pathList,
@QueryParam("child") final List<String> requestedChildren,
@Context final Request request) throws RepositoryException, IOException,
NoSuchAlgorithmException {
public Response getBinaryContents(
@PathParam("path") final List<PathSegment> pathList,
@QueryParam("child") final List<String> requestedChildren,
@Context final Request request) throws RepositoryException, NoSuchAlgorithmException {

final List<Datastream> datastreams = new ArrayList<Datastream>();
final List<Datastream> datastreams = new ArrayList<>();

try {
final String path = toPath(pathList);
Expand Down
Expand Up @@ -101,8 +101,7 @@ public Response create(@PathParam("path")
@QueryParam("checksum") final String checksum,
@HeaderParam("Content-Type") final MediaType requestContentType,
final InputStream requestBodyStream)
throws IOException, InvalidChecksumException,
RepositoryException, URISyntaxException, ParseException {
throws InvalidChecksumException, RepositoryException, URISyntaxException, ParseException {
final MediaType contentType =
requestContentType != null ? requestContentType
: APPLICATION_OCTET_STREAM_TYPE;
Expand Down Expand Up @@ -182,7 +181,6 @@ public Response create(@PathParam("path")
* @param requestBodyStream Binary blob
* @return 201 Created
* @throws RepositoryException
* @throws IOException
* @throws InvalidChecksumException
*/
@PUT
Expand All @@ -193,7 +191,7 @@ public Response modifyContent(@PathParam("path") final List<PathSegment> pathLis
@HeaderParam("Content-Type") final MediaType requestContentType,
final InputStream requestBodyStream,
@Context final Request request)
throws RepositoryException, IOException, InvalidChecksumException, URISyntaxException, ParseException {
throws RepositoryException, InvalidChecksumException, URISyntaxException, ParseException {

try {
final String path = toPath(pathList);
Expand Down Expand Up @@ -258,9 +256,8 @@ public Response modifyContent(@PathParam("path") final List<PathSegment> pathLis
datastreamNode
.getNode(JCR_CONTENT))
.getURI())).build();
} else {
return noContent().build();
}
return noContent().build();
} finally {
session.logout();
}
Expand Down
Expand Up @@ -94,7 +94,7 @@ public RdfStream getNextPid(@PathParam("path")
@DefaultValue("1")
final Integer count,
@Context
final UriInfo uriInfo) throws RepositoryException {
final UriInfo uriInfo) {


final String path = toPath(pathList);
Expand Down Expand Up @@ -127,7 +127,7 @@ public String apply(final String identifier) {
};
}

private Function<String, Triple> identifier2triple(
private static Function<String, Triple> identifier2triple(
final GraphSubjects subjects, final Node pidsResult) {
return new Function<String, Triple>() {

Expand Down
Expand Up @@ -141,7 +141,6 @@ public class FedoraNodes extends AbstractResource {
* @param uriInfo
* @return
* @throws RepositoryException
* @throws IOException
*/
@GET
@Produces({TURTLE, N3, N3_ALT2, RDF_XML, NTRIPLES, APPLICATION_XML, TEXT_PLAIN, TURTLE_X,
Expand All @@ -152,7 +151,7 @@ public RdfStream describe(@PathParam("path") final List<PathSegment> pathList,
@QueryParam("non-member-properties") final String nonMemberProperties,
@Context final Request request,
@Context final HttpServletResponse servletResponse,
@Context final UriInfo uriInfo) throws RepositoryException, IOException {
@Context final UriInfo uriInfo) throws RepositoryException {
final String path = toPath(pathList);
LOGGER.trace("Getting profile for: {}", path);

Expand Down Expand Up @@ -295,10 +294,9 @@ public Response updateSparql(@PathParam("path")
versionService.nodeUpdated(resource.getNode());

return status(SC_NO_CONTENT).build();
} else {
return status(SC_BAD_REQUEST).entity(
"SPARQL-UPDATE requests must have content!").build();
}
return status(SC_BAD_REQUEST).entity(
"SPARQL-UPDATE requests must have content!").build();

} finally {
session.logout();
Expand Down
Expand Up @@ -74,12 +74,11 @@ public class FedoraSitemap extends AbstractResource {
* Get the sitemap index for the repository GET /sitemap
*
* @return
* @throws RepositoryException
*/
@GET
@Timed
@Produces(TEXT_XML)
public SitemapIndex getSitemapIndex() throws RepositoryException {
public SitemapIndex getSitemapIndex() {

LOGGER.trace("Executing getSitemapIndex()...");

Expand Down
Expand Up @@ -87,19 +87,18 @@ public Response createTransaction(@PathParam("path")
t.updateExpiryDate();
return noContent().expires(t.getExpires()).build();

} else {
final Transaction t = txService.beginTransaction(session);
final HttpSession httpSession = req.getSession(true);
if (httpSession != null) {
httpSession.setAttribute("currentTx", t.getId());
}
return created(
uriInfo.getBaseUriBuilder().path(FedoraNodes.class)
.buildFromMap(
singletonMap("path", "tx:" +
t.getId()))).expires(
t.getExpires()).build();
}
final Transaction t = txService.beginTransaction(session);
final HttpSession httpSession = req.getSession(true);
if (httpSession != null) {
httpSession.setAttribute("currentTx", t.getId());
}
return created(
uriInfo.getBaseUriBuilder().path(FedoraNodes.class)
.buildFromMap(
singletonMap("path", "tx:" +
t.getId()))).expires(
t.getExpires()).build();
}

/**
Expand Down
Expand Up @@ -31,7 +31,6 @@
import static org.fcrepo.http.commons.domain.RDFMediaType.TURTLE_X;
import static org.slf4j.LoggerFactory.getLogger;

import java.io.IOException;
import java.util.Collections;
import java.util.List;

Expand Down Expand Up @@ -151,7 +150,6 @@ private Response addVersion(final String path, final String label) throws Reposi
* @param uriInfo
* @return
* @throws RepositoryException
* @throws IOException
*/
@Path("/{versionLabel}")
@GET
Expand All @@ -164,7 +162,7 @@ public RdfStream getVersion(@PathParam("path")
@Context
final Request request,
@Context
final UriInfo uriInfo) throws RepositoryException, IOException {
final UriInfo uriInfo) throws RepositoryException {
final String path = toPath(pathList);
LOGGER.trace("Getting version profile for: {} at version: {}", path,
versionLabel);
Expand All @@ -174,10 +172,9 @@ public RdfStream getVersion(@PathParam("path")

if (resource == null) {
throw new WebApplicationException(status(NOT_FOUND).build());
} else {
return resource.getTriples(nodeTranslator()).session(session).topic(
nodeTranslator().getGraphSubject(resource.getNode()).asNode());
}
return resource.getTriples(nodeTranslator()).session(session).topic(
nodeTranslator().getGraphSubject(resource.getNode()).asNode());
}

/**
Expand Down
Expand Up @@ -98,10 +98,9 @@ public Response updateSparql(final InputStream requestBodyStream)
session.save();

return status(SC_NO_CONTENT).build();
} else {
return status(SC_BAD_REQUEST).entity(
"SPARQL-UPDATE requests must have content ").build();
}
return status(SC_BAD_REQUEST).entity(
"SPARQL-UPDATE requests must have content ").build();
} finally {
session.logout();
}
Expand Down
Expand Up @@ -100,9 +100,8 @@ public String runBackup(final InputStream bodyStream) throws RepositoryException

throw new WebApplicationException(serverError().entity(problemsOutput.toString()).build());

} else {
return backupDirectory.getCanonicalPath();
}
return backupDirectory.getCanonicalPath();
} finally {
session.logout();
}
Expand Down
Expand Up @@ -97,14 +97,13 @@ public Response updateNamespaces(final InputStream requestBodyStream)
/**
* @return
* @throws RepositoryException
* @throws IOException
*/
@GET
@Timed
@Produces({TURTLE, N3, N3_ALT2, RDF_XML, NTRIPLES, APPLICATION_XML, TEXT_PLAIN, TURTLE_X,
TEXT_HTML, APPLICATION_XHTML_XML})
@HtmlTemplate("jcr:namespaces")
public RdfStream getNamespaces() throws RepositoryException, IOException {
public RdfStream getNamespaces() throws RepositoryException {
return nodeService.getNamespaceRegistryStream(session).session(session);
}
}
Expand Up @@ -85,7 +85,7 @@ public Response runRestore(final InputStream bodyStream) throws RepositoryExcept
if (problems.hasProblems()) {
LOGGER.error("Problems restoring up the repository:");

final List<String> problemsOutput = new ArrayList<String>();
final List<String> problemsOutput = new ArrayList<>();

// Report the problems (we'll just print them out) ...
for (final Problem problem : problems) {
Expand All @@ -96,9 +96,8 @@ public Response runRestore(final InputStream bodyStream) throws RepositoryExcept
throw new WebApplicationException(serverError()
.entity(problemsOutput).build());

} else {
return noContent().build();
}
return noContent().build();
} finally {
session.logout();
}
Expand Down
Expand Up @@ -30,7 +30,6 @@
import static org.fcrepo.http.commons.domain.RDFMediaType.TURTLE;
import static org.fcrepo.http.commons.domain.RDFMediaType.TURTLE_X;

import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import javax.jcr.RepositoryException;
Expand Down Expand Up @@ -99,13 +98,12 @@ public RdfStream getWorkspaces()
* @param uriInfo
* @return
* @throws RepositoryException
* @throws MalformedURLException
*/
@POST
@Path("{path}")
public Response createWorkspace(@PathParam("path") final String path,
@Context final UriInfo uriInfo)
throws RepositoryException, MalformedURLException, URISyntaxException {
throws RepositoryException, URISyntaxException {

try {
final Workspace workspace = session.getWorkspace();
Expand Down
Expand Up @@ -180,7 +180,7 @@ public void testBatchRdfPost() throws Exception {
multipart.bodyPart(part);

testObj.batchModify(createPathList(pid), multipart);
ArgumentCaptor<Model> captor = ArgumentCaptor.forClass(Model.class);
final ArgumentCaptor<Model> captor = ArgumentCaptor.forClass(Model.class);
verify(mockObject).replaceProperties(any(GraphSubjects.class), captor.capture());
final Model capturedModel = captor.getValue();
assertTrue(capturedModel.contains(capturedModel.createResource("http://localhost/fcrepo/" + pid),
Expand Down Expand Up @@ -271,7 +271,7 @@ public void testBatchDelete() throws Exception {
}

@Test
public void testDeleteDatastreams() throws RepositoryException, IOException {
public void testDeleteDatastreams() throws RepositoryException {
final String pid = "FedoraDatastreamsTest1";
final String path = "/" + pid;
final List<String> dsidList = asList("ds1", "ds2");
Expand Down Expand Up @@ -318,7 +318,6 @@ public void testGetDatastreamsContents() throws RepositoryException,

@Test
public void testGetDatastreamsContentsCached() throws RepositoryException,
IOException,
NoSuchAlgorithmException {
final String pid = "FedoraDatastreamsTest1";
final String dsId = "testDS";
Expand Down
Expand Up @@ -105,8 +105,7 @@ public void setUp() throws Exception {
}

@Test
public void testPutContent() throws RepositoryException, IOException,
InvalidChecksumException, URISyntaxException, ParseException {
public void testPutContent() throws RepositoryException, InvalidChecksumException, URISyntaxException, ParseException {
final String pid = "FedoraDatastreamsTest1";
final String dsId = "testDS";
final String dsContent = "asdf";
Expand All @@ -130,6 +129,7 @@ public void testPutContent() throws RepositoryException, IOException,
verify(mockSession).save();
}

@SuppressWarnings("unused")
@Test
public void testCreateContent() throws RepositoryException, IOException,
InvalidChecksumException, URISyntaxException, ParseException {
Expand Down Expand Up @@ -157,11 +157,8 @@ public void testCreateContent() throws RepositoryException, IOException,
}

@Test
public void testCreateContentAtMintedPath() throws RepositoryException,
IOException,
InvalidChecksumException,
URISyntaxException,
NoSuchFieldException, ParseException {
public void testCreateContentAtMintedPath() throws RepositoryException, InvalidChecksumException,
URISyntaxException, ParseException {
final String pid = "FedoraDatastreamsTest1";
final String dsContent = "asdf";
final String dsPath = "/" + pid;
Expand All @@ -188,11 +185,8 @@ public void testCreateContentAtMintedPath() throws RepositoryException,


@Test
public void testCreateContentWithSlug() throws RepositoryException,
IOException,
InvalidChecksumException,
URISyntaxException,
NoSuchFieldException, ParseException {
public void testCreateContentWithSlug() throws RepositoryException, InvalidChecksumException,
URISyntaxException, ParseException {
final String pid = "FedoraDatastreamsTest1";
final String dsid = "slug";
final String dsContent = "asdf";
Expand All @@ -218,8 +212,7 @@ public void testCreateContentWithSlug() throws RepositoryException,
}

@Test
public void testModifyContent() throws RepositoryException, IOException,
InvalidChecksumException, URISyntaxException, ParseException {
public void testModifyContent() throws RepositoryException, InvalidChecksumException, URISyntaxException, ParseException {
final String pid = "FedoraDatastreamsTest1";
final String dsId = "testDS";
final String dsContent = "asdf";
Expand Down
Expand Up @@ -27,8 +27,6 @@
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;

import java.io.IOException;

import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
Expand Down Expand Up @@ -72,8 +70,7 @@ public void setUp() throws Exception {
}

@Test
public void testGetDatastreamFixity() throws RepositoryException,
IOException {
public void testGetDatastreamFixity() throws RepositoryException {
final String pid = "FedoraDatastreamsTest1";
final String path = "/objects/" + pid + "/testDS";
final String dsId = "testDS";
Expand Down

0 comments on commit f4daad5

Please sign in to comment.