Skip to content

Commit

Permalink
fixed retrieve uris test and added //NOSONOAR comment for ArrayList.c…
Browse files Browse the repository at this point in the history
…lass since the interface can not be used
  • Loading branch information
fasseg committed Jun 6, 2013
1 parent 8c8b9e4 commit 92fd7c8
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 45 deletions.
Expand Up @@ -8,7 +8,6 @@
import java.util.ArrayList;
import java.util.List;

import org.apache.http.client.methods.HttpGet;
import org.apache.jena.atlas.web.HttpException;
import org.apache.jena.riot.RDFDataMgr;
import org.fcrepo.RdfLexicon;
Expand Down Expand Up @@ -47,7 +46,6 @@ public class FedoraFixityClient {
*/
public List<String> retrieveUris(String parentUri) throws IOException {
/* fetch a RDF Description of the parent form the repository */
final HttpGet search = new HttpGet(parentUri);
StmtIterator stmts = null;
try {
/* parse the RDF N3 response using Apache Jena */
Expand All @@ -64,17 +62,17 @@ public List<String> retrieveUris(String parentUri) throws IOException {
* and iterate over all the elements which contain the predicate
* #hasParent in order to discover objects
*/
stmts = model.listStatements(null, RdfLexicon.HAS_PARENT, model
.createResource(parentUri));
stmts = model.listStatements(model.createResource(parentUri), RdfLexicon.HAS_CHILD, (RDFNode) null);
final List<String> uris = new ArrayList<>();
while (stmts.hasNext()) {
Statement st = stmts.next(); //NOSONAR
uris.add(st.getSubject().getURI());
String uri = st.getObject().asResource().getURI();
uris.add(uri);
LOG.debug("adding '" + uri + "' to retrieveUris results");
}
return uris;
} finally {
stmts.close();
search.releaseConnection();
}
}

Expand Down
Expand Up @@ -18,6 +18,7 @@
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSeeAlso;

import org.fcrepo.fixity.service.FixityService;
import org.hibernate.annotations.DiscriminatorOptions;

/**
Expand All @@ -29,7 +30,7 @@
@DiscriminatorColumn(name="RESULT_DISCRIMINATOR",discriminatorType=DiscriminatorType.INTEGER)
@DiscriminatorOptions(force=true)
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@XmlRootElement
@XmlRootElement(name="datastream-fixity-result", namespace = FixityService.FIXITY_NAMESPACE)
@XmlSeeAlso({DatastreamFixitySuccess.class, DatastreamFixityError.class, DatastreamFixityRepaired.class})
@XmlAccessorType(XmlAccessType.FIELD)
public abstract class DatastreamFixityResult {
Expand Down
Expand Up @@ -4,6 +4,7 @@

package org.fcrepo.fixity.model;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

Expand All @@ -29,7 +30,7 @@
*
*/
@Entity
@Table(name = "FIXITY_OBJECTS")
@Table(name = "FIXITY_OBJECT_RESULTS")
@XmlRootElement(name = "object-fixity-result", namespace = FixityService.FIXITY_NAMESPACE)
@XmlAccessorType(XmlAccessType.FIELD)
public class ObjectFixityResult {
Expand Down Expand Up @@ -59,17 +60,20 @@ public static enum FixityResult {

@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name=COLUMN_OBJECT_FIXITY_ID)
@XmlElement(name="successes",namespace=FixityService.FIXITY_NAMESPACE,type=List.class)
@XmlElement(name="successes",namespace=FixityService.FIXITY_NAMESPACE
,type=ArrayList.class) //NOSONAR
private List<DatastreamFixitySuccess> successes;

@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name=COLUMN_OBJECT_FIXITY_ID)
@XmlElement(name="errors",namespace=FixityService.FIXITY_NAMESPACE,type=List.class)
@XmlElement(name="errors",namespace=FixityService.FIXITY_NAMESPACE
,type=ArrayList.class) //NOSONAR
private List<DatastreamFixityError> errors;

@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name=COLUMN_OBJECT_FIXITY_ID)
@XmlElement(name="repairs",namespace=FixityService.FIXITY_NAMESPACE,type=List.class)
@XmlElement(name="repairs",namespace=FixityService.FIXITY_NAMESPACE
,type=ArrayList.class) //NOSONAR
private List<DatastreamFixityRepaired> repairs;

public Date getTimeStamp() {
Expand Down
Expand Up @@ -126,7 +126,9 @@ public void consumeFixityMessage(String uri) throws JMSException {
*/
final ObjectFixityResult result = this.checkObjectFixity(uri);
/* save the new result to the database */
this.databaseService.addResult(result);
if (result != null){
this.databaseService.addResult(result);
}
} catch (IOException e) {
/* rethrow the exception as a Spring JMS Exception */
LOG.error(e.getMessage(), e);
Expand All @@ -136,6 +138,7 @@ public void consumeFixityMessage(String uri) throws JMSException {

/**
* Request fixity check execution from the Fedora repository
* @return the {@link ObjectFixityResult} or null if no result could be created
*/
private ObjectFixityResult checkObjectFixity(final String uri)
throws IOException {
Expand All @@ -147,6 +150,10 @@ private ObjectFixityResult checkObjectFixity(final String uri)
LOG.debug("discovered {} datastream URIs for Object {}",
datastreamUris.size(), uri);

if (datastreamUris.isEmpty()){
LOG.warn("Unable to generate fixity result for object without datastreams");
return null;
}
/*
* for each of the child datastreams queue a fixity check by calling the
* corresponding Fedora endpoint
Expand Down
@@ -1,6 +1,7 @@
/**
*
*/

package org.fcrepo.fixity.integration;

import static org.junit.Assert.assertEquals;
Expand All @@ -23,57 +24,71 @@
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;


/**
* @author frank asseg
*
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"/integration-tests/test-container.xml", "/integration-tests/fixity.xml"})
public class FedoraFixityClientIT{
@ContextConfiguration(locations = {"/integration-tests/test-container.xml",
"/integration-tests/fixity.xml"})
public class FedoraFixityClientIT {

private final FedoraFixityClient fixityClient = new FedoraFixityClient();

private final String serverAddress = "http://localhost:" + (System.getProperty("test.port") != null ? System.getProperty("test.port") : 8080) + "/";
private final String serverAddress = "http://localhost:" +
(System.getProperty("test.port") != null ? System
.getProperty("test.port") : 8080);

private final HttpClient httpClient = new DefaultHttpClient();

@Test
public void testRetrievePids() throws Exception {
/* create a new item in the objects folder */
HttpPost postObject = new HttpPost(serverAddress + "rest/objects/fcr:new");
HttpPost postObject =
new HttpPost(serverAddress + "/rest/objects/fcr:new");
HttpResponse resp = new DefaultHttpClient().execute(postObject);
assertEquals("Unable to create Object",201, resp.getStatusLine().getStatusCode());
assertEquals("Unable to create Object", 201, resp.getStatusLine()
.getStatusCode());

String createdPid = EntityUtils.toString(resp.getEntity());

List<String> uris = this.fixityClient.retrieveUris(serverAddress + "rest/objects");
assertTrue("created pid not found in fixity client request", uris.contains(serverAddress + "rest" + createdPid));
List<String> uris =
this.fixityClient.retrieveUris(serverAddress + "/rest/objects");
String createdUri = serverAddress + createdPid;
assertTrue("created pid not found in fixity client request", uris
.contains(createdUri));
}

@Test
public void testQueueDatastreamFixityChecks() throws Exception {
/* create a new item in the objects folder */
HttpPost postObject = new HttpPost(serverAddress + "rest/objects/fcr:new");
HttpPost postObject =
new HttpPost(serverAddress + "/rest/objects/fcr:new");
HttpResponse resp = this.httpClient.execute(postObject);
assertEquals("Unable to create Object",201, resp.getStatusLine().getStatusCode());
String objectUri = serverAddress + "rest" + EntityUtils.toString(resp.getEntity());
assertEquals("Unable to create Object", 201, resp.getStatusLine()
.getStatusCode());
String objectUri =
serverAddress + "/rest" + EntityUtils.toString(resp.getEntity());
postObject.releaseConnection();

/* add two datastreams to the object for checksumming tests */
HttpPost postDs =new HttpPost(objectUri + "/ds1/fcr:content");
HttpPost postDs = new HttpPost(objectUri + "/ds1/fcr:content");
postDs.setEntity(new StringEntity("foo"));
resp=this.httpClient.execute(postDs);
assertEquals("Unable to create datastream",201, resp.getStatusLine().getStatusCode());
resp = this.httpClient.execute(postDs);
assertEquals("Unable to create datastream", 201, resp.getStatusLine()
.getStatusCode());
postDs.releaseConnection();
postDs =new HttpPost(objectUri + "/ds2/fcr:content");
postDs = new HttpPost(objectUri + "/ds2/fcr:content");
postDs.setEntity(new StringEntity("bar"));
resp=this.httpClient.execute(postDs);
assertEquals("Unable to create datastream",201, resp.getStatusLine().getStatusCode());
resp = this.httpClient.execute(postDs);
assertEquals("Unable to create datastream", 201, resp.getStatusLine()
.getStatusCode());
postDs.releaseConnection();

/* queue a fixity check for the datastream uris */
List<DatastreamFixityResult> results = this.fixityClient.requestFixityChecks(Arrays.asList(objectUri + "/ds1",objectUri + "/ds1"));
List<DatastreamFixityResult> results =
this.fixityClient.requestFixityChecks(Arrays.asList(objectUri +
"/ds1", objectUri + "/ds1"));
assertTrue(2 == results.size());
assertTrue(results.get(0).getType() == ResultType.SUCCESS);
assertTrue(results.get(1).getType() == ResultType.SUCCESS);
Expand Down
@@ -1,6 +1,3 @@
/**
*
*/

package org.fcrepo.fixity.web.provider;

Expand All @@ -18,29 +15,30 @@
import org.fcrepo.fixity.model.DatastreamFixitySuccess;
import org.fcrepo.fixity.model.ObjectFixityResult;
import org.fcrepo.fixity.model.Statistics;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
* @author frank asseg
*
*/
@Provider
@Produces({MediaType.APPLICATION_JSON, MediaType.TEXT_XML})
@Component
@Produces({MediaType.APPLICATION_JSON, MediaType.TEXT_XML})
public class FixityJaxbContextResolver implements ContextResolver<JAXBContext> {

private final JAXBContext context;

private static final Logger LOG =
LoggerFactory.getLogger(FixityJaxbContextResolver.class);

public FixityJaxbContextResolver() {
try {

context =
JAXBContext.newInstance(DailyStatistics.class,
Statistics.class, DatastreamFixityResult.class,
DatastreamFixityError.class,
DatastreamFixityRepaired.class,
DatastreamFixitySuccess.class,
ObjectFixityResult.class);
DatastreamFixityError.class, DatastreamFixityRepaired.class,
DatastreamFixitySuccess.class, ObjectFixityResult.class);
} catch (JAXBException e) {
LOG.error(e.getMessage(),e);
throw new IllegalStateException("Not able to instantiate Jaxb context",e);
}
}
Expand Down
2 changes: 1 addition & 1 deletion fcrepo-fixity-webapp/src/main/resources/fixity.xml
Expand Up @@ -38,7 +38,7 @@
<props>
<prop key="hibernate.dialect"> org.hibernate.dialect.HSQLDialect</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
</props>
</property>
</bean>
Expand Down
4 changes: 2 additions & 2 deletions fcrepo-fixity-webapp/src/main/webapp/static/results.html
Expand Up @@ -82,7 +82,7 @@ <h1>Fedora 4 - Fixity Service Report</h1>
<thead>
<tr>
<th>Id</th>
<th>Pid</th>
<th>Uri</th>
<th>Timestamp</th>
<th>Result</th>
</tr>
Expand All @@ -92,7 +92,7 @@ <h1>Fedora 4 - Fixity Service Report</h1>
<tfoot>
<tr>
<th>Id</th>
<th>Pid</th>
<th>Uri</th>
<th>Timestamp</th>
<th>Result</th>
</tr>
Expand Down

0 comments on commit 92fd7c8

Please sign in to comment.