diff options
author | <philippe colliot> | 2015-04-23 09:44:13 +0200 |
---|---|---|
committer | <philippe colliot> | 2015-04-23 09:44:13 +0200 |
commit | 72fdb5bfac7fb7923b83e47e81a13d10ad09dfe2 (patch) | |
tree | 0406c07b3e7949cdfe236e38759c0e5cbf6f1d68 /src | |
parent | 5e5ecad2a37e4c369fd181468b056819b3432a77 (diff) | |
download | poi-service-72fdb5bfac7fb7923b83e47e81a13d10ad09dfe2.tar.gz |
Add commonapi generated stuff to allow poi-manager being built
Diffstat (limited to 'src')
-rw-r--r-- | src/poi-service/poi-manager-server/poi-manager-server-stub.cpp | 193 | ||||
-rw-r--r-- | src/poi-service/poi-manager-server/poi-manager-server-stub.h | 23 | ||||
-rwxr-xr-x | src/poi-service/script/build-for-commonapi.sh | 77 | ||||
-rwxr-xr-x | src/poi-service/script/build.sh | 12 |
4 files changed, 282 insertions, 23 deletions
diff --git a/src/poi-service/poi-manager-server/poi-manager-server-stub.cpp b/src/poi-service/poi-manager-server/poi-manager-server-stub.cpp index 3f9de45..0da7842 100644 --- a/src/poi-service/poi-manager-server/poi-manager-server-stub.cpp +++ b/src/poi-service/poi-manager-server/poi-manager-server-stub.cpp @@ -40,7 +40,7 @@ sqlRequest::~sqlRequest() sqlRequest::SQL_REQUEST_ERRORS sqlRequest::setDatabase(const char *poiDatabaseFileName) { mp_database = new Database(poiDatabaseFileName); - return sqlRequest::OK; //todo check if database OK + return OK; //todo check if database OK } void sqlRequest::onError() @@ -211,6 +211,10 @@ sqlRequest::SQL_REQUEST_ERRORS sqlRequest::createCategory(POIServiceTypes::CAMCa { sqlRequest::SQL_REQUEST_ERRORS ret; size_t index; + std::string sqlQuery; //SQL request on database + vector<vector<string> > query_result; + vector<string > query_line; + std::ostringstream strStream; //temporary stream used for transformation into string //Check if all the parent categories exist for (index=0;index < category.details.parentsId.size();index++) @@ -222,13 +226,69 @@ sqlRequest::SQL_REQUEST_ERRORS sqlRequest::createCategory(POIServiceTypes::CAMCa //Check if the name doesn't exist into the database to avoid duplications ret = checkIfCategoryNameDoesntExist(category.details.name); - if (ret == OK) + if (ret != OK) + return ret; + + //Get a free id (poicategory) + ret = getFreeCategoryId(unique_id); + if (ret != OK) + return ret; + + //Create the category + sqlQuery = m_SQL_REQUEST_INSERT_CATEGORY; + strStream.str(""); + strStream << unique_id; + sqlQuery += strStream.str(); + sqlQuery += ",'"; + sqlQuery.append(category.details.name); + sqlQuery += "');"; + query_result = mp_database->queryNotUTF(sqlQuery.c_str()); + if (!query_result.empty()) { - //Now create the new category and get the unique id + onError(); //database is not well populated + //todo something with table ? + ret = DATABASE_ACCESS_ERROR; + return ret; + } + //Check the attributes and complete the table if necessary (poiattribute) + for (index=0;index < category.attributes.size();index++) + { + ret = checkIfAttributeExist((category.attributes.at(index)).id); + if (ret == ATTRIBUTE_ID_NOT_EXIST) + { + //Create the attribute + sqlQuery = m_SQL_REQUEST_INSERT_ATTRIBUTE; + strStream.str(""); + strStream << (category.attributes.at(index)).id; + sqlQuery += strStream.str(); + sqlQuery += ",'"; + sqlQuery.append((category.attributes.at(index)).name); + sqlQuery += "');"; + query_result = mp_database->queryNotUTF(sqlQuery.c_str()); + if (!query_result.empty()) + { + onError(); //database is not well populated + //todo something with table ? + ret = DATABASE_ACCESS_ERROR; + return ret; + } + } + else + { + if (ret != OK) + return ret; + } } + //Complete the table of attributes for the category (hasattribute) + + //Complete the table of family categories (poicategorykinship) + + //Complete the table of icons (iconset and isdisplayedas) + + return ret; } @@ -241,10 +301,13 @@ sqlRequest::SQL_REQUEST_ERRORS sqlRequest::checkIfCategoryNameDoesntExist(std::s sqlRequest::SQL_REQUEST_ERRORS ret; bool retSqlRequest; - sqlQuery = m_SQL_CHECK_IF_CATEGORY_NAME_EXIST; + sqlQuery = m_SQL_REQUEST_CHECK_IF_CATEGORY_NAME_EXIST; strStream.str(""); strStream << name; + sqlQuery += "'"; sqlQuery += strStream.str(); + sqlQuery += "'"; + sqlQuery += ")"; sqlQuery += m_SQL_RETURN_BOOL_VALUE; query_result = mp_database->queryNotUTF(sqlQuery.c_str()); if (query_result.empty()) @@ -275,10 +338,11 @@ sqlRequest::SQL_REQUEST_ERRORS sqlRequest::checkIfCategoryIdExist(POIServiceType sqlRequest::SQL_REQUEST_ERRORS ret; bool retSqlRequest; - sqlQuery = m_SQL_CHECK_IF_CATEGORY_ID_EXIST; + sqlQuery = m_SQL_REQUEST_CHECK_IF_CATEGORY_ID_EXIST; strStream.str(""); strStream << unique_id; sqlQuery += strStream.str(); + sqlQuery += ")"; sqlQuery += m_SQL_RETURN_BOOL_VALUE; query_result = mp_database->queryNotUTF(sqlQuery.c_str()); if (query_result.empty()) @@ -304,12 +368,94 @@ sqlRequest::SQL_REQUEST_ERRORS sqlRequest::removeCategory(POIServiceTypes::Categ { sqlRequest::SQL_REQUEST_ERRORS ret; + ret = OK; + return ret; } +sqlRequest::SQL_REQUEST_ERRORS sqlRequest::getFreeCategoryId(POIServiceTypes::CategoryID& unique_id) +{ + sqlRequest::SQL_REQUEST_ERRORS ret; + vector<vector<string> > query_result; + vector<string > query_line; + // retrieve the next free category id + query_result = mp_database->queryNotUTF(m_SQL_REQUEST_GET_AVAILABLE_NEXT_FREE_CATEGORY_ID); + if (query_result.empty()) + { + onError(); //database is not well populated + //todo something with table ? + ret = DATABASE_ACCESS_ERROR; + } + else + { // Id + query_line = query_result.at(0); + fromString<categoryId_t>(unique_id,query_line[0], std::dec); + ret = OK; + } + return ret; +} + +sqlRequest::SQL_REQUEST_ERRORS sqlRequest::getFreeAttributeId(POIServiceTypes::AttributeID &unique_id) +{ + sqlRequest::SQL_REQUEST_ERRORS ret; + vector<vector<string> > query_result; + vector<string > query_line; + + // retrieve the next free category id + query_result = mp_database->queryNotUTF(m_SQL_REQUEST_GET_AVAILABLE_NEXT_FREE_ATTRIBUTE_ID); + if (query_result.empty()) + { + onError(); //database is not well populated + //todo something with table ? + ret = DATABASE_ACCESS_ERROR; + } + else + { // Id + query_line = query_result.at(0); + fromString<attributeId_t>(unique_id,query_line[0], std::dec); + ret = OK; + } + + return ret; +} + +sqlRequest::SQL_REQUEST_ERRORS sqlRequest::checkIfAttributeExist(POIServiceTypes::AttributeID unique_id) +{ + std::string sqlQuery; //SQL request on database + vector<vector<string> > query_result; + vector<string > query_line; + std::ostringstream strStream; //temporary stream used for transformation into string + sqlRequest::SQL_REQUEST_ERRORS ret; + bool retSqlRequest; + + sqlQuery = m_SQL_REQUEST_CHECK_IF_ATTRIBUTE_ID_EXIST; + strStream.str(""); + strStream << unique_id; + sqlQuery += strStream.str(); + sqlQuery += ")"; + sqlQuery += m_SQL_RETURN_BOOL_VALUE; + query_result = mp_database->queryNotUTF(sqlQuery.c_str()); + if (query_result.empty()) + { + onError(); //database is not well populated + //todo something with table ? + ret = DATABASE_ACCESS_ERROR; + } + else + { + // read the result of the query + query_line = query_result.at(0); + fromString<bool>(retSqlRequest,query_line[0], std::dec); + if (retSqlRequest) + ret = OK; + else + ret = ATTRIBUTE_ID_NOT_EXIST; + } + return ret; +} PoiManagerServerStub::PoiManagerServerStub() { m_version.versionMajor = 1; @@ -405,12 +551,28 @@ void PoiManagerServerStub::getChildrenCategories(const std::shared_ptr<CommonAPI void PoiManagerServerStub::createCategory(const std::shared_ptr<CommonAPI::ClientId> clientId, POIServiceTypes::CAMCategory category, POIServiceTypes::CategoryID& unique_id) { - + mp_sqlRequest->createCategory(category,unique_id); + refreshCategoryList(); } void PoiManagerServerStub::removeCategories(const std::shared_ptr<CommonAPI::ClientId> clientId, std::vector<POIServiceTypes::CategoryID> categories) { + size_t index; + for(index=0;index<categories.size();index++) + { + if (mp_sqlRequest->removeCategory(categories.at(index)) != sqlRequest::OK) + break; + } + if (index<categories.size()) + { //it failed +//to do something + } + else + { + fireCategoriesRemovedEvent(categories); + refreshCategoryList(); + } } void PoiManagerServerStub::addPOIs(const std::shared_ptr<CommonAPI::ClientId> clientId, POIServiceTypes::CategoryID unique_id, std::vector<POIServiceTypes::PoiAddedDetails> poiList) @@ -427,6 +589,25 @@ bool PoiManagerServerStub::initDatabase(const char* poiDatabaseFileName) { mp_sqlRequest->setDatabase(poiDatabaseFileName); refreshCategoryList(); //read the database and buffer the category list locally + + POIServiceTypes::CAMCategory category; + POIServiceTypes::CategoryAttribute attribute; + POIServiceTypes::CategoryID unique_id; + + category.details.name = "recreation"; + attribute.id = 2; + attribute.name = "phone"; + category.attributes.push_back(attribute); + attribute.id = 13; + attribute.name = "credit card"; + category.attributes.push_back(attribute); + category.details.parentsId.push_back(0); + mp_sqlRequest->createCategory(category,unique_id); + refreshCategoryList(); //read the database and buffer the category list locally + + mp_sqlRequest->removeCategory(unique_id); + refreshCategoryList(); //read the database and buffer the category list locally + return true; //maybe add some check of the file here } diff --git a/src/poi-service/poi-manager-server/poi-manager-server-stub.h b/src/poi-service/poi-manager-server/poi-manager-server-stub.h index 9880e31..c5bb1f9 100644 --- a/src/poi-service/poi-manager-server/poi-manager-server-stub.h +++ b/src/poi-service/poi-manager-server/poi-manager-server-stub.h @@ -50,6 +50,7 @@ public: CATEGORY_NOT_EXIST, CATEGORY_NAME_ALREADY_EXIST, CATEGORY_ID_NOT_EXIST, + ATTRIBUTE_ID_NOT_EXIST, PARENT_CATEGORY_NOT_EXIST, DATABASE_ACCESS_ERROR, OK @@ -70,12 +71,18 @@ private: const char* m_SQL_REQUEST_GET_CHILD_CATEGORIES = "SELECT childId FROM poicategorykinship WHERE parentId IS "; const char* m_SQL_REQUEST_GET_CATEGORY_ICONS = "SELECT url,format FROM iconset WHERE Id IS (SELECT iconset_Id FROM isdisplayedas WHERE poicategory_Id IS "; const char* m_SQL_REQUEST_GET_AVAILABLE_NEXT_FREE_CATEGORY_ID = "SELECT a.id+1 FROM poicategory a WHERE NOT EXISTS (SELECT * FROM poicategory b WHERE a.id+1 = b.id) ORDER BY a.id"; + const char* m_SQL_REQUEST_GET_AVAILABLE_NEXT_FREE_ATTRIBUTE_ID = "SELECT a.id+1 FROM poiattribute a WHERE NOT EXISTS (SELECT * FROM poicategory b WHERE a.id+1 = b.id) ORDER BY a.id"; const char* m_SQL_REQUEST_GET_AVAILABLE_NEXT_FREE_POI_ID = "SELECT a.id+1 FROM poi a WHERE NOT EXISTS (SELECT * FROM poi b WHERE a.id+1 = b.id) ORDER BY a.id"; - const char* m_SQL_INSERT_CATEGORY = "INSERT INTO poicategory VALUES ("; - const char* m_SQL_DELETE_CATEGORY = "DELETE from poicategory WHERE id = "; - const char* m_SQL_CHECK_IF_CATEGORY_ID_EXIST = "SELECT CASE WHEN EXISTS (SELECT * FROM poicategory WHERE id = "; - const char* m_SQL_CHECK_IF_CATEGORY_NAME_EXIST = "SELECT CASE WHEN EXISTS (SELECT * FROM poicategory WHERE name = "; - const char* m_SQL_RETURN_BOOL_VALUE = "THEN CAST(1 AS BIT) ELSE CAST(0 AS BIT) END"; + const char* m_SQL_REQUEST_INSERT_CATEGORY = "INSERT INTO poicategory VALUES ("; + const char* m_SQL_REQUEST_DELETE_CATEGORY = "DELETE from poicategory WHERE id = "; + const char* m_SQL_REQUEST_CHECK_IF_CATEGORY_ID_EXIST = "SELECT CASE WHEN EXISTS (SELECT * FROM poicategory WHERE id = "; + const char* m_SQL_REQUEST_CHECK_IF_CATEGORY_NAME_EXIST = "SELECT CASE WHEN EXISTS (SELECT * FROM poicategory WHERE name = "; + const char* m_SQL_REQUEST_INSERT_ATTRIBUTE = "INSERT INTO poiattribute VALUES ("; + const char* m_SQL_REQUEST_DELETE_ATTRIBUTE = "DELETE from poiattribute WHERE id = "; + const char* m_SQL_REQUEST_CHECK_IF_ATTRIBUTE_ID_EXIST = "SELECT CASE WHEN EXISTS (SELECT * FROM poiattribute WHERE id = "; + const char* m_SQL_REQUEST_GET_POI_PROVIDER_ID = "(SELECT Id FROM poiprovider WHERE name='OpenStreetMap')"; + const char* m_SQL_RETURN_BOOL_VALUE = " THEN CAST(1 AS BIT) ELSE CAST(0 AS BIT) END;"; + const char* m_SQL_REQUEST_INSERT_BELONGSTO = "INSERT INTO belongsto (Id,poiprovider_Id,poicategory_Id,poi_Id) "; Database *mp_database; // database access @@ -93,6 +100,12 @@ private: SQL_REQUEST_ERRORS checkIfCategoryIdExist(POIServiceTypes::CategoryID unique_id); + SQL_REQUEST_ERRORS checkIfAttributeExist(POIServiceTypes::AttributeID unique_id); + + SQL_REQUEST_ERRORS getFreeCategoryId(POIServiceTypes::CategoryID &unique_id); + + SQL_REQUEST_ERRORS getFreeAttributeId(POIServiceTypes::AttributeID &unique_id); + void getAvailableArea(); NavigationTypes::Coordinate2D m_leftBottomLocation,m_rightTopLocation; diff --git a/src/poi-service/script/build-for-commonapi.sh b/src/poi-service/script/build-for-commonapi.sh new file mode 100755 index 0000000..4a14a26 --- /dev/null +++ b/src/poi-service/script/build-for-commonapi.sh @@ -0,0 +1,77 @@ +#!/bin/bash + +########################################################################### +# @licence app begin@ +# SPDX-License-Identifier: MPL-2.0 +# +# Component Name: poi-server +# Author: Philippe Colliot <philippe.colliot@mpsa.com> +# +# Copyright (C) 2013-2014, PCA Peugeot Citroen +# +# License: +# This Source Code Form is subject to the terms of the +# Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with +# this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# @licence end@ +########################################################################### +POI_MANAGER_SERVER=poi-manager-server + +target_root=$PWD/.. +target_bin=$PWD/../bin #by default + +set-path() +{ + TOP_DIR=$target_root + TOP_BIN_DIR=$target_bin + POI_MANAGER_SERVER_SRC_DIR=$TOP_DIR/$POI_MANAGER_SERVER + POI_MANAGER_SERVER_BIN_DIR=$TOP_BIN_DIR/$POI_MANAGER_SERVER +} + +usage() { + echo "Usage: ./build.sh [command]" + echo + echo "command:" + echo " make Build" + echo " clean Clean" + echo " help Print Help" + echo + echo +} + +build() { + + echo '' + echo 'Building poi-manager-server' + + cd $TOP_BIN_DIR + mkdir -p $POI_MANAGER_SERVER + cd $POI_MANAGER_SERVER_BIN_DIR + cmake -DCOMMON_API_PATH_GENERATED_FILES=../../../api/franca/navigation/src-gen -DDBUS_LIB_PATH=/usr/local/lib $POI_MANAGER_SERVER_SRC_DIR && make + +} + +clean() { + echo 'delete' $TOP_BIN_DIR + rm -rf $TOP_BIN_DIR +} + + +set -e + +if [ $# -ge 1 ]; then + if [ $1 = help ]; then + usage + elif [ $1 = make ]; then + set-path + build + elif [ $1 = clean ]; then + set-path + clean + else + usage + fi +else + usage +fi diff --git a/src/poi-service/script/build.sh b/src/poi-service/script/build.sh index c02195e..3fc0f1a 100755 --- a/src/poi-service/script/build.sh +++ b/src/poi-service/script/build.sh @@ -17,7 +17,6 @@ # @licence end@ ########################################################################### POI_SERVER=poi-server -POI_MANAGER_SERVER=poi-manager-server POI_COMMON=poi-common NAVIGATION_CORE=navigation-core MAP_VIEWER=map-viewer @@ -34,8 +33,6 @@ set-path() POI_SERVER_SRC_DIR=$TOP_DIR/$POI_SERVER POI_SERVER_BIN_DIR=$TOP_BIN_DIR/$POI_SERVER - POI_MANAGER_SERVER_SRC_DIR=$TOP_DIR/$POI_MANAGER_SERVER - POI_MANAGER_SERVER_BIN_DIR=$TOP_BIN_DIR/$POI_MANAGER_SERVER POI_COMMON_SRC_DIR=$TOP_DIR/$POI_COMMON } @@ -68,15 +65,6 @@ build() { mkdir -p $POI_SERVER cd $POI_SERVER_BIN_DIR cmake -Dapi_DIR=$API_DIR -Dgenerated_api_DIR=$GENERATED_API_DIR $POI_SERVER_SRC_DIR && make - - echo '' - echo 'Building poi-manager-server' - - cd $TOP_BIN_DIR - mkdir -p $POI_MANAGER_SERVER - cd $POI_MANAGER_SERVER_BIN_DIR - cmake -DCOMMON_API_PATH_GENERATED_FILES=../../../api/franca/navigation/src-gen -DDBUS_LIB_PATH=/usr/local/lib $POI_MANAGER_SERVER_SRC_DIR && make - } clean() { |