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

Commit

Permalink
Merge pull request #25 from futures/SonarFixes
Browse files Browse the repository at this point in the history
Sonar fixes
  • Loading branch information
ajs6f committed Dec 17, 2013
2 parents cac6a03 + a65712e commit 7f4103e
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 47 deletions.
Expand Up @@ -17,13 +17,15 @@
package org.fcrepo.indexer;

import static com.google.common.base.Throwables.propagate;
import static java.util.Locale.US;
import static org.apache.commons.lang.StringUtils.substringAfterLast;
import static org.fcrepo.indexer.Indexer.IndexerType.NAMEDFIELDS;
import static org.slf4j.LoggerFactory.getLogger;

import java.io.File;
import java.io.FileWriter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.text.SimpleDateFormat;
import java.util.Date;
Expand All @@ -44,13 +46,15 @@ public class FileSerializer extends SynchIndexer<NamedFields, File> {
private static final Logger LOGGER = getLogger(FileSerializer.class);

private static SimpleDateFormat fmt =
new SimpleDateFormat("yyyyMMddHHmmss");
new SimpleDateFormat("yyyyMMddHHmmss", US);

private File path;

/**
* Set path to write files.
**/
*
* @param pathName
*/
public void setPath( final String pathName ) {
this.path = new File(pathName);
if (!this.path.exists()) {
Expand All @@ -59,7 +63,9 @@ public void setPath( final String pathName ) {
}
/**
* Return path where files are written.
**/
*
* @return
*/
public String getPath() {
return path.getAbsolutePath();
}
Expand All @@ -82,13 +88,17 @@ public Callable<File> updateSynch(final String pid, final NamedFields content) {
@Override
public File call() {
// write content to disk
try (Writer w = new FileWriter(file)) {
try (
Writer w =
new OutputStreamWriter(new FileOutputStream(file),
"UTF8")) {
if (content.isEmpty()) {
w.write("");
} else {
w.write(content.toString());
}
} catch (final IOException e) {
LOGGER.error("Failed to write to file: {}", file);
propagate(e);
}
return file;
Expand Down
Expand Up @@ -36,16 +36,22 @@ public interface Indexer<Content> {

/**
* Create or update an index entry for the object.
*
* @param id
* @param content
* @return the results of addition
**/
public ListenableFuture<?> update(final String pid, final Content content) throws IOException;
* @throws IOException
*/
public ListenableFuture<?> update(final String id, final Content content) throws IOException;

/**
* Remove the object from the index.
* @return the results of removal
*
**/
public ListenableFuture<?> remove(final String pid) throws IOException;
* @param id
* @return the results of removal
* @throws IOException
*/
public ListenableFuture<?> remove(final String id) throws IOException;

/**
* @return What kind of indexer this is.
Expand Down
Expand Up @@ -127,15 +127,19 @@ public String getRepositoryURL() {

/**
* Set indexers for this group.
**/
*
* @param indexers
*/
public void setIndexers(final Set<Indexer<Object>> indexers) {
this.indexers = indexers;
LOGGER.debug("Using indexer complement: {} ", indexers);
}

/**
* Get indexers set for this group.
**/
*
* @return indexers
*/
public Set<Indexer<Object>> getIndexers() {
return indexers;
}
Expand Down Expand Up @@ -197,19 +201,17 @@ public void onMessage(final Message message) {
content = nfr.get();
hasContent = true;
} catch (final AbsentTransformPropertyException e) {
LOGGER.error("Failed to retrieve indexable content:"
+ "could not find transform property!");
hasContent = false;
}
break;
case RDF:
LOGGER.debug(
"Retrieving RDF for: {}, (may be cached) to index to {}...",
pid, indexer);
try {
content = rdfr.get();
hasContent = true;
} catch (final AbsentTransformPropertyException e1) {
hasContent = false;
}
content = rdfr.get();
hasContent = true;
break;
default:
hasContent = true;
Expand Down Expand Up @@ -243,9 +245,6 @@ public void onMessage(final Message message) {

} catch (final JMSException e) {
LOGGER.error("Error processing JMS event!", e);
} catch (final AbsentTransformPropertyException e2) {
// cannot be thrown here: simply an artifact of Java's crappy type
// system
}
}

Expand Down
Expand Up @@ -16,6 +16,7 @@

package org.fcrepo.indexer;

import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.ImmutableList.builder;
import static com.google.common.collect.Maps.transformValues;
import static org.slf4j.LoggerFactory.getLogger;
Expand Down Expand Up @@ -60,8 +61,10 @@ public class NamedFieldsDeserializer extends TypeAdapter<NamedFields> {

@Override
public List<String> apply(final JsonElement input) {
final JsonElement json =
checkNotNull(input, "Cannot transform null!");
final ImmutableList.Builder<String> b = builder();
for (final JsonElement value : input.getAsJsonArray()) {
for (final JsonElement value : json.getAsJsonArray()) {
b.add(value.getAsString());
}
return b.build();
Expand Down Expand Up @@ -93,6 +96,7 @@ public NamedFields read(final JsonReader in)

/**
* @param gson the Gson engine to set
* @return this object for continued use
*/
public NamedFieldsDeserializer setGson(final Gson gson) {
this.gson = gson;
Expand Down
Expand Up @@ -64,6 +64,8 @@ public class NamedFieldsRetriever implements Supplier<NamedFields> {
/**
* @param uri
* @param client
* @param rdfr Used to determine the transform to use with this indexing
* step
*/
public NamedFieldsRetriever(final String uri, final HttpClient client,
final Supplier<Model> rdfr) {
Expand Down Expand Up @@ -108,7 +110,8 @@ public NamedFields get() {
}
try (
Reader r =
new InputStreamReader(response.getEntity().getContent())) {
new InputStreamReader(response.getEntity().getContent(),
"UTF8")) {
return gson.fromJson(r, typeToken);
}

Expand Down
Expand Up @@ -73,7 +73,8 @@ public Model get() {
if (response.getStatusLine().getStatusCode() == SC_OK) {
try (
Reader r =
new InputStreamReader(response.getEntity().getContent())) {
new InputStreamReader(
response.getEntity().getContent(), "UTF8")) {
return createDefaultModel().read(r, "", "N3");
}
} else {
Expand Down
Expand Up @@ -29,15 +29,12 @@
import java.util.Map;
import java.util.concurrent.Callable;

import javax.inject.Inject;

import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.response.UpdateResponse;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.SolrInputField;
import org.fcrepo.indexer.AsynchIndexer;
import org.fcrepo.indexer.IndexerGroup;
import org.fcrepo.indexer.NamedFields;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -74,11 +71,9 @@ public class SolrIndexer extends AsynchIndexer<NamedFields, UpdateResponse> {

private static final Logger LOGGER = getLogger(SolrIndexer.class);

@Inject
private IndexerGroup indexerGroup;

/**
* @Autowired solrServer instance is auto-@Autowired in indexer-core.xml
* @param solrServer
*/
@Autowired
public SolrIndexer(final SolrServer solrServer) {
Expand All @@ -92,7 +87,7 @@ public Callable<UpdateResponse> updateSynch(final String id,
return new Callable<UpdateResponse>() {

@Override
public UpdateResponse call() throws Exception {
public UpdateResponse call() {
try {
LOGGER.debug(
"Executing request to Solr index for identifier: {} with fields: {}",
Expand Down Expand Up @@ -149,7 +144,7 @@ public Callable<UpdateResponse> removeSynch(final String pid) {
return new Callable<UpdateResponse>() {

@Override
public UpdateResponse call() throws Exception {
public UpdateResponse call() {
try {
final UpdateResponse resp = server.deleteById(pid);
if (resp.getStatus() == 0) {
Expand Down
Expand Up @@ -16,7 +16,6 @@

package org.fcrepo.indexer.sparql;

import static com.google.common.base.Throwables.propagate;
import static com.google.common.util.concurrent.MoreExecutors.listeningDecorator;
import static com.hp.hpl.jena.sparql.util.Context.emptyContext;
import static com.hp.hpl.jena.update.UpdateExecutionFactory.createRemoteForm;
Expand All @@ -29,6 +28,7 @@
import java.io.OutputStream;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.concurrent.Callable;

import com.google.common.util.concurrent.ListenableFutureTask;
Expand Down Expand Up @@ -81,13 +81,7 @@ public class SparqlIndexer extends AsynchIndexer<Model, Void> {
public Callable<Void> updateSynch(final String pid,
final Model model) {
LOGGER.debug("Received update for: {}", pid);
// first remove old data
try {
remove(pid);
} catch (final IOException e) {
propagate(e);
}

removeSynch(pid);
// build a list of triples
final StmtIterator triples = model.listStatements();
final QuadDataAcc add = new QuadDataAcc();
Expand All @@ -114,7 +108,7 @@ public Callable<Void> removeSynch(final String subject) {
final Iterator<Triple> results = qexec.execDescribeTriples();

// build list of triples to delete
final HashSet<String> uris = new HashSet<>();
final Set<String> uris = new HashSet<>();
while ( results.hasNext() ) {
final Triple triple = results.next();

Expand Down Expand Up @@ -164,7 +158,7 @@ private Callable<Void> exec(final UpdateRequest update) {
return new Callable<Void>() {

@Override
public Void call() throws Exception {
public Void call() {
return null;
}
};
Expand Down Expand Up @@ -225,10 +219,13 @@ public void run() {

/**
* Count the number of triples in the triplestore for a Fedora object.
**/
public int countTriples(final String pid) {
*
* @param uri
* @return the number of triples
*/
public int countTriples(final String uri) {
// perform describe query
final String describeQuery = "DESCRIBE <" + pid + ">";
final String describeQuery = "DESCRIBE <" + uri + ">";
final QueryEngineHTTP qexec = new QueryEngineHTTP( queryBase, describeQuery );
final Iterator<Triple> results = qexec.execDescribeTriples();

Expand Down
Expand Up @@ -79,7 +79,7 @@ public Callable<ActionResponse> removeSynch(final String id) {
return new Callable<ActionResponse>() {

@Override
public ActionResponse call() throws Exception {
public ActionResponse call() {
return client.prepareDelete(getIndexName(),
getSearchIndexType(), id).execute().actionGet();
}
Expand All @@ -92,7 +92,7 @@ public Callable<ActionResponse> updateSynch(final String id,
return new Callable<ActionResponse>() {

@Override
public ActionResponse call() throws Exception {
public ActionResponse call() {
return client.prepareIndex(indexName, searchIndexType, id)
.execute().actionGet();

Expand Down

0 comments on commit 7f4103e

Please sign in to comment.