Esempio n. 1
0
int isCitySaverZone(U8_t zoneId)
{
	if ( !g_citySaverZonesRetrieved )
	{
		DbAccess 	*m_dbAccess;
		Rows rows;

		m_dbAccess =  getDBAccess();
        
        if(m_dbAccess==NULL)
            return false;

		char s_query[200];
		sprintf(s_query, "SELECT logical FROM ZoneRecord where is_city_saver='true' AND %s", getCurrentCDVersionWhere());
		m_dbAccess->executeSqlQuery(s_query, rows);

		for ( Rows::iterator row = rows.begin(); row != rows.end(); row++ )
		{
			g_citySaverZones.insert(U8_t(atoi(row->begin()->second)));
		}

		g_citySaverZonesRetrieved = true;
	}

	if ( g_citySaverZones.find(zoneId) != g_citySaverZones.end() )
	{
		return true;
	}
    
	return false;
}
Esempio n. 2
0
YBORM_DECL ElementTree::ElementPtr
xmlize_rows(const Rows &rows, const String &entries_name, const String &entry_name)
{
    ElementTree::ElementPtr entries = ElementTree::new_element(entries_name);
    Rows::const_iterator it = rows.begin(), end = rows.end();
    for (; it != end; ++it)
        entries->children_.push_back(xmlize_row(*it, entry_name));
    return entries;
}
Esempio n. 3
0
int getLinesByStation(U16_t stationId, MYKI_CD_LinesByStation_t &linesByStation, MYKI_CD_U16Array_t &lines)
{
    int returnValue=false;
    bool isNull=false;

    LinesByStationItem cacheItem;
    if (g_linesByStationCache.getCacheValue(stationId, cacheItem, isNull))
    {
        if ( !isNull )
        {
            linesByStation = cacheItem.linesByStation;
            lines = cacheItem.lines;
        }
        returnValue = !isNull;
        CsDebug(CD_DEBUG, (CD_DEBUG, "MYKI_CD:getLinesByStation: Return Cache lines by station record found for id %d.", int(stationId)));
    }
    else
    {
        DbAccess 	*m_dbAccess;

        Rows rows;

        m_dbAccess =  getDBAccess();
        if(m_dbAccess==NULL)
            return false;
        char s_query[256];
        sprintf(s_query, "SELECT line FROM StationLineRecord WHERE station='%d' AND %s ORDER BY line ASC", int(stationId), getCurrentCDVersionWhere());

        m_dbAccess->executeSqlQuery(s_query, rows);

        Rows::const_iterator itr;

        lines.arraySize = rows.size();
        if (lines.arraySize > 0)
            lines.arrayOfU16 = (U16_t*)malloc(int(lines.arraySize) * sizeof(U16_t));
        else
            lines.arrayOfU16 = NULL;
        linesByStation.station = stationId;

        int i = 0;
        for(itr = rows.begin(); itr != rows.end(); ++itr) {
            const ColumnValue& cv = *itr;
            lines.arrayOfU16[i]=convertStringToU16(cv["line"]);
            i++;
        }

        // TEST: Print out results
        if(rows.empty())
        {
            //std::cout << "\nNo Station record found for Station id " << stationId <<".\n";
            CsDebug(CD_DEBUG, (CD_DEBUG, "MYKI_CD:getServiceProviders: No Station record found for Station id %d.", stationId));
        }
        else
        {
            returnValue = true;
            //printStationLinesMap(rows);
            //testPrintLinesByStationResult(stationId, linesByStation, lines);
        }
        cacheItem.linesByStation = linesByStation;
        cacheItem.lines = lines;
        g_linesByStationCache.addCacheValue(stationId, cacheItem, !returnValue);
    }

    return returnValue;
}
Esempio n. 4
0
int  getStationsByLine(U16_t lineId, MYKI_CD_StationsByLine_t &stationsByLine, MYKI_CD_U16Array_t &stations)
{
    int returnValue=false;
    bool isNull=false;

    StationsByLineItem cacheItem;
    if (g_stationsByLineCache.getCacheValue(lineId, cacheItem, isNull))
    {
        if (!isNull)
        {
            stationsByLine = cacheItem.stationsByLine;
            stations = cacheItem.stations;
        }
        returnValue = !isNull;
        CsDebug(CD_DEBUG, (CD_DEBUG, "MYKI_CD:getStationsByLine: Return Cache stations by line record found for id %d.", int(lineId)));
    }
    else
    {
        DbAccess 	*m_dbAccess=NULL;

        Rows rows;

        m_dbAccess =  getDBAccess();
        if(m_dbAccess==NULL)
            return false;
        char s_query[256];
        sprintf(s_query, "SELECT station FROM StationLineRecord WHERE line='%d' AND %s ORDER BY station DESC", int(lineId), getCurrentCDVersionWhere());

        m_dbAccess->executeSqlQuery(s_query, rows);

        Rows::const_iterator itr;

        stations.arraySize = rows.size();
        if (stations.arraySize > 0)
            stations.arrayOfU16 = (U16_t*)malloc(int(stations.arraySize) * sizeof(U16_t));
        else
            stations.arrayOfU16 = NULL;
        stationsByLine.line = lineId;

        int i = 0;
        for(itr = rows.begin(); itr != rows.end(); ++itr) {
            const ColumnValue& cv = *itr;
            stations.arrayOfU16[i]=convertStringToU16(cv["station"]);
            i++;
        }

        // TEST: Print out results
        if(rows.empty())
        {
            //std::cout << "\nNo Line record found for Line id " << lineId <<".\n";
            CsDebug(CD_DEBUG, (CD_DEBUG, "MYKI_CD:getStationsByLine: No Line record found for Line id %d.", lineId));
        }
        else
        {
            returnValue=true;
            //printStationLinesMap(rows);
            //testPrintStationsByLineResult(lineId, stationsByLine, stations);
        }
        cacheItem.stationsByLine = stationsByLine;
        cacheItem.stations = stations;
        g_stationsByLineCache.addCacheValue(lineId, cacheItem, !returnValue);
    }

    return returnValue;
}
Esempio n. 5
0
    /**
     *  @brief  Retrieves saleable product details given search
     *          criteria.
     *  This (C++) function returns saleable product details that
     *  satisfy the specified search criteria.
     *  @note   Products with product price of zero are excluded
     *          from the saleable product list.
     *  @param  products returned Json:Value object containing
     *          saleable product details. The returned JSON object
     *          has the following format,
     *  @code
     *  {
     *    "products":
     *    [
     *      {
     *        "GSTApplicable":false,
     *        "PLU":"4. myki Child",
     *        "Price":50,
     *        "id":46,
     *        "issuer_id":1,
     *        "long_desc":"GTS Timetable",
     *        "short_desc":"GTS Timetable",
     *        "subtype":"None",
     *        "type":"ThirdParty"
     *      },
     *      { ... },
     *      null
     *    ]
     *  }
     *  @endcode
     *  where,
     *  @li     @c id is the product id (1-255).
     *  @li     @c issuer_id is the product issuer/owner id.
     *  @li     @c type is the product type, eg. "ThirdParty", "PremiumSurcharge".
     *  @li     @c subtype is the product sub-type, eg. "None".
     *  @li     @c long_desc is the product long description.
     *  @li     @c short_desc is the product short description.
     *  @li     @c Price is the product price in lowest denomination (cents).
     *  @li     @c GSTApplicable is true if GTS is applicable, false otherwise.
     *  @li     @c PLU is (optional) 'Price Lookup Unit' uniquely identifies product.
     *  @param  zone zone to validate against sales zones.
     *  @param  productType product type to search for (eg. "ThirdParty").
     *  @param  time time to validate against.
     *  @param  serviceProviderId service provider id.
     *  @param  deviceType device type (eg. "BDC").
     *  @return true if successful; false otherwise.
     */
