Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Automated formatting per Eclipse rules
  • Loading branch information
Edwin Shin committed Jun 26, 2013
1 parent 1a84664 commit 704d1c0
Show file tree
Hide file tree
Showing 138 changed files with 2,134 additions and 1,606 deletions.
Expand Up @@ -41,22 +41,23 @@ public class DublinCoreGenerator extends AbstractResource {
public Response getObjectAsDublinCore(@PathParam("path")
final List<PathSegment> pathList) throws RepositoryException {

try {
final String path = toPath(pathList);
final FedoraResource obj = nodeService.getObject(session, path);
try {
final String path = toPath(pathList);
final FedoraResource obj = nodeService.getObject(session, path);

for (final DCGenerator indexer : dcgenerators) {
final InputStream inputStream = indexer.getStream(obj.getNode());
for (final DCGenerator indexer : dcgenerators) {
final InputStream inputStream =
indexer.getStream(obj.getNode());

if (inputStream != null) {
return ok(inputStream).build();
}
}
// no indexers = no path for DC
throw new PathNotFoundException();
} finally {
session.logout();
}
if (inputStream != null) {
return ok(inputStream).build();
}
}
// no indexers = no path for DC
throw new PathNotFoundException();
} finally {
session.logout();
}

}

Expand Down
Expand Up @@ -34,7 +34,7 @@ public InputStream getStream(final Node node) {
}

private InputStream getContentInputStream(final Node node)
throws RepositoryException {
throws RepositoryException {
if (node.hasNode(wellKnownDsid)) {
final Node dc = node.getNode(wellKnownDsid);

Expand Down
@@ -1,3 +1,4 @@

package org.fcrepo.generator;

import static org.fcrepo.test.util.PathSegmentImpl.createPathList;
Expand All @@ -24,39 +25,43 @@
public class DublinCoreGeneratorTest {

DublinCoreGenerator testObj;
NodeService mockNodeService;

NodeService mockNodeService;

DCGenerator mockGenerator;
Session mockSession;


Session mockSession;

@Before
public void setUp() throws RepositoryException {
mockNodeService = mock(NodeService.class);
mockNodeService = mock(NodeService.class);
testObj = new DublinCoreGenerator();
testObj.setNodeService(mockNodeService);
testObj.setNodeService(mockNodeService);

mockSession = TestHelpers.mockSession(testObj);
mockSession = TestHelpers.mockSession(testObj);
testObj.setSession(mockSession);
mockGenerator = mock(DCGenerator.class);
testObj.dcgenerators = Arrays.asList(mockGenerator);
}

@Test
public void testGetObjectAsDublinCore() throws RepositoryException {
testObj.dcgenerators = Arrays.asList(mockGenerator);
InputStream mockIS = mock(InputStream.class);
FedoraResource mockResource = mock(FedoraResource.class);
when(mockResource.getNode()).thenReturn(mock(Node.class));
when(mockNodeService.getObject(mockSession, "/objects/foo")).thenReturn(mockResource);
FedoraResource mockResource = mock(FedoraResource.class);
when(mockResource.getNode()).thenReturn(mock(Node.class));
when(mockNodeService.getObject(mockSession, "/objects/foo"))
.thenReturn(mockResource);
when(mockGenerator.getStream(any(Node.class))).thenReturn(mockIS);
testObj.getObjectAsDublinCore(createPathList("objects","foo"));
testObj.getObjectAsDublinCore(createPathList("objects", "foo"));

}

@Test
public void testNoGenerators() {
testObj.dcgenerators = Arrays.asList(new DCGenerator[0]);
try {
testObj.getObjectAsDublinCore(createPathList("objects","foo"));
testObj.getObjectAsDublinCore(createPathList("objects", "foo"));
fail("Should have failed without a generator configured!");
} catch (PathNotFoundException ex) {
// this is what we expect
Expand Down
@@ -1,3 +1,4 @@

package org.fcrepo.generator.dublincore;

import static org.junit.Assert.assertEquals;
Expand All @@ -18,23 +19,22 @@
import org.junit.Before;
import org.junit.Test;


public class WellKnownDatastreamGeneratorTest {

private WellKnownDatastreamGenerator testObj;

@Before
public void setUp() {
testObj = new WellKnownDatastreamGenerator();
}

@Test
public void testGetStreamAbsent() {
Node mockNode = mock(Node.class);
InputStream actual = testObj.getStream(mockNode);
assertTrue(actual == null);
}

@Test
public void testGetStreamPresent() throws Exception {
String dsid = "foo";
Expand All @@ -56,7 +56,9 @@ public void testGetStreamPresent() throws Exception {
@Test
public void testSetWellKnownDsid() throws Exception {
testObj.setWellKnownDsid("foo");
Field field = WellKnownDatastreamGenerator.class.getDeclaredField("wellKnownDsid");
Field field =
WellKnownDatastreamGenerator.class
.getDeclaredField("wellKnownDsid");
field.setAccessible(true);
String actual = (String) field.get(testObj);
assertEquals("foo", actual);
Expand Down
@@ -1,3 +1,4 @@

package org.fcrepo.generator.dublincore;

import static org.junit.Assert.assertTrue;
Expand All @@ -13,26 +14,25 @@
import org.junit.Before;
import org.junit.Test;


public class WorstCaseGeneratorTest {

private WorstCaseGenerator testObj;

private JAXBContext context;

@Before
public void setUp() throws JAXBException {
testObj = new WorstCaseGenerator();
context =
JAXBContext.newInstance(OaiDublinCore.class);
context = JAXBContext.newInstance(OaiDublinCore.class);

}

@Test
public void testGetStream() throws Exception {
Node mockNode = mock(Node.class);
InputStream out = testObj.getStream(mockNode);
OaiDublinCore actual = (OaiDublinCore)context.createUnmarshaller().unmarshal(out);
OaiDublinCore actual =
(OaiDublinCore) context.createUnmarshaller().unmarshal(out);
assertTrue(actual != null);
}
}
@@ -1,9 +1,10 @@

package org.fcrepo.generator.util;

import javax.xml.bind.annotation.XmlRootElement;


@XmlRootElement(name = "dc", namespace = "http://www.openarchives.org/OAI/2.0/oai_dc/")
@XmlRootElement(name = "dc",
namespace = "http://www.openarchives.org/OAI/2.0/oai_dc/")
public class OaiDublinCore {

}
Expand Up @@ -60,19 +60,19 @@ protected static HttpPost postObjMethod(final String pid) {
protected static HttpPost postDSMethod(final String pid, final String ds,
final String content) throws UnsupportedEncodingException {
final HttpPost post =
new HttpPost(serverAddress + "objects/" + pid +
"/" + ds + "?mixin=" + FedoraJcrTypes.FEDORA_DATASTREAM);
new HttpPost(serverAddress + "objects/" + pid + "/" + ds +
"?mixin=" + FedoraJcrTypes.FEDORA_DATASTREAM);
post.setEntity(new StringEntity(content));
return post;
}

protected static HttpPut putDSMethod(final String pid, final String ds) {
return new HttpPut(serverAddress + "objects/" + pid +
"/" + ds + "?mixin=" + FedoraJcrTypes.FEDORA_DATASTREAM);
return new HttpPut(serverAddress + "objects/" + pid + "/" + ds +
"?mixin=" + FedoraJcrTypes.FEDORA_DATASTREAM);
}

protected int getStatus(final HttpUriRequest method)
throws ClientProtocolException, IOException {
throws ClientProtocolException, IOException {
logger.debug("Executing: " + method.getMethod() + " to " +
method.getURI());
return client.execute(method).getStatusLine().getStatusCode();
Expand Down
Expand Up @@ -22,18 +22,17 @@ public class DublinCoreGeneratorIT extends AbstractResourceIT {

@Test
public void testJcrPropertiesBasedOaiDc() throws Exception {
final int status = getStatus( postObjMethod("DublinCoreTest1"));
assertEquals(201, status);
final HttpPost post = postObjMethod("DublinCoreTest1");
post.setHeader("Content-Type", "application/sparql-update");
BasicHttpEntity entity = new BasicHttpEntity();
String subjectURI = serverAddress + "objects/DublinCoreTest1";
entity.setContent(new ByteArrayInputStream(
("INSERT { <" + subjectURI +
"> <http://purl.org/dc/terms/identifier> \"this is an identifier\" } WHERE {}")
.getBytes()));
post.setEntity(entity);
assertEquals(204, getStatus( post));
final int status = getStatus(postObjMethod("DublinCoreTest1"));
assertEquals(201, status);
final HttpPost post = postObjMethod("DublinCoreTest1");
post.setHeader("Content-Type", "application/sparql-update");
BasicHttpEntity entity = new BasicHttpEntity();
String subjectURI = serverAddress + "objects/DublinCoreTest1";
entity.setContent(new ByteArrayInputStream(
("INSERT { <" + subjectURI + "> <http://purl.org/dc/terms/identifier> \"this is an identifier\" } WHERE {}")
.getBytes()));
post.setEntity(entity);
assertEquals(204, getStatus(post));
final HttpGet getWorstCaseOaiMethod =
new HttpGet(serverOAIAddress + "objects/DublinCoreTest1/oai:dc");
getWorstCaseOaiMethod.setHeader("Accept", TEXT_XML);
Expand All @@ -42,7 +41,7 @@ public void testJcrPropertiesBasedOaiDc() throws Exception {
assertEquals(200, response.getStatusLine().getStatusCode());

final String content = EntityUtils.toString(response.getEntity());
logger.debug("Got content: {}", content);
logger.debug("Got content: {}", content);
assertTrue("Didn't find oai_dc!", compile("oai_dc", DOTALL).matcher(
content).find());

Expand Down
50 changes: 30 additions & 20 deletions fcrepo-http-api/src/main/java/org/fcrepo/api/FedoraContent.java
Expand Up @@ -56,10 +56,11 @@ public class FedoraContent extends AbstractResource {
private final Logger logger = getLogger(FedoraContent.class);

/**
* Create an anonymous DS with a newly minted name
* and content from request body
* Create an anonymous DS with a newly minted name and content from request
* body
*
* @param pathList
* @throws RepositoryException
* @throws RepositoryException
*/
@POST
@Timed
Expand All @@ -68,7 +69,8 @@ public Response create(@PathParam("path")
final String checksumType, @QueryParam("checksum")
final String checksum, @HeaderParam("Content-Type")
final MediaType requestContentType, final InputStream requestBodyStream)
throws IOException, InvalidChecksumException, RepositoryException, URISyntaxException {
throws IOException, InvalidChecksumException, RepositoryException,
URISyntaxException {
final MediaType contentType =
requestContentType != null ? requestContentType
: APPLICATION_OCTET_STREAM_TYPE;
Expand All @@ -82,13 +84,18 @@ public Response create(@PathParam("path")

logger.debug("create Datastream {}", path);
try {
final Node datastreamNode = datastreamService.createDatastreamNode(session, path, contentType.toString(), requestBodyStream, checksumType, checksum);

final Node datastreamNode =
datastreamService.createDatastreamNode(session, path,
contentType.toString(), requestBodyStream,
checksumType, checksum);

final HttpGraphSubjects subjects =
new HttpGraphSubjects(FedoraNodes.class, uriInfo, session);
final HttpGraphSubjects subjects =
new HttpGraphSubjects(FedoraNodes.class, uriInfo, session);

return created(new URI(subjects.getGraphSubject(datastreamNode.getNode(JcrConstants.JCR_CONTENT)).getURI())).build();
return created(
new URI(subjects.getGraphSubject(
datastreamNode.getNode(JcrConstants.JCR_CONTENT))
.getURI())).build();

} finally {
session.save();
Expand All @@ -98,16 +105,14 @@ public Response create(@PathParam("path")

/**
* Modify an existing datastream's content
*
*
* @param pathList
* @param requestContentType
* Content-Type header
* @param requestBodyStream
* Binary blob
* @param requestContentType Content-Type header
* @param requestBodyStream Binary blob
* @return 201 Created
* @throws RepositoryException
* @throws IOException
* @throws InvalidChecksumException
* @throws InvalidChecksumException
*/
@PUT
@Timed
Expand All @@ -116,7 +121,7 @@ public Response modifyContent(@PathParam("path")
final MediaType requestContentType, final InputStream requestBodyStream,
@Context
final Request request) throws RepositoryException, IOException,
InvalidChecksumException, URISyntaxException {
InvalidChecksumException, URISyntaxException {
try {
final String path = toPath(pathList);
final MediaType contentType =
Expand Down Expand Up @@ -150,9 +155,14 @@ public Response modifyContent(@PathParam("path")

if (isNew) {
final HttpGraphSubjects subjects =
new HttpGraphSubjects(FedoraNodes.class, uriInfo, session);

return created(new URI(subjects.getGraphSubject(datastreamNode.getNode(JcrConstants.JCR_CONTENT)).getURI())).build();
new HttpGraphSubjects(FedoraNodes.class, uriInfo,
session);

return created(
new URI(subjects.getGraphSubject(
datastreamNode
.getNode(JcrConstants.JCR_CONTENT))
.getURI())).build();
} else {
return noContent().build();
}
Expand All @@ -164,7 +174,7 @@ public Response modifyContent(@PathParam("path")

/**
* Get the binary content of a datastream
*
*
* @param pathList
* @return Binary blob
* @throws RepositoryException
Expand Down

0 comments on commit 704d1c0

Please sign in to comment.