Search in sources :

Example 1 with RepositoryException

use of dk.dbc.opensearch.commons.repository.RepositoryException in project solr-document-store by DBCDK.

the class SolrWorker method deployRecords.

/**
 * Pushes records to SolrDocStore
 *
 * @param foXml   the original FoXML
 * @param updater Object containing all generated documents
 */
public void deployRecords(String foXml, SolrUpdaterCallback updater) {
    String trackingId = updater.getTrackingId();
    HashSet<String> marc002a = otherRecordIds.fromFoXML(foXml);
    try {
        String pid = updater.getPid();
        String unit = docBuilder.unitFor(pid);
        String work = docBuilder.workFor(unit);
        for (Map<String, Set<String>> updatedDocument : updater.getUpdatedDocuments()) {
            ObjectNode record = O.createObjectNode();
            String id = updatedDocument.get("id").iterator().next();
            makeMetadata(record, id, false, unit, work, trackingId, marc002a);
            ObjectNode document = record.putObject("indexKeys");
            for (Map.Entry<String, Set<String>> entry : updatedDocument.entrySet()) {
                ArrayNode documentKey = document.putArray(entry.getKey());
                for (String value : entry.getValue()) {
                    documentKey.add(value);
                }
            }
            sendRecordToSolrDocStore(id, record);
        }
        for (DeleteMessage deletedDocument : updater.getDeletedDocuments()) {
            ObjectNode record = O.createObjectNode();
            String id = deletedDocument.getDocumentId();
            makeMetadata(record, id, true, unit, work, trackingId, Collections.EMPTY_SET);
            sendRecordToSolrDocStore(id, record);
        }
    } catch (RepositoryException ex) {
        throw new RuntimeException("Defect unit structure", ex);
    } catch (JsonProcessingException ex) {
        throw new RuntimeException("Error making JSON", ex);
    } catch (IOException ex) {
        throw new RuntimeException("Error communicating with solrDocStore", ex);
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DeleteMessage(dk.dbc.solr.indexer.cloud.shared.DeleteMessage) RepositoryException(dk.dbc.opensearch.commons.repository.RepositoryException) IOException(java.io.IOException) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Map(java.util.Map) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 RepositoryException (dk.dbc.opensearch.commons.repository.RepositoryException)1 DeleteMessage (dk.dbc.solr.indexer.cloud.shared.DeleteMessage)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1