private static Set<DcsMetadata> getMetadataSet(SolrDocument doc) { Set<DcsMetadata> set = new HashSet<DcsMetadata>(); String[] schemas = setgetAll(doc, MetadataField.SCHEMA); String[] texts = setgetAll(doc, MetadataField.TEXT); for (int i = 0; i < schemas.length; i++) { DcsMetadata md = new DcsMetadata(); md.setMetadata(texts[i]); if (schemas[i] != null && schemas[i].trim().length() > 0) { md.setSchemaUri(schemas[i]); } set.add(md); } return set; }
private DcsMetadata createMetaData() { DcsMetadata md = new DcsMetadata(); md.setSchemaUri(randomString(10, false)); md.setMetadata(randomXML(3)); return md; }
@Override public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { final String schemaUri = reader.getAttribute(A_SCHEMA); final String mdRef = reader.getAttribute(A_REF); // If we are dealing with a reference, create the reference and return if (!isEmptyOrNull(mdRef)) { final DcsMetadataRef ref = new DcsMetadataRef(); ref.setRef(mdRef); return ref; } // Otherwise we're dealing with a full, in-line DcsMetadata object final DcsMetadata md = new DcsMetadata(); if (!isEmptyOrNull(schemaUri)) { md.setSchemaUri(schemaUri); } final ByteArrayOutputStream out = new ByteArrayOutputStream(); reader.moveDown(); try { ((DcsStaxReader) reader.underlyingReader()).copyNode(out); } catch (XMLStreamException e) { throw new ConversionException(e.getMessage(), e); } reader.moveUp(); final String mdValue = new String(out.toByteArray(), Charset.forName("UTF-8")); md.setMetadata(mdValue); log.trace("Deserialized metadata blob \n{}", mdValue); return md; }
@Override public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { final String schemaUri = reader.getAttribute(A_SCHEMA); final String mdRef = reader.getAttribute(A_REF); // If we are dealing with a reference, create the reference and return if (!isEmptyOrNull(mdRef)) { final DcsMetadataRef ref = new DcsMetadataRef(); ref.setRef(mdRef); return ref; } // Otherwise we're dealing with a full, in-line DcsMetadata object final DcsMetadata md = new DcsMetadata(); if (!isEmptyOrNull(schemaUri)) { md.setSchemaUri(schemaUri); } final ByteArrayOutputStream out = new ByteArrayOutputStream(); reader.moveDown(); try { ((DcsStaxReader) reader.underlyingReader()).copyNode(out); } catch (XMLStreamException e) { throw new ConversionException(e.getMessage(), e); } reader.moveUp(); final String mdValue = new String(out.toByteArray(), Charset.forName("UTF-8")); md.setMetadata(mdValue); log.trace("Deserialized metadata blob \n{}", mdValue); return md; }
@Override public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { final String schemaUri = reader.getAttribute(A_SCHEMA); final String mdRef = reader.getAttribute(A_REF); // If we are dealing with a reference, create the reference and return if (!isEmptyOrNull(mdRef)) { final DcsMetadataRef ref = new DcsMetadataRef(); ref.setRef(mdRef); return ref; } // Otherwise we're dealing with a full, in-line DcsMetadata object final DcsMetadata md = new DcsMetadata(); if (!isEmptyOrNull(schemaUri)) { md.setSchemaUri(schemaUri); } final ByteArrayOutputStream out = new ByteArrayOutputStream(); reader.moveDown(); try { ((DcsStaxReader) reader.underlyingReader()).copyNode(out); } catch (XMLStreamException e) { throw new RuntimeException("Unmarshalling failed", e); } reader.moveUp(); final String metadataAsString = new String(out.toByteArray(), Charset.forName("UTF-8")); md.setMetadata(metadataAsString); return md; }