Search in sources :

Example 71 with Metadata

use of org.hisp.dhis.dxf2.metadata.Metadata in project ExoPlayer by google.

the class Id3DecoderTest method testDecodePrivFrame.

public void testDecodePrivFrame() throws MetadataDecoderException {
    byte[] rawId3 = new byte[] { 73, 68, 51, 4, 0, 0, 0, 0, 0, 19, 80, 82, 73, 86, 0, 0, 0, 9, 0, 0, 116, 101, 115, 116, 0, 1, 2, 3, 4 };
    Id3Decoder decoder = new Id3Decoder();
    Metadata metadata = decoder.decode(rawId3, rawId3.length);
    assertEquals(1, metadata.length());
    PrivFrame privFrame = (PrivFrame) metadata.get(0);
    assertEquals("test", privFrame.owner);
    MoreAsserts.assertEquals(new byte[] { 1, 2, 3, 4 }, privFrame.privateData);
}
Also used : Metadata(com.google.android.exoplayer2.metadata.Metadata)

Example 72 with Metadata

use of org.hisp.dhis.dxf2.metadata.Metadata in project ExoPlayer by google.

the class SpliceInfoDecoderTest method testWrappedAroundTimeSignalCommand.

public void testWrappedAroundTimeSignalCommand() throws MetadataDecoderException {
    byte[] rawTimeSignalSection = new byte[] { // table_id.
    0, // section_syntax_indicator, private_indicator, reserved, section_length(4).
    (byte) 0x80, // section_length(8).
    0x14, // protocol_version.
    0x00, // encrypted_packet, encryption_algorithm, pts_adjustment(1).
    0x00, // pts_adjustment(32).
    0x00, // pts_adjustment(32).
    0x00, // pts_adjustment(32).
    0x00, // pts_adjustment(32).
    0x00, // cw_index.
    0x00, // tier(8).
    0x00, // tier(4), splice_command_length(4).
    0x00, // splice_command_length(8).
    0x05, // splice_command_type = time_signal.
    0x06, // time_specified_flag, reserved, pts_time(1).
    (byte) 0x80, // pts_time(32). PTS for a second after playback position.
    0x52, // pts_time(32). PTS for a second after playback position.
    0x03, // pts_time(32). PTS for a second after playback position.
    0x02, // pts_time(32). PTS for a second after playback position.
    (byte) 0x8f, 0x00, 0x00, 0x00, // CRC_32 (ignored, check happens at extraction).
    0x00 };
    // The playback position is 57:15:58.43 approximately.
    // With this offset, the playback position pts before wrapping is 0x451ebf851.
    Metadata metadata = feedInputBuffer(rawTimeSignalSection, 0x3000000000L, -0x50000L);
    assertEquals(1, metadata.length());
    assertEquals(removePtsConversionPrecisionError(0x3001000000L, inputBuffer.subsampleOffsetUs), ((TimeSignalCommand) metadata.get(0)).playbackPositionUs);
}
Also used : Metadata(com.google.android.exoplayer2.metadata.Metadata)

Example 73 with Metadata

use of org.hisp.dhis.dxf2.metadata.Metadata in project ExoPlayer by google.

the class EventMessageDecoder method decode.

@Override
public Metadata decode(MetadataInputBuffer inputBuffer) {
    ByteBuffer buffer = inputBuffer.data;
    byte[] data = buffer.array();
    int size = buffer.limit();
    ParsableByteArray emsgData = new ParsableByteArray(data, size);
    String schemeIdUri = emsgData.readNullTerminatedString();
    String value = emsgData.readNullTerminatedString();
    long timescale = emsgData.readUnsignedInt();
    // presentation_time_delta
    emsgData.skipBytes(4);
    long durationMs = (emsgData.readUnsignedInt() * 1000) / timescale;
    long id = emsgData.readUnsignedInt();
    byte[] messageData = Arrays.copyOfRange(data, emsgData.getPosition(), size);
    return new Metadata(new EventMessage(schemeIdUri, value, durationMs, id, messageData));
}
Also used : ParsableByteArray(com.google.android.exoplayer2.util.ParsableByteArray) Metadata(com.google.android.exoplayer2.metadata.Metadata) ByteBuffer(java.nio.ByteBuffer)

Example 74 with Metadata

use of org.hisp.dhis.dxf2.metadata.Metadata in project ExoPlayer by google.

the class Id3Decoder method decode.

/**
   * Decodes ID3 tags.
   *
   * @param data The bytes to decode ID3 tags from.
   * @param size Amount of bytes in {@code data} to read.
   * @return A {@link Metadata} object containing the decoded ID3 tags.
   */
public Metadata decode(byte[] data, int size) {
    List<Id3Frame> id3Frames = new ArrayList<>();
    ParsableByteArray id3Data = new ParsableByteArray(data, size);
    Id3Header id3Header = decodeHeader(id3Data);
    if (id3Header == null) {
        return null;
    }
    int startPosition = id3Data.getPosition();
    int framesSize = id3Header.framesSize;
    if (id3Header.isUnsynchronized) {
        framesSize = removeUnsynchronization(id3Data, id3Header.framesSize);
    }
    id3Data.setLimit(startPosition + framesSize);
    boolean unsignedIntFrameSizeHack = false;
    if (id3Header.majorVersion == 4) {
        if (!validateV4Frames(id3Data, false)) {
            if (validateV4Frames(id3Data, true)) {
                unsignedIntFrameSizeHack = true;
            } else {
                Log.w(TAG, "Failed to validate V4 ID3 tag");
                return null;
            }
        }
    }
    int frameHeaderSize = id3Header.majorVersion == 2 ? 6 : 10;
    while (id3Data.bytesLeft() >= frameHeaderSize) {
        Id3Frame frame = decodeFrame(id3Header.majorVersion, id3Data, unsignedIntFrameSizeHack, frameHeaderSize, framePredicate);
        if (frame != null) {
            id3Frames.add(frame);
        }
    }
    return new Metadata(id3Frames);
}
Also used : ParsableByteArray(com.google.android.exoplayer2.util.ParsableByteArray) ArrayList(java.util.ArrayList) Metadata(com.google.android.exoplayer2.metadata.Metadata)

Example 75 with Metadata

use of org.hisp.dhis.dxf2.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

DhisSpringTest (org.hisp.dhis.DhisSpringTest)55 Test (org.junit.Test)55 List (java.util.List)46 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)46 ClassPathResource (org.springframework.core.io.ClassPathResource)42 ObjectBundleValidationReport (org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport)37 DataElement (org.hisp.dhis.dataelement.DataElement)25 User (org.hisp.dhis.user.User)20 Metadata (com.google.android.exoplayer2.metadata.Metadata)19 MetadataVersion (org.hisp.dhis.metadata.version.MetadataVersion)19 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)19 DataSet (org.hisp.dhis.dataset.DataSet)15 ArrayList (java.util.ArrayList)14 MetadataVersionServiceException (org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException)14 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)14 IOException (java.io.IOException)10 Metadata (org.hisp.dhis.dxf2.metadata.Metadata)10 DhisHttpResponse (org.hisp.dhis.system.util.DhisHttpResponse)10 UserAuthorityGroup (org.hisp.dhis.user.UserAuthorityGroup)10 IntegrationTest (org.hisp.dhis.IntegrationTest)9