Skip to content

Commit

Permalink
removed some more sonar violations
Browse files Browse the repository at this point in the history
  • Loading branch information
fasseg committed Jun 5, 2013
1 parent f8efb62 commit cf3cf46
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 69 deletions.
Expand Up @@ -37,7 +37,7 @@
@Service("fixityClient")
public class FedoraFixityClient {

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

/**
Expand All @@ -48,30 +48,31 @@ 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 */
final Model model = ModelFactory.createDefaultModel();
try{
try {
RDFDataMgr.read(model, parentUri);
}catch (HttpException e){
throw new IOException("Unable to fetch uris from " + parentUri,e);
} catch (HttpException e) {
throw new IOException("Unable to fetch uris from " + parentUri,
e);
}

/*
* and iterate over all the elements which contain the predicate
* #hasParent in order to discover objects
*/
final StmtIterator stmts =
model.listStatements(null, RdfLexicon.HAS_PARENT, model
.createResource(parentUri));
stmts = model.listStatements(null, RdfLexicon.HAS_PARENT, model
.createResource(parentUri));
final List<String> uris = new ArrayList<>();
while (stmts.hasNext()) {
final Statement st = stmts.next();
Statement st = stmts.next();
uris.add(st.getSubject().getURI());
}

return uris;
} finally {
stmts.close();
search.releaseConnection();
}
}
Expand All @@ -88,52 +89,55 @@ public List<DatastreamFixityResult> requestFixityChecks(
/* parse the fixity part of the RDF response */
final Model model = ModelFactory.createDefaultModel();
RDFDataMgr.read(model, uri + "/fcr:fixity");

final StmtIterator sts =
model.listStatements(model.createResource(uri),
RdfLexicon.HAS_FIXITY_RESULT, (RDFNode) null);
if (!sts.hasNext()) {
throw new IOException("No fixity information available for " +
uri);
}
Statement st = sts.next();
final Resource res = st.getObject().asResource();

/* parse the checksum from the model */
st =
model.listStatements(res, RdfLexicon.HAS_COMPUTED_CHECKSUM,
(RDFNode) null).next();
final String checksum = st.getObject().asResource().getURI();

/* parse the status */
st =
model.listStatements(res, RdfLexicon.HAS_FIXITY_STATE,
(RDFNode) null).next();
final String state = st.getObject().asLiteral().getString();

/* parse the location */
st =
model.listStatements(res, RdfLexicon.HAS_LOCATION,
(RDFNode) null).next();
final String location = st.getObject().asResource().getURI();

logger.debug("Found fixity information: [{}, {}, {}]", state,
checksum, location);

ResultType type = ResultType.valueOf(state);
switch (type) {
case ERROR:
results.add(new DatastreamFixityError(uri));
break;
case SUCCESS:
results.add(new DatastreamFixitySuccess(uri));
break;
case REPAIRED:
results.add(new DatastreamFixityRepaired(uri));
break;
default:
throw new IOException(
"Unabel to handle results of unkwonn type");
StmtIterator sts=null;
try{
sts = model.listStatements(model.createResource(uri),
RdfLexicon.HAS_FIXITY_RESULT, (RDFNode) null);
if (!sts.hasNext()) {
throw new IOException("No fixity information available for " +
uri);
}
Statement st = sts.next();
final Resource res = st.getObject().asResource();

/* parse the checksum from the model */
st =
model.listStatements(res, RdfLexicon.HAS_COMPUTED_CHECKSUM,
(RDFNode) null).next();
final String checksum = st.getObject().asResource().getURI();

/* parse the status */
st =
model.listStatements(res, RdfLexicon.HAS_FIXITY_STATE,
(RDFNode) null).next();
final String state = st.getObject().asLiteral().getString();

/* parse the location */
st =
model.listStatements(res, RdfLexicon.HAS_LOCATION,
(RDFNode) null).next();
final String location = st.getObject().asResource().getURI();

LOG.debug("Found fixity information: [{}, {}, {}]", state,
checksum, location);

ResultType type = ResultType.valueOf(state);
switch (type) {
case ERROR:
results.add(new DatastreamFixityError(uri));
break;
case SUCCESS:
results.add(new DatastreamFixitySuccess(uri));
break;
case REPAIRED:
results.add(new DatastreamFixityRepaired(uri));
break;
default:
throw new IOException(
"Unabel to handle results of unkwonn type");
}
}finally{
sts.close();
}
}
return results;
Expand Down
Expand Up @@ -33,7 +33,7 @@
@Service("fixityDatabaseService")
public class HibernateDatabaseService implements FixityDatabaseService {

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

@Autowired
Expand Down Expand Up @@ -308,7 +308,7 @@ public void deleteAllResults() {
.executeUpdate();
sess.flush();
} catch (Exception e) {
logger.error(e.getMessage(), e);
LOG.error(e.getMessage(), e);
throw e;
} finally {
sess.close();
Expand Down
Expand Up @@ -4,7 +4,6 @@

package org.fcrepo.fixity.model;

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

Expand Down Expand Up @@ -60,17 +59,17 @@ 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=ArrayList.class)
@XmlElement(name="successes",namespace=FixityService.FIXITY_NAMESPACE,type=List.class)
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=ArrayList.class)
@XmlElement(name="errors",namespace=FixityService.FIXITY_NAMESPACE,type=List.class)
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=ArrayList.class)
@XmlElement(name="repairs",namespace=FixityService.FIXITY_NAMESPACE,type=List.class)
private List<DatastreamFixityRepaired> repairs;

