List of usage examples for org.apache.solr.handler.loader XMLLoader readDoc
public SolrInputDocument readDoc(XMLStreamReader parser) throws XMLStreamException
From source file:org.roda.core.index.utils.SolrUtils.java
public static SolrInputDocument getDescriptiveMetadataFields(Binary binary, String metadataType, String metadataVersion) throws GenericException { SolrInputDocument doc;/*from ww w . j a va2 s.c om*/ Map<String, String> parameters = new HashMap<>(); parameters.put("prefix", RodaConstants.INDEX_OTHER_DESCRIPTIVE_DATA_PREFIX); Reader transformationResult = RodaUtils.applyMetadataStylesheet(binary, RodaConstants.CORE_CROSSWALKS_INGEST, metadataType, metadataVersion, parameters); try { XMLLoader loader = new XMLLoader(); XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader(transformationResult); boolean parsing = true; doc = null; while (parsing) { int event = parser.next(); if (event == XMLStreamConstants.END_DOCUMENT) { parser.close(); parsing = false; } else if (event == XMLStreamConstants.START_ELEMENT) { String currTag = parser.getLocalName(); if ("doc".equals(currTag)) { doc = loader.readDoc(parser); } } } } catch (XMLStreamException | FactoryConfigurationError e) { throw new GenericException("Could not process descriptive metadata binary " + binary.getStoragePath(), e); } finally { IOUtils.closeQuietly(transformationResult); } return doc == null ? new SolrInputDocument() : validateDescriptiveMetadataFields(doc); }
From source file:org.roda.core.index.utils.SolrUtils.java
public static SolrInputDocument premisToSolr(PreservationMetadataType preservationMetadataType, AIP aip, String representationUUID, String fileUUID, Binary binary) throws GenericException { SolrInputDocument doc;// ww w . java 2 s.co m Map<String, String> stylesheetOpt = new HashMap<>(); stylesheetOpt.put(RodaConstants.PRESERVATION_EVENT_OBJECT_CLASS, PreservationMetadataEventClass.REPOSITORY.toString()); if (aip != null) { stylesheetOpt.put(RodaConstants.PRESERVATION_EVENT_OBJECT_CLASS, PreservationMetadataEventClass.AIP.toString()); stylesheetOpt.put(RodaConstants.PRESERVATION_EVENT_AIP_ID, aip.getId()); if (representationUUID != null) { stylesheetOpt.put(RodaConstants.PRESERVATION_EVENT_REPRESENTATION_UUID, representationUUID); stylesheetOpt.put(RodaConstants.PRESERVATION_EVENT_OBJECT_CLASS, PreservationMetadataEventClass.REPRESENTATION.toString()); } if (fileUUID != null) { stylesheetOpt.put(RodaConstants.PRESERVATION_EVENT_FILE_UUID, fileUUID); stylesheetOpt.put(RodaConstants.PRESERVATION_EVENT_OBJECT_CLASS, PreservationMetadataEventClass.FILE.toString()); } } Reader reader = null; try { reader = RodaUtils.applyMetadataStylesheet(binary, RodaConstants.CORE_CROSSWALKS_INGEST_OTHER, RodaConstants.PREMIS_METADATA_TYPE, RodaConstants.PREMIS_METADATA_VERSION, stylesheetOpt); XMLLoader loader = new XMLLoader(); XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader(reader); boolean parsing = true; doc = null; while (parsing) { int event = parser.next(); if (event == XMLStreamConstants.END_DOCUMENT) { parser.close(); parsing = false; } else if (event == XMLStreamConstants.START_ELEMENT && "doc".equals(parser.getLocalName())) { doc = loader.readDoc(parser); } } } catch (XMLStreamException | FactoryConfigurationError e) { throw new GenericException("Could not process PREMIS " + binary.getStoragePath(), e); } finally { IOUtils.closeQuietly(reader); } if (preservationMetadataType == PreservationMetadataType.EVENT && doc != null) { try { List<LinkingIdentifier> agents = PremisV3Utils.extractAgentsFromEvent(binary); for (LinkingIdentifier id : agents) { doc.addField(RodaConstants.PRESERVATION_EVENT_LINKING_AGENT_IDENTIFIER, JsonUtils.getJsonFromObject(id)); } } catch (org.roda.core.data.v2.validation.ValidationException e) { LOGGER.warn("Error setting linking agent field: {}", e.getMessage()); } try { List<LinkingIdentifier> sources = PremisV3Utils.extractObjectFromEvent(binary); for (LinkingIdentifier id : sources) { doc.addField(RodaConstants.PRESERVATION_EVENT_LINKING_SOURCE_OBJECT_IDENTIFIER, JsonUtils.getJsonFromObject(id)); } } catch (org.roda.core.data.v2.validation.ValidationException e) { LOGGER.warn("Error setting linking source field: {}", e.getMessage()); } try { List<LinkingIdentifier> outcomes = PremisV3Utils.extractObjectFromEvent(binary); for (LinkingIdentifier id : outcomes) { doc.addField(RodaConstants.PRESERVATION_EVENT_LINKING_OUTCOME_OBJECT_IDENTIFIER, JsonUtils.getJsonFromObject(id)); } } catch (org.roda.core.data.v2.validation.ValidationException e) { LOGGER.warn("Error setting linking outcome field: {}", e.getMessage()); } // indexing active state and permissions if (aip != null) { doc.addField(RodaConstants.STATE, aip.getState().toString()); setPermissions(aip.getPermissions(), doc); } else { doc.addField(RodaConstants.STATE, AIPState.ACTIVE); } } // set uuid from id defined in xslt if (doc != null) { doc.addField(RodaConstants.INDEX_UUID, doc.getFieldValue(RodaConstants.PRESERVATION_EVENT_ID)); } else { doc = new SolrInputDocument(); } return doc; }