int
getProducts(
    Json::Value    &products,
    int             zone,
    const char     *productType,
    Time_t          time,
    int             serviceProviderId,
    const char     *deviceType )
{
    #define MYKI_CD_DOW_SUNDAY      7

    int             returnValue     = false;
    DateC19_t       date            = 0;
    int             dayOfWeek       = 0;
    Time_t          timeHHMM        = 2400;
    struct tm       localTm         = { 0 };

    CsDbg( CD_DEBUG, "MYKI_CD:getProducts" );

    if ( time == TIME_NOT_SET )
    {
        CsErrx( "MYKI_CD:getProducts : time not set" );
        return  false;
    }

    /*  Creates an empty "products" array */
    products[ "products" ]  = Json::Value( Json::arrayValue );

    localtime_r( (time_t*)&time, &localTm );
    date        = mkdate( &localTm );
    dayOfWeek   = ( localTm.tm_wday == 0 /*SUNDAY*/ ? MYKI_CD_DOW_SUNDAY : localTm.tm_wday );
    timeHHMM    = ( localTm.tm_hour * 100 ) + localTm.tm_min;

    try
    {
        std::stringstream   query1;
        std::string         query;
        const char         *pQuery          = NULL;
        Rows                productRecords;
        DbAccess           *m_dbAccess      = getDBAccess();

        if ( m_dbAccess == NULL )
        {
            /*  Failed opening Tariff database */
            throw   __LINE__;
        }

        /*  Retrieves all products matching given product type */
        query1  << "SELECT  * "
                   "FROM    ProductRecord "
                   "WHERE   ProductRecord.fk_major_version= " << getCurrentCDMajorVersion() << " "
                       "AND ProductRecord.fk_minor_version= " << getCurrentCDMinorVersion() << " ";
        if ( productType != NULL )
        {
            query1  << "AND ProductRecord.type LIKE '" << productType << "' ";
        }
        query   = query1.str();
        pQuery  = query.c_str();
        if ( m_dbAccess->executeSqlQuery( pQuery, productRecords ) != SQLITE_OK )
        {
            /*  Failed executing query */
            throw   __LINE__;
        }

        for ( Rows::const_iterator itrProduct = productRecords.begin();
                itrProduct != productRecords.end();
                ++itrProduct )
        {
            const ColumnValue  &productRecord           = *itrProduct;
            std::string         productPK               = productRecord[ "PrimaryKey" ];
            std::string         productType             = productRecord[ "type"       ];
            std::stringstream   query2;
            Rows                attrRecords;
            bool                allowSalesChannel       = false;
            bool                allowServiceProvider    = false;
            bool                allowStartDate          = productType == "ThirdParty" ? true : false;
            bool                allowEndDate            = productType == "ThirdParty" ? true : false;
            bool                allowDayOfWeek          = false;
            bool                allowTime               = false;
            bool                allowSaleZone           = false;
            std::string         PLU;
            U32_t               productPrice            = 0;
            bool                GSTApplicable           = false;

            /*  Retrieves all default and specific attribute name/value pairs */
            query2  << "SELECT      1 AS is_default, name, value "
                       "FROM        ProductDefaultAttribute "
                       "WHERE       ProductDefaultAttribute.FK_ProductRecord=" << productPK << " "
                       "UNION "
                       "SELECT      0 AS is_default, name, value "
                       "FROM        ProductAttribute "
                       "WHERE       ProductAttribute.FK_ProductRecord=" << productPK << " "
                       "ORDER   BY  name, is_default DESC ";
            query   = query2.str();
            pQuery  = query.c_str();
            if ( m_dbAccess->executeSqlQuery( pQuery, attrRecords ) != SQLITE_OK )
            {
                /*  Failed executing query */
                throw   __LINE__;
            }

            /*  Performs validity check on saleable product */
            for ( Rows::const_iterator itrAttr = attrRecords.begin();
                    itrAttr != attrRecords.end();
                    ++itrAttr )
            {
                const ColumnValue  &attrRecord  = *itrAttr;
                std::string         attrName    = attrRecord[ "name"  ];
                std::string         attrValue   = attrRecord[ "value" ];
                const char         *pAttrName   = attrName.c_str();
                const char         *pAttrValue  = attrValue.c_str();

                if      ( attrName == "SalesChannel"    )   { checkProductIncluded(          allowSalesChannel,    deviceType,        attrValue ); }
                else if ( attrName == "ServiceProvider" )   { checkProductIncluded(          allowServiceProvider, serviceProviderId, attrValue ); }
                else if ( attrName == "SalesZone"       )   { checkProductIncluded(          allowSaleZone,        zone,              attrValue ); }
                else if ( attrName == "StartDate"       )   { checkProductIncludedStartDate( allowStartDate,       date,              attrValue ); }
                else if ( attrName == "EndDate"         )   { checkProductIncludedEndDate(   allowEndDate,         date,              attrValue ); }
                else if ( attrName == "DayOfWeek"       )   { checkProductIncluded(          allowDayOfWeek,       dayOfWeek,         attrValue ); }
                else if ( attrName == "TimeOfDay"       )   { checkProductIncludedTime(      allowTime,            timeHHMM,          attrValue ); }
                else if ( attrName == "PLU"             )   { PLU           =                                                         attrValue  ; }
                else if ( attrName == "Price"           )   { productPrice  = convertStringToU32(                                     attrValue ); }
                else if ( attrName == "GSTApplicable"   )   { GSTApplicable = convertStringToBool(                                    attrValue ); }
            }

            if      ( allowSalesChannel    == false ) { CsDbg( CD_DEBUG, "MYKI_CD:getProducts : excluded device type"       ); }
            else if ( allowServiceProvider == false ) { CsDbg( CD_DEBUG, "MYKI_CD:getProducts : excluded service provider"  ); }
            else if ( allowSaleZone        == false ) { CsDbg( CD_DEBUG, "MYKI_CD:getProducts : excluded sales zone"        ); }
            else if ( allowStartDate       == false ) { CsDbg( CD_DEBUG, "MYKI_CD:getProducts : not yet available"          ); }
            else if ( allowEndDate         == false ) { CsDbg( CD_DEBUG, "MYKI_CD:getProducts : no longer available"        ); }
            else if ( allowDayOfWeek       == false ) { CsDbg( CD_DEBUG, "MYKI_CD:getProducts : not available on this day"  ); }
            else if ( allowTime            == false ) { CsDbg( CD_DEBUG, "MYKI_CD:getProducts : not available at this time" ); }
            else if ( productPrice         == 0     ) { CsDbg( CD_DEBUG, "MYKI_CD:getProducts : zero product price"         ); }
            else
            {
                Json::Value     productValue;
                std::string     productId           = productRecord[ "id" ];
                std::string     productShortDesc    = productRecord[ "short_desc" ];

                CsDbg( CD_DEBUG, "MYKI_CD:getProducts : Add '%d-%s'",
                        productId.c_str(),
                        productShortDesc.c_str() );

                /*  Creates saleable product object */
                productValue[ "id"            ] = convertStringToU32( productRecord[ "id"        ] );
                productValue[ "issuer_id"     ] = convertStringToU32( productRecord[ "issuer_id" ] );
                productValue[ "type"          ] = productRecord[ "type"       ];
                productValue[ "subtype"       ] = productRecord[ "subtype"    ];
                productValue[ "short_desc"    ] = productRecord[ "short_desc" ];
                productValue[ "long_desc"     ] = productRecord[ "long_desc"  ];
                if ( PLU.empty() == false )
                {
                    productValue[ "PLU"       ] = PLU;
                }
                productValue[ "Price"         ] = productPrice;
                productValue[ "GSTApplicable" ] = GSTApplicable;

                /*  And adds to saleable product list */
                products[ "products" ].append( productValue );
            }
        }
        returnValue = true;
    }
    catch ( int e )
    {
        /*  Failed accessing Tariff database */
        returnValue = false;
    }

    CsDbg( CD_DEBUG, "MYKI_CD:getProducts returns %s", returnValue == false ? "FALSE" : "TRUE" );
    return  returnValue;
}
Esempio n. 6
0
int getProduct(U8_t id, MYKI_CD_Product_t &product)
{
    int returnValue=false;
	DbAccess 	*m_dbAccess;
	Rows rows;
    
    CsDebug(CD_DEBUG, (CD_DEBUG, "MYKI_CD:getProduct %d", id));

	bool isNull = false;
    if(g_productCache.getCacheValue(id, product, isNull))
    {
        returnValue = !isNull;
		CsDebug(CD_DEBUG, (CD_DEBUG, "MYKI_CD:getProduct: Return Cache Product record found for id %d.", int(id)));
    }
	else
    {    
        m_dbAccess =  getDBAccess();
        if(m_dbAccess==NULL)
            return false;  
        char s_query[200];
        sprintf(s_query, "SELECT * FROM ProductRecord WHERE id='%d' AND %s", int(id), getCurrentCDVersionWhere());

        m_dbAccess->executeSqlQuery(s_query, rows);

        Rows::const_iterator itr1;
        for(itr1 = rows.begin(); itr1 != rows.end(); ++itr1){
            const ColumnValue& cv = *itr1;
            product.issuer_id = convertStringToU8(cv["issuer_id"]);
            product.id = convertStringToU8(cv["id"]);
            stringCopy(product.type, cv["type"], LEN_20_t);
            stringCopy(product.subtype, cv["subtype"], LEN_20_t);
            stringCopy(product.short_desc, cv["short_desc"], LEN_Short_Description_t);
            stringCopy(product.long_desc, cv["long_desc"], LEN_Long_Description_t);
        }



        // TEST: Print out results
        if(rows.empty())
        {
            //std::cout << "\nNo Product record found for id " << (int)id <<".\n";
            CsDebug(CD_DEBUG, (CD_DEBUG, "MYKI_CD:getProduct %d - no product exists", id));
        }
        else
        {
            CsDebug(CD_DEBUG, (CD_DEBUG, "MYKI_CD:getProduct %d - Get Attributes", id));
            // Get the product default attributes             // Get the product attributes
/*            if(getProductDefaultAttribute(id, product) && getProductAttribute(id, product))
            {
                CsDebug(CD_DEBUG, (CD_DEBUG, "MYKI_CD:getProduct %d - Return true", id));
                returnValue = true;
                //printProductMap(rows);
                //testPrintProductResult(id, product);
            }*/
            returnValue = true;
        }
        g_productCache.addCacheValue(id, product, !returnValue);
    }
    
    return returnValue;
}