public Date getTimeStamp() {
Expand Down
Expand Up @@ -56,7 +56,7 @@ public class FixityService {
@Autowired
private FixityDatabaseService databaseService;

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

/**
Expand All @@ -67,7 +67,7 @@ public void setFedoraFolderUri(String fedoraFolderUri) {
}

@PostConstruct
public void afterPropertiesSet() throws IllegalStateException {
public void afterPropertiesSet(){
if (fedoraFolderUri == null) {
throw new IllegalStateException(
"fedoraFolderUri property has to be set via spring configuration or the system property 'org.fcrepo.fixity.fcrepo.url' to e.g. 'http://{fedora-host}:{port}/rest/objects");
Expand All @@ -84,7 +84,7 @@ public void queueFixityChecks(final List<String> uris) throws IOException {
/* no pid was given, so queue all objects */
queueElements = fixityClient.retrieveUris(this.fedoraFolderUri);
if (queueElements == null) {
logger.warn("Fixity check was requested for all objects, but no objects could be discovered in the repository at " +
LOG.warn("Fixity check was requested for all objects, but no objects could be discovered in the repository at " +
this.fedoraFolderUri);
return;
}
Expand Down Expand Up @@ -118,7 +118,7 @@ public Message createMessage(Session session) throws JMSException {
* @param uri the text of the {@link Message} which is supposed to be a object uri
*/
public void consumeFixityMessage(String uri) throws JMSException {
logger.debug("received fixity request for object {}", uri);
LOG.debug("received fixity request for object {}", uri);
try {
/*
* queue a fixity check and retrieve the new results from the
Expand All @@ -129,7 +129,7 @@ public void consumeFixityMessage(String uri) throws JMSException {
this.databaseService.addResult(result);
} catch (IOException e) {
/* rethrow the exception as a Spring JMS Exception */
logger.error(e.getMessage(), e);
LOG.error(e.getMessage(), e);
throw new ListenerExecutionFailedException(e.getMessage(), e);
}
}
Expand All @@ -144,7 +144,7 @@ private ObjectFixityResult checkObjectFixity(final String uri)
* information
*/
final List<String> datastreamUris = this.fixityClient.retrieveUris(uri);
logger.debug("discovered {} datastream URIs for Object {}",
LOG.debug("discovered {} datastream URIs for Object {}",
datastreamUris.size(), uri);

/*
Expand All @@ -164,7 +164,7 @@ private ObjectFixityResult checkObjectFixity(final String uri)
} else if (dr instanceof DatastreamFixityError) {
errors.add((DatastreamFixityError) dr);
} else {
logger.error(
LOG.error(
"Unable to handle result type of datasstream fixity result: {}",
dr.getType());
}
Expand Down
Expand Up @@ -32,6 +32,8 @@
@Component
public class FixityResults {

private static final int MAX_RESULTS = 50;

@Autowired
private FixityService fixityService;

Expand All @@ -41,7 +43,7 @@ public class FixityResults {
@GET
@Produces({MediaType.APPLICATION_JSON, MediaType.TEXT_XML})
public List<ObjectFixityResult> getAllResults() {
return databaseService.getResults(0, 50);
return databaseService.getResults(0, MAX_RESULTS);
}

@Path("/{offset}/{length}")
Expand Down

0 comments on commit cf3cf46

Please sign in to comment.