Пример #1
0
    json::QuickBuilder
    NodeSetFactory::GetSchema()
    {
        // Iterate over all registrangs, instantiate using function pointer (or functor?), call Configure
        // but with special 'don't error out' mode.
        //json::Object returnVal;
        support_spec_map_t& registrants = getRegisteredClasses();

        JsonConfigurable::_dryrun = true;

        json::Object nodeSetsJsonArray;
        for (auto& entry : registrants)
        {
            const std::string& class_name = entry.first;
            LOG_DEBUG_F("class_name = %s\n", class_name.c_str());
            json::Object fakeJson;
            fakeJson["class"] = json::String(class_name);
            Configuration * fakeConfig = Configuration::CopyFromElement( fakeJson );
            instantiator_function_t creator = entry.second;

            try
            {
                // TBD: Handle Node-targeted interventions
                 
                ISupports * pNS = CreateInstanceFromSpecs<INodeSet>(fakeConfig, getRegisteredClasses(), true);
                if( pNS )
                {
                    //campaignSchema[std::string(class_name)] = dynamic_cast<JsonConfigurable*>(pNS)->GetSchema();
                    json::QuickBuilder* schema = &dynamic_cast<JsonConfigurable*>(pNS)->GetSchema();
                    (*schema)[ "class" ] = json::String( class_name );
                    nodeSetsJsonArray[ class_name ] = *schema;
                    //nodeSetsJsonArray[jsonArrayIdx][ "class" ] = json::String( class_name );
                }
            }
            catch( DetailedException &e )
            {
                std::ostringstream msg;
                msg << "ConfigException creating nodeset for GetSchema: " 
                    << e.what()
                    << std::endl;
                LOG_INFO( msg.str().c_str() );
            }
            catch( const json::Exception &e )
            {
                std::ostringstream msg;
                msg << "json Exception creating nodeset for GetSchema: "
                    << e.what()
                    << std::endl;
                LOG_INFO( msg.str().c_str() );
            }
            LOG_DEBUG( "Done with that class....\n" );
            delete fakeConfig;
            fakeConfig = nullptr;
        }
        campaignSchema[ "schema" ] = nodeSetsJsonArray;
        LOG_DEBUG( "Returning from GetSchema.\n" );
        json::QuickBuilder retSchema = json::QuickBuilder(campaignSchema);
        return retSchema;
    }
Пример #2
0
    json::QuickBuilder
    InterventionFactory::GetSchema()
    {
        // Iterate over all registrangs, instantiate using function pointer (or functor?), call Configure
        // but with special 'don't error out' mode.
        //json::Object returnVal;
        //campaignSchema["hello"] = json::String( "world" );
        support_spec_map_t& registrants = getRegisteredClasses();
#ifdef WIN32
        JsonConfigurable::_dryrun = true;
#else
        setenv( "DRYRUN", "1", 1 );
#endif
        for (auto& entry : registrants)
        {
            const std::string& class_name = entry.first;
            LOG_DEBUG_F("class_name = %s\n", class_name.c_str());
            json::Object fakeJson;
            fakeJson["class"] = json::String(class_name);
            Configuration * fakeConfig = Configuration::CopyFromElement( fakeJson );
            instantiator_function_t creator = entry.second;
            try
            {
                // TBD: Handle Node-targeted interventions
                ISupports * pCampaignForSchema = CreateIntervention((const Configuration*)fakeConfig);
                if( pCampaignForSchema )
                {
                    assert( pCampaignForSchema );
                    json::QuickBuilder* schema = &dynamic_cast<JsonConfigurable*>(pCampaignForSchema)->GetSchema();
                    (*schema)[std::string("iv_type")] = json::String("IndividualTargeted");
                    (*schema)[std::string("class")] = json::String(class_name);
                    campaignSchema[ class_name ] = *schema;
                }
                else // Try Node-targeted
                {
                    ISupports * pCampaignForSchema = CreateNDIIntervention((const Configuration*)fakeConfig);
                    json::QuickBuilder* schema = &dynamic_cast<JsonConfigurable*>(pCampaignForSchema)->GetSchema();
                    (*schema)[std::string("iv_type")] = json::String("NodeTargeted");
                    (*schema)[std::string("class")] = json::String(class_name);
                    campaignSchema[ class_name ] = *schema;
                }
            }
            catch( DetailedException &e )
            {
                std::ostringstream msg;
                msg << "ConfigException creating intervention for GetSchema: " 
                    << e.what()
                    << std::endl;
                LOG_INFO( msg.str().c_str() );
            }
            catch( const json::Exception &e )
            {
                std::ostringstream msg;
                msg << "json Exception creating intervention for GetSchema: "
                    << e.what()
                    << std::endl;
                LOG_INFO( msg.str().c_str() );
            }
            LOG_DEBUG( "Done with that class....\n" );
            delete fakeConfig;
            fakeConfig = nullptr;
        }
        LOG_DEBUG( "Returning from GetSchema.\n" );
        json::QuickBuilder retSchema = json::QuickBuilder(campaignSchema);
        return retSchema;
    }
Пример #3
0
 INodeDistributableIntervention* InterventionFactory::CreateNDIIntervention( const Configuration *config )
 {
     bool reset = JsonConfigurable::_useDefaults;
     JsonConfigurable::_useDefaults = useDefaults;
     INodeDistributableIntervention* ret = CreateInstanceFromSpecs<INodeDistributableIntervention>(config, getRegisteredClasses(), true);
     JsonConfigurable::_useDefaults = reset;
     return ret;
 }
Пример #4
0
 // new, configurable method
 IDistributableIntervention* InterventionFactory::CreateIntervention( const Configuration *config )
 {
     // Keeping this simple. But bear in mind CreateInstanceFromSpecs can throw exception
     // and JC::_useDefaults will not be restored. But we won't keep running in that case.
     bool reset = JsonConfigurable::_useDefaults;
     JsonConfigurable::_useDefaults = useDefaults;
     IDistributableIntervention* ret = CreateInstanceFromSpecs<IDistributableIntervention>(config, getRegisteredClasses(), true);
     JsonConfigurable::_useDefaults = reset;
     return ret;
 }