*
* @return The ISO metadata object.
* @throws IOException If an I/O operation was necessary but failed.
*/
public Metadata read() throws IOException {
final DefaultMetadata metadata = new DefaultMetadata();
metadata.setMetadataStandardName(MetadataUtilities.STANDARD_NAME_2);
metadata.setMetadataStandardVersion(MetadataUtilities.STANDARD_VERSION_2);
final Identifier identifier = getFileIdentifier();
if (identifier != null) {
String code = identifier.getCode();
final Citation authority = identifier.getAuthority();
if (authority != null) {
final InternationalString title = authority.getTitle();
if (title != null) {
code = title.toString() + DefaultNameSpace.DEFAULT_SEPARATOR + code;
}
}
metadata.setFileIdentifier(code);
}
metadata.setDateStamp(decoder.dateValue(METADATA_CREATION));
metadata.getHierarchyLevels().add(ScopeCode.DATASET);
final String wms = decoder.stringValue("wms_service");
final String wcs = decoder.stringValue("wcs_service");
if (wms != null || wcs != null) {
metadata.getHierarchyLevels().add(ScopeCode.SERVICE);
}
/*
* Add the ResponsibleParty which is declared in global attributes, or in
* the THREDDS attributes if no information was found in global attributes.
*/
for (final String path : searchPath) {
decoder.setSearchPath(path);
final ResponsibleParty party = createResponsibleParty(CREATOR, true);
if (party != null && party != pointOfContact) {
addIfAbsent(metadata.getContacts(), party);
if (pointOfContact == null) {
pointOfContact = party;
}
}
}
/*
* Add the publisher AFTER the creator, because this method may
* reuse the 'creator' field (if non-null and if applicable).
*/
Set<InternationalString> publisher = null;
DefaultDistribution distribution = null;
for (final String path : searchPath) {
decoder.setSearchPath(path);
final ResponsibleParty party = createResponsibleParty(PUBLISHER, false);
if (party != null) {
if (distribution == null) {
distribution = new DefaultDistribution();
metadata.setDistributionInfo(distribution);
}
final DefaultDistributor distributor = new DefaultDistributor(party);
// TODO: There is some transfert option, etc. that we could set there.
// See UnidataDD2MI.xsl for options for OPeNDAP, THREDDS, etc.
addIfAbsent(distribution.getDistributors(), distributor);
publisher = addIfNonNull(publisher, toInternationalString(party.getIndividualName()));
}
// Also add history.
final String history = decoder.stringValue(HISTORY);
if (history != null) {
final DefaultDataQuality quality = new DefaultDataQuality();
final DefaultLineage lineage = new DefaultLineage();
lineage.setStatement(new SimpleInternationalString(history));
quality.setLineage(lineage);
addIfAbsent(metadata.getDataQualityInfo(), quality);
}
}
/*
* Add the identification info AFTER the responsible parties (both creator and publisher),
* because this method will reuse the 'creator' and 'publisher' information (if non-null).
*/
final DataIdentification identification = createIdentificationInfo(identifier, publisher);
if (identification != null) {
metadata.getIdentificationInfo().add(identification);
}
metadata.setContentInfo(createContentInfo());
/*
* Add the dimension information, if any. This metadata node
* is built from the NetCDF CoordinateSystem objects.
*/
for (final GridGeometry cs : decoder.getGridGeometries()) {
if (cs.getSourceDimensions() >= Variable.MIN_DIMENSION && cs.getTargetDimensions() >= Variable.MIN_DIMENSION) {
metadata.getSpatialRepresentationInfo().add(createSpatialRepresentationInfo(cs));
}
}
metadata.freeze();
return metadata;
}