Esempio n. 1
0
File: main.cpp Progetto: SSE4/vmf-1
// schemaName == "" means all schemas (i.e. all metadata in the stream)
// setName == "" means the whole schema with descriptions
// schemaName and setName specified means removal all the metadata items from the specified set
void removeMetadata(const string& path, const string& schemaName = "", const string& setName = "")
{
    cout << "\nRemoving metadata: " 
         << (schemaName.empty() ? string("*") : schemaName + '/' + 
                                               (setName.empty() ? string("*") : setName) ) 
         << endl;
    MetadataStream ms;
    if (!ms.open(path, MetadataStream::ReadWrite))
        throw std::runtime_error("Can't open MetadataStream");
    vector<string> schemas;
    if(schemaName.empty())
    {
        // remove all metadata
        ms.remove();
    }
    else
    {
        schemas.push_back(schemaName);
        for (unsigned int sNum = 0; sNum < schemas.size(); sNum++)
        {
            auto sName = schemas[sNum];
            cout << "\t* (" << sNum << ") [schema]: " << sName << endl;
            if(!ms.load(sName))
                throw std::runtime_error(string("Error loading schema: ") + sName);
            vector<shared_ptr<MetadataDesc>>mDescs;
            if(setName.empty())
            {
                // remove the whole schema with descriptions
                ms.remove( ms.getSchema(sName) );
            }
            else
            {
                mDescs.push_back(ms.getSchema(sName)->findMetadataDesc(setName));
                for (unsigned int setNum = 0; setNum < mDescs.size(); setNum++)
                {
                    auto mDesc = mDescs[setNum];
                    string setName = mDesc->getMetadataName();
                    MetadataSet set = ms.queryByName(setName);
                    cout << "\t\t* (" << sNum << "." << setNum << ") [set]: " << setName << "(" << set.size() << " items)" << endl;
                    ms.remove(set);
                    set.clear();
                }
            }
        }
    }
    cout << "Saving stream..." << endl;
    ms.save();
    cout << "Done." << endl;
}
Esempio n. 2
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;
}
Esempio n. 3
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;
}