Example #1
0
void generateMetadata(MetadataStream& mdStream)
{
    mdStream.remove();
    mdStream.save();
    mdStream.close();
    mdStream.reopen(MetadataStream::OpenModeFlags::Update);

    // Create a GPS metadata field descriptions
    shared_ptr<MetadataSchema> gpsSchema(new MetadataSchema(GPS_SCHEMA_NAME));

    UMF_METADATA_BEGIN(GPS_DESC);
        UMF_FIELD_REAL(GPS_COORD_LAT_FIELD);
        UMF_FIELD_REAL(GPS_COORD_LNG_FIELD);
    UMF_METADATA_END(gpsSchema);

    cout << "Adding metadata schema '" << GPS_SCHEMA_NAME << "':" << endl;

    // Add schema to metadata stream
    mdStream.addSchema(gpsSchema);

    shared_ptr<Metadata> gpsMetadata;

    // Let there be an UFO moving around some point on Earth
    const int nPoints = 1<<10;
    for(int i = 0; i < nPoints; i++)
    {
        float lat = float(  37.235 + cos(i/25.0*2.0*PI) * 0.001);
        float lng = float(-115.811 + sin(i/25.0*2.0*PI) * 0.001);
        long long time = i;
        if (i<3) cout << "\t[" << i << "] 'lat " << lat << " lng " << lng << '\'' << " time " << time << endl;
        else cout << '.';

        // Create a metadata item
        gpsMetadata = shared_ptr<Metadata>(new Metadata(gpsSchema->findMetadataDesc(GPS_DESC)));

        // Fill item fields
        gpsMetadata->push_back(FieldValue(GPS_COORD_LAT_FIELD, lat));
        gpsMetadata->push_back(FieldValue(GPS_COORD_LNG_FIELD, lng));
        gpsMetadata->setTimestamp(time);

        // Add to metadata a new item
        mdStream.add(gpsMetadata);
    }
    cout << "\n\t" << nPoints << " items." << endl;
}
Example #2
0
void generateEncryptedMetadata(MetadataStream &mdStream, EncryptionScope scope)
{
    mdStream.remove();
    mdStream.save();
    mdStream.close();
    mdStream.reopen(MetadataStream::OpenModeFlags::Update);

    // Create a GPS metadata field descriptions
    shared_ptr<MetadataSchema> gpsSchema(new MetadataSchema(GPS_SCHEMA_NAME));

    UMF_METADATA_BEGIN(GPS_DESC);
        UMF_FIELD_REAL(GPS_COORD_LAT_FIELD);
        UMF_FIELD_REAL(GPS_COORD_LNG_FIELD);
    UMF_METADATA_END(gpsSchema);

    //set encryption for all fields/metadata/schema/stream
    std::shared_ptr< MetadataDesc > metadesc = gpsSchema->findMetadataDesc(GPS_DESC);
    FieldDesc& field = metadesc->getFieldDesc(GPS_COORD_LNG_FIELD);
    if(scope == EncryptionScope::Whole)
    {
        mdStream.setUseEncryption(true);
    }
    else if(scope == EncryptionScope::AllSchema)
    {
        gpsSchema->setUseEncryption(true);
    }
    else if(scope == EncryptionScope::AllMetaDesc)
    {
        metadesc->setUseEncryption(true);
    }
    else if(scope == EncryptionScope::AllFieldDesc)
    {
        field.useEncryption = true;
    }

    cout << "Adding metadata schema '" << GPS_SCHEMA_NAME << "':" << endl;

    // Add schema to metadata stream
    mdStream.addSchema(gpsSchema);

    shared_ptr<Metadata> gpsMetadata;

    // Let there be an UFO moving around some point on Earth
    const int nPoints = 1<<10;
    for(int i = 0; i < nPoints; i++)
    {
        float lat = float(  37.235 + cos(i/25.0*2.0*PI) * 0.001);
        float lng = float(-115.811 + sin(i/25.0*2.0*PI) * 0.001);
        long long time = i;
        if (i<3) cout << "\t[" << i << "] 'lat " << lat << " lng " << lng << '\'' << " time " << time << endl;
        else cout << '.';

        // Create a metadata item
        gpsMetadata = shared_ptr<Metadata>(new Metadata(gpsSchema->findMetadataDesc(GPS_DESC)));

        //Encrypt specified fields/records or not
        bool encryptRecord = false, encryptField = false;
        if(i == 0)
        {
            if(scope == EncryptionScope::OneField)
            {
                encryptField = true;
            }
            if(scope == EncryptionScope::OneMetadata)
            {
                encryptRecord = true;
            }
        }

        // Fill item fields
        gpsMetadata->push_back(FieldValue(GPS_COORD_LAT_FIELD, lat, encryptField));
        gpsMetadata->push_back(FieldValue(GPS_COORD_LNG_FIELD, lng));
        gpsMetadata->setTimestamp(time);
        gpsMetadata->setUseEncryption(encryptRecord);

        // Add to metadata a new item
        mdStream.add(gpsMetadata);
    }
    cout << "\n\t" << nPoints << " items." << endl;
}