use of com.google.android.exoplayer2.metadata.Metadata in project dhis2-core by dhis2.
the class DefaultGmlImportService method preProcessGml.
// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
private PreProcessingResult preProcessGml(InputStream inputStream) {
InputStream dxfStream = null;
Metadata metadata = null;
try {
dxfStream = transformGml(inputStream);
metadata = renderService.fromXml(dxfStream, Metadata.class);
} catch (IOException | TransformerException e) {
return PreProcessingResult.failure(e);
} finally {
IOUtils.closeQuietly(dxfStream);
}
Map<String, OrganisationUnit> uidMap = Maps.newHashMap(), codeMap = Maps.newHashMap(), nameMap = Maps.newHashMap();
matchAndFilterOnIdentifiers(metadata.getOrganisationUnits(), uidMap, codeMap, nameMap);
Map<String, OrganisationUnit> persistedUidMap = getMatchingPersistedOrgUnits(uidMap.keySet(), IdentifiableProperty.UID);
Map<String, OrganisationUnit> persistedCodeMap = getMatchingPersistedOrgUnits(codeMap.keySet(), IdentifiableProperty.CODE);
Map<String, OrganisationUnit> persistedNameMap = getMatchingPersistedOrgUnits(nameMap.keySet(), IdentifiableProperty.NAME);
Iterator<OrganisationUnit> persistedIterator = Iterators.concat(persistedUidMap.values().iterator(), persistedCodeMap.values().iterator(), persistedNameMap.values().iterator());
while (persistedIterator.hasNext()) {
OrganisationUnit persisted = persistedIterator.next(), imported = null;
if (!Strings.isNullOrEmpty(persisted.getUid()) && uidMap.containsKey(persisted.getUid())) {
imported = uidMap.get(persisted.getUid());
} else if (!Strings.isNullOrEmpty(persisted.getCode()) && codeMap.containsKey(persisted.getCode())) {
imported = codeMap.get(persisted.getCode());
} else if (!Strings.isNullOrEmpty(persisted.getName()) && nameMap.containsKey(persisted.getName())) {
imported = nameMap.get(persisted.getName());
}
if (imported == null || imported.getCoordinates() == null || imported.getFeatureType() == null) {
// Failed to dereference a persisted entity for this org unit or geo data incomplete/missing, therefore ignore
continue;
}
mergeNonGeoData(persisted, imported);
}
String dxf2MetaData = metaDataToDxf2(metadata);
if (dxf2MetaData == null) {
return PreProcessingResult.failure(new Exception("GML import failed during pre-processing stage."));
}
return PreProcessingResult.success(dxf2MetaData);
}
Aggregations