Search in sources :

Example 36 with Metadata

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);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Metadata(org.hisp.dhis.dxf2.metadata.Metadata) IOException(java.io.IOException) TransformerException(javax.xml.transform.TransformerException) TransformerException(javax.xml.transform.TransformerException) MalformedByteSequenceException(org.apache.xerces.impl.io.MalformedByteSequenceException) IOException(java.io.IOException) SAXParseException(org.xml.sax.SAXParseException)

Aggregations

Metadata (com.google.android.exoplayer2.metadata.Metadata)18 Metadata (org.hisp.dhis.dxf2.metadata.Metadata)10 ParsableByteArray (com.google.android.exoplayer2.util.ParsableByteArray)6 IOException (java.io.IOException)5 Format (com.google.android.exoplayer2.Format)3 ArrayList (java.util.ArrayList)3 MediaFormat (android.media.MediaFormat)2 DrmInitData (com.google.android.exoplayer2.drm.DrmInitData)2 ApicFrame (com.google.android.exoplayer2.metadata.id3.ApicFrame)2 Id3Frame (com.google.android.exoplayer2.metadata.id3.Id3Frame)2 PrivFrame (com.google.android.exoplayer2.metadata.id3.PrivFrame)2 TextInformationFrame (com.google.android.exoplayer2.metadata.id3.TextInformationFrame)2 TrackGroup (com.google.android.exoplayer2.source.TrackGroup)2 TrackGroupArray (com.google.android.exoplayer2.source.TrackGroupArray)2 TrackSelection (com.google.android.exoplayer2.trackselection.TrackSelection)2 FlacStreamInfo (com.google.android.exoplayer2.util.FlacStreamInfo)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 ByteBuffer (java.nio.ByteBuffer)2 MetadataImportParams (org.hisp.dhis.dxf2.metadata.MetadataImportParams)2