diff --git a/src/main/java/se/raa/ksamsok/harvest/HarvestRepositoryManagerImpl.java b/src/main/java/se/raa/ksamsok/harvest/HarvestRepositoryManagerImpl.java index ea91b46..08bc514 100755 --- a/src/main/java/se/raa/ksamsok/harvest/HarvestRepositoryManagerImpl.java +++ b/src/main/java/se/raa/ksamsok/harvest/HarvestRepositoryManagerImpl.java @@ -174,7 +174,6 @@ public void updateIndex(HarvestService service, Timestamp ts, HarvestService enc String xmlContent; Timestamp added; int i = 0; - int nonI = 0; int deleted = 0; ContentHelper helper = getContentHelper(service); ContentHelper.initProblemMessages(); @@ -195,10 +194,11 @@ public void updateIndex(HarvestService service, Timestamp ts, HarvestService enc } xmlContent = rs.getString("xmldata"); added = rs.getTimestamp("added"); - SolrInputDocument doc = helper.createSolrDocument(service, xmlContent, added); + SolrInputDocument doc; + doc = helper.createSolrDocument(service, xmlContent, added); if (doc == null) { - // inget dokument betyder att tjänsten har skickat itemForIndexing=n - ++nonI; + // Some error occured, it has been logged in createSolrDocument. + // Nothing to see here - carry on continue; } docs.add(doc); @@ -247,7 +247,6 @@ public void updateIndex(HarvestService service, Timestamp ts, HarvestService enc String speed = ContentHelper.formatSpeedPerSec(count, durationMillis); ss.setStatusTextAndLog(service, "Updated index, " + i + " records (" + (ts == null ? "delete + insert" : "updated incl " + deleted + " deleted") + - (nonI > 0 ? ", itemForIndexing=n: " + nonI : "") + "), time: " + runTime + " (" + speed + ")"); if (logger.isInfoEnabled()) { logger.info(service.getId() + diff --git a/src/main/java/se/raa/ksamsok/lucene/BaseSamsokProtocolHandler.java b/src/main/java/se/raa/ksamsok/lucene/BaseSamsokProtocolHandler.java index 5d7dfd8..09c07ba 100644 --- a/src/main/java/se/raa/ksamsok/lucene/BaseSamsokProtocolHandler.java +++ b/src/main/java/se/raa/ksamsok/lucene/BaseSamsokProtocolHandler.java @@ -9,10 +9,12 @@ import org.apache.jena.rdf.model.SimpleSelector; import org.apache.jena.rdf.model.Statement; import org.apache.jena.rdf.model.StmtIterator; +import org.apache.jena.sparql.pfunction.library.str; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.solr.common.SolrInputDocument; import se.raa.ksamsok.harvest.HarvestService; +import se.raa.ksamsok.lucene.exception.SamsokProtocolException; import java.net.URI; import java.util.Date; @@ -491,9 +493,8 @@ void extractMediaLicense(Resource cS) throws Exception { ip.setCurrent(IX_MEDIALICENSE, false); // uri, ingen uppslagning fn final String mediaLicense = extractValue(model, cS, getURIRef(uri_rMediaLicense), null, ip); if (requireMediaLicense && mediaLicense == null) { - throw new Exception("Missing mediaLicense for identifier " + subject.toString()); + throw new SamsokProtocolException("Missing mediaLicense","for identifier " + subject.toString()); } - ; } /** diff --git a/src/main/java/se/raa/ksamsok/lucene/ContentHelper.java b/src/main/java/se/raa/ksamsok/lucene/ContentHelper.java index e317ab4..5078486 100755 --- a/src/main/java/se/raa/ksamsok/lucene/ContentHelper.java +++ b/src/main/java/se/raa/ksamsok/lucene/ContentHelper.java @@ -622,14 +622,13 @@ public ContentHelper() {} * Skapar ett solr-dokument utifrån det inskickade xml-innehållet. För k-samsökstjänster är * xml-innehållet en post med k-samsöks-xml (rdf). Om metoden ger null har tjänsten begärt att * posten bara ska lagras och inte indexeras. - * + * * @param service tjänst * @param xmlContent xml-innehåll * @param added datum posten först lades till i repot * @return ett solr-dokument, eller null om inte posten ska indexeras */ - public abstract SolrInputDocument createSolrDocument(HarvestService service, String xmlContent, Date added) - ; + public abstract SolrInputDocument createSolrDocument(HarvestService service, String xmlContent, Date added); // statiska metoder diff --git a/src/main/java/se/raa/ksamsok/lucene/SamsokContentHelper.java b/src/main/java/se/raa/ksamsok/lucene/SamsokContentHelper.java index 49eec91..ea46533 100755 --- a/src/main/java/se/raa/ksamsok/lucene/SamsokContentHelper.java +++ b/src/main/java/se/raa/ksamsok/lucene/SamsokContentHelper.java @@ -17,6 +17,7 @@ import org.xml.sax.SAXException; import se.raa.ksamsok.harvest.ExtractedInfo; import se.raa.ksamsok.harvest.HarvestService; +import se.raa.ksamsok.lucene.exception.SamsokProtocolException; import se.raa.ksamsok.spatial.GMLUtil; import javax.vecmath.Point2d; @@ -35,6 +36,7 @@ import java.io.StringWriter; import java.nio.charset.StandardCharsets; import java.util.Date; +import java.util.HashMap; import java.util.LinkedList; import static se.raa.ksamsok.lucene.RDFUtil.extractSingleValue; @@ -58,6 +60,7 @@ public SamsokContentHelper(boolean requireMediaLicense) { this.requireMediaLicense = requireMediaLicense; } + @Override public SolrInputDocument createSolrDocument(HarvestService service, String xmlContent, Date added) { @@ -97,7 +100,7 @@ public SolrInputDocument createSolrDocument(HarvestService service, // specialfall i resolverservleten då den främst jobbar mot lucene-indexet String itemForIndexing = RDFUtil.extractSingleValue(model, subject, rItemForIndexing, null); if ("n".equals(itemForIndexing)) { - return null; + throw new Exception ("ItemForIndexing = 'n':"); } String protocolVersion = RDFUtil.extractSingleValue(model, subject, rProtocolVersion, null); if (protocolVersion == null) { @@ -188,10 +191,14 @@ public SolrInputDocument createSolrDocument(HarvestService service, byte[] rdfBytes = xmlContent.getBytes(StandardCharsets.UTF_8); luceneDoc.addField(I_IX_RDF, Base64.byteArrayToBase64(rdfBytes, 0, rdfBytes.length)); - } catch (Exception e) { - // TODO: kasta exception/räkna felen/annat? - logger.error("Fel vid skapande av lucenedokument för " + identifier + ": " + e.getMessage()); - //throw e; + } + catch (Exception e) { + addProblemMessage(e.getMessage()); + String errorMessage = "Fel vid skapande av lucenedokument för " + identifier + ": " + e.getMessage(); + if (e instanceof SamsokProtocolException) { + errorMessage = errorMessage + " " + ((SamsokProtocolException) e).getSpecificMessage(); + logger.error(errorMessage); + } } finally { if (model != null) { model.close(); diff --git a/src/main/java/se/raa/ksamsok/lucene/exception/SamsokProtocolException.java b/src/main/java/se/raa/ksamsok/lucene/exception/SamsokProtocolException.java new file mode 100644 index 0000000..ae6ee3d --- /dev/null +++ b/src/main/java/se/raa/ksamsok/lucene/exception/SamsokProtocolException.java @@ -0,0 +1,17 @@ +package se.raa.ksamsok.lucene.exception; + +import se.raa.ksamsok.lucene.SamsokProtocol; + +public class SamsokProtocolException extends Exception { + + String specificMessage; + + public SamsokProtocolException(String generalMessage, String specificMessage) { + super(generalMessage); + this.specificMessage = specificMessage; + } + + public String getSpecificMessage() { + return specificMessage; + } +}