From 83bf6a7f1d4ad9b749f813702880c95eb31b39c3 Mon Sep 17 00:00:00 2001 From: agazzarini Date: Thu, 9 Apr 2015 11:29:39 +0200 Subject: [PATCH] [ issue #12 ] Additional messages in MessageCatalog --- .../update/RdfBulkUpdateRequestHandler.java | 46 +++++++++++++++++-- .../update/RdfUpdateRequestHandler.java | 17 +++++++ .../update/Sparql11UpdateRdfDataLoader.java | 13 ++++-- .../labs/solrdf/log/MessageCatalog.java | 7 ++- 4 files changed, 74 insertions(+), 9 deletions(-) diff --git a/solrdf/src/main/java/org/gazzax/labs/solrdf/handler/update/RdfBulkUpdateRequestHandler.java b/solrdf/src/main/java/org/gazzax/labs/solrdf/handler/update/RdfBulkUpdateRequestHandler.java index ae134f1..1859258 100644 --- a/solrdf/src/main/java/org/gazzax/labs/solrdf/handler/update/RdfBulkUpdateRequestHandler.java +++ b/solrdf/src/main/java/org/gazzax/labs/solrdf/handler/update/RdfBulkUpdateRequestHandler.java @@ -5,6 +5,7 @@ import java.io.Reader; import java.util.HashMap; import java.util.Map; +import java.util.Map.Entry; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -28,6 +29,8 @@ import org.apache.solr.update.processor.UpdateRequestProcessor; import org.gazzax.labs.solrdf.Names; import org.gazzax.labs.solrdf.graph.SolRDFDatasetGraph; +import org.gazzax.labs.solrdf.log.MessageCatalog; +import org.gazzax.labs.solrdf.log.MessageFactory; import com.hp.hpl.jena.graph.Graph; import com.hp.hpl.jena.graph.NodeFactory; @@ -36,7 +39,7 @@ import com.hp.hpl.jena.sparql.core.Quad; /** - * A subclass of {@link UpdateRequestHandler} for handlong RDF bulk loadings. + * A subclass of {@link UpdateRequestHandler} for handling RDF bulk loadings. * * @author Andrea Gazzarini * @since 1.0 @@ -81,6 +84,11 @@ public void run() { dataset.add(iterator.next()); } } + + @Override + public String toString() { + return "Quads Loader"; + }; }; final ContentStreamLoader triplesLoader = new ContentStreamLoader() { @@ -107,7 +115,10 @@ public void run() { } } }); - + + // Graph Store Protocol indicates the target graph URI separately. + // So the incoming Content-type here is one that maps "Triples Loader" but + // the indexed tuple could be a Quad. final String graphUri = request.getParams().get(Names.GRAPH_URI_ATTRIBUTE_NAME); final DatasetGraph dataset = new SolRDFDatasetGraph(request, response, null, null); @@ -118,6 +129,11 @@ public void run() { defaultGraph.add(iterator.next()); } } + + @Override + public String toString() { + return "Triples Loader"; + }; }; @Override @@ -127,15 +143,24 @@ public void load( final ContentStream stream, final UpdateRequestProcessor processor) throws Exception { + // Default ContentStream implementation starts reading the stream and + // if it starts with '<' then it assumes a content type of "application/xml", + // if it starts with '{' then it assumes a content type of "application/json" + // This behaviour is wrong is SolRDF and maybe we need a custom ContentStream here + // At the moment this is just a workaround: final String contentType = stream.getContentType() != null && !"application/xml".equals(stream.getContentType()) && !"application/json".equals(stream.getContentType()) ? stream.getContentType() : request.getParams().get(UpdateParams.ASSUME_CONTENT_TYPE); + log.debug(MessageCatalog._00094_BULK_LOADER_CT, contentType); + final Lang lang = RDFLanguages.contentTypeToLang(contentType); if (lang == null) { - throw new SolrException(ErrorCode.BAD_REQUEST, "Unknown Content-type: " + contentType); + final String message = MessageFactory.createMessage(MessageCatalog._00095_INVALID_CT, contentType); + log.error(message); + throw new SolrException(ErrorCode.BAD_REQUEST, message); } final ContentStreamLoader delegate = @@ -143,6 +168,8 @@ public void load( ? quadsLoader : triplesLoader; + log.debug(MessageCatalog._00096_SELECTED_BULK_LOADER, contentType, delegate); + delegate.load( request, response, @@ -191,6 +218,10 @@ protected Map createDefaultLoaders(final NamedList } registry.put(WebContent.contentTypeSPARQLUpdate, new Sparql11UpdateRdfDataLoader()); + if (log.isDebugEnabled()) { + prettyPrint(registry); + } + return registry; } @@ -203,4 +234,13 @@ public String getDescription() { public String getSource() { return "$https://github.com/agazzarini/SolRDF/blob/master/solrdf/src/main/java/org/gazzax/labs/solrdf/handler/update/RdfBulkUpdateRequestHandler.java $"; } + + /** + * Debugs the registry content. + */ + void prettyPrint(final Map registry) { + for (final Entry entry : registry.entrySet()) { + log.debug(MessageCatalog._00097_BULK_LOADER_REGISTRY_ENTRY, entry.getKey(), entry.getValue()); + } + } } \ No newline at end of file diff --git a/solrdf/src/main/java/org/gazzax/labs/solrdf/handler/update/RdfUpdateRequestHandler.java b/solrdf/src/main/java/org/gazzax/labs/solrdf/handler/update/RdfUpdateRequestHandler.java index d48686a..9db54de 100644 --- a/solrdf/src/main/java/org/gazzax/labs/solrdf/handler/update/RdfUpdateRequestHandler.java +++ b/solrdf/src/main/java/org/gazzax/labs/solrdf/handler/update/RdfUpdateRequestHandler.java @@ -2,11 +2,13 @@ import java.util.HashMap; import java.util.Map; +import java.util.Map.Entry; import org.apache.jena.riot.WebContent; import org.apache.solr.common.util.NamedList; import org.apache.solr.handler.UpdateRequestHandler; import org.apache.solr.handler.loader.ContentStreamLoader; +import org.gazzax.labs.solrdf.log.MessageCatalog; /** * An {@link UpdateRequestHandler} implementation for handling SPARQL updates. @@ -24,6 +26,11 @@ protected Map createDefaultLoaders(final NamedList final Map registry = new HashMap(); registry.put("application/rdf+xml", new Sparql11UpdateRdfDataLoader()); registry.put(WebContent.contentTypeSPARQLUpdate, new Sparql11UpdateRdfDataLoader()); + + if (log.isDebugEnabled()) { + prettyPrint(registry); + } + return registry; } @@ -36,4 +43,14 @@ public String getDescription() { public String getSource() { return "https://github.com/agazzarini/SolRDF"; } + + /** + * Debugs the registry content. + */ + void prettyPrint(final Map registry) { + for (final Entry entry : registry.entrySet()) { + log.debug(MessageCatalog._00098_UPDATE_HANDLER_REGISTRY_ENTRY, entry.getKey(), entry.getValue()); + } + } + } \ No newline at end of file diff --git a/solrdf/src/main/java/org/gazzax/labs/solrdf/handler/update/Sparql11UpdateRdfDataLoader.java b/solrdf/src/main/java/org/gazzax/labs/solrdf/handler/update/Sparql11UpdateRdfDataLoader.java index c2d3b45..7ebc14c 100644 --- a/solrdf/src/main/java/org/gazzax/labs/solrdf/handler/update/Sparql11UpdateRdfDataLoader.java +++ b/solrdf/src/main/java/org/gazzax/labs/solrdf/handler/update/Sparql11UpdateRdfDataLoader.java @@ -11,6 +11,9 @@ import org.apache.solr.response.SolrQueryResponse; import org.apache.solr.update.processor.UpdateRequestProcessor; import org.gazzax.labs.solrdf.graph.SolRDFDatasetGraph; +import org.gazzax.labs.solrdf.log.Log; +import org.gazzax.labs.solrdf.log.MessageCatalog; +import org.slf4j.LoggerFactory; import com.hp.hpl.jena.update.UpdateAction; import com.hp.hpl.jena.update.UpdateFactory; @@ -25,7 +28,7 @@ * @since 1.0 */ class Sparql11UpdateRdfDataLoader extends ContentStreamLoader { - static final int READ_BUFFER_DEFAULT_SIZE = 512; + private final static Log LOGGER = new Log(LoggerFactory.getLogger(Sparql11UpdateRdfDataLoader.class)); @Override public void load( @@ -36,12 +39,12 @@ public void load( final String q = request.getParams().get(CommonParams.Q); if (isNullOrEmpty(q)) { - throw new SolrException(ErrorCode.BAD_REQUEST, "Invalid query : " + q); + LOGGER.error(MessageCatalog._00099_INVALID_UPDATE_QUERY); + throw new SolrException(ErrorCode.BAD_REQUEST, MessageCatalog._00099_INVALID_UPDATE_QUERY); } UpdateAction.execute( - UpdateFactory.create( - request.getParams().get(CommonParams.Q)), - new SolRDFDatasetGraph(request, response)); + UpdateFactory.create(q), + new SolRDFDatasetGraph(request, response)); } } \ No newline at end of file diff --git a/solrdf/src/main/java/org/gazzax/labs/solrdf/log/MessageCatalog.java b/solrdf/src/main/java/org/gazzax/labs/solrdf/log/MessageCatalog.java index cbb75c2..4631d55 100644 --- a/solrdf/src/main/java/org/gazzax/labs/solrdf/log/MessageCatalog.java +++ b/solrdf/src/main/java/org/gazzax/labs/solrdf/log/MessageCatalog.java @@ -14,5 +14,10 @@ public interface MessageCatalog { String _00091_NULL_QUERY_OR_EXECUTION = PREFIX + "-00091> : Query or QueryExecution cannot be null."; String _00092_NEGOTIATED_CONTENT_TYPE = PREFIX + "-00092> : Query type %s, incoming Accept header is %s, applied Content-type is %s"; String _00093_GSP_REQUEST = PREFIX + "-00093> : Incoming GraphStoreProtocol %s request on %s Graph."; - + String _00094_BULK_LOADER_CT = PREFIX + "-00094> : Content-type of the incoming stream: %s"; + String _00095_INVALID_CT = PREFIX + "-00095> : Unsupported / Unknown Content-type: %s"; + String _00096_SELECTED_BULK_LOADER = PREFIX + "-00096> : Incoming stream with Content-type %s has been associated with %s"; + String _00097_BULK_LOADER_REGISTRY_ENTRY = PREFIX + "-00097> : New Bulk Loader registry entry: %s => %s"; + String _00098_UPDATE_HANDLER_REGISTRY_ENTRY = PREFIX + "-00098> : New Bulk Loader registry entry: %s => %s"; + String _00099_INVALID_UPDATE_QUERY = PREFIX + "-00099> : Invalid (empty or null) query."; } \ No newline at end of file