Skip to content
This repository has been archived by the owner on Jan 3, 2019. It is now read-only.

Commit

Permalink
Fixing issues in Sonar report
Browse files Browse the repository at this point in the history
  • Loading branch information
escowles committed Oct 4, 2013
1 parent cd54fd8 commit 0669895
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
Expand Up @@ -60,7 +60,7 @@ public String getPath() {
public void update(String pid, String content) throws IOException {
// timestamped filename
String fn = pid + "." + fmt.format( new Date() );
if ( fn.indexOf("/") != -1 ) {
if ( fn.indexOf('/') != -1 ) {
fn = StringUtils.substringAfterLast(fn, "/");
}

Expand All @@ -78,6 +78,7 @@ public void update(String pid, String content) throws IOException {
* Remove the object from the index.
**/
public void remove(String pid) throws IOException {
update(pid,""); // empty update
// empty update
update(pid,"");
}
}
Expand Up @@ -41,6 +41,10 @@
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.PoolingClientConnectionManager;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
* MessageListener implementation that retrieves objects from the repository and
* invokes one or more indexers to index the content.
Expand All @@ -49,6 +53,7 @@
* Date: Aug 19, 2013
**/
public class IndexerGroup implements MessageListener {
private final Logger logger = LoggerFactory.getLogger(IndexerGroup.class);
private Parser atomParser = new Abdera().getParser();
private String repositoryURL;
private Set<Indexer> indexers;
Expand Down Expand Up @@ -133,8 +138,10 @@ public void onMessage(Message message) {
content = IOUtils.toString(response.getEntity()
.getContent(), Charset.forName("UTF-8"));
}
//pid represents the full path. Alternative would be to send path separately in all calls
//String pid = getPath(entry.getCategories("xsd:string")).replace("//objects", "/objects");
// pid represents the full path. Alternative would be to send
// path separately in all calls
// String pid = getPath(entry.getCategories("xsd:string"))
// .replace("//objects", "/objects");
String pid = getPath(entry.getCategories("xsd:string"));


Expand All @@ -147,14 +154,14 @@ public void onMessage(Message message) {
indexer.update(pid, content);
}
} catch (Exception innerex) {
innerex.printStackTrace();
logger.warn("Error indexing {}, {}", pid, innerex);
}
}
}
} catch (JMSException e) {
e.printStackTrace();
logger.warn("Error processing JMS event", e);
} catch (IOException e) {
e.printStackTrace();
logger.warn("Error retrieving object from repository", e);
}
}
}
Expand Up @@ -50,7 +50,7 @@ public class SparqlIndexer implements Indexer {
private String updateBase;
private boolean formUpdates = false;

final private Logger logger = LoggerFactory.getLogger(SparqlIndexer.class);
private final Logger logger = LoggerFactory.getLogger(SparqlIndexer.class);

/**
* Set URI prefix for building triplestore subjects. The fedora PID will
Expand Down Expand Up @@ -114,8 +114,7 @@ public void remove( String subject ) {

// find triples/quads to delete
String describeQuery = "DESCRIBE <" + subject + ">";
QueryEngineHTTP qexec = new QueryEngineHTTP(
queryBase, describeQuery );
QueryEngineHTTP qexec = new QueryEngineHTTP( queryBase, describeQuery );
Iterator<Triple> results = qexec.execDescribeTriples();

// build list of triples to delete
Expand All @@ -126,17 +125,15 @@ public void remove( String subject ) {
// add subject uri, if it is part of this object
if ( triple.getSubject().isURI() ) {
String uri = ((Node_URI)triple.getSubject()).getURI();
if ( uri.equals(subject) || uri.startsWith(subject + "/") ||
uri.startsWith(subject + "#") ) {
if ( matches(subject, uri) ) {
uris.add(uri);
}
}

// add object uri, if it is part of this object
if ( triple.getObject().isURI() ) {
String uri = ((Node_URI)triple.getObject()).getURI();
if ( uri.equals(subject) || uri.startsWith(subject + "/") ||
uri.startsWith(subject + "#") ) {
if ( matches(subject, uri) ) {
uris.add(uri);
}
}
Expand All @@ -155,6 +152,16 @@ public void remove( String subject ) {
exec( del );
}

/**
* Determine whether uri2 is a sub-URI of uri1, defined as uri1 starting
* with uri2, plus an option suffix starting with a hash (#) or slash (/)
* suffix.
**/
private boolean matches( String uri1, String uri2 ) {
return uri1.equals(uri2) || uri1.startsWith(uri2 + "/")
|| uri1.startsWith(uri2 + "#");
}

private void exec( UpdateRequest update ) {
if ( formUpdates ) {
// form updates
Expand All @@ -181,7 +188,7 @@ public int countTriples(String pid) {
// count triples
int triples = 0;
while ( results.hasNext() ) {
Triple t = results.next();
results.next();
triples++;
}
qexec.close();
Expand Down

0 comments on commit 0669895

Please sign in to comment.