private Map<String, Integer> getFileCountByFormat(Set<AttributeSet> fileAttributeSets) { //TODO: map keyed by format's name. keyed by DcsFormat object would be more reliable. Report consumer can //decide what field of DcsFormat to use. But IngestReport doesn't current support mapping keyed on DcsFormat type. Map<String, Integer> fileCountByFormat = new HashMap<String, Integer>(); for (AttributeSet fileAttributeSet : fileAttributeSets) { //extract file-formats java.util.Collection<Attribute> matchingAttributes = fileAttributeSet.getAttributesByName(Metadata.FILE_FORMAT); for (Attribute attribute : matchingAttributes) { if (attribute.getType().equals(AttributeValueType.DCS_FORMAT)) { DcsFormat format = DcsFormat.parseDcsFormat(attribute.getValue()); // Only add the Pronom format to the report to be displayed or the unknown mime-type // (application/octet-stream) if (format.getSchemeUri().contains("PRONOM") || format.getName().equalsIgnoreCase("application/octet-stream")) { // if an entry for this format does not exist yet if (!fileCountByFormat.containsKey(format.getName())) { // create the new entry fileCountByFormat.put(format.getName(), 0); } // increase count for the format entry. fileCountByFormat.put(format.getName(), fileCountByFormat.get(format.getName()) + 1); } } } } return fileCountByFormat; } /**
/** * Copy constructor for a DcsFormat. The state of <code>toCopy</code> is copied * to this. * * @param toCopy the dcs format to copy */ public DcsFormat(DcsFormat toCopy) { this.format = toCopy.getFormat(); this.version = toCopy.getVersion(); this.name = toCopy.getName(); this.schemeUri = toCopy.getSchemeUri(); }
private static void addFormatSet(SolrInputDocument doc, Collection<DcsFormat> set) { if (set == null || set.size() == 0) { return; } for (DcsFormat fmt : set) { setadd(doc, FormatField.NAME, fmt.getName()); setadd(doc, FormatField.FORMAT, fmt.getFormat()); setadd(doc, FormatField.SCHEMA, fmt.getSchemeUri()); setadd(doc, FormatField.VERSION, fmt.getVersion()); } }
@Override public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { super.marshal(source, writer, context); final DcsFormat format = (DcsFormat) source; writer.startNode(E_ID); if (format.getSchemeUri() != null) { writer.addAttribute(A_SCHEME, format.getSchemeUri()); } if (format.getFormat() != null) { writer.setValue(format.getFormat()); } writer.endNode(); if (format.getName() != null) { writer.startNode(E_NAME); writer.setValue(format.getName()); writer.endNode(); } if (format.getVersion() != null) { writer.startNode(E_VERSION); writer.setValue(format.getVersion()); writer.endNode(); } }
@Override public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { super.marshal(source, writer, context); final DcsFormat format = (DcsFormat) source; writer.startNode(E_ID); if (format.getSchemeUri() != null) { writer.addAttribute(A_SCHEME, format.getSchemeUri()); } if (format.getFormat() != null) { writer.setValue(format.getFormat()); } writer.endNode(); if (format.getName() != null) { writer.startNode(E_NAME); writer.setValue(format.getName()); writer.endNode(); } if (format.getVersion() != null) { writer.startNode(E_VERSION); writer.setValue(format.getVersion()); writer.endNode(); } }