Skip to content

Commit

Permalink
Pull request #83: Feature/KSAM-387 bebr poster indexeras inte
Browse files Browse the repository at this point in the history
Merge in KSAM/ksamsok from feature/KSAM-387-bebr-poster-indexeras-inte to master

* commit '83dcda68b13948b6a0ad9303f1e1d2b98eeb09fd':
  KSAM-387 Bättre felmeddelanden vid indexering
  KSAM-387 Bättre felmeddelanden vid indexering
  • Loading branch information
stefanmalmesjo committed Sep 21, 2020
2 parents 19f6557 + 83dcda6 commit 65b52a3
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand Down Expand Up @@ -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() +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
;
}

/**
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/se/raa/ksamsok/lucene/ContentHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
17 changes: 12 additions & 5 deletions src/main/java/se/raa/ksamsok/lucene/SamsokContentHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -58,6 +60,7 @@ public SamsokContentHelper(boolean requireMediaLicense) {
this.requireMediaLicense = requireMediaLicense;
}


@Override
public SolrInputDocument createSolrDocument(HarvestService service,
String xmlContent, Date added) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 65b52a3

Please sign in to comment.