diff --git a/CHANGES_NEXT_RELEASE b/CHANGES_NEXT_RELEASE index e69de29bb2..5ff9e28073 100644 --- a/CHANGES_NEXT_RELEASE +++ b/CHANGES_NEXT_RELEASE @@ -0,0 +1 @@ +- Fix: registrations with more than one contextRegistration element (not possible in NGSIv2) are logged as Runtime Errors diff --git a/CMakeLists.txt b/CMakeLists.txt index 9c922231cf..3feac647f4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -187,20 +187,18 @@ ENDIF() SET (ORION_LIBS common + rest # verbName(Verb) from setExtendedHttpInfo@MongoCommonSubscription.cpp.o; jsonRequestTreat from payloadParse@RestService.cpp.o; serviceRoutinesV2 serviceRoutines ngsiNotify - rest # verbName(Verb) from setExtendedHttpInfo@MongoCommonSubscription.cpp.o; jsonRequestTreat from payloadParse@RestService.cpp.o; - jsonParse jsonParseV2 rest # this is repeated for linking str2Verb from parseSubscription@parseSubscription.cpp.o; # verbName(Verb) from setExtendedHttpInfo@MongoCommonSubscription.cpp.o - convenience - ngsi9 + mongoBackend ngsi10 ngsi cache - mongoBackend + mongoBackend # repeated (probably due to some circular dependency between mongoBackend and ngsi) mongoDriver parse apiTypesV2 @@ -325,13 +323,10 @@ if (error EQUAL 0) ADD_SUBDIRECTORY(src/lib/ngsi) ADD_SUBDIRECTORY(src/lib/serviceRoutines) ADD_SUBDIRECTORY(src/lib/serviceRoutinesV2) - ADD_SUBDIRECTORY(src/lib/convenience) - ADD_SUBDIRECTORY(src/lib/ngsi9) ADD_SUBDIRECTORY(src/lib/ngsi10) ADD_SUBDIRECTORY(src/lib/ngsiNotify) ADD_SUBDIRECTORY(src/lib/apiTypesV2) ADD_SUBDIRECTORY(src/lib/parse) - ADD_SUBDIRECTORY(src/lib/jsonParse) ADD_SUBDIRECTORY(src/lib/jsonParseV2) ADD_SUBDIRECTORY(src/lib/rest) ADD_SUBDIRECTORY(src/lib/mongoBackend) diff --git a/doc/manuals.jp/admin/cli.md b/doc/manuals.jp/admin/cli.md index bdc50ba14a..1d20fcb7ca 100644 --- a/doc/manuals.jp/admin/cli.md +++ b/doc/manuals.jp/admin/cli.md @@ -94,9 +94,6 @@ broker はデフォルトでバックグラウンドで実行されるため、 - **-logLineMaxSize** : ログ行の最大長 (超過すると、Orion は `LINE TOO LONG` をログ・トレースとして出力します)。最小許容値:100バイト。デフォルト値:32キロバイト。Orion の起動後に [log admin REST API](management_api.md#log-configs-and-trace-levels) の `lineMaxSize` フィールドで変更できます - **-logInfoPayloadMaxSize** : リクエストおよび/またはレスポンス・ペイロードを出力する INFO レベルのログ・トレースの場合、これはそれらのペイロードに許可される最大サイズです。ペイロード・サイズがこの設定より大きい場合、最初の `-logInfoPayloadMaxSize` バイトのみが含まれます (そして、`(...)` の形式の省略記号がトレースに表示されます)。デフォルト値:5キロバイト。Orion の起動後に [log admin REST API](management_api.md#log-configs-and-trace-levels) で `infoPayloadMaxSize` フィールドを使用して変更できます。 - **-disableMetrics** : 'metrics' 機能をオフにします。メトリックの収集は、システムコールやセマフォが関与するため、少しコストがかかります。メトリックオーバーヘッドなしで broker を起動するには、このパラメータを使用します -- **-disableNgsiv1** : NGSIv1 操作をオフにします。 API エンドポイントのみが無効になることに注意してください。 - [`"attrsFormat": "legacy"`](../orion-api.md#subscriptionnotification) を使用する通知や、 - [`"legacyForwarding": true`](../orion-api.md#registrationprovider) を使用するレジストレーションに対応するリクエスト転送は機能します - **-insecureNotif** : 既知の CA 証明書で認証できないピアへの HTTPS 通知を許可する。これは、curl コマンドのパラメータ `-k` または `--insecureparameteres` に似ています - **-mqttMaxAge** : 未使用の MQTT 接続が保持される最大時間 (分単位)。デフォルト値: 60 - **-logDeprecate** : 非推奨の使用法を警告として記録します。詳細については、[ドキュメントのこのセクション](../deprecated.md#log-deprecation-warnings) を参照してください。デフォルトは false です。これは、Orion の起動後に [log admin REST API](management_api.md#log-configs-and-trace-levels) を使用して `deprecated` フィールドを使用して変更できます @@ -160,14 +157,11 @@ Orion は、環境変数を使用した引数の受け渡しをサポートし | ORION_STAT_NOTIF_QUEUE | statNotifQueue | | ORION_LOG_SUMMARY_PERIOD | logSummary | | ORION_RELOG_ALARMS | relogAlarms | -| ORION_CHECK_ID_V1 | strictNgsiv1Ids | | ORION_DISABLE_CUSTOM_NOTIF | disableCustomNotifications | | ORION_DISABLE_FILE_LOG | disableFileLog | | ORION_LOG_FOR_HUMANS | logForHumans | | ORION_LOG_LINE_MAX_SIZE | logLineMaxSize | | ORION_LOG_INFO_PAYLOAD_MAX_SIZE | logInfoPayloadMaxSize | | ORION_DISABLE_METRICS | disableMetrics | -| ORION_DISABLE_NGSIV1 | disableNgsiv1 | | ORION_INSECURE_NOTIF | insecureNotif | -| ORION_NGSIV1_AUTOCAST | ngsiv1Autocast | | ORION_MQTT_MAX_AGE | mqttMaxAge | diff --git a/doc/manuals.jp/admin/logs.md b/doc/manuals.jp/admin/logs.md index 37962c15a4..da892c6ea9 100644 --- a/doc/manuals.jp/admin/logs.md +++ b/doc/manuals.jp/admin/logs.md @@ -351,8 +351,6 @@ time=2020-10-26T15:06:14.642Z | lvl=INFO | corr=c4a3192e-179c-11eb-ac8f-000c29df ``` time=2024-01-11T13:57:13.537Z | lvl=WARN | corr=527378d8-b089-11ee-875d-080027cd35f1 | trans=1704981432-655-00000000006 | from=127.0.0.1 | srv=s1 | subsrv=/A | comp=Orion | op=mongoRegistrationCreate.cpp[235]:mongoRegistrationCreate | msg=Deprecated usage of legacyForwarding mode in registration creation (regId: 659ff3b9691855f16d00ec5a) time=2024-01-11T13:57:13.565Z | lvl=WARN | corr=52778eaa-b089-11ee-861c-080027cd35f1 | trans=1704981432-655-00000000007 | from=127.0.0.1 | srv=s1 | subsrv=/A | comp=Orion | op=mongoRegistrationGet.cpp[93]:setProvider | msg=Deprecated usage of legacyForwarding mode detected in existing registration (regId: 659ff3b9691855f16d00ec5a) -time=2024-01-11T13:57:13.595Z | lvl=WARN | corr=527c0912-b089-11ee-bb8c-080027cd35f1 | trans=1704981432-655-00000000008 | from=127.0.0.1 | srv=s1 | subsrv=/A | comp=Orion | op=postQueryContext.cpp[191]:queryForward | msg=Deprecated usage of legacyForwarding mode in query forwarding operation (regId: 659ff3b9691855f16d00ec5a) -time=2024-01-11T13:57:13.624Z | lvl=WARN | corr=52808938-b089-11ee-9835-080027cd35f1 | trans=1704981432-655-00000000010 | from=127.0.0.1 | srv=s1 | subsrv=/A | comp=Orion | op=postUpdateContext.cpp[163]:updateForward | msg=Deprecated usage of legacyForwarding mode in update forwarding operation (regId: 659ff3b9691855f16d00ec5a) ``` * `geo:point`, `geo:line`, `geo:box` また `geo:line` の使用 diff --git a/doc/manuals.jp/admin/statistics.md b/doc/manuals.jp/admin/statistics.md index 2aa42f09e7..72fed7025b 100644 --- a/doc/manuals.jp/admin/statistics.md +++ b/doc/manuals.jp/admin/statistics.md @@ -44,8 +44,7 @@ Orion Context broker は、`GET /statistics` と `GET /cache/statistics` を介 "counters": { "deprecatedFeatures": { "geoFormat": 2, - "ngsiv1Forwarding": 4, - "ngsiv1Requests": 4 + "ngsiv1Forwarding": 4 }, "invalidRequests": 2, "jsonRequests": 4, @@ -113,7 +112,6 @@ SemWait ブロックは、メインの内部セマフォの累積待ち時間を ... "timing": { "accumulated": { - "jsonV1Parse": 7.860908311, "jsonV2Parse": 120.680244446, "mongoBackend": 12778.52734375, "mongoReadWait": 7532.301757812, @@ -143,7 +141,6 @@ SemWait ブロックは、メインの内部セマフォの累積待ち時間を 特定のカウンタは次のとおりです : * `total` : HTTP ライブラリがリクエスト/レスポンス・ディスパッチ (擬似エンド・ツー・エンド時間) にかかる時間を除く、リクエスト全体の処理時間です -* `jsonV1Parse` : NGSIv1 JSON パース・モジュールで渡された時間です (疑似セルフタイム) * `jsonV2Parse` : NGSIv2 JSON パース・モジュールで渡された時間です (疑似セルフタイム) * `mongoBackend` : mongoBackend モジュールで渡された時間です (疑似セルフタイム) * `render` : レンダリングモジュールに渡された時間です (擬似セルフタイム) diff --git a/doc/manuals.jp/devel/ServiceRoutines.txt b/doc/manuals.jp/devel/ServiceRoutines.txt index 100340df28..f63c23057f 100644 --- a/doc/manuals.jp/devel/ServiceRoutines.txt +++ b/doc/manuals.jp/devel/ServiceRoutines.txt @@ -76,242 +76,6 @@ API V2: * /v2/op/update badVerbPostOnly -V0 STANDARD REGISTRY REQUESTS: -==================================================================================================== - POST /ngsi9/registerContext postRegisterContext ------------------------------------------------------------------------------------------------------> mongoRegisterContext - * /ngsi9/registerContext badVerbPostOnly - - POST /ngsi9/discoverContextAvailability postDiscoverContextAvailability ------------------------------------------------------------------------------------------> mongoDiscoverContextAvailability - * /ngsi9/discoverContextAvailability badVerbPostOnly - - -V1 STANDARD REGISTRY REQUESTS: -==================================================================================================== - POST /v1/registerContext postRegisterContext ------------------------------------------------------------------------------------------------------> mongoRegisterContext - * /v1/registerContext badVerbPostOnly - - POST /v1/discoverContextAvailability postDiscoverContextAvailability ------------------------------------------------------------------------------------------> mongoDiscoverContextAvailability - * /v1/discoverContextAvailability badVerbPostOnly - - -V0 STANDARD REQUESTS: -==================================================================================================== - POST /ngsi10/updateContext postUpdateContext --------------------------------------------------------------------------------------------------------> mongoUpdateContext - * /ngsi10/updateContext badVerbPostOnly - - POST /ngsi10/queryContext postQueryContext ---------------------------------------------------------------------------------------------------------> mongoQueryContext - * /ngsi10/queryContext badVerbPostOnly - - POST /ngsi10/subscribeContext postSubscribeContext -----------------------------------------------------------------------------------------------------> mongoSubscribeContext - * /ngsi10/subscribeContext badVerbPostOnly - - POST /ngsi10/unsubscribeContext postUnsubscribeContext ---------------------------------------------------------------------------------------------------> mongoUnsubscribeContext - * /ngsi10/unsubscribeContext badVerbPostOnly - - POST /ngsi10/updateContextSubscription postUpdateContextSubscription --------------------------------------------------------------------------------------------> mongoUpdateContextSubscription - * /ngsi10/updateContextSubscription badVerbPostOnly - - POST /ngsi10/notifyContext postNotifyContext --------------------------------------------------------------------------------------------------------> mongoNotifyContext - * /ngsi10/notifyContext badVerbPostOnly - - -V1 STANDARD REQUESTS: -==================================================================================================== - POST /v1/updateContext postUpdateContext --------------------------------------------------------------------------------------------------------> mongoUpdateContext - * /v1/updateContext badVerbPostOnly - - POST /v1/queryContext postQueryContext ---------------------------------------------------------------------------------------------------------> mongoQueryContext - * /v1/queryContext badVerbPostOnly - - POST /v1/subscribeContext postSubscribeContext -----------------------------------------------------------------------------------------------------> mongoSubscribeContext - * /v1/subscribeContext badVerbPostOnly - - POST /v1/unsubscribeContext postUnsubscribeContext ---------------------------------------------------------------------------------------------------> mongoUnsubscribeContext - * /v1/unsubscribeContext badVerbPostOnly - - POST /v1/updateContextSubscription postUpdateContextSubscription --------------------------------------------------------------------------------------------> mongoUpdateContextSubscription - * /v1/updateContextSubscription badVerbPostOnly - - POST /v1/notifyContext postNotifyContext --------------------------------------------------------------------------------------------------------> mongoNotifyContext - * /v1/notifyContext badVerbPostOnly - - -V0 REGISTRY CONVENIENCE OPERATIONS: -==================================================================================================== - GET /ngsi9/contextEntities/{EID} getContextEntitiesByEntityId ------------------------------> postDiscoverContextAvailability -----------------------------> mongoDiscoverContextAvailability - POST /ngsi9/contextEntities/{EID} postContextEntitiesByEntityId -----------------------------> postRegisterContext -----------------------------------------> mongoRegisterContext - * /ngsi9/contextEntities/{EID} badVerbGetPostOnly - - GET /ngsi9/contextEntities/{EID}/attributes getContextEntityAttributes --------------------------------> postDiscoverContextAvailability -----------------------------> mongoDiscoverContextAvailability - POST /ngsi9/contextEntities/{EID}/attributes postContextEntityAttributes -------------------------------> postRegisterContext -----------------------------------------> mongoRegisterContext - * /ngsi9/contextEntities/{EID}/attributes badVerbGetPostOnly - - GET /ngsi9/contextEntities/{EID}/attributes/{ATTRNAME} getEntityByIdAttributeByName ------------------------------> postDiscoverContextAvailability -----------------------------> mongoDiscoverContextAvailability - POST /ngsi9/contextEntities/{EID}/attributes/{ATTRNAME} postEntityByIdAttributeByName -----------------------------> postRegisterContext -----------------------------------------> mongoRegisterContext - * /ngsi9/contextEntities/{EID}/attributes/{ATTRNAME} badVerbGetPostOnly - - GET /ngsi9/contextEntityTypes/{ETYPE} getContextEntityTypes -------------------------------------> postDiscoverContextAvailability -----------------------------> mongoDiscoverContextAvailability - POST /ngsi9/contextEntityTypes/{ETYPE} postContextEntityTypes ------------------------------------> postRegisterContext -----------------------------------------> mongoRegisterContext - * /ngsi9/contextEntityTypes/{ETYPE} badVerbGetPostOnly - - GET /ngsi9/contextEntityTypes/{ETYPE}/attributes getContextEntityTypes -------------------------------------> postDiscoverContextAvailability -----------------------------> mongoDiscoverContextAvailability - POST /ngsi9/contextEntityTypes/{ETYPE}/attributes postContextEntityTypes ------------------------------------> postRegisterContext -----------------------------------------> mongoRegisterContext - * /ngsi9/contextEntityTypes/{ETYPE}/attributes badVerbGetPostOnly - - GET /ngsi9/contextEntityTypes/{ETYPE}/attributes/{ATTRNAME} getContextEntityTypeAttribute -----------------------------> postDiscoverContextAvailability -----------------------------> mongoDiscoverContextAvailability - POST /ngsi9/contextEntityTypes/{ETYPE}/attributes/{ATTRNAME} postContextEntityTypeAttribute ----------------------------> postRegisterContext -----------------------------------------> mongoRegisterContext - * /ngsi9/contextEntityTypes/{ETYPE}/attributes/{ATTRNAME} badVerbGetPostOnly - - -V1 REGISTRY CONVENIENCE OPERATIONS: -==================================================================================================== - GET /v1/registry/contextEntities/{EID} getContextEntitiesByEntityId ------------------------------> postDiscoverContextAvailability -----------------------------> mongoDiscoverContextAvailability - POST /v1/registry/contextEntities/{EID} postContextEntitiesByEntityId -----------------------------> postRegisterContext -----------------------------------------> mongoRegisterContext - * /v1/registry/contextEntities/{EID} badVerbGetPostOnly - - GET /v1/registry/contextEntities/{EID}/attributes getContextEntityAttributes --------------------------------> postDiscoverContextAvailability -----------------------------> mongoDiscoverContextAvailability - POST /v1/registry/contextEntities/{EID}/attributes postContextEntityAttributes -------------------------------> postRegisterContext -----------------------------------------> mongoRegisterContext - * /v1/registry/contextEntities/{EID}/attributes badVerbGetPostOnly - - GET /v1/registry/contextEntities/{EID}/attributes/{ATTRNAME} getEntityByIdAttributeByName ------------------------------> postDiscoverContextAvailability -----------------------------> mongoDiscoverContextAvailability - POST /v1/registry/contextEntities/{EID}/attributes/{ATTRNAME} postEntityByIdAttributeByName -----------------------------> postRegisterContext -----------------------------------------> mongoRegisterContext - * /v1/registry/contextEntities/{EID}/attributes/{ATTRNAME} badVerbGetPostOnly - - GET /v1/registry/contextEntityTypes/{ETYPE} getContextEntityTypes -------------------------------------> postDiscoverContextAvailability -----------------------------> mongoDiscoverContextAvailability - POST /v1/registry/contextEntityTypes/{ETYPE} postContextEntityTypes ------------------------------------> postRegisterContext -----------------------------------------> mongoRegisterContext - * /v1/registry/contextEntityTypes/{ETYPE} badVerbGetPostOnly - - GET /v1/registry/contextEntityTypes/{ETYPE}/attributes getContextEntityTypes -------------------------------------> postDiscoverContextAvailability -----------------------------> mongoDiscoverContextAvailability - POST /v1/registry/contextEntityTypes/{ETYPE}/attributes postContextEntityTypes ------------------------------------> postRegisterContext -----------------------------------------> mongoRegisterContext - * /v1/registry/contextEntityTypes/{ETYPE}/attributes badVerbGetPostOnly - - GET /v1/registry/contextEntityTypes/{ETYPE}/attributes/{ATTRNAME} getContextEntityTypeAttribute -----------------------------> postDiscoverContextAvailability -----------------------------> mongoDiscoverContextAvailability - POST /v1/registry/contextEntityTypes/{ETYPE}/attributes/{ATTRNAME} postContextEntityTypeAttribute ----------------------------> postRegisterContext -----------------------------------------> mongoRegisterContext - * /v1/registry/contextEntityTypes/{ETYPE}/attributes/{ATTRNAME} badVerbGetPostOnly - -V0 CONVENIENCE OPERATIONS: -==================================================================================================== - GET /ngsi10/contextEntities/{EID} getIndividualContextEntity --------------------------------> postQueryContext --------------------------------------------> mongoQueryContext - PUT /ngsi10/contextEntities/{EID} putIndividualContextEntity --------------------------------> postUpdateContext -------------------------------------------> mongoUpdateContext - POST /ngsi10/contextEntities/{EID} postIndividualContextEntity -------------------------------> postUpdateContext -------------------------------------------> mongoUpdateContext - DELETE /ngsi10/contextEntities/{EID} deleteIndividualContextEntity -----------------------------> postUpdateContext -------------------------------------------> mongoUpdateContext - * /ngsi10/contextEntities/{EID} badVerbAllFour - - GET /ngsi10/contextEntities/{EID}/attributes getIndividualContextEntity --------------------------------> postQueryContext --------------------------------------------> mongoQueryContext - PUT /ngsi10/contextEntities/{EID}/attributes putIndividualContextEntity --------------------------------> postUpdateContext -------------------------------------------> mongoUpdateContext - POST /ngsi10/contextEntities/{EID}/attributes postIndividualContextEntity -------------------------------> postUpdateContext -------------------------------------------> mongoUpdateContext - DELETE /ngsi10/contextEntities/{EID}/attributes deleteIndividualContextEntity -----------------------------> postUpdateContext -------------------------------------------> mongoUpdateContext - * /ngsi10/contextEntities/{EID}/attributes badVerbAllFour - - GET /ngsi10/contextEntities/{EID}/attributes/{ATTRNAME} getIndividualContextEntityAttribute -----------------------> postQueryContext --------------------------------------------> mongoQueryContext - PUT /ngsi10/contextEntities/{EID}/attributes/{ATTRNAME} putIndividualContextEntityAttribute -----------------------> postUpdateContext -------------------------------------------> mongoUpdateContext - POST /ngsi10/contextEntities/{EID}/attributes/{ATTRNAME} postIndividualContextEntityAttribute ----------------------> postUpdateContext -------------------------------------------> mongoUpdateContext - DELETE /ngsi10/contextEntities/{EID}/attributes/{ATTRNAME} deleteIndividualContextEntityAttribute --------------------> postUpdateContext -------------------------------------------> mongoUpdateContext - * /ngsi10/contextEntities/{EID}/attributes/{ATTRNAME} badVerbAllFour - - GET /ngsi10/contextEntities/{EID}/attributes/{ATTRNAME}/{ID} getAttributeValueInstance ---------------------------------> postQueryContext --------------------------------------------> mongoQueryContext - PUT /ngsi10/contextEntities/{EID}/attributes/{ATTRNAME}/{ID} putAttributeValueInstance ---------------------------------> postUpdateContext -------------------------------------------> mongoUpdateContext - DELETE /ngsi10/contextEntities/{EID}/attributes/{ATTRNAME}/{ID} deleteAttributeValueInstance ------------------------------> postUpdateContext -------------------------------------------> mongoUpdateContext - * /ngsi10/contextEntities/{EID}/attributes/{ATTRNAME}/{ID} badVerbGetPutDeleteOnly - - GET /ngsi10/contextEntityTypes/{ETYPE} getNgsi10ContextEntityTypes -------------------------------> postQueryContext --------------------------------------------> mongoQueryContext - * /ngsi10/contextEntityTypes/{ETYPE} badVerbGetOnly - - GET /ngsi10/contextEntityTypes/{ETYPE}/attributes getNgsi10ContextEntityTypes -------------------------------> postQueryContext --------------------------------------------> mongoQueryContext - * /ngsi10/contextEntityTypes/{ETYPE}/attributes badVerbGetOnlyy - - GET /ngsi10/contextEntityTypes/{ETYPE}/attributes/{ATTRNAME} getNgsi10ContextEntityTypesAttribute ----------------------> postQueryContext --------------------------------------------> mongoQueryContext - * /ngsi10/contextEntityTypes/{ETYPE}/attributes/{ATTRNAME} badVerbGetOnly - - POST /ngsi10/contextSubscriptions postSubscribeContextConvOp --------------------------------> postSubscribeContext ----------------------------------------> mongoSubscribeContext - * /ngsi10/contextSubscriptions badVerbPostOnly - - PUT /ngsi10/contextSubscriptions/{SUBID} putSubscriptionConvOp -------------------------------------> postUpdateContextSubscription -------------------------------> mongoUpdateContextSubscription - DELETE /ngsi10/contextSubscriptions/{SUBID} deleteSubscriptionConvOp ----------------------------------> postUnsubscribeContext --------------------------------------> mongoUnsubscribeContext - * /ngsi10/contextSubscriptions/{SUBID} badVerbPutDeleteOnly - - -V1 CONVENIENCE OPERATIONS: -==================================================================================================== - GET /v1/contextEntities/{EID} getIndividualContextEntity --------------------------------> postQueryContext --------------------------------------------> mongoQueryContext - PUT /v1/contextEntities/{EID} putIndividualContextEntity --------------------------------> postUpdateContext -------------------------------------------> mongoUpdateContext - POST /v1/contextEntities/{EID} postIndividualContextEntity -------------------------------> postUpdateContext -------------------------------------------> mongoUpdateContext - DELETE /v1/contextEntities/{EID} deleteIndividualContextEntity -----------------------------> postUpdateContext -------------------------------------------> mongoUpdateContext - * /v1/contextEntities/{EID} badVerbAllFour - - GET /v1/contextEntities/{EID}/attributes getIndividualContextEntity --------------------------------> postQueryContext --------------------------------------------> mongoQueryContext - PUT /v1/contextEntities/{EID}/attributes putIndividualContextEntity --------------------------------> postUpdateContext -------------------------------------------> mongoUpdateContext - POST /v1/contextEntities/{EID}/attributes postIndividualContextEntity -------------------------------> postUpdateContext -------------------------------------------> mongoUpdateContext - DELETE /v1/contextEntities/{EID}/attributes deleteIndividualContextEntity -----------------------------> postUpdateContext -------------------------------------------> mongoUpdateContext - * /v1/contextEntities/{EID}/attributes badVerbAllFour - - GET /v1/contextEntities/{EID}/attributes/{ATTRNAME} getIndividualContextEntityAttribute -----------------------> postQueryContext --------------------------------------------> mongoQueryContext - PUT /v1/contextEntities/{EID}/attributes/{ATTRNAME} putIndividualContextEntityAttribute -----------------------> postUpdateContext -------------------------------------------> mongoUpdateContext - POST /v1/contextEntities/{EID}/attributes/{ATTRNAME} postIndividualContextEntityAttribute ----------------------> postUpdateContext -------------------------------------------> mongoUpdateContext - DELETE /v1/contextEntities/{EID}/attributes/{ATTRNAME} deleteIndividualContextEntityAttribute --------------------> postUpdateContext -------------------------------------------> mongoUpdateContext - * /v1/contextEntities/{EID}/attributes/{ATTRNAME} badVerbAllFour - - GET /v1/contextEntities/{EID}/attributes/{ATTRNAME}/{ID} getAttributeValueInstance ---------------------------------> postQueryContext --------------------------------------------> mongoQueryContext - PUT /v1/contextEntities/{EID}/attributes/{ATTRNAME}/{ID} putAttributeValueInstance ---------------------------------> postUpdateContext -------------------------------------------> mongoUpdateContext - DELETE /v1/contextEntities/{EID}/attributes/{ATTRNAME}/{ID} deleteAttributeValueInstance ------------------------------> postUpdateContext -------------------------------------------> mongoUpdateContext - * /v1/contextEntities/{EID}/attributes/{ATTRNAME}/{ID} badVerbGetPutDeleteOnly - - GET /v1/contextEntityTypes/{ETYPE} getNgsi10ContextEntityTypes -------------------------------> postQueryContext --------------------------------------------> mongoQueryContext - * /v1/contextEntityTypes/{ETYPE} badVerbGetOnly - - GET /v1/contextEntityTypes/{ETYPE}/attributes getNgsi10ContextEntityTypes -------------------------------> postQueryContext --------------------------------------------> mongoQueryContext - * /v1/contextEntityTypes/{ETYPE}/attributes badVerbGetOnlyy - - GET /v1/contextEntityTypes/{ETYPE}/attributes/{ATTRNAME} getNgsi10ContextEntityTypesAttribute ----------------------> postQueryContext --------------------------------------------> mongoQueryContext - * /v1/contextEntityTypes/{ETYPE}/attributes/{ATTRNAME} badVerbGetOnly - - POST /v1/contextSubscriptions postSubscribeContextConvOp --------------------------------> postSubscribeContext ----------------------------------------> mongoSubscribeContext - * /v1/contextSubscriptions badVerbPostOnly - - PUT /v1/contextSubscriptions/{SUBID} putSubscriptionConvOp -------------------------------------> postUpdateContextSubscription -------------------------------> mongoUpdateContextSubscription - DELETE /v1/contextSubscriptions/{SUBID} deleteSubscriptionConvOp ----------------------------------> postUnsubscribeContext --------------------------------------> mongoUnsubscribeContext - * /v1/contextSubscriptions/{SUBID} badVerbPutDeleteOnly - - -TID CONVENIENCE OPERATIONS: -==================================================================================================== - GET /v1/contextTypes getEntityTypes -----------------------------------------------------------------------------------------------------------> mongoEntityTypes - * /v1/contextTypes badVerbGetOnly - - GET /v1/contextTypes/{ETYPE} getAttributesForEntityType ----------------------------------------------------------------------------------------------> mongoAttributesForEntityType - * /v1/contextTypes/{ETYPE} badVerbGetOnly - - GET /v1/contextEntities getAllContextEntities -------------------------------> postQueryContext --------------------------------------------> mongoQueryContext - POST /v1/contextEntities postIndividualContextEntity -------------------------------> postUpdateContext -------------------------------------------> mongoUpdateContext - * /v1/contextEntities badVerbGetPostOnly - - GET /v1/contextEntities/type/{ETYPE}/id/{EID} getAllEntitiesWithTypeAndId -------------------------------> postQueryContext --------------------------------------------> mongoQueryContext - POST /v1/contextEntities/type/{ETYPE}/id/{EID} postAllEntitiesWithTypeAndId ------------------------------> postUpdateContext -------------------------------------------> mongoUpdateContext - PUT /v1/contextEntities/type/{ETYPE}/id/{EID} putAllEntitiesWithTypeAndId -------------------------------> postUpdateContext -------------------------------------------> mongoUpdateContext - DELETE /v1/contextEntities/type/{ETYPE}/id/{EID} deleteAllEntitiesWithTypeAndId ----------------------------> postUpdateContext -------------------------------------------> mongoUpdateContext - * /v1/contextEntities/type/{ETYPE}/id/{EID} badVerbAllFour - - GET /v1/contextEntities/type/{ETYPE}/id/{EID}/attributes/{ATTRNAME} getIndividualContextEntityAttributeWithTypeAndId -------> postQueryContext --------------------------------------------> mongoQueryContext - POST /v1/contextEntities/type/{ETYPE}/id/{EID}/attributes/{ATTRNAME} postIndividualContextEntityAttributeWithTypeAndId -------> postUpdateContext -------------------------------------------> mongoUpdateContext - PUT /v1/contextEntities/type/{ETYPE}/id/{EID}/attributes/{ATTRNAME} putIndividualContextEntityAttributeWithTypeAndId -------> postUpdateContext -------------------------------------------> mongoUpdateContext - DELETE /v1/contextEntities/type/{ETYPE}/id/{EID}/attributes/{ATTRNAME} deleteIndividualContextEntityAttributeWithTypeAndId -------> postUpdateContext -------------------------------------------> mongoUpdateContext - * /v1/contextEntities/type/{ETYPE}/id/{EID}/attributes/{ATTRNAME} badVerbAllFour - - GET /v1/contextEntities/type/{ETYPE}/id/{EID}/attributes/{ATTRNAME}/{ID} getAttributeValueInstanceWithTypeAndId -----------------> postQueryContext --------------------------------------------> mongoQueryContext - POST /v1/contextEntities/type/{ETYPE}/id/{EID}/attributes/{ATTRNAME}/{ID} postAttributeValueInstanceWithTypeAndId -----------------> postUpdateContext -------------------------------------------> mongoUpdateContext - PUT /v1/contextEntities/type/{ETYPE}/id/{EID}/attributes/{ATTRNAME}/{ID} putAttributeValueInstanceWithTypeAndId -----------------> postUpdateContext -------------------------------------------> mongoUpdateContext - DELETE /v1/contextEntities/type/{ETYPE}/id/{EID}/attributes/{ATTRNAME}/{ID} deleteAttributeValueInstanceWithTypeAndId -----------------> postUpdateContext -------------------------------------------> mongoUpdateContext - * /v1/contextEntities/type/{ETYPE}/id/{EID}/attributes/{ATTRNAME}/{ID} badVerbAllFour - - GET /v1/registry/contextEntities/type/{ETYPE}/id/{ID} getContextEntitiesByEntityIdAndType -----------------> postDiscoverContextAvailability -----------------------------> mongoDiscoverContextAvailability - POST /v1/registry/contextEntities/type/{ETYPE}/id/{ID} postContextEntitiesByEntityIdAndType -----------------> postRegisterContext -----------------------------------------> mongoRegisterContext - * /v1/registry/contextEntities/type/{ETYPE}/id/{ID} badVerbGetPostOnly - - GET /v1/registry/contextEntities/type/{ETYPE}/id/{ID}/attributes/{ATTRNAME} getEntityByIdAttributeByNameWithTypeAndId ----------------> postDiscoverContextAvailability -----------------------------> mongoDiscoverContextAvailability - POST /v1/registry/contextEntities/type/{ETYPE}/id/{ID}/attributes/{ATTRNAME} postEntityByIdAttributeByNameWithTypeAndId ----------------> postRegisterContext -----------------------------------------> mongoRegisterContext - * /v1/registry/contextEntities/type/{ETYPE}/id/{ID}/attributes/{ATTRNAME} badVerbGetPostOnly - - MISC REQUESTS: ==================================================================================================== GET /log/trace logTraceTreat @@ -330,38 +94,14 @@ MISC REQUESTS: DELETE /log/traceLevel/{TRACELEVEL} logTraceTreat * /log/traceLevel/{TRACELEVEL} badVerbPutDeleteOnly - GET /v1/admin/log/trace logTraceTreat - DELETE /v1/admin/log/trace logTraceTreat - * /v1/admin/log/trace badVerbGetDeleteOnly - - PUT /v1/admin/log/trace/{TRACELEVEL} logTraceTreat - DELETE /v1/admin/log/trace/{TRACELEVEL} logTraceTreat - * /v1/admin/log/trace/{TRACELEVEL} badVerbPutDeleteOnly - - GET /v1/admin/log/traceLevel logTraceTreat - DELETE /v1/admin/log/traceLevel logTraceTreat - * /v1/admin/log/traceLevel badVerbGetDeleteOnly - - PUT /v1/admin/log/traceLevel/{TRACELEVEL} logTraceTreat - DELETE /v1/admin/log/traceLevel/{TRACELEVEL} logTraceTreat - * /v1/admin/log/traceLevel/{TRACELEVEL} badVerbPutDeleteOnly - GET /statistics statisticsTreat DELETE /statistics statisticsTreat * /statistics badVerbGetDeleteOnly - GET /v1/admin/statistics statisticsTreat - DELETE /v1/admin/statistics statisticsTreat - * /v1/admin/statistics badVerbGetDeleteOnly - GET /cache/statistics statisticsCacheTreat DELETE /cache/statistics statisticsCacheTreat * /cache/statistics badVerbGetDeleteOnly - GET /v1/admin/cache/statistics statisticsCacheTreat - DELETE /v1/admin/cache/statistics statisticsCacheTreat - * /v1/admin/cache/statistics badVerbGetDeleteOnly - GET /version versionTreat OPTIONS /version optionsVersionRequest * /version badVerbGetOnly diff --git a/doc/manuals/admin/cli.md b/doc/manuals/admin/cli.md index 0159a4e1a8..b96a3a84d4 100644 --- a/doc/manuals/admin/cli.md +++ b/doc/manuals/admin/cli.md @@ -157,9 +157,6 @@ The list of available options is the following: - **-logInfoPayloadMaxSize**. For those log traces at INFO level that print request and/or response payloads, this is the maximum allowed size for those payloads. If the payload size is greater than this setting, then only the first `-logInfoPayloadMaxSize` bytes are included (and an ellipsis in the form of `(...)` is shown in trace). Default value: 5 KBytes. It can be changed after Orion startup with the [log admin REST API](management_api.md#log-configs-and-trace-levels), with the `infoPayloadMaxSize` field. - **-disableMetrics**. To turn off the 'metrics' feature. Gathering of metrics is a bit costly, as system calls and semaphores are involved. Use this parameter to start the broker without metrics overhead. -- **-disableNgsiv1**. To turn off NGSIv1 operations. Note that only API endpoints are disabled, notifications using - [`"attrsFormat": "legacy"`](../orion-api.md#subscriptionnotification) or forward requests corresponding to registrations - using [`"legacyForwarding": true`](../orion-api.md#registrationprovider) will work. - **-insecureNotif**. Allow HTTPS notifications to peers which certificate cannot be authenticated with known CA certificates. This is similar to the `-k` or `--insecure` parameteres of the curl command. - **-mqttMaxAge**. Max time (in minutes) that an unused MQTT connection is kept. Default: 60 @@ -224,15 +221,12 @@ Two facts have to be taken into account: | ORION_STAT_NOTIF_QUEUE | statNotifQueue | | ORION_LOG_SUMMARY_PERIOD | logSummary | | ORION_RELOG_ALARMS | relogAlarms | -| ORION_CHECK_ID_V1 | strictNgsiv1Ids | | ORION_DISABLE_CUSTOM_NOTIF | disableCustomNotifications | | ORION_DISABLE_FILE_LOG | disableFileLog | | ORION_LOG_FOR_HUMANS | logForHumans | | ORION_LOG_LINE_MAX_SIZE | logLineMaxSize | | ORION_LOG_INFO_PAYLOAD_MAX_SIZE | logInfoPayloadMaxSize | | ORION_DISABLE_METRICS | disableMetrics | -| ORION_DISABLE_NGSIV1 | disableNgsiv1 | | ORION_INSECURE_NOTIF | insecureNotif | -| ORION_NGSIV1_AUTOCAST | ngsiv1Autocast | | ORION_MQTT_MAX_AGE | mqttMaxAge | | ORION_LOG_DEPRECATE | logDeprecate | diff --git a/doc/manuals/admin/logs.md b/doc/manuals/admin/logs.md index ae145c427c..9624d7760f 100644 --- a/doc/manuals/admin/logs.md +++ b/doc/manuals/admin/logs.md @@ -411,8 +411,6 @@ following WARN traces are generated: ``` time=2024-01-11T13:57:13.537Z | lvl=WARN | corr=527378d8-b089-11ee-875d-080027cd35f1 | trans=1704981432-655-00000000006 | from=127.0.0.1 | srv=s1 | subsrv=/A | comp=Orion | op=mongoRegistrationCreate.cpp[235]:mongoRegistrationCreate | msg=Deprecated usage of legacyForwarding mode in registration creation (regId: 659ff3b9691855f16d00ec5a) time=2024-01-11T13:57:13.565Z | lvl=WARN | corr=52778eaa-b089-11ee-861c-080027cd35f1 | trans=1704981432-655-00000000007 | from=127.0.0.1 | srv=s1 | subsrv=/A | comp=Orion | op=mongoRegistrationGet.cpp[93]:setProvider | msg=Deprecated usage of legacyForwarding mode detected in existing registration (regId: 659ff3b9691855f16d00ec5a) -time=2024-01-11T13:57:13.595Z | lvl=WARN | corr=527c0912-b089-11ee-bb8c-080027cd35f1 | trans=1704981432-655-00000000008 | from=127.0.0.1 | srv=s1 | subsrv=/A | comp=Orion | op=postQueryContext.cpp[191]:queryForward | msg=Deprecated usage of legacyForwarding mode in query forwarding operation (regId: 659ff3b9691855f16d00ec5a) -time=2024-01-11T13:57:13.624Z | lvl=WARN | corr=52808938-b089-11ee-9835-080027cd35f1 | trans=1704981432-655-00000000010 | from=127.0.0.1 | srv=s1 | subsrv=/A | comp=Orion | op=postUpdateContext.cpp[163]:updateForward | msg=Deprecated usage of legacyForwarding mode in update forwarding operation (regId: 659ff3b9691855f16d00ec5a) ``` * Usages of `geo:point`, `geo:line`, `geo:box` or `geo:line`. diff --git a/doc/manuals/admin/statistics.md b/doc/manuals/admin/statistics.md index 2f8bf60f17..804f3c1ab9 100644 --- a/doc/manuals/admin/statistics.md +++ b/doc/manuals/admin/statistics.md @@ -56,8 +56,7 @@ The counter block provides information about counters for the times a particular "counters": { "deprecatedFeatures": { "geoFormat": 2, - "ngsiv1Forwarding": 4, - "ngsiv1Requests": 4 + "ngsiv1Forwarding": 4 }, "invalidRequests": 2, "jsonRequests": 4, @@ -127,7 +126,6 @@ Provides timing information, i.e. the time that CB passes executing in different ... "timing": { "accumulated": { - "jsonV1Parse": 7.860908311, "jsonV2Parse": 120.680244446, "mongoBackend": 12778.52734375, "mongoReadWait": 7532.301757812, @@ -159,7 +157,6 @@ The particular counters are as follows: * `total`: processing time for the whole request, excluding the time that the HTTP library takes for request/response dispatching (pseudo end-to-end time) -* `jsonV1Parse`: time passed in NGSIv1 JSON parsing module (pseudo self-time) * `jsonV2Parse`: time passed in NGSIv2 JSON parsing module (pseudo self-time) * `mongoBackend`: time passed in mongoBackend module (pseduo self-time) * `render`: time passed in rendering module (pseudo self-time) diff --git a/doc/manuals/devel/ServiceRoutines.txt b/doc/manuals/devel/ServiceRoutines.txt index f43c05a97f..a9710186eb 100644 --- a/doc/manuals/devel/ServiceRoutines.txt +++ b/doc/manuals/devel/ServiceRoutines.txt @@ -76,243 +76,6 @@ API V2: * /v2/op/update badVerbPostOnly -V0 STANDARD REGISTRY REQUESTS: -==================================================================================================== - POST /ngsi9/registerContext postRegisterContext ------------------------------------------------------------------------------------------------------> mongoRegisterContext - * /ngsi9/registerContext badVerbPostOnly - - POST /ngsi9/discoverContextAvailability postDiscoverContextAvailability ------------------------------------------------------------------------------------------> mongoDiscoverContextAvailability - * /ngsi9/discoverContextAvailability badVerbPostOnly - - -V1 STANDARD REGISTRY REQUESTS: -==================================================================================================== - POST /v1/registerContext postRegisterContext ------------------------------------------------------------------------------------------------------> mongoRegisterContext - * /v1/registerContext badVerbPostOnly - - POST /v1/discoverContextAvailability postDiscoverContextAvailability ------------------------------------------------------------------------------------------> mongoDiscoverContextAvailability - * /v1/discoverContextAvailability badVerbPostOnly - - -V0 STANDARD REQUESTS: -==================================================================================================== - POST /ngsi10/updateContext postUpdateContext --------------------------------------------------------------------------------------------------------> mongoUpdateContext - * /ngsi10/updateContext badVerbPostOnly - - POST /ngsi10/queryContext postQueryContext ---------------------------------------------------------------------------------------------------------> mongoQueryContext - * /ngsi10/queryContext badVerbPostOnly - - POST /ngsi10/subscribeContext postSubscribeContext -----------------------------------------------------------------------------------------------------> mongoSubscribeContext - * /ngsi10/subscribeContext badVerbPostOnly - - POST /ngsi10/unsubscribeContext postUnsubscribeContext ---------------------------------------------------------------------------------------------------> mongoUnsubscribeContext - * /ngsi10/unsubscribeContext badVerbPostOnly - - POST /ngsi10/updateContextSubscription postUpdateContextSubscription --------------------------------------------------------------------------------------------> mongoUpdateContextSubscription - * /ngsi10/updateContextSubscription badVerbPostOnly - - POST /ngsi10/notifyContext postNotifyContext --------------------------------------------------------------------------------------------------------> mongoNotifyContext - * /ngsi10/notifyContext badVerbPostOnly - - -V1 STANDARD REQUESTS: -==================================================================================================== - POST /v1/updateContext postUpdateContext --------------------------------------------------------------------------------------------------------> mongoUpdateContext - * /v1/updateContext badVerbPostOnly - - POST /v1/queryContext postQueryContext ---------------------------------------------------------------------------------------------------------> mongoQueryContext - * /v1/queryContext badVerbPostOnly - - POST /v1/subscribeContext postSubscribeContext -----------------------------------------------------------------------------------------------------> mongoSubscribeContext - * /v1/subscribeContext badVerbPostOnly - - POST /v1/unsubscribeContext postUnsubscribeContext ---------------------------------------------------------------------------------------------------> mongoUnsubscribeContext - * /v1/unsubscribeContext badVerbPostOnly - - POST /v1/updateContextSubscription postUpdateContextSubscription --------------------------------------------------------------------------------------------> mongoUpdateContextSubscription - * /v1/updateContextSubscription badVerbPostOnly - - POST /v1/notifyContext postNotifyContext --------------------------------------------------------------------------------------------------------> mongoNotifyContext - * /v1/notifyContext badVerbPostOnly - - -V0 REGISTRY CONVENIENCE OPERATIONS: -==================================================================================================== - GET /ngsi9/contextEntities/{EID} getContextEntitiesByEntityId ------------------------------> postDiscoverContextAvailability -----------------------------> mongoDiscoverContextAvailability - POST /ngsi9/contextEntities/{EID} postContextEntitiesByEntityId -----------------------------> postRegisterContext -----------------------------------------> mongoRegisterContext - * /ngsi9/contextEntities/{EID} badVerbGetPostOnly - - GET /ngsi9/contextEntities/{EID}/attributes getContextEntityAttributes --------------------------------> postDiscoverContextAvailability -----------------------------> mongoDiscoverContextAvailability - POST /ngsi9/contextEntities/{EID}/attributes postContextEntityAttributes -------------------------------> postRegisterContext -----------------------------------------> mongoRegisterContext - * /ngsi9/contextEntities/{EID}/attributes badVerbGetPostOnly - - GET /ngsi9/contextEntities/{EID}/attributes/{ATTRNAME} getEntityByIdAttributeByName ------------------------------> postDiscoverContextAvailability -----------------------------> mongoDiscoverContextAvailability - POST /ngsi9/contextEntities/{EID}/attributes/{ATTRNAME} postEntityByIdAttributeByName -----------------------------> postRegisterContext -----------------------------------------> mongoRegisterContext - * /ngsi9/contextEntities/{EID}/attributes/{ATTRNAME} badVerbGetPostOnly - - GET /ngsi9/contextEntityTypes/{ETYPE} getContextEntityTypes -------------------------------------> postDiscoverContextAvailability -----------------------------> mongoDiscoverContextAvailability - POST /ngsi9/contextEntityTypes/{ETYPE} postContextEntityTypes ------------------------------------> postRegisterContext -----------------------------------------> mongoRegisterContext - * /ngsi9/contextEntityTypes/{ETYPE} badVerbGetPostOnly - - GET /ngsi9/contextEntityTypes/{ETYPE}/attributes getContextEntityTypes -------------------------------------> postDiscoverContextAvailability -----------------------------> mongoDiscoverContextAvailability - POST /ngsi9/contextEntityTypes/{ETYPE}/attributes postContextEntityTypes ------------------------------------> postRegisterContext -----------------------------------------> mongoRegisterContext - * /ngsi9/contextEntityTypes/{ETYPE}/attributes badVerbGetPostOnly - - GET /ngsi9/contextEntityTypes/{ETYPE}/attributes/{ATTRNAME} getContextEntityTypeAttribute -----------------------------> postDiscoverContextAvailability -----------------------------> mongoDiscoverContextAvailability - POST /ngsi9/contextEntityTypes/{ETYPE}/attributes/{ATTRNAME} postContextEntityTypeAttribute ----------------------------> postRegisterContext -----------------------------------------> mongoRegisterContext - * /ngsi9/contextEntityTypes/{ETYPE}/attributes/{ATTRNAME} badVerbGetPostOnly - - -V1 REGISTRY CONVENIENCE OPERATIONS: -==================================================================================================== - GET /v1/registry/contextEntities/{EID} getContextEntitiesByEntityId ------------------------------> postDiscoverContextAvailability -----------------------------> mongoDiscoverContextAvailability - POST /v1/registry/contextEntities/{EID} postContextEntitiesByEntityId -----------------------------> postRegisterContext -----------------------------------------> mongoRegisterContext - * /v1/registry/contextEntities/{EID} badVerbGetPostOnly - - GET /v1/registry/contextEntities/{EID}/attributes getContextEntityAttributes --------------------------------> postDiscoverContextAvailability -----------------------------> mongoDiscoverContextAvailability - POST /v1/registry/contextEntities/{EID}/attributes postContextEntityAttributes -------------------------------> postRegisterContext -----------------------------------------> mongoRegisterContext - * /v1/registry/contextEntities/{EID}/attributes badVerbGetPostOnly - - GET /v1/registry/contextEntities/{EID}/attributes/{ATTRNAME} getEntityByIdAttributeByName ------------------------------> postDiscoverContextAvailability -----------------------------> mongoDiscoverContextAvailability - POST /v1/registry/contextEntities/{EID}/attributes/{ATTRNAME} postEntityByIdAttributeByName -----------------------------> postRegisterContext -----------------------------------------> mongoRegisterContext - * /v1/registry/contextEntities/{EID}/attributes/{ATTRNAME} badVerbGetPostOnly - - GET /v1/registry/contextEntityTypes/{ETYPE} getContextEntityTypes -------------------------------------> postDiscoverContextAvailability -----------------------------> mongoDiscoverContextAvailability - POST /v1/registry/contextEntityTypes/{ETYPE} postContextEntityTypes ------------------------------------> postRegisterContext -----------------------------------------> mongoRegisterContext - * /v1/registry/contextEntityTypes/{ETYPE} badVerbGetPostOnly - - GET /v1/registry/contextEntityTypes/{ETYPE}/attributes getContextEntityTypes -------------------------------------> postDiscoverContextAvailability -----------------------------> mongoDiscoverContextAvailability - POST /v1/registry/contextEntityTypes/{ETYPE}/attributes postContextEntityTypes ------------------------------------> postRegisterContext -----------------------------------------> mongoRegisterContext - * /v1/registry/contextEntityTypes/{ETYPE}/attributes badVerbGetPostOnly - - GET /v1/registry/contextEntityTypes/{ETYPE}/attributes/{ATTRNAME} getContextEntityTypeAttribute -----------------------------> postDiscoverContextAvailability -----------------------------> mongoDiscoverContextAvailability - POST /v1/registry/contextEntityTypes/{ETYPE}/attributes/{ATTRNAME} postContextEntityTypeAttribute ----------------------------> postRegisterContext -----------------------------------------> mongoRegisterContext - * /v1/registry/contextEntityTypes/{ETYPE}/attributes/{ATTRNAME} badVerbGetPostOnly - - -V0 CONVENIENCE OPERATIONS: -==================================================================================================== - GET /ngsi10/contextEntities/{EID} getIndividualContextEntity --------------------------------> postQueryContext --------------------------------------------> mongoQueryContext - PUT /ngsi10/contextEntities/{EID} putIndividualContextEntity --------------------------------> postUpdateContext -------------------------------------------> mongoUpdateContext - POST /ngsi10/contextEntities/{EID} postIndividualContextEntity -------------------------------> postUpdateContext -------------------------------------------> mongoUpdateContext - DELETE /ngsi10/contextEntities/{EID} deleteIndividualContextEntity -----------------------------> postUpdateContext -------------------------------------------> mongoUpdateContext - * /ngsi10/contextEntities/{EID} badVerbAllFour - - GET /ngsi10/contextEntities/{EID}/attributes getIndividualContextEntity --------------------------------> postQueryContext --------------------------------------------> mongoQueryContext - PUT /ngsi10/contextEntities/{EID}/attributes putIndividualContextEntity --------------------------------> postUpdateContext -------------------------------------------> mongoUpdateContext - POST /ngsi10/contextEntities/{EID}/attributes postIndividualContextEntity -------------------------------> postUpdateContext -------------------------------------------> mongoUpdateContext - DELETE /ngsi10/contextEntities/{EID}/attributes deleteIndividualContextEntity -----------------------------> postUpdateContext -------------------------------------------> mongoUpdateContext - * /ngsi10/contextEntities/{EID}/attributes badVerbAllFour - - GET /ngsi10/contextEntities/{EID}/attributes/{ATTRNAME} getIndividualContextEntityAttribute -----------------------> postQueryContext --------------------------------------------> mongoQueryContext - PUT /ngsi10/contextEntities/{EID}/attributes/{ATTRNAME} putIndividualContextEntityAttribute -----------------------> postUpdateContext -------------------------------------------> mongoUpdateContext - POST /ngsi10/contextEntities/{EID}/attributes/{ATTRNAME} postIndividualContextEntityAttribute ----------------------> postUpdateContext -------------------------------------------> mongoUpdateContext - DELETE /ngsi10/contextEntities/{EID}/attributes/{ATTRNAME} deleteIndividualContextEntityAttribute --------------------> postUpdateContext -------------------------------------------> mongoUpdateContext - * /ngsi10/contextEntities/{EID}/attributes/{ATTRNAME} badVerbAllFour - - GET /ngsi10/contextEntities/{EID}/attributes/{ATTRNAME}/{ID} getAttributeValueInstance ---------------------------------> postQueryContext --------------------------------------------> mongoQueryContext - PUT /ngsi10/contextEntities/{EID}/attributes/{ATTRNAME}/{ID} putAttributeValueInstance ---------------------------------> postUpdateContext -------------------------------------------> mongoUpdateContext - DELETE /ngsi10/contextEntities/{EID}/attributes/{ATTRNAME}/{ID} deleteAttributeValueInstance ------------------------------> postUpdateContext -------------------------------------------> mongoUpdateContext - * /ngsi10/contextEntities/{EID}/attributes/{ATTRNAME}/{ID} badVerbGetPutDeleteOnly - - GET /ngsi10/contextEntityTypes/{ETYPE} getNgsi10ContextEntityTypes -------------------------------> postQueryContext --------------------------------------------> mongoQueryContext - * /ngsi10/contextEntityTypes/{ETYPE} badVerbGetOnly - - GET /ngsi10/contextEntityTypes/{ETYPE}/attributes getNgsi10ContextEntityTypes -------------------------------> postQueryContext --------------------------------------------> mongoQueryContext - * /ngsi10/contextEntityTypes/{ETYPE}/attributes badVerbGetOnlyy - - GET /ngsi10/contextEntityTypes/{ETYPE}/attributes/{ATTRNAME} getNgsi10ContextEntityTypesAttribute ----------------------> postQueryContext --------------------------------------------> mongoQueryContext - * /ngsi10/contextEntityTypes/{ETYPE}/attributes/{ATTRNAME} badVerbGetOnly - - POST /ngsi10/contextSubscriptions postSubscribeContextConvOp --------------------------------> postSubscribeContext ----------------------------------------> mongoSubscribeContext - * /ngsi10/contextSubscriptions badVerbPostOnly - - PUT /ngsi10/contextSubscriptions/{SUBID} putSubscriptionConvOp -------------------------------------> postUpdateContextSubscription -------------------------------> mongoUpdateContextSubscription - DELETE /ngsi10/contextSubscriptions/{SUBID} deleteSubscriptionConvOp ----------------------------------> postUnsubscribeContext --------------------------------------> mongoUnsubscribeContext - * /ngsi10/contextSubscriptions/{SUBID} badVerbPutDeleteOnly - - -V1 CONVENIENCE OPERATIONS: -==================================================================================================== - GET /v1/contextEntities/{EID} getIndividualContextEntity --------------------------------> postQueryContext --------------------------------------------> mongoQueryContext - PUT /v1/contextEntities/{EID} putIndividualContextEntity --------------------------------> postUpdateContext -------------------------------------------> mongoUpdateContext - POST /v1/contextEntities/{EID} postIndividualContextEntity -------------------------------> postUpdateContext -------------------------------------------> mongoUpdateContext - DELETE /v1/contextEntities/{EID} deleteIndividualContextEntity -----------------------------> postUpdateContext -------------------------------------------> mongoUpdateContext - * /v1/contextEntities/{EID} badVerbAllFour - - GET /v1/contextEntities/{EID}/attributes getIndividualContextEntity --------------------------------> postQueryContext --------------------------------------------> mongoQueryContext - PUT /v1/contextEntities/{EID}/attributes putIndividualContextEntity --------------------------------> postUpdateContext -------------------------------------------> mongoUpdateContext - POST /v1/contextEntities/{EID}/attributes postIndividualContextEntity -------------------------------> postUpdateContext -------------------------------------------> mongoUpdateContext - DELETE /v1/contextEntities/{EID}/attributes deleteIndividualContextEntity -----------------------------> postUpdateContext -------------------------------------------> mongoUpdateContext - * /v1/contextEntities/{EID}/attributes badVerbAllFour - - GET /v1/contextEntities/{EID}/attributes/{ATTRNAME} getIndividualContextEntityAttribute -----------------------> postQueryContext --------------------------------------------> mongoQueryContext - PUT /v1/contextEntities/{EID}/attributes/{ATTRNAME} putIndividualContextEntityAttribute -----------------------> postUpdateContext -------------------------------------------> mongoUpdateContext - POST /v1/contextEntities/{EID}/attributes/{ATTRNAME} postIndividualContextEntityAttribute ----------------------> postUpdateContext -------------------------------------------> mongoUpdateContext - DELETE /v1/contextEntities/{EID}/attributes/{ATTRNAME} deleteIndividualContextEntityAttribute --------------------> postUpdateContext -------------------------------------------> mongoUpdateContext - * /v1/contextEntities/{EID}/attributes/{ATTRNAME} badVerbAllFour - - GET /v1/contextEntities/{EID}/attributes/{ATTRNAME}/{ID} getAttributeValueInstance ---------------------------------> postQueryContext --------------------------------------------> mongoQueryContext - PUT /v1/contextEntities/{EID}/attributes/{ATTRNAME}/{ID} putAttributeValueInstance ---------------------------------> postUpdateContext -------------------------------------------> mongoUpdateContext - DELETE /v1/contextEntities/{EID}/attributes/{ATTRNAME}/{ID} deleteAttributeValueInstance ------------------------------> postUpdateContext -------------------------------------------> mongoUpdateContext - * /v1/contextEntities/{EID}/attributes/{ATTRNAME}/{ID} badVerbGetPutDeleteOnly - - GET /v1/contextEntityTypes/{ETYPE} getNgsi10ContextEntityTypes -------------------------------> postQueryContext --------------------------------------------> mongoQueryContext - * /v1/contextEntityTypes/{ETYPE} badVerbGetOnly - - GET /v1/contextEntityTypes/{ETYPE}/attributes getNgsi10ContextEntityTypes -------------------------------> postQueryContext --------------------------------------------> mongoQueryContext - * /v1/contextEntityTypes/{ETYPE}/attributes badVerbGetOnlyy - - GET /v1/contextEntityTypes/{ETYPE}/attributes/{ATTRNAME} getNgsi10ContextEntityTypesAttribute ----------------------> postQueryContext --------------------------------------------> mongoQueryContext - * /v1/contextEntityTypes/{ETYPE}/attributes/{ATTRNAME} badVerbGetOnly - - POST /v1/contextSubscriptions postSubscribeContextConvOp --------------------------------> postSubscribeContext ----------------------------------------> mongoSubscribeContext - * /v1/contextSubscriptions badVerbPostOnly - - PUT /v1/contextSubscriptions/{SUBID} putSubscriptionConvOp -------------------------------------> postUpdateContextSubscription -------------------------------> mongoUpdateContextSubscription - DELETE /v1/contextSubscriptions/{SUBID} deleteSubscriptionConvOp ----------------------------------> postUnsubscribeContext --------------------------------------> mongoUnsubscribeContext - * /v1/contextSubscriptions/{SUBID} badVerbPutDeleteOnly - - -TID CONVENIENCE OPERATIONS: -==================================================================================================== - GET /v1/contextTypes getEntityTypes -----------------------------------------------------------------------------------------------------------> mongoEntityTypes - * /v1/contextTypes badVerbGetOnly - - GET /v1/contextTypes/{ETYPE} getAttributesForEntityType ----------------------------------------------------------------------------------------------> mongoAttributesForEntityType - * /v1/contextTypes/{ETYPE} badVerbGetOnly - - GET /v1/contextEntities getAllContextEntities -------------------------------> postQueryContext --------------------------------------------> mongoQueryContext - POST /v1/contextEntities postIndividualContextEntity -------------------------------> postUpdateContext -------------------------------------------> mongoUpdateContext - * /v1/contextEntities badVerbGetPostOnly - - GET /v1/contextEntities/type/{ETYPE}/id/{EID} getAllEntitiesWithTypeAndId -------------------------------> postQueryContext --------------------------------------------> mongoQueryContext - POST /v1/contextEntities/type/{ETYPE}/id/{EID} postAllEntitiesWithTypeAndId ------------------------------> postUpdateContext -------------------------------------------> mongoUpdateContext - PUT /v1/contextEntities/type/{ETYPE}/id/{EID} putAllEntitiesWithTypeAndId -------------------------------> postUpdateContext -------------------------------------------> mongoUpdateContext - DELETE /v1/contextEntities/type/{ETYPE}/id/{EID} deleteAllEntitiesWithTypeAndId ----------------------------> postUpdateContext -------------------------------------------> mongoUpdateContext - * /v1/contextEntities/type/{ETYPE}/id/{EID} badVerbAllFour - - GET /v1/contextEntities/type/{ETYPE}/id/{EID}/attributes/{ATTRNAME} getIndividualContextEntityAttributeWithTypeAndId -------> postQueryContext --------------------------------------------> mongoQueryContext - POST /v1/contextEntities/type/{ETYPE}/id/{EID}/attributes/{ATTRNAME} postIndividualContextEntityAttributeWithTypeAndId -------> postUpdateContext -------------------------------------------> mongoUpdateContext - PUT /v1/contextEntities/type/{ETYPE}/id/{EID}/attributes/{ATTRNAME} putIndividualContextEntityAttributeWithTypeAndId -------> postUpdateContext -------------------------------------------> mongoUpdateContext - DELETE /v1/contextEntities/type/{ETYPE}/id/{EID}/attributes/{ATTRNAME} deleteIndividualContextEntityAttributeWithTypeAndId -------> postUpdateContext -------------------------------------------> mongoUpdateContext - * /v1/contextEntities/type/{ETYPE}/id/{EID}/attributes/{ATTRNAME} badVerbAllFour - - GET /v1/contextEntities/type/{ETYPE}/id/{EID}/attributes/{ATTRNAME}/{ID} getAttributeValueInstanceWithTypeAndId -----------------> postQueryContext --------------------------------------------> mongoQueryContext - POST /v1/contextEntities/type/{ETYPE}/id/{EID}/attributes/{ATTRNAME}/{ID} postAttributeValueInstanceWithTypeAndId -----------------> postUpdateContext -------------------------------------------> mongoUpdateContext - PUT /v1/contextEntities/type/{ETYPE}/id/{EID}/attributes/{ATTRNAME}/{ID} putAttributeValueInstanceWithTypeAndId -----------------> postUpdateContext -------------------------------------------> mongoUpdateContext - DELETE /v1/contextEntities/type/{ETYPE}/id/{EID}/attributes/{ATTRNAME}/{ID} deleteAttributeValueInstanceWithTypeAndId -----------------> postUpdateContext -------------------------------------------> mongoUpdateContext - * /v1/contextEntities/type/{ETYPE}/id/{EID}/attributes/{ATTRNAME}/{ID} badVerbAllFour - - GET /v1/registry/contextEntities/type/{ETYPE}/id/{ID} getContextEntitiesByEntityIdAndType -----------------> postDiscoverContextAvailability -----------------------------> mongoDiscoverContextAvailability - POST /v1/registry/contextEntities/type/{ETYPE}/id/{ID} postContextEntitiesByEntityIdAndType -----------------> postRegisterContext -----------------------------------------> mongoRegisterContext - * /v1/registry/contextEntities/type/{ETYPE}/id/{ID} badVerbGetPostOnly - - GET /v1/registry/contextEntities/type/{ETYPE}/id/{ID}/attributes/{ATTRNAME} getEntityByIdAttributeByNameWithTypeAndId ----------------> postDiscoverContextAvailability -----------------------------> mongoDiscoverContextAvailability - POST /v1/registry/contextEntities/type/{ETYPE}/id/{ID}/attributes/{ATTRNAME} postEntityByIdAttributeByNameWithTypeAndId ----------------> postRegisterContext -----------------------------------------> mongoRegisterContext - * /v1/registry/contextEntities/type/{ETYPE}/id/{ID}/attributes/{ATTRNAME} badVerbGetPostOnly - - MISC REQUESTS: ==================================================================================================== GET /log/trace logTraceTreat @@ -331,37 +94,15 @@ MISC REQUESTS: DELETE /log/traceLevel/{TRACELEVEL} logTraceTreat * /log/traceLevel/{TRACELEVEL} badVerbPutDeleteOnly - GET /v1/admin/log/trace logTraceTreat - DELETE /v1/admin/log/trace logTraceTreat - * /v1/admin/log/trace badVerbGetDeleteOnly - - PUT /v1/admin/log/trace/{TRACELEVEL} logTraceTreat - DELETE /v1/admin/log/trace/{TRACELEVEL} logTraceTreat - * /v1/admin/log/trace/{TRACELEVEL} badVerbPutDeleteOnly - - GET /v1/admin/log/traceLevel logTraceTreat - DELETE /v1/admin/log/traceLevel logTraceTreat - * /v1/admin/log/traceLevel badVerbGetDeleteOnly - - PUT /v1/admin/log/traceLevel/{TRACELEVEL} logTraceTreat - DELETE /v1/admin/log/traceLevel/{TRACELEVEL} logTraceTreat - * /v1/admin/log/traceLevel/{TRACELEVEL} badVerbPutDeleteOnly - GET /statistics statisticsTreat DELETE /statistics statisticsTreat * /statistics badVerbGetDeleteOnly - GET /v1/admin/statistics statisticsTreat - DELETE /v1/admin/statistics statisticsTreat - * /v1/admin/statistics badVerbGetDeleteOnly GET /cache/statistics statisticsCacheTreat DELETE /cache/statistics statisticsCacheTreat * /cache/statistics badVerbGetDeleteOnly - GET /v1/admin/cache/statistics statisticsCacheTreat - DELETE /v1/admin/cache/statistics statisticsCacheTreat - * /v1/admin/cache/statistics badVerbGetDeleteOnly GET /version versionTreat OPTIONS /version optionsVersionRequest @@ -378,8 +119,4 @@ MISC REQUESTS: DELETE /admin/metrics deleteMetrics * /admin/metrics badVerbGetDeleteOnly - * /ngsi9/{ANYTHING} badNgsi9Request - - * /ngsi10/{ANYTHING} badNgsi10Request - * {ANYTHING} badRequest diff --git a/doc/manuals/devel/architecture.md b/doc/manuals/devel/architecture.md index b62183d6de..86e9f95a8b 100644 --- a/doc/manuals/devel/architecture.md +++ b/doc/manuals/devel/architecture.md @@ -14,11 +14,7 @@ _Current Orion internal architecture_ * The `connectionTreat()` function is the entry point for new requests (see [RQ-01 diagram](sourceCode.md#flow-rq-01) for details). Depending on the version of the NGSI API to which the request belongs (basically, depending whether the request URL prefix is `/v1` or `/v2`) the execution flow goes in one "branch" or another, of the execution logic. -* In the case of NGSIv1 requests (deprecated), the logic is as follows: - * First, the [**jsonParse** library](sourceCode.md#srclibjsonparse) takes the request payload as input and generates a set of objects. The NGSIv1 parsing logic is based on the [Boost library property_tree](https://theboostcpplibraries.com/boost.propertytree). - * Next, a request servicing function is invoked to process the request. Each request type (in terms of HTTP and URL pattern) has a separate function. We call these functions "service routines" and they reside in the library [**serviceRoutines**](sourceCode.md#srclibserviceroutines). Note that some "high level" service routines may call other "low level" service routines. - * At the end (either in one or two hops, see [the mapping document](ServiceRoutines.txt) for details), the service routine calls the **mongoBackend** library. -* In the case of NGSIv2 requests, the logic is as follows: +* The logic is as follows: * First, the [**jsonParseV2** library](sourceCode.md#srclibjsonparsev2) takes the request payload as input and generates a set of objects. The NGSIv2 parsing logic is based in [rapidjson](http://rapidjson.org). * Next, similar to NGSIv1, a service routine is called to process the request. Each request type (in terms of HTTP and URL pattern) has a service routine. These "NGSIv2 service routines" reside in the library [**serviceRoutinesV2**](sourceCode.md#srclibserviceroutinesv2). Note that some V2 service routines may call NGSIv1 service routines (see [the mapping document](ServiceRoutines.txt) for details). * At the end, the **mongoBackend** library is invoked. Depending on the case, this can be done directly from a V2 service routine or indirectly via a V1 service routine, as shown in the figure above. diff --git a/doc/manuals/devel/cprs.md b/doc/manuals/devel/cprs.md index 26d1a31f8c..be3c17fa81 100644 --- a/doc/manuals/devel/cprs.md +++ b/doc/manuals/devel/cprs.md @@ -55,7 +55,7 @@ _FW-02: `updateForward()` function detail_ * Parse the context provider string to extract IP, port, URI path, etc. (step 1) * The request to forward has to be built (step 2). In the case of NGSIv1, we need to extract information of the binary object into text to be able to send the REST request (plain text) to the Context Provider using `POST /v1/updateContext`. In the case of NGSIv2, `POST /v2/op/updated` is used. * The request to forward is sent with the help of `httpRequestSend()` (step 3), that in its turn uses [libcurl](https://curl.haxx.se/libcurl/) (step 4). libcurl sends in sequence the request to the Context Provider (step 5). -* The textual response from the Context Provider is parsed and an `UpdateContextResponse` object is created (step 6). Parsing details are provided in diagram [PP-01](jsonParse.md#flow-pp-01). +* The textual response from the Context Provider is parsed and an `UpdateContextResponse` object is created (step 6). Parsing details are provided in diagram [PP-01](jsonParse.md#flow-pp-01). - FIXME PR: review this [Top](#top) @@ -91,7 +91,7 @@ _FW-04: `queryForward()` function detail_ * Parse the context provider string to extract IP, port, URI path, etc. (step 1). * The request to forward has to be built (step 2). In the case of NGSIv1, we need to extract information of the binary object into text to be able to send the REST request (plain text) to the Context Provider using `POST /v1/queryContext`. In the case of NGSIv2, `POST /v2/op/query` is used. * The request to forward is sent with the help of `httpRequestSend()` (step 3) which uses [libcurl](https://curl.haxx.se/libcurl/) to forward the request (step 4). libcurl sends in sequence the request to the Context Provider (step 5). -* The textual response from the Context Provider is parsed and an `QueryContextResponse` object is created (step 6). Parsing details are provided in diagram [PP-01](jsonParse.md#flow-pp-01). +* The textual response from the Context Provider is parsed and an `QueryContextResponse` object is created (step 6). Parsing details are provided in diagram [PP-01](jsonParse.md#flow-pp-01). - FIXME PR: review this ## A Caveat about shadowing of entities The Context Provider mechanism is implemented using standard registration requests and this might lead to unwanted situations. diff --git a/doc/manuals/devel/flowsIndex.md b/doc/manuals/devel/flowsIndex.md index 0d84d85cda..5a84dc395b 100644 --- a/doc/manuals/devel/flowsIndex.md +++ b/doc/manuals/devel/flowsIndex.md @@ -16,7 +16,7 @@ Related to request management (RQ management): Related to parsing (PP prefix): -* [PP-01: Parsing an NGSIv1 payload](jsonParse.md#flow-pp-01) +* [PP-01: Parsing an NGSIv1 payload](jsonParse.md#flow-pp-01) - FIXME PR: review this * Continues from RQ-02, FW-02 or FW-04 * [PP-02: Parsing a text payload](sourceCode.md#flow-pp-02) * Continues from RQ-02 @@ -78,15 +78,15 @@ Related to mongoBackend logic (MB and MD prefixes): * Continues from RQ-02 * [MB-15: mongoUnsbuscribeContext](mongoBackend.md#flow-mb-15) * Continues from RQ-02 -* [MB-16: mongoSubscribeContext](mongoBackend.md#flow-mb-16) +* [MB-16: mongoSubscribeContext](mongoBackend.md#flow-mb-16) - FIXME PR: probably deleted * Continues from RQ-02 * Continues in MB-11 -* [MB-17: mongoUpdateContextSubscription](mongoBackend.md#flow-mb-17) +* [MB-17: mongoUpdateContextSubscription](mongoBackend.md#flow-mb-17) - FIXME PR: probably deleted * Continues from RQ-02 * Continues in MB-12 -* [MB-18: mongoRegisterContext](mongoBackend.md#flow-mb-18) +* [MB-18: mongoRegisterContext](mongoBackend.md#flow-mb-18) - FIXME PR: probably deleted * Continues from RQ-02 -* [MB-19: mongoDiscoverContextAvailability](mongoBackend.md#flow-mb-19) +* [MB-19: mongoDiscoverContextAvailability](mongoBackend.md#flow-mb-19) - FIXME PR: probably deleted * Continues from RQ-02 * [MB-23: mongoRegistrationGet](mongoBackend.md#flow-mb-23) * Continues from RQ-02 diff --git a/doc/manuals/devel/jsonParse.md b/doc/manuals/devel/jsonParse.md deleted file mode 100644 index 76a4d36382..0000000000 --- a/doc/manuals/devel/jsonParse.md +++ /dev/null @@ -1,389 +0,0 @@ -# JSON Parse NGSIv1 - -* [Introduction](#introduction) -* [Parsing process](#parsing-process) - * [Implementation details](#implementation-details) -* [Top-level `jsonParse()`](#top-level-jsonparse) -* [Low-level `jsonParse()`](#low-level-jsonparse) - -## Introduction - -Orion Context Broker contains not one but **two** libraries for JSON parsing. The reason for this is that the external library that was originally selected for parsing of NGSIv1 JSON cannot distinguish between JSON value types such as String, Number, Boolean, Null but **treats all values as strings**. This was unacceptable for NGSIv2 and so, another external JSON library ([rapidjson](http://rapidjson.org/)) was chosen. The two JSON libraries of Orion implement the necessary adaption of the external libraries to be usable by Orion. - -This document describes NGSIv1 parsing details (note that NGSIv1 has been deprecated). NGSIv2 parsing details are described in a [separate document](jsonParseV2.md). - -In general, the NGSIv1 parsing logic is more complex than NGSIv2 logic. The good news is that you will probably not need to change anything in NGSIv1 parsing as this is the old version of the Orion API and the work should now concentrate in evolving NGSIv2, not NGSIv1. - -The purpose of the parse step is to transform a text buffer, JSON in this case, to an instance of a class/struct in C++. The external library takes care of parsing the JSON string while the Orion library extracts the information and populates the approipriate instance of the class/struct in C++. - -A very simple but illustrative example: - -The following payload (for `POST /v1/queryContext`) ... : -``` -{ - "entities": [ - { - "type": "Room", - "id": "ConferenceRoom" - } - ], - "attributes": [ "temperature" ] -} -``` - -... would be transformed into a C++ instance of the class `QueryContextRequest` something like this: -``` -QueryContextRequest* qprP = new QueryContextRequest(); -EntityId* eP = new EntityId(); - -eP->id = "ConferenceRoom"; -eP->type = "Room"; - -qprP->entityIdVector.push_back(eP); -qprP->attributeList.push_back("temperature"); -``` - -This instance of `QueryContextRequest` is created by the **jsonParse** library and the service routine `postQueryContext()` passes it to the [**mongoBackend**](sourceCode.md#srclibmongobackend) function `mongoQueryContext()`. - -[Top](#top) - -## Parsing process -The library **jsonParse** contains two overloaded functions with the name `jsonParse()`: - -* The first one is the toplevel function that is called only once per request. See [dedicated section on top-level jsonParse()](#top-level-jsonparse). -* The second `jsonParse()` is invoked by the **toplevel** `jsonParse()` once per node in the parsed tree that is output from [boost property_tree](https://theboostcpplibraries.com/boost.propertytree) and it *calls itself recursively* following the output tree (we will use `jsonParse()*` from now on to distinguish this second, lower level `jsonParse()` from the top level `jsonParse()` function). See its full explanation in the [dedicated section on low level jsonParse()](#low-level-jsonparse). - -The concrete example used for the following image is the parsing of payload for `POST /v1/updateContextRequest`. - - -![Parsing an NGSIv1 payload](images/Flow-PP-01.png) - -_PP-01: Parsing an NGSIv1 payload_ - -* `payloadParse()` calls the NGSIv1 parse function for JSON payloads (which is one of three possible parse functions to call: parsing of NGSIv1 JSON, NGSIv2 JSON and text) (step 1). -* `jsonTreat()` looks up the type of the request by calling `jsonRequestGet()` (step 2), which returns a pointer to a `JsonRequest` struct that is needed to parse the payload. - * Each type of payload needs different input to the common parsing routines. A vector of `JsonRequest` structs contains this information and `jsonRequestGet()` looks up the corresponding `JsonRequest` struct in the vector and returns it. More on the `JsonRequest` struct later. -* Knowing the specific information for the request type, `jsonTreat()` calls the toplevel `jsonParse()`, whose responsibility is to start the parsing of the payload (step 3). `jsonParse()` reads in the payload into a `stringstream` and calls the function `read_json()` that takes care of the parsing of the payload and converts the payload into a property tree. -* After that, `jsonParse()*` (the lower level) is invoked on the resulting tree to convert the boost property tree into an Orion structure (step 4). In fact, `jsonParse()*` is invoked at this point as many times as there are top level keys in the JSON to process. - * Example: for `{ "a": ..., "b": ..., "c:"... }`, `jsonParse()*` will be invoked three times (once for `"a"`, once for `"b"` and once for `"c"`). -* `jsonParse()*` calls the `treat()` function on each node (step 5) and if the node is not a leaf, it does an recursive call to itself for each child of the node. -* The `treat()` function checks for forbidden characters in the payload and then calls the specific Parse-Function for the node in question (step 6). A pointer to this specific Parse-Function is found in the struct `JsonRequest`, as well as the path to each node, which is how the struct is found. -* The Parse-Function simply extracts the information from the tree node and adds it to the resulting Orion struct that is the result of the entire parse. Note that each node in the tree has its own Parse-Function and that in this image just a few selected Parse-Functions are shown. In fact, to parse this `UpdateContextRequest` payload, there are no less than 19 Parse-Functions (see `jsonParse/jsonUpdateContextRequest.cpp`). - -[Top](#top) - -### Implementation Details -As earlier stated, `jsonTreat()` in `src/lib/jsonParse/jsonRequest.cpp` is invoked by `payloadParse()` in `src/lib/rest/RestService.cpp`. Before diving into `jsonTreat()`, let's take a look at the struct `JsonRequest` that has a very important role in the function: - -``` -typedef struct JsonRequest -{ - RequestType type; // Type of request (URI PATH translated to enum) - std::string method; // HTTP Method (POST/PUT/PATCH ...) - std::string keyword; // Old reminiscent from XML parsing - JsonNode* parseVector; // Path and pointer to entry function for parsing - RequestInit init; // pointer to function for parse initialization - RequestCheck check; // pointer to function for checking of the parse result - RequestPresent present; // pointer to function for presenting the parse result in log file - RequestRelease release; // pointer to function that frees up memory after the parse result has been used -} JsonRequest; -``` - -See also the variable `jsonRequest`, which is a vector of `JsonRequest`, in `src/lib/jsonParse/jsonRequest.cpp` for a full list of the supported requests with payload. - -The first thing that `jsonTreat()` does is to call `jsonRequestGet()` to look up an item in the vector `jsonRequest`. The search criteria to look up the vector item is the **RequestType** (which depends on the URL PATH of the request) and the **HTTP Method** used. - -If the combination of URL PATH and HTTP Method is not found in the `JsonRequest` vector (`jsonRequest`), then the request is not valid and an error is returned. If found, then the vector item contains all the information needed to parse the payload and build the corresponding raw structure. - -#### Adding a new request with payload - -To add a request in NGSIv1, with payload to parse, an item **must be added** to the vector `jsonRequest`. - -Now, after finding the vector item for the request, `jsonTreat()` does the following: - -* `init()` -* `parse()` -* `check()` - -`release()` cannot be called until the result of the parse has been used. that is, if no error has been detected. In case of errors, the `release()` function is called right after the call to payloadParse, as the result is garbage and cannot be used. Normally the parse works just fine and the resulting instance from the parse step is passed to mongoBackend for processing and the release function cannot be called until mongoBackend is done with its processing. The corresponding service routine calls mongoBackend and `restService()` calls the service routine: - -``` -std::string response = serviceV[ix].treat(ciP, components, compV, &parseData); -``` - -After returning from the service routine, the result of the parse can be released without risk. - -[Top](#top) - -## Top-level `jsonParse()` -As mentioned, there are two different functions called `jsonParse()` in `src/lib/jsonParse/jsonParse.cpp`. One top level and one lower level. The top level `jsonParse()` is the entry function and it is visible from outside of `src/lib/jsonParse/jsonParse.cpp`: - -``` -std::string jsonParse -( - ConnectionInfo* ciP, // Connection Info valid for the life span of the request - const char* content, // Payload as a string - const std::string& requestType, // The type of request (URL PATH) - JsonNode* parseVector, // Function pointers etc for treatment of the nodes - ParseData* parseDataP // Output pointer to C++ classes for the result of the the parse -) -``` - -This function is called by `jsonTreat()` in `src/lib/jsonParse/jsonRequest.cpp`, which in its turn in called by `payloadParse()` in `src/lib/rest/RestService.cpp`. - -The purpose of the function is to initiate the parsing of the content (JSON string in the parameter `content`) with the help of `boost::property_tree::ptree`, by: - -* Get start-time for timing statistics, if requested -* Fix *escaped chars*, i.e remove backslash preceding a slash: `"\/"` => `"/"` -* Load the `content` in the `ptree` variable `tree` -* Call the low-level `jsonParse()` for each first level node of the tree. The low-level `jsonTreat()` dives deeper. -* Return **Error** if low-level `jsonTreat()` fails -* Get end-time for timing statistics, if requested, and save diff-time for later use - -[Top](#top) - -## Low-level `jsonParse()` -The low-level `jsonParse` is static in `src/lib/jsonParse/jsonParse.cpp` and **only** called by the high-level `jsonParse()` (except for the recursive calls it makes itself). - -Its signature: - -``` -static std::string jsonParse -( - ConnectionInfo* ciP, // "Global" info about the current request - boost::property_tree::ptree::value_type& v, // The node-in-the-tree - const std::string& _path, // The path to the node-in-the-tree - JsonNode* parseVector, // Function pointers etc for treatment of the nodes - ParseData* parseDataP // Output pointer to C++ classes for the result of the the parse -) -``` - -Let's describe the different parameters one by one. - -### `ConnectionInfo* ciP` -This pointer to `ConnectionInfo` is created by the function that MHD (libmicrohttpd) uses for the callbacks while reading the request (`connectionTreat` in `src/lib/rest/rest.cpp`). `ciP` contains information about the request such as: - -* HTTP Method/Verb -* HTTP Headers -* URI Parameters (E.g. `?a=1&b=2`) -* URI Path (E.g. `/v1/queryRequest`) ... -* ... and much more. See `src/lib/rest/ConnectionInfo.h` - -The pointer to `ConnectionInfo` is passed to many functions in the libraries **jsonParse**, **jsonParseV2**, **rest**, **serviceRoutines** and **serviceRoutinesV2**. - -### `boost::property_tree::ptree::value_type& v` - -This is a reference to the currently treated node in the tree. Not much more to say about it. See the [boost property_tree documentation](https://theboostcpplibraries.com/boost.propertytree) for more information on this. - -### `const std::string& _path` - -`jsonParse()` keeps the path to the node as a string, to know exactly which node in the tree is treated. E.g.: - -``` -{ - "entities": [ - { - "type": "Room", - "id": "ConferenceRoom" - } - ], - "attributes": [ "temperature" ] -} -``` - -The node `type` would have the path `/entities/entity/type`. The middle name `entity` is because `entities` is a vector. More on this later. - -### `JsonNode* parseVector` -`JsonNode` is a struct defined in `src/lib/jsonParse/JsonNode.h`: - -``` -typedef std::string (*JsonNodeTreat)(const std::string& path, const std::string& value, ParseData* reqDataP); - -typedef struct JsonNode -{ - std::string path; - JsonNodeTreat treat; -} JsonNode; -``` - -Instances of `JsonNode` contain the path of a node (e.g. `/entities/entity/type`) and a reference to the corresponding treat-function for a node with that very path. This is how `jsonTreat` knows which treat-function to call for each node in the tree. As illustration, see `src/lib/jsonParse/jsonQueryContextRequest.cpp`, variable `jsonQcrParseVector`: - -``` -JsonNode jsonQcrParseVector[] = -{ - { "/entities", jsonNullTreat }, - { "/entities/entity", entityId }, - { "/entities/entity/id", entityIdId }, - { "/entities/entity/type", entityIdType }, - { "/entities/entity/isPattern", entityIdIsPattern }, - ... -``` - -As explained, this is a vector of **path-in-the-tree** and corresponding **treat-function** and this is how the low-level `jsonParse()` knows which treat-function to call for each node in the tree. - -This vector and the other vectors (one per type of payload) is used by the variable `jsonRequest` in `src/lib/jsonParse/jsonRequest.cpp` of type `JsonRequest`: -``` -typedef struct JsonRequest -{ - RequestType type; - std::string method; - std::string keyword; - JsonNode* parseVector; - RequestInit init; - RequestCheck check; - RequestPresent present; - RequestRelease release; -} JsonRequest; -``` - -`jsonRequest` is a vector of `JsonRequest` and it defines all payloads that are to be parsed by `jsonParse`, see [Implementation Details](#implementation-details) for more info on `jsonRequest`. - -The JsonRequest vector is declared in `src/lib/jsonParse/jsonRequest.cpp`: - -``` -static JsonRequest jsonRequest[] = -{ - // NGSI9 - { RegisterContext, "POST", "registerContextRequest", FUNCS(Rcr) }, - { DiscoverContextAvailability, "POST", "discoverContextAvailabilityRequest", FUNCS(Dcar) }, - - // NGSI10 - { QueryContext, "POST", "queryContextRequest", FUNCS(Qcr) }, - { UpdateContext, "POST", "updateContextRequest", FUNCS(Upcr) }, - ... -}; -``` - -The macro `FUNCS()` is to make the lines a bit shorter and it looks like this: - -``` -#define FUNCS(prefix) json##prefix##ParseVector, json##prefix##Init, \ - json##prefix##Check, json##prefix##Present, \ - json##prefix##Release -``` - -I.e., all the "methods" for the parsing of a type of payload. These functions reside in one module per type of payload, such as: - -* `src/lib/jsonParse/jsonQueryContextRequest.cpp` -* `src/lib/jsonParse/jsonUpdateContextRequest.cpp` -* etc - -The "methods" are for: - -* `init()`, -* `check()`, -* `present()`, and -* `release()` - -and there is one set of "methods" for each type of payload. - -So, the modules called `jsonXxxRequest` or `jsonXxxResponse` (`Xxx` being the name of the payload, e.g. `QueryContent` or `UpdateContent`) all contain: - -* this set of methods (`init()`, `check()`, `present()` and `release()`), -* the *Parse-Vector* that contains the path and treat methods for each node, -* all treat methods for the nodes - -which is the entire set of functions and variables that `jsonParse()` needs to convert the JSON input payload string into a C++ class instance. - -Now some example of treat-methods, they are all pretty simple: - -``` -/* **************************************************************************** -* -* entityId - -*/ -static std::string entityId(const std::string& path, const std::string& value, ParseData* reqDataP) -{ - reqDataP->qcr.entityIdP = new EntityId(); - - reqDataP->qcr.entityIdP->id = ""; - reqDataP->qcr.entityIdP->type = ""; - reqDataP->qcr.entityIdP->isPattern = "false"; - - reqDataP->qcr.res.entityIdVector.push_back(reqDataP->qcr.entityIdP); - - return "OK"; -} - - - -/* **************************************************************************** -* -* entityIdId - -*/ -static std::string entityIdId(const std::string& path, const std::string& value, ParseData* reqDataP) -{ - reqDataP->qcr.entityIdP->id = value; - - return "OK"; -} -``` - -Also, lets have a look at the Parse-Vector where these two treat-functions reside: - -``` -/* **************************************************************************** -* -* qcrParseVector - -*/ -JsonNode jsonQcrParseVector[] = -{ - { "/entities", jsonNullTreat }, - { "/entities/entity", entityId }, - { "/entities/entity/id", entityIdId }, - ... -``` - -The treat-function `entityId` is called when a node `/entities/entity` is found. `entities` is a vector inside the payload for `QueryContextRequest`: -``` -{ - "entities": [ - { - "id": "", - "type": "", - ... - } -} -``` - -As vectors items have no key-name in JSON, we decided to use the singular word of the name of the vector (which is always in plural), i.e. an instance of **entities** is called **entity**. So, when the node `/entities/entity` is found (an item of the entities vector), the treat-function `entityId()` is called and it allocates room for an `EntityId` (`class EntityId` resides in the module `src/lib/ngsi/EntityId.h/cpp`) and pushes the `EntityId` pointer to the vector `reqDataP->qcr.res.entityIdVector`. - -The treat-function `entityId()` also sets `reqDataP->qcr.entityIdP` to reference this latest instance of `EntityId` so that consequent treat-functions can reach it. For example, `entityIdId()` needs it, to set the `id` field of the entity, which is all `entityIdId()` does. Pointers of this type are needed during the parse/extraction and these pointers are the reason for the ParseData structs (see `src/lib/ngsi/ParseData.h` - one "XxxData" struct per payload type, with an output class instance and these help pointers). - -### `ParseData* parseDataP` - -As the parsing of NGSI v1 payload is strongly centralized, and function pointers are needed, there is a need for a unique type for **all** types of payload. The types for storing the result of the parse (the C++ class instances are different for each type of payload) are all collected into a big struct contaning all types of payload. Then each treat-function picks which field to operate on. - -A pointer to this structure is passed as parameter to low-level `jsonParse()`. - -`ParseData` is found in `src/lib/ngsi/ParseData.h`: - -``` -typedef struct ParseData -{ - std::string errorString; - ContextAttribute* lastContextAttribute; - - RegisterContextData rcr; - DiscoverContextAvailabilityData dcar; - ... -} ParseData; -``` - -For example, parsing of an NGSI10 query operates on `ParseData::qcr` which is of the type `QueryContextData`. `QueryContextData` in its turn contains an instance of `QueryContextRequest` which is where the result of the parse is stored. But, as help variables are needed during the parse, these "XxxData structs" are used and they contain the output instance (`QueryContextRequest` in the case of `QueryContextData`) **and** the help variables needed for the parsing of a `QueryContextRequest`: - -``` -struct QueryContextData -{ - QueryContextRequest res; // Output/Result of the parse - EntityId* entityIdP; // Pointer to the current EntityId - Scope* scopeP; // Pointer to the current Scope - orion::Point* vertexP; // Pointer to the current Point - int pointNo; // Index of the current Point - int coords; // Number of coordinates -}; -``` - -Each XxxData struct has a different set of help variables. - -[Top](#top) diff --git a/doc/manuals/devel/jsonParseV2.md b/doc/manuals/devel/jsonParseV2.md index e0b42f8b13..f52462763e 100644 --- a/doc/manuals/devel/jsonParseV2.md +++ b/doc/manuals/devel/jsonParseV2.md @@ -1,6 +1,6 @@ # JSON Parse NGSIv2 -NGSIv2 payloads are parsed in a very different manner than NGSIv1 payloads. This document describes NGSIv2 parsing details. NGSIv1 parsing details are described in a [separate document](jsonParse.md). +This document describes NGSIv2 parsing details. Instead of the centralized approach of NGSIv1 parse, an individual approach is used. The advantage of this approach is that the code is much easier to understand and to reuse, while the inconvenience is that some tasks, e.g. checks for unsupported fields are spread out in many different functions and this way it is easy for some of these checks to be forgotten. diff --git a/doc/manuals/devel/mongoBackend.md b/doc/manuals/devel/mongoBackend.md index a7093010f7..196576ff47 100644 --- a/doc/manuals/devel/mongoBackend.md +++ b/doc/manuals/devel/mongoBackend.md @@ -9,10 +9,10 @@ * [`mongoUpdateSubscription` (SR2)](#mongoupdatesubscription-sr2) * [`mongoGetSubscriptions` (SR2)](#mongogetsubscriptions-sr2) * [`mongoUnsubscribeContext` (SR and SR2)](#mongounsubscribecontext-sr-and-sr2) - * [`mongoSubscribeContext` (SR)](#mongosubscribecontext-sr) - * [`mongoUpdateContextSubscription` (SR)](#mongoupdatecontextsubscription-sr) - * [`mongoRegisterContext` (SR)](#mongoregistercontext-sr) - * [`mongoDiscoverContextAvailability` (SR)](#mongodiscovercontextavailability-sr) + * [`mongoSubscribeContext` (SR)](#mongosubscribecontext-sr) - FIXME PR: probably deleted + * [`mongoUpdateContextSubscription` (SR)](#mongoupdatecontextsubscription-sr) - FIXME PR: probably deleted + * [`mongoRegisterContext` (SR)](#mongoregistercontext-sr) - FIXME PR: probably deleted + * [`mongoDiscoverContextAvailability` (SR)](#mongodiscovercontextavailability-sr) - FIXME PR: probably deleted * [`mongoRegistrationGet` (SR2)](#mongoregistrationget-sr2) * [`mongoRegistrationCreate` (SR2)](#mongoregistrationcreate-sr2) * [Low-level modules related to DB interaction](#low-level-modules-related-to-db-interaction) @@ -50,7 +50,7 @@ These modules implement the different Context Broker requests. They are called d This section also describes the `MongoCommonRegister` and `MongoCommonUpdate` modules which provide common functionality highly coupled with several other request processing modules. In particular: -* `MongoCommonRegister` provides common functionality for the `mongoRegisterContext` modules. +* `MongoCommonRegister` provides common functionality for the `mongoRegisterContext` modules. - FIXME PR: probably deleted * `MongoCommonUpdate` provides common functionality for the `mongoUpdateContext` and `mongoNotifyContext` modules. [Top](#top) @@ -283,7 +283,7 @@ The detail for `mongoEntityTypes()` is as shown in the following diagram. _MB-08: mongoEntityTypes_ -* `mongoEntityTypes()` is invoked from a service routine (step 1). This can be from either `getEntityTypes()` (which resides in `lib/serviceRoutines/getEntityTypes.cpp`) or `getEntityAllTypes()` (which resides in `lib/serviceRoutinesV2/getEntityAllTypes.cpp`). +* `mongoEntityTypes()` is invoked from a service routine (step 1). This is from `getEntityAllTypes()` (which resides in `lib/serviceRoutinesV2/getEntityAllTypes.cpp`). * Depending on `-reqMutexPolicy`, the request semaphore may be taken (read mode) (step 2). See [this document for details](semaphores.md#mongo-request-semaphore). * A list of entity types and of attributes belonging to each of those entity types is retrieved from the database, using `runCollectionCommand()` in the `connectionOperations` module, to run an aggregation command (steps 3 and 4). * If attribute detail is enabled (i.e. `noAttrDetail` set to `false`) a loop iterates on every attribute of every entity type, in order to: @@ -310,7 +310,7 @@ The detail for `mongoAttributesForEntityType()` is as shown in the following dia _MB-10: mongoAttributesForEntityType_ -* `mongoAttributesForEntityType()` is invoked from a service routine (step 1). This can be from either `getEntityType()` (which resides in `lib/serviceRoutinesV2/getEntityType.cpp`) or `getAttributesForEntityType()` (which resides in `lib/serviceRoutines/getAttributesForEntityType.cpp`). +* `mongoAttributesForEntityType()` is invoked from a service routine (step 1). This can be from either `getEntityType()` (which resides in `lib/serviceRoutinesV2/getEntityType.cpp`). * Depending on `-reqMutexPolicy`, the request semaphore may be taken (read mode) (step 2). See [this document for details](semaphores.md#mongo-request-semaphore). * A list of entity attributes corresponding to the entity type is retrieved from the database, using `runCollectionCommand()` in the `connectionOperations` module to run an aggregation command (steps 3 and 4). * If attribute detail is enabled (i.e. `noAttrDetail` set to `false`) a loop iterates on every attribute in order to: @@ -337,7 +337,7 @@ The header file contains only the function `mongoCreateSubscription()` whose wor _MB-11: mongoCreateSubscription_ -* `mongoCreateSubscription()` is invoked from a service routine (step 1). This can be from either `postSubscriptions()` (which resides in `lib/serviceRoutinesV2/postSubscriptions.cpp`) or `mongoSubscribeContext()` (which resides in `lib/mongoBackend/mongoSubscribeContext.cpp`). +* `mongoCreateSubscription()` is invoked from a service routine (step 1). This is `postSubscriptions()` (which resides in `lib/serviceRoutinesV2/postSubscriptions.cpp`). * Depending on `-reqMutexPolicy`, the request semaphore may be taken (write mode) (step 2). See [this document for details](semaphores.md#mongo-request-semaphore). * This function builds a BSON object that will be at the end the one to be persisted in the database, using different `set*()` functions (`setExpiration()`, `setHttpInfo()`, etc.) (step 3). * The BSON object corresponding to the new subscription is inserted in the database using `collectionInsert()` in the `connectionOperations` module (steps 4 and 5). @@ -359,7 +359,7 @@ The header file contains only a function named `mongoUpdateSubscription()` whose _MB-12: mongoUpdateSubscription_ -* `mongoUpdateSubscription()` is invoked from a service routine (step 1). This can be from either `patchSubscription()` (which resides in `lib/serviceRoutinesV2/patchSubscription.cpp`) or `mongoUpdateContextSubscription()` (which resides in `lib/mongoBackend/mongoUpdateContextSubscription.cpp`). +* `mongoUpdateSubscription()` is invoked from a service routine (step 1). This is from `patchSubscription()` (which resides in `lib/serviceRoutinesV2/patchSubscription.cpp`). * Depending on `-reqMutexPolicy`, the request semaphore may be taken (write mode) (step 2). See [this document for details](semaphores.md#mongo-request-semaphore). * The subscription is updated in DB using MongoDB `$set`/`$unset` operators. This operation is done in the function `colletionFindAndModify()` in the `connectionOperations` module (steps 3 and 4). * In case the subscription cache is enabled (i.e. `noCache` set to `false`) the subscription is updated in the subscription cache based in the result from `collectionFindAndModify()` in the previous step (step 5). `updateInCache()` uses the subscription cache semaphore internally. @@ -423,7 +423,7 @@ Its work is to remove from the database the document associated to the subscript _MB-15: mongoUnsubscribeContext_ -* `mongoUnsubscribeContext()` is invoked from a service routine (step 1). This can be from either `postUnsubscribeContext()` (which resides in `lib/serviceRoutines/postUnsubscribeContext.cpp`) or `mongoUpdateContextSubscription()` (which resides in `lib/serviceRoutinesV2/deleteSubscription.cpp`). +* `mongoUnsubscribeContext()` is invoked from a service routine (step 1). This is from `mongoUnsubscribeContext()` (which resides in `lib/serviceRoutinesV2/deleteSubscription.cpp`). * Depending on `-reqMutexPolicy`, the request semaphore may be taken (write mode) (step 2). See [this document for details](semaphores.md#mongo-request-semaphore). * The subscription is retrieved from the database using `collectionFindOne()` in the `connectionOperations` module (steps 3 and 4). * The subscription is removed from the database using `collectionRemove()` in the `connectionOperations` module (steps 5 and 6). @@ -436,6 +436,8 @@ Note that steps 6 and 7 are done no matter the value of `noCache`. This works bu #### `mongoSubscribeContext` (SR) +FIXME PR: probably deleted + `mongoSubscribeContext` encapsulates the logic for subscribe context (NGSIv1) operation. The header file contains only a function named `mongoSubscribeContext()` which uses a `SubscribeContextRequest` object as input parameter and a `SubscribeContextResponse` as output parameter. @@ -454,6 +456,8 @@ _MB-16: mongoSubscribeContext_ #### `mongoUpdateContextSubscription` (SR) +FIXME PR: probably deleted + `mongoUpdateContextSubscription` encapsulates the logic for update context subscription (NGSIv1) operation. The header file contains only a function named `mongoUpdateContextSubscription()` which uses an `UpdateContextSubscriptionRequest` object as input parameter and an `UpdateContextSubscriptionResponse` as output parameter. @@ -472,6 +476,8 @@ _MB-17: mongoUpdateContextSubscription_ #### `mongoRegisterContext` (SR) +FIXME PR: probably deleted + The `mongoRegisterContext` module provides the entry point for the register context operation processing logic (by means of `mongoRegisterContext()` defined in its header file). @@ -490,6 +496,8 @@ _MB-18: mongoRegisterContext_ #### `mongoDiscoverContextAvailability` (SR) +FIXME PR: probably deleted + `mongoDiscoverContextAvailability` encapsulates the logic for the context availability discovery (NGSIv1) operation. The header file contains only a function named `mongoDiscoverContextAvailability()` which uses a `DiscoverContextAvailabilityRequest` object as input parameter and a `DiscoverContextAvailabilityResponse` as output parameter. Its work is to build a response object based on the input request object and the registration existing in the database. @@ -633,7 +641,7 @@ This function basically searches for existing registrations in the (`registratio It is used by several functions: -* `mongoDiscoverContextAvailability()` (in the `mongoDiscoverContextAvailability` module), as "core" of the discovery operation. +* `mongoDiscoverContextAvailability()` (in the `mongoDiscoverContextAvailability` module), as "core" of the discovery operation. - FIXME PR: probably deleted * `mongoQueryContext()` in the `mongoQueryContext` module, in order to locate Context Providers for forwarding of the query. Note that the forwarding is not done within the **mongoBackend** library, but from the calling **serviceRoutine**. * `searchContextProviders()` in the `MongoCommonUpdate` module, in order to locate Context Providers for forwarding of the update. Note that the forwarding is not done within the **mongoBackend** library, but from the calling **serviceRoutine**. diff --git a/doc/manuals/devel/sourceCode.md b/doc/manuals/devel/sourceCode.md index a829aa1f41..b75e4ca338 100644 --- a/doc/manuals/devel/sourceCode.md +++ b/doc/manuals/devel/sourceCode.md @@ -8,14 +8,11 @@ * [src/lib/rest/](#srclibrest) (REST interface, using external library microhttpd) * [src/lib/ngsi/](#srclibngsi) (Common NGSI types) * [src/lib/ngsi10/](#srclibngsi10) (Common NGSI10 types, NGSI10 = context management) -* [src/lib/ngsi9/](#srclibngsi9) (Common NGSI9 types, NGSI9 = context management availability) * [src/lib/apiTypesV2/](#srclibapitypesv2) (NGSIv2 types) * [src/lib/parse/](#srclibparse) (Common functions and types for payload parsing) -* [src/lib/jsonParse/](#srclibjsonparse) (Parsing of JSON payload for NGSIv1 requests, using external library Boost property_tree) * [src/lib/jsonParseV2/](#srclibjsonparsev2) (Parsing of JSON payload for NGSIv2 requests, using external library rapidjson) * [src/lib/serviceRoutines/](#srclibserviceroutines) (Service routines for NGSIv1) * [src/lib/serviceRoutinesV2/](#srclibserviceroutinesv2) (Service routines for NGSIv2) -* [src/lib/convenience/](#srclibconvenience) (Convenience operations in NGSIv1) * [src/lib/mongoBackend/](#srclibmongobackend) (Database operations implementation) * [src/lib/mongoDriver/](#srclibmongodriver) (Database interface to MongoDB) * [src/lib/ngsiNotify/](#srclibngsinotify) (NGSI notifications) @@ -200,6 +197,8 @@ The JSON parse implementations reside in dedicated libraries while the text pars ## src/lib/ngsi/ The **ngsi** library contains a collection of classes for the different payloads that constitutes the common part of the ngsi9 and ngsi10 protocols. Here you find basic classes like: +FIXME PR: no point in aving ngsi/ and ngsi10/ separately (now that ngsi9/ has been removed) + * `EntityId` * `EntityIdVector` * `ContextAttribute` @@ -209,12 +208,11 @@ The **ngsi** library contains a collection of classes for the different payloads ### Methods and hierarchy -These classes (as well as the classes in the libraries `ngsi9`, `ngsi10`, `convenience`) all have a standard set of methods: +These classes (as well as the classes in the library `ngsi10`) all have a standard set of methods: -* `toJson()`, to render the object to a JSON string (for NGSIv2). This method levarages `JsonObjectHelper` and `JsonVectorHelper` +* `toJson()`, to render the object to a JSON string. This method levarages `JsonObjectHelper` and `JsonVectorHelper` in order to simplify the rendering process. This way you just add the elements you needs to print using `add*()` methods and don't need to bother with starting/ending brackets, quotes and comma control. -* `toJsonV1()`, to render the object to a JSON string (for NGSIv1) * `present()`, for debugging (the object is dumped as text to the log file) * `release()`, to release all allocated resources of the object * `check()`, to make sure the object follows the rules, i.e. about no forbidden characters, or mandatory fields missing, etc. @@ -250,8 +248,8 @@ The **ngsi10** library contains the top hierarchy classes for NGSI10 (NGSIv1) re * `QueryContextResponse` * `SubscribeContextRequest` * `SubscribeContextResponse` -* `UpdateContextSubscriptionRequest` -* `UpdateContextSubscriptionResponse` +* `UpdateContextSubscriptionRequest` - FIXME PR: removed +* `UpdateContextSubscriptionResponse` - FIXME PR: removed * `UnsubscribeContextRequest` * `UnsubscribeContextResponse` * `NotifyContextRequest` (outgoing request, sent by Orion, to notify subscribers) @@ -262,21 +260,8 @@ See the explanation of methods and hierarchy of the [**ngsi** library](#methods- [Top](#top) -## src/lib/ngsi9/ -Just like the ngsi10 library, the **ngsi9** library contains the top hierarchy classes for NGSI9 (NGSIv1) requests: - -* `RegisterContextRequest` -* `RegisterContextResponse` -* `DiscoverContextAvailabilityRequest` -* `DiscoverContextAvailabilityResponse` - -See the explanation of methods and hierarchy of the [**ngsi** library](#methods-and-hierarchy). - -[Top](#top) - - ## src/lib/apiTypesV2/ -The **apiTypesV2** library, just like the ngsi* libraries, contains classes; both basic classes (like the library **ngsi**) and top hierarchy classes (like the libraries **ngsi9** and **ngsi10**), for NGSIv2, the improved NGSI protocol. +The **apiTypesV2** library, just like the ngsi* libraries, contains classes; both basic classes (like the library **ngsi**) and top hierarchy classes (like the library **ngsi10**), for NGSIv2, the improved NGSI protocol. The hierarchical methods `release()`, `toJson()`, `check()`, etc. are found in these classes as well. @@ -300,16 +285,6 @@ _PP-02: Parsing a text payload_ [Top](#top) -## src/lib/jsonParse/ -This library takes care of the JSON parsing of payload for NGSIv1 requests. It depends on the [Boost library property_tree](https://theboostcpplibraries.com/boost.propertytree) and uses SAX to translate the incoming JSON text into the ngsi classes. - -This library contains a vector of the type `JsonRequest`, that defines how to parse the different requests. The function `jsonTreat()` picks the parsing method and `jsonParse()` takes care of the parsing, with help from the Boost property_tree library. - -See detailed explanation of the V1 JSON parse implementation in its [dedicated document](jsonParse.md). - -[Top](#top) - - ## src/lib/jsonParseV2/ This is where the newer NGSIv2 request payloads are parsed, using DOM. The [rapidjson](http://rapidjson.org/) library is used to parse the JSON payload, while the purpose of **jsonParseV2** (apart from invoking rapidjson) is to build a tree of objects representing the JSON payload. @@ -375,14 +350,6 @@ Some NGSIv2 service routines invoke [**mongoBackend**](#srclibmongobackend) dire [Top](#top) -## src/lib/convenience/ -The **convenience** library contains top hierarchy classes for the NGSIv1 convenience operations. For a complete list of these requests (and the service routines in which they are based), kindly see [the service routines mapping document](ServiceRoutines.txt). - -This library is similar to the [**ngsi9**](#srclibngsi9) and [**ngsi10**](#srclibngsi10) libraries. - -[Top](#top) - - ## src/lib/mongoBackend/ The most important of all libraries of the broker, the **mongoBackend** library is where all the database interaction takes place (through the "wrapping" library **mongoDriver**). This library is described in detail in [a separate document](mongoBackend.md). diff --git a/docker/Dockerfile b/docker/Dockerfile index aac4d0b52f..5c4eb8c651 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -157,7 +157,7 @@ RUN --mount=type=secret,id=repo_token,dst=/run/secrets/repo_token \ WORKDIR / # Note we disable log file as docker container will output by stdout -ENTRYPOINT ["/usr/bin/contextBroker","-fg", "-multiservice", "-ngsiv1Autocast", "-disableFileLog" ] +ENTRYPOINT ["/usr/bin/contextBroker","-fg", "-multiservice", "-disableFileLog" ] EXPOSE 1026 LABEL "maintainer"="Orion Team. Telefónica I+D" diff --git a/docker/Dockerfile.alpine b/docker/Dockerfile.alpine index 884c9cf1ef..07d63a291e 100644 --- a/docker/Dockerfile.alpine +++ b/docker/Dockerfile.alpine @@ -170,7 +170,7 @@ RUN --mount=type=secret,id=repo_token,dst=/run/secrets/repo_token \ WORKDIR / # Note we disable log file as docker container will output by stdout -ENTRYPOINT ["/usr/bin/contextBroker","-fg", "-multiservice", "-ngsiv1Autocast", "-disableFileLog" ] +ENTRYPOINT ["/usr/bin/contextBroker","-fg", "-multiservice", "-disableFileLog" ] EXPOSE 1026 LABEL "maintainer"="Orion Team. Telefónica I+D" diff --git a/makefile b/makefile index 8ce9dd233b..10a87d369d 100644 --- a/makefile +++ b/makefile @@ -204,6 +204,7 @@ clean: rm -rf BUILD_DEBUG rm -rf BUILD_COVERAGE rm -rf BUILD_UNITTEST + rm -rf BUILD_FUNCTIONAL style: ./scripts/style_check_in_makefile.sh diff --git a/scripts/accumulator-server.py b/scripts/accumulator-server.py index c08b893bd0..48a8095706 100755 --- a/scripts/accumulator-server.py +++ b/scripts/accumulator-server.py @@ -458,6 +458,207 @@ def record_2871(): ''' return r + +# In NGSIv1 the response for queryContext and updateContext has the same structure, so we reuse +# this function for boths +@app.route("/cpr/queryContext", methods=['POST']) +@app.route("/cpr/updateContext", methods=['POST']) +def cpr_simulation(): + + # Store request + record_request(request) + + if send_continue(request): + return Response(status=100) + else: + # Ad hoc response to test new NGSIv1 parsing logic in PR #4603 + r = Response(status=200) + r.data = ''' + { + "contextResponses": [ + { + "contextElement": { + "attributes": [ + { + "name": "lightstatus", + "type": "light", + "value": { + "x": 1, + "y": 2 + } + }, + { + "name": "pressure", + "type": "clima", + "value": [ "a", "b", "c" ] + }, + { + "name": "temperature", + "type": "degree", + "value": "14", + "metadatas": [ + { + "name": "ID1", + "type": "Text", + "value": { + "x": 1, + "y": 2 + } + }, + { + "name": "ID2", + "type": "Text", + "value": [ "a", "b", "c" ] + }, + { + "name": "ID3", + "type": "Text", + "value": "ThisIsID" + } + ] + } + ], + "id": "ConferenceRoom", + "isPattern": "false", + "type": "Room" + }, + "statusCode": { + "code": "200", + "reasonPhrase": "OK" + } + }, + { + "contextElement": { + "attributes": [ + { + "name": "temperature", + "type": "degree", + "value": "14" + } + ], + "id": "ConferenceRoom2", + "isPattern": "false", + "type": "Room" + }, + "statusCode": { + "code": "200", + "reasonPhrase": "OK" + } + }, + { + "contextElement": { + "attributes": [ + { + "name": "pressure", + "type": "degree", + "value": "14" + } + ], + "id": "ConferenceRoom3", + "isPattern": "false", + "type": "Room" + }, + "statusCode": { + "code": "200", + "reasonPhrase": "OK" + } + } + ] + } + ''' + return r + + + +@app.route("/cprfail/updateContext", methods=['POST']) +def cpr_simulation_fail(): + + # Store request + record_request(request) + + if send_continue(request): + return Response(status=100) + else: + # Ad hoc response to test new NGSIv1 parsing logic in PR #4603 + r = Response(status=200) + r.data = ''' + { + "contextResponses": [ + { + "contextElement": { + "attributes": [ + { + "name": "lightstatus", + "type": "light", + "value": { + "x": 1, + "y": 2 + } + }, + { + "name": "pressure", + "type": "clima", + "value": [ "a", "b", "c" ] + }, + { + "name": "temperature", + "type": "degree", + "value": "14", + "metadatas": [ + { + "name": "ID1", + "type": "Text", + "value": { + "x": 1, + "y": 2 + } + }, + { + "name": "ID2", + "type": "Text", + "value": [ "a", "b", "c" ] + }, + { + "name": "ID3", + "type": "Text", + "value": "ThisIsID" + } + ] + } + ], + "id": "ConferenceRoom", + "isPattern": "false", + "type": "Room" + }, + "statusCode": { + "code": "200", + "reasonPhrase": "OK" + } + }, + { + "contextElement": { + "attributes": [ + { + "name": "temperature", + "type": "degree", + "value": "14" + } + ], + "id": "ConferenceRoom2", + "isPattern": "false", + "type": "Room" + }, + "statusCode": { + "code": "422", + "reasonPhrase": "this is a fail" + } + } + ] + } + ''' + return r + + # Next 6 ones are for testing subscription status and failure logic. They are used by test # 1126_GET_v2_subscriptions/lastsuccesscode_and_lastfailurereason.test diff --git a/scripts/style_check_in_makefile.sh b/scripts/style_check_in_makefile.sh index 109b0c67f0..df8fa8ed39 100755 --- a/scripts/style_check_in_makefile.sh +++ b/scripts/style_check_in_makefile.sh @@ -59,8 +59,6 @@ style_check src/lib/alarmMgr style_check src/lib/metricsMgr style_check src/lib/expressions style_check test/unittests -style_check test/unittests/orionTypes -style_check test/unittests/jsonParse style_check test/unittests/apiTypesV2 style_check test/unittests/cache style_check test/unittests/mongoBackend @@ -75,18 +73,13 @@ style_check test/unittests/serviceRoutines # style_check src/lib/rest (3 files) # style_check src/lib/common (6 files) # style_check src/lib/orionTypes (9 files) -# style_check src/lib/convenience (17 files) -# style_check src/lib/jsonParse (19 files) # style_check src/lib/ngsi10 (24 files) -# style_check src/lib/ngsi9 (24 files) # style_check src/lib/serviceRoutines (46 files) # style_check src/lib/ngsi (74 files) # style_check test/unittests/common (1 file) # style_check test/unittests/parse (2 files) -# style_check test/unittests/convenience (8 files) # style_check test/unittests/ngsi10 (9 files) -# style_check test/unittests/ngsi9 (10 files) # style_check test/unittests/ngsi (32 files) # # style_check test/unittests (1 file, but already done) @@ -109,8 +102,6 @@ style_check test/unittests/serviceRoutines # o common/string.h (haderding/remove_ngsiv1_indent: 1 include, 1 external declaration) # o common/globals.h (feature/mqtt_notifications_poc: 1 external declaration) # o common/globals.h (haderding/remove_ngsiv1_indent: 1 new external declaration) -# o common/tag.cpp (haderding/remove_ngsiv1_indent: 'indent' removed from 6 signatures, slight change in 6 functions) -# o common/tag.h (haderding/remove_ngsiv1_indent: 'indent' removed from 6 signatures) # o common/macroSubstitute.cpp (haderding/remove_ngsiv1_indent: 2 lines: a param added to toJson()) # # o rest/httpRequestSend.cpp (feature/mqtt_notifications_poc: 1 include, 1 new function, addition in httpRequestSendWithCurl()) @@ -170,16 +161,6 @@ style_check test/unittests/serviceRoutines # o ngsi/ContextElementResponseVector.h (haderding/remove_ngsiv1_indent: 7 lines) # o ngsi/ContextElementVector.cpp (haderding/remove_ngsiv1_indent: 13 lines) # o ngsi/ContextElementVector.h (haderding/remove_ngsiv1_indent: 8 lines) -# o ngsi/ContextRegistration.cpp (haderding/remove_ngsiv1_indent: 10 lines) -# o ngsi/ContextRegistration.h (haderding/remove_ngsiv1_indent: 2 lines) -# o ngsi/ContextRegistrationAttribute.cpp (haderding/remove_ngsiv1_indent: 7 lines) -# o ngsi/ContextRegistrationAttribute.h (haderding/remove_ngsiv1_indent: 1 line) -# o ngsi/ContextRegistrationAttributeVector.cpp (haderding/remove_ngsiv1_indent: 4 lines) -# o ngsi/ContextRegistrationAttributeVector.h (haderding/remove_ngsiv1_indent: 1 line) -# o ngsi/ContextRegistrationResponse.cpp (haderding/remove_ngsiv1_indent: 7 lines) -# o ngsi/ContextRegistrationResponse.h (haderding/remove_ngsiv1_indent: 2 lines) -# o ngsi/ContextRegistrationResponseVector.cpp (haderding/remove_ngsiv1_indent: 6 lines) -# o ngsi/ContextRegistrationResponseVector.h (haderding/remove_ngsiv1_indent: 2 lines) # o ngsi/ContextRegistrationVector.cpp (haderding/remove_ngsiv1_indent: 6 lines) # o ngsi/ContextRegistrationVector.h (haderding/remove_ngsiv1_indent: 2 lines) # o ngsi/Duration.cpp (haderding/remove_ngsiv1_indent: 9 lines) @@ -198,8 +179,6 @@ style_check test/unittests/serviceRoutines # o ngsi/NotifyConditionVector.h (haderding/remove_ngsiv1_indent: 2 lines) # o ngsi/Originator.cpp (haderding/remove_ngsiv1_indent: 9 lines) # o ngsi/Originator.h (haderding/remove_ngsiv1_indent: 5 lines) -# o ngsi/ProvidingApplication.cpp (haderding/remove_ngsiv1_indent: 9 lines) -# o ngsi/ProvidingApplication.h (haderding/remove_ngsiv1_indent: 5 lines) # o ngsi/Reference.cpp (haderding/remove_ngsiv1_indent: 9 lines) # o ngsi/Reference.h (haderding/remove_ngsiv1_indent: 5 lines) # o ngsi/RegistrationId.cpp (haderding/remove_ngsiv1_indent: 9 lines) @@ -281,45 +260,10 @@ style_check test/unittests/serviceRoutines # alt exec-part in restReply(), # 'indent' removed from 13 calls to render()) # -# o serviceRoutines/deleteAllEntitiesWithTypeAndId.cpp (haderding/remove_ngsiv1_indent: 3 TIMED_RENDER) -# o serviceRoutines/deleteAttributeValueInstance.cpp (haderding/remove_ngsiv1_indent: 1 TIMED_RENDER) -# o serviceRoutines/deleteAttributeValueInstanceWithTypeAndId.cpp (haderding/remove_ngsiv1_indent: 2 TIMED_RENDER) -# o serviceRoutines/deleteIndividualContextEntity.cpp (haderding/remove_ngsiv1_indent: 1 TIMED_RENDER) -# o serviceRoutines/deleteIndividualContextEntityAttribute.cpp (haderding/remove_ngsiv1_indent: 1 TIMED_RENDER) -# o serviceRoutines/deleteIndividualContextEntityAttributeWithTypeAndId.cpp (haderding/remove_ngsiv1_indent: 3 TIMED_RENDER) -# o serviceRoutines/getAllEntitiesWithTypeAndId.cpp (haderding/remove_ngsiv1_indent: 1 TIMED_RENDER) -# o serviceRoutines/getAttributeValueInstance.cpp (haderding/remove_ngsiv1_indent: 1 TIMED_RENDER) -# o serviceRoutines/getAttributeValueInstanceWithTypeAndId.cpp (haderding/remove_ngsiv1_indent: 1 TIMED_RENDER) -# o serviceRoutines/getAttributesForEntityType.cpp (haderding/remove_ngsiv1_indent: 1 TIMED_RENDER) -# o serviceRoutines/getContextEntitiesByEntityIdAndType.cpp (haderding/remove_ngsiv1_indent: 2 TIMED_RENDER) -# o serviceRoutines/getEntityByIdAttributeByNameWithTypeAndId.cpp (haderding/remove_ngsiv1_indent: 2 TIMED_RENDER) -# o serviceRoutines/getEntityTypes.cpp (haderding/remove_ngsiv1_indent: 1 TIMED_RENDER) -# o serviceRoutines/getIndividualContextEntity.cpp (haderding/remove_ngsiv1_indent: 1 TIMED_RENDER) -# o serviceRoutines/getIndividualContextEntityAttribute.cpp (haderding/remove_ngsiv1_indent: 1 TIMED_RENDER) -# o serviceRoutines/getIndividualContextEntityAttributeWithTypeAndId.cpp (haderding/remove_ngsiv1_indent: 1 TIMED_RENDER) -# o serviceRoutines/getNgsi10ContextEntityTypes.cpp (haderding/remove_ngsiv1_indent: 3 TIMED_RENDER) -# o serviceRoutines/getNgsi10ContextEntityTypesAttribute.cpp (haderding/remove_ngsiv1_indent: 3 TIMED_RENDER) -# o serviceRoutines/postAllEntitiesWithTypeAndId.cpp (haderding/remove_ngsiv1_indent: 4 TIMED_RENDER) -# o serviceRoutines/postAttributeValueInstanceWithTypeAndId.cpp (haderding/remove_ngsiv1_indent: 3 TIMED_RENDER) -# o serviceRoutines/postContextEntitiesByEntityIdAndType.cpp (haderding/remove_ngsiv1_indent: 2 TIMED_RENDER) -# o serviceRoutines/postDiscoverContextAvailability.cpp (haderding/remove_ngsiv1_indent: 1 TIMED_RENDER) -# o serviceRoutines/postEntityByIdAttributeByNameWithTypeAndId.cpp (haderding/remove_ngsiv1_indent: 2 TIMED_RENDER) -# o serviceRoutines/postIndividualContextEntity.cpp (haderding/remove_ngsiv1_indent: 5 TIMED_RENDER) -# o serviceRoutines/postIndividualContextEntityAttribute.cpp (haderding/remove_ngsiv1_indent: 1 TIMED_RENDER) -# o serviceRoutines/postIndividualContextEntityAttributeWithTypeAndId.cpp (haderding/remove_ngsiv1_indent: 1 TIMED_RENDER) + # o serviceRoutines/postNotifyContext.cpp (haderding/remove_ngsiv1_indent: 1 TIMED_RENDER) # o serviceRoutines/postQueryContext.cpp (haderding/remove_ngsiv1_indent: 3 includes, 2 TIMED_RENDER, 35 lines in queryForward()) -# o serviceRoutines/postRegisterContext.cpp (haderding/remove_ngsiv1_indent: 3 TIMED_RENDER) -# o serviceRoutines/postSubscribeContext.cpp (haderding/remove_ngsiv1_indent: 2 TIMED_RENDER) -# o serviceRoutines/postUnsubscribeContext.cpp (haderding/remove_ngsiv1_indent: 1 TIMED_RENDER) # o serviceRoutines/postUpdateContext.cpp (haderding/remove_ngsiv1_indent: 3 includes, 5 TIMED_RENDER, 35 lines in updateForward) -# o serviceRoutines/postUpdateContextSubscription.cpp (haderding/remove_ngsiv1_indent: 1 TIMED_RENDER) -# o serviceRoutines/putAllEntitiesWithTypeAndId.cpp (haderding/remove_ngsiv1_indent: 3 TIMED_RENDER) -# o serviceRoutines/putAttributeValueInstance.cpp (haderding/remove_ngsiv1_indent: 2 TIMED_RENDER) -# o serviceRoutines/putAttributeValueInstanceWithTypeAndId.cpp (haderding/remove_ngsiv1_indent: 3 TIMED_RENDER) -# o serviceRoutines/putIndividualContextEntity.cpp (haderding/remove_ngsiv1_indent: 1 TIMED_RENDER) -# o serviceRoutines/putIndividualContextEntityAttribute.cpp (haderding/remove_ngsiv1_indent: 1 TIMED_RENDER) -# o serviceRoutines/putIndividualContextEntityAttributeWithTypeAndId.cpp (haderding/remove_ngsiv1_indent: 1 TIMED_RENDER) # o serviceRoutines/versionTreat.cpp (haderding/remove_ngsiv1_indent: 8 lines in versionTreat()) # o serviceRoutinesV2/getEntityAttributeValue.cpp (haderding/remove_ngsiv1_indent: 1 TIMED_RENDER) # o serviceRoutinesV2/postSubscriptions.cpp (haderding/remove_ngsiv1_indent: 1 TIMED_RENDER) @@ -327,8 +271,6 @@ style_check test/unittests/serviceRoutines # # o unittests/main_UnitTest.cpp (haderding/remove_ngsiv1_indent: 1 variable) # -# o unittests/common/commonTag_test.cpp (haderding/remove_ngsiv1_indent: 24 lineas) -# # o unittests/convenience/AppendContextElementRequest_test.cpp (haderding/remove_ngsiv1_indent: 1 render(), 4 check()) # o unittests/convenience/AppendContextElementResponse_test.cpp (haderding/remove_ngsiv1_indent: 2 render(), 3 check()) # o unittests/convenience/ContextAttributeResponseVector_test.cpp (haderding/remove_ngsiv1_indent: 2 render(), 3 check()) @@ -348,8 +290,6 @@ style_check test/unittests/serviceRoutines # o unittests/ngsi/ContextElement_test.cpp (haderding/remove_ngsiv1_indent: 8 check()) # o unittests/ngsi/ContextRegistrationAttributeVector_test.cpp (haderding/remove_ngsiv1_indent: 4 render() # o unittests/ngsi/ContextRegistrationAttribute_test.cpp (haderding/remove_ngsiv1_indent: 1 render() -# o unittests/ngsi/ContextRegistrationResponseVector_test.cpp (haderding/remove_ngsiv1_indent: 1 render(), 3 check()) -# o unittests/ngsi/ContextRegistrationResponse_test.cpp (haderding/remove_ngsiv1_indent: 2 render(), 1 check()) # o unittests/ngsi/ContextRegistrationVector_test.cpp (haderding/remove_ngsiv1_indent: 1 render() # o unittests/ngsi/Duration_test.cpp (haderding/remove_ngsiv1_indent: 3 check()) # o unittests/ngsi/EntityId_test.cpp (haderding/remove_ngsiv1_indent: 1 render() diff --git a/src/app/contextBroker/contextBroker.cpp b/src/app/contextBroker/contextBroker.cpp index 4edaa8a84f..9d7d2294ea 100644 --- a/src/app/contextBroker/contextBroker.cpp +++ b/src/app/contextBroker/contextBroker.cpp @@ -80,7 +80,6 @@ #include "logMsg/logMsg.h" #include "logMsg/traceLevels.h" -#include "jsonParse/jsonRequest.h" #include "rest/ConnectionInfo.h" #include "rest/RestService.h" #include "rest/restReply.h" @@ -180,17 +179,14 @@ bool statTiming; bool statNotifQueue; int lsPeriod; bool relogAlarms; -bool strictIdv1; bool disableCusNotif; bool logForHumans; unsigned long logLineMaxSize; unsigned long logInfoPayloadMaxSize; bool disableMetrics; -bool disableNgsiv1; bool disableFileLog; int reqTimeout; bool insecureNotif; -bool ngsiv1Autocast; bool fcEnabled; double fcGauge; @@ -256,17 +252,14 @@ bool logDeprecate; #define STAT_NOTIF_QUEUE "enable thread pool notifications queue statistics" #define LOG_SUMMARY_DESC "log summary period in seconds (defaults to 0, meaning 'off')" #define RELOGALARMS_DESC "log messages for existing alarms beyond the raising alarm log message itself" -#define CHECK_v1_ID_DESC "additional checks for id fields in the NGSIv1 API" #define DISABLE_CUSTOM_NOTIF "disable NGSIv2 custom notifications" #define DISABLE_FILE_LOG "disable logging into file" #define LOG_FOR_HUMANS_DESC "human readible log to screen" #define LOG_LINE_MAX_SIZE_DESC "log line maximum size (in bytes)" #define LOG_INFO_PAYLOAD_MAX_SIZE_DESC "maximum length for request or response payload in INFO log level (in bytes)" #define DISABLE_METRICS_DESC "turn off the 'metrics' feature" -#define DISABLE_NGSIV1_DESC "turn off NGSIv1 request endpoints" #define REQ_TMO_DESC "connection timeout for REST requests (in seconds)" #define INSECURE_NOTIF_DESC "allow HTTPS notifications to peers which certificate cannot be authenticated with known CA certificates" -#define NGSIV1_AUTOCAST_DESC "automatic cast for number, booleans and dates in NGSIv1 update/create attribute operations" #define MQTT_MAX_AGE_DESC "max time (in minutes) that an unused MQTT connection is kept, default: 60" #define LOG_DEPRECATE_DESC "log deprecation usages as warnings" #define DBURI_DESC "complete URI for database connection" @@ -335,7 +328,6 @@ PaArgument paArgs[] = { "-logSummary", &lsPeriod, "LOG_SUMMARY_PERIOD", PaInt, PaOpt, 0, 0, ONE_MONTH_PERIOD, LOG_SUMMARY_DESC }, { "-relogAlarms", &relogAlarms, "RELOG_ALARMS", PaBool, PaOpt, false, false, true, RELOGALARMS_DESC }, - { "-strictNgsiv1Ids", &strictIdv1, "CHECK_ID_V1", PaBool, PaOpt, false, false, true, CHECK_v1_ID_DESC }, { "-disableCustomNotifications", &disableCusNotif, "DISABLE_CUSTOM_NOTIF", PaBool, PaOpt, false, false, true, DISABLE_CUSTOM_NOTIF }, { "-disableFileLog", &disableFileLog, "DISABLE_FILE_LOG", PaBool, PaOpt, false, false, true, DISABLE_FILE_LOG }, @@ -344,12 +336,9 @@ PaArgument paArgs[] = { "-logInfoPayloadMaxSize", &logInfoPayloadMaxSize, "LOG_INFO_PAYLOAD_MAX_SIZE",PaLong, PaOpt, (5 * 1024), 0, PaNL, LOG_INFO_PAYLOAD_MAX_SIZE_DESC }, { "-disableMetrics", &disableMetrics, "DISABLE_METRICS", PaBool, PaOpt, false, false, true, DISABLE_METRICS_DESC }, - { "-disableNgsiv1", &disableNgsiv1, "DISABLE_NGSIV1", PaBool, PaOpt, false, false, true, DISABLE_NGSIV1_DESC }, { "-insecureNotif", &insecureNotif, "INSECURE_NOTIF", PaBool, PaOpt, false, false, true, INSECURE_NOTIF_DESC }, - { "-ngsiv1Autocast", &ngsiv1Autocast, "NGSIV1_AUTOCAST", PaBool, PaOpt, false, false, true, NGSIV1_AUTOCAST_DESC }, - { "-mqttMaxAge", &mqttMaxAge, "MQTT_MAX_AGE", PaInt, PaOpt, 60, PaNL, PaNL, MQTT_MAX_AGE_DESC }, { "-logDeprecate", &logDeprecate, "LOG_DEPRECATE", PaBool, PaOpt, false, false, true, LOG_DEPRECATE_DESC }, @@ -384,8 +373,8 @@ static const char* validLogLevels[] = * to treat the incoming request. * * The URL path is divided into components (Using '/' as field separator) so that the URL -* "/ngsi9/registerContext" becomes a component vector of the two components -* "ngsi9" and "registerContext". +* "/v2/entities" becomes a component vector of the two components +* "v2" and "entities". * * Each line contains the necessary information for ONE service: * RequestType request - The type of the request @@ -1206,7 +1195,7 @@ int main(int argC, char* argV[]) alarmMgr.init(relogAlarms); mqttMgr.init(mqttTimeout); exprMgr.init(); - orionInit(orionExit, ORION_VERSION, policy, statCounters, statSemWait, statTiming, statNotifQueue, strictIdv1); + orionInit(orionExit, ORION_VERSION, policy, statCounters, statSemWait, statTiming, statNotifQueue); mongoInit(dbURI, dbName, pwd, mtenant, writeConcern, dbPoolSize, statSemWait); metricsMgr.init(!disableMetrics, statSemWait); logSummaryInit(&lsPeriod); @@ -1284,7 +1273,6 @@ int main(int argC, char* argV[]) allowedOrigin, maxAge, reqTimeout, - disableNgsiv1, httpsPrivateServerKey, httpsCertificate); @@ -1303,7 +1291,6 @@ int main(int argC, char* argV[]) allowedOrigin, maxAge, reqTimeout, - disableNgsiv1, NULL, NULL); } diff --git a/src/app/contextBroker/orionRestServices.cpp b/src/app/contextBroker/orionRestServices.cpp index cf4eafc048..926020d495 100644 --- a/src/app/contextBroker/orionRestServices.cpp +++ b/src/app/contextBroker/orionRestServices.cpp @@ -22,81 +22,29 @@ * * Author: Ken Zangelin */ + + #include "serviceRoutines/logTraceTreat.h" -#include "serviceRoutines/getEntityTypes.h" -#include "serviceRoutines/getAttributesForEntityType.h" -#include "serviceRoutines/getAllContextEntities.h" #include "serviceRoutines/versionTreat.h" #include "serviceRoutines/statisticsTreat.h" #include "serviceRoutines/exitTreat.h" #include "serviceRoutines/leakTreat.h" - -#include "serviceRoutines/postDiscoverContextAvailability.h" -/// FIXME: disable unused NGSIv1 API (last batch) in Orion 4.0.0, to be definetively removed at some point of the future -///#include "serviceRoutines/postQueryContext.h" -#include "serviceRoutines/postRegisterContext.h" -#include "serviceRoutines/postSubscribeContext.h" -/// FIXME: disable unused NGSIv1 API (last batch) in Orion 4.0.0, to be definetively removed at some point of the future -///#include "serviceRoutines/postUpdateContext.h" -#include "serviceRoutines/postUpdateContextSubscription.h" -#include "serviceRoutines/postUnsubscribeContext.h" -#include "serviceRoutines/postNotifyContext.h" -#include "serviceRoutines/postSubscribeContextConvOp.h" -#include "serviceRoutines/getContextEntitiesByEntityId.h" -#include "serviceRoutines/postContextEntitiesByEntityId.h" -#include "serviceRoutines/getContextEntityAttributes.h" -#include "serviceRoutines/postContextEntityAttributes.h" -#include "serviceRoutines/getEntityByIdAttributeByName.h" -#include "serviceRoutines/postEntityByIdAttributeByName.h" -#include "serviceRoutines/getContextEntityTypes.h" -#include "serviceRoutines/postContextEntityTypes.h" -#include "serviceRoutines/getContextEntityTypeAttribute.h" -#include "serviceRoutines/postContextEntityTypeAttribute.h" -#include "serviceRoutines/getIndividualContextEntity.h" -#include "serviceRoutines/putIndividualContextEntity.h" +#include "serviceRoutines/optionsVersionRequest.h" #include "serviceRoutines/badVerbPostOnly.h" #include "serviceRoutines/badVerbPutDeleteOnly.h" #include "serviceRoutines/badVerbGetPostOnly.h" #include "serviceRoutines/badVerbGetDeleteOnly.h" -#include "serviceRoutines/postIndividualContextEntity.h" -#include "serviceRoutines/deleteIndividualContextEntity.h" -#include "serviceRoutines/badVerbAllFour.h" -#include "serviceRoutines/badVerbAllFive.h" #include "serviceRoutines/badVerbPutOnly.h" -#include "serviceRoutines/putIndividualContextEntityAttribute.h" -#include "serviceRoutines/getIndividualContextEntityAttribute.h" -#include "serviceRoutines/getNgsi10ContextEntityTypes.h" -#include "serviceRoutines/getNgsi10ContextEntityTypesAttribute.h" -#include "serviceRoutines/postIndividualContextEntityAttribute.h" -#include "serviceRoutines/deleteIndividualContextEntityAttribute.h" -#include "serviceRoutines/putSubscriptionConvOp.h" -#include "serviceRoutines/deleteSubscriptionConvOp.h" -#include "serviceRoutines/getAllEntitiesWithTypeAndId.h" -#include "serviceRoutines/postAllEntitiesWithTypeAndId.h" -#include "serviceRoutines/putAllEntitiesWithTypeAndId.h" -#include "serviceRoutines/deleteAllEntitiesWithTypeAndId.h" -#include "serviceRoutines/getIndividualContextEntityAttributeWithTypeAndId.h" -#include "serviceRoutines/postIndividualContextEntityAttributeWithTypeAndId.h" -#include "serviceRoutines/putIndividualContextEntityAttributeWithTypeAndId.h" -#include "serviceRoutines/deleteIndividualContextEntityAttributeWithTypeAndId.h" -#include "serviceRoutines/getContextEntitiesByEntityIdAndType.h" -#include "serviceRoutines/postContextEntitiesByEntityIdAndType.h" -#include "serviceRoutines/getEntityByIdAttributeByNameWithTypeAndId.h" -#include "serviceRoutines/postEntityByIdAttributeByNameWithTypeAndId.h" #include "serviceRoutines/badVerbGetPutDeleteOnly.h" -#include "serviceRoutines/badVerbGetPostDeleteOnly.h" #include "serviceRoutines/badVerbGetOnly.h" -#include "serviceRoutines/badVerbGetDeleteOnly.h" +#include "serviceRoutines/badRequest.h" + +// FIXME PR: postNotifyContext.h should be in serviceRoutinesV2 as it is for a v2 operation +#include "serviceRoutines/postNotifyContext.h" + #include "serviceRoutinesV2/badVerbGetPutOnly.h" #include "serviceRoutinesV2/badVerbGetDeletePatchOnly.h" -// FIXME: disable NGSI9 API routes in Orion 3.8.0, to be definetively removed at some point of the future -// (along with badNgsi9Request.h|cpp files themselves) -//#include "serviceRoutines/badNgsi9Request.h" -/// FIXME: disable unused NGSIv1 API (last batch) in Orion 4.0.0, to be definetively removed at some point of the future -///#include "serviceRoutines/badNgsi10Request.h" -#include "serviceRoutines/badRequest.h" #include "serviceRoutinesV2/badVerbAllNotDelete.h" - #include "serviceRoutinesV2/getEntities.h" #include "serviceRoutinesV2/entryPointsTreat.h" #include "serviceRoutinesV2/getEntity.h" @@ -130,7 +78,6 @@ #include "serviceRoutinesV2/optionsGetPutDeleteOnly.h" #include "serviceRoutinesV2/optionsGetDeletePatchOnly.h" #include "serviceRoutinesV2/optionsPostOnly.h" -#include "serviceRoutines/optionsVersionRequest.h" #include "serviceRoutinesV2/getRegistration.h" #include "serviceRoutinesV2/deleteRegistration.h" @@ -179,79 +126,6 @@ static RestService getServiceV[] = ORION_REST_SERVICE_END }; -static RestService getServiceVlegacy[] = -{ - { EntryPointsRequest, 1, { "v2" }, entryPointsTreat }, - { EntitiesRequest, 2, { "v2", "entities" }, getEntities }, - { EntityRequest, 3, { "v2", "entities", "*" }, getEntity }, - { EntityRequest, 4, { "v2", "entities", "*", "attrs" }, getEntity }, - { EntityAttributeValueRequest, 6, { "v2", "entities", "*", "attrs", "*", "value" }, getEntityAttributeValue }, - { EntityAttributeRequest, 5, { "v2", "entities", "*", "attrs", "*" }, getEntityAttribute }, - { EntityTypeRequest, 3, { "v2", "types", "*" }, getEntityType }, - { EntityAllTypesRequest, 2, { "v2", "types" }, getEntityAllTypes }, - { SubscriptionsRequest, 2, { "v2", "subscriptions" }, getAllSubscriptions }, - { SubscriptionRequest, 3, { "v2", "subscriptions", "*" }, getSubscription }, - { RegistrationRequest, 3, { "v2", "registrations", "*" }, getRegistration }, - { RegistrationsRequest, 2, { "v2", "registrations" }, getRegistrations }, - // FIXME: disable NGSI9 API routes in Orion 3.8.0, to be definetively removed at some point of the future - //{ ContextEntitiesByEntityId, 3, { "ngsi9", "contextEntities", "*" }, getContextEntitiesByEntityId }, - //{ ContextEntityAttributes, 4, { "ngsi9", "contextEntities", "*", "attributes" }, getContextEntityAttributes }, - //{ EntityByIdAttributeByName, 5, { "ngsi9", "contextEntities", "*", "attributes", "*" }, getEntityByIdAttributeByName }, - //{ ContextEntityTypes, 3, { "ngsi9", "contextEntityTypes", "*" }, getContextEntityTypes }, - //{ ContextEntityTypeAttributeContainer, 4, { "ngsi9", "contextEntityTypes", "*", "attributes" }, getContextEntityTypes }, - //{ ContextEntityTypeAttribute, 5, { "ngsi9", "contextEntityTypes", "*", "attributes", "*" }, getContextEntityTypeAttribute }, - // FIXME: disable unused NGSv1 API routes in Orion 3.9.0, to be definetively removed at some point of the future - //{ ContextEntitiesByEntityId, 4, { "v1", "registry", "contextEntities", "*" }, getContextEntitiesByEntityId }, - //{ ContextEntityAttributes, 5, { "v1", "registry", "contextEntities", "*", "attributes" }, getContextEntityAttributes }, - //{ EntityByIdAttributeByName, 6, { "v1", "registry", "contextEntities", "*", "attributes", "*" }, getEntityByIdAttributeByName }, - //{ ContextEntityTypes, 4, { "v1", "registry", "contextEntityTypes", "*" }, getContextEntityTypes }, - //{ ContextEntityTypeAttributeContainer, 5, { "v1", "registry", "contextEntityTypes", "*", "attributes" }, getContextEntityTypes }, - //{ ContextEntityTypeAttribute, 6, { "v1", "registry", "contextEntityTypes", "*", "attributes", "*" }, getContextEntityTypeAttribute }, - //{ IndividualContextEntity, 3, { "ngsi10", "contextEntities", "*" }, getIndividualContextEntity }, - //{ IndividualContextEntityAttributes, 4, { "ngsi10", "contextEntities", "*", "attributes" }, getIndividualContextEntity }, - //{ IndividualContextEntityAttribute, 5, { "ngsi10", "contextEntities", "*", "attributes", "*" }, getIndividualContextEntityAttribute }, - //{ Ngsi10ContextEntityTypes, 3, { "ngsi10", "contextEntityTypes", "*" }, getNgsi10ContextEntityTypes }, - //{ Ngsi10ContextEntityTypesAttributeContainer, 4, { "ngsi10", "contextEntityTypes", "*", "attributes" }, getNgsi10ContextEntityTypes }, - //{ Ngsi10ContextEntityTypesAttribute, 5, { "ngsi10", "contextEntityTypes", "*", "attributes", "*" }, getNgsi10ContextEntityTypesAttribute }, - //{ IndividualContextEntity, 3, { "v1", "contextEntities", "*" }, getIndividualContextEntity }, - //{ IndividualContextEntityAttributes, 4, { "v1", "contextEntities", "*", "attributes" }, getIndividualContextEntity }, - /// FIXME: disable unused NGSIv1 API (last batch) in Orion 4.0.0, to be definetively removed at some point of the future - ///{ IndividualContextEntityAttribute, 5, { "v1", "contextEntities", "*", "attributes", "*" }, getIndividualContextEntityAttribute }, - //{ Ngsi10ContextEntityTypes, 3, { "v1", "contextEntityTypes", "*" }, getNgsi10ContextEntityTypes }, - //{ Ngsi10ContextEntityTypesAttributeContainer, 4, { "v1", "contextEntityTypes", "*", "attributes" }, getNgsi10ContextEntityTypes }, - //{ Ngsi10ContextEntityTypesAttribute, 5, { "v1", "contextEntityTypes", "*", "attributes", "*" }, getNgsi10ContextEntityTypesAttribute }, - //{ EntityTypes, 2, { "v1", "contextTypes" }, getEntityTypes }, - //{ AttributesForEntityType, 3, { "v1", "contextTypes", "*" }, getAttributesForEntityType }, - //{ AllContextEntities, 2, { "v1", "contextEntities" }, getAllContextEntities }, - //{ AllEntitiesWithTypeAndId, 6, { "v1", "contextEntities", "type", "*", "id", "*" }, getAllEntitiesWithTypeAndId }, - //{ IndividualContextEntityAttributeWithTypeAndId, 8, { "v1", "contextEntities", "type", "*", "id", "*", "attributes", "*" }, getIndividualContextEntityAttributeWithTypeAndId }, - //{ ContextEntitiesByEntityIdAndType, 7, { "v1", "registry", "contextEntities", "type", "*", "id", "*" }, getContextEntitiesByEntityIdAndType }, - //{ EntityByIdAttributeByNameIdAndType, 9, { "v1", "registry", "contextEntities", "type", "*", "id", "*", "attributes", "*" }, getEntityByIdAttributeByNameWithTypeAndId }, - { LogTraceRequest, 2, { "log", "trace" }, logTraceTreat }, - // FIXME: disable administrative API routes not aligned with documentation in Orion 3.8.0, - // to be definetively removed at some point of the future - //{ LogTraceRequest, 2, { "log", "traceLevel" }, logTraceTreat }, - //{ LogTraceRequest, 4, { "v1", "admin", "log", "trace" }, logTraceTreat }, - //{ LogTraceRequest, 4, { "v1", "admin", "log", "traceLevel" }, logTraceTreat }, - { StatisticsRequest, 1, { "statistics" }, statisticsTreat }, - //{ StatisticsRequest, 3, { "v1", "admin", "statistics" }, statisticsTreat }, - { StatisticsRequest, 2, { "cache", "statistics" }, statisticsCacheTreat }, - //{ StatisticsRequest, 4, { "v1", "admin", "cache", "statistics" }, statisticsCacheTreat }, - { VersionRequest, 1, { "version" }, versionTreat }, - { LogLevelRequest, 2, { "admin", "log" }, getLogConfig }, - { SemStateRequest, 2, { "admin", "sem" }, semStateTreat }, - { MetricsRequest, 2, { "admin", "metrics" }, getMetrics }, - -#ifdef DEBUG - { ExitRequest, 2, { "exit", "*" }, exitTreat }, - { ExitRequest, 1, { "exit" }, exitTreat }, - { LeakRequest, 2, { "leak", "*" }, leakTreat }, - { LeakRequest, 1, { "leak" }, leakTreat }, -#endif - - ORION_REST_SERVICE_END -}; - /* **************************************************************************** @@ -271,70 +145,6 @@ static RestService postServiceV[] = ORION_REST_SERVICE_END }; -static RestService postServiceVlegacy[] = -{ - { EntitiesRequest, 2, { "v2", "entities" }, postEntities }, - { EntityRequest, 4, { "v2", "entities", "*", "attrs" }, postEntity }, - { NotifyContext, 3, { "v2", "op", "notify" }, postNotifyContext }, - { BatchQueryRequest, 3, { "v2", "op", "query" }, postBatchQuery }, - { BatchUpdateRequest, 3, { "v2", "op", "update" }, postBatchUpdate }, - { SubscriptionsRequest, 2, { "v2", "subscriptions" }, postSubscriptions }, - { RegistrationsRequest, 2, { "v2", "registrations" }, postRegistration }, - // FIXME: disable NGSI9 API routes in Orion 3.8.0, to be definetively removed at some point of the future - //{ RegisterContext, 2, { "ngsi9", "registerContext" }, postRegisterContext }, - //{ DiscoverContextAvailability, 2, { "ngsi9", "discoverContextAvailability" }, postDiscoverContextAvailability }, - // FIXME: disable NGSI9 API routes in Orion 3.8.0, to be definetively removed at some point of the future - //{ RegisterContext, 3, { "v1", "registry", "registerContext" }, postRegisterContext }, - //{ DiscoverContextAvailability, 3, { "v1", "registry", "discoverContextAvailability" }, postDiscoverContextAvailability }, - // FIXME: disable NGSI9 API routes in Orion 3.8.0, to be definetively removed at some point of the future - //{ RegisterContext, 2, { "ngsi9", "registerContext" }, postRegisterContext }, - //{ DiscoverContextAvailability, 2, { "ngsi9", "discoverContextAvailability" }, postDiscoverContextAvailability }, - /// FIXME: disable unused NGSIv1 API (last batch) in Orion 4.0.0, to be definetively removed at some point of the future - ///{ UpdateContext, 2, { "v1", "updateContext" }, (RestTreat) postUpdateContext }, - ///{ QueryContext, 2, { "v1", "queryContext" }, postQueryContext }, - // FIXME: disable unused NGSv1 API routes in Orion 3.9.0, to be definetively removed at some point of the future - //{ SubscribeContext, 2, { "v1", "subscribeContext" }, postSubscribeContext }, - //{ UpdateContextSubscription, 2, { "v1", "updateContextSubscription" }, postUpdateContextSubscription }, - //{ UnsubscribeContext, 2, { "v1", "unsubscribeContext" }, postUnsubscribeContext }, - //{ NotifyContext, 2, { "v1", "notifyContext" }, postNotifyContext }, - // FIXME: disable NGSI9 API routes in Orion 3.8.0, to be definetively removed at some point of the future - //{ ContextEntitiesByEntityId, 3, { "ngsi9", "contextEntities", "*" }, postContextEntitiesByEntityId }, - //{ ContextEntityAttributes, 4, { "ngsi9", "contextEntities", "*", "attributes" }, postContextEntityAttributes }, - //{ EntityByIdAttributeByName, 5, { "ngsi9", "contextEntities", "*", "attributes", "*" }, postEntityByIdAttributeByName }, - //{ ContextEntityTypes, 3, { "ngsi9", "contextEntityTypes", "*" }, postContextEntityTypes }, - //{ ContextEntityTypeAttributeContainer, 4, { "ngsi9", "contextEntityTypes", "*", "attributes" }, postContextEntityTypes }, - //{ ContextEntityTypeAttribute, 5, { "ngsi9", "contextEntityTypes", "*", "attributes", "*" }, postContextEntityTypeAttribute }, - // FIXME: disable unused NGSv1 API routes in Orion 3.9.0, to be definetively removed at some point of the future - //{ ContextEntitiesByEntityId, 4, { "v1", "registry", "contextEntities", "*" }, postContextEntitiesByEntityId }, - //{ ContextEntityAttributes, 5, { "v1", "registry", "contextEntities", "*", "attributes" }, postContextEntityAttributes }, - //{ EntityByIdAttributeByName, 6, { "v1", "registry", "contextEntities", "*", "attributes", "*" }, postEntityByIdAttributeByName }, - //{ ContextEntityTypes, 4, { "v1", "registry", "contextEntityTypes", "*" }, postContextEntityTypes }, - //{ ContextEntityTypeAttributeContainer, 5, { "v1", "registry", "contextEntityTypes", "*", "attributes" }, postContextEntityTypes }, - //{ ContextEntityTypeAttribute, 6, { "v1", "registry", "contextEntityTypes", "*", "attributes", "*" }, postContextEntityTypeAttribute }, - //{ IndividualContextEntity, 3, { "ngsi10", "contextEntities", "*" }, postIndividualContextEntity }, - //{ IndividualContextEntityAttributes, 4, { "ngsi10", "contextEntities", "*", "attributes" }, postIndividualContextEntity }, - //{ IndividualContextEntityAttribute, 5, { "ngsi10", "contextEntities", "*", "attributes", "*" }, postIndividualContextEntityAttribute }, - //{ SubscribeContext, 2, { "ngsi10", "contextSubscriptions" }, postSubscribeContextConvOp }, - //{ IndividualContextEntity, 3, { "v1", "contextEntities", "*" }, postIndividualContextEntity }, - //{ IndividualContextEntityAttributes, 4, { "v1", "contextEntities", "*", "attributes" }, postIndividualContextEntity }, - //{ IndividualContextEntityAttribute, 5, { "v1", "contextEntities", "*", "attributes", "*" }, postIndividualContextEntityAttribute }, - //{ SubscribeContext, 2, { "v1", "contextSubscriptions" }, postSubscribeContextConvOp }, - //{ AllContextEntities, 2, { "v1", "contextEntities" }, postIndividualContextEntity }, - //{ AllEntitiesWithTypeAndId, 6, { "v1", "contextEntities", "type", "*", "id", "*" }, postAllEntitiesWithTypeAndId }, - //{ IndividualContextEntityAttributeWithTypeAndId, 8, { "v1", "contextEntities", "type", "*", "id", "*", "attributes", "*" }, postIndividualContextEntityAttributeWithTypeAndId }, - //{ ContextEntitiesByEntityIdAndType, 7, { "v1", "registry", "contextEntities", "type", "*", "id", "*" }, postContextEntitiesByEntityIdAndType }, - //{ EntityByIdAttributeByNameIdAndType, 9, { "v1", "registry", "contextEntities", "type", "*", "id", "*", "attributes", "*" }, postEntityByIdAttributeByNameWithTypeAndId }, - /// FIXME: disable unused NGSIv1 API (last batch) in Orion 4.0.0, to be definetively removed at some point of the future - ///{ UpdateContext, 2, { "ngsi10", "updateContext" }, (RestTreat) postUpdateContext }, - ///{ QueryContext, 2, { "ngsi10", "queryContext" }, postQueryContext }, - //{ SubscribeContext, 2, { "ngsi10", "subscribeContext" }, postSubscribeContext }, - //{ UpdateContextSubscription, 2, { "ngsi10", "updateContextSubscription" }, postUpdateContextSubscription }, - //{ UnsubscribeContext, 2, { "ngsi10", "unsubscribeContext" }, postUnsubscribeContext }, - //{ NotifyContext, 2, { "ngsi10", "notifyContext" }, postNotifyContext }, - - ORION_REST_SERVICE_END -}; - /* **************************************************************************** * @@ -351,34 +161,6 @@ static RestService putServiceV[] = ORION_REST_SERVICE_END }; -static RestService putServiceVlegacy[] = -{ - { EntityRequest, 4, { "v2", "entities", "*", "attrs" }, putEntity }, - { EntityAttributeValueRequest, 6, { "v2", "entities", "*", "attrs", "*", "value" }, putEntityAttributeValue }, - { EntityAttributeRequest, 5, { "v2", "entities", "*", "attrs", "*" }, putEntityAttribute }, - // FIXME: disable unused NGSv1 API routes in Orion 3.9.0, to be definetively removed at some point of the future - //{ IndividualContextEntity, 3, { "ngsi10", "contextEntities", "*" }, putIndividualContextEntity }, - //{ IndividualContextEntityAttributes, 4, { "ngsi10", "contextEntities", "*", "attributes" }, putIndividualContextEntity }, - //{ IndividualContextEntityAttribute, 5, { "ngsi10", "contextEntities", "*", "attributes", "*" }, putIndividualContextEntityAttribute }, - //{ Ngsi10SubscriptionsConvOp, 3, { "ngsi10", "contextSubscriptions", "*" }, putSubscriptionConvOp }, - /// FIXME: disable unused NGSIv1 API (last batch) in Orion 4.0.0, to be definetively removed at some point of the future - ///{ IndividualContextEntity, 3, { "v1", "contextEntities", "*" }, putIndividualContextEntity }, - //{ IndividualContextEntityAttributes, 4, { "v1", "contextEntities", "*", "attributes" }, putIndividualContextEntity }, - //{ IndividualContextEntityAttribute, 5, { "v1", "contextEntities", "*", "attributes", "*" }, putIndividualContextEntityAttribute }, - //{ Ngsi10SubscriptionsConvOp, 3, { "v1", "contextSubscriptions", "*" }, putSubscriptionConvOp }, - //{ AllEntitiesWithTypeAndId, 6, { "v1", "contextEntities", "type", "*", "id", "*" }, putAllEntitiesWithTypeAndId }, - //{ IndividualContextEntityAttributeWithTypeAndId, 8, { "v1", "contextEntities", "type", "*", "id", "*", "attributes", "*" }, putIndividualContextEntityAttributeWithTypeAndId }, - // FIXME: disable administrative API routes not aligned with documentation in Orion 3.8.0, - // to be definetively removed at some point of the future - { LogTraceRequest, 3, { "log", "trace", "*" }, logTraceTreat }, - //{ LogTraceRequest, 3, { "log", "traceLevel", "*" }, logTraceTreat }, - //{ LogTraceRequest, 5, { "v1", "admin", "log", "trace", "*" }, logTraceTreat }, - //{ LogTraceRequest, 5, { "v1", "admin", "log", "traceLevel", "*" }, logTraceTreat }, - { LogLevelRequest, 2, { "admin", "log" }, changeLogConfig }, - - ORION_REST_SERVICE_END -}; - /* **************************************************************************** * @@ -412,43 +194,6 @@ static RestService deleteServiceV[] = ORION_REST_SERVICE_END }; -static RestService deleteServiceVlegacy[] = -{ - { EntityRequest, 3, { "v2", "entities", "*" }, deleteEntity }, - { EntityAttributeRequest, 5, { "v2", "entities", "*", "attrs", "*" }, deleteEntity }, - { SubscriptionRequest, 3, { "v2", "subscriptions", "*" }, deleteSubscription }, - { RegistrationRequest, 3, { "v2", "registrations", "*" }, deleteRegistration }, - // FIXME: disable unused NGSv1 API routes in Orion 3.9.0, to be definetively removed at some point of the future - //{ IndividualContextEntity, 3, { "ngsi10", "contextEntities", "*" }, deleteIndividualContextEntity }, - //{ IndividualContextEntityAttributes, 4, { "ngsi10", "contextEntities", "*", "attributes" }, deleteIndividualContextEntity }, - //{ IndividualContextEntityAttribute, 5, { "ngsi10", "contextEntities", "*", "attributes", "*" }, deleteIndividualContextEntityAttribute }, - //{ Ngsi10SubscriptionsConvOp, 3, { "ngsi10", "contextSubscriptions", "*" }, deleteSubscriptionConvOp }, - /// FIXME: disable unused NGSIv1 API (last batch) in Orion 4.0.0, to be definetively removed at some point of the future - ///{ IndividualContextEntity, 3, { "v1", "contextEntities", "*" }, deleteIndividualContextEntity }, - //{ IndividualContextEntityAttributes, 4, { "v1", "contextEntities", "*", "attributes" }, deleteIndividualContextEntity }, - //{ IndividualContextEntityAttribute, 5, { "v1", "contextEntities", "*", "attributes", "*" }, deleteIndividualContextEntityAttribute }, - //{ Ngsi10SubscriptionsConvOp, 3, { "v1", "contextSubscriptions", "*" }, deleteSubscriptionConvOp }, - //{ AllEntitiesWithTypeAndId, 6, { "v1", "contextEntities", "type", "*", "id", "*" }, deleteAllEntitiesWithTypeAndId }, - //{ IndividualContextEntityAttributeWithTypeAndId, 8, { "v1", "contextEntities", "type", "*", "id", "*", "attributes", "*" }, deleteIndividualContextEntityAttributeWithTypeAndId }, - // FIXME: disable administrative API routes not aligned with documentation in Orion 3.8.0, - // to be definetively removed at some point of the future - { LogTraceRequest, 2, { "log", "trace" }, logTraceTreat }, - { LogTraceRequest, 3, { "log", "trace", "*" }, logTraceTreat }, - //{ LogTraceRequest, 2, { "log", "traceLevel" }, logTraceTreat }, - //{ LogTraceRequest, 3, { "log", "traceLevel", "*" }, logTraceTreat }, - //{ LogTraceRequest, 4, { "v1", "admin", "log", "trace" }, logTraceTreat }, - //{ LogTraceRequest, 5, { "v1", "admin", "log", "trace", "*" }, logTraceTreat }, - //{ LogTraceRequest, 4, { "v1", "admin", "log", "traceLevel" }, logTraceTreat }, - //{ LogTraceRequest, 5, { "v1", "admin", "log", "traceLevel", "*" }, logTraceTreat }, - { StatisticsRequest, 1, { "statistics" }, statisticsTreat }, - //{ StatisticsRequest, 3, { "v1", "admin", "statistics" }, statisticsTreat }, - { StatisticsRequest, 2, { "cache", "statistics" }, statisticsCacheTreat }, - //{ StatisticsRequest, 4, { "v1", "admin", "cache", "statistics" }, statisticsCacheTreat }, - { MetricsRequest, 2, { "admin", "metrics" }, deleteMetrics }, - - ORION_REST_SERVICE_END -}; - /* **************************************************************************** * @@ -485,111 +230,6 @@ static RestService badVerbV[] = ORION_REST_SERVICE_END }; -static RestService badVerbVlegacy[] = -{ - { EntryPointsRequest, 1, { "v2" }, badVerbGetOnly }, - { EntitiesRequest, 2, { "v2", "entities" }, badVerbGetPostOnly }, - { EntityRequest, 3, { "v2", "entities", "*" }, badVerbGetDeleteOnly }, - { EntityRequest, 4, { "v2", "entities", "*", "attrs" }, badVerbAllNotDelete }, - { EntityAttributeValueRequest, 6, { "v2", "entities", "*", "attrs", "*", "value" }, badVerbGetPutOnly }, - { EntityAttributeRequest, 5, { "v2", "entities", "*", "attrs", "*" }, badVerbGetPutDeleteOnly }, - { EntityTypeRequest, 3, { "v2", "types", "*" }, badVerbGetOnly }, - { EntityAllTypesRequest, 2, { "v2", "types" }, badVerbGetOnly }, - { SubscriptionsRequest, 2, { "v2", "subscriptions" }, badVerbGetPostOnly }, - { SubscriptionRequest, 3, { "v2", "subscriptions", "*" }, badVerbGetDeletePatchOnly }, - { BatchQueryRequest, 3, { "v2", "op", "query" }, badVerbPostOnly }, - { BatchUpdateRequest, 3, { "v2", "op", "update" }, badVerbPostOnly }, - { RegistrationRequest, 3, { "v2", "registrations", "*" }, badVerbGetDeleteOnly }, - { RegistrationsRequest, 2, { "v2", "registrations" }, badVerbGetPostOnly }, - // FIXME: disable NGSI9 API routes in Orion 3.8.0, to be definetively removed at some point of the future - //{ RegisterContext, 2, { "ngsi9", "registerContext" }, badVerbPostOnly }, - //{ DiscoverContextAvailability, 2, { "ngsi9", "discoverContextAvailability" }, badVerbPostOnly }, - /// FIXME: disable unused NGSIv1 API (last batch) in Orion 4.0.0, to be definetively removed at some point of the future - ///{ RegisterContext, 3, { "v1", "registry", "registerContext" }, badVerbPostOnly }, - ///{ DiscoverContextAvailability, 3, { "v1", "registry", "discoverContextAvailability" }, badVerbPostOnly }, - // FIXME: disable NGSI9 API routes in Orion 3.8.0, to be definetively removed at some point of the future - //{ RegisterContext, 2, { "ngsi9", "registerContext" }, badVerbPostOnly }, - //{ DiscoverContextAvailability, 2, { "ngsi9", "discoverContextAvailability" }, badVerbPostOnly }, - /// FIXME: disable unused NGSIv1 API (last batch) in Orion 4.0.0, to be definetively removed at some point of the future - ///{ UpdateContext, 2, { "v1", "updateContext" }, badVerbPostOnly }, - ///{ QueryContext, 2, { "v1", "queryContext" }, badVerbPostOnly }, - ///{ SubscribeContext, 2, { "v1", "subscribeContext" }, badVerbPostOnly }, - ///{ UpdateContextSubscription, 2, { "v1", "updateContextSubscription" }, badVerbPostOnly }, - ///{ UnsubscribeContext, 2, { "v1", "unsubscribeContext" }, badVerbPostOnly }, - ///{ NotifyContext, 2, { "v1", "notifyContext" }, badVerbPostOnly }, - // FIXME: disable NGSI9 API routes in Orion 3.8.0, to be definetively removed at some point of the future - //{ ContextEntitiesByEntityId, 3, { "ngsi9", "contextEntities", "*" }, badVerbGetPostOnly }, - //{ ContextEntityAttributes, 4, { "ngsi9", "contextEntities", "*", "attributes" }, badVerbGetPostOnly }, - //{ EntityByIdAttributeByName, 5, { "ngsi9", "contextEntities", "*", "attributes", "*" }, badVerbGetPostOnly }, - //{ ContextEntityTypes, 3, { "ngsi9", "contextEntityTypes", "*" }, badVerbGetPostOnly }, - //{ ContextEntityTypeAttributeContainer, 4, { "ngsi9", "contextEntityTypes", "*", "attributes" }, badVerbGetPostOnly }, - //{ ContextEntityTypeAttribute, 5, { "ngsi9", "contextEntityTypes", "*", "attributes", "*" }, badVerbGetPostOnly }, - /// FIXME: disable unused NGSIv1 API (last batch) in Orion 4.0.0, to be definetively removed at some point of the future - ///{ ContextEntitiesByEntityId, 4, { "v1", "registry", "contextEntities", "*" }, badVerbGetPostOnly }, - ///{ ContextEntityAttributes, 5, { "v1", "registry", "contextEntities", "*", "attributes" }, badVerbGetPostOnly }, - ///{ EntityByIdAttributeByName, 6, { "v1", "registry", "contextEntities", "*", "attributes", "*" }, badVerbGetPostOnly }, - ///{ ContextEntityTypes, 4, { "v1", "registry", "contextEntityTypes", "*" }, badVerbGetPostOnly }, - ///{ ContextEntityTypeAttributeContainer, 5, { "v1", "registry", "contextEntityTypes", "*", "attributes" }, badVerbGetPostOnly }, - ///{ ContextEntityTypeAttribute, 6, { "v1", "registry", "contextEntityTypes", "*", "attributes", "*" }, badVerbGetPostOnly }, - ///{ IndividualContextEntity, 3, { "ngsi10", "contextEntities", "*" }, badVerbAllFour }, - ///{ IndividualContextEntityAttributes, 4, { "ngsi10", "contextEntities", "*", "attributes" }, badVerbAllFour }, - ///{ IndividualContextEntityAttribute, 5, { "ngsi10", "contextEntities", "*", "attributes", "*" }, badVerbAllFour }, - ///{ Ngsi10ContextEntityTypes, 3, { "ngsi10", "contextEntityTypes", "*" }, badVerbGetOnly }, - ///{ Ngsi10ContextEntityTypesAttributeContainer, 4, { "ngsi10", "contextEntityTypes", "*", "attributes" }, badVerbGetOnly }, - ///{ Ngsi10ContextEntityTypesAttribute, 5, { "ngsi10", "contextEntityTypes", "*", "attributes", "*" }, badVerbGetOnly }, - ///{ SubscribeContext, 2, { "ngsi10", "contextSubscriptions" }, badVerbPostOnly }, - ///{ Ngsi10SubscriptionsConvOp, 3, { "ngsi10", "contextSubscriptions", "*" }, badVerbPutDeleteOnly }, - ///{ IndividualContextEntity, 3, { "v1", "contextEntities", "*" }, badVerbAllFour }, - ///{ IndividualContextEntityAttributes, 4, { "v1", "contextEntities", "*", "attributes" }, badVerbAllFour }, - ///{ IndividualContextEntityAttribute, 5, { "v1", "contextEntities", "*", "attributes", "*" }, badVerbAllFour }, - ///{ Ngsi10ContextEntityTypes, 3, { "v1", "contextEntityTypes", "*" }, badVerbGetOnly }, - ///{ Ngsi10ContextEntityTypesAttributeContainer, 4, { "v1", "contextEntityTypes", "*", "attributes" }, badVerbGetOnly }, - ///{ Ngsi10ContextEntityTypesAttribute, 5, { "v1", "contextEntityTypes", "*", "attributes", "*" }, badVerbGetOnly }, - ///{ SubscribeContext, 2, { "v1", "contextSubscriptions" }, badVerbPostOnly }, - ///{ Ngsi10SubscriptionsConvOp, 3, { "v1", "contextSubscriptions", "*" }, badVerbPutDeleteOnly }, - ///{ EntityTypes, 2, { "v1", "contextTypes" }, badVerbGetOnly }, - ///{ AttributesForEntityType, 3, { "v1", "contextTypes", "*" }, badVerbGetOnly }, - ///{ AllContextEntities, 2, { "v1", "contextEntities" }, badVerbGetPostOnly }, - ///{ AllEntitiesWithTypeAndId, 6, { "v1", "contextEntities", "type", "*", "id", "*" }, badVerbAllFour }, - ///{ IndividualContextEntityAttributeWithTypeAndId, 8, { "v1", "contextEntities", "type", "*", "id", "*", "attributes", "*" }, badVerbAllFour }, - ///{ ContextEntitiesByEntityIdAndType, 7, { "v1", "registry", "contextEntities", "type", "*", "id", "*" }, badVerbGetPostOnly }, - ///{ EntityByIdAttributeByNameIdAndType, 9, { "v1", "registry", "contextEntities", "type", "*", "id", "*", "attributes", "*" }, badVerbGetPostOnly }, - // FIXME: disable administrative API routes not aligned with documentation in Orion 3.8.0, - // to be definetively removed at some point of the future - { LogTraceRequest, 2, { "log", "trace" }, badVerbGetDeleteOnly }, - { LogTraceRequest, 3, { "log", "trace", "*" }, badVerbPutDeleteOnly }, - //{ LogTraceRequest, 2, { "log", "traceLevel" }, badVerbGetDeleteOnly }, - //{ LogTraceRequest, 3, { "log", "traceLevel", "*" }, badVerbPutDeleteOnly }, - //{ LogTraceRequest, 4, { "v1", "admin", "log", "trace" }, badVerbGetDeleteOnly }, - //{ LogTraceRequest, 5, { "v1", "admin", "log", "trace", "*" }, badVerbPutDeleteOnly }, - //{ LogTraceRequest, 4, { "v1", "admin", "log", "traceLevel" }, badVerbGetDeleteOnly }, - //{ LogTraceRequest, 5, { "v1", "admin", "log", "traceLevel", "*" }, badVerbPutDeleteOnly }, - { StatisticsRequest, 1, { "statistics" }, badVerbGetDeleteOnly }, - //{ StatisticsRequest, 3, { "v1", "admin", "statistics" }, badVerbGetDeleteOnly }, - { StatisticsRequest, 2, { "cache", "statistics" }, badVerbGetDeleteOnly }, - //{ StatisticsRequest, 4, { "v1", "admin", "cache", "statistics" }, badVerbGetDeleteOnly }, - { VersionRequest, 1, { "version" }, badVerbGetOnly }, - { LogLevelRequest, 2, { "admin", "log" }, badVerbPutOnly }, - { SemStateRequest, 2, { "admin", "sem" }, badVerbGetOnly }, - { MetricsRequest, 2, { "admin", "metrics" }, badVerbGetDeleteOnly }, - /// FIXME: disable unused NGSIv1 API (last batch) in Orion 4.0.0, to be definetively removed at some point of the future - ///{ UpdateContext, 2, { "ngsi10", "updateContext" }, badVerbPostOnly }, - ///{ QueryContext, 2, { "ngsi10", "queryContext" }, badVerbPostOnly }, - ///{ SubscribeContext, 2, { "ngsi10", "subscribeContext" }, badVerbPostOnly }, - ///{ UpdateContextSubscription, 2, { "ngsi10", "updateContextSubscription" }, badVerbPostOnly }, - ///{ UnsubscribeContext, 2, { "ngsi10", "unsubscribeContext" }, badVerbPostOnly }, - ///{ NotifyContext, 2, { "ngsi10", "notifyContext" }, badVerbPostOnly }, - // FIXME: disable NGSI9 API routes in Orion 3.8.0, to be definetively removed at some point of the future - //{ InvalidRequest, 2, { "ngsi9", "*" }, badNgsi9Request }, - /// FIXME: disable unused NGSIv1 API (last batch) in Orion 4.0.0, to be definetively removed at some point of the future - ///{ InvalidRequest, 2, { "ngsi10", "*" }, badNgsi10Request }, - { InvalidRequest, 0, { "*", "*", "*", "*", "*", "*" }, badRequest }, - { InvalidRequest, 0, { }, NULL }, - - ORION_REST_SERVICE_END -}; - - /* **************************************************************************** * @@ -635,7 +275,6 @@ void orionRestServicesInit const char* allowedOrigin, int corsMaxAge, int mhdTimeoutInSeconds, - bool disableNgsiv1, const char* httpsKey, const char* httpsCert ) @@ -643,47 +282,23 @@ void orionRestServicesInit // Use options service vector (optionsServiceV) only when CORS is enabled RestService* optionsServiceV = (strlen(allowedOrigin) > 0) ? optionsV : NULL; - if (disableNgsiv1) - { - restInit(getServiceV, - putServiceV, - postServiceV, - patchServiceV, - deleteServiceV, - optionsServiceV, - badVerbV, - ipVersion, - bindAddress, - port, - multitenant, - connectionMemory, - maxConnections, - mhdThreadPoolSize, - allowedOrigin, - corsMaxAge, - mhdTimeoutInSeconds, - httpsKey, - httpsCert); - } - else - { - restInit(getServiceVlegacy, - putServiceVlegacy, - postServiceVlegacy, - patchServiceV, - deleteServiceVlegacy, - optionsServiceV, - badVerbVlegacy, - ipVersion, - bindAddress, - port, - multitenant, - connectionMemory, - maxConnections, - mhdThreadPoolSize, - allowedOrigin, - corsMaxAge, - mhdTimeoutInSeconds, - httpsKey, - httpsCert); } + restInit(getServiceV, + putServiceV, + postServiceV, + patchServiceV, + deleteServiceV, + optionsServiceV, + badVerbV, + ipVersion, + bindAddress, + port, + multitenant, + connectionMemory, + maxConnections, + mhdThreadPoolSize, + allowedOrigin, + corsMaxAge, + mhdTimeoutInSeconds, + httpsKey, + httpsCert); } diff --git a/src/app/contextBroker/orionRestServices.h b/src/app/contextBroker/orionRestServices.h index 038ffdcbb5..2f2ff2c4cd 100644 --- a/src/app/contextBroker/orionRestServices.h +++ b/src/app/contextBroker/orionRestServices.h @@ -53,7 +53,6 @@ extern void orionRestServicesInit const char* _allowedOrigin, int _corsMaxAge, int _mhdTimeoutInSeconds, - bool _disableNgsiv1, const char* _httpsKey, const char* _httpsCert ); diff --git a/src/lib/apiTypesV2/Attribute.cpp b/src/lib/apiTypesV2/Attribute.cpp deleted file mode 100644 index a90e1b47f7..0000000000 --- a/src/lib/apiTypesV2/Attribute.cpp +++ /dev/null @@ -1,144 +0,0 @@ -/* -* -* Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Orion dev team -*/ -#include -#include - -#include "common/tag.h" -#include "common/errorMessages.h" -#include "common/RenderFormat.h" -#include "common/string.h" -#include "common/JsonHelper.h" -#include "logMsg/logMsg.h" -#include "ngsi10/QueryContextResponse.h" -#include "apiTypesV2/Attribute.h" -#include "rest/OrionError.h" - - - - -/* **************************************************************************** -* -* Attribute::toJson - -*/ -std::string Attribute::toJson -( - bool acceptedTextPlain, // in parameter (pass-through) - bool acceptedJson, // in parameter (pass-through) - MimeType outFormatSelection, // in parameter (pass-through) - MimeType* outMimeTypeP, // out parameter (pass-through) - HttpStatusCode* scP, // out parameter (pass-through) - bool keyValues, // in parameter - const std::vector& metadataFilter, // in parameter - RequestType requestType // in parameter -) -{ - if (contextAttributeP == NULL) { - LM_E(("Runtime Error (NULL contextAttributeP)")); - return ""; - } - - RenderFormat renderFormat = (keyValues == true)? NGSI_V2_KEYVALUES : NGSI_V2_NORMALIZED; - - std::string out; - - if (requestType == EntityAttributeValueRequest) - { - out = contextAttributeP->toJsonAsValue(V2, - acceptedTextPlain, - acceptedJson, - outFormatSelection, - outMimeTypeP, - scP); - } - else - { - if (renderFormat == NGSI_V2_KEYVALUES) - { - JsonObjectHelper jh; - jh.addRaw(contextAttributeP->name, contextAttributeP->toJsonValue()); - out = jh.str(); - } - else // NGSI_V2_NORMALIZED - { - out = contextAttributeP->toJson(metadataFilter); - } - } - - return out; -} - - - - -/* **************************************************************************** -* -* Attribute::fill - -* -* CAUTION -* The Query should be for an indvidual entity -* -*/ -void Attribute::fill(const QueryContextResponse& qcrs, const std::string& attrName, OrionError* oeP) -{ - if (qcrs.errorCode.code == SccContextElementNotFound) - { - oeP->fill(SccContextElementNotFound, ERROR_DESC_NOT_FOUND_ENTITY, ERROR_NOT_FOUND); - } - else if (qcrs.errorCode.code != SccOk) - { - // - // any other error distinct from Not Found - // - oeP->fill(qcrs.errorCode.code, qcrs.errorCode.details, qcrs.errorCode.reasonPhrase); - } - else if (qcrs.contextElementResponseVector.size() > 1) // qcrs.errorCode.code == SccOk - { - // - // If there are more than one entity, we return an error - // - oeP->fill(SccConflict, ERROR_DESC_TOO_MANY_ENTITIES, ERROR_TOO_MANY); - } - else - { - contextAttributeP = NULL; - // Look for the attribute by name - - ContextElementResponse* cerP = qcrs.contextElementResponseVector[0]; - - for (std::size_t i = 0; i < cerP->entity.attributeVector.size(); ++i) - { - if (cerP->entity.attributeVector[i]->name == attrName) - { - contextAttributeP = cerP->entity.attributeVector[i]; - break; - } - } - - if (contextAttributeP == NULL) - { - oeP->fill(SccContextElementNotFound, ERROR_DESC_NOT_FOUND_ATTRIBUTE, ERROR_NOT_FOUND); - } - } -} diff --git a/src/lib/apiTypesV2/Attribute.h b/src/lib/apiTypesV2/Attribute.h deleted file mode 100644 index 4242f5cbae..0000000000 --- a/src/lib/apiTypesV2/Attribute.h +++ /dev/null @@ -1,69 +0,0 @@ -#ifndef SRC_LIB_APITYPESV2_ATTRIBUTE_H_ -#define SRC_LIB_APITYPESV2_ATTRIBUTE_H_ - -/* -* -* Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Orion dev team -*/ -#include -#include -#include - -#include "ngsi/ContextAttributeVector.h" -#include "ngsi/ContextAttribute.h" -#include "rest/OrionError.h" - - - -/* **************************************************************************** -* -* To avoid a problematic and not necessary include -*/ -struct QueryContextResponse; - - - -/* **************************************************************************** -* -* Attribute - -*/ -class Attribute -{ - public: - ContextAttribute* contextAttributeP; // Mandatory - - Attribute(): contextAttributeP(0) {} - - std::string toJson(bool acceptedTextPlain, - bool acceptedJson, - MimeType outFormatSelection, - MimeType* outMimeTypeP, - HttpStatusCode* scP, - bool keyValues, - const std::vector& metadataFilter, - RequestType requestType); - - void fill(const QueryContextResponse& qcrs, const std::string& attrName, OrionError* oeP); -}; - -#endif // SRC_LIB_APITYPESV2_ATTRIBUTE_H_ diff --git a/src/lib/apiTypesV2/BatchQuery.h b/src/lib/apiTypesV2/BatchQuery.h index 48a3b5df64..74ca63a318 100644 --- a/src/lib/apiTypesV2/BatchQuery.h +++ b/src/lib/apiTypesV2/BatchQuery.h @@ -31,7 +31,8 @@ #include "ngsi/StringList.h" #include "ngsi/Request.h" #include "ngsi/ScopeVector.h" -#include "apiTypesV2/Entities.h" + +#include "apiTypesV2/EntityVector.h" @@ -42,7 +43,7 @@ class BatchQuery { public: - Entities entities; + EntityVector entities; StringList attributeV; // Deprecated StringList attrsV; ScopeVector scopeV; diff --git a/src/lib/apiTypesV2/BatchUpdate.h b/src/lib/apiTypesV2/BatchUpdate.h index 2d2282d6d0..26215d23a4 100644 --- a/src/lib/apiTypesV2/BatchUpdate.h +++ b/src/lib/apiTypesV2/BatchUpdate.h @@ -30,7 +30,8 @@ #include "orionTypes/UpdateActionType.h" #include "ngsi/Request.h" -#include "apiTypesV2/Entities.h" + +#include "apiTypesV2/EntityVector.h" @@ -42,7 +43,7 @@ class BatchUpdate { public: ActionType updateActionType; // Mandatory - Entities entities; // Mandatory + EntityVector entities; // Mandatory BatchUpdate(); ~BatchUpdate(); diff --git a/src/lib/apiTypesV2/CMakeLists.txt b/src/lib/apiTypesV2/CMakeLists.txt index 18be8b1975..33f68bc7d5 100644 --- a/src/lib/apiTypesV2/CMakeLists.txt +++ b/src/lib/apiTypesV2/CMakeLists.txt @@ -23,11 +23,8 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.0) SET (SOURCES Entity.cpp EntityVector.cpp - Entities.cpp - Attribute.cpp Subscription.cpp Registration.cpp - EntID.cpp BatchQuery.cpp BatchUpdate.cpp HttpInfo.cpp @@ -37,11 +34,8 @@ SET (SOURCES SET (HEADERS Entity.h EntityVector.h - Entities.h - Attribute.h Subscription.h Registration.h - EntID.h BatchQuery.h BatchUpdate.h CustomPayloadType.h diff --git a/src/lib/apiTypesV2/EntID.cpp b/src/lib/apiTypesV2/EntID.cpp deleted file mode 100644 index 9968585ab0..0000000000 --- a/src/lib/apiTypesV2/EntID.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/* -* -* Copyright 2017 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Fermín Galán Márquez -*/ - -#include - -#include "apiTypesV2/EntID.h" - -#include "common/JsonHelper.h" - -namespace ngsiv2 -{ -/* **************************************************************************** -* -* EntID::toJson - -*/ -std::string EntID::toJson() -{ - JsonObjectHelper jh; - - if (!this->id.empty()) - { - jh.addString("id", this->id); - } - - if (!this->idPattern.empty()) - { - jh.addString("idPattern", this->idPattern); - } - - if (!this->type.empty()) - { - jh.addString("type", this->type); - } - - if (!this->typePattern.empty()) - { - jh.addString("typePattern", this->typePattern); - } - - return jh.str(); -} -} diff --git a/src/lib/apiTypesV2/EntID.h b/src/lib/apiTypesV2/EntID.h deleted file mode 100644 index d47444f5b1..0000000000 --- a/src/lib/apiTypesV2/EntID.h +++ /dev/null @@ -1,74 +0,0 @@ -#ifndef SRC_LIB_APITYPESV2_ENTID_H_ -#define SRC_LIB_APITYPESV2_ENTID_H_ - -/* -* -* Copyright 2017 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Fermín Galán Márquez -*/ -#include - - -namespace ngsiv2 -{ -/* **************************************************************************** -* -* EntID - -*/ -struct EntID -{ - std::string id; - std::string idPattern; - std::string type; - std::string typePattern; - std::string toJson(); - - EntID(const std::string& idA, const std::string& idPatternA, - const std::string& typeA, const std::string& typePatternA): - id(idA), - idPattern(idPatternA), - type(typeA), - typePattern(typePatternA) - {} - - EntID() {} - - bool operator==(const EntID& e) - { - return (id == e.id) && - (idPattern == e.idPattern) && - (type == e.type) && - (typePattern == e.typePattern); - } - - bool operator!=(const EntID& e) - { - return (id != e.id) || - (idPattern != e.idPattern) || - (type != e.type) || - (typePattern != e.typePattern); - } -}; - -} // end namespace - -#endif // SRC_LIB_APITYPESV2_ENTID_H_ diff --git a/src/lib/apiTypesV2/Entities.cpp b/src/lib/apiTypesV2/Entities.cpp deleted file mode 100644 index d8c08d6d4f..0000000000 --- a/src/lib/apiTypesV2/Entities.cpp +++ /dev/null @@ -1,162 +0,0 @@ -/* -* -* Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include -#include - -#include "logMsg/traceLevels.h" -#include "logMsg/logMsg.h" -#include "ngsi10/QueryContextResponse.h" -#include "apiTypesV2/Entities.h" - - - -/* **************************************************************************** -* -* Entities::Entities - -*/ -Entities::Entities() -{ -} - - - -/* **************************************************************************** -* -* Entities::~Entities - -*/ -Entities::~Entities() -{ - release(); -} - - - -/* **************************************************************************** -* -* Entities::toJson - -* -*/ -std::string Entities::toJson -( - RenderFormat renderFormat, - const std::vector& attrsFilter, - bool blacklist, - const std::vector& metadataFilter -) -{ - return vec.toJson(renderFormat, attrsFilter, blacklist, metadataFilter); -} - - - -/* **************************************************************************** -* -* Entities::check - -* -* NOTE -* The 'check' method is normally only used to check that incoming payload is correct. -* For now (at least), the Entities type is only used as outgoing payload ... -*/ -std::string Entities::check(RequestType requestType) -{ - return vec.check(V2, requestType); -} - - - -/* **************************************************************************** -* -* Entities::release - -*/ -void Entities::release(void) -{ - vec.release(); -} - - - -/* **************************************************************************** -* -* Entities::fill - -* -* NOTE -* The errorCode field from qcrsP is not used at all if errorCode::code equals SccOk. -* This means that e.g. the "Count:" in errorCode::details (from v1 logic) will not be -* present in the Entities for v2 (that number is in the HTTP header Fiware-Total-Count for v2). -* Other values for "details" are lost as well, if errorCode::code equals SccOk. -*/ -void Entities::fill(const QueryContextResponse& qcrs, OrionError* oeP) -{ - if (qcrs.errorCode.code == SccContextElementNotFound) - { - // - // If no entities are found, we respond with a 200 OK - // and an empty vector of entities ( [] ) - // - - oeP->fill(SccOk, "", "OK"); - return; - } - else if (qcrs.errorCode.code != SccOk) - { - // - // If any other error - use the error for the response - // - - oeP->fill(qcrs.errorCode.code, qcrs.errorCode.details, qcrs.errorCode.reasonPhrase); - return; - } - - for (unsigned int ix = 0; ix < qcrs.contextElementResponseVector.size(); ++ix) - { - Entity* eP = &qcrs.contextElementResponseVector[ix]->entity; - StatusCode* scP = &qcrs.contextElementResponseVector[ix]->statusCode; - - if (scP->code == SccReceiverInternalError) - { - // FIXME P4: Do we need to release the memory allocated in 'vec' before returning? I don't - // think so, as the releasing logic in the upper layer will deal with that but - // let's do anyway just in case... (we don't have a ft covering this, so valgrind suite - // cannot help here and it is better to ensure) - oeP->fill(SccReceiverInternalError, scP->details, "InternalServerError"); - vec.release(); - return; - } - else - { - Entity* newP = new Entity(); - - newP->id = eP->id; - newP->type = eP->type; - newP->isPattern = eP->isPattern; - newP->creDate = eP->creDate; - newP->modDate = eP->modDate; - - newP->attributeVector.fill(eP->attributeVector); - vec.push_back(newP); - } - } -} diff --git a/src/lib/apiTypesV2/Entities.h b/src/lib/apiTypesV2/Entities.h deleted file mode 100644 index 991a005d37..0000000000 --- a/src/lib/apiTypesV2/Entities.h +++ /dev/null @@ -1,68 +0,0 @@ -#ifndef SRC_LIB_APITYPESV2_ENTITIES_H_ -#define SRC_LIB_APITYPESV2_ENTITIES_H_ - -/* -* -* Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include -#include - -#include "apiTypesV2/EntityVector.h" -#include "rest/OrionError.h" - - - -/* **************************************************************************** -* -* To avoid a problematic and not necessary include -*/ -struct QueryContextResponse; - - - -/* **************************************************************************** -* -* Entities - -*/ -class Entities -{ - public: - EntityVector vec; // Mandatory - - Entities(); - ~Entities(); - - std::string toJson(RenderFormat renderFormat, - const std::vector& attrsFilter, - bool blacklist, - const std::vector& metadataFilter); - - std::string check(RequestType requestType); - void release(void); - void fill(const QueryContextResponse& qcrs, OrionError* oeP); - int size(void) const { return vec.vec.size(); } -}; - -#endif // SRC_LIB_APITYPESV2_ENTITIES_H_ diff --git a/src/lib/apiTypesV2/Entity.cpp b/src/lib/apiTypesV2/Entity.cpp index f51cbd6b35..5516bb0173 100644 --- a/src/lib/apiTypesV2/Entity.cpp +++ b/src/lib/apiTypesV2/Entity.cpp @@ -28,7 +28,6 @@ #include "logMsg/traceLevels.h" #include "logMsg/logMsg.h" -#include "common/tag.h" #include "common/string.h" #include "common/globals.h" #include "common/JsonHelper.h" @@ -49,10 +48,8 @@ * * Entity::Entity - */ -Entity::Entity(): isTypePattern(false), typeGiven(false), renderId(true), creDate(0), modDate(0) +Entity::Entity(): typeGiven(false), renderId(true), creDate(0), modDate(0) { - creDate = 0; - modDate = 0; } @@ -63,46 +60,16 @@ Entity::Entity(): isTypePattern(false), typeGiven(false), renderId(true), creDat * * This constructor was ported from old ContextElement class */ -Entity::Entity(const std::string& _id, const std::string& _type, const std::string& _isPattern, bool _isTypePattern) +Entity::Entity(const std::string& _id, const std::string& _idPattern, const std::string& _type, const std::string& _typePattern) { - id = _id; - type = _type; - isPattern = _isPattern; - isTypePattern = _isTypePattern; - creDate = 0; - modDate = 0; -} - - - -/* **************************************************************************** -* -* Entity::Entity - -* -* This constructor was ported from old ContextElement class -*/ -Entity::Entity(EntityId* eP) -{ - id = eP->id; - type = eP->type; - isPattern = eP->isPattern; - isTypePattern = eP->isTypePattern; - servicePath = eP->servicePath; - creDate = eP->creDate; - modDate = eP->modDate; -} - - - -/* **************************************************************************** -* -* Entity::Entity - -* -* This constructor was ported from old ContextElement class -*/ -Entity::Entity(Entity* eP) -{ - fill(*eP); + entityId.id = _id; + entityId.idPattern = _idPattern; + entityId.type = _type; + entityId.typePattern = _typePattern; + typeGiven = false; + renderId = true; + creDate = 0; + modDate = 0; } @@ -227,67 +194,6 @@ void Entity::filterAndOrderAttrs - -/* **************************************************************************** -* -* Entity::toJsonV1 - -* -* This method was ported from old ContextElement class. It was name render() there -* -*/ -std::string Entity::toJsonV1 -( - bool asJsonObject, - RequestType requestType, - const std::vector& attrsFilter, - bool blacklist, - const std::vector& metadataFilter, - bool comma, - bool omitAttributeValues -) -{ - std::string out = ""; - bool contextAttributeVectorRendered = attributeVector.size() != 0; - - out += startTag(requestType != UpdateContext? "contextElement" : ""); - - // Filter and order attributes - std::vector orderedAttrs; - filterAndOrderAttrs(attrsFilter, blacklist, &orderedAttrs); - - EntityId en(id, type, isPattern); - out += en.toJsonV1(contextAttributeVectorRendered, false); - out += attributeVector.toJsonV1(asJsonObject, requestType, orderedAttrs, metadataFilter, false, omitAttributeValues); - - out += endTag(comma, false); - - return out; -} - - - -/* **************************************************************************** -* -* Entity::toJsonV1 - -* -* Wrapper of toJsonV1 with empty attrsFilter and metadataFilter -* -*/ -std::string Entity::toJsonV1 -( - bool asJsonObject, - RequestType requestType, - bool blacklist, - bool comma, - bool omitAttributeValues -) -{ - std::vector emptyV; - return toJsonV1(asJsonObject, requestType, emptyV, blacklist, emptyV, comma, omitAttributeValues); -} - - - /* **************************************************************************** * * Entity::toJson - @@ -415,10 +321,10 @@ std::string Entity::toJsonKeyvalues(const std::vector& ordere if (renderId) { - jh.addString("id", id); + jh.addString("id", entityId.id); /* This is needed for entities coming from NGSIv1 (which allows empty or missing types) */ - jh.addString("type", (!type.empty())? type : DEFAULT_ENTITY_TYPE); + jh.addString("type", (!entityId.type.empty())? entityId.type : DEFAULT_ENTITY_TYPE); } for (unsigned int ix = 0; ix < orderedAttrs.size(); ix++) @@ -455,21 +361,21 @@ std::string Entity::toJsonNormalized { /* In ngsi field in notifications "" is allowed for id and type, in which case we don't * print the field */ - if (!id.empty()) + if (!entityId.id.empty()) { - jh.addString("id", id); + jh.addString("id", entityId.id); } - if (!type.empty()) + if (!entityId.type.empty()) { - jh.addString("type", type); + jh.addString("type", entityId.type); } } else { - jh.addString("id", id); + jh.addString("id", entityId.id); /* This is needed for entities coming from NGSIv1 (which allows empty or missing types) */ - jh.addString("type", (!type.empty())? type : DEFAULT_ENTITY_TYPE); + jh.addString("type", (!entityId.type.empty())? entityId.type : DEFAULT_ENTITY_TYPE); } } @@ -488,19 +394,34 @@ std::string Entity::toJsonNormalized * * toString - * -* FIXME P3: Copied from EntityId class */ -std::string Entity::toString(bool useIsPattern, const std::string& delimiter) +std::string Entity::toString(void) { std::string s; - s = id + delimiter + type; + std::string effectiveId; + std::string effectiveType; - if (useIsPattern) + if (entityId.idPattern.empty()) + { + effectiveId = entityId.id; + } + else { - s += delimiter + isPattern; + effectiveId = entityId.idPattern; } + if (entityId.typePattern.empty()) + { + effectiveType = entityId.type; + } + else + { + effectiveType = entityId.typePattern; + } + + return effectiveId + ", " + effectiveType; + return s; } @@ -508,118 +429,203 @@ std::string Entity::toString(bool useIsPattern, const std::string& delimiter) /* **************************************************************************** * -* ContextElement::check -* -* This V1 "branch" of this method has been ported from old ContextElement class +* ContextElement::checkId * */ -std::string Entity::check(ApiVersion apiVersion, RequestType requestType) +std::string Entity::checkId(RequestType requestType) { - if (apiVersion == V1) + ssize_t len; + char errorMsg[128]; + + if (((len = strlen(entityId.id.c_str())) < MIN_ID_LEN) && (requestType != EntityRequest)) { - std::string res; + snprintf(errorMsg, sizeof errorMsg, "entity id length: %zd, min length supported: %d", len, MIN_ID_LEN); + alarmMgr.badInput(clientIp, errorMsg); + return std::string(errorMsg); + } - if (id.empty()) - { - return "empty entityId:id"; - } + if ((len = strlen(entityId.id.c_str())) > MAX_ID_LEN) + { + snprintf(errorMsg, sizeof errorMsg, "entity id length: %zd, max length supported: %d", len, MAX_ID_LEN); + alarmMgr.badInput(clientIp, errorMsg); + return std::string(errorMsg); + } - if (!isTrue(isPattern) && !isFalse(isPattern) && !isPattern.empty()) - { - return std::string("invalid isPattern value for entity: /") + isPattern + "/"; - } + // Check for forbidden chars for "id", but not for "idPattern" is a pattern + if (forbiddenIdCharsV2(entityId.id.c_str())) + { + alarmMgr.badInput(clientIp, ERROR_DESC_BAD_REQUEST_INVALID_CHAR_ENTID, entityId.id); + return ERROR_DESC_BAD_REQUEST_INVALID_CHAR_ENTID; + } - if ((requestType == RegisterContext) && (isTrue(isPattern))) - { - return "isPattern set to true for registrations is currently not supported"; - } + return "OK"; +} - if (isTrue(isPattern)) - { - regex_t re; - if ((id.find('\0') != std::string::npos) || (!regComp(&re, id.c_str(), REG_EXTENDED))) - { - return "invalid regex for entity id pattern"; - } - regfree(&re); // If regcomp fails it frees up itself (see glibc sources for details) - } + + +/* **************************************************************************** +* +* ContextElement::checkIdPattern +* +*/ +std::string Entity::checkIdPattern(RequestType requestType) +{ + ssize_t len; + char errorMsg[128]; + + if (((len = strlen(entityId.idPattern.c_str())) < MIN_ID_LEN) && (requestType != EntityRequest)) + { + snprintf(errorMsg, sizeof errorMsg, "entity idPattern length: %zd, min length supported: %d", len, MIN_ID_LEN); + alarmMgr.badInput(clientIp, errorMsg); + return std::string(errorMsg); } - else // V2 + + if ((len = strlen(entityId.idPattern.c_str())) > MAX_ID_LEN) + { + snprintf(errorMsg, sizeof errorMsg, "entity idPattern length: %zd, max length supported: %d", len, MAX_ID_LEN); + alarmMgr.badInput(clientIp, errorMsg); + return std::string(errorMsg); + } + + return "OK"; +} + + + +/* **************************************************************************** +* +* ContextElement::checkType +* +*/ +std::string Entity::checkType(RequestType requestType) +{ + ssize_t len; + char errorMsg[128]; + + if ((len = strlen(entityId.type.c_str())) > MAX_ID_LEN) { - ssize_t len; - char errorMsg[128]; + snprintf(errorMsg, sizeof errorMsg, "entity type length: %zd, max length supported: %d", len, MAX_ID_LEN); + alarmMgr.badInput(clientIp, errorMsg); + return std::string(errorMsg); + } - if (((len = strlen(id.c_str())) < MIN_ID_LEN) && (requestType != EntityRequest)) + if (!((requestType == BatchQueryRequest) || (requestType == BatchUpdateRequest && !typeGiven))) + { + if ((len = strlen(entityId.type.c_str())) < MIN_ID_LEN) { - snprintf(errorMsg, sizeof errorMsg, "entity id length: %zd, min length supported: %d", len, MIN_ID_LEN); + snprintf(errorMsg, sizeof errorMsg, "entity type length: %zd, min length supported: %d", len, MIN_ID_LEN); alarmMgr.badInput(clientIp, errorMsg); return std::string(errorMsg); } + } - if ((requestType == EntitiesRequest) && (id.empty())) - { - return "No Entity ID"; - } + // Check for forbidden chars for "type", but not for "typePattern" + if (forbiddenIdCharsV2(entityId.type.c_str())) + { + alarmMgr.badInput(clientIp, ERROR_DESC_BAD_REQUEST_INVALID_CHAR_ENTTYPE, entityId.type); + return ERROR_DESC_BAD_REQUEST_INVALID_CHAR_ENTTYPE; + } + + return "OK"; +} + + + +/* **************************************************************************** +* +* ContextElement::checkTypePattern +* +*/ +std::string Entity::checkTypePattern(RequestType requestType) +{ + ssize_t len; + char errorMsg[128]; - if ( (len = strlen(id.c_str())) > MAX_ID_LEN) + if ((len = strlen(entityId.typePattern.c_str())) > MAX_ID_LEN) + { + snprintf(errorMsg, sizeof errorMsg, "entity typePattern length: %zd, max length supported: %d", len, MAX_ID_LEN); + alarmMgr.badInput(clientIp, errorMsg); + return std::string(errorMsg); + } + + if (!((requestType == BatchQueryRequest) || (requestType == BatchUpdateRequest && !typeGiven))) + { + if ((len = strlen(entityId.typePattern.c_str())) < MIN_ID_LEN) { - snprintf(errorMsg, sizeof errorMsg, "entity id length: %zd, max length supported: %d", len, MAX_ID_LEN); + snprintf(errorMsg, sizeof errorMsg, "entity typePattern length: %zd, min length supported: %d", len, MIN_ID_LEN); alarmMgr.badInput(clientIp, errorMsg); return std::string(errorMsg); } + } - if (isPattern.empty()) - { - isPattern = "false"; - } + return "OK"; +} - // isPattern MUST be either "true" or "false" (or empty => "false") - if ((isPattern != "true") && (isPattern != "false")) - { - alarmMgr.badInput(clientIp, "invalid value for isPattern", isPattern); - return "Invalid value for isPattern"; - } - // Check for forbidden chars for "id", but not if "id" is a pattern - if (isPattern == "false") + +/* **************************************************************************** +* +* ContextElement::check +* +*/ +std::string Entity::check(RequestType requestType) +{ + std::string err; + char errorMsg[128]; + + // In EntityRequest the entity id comes in the URL so Entity is allowed to have empty id and idPattern + if ((requestType != EntityRequest) && (entityId.id.empty()) && (entityId.idPattern.empty())) + { + snprintf(errorMsg, sizeof errorMsg, "id and idPattern cannot be both empty at the same time"); + alarmMgr.badInput(clientIp, errorMsg); + return std::string(errorMsg); + } + + if ((!entityId.id.empty()) && (!entityId.idPattern.empty())) + { + snprintf(errorMsg, sizeof errorMsg, "id and idPattern cannot be both filled at the same time"); + alarmMgr.badInput(clientIp, errorMsg); + return std::string(errorMsg); + } + + if ((!entityId.id.empty()) && ((err = checkId(requestType)) != "OK")) + { + return err; + } + if ((!entityId.idPattern.empty()) && ((err = checkIdPattern(requestType)) != "OK")) + { + return err; + } + + // typeGiven enables some additional checkings for type and typePattern + if (typeGiven) + { + if ((entityId.type.empty()) && (entityId.typePattern.empty())) { - if (forbiddenIdChars(V2, id.c_str())) - { - alarmMgr.badInput(clientIp, ERROR_DESC_BAD_REQUEST_INVALID_CHAR_ENTID, id); - return ERROR_DESC_BAD_REQUEST_INVALID_CHAR_ENTID; - } + snprintf(errorMsg, sizeof errorMsg, "type and typePattern cannot be both empty at the same time"); + alarmMgr.badInput(clientIp, errorMsg); + return std::string(errorMsg); } - if ( (len = strlen(type.c_str())) > MAX_ID_LEN) + if ((!entityId.type.empty()) && (!entityId.typePattern.empty())) { - snprintf(errorMsg, sizeof errorMsg, "entity type length: %zd, max length supported: %d", len, MAX_ID_LEN); + snprintf(errorMsg, sizeof errorMsg, "type and typePattern cannot be both filled at the same time"); alarmMgr.badInput(clientIp, errorMsg); return std::string(errorMsg); } - if (!((requestType == BatchQueryRequest) || (requestType == BatchUpdateRequest && !typeGiven))) + if ((!entityId.type.empty()) && ((err = checkType(requestType)) != "OK")) { - if ( (len = strlen(type.c_str())) < MIN_ID_LEN) - { - snprintf(errorMsg, sizeof errorMsg, "entity type length: %zd, min length supported: %d", len, MIN_ID_LEN); - alarmMgr.badInput(clientIp, errorMsg); - return std::string(errorMsg); - } + return err; } - // Check for forbidden chars for "type", but not if "type" is a pattern - if (isTypePattern == false) + if ((!entityId.typePattern.empty()) && ((err = checkTypePattern(requestType)) != "OK")) { - if (forbiddenIdChars(V2, type.c_str())) - { - alarmMgr.badInput(clientIp, ERROR_DESC_BAD_REQUEST_INVALID_CHAR_ENTTYPE, type); - return ERROR_DESC_BAD_REQUEST_INVALID_CHAR_ENTTYPE; - } + return err; } } - // Common part (V1 and V2) - return attributeVector.check(apiVersion, requestType); + return attributeVector.check(requestType); } @@ -629,17 +635,13 @@ std::string Entity::check(ApiVersion apiVersion, RequestType requestType) */ void Entity::fill ( - const std::string& _id, - const std::string& _type, - const std::string& _isPattern, + const EntityId& _entityId, const ContextAttributeVector& caV, double _creDate, double _modDate ) { - id = _id; - type = _type; - isPattern = _isPattern; + entityId = _entityId; creDate = _creDate; modDate = _modDate; @@ -655,17 +657,13 @@ void Entity::fill */ void Entity::fill ( - const std::string& _id, - const std::string& _type, - const std::string& _isPattern, + const EntityId& _entityId, const std::string& _servicePath, double _creDate, double _modDate ) { - id = _id; - type = _type; - isPattern = _isPattern; + entityId = _entityId; servicePath = _servicePath; @@ -679,16 +677,9 @@ void Entity::fill * * Entity::fill - */ -void Entity::fill -( - const std::string& _id, - const std::string& _type, - const std::string& _isPattern -) +void Entity::fill(const EntityId& _entityId) { - id = _id; - type = _type; - isPattern = _isPattern; + entityId = _entityId; } @@ -701,22 +692,20 @@ void Entity::fill */ void Entity::fill(const Entity& en, bool useDefaultType, bool cloneCompounds) { - id = en.id; - type = en.type; - isPattern = en.isPattern; - isTypePattern = en.isTypePattern; + entityId = en.entityId; servicePath = en.servicePath; creDate = en.creDate; modDate = en.modDate; - if (useDefaultType && (type.empty())) + if (useDefaultType && (entityId.type.empty())) { - type = DEFAULT_ENTITY_TYPE; + entityId.type = DEFAULT_ENTITY_TYPE; } attributeVector.fill(en.attributeVector, useDefaultType, cloneCompounds); - providingApplicationList = en.providingApplicationList; + providerList = en.providerList; + providerRegIdList = en.providerRegIdList; } @@ -729,18 +718,18 @@ void Entity::fill(const QueryContextResponse& qcrs, OrionError* oeP) { Entity* eP = NULL; - if (qcrs.errorCode.code == SccContextElementNotFound) + if (qcrs.error.code == SccContextElementNotFound) { oeP->fill(SccContextElementNotFound, ERROR_DESC_NOT_FOUND_ENTITY, ERROR_NOT_FOUND); } - else if (qcrs.errorCode.code != SccOk) + else if (qcrs.error.code != SccOk) { // // any other error distinct from Not Found // - oeP->fill(qcrs.errorCode.code, qcrs.errorCode.details, qcrs.errorCode.reasonPhrase); + oeP->fill(qcrs.error.code, qcrs.error.description, qcrs.error.error); } - else // qcrs.errorCode.code == SccOk + else // qcrs.error.code == SccOk { // // If there are more than one entity (ignoring SccContextElementNotFound cases), we return an error @@ -748,7 +737,7 @@ void Entity::fill(const QueryContextResponse& qcrs, OrionError* oeP) // for (unsigned int ix = 0; ix < qcrs.contextElementResponseVector.size(); ++ix) { - if (qcrs.contextElementResponseVector[ix]->statusCode.code != SccContextElementNotFound) + if (qcrs.contextElementResponseVector[ix]->error.code != SccContextElementNotFound) { if (eP != NULL) { @@ -762,9 +751,7 @@ void Entity::fill(const QueryContextResponse& qcrs, OrionError* oeP) } } - fill(eP->id, - eP->type, - eP->isPattern, + fill(eP->entityId, eP->attributeVector, eP->creDate, eP->modDate); @@ -839,8 +826,5 @@ ContextAttribute* Entity::getAttribute(const std::string& attrName) */ bool Entity::equal(Entity* eP) { - return ((eP->id == id) && - (eP->type == type) && - (isTrue(eP->isPattern) == isTrue(isPattern)) && - (eP->isTypePattern == isTypePattern)); + return entityId == eP->entityId; } diff --git a/src/lib/apiTypesV2/Entity.h b/src/lib/apiTypesV2/Entity.h index 9d534d52ed..838676fab8 100644 --- a/src/lib/apiTypesV2/Entity.h +++ b/src/lib/apiTypesV2/Entity.h @@ -51,10 +51,7 @@ struct QueryContextResponse; class Entity { public: - std::string id; // Mandatory - std::string type; // Optional - std::string isPattern; // Optional - bool isTypePattern; + EntityId entityId; // Mandatory ContextAttributeVector attributeVector; // Optional std::string servicePath; // Not part of payload, just an internal field @@ -64,29 +61,14 @@ class Entity double creDate; // used by dateCreated functionality in NGSIv2 double modDate; // used by dateModified functionality in NGSIv2 - std::vector providingApplicationList; // Not part of NGSI, used internally for CPr forwarding functionality + std::vector providerList; // Used internally for CPr forwarding functionality + std::vector providerRegIdList; // Side vector to providerList, to hold the reg ids where they come (used for login purposes) Entity(); - Entity(const std::string& id, const std::string& type, const std::string& isPattern, bool isTypePattern = false); - explicit Entity(EntityId* eP); - explicit Entity(Entity* eP); + Entity(const std::string& id, const std::string& idPattern, const std::string& type, const std::string& typePattern); ~Entity(); - std::string toJsonV1(bool asJsonObject, - RequestType requestType, - const std::vector& attrsFilter, - bool blacklist, - const std::vector& metadataFilter, - bool comma, - bool omitAttributeValues = false); - - std::string toJsonV1(bool asJsonObject, - RequestType requestType, - bool blacklist, - bool comma, - bool omitAttributeValues = false); - std::string toJson(RenderFormat renderFormat, const std::vector& attrsFilter, bool blacklist, @@ -97,31 +79,25 @@ class Entity std::string toJson(RenderFormat renderFormat, bool renderNgsiField = false); - std::string toString(bool useIsPattern = false, const std::string& delimiter = ", "); + std::string toString(void); - std::string check(ApiVersion apiVersion, RequestType requestType); + std::string check(RequestType requestType); void applyUpdateOperators(void); void release(void); - void fill(const std::string& id, - const std::string& type, - const std::string& isPattern, + void fill(const EntityId& entId, const ContextAttributeVector& caV, double creDate, double modDate); - void fill(const std::string& id, - const std::string& type, - const std::string& isPattern, + void fill(const EntityId& entId, const std::string& servicePath, double creDate = 0, double modDate = 0); - void fill(const std::string& id, - const std::string& type, - const std::string& isPattern); + void fill(const EntityId& entId); void fill(const Entity& en, bool useDefaultType = false, bool cloneCompounds = false); @@ -147,6 +123,11 @@ class Entity const std::vector& metadataFilter, bool renderNgsiField = false, ExprContextObject* exprContextObject = NULL); + + std::string checkId(RequestType requestType); + std::string checkIdPattern(RequestType requestType); + std::string checkType(RequestType requestType); + std::string checkTypePattern(RequestType requestType); }; #endif // SRC_LIB_APITYPESV2_ENTITY_H_ diff --git a/src/lib/apiTypesV2/EntityVector.cpp b/src/lib/apiTypesV2/EntityVector.cpp index 4cf87b08b0..eb3e8a1504 100644 --- a/src/lib/apiTypesV2/EntityVector.cpp +++ b/src/lib/apiTypesV2/EntityVector.cpp @@ -32,7 +32,6 @@ #include "logMsg/traceLevels.h" #include "common/globals.h" -#include "common/tag.h" #include "common/JsonHelper.h" #include "alarmMgr/alarmMgr.h" @@ -96,73 +95,6 @@ std::string EntityVector::toJson(RenderFormat renderFormat) -/* **************************************************************************** -* -* EntityVector::toJsonV1 - -* -* Ported from old class ContextElementVector -*/ -std::string EntityVector::toJsonV1 -( - bool asJsonObject, - RequestType requestType, - bool comma -) -{ - std::string out = ""; - - if (vec.size() == 0) - { - return ""; - } - - out += startTag("contextElements", true); - - for (unsigned int ix = 0; ix < vec.size(); ++ix) - { - out += vec[ix]->toJsonV1(asJsonObject, requestType, false, ix != vec.size() - 1); - } - - out += endTag(comma, true); - - return out; -} - - - -/* **************************************************************************** -* -* EntityVector::check - -*/ -std::string EntityVector::check(ApiVersion apiVersion, RequestType requestType) -{ - if ((apiVersion == V1) && (requestType == UpdateContext)) - { - if (vec.size() == 0) - { - return "No context elements"; - } - } - - for (unsigned int ix = 0; ix < vec.size(); ++ix) - { - std::string res; - - if ((res = vec[ix]->check(apiVersion, requestType)) != "OK") - { - if (apiVersion == V2) - { - alarmMgr.badInput(clientIp, "invalid vector of Entity", res); - } - return res; - } - } - - return "OK"; -} - - - /* **************************************************************************** * * EntityVector::push_back - @@ -209,7 +141,7 @@ Entity* EntityVector::lookup(const std::string& name, const std::string& type) { for (unsigned int ix = 0; ix < vec.size(); ++ix) { - if ((vec[ix]->id == name) && (vec[ix]->type == type)) + if ((vec[ix]->entityId.id == name) && (vec[ix]->entityId.type == type)) { return vec[ix]; } diff --git a/src/lib/apiTypesV2/EntityVector.h b/src/lib/apiTypesV2/EntityVector.h index 6714e67ab8..5ea59cb3b6 100644 --- a/src/lib/apiTypesV2/EntityVector.h +++ b/src/lib/apiTypesV2/EntityVector.h @@ -48,9 +48,6 @@ typedef struct EntityVector std::string toJson(RenderFormat renderFormat); - std::string toJsonV1(bool asJsonObject, RequestType requestType, bool comma); - - std::string check(ApiVersion apiVersion, RequestType requestType); void push_back(Entity* item); unsigned int size(void); Entity* lookup(const std::string& name, const std::string& type); diff --git a/src/lib/apiTypesV2/HttpInfo.cpp b/src/lib/apiTypesV2/HttpInfo.cpp index d4eb24114c..c5b473991c 100644 --- a/src/lib/apiTypesV2/HttpInfo.cpp +++ b/src/lib/apiTypesV2/HttpInfo.cpp @@ -193,11 +193,11 @@ void HttpInfo::fill(const orion::BSONObj& bo) orion::BSONObj ngsiObj = getObjectFieldF(bo, CSUB_NGSI); if (ngsiObj.hasField(ENT_ENTITY_ID)) { - this->ngsi.id = getStringFieldF(ngsiObj, ENT_ENTITY_ID); + this->ngsi.entityId.id = getStringFieldF(ngsiObj, ENT_ENTITY_ID); } if (ngsiObj.hasField(ENT_ENTITY_TYPE)) { - this->ngsi.type = getStringFieldF(ngsiObj, ENT_ENTITY_TYPE); + this->ngsi.entityId.type = getStringFieldF(ngsiObj, ENT_ENTITY_TYPE); } if (ngsiObj.hasField(ENT_ATTRS)) { diff --git a/src/lib/apiTypesV2/MqttInfo.cpp b/src/lib/apiTypesV2/MqttInfo.cpp index e604f21e1a..895e363779 100644 --- a/src/lib/apiTypesV2/MqttInfo.cpp +++ b/src/lib/apiTypesV2/MqttInfo.cpp @@ -47,16 +47,6 @@ MqttInfo::MqttInfo() : qos(0), custom(false), json(NULL), payloadType(Text), inc -/* **************************************************************************** -* -* MqttInfo::MqttInfo - -*/ -MqttInfo::MqttInfo(const std::string& _url) : url(_url), qos(0), custom(false), json(NULL), payloadType(Text), includePayload(true), providedAuth(false) -{ -} - - - /* **************************************************************************** * * MqttInfo::toJson - @@ -205,11 +195,11 @@ void MqttInfo::fill(const orion::BSONObj& bo) orion::BSONObj ngsiObj = getObjectFieldF(bo, CSUB_NGSI); if (ngsiObj.hasField(ENT_ENTITY_ID)) { - this->ngsi.id = getStringFieldF(ngsiObj, ENT_ENTITY_ID); + this->ngsi.entityId.id = getStringFieldF(ngsiObj, ENT_ENTITY_ID); } if (ngsiObj.hasField(ENT_ENTITY_TYPE)) { - this->ngsi.type = getStringFieldF(ngsiObj, ENT_ENTITY_TYPE); + this->ngsi.entityId.type = getStringFieldF(ngsiObj, ENT_ENTITY_TYPE); } if (ngsiObj.hasField(ENT_ATTRS)) { diff --git a/src/lib/apiTypesV2/MqttInfo.h b/src/lib/apiTypesV2/MqttInfo.h index 738e73c6a9..13da4a43e3 100644 --- a/src/lib/apiTypesV2/MqttInfo.h +++ b/src/lib/apiTypesV2/MqttInfo.h @@ -58,7 +58,6 @@ struct MqttInfo std::string passwd; MqttInfo(); - explicit MqttInfo(const std::string& _url); std::string toJson(); void fill(const orion::BSONObj& bo); diff --git a/src/lib/apiTypesV2/Registration.cpp b/src/lib/apiTypesV2/Registration.cpp index 284b6232e8..8ab6769c81 100644 --- a/src/lib/apiTypesV2/Registration.cpp +++ b/src/lib/apiTypesV2/Registration.cpp @@ -27,6 +27,10 @@ #include "apiTypesV2/Registration.h" #include "common/JsonHelper.h" #include "common/globals.h" +#include "common/statistics.h" +#include "logMsg/logMsg.h" +#include "mongoDriver/safeMongo.h" +#include "mongoBackend/dbConstants.h" @@ -61,6 +65,221 @@ Registration::~Registration() } +/* **************************************************************************** +* +* setRegistrationId - +*/ +void Registration::setRegistrationId(const orion::BSONObj& r) +{ + id = getFieldF(r, "_id").OID(); +} + + + +/* **************************************************************************** +* +* setDescription - +*/ +void Registration::setDescription(const orion::BSONObj& r) +{ + if (r.hasField(REG_DESCRIPTION)) + { + description = getStringFieldF(r, REG_DESCRIPTION); + descriptionProvided = true; + } + else + { + description = ""; + descriptionProvided = false; + } +} + + + +/* **************************************************************************** +* +* setProvider - +*/ +void Registration::setProvider(const ngsiv2::ForwardingMode forwardingMode, const std::string& format, const orion::BSONObj& r) +{ + provider.http.url = (r.hasField(REG_PROVIDING_APPLICATION))? getStringFieldF(r, REG_PROVIDING_APPLICATION): ""; + + provider.supportedForwardingMode = forwardingMode; + + if (format == "JSON") + { + __sync_fetch_and_add(&noOfDprLegacyForwarding, 1); + if (logDeprecate) + { + LM_W(("Deprecated usage of legacyForwarding mode detected in existing registration (regId: %s)", id.c_str())); + } + provider.legacyForwardingMode = true; + } + else + { + provider.legacyForwardingMode = false; + } +} + + + +/* **************************************************************************** +* +* setEntities - +*/ +void Registration::setEntities(const orion::BSONObj& cr0) +{ + std::vector dbEntityV = getFieldF(cr0, REG_ENTITIES).Array(); + + for (unsigned int ix = 0; ix < dbEntityV.size(); ++ix) + { + EntityId entity; + orion::BSONObj ce = dbEntityV[ix].embeddedObject(); + + if (ce.hasField(REG_ENTITY_ISPATTERN)) + { + std::string isPattern = getStringFieldF(ce, REG_ENTITY_ISPATTERN); + + if (isPattern == "true") + { + entity.idPattern = getStringFieldF(ce, REG_ENTITY_ID); + } + else + { + entity.id = getStringFieldF(ce, REG_ENTITY_ID); + } + } + else + { + entity.id = getStringFieldF(ce, REG_ENTITY_ID); + } + + if (ce.hasField(REG_ENTITY_ISTYPEPATTERN)) + { + std::string isPattern = getStringFieldF(ce, REG_ENTITY_ISTYPEPATTERN); + + if (isPattern == "true") + { + entity.typePattern = getStringFieldF(ce, REG_ENTITY_TYPE); + } + else + { + entity.type = getStringFieldF(ce, REG_ENTITY_TYPE); + } + } + else + { + entity.type = getStringFieldF(ce, REG_ENTITY_TYPE); + } + + dataProvided.entities.push_back(entity); + } +} + + + +/* **************************************************************************** +* +* setAttributes - +*/ +void Registration::setAttributes(const orion::BSONObj& cr0) +{ + std::vector dbAttributeV = getFieldF(cr0, REG_ATTRS).Array(); + + for (unsigned int ix = 0; ix < dbAttributeV.size(); ++ix) + { + orion::BSONObj aobj = dbAttributeV[ix].embeddedObject(); + std::string attrName = getStringFieldF(aobj, REG_ATTRS_NAME); + + if (!attrName.empty()) + { + dataProvided.attributes.push_back(attrName); + } + } +} + + + +/* **************************************************************************** +* +* setDataProvided - +*/ +bool Registration::setDataProvided(const orion::BSONObj& r, bool arrayAllowed) +{ + std::vector crV = getFieldF(r, REG_CONTEXT_REGISTRATION).Array(); + + // Only one element is allowed. This is a weird thing in the database model, see issue #4611 + if (crV.size() > 1) + { + return false; + } + + // Get the forwarding mode to be used later in setProvider() + ngsiv2::ForwardingMode forwardingMode = + ngsiv2::stringToForwardingMode(r.hasField(REG_FORWARDING_MODE)? getStringField(r, REG_FORWARDING_MODE) : "all"); + + // Get the format to be used later in setProvider() + std::string format = r.hasField(REG_FORMAT)? getStringFieldF(r, REG_FORMAT) : "JSON"; + + // + // Extract the first (and only) CR from the contextRegistration vector + // + orion::BSONObj cr0 = crV[0].embeddedObject(); + + setEntities(cr0); + setAttributes(cr0); + setProvider(forwardingMode, format, cr0); + + return true; +} + + + +/* **************************************************************************** +* +* setExpires - +*/ +void Registration::setExpires(const orion::BSONObj& r) +{ + expires = (r.hasField(REG_EXPIRATION))? getIntOrLongFieldAsLongF(r, REG_EXPIRATION) : -1; +} + + + +/* **************************************************************************** +* +* setStatus - +*/ +void Registration::setStatus(const orion::BSONObj& r) +{ + status = (r.hasField(REG_STATUS))? getStringFieldF(r, REG_STATUS): ""; +} + + + +/* **************************************************************************** +* +* Registration::fromBson - +*/ +bool Registration::fromBson(const orion::BSONObj& r) +{ + setRegistrationId(r); + setDescription(r); + + if (setDataProvided(r, false) == false) + { + // FIXME #4611: this check will be no longer needed after fixing the issue. setDataProvided return type (and the return type of this method) + // could be changed to void + return false; + } + + setExpires(r); + setStatus(r); + + return true; +} + + /* **************************************************************************** * diff --git a/src/lib/apiTypesV2/Registration.h b/src/lib/apiTypesV2/Registration.h index c9be132333..63d79e5428 100644 --- a/src/lib/apiTypesV2/Registration.h +++ b/src/lib/apiTypesV2/Registration.h @@ -28,7 +28,8 @@ #include #include -#include "apiTypesV2/EntID.h" +#include "ngsi/EntityId.h" +#include "mongoDriver/BSONObj.h" namespace ngsiv2 @@ -123,7 +124,7 @@ struct Provider */ struct DataProvided { - std::vector entities; + std::vector entities; std::vector attributes; std::string toJson(); @@ -149,7 +150,19 @@ struct Registration Registration(); ~Registration(); + bool fromBson(const orion::BSONObj& r); std::string toJson(); + +private: + // used by fromBson + void setRegistrationId(const orion::BSONObj& r); + void setDescription(const orion::BSONObj& r); + void setProvider(const ngsiv2::ForwardingMode forwardingMode, const std::string& format, const orion::BSONObj& r); + void setEntities(const orion::BSONObj& cr0); + void setAttributes(const orion::BSONObj& cr0); + bool setDataProvided(const orion::BSONObj& r, bool arrayAllowed); + void setExpires(const orion::BSONObj& r); + void setStatus(const orion::BSONObj& r); }; } diff --git a/src/lib/apiTypesV2/Subscription.cpp b/src/lib/apiTypesV2/Subscription.cpp index 6716848f2f..564237f480 100644 --- a/src/lib/apiTypesV2/Subscription.cpp +++ b/src/lib/apiTypesV2/Subscription.cpp @@ -116,16 +116,16 @@ namespace ngsiv2 */ Subscription::~Subscription() { - unsigned int sz = restriction.scopeVector.size(); + unsigned int sz = scopeVector.size(); if (sz > 0) { for (unsigned i = 0; i != sz; i++ ) { - restriction.scopeVector[i]->release(); - delete restriction.scopeVector[i]; + scopeVector[i]->release(); + delete scopeVector[i]; } - restriction.scopeVector.vec.clear(); + scopeVector.vec.clear(); } } @@ -157,7 +157,7 @@ std::string Subscription::toJson(void) jh.addString("status", this->status); jh.addRaw("subject", this->subject.toJson()); - jh.addRaw("notification", this->notification.toJson(renderFormatToString(this->attrsFormat, true, true))); + jh.addRaw("notification", this->notification.toJson(renderFormatToString(this->attrsFormat))); if (this->throttling > 0) { diff --git a/src/lib/apiTypesV2/Subscription.h b/src/lib/apiTypesV2/Subscription.h index 88d6660038..7ca649dde6 100644 --- a/src/lib/apiTypesV2/Subscription.h +++ b/src/lib/apiTypesV2/Subscription.h @@ -28,13 +28,11 @@ #include #include -#include "ngsi/Duration.h" -#include "ngsi/Throttling.h" -#include "apiTypesV2/EntID.h" #include "apiTypesV2/HttpInfo.h" #include "apiTypesV2/MqttInfo.h" #include "apiTypesV2/SubscriptionExpression.h" -#include "ngsi/Restriction.h" +#include "ngsi/EntityId.h" +#include "ngsi/ScopeVector.h" #include "common/RenderFormat.h" namespace ngsiv2 @@ -142,9 +140,9 @@ struct Condition */ struct Subject { - std::vector entities; - Condition condition; - std::string toJson(); + std::vector entities; + Condition condition; + std::string toJson(); }; @@ -165,7 +163,7 @@ class Subscription Notification notification; long long throttling; RenderFormat attrsFormat; - Restriction restriction; + ScopeVector scopeVector; std::string toJson(); void release(); diff --git a/src/lib/apiTypesV2/SubscriptionUpdate.h b/src/lib/apiTypesV2/SubscriptionUpdate.h index f5ac7004ba..707c4fa8d1 100644 --- a/src/lib/apiTypesV2/SubscriptionUpdate.h +++ b/src/lib/apiTypesV2/SubscriptionUpdate.h @@ -48,7 +48,6 @@ class SubscriptionUpdate : public Subscription bool onlyChangedProvided; bool coveredProvided; bool notifyOnMetadataChangeProvided; - bool fromNgsiv1; // to support a special case when the SubscriptionUpdate comes from NGSIv1 SubscriptionUpdate(): subjectProvided(false), @@ -60,8 +59,7 @@ class SubscriptionUpdate : public Subscription blacklistProvided(false), onlyChangedProvided(false), coveredProvided(false), - notifyOnMetadataChangeProvided(true), - fromNgsiv1(false) + notifyOnMetadataChangeProvided(true) { descriptionProvided = false; } diff --git a/src/lib/cache/subCache.cpp b/src/lib/cache/subCache.cpp index 23b1af6c8c..53d29aca1c 100644 --- a/src/lib/cache/subCache.cpp +++ b/src/lib/cache/subCache.cpp @@ -38,7 +38,6 @@ #include "apiTypesV2/Subscription.h" #include "mongoBackend/MongoGlobal.h" #include "mongoBackend/mongoSubCache.h" -#include "ngsi10/SubscribeContextRequest.h" #include "cache/subCache.h" #include "alarmMgr/alarmMgr.h" #include "mongoBackend/dbConstants.h" @@ -61,9 +60,7 @@ volatile SubCacheState subCacheState = ScsIdle; // // The 'mongo part' of the cache is implemented in mongoBackend/mongoSubCache.cpp/h and used in: // - MongoCommonUpdate.cpp (in function addTriggeredSubscriptions_withCache) -// - mongoSubscribeContext.cpp (in function mongoSubscribeContext) // - mongoUnsubscribeContext.cpp (in function mongoUnsubscribeContext) -// - mongoUpdateContextSubscription.cpp (in function mongoUpdateContextSubscription) // - contextBroker.cpp (to initialize and sybchronize) // // To manipulate the subscription cache, a semaphore is necessary, as various threads can be @@ -821,7 +818,7 @@ void subCacheItemInsert const char* servicePath, const ngsiv2::HttpInfo& httpInfo, const ngsiv2::MqttInfo& mqttInfo, - const std::vector& entIdVector, + const std::vector& entIdVector, const std::vector& attributes, const std::vector& metadata, const std::vector& conditionAttrs, @@ -929,7 +926,7 @@ void subCacheItemInsert // for (unsigned int ix = 0; ix < entIdVector.size(); ++ix) { - const ngsiv2::EntID* eIdP = &entIdVector[ix]; + const EntityId* eIdP = &entIdVector[ix]; std::string isPattern = (eIdP->id.empty())? "true" : "false"; bool isTypePattern = (eIdP->type.empty()); std::string id = (eIdP->id.empty())? eIdP->idPattern : eIdP->id; diff --git a/src/lib/cache/subCache.h b/src/lib/cache/subCache.h index d64d51eaf3..42ed21e314 100644 --- a/src/lib/cache/subCache.h +++ b/src/lib/cache/subCache.h @@ -30,7 +30,6 @@ #include #include "common/RenderFormat.h" -#include "ngsi/NotifyConditionVector.h" #include "ngsi/EntityIdVector.h" #include "ngsi/StringList.h" #include "apiTypesV2/HttpInfo.h" @@ -197,7 +196,7 @@ extern void subCacheItemInsert const char* servicePath, const ngsiv2::HttpInfo& httpInfo, const ngsiv2::MqttInfo& mqttInfo, - const std::vector& entities, + const std::vector& entities, const std::vector& attributes, const std::vector& metadata, const std::vector& conditionAttrs, diff --git a/src/lib/common/CMakeLists.txt b/src/lib/common/CMakeLists.txt index 07ba47566f..13d2594e2a 100644 --- a/src/lib/common/CMakeLists.txt +++ b/src/lib/common/CMakeLists.txt @@ -23,7 +23,6 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.0) SET (SOURCES globals.cpp string.cpp - tag.cpp sem.cpp MimeType.cpp RenderFormat.cpp diff --git a/src/lib/common/RenderFormat.cpp b/src/lib/common/RenderFormat.cpp index 9c29536216..c28ebc2375 100644 --- a/src/lib/common/RenderFormat.cpp +++ b/src/lib/common/RenderFormat.cpp @@ -37,7 +37,7 @@ * * renderFormatToString - */ -const char* renderFormatToString(RenderFormat format, bool noDefault, bool useLegacyWord) +const char* renderFormatToString(RenderFormat format) { switch (format) { @@ -48,15 +48,7 @@ const char* renderFormatToString(RenderFormat format, bool noDefault, bool useLe case NGSI_V2_CUSTOM: return "custom"; case NGSI_V2_SIMPLIFIEDNORMALIZED:return "simplifiedNormalized"; case NGSI_V2_SIMPLIFIEDKEYVALUES: return "simplifiedKeyValues"; - case NO_FORMAT: - if (noDefault == true) - { - return "no render format"; - } - else - { - return useLegacyWord ? "legacy" : "JSON"; - } + case NO_FORMAT: return "no render format"; } return "Unknown render format"; diff --git a/src/lib/common/RenderFormat.h b/src/lib/common/RenderFormat.h index 8307896052..55c09384cc 100644 --- a/src/lib/common/RenderFormat.h +++ b/src/lib/common/RenderFormat.h @@ -59,7 +59,7 @@ typedef enum RenderFormat * * renderFormatToString - */ -extern const char* renderFormatToString(RenderFormat format, bool noDefault = true, bool userLegacyWord = false); +extern const char* renderFormatToString(RenderFormat format); diff --git a/src/lib/common/Timer.cpp b/src/lib/common/Timer.cpp index 9994c174a6..7974248452 100644 --- a/src/lib/common/Timer.cpp +++ b/src/lib/common/Timer.cpp @@ -39,9 +39,9 @@ Timer::~Timer(void) { // - // FIXME: This destructor is needed to avoid warning message. - // Compilation fails when a warning occurs, and it is enabled - // compilation option -Werror "warnings being treated as errors" + // If we don't implement this destructor in unittest we get a fail when "delete timerMock;" is done: + // + // error: deleting object of polymorphic class type ‘TimerMock’ which has non-virtual destructor might cause undefined behavior [-Werror=delete-non-virtual-dtor] // LM_T(LmtNotImplemented, ("Timer destructor not implemented")); } diff --git a/src/lib/common/globals.cpp b/src/lib/common/globals.cpp index ec8be53148..be134fa6b0 100644 --- a/src/lib/common/globals.cpp +++ b/src/lib/common/globals.cpp @@ -55,7 +55,6 @@ bool countersStatistics = false; bool semWaitStatistics = false; bool timingStatistics = false; bool notifQueueStatistics = false; -bool checkIdv1 = false; unsigned long long inReqPayloadMaxSize = DEFAULT_IN_REQ_PAYLOAD_MAX_SIZE; unsigned long long outReqMsgMaxSize = DEFAULT_OUT_REQ_MSG_MAX_SIZE; @@ -194,8 +193,7 @@ void orionInit bool _countersStatistics, bool _semWaitStatistics, bool _timingStatistics, - bool _notifQueueStatistics, - bool _checkIdv1 + bool _notifQueueStatistics ) { // Give the rest library the correct version string of this executable @@ -227,8 +225,6 @@ void orionInit notifQueueStatistics = _notifQueueStatistics; strncpy(transactionId, "N/A", sizeof(transactionId)); - - checkIdv1 = _checkIdv1; } @@ -307,175 +303,6 @@ double getCurrentTime(void) -/* **************************************************************************** -* -* toSeconds - -*/ -int64_t toSeconds(int value, char what, bool dayPart) -{ - int64_t result = -1; - - if (dayPart == true) - { - if (what == 'Y') - { - result = 365L * 24 * 3600 * value; - } - else if (what == 'M') - { - result = 30L * 24 * 3600 * value; - } - else if (what == 'W') - { - result = 7L * 24 * 3600 * value; - } - else if (what == 'D') - { - result = 24L * 3600 * value; - } - } - else - { - if (what == 'H') - { - result = 3600L * value; - } - else if (what == 'M') - { - result = 60L * value; - } - else if (what == 'S') - { - result = value; - } - } - - if (result == -1) - { - alarmMgr.badInput(clientIp, "ERROR in duration string", std::string(1, what)); - } - - return result; -} - - - -/***************************************************************************** -* -* parse8601 - -* -* This is common code for Duration and Throttling (at least) -* -*/ -int64_t parse8601(const std::string& s) -{ - if (s.empty()) - { - return -1; - } - - char* duration = strdup(s.c_str()); - char* toFree = duration; - bool dayPart = true; - int64_t accumulated = 0; - char* start; - - if (*duration != 'P') - { - free(toFree); - return -1; - } - - ++duration; - start = duration; - - if (*duration == 0) - { - free(toFree); - return -1; - } - - bool digitsPending = false; - - while (*duration != 0) - { - if (isdigit(*duration) || (*duration == '.') || (*duration == ',')) - { - ++duration; - digitsPending = true; - } - else if ((dayPart == true) && - ((*duration == 'Y') || (*duration == 'M') || (*duration == 'D') || (*duration == 'W'))) - { - char what = *duration; - - *duration = 0; - int value = atoi(start); - - if ((value == 0) && (*start != '0')) - { - std::string details = std::string("parse error for duration '") + start + "'"; - alarmMgr.badInput(clientIp, details, s); - - free(toFree); - return -1; - } - - accumulated += toSeconds(value, what, dayPart); - digitsPending = false; - ++duration; - start = duration; - } - else if ((dayPart == true) && (*duration == 'T')) - { - dayPart = false; - ++duration; - start = duration; - digitsPending = false; - } - else if ((dayPart == false) && - ((*duration == 'H') || (*duration == 'M') || (*duration == 'S'))) - { - char what = *duration; - int value; - - *duration = 0; - - if (what == 'S') // We support floats for the seconds, but only to round to an integer - { - // NOTE: here we use atof and not str2double on purpose - float secs = atof(start); - value = (int) round(secs); - } - else - { - value = atoi(start); - } - - accumulated += toSeconds(value, what, dayPart); - digitsPending = false; - ++duration; - start = duration; - } - else - { - free(toFree); - return -1; // ParseError - } - } - - free(toFree); - - if (digitsPending == true) - { - return -1; - } - - return accumulated; -} - - - /***************************************************************************** * * timezoneOffset - @@ -585,9 +412,7 @@ int daysInMonth(int year, int month) /***************************************************************************** * * parse8601Time - -* -* This is common code for Duration and Throttling (at least). -* +** * Based in http://stackoverflow.com/questions/26895428/how-do-i-parse-an-iso-8601-date-with-optional-milliseconds-to-a-struct-tm-in-c * */ diff --git a/src/lib/common/globals.h b/src/lib/common/globals.h index 4533e0f5f1..87cf7dac60 100644 --- a/src/lib/common/globals.h +++ b/src/lib/common/globals.h @@ -36,10 +36,8 @@ /* **************************************************************************** * -* FIWARE_LOCATION - +* FIWARE_LOCATION_V2 - */ -#define FIWARE_LOCATION "FIWARE::Location" -#define FIWARE_LOCATION_DEPRECATED "FIWARE_Location" // Deprecated (but still supported) in Orion 0.16.0 #define FIWARE_LOCATION_V2 "FIWARE::Location::NGSIv2" #define EARTH_RADIUS_METERS 6371000 @@ -152,20 +150,6 @@ typedef enum Ngsiv2Flavour -/* **************************************************************************** -* -* NGSI API version - -*/ -typedef enum ApiVersion -{ - NO_VERSION = -1, - ADMIN_API = 0, - V1 = 1, - V2 = 2 -} ApiVersion; - - - /* **************************************************************************** * * PERMANENT_EXPIRES_DATETIME - date for permanent subscriptions/registrations @@ -217,11 +201,9 @@ extern bool timingStatistics; extern bool countersStatistics; extern bool notifQueueStatistics; -extern bool checkIdv1; extern bool disableCusNotif; extern bool insecureNotif; -extern bool ngsiv1Autocast; extern unsigned long long inReqPayloadMaxSize; extern unsigned long long outReqMsgMaxSize; @@ -246,8 +228,7 @@ extern void orionInit bool _countersStatistics, bool _semWaitStatistics, bool _timingStatistics, - bool _notifQueueStatistics, - bool _checkIdv1 + bool _notifQueueStatistics ); @@ -285,31 +266,9 @@ extern double getCurrentTime(void); -/* **************************************************************************** -* -* toSeconds - -*/ -extern int64_t toSeconds(int value, char what, bool dayPart); - - - -/***************************************************************************** -* -* parse8601 - -* -* This is common code for Duration and Throttling (at least) -* -*/ -extern int64_t parse8601(const std::string& s); - - - /***************************************************************************** * * parse8601Time - -* -* This is common code for Duration and Throttling (at least) -* */ extern double parse8601Time(const std::string& s); diff --git a/src/lib/common/logTracing.cpp b/src/lib/common/logTracing.cpp index 750d9bd472..d78e11e694 100644 --- a/src/lib/common/logTracing.cpp +++ b/src/lib/common/logTracing.cpp @@ -32,17 +32,6 @@ -/* **************************************************************************** -* -* isNgsiV1Url -*/ -inline bool isNgsiV1Url(const char* url) -{ - return (strstr(url, "/v1/") || strcasestr(url, "/ngsi10/") || strcasestr(url, "/ngsi9/")); -} - - - /* **************************************************************************** * * truncatePayload - @@ -170,15 +159,6 @@ void logInfoRequestWithoutPayload ) { LM_I(("Request received: %s %s, response code: %d", verb, url, rc)); - - if (isNgsiV1Url(url)) - { - __sync_fetch_and_add(&noOfDprNgsiv1Request, 1); - if (logDeprecate) - { - LM_W(("Deprecated NGSIv1 request received: %s %s, response code: %d", verb, url, rc)); - } - } } @@ -210,15 +190,6 @@ void logInfoRequestWithPayload LM_I(("Request received: %s %s, request payload (%d bytes): %s, response code: %d", verb, url, strlen(payload), effectivePayload, rc)); - if (isNgsiV1Url(url)) - { - __sync_fetch_and_add(&noOfDprNgsiv1Request, 1); - if (logDeprecate) - { - LM_W(("Deprecated NGSIv1 request received: %s %s, request payload (%d bytes): %s, response code: %d", verb, url, strlen(payload), effectivePayload, rc)); - } - } - if (cleanAfterUse) { free(effectivePayload); @@ -258,7 +229,15 @@ void logInfoFwdRequest { char buffer[STRING_SIZE_FOR_INT]; snprintf(buffer, sizeof(buffer), "%d", rc); - logInfoFwdRequest(regId, verb, url, requestPayload, responsePayload, buffer); + + if (responsePayload == NULL) + { + logInfoFwdRequest(regId, verb, url, requestPayload, "", buffer); + } + else + { + logInfoFwdRequest(regId, verb, url, requestPayload, responsePayload, buffer); + } } diff --git a/src/lib/common/macroSubstitute.cpp b/src/lib/common/macroSubstitute.cpp index 28dd9c156a..91a48fc9e1 100644 --- a/src/lib/common/macroSubstitute.cpp +++ b/src/lib/common/macroSubstitute.cpp @@ -31,6 +31,7 @@ #include "common/globals.h" #include "common/JsonHelper.h" #include "common/macroSubstitute.h" +#include "common/MimeType.h" #include "expressions/exprMgr.h" diff --git a/src/lib/common/statistics.cpp b/src/lib/common/statistics.cpp index 1a6dd710ff..13b49a3c01 100644 --- a/src/lib/common/statistics.cpp +++ b/src/lib/common/statistics.cpp @@ -23,7 +23,6 @@ * Author: Ken Zangelin */ #include "common/statistics.h" -#include "common/tag.h" #include "ngsi/Request.h" #include "logMsg/logMsg.h" #include "common/JsonHelper.h" @@ -69,7 +68,7 @@ UrlCounter noOfRequestCounters[] = {RegistrationRequest, "v2", -1, -1, -1, -1, -1, -1, true, false, true, false, true, true}, {BatchQueryRequest, "v2", -1, -1, -1, -1, -1, -1, false, true, false, false, false, true}, {BatchUpdateRequest, "v2", -1, -1, -1, -1, -1, -1, false, true, false, false, false, true}, - {NotifyContext, "v2", -1, -1, -1, -1, -1, -1, false, true, false, false, false, false}, + {NotifyContext, "v2", -1, -1, -1, -1, -1, -1, false, true, false, false, false, false}, {LogTraceRequest, "log", -1, -1, -1, -1, -1, -1, true, false, false, true, true, false}, {StatisticsRequest, "statistics", -1, -1, -1, -1, -1, -1, true, false, false, false, true, false}, @@ -79,63 +78,6 @@ UrlCounter noOfRequestCounters[] = {VersionRequest, "version", -1, -1, -1, -1, -1, -1, true, false, false, false, false, false}, {MetricsRequest, "admin", -1, -1, -1, -1, -1, -1, true, false, false, false, true, false}, - // FIXME: disable unused NGSv1 API routes in Orion 3.9.0, to be definetively removed at some point of the future - // v1 and ngsi10 legacy GET POST PATCH PUT DELET OPT - //{ContextEntitiesByEntityId, "v1", -1, -1, -1, -1, -1, -1, true, true, false, false, false, false}, - //{ContextEntityAttributes, "v1", -1, -1, -1, -1, -1, -1, true, true, false, false, false, false}, - //{EntityByIdAttributeByName, "v1", -1, -1, -1, -1, -1, -1, true, true, false, false, false, false}, - //{ContextEntityTypes, "v1", -1, -1, -1, -1, -1, -1, true, true, false, false, false, false}, - //{ContextEntityTypeAttributeContainer, "v1", -1, -1, -1, -1, -1, -1, true, true, false, false, false, false}, - //{ContextEntityTypeAttribute, "v1", -1, -1, -1, -1, -1, -1, true, true, false, false, false, false}, - - //{IndividualContextEntity, "v1", -1, -1, -1, -1, -1, -1, true, true, false, true, true, false}, - //{IndividualContextEntity, "ngsi10", -1, -1, -1, -1, -1, -1, true, true, false, true, true, false}, - {IndividualContextEntity, "v1", -1, -1, -1, -1, -1, -1, false, false, false, true, true, false}, - - //{IndividualContextEntityAttributes, "v1", -1, -1, -1, -1, -1, -1, true, true, false, true, true, false}, - //{IndividualContextEntityAttributes, "ngsi10", -1, -1, -1, -1, -1, -1, true, true, false, true, true, false},ç - - //{IndividualContextEntityAttribute, "v1", -1, -1, -1, -1, -1, -1, true, true, false, true, true, false}, - //{IndividualContextEntityAttribute, "ngsi10", -1, -1, -1, -1, -1, -1, true, true, false, true, true, false}, - {IndividualContextEntityAttribute, "v1", -1, -1, -1, -1, -1, -1, true, false, false, false, false, false}, - - //{Ngsi10ContextEntityTypes, "v1", -1, -1, -1, -1, -1, -1, true, false, false, false, false, false}, - //{Ngsi10ContextEntityTypes, "ngsi10", -1, -1, -1, -1, -1, -1, true, false, false, false, false, false}, - - //{Ngsi10ContextEntityTypesAttributeContainer, "v1", -1, -1, -1, -1, -1, -1, true, false, false, false, false, false}, - //{Ngsi10ContextEntityTypesAttributeContainer, "ngsi10", -1, -1, -1, -1, -1, -1, true, false, false, false, false, false}, - - //{Ngsi10ContextEntityTypesAttribute, "v1", -1, -1, -1, -1, -1, -1, true, false, false, false, false, false}, - //{Ngsi10ContextEntityTypesAttribute, "ngsi10", -1, -1, -1, -1, -1, -1, true, false, false, false, false, false}, - - //{Ngsi10SubscriptionsConvOp, "v1", -1, -1, -1, -1, -1, -1, false, false, false, true, true, false}, - //{Ngsi10SubscriptionsConvOp, "ngsi10", -1, -1, -1, -1, -1, -1, false, false, false, true, true, false}, - - //{EntityTypes, "v1", -1, -1, -1, -1, -1, -1, true, false, false, false, false, false}, - //{AttributesForEntityType, "v1", -1, -1, -1, -1, -1, -1, true, false, false, false, false, false}, - //{AllContextEntities, "v1", -1, -1, -1, -1, -1, -1, true, true, false, false, false, false}, - //{AllEntitiesWithTypeAndId, "v1", -1, -1, -1, -1, -1, -1, true, true, false, true, true, false}, - //{IndividualContextEntityAttributeWithTypeAndId, "v1", -1, -1, -1, -1, -1, -1, true, true, false, true, true, false}, - //{ContextEntitiesByEntityIdAndType, "v1", -1, -1, -1, -1, -1, -1, true, true, false, false, false, false}, - //{EntityByIdAttributeByNameIdAndType, "v1", -1, -1, -1, -1, -1, -1, true, true, false, false, false, false}, - - //{RegisterContext, "v1", -1, -1, -1, -1, -1, -1, false, true, false, false, false, false}, - //{DiscoverContextAvailability, "v1", -1, -1, -1, -1, -1, -1, false, true, false, false, false, false}, - - {UpdateContext, "v1", -1, -1, -1, -1, -1, -1, false, true, false, false, false, false}, - {UpdateContext, "ngsi10", -1, -1, -1, -1, -1, -1, false, true, false, false, false, false}, - {QueryContext, "v1", -1, -1, -1, -1, -1, -1, false, true, false, false, false, false}, - {QueryContext, "ngsi10", -1, -1, -1, -1, -1, -1, false, true, false, false, false, false}, - //{SubscribeContext, "v1", -1, -1, -1, -1, -1, -1, false, true, false, false, false, false}, // two URLs: subscribeContext and contextSubscriptions - //{SubscribeContext, "ngsi10", -1, -1, -1, -1, -1, -1, false, true, false, false, false, false}, // two URLs: subscribeContext and contextSubscriptions - //{UpdateContextSubscription, "v1", -1, -1, -1, -1, -1, -1, false, true, false, false, false, false}, - //{UpdateContextSubscription, "ngsi10", -1, -1, -1, -1, -1, -1, false, true, false, false, false, false}, - //{UnsubscribeContext, "v1", -1, -1, -1, -1, -1, -1, false, true, false, false, false, false}, - //{UnsubscribeContext, "ngsi10", -1, -1, -1, -1, -1, -1, false, true, false, false, false, false}, - - //{NotifyContext, "v1", -1, -1, -1, -1, -1, -1, false, true, false, false, false, false}, // also in v2 - //{NotifyContext, "ngsi10", -1, -1, -1, -1, -1, -1, false, true, false, false, false, false}, // also in v2 - // Special ones (LeakRequest MUST be always the last one in the array. See statisticsUpdate() and resetStatistics() comments {ExitRequest, "exit", -1, -1, -1, -1, -1, -1, true, false, false, false, false, false}, {LeakRequest, "leak", -1, -1, -1, -1, -1, -1, true, false, false, false, false, false} @@ -150,7 +92,6 @@ int noOfNotificationsSent = -1; int noOfSimulatedNotifications = -1; // Deprecated features -int noOfDprNgsiv1Request = -1; int noOfDprLegacyForwarding = -1; int noOfDprGeoformat = -1; @@ -174,7 +115,6 @@ inline float timeSpecToFloat(const struct timespec& t) * xxxReqTime - the total time that the LAST request took. * Measuring from the first MHD callback to 'connectionTreat', * until the MHD callback to 'requestCompleted'. -* xxxJsonV1ParseTime - the time that the JSON parse+treat of the LAST request took. * xxxJsonV2ParseTime - the time that the JSON parse+treat of the LAST request took. * xxxMongoBackendTime - the time that the mongoBackend took to treat the last request * xxxReadWaitTime - @@ -188,7 +128,6 @@ std::string renderTimingStatistics(void) timeStatSemTake(__FUNCTION__, "putting stats together"); - bool accJsonV1ParseTime = (accTimeStat.jsonV1ParseTime.tv_sec != 0) || (accTimeStat.jsonV1ParseTime.tv_nsec != 0); bool accJsonV2ParseTime = (accTimeStat.jsonV2ParseTime.tv_sec != 0) || (accTimeStat.jsonV2ParseTime.tv_nsec != 0); bool accMongoBackendTime = (accTimeStat.mongoBackendTime.tv_sec != 0) || (accTimeStat.mongoBackendTime.tv_nsec != 0); bool accMongoReadWaitTime = (accTimeStat.mongoReadWaitTime.tv_sec != 0) || (accTimeStat.mongoReadWaitTime.tv_nsec != 0); @@ -201,7 +140,6 @@ std::string renderTimingStatistics(void) bool accRenderTime = (accTimeStat.renderTime.tv_sec != 0) || (accTimeStat.renderTime.tv_nsec != 0); bool accReqTime = (accTimeStat.reqTime.tv_sec != 0) || (accTimeStat.reqTime.tv_nsec != 0); - bool lastJsonV1ParseTime = (lastTimeStat.jsonV1ParseTime.tv_sec != 0) || (lastTimeStat.jsonV1ParseTime.tv_nsec != 0); bool lastJsonV2ParseTime = (lastTimeStat.jsonV2ParseTime.tv_sec != 0) || (lastTimeStat.jsonV2ParseTime.tv_nsec != 0); bool lastMongoBackendTime = (lastTimeStat.mongoBackendTime.tv_sec != 0) || (lastTimeStat.mongoBackendTime.tv_nsec != 0); bool lastMongoReadWaitTime = (lastTimeStat.mongoReadWaitTime.tv_sec != 0) || (lastTimeStat.mongoReadWaitTime.tv_nsec != 0); @@ -214,8 +152,8 @@ std::string renderTimingStatistics(void) bool lastRenderTime = (lastTimeStat.renderTime.tv_sec != 0) || (lastTimeStat.renderTime.tv_nsec != 0); bool lastReqTime = (lastTimeStat.reqTime.tv_sec != 0) || (lastTimeStat.reqTime.tv_nsec != 0); - bool last = lastJsonV1ParseTime || lastJsonV2ParseTime || lastMongoBackendTime || lastRenderTime || lastReqTime; - bool acc = accJsonV1ParseTime || accJsonV2ParseTime || accMongoBackendTime || accRenderTime || accReqTime; + bool last = lastJsonV2ParseTime || lastMongoBackendTime || lastRenderTime || lastReqTime; + bool acc = accJsonV2ParseTime || accMongoBackendTime || accRenderTime || accReqTime; if (!acc && !last) { @@ -229,7 +167,6 @@ std::string renderTimingStatistics(void) { JsonObjectHelper accJh; - if (accJsonV1ParseTime) accJh.addNumber("jsonV1Parse", timeSpecToFloat(accTimeStat.jsonV1ParseTime)); if (accJsonV2ParseTime) accJh.addNumber("jsonV2Parse", timeSpecToFloat(accTimeStat.jsonV2ParseTime)); if (accMongoBackendTime) accJh.addNumber("mongoBackend", timeSpecToFloat(accTimeStat.mongoBackendTime)); if (accMongoReadWaitTime) accJh.addNumber("mongoReadWait", timeSpecToFloat(accTimeStat.mongoReadWaitTime)); @@ -248,7 +185,6 @@ std::string renderTimingStatistics(void) { JsonObjectHelper lastJh; - if (lastJsonV1ParseTime) lastJh.addNumber("jsonV1Parse", timeSpecToFloat(lastTimeStat.jsonV1ParseTime)); if (lastJsonV2ParseTime) lastJh.addNumber("jsonV2Parse", timeSpecToFloat(lastTimeStat.jsonV2ParseTime)); if (lastMongoBackendTime) lastJh.addNumber("mongoBackend", timeSpecToFloat(lastTimeStat.mongoBackendTime)); if (lastMongoReadWaitTime) lastJh.addNumber("mongoReadWait", timeSpecToFloat(lastTimeStat.mongoReadWaitTime)); @@ -405,7 +341,7 @@ void statisticsUpdate(RequestType request, MimeType inMimeType, Verb verb, const } } - // If it is not a NGSIv2 request it has to be NGSIv1 or invalid + // If it is not a NGSIv2 request it has to be invalid if (!requestFound) { ++noOfInvalidRequests; diff --git a/src/lib/common/statistics.h b/src/lib/common/statistics.h index a5e1195781..bfdee3f89a 100644 --- a/src/lib/common/statistics.h +++ b/src/lib/common/statistics.h @@ -311,7 +311,6 @@ */ typedef struct TimeStat { - struct timespec jsonV1ParseTime; struct timespec jsonV2ParseTime; struct timespec mongoBackendTime; struct timespec mongoReadWaitTime; @@ -378,7 +377,6 @@ extern int noOfNotificationsSent; extern int noOfSimulatedNotifications; // Deprecated features -extern int noOfDprNgsiv1Request; extern int noOfDprLegacyForwarding; extern int noOfDprLegacyNotif; extern int noOfDprGeoformat; diff --git a/src/lib/common/string.cpp b/src/lib/common/string.cpp index 2bfc72e99a..9c8f05b12e 100644 --- a/src/lib/common/string.cpp +++ b/src/lib/common/string.cpp @@ -469,34 +469,6 @@ bool parseUrl(const std::string& url, std::string& host, int& port, std::string& -/* **************************************************************************** -* -* validUrl - check validity of a URL -*/ -bool validUrl(const std::string& url) -{ - std::string host; - int port; - std::string path; - std::string protocol; - - return parseUrl(url, host, port, path, protocol); -} - - - -/* **************************************************************************** -* -* i2s - integer to string -*/ -char* i2s(int i, char* placeholder, int placeholderSize) -{ - snprintf(placeholder, placeholderSize, "%d", i); - return placeholder; -} - - - /* **************************************************************************** * * parsedUptime @@ -524,32 +496,6 @@ std::string parsedUptime(int uptime) -/* **************************************************************************** -* -* onlyWs - -*/ -bool onlyWs(const char* s) -{ - if (*s == 0) - { - return true; - } - - while (*s != 0) - { - if ((*s != ' ') && (*s != '\t') && (*s != '\n')) - { - return false; - } - - ++s; - } - - return true; -} - - - /* **************************************************************************** * * string2coords - @@ -811,38 +757,6 @@ char* strToLower(char* to, const char* from, int toSize) -/* **************************************************************************** -* -* strReplace - -*/ -void strReplace(char* to, int toLen, const char* from, const char* oldString, const char* newString) -{ - int toIx = 0; - int fromIx = 0; - int oldLen = strlen(oldString); - int newLen = strlen(newString); - - while (from[fromIx] != 0) - { - if (strncmp(&from[fromIx], oldString, oldLen) == 0) - { - strncat(to, newString, toLen - strlen(to)); - toIx += newLen; - fromIx += oldLen; - } - else - { - to[toIx] = from[fromIx]; - toIx += 1; - fromIx += 1; - } - } - - to[toIx] = 0; -} - - - /* **************************************************************************** * * servicePathCheck - check one single component of the service-path @@ -1139,3 +1053,113 @@ bool regComp(regex_t* re, const char* pattern, int flags) return false; } + + + +/* **************************************************************************** +* +* htmlEscape - +* +* Allocate a new buffer to hold an escaped version of the input buffer 's'. +* Escaping characters demands more space in the buffer, for some characters up to six +* characters - double-quote (") needs SIX chars: " +* So, when allocating room for the output (escaped) buffer, we need to consider the worst case +* and six times the length of the input buffer is allocated (plus one byte for the zero-termination. +* +* See http://www.anglesanddangles.com/asciichart.php for more info on the 'html-escpaing' of ASCII chars. +*/ +char* htmlEscape(const char* s) +{ + int newLen = strlen(s) * 6 + 1; // See function header comment + char* out = (char*) calloc(1, newLen); + int sIx = 0; + int outIx = 0; + + if (out == NULL) + { + LM_E(("Runtime Error (allocating %d bytes: %s)", newLen, strerror(errno))); + return NULL; + } + + while (s[sIx] != 0) + { + switch (s[sIx]) + { + case '<': + out[outIx++] = '&'; + out[outIx++] = 'l'; + out[outIx++] = 't'; + out[outIx++] = ';'; + ++sIx; + break; + + case '>': + out[outIx++] = '&'; + out[outIx++] = 'g'; + out[outIx++] = 't'; + out[outIx++] = ';'; + ++sIx; + break; + + case '(': + out[outIx++] = '&'; + out[outIx++] = '#'; + out[outIx++] = '4'; + out[outIx++] = '0'; + out[outIx++] = ';'; + ++sIx; + break; + + case ')': + out[outIx++] = '&'; + out[outIx++] = '#'; + out[outIx++] = '4'; + out[outIx++] = '1'; + out[outIx++] = ';'; + ++sIx; + break; + + case '=': + out[outIx++] = '&'; + out[outIx++] = '#'; + out[outIx++] = '6'; + out[outIx++] = '1'; + out[outIx++] = ';'; + ++sIx; + break; + + case '\'': + out[outIx++] = '&'; + out[outIx++] = '#'; + out[outIx++] = '3'; + out[outIx++] = '9'; + out[outIx++] = ';'; + ++sIx; + break; + + case '"': + out[outIx++] = '&'; + out[outIx++] = 'q'; + out[outIx++] = 'u'; + out[outIx++] = 'o'; + out[outIx++] = 't'; + out[outIx++] = ';'; + ++sIx; + break; + + case ';': + out[outIx++] = '&'; + out[outIx++] = '#'; + out[outIx++] = '5'; + out[outIx++] = '9'; + out[outIx++] = ';'; + ++sIx; + break; + + default: + out[outIx++] = s[sIx++]; + } + } + + return out; +} \ No newline at end of file diff --git a/src/lib/common/string.h b/src/lib/common/string.h index f3abcee416..2370c71e7d 100644 --- a/src/lib/common/string.h +++ b/src/lib/common/string.h @@ -36,6 +36,16 @@ // the same macro in parseArg library #define FT(x) (x == true)? "true" : "false" + + +/* **************************************************************************** +* +* Macros for JSON rendering +*/ +#define JSON_STR(value) std::string("\"" + std::string(value) + "\"") + + + /* **************************************************************************** * * isIPv6 - @@ -67,22 +77,6 @@ extern bool parseUrl -/* **************************************************************************** -* -* validUrl - check validity of a URL -*/ -extern bool validUrl(const std::string& url); - - - -/* **************************************************************************** -* -* i2s - integer to string -*/ -extern char* i2s(int i, char* placeholder, int placeholderSize); - - - /* **************************************************************************** * * parsedUptime @@ -91,14 +85,6 @@ extern std::string parsedUptime(int uptime); -/* **************************************************************************** -* -* onlyWs - -*/ -extern bool onlyWs(const char* s); - - - /* **************************************************************************** * * string2coords - @@ -146,21 +132,6 @@ extern char* strToLower(char* to, const char* from, int toSize); -/* **************************************************************************** -* -* strReplace - -*/ -extern void strReplace -( - char* to, - int toLen, - const char* from, - const char* newString, - const char* oldString -); - - - /* **************************************************************************** * * servicePathCheck - @@ -237,4 +208,12 @@ inline std::string removeQuotes(std::string s) +/* **************************************************************************** +* +* htmlEscape - +*/ +extern char* htmlEscape(const char* s); + + + #endif // SRC_LIB_COMMON_STRING_H_ diff --git a/src/lib/common/tag.cpp b/src/lib/common/tag.cpp deleted file mode 100644 index d9d084621d..0000000000 --- a/src/lib/common/tag.cpp +++ /dev/null @@ -1,290 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include -#include - -#include "logMsg/logMsg.h" -#include "common/tag.h" -#include "common/JsonHelper.h" - - - -/* **************************************************************************** -* -* htmlEscape - -* -* Allocate a new buffer to hold an escaped version of the input buffer 's'. -* Escaping characters demands more space in the buffer, for some characters up to six -* characters - double-quote (") needs SIX chars: " -* So, when allocating room for the output (escaped) buffer, we need to consider the worst case -* and six times the length of the input buffer is allocated (plus one byte for the zero-termination. -* -* See http://www.anglesanddangles.com/asciichart.php for more info on the 'html-escpaing' of ASCII chars. -*/ -char* htmlEscape(const char* s) -{ - int newLen = strlen(s) * 6 + 1; // See function header comment - char* out = (char*) calloc(1, newLen); - int sIx = 0; - int outIx = 0; - - if (out == NULL) - { - LM_E(("Runtime Error (allocating %d bytes: %s)", newLen, strerror(errno))); - return NULL; - } - - while (s[sIx] != 0) - { - switch (s[sIx]) - { - case '<': - out[outIx++] = '&'; - out[outIx++] = 'l'; - out[outIx++] = 't'; - out[outIx++] = ';'; - ++sIx; - break; - - case '>': - out[outIx++] = '&'; - out[outIx++] = 'g'; - out[outIx++] = 't'; - out[outIx++] = ';'; - ++sIx; - break; - - case '(': - out[outIx++] = '&'; - out[outIx++] = '#'; - out[outIx++] = '4'; - out[outIx++] = '0'; - out[outIx++] = ';'; - ++sIx; - break; - - case ')': - out[outIx++] = '&'; - out[outIx++] = '#'; - out[outIx++] = '4'; - out[outIx++] = '1'; - out[outIx++] = ';'; - ++sIx; - break; - - case '=': - out[outIx++] = '&'; - out[outIx++] = '#'; - out[outIx++] = '6'; - out[outIx++] = '1'; - out[outIx++] = ';'; - ++sIx; - break; - - case '\'': - out[outIx++] = '&'; - out[outIx++] = '#'; - out[outIx++] = '3'; - out[outIx++] = '9'; - out[outIx++] = ';'; - ++sIx; - break; - - case '"': - out[outIx++] = '&'; - out[outIx++] = 'q'; - out[outIx++] = 'u'; - out[outIx++] = 'o'; - out[outIx++] = 't'; - out[outIx++] = ';'; - ++sIx; - break; - - case ';': - out[outIx++] = '&'; - out[outIx++] = '#'; - out[outIx++] = '5'; - out[outIx++] = '9'; - out[outIx++] = ';'; - ++sIx; - break; - - default: - out[outIx++] = s[sIx++]; - } - } - - return out; -} - - - -/* **************************************************************************** -* -* startTag - -*/ -std::string startTag -( - const std::string& key, - bool isVector -) -{ - // Empty key is legal JSON. However, Orion doesn't use that kind of keys, - // so we can use an empty key string as argument instead of a showkey boolean - // parameter, keeping the function signature simpler - bool showKey = (!key.empty()); - - if (isVector && showKey) - { - return "\"" + key + "\":["; - } - else if (isVector && !showKey) - { - return "["; - } - else if (!isVector && showKey) - { - return "\"" + key + "\":{"; - } - - // else: !isVector && !showKey - - return "{"; -} - - - -/* **************************************************************************** -* -* endTag - -*/ -std::string endTag -( - bool comma, - bool isVector -) -{ - std::string out = ""; - - out += isVector? "]" : "}"; - out += comma? "," : ""; - - return out; -} - - - -/* **************************************************************************** -* -* valueTag - -* -* Function version for string values -* -*/ -std::string valueTag -( - const std::string& key, - const std::string& unescapedValue, - bool showComma, - bool isVectorElement, - bool withoutQuotes -) -{ - char* value; - - if (unescapedValue.empty()) - { - value = (char*) malloc(1); - - *value = 0; - } - else - { - value = htmlEscape(unescapedValue.c_str()); - } - - if (value == NULL) - { - return "ERROR: no memory"; - } - - std::string effectiveValue = toJsonString(value); - free(value); - - effectiveValue = withoutQuotes ? effectiveValue : std::string("\"") + effectiveValue + "\""; - - if (showComma == true) - { - if (isVectorElement == true) - { - std::string out = effectiveValue + ","; - return out; - } - else - { - std::string out = "\"" + key + "\":" + effectiveValue + ","; - return out; - } - } - else - { - if (isVectorElement == true) - { - std::string out = effectiveValue; - return out; - } - else - { - std::string out = "\"" + key + "\":" + effectiveValue; - return out; - } - } -} - - - -/* **************************************************************************** -* -* valueTag - -* -* Function version for integer values -* -*/ -std::string valueTag -( - const std::string& key, - int value, - bool showComma -) -{ - char val[32]; - - snprintf(val, sizeof(val), "%d", value); - - return valueTag(key, val, showComma, false, false); -} - - diff --git a/src/lib/common/tag.h b/src/lib/common/tag.h deleted file mode 100644 index caf90a6832..0000000000 --- a/src/lib/common/tag.h +++ /dev/null @@ -1,127 +0,0 @@ -#ifndef SRC_LIB_COMMON_TAG_H_ -#define SRC_LIB_COMMON_TAG_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include - -/* FIXME P2: this file (along with some other places around all the code) uses - * the old term "tag", coming from the XML days. Now we only support JSON and - * all the terminology should use "key" or "keyName". We have changed terminology - * in many places, but there are yet some remains (not so important, anyway). - */ - - -/* **************************************************************************** -* -* Macros for JSON rendering -*/ -#define JSON_STR(value) std::string("\"" + std::string(value) + "\"") - - - -/* **************************************************************************** -* -* htmlEscape - -*/ -extern char* htmlEscape(const char* s); - -/* **************************************************************************** -* -* jsonInvalidCharsTransformation - -* -* FIXME P5: this is a quick fix for #1172. A better fix should be developed. -*/ -extern std::string jsonInvalidCharsTransformation(const std::string& input); - - - -/* **************************************************************************** -* -* startTag - -* -*/ -extern std::string startTag -( - const std::string& key = "", - bool isVector = false -); - - - -/* **************************************************************************** -* -* endTag - -*/ -extern std::string endTag -( - bool comma = false, - bool isVector = false -); - - - -/* **************************************************************************** -* -* valueTag - -* -*/ -extern std::string valueTag -( - const std::string& key, - const std::string& value, - bool showComma = false, - bool isVectorElement = false, - bool withoutQuotes = false -); - -extern std::string valueTag -( - const std::string& key, - int value, - bool showComma = false -); - - - -/* **************************************************************************** -* -* startArray - -*/ -extern std::string startArray -( - const std::string& key, - bool showKey = true -); - - - -/* **************************************************************************** -* -* endArray - -*/ -extern std::string endArray(const std::string& key); - -#endif // SRC_LIB_COMMON_TAG_H_ diff --git a/src/lib/convenience/AppendContextElementRequest.cpp b/src/lib/convenience/AppendContextElementRequest.cpp deleted file mode 100644 index a45268b932..0000000000 --- a/src/lib/convenience/AppendContextElementRequest.cpp +++ /dev/null @@ -1,119 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "common/tag.h" -#include "convenience/AppendContextElementRequest.h" -#include "convenience/AppendContextElementResponse.h" -#include "ngsi/ContextAttributeVector.h" -#include "ngsi/MetadataVector.h" -#include "rest/ConnectionInfo.h" - - - -/* **************************************************************************** -* -* Constructor - -*/ -AppendContextElementRequest::AppendContextElementRequest() -{ -} - - - -/* **************************************************************************** -* -* toJsonV1 - -*/ -std::string AppendContextElementRequest::toJsonV1 -( - bool asJsonObject, - RequestType requestType -) -{ - std::string out = ""; - - out += startTag(); - - if (!entity.id.empty()) - { - out += entity.toJsonV1(false); - } - - // No metadata filter in this case, an empty vector is used to fulfil method signature. - // For attribute filter, we use the ContextAttributeVector itself - std::vector emptyMdV; - - out += contextAttributeVector.toJsonV1(asJsonObject, requestType, contextAttributeVector.vec, emptyMdV); - out += endTag(); - - return out; -} - - - -/* **************************************************************************** -* -* check - -* -*/ -std::string AppendContextElementRequest::check -( - ApiVersion apiVersion, - bool asJsonObject, - RequestType requestType, - const std::string& predetectedError // Predetected Error, normally during parsing -) -{ - AppendContextElementResponse response; - std::string res; - - if (!predetectedError.empty()) - { - response.errorCode.fill(SccBadRequest, predetectedError); - } - else if ((res = contextAttributeVector.check(apiVersion, AppendContextElement)) != "OK") - { - response.errorCode.fill(SccBadRequest, res); - } - else - { - return "OK"; - } - - return response.toJsonV1(asJsonObject, requestType); -} - - - -/* **************************************************************************** -* -* release - -*/ -void AppendContextElementRequest::release(void) -{ - contextAttributeVector.release(); -} diff --git a/src/lib/convenience/AppendContextElementRequest.h b/src/lib/convenience/AppendContextElementRequest.h deleted file mode 100644 index 1b497a17ab..0000000000 --- a/src/lib/convenience/AppendContextElementRequest.h +++ /dev/null @@ -1,64 +0,0 @@ -#ifndef SRC_LIB_CONVENIENCE_APPENDCONTEXTELEMENTREQUEST_H_ -#define SRC_LIB_CONVENIENCE_APPENDCONTEXTELEMENTREQUEST_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "ngsi/EntityId.h" -#include "ngsi/ContextAttributeVector.h" -#include "ngsi/MetadataVector.h" -#include "rest/ConnectionInfo.h" - - - -/* **************************************************************************** -* -* AppendContextElementRequest - -* -* NOTE -* The field 'entity' is MANDATORY for "POST /v1/contextEntities". -* For other requests, data in the URL (path and parameters) must coincide -* with the data in the payload. -* If not, an error is raised. -* -*/ -typedef struct AppendContextElementRequest -{ - EntityId entity; // See NOTE in type header above - ContextAttributeVector contextAttributeVector; // Optional - - AppendContextElementRequest(); - - std::string toJsonV1(bool asJsonObject, RequestType requestType); - void release(); - std::string check(ApiVersion apiVersion, - bool asJsonObject, - RequestType requestType, - const std::string& predetectedError); -} AppendContextElementRequest; - -#endif // SRC_LIB_CONVENIENCE_APPENDCONTEXTELEMENTREQUEST_H_ diff --git a/src/lib/convenience/AppendContextElementResponse.cpp b/src/lib/convenience/AppendContextElementResponse.cpp deleted file mode 100644 index df5c9da1d4..0000000000 --- a/src/lib/convenience/AppendContextElementResponse.cpp +++ /dev/null @@ -1,197 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/tag.h" -#include "convenience/ContextAttributeResponseVector.h" -#include "ngsi/StatusCode.h" -#include "ngsi/ContextElementResponse.h" -#include "ngsi10/UpdateContextResponse.h" -#include "convenience/AppendContextElementResponse.h" -#include "rest/ConnectionInfo.h" - - - -/* **************************************************************************** -* -* AppendContextElementResponse::AppendContextElementResponse - -*/ -AppendContextElementResponse::AppendContextElementResponse() : errorCode("errorCode") -{ -} - - - -/* **************************************************************************** -* -* AppendContextElementResponse::toJsonV1 - -*/ -std::string AppendContextElementResponse::toJsonV1 -( - bool asJsonObject, - RequestType requestType -) -{ - std::string out = ""; - - out += startTag(); - - if ((errorCode.code != SccNone) && (errorCode.code != SccOk)) - { - out += errorCode.toJsonV1(false); - } - else - { - if (!entity.id.empty()) - { - out += entity.toJsonV1(true); - } - - out += contextAttributeResponseVector.toJsonV1(asJsonObject, requestType); - } - - out += endTag(); - - return out; -} - - - -/* **************************************************************************** -* -* AppendContextElementResponse::check - -*/ -std::string AppendContextElementResponse::check -( - ApiVersion apiVersion, - bool asJsonObject, - RequestType requestType, - const std::string& predetectedError -) -{ - std::string res; - - if (!predetectedError.empty()) - { - errorCode.fill(SccBadRequest, predetectedError); - } - else if ((res = contextAttributeResponseVector.check(apiVersion, asJsonObject, requestType, "")) != "OK") - { - errorCode.fill(SccBadRequest, res); - } - else - { - return "OK"; - } - - return toJsonV1(asJsonObject, requestType); -} - - - -/* **************************************************************************** -* -* AppendContextElementResponse::release - -*/ -void AppendContextElementResponse::release(void) -{ - LM_T(LmtRelease, ("Releasing AppendContextElementResponse")); - - contextAttributeResponseVector.release(); - errorCode.release(); -} - - - -/* **************************************************************************** -* -* AppendContextElementResponse::fill - -* -* NOTE -* This method is used in the service routine of 'POST /v1/contextEntities/{entityId::id} et al. -* Only ONE response in the vector contextElementResponseVector of UpdateContextResponse is possible. -*/ -void AppendContextElementResponse::fill(UpdateContextResponse* ucrsP, const std::string& entityId, const std::string& entityType) -{ - if (ucrsP->contextElementResponseVector.size() != 0) - { - ContextElementResponse* cerP = ucrsP->contextElementResponseVector[0]; - - contextAttributeResponseVector.fill(cerP->entity.attributeVector, cerP->statusCode); - - entity.fill(cerP->entity.id, cerP->entity.type, cerP->entity.isPattern); - } - else - { - entity.fill(entityId, entityType, "false"); - } - - errorCode.fill(ucrsP->errorCode); - - // - // Special treatment if only one contextElementResponse that is NOT FOUND and if - // AppendContextElementResponse::errorCode is not 404 already - // - // Also if NO contextElementResponse is present - // - // These 'fixes' are mainly to maintain backward compatibility - // - if ((errorCode.code != SccContextElementNotFound) && - (contextAttributeResponseVector.size() == 1) && - (contextAttributeResponseVector[0]->statusCode.code == SccContextElementNotFound) - ) - { - errorCode.fill(SccContextElementNotFound); - } - else if ((errorCode.code != SccContextElementNotFound) && (contextAttributeResponseVector.size() == 0)) - { - errorCode.fill(SccContextElementNotFound); - } - else if (contextAttributeResponseVector.size() == 1) - { - // - // Now, if any error inside ContextAttributeResponse, move it to the outside, but only if we have ONLY ONE contextAttributeResponse - // and only if there is no error already in the 'external' errorCode. - // - if (((errorCode.code == SccNone) || (errorCode.code == SccOk)) && - ((contextAttributeResponseVector[0]->statusCode.code != SccNone) && (contextAttributeResponseVector[0]->statusCode.code != SccOk))) - { - errorCode.fill(contextAttributeResponseVector[0]->statusCode); - } - } - - // Now, if the external error code is 404 and 'details' is empty - add the name of the incoming entity::id as details - if ((errorCode.code == SccContextElementNotFound) && (errorCode.details.empty())) - { - if (ucrsP->contextElementResponseVector.size() == 1) - { - errorCode.details = ucrsP->contextElementResponseVector[0]->entity.id; - } - } -} diff --git a/src/lib/convenience/AppendContextElementResponse.h b/src/lib/convenience/AppendContextElementResponse.h deleted file mode 100644 index 7d2310c6bd..0000000000 --- a/src/lib/convenience/AppendContextElementResponse.h +++ /dev/null @@ -1,83 +0,0 @@ -#ifndef SRC_LIB_CONVENIENCE_APPENDCONTEXTELEMENTRESPONSE_H_ -#define SRC_LIB_CONVENIENCE_APPENDCONTEXTELEMENTRESPONSE_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "convenience/ContextAttributeResponseVector.h" -#include "ngsi/EntityId.h" -#include "ngsi/StatusCode.h" -#include "rest/ConnectionInfo.h" - - - -/* **************************************************************************** -* -* Forward declaration -*/ -struct UpdateContextResponse; - - - -/* **************************************************************************** -* -* AppendContextElementResponse - -* -* FIXME P5: AppendContextElementResponse and UpdateContextElementResponse are -* identical. They should 'merge' into ONE struct. -* This problem origins from an ?error? in the ngsi10 binding doc by NEC -* See: https://github.com/telefonicaid/fiware-orion/issues/106 -* -* NOTE -* The field 'entity' is: -* o MANDATORY for "POST /v1/contextEntities" -* o FORBIDDEN for "POST /v1/contextEntities/{entityId::id}" -* o FORBIDDEN for "POST /v1/contextEntities/type/{entityId::type}/id/{entityId::id}" -* -* So, for its response (AppendContextElementResponse), the field 'entity' will be -* rendered if the response is for "POST /v1/contextEntities", but NOT if the -* response is for the other two requests. -* -*/ -typedef struct AppendContextElementResponse -{ - EntityId entity; // See NOTE in type header above - ContextAttributeResponseVector contextAttributeResponseVector; // Optional, but mandatory if success - StatusCode errorCode; // Optional, but mandatory if failure - - AppendContextElementResponse(); - - std::string toJsonV1(bool asJsonObject, RequestType requestType); - void release(void); - std::string check(ApiVersion apiVersion, - bool asJsonObject, - RequestType requestType, - const std::string& predetectedError); - void fill(UpdateContextResponse* ucrsP, const std::string& entityId = "", const std::string& entityType = ""); -} AppendContextElementResponse; - -#endif // SRC_LIB_CONVENIENCE_APPENDCONTEXTELEMENTRESPONSE_H_ diff --git a/src/lib/convenience/CMakeLists.txt b/src/lib/convenience/CMakeLists.txt deleted file mode 100644 index 65760b1253..0000000000 --- a/src/lib/convenience/CMakeLists.txt +++ /dev/null @@ -1,55 +0,0 @@ -# Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -# -# This file is part of Orion Context Broker. -# -# Orion Context Broker is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Orion Context Broker is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -# General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -# -# For those usages not covered by this license please contact with -# iot_support at tid dot es - -CMAKE_MINIMUM_REQUIRED(VERSION 3.0) - -SET (SOURCES - AppendContextElementRequest.cpp - AppendContextElementResponse.cpp - ContextAttributeResponse.cpp - ContextAttributeResponseVector.cpp - RegisterProviderRequest.cpp - UpdateContextElementRequest.cpp - UpdateContextElementResponse.cpp - UpdateContextAttributeRequest.cpp -) - -SET (HEADERS - AppendContextElementRequest.h - AppendContextElementResponse.h - ContextAttributeResponse.h - ContextAttributeResponseVector.h - Convenience.h - RegisterProviderRequest.h - UpdateContextElementRequest.h - UpdateContextElementResponse.h - UpdateContextAttributeRequest.h -) - - - -# Include directories -# ----------------------------------------------------------------- -include_directories("${PROJECT_SOURCE_DIR}/src/lib") - - -# Library declaration -# ----------------------------------------------------------------- -ADD_LIBRARY(convenience STATIC ${SOURCES} ${HEADERS}) diff --git a/src/lib/convenience/ContextAttributeResponse.cpp b/src/lib/convenience/ContextAttributeResponse.cpp deleted file mode 100644 index 41e768f048..0000000000 --- a/src/lib/convenience/ContextAttributeResponse.cpp +++ /dev/null @@ -1,194 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/logMsg.h" - -#include "common/tag.h" -#include "alarmMgr/alarmMgr.h" -#include "ngsi/ContextAttributeVector.h" -#include "ngsi/StatusCode.h" -#include "ngsi10/QueryContextResponse.h" -#include "ngsi/Request.h" -#include "convenience/ContextAttributeResponse.h" -#include "rest/ConnectionInfo.h" - - - -/* **************************************************************************** -* -* toJsonV1 - -*/ -std::string ContextAttributeResponse::toJsonV1 -( - bool asJsonObject, - RequestType request -) -{ - std::string out = ""; - - // No metadata filter in this case, an empty vector is used to fulfil method signature. - // For attribute filter, we use the ContextAttributeVector itself - std::vector emptyMdV; - - out += startTag(); - out += contextAttributeVector.toJsonV1(asJsonObject, request, contextAttributeVector.vec, emptyMdV, true); - out += statusCode.toJsonV1(false); - out += endTag(); - - return out; -} - - - -/* **************************************************************************** -* -* check - -*/ -std::string ContextAttributeResponse::check -( - ApiVersion apiVersion, - bool asJsonObject, - RequestType requestType, - const std::string& predetectedError -) -{ - std::string res; - - if (!predetectedError.empty()) - { - statusCode.fill(SccBadRequest, predetectedError); - } - else if ((res = contextAttributeVector.check(apiVersion, requestType)) != "OK") - { - std::string details = std::string("contextAttributeVector: '") + res + "'"; - alarmMgr.badInput(clientIp, details); - statusCode.fill(SccBadRequest, res); - - // - // If this ContextAttributeResponse is part of an IndividualContextEntity, the complete rendered - // response is not desired, just the string returned from the check method - // - if (requestType == IndividualContextEntity) - { - return res; - } - } - else - { - return "OK"; - } - - return toJsonV1(asJsonObject, requestType); -} - - - -/* **************************************************************************** -* -* release - -*/ -void ContextAttributeResponse::release(void) -{ - contextAttributeVector.release(); -} - - - -/* **************************************************************************** -* -* fill - -*/ -void ContextAttributeResponse::fill(const ContextAttributeVector& caV, const StatusCode& _statusCode) -{ - contextAttributeVector.fill(caV); - statusCode.fill(_statusCode); -} - - -/* **************************************************************************** -* -* ContextAttributeResponse::fill - -*/ -void ContextAttributeResponse::fill -( - QueryContextResponse* qcrP, - const std::string& entityId, - const std::string& entityType, - const std::string& attributeName -) -{ - if (qcrP == NULL) - { - statusCode.fill(SccContextElementNotFound); - return; - } - - if (qcrP->contextElementResponseVector.size() == 0) - { - statusCode.fill(&qcrP->errorCode); - - if ((statusCode.code == SccOk) || (statusCode.code == SccNone)) - { - statusCode.fill(SccContextElementNotFound, ""); - } - - if ((statusCode.code != SccOk) && (statusCode.details.empty())) - { - statusCode.details = "Entity-Attribute pair: /" + entityId + "-" + attributeName + "/"; - } - - return; - } - - - // - // FIXME P7: If more than one context element is found, we simply select the first one. - // A better approach would be to change this convop to return a vector of responses. - // Adding a call to alarmMgr::badInput - with this I mean that the user that sends the - // query needs to avoid using this conv op to make any queries that can give more than - // one unique context element :-). - // This FIXME is related to github issue #588 and (probably) #650. - // Also, optimizing this would be part of issue #768 - // - if (qcrP->contextElementResponseVector.size() > 1) - { - alarmMgr.badInput(clientIp, "more than one context element found in this query - selecting the first one"); - } - - contextAttributeVector.fill(qcrP->contextElementResponseVector[0]->entity.attributeVector); - - if ((statusCode.code == SccNone) || (statusCode.code == SccOk)) - { - if (qcrP->errorCode.code == SccNone) - { - // Fix code, preserve details - qcrP->errorCode.fill(SccOk, qcrP->errorCode.details); - } - - statusCode.fill(&qcrP->errorCode); - } -} diff --git a/src/lib/convenience/ContextAttributeResponse.h b/src/lib/convenience/ContextAttributeResponse.h deleted file mode 100644 index f277a3443f..0000000000 --- a/src/lib/convenience/ContextAttributeResponse.h +++ /dev/null @@ -1,67 +0,0 @@ -#ifndef SRC_LIB_CONVENIENCE_CONTEXTATTRIBUTERESPONSE_H_ -#define SRC_LIB_CONVENIENCE_CONTEXTATTRIBUTERESPONSE_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "ngsi/ContextAttributeVector.h" -#include "ngsi/StatusCode.h" -#include "rest/ConnectionInfo.h" - - - -/* **************************************************************************** -* -* Forward declarations -*/ -struct QueryContextResponse; - - - -/* **************************************************************************** -* -* ContextAttributeResponse - -*/ -typedef struct ContextAttributeResponse -{ - ContextAttributeVector contextAttributeVector; // Mandatory - StatusCode statusCode; // Mandatory - - std::string toJsonV1(bool asJsonObject, RequestType request); - void release(void); - std::string check(ApiVersion apiVersion, - bool asJsonObject, - RequestType requestType, - const std::string& predetectedError); - void fill(const ContextAttributeVector& caV, const StatusCode& _statusCode); - void fill(QueryContextResponse* qcrP, - const std::string& entityId, - const std::string& entityType, - const std::string& attributeName); -} ContextAttributeResponse; - -#endif // SRC_LIB_CONVENIENCE_CONTEXTATTRIBUTERESPONSE_H_ diff --git a/src/lib/convenience/ContextAttributeResponseVector.cpp b/src/lib/convenience/ContextAttributeResponseVector.cpp deleted file mode 100755 index 953937effc..0000000000 --- a/src/lib/convenience/ContextAttributeResponseVector.cpp +++ /dev/null @@ -1,155 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include -#include - -#include "logMsg/traceLevels.h" -#include "common/globals.h" -#include "common/tag.h" -#include "convenience/ContextAttributeResponseVector.h" -#include "rest/ConnectionInfo.h" - - - -/* **************************************************************************** -* -* ContextAttributeResponseVector::toJsonV1 - -*/ -std::string ContextAttributeResponseVector::toJsonV1 -( - bool asJsonObject, - RequestType request -) -{ - std::string out = ""; - std::string key = "contextResponses"; - - if (vec.size() == 0) - { - return ""; - } - - out += startTag(key, true); - for (unsigned int ix = 0; ix < vec.size(); ++ix) - { - out += vec[ix]->toJsonV1(asJsonObject, request); - } - out += endTag(false, true); - - return out; -} - - - -/* **************************************************************************** -* -* ContextAttributeResponseVector::check - -*/ -std::string ContextAttributeResponseVector::check -( - ApiVersion apiVersion, - bool asJsonObject, - RequestType request, - const std::string& predetectedError -) -{ - for (unsigned int ix = 0; ix < vec.size(); ++ix) - { - std::string res; - - if ((res = vec[ix]->check(apiVersion, asJsonObject, request, predetectedError)) != "OK") - { - return res; - } - } - - return "OK"; -} - - - -/* **************************************************************************** -* -* ContextAttributeResponseVector::push_back - -*/ -void ContextAttributeResponseVector::push_back(ContextAttributeResponse* item) -{ - vec.push_back(item); -} - - - -/* **************************************************************************** -* -* ContextAttributeResponseVector::operator[] - -*/ -ContextAttributeResponse* ContextAttributeResponseVector::operator[](unsigned int ix) const -{ - if (ix < vec.size()) - { - return vec[ix]; - } - return NULL; -} - - -/* **************************************************************************** -* -* ContextAttributeResponseVector::size - -*/ -unsigned int ContextAttributeResponseVector::size(void) -{ - return vec.size(); -} - - - -/* **************************************************************************** -* -* ContextAttributeResponseVector::release - -*/ -void ContextAttributeResponseVector::release(void) -{ - for (unsigned int ix = 0; ix < vec.size(); ++ix) - { - vec[ix]->release(); - delete vec[ix]; - } - - vec.clear(); -} - - - -/* **************************************************************************** -* -* ContextAttributeResponseVector::fill - -*/ -void ContextAttributeResponseVector::fill(const ContextAttributeVector& caV, const StatusCode& statusCode) -{ - vec.push_back(new ContextAttributeResponse()); - vec[0]->fill(caV, statusCode); -} diff --git a/src/lib/convenience/ContextAttributeResponseVector.h b/src/lib/convenience/ContextAttributeResponseVector.h deleted file mode 100644 index 3f31c85cb9..0000000000 --- a/src/lib/convenience/ContextAttributeResponseVector.h +++ /dev/null @@ -1,58 +0,0 @@ -#ifndef SRC_LIB_CONVENIENCE_CONTEXTATTRIBUTERESPONSEVECTOR_H_ -#define SRC_LIB_CONVENIENCE_CONTEXTATTRIBUTERESPONSEVECTOR_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "convenience/ContextAttributeResponse.h" -#include "rest/ConnectionInfo.h" - - - -/* **************************************************************************** -* -* ContextAttributeResponseVector - -*/ -typedef struct ContextAttributeResponseVector -{ - std::vector vec; - - std::string toJsonV1(bool asJsonObject, RequestType request); - void push_back(ContextAttributeResponse* item); - unsigned int size(void); - void release(void); - std::string check(ApiVersion apiVersion, - bool asJsonObject, - RequestType requestType, - const std::string& predetectedError); - void fill(const ContextAttributeVector& caV, const StatusCode& statusCode); - - ContextAttributeResponse* operator[](unsigned int ix) const; - -} ContextAttributeResponseVector; - -#endif // SRC_LIB_CONVENIENCE_CONTEXTATTRIBUTERESPONSEVECTOR_H_ diff --git a/src/lib/convenience/Convenience.h b/src/lib/convenience/Convenience.h deleted file mode 100644 index e85b75908f..0000000000 --- a/src/lib/convenience/Convenience.h +++ /dev/null @@ -1,77 +0,0 @@ -#ifndef SRC_LIB_CONVENIENCE_CONVENIENCE_H_ -#define SRC_LIB_CONVENIENCE_CONVENIENCE_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "rest/ConnectionInfo.h" -#include "rest/Verb.h" -#include "rest/HttpStatusCode.h" -#include "ngsi/ParseData.h" - - - -/* **************************************************************************** -* -* Convenience - -*/ -typedef void (*ConvenienceTreat) -( - ConnectionInfo* ciP, - Verb verb, - int components, - std::vector compV, - ParseData* reqDataP, - std::string* responseData -); - -typedef struct Convenience -{ - Verb verb; - int components; - std::string compV[6]; - ConvenienceTreat treat; -} Convenience; - - - -/* **************************************************************************** -* -* convenienceTreat - -*/ -extern void convenienceTreat -( - ConnectionInfo* ciP, - std::string protocol, - Verb verb, - int components, - std::vector compV, - ParseData* reqDataP, - std::string* responseData -); - -#endif // SRC_LIB_CONVENIENCE_CONVENIENCE_H_ diff --git a/src/lib/convenience/RegisterProviderRequest.cpp b/src/lib/convenience/RegisterProviderRequest.cpp deleted file mode 100755 index 432dcef5bf..0000000000 --- a/src/lib/convenience/RegisterProviderRequest.cpp +++ /dev/null @@ -1,112 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/globals.h" -#include "common/tag.h" -#include "alarmMgr/alarmMgr.h" - -#include "convenience/RegisterProviderRequest.h" -#include "ngsi/StatusCode.h" -#include "ngsi/MetadataVector.h" -#include "ngsi/Duration.h" -#include "ngsi/ProvidingApplication.h" -#include "ngsi/RegistrationId.h" -#include "ngsi9/DiscoverContextAvailabilityResponse.h" - - - -/* **************************************************************************** -* -* Constructor - -*/ -RegisterProviderRequest::RegisterProviderRequest() -{ -} - - - -/* **************************************************************************** -* -* RegisterProviderRequest::toJsonV1 - -*/ -std::string RegisterProviderRequest::toJsonV1(void) -{ - std::string out = ""; - bool providingApplicationRendered = !providingApplication.get().empty(); - bool registrationIdRendered = !registrationId.get().empty(); - bool commaAfterProvidingApplication = registrationIdRendered; - bool commaAfterDuration = commaAfterProvidingApplication || providingApplicationRendered; - - out += startTag(); - out += duration.toJsonV1(commaAfterDuration); - out += providingApplication.toJsonV1(commaAfterProvidingApplication); - out += registrationId.toJsonV1(RegisterContext, false); - out += endTag(false); - - return out; -} - - - -/* **************************************************************************** -* -* RegisterProviderRequest::check - -*/ -std::string RegisterProviderRequest::check -( - ApiVersion apiVersion, - RequestType requestType, - const std::string& predetectedError -) -{ - DiscoverContextAvailabilityResponse response; - std::string res; - - if (!predetectedError.empty()) - { - response.errorCode.fill(SccBadRequest, predetectedError); - } - else if (((res = duration.check()) != "OK") || - ((res = providingApplication.check()) != "OK") || - ((res = registrationId.check()) != "OK")) - { - response.errorCode.fill(SccBadRequest, res); - } - else - { - return "OK"; - } - - std::string details = std::string("RegisterProviderRequest Error: '") + res + "'"; - alarmMgr.badInput(clientIp, details); - - return response.toJsonV1(); -} diff --git a/src/lib/convenience/RegisterProviderRequest.h b/src/lib/convenience/RegisterProviderRequest.h deleted file mode 100644 index 297a6eff20..0000000000 --- a/src/lib/convenience/RegisterProviderRequest.h +++ /dev/null @@ -1,55 +0,0 @@ -#ifndef SRC_LIB_CONVENIENCE_REGISTERPROVIDERREQUEST_H_ -#define SRC_LIB_CONVENIENCE_REGISTERPROVIDERREQUEST_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "ngsi/MetadataVector.h" -#include "ngsi/Duration.h" -#include "ngsi/ProvidingApplication.h" -#include "ngsi/RegistrationId.h" - - - -/* **************************************************************************** -* -* RegisterProviderRequest - -*/ -typedef struct RegisterProviderRequest -{ - Duration duration; // Optional - ProvidingApplication providingApplication; // Mandatory - RegistrationId registrationId; // Optional - - RegisterProviderRequest(); - - std::string toJsonV1(void); - std::string check(ApiVersion apiVersion, RequestType requestType, const std::string& preError); - -} RegisterProviderRequest; - -#endif // SRC_LIB_CONVENIENCE_REGISTERPROVIDERREQUEST_H_ diff --git a/src/lib/convenience/UpdateContextAttributeRequest.cpp b/src/lib/convenience/UpdateContextAttributeRequest.cpp deleted file mode 100755 index 10a552879a..0000000000 --- a/src/lib/convenience/UpdateContextAttributeRequest.cpp +++ /dev/null @@ -1,128 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/globals.h" -#include "common/tag.h" -#include "convenience/UpdateContextAttributeRequest.h" -#include "ngsi/StatusCode.h" -#include "parse/compoundValue.h" - - - -/* **************************************************************************** -* -* Constructor - -*/ -UpdateContextAttributeRequest::UpdateContextAttributeRequest() -{ - compoundValueP = NULL; - valueType = orion::ValueTypeNotGiven; -} - - - -/* **************************************************************************** -* -* toJsonV1 - -*/ -std::string UpdateContextAttributeRequest::toJsonV1(void) -{ - std::string out = ""; - - out += startTag(); - out += valueTag("type", type, true); - - if (compoundValueP == NULL) - { - out += valueTag("contextValue", contextValue, true); - } - else - { - out += JSON_STR("value") + ":" + compoundValueP->toJson(); - } - - out += metadataVector.toJsonV1(metadataVector.vec, false); - out += endTag(); - - return out; -} - - - -/* **************************************************************************** -* -* check - -*/ -std::string UpdateContextAttributeRequest::check -( - ApiVersion apiVersion, - const std::string& predetectedError -) -{ - StatusCode response; - std::string res; - - if (!predetectedError.empty()) - { - response.fill(SccBadRequest, predetectedError); - } - else if ((res = metadataVector.check(apiVersion)) != "OK") - { - response.fill(SccBadRequest, res); - } - else - { - return "OK"; - } - - std::string out = response.toJsonV1(false); - - out = "{" + out + "}"; - - return out; -} - - - -/* **************************************************************************** -* -* release - -*/ -void UpdateContextAttributeRequest::release(void) -{ - metadataVector.release(); - - if (compoundValueP != NULL) - { - delete compoundValueP; - compoundValueP = NULL; - } -} diff --git a/src/lib/convenience/UpdateContextAttributeRequest.h b/src/lib/convenience/UpdateContextAttributeRequest.h deleted file mode 100644 index 2534c6e5a9..0000000000 --- a/src/lib/convenience/UpdateContextAttributeRequest.h +++ /dev/null @@ -1,57 +0,0 @@ -#ifndef SRC_LIB_CONVENIENCE_UPDATECONTEXTATTRIBUTEREQUEST_H_ -#define SRC_LIB_CONVENIENCE_UPDATECONTEXTATTRIBUTEREQUEST_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "ngsi/MetadataVector.h" -#include "parse/CompoundValueNode.h" - -struct ConnectionInfo; - - - -/* **************************************************************************** -* -* UpdateContextAttributeRequest - -*/ -typedef struct UpdateContextAttributeRequest -{ - std::string type; // Optional - std::string contextValue; // Mandatory - MetadataVector metadataVector; // Optional - - orion::ValueType valueType; // Type of value: either string or none - orion::CompoundValueNode* compoundValueP; - - UpdateContextAttributeRequest(); - std::string toJsonV1(void); - std::string check(ApiVersion apiVersion, const std::string& preError); - void release(); -} UpdateContextAttributeRequest; - -#endif // SRC_LIB_CONVENIENCE_UPDATECONTEXTATTRIBUTEREQUEST_H_ diff --git a/src/lib/convenience/UpdateContextElementRequest.cpp b/src/lib/convenience/UpdateContextElementRequest.cpp deleted file mode 100644 index 9109ace412..0000000000 --- a/src/lib/convenience/UpdateContextElementRequest.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "common/globals.h" -#include "common/tag.h" -#include "ngsi/ContextAttributeVector.h" -#include "convenience/UpdateContextElementRequest.h" -#include "convenience/UpdateContextElementResponse.h" -#include "rest/ConnectionInfo.h" - - - -/* **************************************************************************** -* -* toJsonV1 - -* -*/ -std::string UpdateContextElementRequest::toJsonV1(bool asJsonObject, RequestType requestType) -{ - std::string out = ""; - - // No metadata filter in this case, an empty vector is used to fulfil method signature. - // For attribute filter, we use the ContextAttributeVector itself - std::vector emptyMdV; - - out += startTag(); - out += contextAttributeVector.toJsonV1(asJsonObject, requestType, contextAttributeVector.vec, emptyMdV); - out += endTag(); - - return out; -} - - - -/* **************************************************************************** -* -* check - -* -*/ -std::string UpdateContextElementRequest::check -( - ApiVersion apiVersion, - bool asJsonObject, - RequestType requestType, - const std::string& predetectedError // Predetected Error, normally during parsing -) -{ - UpdateContextElementResponse response; - std::string res; - - if (!predetectedError.empty()) - { - response.errorCode.fill(SccBadRequest, predetectedError); - } - else if ((res = contextAttributeVector.check(apiVersion, UpdateContextElement)) != "OK") - { - response.errorCode.fill(SccBadRequest, res); - } - else - { - return "OK"; - } - - return response.toJsonV1(asJsonObject, requestType); -} - - - -/* **************************************************************************** -* -* release - -*/ -void UpdateContextElementRequest::release(void) -{ - contextAttributeVector.release(); -} diff --git a/src/lib/convenience/UpdateContextElementRequest.h b/src/lib/convenience/UpdateContextElementRequest.h deleted file mode 100644 index 5e9a3872a8..0000000000 --- a/src/lib/convenience/UpdateContextElementRequest.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef SRC_LIB_CONVENIENCE_UPDATECONTEXTELEMENTREQUEST_H_ -#define SRC_LIB_CONVENIENCE_UPDATECONTEXTELEMENTREQUEST_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "ngsi/ContextAttributeVector.h" -#include "rest/ConnectionInfo.h" - - - -/* **************************************************************************** -* -* UpdateContextElementRequest - -*/ -typedef struct UpdateContextElementRequest -{ - ContextAttributeVector contextAttributeVector; // Optional - - std::string toJsonV1(bool asJsonObject, RequestType requestType); - void release(void); - std::string check(ApiVersion apiVersion, - bool asJsonObject, - RequestType requestType, - const std::string& predetectedError); -} UpdateContextElementRequest; - -#endif // SRC_LIB_CONVENIENCE_UPDATECONTEXTELEMENTREQUEST_H_ diff --git a/src/lib/convenience/UpdateContextElementResponse.cpp b/src/lib/convenience/UpdateContextElementResponse.cpp deleted file mode 100644 index aa7038f9fd..0000000000 --- a/src/lib/convenience/UpdateContextElementResponse.cpp +++ /dev/null @@ -1,202 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/traceLevels.h" -#include "common/tag.h" -#include "convenience/ContextAttributeResponse.h" -#include "convenience/UpdateContextElementResponse.h" -#include "ngsi/StatusCode.h" -#include "ngsi10/UpdateContextResponse.h" -#include "rest/ConnectionInfo.h" - - - -/* **************************************************************************** -* -* UpdateContextElementResponse::UpdateContextElementResponse - -*/ -UpdateContextElementResponse::UpdateContextElementResponse() -{ - errorCode.keyNameSet("errorCode"); -} - - - -/* **************************************************************************** -* -* toJsonV1 - -*/ -std::string UpdateContextElementResponse::toJsonV1 -( - bool asJsonObject, - RequestType requestType -) -{ - std::string out = ""; - - out += startTag(); - - if ((errorCode.code != SccNone) && (errorCode.code != SccOk)) - { - out += errorCode.toJsonV1(false); - } - else - { - out += contextAttributeResponseVector.toJsonV1(asJsonObject, requestType); - } - - out += endTag(); - - return out; -} - - - -/* **************************************************************************** -* -* check - -*/ -std::string UpdateContextElementResponse::check -( - ApiVersion apiVersion, - bool asJsonObject, - RequestType requestType, - const std::string& predetectedError // Predetected Error, normally during parsing -) -{ - std::string res; - - if (!predetectedError.empty()) - { - errorCode.fill(SccBadRequest, predetectedError); - } - else if ((res = contextAttributeResponseVector.check(apiVersion, asJsonObject, requestType, "")) != "OK") - { - errorCode.fill(SccBadRequest, res); - } - else - { - return "OK"; - } - - return toJsonV1(asJsonObject, requestType); -} - - - -/* **************************************************************************** -* -* UpdateContextElementResponse::release - -*/ -void UpdateContextElementResponse::release(void) -{ - contextAttributeResponseVector.release(); - errorCode.release(); -} - - - -/* **************************************************************************** -* -* UpdateContextElementResponse::fill - -* -* NOTE -* This method is used in the service routine of 'PUT /v1/contextEntities/{entityId::id}. -* Only ONE response in the vector contextElementResponseVector of UpdateContextResponse is possible. -*/ -void UpdateContextElementResponse::fill(UpdateContextResponse* ucrsP) -{ - ContextElementResponse* cerP = ucrsP->contextElementResponseVector[0]; - - errorCode.fill(ucrsP->errorCode); - if (errorCode.code == SccNone) - { - errorCode.fill(SccOk, errorCode.details); - } - - if (ucrsP->contextElementResponseVector.size() != 0) - { - // - // Remove values from the context attributes - // - for (unsigned int aIx = 0; aIx < cerP->entity.attributeVector.size(); ++aIx) - { - // - // NOTE - // Only stringValue is cleared here (not numberValue nor boolValue, which are new for v2). - // This is OK for /v1, where all fields are strings. - // For /v2, we would need to reset the valueType to STRING as well, but since this function is used only - // in v1, this is not strictly necessary. - // However, it doesn't hurt, so that modification is included as well: - // cerP->entity.attributeVector[aIx]->valueType = orion::ValueTypeString - // - cerP->entity.attributeVector[aIx]->stringValue = ""; - cerP->entity.attributeVector[aIx]->valueType = orion::ValueTypeString; - } - - contextAttributeResponseVector.fill(cerP->entity.attributeVector, cerP->statusCode); - } - - - // - // Special treatment if only one contextElementResponse that is NOT FOUND and if - // UpdateContextElementResponse::errorCode is not 404 already - // - // Also if NO contextElementResponse is present - // - // These 'fixes' are mainly to maintain backward compatibility - // - if ((errorCode.code != SccContextElementNotFound) && (contextAttributeResponseVector.size() == 1) && (contextAttributeResponseVector[0]->statusCode.code == SccContextElementNotFound)) - { - errorCode.fill(SccContextElementNotFound); - } - else if ((errorCode.code != SccContextElementNotFound) && (contextAttributeResponseVector.size() == 0)) - { - errorCode.fill(SccContextElementNotFound); - } - else if (contextAttributeResponseVector.size() == 1) - { - // - // Now, if any error inside ContextAttributeResponse, move it to the outside, but only if we have ONLY ONE contextAttributeResponse - // and only if there is no error already in the 'external' errorCode. - // - if (((errorCode.code == SccNone) || (errorCode.code == SccOk)) && - ((contextAttributeResponseVector[0]->statusCode.code != SccNone) && (contextAttributeResponseVector[0]->statusCode.code != SccOk))) - { - errorCode.fill(contextAttributeResponseVector[0]->statusCode); - } - } - - // Now, if the external error code is 404 and 'details' is empty - add the name of the incoming entity::id as details - if ((errorCode.code == SccContextElementNotFound) && (errorCode.details.empty())) - { - if (ucrsP->contextElementResponseVector.size() == 1) - { - errorCode.details = ucrsP->contextElementResponseVector[0]->entity.id; - } - } -} diff --git a/src/lib/convenience/UpdateContextElementResponse.h b/src/lib/convenience/UpdateContextElementResponse.h deleted file mode 100644 index a9a2d05997..0000000000 --- a/src/lib/convenience/UpdateContextElementResponse.h +++ /dev/null @@ -1,70 +0,0 @@ -#ifndef SRC_LIB_CONVENIENCE_UPDATECONTEXTELEMENTRESPONSE_H_ -#define SRC_LIB_CONVENIENCE_UPDATECONTEXTELEMENTRESPONSE_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "convenience/ContextAttributeResponseVector.h" -#include "ngsi/StatusCode.h" -#include "rest/ConnectionInfo.h" - - - -/* **************************************************************************** -* -* Forward declaration -*/ -struct UpdateContextResponse; - - - -/* **************************************************************************** -* -* UpdateContextElementResponse - -* -* FIXME P5: AppendContextElementResponse and UpdateContextElementResponse are -* identical. They should 'merge' into ONE struct. -* This problem origins from an ?error? in the ngsi10 binding doc by NEC -* See: https://github.com/telefonicaid/fiware-orion/issues/106 -*/ -typedef struct UpdateContextElementResponse -{ - ContextAttributeResponseVector contextAttributeResponseVector; // Optional, but mandatory if success - StatusCode errorCode; // Optional, but mandatory if failure - - UpdateContextElementResponse(); - - std::string toJsonV1(bool asJsonObject, RequestType requestType); - void release(); - std::string check(ApiVersion apiVersion, - bool asJsonObject, - RequestType requestType, - const std::string& predetectedError); - void fill(UpdateContextResponse* ucrsP); -} UpdateContextElementResponse; - -#endif // SRC_LIB_CONVENIENCE_UPDATECONTEXTELEMENTRESPONSE_H_ diff --git a/src/lib/jsonParse/CMakeLists.txt b/src/lib/jsonParse/CMakeLists.txt deleted file mode 100644 index 1ea8952bdc..0000000000 --- a/src/lib/jsonParse/CMakeLists.txt +++ /dev/null @@ -1,77 +0,0 @@ -# Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -# -# This file is part of Orion Context Broker. -# -# Orion Context Broker is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Orion Context Broker is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -# General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -# -# For those usages not covered by this license please contact with -# iot_support at tid dot es - -CMAKE_MINIMUM_REQUIRED(VERSION 3.0) - -SET (SOURCES - jsonRequest.cpp - jsonParse.cpp - - jsonRegisterContextRequest.cpp - jsonDiscoverContextAvailabilityRequest.cpp - - jsonQueryContextRequest.cpp - jsonQueryContextResponse.cpp - jsonUpdateContextRequest.cpp - jsonUpdateContextResponse.cpp - jsonSubscribeContextRequest.cpp - jsonNotifyContextRequest.cpp - jsonUnsubscribeContextRequest.cpp - jsonUpdateContextSubscriptionRequest.cpp - - jsonRegisterProviderRequest.cpp - jsonUpdateContextElementRequest.cpp - jsonAppendContextElementRequest.cpp - jsonUpdateContextAttributeRequest.cpp -) - -SET (HEADERS - jsonRequest.h - jsonParse.h - JsonNode.h - - jsonRegisterContextRequest.h - jsonDiscoverContextAvailabilityRequest.h - - jsonQueryContextRequest.h - jsonQueryContextResponse.h - jsonUpdateContextRequest.h - jsonUpdateContextResponse.h - jsonSubscribeContextRequest.h - jsonNotifyContextRequest.h - jsonUnsubscribeContextRequest.h - jsonUpdateContextSubscriptionRequest.h - - jsonRegisterProviderRequest.h - jsonUpdateContextElementRequest.h - jsonAppendContextElementRequest.h - jsonUpdateContextAttributeRequest.h -) - - - -# Include directories -# ----------------------------------------------------------------- -include_directories("${PROJECT_SOURCE_DIR}/src/lib") - - -# Library declaration -# ----------------------------------------------------------------- -ADD_LIBRARY(jsonParse STATIC ${SOURCES} ${HEADERS}) diff --git a/src/lib/jsonParse/JsonNode.h b/src/lib/jsonParse/JsonNode.h deleted file mode 100644 index dc707489f7..0000000000 --- a/src/lib/jsonParse/JsonNode.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef SRC_LIB_JSONPARSE_JSONNODE_H_ -#define SRC_LIB_JSONPARSE_JSONNODE_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include - -#include "ngsi/Request.h" -#include "ngsi/ParseData.h" - - - -/* **************************************************************************** -* -* JsonNodeTreat - -*/ -typedef std::string (*JsonNodeTreat)(const std::string& path, const std::string& value, ParseData* reqDataP); - - - -/* **************************************************************************** -* -* JsonNode - -*/ -typedef struct JsonNode -{ - std::string path; - JsonNodeTreat treat; -} JsonNode; - -#endif // SRC_LIB_JSONPARSE_JSONNODE_H_ diff --git a/src/lib/jsonParse/jsonAppendContextElementRequest.cpp b/src/lib/jsonParse/jsonAppendContextElementRequest.cpp deleted file mode 100644 index 8707051965..0000000000 --- a/src/lib/jsonParse/jsonAppendContextElementRequest.cpp +++ /dev/null @@ -1,258 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/globals.h" -#include "convenience/AppendContextElementRequest.h" -#include "jsonParse/jsonParse.h" -#include "jsonParse/JsonNode.h" -#include "jsonParse/jsonAppendContextElementRequest.h" -#include "parse/nullTreat.h" -#include "ngsi/Request.h" -#include "rest/ConnectionInfo.h" -#include "rest/uriParamNames.h" - - - -/* **************************************************************************** -* -* contextAttribute - -*/ -static std::string contextAttribute(const std::string& path, const std::string& value, ParseData* reqData) -{ - LM_T(LmtParse, ("Got an attribute")); - reqData->acer.attributeP = new ContextAttribute(); - reqData->acer.res.contextAttributeVector.push_back(reqData->acer.attributeP); - return "OK"; -} - - - -/* **************************************************************************** -* -* contextAttributeName - -*/ -static std::string contextAttributeName(const std::string& path, const std::string& value, ParseData* reqData) -{ - LM_T(LmtParse, ("Got an attribute name: %s", value.c_str())); - reqData->acer.attributeP->name = safeValue(value); - return "OK"; -} - - - -/* **************************************************************************** -* -* contextAttributeType - -*/ -static std::string contextAttributeType(const std::string& path, const std::string& value, ParseData* reqData) -{ - LM_T(LmtParse, ("Got an attribute type: %s", value.c_str())); - reqData->acer.attributeP->type = value; - return "OK"; -} - - - -/* **************************************************************************** -* -* contextAttributeValue - -*/ -static std::string contextAttributeValue(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got an attribute value: %s", value.c_str())); - parseDataP->lastContextAttribute = parseDataP->acer.attributeP; - parseDataP->acer.attributeP->stringValue = value; - parseDataP->acer.attributeP->valueType = orion::ValueTypeString; - return "OK"; -} - - - -/* **************************************************************************** -* -* contextMetadata - -*/ -static std::string contextMetadata(const std::string& path, const std::string& value, ParseData* reqData) -{ - LM_T(LmtParse, ("Got a metadata")); - reqData->acer.metadataP = new Metadata(); - reqData->acer.attributeP->metadataVector.push_back(reqData->acer.metadataP); - return "OK"; -} - - - -/* **************************************************************************** -* -* contextMetadataName - -*/ -static std::string contextMetadataName(const std::string& path, const std::string& value, ParseData* reqData) -{ - LM_T(LmtParse, ("Got a metadata name '%s'", value.c_str())); - reqData->acer.metadataP->name = safeValue(value); - return "OK"; -} - - - -/* **************************************************************************** -* -* contextMetadataType - -*/ -static std::string contextMetadataType(const std::string& path, const std::string& value, ParseData* reqData) -{ - LM_T(LmtParse, ("Got a metadata type '%s'", value.c_str())); - reqData->acer.metadataP->type = value; - return "OK"; -} - - - -/* **************************************************************************** -* -* contextMetadataValue - -*/ -static std::string contextMetadataValue(const std::string& path, const std::string& value, ParseData* reqData) -{ - LM_T(LmtParse, ("Got a metadata value '%s'", value.c_str())); - reqData->acer.metadataP->stringValue = value; - reqData->acer.metadataP->valueType = orion::ValueTypeString; - return "OK"; -} - - - -/* **************************************************************************** -* -* entityIdId - -*/ -static std::string entityIdId(const std::string& path, const std::string& value, ParseData* reqDataP) -{ - reqDataP->acer.res.entity.id = value; - LM_T(LmtParse, ("Set 'id' to '%s' for an entity", reqDataP->acer.res.entity.id.c_str())); - - return "OK"; -} - - - -/* **************************************************************************** -* -* entityIdType - -*/ -static std::string entityIdType(const std::string& path, const std::string& value, ParseData* reqDataP) -{ - reqDataP->acer.res.entity.type = value; - LM_T(LmtParse, ("Set 'type' to '%s' for an entity", reqDataP->acer.res.entity.type.c_str())); - - return "OK"; -} - - - -/* **************************************************************************** -* -* entityIdIsPattern - -*/ -static std::string entityIdIsPattern(const std::string& path, const std::string& value, ParseData* reqDataP) -{ - LM_T(LmtParse, ("Got an entityId:isPattern: '%s'", value.c_str())); - - if (!isTrue(value) && !isFalse(value)) - { - return "invalid isPattern value for entity: /" + value + "/"; - } - - reqDataP->acer.res.entity.isPattern = value; - - return "OK"; -} - - - -/* **************************************************************************** -* -* jsonAcerParseVector - -*/ -JsonNode jsonAcerParseVector[] = -{ - { "/id", entityIdId }, - { "/type", entityIdType }, - { "/isPattern", entityIdIsPattern }, - - { "/attributes", jsonNullTreat }, - { "/attributes/attribute", contextAttribute }, - { "/attributes/attribute/name", contextAttributeName }, - { "/attributes/attribute/type", contextAttributeType }, - { "/attributes/attribute/value", contextAttributeValue }, - - { "/attributes/attribute/metadatas", jsonNullTreat }, - { "/attributes/attribute/metadatas/metadata", contextMetadata }, - { "/attributes/attribute/metadatas/metadata/name", contextMetadataName }, - { "/attributes/attribute/metadatas/metadata/type", contextMetadataType }, - { "/attributes/attribute/metadatas/metadata/value", contextMetadataValue }, - - { "LAST", NULL } -}; - - - -/* **************************************************************************** -* -* jsonAcerInit - -*/ -void jsonAcerInit(ParseData* reqData) -{ - reqData->acer.attributeP = NULL; - reqData->acer.metadataP = NULL; -} - - - -/* **************************************************************************** -* -* jsonAcerRelease - -*/ -void jsonAcerRelease(ParseData* reqData) -{ - reqData->acer.res.release(); -} - - - -/* **************************************************************************** -* -* jsonAcerCheck - -*/ -std::string jsonAcerCheck(ParseData* reqData, ConnectionInfo* ciP) -{ - bool asJsonObject = (ciP->uriParam[URI_PARAM_ATTRIBUTE_FORMAT] == "object" && ciP->outMimeType == JSON); - return reqData->acer.res.check(ciP->apiVersion, asJsonObject, AppendContextElement, reqData->errorString); -} diff --git a/src/lib/jsonParse/jsonAppendContextElementRequest.h b/src/lib/jsonParse/jsonAppendContextElementRequest.h deleted file mode 100644 index 0f230031d3..0000000000 --- a/src/lib/jsonParse/jsonAppendContextElementRequest.h +++ /dev/null @@ -1,67 +0,0 @@ -#ifndef SRC_LIB_JSONPARSE_JSONAPPENDCONTEXTELEMENTREQUEST_H_ -#define SRC_LIB_JSONPARSE_JSONAPPENDCONTEXTELEMENTREQUEST_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "jsonParse/JsonNode.h" - - - -/* **************************************************************************** -* -* jsonAcerParseVector - -*/ -extern JsonNode jsonAcerParseVector[]; - - - -/* **************************************************************************** -* -* jsonAcerInit - -*/ -extern void jsonAcerInit(ParseData* reqData); - - - -/* **************************************************************************** -* -* jsonAcerRelease - -*/ -extern void jsonAcerRelease(ParseData* reqData); - - - -/* **************************************************************************** -* -* jsonAcerCheck - -*/ -extern std::string jsonAcerCheck(ParseData* reqData, ConnectionInfo* ciP); - - - -#endif // SRC_LIB_JSONPARSE_JSONAPPENDCONTEXTELEMENTREQUEST_H_ diff --git a/src/lib/jsonParse/jsonDiscoverContextAvailabilityRequest.cpp b/src/lib/jsonParse/jsonDiscoverContextAvailabilityRequest.cpp deleted file mode 100755 index 426d8900e2..0000000000 --- a/src/lib/jsonParse/jsonDiscoverContextAvailabilityRequest.cpp +++ /dev/null @@ -1,283 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/globals.h" -#include "alarmMgr/alarmMgr.h" - -#include "jsonParse/JsonNode.h" -#include "jsonParse/jsonDiscoverContextAvailabilityRequest.h" -#include "ngsi/ContextAttribute.h" -#include "ngsi/EntityId.h" -#include "ngsi9/DiscoverContextAvailabilityRequest.h" -#include "parse/nullTreat.h" -#include "rest/ConnectionInfo.h" - - - -/* **************************************************************************** -* -* entityId - -*/ -static std::string entityId(const std::string& path, const std::string& value, ParseData* reqDataP) -{ - LM_T(LmtParse, ("%s: %s", path.c_str(), value.c_str())); - - reqDataP->dcar.entityIdP = new EntityId(); - - LM_T(LmtNew, ("New entityId at %p", reqDataP->dcar.entityIdP)); - reqDataP->dcar.entityIdP->id = ""; - reqDataP->dcar.entityIdP->type = ""; - reqDataP->dcar.entityIdP->isPattern = "false"; - - reqDataP->dcar.res.entityIdVector.push_back(reqDataP->dcar.entityIdP); - - return "OK"; -} - - - -/* **************************************************************************** -* -* entityIdId - -*/ -static std::string entityIdId(const std::string& path, const std::string& value, ParseData* reqDataP) -{ - reqDataP->dcar.entityIdP->id = value; - LM_T(LmtParse, ("Set 'id' to '%s' for an entity", reqDataP->dcar.entityIdP->id.c_str())); - - return "OK"; -} - - - -/* **************************************************************************** -* -* entityIdType - -*/ -static std::string entityIdType(const std::string& path, const std::string& value, ParseData* reqDataP) -{ - reqDataP->dcar.entityIdP->type = value; - LM_T(LmtParse, ("Set 'type' to '%s' for an entity", reqDataP->dcar.entityIdP->type.c_str())); - - return "OK"; -} - - - -/* **************************************************************************** -* -* entityIdIsPattern - -*/ -static std::string entityIdIsPattern(const std::string& path, const std::string& value, ParseData* reqDataP) -{ - LM_T(LmtParse, ("Got an entityId:isPattern: '%s'", value.c_str())); - - reqDataP->dcar.entityIdP->isPattern = value; - - if (!isTrue(value) && !isFalse(value)) - { - return "invalid isPattern value for entity: /" + value + "/"; - } - - return "OK"; -} - - - -/* **************************************************************************** -* -* attribute - -*/ -static std::string attribute(const std::string& path, const std::string& value, ParseData* reqDataP) -{ - LM_T(LmtParse, ("Got an attribute: '%s'", value.c_str())); - - reqDataP->dcar.res.attributeList.push_back(value); - - return "OK"; -} - - - -/* **************************************************************************** -* -* attributeList - -*/ -static std::string attributeList(const std::string& path, const std::string& value, ParseData* reqDataP) -{ - LM_T(LmtParse, ("Got an attributeList: '%s'", value.c_str())); - return "OK"; -} - - - -/* **************************************************************************** -* -* restriction - -*/ -static std::string restriction(const std::string& path, const std::string& value, ParseData* reqDataP) -{ - reqDataP->dcar.res.restrictions += 1; - return "OK"; -} - - - -/* **************************************************************************** -* -* attributeExpression - -*/ -static std::string attributeExpression(const std::string& path, const std::string& value, ParseData* reqDataP) -{ - LM_T(LmtParse, ("Got an attributeExpression: '%s'", value.c_str())); - - reqDataP->dcar.res.restriction.attributeExpression.set(value); - - if (value.empty()) - { - alarmMgr.badInput(clientIp, "empty attribute expression"); - return "Empty attribute expression"; - } - - return "OK"; -} - - - -/* **************************************************************************** -* -* operationScope - -*/ -static std::string operationScope(const std::string& path, const std::string& value, ParseData* reqDataP) -{ - LM_T(LmtParse, ("Got an operationScope")); - - reqDataP->dcar.scopeP = new Scope(); - reqDataP->dcar.res.restriction.scopeVector.push_back(reqDataP->dcar.scopeP); - reqDataP->dcar.scopeP->type = ""; - reqDataP->dcar.scopeP->value = ""; - - return "OK"; -} - - - -/* **************************************************************************** -* -* scopeType - -*/ -static std::string scopeType(const std::string& path, const std::string& value, ParseData* reqDataP) -{ - reqDataP->dcar.scopeP->type = value; - LM_T(LmtParse, ("Set scope 'type' to '%s' for a scope", reqDataP->dcar.scopeP->type.c_str())); - return "OK"; -} - - - -/* **************************************************************************** -* -* scopeValue - -*/ -static std::string scopeValue(const std::string& path, const std::string& value, ParseData* reqDataP) -{ - reqDataP->dcar.scopeP->value = value; - LM_T(LmtParse, ("Set scope 'value' to '%s' for a scope", reqDataP->dcar.scopeP->value.c_str())); - - return "OK"; -} - - - -/* **************************************************************************** -* -* jsonDcarInit - -*/ -void jsonDcarInit(ParseData* reqDataP) -{ - jsonDcarRelease(reqDataP); - - reqDataP->dcar.entityIdP = NULL; - reqDataP->dcar.scopeP = NULL; - reqDataP->errorString = ""; - - reqDataP->dcar.res.restrictions = 0; - reqDataP->dcar.res.restriction.attributeExpression.set(""); -} - - - -/* **************************************************************************** -* -* jsonDcarRelease - -*/ -void jsonDcarRelease(ParseData* reqDataP) -{ - reqDataP->dcar.res.release(); -} - - - -/* **************************************************************************** -* -* jsonDcarCheck - -*/ -std::string jsonDcarCheck(ParseData* reqDataP, ConnectionInfo* ciP) -{ - return reqDataP->dcar.res.check(reqDataP->errorString); -} - - - - -/* **************************************************************************** -* -* dcarParseVector - -*/ -JsonNode jsonDcarParseVector[] = -{ - { "/entities", jsonNullTreat }, - { "/entities/entity", entityId }, - { "/entities/entity/id", entityIdId }, - { "/entities/entity/type", entityIdType }, - { "/entities/entity/isPattern", entityIdIsPattern }, - - { "/attributes", attributeList }, - { "/attributes/attribute", attribute }, - - { "/restriction", restriction }, - { "/restriction/attributeExpression", attributeExpression }, - { "/restriction/scopes", jsonNullTreat }, - { "/restriction/scopes/scope", operationScope }, - { "/restriction/scopes/scope/type", scopeType }, - { "/restriction/scopes/scope/value", scopeValue }, - - { "LAST", NULL } -}; diff --git a/src/lib/jsonParse/jsonDiscoverContextAvailabilityRequest.h b/src/lib/jsonParse/jsonDiscoverContextAvailabilityRequest.h deleted file mode 100644 index a67266393a..0000000000 --- a/src/lib/jsonParse/jsonDiscoverContextAvailabilityRequest.h +++ /dev/null @@ -1,65 +0,0 @@ -#ifndef SRC_LIB_JSONPARSE_JSONDISCOVERCONTEXTAVAILABILITYREQUEST_H_ -#define SRC_LIB_JSONPARSE_JSONDISCOVERCONTEXTAVAILABILITYREQUEST_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include - -#include "jsonParse/JsonNode.h" -#include "rest/ConnectionInfo.h" - - - -/* **************************************************************************** -* -* dcarParseVector - -*/ -extern JsonNode jsonDcarParseVector[]; - - - -/* **************************************************************************** -* -* jsonDcarInit - -*/ -extern void jsonDcarInit(ParseData* reqDataP); - - - -/* **************************************************************************** -* -* jsonDcarRelease - -*/ -extern void jsonDcarRelease(ParseData* reqDataP); - - - -/* **************************************************************************** -* -* jsonDcarCheck - -*/ -extern std::string jsonDcarCheck(ParseData* reqDataP, ConnectionInfo* ciP); - -#endif // SRC_LIB_JSONPARSE_JSONDISCOVERCONTEXTAVAILABILITYREQUEST_H_ diff --git a/src/lib/jsonParse/jsonNotifyContextRequest.cpp b/src/lib/jsonParse/jsonNotifyContextRequest.cpp deleted file mode 100755 index b777f8c857..0000000000 --- a/src/lib/jsonParse/jsonNotifyContextRequest.cpp +++ /dev/null @@ -1,352 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "common/globals.h" - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "ngsi/ContextAttribute.h" -#include "ngsi/Metadata.h" - -#include "jsonParse/JsonNode.h" -#include "jsonParse/jsonParse.h" -#include "parse/nullTreat.h" -#include "jsonParse/jsonNotifyContextRequest.h" - -#include "rest/ConnectionInfo.h" - - - -/* **************************************************************************** -* -* subscriptionId - -*/ -static std::string subscriptionId(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a subscriptionId: '%s'", value.c_str())); - parseDataP->ncr.res.subscriptionId.set(value); - return "OK"; -} - - - -/* **************************************************************************** -* -* originator - -*/ -static std::string originator(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got an originator: '%s'", value.c_str())); - parseDataP->ncr.res.originator.set(value); - return "OK"; -} - - - -/* **************************************************************************** -* -* contextResponse - -*/ -static std::string contextResponse(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - parseDataP->ncr.cerP = new ContextElementResponse(); - parseDataP->ncr.res.contextElementResponseVector.push_back(parseDataP->ncr.cerP); - return "OK"; -} - - - -/* **************************************************************************** -* -* entityIdId - -*/ -static std::string entityIdId(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - parseDataP->ncr.cerP->entity.id = value; - LM_T(LmtParse, ("Set 'id' to '%s' for an entity", parseDataP->ncr.cerP->entity.id.c_str())); - - return "OK"; -} - - - -/* **************************************************************************** -* -* entityIdType - -*/ -static std::string entityIdType(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - parseDataP->ncr.cerP->entity.type = value; - LM_T(LmtParse, ("Set 'type' to '%s' for an entity", parseDataP->ncr.cerP->entity.type.c_str())); - - return "OK"; -} - - - -/* **************************************************************************** -* -* entityIdIsPattern - -*/ -static std::string entityIdIsPattern(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got an entityId:isPattern: '%s'", value.c_str())); - parseDataP->ncr.cerP->entity.isPattern = value; - - if (!isTrue(value) && !isFalse(value)) - { - return "invalid isPattern value for entity: /" + value + "/"; - } - - return "OK"; -} - - - -/* **************************************************************************** -* -* attribute - -*/ -static std::string attribute(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Creating an attribute")); - parseDataP->ncr.attributeP = new ContextAttribute(); - parseDataP->ncr.cerP->entity.attributeVector.push_back(parseDataP->ncr.attributeP); - return "OK"; -} - - - -/* **************************************************************************** -* -* attributeName - -*/ -static std::string attributeName(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got an attribute name: '%s'", value.c_str())); - parseDataP->ncr.attributeP->name = safeValue(value); - return "OK"; -} - - - -/* **************************************************************************** -* -* attributeType - -*/ -static std::string attributeType(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got an attribute type: '%s'", value.c_str())); - parseDataP->ncr.attributeP->type = value; - return "OK"; -} - - - -/* **************************************************************************** -* -* attributeValue - -*/ -static std::string attributeValue(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got an attribute value: '%s'", value.c_str())); - parseDataP->lastContextAttribute = parseDataP->ncr.attributeP; - parseDataP->ncr.attributeP->stringValue = value; - parseDataP->ncr.attributeP->valueType = orion::ValueTypeString; - return "OK"; -} - - - -/* **************************************************************************** -* -* statusCodeCode - -*/ -static std::string statusCodeCode(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a statusCode code: '%s'", value.c_str())); - parseDataP->ncr.cerP->statusCode.code = (HttpStatusCode) atoi(value.c_str()); - LM_T(LmtParse, ("Got a statusCode code: %d", (int) parseDataP->ncr.cerP->statusCode.code)); - return "OK"; -} - - - -/* **************************************************************************** -* -* statusCodeReasonPhrase - -*/ -static std::string statusCodeReasonPhrase(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a statusCode reasonPhrase: '%s'", value.c_str())); - parseDataP->ncr.cerP->statusCode.reasonPhrase = value; // OK - parsing step reading reasonPhrase - return "OK"; -} - - - -/* **************************************************************************** -* -* statusCodeDetails - -*/ -static std::string statusCodeDetails(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a statusCode details: '%s'", value.c_str())); - parseDataP->ncr.cerP->statusCode.details = value; - return "OK"; -} - - - -/* **************************************************************************** -* -* attributeMetadata - -*/ -static std::string attributeMetadata(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Creating an attributeMetadata")); - parseDataP->ncr.attributeMetadataP = new Metadata(); - parseDataP->ncr.attributeP->metadataVector.push_back(parseDataP->ncr.attributeMetadataP); - return "OK"; -} - - - -/* **************************************************************************** -* -* attributeMetadataName - -*/ -static std::string attributeMetadataName(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got an attributeMetadata name: '%s'", value.c_str())); - parseDataP->ncr.attributeMetadataP->name = safeValue(value); - return "OK"; -} - - - -/* **************************************************************************** -* -* attributeMetadataType - -*/ -static std::string attributeMetadataType(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got an attributeMetadata type: '%s'", value.c_str())); - parseDataP->ncr.attributeMetadataP->type = value; - return "OK"; -} - - - -/* **************************************************************************** -* -* attributeMetadataValue - -*/ -static std::string attributeMetadataValue(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got an attributeMetadata value: '%s'", value.c_str())); - parseDataP->ncr.attributeMetadataP->stringValue = value; - parseDataP->ncr.attributeMetadataP->valueType = orion::ValueTypeString; - return "OK"; -} - - - -#define CELEM "/contextResponses/contextResponse/contextElement" -/* **************************************************************************** -* -* ncrParseVector - -*/ -JsonNode jsonNcrParseVector[] = -{ - { "/subscriptionId", subscriptionId }, - { "/originator", originator }, - - { "/contextResponses", jsonNullTreat }, - { "/contextResponses/contextResponse", contextResponse }, - { CELEM, jsonNullTreat }, - { CELEM "/id", entityIdId }, - { CELEM "/type", entityIdType }, - { CELEM "/isPattern", entityIdIsPattern }, - - { CELEM "/attributes", jsonNullTreat }, - { CELEM "/attributes/attribute", attribute }, - { CELEM "/attributes/attribute/name", attributeName }, - { CELEM "/attributes/attribute/type", attributeType }, - { CELEM "/attributes/attribute/value", attributeValue }, - - { CELEM "/attributes/attribute/metadatas", jsonNullTreat }, - { CELEM "/attributes/attribute/metadatas/metadata", attributeMetadata }, - { CELEM "/attributes/attribute/metadatas/metadata/name", attributeMetadataName }, - { CELEM "/attributes/attribute/metadatas/metadata/type", attributeMetadataType }, - { CELEM "/attributes/attribute/metadatas/metadata/value", attributeMetadataValue }, - - { "/contextResponses/contextResponse/statusCode", jsonNullTreat }, - { "/contextResponses/contextResponse/statusCode/code", statusCodeCode }, - { "/contextResponses/contextResponse/statusCode/reasonPhrase", statusCodeReasonPhrase }, - { "/contextResponses/contextResponse/statusCode/details", statusCodeDetails }, - - { "LAST", NULL } -}; - - - -/* **************************************************************************** -* -* jsonNcrInit - -*/ -void jsonNcrInit(ParseData* parseDataP) -{ - jsonNcrRelease(parseDataP); - - parseDataP->ncr.cerP = NULL; - parseDataP->ncr.attributeP = NULL; - parseDataP->ncr.attributeMetadataP = NULL; -} - - - -/* **************************************************************************** -* -* jsonNcrRelease - -*/ -void jsonNcrRelease(ParseData* parseDataP) -{ - parseDataP->ncr.res.release(); -} - - - -/* **************************************************************************** -* -* jsonNcrCheck - -*/ -std::string jsonNcrCheck(ParseData* parseDataP, ConnectionInfo* ciP) -{ - return parseDataP->ncr.res.check(ciP->apiVersion, parseDataP->errorString); -} diff --git a/src/lib/jsonParse/jsonNotifyContextRequest.h b/src/lib/jsonParse/jsonNotifyContextRequest.h deleted file mode 100644 index 6d16c0125c..0000000000 --- a/src/lib/jsonParse/jsonNotifyContextRequest.h +++ /dev/null @@ -1,65 +0,0 @@ -#ifndef SRC_LIB_JSONPARSE_JSONNOTIFYCONTEXTREQUEST_H_ -#define SRC_LIB_JSONPARSE_JSONNOTIFYCONTEXTREQUEST_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include - -#include "jsonParse/JsonNode.h" -#include "rest/ConnectionInfo.h" - - - -/* **************************************************************************** -* -* ncrParseVector - -*/ -extern JsonNode jsonNcrParseVector[]; - - - -/* **************************************************************************** -* -* jsonNcrInit - -*/ -extern void jsonNcrInit(ParseData* reqDataP); - - - -/* **************************************************************************** -* -* jsonNcrRelease - -*/ -extern void jsonNcrRelease(ParseData* reqDataP); - - - -/* **************************************************************************** -* -* jsonNcrCheck - -*/ -extern std::string jsonNcrCheck(ParseData* reqDataP, ConnectionInfo* ciP); - -#endif // SRC_LIB_JSONPARSE_JSONNOTIFYCONTEXTREQUEST_H_ diff --git a/src/lib/jsonParse/jsonParse.cpp b/src/lib/jsonParse/jsonParse.cpp deleted file mode 100644 index db9043784b..0000000000 --- a/src/lib/jsonParse/jsonParse.cpp +++ /dev/null @@ -1,590 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include - -#include "common/limits.h" - -// -// http://www.boost.org/doc/libs/1_31_0/libs/spirit/doc/grammar.html: -// -// if a grammar is intended to be used in multithreaded code, we should then define -// BOOST_SPIRIT_THREADSAFE before including any spirit header files. -// In this case it will also be required to link against Boost.Threads -// -#define BOOST_SPIRIT_THREADSAFE - -#include -#include -#include - -#include -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/statistics.h" -#include "common/clockFunctions.h" -#include "alarmMgr/alarmMgr.h" - -#include "ngsi/Request.h" -#include "ngsi/ParseData.h" - -#include "parse/compoundValue.h" -#include "parse/CompoundValueNode.h" -#include "parse/forbiddenChars.h" - -#include "jsonParse/JsonNode.h" -#include "jsonParse/jsonParse.h" - -using boost::property_tree::ptree; -using namespace orion; - - - -/* **************************************************************************** -* -* compoundRootV - -* -*/ -static const char* compoundRootV[] = -{ - "/contextElements/contextElement/attributes/attribute/value", - "/attributes/attribute/value", - "/contextResponses/contextResponse/contextElement/attributes/attribute/value", - "/value" -}; - - - -/* **************************************************************************** -* -* isCompoundPath - -* -* This function examines a path to see whether we are inside a compound value or not. -* Also, it returns the root of the compound (found in 'compoundValueRootV') and also -* the 'rest' of the path, i.e. its relative path inside the compound. -* -* If the path doesn't belong to any compound, FALSE is returned. -*/ -static bool isCompoundPath(const char* path) -{ - - for (unsigned int ix = 0; ix < sizeof(compoundRootV) / sizeof(compoundRootV[0]); ++ix) - { - size_t len = strlen(compoundRootV[ix]); - - if (strlen(path) < len) - { - continue; - } - - if (strncmp(compoundRootV[ix], path, len) == 0) - { - return true; - } - } - - return false; -} - - - -/* **************************************************************************** -* -* isScopeValue - -* -* A path is a scope value if the path ends with /scopes/scope/value -*/ -static bool isScopeValue(const char* path) -{ - int slen = strlen(path); - const char* end = "/scopes/scope/value"; - int start = slen - strlen(end); - - if (start < 0) - { - return false; - } - - if (strcmp(&path[start], end) == 0) - { - return true; - } - - return false; -} - - - -/* **************************************************************************** -* -* treat - -*/ -static bool treat -( - ConnectionInfo* ciP, - const std::string& path, - const std::string& value, - JsonNode* parseVector, - ParseData* parseDataP -) -{ - LM_T(LmtTreat, ("Treating path '%s', value '%s'", path.c_str(), value.c_str())); - - for (unsigned int ix = 0; parseVector[ix].path != "LAST"; ++ix) - { - // - // Before treating a node, a check is made that the value of the node has no forbidden - // characters. - // - // For scopes, the check for forbiddenChars is postponed to the check() method of scope - // - if (!isScopeValue(path.c_str())) - { - if (forbiddenChars(value.c_str()) == true) - { - alarmMgr.badInput(clientIp, "found a forbidden value", value); - ciP->httpStatusCode = SccBadRequest; - ciP->answer = std::string("Illegal value for JSON field"); - return false; - } - } - - if (path == parseVector[ix].path) - { - LM_T(LmtTreat, ("calling treat function for '%s': '%s'", path.c_str(), value.c_str())); - std::string res = parseVector[ix].treat(path, value, parseDataP); - LM_T(LmtTreat, ("called treat function for '%s'. result: '%s'", path.c_str(), res.c_str())); - - return true; - } - } - - return false; -} - - - -/* **************************************************************************** -* -* getArrayElementName - -*/ -static std::string getArrayElementName(const std::string& arrayName) -{ - // Get the name of the array - int pos = arrayName.find_last_of("/"); - std::string elementName = arrayName.substr(pos + 1); - - // Take out the last letter (if it is an array it will delete the 's' character - // that is present in every case - elementName = elementName.substr(0, elementName.length() - 1); - - // Is the singular form changing 'ie' for 'y' ?? - if (elementName.length() > 2 && elementName.substr(elementName.length() - 2).compare("ie") == 0) - { - elementName.replace(elementName.length() - 2, 2, "y"); - } - - return elementName; -} - - - -/* **************************************************************************** -* -* nodeType - -*/ -std::string nodeType(const std::string& nodeName, const std::string& value, orion::ValueType* typeP) -{ - bool isObject = (nodeName.empty()) && (value.empty()); - bool isString = (!nodeName.empty()) && (!value.empty()); - bool isVector = (!nodeName.empty()) && (value.empty()); - - if (isObject) - { - *typeP = orion::ValueTypeObject; - return "Object"; - } - - if (isString) - { - *typeP = orion::ValueTypeString; - return "String"; - } - - if (isVector) - { - *typeP = orion::ValueTypeVector; - return "Vector"; - } - - // Simple String inside vector - return "String"; -} - - - -/* **************************************************************************** -* -* eatCompound - -* -* This is a recusive function. -*/ -static void eatCompound -( - ConnectionInfo* ciP, - orion::CompoundValueNode* containerP, - boost::property_tree::ptree::value_type& v, - const std::string& indent, - int deep -) -{ - if (deep > MAX_JSON_NESTING) - { - std::string details = std::string("compound attribute value has overpassed maximum nesting limit"); - alarmMgr.badInput(clientIp, details); - - ciP->httpStatusCode = SccBadRequest; - ciP->answer = details; - - return; - } - - std::string nodeName = v.first.data(); - std::string nodeValue = v.second.data(); - boost::property_tree::ptree subtree1 = (boost::property_tree::ptree) v.second; - int noOfChildren = subtree1.size(); - - if (containerP == NULL) - { - LM_T(LmtCompoundValue, ("COMPOUND: '%s'", nodeName.c_str())); - containerP = new CompoundValueNode(ValueTypeObject); - ciP->compoundValueRoot = containerP; - } - else - { - if ((!nodeName.empty()) && (!nodeValue.empty())) // Named String - { - if (forbiddenChars(nodeValue.c_str()) == true) - { - alarmMgr.badInput(clientIp, "found a forbidden value in compound", nodeValue); - - ciP->httpStatusCode = SccBadRequest; - ciP->answer = std::string("Illegal value for JSON field"); - return; - } - - containerP->add(orion::ValueTypeString, nodeName, nodeValue); - LM_T(LmtCompoundValue, ("Added string '%s' (value: '%s')", - nodeName.c_str(), - nodeValue.c_str())); - } - else if ((nodeName.empty()) && (nodeValue.empty()) && (noOfChildren == 0)) // Unnamed String with EMPTY VALUE - { - LM_T(LmtCompoundValue, ("'Bad' input - looks like a container but it is an EMPTY STRING - no name, no value")); - containerP->add(orion::ValueTypeString, "item", ""); - } - else if ((!nodeName.empty()) && (nodeValue.empty()) && (noOfChildren == 0)) // Named Empty string - { - LM_T(LmtCompoundValue, ("Adding container '%s'", nodeName.c_str())); - containerP = containerP->add(ValueTypeString, nodeName, ""); - } - else if ((!nodeName.empty()) && (nodeValue.empty())) // Named Container - { - LM_T(LmtCompoundValue, ("Adding container '%s'", nodeName.c_str())); - containerP = containerP->add(ValueTypeObject, nodeName, ""); - } - else if ((nodeName.empty()) && (nodeValue.empty())) // Name-Less container - { - LM_T(LmtCompoundValue, ("Adding name-less container (parent may be a Vector!)")); - containerP->valueType = ValueTypeVector; - containerP = containerP->add(ValueTypeObject, "item", ""); - } - else if ((nodeName.empty()) && (!nodeValue.empty())) // Name-Less String + its container is a vector - { - containerP->valueType = ValueTypeVector; - LM_T(LmtCompoundValue, ("Set to be a vector")); - containerP->add(orion::ValueTypeString, "item", nodeValue); - LM_T(LmtCompoundValue, ("Added a name-less string (value: '%s')", nodeValue.c_str())); - } - else - { - LM_E(("Runtime Error (impossible siutation)")); - } - } - - boost::property_tree::ptree subtree = (boost::property_tree::ptree) v.second; - BOOST_FOREACH(boost::property_tree::ptree::value_type &v2, subtree) - { - eatCompound(ciP, containerP, v2, indent + " ", deep + 1); - } -} - - - -/* **************************************************************************** -* -* jsonParse - -*/ -static std::string jsonParse -( - ConnectionInfo* ciP, - boost::property_tree::ptree::value_type& v, - const std::string& _path, - JsonNode* parseVector, - ParseData* parseDataP -) -{ - std::string nodeName = v.first.data(); - std::string nodeValue = v.second.data(); - std::string arrayElementName = getArrayElementName(_path); - std::string path = _path; - bool treated; - - // If the node name is empty, boost will yield an empty name. This will happen only in the case of a vector. - // See: http://www.boost.org/doc/libs/1_41_0/doc/html/boost_propertytree/parsers.html#boost_propertytree.parsers.json_parser - if (!nodeName.empty()) - { - // This detects whether we are trying to use an object within an object instead of an one-item array. - // We don't allow the first case, hence the exception thrown. - // However, this restriction is not valid inside Compound Values. - if ((nodeName != arrayElementName) || (ciP->inCompoundValue == true)) - { - path = path + "/" + nodeName; - } - else - { - throw std::logic_error("The object '" + path + "' may not have a child named '" + nodeName + "'"); - } - } - else - { - path = path + "/" + arrayElementName; - } - - treated = treat(ciP, path, nodeValue, parseVector, parseDataP); - - - boost::property_tree::ptree subtree = (boost::property_tree::ptree) v.second; - int noOfChildren = subtree.size(); - if ((isCompoundPath(path.c_str()) == true) && (nodeValue.empty()) && (noOfChildren != 0) && (treated == true)) - { - - LM_T(LmtCompoundValue, ("Calling eatCompound for '%s'", path.c_str())); - eatCompound(ciP, NULL, v, "", 0); - compoundValueEnd(ciP, parseDataP); - - if (ciP->httpStatusCode != SccOk) - { - return ciP->answer; - } - - return "OK"; - } - else if (treated == false) - { - ciP->httpStatusCode = SccBadRequest; - if (ciP->answer.empty()) - { - ciP->answer = std::string("JSON Parse Error: unknown field: ") + path.c_str(); - } - - alarmMgr.badInput(clientIp, ciP->answer); - return ciP->answer; - } - - if (noOfChildren == 0) - { - return "OK"; - } - - subtree = (boost::property_tree::ptree) v.second; - BOOST_FOREACH(boost::property_tree::ptree::value_type &v2, subtree) - { - std::string out = jsonParse(ciP, v2, path, parseVector, parseDataP); - if (out != "OK") - { - alarmMgr.badInput(clientIp, "JSON Parse Error", out); - return out; - } - } - - return "OK"; -} - - - -/* **************************************************************************** -* -* backslashFix - -*/ -static void backslashFix(char* content) -{ - char* newContent = strdup(content); - if (newContent == NULL) - { - // strdup could return NULL if we run of of memory. Very unlikely, but - // theoretically possible (and static code analysis tools complaint about it ;) - LM_E(("Runtime Error (strdup returns NULL)")); - return; - } - - int nIx = 0; - - for (unsigned int ix = 0; ix < strlen(content); ++ix) - { - if (content[ix] != '\\') - { - newContent[nIx] = content[ix]; - ++nIx; - } - else // Found a backslash! - { - // - // Valid chars after backslash, according to http://www.json.org/: - // - " Error in json v1 parse - // - \ OK - // - / Error in json v1 parse - // - b OK - // - f OK - // - n OK - // - r OK - // - t OK - // - u + four-hex-digits OK - // - // What we will do here is to replace backslash+slash with 'just slash' as - // otherwise this JSON parser gives a parse error. - // - // Nothing can be done with with backslash+citation-mark, that would have to be - // taken care of inside the parser, and that we will not do. - // We will just let it pass and provoke a JSON Parse Error. - // - char next = content[ix + 1]; - - if (next == '/') - { - // Eat the backslash - } - else - { - // Keep the backslash - newContent[nIx] = content[ix]; - ++nIx; - } - } - } - - newContent[nIx] = 0; - strcpy(content, newContent); - - free(newContent); -} - - - -/* **************************************************************************** -* -* jsonParse - -*/ -std::string jsonParse -( - ConnectionInfo* ciP, - const char* content, - const std::string& requestType, - JsonNode* parseVector, - ParseData* parseDataP -) -{ - std::stringstream ss; - ptree tree; - ptree subtree; - std::string path; - struct timespec start; - struct timespec end; - - if (timingStatistics) - { - clock_gettime(CLOCK_REALTIME, &start); - } - - // - // Does 'content' contain any '\/' (escaped slashes) ? - // If so, change all '\/' to '/' - // - if ((strstr(content, "\\/") != NULL)) - { - backslashFix((char*) content); - } - - ss << content; - read_json(ss, subtree); - - tree.put_child(requestType, subtree); - - // LM_T(LmtParse, ("parsing '%s'", content)); - BOOST_FOREACH(boost::property_tree::ptree::value_type &v, tree.get_child(requestType)) - { - std::string res = jsonParse(ciP, v, path, parseVector, parseDataP); - if (res != "OK") - { - alarmMgr.badInput(clientIp, "JSON Parse Error", res); - return res; - } - } - - if (timingStatistics) - { - clock_gettime(CLOCK_REALTIME, &end); - clock_difftime(&end, &start, &threadLastTimeStat.jsonV1ParseTime); - } - - return "OK"; -} - - - -/* **************************************************************************** -* -* safeValue - -* -* If the string passed as argument has \0, truncates to the first \0. Not doing -* so can cause problems when that value is used as field in mongo backend. -* -*/ -std::string safeValue(const std::string& s) -{ - unsigned int pos = s.find('\0'); - if (pos != std::string::npos) - { - return s.substr(0, pos); - } - else - { - return s; - } - -} diff --git a/src/lib/jsonParse/jsonParse.h b/src/lib/jsonParse/jsonParse.h deleted file mode 100644 index 10d00655b6..0000000000 --- a/src/lib/jsonParse/jsonParse.h +++ /dev/null @@ -1,55 +0,0 @@ -#ifndef SRC_LIB_JSONPARSE_JSONPARSE_H_ -#define SRC_LIB_JSONPARSE_JSONPARSE_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include - -#include "jsonParse/JsonNode.h" -#include "ngsi/ParseData.h" -#include "rest/ConnectionInfo.h" - - - -/* **************************************************************************** -* -* jsonParse - -*/ -extern std::string jsonParse -( - ConnectionInfo* ciP, - const char* content, - const std::string& requestType, - JsonNode* parseVector, - ParseData* reqDataP -); - -/* **************************************************************************** -* -* safeValue - -*/ -extern std::string safeValue(const std::string& s); - -#endif // SRC_LIB_JSONPARSE_JSONPARSE_H_ diff --git a/src/lib/jsonParse/jsonQueryContextRequest.cpp b/src/lib/jsonParse/jsonQueryContextRequest.cpp deleted file mode 100755 index a866093db1..0000000000 --- a/src/lib/jsonParse/jsonQueryContextRequest.cpp +++ /dev/null @@ -1,773 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/globals.h" -#include "common/string.h" -#include "alarmMgr/alarmMgr.h" - -#include "orionTypes/areas.h" -#include "ngsi/ContextAttribute.h" -#include "ngsi/EntityId.h" -#include "ngsi10/QueryContextRequest.h" -#include "jsonParse/JsonNode.h" -#include "jsonParse/jsonQueryContextRequest.h" -#include "parse/nullTreat.h" -#include "rest/ConnectionInfo.h" -#include "rest/uriParamNames.h" - -using namespace orion; - - - -/* **************************************************************************** -* -* entityId - -*/ -static std::string entityId(const std::string& path, const std::string& value, ParseData* reqDataP) -{ - LM_T(LmtParse, ("%s: %s", path.c_str(), value.c_str())); - - reqDataP->qcr.entityIdP = new EntityId(); - - LM_T(LmtNew, ("New entityId at %p", reqDataP->qcr.entityIdP)); - reqDataP->qcr.entityIdP->id = ""; - reqDataP->qcr.entityIdP->type = ""; - reqDataP->qcr.entityIdP->isPattern = "false"; - - reqDataP->qcr.res.entityIdVector.push_back(reqDataP->qcr.entityIdP); - - return "OK"; -} - - - -/* **************************************************************************** -* -* entityIdId - -*/ -static std::string entityIdId(const std::string& path, const std::string& value, ParseData* reqDataP) -{ - reqDataP->qcr.entityIdP->id = value; - LM_T(LmtParse, ("Set 'id' to '%s' for an entity", reqDataP->qcr.entityIdP->id.c_str())); - - return "OK"; -} - - - -/* **************************************************************************** -* -* entityIdType - -*/ -static std::string entityIdType(const std::string& path, const std::string& value, ParseData* reqDataP) -{ - reqDataP->qcr.entityIdP->type = value; - LM_T(LmtParse, ("Set 'type' to '%s' for an entity", reqDataP->qcr.entityIdP->type.c_str())); - - return "OK"; -} - - - -/* **************************************************************************** -* -* entityIdIsPattern - -*/ -static std::string entityIdIsPattern(const std::string& path, const std::string& value, ParseData* reqDataP) -{ - LM_T(LmtParse, ("Got an entityId:isPattern: '%s'", value.c_str())); - - reqDataP->qcr.entityIdP->isPattern = value; - if (!isTrue(value) && !isFalse(value)) - { - return "invalid isPattern value for entity: /" + value + "/"; - } - - return "OK"; -} - - - -/* **************************************************************************** -* -* attribute - -*/ -static std::string attribute(const std::string& path, const std::string& value, ParseData* reqDataP) -{ - LM_T(LmtParse, ("Got an attribute: '%s'", value.c_str())); - - if (value.empty()) - { - alarmMgr.badInput(clientIp, "empty attribute name"); - reqDataP->errorString = "Empty attribute name"; - } - - reqDataP->qcr.res.attributeList.push_back(value); - - return "OK"; -} - - - -/* **************************************************************************** -* -* attributeList - -*/ -static std::string attributeList(const std::string& path, const std::string& value, ParseData* reqDataP) -{ - LM_T(LmtParse, ("Got an attributeList: '%s'", value.c_str())); - return "OK"; -} - - - -/* **************************************************************************** -* -* restriction - -*/ -static std::string restriction(const std::string& path, const std::string& value, ParseData* reqDataP) -{ - reqDataP->qcr.res.restrictions += 1; - return "OK"; -} - - - -/* **************************************************************************** -* -* attributeExpression - -*/ -static std::string attributeExpression(const std::string& path, const std::string& value, ParseData* reqDataP) -{ - LM_T(LmtParse, ("Got an attributeExpression: '%s'", value.c_str())); - - reqDataP->qcr.res.restriction.attributeExpression.set(value); - - if (value.empty()) - { - alarmMgr.badInput(clientIp, "empty attribute expression"); - reqDataP->errorString = "Empty attribute expression"; - } - - return "OK"; -} - - - -/* **************************************************************************** -* -* operationScope - -*/ -static std::string operationScope(const std::string& path, const std::string& value, ParseData* reqDataP) -{ - LM_T(LmtParse, ("Got an operationScope")); - - reqDataP->qcr.scopeP = new Scope(); - reqDataP->qcr.res.restriction.scopeVector.push_back(reqDataP->qcr.scopeP); - reqDataP->qcr.scopeP->type = ""; - reqDataP->qcr.scopeP->value = ""; - - return "OK"; -} - - - -/* **************************************************************************** -* -* scopeType - -*/ -static std::string scopeType(const std::string& path, const std::string& value, ParseData* reqDataP) -{ - reqDataP->qcr.scopeP->type = value; - LM_T(LmtParse, ("Set scope 'type' to '%s' for a scope", reqDataP->qcr.scopeP->type.c_str())); - - return "OK"; -} - - - -/* **************************************************************************** -* -* scopeValue - -*/ -static std::string scopeValue(const std::string& path, const std::string& value, ParseData* reqDataP) -{ - if (reqDataP->qcr.scopeP->type == FIWARE_LOCATION || reqDataP->qcr.scopeP->type == FIWARE_LOCATION_DEPRECATED) - { - // - // If the scope type is FIWARE_LOCATION' (or its deprecated variant), then the value of this scope is stored in 'circle' or 'polygon'. - // The field 'value' is not used as more complexity is needed. - // scopeP->value is here set to FIWARE_LOCATION, in an attempt to warn a future use of 'scopeP->value' when - // instead 'circle' or 'polygon' should be used. - // - reqDataP->qcr.scopeP->value = FIWARE_LOCATION; - LM_T(LmtParse, ("Preparing scopeValue for '%s'", reqDataP->qcr.scopeP->type.c_str())); - } - else if (reqDataP->qcr.scopeP->type == FIWARE_LOCATION_V2) - { - // Mark the value of the scope to be of complex nature, v2 - reqDataP->qcr.scopeP->value = FIWARE_LOCATION_V2; - } - else if (reqDataP->qcr.scopeP->type == SCOPE_TYPE_SIMPLE_QUERY) - { - std::string errorString; - - reqDataP->qcr.scopeP->value = value; - - reqDataP->qcr.scopeP->stringFilterP = new StringFilter(SftQ); - bool b = reqDataP->qcr.scopeP->stringFilterP->parse(value.c_str(), &errorString); - - if (b != true) - { - delete reqDataP->qcr.scopeP->stringFilterP; - reqDataP->qcr.scopeP->stringFilterP = NULL; - - return errorString; - } - } - else if (reqDataP->qcr.scopeP->type == SCOPE_TYPE_SIMPLE_QUERY_MD) - { - std::string errorString; - - reqDataP->qcr.scopeP->value = value; - - reqDataP->qcr.scopeP->mdStringFilterP = new StringFilter(SftMq); - bool b = reqDataP->qcr.scopeP->mdStringFilterP->parse(value.c_str(), &errorString); - - if (b != true) - { - delete reqDataP->qcr.scopeP->mdStringFilterP; - reqDataP->qcr.scopeP->mdStringFilterP = NULL; - - return errorString; - } - } - else - { - reqDataP->qcr.scopeP->value = value; - LM_T(LmtParse, ("Got a scopeValue: '%s' for scopeType '%s'", value.c_str(), reqDataP->qcr.scopeP->type.c_str())); - } - - return "OK"; -} - - - -/* **************************************************************************** -* -* circle - -*/ -static std::string circle(const std::string& path, const std::string& value, ParseData* reqDataP) -{ - LM_T(LmtParse, ("Got a circle")); - reqDataP->qcr.scopeP->areaType = orion::CircleType; - - return "OK"; -} - - - -/* **************************************************************************** -* -* circleCenterLatitude - -*/ -static std::string circleCenterLatitude(const std::string& path, const std::string& value, ParseData* reqDataP) -{ - LM_T(LmtParse, ("Got a circleCenterLatitude: %s", value.c_str())); - reqDataP->qcr.scopeP->circle.center.latitudeSet(value); - - return "OK"; -} - - - -/* **************************************************************************** -* -* circleCenterLongitude - -*/ -static std::string circleCenterLongitude(const std::string& path, const std::string& value, ParseData* reqDataP) -{ - LM_T(LmtParse, ("Got a circleCenterLongitude: %s", value.c_str())); - reqDataP->qcr.scopeP->circle.center.longitudeSet(value); - - return "OK"; -} - - - -/* **************************************************************************** -* -* circleRadius - -*/ -static std::string circleRadius(const std::string& path, const std::string& value, ParseData* reqDataP) -{ - LM_T(LmtParse, ("Got a circleRadius: %s", value.c_str())); - reqDataP->qcr.scopeP->circle.radiusSet(value); - - return "OK"; -} - - - -/* **************************************************************************** -* -* circleInverted - -*/ -static std::string circleInverted(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a circleInverted: %s", value.c_str())); - - parseDataP->qcr.scopeP->circle.invertedSet(value); - if (!isTrue(value) && !isFalse(value)) - { - parseDataP->errorString = "bad string for circle/inverted: /" + value + "/"; - return parseDataP->errorString; - } - - return "OK"; -} - - - -/* **************************************************************************** -* -* polygon - -*/ -static std::string polygon(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a polygon")); - parseDataP->qcr.scopeP->areaType = orion::PolygonType; - - return "OK"; -} - - - -/* **************************************************************************** -* -* polygonInverted - -*/ -static std::string polygonInverted(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a polygonInverted: %s", value.c_str())); - - parseDataP->qcr.scopeP->polygon.invertedSet(value); - if (!isTrue(value) && !isFalse(value)) - { - parseDataP->errorString = "bad string for polygon/inverted: /" + value + "/"; - return parseDataP->errorString; - } - - return "OK"; -} - - - -/* **************************************************************************** -* -* polygonVertexList - -*/ -static std::string polygonVertexList(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a polygonVertexList")); - - return "OK"; -} - - - -/* **************************************************************************** -* -* polygonVertex - -*/ -static std::string polygonVertex(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a polygonVertex - creating new vertex for the vertex list")); - parseDataP->qcr.vertexP = new orion::Point(); - parseDataP->qcr.scopeP->polygon.vertexAdd(parseDataP->qcr.vertexP); - // parseDataP->qcr.scopeP->polygon.vertexList.push_back(parseDataP->qcr.vertexP); - - return "OK"; -} - - - -/* **************************************************************************** -* -* polygonVertexLatitude - -*/ -static std::string polygonVertexLatitude(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a polygonVertexLatitude: %s", value.c_str())); - parseDataP->qcr.vertexP->latitudeSet(value); - - return "OK"; -} - - - -/* **************************************************************************** -* -* polygonVertexLongitude - -*/ -static std::string polygonVertexLongitude(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a polygonVertexLongitude: %s", value.c_str())); - parseDataP->qcr.vertexP->longitudeSet(value); - - return "OK"; -} - - - -/* **************************************************************************** -* -* georel - -*/ -static std::string georel(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a georel")); - if (parseDataP->qcr.scopeP->type != FIWARE_LOCATION_V2) - { - return "georel in scope value used with non-api-v2 scope"; - } - - parseDataP->qcr.coords = 0; - parseDataP->qcr.pointNo = 0; - - return "OK"; -} - - - -/* **************************************************************************** -* -* georelValue - -*/ -static std::string georelValue(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a georel value")); - if (parseDataP->qcr.scopeP->type != FIWARE_LOCATION_V2) - { - return "georel in scope value used with non-api-v2 scope"; - } - - if (strncmp(value.c_str(), "maxDistance:", strlen("maxDistance:")) == 0) - { - const char* maxDistanceP = &value.c_str()[strlen("maxDistance:")]; - if (str2double(maxDistanceP, &parseDataP->qcr.scopeP->georel.maxDistance) != true) - { - return "georel with a maxDistance that is not a number"; - } - } - else if (strncmp(value.c_str(), "minDistance:", strlen("minDistance:")) == 0) - { - const char* minDistanceP = &value.c_str()[strlen("minDistance:")]; - if (str2double(minDistanceP, &parseDataP->qcr.scopeP->georel.minDistance) != true) - { - return "georel with a minDistance that is not a number"; - } - } - else - { - // Check for valid georel.type comes later - parseDataP->qcr.scopeP->georel.type = value; - } - - return "OK"; -} - - - -/* **************************************************************************** -* -* geometry - -*/ -static std::string geometry(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a geometry")); - - if (parseDataP->qcr.scopeP->type != FIWARE_LOCATION_V2) - { - return "geometry in scope value used with non-api-v2 scope"; - } - - parseDataP->qcr.coords = 0; - parseDataP->qcr.pointNo = 0; - parseDataP->qcr.scopeP->areaTypeSet(value); - - return "OK"; -} - - -/* **************************************************************************** -* -* coords - -*/ -static std::string coords(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a coords")); - - if (parseDataP->qcr.scopeP->type != FIWARE_LOCATION_V2) - { - return "coords in scope value used with non-api-v2 scope"; - } - - return "OK"; -} - - - -/* **************************************************************************** -* -* coord - -*/ -static std::string coord(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a coord-pair")); - - if (parseDataP->qcr.scopeP->type != FIWARE_LOCATION_V2) - { - return "coords in scope value used with non-api-v2 scope"; - } - - parseDataP->qcr.coords = 0; - parseDataP->qcr.pointNo += 1; - - return "OK"; -} - - - -/* **************************************************************************** -* -* coordValue - -*/ -static std::string coordValue(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a coordinate")); - - if (parseDataP->qcr.scopeP->type != FIWARE_LOCATION_V2) - { - return "coords in scope value used with non-api-v2 scope"; - } - - - // - // Decide where to put the point ... - // - double coordVal; - - if (str2double(value.c_str(), &coordVal) == false) - { - return "invalid coordinate"; - } - - switch (parseDataP->qcr.scopeP->areaType) - { - case orion::PointType: - if (parseDataP->qcr.coords == 0) - { - parseDataP->qcr.scopeP->point.latitudeSet(coordVal); - } - else if (parseDataP->qcr.coords == 1) - { - parseDataP->qcr.scopeP->point.longitudeSet(coordVal); - } - else - { - return "too many coordinates for a Point geometry"; - } - break; - - case orion::PolygonType: - if (parseDataP->qcr.coords == 0) - { - parseDataP->qcr.vertexP = new Point(coordVal, 0); - parseDataP->qcr.scopeP->polygon.vertexAdd(parseDataP->qcr.vertexP); - } - else if (parseDataP->qcr.coords == 1) - { - parseDataP->qcr.vertexP->longitudeSet(coordVal); - } - else - { - return "too many coordinates for a Point in Polygon geometry"; - } - break; - - case orion::LineType: - if (parseDataP->qcr.coords == 0) - { - parseDataP->qcr.vertexP = new Point(coordVal, 0); - parseDataP->qcr.scopeP->line.pointAdd(parseDataP->qcr.vertexP); - } - else if (parseDataP->qcr.coords == 1) - { - parseDataP->qcr.vertexP->longitudeSet(coordVal); - } - else - { - return "too many coordinates for a Point in Line geometry"; - } - break; - - case orion::BoxType: - if (parseDataP->qcr.pointNo > 2) - { - return "too many points for a Box geoetry"; - } - - if (parseDataP->qcr.coords == 0) - { - if (parseDataP->qcr.pointNo == 1) - { - parseDataP->qcr.scopeP->box.lowerLeft.latitudeSet(coordVal); - } - else - { - parseDataP->qcr.scopeP->box.upperRight.latitudeSet(coordVal); - } - } - else if (parseDataP->qcr.coords == 1) - { - if (parseDataP->qcr.pointNo == 1) - { - parseDataP->qcr.scopeP->box.lowerLeft.longitudeSet(coordVal); - } - else - { - parseDataP->qcr.scopeP->box.upperRight.longitudeSet(coordVal); - } - } - else - { - return "too many coordinates for a Point in Box geometry"; - } - break; - - case orion::NoArea: - case orion::CircleType: - return "received coordinates for invalid geometry"; - break; - } - - parseDataP->qcr.coords += 1; - return "OK"; -} - - - -/* **************************************************************************** -* -* qcrParseVector - -*/ -JsonNode jsonQcrParseVector[] = -{ - { "/entities", jsonNullTreat }, - { "/entities/entity", entityId }, - { "/entities/entity/id", entityIdId }, - { "/entities/entity/type", entityIdType }, - { "/entities/entity/isPattern", entityIdIsPattern }, - - { "/attributes", attributeList }, - { "/attributes/attribute", attribute }, - - { "/restriction", restriction }, - { "/restriction/attributeExpression", attributeExpression }, - { "/restriction/scopes", jsonNullTreat }, - { "/restriction/scopes/scope", operationScope }, - { "/restriction/scopes/scope/type", scopeType }, - { "/restriction/scopes/scope/value", scopeValue }, - - { "/restriction/scopes/scope/value/circle", circle }, - { "/restriction/scopes/scope/value/circle/centerLatitude", circleCenterLatitude }, - { "/restriction/scopes/scope/value/circle/centerLongitude", circleCenterLongitude }, - { "/restriction/scopes/scope/value/circle/radius", circleRadius }, - { "/restriction/scopes/scope/value/circle/inverted", circleInverted }, - - { "/restriction/scopes/scope/value/polygon", polygon }, - { "/restriction/scopes/scope/value/polygon/inverted", polygonInverted }, - { "/restriction/scopes/scope/value/polygon/vertices", polygonVertexList }, - { "/restriction/scopes/scope/value/polygon/vertices/vertice", polygonVertex }, - { "/restriction/scopes/scope/value/polygon/vertices/vertice/latitude", polygonVertexLatitude }, - { "/restriction/scopes/scope/value/polygon/vertices/vertice/longitude", polygonVertexLongitude }, - - // APIv2 geolocation in v1 - { "/restriction/scopes/scope/value/geometry", geometry }, - { "/restriction/scopes/scope/value/georel", georel }, - { "/restriction/scopes/scope/value/georel/geore", georelValue }, - { "/restriction/scopes/scope/value/coords", coords }, - { "/restriction/scopes/scope/value/coords/coord", coord }, - { "/restriction/scopes/scope/value/coords/coord/coor", coordValue }, - - { "LAST", NULL } -}; - - - -/* **************************************************************************** -* -* jsonQcrInit - -*/ -void jsonQcrInit(ParseData* reqDataP) -{ - jsonQcrRelease(reqDataP); - - reqDataP->qcr.entityIdP = NULL; - reqDataP->qcr.scopeP = NULL; - reqDataP->errorString = ""; - - reqDataP->qcr.res.restrictions = 0; - reqDataP->qcr.res.restriction.attributeExpression.set(""); -} - - - -/* **************************************************************************** -* -* jsonQcrRelease - -*/ -void jsonQcrRelease(ParseData* reqDataP) -{ - reqDataP->qcr.res.release(); -} - - - -/* **************************************************************************** -* -* jsonQcrCheck - -*/ -std::string jsonQcrCheck(ParseData* reqDataP, ConnectionInfo* ciP) -{ - bool asJsonObject = (ciP->uriParam[URI_PARAM_ATTRIBUTE_FORMAT] == "object" && ciP->outMimeType == JSON); - return reqDataP->qcr.res.check(ciP->apiVersion, asJsonObject, reqDataP->errorString); -} diff --git a/src/lib/jsonParse/jsonQueryContextRequest.h b/src/lib/jsonParse/jsonQueryContextRequest.h deleted file mode 100644 index 0ce7ad0ad4..0000000000 --- a/src/lib/jsonParse/jsonQueryContextRequest.h +++ /dev/null @@ -1,65 +0,0 @@ -#ifndef SRC_LIB_JSONPARSE_JSONQUERYCONTEXTREQUEST_H_ -#define SRC_LIB_JSONPARSE_JSONQUERYCONTEXTREQUEST_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include - -#include "jsonParse/JsonNode.h" -#include "rest/ConnectionInfo.h" - - - -/* **************************************************************************** -* -* qcrParseVector - -*/ -extern JsonNode jsonQcrParseVector[]; - - - -/* **************************************************************************** -* -* jsonQcrInit - -*/ -extern void jsonQcrInit(ParseData* reqDataP); - - - -/* **************************************************************************** -* -* jsonQcrRelease - -*/ -extern void jsonQcrRelease(ParseData* reqDataP); - - - -/* **************************************************************************** -* -* jsonQcrCheck - -*/ -extern std::string jsonQcrCheck(ParseData* reqDataP, ConnectionInfo* ciP); - -#endif // SRC_LIB_JSONPARSE_JSONQUERYCONTEXTREQUEST_H_ diff --git a/src/lib/jsonParse/jsonQueryContextResponse.cpp b/src/lib/jsonParse/jsonQueryContextResponse.cpp deleted file mode 100644 index eac107a3a2..0000000000 --- a/src/lib/jsonParse/jsonQueryContextResponse.cpp +++ /dev/null @@ -1,376 +0,0 @@ -/* -* -* Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/globals.h" -#include "orionTypes/areas.h" -#include "ngsi/ContextAttribute.h" -#include "ngsi/EntityId.h" -#include "ngsi10/QueryContextRequest.h" - -#include "jsonParse/JsonNode.h" -#include "jsonParse/jsonParse.h" -#include "jsonParse/jsonQueryContextResponse.h" -#include "parse/nullTreat.h" - -#include "rest/ConnectionInfo.h" -#include "rest/uriParamNames.h" - -using namespace orion; - - - -/* **************************************************************************** -* -* contextResponse - -*/ -static std::string contextResponse(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - parseDataP->qcrs.cerP = new ContextElementResponse(); - parseDataP->qcrs.res.contextElementResponseVector.push_back(parseDataP->qcrs.cerP); - return "OK"; -} - - -/* **************************************************************************** -* -* entityIdId - -*/ -static std::string entityIdId(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - parseDataP->qcrs.cerP->entity.id = value; - LM_T(LmtParse, ("Set 'id' to '%s' for an entity", parseDataP->qcrs.cerP->entity.id.c_str())); - - return "OK"; -} - - - -/* **************************************************************************** -* -* entityIdType - -*/ -static std::string entityIdType(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - parseDataP->qcrs.cerP->entity.type = value; - LM_T(LmtParse, ("Set 'type' to '%s' for an entity", parseDataP->qcrs.cerP->entity.type.c_str())); - - return "OK"; -} - - - -/* **************************************************************************** -* -* entityIdIsPattern - -*/ -static std::string entityIdIsPattern(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got an entityId:isPattern: '%s'", value.c_str())); - parseDataP->qcrs.cerP->entity.isPattern = value; - - if (!isTrue(value) && !isFalse(value)) - { - return "invalid isPattern value for entity: /" + value + "/"; - } - - return "OK"; -} - - - -/* **************************************************************************** -* -* attribute - -*/ -static std::string attribute(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Creating an attribute")); - parseDataP->qcrs.attributeP = new ContextAttribute(); - parseDataP->qcrs.cerP->entity.attributeVector.push_back(parseDataP->qcrs.attributeP); - return "OK"; -} - - - -/* **************************************************************************** -* -* attributeName - -*/ -static std::string attributeName(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got an attribute name: '%s'", value.c_str())); - parseDataP->qcrs.attributeP->name = safeValue(value); - return "OK"; -} - - - -/* **************************************************************************** -* -* attributeType - -*/ -static std::string attributeType(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got an attribute type: '%s'", value.c_str())); - parseDataP->qcrs.attributeP->type = value; - return "OK"; -} - - - -/* **************************************************************************** -* -* attributeValue - -*/ -static std::string attributeValue(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got an attribute value: '%s'", value.c_str())); - parseDataP->lastContextAttribute = parseDataP->qcrs.attributeP; - parseDataP->qcrs.attributeP->stringValue = value; - parseDataP->qcrs.attributeP->valueType = orion::ValueTypeString; - return "OK"; -} - - - -/* **************************************************************************** -* -* attributeMetadata - -*/ -static std::string attributeMetadata(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Creating an attributeMetadata")); - parseDataP->qcrs.metadataP = new Metadata(); - parseDataP->qcrs.attributeP->metadataVector.push_back(parseDataP->qcrs.metadataP); - return "OK"; -} - - - -/* **************************************************************************** -* -* attributeMetadataName - -*/ -static std::string attributeMetadataName(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got an attributeMetadata name: '%s'", value.c_str())); - parseDataP->qcrs.metadataP->name = safeValue(value); - return "OK"; -} - - - -/* **************************************************************************** -* -* attributeMetadataType - -*/ -static std::string attributeMetadataType(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got an attributeMetadata type: '%s'", value.c_str())); - parseDataP->qcrs.metadataP->type = value; - return "OK"; -} - - - -/* **************************************************************************** -* -* attributeMetadataValue - -*/ -static std::string attributeMetadataValue(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got an attributeMetadata value: '%s'", value.c_str())); - parseDataP->qcrs.metadataP->stringValue = value; - parseDataP->qcrs.metadataP->valueType = orion::ValueTypeString; - return "OK"; -} - - - -/* **************************************************************************** -* -* statusCodeCode - -*/ -static std::string statusCodeCode(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a statusCode code: '%s'", value.c_str())); - parseDataP->qcrs.cerP->statusCode.code = (HttpStatusCode) atoi(value.c_str()); - LM_T(LmtParse, ("Got a statusCode code: %d", (int) parseDataP->qcrs.cerP->statusCode.code)); - return "OK"; -} - - - -/* **************************************************************************** -* -* statusCodeReasonPhrase - -*/ -static std::string statusCodeReasonPhrase(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a statusCode reasonPhrase: '%s'", value.c_str())); - parseDataP->qcrs.cerP->statusCode.reasonPhrase = value; // OK - parsing step reading reasonPhrase - return "OK"; -} - - - -/* **************************************************************************** -* -* statusCodeDetails - -*/ -static std::string statusCodeDetails(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a statusCode details: '%s'", value.c_str())); - parseDataP->qcrs.cerP->statusCode.details = value; - return "OK"; -} - - - -/* **************************************************************************** -* -* errorCodeCode - -*/ -static std::string errorCodeCode(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a errorCode code: '%s'", value.c_str())); - parseDataP->qcrs.res.errorCode.code = (HttpStatusCode) atoi(value.c_str()); - LM_T(LmtParse, ("Got a errorCode code: %d", (int) parseDataP->qcrs.res.errorCode.code)); - return "OK"; -} - - - -/* **************************************************************************** -* -* errorCodeReasonPhrase - -*/ -static std::string errorCodeReasonPhrase(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a errorCode reasonPhrase: '%s'", value.c_str())); - parseDataP->qcrs.res.errorCode.reasonPhrase = value; // OK - parsing step reading reasonPhrase - return "OK"; -} - - - -/* **************************************************************************** -* -* errorCodeDetails - -*/ -static std::string errorCodeDetails(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a errorCode details: '%s'", value.c_str())); - parseDataP->qcrs.res.errorCode.details = value; - return "OK"; -} - - - - -#define CELEM "/contextResponses/contextResponse/contextElement" -/* **************************************************************************** -* -* qcrsParseVector - -*/ -JsonNode jsonQcrsParseVector[] = -{ - { "/contextResponses", jsonNullTreat }, - { "/contextResponses/contextResponse", contextResponse }, - - { CELEM, jsonNullTreat }, - { CELEM "/id", entityIdId }, - { CELEM "/type", entityIdType }, - { CELEM "/isPattern", entityIdIsPattern }, - - { CELEM "/attributes", jsonNullTreat }, - { CELEM "/attributes/attribute", attribute }, - { CELEM "/attributes/attribute/name", attributeName }, - { CELEM "/attributes/attribute/type", attributeType }, - { CELEM "/attributes/attribute/value", attributeValue }, - - { CELEM "/attributes/attribute/metadatas", jsonNullTreat }, - { CELEM "/attributes/attribute/metadatas/metadata", attributeMetadata }, - { CELEM "/attributes/attribute/metadatas/metadata/name", attributeMetadataName }, - { CELEM "/attributes/attribute/metadatas/metadata/type", attributeMetadataType }, - { CELEM "/attributes/attribute/metadatas/metadata/value", attributeMetadataValue }, - - { "/contextResponses/contextResponse/statusCode", jsonNullTreat }, - { "/contextResponses/contextResponse/statusCode/code", statusCodeCode }, - { "/contextResponses/contextResponse/statusCode/reasonPhrase", statusCodeReasonPhrase }, - { "/contextResponses/contextResponse/statusCode/details", statusCodeDetails }, - - { "/errorCode", jsonNullTreat }, - { "/errorCode/code", errorCodeCode }, - { "/errorCode/reasonPhrase", errorCodeReasonPhrase }, - { "/errorCode/details", errorCodeDetails }, - - { "LAST", NULL } -}; - - - -/* **************************************************************************** -* -* jsonQcrsInit - -*/ -void jsonQcrsInit(ParseData* reqDataP) -{ - jsonQcrsRelease(reqDataP); - - reqDataP->qcrs.cerP = NULL; - reqDataP->qcrs.attributeP = NULL; - reqDataP->qcrs.metadataP = NULL; - - reqDataP->errorString = ""; -} - - - -/* **************************************************************************** -* -* jsonQcrsRelease - -*/ -void jsonQcrsRelease(ParseData* reqDataP) -{ - reqDataP->qcrs.res.release(); -} - - - -/* **************************************************************************** -* -* jsonQcrsCheck - -*/ -std::string jsonQcrsCheck(ParseData* reqDataP, ConnectionInfo* ciP) -{ - bool asJsonObject = (ciP->uriParam[URI_PARAM_ATTRIBUTE_FORMAT] == "object" && ciP->outMimeType == JSON); - return reqDataP->qcrs.res.check(ciP->apiVersion,asJsonObject, reqDataP->errorString); -} diff --git a/src/lib/jsonParse/jsonQueryContextResponse.h b/src/lib/jsonParse/jsonQueryContextResponse.h deleted file mode 100644 index 73416a2cf1..0000000000 --- a/src/lib/jsonParse/jsonQueryContextResponse.h +++ /dev/null @@ -1,65 +0,0 @@ -#ifndef SRC_LIB_JSONPARSE_JSONQUERYCONTEXTRESPONSE_H_ -#define SRC_LIB_JSONPARSE_JSONQUERYCONTEXTRESPONSE_H_ - -/* -* -* Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include - -#include "jsonParse/JsonNode.h" -#include "rest/ConnectionInfo.h" - - - -/* **************************************************************************** -* -* qcrsParseVector - -*/ -extern JsonNode jsonQcrsParseVector[]; - - - -/* **************************************************************************** -* -* jsonQcrsInit - -*/ -extern void jsonQcrsInit(ParseData* reqDataP); - - - -/* **************************************************************************** -* -* jsonQcrsRelease - -*/ -extern void jsonQcrsRelease(ParseData* reqDataP); - - - -/* **************************************************************************** -* -* jsonQcrsCheck - -*/ -extern std::string jsonQcrsCheck(ParseData* reqDataP, ConnectionInfo* ciP); - -#endif // SRC_LIB_JSONPARSE_JSONQUERYCONTEXTRESPONSE_H_ diff --git a/src/lib/jsonParse/jsonRegisterContextRequest.cpp b/src/lib/jsonParse/jsonRegisterContextRequest.cpp deleted file mode 100755 index 19a237140b..0000000000 --- a/src/lib/jsonParse/jsonRegisterContextRequest.cpp +++ /dev/null @@ -1,284 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/globals.h" -#include "ngsi/EntityId.h" -#include "ngsi/ContextRegistrationAttribute.h" -#include "ngsi/Metadata.h" -#include "ngsi9/RegisterContextRequest.h" -#include "jsonParse/JsonNode.h" -#include "jsonParse/jsonParse.h" -#include "parse/nullTreat.h" -#include "rest/ConnectionInfo.h" - - - -/* **************************************************************************** -* -* contextRegistration - -*/ -static std::string contextRegistration(const std::string& path, const std::string& value, ParseData* reqDataP) -{ - // LM_T(LmtParse, ("%s: %s", path.c_str(), value.c_str())); - reqDataP->rcr.crP = new ContextRegistration(); - // LM_T(LmtParse, ("%s: %s", path.c_str(), value.c_str())); - - reqDataP->rcr.res.contextRegistrationVector.push_back(reqDataP->rcr.crP); - LM_T(LmtParse, ("%s: %s", path.c_str(), value.c_str())); - - return "OK"; -} - - - -/* **************************************************************************** -* -* entityId - -*/ -static std::string entityId(const std::string& path, const std::string& value, ParseData* reqDataP) -{ - LM_T(LmtParse, ("%s: %s", path.c_str(), value.c_str())); - - reqDataP->rcr.entityIdP = new EntityId(); - - reqDataP->rcr.entityIdP->id = ""; - reqDataP->rcr.entityIdP->type = ""; - reqDataP->rcr.entityIdP->isPattern = "false"; - - reqDataP->rcr.crP->entityIdVector.push_back(reqDataP->rcr.entityIdP); - - return "OK"; -} - - - -/* **************************************************************************** -* -* entityIdId - -*/ -static std::string entityIdId(const std::string& path, const std::string& value, ParseData* reqDataP) -{ - reqDataP->rcr.entityIdP->id = value; - LM_T(LmtParse, ("Set 'id' to '%s' for an entity", reqDataP->rcr.entityIdP->id.c_str())); - - return "OK"; -} - - - -/* **************************************************************************** -* -* entityIdType - -*/ -static std::string entityIdType(const std::string& path, const std::string& value, ParseData* reqDataP) -{ - reqDataP->rcr.entityIdP->type = value; - LM_T(LmtParse, ("Set 'type' to '%s' for an entity", reqDataP->rcr.entityIdP->type.c_str())); - - return "OK"; -} - - - -/* **************************************************************************** -* -* entityIdIsPattern - -*/ -static std::string entityIdIsPattern(const std::string& path, const std::string& value, ParseData* reqDataP) -{ - LM_T(LmtParse, ("Got an entityId:isPattern: '%s'", value.c_str())); - - if (!isTrue(value) && !isFalse(value)) - { - return "invalid isPattern value for entity: /" + value + "/"; - } - - reqDataP->rcr.entityIdP->isPattern = value; - - if (isTrue(reqDataP->rcr.entityIdP->isPattern)) - { - return "isPattern set to true for registrations is currently not supported"; - } - - return "OK"; -} - - - -/* **************************************************************************** -* -* crAttribute - -*/ -static std::string crAttribute(const std::string& path, const std::string& value, ParseData* reqDataP) -{ - LM_T(LmtParse, ("%s: %s", path.c_str(), value.c_str())); - - reqDataP->rcr.attributeP = new ContextRegistrationAttribute("", ""); - reqDataP->rcr.crP->contextRegistrationAttributeVector.push_back(reqDataP->rcr.attributeP); - - return "OK"; -} - - - -/* **************************************************************************** -* -* craName - -*/ -static std::string craName(const std::string& path, const std::string& value, ParseData* reqDataP) -{ - reqDataP->rcr.attributeP->name = safeValue(value); - LM_T(LmtParse, ("Set 'name' to '%s' for a contextRegistrationAttribute", reqDataP->rcr.attributeP->name.c_str())); - - return "OK"; -} - - - -/* **************************************************************************** -* -* craType - -*/ -static std::string craType(const std::string& path, const std::string& value, ParseData* reqDataP) -{ - reqDataP->rcr.attributeP->type = value; - LM_T(LmtParse, ("Set 'type' to '%s' for a contextRegistrationAttribute", reqDataP->rcr.attributeP->type.c_str())); - - return "OK"; -} - - - -/* **************************************************************************** -* -* providingApplication - -*/ -static std::string providingApplication(const std::string& path, const std::string& value, ParseData* reqDataP) -{ - LM_T(LmtParse, ("Got a providing application: '%s'", value.c_str())); - reqDataP->rcr.crP->providingApplication.set(value); - - return "OK"; -} - - - -/* **************************************************************************** -* -* duration - -*/ -static std::string duration(const std::string& path, const std::string& value, ParseData* reqDataP) -{ - LM_T(LmtParse, ("Got a duration: '%s'. Saving in %p", value.c_str(), &reqDataP->rcr.res.duration)); - reqDataP->rcr.res.duration.set(value); - LM_T(LmtParse, ("Got a duration: SAVED!")); - return "OK"; -} - - - -/* **************************************************************************** -* -* registrationId - -*/ -static std::string registrationId(const std::string& path, const std::string& value, ParseData* reqDataP) -{ - LM_T(LmtParse, ("Got a registration id: '%s'", value.c_str())); - reqDataP->rcr.res.registrationId.set(value); - - return "OK"; -} - - - -#define CR "/contextRegistrations" -/* **************************************************************************** -* -* jsonRcrParseVector - -*/ -JsonNode jsonRcrParseVector[] = -{ - { "/contextRegistrations", jsonNullTreat }, - { CR "/contextRegistration", contextRegistration }, - { CR "/contextRegistration/entities", jsonNullTreat }, - { CR "/contextRegistration/entities/entity", entityId }, - { CR "/contextRegistration/entities/entity/id", entityIdId }, - { CR "/contextRegistration/entities/entity/type", entityIdType }, - { CR "/contextRegistration/entities/entity/isPattern", entityIdIsPattern }, - - { CR "/contextRegistration/attributes", jsonNullTreat }, - { CR "/contextRegistration/attributes/attribute", crAttribute }, - { CR "/contextRegistration/attributes/attribute/name", craName }, - { CR "/contextRegistration/attributes/attribute/type", craType }, - - { CR "/contextRegistration/providingApplication", providingApplication }, - { "/duration", duration }, - { "/registrationId", registrationId }, - - { "LAST", NULL } -}; - - - -/* **************************************************************************** -* -* jsonRcrInit - -*/ -void jsonRcrInit(ParseData* reqDataP) -{ - reqDataP->rcr.crP = NULL; - reqDataP->rcr.entityIdP = NULL; - reqDataP->rcr.attributeP = NULL; - reqDataP->rcr.attributeMetadataP = NULL; - reqDataP->rcr.registrationMetadataP = NULL; - reqDataP->errorString = ""; -} - - - -/* **************************************************************************** -* -* jsonRcrRelease - -*/ -void jsonRcrRelease(ParseData* reqDataP) -{ - reqDataP->rcr.res.release(); -} - - - -/* **************************************************************************** -* -* jsonRcrCheck - -*/ -std::string jsonRcrCheck(ParseData* reqData, ConnectionInfo* ciP) -{ - return reqData->rcr.res.check(ciP->apiVersion, reqData->errorString, 0); -} diff --git a/src/lib/jsonParse/jsonRegisterContextRequest.h b/src/lib/jsonParse/jsonRegisterContextRequest.h deleted file mode 100644 index 386e021a88..0000000000 --- a/src/lib/jsonParse/jsonRegisterContextRequest.h +++ /dev/null @@ -1,66 +0,0 @@ -#ifndef SRC_LIB_JSONPARSE_JSONREGISTERCONTEXTREQUEST_H_ -#define SRC_LIB_JSONPARSE_JSONREGISTERCONTEXTREQUEST_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "rest/ConnectionInfo.h" -#include "jsonParse/JsonNode.h" - - - -/* **************************************************************************** -* -* jsonRcrParseVector - -*/ -extern JsonNode jsonRcrParseVector[]; - - - -/* **************************************************************************** -* -* jsonRcrInit - -*/ -extern void jsonRcrInit(ParseData* reqDataP); - - - -/* **************************************************************************** -* -* jsonRcrRelease - -*/ -extern void jsonRcrRelease(ParseData* reqDataP); - - - -/* **************************************************************************** -* -* jsonRcrCheck - -*/ -extern std::string jsonRcrCheck(ParseData* reqDataP, ConnectionInfo* ciP); - -#endif // SRC_LIB_JSONPARSE_JSONREGISTERCONTEXTREQUEST_H_ diff --git a/src/lib/jsonParse/jsonRegisterProviderRequest.cpp b/src/lib/jsonParse/jsonRegisterProviderRequest.cpp deleted file mode 100644 index dfbb39ada8..0000000000 --- a/src/lib/jsonParse/jsonRegisterProviderRequest.cpp +++ /dev/null @@ -1,127 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/globals.h" -#include "convenience/RegisterProviderRequest.h" -#include "jsonParse/jsonParse.h" -#include "jsonParse/jsonRegisterProviderRequest.h" -#include "jsonParse/JsonNode.h" -#include "parse/nullTreat.h" -#include "ngsi/Request.h" -#include "rest/ConnectionInfo.h" -#include "rest/uriParamNames.h" - - - -/* **************************************************************************** -* -* duration - -*/ -static std::string duration(const std::string& path, const std::string& value, ParseData* reqData) -{ - LM_T(LmtParse, ("Got a duration '%s'", value.c_str())); - reqData->rpr.res.duration.set(value); - return "OK"; -} - - - -/* **************************************************************************** -* -* providingApplication - -*/ -static std::string providingApplication(const std::string& path, const std::string& value, ParseData* reqData) -{ - LM_T(LmtParse, ("Got a providingApplication '%s'", value.c_str())); - reqData->rpr.res.providingApplication.set(value); - return "OK"; -} - - - -/* **************************************************************************** -* -* registrationId - -*/ -static std::string registrationId(const std::string& path, const std::string& value, ParseData* reqData) -{ - LM_T(LmtParse, ("Got a registrationId '%s'", value.c_str())); - reqData->rpr.res.registrationId.set(value); - return "OK"; -} - - -/* **************************************************************************** -* -* jsonRprParseVector - -*/ -JsonNode jsonRprParseVector[] = -{ - { "/duration", duration }, - { "/providingApplication", providingApplication }, - { "/registrationId", registrationId }, - - { "LAST", NULL } -}; - - - -/* **************************************************************************** -* -* jsonRprInit - -*/ -void jsonRprInit(ParseData* reqData) -{ - reqData->rpr.res.registrationId.set(""); - reqData->rpr.res.providingApplication.set(""); - reqData->rpr.res.duration.set(""); - - reqData->rpr.metadataP = NULL; -} - - - -/* **************************************************************************** -* -* jsonRprRelease - -*/ -void jsonRprRelease(ParseData* reqData) -{ -} - - -/* **************************************************************************** -* -* jsonRprCheck - -*/ -std::string jsonRprCheck(ParseData* reqData, ConnectionInfo* ciP) -{ - return reqData->rpr.res.check(ciP->apiVersion, ContextEntitiesByEntityId, reqData->errorString); -} diff --git a/src/lib/jsonParse/jsonRegisterProviderRequest.h b/src/lib/jsonParse/jsonRegisterProviderRequest.h deleted file mode 100644 index ddd0cfad6f..0000000000 --- a/src/lib/jsonParse/jsonRegisterProviderRequest.h +++ /dev/null @@ -1,64 +0,0 @@ -#ifndef SRC_LIB_JSONPARSE_JSONREGISTERPROVIDERREQUEST_H_ -#define SRC_LIB_JSONPARSE_JSONREGISTERPROVIDERREQUEST_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "jsonParse/JsonNode.h" - - -/* **************************************************************************** -* -* jsonRprParseVector - -*/ -extern JsonNode jsonRprParseVector[]; - - - -/* **************************************************************************** -* -* jsonRprInit - -*/ -extern void jsonRprInit(ParseData* reqDataP); - - - -/* **************************************************************************** -* -* jsonRprRelease - -*/ -extern void jsonRprRelease(ParseData* reqDataP); - - - -/* **************************************************************************** -* -* jsonRprCheck - -*/ -extern std::string jsonRprCheck(ParseData* reqDataP, ConnectionInfo* ciP); - -#endif // SRC_LIB_JSONPARSE_JSONREGISTERPROVIDERREQUEST_H_ diff --git a/src/lib/jsonParse/jsonRequest.cpp b/src/lib/jsonParse/jsonRequest.cpp deleted file mode 100644 index 1ebf8769ab..0000000000 --- a/src/lib/jsonParse/jsonRequest.cpp +++ /dev/null @@ -1,260 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/limits.h" -#include "alarmMgr/alarmMgr.h" -#include "ngsi/Request.h" -#include "ngsi/ParseData.h" - -#include "jsonParse/JsonNode.h" -#include "jsonParse/jsonParse.h" -#include "jsonParse/jsonRequest.h" - -#include "jsonParse/jsonRegisterContextRequest.h" -#include "jsonParse/jsonDiscoverContextAvailabilityRequest.h" - -#include "jsonParse/jsonQueryContextRequest.h" -#include "jsonParse/jsonQueryContextResponse.h" -#include "jsonParse/jsonUpdateContextRequest.h" -#include "jsonParse/jsonUpdateContextResponse.h" -#include "jsonParse/jsonSubscribeContextRequest.h" -#include "jsonParse/jsonUnsubscribeContextRequest.h" -#include "jsonParse/jsonNotifyContextRequest.h" -#include "jsonParse/jsonUpdateContextSubscriptionRequest.h" - -#include "jsonParse/jsonRegisterProviderRequest.h" -#include "jsonParse/jsonUpdateContextElementRequest.h" -#include "jsonParse/jsonAppendContextElementRequest.h" -#include "jsonParse/jsonUpdateContextAttributeRequest.h" - -#include "parse/compoundValue.h" -#include "rest/restReply.h" - - -#define FUNCS(prefix) json##prefix##ParseVector, json##prefix##Init, \ - json##prefix##Check, json##prefix##Release - - - -/* **************************************************************************** -* -* jsonRequest - -*/ -static JsonRequest jsonRequest[] = -{ - // NGSI9 - { RegisterContext, "POST", "registerContextRequest", FUNCS(Rcr) }, - { DiscoverContextAvailability, "POST", "discoverContextAvailabilityRequest", FUNCS(Dcar) }, - - // NGSI10 - { QueryContext, "POST", "queryContextRequest", FUNCS(Qcr) }, - { UpdateContext, "POST", "updateContextRequest", FUNCS(Upcr) }, - { SubscribeContext, "POST", "subscribeContextRequest", FUNCS(Scr) }, - { NotifyContext, "POST", "notifyContextRequest", FUNCS(Ncr) }, - { UnsubscribeContext, "POST", "unsubscribeContextRequest", FUNCS(Uncr) }, - { UpdateContextSubscription, "POST", "updateContextSubscriptionRequest", FUNCS(Ucsr) }, - - // Convenience - { ContextEntitiesByEntityId, "POST", "registerProviderRequest", FUNCS(Rpr) }, - { ContextEntitiesByEntityId, "*", "registerProviderRequest", FUNCS(Rpr) }, - { EntityByIdAttributeByName, "POST", "registerProviderRequest", FUNCS(Rpr) }, - { EntityByIdAttributeByName, "*", "registerProviderRequest", FUNCS(Rpr) }, - { ContextEntityAttributes, "POST", "registerProviderRequest", FUNCS(Rpr) }, - { ContextEntityAttributes, "*", "registerProviderRequest", FUNCS(Rpr) }, - { ContextEntityTypeAttributeContainer, "POST", "registerProviderRequest", FUNCS(Rpr) }, - { ContextEntityTypeAttributeContainer, "*", "registerProviderRequest", FUNCS(Rpr) }, - { ContextEntityTypeAttribute, "POST", "registerProviderRequest", FUNCS(Rpr) }, - { ContextEntityTypeAttribute, "*", "registerProviderRequest", FUNCS(Rpr) }, - - { IndividualContextEntity, "PUT", "updateContextElementRequest", FUNCS(Ucer) }, - { IndividualContextEntity, "POST", "appendContextElementRequest", FUNCS(Acer) }, - { AllContextEntities, "POST", "appendContextElementRequest", FUNCS(Acer) }, - - { ContextEntityTypes, "POST", "registerProviderRequest", FUNCS(Rpr) }, - { ContextEntityTypes, "*", "registerProviderRequest", FUNCS(Rpr) }, - - { IndividualContextEntityAttribute, "POST", "updateContextAttributeRequest", FUNCS(Upcar) }, - { IndividualContextEntityAttribute, "PUT", "updateContextAttributeRequest", FUNCS(Upcar) }, - { IndividualContextEntityAttributes, "POST", "appendContextElementRequest", FUNCS(Acer) }, - { IndividualContextEntityAttributes, "PUT", "updateContextElementRequest", FUNCS(Ucer) }, - { AttributeValueInstance, "PUT", "updateContextAttributeRequest", FUNCS(Upcar) }, - { Ngsi10SubscriptionsConvOp, "PUT", "updateContextSubscriptionRequest", FUNCS(Ucsr) }, - - { AllEntitiesWithTypeAndId, "PUT", "updateContextElementRequest", FUNCS(Ucer) }, - { AllEntitiesWithTypeAndId, "POST", "appendContextElementRequest", FUNCS(Acer) }, - { AllEntitiesWithTypeAndId, "*", "", FUNCS(Ucer) }, - - { IndividualContextEntityAttributeWithTypeAndId, "POST", "updateContextAttributeRequest", FUNCS(Upcar) }, - { IndividualContextEntityAttributeWithTypeAndId, "PUT", "updateContextAttributeRequest", FUNCS(Upcar) }, - - { AttributeValueInstanceWithTypeAndId, "PUT", "updateContextAttributeRequest", FUNCS(Upcar) }, - { AttributeValueInstanceWithTypeAndId, "POST", "updateContextAttributeRequest", FUNCS(Upcar) }, - - { ContextEntitiesByEntityIdAndType, "POST", "registerProviderRequest", FUNCS(Rpr) }, - { EntityByIdAttributeByNameIdAndType, "POST", "registerProviderRequest", FUNCS(Rpr) }, - - { RtQueryContextResponse, "POST", "queryContextResponse", FUNCS(Qcrs) }, - { RtUpdateContextResponse, "POST", "updateContextResponse", FUNCS(Upcrs) } -}; - - - -/* **************************************************************************** -* -* jsonRequestGet - -*/ -static JsonRequest* jsonRequestGet(RequestType request, std::string method) -{ - for (unsigned int ix = 0; ix < sizeof(jsonRequest) / sizeof(jsonRequest[0]); ++ix) - { - if ((request == jsonRequest[ix].type) && (jsonRequest[ix].method == method)) - { - if (jsonRequest[ix].parseVector != NULL) - { - LM_T(LmtHttpRequest, ("Found jsonRequest of type %d, method '%s' - index %d (%s)", - request, method.c_str(), ix, jsonRequest[ix].parseVector[0].path.c_str())); - } - - return &jsonRequest[ix]; - } - } - - std::string extra = std::string("RequestType '") + requestType(request) + "'', method '" + method + "'"; - alarmMgr.badInput(clientIp, "no request found", extra); - - return NULL; -} - - - -/* **************************************************************************** -* -* jsonTreat - -*/ -std::string jsonTreat -( - const char* content, - ConnectionInfo* ciP, - ParseData* parseDataP, - RequestType request, - JsonRequest** reqPP -) -{ - std::string res = "OK"; - JsonRequest* reqP = jsonRequestGet(request, ciP->method); - - // - // FIXME P4 #1862: - // - // This check comes from the old XML days, as the the XML parsing library did an assert - // and the broker died. We need to test what happen with the JSON library. - // If JSON library is "safer" with that regards, the check should be removed. - // - // 'OK' is returned as there is no error to send a request without payload. - // - if ((content == NULL) || (*content == 0)) - { - return "OK"; - } - - LM_T(LmtParse, ("Treating a JSON request: '%s'", content)); - - ciP->parseDataP = parseDataP; - - if (reqP == NULL) - { - std::string details = std::string("Sorry, no request treating object found for RequestType /") + requestType(request) + "/"; - std::string errorReply; - char reqTypeV[STRING_SIZE_FOR_INT]; - - restErrorReplyGet(ciP, SccBadRequest, details, &errorReply); - snprintf(reqTypeV, sizeof(reqTypeV), "%d", request); - - std::string extra = std::string("RequestType ") + reqTypeV + " (" + requestType(request) + ")"; - alarmMgr.badInput(clientIp, "no request treating object found for RequestType", extra); - - return errorReply; - } - - if (reqPP != NULL) - { - *reqPP = reqP; - } - - LM_T(LmtParse, ("Treating '%s' request", reqP->keyword.c_str())); - - reqP->init(parseDataP); - - try - { - res = jsonParse(ciP, content, reqP->keyword, reqP->parseVector, parseDataP); - } - catch (const std::exception &e) - { - std::string errorReply; - restErrorReplyGet(ciP, SccBadRequest, "JSON Parse Error", &errorReply); - alarmMgr.badInput(clientIp, "JSON Parse Error", e.what()); - return errorReply; - } - catch (...) - { - std::string errorReply; - - restErrorReplyGet(ciP, SccBadRequest, "JSON Generic Error", &errorReply); - alarmMgr.badInput(clientIp, "JSON parse generic error"); - return errorReply; - } - - if (res != "OK") - { - std::string answer; - alarmMgr.badInput(clientIp, "JSON Parse Error", res); - ciP->httpStatusCode = SccBadRequest; - restErrorReplyGet(ciP, ciP->httpStatusCode, res, &answer); - return answer; - } - - if (ciP->inCompoundValue == true) - { - orion::compoundValueEnd(ciP, parseDataP); - } - if ((lmTraceIsSet(LmtCompoundValueShow)) && (ciP->compoundValueP != NULL)) - { - ciP->compoundValueP->shortShow("after parse: "); - } - - res = reqP->check(parseDataP, ciP); - if (res != "OK") - { - alarmMgr.badInput(clientIp, reqP->keyword, res); - } - - return res; -} diff --git a/src/lib/jsonParse/jsonRequest.h b/src/lib/jsonParse/jsonRequest.h deleted file mode 100644 index 905edda14c..0000000000 --- a/src/lib/jsonParse/jsonRequest.h +++ /dev/null @@ -1,67 +0,0 @@ -#ifndef SRC_LIB_JSONPARSE_JSONREQUEST_H_ -#define SRC_LIB_JSONPARSE_JSONREQUEST_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include "ngsi/Request.h" -#include "ngsi/ParseData.h" -#include "jsonParse/JsonNode.h" - -class ConnectionInfo; - - - -/* **************************************************************************** -* -* JsonRequest - -*/ -typedef struct JsonRequest -{ - RequestType type; - std::string method; - std::string keyword; - JsonNode* parseVector; - RequestInit init; - RequestCheck check; - RequestRelease release; -} JsonRequest; - - - -/* **************************************************************************** -* -* jsonTreat - -*/ -extern std::string jsonTreat -( - const char* content, - ConnectionInfo* ciP, - ParseData* parseDataP, - RequestType request, - JsonRequest** reqPP -); - -#endif // SRC_LIB_JSONPARSE_JSONREQUEST_H_ diff --git a/src/lib/jsonParse/jsonSubscribeContextRequest.cpp b/src/lib/jsonParse/jsonSubscribeContextRequest.cpp deleted file mode 100644 index 704c7dd893..0000000000 --- a/src/lib/jsonParse/jsonSubscribeContextRequest.cpp +++ /dev/null @@ -1,566 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/globals.h" -#include "alarmMgr/alarmMgr.h" - -#include "orionTypes/areas.h" -#include "ngsi/EntityId.h" -#include "ngsi10/SubscribeContextRequest.h" -#include "parse/nullTreat.h" -#include "jsonParse/JsonNode.h" -#include "jsonParse/jsonSubscribeContextRequest.h" - -using namespace orion; - - - -/* **************************************************************************** -* -* entityId - -*/ -static std::string entityId(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("%s: %s", path.c_str(), value.c_str())); - - parseDataP->scr.entityIdP = new EntityId(); - - LM_T(LmtNew, ("New entityId at %p", parseDataP->scr.entityIdP)); - parseDataP->scr.entityIdP->id = ""; - parseDataP->scr.entityIdP->type = ""; - parseDataP->scr.entityIdP->isPattern = "false"; - - parseDataP->scr.res.entityIdVector.push_back(parseDataP->scr.entityIdP); - LM_T(LmtNew, ("After push_back")); - - return "OK"; -} - - - -/* **************************************************************************** -* -* entityIdId - -*/ -static std::string entityIdId(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - parseDataP->scr.entityIdP->id = value; - LM_T(LmtParse, ("Set 'id' to '%s' for an entity", parseDataP->scr.entityIdP->id.c_str())); - - return "OK"; -} - - - -/* **************************************************************************** -* -* entityIdType - -*/ -static std::string entityIdType(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - parseDataP->scr.entityIdP->type = value; - LM_T(LmtParse, ("Set 'type' to '%s' for an entity", parseDataP->scr.entityIdP->type.c_str())); - - return "OK"; -} - - - -/* **************************************************************************** -* -* entityIdIsPattern - -*/ -static std::string entityIdIsPattern(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got an entityId:isPattern: '%s'", value.c_str())); - - parseDataP->scr.entityIdP->isPattern = value; - - return "OK"; -} - - - -/* **************************************************************************** -* -* attribute - -*/ -static std::string attribute(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got an attribute: '%s'", value.c_str())); - - parseDataP->scr.res.attributeList.push_back(value); - - return "OK"; -} - - - -/* **************************************************************************** -* -* reference - -*/ -static std::string reference(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a reference: '%s'", value.c_str())); - - parseDataP->scr.res.reference.set(value); - - return "OK"; -} - - - -/* **************************************************************************** -* -* duration - -*/ -static std::string duration(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - std::string s; - - LM_T(LmtParse, ("Got a duration: '%s'", value.c_str())); - - parseDataP->scr.res.duration.set(value); - - if ((s = parseDataP->scr.res.duration.check()) != "OK") - { - std::string extra = parseDataP->scr.res.duration.get() + "': " + s; - alarmMgr.badInput(clientIp, "error parsing duration", extra); - return s; - } - - return "OK"; -} - - - -/* **************************************************************************** -* -* restriction - -*/ -static std::string restriction(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a restriction")); - - ++parseDataP->scr.res.restrictions; - - return "OK"; -} - - - -/* **************************************************************************** -* -* attributeExpression - -*/ -static std::string attributeExpression(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got an attributeExpression: '%s'", value.c_str())); - - parseDataP->scr.res.restriction.attributeExpression.set(value); - - return "OK"; -} - - - -/* **************************************************************************** -* -* scope - -*/ -static std::string scope(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a scope")); - - parseDataP->scr.scopeP = new Scope(); - parseDataP->scr.res.restriction.scopeVector.push_back(parseDataP->scr.scopeP); - - return "OK"; -} - - - -/* **************************************************************************** -* -* scopeType - -*/ -static std::string scopeType(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a scope type: '%s'", value.c_str())); - - parseDataP->scr.scopeP->type = value; - - return "OK"; -} - - - -/* **************************************************************************** -* -* scopeValue - -*/ -static std::string scopeValue(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - if (parseDataP->scr.scopeP->type == FIWARE_LOCATION || parseDataP->scr.scopeP->type == FIWARE_LOCATION_DEPRECATED) - { - // - // If the scope type is FIWARE_LOCATION (or its deprecated variant), then the value of this scope is stored in 'circle' or 'polygon'. - // The field 'value' is not used as more complexity is needed. - // scopeP->value is here set to FIWARE_LOCATION, in an attempt to warn a future use of 'scopeP->value' when - // instead 'circle' or 'polygon' should be used. - // - parseDataP->scr.scopeP->value = FIWARE_LOCATION; - LM_T(LmtParse, ("Preparing scopeValue for '%s'", parseDataP->scr.scopeP->type.c_str())); - } - else - { - parseDataP->scr.scopeP->value = value; - LM_T(LmtParse, ("Got a scopeValue: '%s' for scopeType '%s'", value.c_str(), parseDataP->scr.scopeP->type.c_str())); - } - - return "OK"; -} - - - -/* **************************************************************************** -* -* circle - -*/ -static std::string circle(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a circle")); - parseDataP->scr.scopeP->areaType = orion::CircleType; - return "OK"; -} - - - -/* **************************************************************************** -* -* circleCenterLatitude - -*/ -static std::string circleCenterLatitude(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a circleCenterLatitude: %s", value.c_str())); - parseDataP->scr.scopeP->circle.center.latitudeSet(value); - - return "OK"; -} - - - -/* **************************************************************************** -* -* circleCenterLongitude - -*/ -static std::string circleCenterLongitude(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a circleCenterLongitude: %s", value.c_str())); - parseDataP->scr.scopeP->circle.center.longitudeSet(value); - return "OK"; -} - - - -/* **************************************************************************** -* -* circleRadius - -*/ -static std::string circleRadius(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a circleRadius: %s", value.c_str())); - parseDataP->scr.scopeP->circle.radiusSet(value); - return "OK"; -} - - - -/* **************************************************************************** -* -* circleInverted - -*/ -static std::string circleInverted(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a circleInverted: %s", value.c_str())); - - parseDataP->scr.scopeP->circle.invertedSet(value); - - if (!isTrue(value) && !isFalse(value)) - { - alarmMgr.badInput(clientIp, "invalid string for circle/inverted", value); - parseDataP->errorString = "bad string for circle/inverted: /" + value + "/"; - return parseDataP->errorString; - } - - return "OK"; -} - - - -/* **************************************************************************** -* -* polygon - -*/ -static std::string polygon(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a polygon")); - parseDataP->scr.scopeP->areaType = orion::PolygonType; - return "OK"; -} - - - -/* **************************************************************************** -* -* polygonInverted - -*/ -static std::string polygonInverted(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a polygonInverted: %s", value.c_str())); - - parseDataP->scr.scopeP->polygon.invertedSet(value); - - if (!isTrue(value) && !isFalse(value)) - { - parseDataP->errorString = "bad string for polygon/inverted: /" + value + "/"; - return parseDataP->errorString; - } - - return "OK"; -} - - - -/* **************************************************************************** -* -* polygonVertexList - -*/ -static std::string polygonVertexList(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a polygonVertexList")); - return "OK"; -} - - - -/* **************************************************************************** -* -* polygonVertex - -*/ -static std::string polygonVertex(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a polygonVertex - creating new vertex for the vertex list")); - parseDataP->scr.vertexP = new orion::Point(); - parseDataP->scr.scopeP->polygon.vertexList.push_back(parseDataP->scr.vertexP); - return "OK"; -} - - - -/* **************************************************************************** -* -* polygonVertexLatitude - -*/ -static std::string polygonVertexLatitude(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a polygonVertexLatitude: %s", value.c_str())); - parseDataP->scr.vertexP->latitudeSet(value); - return "OK"; -} - - - -/* **************************************************************************** -* -* polygonVertexLongitude - -*/ -static std::string polygonVertexLongitude(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a polygonVertexLongitude: %s", value.c_str())); - parseDataP->scr.vertexP->longitudeSet(value); - return "OK"; -} - - - -/* **************************************************************************** -* -* notifyCondition - -*/ -static std::string notifyCondition(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a notifyCondition")); - parseDataP->scr.notifyConditionP = new NotifyCondition(); - parseDataP->scr.res.notifyConditionVector.push_back(parseDataP->scr.notifyConditionP); - return "OK"; -} - - - -/* **************************************************************************** -* -* notifyConditionRestriction - -*/ -static std::string notifyConditionRestriction(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a Notify Condition restriction")); - - parseDataP->scr.notifyConditionP->restriction.set(value); - return "OK"; -} - - - -/* **************************************************************************** -* -* notifyConditionType - -*/ -static std::string notifyConditionType(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a Notify Condition Type: '%s'", value.c_str())); - parseDataP->scr.notifyConditionP->type = value; - return "OK"; -} - - - -/* **************************************************************************** -* -* condValue - -*/ -static std::string notifyConditionCondValue(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a Cond Value: '%s'", value.c_str())); - parseDataP->scr.notifyConditionP->condValueList.push_back(value); - return "OK"; -} - - - -/* **************************************************************************** -* -* throttling - -*/ -static std::string throttling(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a throttling: '%s'", value.c_str())); - parseDataP->scr.res.throttling.set(value); - return "OK"; -} - - - -/* **************************************************************************** -* -* jsonScrParseVector - -*/ -JsonNode jsonScrParseVector[] = -{ - { "/entities", jsonNullTreat }, - { "/entities/entity", entityId }, - { "/entities/entity/id", entityIdId }, - { "/entities/entity/type", entityIdType }, - { "/entities/entity/isPattern", entityIdIsPattern }, - { "/attributes", jsonNullTreat }, - { "/attributes/attribute", attribute }, - { "/reference", reference }, - { "/duration", duration }, - { "/restriction", restriction }, - { "/restriction/attributeExpression", attributeExpression }, - { "/restriction/scopes", jsonNullTreat }, - { "/restriction/scopes/scope", scope, }, - { "/restriction/scopes/scope/type", scopeType }, - { "/restriction/scopes/scope/value", scopeValue }, - { "/restriction/scopes/scope/value/circle", circle }, - { "/restriction/scopes/scope/value/circle/centerLatitude", circleCenterLatitude }, - { "/restriction/scopes/scope/value/circle/centerLongitude", circleCenterLongitude }, - { "/restriction/scopes/scope/value/circle/radius", circleRadius }, - { "/restriction/scopes/scope/value/circle/inverted", circleInverted }, - - { "/restriction/scopes/scope/value/polygon", polygon }, - { "/restriction/scopes/scope/value/polygon/vertices", polygonVertexList }, - { "/restriction/scopes/scope/value/polygon/vertices/vertice", polygonVertex }, - { "/restriction/scopes/scope/value/polygon/vertices/vertice/latitude", polygonVertexLatitude }, - { "/restriction/scopes/scope/value/polygon/vertices/vertice/longitude", polygonVertexLongitude }, - { "/restriction/scopes/scope/value/polygon/inverted", polygonInverted }, - - { "/notifyConditions", jsonNullTreat }, - { "/notifyConditions/notifyCondition", notifyCondition }, - { "/notifyConditions/notifyCondition/type", notifyConditionType }, - { "/notifyConditions/notifyCondition/condValues", jsonNullTreat }, - { "/notifyConditions/notifyCondition/condValues/condValue", notifyConditionCondValue }, - { "/notifyConditions/notifyCondition/restriction", notifyConditionRestriction }, - { "/throttling", throttling }, - - { "LAST", NULL } -}; - - - -/* **************************************************************************** -* -* jsonScrInit - -*/ -void jsonScrInit(ParseData* parseDataP) -{ - jsonScrRelease(parseDataP); - - parseDataP->scr.entityIdP = NULL; - parseDataP->scr.notifyConditionP = NULL; - parseDataP->scr.scopeP = NULL; - parseDataP->scr.res.restrictions = 0; - parseDataP->errorString = ""; -} - - - -/* **************************************************************************** -* -* jsonScrRelease - -*/ -void jsonScrRelease(ParseData* parseDataP) -{ - parseDataP->scr.res.release(); -} - - - -/* **************************************************************************** -* -* jsonScrCheck - -*/ -std::string jsonScrCheck(ParseData* parseDataP, ConnectionInfo* ciP) -{ - std::string s; - s = parseDataP->scr.res.check(parseDataP->errorString, 0); - return s; -} diff --git a/src/lib/jsonParse/jsonSubscribeContextRequest.h b/src/lib/jsonParse/jsonSubscribeContextRequest.h deleted file mode 100644 index a67f7b03c5..0000000000 --- a/src/lib/jsonParse/jsonSubscribeContextRequest.h +++ /dev/null @@ -1,66 +0,0 @@ -#ifndef SRC_LIB_JSONPARSE_JSONSUBSCRIBECONTEXTREQUEST_H_ -#define SRC_LIB_JSONPARSE_JSONSUBSCRIBECONTEXTREQUEST_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "rest/ConnectionInfo.h" -#include "jsonParse/JsonNode.h" - - - -/* **************************************************************************** -* -* jsonScrParseVector - -*/ -extern JsonNode jsonScrParseVector[]; - - - -/* **************************************************************************** -* -* jsonScrInit - -*/ -extern void jsonScrInit(ParseData* reqDataP); - - - -/* **************************************************************************** -* -* jsonScrRelease - -*/ -extern void jsonScrRelease(ParseData* reqDataP); - - - -/* **************************************************************************** -* -* jsonScrCheck - -*/ -extern std::string jsonScrCheck(ParseData* reqDataP, ConnectionInfo* ciP); - -#endif // SRC_LIB_JSONPARSE_JSONSUBSCRIBECONTEXTREQUEST_H_ diff --git a/src/lib/jsonParse/jsonUnsubscribeContextRequest.cpp b/src/lib/jsonParse/jsonUnsubscribeContextRequest.cpp deleted file mode 100755 index 5a9f320f62..0000000000 --- a/src/lib/jsonParse/jsonUnsubscribeContextRequest.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/globals.h" -#include "jsonParse/JsonNode.h" -#include "jsonParse/jsonUnsubscribeContextRequest.h" - - - -/* **************************************************************************** -* -* subscriptionId - -*/ -static std::string subscriptionId(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("%s: %s", path.c_str(), value.c_str())); - parseDataP->uncr.res.subscriptionId.set(value); - return "OK"; -} - - - -/* **************************************************************************** -* -* jsonUncrParseVector - -*/ -JsonNode jsonUncrParseVector[] = -{ - { "/subscriptionId", subscriptionId }, - { "LAST", NULL } -}; - - - -/* **************************************************************************** -* -* jsonUncrInit - -*/ -void jsonUncrInit(ParseData* parseDataP) -{ - jsonUncrRelease(parseDataP); - parseDataP->errorString = ""; -} - - - -/* **************************************************************************** -* -* jsonUncrRelease - -*/ -void jsonUncrRelease(ParseData* parseDataP) -{ - parseDataP->uncr.res.release(); -} - - - -/* **************************************************************************** -* -* jsonUncrCheck - -*/ -std::string jsonUncrCheck(ParseData* parseData, ConnectionInfo* ciP) -{ - return parseData->uncr.res.check(); -} diff --git a/src/lib/jsonParse/jsonUnsubscribeContextRequest.h b/src/lib/jsonParse/jsonUnsubscribeContextRequest.h deleted file mode 100644 index d3ae4804a2..0000000000 --- a/src/lib/jsonParse/jsonUnsubscribeContextRequest.h +++ /dev/null @@ -1,66 +0,0 @@ -#ifndef SRC_LIB_JSONPARSE_JSONUNSUBSCRIBECONTEXTREQUEST_H_ -#define SRC_LIB_JSONPARSE_JSONUNSUBSCRIBECONTEXTREQUEST_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "rest/ConnectionInfo.h" -#include "jsonParse/JsonNode.h" - - - -/* **************************************************************************** -* -* jsonUncrParseVector - -*/ -extern JsonNode jsonUncrParseVector[]; - - - -/* **************************************************************************** -* -* jsonUncrInit - -*/ -extern void jsonUncrInit(ParseData* reqDataP); - - - -/* **************************************************************************** -* -* jsonUncrRelease - -*/ -extern void jsonUncrRelease(ParseData* reqDataP); - - - -/* **************************************************************************** -* -* jsonUncrCheck - -*/ -extern std::string jsonUncrCheck(ParseData* reqDataP, ConnectionInfo* ciP); - -#endif // SRC_LIB_JSONPARSE_JSONUNSUBSCRIBECONTEXTREQUEST_H_ diff --git a/src/lib/jsonParse/jsonUpdateContextAttributeRequest.cpp b/src/lib/jsonParse/jsonUpdateContextAttributeRequest.cpp deleted file mode 100755 index 223b4499da..0000000000 --- a/src/lib/jsonParse/jsonUpdateContextAttributeRequest.cpp +++ /dev/null @@ -1,171 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/globals.h" -#include "convenience/UpdateContextAttributeRequest.h" -#include "jsonParse/jsonParse.h" -#include "jsonParse/JsonNode.h" -#include "jsonParse/jsonUpdateContextAttributeRequest.h" -#include "parse/nullTreat.h" -#include "rest/ConnectionInfo.h" -#include "rest/uriParamNames.h" - - - -/* **************************************************************************** -* -* attributeType - -*/ -static std::string attributeType(const std::string& path, const std::string& value, ParseData* reqData) -{ - reqData->upcar.res.type = value; - - return "OK"; -} - - - -/* **************************************************************************** -* -* attributeValue - -*/ -static std::string attributeValue(const std::string& path, const std::string& value, ParseData* reqData) -{ - reqData->upcar.res.valueType = orion::ValueTypeString; - reqData->upcar.res.contextValue = value; - - return "OK"; -} - - - -/* **************************************************************************** -* -* contextMetadata - -*/ -static std::string contextMetadata(const std::string& path, const std::string& value, ParseData* reqData) -{ - LM_T(LmtParse, ("Creating a metadata")); - reqData->upcar.metadataP = new Metadata(); - reqData->upcar.res.metadataVector.push_back(reqData->upcar.metadataP); - return "OK"; -} - - - -/* **************************************************************************** -* -* contextMetadataName - -*/ -static std::string contextMetadataName(const std::string& path, const std::string& value, ParseData* reqData) -{ - LM_T(LmtParse, ("Got a metadata name: '%s'", value.c_str())); - reqData->upcar.metadataP->name = safeValue(value); - return "OK"; -} - - - -/* **************************************************************************** -* -* contextMetadataType - -*/ -static std::string contextMetadataType(const std::string& path, const std::string& value, ParseData* reqData) -{ - LM_T(LmtParse, ("Got a metadata type: '%s'", value.c_str())); - reqData->upcar.metadataP->type = value; - reqData->upcar.metadataP->typeGiven = true; - return "OK"; -} - - - -/* **************************************************************************** -* -* contextMetadataValue - -*/ -static std::string contextMetadataValue(const std::string& path, const std::string& value, ParseData* reqData) -{ - LM_T(LmtParse, ("Got a metadata value: '%s'", value.c_str())); - reqData->upcar.metadataP->stringValue = value; - reqData->upcar.metadataP->valueType = orion::ValueTypeString; - return "OK"; -} - - - -/* **************************************************************************** -* -* jsonUpcarParseVector - -*/ -JsonNode jsonUpcarParseVector[] = -{ - { "/type", attributeType }, - { "/value", attributeValue }, - { "/metadatas", jsonNullTreat }, - { "/metadatas/metadata", contextMetadata }, - { "/metadatas/metadata/name", contextMetadataName }, - { "/metadatas/metadata/type", contextMetadataType }, - { "/metadatas/metadata/value", contextMetadataValue }, - - { "LAST", NULL } -}; - - - -/* **************************************************************************** -* -* jsonUpcarInit - -*/ -void jsonUpcarInit(ParseData* reqData) -{ -} - - - -/* **************************************************************************** -* -* jsonUpcarRelease - -*/ -void jsonUpcarRelease(ParseData* reqData) -{ - reqData->upcar.res.release(); -} - - - -/* **************************************************************************** -* -* jsonUpcarCheck - -*/ -std::string jsonUpcarCheck(ParseData* reqData, ConnectionInfo* ciP) -{ - return reqData->upcar.res.check(ciP->apiVersion, reqData->errorString); -} diff --git a/src/lib/jsonParse/jsonUpdateContextAttributeRequest.h b/src/lib/jsonParse/jsonUpdateContextAttributeRequest.h deleted file mode 100644 index b8839390ae..0000000000 --- a/src/lib/jsonParse/jsonUpdateContextAttributeRequest.h +++ /dev/null @@ -1,65 +0,0 @@ -#ifndef SRC_LIB_JSONPARSE_JSONUPDATECONTEXTATTRIBUTEREQUEST_H_ -#define SRC_LIB_JSONPARSE_JSONUPDATECONTEXTATTRIBUTEREQUEST_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include - -#include "ngsi/ParseData.h" -#include "jsonParse/JsonNode.h" - - - -/* **************************************************************************** -* -* jsonUpcarParseVector - -*/ -extern JsonNode jsonUpcarParseVector[]; - - - -/* **************************************************************************** -* -* jsonUpcarInit - -*/ -extern void jsonUpcarInit(ParseData* reqData); - - - -/* **************************************************************************** -* -* jsonUpcarRelease - -*/ -extern void jsonUpcarRelease(ParseData* reqData); - - - -/* **************************************************************************** -* -* jsonUpcarCheck - -*/ -extern std::string jsonUpcarCheck(ParseData* reqData, ConnectionInfo* ciP); - -#endif // SRC_LIB_JSONPARSE_JSONUPDATECONTEXTATTRIBUTEREQUEST_H_ diff --git a/src/lib/jsonParse/jsonUpdateContextElementRequest.cpp b/src/lib/jsonParse/jsonUpdateContextElementRequest.cpp deleted file mode 100644 index 1b7682446e..0000000000 --- a/src/lib/jsonParse/jsonUpdateContextElementRequest.cpp +++ /dev/null @@ -1,203 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/globals.h" -#include "jsonParse/jsonParse.h" -#include "jsonParse/JsonNode.h" -#include "jsonParse/jsonUpdateContextElementRequest.h" -#include "parse/nullTreat.h" -#include "ngsi/Request.h" -#include "rest/ConnectionInfo.h" -#include "rest/uriParamNames.h" - - - -/* **************************************************************************** -* -* contextAttribute - -*/ -static std::string contextAttribute(const std::string& path, const std::string& value, ParseData* reqData) -{ - LM_T(LmtParse, ("Got an attribute")); - reqData->ucer.attributeP = new ContextAttribute(); - reqData->ucer.res.contextAttributeVector.push_back(reqData->ucer.attributeP); - return "OK"; -} - - - -/* **************************************************************************** -* -* contextAttributeName - -*/ -static std::string contextAttributeName(const std::string& path, const std::string& value, ParseData* reqData) -{ - LM_T(LmtParse, ("Got an attribute name: %s", value.c_str())); - reqData->ucer.attributeP->name = safeValue(value); - return "OK"; -} - - - -/* **************************************************************************** -* -* contextAttributeType - -*/ -static std::string contextAttributeType(const std::string& path, const std::string& value, ParseData* reqData) -{ - LM_T(LmtParse, ("Got an attribute type: %s", value.c_str())); - reqData->ucer.attributeP->type = value; - return "OK"; -} - - - -/* **************************************************************************** -* -* contextAttributeValue - -*/ -static std::string contextAttributeValue(const std::string& path, const std::string& value, ParseData* reqData) -{ - reqData->lastContextAttribute = reqData->ucer.attributeP; - LM_T(LmtParse, ("Got an attribute value: %s", value.c_str())); - reqData->ucer.attributeP->stringValue = value; - reqData->ucer.attributeP->valueType = orion::ValueTypeString; - return "OK"; -} - - - -/* **************************************************************************** -* -* contextMetadata - -*/ -static std::string contextMetadata(const std::string& path, const std::string& value, ParseData* reqData) -{ - LM_T(LmtParse, ("Got a metadata")); - reqData->ucer.metadataP = new Metadata(); - reqData->ucer.attributeP->metadataVector.push_back(reqData->ucer.metadataP); - return "OK"; -} - - - -/* **************************************************************************** -* -* contextMetadataName - -*/ -static std::string contextMetadataName(const std::string& path, const std::string& value, ParseData* reqData) -{ - LM_T(LmtParse, ("Got a metadata name '%s'", value.c_str())); - reqData->ucer.metadataP->name = safeValue(value); - return "OK"; -} - - - -/* **************************************************************************** -* -* contextMetadataType - -*/ -static std::string contextMetadataType(const std::string& path, const std::string& value, ParseData* reqData) -{ - LM_T(LmtParse, ("Got a metadata type '%s'", value.c_str())); - reqData->ucer.metadataP->type = value; - return "OK"; -} - - - -/* **************************************************************************** -* -* contextMetadataValue - -*/ -static std::string contextMetadataValue(const std::string& path, const std::string& value, ParseData* reqData) -{ - LM_T(LmtParse, ("Got a metadata value '%s'", value.c_str())); - reqData->ucer.metadataP->stringValue = value; - reqData->ucer.metadataP->valueType = orion::ValueTypeString; - return "OK"; -} - - - -/* **************************************************************************** -* -* ucerParseVector - -*/ -JsonNode jsonUcerParseVector[] = -{ - { "/attributes", jsonNullTreat }, - { "/attributes/attribute", contextAttribute }, - { "/attributes/attribute/name", contextAttributeName }, - { "/attributes/attribute/type", contextAttributeType }, - { "/attributes/attribute/value", contextAttributeValue }, - - { "/attributes/attribute/metadatas", jsonNullTreat }, - { "/attributes/attribute/metadatas/metadata", contextMetadata }, - { "/attributes/attribute/metadatas/metadata/name", contextMetadataName }, - { "/attributes/attribute/metadatas/metadata/type", contextMetadataType }, - { "/attributes/attribute/metadatas/metadata/value", contextMetadataValue }, - - { "LAST", NULL } -}; - -/* **************************************************************************** -* -* ucerInit - -*/ -void jsonUcerInit(ParseData* reqData) -{ - reqData->ucer.attributeP = NULL; - reqData->ucer.metadataP = NULL; -} - - - -/* **************************************************************************** -* -* ucerRelease - -*/ -void jsonUcerRelease(ParseData* reqData) -{ - reqData->ucer.res.release(); -} - - - -/* **************************************************************************** -* -* ucerCheck - -*/ -std::string jsonUcerCheck(ParseData* reqData, ConnectionInfo* ciP) -{ - bool asJsonObject = (ciP->uriParam[URI_PARAM_ATTRIBUTE_FORMAT] == "object" && ciP->outMimeType == JSON); - return reqData->ucer.res.check(ciP->apiVersion, asJsonObject, UpdateContextElement, reqData->errorString); -} diff --git a/src/lib/jsonParse/jsonUpdateContextElementRequest.h b/src/lib/jsonParse/jsonUpdateContextElementRequest.h deleted file mode 100644 index 27217124bc..0000000000 --- a/src/lib/jsonParse/jsonUpdateContextElementRequest.h +++ /dev/null @@ -1,65 +0,0 @@ -#ifndef SRC_LIB_JSONPARSE_JSONUPDATECONTEXTELEMENTREQUEST_H_ -#define SRC_LIB_JSONPARSE_JSONUPDATECONTEXTELEMENTREQUEST_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "jsonParse/JsonNode.h" - - - -/* **************************************************************************** -* -* ucerParseVector - -*/ -extern JsonNode jsonUcerParseVector[]; - - - -/* **************************************************************************** -* -* ucerInit - -*/ -extern void jsonUcerInit(ParseData* reqData); - - - -/* **************************************************************************** -* -* ucerRelease - -*/ -extern void jsonUcerRelease(ParseData* reqData); - - - -/* **************************************************************************** -* -* ucerCheck - -*/ -extern std::string jsonUcerCheck(ParseData* reqData, ConnectionInfo* ciP); - -#endif // SRC_LIB_JSONPARSE_JSONUPDATECONTEXTELEMENTREQUEST_H_ diff --git a/src/lib/jsonParse/jsonUpdateContextRequest.cpp b/src/lib/jsonParse/jsonUpdateContextRequest.cpp deleted file mode 100755 index 5a8b59634a..0000000000 --- a/src/lib/jsonParse/jsonUpdateContextRequest.cpp +++ /dev/null @@ -1,304 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/globals.h" -#include "jsonParse/JsonNode.h" -#include "jsonParse/jsonParse.h" -#include "ngsi/ContextRegistrationAttribute.h" -#include "ngsi/EntityId.h" -#include "ngsi/Metadata.h" -#include "ngsi9/RegisterContextRequest.h" -#include "parse/nullTreat.h" -#include "rest/ConnectionInfo.h" -#include "rest/uriParamNames.h" - - - -/* **************************************************************************** -* -* contextElement - -*/ -static std::string contextElement(const std::string& path, const std::string& value, ParseData* reqDataP) -{ - LM_T(LmtParse, ("new contextElement")); - reqDataP->upcr.eP = new Entity(); - - reqDataP->upcr.res.entityVector.push_back(reqDataP->upcr.eP); - - reqDataP->upcr.eP->id = ""; - reqDataP->upcr.eP->type = ""; - reqDataP->upcr.eP->isPattern = "false"; - - return "OK"; -} - - - -/* **************************************************************************** -* -* entityIdId - -*/ -static std::string entityIdId(const std::string& path, const std::string& value, ParseData* reqDataP) -{ - reqDataP->upcr.eP->id = value; - LM_T(LmtParse, ("Set 'id' to '%s' for an entity", reqDataP->upcr.eP->id.c_str())); - - return "OK"; -} - - - -/* **************************************************************************** -* -* entityIdType - -*/ -static std::string entityIdType(const std::string& path, const std::string& value, ParseData* reqDataP) -{ - reqDataP->upcr.eP->type = value; - LM_T(LmtParse, ("Set 'type' to '%s' for an entity", reqDataP->upcr.eP->type.c_str())); - - return "OK"; -} - - - -/* **************************************************************************** -* -* entityIdIsPattern - -*/ -static std::string entityIdIsPattern(const std::string& path, const std::string& value, ParseData* reqDataP) -{ - LM_T(LmtParse, ("Got an entityId:isPattern: '%s'", value.c_str())); - - reqDataP->upcr.eP->isPattern = value; - - return "OK"; -} - - - -/* **************************************************************************** -* -* attribute - -*/ -static std::string attribute(const std::string& path, const std::string& value, ParseData* reqDataP) -{ - LM_T(LmtParse, ("%s: %s", path.c_str(), value.c_str())); - - reqDataP->upcr.attributeP = new ContextAttribute("", "", ""); - reqDataP->upcr.attributeP->valueType = orion::ValueTypeNotGiven; - reqDataP->upcr.eP->attributeVector.push_back(reqDataP->upcr.attributeP); - - return "OK"; -} - - - -/* **************************************************************************** -* -* attributeName - -*/ -static std::string attributeName(const std::string& path, const std::string& value, ParseData* reqDataP) -{ - reqDataP->upcr.attributeP->name = safeValue(value); - LM_T(LmtParse, ("Set 'name' to '%s' for a contextElement Attribute", reqDataP->upcr.attributeP->name.c_str())); - - return "OK"; -} - - - -/* **************************************************************************** -* -* attributeType - -*/ -static std::string attributeType(const std::string& path, const std::string& value, ParseData* reqDataP) -{ - reqDataP->upcr.attributeP->type = value; - LM_T(LmtParse, ("Set 'type' to '%s' for a contextElement attribute", reqDataP->upcr.attributeP->type.c_str())); - - return "OK"; -} - - - -/* **************************************************************************** -* -* attributeValue - -*/ -static std::string attributeValue(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - parseDataP->lastContextAttribute = parseDataP->upcr.attributeP; - LM_T(LmtCompoundValue, ("Set parseDataP->lastContextAttribute to: %p", parseDataP->lastContextAttribute)); - - parseDataP->upcr.attributeP->stringValue = value; - parseDataP->upcr.attributeP->valueType = orion::ValueTypeString; - LM_T(LmtParse, ("Set value to '%s' for a contextElement attribute", parseDataP->upcr.attributeP->stringValue.c_str())); - - return "OK"; -} - - - -/* **************************************************************************** -* -* metadata - -*/ -static std::string metadata(const std::string& path, const std::string& value, ParseData* reqDataP) -{ - LM_T(LmtParse, ("Creating a metadata")); - - reqDataP->upcr.contextMetadataP = new Metadata(); - reqDataP->upcr.attributeP->metadataVector.push_back(reqDataP->upcr.contextMetadataP); - - return "OK"; -} - - - -/* **************************************************************************** -* -* metadataName - -*/ -static std::string metadataName(const std::string& path, const std::string& value, ParseData* reqDataP) -{ - LM_T(LmtParse, ("Got a metadata name: '%s'", value.c_str())); - reqDataP->upcr.contextMetadataP->name = safeValue(value); - - return "OK"; -} - - - -/* **************************************************************************** -* -* metadataType - -*/ -static std::string metadataType(const std::string& path, const std::string& value, ParseData* reqDataP) -{ - LM_T(LmtParse, ("Got a metadata type: '%s'", value.c_str())); - reqDataP->upcr.contextMetadataP->type = value; - - return "OK"; -} - - - -/* **************************************************************************** -* -* metadataValue - -*/ -static std::string metadataValue(const std::string& path, const std::string& value, ParseData* reqDataP) -{ - LM_T(LmtParse, ("Got a metadata value: '%s'", value.c_str())); - reqDataP->upcr.contextMetadataP->stringValue = value; - reqDataP->upcr.contextMetadataP->valueType = orion::ValueTypeString; - return "OK"; -} - - - -/* **************************************************************************** -* -* updateAction - -*/ -static std::string updateAction(const std::string& path, const std::string& value, ParseData* reqDataP) -{ - LM_T(LmtParse, ("Got an updateAction: '%s'", value.c_str())); - reqDataP->upcr.res.updateActionType = parseActionTypeV1(value); - - return "OK"; -} - - - -/* **************************************************************************** -* -* jsonUpcrParseVector - -*/ -JsonNode jsonUpcrParseVector[] = -{ - { "/contextElements", jsonNullTreat }, - { "/contextElements/contextElement", contextElement }, - { "/contextElements/contextElement/type", entityIdType }, - { "/contextElements/contextElement/isPattern", entityIdIsPattern }, - { "/contextElements/contextElement/id", entityIdId }, - { "/contextElements/contextElement/attributes", jsonNullTreat }, - { "/contextElements/contextElement/attributes/attribute", attribute }, - { "/contextElements/contextElement/attributes/attribute/name", attributeName }, - { "/contextElements/contextElement/attributes/attribute/type", attributeType }, - { "/contextElements/contextElement/attributes/attribute/value", attributeValue }, - { "/contextElements/contextElement/attributes/attribute/metadatas", jsonNullTreat }, - { "/contextElements/contextElement/attributes/attribute/metadatas/metadata", metadata }, - { "/contextElements/contextElement/attributes/attribute/metadatas/metadata/name", metadataName }, - { "/contextElements/contextElement/attributes/attribute/metadatas/metadata/type", metadataType }, - { "/contextElements/contextElement/attributes/attribute/metadatas/metadata/value", metadataValue }, - { "/updateAction", updateAction }, - - { "LAST", NULL } -}; - - - -/* **************************************************************************** -* -* jsonUpcrInit - -*/ -void jsonUpcrInit(ParseData* reqDataP) -{ - reqDataP->upcr.eP = NULL; - reqDataP->upcr.attributeP = NULL; - reqDataP->upcr.contextMetadataP = NULL; - reqDataP->errorString = ""; -} - - - -/* **************************************************************************** -* -* jsonUpcrRelease - -*/ -void jsonUpcrRelease(ParseData* reqDataP) -{ - reqDataP->upcr.res.release(); -} - - - -/* **************************************************************************** -* -* jsonUpcrCheck - -*/ -std::string jsonUpcrCheck(ParseData* reqData, ConnectionInfo* ciP) -{ - bool asJsonObject = (ciP->uriParam[URI_PARAM_ATTRIBUTE_FORMAT] == "object" && ciP->outMimeType == JSON); - return reqData->upcr.res.check(ciP->apiVersion, asJsonObject, reqData->errorString); -} - diff --git a/src/lib/jsonParse/jsonUpdateContextRequest.h b/src/lib/jsonParse/jsonUpdateContextRequest.h deleted file mode 100644 index 212b0fe06b..0000000000 --- a/src/lib/jsonParse/jsonUpdateContextRequest.h +++ /dev/null @@ -1,66 +0,0 @@ -#ifndef SRC_LIB_JSONPARSE_JSONUPDATECONTEXTREQUEST_H_ -#define SRC_LIB_JSONPARSE_JSONUPDATECONTEXTREQUEST_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "rest/ConnectionInfo.h" -#include "jsonParse/JsonNode.h" - - - -/* **************************************************************************** -* -* jsonUpcrParseVector - -*/ -extern JsonNode jsonUpcrParseVector[]; - - - -/* **************************************************************************** -* -* jsonUpcrInit - -*/ -extern void jsonUpcrInit(ParseData* reqDataP); - - - -/* **************************************************************************** -* -* jsonUpcrRelease - -*/ -extern void jsonUpcrRelease(ParseData* reqDataP); - - - -/* **************************************************************************** -* -* jsonUpcrCheck - -*/ -extern std::string jsonUpcrCheck(ParseData* reqDataP, ConnectionInfo* ciP); - -#endif // SRC_LIB_JSONPARSE_JSONUPDATECONTEXTREQUEST_H_ diff --git a/src/lib/jsonParse/jsonUpdateContextResponse.cpp b/src/lib/jsonParse/jsonUpdateContextResponse.cpp deleted file mode 100644 index ae2db5be89..0000000000 --- a/src/lib/jsonParse/jsonUpdateContextResponse.cpp +++ /dev/null @@ -1,375 +0,0 @@ -/* -* -* Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/globals.h" -#include "orionTypes/areas.h" -#include "ngsi/ContextAttribute.h" -#include "ngsi/EntityId.h" -#include "ngsi10/UpdateContextRequest.h" - -#include "jsonParse/JsonNode.h" -#include "jsonParse/jsonParse.h" -#include "jsonParse/jsonUpdateContextResponse.h" -#include "parse/nullTreat.h" - -#include "rest/ConnectionInfo.h" -#include "rest/uriParamNames.h" - -using namespace orion; - - - -/* **************************************************************************** -* -* contextResponse - -*/ -static std::string contextResponse(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - parseDataP->upcrs.cerP = new ContextElementResponse(); - parseDataP->upcrs.res.contextElementResponseVector.push_back(parseDataP->upcrs.cerP); - return "OK"; -} - - -/* **************************************************************************** -* -* entityIdId - -*/ -static std::string entityIdId(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - parseDataP->upcrs.cerP->entity.id = value; - LM_T(LmtParse, ("Set 'id' to '%s' for an entity", parseDataP->upcrs.cerP->entity.id.c_str())); - - return "OK"; -} - - - -/* **************************************************************************** -* -* entityIdType - -*/ -static std::string entityIdType(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - parseDataP->upcrs.cerP->entity.type = value; - LM_T(LmtParse, ("Set 'type' to '%s' for an entity", parseDataP->upcrs.cerP->entity.type.c_str())); - - return "OK"; -} - - - -/* **************************************************************************** -* -* entityIdIsPattern - -*/ -static std::string entityIdIsPattern(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got an entityId:isPattern: '%s'", value.c_str())); - parseDataP->upcrs.cerP->entity.isPattern = value; - - if (!isTrue(value) && !isFalse(value)) - { - return "invalid isPattern value for entity: /" + value + "/"; - } - - return "OK"; -} - - - -/* **************************************************************************** -* -* attribute - -*/ -static std::string attribute(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Creating an attribute")); - parseDataP->upcrs.attributeP = new ContextAttribute(); - parseDataP->upcrs.cerP->entity.attributeVector.push_back(parseDataP->upcrs.attributeP); - return "OK"; -} - - - -/* **************************************************************************** -* -* attributeName - -*/ -static std::string attributeName(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got an attribute name: '%s'", value.c_str())); - parseDataP->upcrs.attributeP->name = safeValue(value); - return "OK"; -} - - - -/* **************************************************************************** -* -* attributeType - -*/ -static std::string attributeType(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got an attribute type: '%s'", value.c_str())); - parseDataP->upcrs.attributeP->type = value; - return "OK"; -} - - - -/* **************************************************************************** -* -* attributeValue - -*/ -static std::string attributeValue(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got an attribute value: '%s'", value.c_str())); - parseDataP->lastContextAttribute = parseDataP->upcrs.attributeP; - parseDataP->upcrs.attributeP->stringValue = value; - parseDataP->upcrs.attributeP->valueType = orion::ValueTypeString; - return "OK"; -} - - - -/* **************************************************************************** -* -* attributeMetadata - -*/ -static std::string attributeMetadata(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Creating an attributeMetadata")); - parseDataP->upcrs.metadataP = new Metadata(); - parseDataP->upcrs.attributeP->metadataVector.push_back(parseDataP->upcrs.metadataP); - return "OK"; -} - - - -/* **************************************************************************** -* -* attributeMetadataName - -*/ -static std::string attributeMetadataName(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got an attributeMetadata name: '%s'", value.c_str())); - parseDataP->upcrs.metadataP->name = safeValue(value); - return "OK"; -} - - - -/* **************************************************************************** -* -* attributeMetadataType - -*/ -static std::string attributeMetadataType(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got an attributeMetadata type: '%s'", value.c_str())); - parseDataP->upcrs.metadataP->type = value; - return "OK"; -} - - - -/* **************************************************************************** -* -* attributeMetadataValue - -*/ -static std::string attributeMetadataValue(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got an attributeMetadata value: '%s'", value.c_str())); - parseDataP->upcrs.metadataP->stringValue = value; - parseDataP->upcrs.metadataP->valueType = orion::ValueTypeString; - return "OK"; -} - - - -/* **************************************************************************** -* -* statusCodeCode - -*/ -static std::string statusCodeCode(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a statusCode code: '%s'", value.c_str())); - parseDataP->upcrs.cerP->statusCode.code = (HttpStatusCode) atoi(value.c_str()); - LM_T(LmtParse, ("Got a statusCode code: %d", (int) parseDataP->upcrs.cerP->statusCode.code)); - return "OK"; -} - - - -/* **************************************************************************** -* -* statusCodeReasonPhrase - -*/ -static std::string statusCodeReasonPhrase(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a statusCode reasonPhrase: '%s'", value.c_str())); - parseDataP->upcrs.cerP->statusCode.reasonPhrase = value; // OK - parsing step reading reasonPhrase - return "OK"; -} - - - -/* **************************************************************************** -* -* statusCodeDetails - -*/ -static std::string statusCodeDetails(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a statusCode details: '%s'", value.c_str())); - parseDataP->upcrs.cerP->statusCode.details = value; - return "OK"; -} - - - -/* **************************************************************************** -* -* errorCodeCode - -*/ -static std::string errorCodeCode(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a errorCode code: '%s'", value.c_str())); - parseDataP->upcrs.res.errorCode.code = (HttpStatusCode) atoi(value.c_str()); - LM_T(LmtParse, ("Got a errorCode code: %d", (int) parseDataP->upcrs.res.errorCode.code)); - return "OK"; -} - - - -/* **************************************************************************** -* -* errorCodeReasonPhrase - -*/ -static std::string errorCodeReasonPhrase(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a errorCode reasonPhrase: '%s'", value.c_str())); - parseDataP->upcrs.res.errorCode.reasonPhrase = value; // OK - parsing step reading reasonPhrase - return "OK"; -} - - - -/* **************************************************************************** -* -* errorCodeDetails - -*/ -static std::string errorCodeDetails(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a errorCode details: '%s'", value.c_str())); - parseDataP->upcrs.res.errorCode.details = value; - return "OK"; -} - - - -#define CELEM "/contextResponses/contextResponse/contextElement" -/* **************************************************************************** -* -* upcrsParseVector - -*/ -JsonNode jsonUpcrsParseVector[] = -{ - { "/contextResponses", jsonNullTreat }, - { "/contextResponses/contextResponse", contextResponse }, - - { CELEM, jsonNullTreat }, - { CELEM "/id", entityIdId }, - { CELEM "/type", entityIdType }, - { CELEM "/isPattern", entityIdIsPattern }, - - { CELEM "/attributes", jsonNullTreat }, - { CELEM "/attributes/attribute", attribute }, - { CELEM "/attributes/attribute/name", attributeName }, - { CELEM "/attributes/attribute/type", attributeType }, - { CELEM "/attributes/attribute/value", attributeValue }, - - { CELEM "/attributes/attribute/metadatas", jsonNullTreat }, - { CELEM "/attributes/attribute/metadatas/metadata", attributeMetadata }, - { CELEM "/attributes/attribute/metadatas/metadata/name", attributeMetadataName }, - { CELEM "/attributes/attribute/metadatas/metadata/type", attributeMetadataType }, - { CELEM "/attributes/attribute/metadatas/metadata/value", attributeMetadataValue }, - - { "/contextResponses/contextResponse/statusCode", jsonNullTreat }, - { "/contextResponses/contextResponse/statusCode/code", statusCodeCode }, - { "/contextResponses/contextResponse/statusCode/reasonPhrase", statusCodeReasonPhrase }, - { "/contextResponses/contextResponse/statusCode/details", statusCodeDetails }, - - { "/errorCode", jsonNullTreat }, - { "/errorCode/code", errorCodeCode }, - { "/errorCode/reasonPhrase", errorCodeReasonPhrase }, - { "/errorCode/details", errorCodeDetails }, - - { "LAST", NULL } -}; - - - -/* **************************************************************************** -* -* jsonUpcrsInit - -*/ -void jsonUpcrsInit(ParseData* reqDataP) -{ - jsonUpcrsRelease(reqDataP); - - reqDataP->upcrs.cerP = NULL; - reqDataP->upcrs.attributeP = NULL; - reqDataP->upcrs.metadataP = NULL; - - reqDataP->errorString = ""; -} - - - -/* **************************************************************************** -* -* jsonUpcrsRelease - -*/ -void jsonUpcrsRelease(ParseData* reqDataP) -{ - reqDataP->upcrs.res.release(); -} - - - -/* **************************************************************************** -* -* jsonUpcrsCheck - -*/ -std::string jsonUpcrsCheck(ParseData* reqDataP, ConnectionInfo* ciP) -{ - bool asJsonObject = (ciP->uriParam[URI_PARAM_ATTRIBUTE_FORMAT] == "object" && ciP->outMimeType == JSON); - return reqDataP->upcrs.res.check(ciP->apiVersion, asJsonObject, reqDataP->errorString); -} diff --git a/src/lib/jsonParse/jsonUpdateContextResponse.h b/src/lib/jsonParse/jsonUpdateContextResponse.h deleted file mode 100644 index ff52cc1a0c..0000000000 --- a/src/lib/jsonParse/jsonUpdateContextResponse.h +++ /dev/null @@ -1,65 +0,0 @@ -#ifndef SRC_LIB_JSONPARSE_JSONUPDATECONTEXTRESPONSE_H_ -#define SRC_LIB_JSONPARSE_JSONUPDATECONTEXTRESPONSE_H_ - -/* -* -* Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include - -#include "jsonParse/JsonNode.h" -#include "rest/ConnectionInfo.h" - - - -/* **************************************************************************** -* -* upcrsParseVector - -*/ -extern JsonNode jsonUpcrsParseVector[]; - - - -/* **************************************************************************** -* -* jsonUpcrsInit - -*/ -extern void jsonUpcrsInit(ParseData* reqDataP); - - - -/* **************************************************************************** -* -* jsonUpcrsRelease - -*/ -extern void jsonUpcrsRelease(ParseData* reqDataP); - - - -/* **************************************************************************** -* -* jsonUpcrsCheck - -*/ -extern std::string jsonUpcrsCheck(ParseData* reqDataP, ConnectionInfo* ciP); - -#endif // SRC_LIB_JSONPARSE_JSONUPDATECONTEXTRESPONSE_H_ diff --git a/src/lib/jsonParse/jsonUpdateContextSubscriptionRequest.cpp b/src/lib/jsonParse/jsonUpdateContextSubscriptionRequest.cpp deleted file mode 100644 index 2e0bed45a7..0000000000 --- a/src/lib/jsonParse/jsonUpdateContextSubscriptionRequest.cpp +++ /dev/null @@ -1,475 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/globals.h" -#include "alarmMgr/alarmMgr.h" -#include "orionTypes/areas.h" -#include "ngsi10/UpdateContextSubscriptionRequest.h" -#include "parse/nullTreat.h" -#include "jsonParse/JsonNode.h" -#include "jsonParse/jsonUpdateContextSubscriptionRequest.h" - -using namespace orion; - - - -/* **************************************************************************** -* -* duration - -*/ -static std::string duration(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - std::string s; - - LM_T(LmtParse, ("Got a duration: '%s'", value.c_str())); - - parseDataP->ucsr.res.duration.set(value); - - // The failure is postponed until the 'check' step to not miss the subscriptionId - if ((s = parseDataP->ucsr.res.duration.check()) != "OK") - { - std::string extra = std::string("'") + parseDataP->ucsr.res.duration.get() + "': " + s; - alarmMgr.badInput(clientIp, "error parsing duration", extra); - } - - return "OK"; -} - - - -/* **************************************************************************** -* -* restriction - -*/ -static std::string restriction(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a restriction")); - - ++parseDataP->ucsr.res.restrictions; - - return "OK"; -} - - - -/* **************************************************************************** -* -* attributeExpression - -*/ -static std::string attributeExpression(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got an attributeExpression: '%s'", value.c_str())); - - parseDataP->ucsr.res.restriction.attributeExpression.set(value); - - return "OK"; -} - - - -/* **************************************************************************** -* -* scope - -*/ -static std::string scope(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a scope")); - - parseDataP->ucsr.scopeP = new Scope(); - parseDataP->ucsr.res.restriction.scopeVector.push_back(parseDataP->ucsr.scopeP); - - return "OK"; -} - - - -/* **************************************************************************** -* -* scopeType - -*/ -static std::string scopeType(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a scope type: '%s'", value.c_str())); - - parseDataP->ucsr.scopeP->type = value; - - return "OK"; -} - - - -/* **************************************************************************** -* -* scopeValue - -*/ -static std::string scopeValue(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - if (parseDataP->ucsr.scopeP->type == FIWARE_LOCATION || parseDataP->ucsr.scopeP->type == FIWARE_LOCATION_DEPRECATED) - { - // - // If the scope type is FIWARE_LOCATION (or its deprecated variant), then the value of this scope is stored in 'circle' or 'polygon'. - // The field 'value' is not used as more complexity is needed. - // scopeP->value is here set to FIWARE_LOCATION, in an attempt to warn a future use of 'scopeP->value' when - // instead 'circle' or 'polygon' should be used. - // - parseDataP->ucsr.scopeP->value = FIWARE_LOCATION; - LM_T(LmtParse, ("Preparing scopeValue for '%s'", parseDataP->ucsr.scopeP->type.c_str())); - } - else - { - parseDataP->ucsr.scopeP->value = value; - LM_T(LmtParse, ("Got a scopeValue: '%s' for scopeType '%s'", value.c_str(), parseDataP->ucsr.scopeP->type.c_str())); - } - - return "OK"; -} - - - -/* **************************************************************************** -* -* circle - -*/ -static std::string circle(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a circle")); - parseDataP->ucsr.scopeP->areaType = orion::CircleType; - return "OK"; -} - - - -/* **************************************************************************** -* -* circleCenterLatitude - -*/ -static std::string circleCenterLatitude(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a circleCenterLatitude: %s", value.c_str())); - parseDataP->ucsr.scopeP->circle.center.latitudeSet(value); - - return "OK"; -} - - - -/* **************************************************************************** -* -* circleCenterLongitude - -*/ -static std::string circleCenterLongitude(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a circleCenterLongitude: %s", value.c_str())); - parseDataP->ucsr.scopeP->circle.center.longitudeSet(value); - return "OK"; -} - - - -/* **************************************************************************** -* -* circleRadius - -*/ -static std::string circleRadius(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a circleRadius: %s", value.c_str())); - parseDataP->ucsr.scopeP->circle.radiusSet(value); - return "OK"; -} - - - -/* **************************************************************************** -* -* circleInverted - -*/ -static std::string circleInverted(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a circleInverted: %s", value.c_str())); - - parseDataP->ucsr.scopeP->circle.invertedSet(value); - if (!isTrue(value) && !isFalse(value)) - { - parseDataP->errorString = "bad string for circle/inverted: /" + value + "/"; - return parseDataP->errorString; - } - - return "OK"; -} - - - -/* **************************************************************************** -* -* polygon - -*/ -static std::string polygon(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a polygon")); - parseDataP->ucsr.scopeP->areaType = orion::PolygonType; - return "OK"; -} - - - -/* **************************************************************************** -* -* polygonInverted - -*/ -static std::string polygonInverted(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a polygonInverted: %s", value.c_str())); - - parseDataP->ucsr.scopeP->polygon.invertedSet(value); - if (!isTrue(value) && !isFalse(value)) - { - parseDataP->errorString = "bad string for polygon/inverted: /" + value + "/"; - return parseDataP->errorString; - } - - return "OK"; -} - - - -/* **************************************************************************** -* -* polygonVertexList - -*/ -static std::string polygonVertexList(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a polygonVertexList")); - return "OK"; -} - - - -/* **************************************************************************** -* -* polygonVertex - -*/ -static std::string polygonVertex(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a polygonVertex - creating new vertex for the vertex list")); - parseDataP->ucsr.vertexP = new orion::Point(); - parseDataP->ucsr.scopeP->polygon.vertexAdd(parseDataP->ucsr.vertexP); - // parseDataP->ucsr.scopeP->polygon.vertexList.push_back(parseDataP->ucsr.vertexP); - return "OK"; -} - - - -/* **************************************************************************** -* -* polygonVertexLatitude - -*/ -static std::string polygonVertexLatitude(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a polygonVertexLatitude: %s", value.c_str())); - parseDataP->ucsr.vertexP->latitudeSet(value); - return "OK"; -} - - - -/* **************************************************************************** -* -* polygonVertexLongitude - -*/ -static std::string polygonVertexLongitude(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a polygonVertexLongitude: %s", value.c_str())); - parseDataP->ucsr.vertexP->longitudeSet(value); - return "OK"; -} - - - -/* **************************************************************************** -* -* subscriptionId - -*/ -static std::string subscriptionId(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a subscriptionId: '%s'", value.c_str())); - - parseDataP->ucsr.res.subscriptionId.set(value); - - return "OK"; -} - - - -/* **************************************************************************** -* -* notifyCondition - -*/ -static std::string notifyCondition(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a notifyCondition")); - parseDataP->ucsr.notifyConditionP = new NotifyCondition(); - parseDataP->ucsr.res.notifyConditionVector.push_back(parseDataP->ucsr.notifyConditionP); - return "OK"; -} - - - -/* **************************************************************************** -* -* notifyConditionRestriction - -*/ -static std::string notifyConditionRestriction(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a Notify Condition restriction")); - - parseDataP->ucsr.notifyConditionP->restriction.set(value); - return "OK"; -} - - - -/* **************************************************************************** -* -* notifyConditionType - -*/ -static std::string notifyConditionType(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a Notify Condition Type: '%s'", value.c_str())); - parseDataP->ucsr.notifyConditionP->type = value; - return "OK"; -} - - - -/* **************************************************************************** -* -* condValue - -*/ -static std::string notifyConditionCondValue(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a Cond Value: '%s'", value.c_str())); - parseDataP->ucsr.notifyConditionP->condValueList.push_back(value); - return "OK"; -} - - - -/* **************************************************************************** -* -* throttling - -*/ -static std::string throttling(const std::string& path, const std::string& value, ParseData* parseDataP) -{ - LM_T(LmtParse, ("Got a throttling: '%s'", value.c_str())); - parseDataP->ucsr.res.throttling.set(value); - return "OK"; -} - - - -/* **************************************************************************** -* -* jsonUcsrParseVector - -*/ -JsonNode jsonUcsrParseVector[] = -{ - { "/duration", duration }, - { "/restriction", restriction }, - { "/restriction/attributeExpression", attributeExpression }, - { "/restriction/scopes", jsonNullTreat }, - { "/restriction/scopes/scope", scope, }, - { "/restriction/scopes/scope/type", scopeType }, - { "/restriction/scopes/scope/value", scopeValue }, - - { "/restriction/scopes/scope/value/circle", circle }, - { "/restriction/scopes/scope/value/circle/centerLatitude", circleCenterLatitude }, - { "/restriction/scopes/scope/value/circle/centerLongitude", circleCenterLongitude }, - { "/restriction/scopes/scope/value/circle/radius", circleRadius }, - { "/restriction/scopes/scope/value/circle/inverted", circleInverted }, - - { "/restriction/scopes/scope/value/polygon", polygon }, - { "/restriction/scopes/scope/value/polygon/inverted", polygonInverted }, - { "/restriction/scopes/scope/value/polygon/vertices", polygonVertexList }, - { "/restriction/scopes/scope/value/polygon/vertices/vertice", polygonVertex }, - { "/restriction/scopes/scope/value/polygon/vertices/vertice/latitude", polygonVertexLatitude }, - { "/restriction/scopes/scope/value/polygon/vertices/vertice/longitude", polygonVertexLongitude }, - { "/restriction/scopes/scope/value/polygon/inverted", polygonInverted }, - - { "/subscriptionId", subscriptionId }, - { "/notifyConditions", jsonNullTreat }, - { "/notifyConditions/notifyCondition", notifyCondition }, - { "/notifyConditions/notifyCondition/type", notifyConditionType }, - { "/notifyConditions/notifyCondition/condValues", jsonNullTreat }, - { "/notifyConditions/notifyCondition/condValues/condValue", notifyConditionCondValue }, - { "/notifyConditions/notifyCondition/restriction", notifyConditionRestriction }, - { "/throttling", throttling }, - - { "LAST", NULL } -}; - - - -/* **************************************************************************** -* -* jsonUcsrInit - -*/ -void jsonUcsrInit(ParseData* parseDataP) -{ - jsonUcsrRelease(parseDataP); - - parseDataP->ucsr.notifyConditionP = NULL; - parseDataP->ucsr.scopeP = NULL; - parseDataP->ucsr.res.restrictions = 0; - parseDataP->errorString = ""; -} - - - -/* **************************************************************************** -* -* jsonUcsrRelease - -*/ -void jsonUcsrRelease(ParseData* parseDataP) -{ - parseDataP->ucsr.res.release(); -} - - - -/* **************************************************************************** -* -* jsonUcsrCheck - -*/ -std::string jsonUcsrCheck(ParseData* parseDataP, ConnectionInfo* ciP) -{ - std::string s; - s = parseDataP->ucsr.res.check(parseDataP->errorString, 0); - return s; -} diff --git a/src/lib/jsonParse/jsonUpdateContextSubscriptionRequest.h b/src/lib/jsonParse/jsonUpdateContextSubscriptionRequest.h deleted file mode 100644 index 7d281ab9a9..0000000000 --- a/src/lib/jsonParse/jsonUpdateContextSubscriptionRequest.h +++ /dev/null @@ -1,66 +0,0 @@ -#ifndef SRC_LIB_JSONPARSE_JSONUPDATECONTEXTSUBSCRIPTIONREQUEST_H_ -#define SRC_LIB_JSONPARSE_JSONUPDATECONTEXTSUBSCRIPTIONREQUEST_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "rest/ConnectionInfo.h" -#include "jsonParse/JsonNode.h" - - - -/* **************************************************************************** -* -* jsonUcsrParseVector - -*/ -extern JsonNode jsonUcsrParseVector[]; - - - -/* **************************************************************************** -* -* jsonUcsrInit - -*/ -extern void jsonUcsrInit(ParseData* reqDataP); - - - -/* **************************************************************************** -* -* jsonUcsrRelease - -*/ -extern void jsonUcsrRelease(ParseData* reqDataP); - - - -/* **************************************************************************** -* -* jsonUcsrCheck - -*/ -extern std::string jsonUcsrCheck(ParseData* reqDataP, ConnectionInfo* ciP); - -#endif // SRC_LIB_JSONPARSE_JSONUPDATECONTEXTSUBSCRIPTIONREQUEST_H_ diff --git a/src/lib/jsonParseV2/CMakeLists.txt b/src/lib/jsonParseV2/CMakeLists.txt index 04842e9361..fd952d8c4c 100644 --- a/src/lib/jsonParseV2/CMakeLists.txt +++ b/src/lib/jsonParseV2/CMakeLists.txt @@ -35,7 +35,6 @@ SET (SOURCES parseEntitiesVector.cpp parseEntityObject.cpp parseStringList.cpp - parseScope.cpp parseBatchUpdate.cpp utilsParse.cpp parseRegistration.cpp @@ -44,6 +43,7 @@ SET (SOURCES parseNotification.cpp parseExpression.cpp parseEntitiesResponse.cpp + parseEntitiesResponseV1.cpp ) SET (HEADERS @@ -60,7 +60,6 @@ SET (HEADERS parseEntityVector.h parseEntitiesVector.h parseEntityObject.h - parseScope.h parseStringList.h parseBatchUpdate.h utilsParse.h @@ -70,6 +69,7 @@ SET (HEADERS parseNotification.h parseExpression.h parseEntitiesResponse.h + parseEntitiesResponseV1.h ) diff --git a/src/lib/jsonParseV2/jsonRequestTreat.cpp b/src/lib/jsonParseV2/jsonRequestTreat.cpp index def0d2b519..c18a1abde3 100644 --- a/src/lib/jsonParseV2/jsonRequestTreat.cpp +++ b/src/lib/jsonParseV2/jsonRequestTreat.cpp @@ -77,10 +77,10 @@ std::string jsonRequestTreat return answer; } - if ((answer = parseDataP->ent.res.check(ciP->apiVersion, EntitiesRequest)) != "OK") + if ((answer = parseDataP->ent.res.check(EntitiesRequest)) != "OK") { OrionError oe(SccBadRequest, answer); - return oe.setStatusCodeAndSmartRender(ciP->apiVersion, &(ciP->httpStatusCode)); + return oe.setSCAndRender(&(ciP->httpStatusCode)); } break; @@ -92,10 +92,10 @@ std::string jsonRequestTreat return answer; } - if ((answer = parseDataP->ent.res.check(ciP->apiVersion, EntityRequest)) != "OK") + if ((answer = parseDataP->ent.res.check(EntityRequest)) != "OK") { OrionError oe(SccBadRequest, answer); - return oe.setStatusCodeAndSmartRender(ciP->apiVersion, &(ciP->httpStatusCode)); + return oe.setSCAndRender(&(ciP->httpStatusCode)); } break; @@ -108,10 +108,10 @@ std::string jsonRequestTreat return answer; } - if ((answer = parseDataP->attr.attribute.check(ciP->apiVersion, EntityAttributeRequest)) != "OK") + if ((answer = parseDataP->attr.attribute.check(false)) != "OK") { OrionError oe(SccBadRequest, answer); - return oe.setStatusCodeAndSmartRender(ciP->apiVersion, &(ciP->httpStatusCode)); + return oe.setSCAndRender(&(ciP->httpStatusCode)); } break; @@ -125,7 +125,7 @@ std::string jsonRequestTreat break; case SubscriptionsRequest: - answer = parseSubscription(ciP, &parseDataP->subsV2); + answer = parseSubscription(ciP, &parseDataP->sub); if (answer != "OK") { return answer; @@ -133,7 +133,7 @@ std::string jsonRequestTreat break; case SubscriptionRequest: - answer = parseSubscription(ciP, &parseDataP->subsV2, true); // NOTE: partial == true + answer = parseSubscription(ciP, &parseDataP->sub, true); // NOTE: partial == true if (answer != "OK") { return answer; @@ -174,7 +174,7 @@ std::string jsonRequestTreat default: OrionError error(SccNotImplemented, "Request Treat function not implemented"); - answer = error.toJsonV1(); + answer = error.toJson(); ciP->httpStatusCode = SccNotImplemented; break; } diff --git a/src/lib/jsonParseV2/jsonRequestTreat.h b/src/lib/jsonParseV2/jsonRequestTreat.h index cad8b0db79..e56186f587 100644 --- a/src/lib/jsonParseV2/jsonRequestTreat.h +++ b/src/lib/jsonParseV2/jsonRequestTreat.h @@ -31,8 +31,6 @@ #include "rest/ConnectionInfo.h" #include "ngsi/ParseData.h" #include "ngsi/Request.h" -#include "ngsi10/SubscribeContextRequest.h" -#include "ngsi10/UpdateContextSubscriptionRequest.h" #include "apiTypesV2/Subscription.h" @@ -45,16 +43,12 @@ typedef struct JsonDelayedRelease { Entity* entity; ContextAttribute* attribute; - SubscribeContextRequest* scrP; - UpdateContextSubscriptionRequest* ucsrP; ngsiv2::Subscription* subsP; JsonDelayedRelease() { entity = NULL; attribute = NULL; - scrP = NULL; - ucsrP = NULL; subsP = NULL; } } JsonDelayedRelease; diff --git a/src/lib/jsonParseV2/parseContextAttribute.cpp b/src/lib/jsonParseV2/parseContextAttribute.cpp index 4d4ab692a5..5ca8cda59a 100644 --- a/src/lib/jsonParseV2/parseContextAttribute.cpp +++ b/src/lib/jsonParseV2/parseContextAttribute.cpp @@ -380,28 +380,18 @@ std::string parseContextAttribute return details; } - // Attribute has a regular structure, in which 'value' is mandatory (except in v2) - if (iter->value.HasMember("value") || ciP->apiVersion == V2) + std::string r = parseContextAttributeObject(iter->value, caP, &compoundVector, checkAttrSpecialTypes); + if (r == "max deep reached") { - std::string r = parseContextAttributeObject(iter->value, caP, &compoundVector, checkAttrSpecialTypes); - if (r == "max deep reached") - { - alarmMgr.badInput(clientIp, "max deep reached", "found in ContextAttributeObject::Object"); - ciP->httpStatusCode = SccBadRequest; - return "max deep reached"; - } - else if (r != "OK") // other error cases get a general treatment - { - alarmMgr.badInput(clientIp, "JSON Parse Error in ContextAttribute::Object", r); - ciP->httpStatusCode = SccBadRequest; - return r; - } + alarmMgr.badInput(clientIp, "max deep reached", "found in ContextAttributeObject::Object"); + ciP->httpStatusCode = SccBadRequest; + return "max deep reached"; } - else + else if (r != "OK") // other error cases get a general treatment { - alarmMgr.badInput(clientIp, "JSON Parse Error", "no 'value' for ContextAttribute without keyValues"); + alarmMgr.badInput(clientIp, "JSON Parse Error in ContextAttribute::Object", r); ciP->httpStatusCode = SccBadRequest; - return "no 'value' for ContextAttribute without keyValues"; + return r; } } @@ -410,7 +400,7 @@ std::string parseContextAttribute caP->type = (compoundVector)? defaultType(orion::ValueTypeVector) : defaultType(caP->valueType); } - std::string r = caP->check(ciP->apiVersion, ciP->requestType, relaxForbiddenCheck); + std::string r = caP->check(ciP->requestType == EntityAttributeValueRequest, relaxForbiddenCheck); if (r != "OK") { alarmMgr.badInput(clientIp, "JSON Parse Error", r); diff --git a/src/lib/jsonParseV2/parseEntitiesResponse.cpp b/src/lib/jsonParseV2/parseEntitiesResponse.cpp index 14878152d4..3c714efd3c 100644 --- a/src/lib/jsonParseV2/parseEntitiesResponse.cpp +++ b/src/lib/jsonParseV2/parseEntitiesResponse.cpp @@ -33,7 +33,6 @@ #include "common/errorMessages.h" #include "alarmMgr/AlarmManager.h" #include "alarmMgr/alarmMgr.h" -#include "apiTypesV2/Entities.h" #include "rest/ConnectionInfo.h" #include "rest/OrionError.h" #include "jsonParseV2/parseEntityObject.h" @@ -55,7 +54,7 @@ * of forwarded request so maybe it can be simplified) * */ -bool parseEntitiesResponse(ConnectionInfo* ciP, const char* payload, Entities* evP, OrionError* oeP) +bool parseEntitiesResponse(ConnectionInfo* ciP, const char* payload, EntityVector* evP, OrionError* oeP) { rapidjson::Document document; diff --git a/src/lib/jsonParseV2/parseEntitiesResponse.h b/src/lib/jsonParseV2/parseEntitiesResponse.h index d36e124753..6714128437 100644 --- a/src/lib/jsonParseV2/parseEntitiesResponse.h +++ b/src/lib/jsonParseV2/parseEntitiesResponse.h @@ -31,7 +31,6 @@ #include "rapidjson/document.h" #include "rest/ConnectionInfo.h" -#include "apiTypesV2/Entities.h" @@ -43,7 +42,7 @@ extern bool parseEntitiesResponse ( ConnectionInfo* ciP, const char* payload, - Entities* evP, + EntityVector* evP, OrionError* oeP ); diff --git a/src/lib/jsonParseV2/parseEntitiesResponseV1.cpp b/src/lib/jsonParseV2/parseEntitiesResponseV1.cpp new file mode 100644 index 0000000000..0e0157df43 --- /dev/null +++ b/src/lib/jsonParseV2/parseEntitiesResponseV1.cpp @@ -0,0 +1,534 @@ +/* +* +* Copyright 2024 Telefonica Investigacion y Desarrollo, S.A.U +* +* This file is part of Orion Context Broker. +* +* Orion Context Broker is free software: you can redistribute it and/or +* modify it under the terms of the GNU Affero General Public License as +* published by the Free Software Foundation, either version 3 of the +* License, or (at your option) any later version. +* +* Orion Context Broker is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero +* General Public License for more details. +* +* You should have received a copy of the GNU Affero General Public License +* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. +* +* For those usages not covered by this license please contact with +* iot_support at tid dot es +* +* Author: Ken Zangelin +*/ +#include +#include + +#include "rapidjson/document.h" + +#include "logMsg/logMsg.h" +#include "logMsg/traceLevels.h" + +#include "common/errorMessages.h" +#include "alarmMgr/AlarmManager.h" +#include "alarmMgr/alarmMgr.h" +#include "rest/ConnectionInfo.h" +#include "rest/OrionError.h" +#include "jsonParseV2/jsonParseTypeNames.h" +#include "jsonParseV2/parseEntitiesResponseV1.h" +#include "jsonParseV2/utilsParse.h" +#include "jsonParseV2/parseCompoundCommon.h" + + + +/* **************************************************************************** +* +* prepareContextAttributeCompoundRoot - +* +* Copied from parseContextAttribute.cpp. Given this file is about deprecated functionality and eventually +* will be removed, no need of moving this to a common lib. +*/ +static void prepareContextAttributeCompoundRoot(ContextAttribute* caP, const std::string& type) +{ + caP->compoundValueP = new orion::CompoundValueNode(); + caP->compoundValueP->name = ""; + caP->compoundValueP->valueType = stringToCompoundType(type); + + if (!caP->typeGiven) + { + caP->type = (type == "Object")? defaultType(orion::ValueTypeObject) : defaultType(orion::ValueTypeVector); + } +} + + + +/* **************************************************************************** +* +* parseMetadata - +* +*/ +static std::string parseMetadata(ConnectionInfo* ciP, rapidjson::Value::ConstValueIterator& valueP, Metadata* mP) +{ + for (rapidjson::Value::ConstMemberIterator iter = valueP->MemberBegin(); iter != valueP->MemberEnd(); ++iter) + { + std::string name = iter->name.GetString(); + std::string type = jsonParseTypeNames[iter->value.GetType()]; + + // keys different from name, type and value are ignored + if (name == "name") + { + if (type != "String") + { + return "metadata name must be a string"; + } + mP->name = iter->value.GetString(); + } + if (name == "type") + { + if (type != "String") + { + return "metadata type must be a string"; + } + mP->type = iter->value.GetString(); + } + if (name == "value") + { + if (type == "String") + { + mP->stringValue = iter->value.GetString(); + mP->valueType = orion::ValueTypeString; + } + else if (type == "Number") + { + mP->numberValue = iter->value.GetDouble(); + mP->valueType = orion::ValueTypeNumber; + } + else if (type == "True") + { + mP->boolValue = true; + mP->valueType = orion::ValueTypeBoolean; + } + else if (type == "False") + { + mP->boolValue = false; + mP->valueType = orion::ValueTypeBoolean; + } + else if (type == "Null") + { + mP->valueType = orion::ValueTypeNull; + } + else if ((type == "Array") || (type == "Object")) + { + mP->valueType = orion::ValueTypeObject; // Used both for Array and Object ... + + std::string type = jsonParseTypeNames[iter->value.GetType()]; + + mP->compoundValueP = new orion::CompoundValueNode(); + mP->compoundValueP->name = ""; + mP->compoundValueP->valueType = stringToCompoundType(type); + + std::string r = parseCompoundValue(iter, mP->compoundValueP, 0); + + if (r != "OK") + { + return r; + } + } + } + } + + if ((mP->name.empty()) || (mP->type.empty())) + { + return "metadata must have name and type"; + } + + return "OK"; +} + + + +/* **************************************************************************** +* +* parseAttribute - +* +*/ +static std::string parseAttribute(ConnectionInfo* ciP, rapidjson::Value::ConstValueIterator& valueP, ContextAttribute* caP) +{ + for (rapidjson::Value::ConstMemberIterator iter = valueP->MemberBegin(); iter != valueP->MemberEnd(); ++iter) + { + std::string name = iter->name.GetString(); + std::string type = jsonParseTypeNames[iter->value.GetType()]; + + // keys different from metadatas, name, type and value are ignored + if (name == "metadatas") + { + if (type != "Array") + { + return "metadatas must be an array"; + } + + for (rapidjson::Value::ConstValueIterator iter2 = iter->value.Begin(); iter2 != iter->value.End(); ++iter2) + { + if (!iter2->IsObject()) + { + return "metadatas item must be an object"; + } + + Metadata *mP = new Metadata(); + + std::string s = parseMetadata(ciP, iter2, mP); + if (s != "OK") + { + mP->release(); + delete mP; + return s; + } + + caP->metadataVector.push_back(mP); + } + } + if (name == "name") + { + if (type != "String") + { + return "attribute name must be a string"; + } + caP->name = iter->value.GetString(); + } + if (name == "type") + { + if (type != "String") + { + return "attribute type must be a string"; + } + caP->type = iter->value.GetString(); + } + if (name == "value") + { + if (type == "String") + { + caP->stringValue = iter->value.GetString(); + caP->valueType = orion::ValueTypeString; + } + else if (type == "Number") + { + caP->numberValue = iter->value.GetDouble(); + caP->valueType = orion::ValueTypeNumber; + } + else if (type == "True") + { + caP->boolValue = true; + caP->valueType = orion::ValueTypeBoolean; + } + else if (type == "False") + { + caP->boolValue = false; + caP->valueType = orion::ValueTypeBoolean; + } + else if (type == "Null") + { + caP->valueType = orion::ValueTypeNull; + } + else if (type == "Array") + { + // + // FIXME P4: Here the attribute's valueType is set to ValueTypeVector, but normally all compounds have the + // valueType set as Object in the attribute ... + // to later find its real type in compoundValueP->valueType. + // This seems to be needed later, so no 'fix' for now. + // However, this should be looked into, and probably the attributes with compound values + // should have the real type of its compound (Object|Vector), not always Object. + // This is really confusing ... + // I guess this was to be able to easily compare for compound by checking + // "caP->valueType == orion::ValueTypeObject", + // but it is equally easy to compare "caP->compoundValueP != NULL" instead. + // + caP->valueType = orion::ValueTypeVector; + prepareContextAttributeCompoundRoot(caP, jsonParseTypeNames[iter->value.GetType()]); + std::string r = parseCompoundValue(iter, caP->compoundValueP, 0); + if (r != "OK") + { + return r; + } + } + else if (type == "Object") + { + caP->valueType = orion::ValueTypeObject; + prepareContextAttributeCompoundRoot(caP, jsonParseTypeNames[iter->value.GetType()]); + std::string r = parseCompoundValue(iter, caP->compoundValueP, 0); + if (r != "OK") + { + return r; + } + } + } + } + + if ((caP->name.empty()) || (caP->type.empty())) + { + return "attribute must have name and type"; + } + + return "OK"; +} + + + +/* **************************************************************************** +* +* parseEntity - +* +*/ +static std::string parseEntity(ConnectionInfo* ciP, rapidjson::Value::ConstMemberIterator& valueP, Entity* eP) +{ + for (rapidjson::Value::ConstMemberIterator iter = valueP->value.MemberBegin(); iter != valueP->value.MemberEnd(); ++iter) + { + std::string name = iter->name.GetString(); + std::string type = jsonParseTypeNames[iter->value.GetType()]; + + // keys different from attributes, id and types are ignored (e.g. isPattern) + if (name == "attributes") + { + if (type != "Array") + { + return "attributes must be an array"; + } + + for (rapidjson::Value::ConstValueIterator iter2 = iter->value.Begin(); iter2 != iter->value.End(); ++iter2) + { + if (!iter2->IsObject()) + { + return "attributes item must be an object"; + } + + ContextAttribute *caP = new ContextAttribute(); + + std::string s = parseAttribute(ciP, iter2, caP); + if (s != "OK") + { + caP->release(); + delete caP; + return s; + } + + eP->attributeVector.push_back(caP); + } + } + if (name == "id") + { + if (type != "String") + { + return "entity id must be a string"; + } + eP->entityId.id = iter->value.GetString(); + } + if (name == "type") + { + if (type != "String") + { + return "entity type must be a string"; + } + eP->entityId.type = iter->value.GetString(); + } + } + + if ((eP->entityId.id.empty()) || (eP->entityId.type.empty())) + { + return "entity must have id and type"; + } + + return "OK"; +} + + + +/* **************************************************************************** +* +* parseEntitiesResponseV1 - +* +* This function is to parse responses for POST /v1/queryContext when that request is used +* in legacyForwarding: true scenarios. This function is called only from postQueryContext() logic +* and will be removed if some day the legacyForwarding: true functionality is fully removed +* +* Example of payload response (for reference) +* +* { +* "contextResponses": [ +* { +* "contextElement": { +* "attributes": [ +* { +* "name": "lightstatus", +* "type": "light", +* "value": "L23" +* }, +* { +* "name": "pressure", +* "type": "clima", +* "value": "p23" +* }, +* { +* "name": "temperature", +* "type": "degree", +* "value": "14", +* "metadatas": [ +* { +* "name": "ID", +* "type": "Text", +* "value": "ID2" +* } +* ], +* } +* ], +* "id": "ConferenceRoom", +* "isPattern": "false", +* "type": "Room" +* }, +* "statusCode": { +* "code": "200", +* "reasonPhrase": "OK" +* } +* }, +* { +* "contextElement": { +* "attributes": [ +* { +* "name": "temperature", +* "type": "degree", +* "value": "14" +* } +* ], +* "id": "ConferenceRoom2", +* "isPattern": "false", +* "type": "Room" +* }, +* "statusCode": { +* "code": "200", +* "reasonPhrase": "OK" +* } +* } +* ] +* } +* +*/ +bool parseEntitiesResponseV1(ConnectionInfo* ciP, const char* payload, EntityVector* evP, OrionError* oeP) +{ + rapidjson::Document document; + + document.Parse(payload); + + if (document.HasParseError()) + { + oeP->fill(SccBadRequest, ERROR_DESC_PARSE, ERROR_PARSE); + alarmMgr.badInput(clientIp, "JSON Parse Error", parseErrorString(document.GetParseError())); + ciP->httpStatusCode = SccBadRequest; + return false; + } + + if (!document.IsObject()) + { + oeP->fill(SccBadRequest, ERROR_DESC_PARSE, ERROR_PARSE); + alarmMgr.badInput(clientIp, "JSON Parse Error", "JSON Object not found"); + ciP->httpStatusCode = SccBadRequest; + return false; + } + + for (rapidjson::Value::ConstMemberIterator iter = document.MemberBegin(); iter != document.MemberEnd(); ++iter) + { + std::string name = iter->name.GetString(); + std::string type = jsonParseTypeNames[iter->value.GetType()]; + + if ((name != "contextResponses") || (type != "Array")) + { + oeP->fill(SccBadRequest, "contextResponses key not found or its value is not an array"); + alarmMgr.badInput(clientIp, "JSON Parse Error", "contextResponses key not found or its value is not an array"); + ciP->httpStatusCode = SccBadRequest; + return false; + } + + for (rapidjson::Value::ConstValueIterator iter2 = iter->value.Begin(); iter2 != iter->value.End(); ++iter2) + { + if (!iter2->IsObject()) + { + oeP->fill(SccBadRequest, "contextResponses item is not an object"); + alarmMgr.badInput(clientIp, "JSON Parse Error", "contextResponses item is not an object"); + ciP->httpStatusCode = SccBadRequest; + return false; + } + + for (rapidjson::Value::ConstMemberIterator iter3 = iter2->MemberBegin(); iter3 != iter2->MemberEnd(); ++iter3) + { + std::string name = iter3->name.GetString(); + std::string type = jsonParseTypeNames[iter3->value.GetType()]; + + // keys different from contextElement and statusCode are ignored + if (name == "contextElement") + { + if (type != "Object") + { + oeP->fill(SccBadRequest, "contextElement value is not an object"); + alarmMgr.badInput(clientIp, "JSON Parse Error", "contextResponses item is not an object"); + ciP->httpStatusCode = SccBadRequest; + return false; + } + + Entity* eP = new Entity(); + std::string s = parseEntity(ciP, iter3, eP); + + if (s != "OK") + { + eP->release(); + delete eP; + oeP->fill(SccBadRequest, s); + alarmMgr.badInput(clientIp, "JSON Parse Error", s); + ciP->httpStatusCode = SccBadRequest; + return false; + } + + evP->vec.push_back(eP); + } + + if (name == "statusCode") + { + if (type != "Object") + { + oeP->fill(SccBadRequest, "statusCode value is not an object"); + alarmMgr.badInput(clientIp, "JSON Parse Error", "statusCode value is not an object"); + ciP->httpStatusCode = SccBadRequest; + return false; + } + + for (rapidjson::Value::ConstMemberIterator iter4 = iter3->value.MemberBegin(); iter4 != iter3->value.MemberEnd(); ++iter4) + { + std::string name = iter4->name.GetString(); + std::string type = jsonParseTypeNames[iter4->value.GetType()]; + + // keys different from code is ignored + if (name == "code") + { + if (type != "String") + { + oeP->fill(SccBadRequest, "code value is not an string"); + alarmMgr.badInput(clientIp, "JSON Parse Error", "code value is not an string"); + ciP->httpStatusCode = SccBadRequest; + return false; + } + + std::string code = iter4->value.GetString(); + if (code != "200") + { + oeP->fill(SccBadRequest, "non-200 code: " + code); + alarmMgr.badInput(clientIp, "JSON Parse Error", "non-200 code: " + code); + ciP->httpStatusCode = SccBadRequest; + return false; + } + } + } + } + } + } + } + + return true; +} diff --git a/src/lib/serviceRoutines/badNgsi9Request.h b/src/lib/jsonParseV2/parseEntitiesResponseV1.h similarity index 66% rename from src/lib/serviceRoutines/badNgsi9Request.h rename to src/lib/jsonParseV2/parseEntitiesResponseV1.h index 390b526af0..5eca35ba68 100644 --- a/src/lib/serviceRoutines/badNgsi9Request.h +++ b/src/lib/jsonParseV2/parseEntitiesResponseV1.h @@ -1,9 +1,9 @@ -#ifndef SRC_LIB_SERVICEROUTINES_BADNGSI9REQUEST_H_ -#define SRC_LIB_SERVICEROUTINES_BADNGSI9REQUEST_H_ +#ifndef SRC_LIB_JSONPARSEV2_PARSEENTITIESRESPONSEV1_H_ +#define SRC_LIB_JSONPARSEV2_PARSEENTITIESRESPONSEV1_H_ /* * -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U +* Copyright 2024 Telefonica Investigacion y Desarrollo, S.A.U * * This file is part of Orion Context Broker. * @@ -23,26 +23,29 @@ * For those usages not covered by this license please contact with * iot_support at tid dot es * -* Author: Ken Zangelin +* Author: Orion dev team */ #include #include +#include "rapidjson/document.h" + #include "rest/ConnectionInfo.h" -#include "ngsi/ParseData.h" + +#include "apiTypesV2/EntityVector.h" /* **************************************************************************** * -* badNgsi9Request - +* parseEntitiesResponseV1 - */ -extern std::string badNgsi9Request +extern bool parseEntitiesResponseV1 ( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP + ConnectionInfo* ciP, + const char* payload, + EntityVector* evP, + OrionError* oeP ); -#endif // SRC_LIB_SERVICEROUTINES_BADNGSI9REQUEST_H_ +#endif // SRC_LIB_JSONPARSEV2_PARSEENTITIESRESPONSEV1_H_ diff --git a/src/lib/jsonParseV2/parseEntitiesVector.cpp b/src/lib/jsonParseV2/parseEntitiesVector.cpp index 041b6cf0f4..48ba071322 100644 --- a/src/lib/jsonParseV2/parseEntitiesVector.cpp +++ b/src/lib/jsonParseV2/parseEntitiesVector.cpp @@ -35,7 +35,7 @@ #include "rest/ConnectionInfo.h" #include "rest/OrionError.h" #include "parse/forbiddenChars.h" -#include "apiTypesV2/EntID.h" +#include "ngsi/EntityId.h" #include "common/string.h" #include "common/errorMessages.h" #include "jsonParseV2/utilsParse.h" @@ -49,10 +49,10 @@ */ bool parseEntitiesVector ( - ConnectionInfo* ciP, - std::vector* eivP, - const rapidjson::Value& entities, - std::string* errorStringP + ConnectionInfo* ciP, + std::vector* eivP, + const rapidjson::Value& entities, + std::string* errorStringP ) { if (!entities.IsArray()) @@ -209,7 +209,7 @@ bool parseEntitiesVector } } - ngsiv2::EntID eid(id, idPattern, type, typePattern); + EntityId eid(id, idPattern, type, typePattern); if (std::find(eivP->begin(), eivP->end(), eid) == eivP->end()) // if not already included { diff --git a/src/lib/jsonParseV2/parseEntitiesVector.h b/src/lib/jsonParseV2/parseEntitiesVector.h index 92c1bdea39..bf34906ef3 100644 --- a/src/lib/jsonParseV2/parseEntitiesVector.h +++ b/src/lib/jsonParseV2/parseEntitiesVector.h @@ -31,7 +31,7 @@ #include "rapidjson/document.h" #include "rest/ConnectionInfo.h" -#include "apiTypesV2/EntID.h" +#include "ngsi/EntityId.h" @@ -41,10 +41,10 @@ */ extern bool parseEntitiesVector ( - ConnectionInfo* ciP, - std::vector* eivP, - const rapidjson::Value& entities, - std::string* errorStringP + ConnectionInfo* ciP, + std::vector* eivP, + const rapidjson::Value& entities, + std::string* errorStringP ); #endif // SRC_LIB_JSONPARSEV2_PARSEENTITIESVECTOR_H_ diff --git a/src/lib/jsonParseV2/parseEntity.cpp b/src/lib/jsonParseV2/parseEntity.cpp index c47c3116a8..0382d98722 100644 --- a/src/lib/jsonParseV2/parseEntity.cpp +++ b/src/lib/jsonParseV2/parseEntity.cpp @@ -161,9 +161,9 @@ std::string parseEntity(ConnectionInfo* ciP, Entity* eP, bool eidInURL) return oe.toJson(); } - eP->id = iter->value.GetString(); + eP->entityId.id = iter->value.GetString(); - if (eP->id.empty()) + if (eP->entityId.id.empty()) { OrionError oe(SccBadRequest, ERROR_DESC_BAD_REQUEST_EMPTY_ENTITY_ID, ERROR_BAD_REQUEST); @@ -173,11 +173,11 @@ std::string parseEntity(ConnectionInfo* ciP, Entity* eP, bool eidInURL) return oe.toJson(); } - if (forbiddenIdChars(ciP->apiVersion, eP->id.c_str(), "")) + if (forbiddenIdCharsV2(eP->entityId.id.c_str(), "")) { OrionError oe(SccBadRequest, ERROR_DESC_BAD_REQUEST_INVALID_CHAR_ENTID, ERROR_BAD_REQUEST); - alarmMgr.badInput(clientIp, ERROR_DESC_BAD_REQUEST_INVALID_CHAR_ENTID, eP->id); + alarmMgr.badInput(clientIp, ERROR_DESC_BAD_REQUEST_INVALID_CHAR_ENTID, eP->entityId.id); ciP->httpStatusCode = SccBadRequest; return oe.toJson(); @@ -205,10 +205,10 @@ std::string parseEntity(ConnectionInfo* ciP, Entity* eP, bool eidInURL) return oe.toJson(); } - eP->type = iter->value.GetString(); - eP->typeGiven = true; + eP->entityId.type = iter->value.GetString(); + eP->typeGiven = true; - if (eP->type.empty()) + if (eP->entityId.type.empty()) { const char* errorText = ERROR_DESC_BAD_REQUEST_EMPTY_ENTTYPE; OrionError oe(SccBadRequest, errorText, ERROR_BAD_REQUEST); @@ -219,14 +219,13 @@ std::string parseEntity(ConnectionInfo* ciP, Entity* eP, bool eidInURL) return oe.toJson(); } - if (forbiddenIdChars(ciP->apiVersion, eP->type.c_str(), "")) + if (forbiddenIdCharsV2(eP->entityId.type.c_str(), "")) { OrionError oe(SccBadRequest, ERROR_DESC_BAD_REQUEST_INVALID_CHAR_ENTTYPE, ERROR_BAD_REQUEST); - alarmMgr.badInput(clientIp, ERROR_DESC_BAD_REQUEST_INVALID_CHAR_ENTTYPE, eP->type); + alarmMgr.badInput(clientIp, ERROR_DESC_BAD_REQUEST_INVALID_CHAR_ENTTYPE, eP->entityId.type); ciP->httpStatusCode = SccBadRequest; - return oe.toJson(); } } else // attribute @@ -269,7 +268,7 @@ std::string parseEntity(ConnectionInfo* ciP, Entity* eP, bool eidInURL) if (!eP->typeGiven) { - eP->type = DEFAULT_ENTITY_TYPE; + eP->entityId.type = DEFAULT_ENTITY_TYPE; } return "OK"; diff --git a/src/lib/jsonParseV2/parseEntityObject.cpp b/src/lib/jsonParseV2/parseEntityObject.cpp index aa6cc8b665..0e241d5bb2 100644 --- a/src/lib/jsonParseV2/parseEntityObject.cpp +++ b/src/lib/jsonParseV2/parseEntityObject.cpp @@ -81,9 +81,9 @@ std::string parseEntityObject return ERROR_DESC_BAD_REQUEST_INVALID_JTYPE_ENTID; } - eP->id = iter->value.GetString(); + eP->entityId.id = iter->value.GetString(); - if (forbiddenIdChars(V2, eP->id.c_str(), "")) + if (forbiddenIdCharsV2(eP->entityId.id.c_str(), "")) { return ERROR_DESC_BAD_REQUEST_INVALID_CHAR_ENTID; } @@ -106,8 +106,7 @@ std::string parseEntityObject } regfree(&re); // If regcomp fails it frees up itself (see glibc sources for details) - eP->id = iter->value.GetString(); - eP->isPattern = "true"; + eP->entityId.idPattern = iter->value.GetString(); } else if (name == "type") { @@ -116,15 +115,15 @@ std::string parseEntityObject return ERROR_DESC_BAD_REQUEST_INVALID_JTYPE_ENTTYPE; } - eP->type = iter->value.GetString(); - eP->typeGiven = true; + eP->entityId.type = iter->value.GetString(); + eP->typeGiven = true; - if (eP->type.empty()) + if (eP->entityId.type.empty()) { return ERROR_DESC_BAD_REQUEST_EMPTY_ENTTYPE; } - if (forbiddenIdChars(V2, eP->type.c_str(), "")) + if (forbiddenIdCharsV2(eP->entityId.type.c_str(), "")) { return ERROR_DESC_BAD_REQUEST_INVALID_CHAR_ENTTYPE; } @@ -143,8 +142,7 @@ std::string parseEntityObject } regfree(&re); // If regcomp fails it frees up itself (see glibc sources for details) - eP->type = iter->value.GetString(); - eP->isTypePattern = true; + eP->entityId.typePattern = iter->value.GetString(); } else { @@ -170,5 +168,5 @@ std::string parseEntityObject } } - return eP->check(V2, ciP->requestType); + return eP->check(ciP->requestType); } diff --git a/src/lib/jsonParseV2/parseEntityVector.cpp b/src/lib/jsonParseV2/parseEntityVector.cpp index 14dd8f1854..cab50317dc 100644 --- a/src/lib/jsonParseV2/parseEntityVector.cpp +++ b/src/lib/jsonParseV2/parseEntityVector.cpp @@ -30,7 +30,7 @@ #include "ngsi/ContextAttribute.h" -#include "apiTypesV2/Entities.h" +#include "apiTypesV2/EntityVector.h" #include "rest/ConnectionInfo.h" #include "jsonParseV2/jsonParseTypeNames.h" #include "jsonParseV2/parseEntityObject.h" @@ -46,7 +46,7 @@ std::string parseEntityVector ( ConnectionInfo* ciP, const rapidjson::Value::ConstMemberIterator& iter, - Entities* evP, + EntityVector* evP, bool idPatternAllowed, bool attributesAllowed ) diff --git a/src/lib/jsonParseV2/parseEntityVector.h b/src/lib/jsonParseV2/parseEntityVector.h index 92f09de906..9a51a3c96f 100644 --- a/src/lib/jsonParseV2/parseEntityVector.h +++ b/src/lib/jsonParseV2/parseEntityVector.h @@ -29,7 +29,6 @@ #include "rapidjson/document.h" -#include "apiTypesV2/Entities.h" #include "rest/ConnectionInfo.h" @@ -42,7 +41,7 @@ extern std::string parseEntityVector ( ConnectionInfo* ciP, const rapidjson::Value::ConstMemberIterator& iter, - Entities* evP, + EntityVector* evP, bool idPatternAllowed, bool attributesAllowed ); diff --git a/src/lib/jsonParseV2/parseExpression.cpp b/src/lib/jsonParseV2/parseExpression.cpp index d3d8be81a5..21957bd060 100644 --- a/src/lib/jsonParseV2/parseExpression.cpp +++ b/src/lib/jsonParseV2/parseExpression.cpp @@ -226,7 +226,7 @@ std::string parseExpression Scope* scopeP = new Scope(SCOPE_TYPE_LOCATION, ""); std::string err; - if (scopeP->fill(V2, geometry, coords, georel, &err) != 0) + if (scopeP->fill(geometry, coords, georel, &err) != 0) { delete scopeP; return "error parsing geo-query fields: " + err; diff --git a/src/lib/jsonParseV2/parseNotification.cpp b/src/lib/jsonParseV2/parseNotification.cpp index dd975f2e2f..6b4ff6f660 100644 --- a/src/lib/jsonParseV2/parseNotification.cpp +++ b/src/lib/jsonParseV2/parseNotification.cpp @@ -79,7 +79,8 @@ static bool parseContextElementResponse return false; } - cerP->entity.fill(entity.id, entity.type, entity.isPattern); + EntityId enId(entity.entityId.id, entity.entityId.idPattern, entity.entityId.type, entity.entityId.typePattern); + cerP->entity.fill(enId); cerP->entity.attributeVector.push_back(entity.attributeVector); entity.release(); @@ -196,7 +197,7 @@ static bool parseNotificationNormalized(ConnectionInfo* ciP, NotifyContextReques return false; } - ncrP->subscriptionId.set(iter->value.GetString()); + ncrP->subscriptionId = iter->value.GetString(); } else if (name == "data") { diff --git a/src/lib/jsonParseV2/parseRegistration.cpp b/src/lib/jsonParseV2/parseRegistration.cpp index c72d9df72a..8aa76f527a 100644 --- a/src/lib/jsonParseV2/parseRegistration.cpp +++ b/src/lib/jsonParseV2/parseRegistration.cpp @@ -93,7 +93,7 @@ static bool dataProvidedParse // for (unsigned int eIx = 0; eIx < dataProvidedP->entities.size(); ++eIx) { - ngsiv2::EntID* eP = &dataProvidedP->entities[eIx]; + EntityId* eP = &dataProvidedP->entities[eIx]; if ((!eP->idPattern.empty()) && (eP->idPattern != ".*")) { diff --git a/src/lib/jsonParseV2/parseScope.cpp b/src/lib/jsonParseV2/parseScope.cpp deleted file mode 100644 index 76dee139fe..0000000000 --- a/src/lib/jsonParseV2/parseScope.cpp +++ /dev/null @@ -1,259 +0,0 @@ -/* -* -* Copyright 2016 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include - -#include "rapidjson/document.h" - -#include "rest/ConnectionInfo.h" -#include "ngsi/ParseData.h" -#include "ngsi/Request.h" - -#include "jsonParseV2/jsonParseTypeNames.h" -#include "jsonParseV2/parseScope.h" - -#include "common/errorMessages.h" - - -/* **************************************************************************** -* -* parseScopeValueLocation - -* -* Hint: "value": { -* "georel": [ "near", "minDistance:13500" ], -* "geometry": "point", -* "coords": [ [40.418889,-3.691944] ] -* } -*/ -std::string parseScopeValueLocation(rapidjson::Value::ConstMemberIterator valueP, Scope* scopeP) -{ - // get value georel as a list of strings - // get value geometry as a string - // get coords as a list of pairs of numbers - std::string georelS; - std::string geometryS; - std::string coordsS; - - rapidjson::Value::ConstMemberIterator iter; - for (iter = valueP->value.MemberBegin(); iter != valueP->value.MemberEnd(); ++iter) - { - std::string name = iter->name.GetString(); - std::string type = jsonParseTypeNames[iter->value.GetType()]; - - if (name == "georel") - { - if (type != "Array") - { - return "invalid JSON type for geometry (must be array)"; - } - - for (rapidjson::Value::ConstValueIterator iter2 = iter->value.Begin(); iter2 != iter->value.End(); ++iter2) - { - std::string type = jsonParseTypeNames[iter2->GetType()]; - if (type != "String") - { - return "only JSON Strings allowed in geometry list"; - } - - georelS += iter2->GetString(); - if (iter2 != iter->value.End() - 1) - { - georelS += ";"; - } - } - } - else if (name == "geometry") - { - if (type != "String") - { - return "invalid JSON type for geometry (must be string)"; - } - - geometryS = iter->value.GetString(); - } - else if (name == "coords") - { - if (type != "Array") - { - return "invalid JSON type for geometry (must be array)"; - } - - for (rapidjson::Value::ConstValueIterator iter2 = iter->value.Begin(); iter2 != iter->value.End(); ++iter2) - { - std::string type = jsonParseTypeNames[iter2->GetType()]; - - if (type != "Array") - { - return "only JSON Arrays allowed in coords list"; - } - - rapidjson::Value::ConstValueIterator x = iter2->Begin(); // The first element in the array - rapidjson::Value::ConstValueIterator y = x + 1; // The next element in the array - - // Some sanity checks - if (y != iter2->End() - 1) - { - return "coordinates array must have only 2 elements"; - } - - std::string typeX = jsonParseTypeNames[x->GetType()]; - std::string typeY = jsonParseTypeNames[y->GetType()]; - - if (typeX != "Number" || typeY != "Number") - { - return "invalid JSON type for geometry (must be string)"; - } - - // Adding coord - char buf[STRING_SIZE_FOR_DOUBLE * 2 + 2]; - - snprintf(buf, sizeof(buf), "%f,%f", x->GetDouble(), y->GetDouble()); - coordsS += buf; - - if (iter2 != iter->value.End() - 1) - { - coordsS += ";"; - } - } - } - else - { - return std::string("unrecognized item in value object: /") + name + "/"; - } - } - - std::string result; - scopeP->fill(V2, geometryS, coordsS, georelS, &result); - - return result; -} - - - -/* **************************************************************************** -* -* parseScope - -*/ -std::string parseScope(ConnectionInfo* ciP, rapidjson::Value::ConstValueIterator valueP, Scope* scopeP) -{ - std::string type = jsonParseTypeNames[valueP->GetType()]; - - if (type != "Object") - { - return "scope is not a JSON object"; - } - - // Process scope type - rapidjson::Value::ConstMemberIterator iter = valueP->FindMember("type"); - - if (iter == valueP->MemberEnd()) - { - return "scope without a type"; - } - type = jsonParseTypeNames[iter->value.GetType()]; - - if (type != "String") - { - return "invalid JSON type for scope type"; - } - scopeP->type = iter->value.GetString(); - - // Process scope value - iter = valueP->FindMember("value"); - if (iter == valueP->MemberEnd()) - { - return "scope without a value"; - } - type = jsonParseTypeNames[iter->value.GetType()]; - - // Processing depend on the filter type - if (scopeP->type == FIWARE_LOCATION_V2) - { - if (type != "Object") - { - return "invalid JSON type for scope value (must be object)"; - } - - if (!iter->value.HasMember("georel")) - { - return "missing field in value: georel"; - } - - if (!iter->value.HasMember("geometry")) - { - return "missing field in value: geometry"; - } - - if (!iter->value.HasMember("coords")) - { - return "missing field in value: coords"; - } - - std::string r = parseScopeValueLocation(iter, scopeP); - if (!r.empty()) - { - return r; - } - } - else // Other filters (all them use 'value' as string) - { - if (type != "String") - { - return ERROR_DESC_BAD_REQUEST_INVALID_JTYPE_SCOPE; - } - - scopeP->value = iter->value.GetString(); - } - - if (scopeP->type == SCOPE_TYPE_SIMPLE_QUERY) - { - std::string errorString; - - scopeP->stringFilterP = new StringFilter(SftQ); - bool b = scopeP->stringFilterP->parse(scopeP->value.c_str(), &errorString); - - if (b != true) - { - delete scopeP->stringFilterP; - scopeP->stringFilterP = NULL; - return errorString; - } - } - else if (scopeP->type == SCOPE_TYPE_SIMPLE_QUERY_MD) - { - std::string errorString; - - scopeP->mdStringFilterP = new StringFilter(SftMq); - bool b = scopeP->mdStringFilterP->parse(scopeP->value.c_str(), &errorString); - - if (b != true) - { - delete scopeP->mdStringFilterP; - scopeP->mdStringFilterP = NULL; - return errorString; - } - } - - return "OK"; -} diff --git a/src/lib/jsonParseV2/parseScope.h b/src/lib/jsonParseV2/parseScope.h deleted file mode 100644 index c33d76e9f1..0000000000 --- a/src/lib/jsonParseV2/parseScope.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef SRC_LIB_JSONPARSEV2_PARSESCOPE_H_ -#define SRC_LIB_JSONPARSEV2_PARSESCOPE_H_ - -/* -* -* Copyright 2016 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include - -#include "rapidjson/document.h" - -#include "rest/ConnectionInfo.h" -#include "ngsi/Scope.h" - - - -/* **************************************************************************** -* -* parseScope - -* -* Using 'const rapidjson::Value::GenericValue*' for 'value' causes compilation problems in -* some environments (in particular, at least in Debian 8.2 with gcc 4.9.2) -* -*/ -extern std::string parseScope -( - ConnectionInfo* ciP, - rapidjson::Value::ConstValueIterator valueP, - Scope* scopeP -); - -#endif // SRC_LIB_JSONPARSEV2_PARSESCOPE_H_ diff --git a/src/lib/jsonParseV2/parseSubscription.cpp b/src/lib/jsonParseV2/parseSubscription.cpp index 77269af0aa..cf518c63e3 100644 --- a/src/lib/jsonParseV2/parseSubscription.cpp +++ b/src/lib/jsonParseV2/parseSubscription.cpp @@ -59,7 +59,6 @@ * USING */ using ngsiv2::SubscriptionUpdate; -using ngsiv2::EntID; using rapidjson::Value; @@ -524,7 +523,7 @@ static std::string parseCustomPayload return badInput(ciP, ERROR_DESC_BAD_REQUEST_INVALID_JTYPE_ENTID); } - ngsi->id = iter->value.GetString(); + ngsi->entityId.id = iter->value.GetString(); } else if (name == "type") { @@ -533,7 +532,7 @@ static std::string parseCustomPayload return badInput(ciP, ERROR_DESC_BAD_REQUEST_INVALID_JTYPE_ENTTYPE); } - ngsi->type = iter->value.GetString(); + ngsi->entityId.type = iter->value.GetString(); } else // attribute { @@ -1330,7 +1329,7 @@ static std::string parseNotifyConditionVector // Expression if (condition.HasMember("expression")) { - std::string r = parseExpression(condition["expression"], &subsP->restriction.scopeVector, subsP); + std::string r = parseExpression(condition["expression"], &subsP->scopeVector, subsP); if (r != "OK") { diff --git a/src/lib/logMsg/traceLevels.h b/src/lib/logMsg/traceLevels.h index 84a40bc6f8..510f97c180 100644 --- a/src/lib/logMsg/traceLevels.h +++ b/src/lib/logMsg/traceLevels.h @@ -74,9 +74,8 @@ typedef enum TraceLevels LmtCompoundValueRaw, LmtCompoundValueContainer, LmtCompoundValueStep, - LmtCompoundValueShow, - LmtJsonAttributes = 55, - LmtRegexError, + LmtJsonAttributes, + LmtRegexError = 55, /* RestService and Service (60-79) */ LmtService = 60, diff --git a/src/lib/metricsMgr/MetricsManager.h b/src/lib/metricsMgr/MetricsManager.h index a8b1aac374..6b4f98a973 100644 --- a/src/lib/metricsMgr/MetricsManager.h +++ b/src/lib/metricsMgr/MetricsManager.h @@ -65,7 +65,6 @@ // The following counters are still under discussion // #define METRIC_TRANSACTIONS "transactions" -#define METRIC_NGSIV1_TRANSACTIONS "ngsiv1Transactions" #define METRIC_NGSIV2_TRANSACTIONS "ngsiv2Transactions" #define METRIC_AVERAGE_TRANSACTION_TIME "averageTransactionTime" #define METRIC_OK_TRANSACTIONS "okTransactions" diff --git a/src/lib/mongoBackend/CMakeLists.txt b/src/lib/mongoBackend/CMakeLists.txt index 25960522f5..25db1e03ae 100644 --- a/src/lib/mongoBackend/CMakeLists.txt +++ b/src/lib/mongoBackend/CMakeLists.txt @@ -23,15 +23,10 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.0) SET (SOURCES MongoGlobal.cpp MongoCommonUpdate.cpp - MongoCommonRegister.cpp MongoCommonSubscription.cpp - mongoRegisterContext.cpp - mongoDiscoverContextAvailability.cpp mongoUpdateContext.cpp mongoQueryContext.cpp - mongoSubscribeContext.cpp mongoUnsubscribeContext.cpp - mongoUpdateContextSubscription.cpp mongoNotifyContext.cpp mongoQueryTypes.cpp mongoCreateSubscription.cpp @@ -52,15 +47,10 @@ SET (HEADERS dbConstants.h MongoGlobal.h MongoCommonUpdate.h - MongoCommonRegister.h MongoCommonSubscription.h - mongoRegisterContext.h - mongoDiscoverContextAvailability.h mongoUpdateContext.h mongoQueryContext.h - mongoSubscribeContext.h mongoUnsubscribeContext.h - mongoUpdateContextSubscription.h mongoNotifyContext.h mongoQueryTypes.h mongoCreateSubscription.h diff --git a/src/lib/mongoBackend/MongoCommonRegister.cpp b/src/lib/mongoBackend/MongoCommonRegister.cpp deleted file mode 100644 index ab496e7bd2..0000000000 --- a/src/lib/mongoBackend/MongoCommonRegister.cpp +++ /dev/null @@ -1,189 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Fermín Galán -*/ -#include -#include -#include -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/string.h" -#include "common/globals.h" -#include "common/statistics.h" -#include "common/sem.h" -#include "common/RenderFormat.h" -#include "common/defaultValues.h" -#include "alarmMgr/alarmMgr.h" - -#include "mongoBackend/MongoGlobal.h" -#include "mongoBackend/TriggeredSubscription.h" -#include "mongoBackend/dbConstants.h" -#include "mongoBackend/MongoCommonRegister.h" - -#include "mongoDriver/connectionOperations.h" -#include "mongoDriver/mongoConnectionPool.h" -#include "mongoDriver/safeMongo.h" -#include "mongoDriver/BSONArrayBuilder.h" -#include "mongoDriver/BSONObjBuilder.h" - - - -/* **************************************************************************** -* -* processRegisterContext - -* -* This function has a slightly different behaviour depending on whether the id -* parameter is null (new registration case) or not null (update case), in -* particular: -* -* - In the new registration case, the _id is generated and insert() is used to -* put the document in the DB. -* - In the update case, the _id is set according to the argument 'id' and update() is -* used to put the document in the DB. -*/ -HttpStatusCode processRegisterContext -( - RegisterContextRequest* requestP, - RegisterContextResponse* responseP, - orion::OID* id, - const std::string& tenant, - const std::string& servicePath, - const std::string& format, - const std::string& fiwareCorrelator -) -{ - std::string err; - - /* If expiration is not present, then use a default one */ - if (requestP->duration.isEmpty()) - { - requestP->duration.set(DEFAULT_DURATION); - } - - /* Calculate expiration (using the current time and the duration field in the request) */ - long long expiration = getCurrentTime() + requestP->duration.parse(); - - LM_T(LmtMongo, ("Registration expiration: %lu", expiration)); - - /* Create the mongoDB registration document */ - orion::BSONObjBuilder reg; - orion::OID oid; - - if (id == NULL) - { - oid.init(); - } - else - { - oid = *id; - } - - reg.append("_id", oid); - reg.append(REG_EXPIRATION, expiration); - - // FIXME P4: See issue #3078 - reg.append(REG_SERVICE_PATH, servicePath.empty() ? SERVICE_PATH_ROOT : servicePath); - reg.append(REG_FORMAT, format); - - // In NGISv1 forwarding mode is always "all" - reg.append(REG_FORWARDING_MODE, "all"); - - orion::BSONArrayBuilder contextRegistration; - - for (unsigned int ix = 0; ix < requestP->contextRegistrationVector.size(); ++ix) - { - ContextRegistration* cr = requestP->contextRegistrationVector[ix]; - orion::BSONArrayBuilder entities; - - for (unsigned int jx = 0; jx < cr->entityIdVector.size(); ++jx) - { - EntityId* en = cr->entityIdVector[jx]; - - - orion::BSONObjBuilder bob; - bob.append(REG_ENTITY_ID, en->id); - - if (en->type.empty()) - { - LM_T(LmtMongo, ("Entity registration: {id: %s}", en->id.c_str())); - } - else - { - bob.append(REG_ENTITY_TYPE, en->type); - LM_T(LmtMongo, ("Entity registration: {id: %s, type: %s}", en->id.c_str(), en->type.c_str())); - } - entities.append(bob.obj()); - } - - orion::BSONArrayBuilder attrs; - - for (unsigned int jx = 0; jx < cr->contextRegistrationAttributeVector.size(); ++jx) - { - ContextRegistrationAttribute* cra = cr->contextRegistrationAttributeVector[jx]; - - orion::BSONObjBuilder bob; - bob.append(REG_ATTRS_NAME, cra->name); - bob.append(REG_ATTRS_TYPE, cra->type); - - attrs.append(bob.obj()); - LM_T(LmtMongo, ("Attribute registration: {name: %s, type: %s}", - cra->name.c_str(), - cra->type.c_str())); - } - - // FIXME #3774: previously this part was based in streamming instead of append() - orion::BSONObjBuilder bob; - bob.append(REG_ENTITIES, entities.arr()); - bob.append(REG_ATTRS, attrs.arr()); - bob.append(REG_PROVIDING_APPLICATION, requestP->contextRegistrationVector[ix]->providingApplication.get()); - - contextRegistration.append(bob.obj()); - - LM_T(LmtMongo, ("providingApplication registration: %s", - requestP->contextRegistrationVector[ix]->providingApplication.c_str())); - } - reg.append(REG_CONTEXT_REGISTRATION, contextRegistration.arr()); - - /* Note that we are using upsert = "true". This means that if the document doesn't previously - * exist in the collection, it is created. Thus, this way both uses of registerContext are OK - * (either new registration or updating an existing one) - */ - orion::BSONObjBuilder bobId; - bobId.append("_id", oid); - if (!orion::collectionUpdate(composeDatabaseName(tenant), COL_REGISTRATIONS, bobId.obj(), reg.obj(), true, &err)) - { - responseP->errorCode.fill(SccReceiverInternalError, err); - return SccOk; - } - - // Fill the response element - responseP->duration = requestP->duration; - responseP->registrationId.set(oid.toString()); - responseP->errorCode.fill(SccOk); - - return SccOk; -} diff --git a/src/lib/mongoBackend/MongoCommonRegister.h b/src/lib/mongoBackend/MongoCommonRegister.h deleted file mode 100644 index 392224ef07..0000000000 --- a/src/lib/mongoBackend/MongoCommonRegister.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef SRC_LIB_MONGOBACKEND_MONGOCOMMONREGISTER_H_ -#define SRC_LIB_MONGOBACKEND_MONGOCOMMONREGISTER_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Fermín Galán -*/ -#include - -#include "ngsi9/RegisterContextRequest.h" -#include "ngsi9/RegisterContextResponse.h" -#include "apiTypesV2/Registration.h" - -#include "mongoDriver/OID.h" - - -/* **************************************************************************** -* -* processRegisterContext - -*/ -extern HttpStatusCode processRegisterContext -( - RegisterContextRequest* requestP, - RegisterContextResponse* responseP, - orion::OID* id, - const std::string& tenant, - const std::string& servicePath, - const std::string& format, - const std::string& fiwareCorrelator -); - -#endif // SRC_LIB_MONGOBACKEND_MONGOCOMMONREGISTER_H_ diff --git a/src/lib/mongoBackend/MongoCommonSubscription.cpp b/src/lib/mongoBackend/MongoCommonSubscription.cpp index dd6bcf3101..f7456d3f7f 100644 --- a/src/lib/mongoBackend/MongoCommonSubscription.cpp +++ b/src/lib/mongoBackend/MongoCommonSubscription.cpp @@ -45,7 +45,6 @@ */ using ngsiv2::Subscription; using ngsiv2::HttpInfo; -using ngsiv2::EntID; @@ -142,7 +141,7 @@ static void setCustomHttpInfo(const HttpInfo& httpInfo, orion::BSONObjBuilder* b if (httpInfo.json->isObject()) { orion::BSONObjBuilder jsonBuilder; - compoundValueBson(httpInfo.json->childV, jsonBuilder, false); + compoundValueBson(httpInfo.json->childV, jsonBuilder); orion::BSONObj jsonBuilderObj = jsonBuilder.obj(); logStr = jsonBuilderObj.toString(); b->append(CSUB_JSON, jsonBuilderObj); @@ -150,7 +149,7 @@ static void setCustomHttpInfo(const HttpInfo& httpInfo, orion::BSONObjBuilder* b else // httpInfo.json->isVector(); { orion::BSONArrayBuilder jsonBuilder; - compoundValueBson(httpInfo.json->childV, jsonBuilder, false); + compoundValueBson(httpInfo.json->childV, jsonBuilder); orion::BSONArray jsonBuilderArr = jsonBuilder.arr(); logStr = jsonBuilderArr.toString(); b->append(CSUB_JSON, jsonBuilderArr); @@ -162,20 +161,20 @@ static void setCustomHttpInfo(const HttpInfo& httpInfo, orion::BSONObjBuilder* b { // id and type (both optional in this case) orion::BSONObjBuilder bob; - if (!httpInfo.ngsi.id.empty()) + if (!httpInfo.ngsi.entityId.id.empty()) { - bob.append(ENT_ENTITY_ID, httpInfo.ngsi.id); + bob.append(ENT_ENTITY_ID, httpInfo.ngsi.entityId.id); } - if (!httpInfo.ngsi.type.empty()) + if (!httpInfo.ngsi.entityId.type.empty()) { - bob.append(ENT_ENTITY_TYPE, httpInfo.ngsi.type); + bob.append(ENT_ENTITY_TYPE, httpInfo.ngsi.entityId.type); } // attributes // (-1 as date as creDate and modDate are not used in this case) orion::BSONObjBuilder attrsToAdd; // not actually used orion::BSONArrayBuilder attrNamesToAdd; - httpInfo.ngsi.attributeVector.toBson(-1, &attrsToAdd, &attrNamesToAdd, V2); + httpInfo.ngsi.attributeVector.toBson(-1, &attrsToAdd, &attrNamesToAdd); // note that although metadata is not needed in the ngsi field logic, // mdNames: [ ] is added to each attribute as a consequence of the toBson() logic @@ -214,7 +213,7 @@ static void setCustomMqttInfo(const ngsiv2::MqttInfo& mqttInfo, orion::BSONObjBu if (mqttInfo.json->isObject()) { orion::BSONObjBuilder jsonBuilder; - compoundValueBson(mqttInfo.json->childV, jsonBuilder, false); + compoundValueBson(mqttInfo.json->childV, jsonBuilder); orion::BSONObj jsonBuilderObj = jsonBuilder.obj(); logStr = jsonBuilderObj.toString(); b->append(CSUB_JSON, jsonBuilderObj); @@ -222,7 +221,7 @@ static void setCustomMqttInfo(const ngsiv2::MqttInfo& mqttInfo, orion::BSONObjBu else // httpInfo.json->isVector(); { orion::BSONArrayBuilder jsonBuilder; - compoundValueBson(mqttInfo.json->childV, jsonBuilder, false); + compoundValueBson(mqttInfo.json->childV, jsonBuilder); orion::BSONArray jsonBuilderArr = jsonBuilder.arr(); logStr = jsonBuilderArr.toString(); b->append(CSUB_JSON, jsonBuilderArr); @@ -234,20 +233,20 @@ static void setCustomMqttInfo(const ngsiv2::MqttInfo& mqttInfo, orion::BSONObjBu { // id and type (both optional in this case) orion::BSONObjBuilder bob; - if (!mqttInfo.ngsi.id.empty()) + if (!mqttInfo.ngsi.entityId.id.empty()) { - bob.append(ENT_ENTITY_ID, mqttInfo.ngsi.id); + bob.append(ENT_ENTITY_ID, mqttInfo.ngsi.entityId.id); } - if (!mqttInfo.ngsi.type.empty()) + if (!mqttInfo.ngsi.entityId.type.empty()) { - bob.append(ENT_ENTITY_TYPE, mqttInfo.ngsi.type); + bob.append(ENT_ENTITY_TYPE, mqttInfo.ngsi.entityId.type); } // attributes // (-1 as date as creDate and modDate are not used in this case) orion::BSONObjBuilder attrsToAdd; // not actually used orion::BSONArrayBuilder attrNamesToAdd; - mqttInfo.ngsi.attributeVector.toBson(-1, &attrsToAdd, &attrNamesToAdd, V2); + mqttInfo.ngsi.attributeVector.toBson(-1, &attrsToAdd, &attrNamesToAdd); // note that although metadata is not needed in the ngsi field logic, // mdNames: [ ] is added to each attribute as a consequence of the toBson() logic @@ -392,13 +391,13 @@ void setStatus(const std::string& _status, orion::BSONObjBuilder* b, double now) * * setEntities - */ -void setEntities(const Subscription& sub, orion::BSONObjBuilder* b, bool fromNgsiv1) +void setEntities(const Subscription& sub, orion::BSONObjBuilder* b) { orion::BSONArrayBuilder entities; for (unsigned int ix = 0; ix < sub.subject.entities.size(); ++ix) { - EntID en = sub.subject.entities[ix]; + EntityId en = sub.subject.entities[ix]; std::string finalId; std::string finalType; std::string isIdPattern; @@ -441,15 +440,6 @@ void setEntities(const Subscription& sub, orion::BSONObjBuilder* b, bool fromNgs entities.append(bob.obj()); } - if ((fromNgsiv1) && (entities.arrSize() == 0)) - { - // Special case: in NGSIv1 entities and condition attributes are not - // part of the same field (subject, in NGSIv2) so it may happen that - // subject only contains condition attributes and entities has to be - // left untouched in this case - return; - } - orion::BSONArray entitiesArr = entities.arr(); b->append(CSUB_ENTITIES, entitiesArr); diff --git a/src/lib/mongoBackend/MongoCommonSubscription.h b/src/lib/mongoBackend/MongoCommonSubscription.h index 663d90db9b..ae7e6725cd 100644 --- a/src/lib/mongoBackend/MongoCommonSubscription.h +++ b/src/lib/mongoBackend/MongoCommonSubscription.h @@ -109,7 +109,7 @@ extern void setStatus(const std::string& _status, orion::BSONObjBuilder* b, doub * * setEntities - */ -extern void setEntities(const ngsiv2::Subscription& sub, orion::BSONObjBuilder* b, bool fromNgsiv1 = false); +extern void setEntities(const ngsiv2::Subscription& sub, orion::BSONObjBuilder* b); diff --git a/src/lib/mongoBackend/MongoCommonUpdate.cpp b/src/lib/mongoBackend/MongoCommonUpdate.cpp index a866f45446..04c17fced6 100644 --- a/src/lib/mongoBackend/MongoCommonUpdate.cpp +++ b/src/lib/mongoBackend/MongoCommonUpdate.cpp @@ -355,8 +355,7 @@ static ChangeType mergeAttrInfo orion::BSONObjBuilder* toSet, orion::BSONObjBuilder* toUnset, const bool& forcedUpdate, - const bool& overrideMetadata, - ApiVersion apiVersion + const bool& overrideMetadata ) { /* 1. Add value, if present in the request (it could be omitted in the case of updating only metadata). @@ -368,7 +367,7 @@ static ChangeType mergeAttrInfo if (!isSomeCalculatedOperatorUsed(caP)) { // FIXME P7: boolean return value should be managed? - caP->valueBson(composedName + "." + ENT_ATTRS_VALUE, toSet, getStringFieldF(attr, ENT_ATTRS_TYPE), ngsiv1Autocast && (apiVersion == V1)); + caP->valueBson(composedName + "." + ENT_ATTRS_VALUE, toSet, getStringFieldF(attr, ENT_ATTRS_TYPE)); } } else @@ -430,7 +429,7 @@ static ChangeType mergeAttrInfo { Metadata* mdP = caP->metadataVector[ix]; - mdP->appendToBsoN(&mdBuilder, &mdNamesBuilder, apiVersion == V2); + mdP->appendToBsoN(&mdBuilder, &mdNamesBuilder, true); } @@ -456,7 +455,7 @@ static ChangeType mergeAttrInfo mdSize++; - if (apiVersion != V2 || caP->onlyValue || !overrideMetadata) + if (caP->onlyValue || !overrideMetadata) { if (!hasMetadata(dbDecode(md.name), md.type, caP)) { @@ -591,8 +590,7 @@ static bool updateAttribute ChangeType* changeType, bool isReplace, const bool& forcedUpdate, - const bool& overrideMetadata, - ApiVersion apiVersion + const bool& overrideMetadata ) { *changeType = NO_CHANGE; @@ -608,7 +606,7 @@ static bool updateAttribute *changeType = CHANGE_VALUE_AND_MD; std::string attrType; - if (!caP->typeGiven && (apiVersion == V2)) + if (!caP->typeGiven) { if ((caP->compoundValueP == NULL) || (caP->compoundValueP->valueType != orion::ValueTypeVector)) { @@ -629,13 +627,13 @@ static bool updateAttribute newAttr.append(ENT_ATTRS_MODIFICATION_DATE, now); // FIXME P7: boolean return value should be managed? - caP->valueBson(std::string(ENT_ATTRS_VALUE), &newAttr, attrType, ngsiv1Autocast && (apiVersion == V1)); + caP->valueBson(std::string(ENT_ATTRS_VALUE), &newAttr, attrType); /* Custom metadata */ orion::BSONObjBuilder md; orion::BSONArrayBuilder mdNames; - caP->metadataVector.toBson(&md, &mdNames, apiVersion == V2); + caP->metadataVector.toBson(&md, &mdNames, true); if (mdNames.arrSize() > 0) { newAttr.append(ENT_ATTRS_MD, md.obj()); @@ -655,7 +653,7 @@ static bool updateAttribute orion::BSONObj newAttr; orion::BSONObj attr = getObjectFieldF(*attrsP, effectiveName); - *changeType = mergeAttrInfo(attr, caP, composedName, toSet, toUnset, forcedUpdate, overrideMetadata, apiVersion); + *changeType = mergeAttrInfo(attr, caP, composedName, toSet, toUnset, forcedUpdate, overrideMetadata); } return true; @@ -689,8 +687,7 @@ static bool appendAttribute ContextAttribute* caP, ChangeType* changeType, const bool& forcedUpdate, - const bool& overrideMetadata, - ApiVersion apiVersion + const bool& overrideMetadata ) { std::string effectiveName = dbEncode(caP->name); @@ -699,7 +696,7 @@ static bool appendAttribute /* APPEND with existing attribute equals to UPDATE */ if (attrsP->hasField(effectiveName)) { - updateAttribute(attrsP, toSet, toUnset, attrNamesAdd, caP, changeType, false, forcedUpdate, overrideMetadata, apiVersion); + updateAttribute(attrsP, toSet, toUnset, attrNamesAdd, caP, changeType, false, forcedUpdate, overrideMetadata); return false; } @@ -709,11 +706,11 @@ static bool appendAttribute if (!isSomeCalculatedOperatorUsed(caP)) { // FIXME P7: boolean return value should be managed? - caP->valueBson(composedName + "." + ENT_ATTRS_VALUE, toSet, caP->type, ngsiv1Autocast && (apiVersion == V1)); + caP->valueBson(composedName + "." + ENT_ATTRS_VALUE, toSet, caP->type); } /* 2. Type */ - if ((apiVersion == V2) && !caP->typeGiven) + if (!caP->typeGiven) { std::string attrType; @@ -737,7 +734,7 @@ static bool appendAttribute orion::BSONObjBuilder md; orion::BSONArrayBuilder mdNames; - caP->metadataVector.toBson(&md, &mdNames, apiVersion == V2); + caP->metadataVector.toBson(&md, &mdNames, true); if (mdNames.arrSize() > 0) { toSet->append(composedName + "." + ENT_ATTRS_MD, md.obj()); @@ -1680,14 +1677,11 @@ static bool addTriggeredSubscriptions_noCache LM_T(LmtMongo, ("adding subscription: '%s'", sub.toString().c_str())); - // - // NOTE: renderFormatString: NGSIv1 JSON is 'default' (for old db-content) - // long long throttling = sub.hasField(CSUB_THROTTLING)? getIntOrLongFieldAsLongF(sub, CSUB_THROTTLING) : -1; long long maxFailsLimit = sub.hasField(CSUB_MAXFAILSLIMIT)? getIntOrLongFieldAsLongF(sub, CSUB_MAXFAILSLIMIT) : -1; long long failsCounter = sub.hasField(CSUB_FAILSCOUNTER)? getIntOrLongFieldAsLongF(sub, CSUB_FAILSCOUNTER) : -1; long long lastNotification = sub.hasField(CSUB_LASTNOTIFICATION)? getIntOrLongFieldAsLongF(sub, CSUB_LASTNOTIFICATION) : -1; - std::string renderFormatString = sub.hasField(CSUB_FORMAT)? getStringFieldF(sub, CSUB_FORMAT) : "legacy"; + std::string renderFormatString = sub.hasField(CSUB_FORMAT)? getStringFieldF(sub, CSUB_FORMAT) : "normalized"; bool onlyChanged = sub.hasField(CSUB_ONLYCHANGED)? getBoolFieldF(sub, CSUB_ONLYCHANGED) : false; bool blacklist = sub.hasField(CSUB_BLACKLIST)? getBoolFieldF(sub, CSUB_BLACKLIST) : false; bool covered = sub.hasField(CSUB_COVERED)? getBoolFieldF(sub, CSUB_COVERED) : false; @@ -1988,7 +1982,7 @@ static unsigned int processSubscriptions Scope geoScope; std::string filterErr; - if (geoScope.fill(V2, tSubP->expression.geometry, tSubP->expression.coords, tSubP->expression.georel, &filterErr) != 0) + if (geoScope.fill(tSubP->expression.geometry, tSubP->expression.coords, tSubP->expression.georel, &filterErr) != 0) { // This has been already checked at subscription creation/update parsing time. Thus, the code cannot reach // this part. @@ -2014,8 +2008,8 @@ static unsigned int processSubscriptions std::string keyType = "_id." ENT_ENTITY_TYPE; std::string keySp = "_id." ENT_SERVICE_PATH; - std::string id = notifyCerP->entity.id; - std::string type = notifyCerP->entity.type; + std::string id = notifyCerP->entity.entityId.id; + std::string type = notifyCerP->entity.entityId.type; std::string sp = notifyCerP->entity.servicePath; bobCountQuery.append(keyId, id); @@ -2169,39 +2163,6 @@ static unsigned int processSubscriptions -/* **************************************************************************** -* -* buildGeneralErrorResponse - -*/ -static void buildGeneralErrorResponse -( - Entity* ceP, - ContextAttribute* caP, - UpdateContextResponse* responseP, - HttpStatusCode code, - std::string details = "", - ContextAttributeVector* cavP = NULL -) -{ - ContextElementResponse* cerP = new ContextElementResponse(); - - cerP->entity.fill(ceP->id, ceP->type, ceP->isPattern); - - if (caP != NULL) - { - cerP->entity.attributeVector.push_back(caP); - } - else if (cavP != NULL) - { - cerP->entity.attributeVector.fill(*cavP); - } - - cerP->statusCode.fill(code, details); - responseP->contextElementResponseVector.push_back(cerP); -} - - - /* **************************************************************************** * * setResponseMetadata - @@ -2428,13 +2389,12 @@ static bool updateContextAttributeItem bool isReplace, const bool& forcedUpdate, const bool& overrideMetadata, - ApiVersion apiVersion, OrionError* oe ) { std::string err; - if (updateAttribute(attrsP, toSet, toUnset, attrNamesAdd, targetAttr, changeType, isReplace, forcedUpdate, overrideMetadata, apiVersion)) + if (updateAttribute(attrsP, toSet, toUnset, attrNamesAdd, targetAttr, changeType, isReplace, forcedUpdate, overrideMetadata)) { // Attribute was found *entityModified = *entityModified || (*changeType != NO_CHANGE); @@ -2446,7 +2406,7 @@ static bool updateContextAttributeItem { /* If updateAttribute() returns false, then that particular attribute has not * been found. In this case, we interrupt the processing and early return with - * an error StatusCode */ + * an error OrionError */ // // FIXME P10: not sure if this .fill() is useless... it seems it is "overriden" by @@ -2457,7 +2417,7 @@ static bool updateContextAttributeItem " - entity: [" + entityDetail + "]" + " - offending attribute: " + targetAttr->getName(); - cerP->statusCode.fill(SccInvalidParameter, details); + cerP->error.fill(SccInvalidParameter, details); /* Although 'ca' has been already pushed into cerP, the pointer is still valid, of course */ ca->found = false; @@ -2466,7 +2426,7 @@ static bool updateContextAttributeItem /* Check aspects related with location and date expiration */ /* attrP is passed only if existing metadata has to be inspected for ignoreType in geo-location * i.e. if overrideMetadata is not in use */ - if (!processLocationAtUpdateAttribute(currentLocAttrName, overrideMetadata? NULL : attrsP, targetAttr, geoJson, &err, apiVersion, oe) + if (!processLocationAtUpdateAttribute(currentLocAttrName, overrideMetadata? NULL : attrsP, targetAttr, geoJson, &err, oe) || !processDateExpirationAtUpdateAttribute(targetAttr, dateExpiration, dateExpirationInPayload, &err, oe)) { std::string details = std::string("action: UPDATE") + @@ -2474,14 +2434,14 @@ static bool updateContextAttributeItem " - offending attribute: " + targetAttr->getName() + " - " + err; - cerP->statusCode.fill(SccInvalidParameter, details); + cerP->error.fill(SccInvalidParameter, details); // oe->fill() not used, as this is done internally in processLocationAtUpdateAttribute() alarmMgr.badInput(clientIp, err, targetAttr->getName()); return false; } - updateAttrInNotifyCer(notifyCerP, targetAttr, apiVersion == V2, NGSI_MD_ACTIONTYPE_UPDATE, overrideMetadata); + updateAttrInNotifyCer(notifyCerP, targetAttr, true, NGSI_MD_ACTIONTYPE_UPDATE, overrideMetadata); return true; } @@ -2512,13 +2472,12 @@ static bool appendContextAttributeItem orion::BSONDate* dateExpiration, const bool& forcedUpdate, const bool& overrideMetadata, - ApiVersion apiVersion, OrionError* oe ) { std::string err; - bool actualAppend = appendAttribute(attrsP, toSet, toUnset, attrNamesAdd, targetAttr, changeType, forcedUpdate, overrideMetadata, apiVersion); + bool actualAppend = appendAttribute(attrsP, toSet, toUnset, attrNamesAdd, targetAttr, changeType, forcedUpdate, overrideMetadata); *entityModified = *entityModified || (*changeType != NO_CHANGE); @@ -2526,7 +2485,7 @@ static bool appendContextAttributeItem /* attrP is passed only if existing metadata has to be inspected for ignoreType in geo-location * i.e. if overrideMetadata is not in use */ if (!processLocationAtAppendAttribute(currentLocAttrName, overrideMetadata? NULL : attrsP, targetAttr, actualAppend, geoJson, - &err, apiVersion, oe) + &err, oe) || !processDateExpirationAtAppendAttribute(dateExpiration, targetAttr, actualAppend, &err, oe)) { std::string details = std::string("action: APPEND") + @@ -2534,7 +2493,7 @@ static bool appendContextAttributeItem " - offending attribute: " + targetAttr->getName() + " - " + err; - cerP->statusCode.fill(SccInvalidParameter, details); + cerP->error.fill(SccInvalidParameter, details); // oe->fill() is not used here as it is managed by processLocationAtAppendAttribute() alarmMgr.badInput(clientIp, err, targetAttr->getName()); @@ -2546,7 +2505,7 @@ static bool appendContextAttributeItem // to be called after the location processing logic (as this logic may need the compoundValueP std::string actionType = (actualAppend == true)? NGSI_MD_ACTIONTYPE_APPEND : NGSI_MD_ACTIONTYPE_UPDATE; - updateAttrInNotifyCer(notifyCerP, targetAttr, apiVersion == V2, actionType, overrideMetadata); + updateAttrInNotifyCer(notifyCerP, targetAttr, true, actionType, overrideMetadata); return true; } @@ -2586,7 +2545,7 @@ static bool deleteContextAttributeItem " - offending attribute: " + targetAttr->getName() + " - location attribute has to be defined at creation time, with APPEND"; - cerP->statusCode.fill(SccInvalidParameter, details); + cerP->error.fill(SccInvalidParameter, details); oe->fill(SccInvalidModification, details, ERROR_UNPROCESSABLE); alarmMgr.badInput(clientIp, "location attribute has to be defined at creation time", targetAttr->getName()); @@ -2614,13 +2573,13 @@ static bool deleteContextAttributeItem { /* If deleteAttribute() returns false, then that particular attribute has not * been found. In this case, we interrupt the processing and early return with - * a error StatusCode */ + * a OrionError */ std::string details = std::string("action: DELETE") + " - entity: [" + entityDetail + "]" + " - offending attribute: " + targetAttr->getName() + " - attribute not found"; - cerP->statusCode.fill(SccInvalidParameter, details); + cerP->error.fill(SccInvalidParameter, details); alarmMgr.badInput(clientIp, "attribute to be deleted is not found", targetAttr->getName()); ca->found = false; @@ -2657,13 +2616,12 @@ static bool processContextAttributeVector const std::vector& servicePathV, const bool& forcedUpdate, const bool& overrideMetadata, - ApiVersion apiVersion, bool loopDetected, OrionError* oe ) { - std::string entityId = cerP->entity.id; - std::string entityType = cerP->entity.type; + std::string entityId = cerP->entity.entityId.id; + std::string entityType = cerP->entity.entityId.type; std::string entityDetail = cerP->entity.toString(); bool entityModified = false; std::vector attrsWithModifiedValue; @@ -2709,7 +2667,6 @@ static bool processContextAttributeVector action == ActionTypeReplace, forcedUpdate, overrideMetadata, - apiVersion, oe)) { return false; @@ -2732,7 +2689,6 @@ static bool processContextAttributeVector dateExpiration, forcedUpdate, overrideMetadata, - apiVersion, oe)) { return false; @@ -2760,7 +2716,7 @@ static bool processContextAttributeVector { std::string details = std::string("unknown actionType"); - cerP->statusCode.fill(SccInvalidParameter, details); + cerP->error.fill(SccInvalidParameter, details); oe->fill(SccBadRequest, details, ERROR_BAD_REQUEST); // If we reach this point, there's a BUG in the parse layer checks @@ -2814,7 +2770,7 @@ static bool processContextAttributeVector } else if (!addTriggeredSubscriptions(entityId, entityType, attributes, attrsWithModifiedValue, attrsWithModifiedMd, subsToNotify, err, tenant, servicePathV, targetAltType)) { - cerP->statusCode.fill(SccReceiverInternalError, err); + cerP->error.fill(SccReceiverInternalError, err); oe->fill(SccReceiverInternalError, err, "InternalServerError"); return false; } @@ -2828,14 +2784,14 @@ static bool processContextAttributeVector // FIXME P5: this is ugly, our code should be improved to set cerP in a common place for the "happy case" - cerP->statusCode.fill(SccOk); + cerP->error.fill(SccOk); } #endif /* If the status code was not touched (filled with an error), then set it with Ok */ - if (cerP->statusCode.code == SccNone) + if (cerP->error.code == SccNone) { - cerP->statusCode.fill(SccOk); + cerP->error.fill(SccOk); } return entityModified; @@ -2855,7 +2811,6 @@ static bool createEntity std::string* errDetail, std::string tenant, const std::vector& servicePathV, - ApiVersion apiVersion, const std::string& fiwareCorrelator, bool upsert, OrionError* oeP @@ -2873,7 +2828,7 @@ static bool createEntity std::string locAttr; orion::BSONObjBuilder geoJson; - if (!processLocationAtEntityCreation(attrsV, &locAttr, &geoJson, errDetail, apiVersion, oeP)) + if (!processLocationAtEntityCreation(attrsV, &locAttr, &geoJson, errDetail, oeP)) { // oe->fill() already managed by processLocationAtEntityCreation() return false; @@ -2897,7 +2852,7 @@ static bool createEntity std::string attrType; - if (!attrsV[ix]->typeGiven && (apiVersion == V2)) + if (!attrsV[ix]->typeGiven) { if ((attrsV[ix]->compoundValueP == NULL) || (attrsV[ix]->compoundValueP->valueType != orion::ValueTypeVector)) { @@ -2913,7 +2868,7 @@ static bool createEntity attrType = attrsV[ix]->type; } - if (!attrsV[ix]->valueBson(std::string(ENT_ATTRS_VALUE), &bsonAttr, attrType, ngsiv1Autocast && (apiVersion == V1))) + if (!attrsV[ix]->valueBson(std::string(ENT_ATTRS_VALUE), &bsonAttr, attrType)) { // nothing added to bsonAttr, so attribute is not going to be included in the update to the MongoDB // (for example, when $unset:1 is used) @@ -2934,7 +2889,7 @@ static bool createEntity /* Custom metadata */ orion::BSONObjBuilder md; orion::BSONArrayBuilder mdNames; - attrsV[ix]->metadataVector.toBson(&md, &mdNames, apiVersion == V2); + attrsV[ix]->metadataVector.toBson(&md, &mdNames, true); if (mdNames.arrSize() > 0) { bsonAttr.append(ENT_ATTRS_MD, md.obj()); @@ -2947,19 +2902,15 @@ static bool createEntity orion::BSONObjBuilder bsonIdBuilder; - bsonIdBuilder.append(ENT_ENTITY_ID, eP->id); + bsonIdBuilder.append(ENT_ENTITY_ID, eP->entityId.id); - if (eP->type.empty()) + if (eP->entityId.type.empty()) { - if (apiVersion == V2) - { - // NGSIv2 uses default entity type - bsonIdBuilder.append(ENT_ENTITY_TYPE, DEFAULT_ENTITY_TYPE); - } + bsonIdBuilder.append(ENT_ENTITY_TYPE, DEFAULT_ENTITY_TYPE); } else { - bsonIdBuilder.append(ENT_ENTITY_TYPE, eP->type); + bsonIdBuilder.append(ENT_ENTITY_TYPE, eP->entityId.type); } bsonIdBuilder.append(ENT_SERVICE_PATH, servicePathV[0].empty()? SERVICE_PATH_ROOT : servicePathV[0]); @@ -3088,12 +3039,12 @@ static bool removeEntity std::string err; if (!collectionRemove(composeDatabaseName(tenant), COL_ENTITIES, bob.obj(), &err)) { - cerP->statusCode.fill(SccReceiverInternalError, err); + cerP->error.fill(SccReceiverInternalError, err); oe->fill(SccReceiverInternalError, err, "InternalServerError"); return false; } - cerP->statusCode.fill(SccOk); + cerP->error.fill(SccOk); return true; } @@ -3112,7 +3063,7 @@ static void searchContextProviders ContextElementResponse* cerP ) { - ContextRegistrationResponseVector crrV; + std::vector regV; EntityIdVector enV; StringList attrL; std::string err; @@ -3127,11 +3078,11 @@ static void searchContextProviders /* First CPr lookup (in the case some CER is not found): looking in E-A registrations */ if (someContextElementNotFound(*cerP)) { - if (registrationsQuery(enV, attrL, ngsiv2::ForwardUpdate, &crrV, &err, tenant, servicePathV, 0, 0, false)) + if (registrationsQuery(enV, attrL, ngsiv2::ForwardUpdate, ®V, &err, tenant, servicePathV)) { - if (crrV.size() > 0) + if (regV.size() > 0) { - fillContextProviders(cerP, crrV); + fillContextProviders(cerP, regV); } } else @@ -3142,18 +3093,17 @@ static void searchContextProviders // alarmMgr.dbError(err); } - crrV.release(); } /* Second CPr lookup (in the case some element stills not being found): looking in E- registrations */ StringList attrNullList; if (someContextElementNotFound(*cerP)) { - if (registrationsQuery(enV, attrNullList, ngsiv2::ForwardUpdate, &crrV, &err, tenant, servicePathV, 0, 0, false)) + if (registrationsQuery(enV, attrNullList, ngsiv2::ForwardUpdate, ®V, &err, tenant, servicePathV)) { - if (crrV.size() > 0) + if (regV.size() > 0) { - fillContextProviders(cerP, crrV); + fillContextProviders(cerP, regV); } } else @@ -3164,7 +3114,6 @@ static void searchContextProviders // alarmMgr.dbError(err); } - crrV.release(); } } @@ -3184,7 +3133,7 @@ static bool forwardsPending(UpdateContextResponse* upcrsP) { ContextAttribute* aP = cerP->entity.attributeVector[aIx]; - if (!aP->providingApplication.get().empty()) + if (!aP->provider.http.url.empty()) { return true; } @@ -3236,13 +3185,13 @@ static bool calculateOperator(ContextElementResponse* cerP, const std::string& o else if (child0->valueType == orion::ValueTypeVector) { orion::BSONArrayBuilder ba; - compoundValueBson(child0->childV, ba, false, false); + compoundValueBson(child0->childV, ba, false); b->append(valueKey, ba.arr()); } else if (child0->valueType == orion::ValueTypeObject) { orion::BSONObjBuilder bo; - compoundValueBson(child0->childV, bo, false, false); + compoundValueBson(child0->childV, bo, false); b->append(valueKey, bo.obj()); } else if (child0->valueType == orion::ValueTypeNotGiven) @@ -3346,13 +3295,13 @@ static bool calculateSetOperator(ContextElementResponse* cerP, orion::BSONObjBui else if (child->valueType == orion::ValueTypeVector) { orion::BSONArrayBuilder ba; - compoundValueBson(child->childV, ba, false, false); + compoundValueBson(child->childV, ba, false); b->append(valueKey, ba.arr()); } else if (child->valueType == orion::ValueTypeObject) { orion::BSONObjBuilder bo; - compoundValueBson(child->childV, bo, false, false); + compoundValueBson(child->childV, bo, false); b->append(valueKey, bo.obj()); } else if (child->valueType == orion::ValueTypeNotGiven) @@ -3493,7 +3442,6 @@ static unsigned int updateEntity std::string* attributeNotExistingList, const bool& forcedUpdate, const bool& overrideMetadata, - ApiVersion apiVersion, const std::string& fiwareCorrelator, unsigned int notifStartCounter, const std::string& ngsiV2AttrsFormat @@ -3515,12 +3463,13 @@ static unsigned int updateEntity std::string entityType = idField.hasField(ENT_ENTITY_TYPE) ? getStringFieldF(idField, ENT_ENTITY_TYPE) : ""; std::string entitySPath = getStringFieldF(idField, ENT_SERVICE_PATH); - EntityId en(entityId, entityType); + EntityId en(entityId, "", entityType, ""); LM_T(LmtServicePath, ("Found entity '%s' in ServicePath '%s'", entityId.c_str(), entitySPath.c_str())); ContextElementResponse* cerP = new ContextElementResponse(); - cerP->entity.fill(entityId, entityType, "false"); + EntityId enId(entityId, "", entityType, ""); + cerP->entity.fill(enId); /* Build CER used for notifying (if needed) */ StringList emptyAttrL; @@ -3539,7 +3488,7 @@ static unsigned int updateEntity if ((action == ActionTypeDelete) && (eP->attributeVector.size() == 0)) { LM_T(LmtServicePath, ("Removing entity")); - removeEntity(entityId, entityType, cerP, tenant, entitySPath, &(responseP->oe)); + removeEntity(entityId, entityType, cerP, tenant, entitySPath, &(responseP->error)); responseP->contextElementResponseVector.push_back(cerP); /* EntityDelete subscriptions may be triggered */ @@ -3553,8 +3502,8 @@ static unsigned int updateEntity // Note we cannot use eP->type for the type, as it may be blank in the request // (that would break the cases/1494_subscription_alteration_types/sub_alteration_type_entity_delete2.test case) - if (!addTriggeredSubscriptions(notifyCerP->entity.id, - notifyCerP->entity.type, + if (!addTriggeredSubscriptions(notifyCerP->entity.entityId.id, + notifyCerP->entity.entityId.type, attrNames, attrNames, attrNames, @@ -3565,8 +3514,8 @@ static unsigned int updateEntity ngsiv2::SubAltType::EntityDelete)) { releaseTriggeredSubscriptions(&subsToNotify); - cerP->statusCode.fill(SccReceiverInternalError, err); - responseP->oe.fill(SccReceiverInternalError, err, ERROR_INTERNAL_ERROR); + cerP->error.fill(SccReceiverInternalError, err); + responseP->error.fill(SccReceiverInternalError, err, ERROR_INTERNAL_ERROR); responseP->contextElementResponseVector.push_back(cerP); return 0; // Error already in responseP @@ -3696,9 +3645,8 @@ static unsigned int updateEntity servicePathV, forcedUpdate, overrideMetadata, - apiVersion, loopDetected, - &(responseP->oe))) + &(responseP->error))) { // The entity wasn't actually modified, so we don't need to update it and we can continue with the next one @@ -3950,8 +3898,8 @@ static unsigned int updateEntity } if (!success) { - cerP->statusCode.fill(SccReceiverInternalError, err); - responseP->oe.fill(SccReceiverInternalError, err, "InternalServerError"); + cerP->error.fill(SccReceiverInternalError, err); + responseP->error.fill(SccReceiverInternalError, err, "InternalServerError"); responseP->contextElementResponseVector.push_back(cerP); @@ -3965,8 +3913,7 @@ static unsigned int updateEntity /* Send notifications for each one of the subscriptions accumulated by * previous addTriggeredSubscriptions() invocations. Before that, we add - * builtin attributes and metadata (both NGSIv1 and NGSIv2 as this is - * for notifications and NGSIv2 builtins can be used in NGSIv1 notifications) */ + * builtin attributes and metadata */ addBuiltins(notifyCerP, subAltType2string(ngsiv2::SubAltType::EntityChangeBothValueAndMetadata)); unsigned int notifSent = processSubscriptions(subsToNotify, notifyCerP, @@ -3994,11 +3941,11 @@ static unsigned int updateEntity searchContextProviders(tenant, servicePathV, en, eP->attributeVector, cerP); } - // StatusCode may be set already (if so, we keep the existing value) + // OrionError may be set already (if so, we keep the existing value) - if (cerP->statusCode.code == SccNone) + if (cerP->error.code == SccNone) { - cerP->statusCode.fill(SccOk); + cerP->error.fill(SccOk); } responseP->contextElementResponseVector.push_back(cerP); @@ -4016,8 +3963,7 @@ static bool contextElementPreconditionsCheck ( Entity* eP, UpdateContextResponse* responseP, - ActionType action, - ApiVersion apiVersion + ActionType action ) { /* Checking there aren't duplicate attributes */ @@ -4028,54 +3974,21 @@ static bool contextElementPreconditionsCheck { if ((name == eP->attributeVector[jx]->name)) { - ContextAttribute* ca = new ContextAttribute(eP->attributeVector[ix]); alarmMgr.badInput(clientIp, "duplicated attribute name", name); - buildGeneralErrorResponse(eP, ca, responseP, SccInvalidModification, - "duplicated attribute /" + name + "/"); - responseP->oe.fill(SccBadRequest, "duplicated attribute /" + name + "/", ERROR_BAD_REQUEST); + responseP->error.fill(SccBadRequest, "duplicated attribute /" + name + "/", ERROR_BAD_REQUEST); return false; // Error already in responseP } } } - /* Not supporting isPattern = true currently */ - if (isTrue(eP->isPattern)) + /* Not supporting idPattern currently */ + if (!eP->entityId.idPattern.empty()) { - buildGeneralErrorResponse(eP, NULL, responseP, SccNotImplemented); - // No need of filling responseP->oe, this cannot happen in NGSIv2 + // No need of filling responseP->error, this cannot happen in NGSIv2 + // FIXME PR: check this return false; // Error already in responseP } - /* Check that UPDATE or APPEND is not used with empty attributes (i.e. no value, no type, no metadata) */ - /* Only wanted for API version v1 */ - if (((action == ActionTypeUpdate) || - (action == ActionTypeAppend) || - (action == ActionTypeAppendStrict) || - (action == ActionTypeReplace)) && (apiVersion == V1)) - { - // FIXME: Careful, in V2, this check is not wanted ... - - for (unsigned int ix = 0; ix < eP->attributeVector.size(); ++ix) - { - ContextAttribute* aP = eP->attributeVector[ix]; - if (aP->valueType == orion::ValueTypeNotGiven && aP->type.empty() && (aP->metadataVector.size() == 0)) - { - ContextAttribute* ca = new ContextAttribute(aP); - - std::string details = std::string("action: ") + actionTypeString(apiVersion, action) + - " - entity: [" + eP->toString(true) + "]" + - " - offending attribute: " + aP->name + - " - empty attribute not allowed in APPEND or UPDATE"; - - buildGeneralErrorResponse(eP, ca, responseP, SccInvalidModification, details); - responseP->oe.fill(SccBadRequest, details, ERROR_BAD_REQUEST); - - alarmMgr.badInput(clientIp, "empty attribute not allowed in APPEND or UPDATE", aP->name); - return false; // Error already in responseP - } - } - } - return true; } @@ -4120,7 +4033,6 @@ unsigned int processContextElement const bool& forcedUpdate, const bool& overrideMetadata, unsigned int notifStartCounter, - ApiVersion apiVersion, Ngsiv2Flavour ngsiv2Flavour, UpdateCoverage* updateCoverageP ) @@ -4132,7 +4044,7 @@ unsigned int processContextElement } /* Check preconditions */ - if (!contextElementPreconditionsCheck(eP, responseP, action, apiVersion)) + if (!contextElementPreconditionsCheck(eP, responseP, action)) { return 0; // Error already in responseP } @@ -4142,15 +4054,15 @@ unsigned int processContextElement const std::string typeString = "_id." ENT_ENTITY_TYPE; orion::BSONObjBuilder bob; - EntityId en(eP->id, eP->type); - std::string enStr = eP->id; + EntityId en(eP->entityId.id, "", eP->entityId.type, ""); + std::string enStr = eP->entityId.id; - bob.append(idString, eP->id); + bob.append(idString, eP->entityId.id); - if (!eP->type.empty()) + if (!eP->entityId.type.empty()) { - bob.append(typeString, eP->type); - enStr += '/' + eP->type; + bob.append(typeString, eP->entityId.type); + enStr += '/' + eP->entityId.type; } // Service path @@ -4180,48 +4092,38 @@ unsigned int processContextElement orion::BSONObj query = bob.obj(); orion::DBCursor cursor; - // Several checks related to NGSIv2 - if (apiVersion == V2) - { - unsigned long long entitiesNumber; - std::string err; - - if (!orion::collectionCount(composeDatabaseName(tenant), COL_ENTITIES, query, &entitiesNumber, &err)) - { - buildGeneralErrorResponse(eP, NULL, responseP, SccReceiverInternalError, err); - responseP->oe.fill(SccReceiverInternalError, err, "InternalServerError"); - return 0; - } + // Several checks + unsigned long long entitiesNumber; + std::string err; - // This is the case of POST /v2/entities, in order to check that entity doesn't previously exist - if ((entitiesNumber > 0) && (ngsiv2Flavour == NGSIV2_FLAVOUR_ONCREATE)) - { - buildGeneralErrorResponse(eP, NULL, responseP, SccInvalidModification, ERROR_DESC_UNPROCESSABLE_ALREADY_EXISTS); - responseP->oe.fill(SccInvalidModification, ERROR_DESC_UNPROCESSABLE_ALREADY_EXISTS, ERROR_UNPROCESSABLE); - return 0; - } + if (!orion::collectionCount(composeDatabaseName(tenant), COL_ENTITIES, query, &entitiesNumber, &err)) + { + responseP->error.fill(SccReceiverInternalError, err, "InternalServerError"); + return 0; + } - // This is the case of POST /v2/entities/, in order to check that entity previously exist - // both for regular case and when ?options=append is used - if ((entitiesNumber == 0) && (ngsiv2Flavour == NGSIV2_FLAVOUR_ONAPPEND)) - { - buildGeneralErrorResponse(eP, NULL, responseP, SccContextElementNotFound, ERROR_DESC_NOT_FOUND_ENTITY); - responseP->oe.fill(SccContextElementNotFound, ERROR_DESC_NOT_FOUND_ENTITY, ERROR_NOT_FOUND); - return 0; - } + // This is the case of POST /v2/entities, in order to check that entity doesn't previously exist + if ((entitiesNumber > 0) && (ngsiv2Flavour == NGSIV2_FLAVOUR_ONCREATE)) + { + responseP->error.fill(SccInvalidModification, ERROR_DESC_UNPROCESSABLE_ALREADY_EXISTS, ERROR_UNPROCESSABLE); + return 0; + } - // Next block is to avoid that several entities with the same ID get updated at the same time, which is - // not allowed in NGSIv2. Note that multi-update has been allowed in NGSIv1 (maybe without - // thinking too much about it, but NGSIv1 behaviour has to be preserved to keep backward compatibility) - if (entitiesNumber > 1) - { - buildGeneralErrorResponse(eP, NULL, responseP, SccConflict, ERROR_DESC_TOO_MANY_ENTITIES); - responseP->oe.fill(SccConflict, ERROR_DESC_TOO_MANY_ENTITIES, ERROR_TOO_MANY); - return 0; - } + // This is the case of POST /v2/entities/, in order to check that entity previously exist + // both for regular case and when ?options=append is used + if ((entitiesNumber == 0) && (ngsiv2Flavour == NGSIV2_FLAVOUR_ONAPPEND)) + { + responseP->error.fill(SccContextElementNotFound, ERROR_DESC_NOT_FOUND_ENTITY, ERROR_NOT_FOUND); + return 0; } - std::string err; + // Next block is to avoid that several entities with the same ID get updated at the same time, which is + // not allowed in NGSIv2 + if (entitiesNumber > 1) + { + responseP->error.fill(SccConflict, ERROR_DESC_TOO_MANY_ENTITIES, ERROR_TOO_MANY); + return 0; + } TIME_STAT_MONGO_READ_WAIT_START(); orion::DBConnection connection = orion::getMongoConnection(); @@ -4230,8 +4132,7 @@ unsigned int processContextElement { orion::releaseMongoConnection(connection); TIME_STAT_MONGO_READ_WAIT_STOP(); - buildGeneralErrorResponse(eP, NULL, responseP, SccReceiverInternalError, err); - responseP->oe.fill(SccReceiverInternalError, err, "InternalServerError"); + responseP->error.fill(SccReceiverInternalError, err, "InternalServerError"); return 0; } @@ -4302,7 +4203,6 @@ unsigned int processContextElement &attributeNotExistingList, forcedUpdate, overrideMetadata, - apiVersion, fiwareCorrelator, notifStartCounter, ngsiV2AttrsFormat); @@ -4322,7 +4222,8 @@ unsigned int processContextElement /* Creating the common part of the response that doesn't depend on the case */ ContextElementResponse* cerP = new ContextElementResponse(); - cerP->entity.fill(eP->id, eP->type, "false"); + EntityId enId(eP->entityId.id, "", eP->entityId.type, ""); + cerP->entity.fill(enId); /* All the attributes existing in the request are added to the response with 'found' set to false * in the of UPDATE/DELETE and true in the case of APPEND @@ -4342,7 +4243,7 @@ unsigned int processContextElement { /* In the case of UPDATE or REPLACE we look for context providers */ searchContextProviders(tenant, servicePathV, en, eP->attributeVector, cerP); - cerP->statusCode.fill(SccOk); + cerP->error.fill(SccOk); responseP->contextElementResponseVector.push_back(cerP); // @@ -4350,29 +4251,22 @@ unsigned int processContextElement // if (forwardsPending(responseP) == false) { - cerP->statusCode.fill(SccContextElementNotFound); + cerP->error.fill(SccContextElementNotFound); - if (apiVersion == V1) - { - responseP->oe.fill(SccContextElementNotFound, ERROR_DESC_NOT_FOUND_CONTEXT_ELEMENT, ERROR_NOT_FOUND); - } - else + std::string details = ERROR_DESC_DO_NOT_EXIT + enStr + " - [entity itself]"; + responseP->error.fillOrAppend(SccContextElementNotFound, details, ", " + enStr + " [entity itself]", ERROR_NOT_FOUND); + if (updateCoverageP != NULL) { - std::string details = ERROR_DESC_DO_NOT_EXIT + enStr + " - [entity itself]"; - responseP->oe.fillOrAppend(SccContextElementNotFound, details, ", " + enStr + " [entity itself]", ERROR_NOT_FOUND); - if (updateCoverageP != NULL) - { - *updateCoverageP = UC_ENTITY_NOT_FOUND; - } + *updateCoverageP = UC_ENTITY_NOT_FOUND; } } } else if (action == ActionTypeDelete) { - cerP->statusCode.fill(SccContextElementNotFound); + cerP->error.fill(SccContextElementNotFound); std::string details = ERROR_DESC_DO_NOT_EXIT + enStr + " - [entity itself]"; - responseP->oe.fillOrAppend(SccContextElementNotFound, details, ", " + enStr + " [entity itself]", ERROR_NOT_FOUND); + responseP->error.fillOrAppend(SccContextElementNotFound, details, ", " + enStr + " [entity itself]", ERROR_NOT_FOUND); responseP->contextElementResponseVector.push_back(cerP); if (updateCoverageP != NULL) { @@ -4392,17 +4286,16 @@ unsigned int processContextElement &errDetail, tenant, servicePathV, - apiVersion, fiwareCorrelator, ngsiv2Flavour == NGSIV2_NO_FLAVOUR, - &(responseP->oe))) + &(responseP->error))) { - cerP->statusCode.fill(SccInvalidParameter, errDetail); - // In this case, responseP->oe is not filled, as createEntity() deals internally with that + cerP->error.fill(SccInvalidParameter, errDetail); + // In this case, responseP->error is not filled, as createEntity() deals internally with that } else { - cerP->statusCode.fill(SccOk); + cerP->error.fill(SccOk); /* Successful creation: send potential notifications */ std::map subsToNotify; @@ -4413,8 +4306,8 @@ unsigned int processContextElement attrNames.push_back(eP->attributeVector[ix]->name); } - if (!addTriggeredSubscriptions(eP->id, - eP->type, + if (!addTriggeredSubscriptions(eP->entityId.id, + eP->entityId.type, attrNames, attrNames, attrNames, @@ -4425,8 +4318,8 @@ unsigned int processContextElement ngsiv2::SubAltType::EntityCreate)) { releaseTriggeredSubscriptions(&subsToNotify); - cerP->statusCode.fill(SccReceiverInternalError, err); - responseP->oe.fill(SccReceiverInternalError, err, ERROR_INTERNAL_ERROR); + cerP->error.fill(SccReceiverInternalError, err); + responseP->error.fill(SccReceiverInternalError, err, ERROR_INTERNAL_ERROR); responseP->contextElementResponseVector.push_back(cerP); return 0; // Error already in responseP @@ -4436,7 +4329,7 @@ unsigned int processContextElement // Build CER used for notifying (if needed). Service Path vector shouldn't have more than // one item, so it should be safe to get item 0 // - ContextElementResponse* notifyCerP = new ContextElementResponse(eP, apiVersion == V2); + ContextElementResponse* notifyCerP = new ContextElementResponse(eP, true); notifyCerP->applyUpdateOperators(); // Set action type @@ -4456,8 +4349,7 @@ unsigned int processContextElement notifyCerP->entity.servicePath = servicePathV.size() > 0? servicePathV[0] : ""; /* Send notifications for each one of the subscriptions accumulated by * previous addTriggeredSubscriptions() invocations. Before that, we add - * builtin attributes and metadata (both NGSIv1 and NGSIv2 as this is - * for notifications and NGSIv2 builtins can be used in NGSIv1 notifications) */ + * builtin attributes and metadata */ addBuiltins(notifyCerP, subAltType2string(ngsiv2::SubAltType::EntityCreate)); notifSent = processSubscriptions(subsToNotify, notifyCerP, @@ -4478,15 +4370,13 @@ unsigned int processContextElement if ((attributeAlreadyExistsNumber > 0) && (action == ActionTypeAppendStrict)) { std::string details = ERROR_DESC_UNPROCESSABLE_ATTR_ALREADY_EXISTS + enStr + " - " + attributeAlreadyExistsList; - buildGeneralErrorResponse(eP, NULL, responseP, SccBadRequest, details); - responseP->oe.fillOrAppend(SccInvalidModification, details, ", " + enStr + " - " + attributeAlreadyExistsList, ERROR_UNPROCESSABLE); + responseP->error.fillOrAppend(SccInvalidModification, details, ", " + enStr + " - " + attributeAlreadyExistsList, ERROR_UNPROCESSABLE); } - if ((apiVersion == V2) && (attributeNotExistingNumber > 0) && ((action == ActionTypeUpdate) || (action == ActionTypeDelete))) + if ((attributeNotExistingNumber > 0) && ((action == ActionTypeUpdate) || (action == ActionTypeDelete))) { std::string details = ERROR_DESC_DO_NOT_EXIT + enStr + " - " + attributeNotExistingList; - buildGeneralErrorResponse(eP, NULL, responseP, SccBadRequest, details); - responseP->oe.fillOrAppend(SccInvalidModification, details, ", " + enStr + " - " + attributeNotExistingList, ERROR_UNPROCESSABLE); + responseP->error.fillOrAppend(SccInvalidModification, details, ", " + enStr + " - " + attributeNotExistingList, ERROR_UNPROCESSABLE); } // The following check makes sense only when there are at least one attribute in the request diff --git a/src/lib/mongoBackend/MongoCommonUpdate.h b/src/lib/mongoBackend/MongoCommonUpdate.h index a3d4266dcc..05d0f24ea8 100644 --- a/src/lib/mongoBackend/MongoCommonUpdate.h +++ b/src/lib/mongoBackend/MongoCommonUpdate.h @@ -67,7 +67,6 @@ extern unsigned int processContextElement const bool& forcedUpdate, const bool& overrideMetadata, unsigned int notifStartCounter, - ApiVersion apiVersion = V1, Ngsiv2Flavour ngsiV2Flavour = NGSIV2_NO_FLAVOUR, UpdateCoverage* updateCoverageP = NULL ); diff --git a/src/lib/mongoBackend/MongoGlobal.cpp b/src/lib/mongoBackend/MongoGlobal.cpp index 82abe1b596..a663de0af9 100644 --- a/src/lib/mongoBackend/MongoGlobal.cpp +++ b/src/lib/mongoBackend/MongoGlobal.cpp @@ -49,8 +49,6 @@ #include "ngsi/EntityIdVector.h" #include "ngsi/StringList.h" #include "ngsi/ContextElementResponseVector.h" -#include "ngsi/Duration.h" -#include "ngsi/Restriction.h" #include "ngsiNotify/Notifier.h" #include "rest/StringFilter.h" #include "apiTypesV2/Subscription.h" @@ -73,7 +71,6 @@ * USING */ using ngsiv2::HttpInfo; -using ngsiv2::EntID; @@ -403,18 +400,18 @@ void ensureDateExpirationIndex(const std::string& tenant) * commutative: en1 is interpreted as the entity to match *in* en2 (i.e. * it is assumed that the pattern is in en2) */ -bool matchEntity(const EntityId* en1, const EntityId* en2) +bool matchEntity(const EntityId* en1, const EntityId& en2) { bool idMatch; - if (isTrue(en2->isPattern)) + if (!en2.idPattern.empty()) { regex_t regex; idMatch = false; - if (!regComp(®ex, en2->id.c_str(), REG_EXTENDED)) + if (!regComp(®ex, en2.idPattern.c_str(), REG_EXTENDED)) { - std::string details = std::string("error compiling regex for id: '") + en2->id + "'"; + std::string details = std::string("error compiling regex for id: '") + en2.id + "'"; alarmMgr.badInput(clientIp, details); } else @@ -424,40 +421,13 @@ bool matchEntity(const EntityId* en1, const EntityId* en2) regfree(®ex); // If regcomp fails it frees up itself (see glibc sources for details) } } - else /* isPattern == false */ + else /* is not a pattern */ { - idMatch = (en2->id == en1->id); + idMatch = (en2.id == en1->id); } // Note that type.empty() is like a * wildcard for type - return idMatch && (en1->type.empty() || en2->type.empty() || en2->type == en1->type); -} - - - -/* **************************************************************************** -* -* includedEntity - -*/ -bool includedEntity(EntityId en, const EntityIdVector& entityIdV) -{ - for (unsigned int ix = 0; ix < entityIdV.size(); ++ix) - { - if (en.isPatternIsTrue() && en.id == ".*") - { - // By the moment the only supported pattern is .*. In this case matching is - // based exclusively in type - if (en.type == entityIdV[ix]->type) - { - return true; - } - } - else if (matchEntity(&en, entityIdV[ix])) - { - return true; - } - } - return false; + return idMatch && (en1->type.empty() || en2.type.empty() || en2.type == en1->type); } @@ -499,12 +469,12 @@ static void fillQueryEntity(orion::BSONObjBuilder* bobP, const EntityId* enP) const std::string idString = "_id." ENT_ENTITY_ID; const std::string typeString = "_id." ENT_ENTITY_TYPE; - if (enP->isPattern == "true") + if (!enP->idPattern.empty()) { // In the case of "universal pattern" we can avoid adding anything (simpler query) - if (enP->id != ".*") + if (enP->idPattern != ".*") { - bobP->appendRegex(idString, enP->id); + bobP->appendRegex(idString, enP->idPattern); } } else @@ -512,17 +482,18 @@ static void fillQueryEntity(orion::BSONObjBuilder* bobP, const EntityId* enP) bobP->append(idString, enP->id); } - if (!enP->type.empty()) + + if (!enP->typePattern.empty()) { - if (enP->isTypePattern) + // In the case of "universal pattern" we can avoid adding anything (simpler query) + if (enP->typePattern != ".*") { - // In the case of "universal pattern" we can avoid adding anything (simpler query) - if (enP->type != ".*") - { - bobP->appendRegex(typeString, enP->type); - } + bobP->appendRegex(typeString, enP->typePattern); } - else + } + else + { + if (!enP->type.empty()) { bobP->append(typeString, enP->type); } @@ -639,137 +610,15 @@ orion::BSONObj fillQueryServicePath(const std::string& spKey, const std::vector< -/* ***************************************************************************** -* -* processAreaScope - -* -* Returns true if 'areaQueryP' was filled, false otherwise -*/ -static bool processAreaScope(const Scope* scoP, orion::BSONObjBuilder* queryP) -{ - // FIXME #3774: previously this part was based in streamming instead of append() - - std::string locCoords = ENT_LOCATION "." ENT_LOCATION_COORDS; - - if (!mongoLocationCapable()) - { - std::string details = std::string("location scope was found but your MongoDB version doesn't support it. ") + - "Please upgrade MongoDB server to 2.4 or newer)"; - - alarmMgr.badInput(clientIp, details); - return false; - } - - bool inverted = false; - orion::BSONObj geoWithin; - - if (scoP->areaType == orion::CircleType) - { - double radians = scoP->circle.radius() / EARTH_RADIUS_METERS; - - orion::BSONObjBuilder bobGeoWithin; - orion::BSONArrayBuilder baOuter; - orion::BSONArrayBuilder baInner; - - baInner.append(scoP->circle.center.longitude()); - baInner.append(scoP->circle.center.latitude()); - - baOuter.append(baInner.arr()); - baOuter.append(radians); - - bobGeoWithin.append("$centerSphere", baOuter.arr()); - - geoWithin = bobGeoWithin.obj(); - - inverted = scoP->circle.inverted(); - } - else if (scoP->areaType == orion::PolygonType) - { - orion::BSONArrayBuilder vertex; - double lat0 = 0; - double lon0 = 0; - - for (unsigned int jx = 0; jx < scoP->polygon.vertexList.size() ; ++jx) - { - double lat = scoP->polygon.vertexList[jx]->latitude(); - double lon = scoP->polygon.vertexList[jx]->longitude(); - - if (jx == 0) - { - lat0 = lat; - lon0 = lon; - } - - orion::BSONArrayBuilder baCoords; - baCoords.append(lon); - baCoords.append(lat); - - vertex.append(baCoords.arr()); - } - - /* MongoDB query API needs to "close" the polygon with the same point that the initial point */ - orion::BSONArrayBuilder baCoords0; - baCoords0.append(lon0); - baCoords0.append(lat0); - vertex.append(baCoords0.arr()); - - /* Note that MongoDB query API uses an ugly "double array" structure for coordinates */ - orion::BSONObjBuilder bobGeoWithin; - orion::BSONObjBuilder bobGeometry; - orion::BSONArrayBuilder baVertex; - - baVertex.append(vertex.arr()); - - bobGeometry.append("type", "Polygon"); - bobGeometry.append("coordinates", baVertex.arr()); - - bobGeoWithin.append("$geometry", bobGeometry.obj()); - geoWithin = bobGeoWithin.obj(); - - inverted = scoP->polygon.inverted(); - } - else - { - alarmMgr.badInput(clientIp, "unknown area type"); - return false; - } - - if (inverted) - { - /* The "$exist: true" was added to make this work with MongoDB 2.6. Surprisingly, MongoDB 2.4 - * doesn't need it. See http://stackoverflow.com/questions/29388981/different-semantics-in-not-geowithin-with-polygon-geometries-between-mongodb-2 */ - orion::BSONObjBuilder bobAreaQuery; - orion::BSONObjBuilder bobGeoWithin; - - bobGeoWithin.append("$geoWithin", geoWithin); - - bobAreaQuery.append("$exists", true); - bobAreaQuery.append("$not", bobGeoWithin.obj()); - - queryP->append(locCoords, bobAreaQuery.obj()); - } - else - { - orion::BSONObjBuilder bobAreaQuery; - bobAreaQuery.append("$geoWithin", geoWithin); - queryP->append(locCoords, bobAreaQuery.obj()); - } - - return true; -} - - - /* ***************************************************************************** * * addFilterScope - */ -static void addFilterScope(ApiVersion apiVersion, const Scope* scoP, std::vector* filtersP) +static void addFilterScope( const Scope* scoP, std::vector* filtersP) { - if ((apiVersion == V2) && (scoP->type == SCOPE_FILTER_EXISTENCE) && (scoP->value == SCOPE_VALUE_ENTITY_TYPE)) + if ((scoP->type == SCOPE_FILTER_EXISTENCE) && (scoP->value == SCOPE_VALUE_ENTITY_TYPE)) { - // Early return to avoid _id.type: {$exits: true} in NGSIv2 case. Entity type existence filter only - // makes sense in NGSIv1 (and may be removed soon as NGSIv1 is deprecated functionality) + // Early return to avoid _id.type: {$exits: true} return; } @@ -1375,17 +1224,16 @@ bool entitiesQuery ( const EntityIdVector& enV, const StringList& attrL, - const Restriction& res, + const ScopeVector& spV, ContextElementResponseVector* cerV, - std::string* err, + OrionError* oeP, const std::string& tenant, const std::vector& servicePath, int offset, int limit, bool* limitReached, long long* countP, - const std::string& sortOrderList, - ApiVersion apiVersion + const std::string& sortOrderList ) { /* Query structure is as follows @@ -1399,6 +1247,8 @@ bool entitiesQuery * */ + std::string err; + orion::BSONObjBuilder finalQuery; orion::BSONObjBuilder finalCountQuery; orion::BSONArrayBuilder orEnt; @@ -1474,18 +1324,15 @@ bool entitiesQuery std::vector filters; unsigned int geoScopes = 0; - for (unsigned int ix = 0; ix < res.scopeVector.size(); ++ix) + for (unsigned int ix = 0; ix < spV.size(); ++ix) { - const Scope* scopeP = res.scopeVector[ix]; + const Scope* scopeP = spV[ix]; if (scopeP->type.find(SCOPE_FILTER) == 0) { - // FIXME P5: NGSIv1 filter, probably to be removed in the future - addFilterScope(apiVersion, scopeP, &filters); + addFilterScope(scopeP, &filters); } - else if (scopeP->type == FIWARE_LOCATION || - scopeP->type == FIWARE_LOCATION_DEPRECATED || - scopeP->type == FIWARE_LOCATION_V2) + else if (scopeP->type == FIWARE_LOCATION_V2) { geoScopes++; if (geoScopes > 1) @@ -1494,14 +1341,7 @@ bool entitiesQuery } else { - if (scopeP->type == FIWARE_LOCATION_V2) - { - processAreaScopeV2(scopeP, &finalQuery, &finalCountQuery); - } - else // FIWARE Location NGSIv1 (legacy) - { - processAreaScope(scopeP, &finalQuery); - } + processAreaScopeV2(scopeP, &finalQuery, &finalCountQuery); } } else if (scopeP->type == SCOPE_TYPE_SIMPLE_QUERY) @@ -1592,7 +1432,7 @@ bool entitiesQuery TIME_STAT_MONGO_READ_WAIT_START(); orion::DBConnection connection = orion::getMongoConnection(); - if (!orion::collectionRangedQuery(connection, composeDatabaseName(tenant), COL_ENTITIES, query, countQuery, sort, limit, offset, &cursor, countP, err)) + if (!orion::collectionRangedQuery(connection, composeDatabaseName(tenant), COL_ENTITIES, query, countQuery, sort, limit, offset, &cursor, countP, &err)) { orion::releaseMongoConnection(connection); TIME_STAT_MONGO_READ_WAIT_STOP(); @@ -1617,11 +1457,8 @@ bool entitiesQuery LM_T(LmtMongo, ("retrieved document [%d]: '%s'", docs, r.toString().c_str())); ContextElementResponse* cer = new ContextElementResponse(r, attrL); - // Add builtin attributes and metadata (only in NGSIv2) - if (apiVersion == V2) - { - addBuiltins(cer, ""); - } + // Add builtin attributes and metadata + addBuiltins(cer, ""); /* All the attributes existing in the request but not found in the response are added with 'found' set to false */ for (unsigned int ix = 0; ix < attrL.size(); ++ix) @@ -1651,7 +1488,6 @@ bool entitiesQuery } } - cer->statusCode.fill(SccOk); cerV->push_back(cer); } @@ -1663,34 +1499,15 @@ bool entitiesQuery if (errType == ON_NEXT_MANAGED_ERROR) { - ContextElementResponse* cer = new ContextElementResponse(); - alarmMgr.dbError(nextErr); - // - // It would be nice to fill in the entity but it is difficult to do this. - // - // Solution: - // If the incoming entity-vector has only *one* entity, I simply fill it in with enV[0] and - // if more than one entity is in the vector, an empty entity is returned. - // - if (enV.size() == 1) - { - cer->entity.fill(enV[0]->id, enV[0]->type, enV[0]->isPattern); - } - else - { - cer->entity.fill("", "", ""); - } - - cer->statusCode.fill(SccReceiverInternalError, nextErr); - cerV->push_back(cer); - return true; + oeP->fill(SccReceiverInternalError, nextErr); + return false; } else if (errType == ON_NEXT_UNMANAGED_ERROR) { - *err = nextErr; LM_E(("Runtime Error (exception in next(): %s - query: %s)", nextErr.c_str(), query.toString().c_str())); + oeP->fill(SccReceiverInternalError, nextErr); return false; } @@ -1712,13 +1529,13 @@ bool entitiesQuery * used before pruning in the CPr calculation logic */ for (unsigned int ix = 0; ix < enV.size(); ++ix) { - if (enV[ix]->isPattern != "true") + if (enV[ix]->idPattern.empty()) { bool needToAdd = true; for (unsigned int jx = 0; jx < cerV->size(); ++jx) { - if (((*cerV)[jx]->entity.id == enV[ix]->id) && ((*cerV)[jx]->entity.type == enV[ix]->type)) + if (((*cerV)[jx]->entity.entityId.id == enV[ix]->id) && ((*cerV)[jx]->entity.entityId.type == enV[ix]->type)) { needToAdd = false; break; /* jx */ @@ -1729,9 +1546,7 @@ bool entitiesQuery { ContextElementResponse* cerP = new ContextElementResponse(); - cerP->entity.id = enV[ix]->id; - cerP->entity.type = enV[ix]->type; - cerP->entity.isPattern = "false"; + cerP->entity.entityId = enV[ix]; // // This entity has to be pruned if after CPr searching no attribute is "added" to it. @@ -1747,7 +1562,7 @@ bool entitiesQuery cerP->entity.attributeVector.push_back(caP); } - cerP->statusCode.fill(SccOk); + cerP->error.fill(SccOk); cerV->push_back(cerP); } @@ -1765,7 +1580,7 @@ bool entitiesQuery * * Remove attributes in the vector with 'found' value is 'false' * -* In the case of NGSIv2 we filter attributes with CPr not included in a list of attributes +* We filter attributes with CPr not included in a list of attributes * passed as reference (and that comes from the original NGSIv2 query). Otherwise, * over-querying for attributes may occur and this could break some CPr usage cases (in particular * the ones with IOTAs, which may report error in the case of being asked for an attribute @@ -1777,7 +1592,6 @@ bool entitiesQuery */ void pruneContextElements ( - ApiVersion apiVersion, const StringList& attrsV, const ContextElementResponseVector& oldCerV, ContextElementResponseVector* newCerVP @@ -1788,16 +1602,15 @@ void pruneContextElements ContextElementResponse* cerP = oldCerV[ix]; ContextElementResponse* newCerP = new ContextElementResponse(); - newCerP->entity.fill(cerP->entity.id, - cerP->entity.type, - cerP->entity.isPattern, + newCerP->entity.fill(cerP->entity.entityId, cerP->entity.servicePath, cerP->entity.creDate, cerP->entity.modDate); // FIXME P10: not sure if this is the right way to do it, maybe we need a fill() method for this - newCerP->entity.providingApplicationList = cerP->entity.providingApplicationList; - newCerP->statusCode.fill(&cerP->statusCode); + newCerP->entity.providerList = cerP->entity.providerList; + newCerP->entity.providerRegIdList = cerP->entity.providerRegIdList; + newCerP->error.fill(&cerP->error); bool pruneEntity = cerP->prune; @@ -1806,10 +1619,9 @@ void pruneContextElements ContextAttribute* caP = cerP->entity.attributeVector[jx]; // To be included, it need to be found and one of the following: - // - It is V1 - // - (Not being V1) The attributes filter list is empty - // - (Not being V1 and not empty attributes filter) The attribute is included in the filter list (taking into account wildcard) - if ((caP->found) && ((apiVersion == V1) || (attrsV.size() == 0) || (attrsV.lookup(caP->name, ALL_ATTRS)))) + // - The attributes filter list is empty + // - (Not empty attributes filter) The attribute is included in the filter list (taking into account wildcard) + if ((caP->found) && ((attrsV.size() == 0) || (attrsV.lookup(caP->name, ALL_ATTRS)))) { ContextAttribute* newCaP = new ContextAttribute(caP); newCerP->entity.attributeVector.push_back(newCaP); @@ -1819,8 +1631,8 @@ void pruneContextElements /* If after pruning the entity has no attribute and no CPr information, then it is not included * in the output vector, except if "prune" is set to false */ if (pruneEntity && - (newCerP->entity.attributeVector.size() == 0) && - (newCerP->entity.providingApplicationList.size() == 0)) + (newCerP->entity.attributeVector.size() == 0) && + (newCerP->entity.providerList.size() == 0)) { newCerP->release(); delete newCerP; @@ -1834,137 +1646,19 @@ void pruneContextElements -/* *************************************************************************** -* -* processEntity - -*/ -static void processEntity(ContextRegistrationResponse* crr, const EntityIdVector& enV, orion::BSONObj entity) -{ - EntityId en; - - en.id = getStringFieldF(entity, REG_ENTITY_ID); - en.type = entity.hasField(REG_ENTITY_TYPE)? getStringFieldF(entity, REG_ENTITY_TYPE) : ""; - en.isPattern = entity.hasField(REG_ENTITY_ISPATTERN)? getStringFieldF(entity, REG_ENTITY_ISPATTERN) : "false"; - - if (includedEntity(en, enV)) - { - EntityId* enP = new EntityId(en.id, en.type, en.isPattern); - - crr->contextRegistration.entityIdVector.push_back(enP); - } -} - - - -/* *************************************************************************** -* -* processAttribute - -*/ -static void processAttribute(ContextRegistrationResponse* crr, const StringList& attrL, const orion::BSONObj& attribute) -{ - ContextRegistrationAttribute attr( - getStringFieldF(attribute, REG_ATTRS_NAME), - getStringFieldF(attribute, REG_ATTRS_TYPE)); - - if (includedAttribute(attr.name, attrL)) - { - ContextRegistrationAttribute* attrP = new ContextRegistrationAttribute(attr.name, attr.type); - crr->contextRegistration.contextRegistrationAttributeVector.push_back(attrP); - } -} - - - -/* *************************************************************************** -* -* processContextRegistrationElement - -*/ -static void processContextRegistrationElement -( - orion::BSONObj cr, - const EntityIdVector& enV, - const StringList& attrL, - ContextRegistrationResponseVector* crrV, - MimeType mimeType, - ProviderFormat providerFormat, - const std::string& regId -) -{ - ContextRegistrationResponse crr; - - crr.contextRegistration.providingApplication.set(getStringFieldF(cr, REG_PROVIDING_APPLICATION)); - crr.contextRegistration.providingApplication.setProviderFormat(providerFormat); - - std::vector queryEntityV = getFieldF(cr, REG_ENTITIES).Array(); - - for (unsigned int ix = 0; ix < queryEntityV.size(); ++ix) - { - processEntity(&crr, enV, queryEntityV[ix].embeddedObject()); - } - - /* Note that attributes can be included only if at least one entity has been found */ - if (crr.contextRegistration.entityIdVector.size() > 0) - { - if (cr.hasField(REG_ATTRS)) /* To prevent registration in the E- style */ - { - std::vector queryAttrV = getFieldF(cr, REG_ATTRS).Array(); - - for (unsigned int ix = 0; ix < queryAttrV.size(); ++ix) - { - processAttribute(&crr, attrL, queryAttrV[ix].embeddedObject()); - } - } - } - - // FIXME: we don't take metadata into account at the moment - // crr.contextRegistration.registrationMetadataV = .. - - /* Note that the context registration element is only included in one of the following cases: - * - The number of entities and attributes included are both greater than 0 - * - The number of entities is greater than 0, the number of attributes is 0 but the discover - * doesn't use attributes in the request - */ - if (crr.contextRegistration.entityIdVector.size() == 0) - { - return; - } - - if (crr.contextRegistration.contextRegistrationAttributeVector.size() > 0 || - (crr.contextRegistration.contextRegistrationAttributeVector.size() == 0 && attrL.size() == 0)) - { - ContextRegistrationResponse* crrP = new ContextRegistrationResponse(); - - crrP->contextRegistration = crr.contextRegistration; - crrP->providerFormat = providerFormat; - crrP->regId = regId; - - crrV->push_back(crrP); - } -} - - - /* **************************************************************************** * * registrationsQuery - -* -* This method is used by discoverContextAvailabililty and subscribeContextAvailability. It takes -* a vector with entities and a vector with attributes as input and returns the corresponding -* ContextRegistrationResponseVector or error. */ bool registrationsQuery ( const EntityIdVector& enV, const StringList& attrL, const ngsiv2::ForwardingMode forwardingMode, - ContextRegistrationResponseVector* crrV, + std::vector* regV, std::string* err, const std::string& tenant, - const std::vector& servicePathV, - int offset, - int limit, - bool details, - long long* countP + const std::vector& servicePathV ) { // query structure: @@ -1992,8 +1686,6 @@ bool registrationsQuery // Note that by construction the $or array always has at least two elements (the two ones corresponding to the // universal pattern) so we cannot avoid to use this operator. // - // FIXME P5: the 'contextRegistration' token (19 chars) repeats in the query BSON. It would be better use 'cr' (2 chars) - // but this would need a data model migration in DB /* Build query based on arguments */ std::string crEntitiesId = REG_CONTEXT_REGISTRATION "." REG_ENTITIES "." REG_ENTITY_ID; @@ -2008,11 +1700,11 @@ bool registrationsQuery const EntityId* en = enV[ix]; orion::BSONObjBuilder b; - if (isTrue(en->isPattern)) + if (!en->idPattern.empty()) { - b.appendRegex(crEntitiesId, en->id); + b.appendRegex(crEntitiesId, en->idPattern); } - else /* isPattern = false */ + else /* not a pattern */ { b.append(crEntitiesId, en->id); } @@ -2113,15 +1805,13 @@ bool registrationsQuery orion::BSONObj query = queryBuilder.obj(); - LM_T(LmtPagination, ("Offset: %d, Limit: %d, Details: %s", offset, limit, (details == true)? "true" : "false")); - TIME_STAT_MONGO_READ_WAIT_START(); orion::DBConnection connection = orion::getMongoConnection(); orion::BSONObjBuilder bobSort; bobSort.append("_id", 1); - if (!orion::collectionRangedQuery(connection, composeDatabaseName(tenant), COL_REGISTRATIONS, query, query, bobSort.obj(), limit, offset, &cursor, countP, err)) + if (!orion::collectionRangedQuery(connection, composeDatabaseName(tenant), COL_REGISTRATIONS, query, query, bobSort.obj(), 0, 0, &cursor, NULL, err)) { orion::releaseMongoConnection(connection); TIME_STAT_MONGO_READ_WAIT_STOP(); @@ -2139,15 +1829,15 @@ bool registrationsQuery LM_T(LmtMongo, ("retrieved document [%d]: '%s'", docs, r.toString().c_str())); - MimeType mimeType = JSON; - std::vector queryContextRegistrationV = getFieldF(r, REG_CONTEXT_REGISTRATION).Array(); - std::string format = getStringFieldF(r, REG_FORMAT); - ProviderFormat providerFormat = (format.empty())? PfJson : (format == "JSON")? PfJson : PfV2; - std::string regId = getFieldF(r, "_id").OID(); - - for (unsigned int ix = 0 ; ix < queryContextRegistrationV.size(); ++ix) + ngsiv2::Registration reg; + if (reg.fromBson(r)) { - processContextRegistrationElement(queryContextRegistrationV[ix].embeddedObject(), enV, attrL, crrV, mimeType, providerFormat, regId); + regV->push_back(reg); + } + else + { + // FIXME #4611: this else branch will be no longer needed after fixing the issue + LM_E(("Runtime Error (registrations with more than one CR are considered runtime errors since Orion 4.1.0, please fix reg %s at DB)", reg.id.c_str())); } /* FIXME: note that given the response doesn't distinguish from which registration ID the @@ -2164,39 +1854,6 @@ bool registrationsQuery -/* **************************************************************************** -* -* isCondValueInContextElementResponse - -*/ -bool isCondValueInContextElementResponse(ConditionValueList* condValues, ContextElementResponseVector* cerV) -{ - /* Empty conValue means that any attribute matches (aka ONANYCHANGE) */ - if (condValues->size() == 0) - { - return true; - } - - for (unsigned int cvlx = 0; cvlx < condValues->size(); ++cvlx) - { - for (unsigned int aclx = 0; aclx < cerV->size(); ++aclx) - { - ContextAttributeVector caV = (*cerV)[aclx]->entity.attributeVector; - - for (unsigned int kx = 0; kx < caV.size(); ++kx) - { - if (caV[kx]->name == (*condValues)[cvlx]) - { - return true; - } - } - } - } - - return false; -} - - - /* **************************************************************************** * * condValueAttrMatch - @@ -2234,32 +1891,6 @@ bool condValueAttrMatch(const orion::BSONObj& sub, const std::vector subEnts = getFieldF(sub, CSUB_ENTITIES).Array(); - - for (unsigned int ix = 0; ix < subEnts.size() ; ++ix) - { - orion::BSONObj subEnt = subEnts[ix].embeddedObject(); - EntityId* en = new EntityId(getStringFieldF(subEnt, CSUB_ENTITY_ID), - subEnt.hasField(CSUB_ENTITY_TYPE) ? getStringFieldF(subEnt, CSUB_ENTITY_TYPE) : "", - getStringFieldF(subEnt, CSUB_ENTITY_ISPATTERN)); - enV.push_back(en); - } - - return enV; -} - - - /* **************************************************************************** * * getCommonAttributes - @@ -2489,11 +2120,11 @@ void releaseTriggeredSubscriptions(std::map * This functions is very similar the one with the same name in mongoQueryContext.cpp * but acting on a single CER instead that on a complete vector of them. * -* Looks in the CER passed as argument, searching for a suitable CPr in the CRR +* Looks in the CER passed as argument, searching for a suitable CPr in the Registrations * vector passed as argument. If a suitable CPr is found, it is set in the CER (and the 'found' field * is changed to true) */ -void fillContextProviders(ContextElementResponse* cer, const ContextRegistrationResponseVector& crrV) +void fillContextProviders(ContextElementResponse* cer, const std::vector& regV) { for (unsigned int ix = 0; ix < cer->entity.attributeVector.size(); ++ix) { @@ -2504,29 +2135,26 @@ void fillContextProviders(ContextElementResponse* cer, const ContextRegistration continue; } - /* Search for some CPr in crrV */ - std::string perEntPa; - std::string perAttrPa; - MimeType perEntPaMimeType = NOMIMETYPE; - MimeType perAttrPaMimeType = NOMIMETYPE; - ProviderFormat providerFormat; + /* Search for some CPr in Registrations vector */ + std::string perEntProvider; + std::string perAttrProvider; + bool legacyProviderFormat; std::string regId; cprLookupByAttribute(cer->entity, ca->name, - crrV, - &perEntPa, - &perEntPaMimeType, - &perAttrPa, - &perAttrPaMimeType, - &providerFormat, + regV, + &perEntProvider, + &perAttrProvider, + &legacyProviderFormat, ®Id); - /* Looking results after crrV processing */ - ca->providingApplication.set(perAttrPa.empty() ? perEntPa : perAttrPa); - ca->providingApplication.setProviderFormat(providerFormat); - ca->providingApplication.setRegId(regId); - ca->found = (!ca->providingApplication.get().empty()); + /* Looking results after Registrations vector processing */ + ca->provider.http.url = perAttrProvider.empty() ? perEntProvider : perAttrProvider; + ca->provider.legacyForwardingMode = legacyProviderFormat; + ca->providerRegId = regId; + + ca->found = (!ca->provider.http.url.empty()); } } @@ -2568,64 +2196,62 @@ void cprLookupByAttribute ( const Entity& en, const std::string& attrName, - const ContextRegistrationResponseVector& crrV, - std::string* perEntPa, - MimeType* perEntPaMimeType, - std::string* perAttrPa, - MimeType* perAttrPaMimeType, - ProviderFormat* providerFormatP, + const std::vector& regV, + std::string* perEntProviderP, + std::string* perAttrProviderP, + bool* legacyPproviderFormatP, std::string* regId ) { - *perEntPa = ""; - *perAttrPa = ""; + *perEntProviderP = ""; + *perAttrProviderP = ""; *regId = ""; - for (unsigned int crrIx = 0; crrIx < crrV.size(); ++crrIx) + for (unsigned int regIx = 0; regIx < regV.size(); ++regIx) { - ContextRegistrationResponse* crr = crrV[crrIx]; + ngsiv2::Registration reg = regV[regIx]; - /* Is there a matching entity in the CRR? */ - for (unsigned enIx = 0; enIx < crr->contextRegistration.entityIdVector.size(); ++enIx) + /* Is there a matching entity in the Registration? */ + for (unsigned enIx = 0; enIx < reg.dataProvided.entities.size(); ++enIx) { - EntityId* regEn = crr->contextRegistration.entityIdVector[enIx]; + EntityId regEn = reg.dataProvided.entities[enIx]; - if (regEn->isPatternIsTrue() && regEn->id == ".*") + if (regEn.idPattern == ".*") { // By the moment the only supported pattern is .*. In this case matching is // based exclusively in type - if (regEn->type != en.type && !regEn->type.empty()) + if (regEn.type != en.entityId.type && !regEn.type.empty()) { - /* No match (keep searching the CRR) */ + /* No match (keep searching the Registration) */ continue; } } - else if (regEn->id != en.id || (regEn->type != en.type && !regEn->type.empty())) + else if (regEn.id != en.entityId.id || (regEn.type != en.entityId.type && !regEn.type.empty())) { - /* No match (keep searching the CRR) */ + /* No match (keep searching the Registration) */ continue; } - /* CRR without attributes (keep searching in other CRR) */ - if (crr->contextRegistration.contextRegistrationAttributeVector.size() == 0) + /* Registration without attributes (keep searching in other Registration) */ + if (reg.dataProvided.attributes.size() == 0) { - *perEntPa = crr->contextRegistration.providingApplication.get(); - *providerFormatP = crr->contextRegistration.providingApplication.getProviderFormat(); - *regId = crr->regId; + *perEntProviderP = reg.provider.http.url; + *legacyPproviderFormatP = reg.provider.legacyForwardingMode; + *regId = reg.id; break; /* enIx */ } /* Is there a matching entity or the absence of attributes? */ - for (unsigned attrIx = 0; attrIx < crr->contextRegistration.contextRegistrationAttributeVector.size(); ++attrIx) + for (unsigned attrIx = 0; attrIx < reg.dataProvided.attributes.size(); ++attrIx) { - std::string regAttrName = crr->contextRegistration.contextRegistrationAttributeVector[attrIx]->name; + std::string regAttrName = reg.dataProvided.attributes[attrIx]; if (regAttrName == attrName) { - /* We cannot "improve" this result by keep searching the CRR vector, so we return */ - *perAttrPa = crr->contextRegistration.providingApplication.get(); - *providerFormatP = crr->contextRegistration.providingApplication.getProviderFormat(); - *regId = crr->regId; + /* We cannot "improve" this result by keep searching the Registrations vector, so we return */ + *perAttrProviderP = reg.provider.http.url; + *legacyPproviderFormatP = reg.provider.legacyForwardingMode; + *regId = reg.id; return; } diff --git a/src/lib/mongoBackend/MongoGlobal.h b/src/lib/mongoBackend/MongoGlobal.h index 7b951c0784..97370f41f2 100644 --- a/src/lib/mongoBackend/MongoGlobal.h +++ b/src/lib/mongoBackend/MongoGlobal.h @@ -35,18 +35,11 @@ #include "common/RenderFormat.h" #include "ngsi/EntityId.h" -#include "ngsi/ContextRegistrationAttribute.h" #include "ngsi/ContextAttribute.h" #include "ngsi/EntityIdVector.h" #include "ngsi/StringList.h" #include "ngsi/ContextElementResponseVector.h" -#include "ngsi/ContextRegistrationResponseVector.h" -#include "ngsi/ConditionValueList.h" -#include "ngsi/Restriction.h" -#include "ngsi/NotifyConditionVector.h" #include "ngsi10/UpdateContextResponse.h" -#include "ngsi9/RegisterContextRequest.h" -#include "ngsi9/RegisterContextResponse.h" #include "ngsiNotify/Notifier.h" #include "rest/uriParamNames.h" #include "apiTypesV2/Subscription.h" @@ -182,7 +175,7 @@ extern void ensureDateExpirationIndex(const std::string& tenant); * * matchEntity - */ -extern bool matchEntity(const EntityId* en1, const EntityId* en2); +extern bool matchEntity(const EntityId* en1, const EntityId& en2); @@ -219,17 +212,16 @@ extern bool entitiesQuery ( const EntityIdVector& enV, const StringList& attrL, - const Restriction& res, + const ScopeVector& spV, ContextElementResponseVector* cerV, - std::string* err, + OrionError* oeP, const std::string& tenant, const std::vector& servicePath, int offset = DEFAULT_PAGINATION_OFFSET_INT, int limit = DEFAULT_PAGINATION_LIMIT_INT, bool* limitReached = NULL, long long* countP = NULL, - const std::string& sortOrderList = "", - ApiVersion apiVersion = V1 + const std::string& sortOrderList = "" ); @@ -240,7 +232,6 @@ extern bool entitiesQuery */ extern void pruneContextElements ( - ApiVersion apiVersion, const StringList& attrsV, const ContextElementResponseVector& oldCerV, ContextElementResponseVector* newCerVP @@ -257,14 +248,10 @@ extern bool registrationsQuery const EntityIdVector& enV, const StringList& attrL, const ngsiv2::ForwardingMode forwardingMode, - ContextRegistrationResponseVector* crrV, + std::vector* regV, std::string* err, const std::string& tenant, - const std::vector& servicePathV, - int offset = DEFAULT_PAGINATION_OFFSET_INT, - int limit = DEFAULT_PAGINATION_LIMIT_INT, - bool details = false, - long long* countP = NULL + const std::vector& servicePathV ); @@ -277,17 +264,6 @@ extern bool condValueAttrMatch(const orion::BSONObj& sub, const std::vector& crrV); @@ -388,12 +364,10 @@ extern void cprLookupByAttribute ( const Entity& en, const std::string& attrName, - const ContextRegistrationResponseVector& crrV, - std::string* perEntPa, - MimeType* perEntPaMimeType, - std::string* perAttrPa, - MimeType* perAttrPaMimeType, - ProviderFormat* providerFormatP, + const std::vector& regV, + std::string* perEntProviderP, + std::string* perAttrProviderP, + bool* legacyProviderFormatP, std::string* regId ); diff --git a/src/lib/mongoBackend/TriggeredSubscription.cpp b/src/lib/mongoBackend/TriggeredSubscription.cpp index f51103b2b3..20db757dcf 100644 --- a/src/lib/mongoBackend/TriggeredSubscription.cpp +++ b/src/lib/mongoBackend/TriggeredSubscription.cpp @@ -99,10 +99,6 @@ TriggeredSubscription::~TriggeredSubscription() /* **************************************************************************** * * TriggeredSubscription::fillExpression - -* -* TriggeredSubscription class is shared for NGSI9 and NGSI10 subscriptions, so it is better -* to keep expressions (an artifact for NGSI10) out of the constructor, in its independent fill -* method */ void TriggeredSubscription::fillExpression ( @@ -117,21 +113,6 @@ void TriggeredSubscription::fillExpression } -/* **************************************************************************** -* -* TriggeredSubscription::toString - -*/ -std::string TriggeredSubscription::toString(const std::string& delimiter) -{ - std::stringstream ss; - - ss << throttling << delimiter << lastNotification << delimiter << renderFormatToString(renderFormat) << delimiter << httpInfo.url; - ss << expression.georel << delimiter << expression.coords << delimiter << expression.geometry << delimiter; - - return ss.str(); -} - - /* **************************************************************************** * diff --git a/src/lib/mongoBackend/TriggeredSubscription.h b/src/lib/mongoBackend/TriggeredSubscription.h index aa785e91fb..ebd6474093 100644 --- a/src/lib/mongoBackend/TriggeredSubscription.h +++ b/src/lib/mongoBackend/TriggeredSubscription.h @@ -45,10 +45,6 @@ * the csbubs collection. Note that adding all the BSON object retrieved from the * csubs collection is not efficient, so we use only the needed fields- * -* We use the same class for both NGSI10 and NGSI9 subscription. The only difference -* is that throttling and lastNotification are not needed in the second case (note -* that there are different constructor depending the case) -* */ class TriggeredSubscription { @@ -94,7 +90,6 @@ class TriggeredSubscription void fillExpression(const std::string& georel, const std::string& geometry, const std::string& coords); bool stringFilterSet(StringFilter* _stringFilterP, std::string* errorStringP); bool mdStringFilterSet(StringFilter* _stringFilterP, std::string* errorStringP); - std::string toString(const std::string& delimiter); }; #endif // SRC_LIB_MONGOBACKEND_TRIGGEREDSUBSCRIPTION_H_ diff --git a/src/lib/mongoBackend/compoundValueBson.cpp b/src/lib/mongoBackend/compoundValueBson.cpp index 5f6bc9e920..6dca849eda 100644 --- a/src/lib/mongoBackend/compoundValueBson.cpp +++ b/src/lib/mongoBackend/compoundValueBson.cpp @@ -39,13 +39,10 @@ * * compoundValueBson (for arrays) - * -* strings2numbers is used only for the GEO_JSON generation logic to ensure NGSIv1 -* strings are converted to numbers (strings are not allowed in GeoJSON) -* * encode set to true only in the calculateOperator functions, eg. to avoid that * "$each" get replaced by ">each" (see https://github.com/telefonicaid/fiware-orion/issues/744#issuecomment-996752938) */ -void compoundValueBson(const std::vector& children, orion::BSONArrayBuilder& b, bool strings2numbers, bool encode) +void compoundValueBson(const std::vector& children, orion::BSONArrayBuilder& b, bool encode) { for (unsigned int ix = 0; ix < children.size(); ++ix) { @@ -53,15 +50,7 @@ void compoundValueBson(const std::vector& children, o if (child->valueType == orion::ValueTypeString) { - if ((strings2numbers) && (str2double(child->stringValue.c_str(), &child->numberValue))) - { - b.append(child->numberValue); - } - else - { - // Fails in str2double() means that values is not an actual number, so we do nothing and leave it as it is - b.append(child->stringValue); - } + b.append(child->stringValue); } else if (child->valueType == orion::ValueTypeNumber) { @@ -79,14 +68,14 @@ void compoundValueBson(const std::vector& children, o { orion::BSONArrayBuilder ba; - compoundValueBson(child->childV, ba, strings2numbers, encode); + compoundValueBson(child->childV, ba, encode); b.append(ba.arr()); } else if (child->valueType == orion::ValueTypeObject) { orion::BSONObjBuilder bo; - compoundValueBson(child->childV, bo, strings2numbers, encode); + compoundValueBson(child->childV, bo, encode); b.append(bo.obj()); } else if (child->valueType == orion::ValueTypeNotGiven) @@ -106,13 +95,10 @@ void compoundValueBson(const std::vector& children, o * * compoundValueBson (for objects) - * -* strings2numbers is used only for the GEO_JSON generation logic to ensure NGSIv1 -* strings are converted to numbers (strings are not allowed in GeoJSON) -* * encode set to true only in the calculateOperator functions, eg. to avoid that * "$each" get replaced by ">each" (see https://github.com/telefonicaid/fiware-orion/issues/744#issuecomment-996752938) */ -void compoundValueBson(const std::vector& children, orion::BSONObjBuilder& b, bool strings2numbers, bool encode) +void compoundValueBson(const std::vector& children, orion::BSONObjBuilder& b, bool encode) { for (unsigned int ix = 0; ix < children.size(); ++ix) { @@ -121,15 +107,7 @@ void compoundValueBson(const std::vector& children, o if (child->valueType == orion::ValueTypeString) { - if ((strings2numbers) && (str2double(child->stringValue.c_str(), &child->numberValue))) - { - b.append(effectiveName, child->numberValue); - } - else - { - // Fails in str2double() means that values is not an actual number, so we do nothing and leave it as it is - b.append(effectiveName, child->stringValue); - } + b.append(effectiveName, child->stringValue); } else if (child->valueType == orion::ValueTypeNumber) { @@ -147,14 +125,14 @@ void compoundValueBson(const std::vector& children, o { orion::BSONArrayBuilder ba; - compoundValueBson(child->childV, ba, strings2numbers, encode); + compoundValueBson(child->childV, ba, encode); b.append(effectiveName, ba.arr()); } else if (child->valueType == orion::ValueTypeObject) { orion::BSONObjBuilder bo; - compoundValueBson(child->childV, bo, strings2numbers, encode); + compoundValueBson(child->childV, bo, encode); b.append(effectiveName, bo.obj()); } else if (child->valueType == orion::ValueTypeNotGiven) diff --git a/src/lib/mongoBackend/compoundValueBson.h b/src/lib/mongoBackend/compoundValueBson.h index aeaa29902a..aa514c7bfb 100644 --- a/src/lib/mongoBackend/compoundValueBson.h +++ b/src/lib/mongoBackend/compoundValueBson.h @@ -37,7 +37,7 @@ * * compoundValueBson (for objects) - */ -extern void compoundValueBson(const std::vector& children, orion::BSONObjBuilder& b, bool strings2numbers = false, bool encode = true); +extern void compoundValueBson(const std::vector& children, orion::BSONObjBuilder& b, bool encode = true); @@ -45,6 +45,6 @@ extern void compoundValueBson(const std::vector& chil * * compoundValueBson (for arrays) - */ -extern void compoundValueBson(const std::vector& children, orion::BSONArrayBuilder& b, bool strings2numbers = false, bool encode = true); +extern void compoundValueBson(const std::vector& children, orion::BSONArrayBuilder& b, bool encode = true); #endif // SRC_LIB_MONGOBACKEND_COMPOUNDVALUEBSON_H_ diff --git a/src/lib/mongoBackend/location.cpp b/src/lib/mongoBackend/location.cpp index d6de878cba..115c7051ae 100644 --- a/src/lib/mongoBackend/location.cpp +++ b/src/lib/mongoBackend/location.cpp @@ -182,7 +182,7 @@ orion::CompoundValueNode* getGeometry(orion::CompoundValueNode* compoundValueP) * Checked: * - geometry field exists and it's an object */ -static void isFeatureType(CompoundValueNode* feature, orion::BSONObjBuilder* geoJson, ApiVersion apiVersion, std::string* errP) +static void isFeatureType(CompoundValueNode* feature, orion::BSONObjBuilder* geoJson, std::string* errP) { for (unsigned int ix = 0; ix < feature->childV.size(); ++ix) { @@ -195,7 +195,7 @@ static void isFeatureType(CompoundValueNode* feature, orion::BSONObjBuilder* geo return; } - compoundValueBson(childP->childV, *geoJson, apiVersion == V1); + compoundValueBson(childP->childV, *geoJson, false); return; } } @@ -220,7 +220,7 @@ static void isFeatureType(CompoundValueNode* feature, orion::BSONObjBuilder* geo * * the feature field is an array with exactly one item * * the feature field item has a geometry field and it's an object */ -static void isFeatureCollectionType(CompoundValueNode* featureCollection, orion::BSONObjBuilder* geoJson, ApiVersion apiVersion, std::string* errP) +static void isFeatureCollectionType(CompoundValueNode* featureCollection, orion::BSONObjBuilder* geoJson, std::string* errP) { for (unsigned int ix = 0; ix < featureCollection->childV.size(); ++ix) { @@ -244,7 +244,7 @@ static void isFeatureCollectionType(CompoundValueNode* featureCollection, orion: } else { - isFeatureType(featureCollection->childV[ix]->childV[0], geoJson, apiVersion, errP); + isFeatureType(featureCollection->childV[ix]->childV[0], geoJson, errP); return; } } @@ -263,7 +263,7 @@ static void isFeatureCollectionType(CompoundValueNode* featureCollection, orion: * * Return false if no special GeoJSON type was found */ -static bool isSpecialGeoJsonType(const ContextAttribute* caP, orion::BSONObjBuilder* geoJson, ApiVersion apiVersion, std::string* errP) +static bool isSpecialGeoJsonType(const ContextAttribute* caP, orion::BSONObjBuilder* geoJson, std::string* errP) { *errP = ""; @@ -280,12 +280,12 @@ static bool isSpecialGeoJsonType(const ContextAttribute* caP, orion::BSONObjBuil { if (childP->stringValue == "Feature") { - isFeatureType(caP->compoundValueP, geoJson, apiVersion, errP); + isFeatureType(caP->compoundValueP, geoJson, errP); return true; } if (childP->stringValue == "FeatureCollection") { - isFeatureCollectionType(caP->compoundValueP, geoJson, apiVersion, errP); + isFeatureCollectionType(caP->compoundValueP, geoJson, errP); return true; } } @@ -304,8 +304,6 @@ static bool isSpecialGeoJsonType(const ContextAttribute* caP, orion::BSONObjBuil * * It returns true, except in the case of error (in which in addition errDetail gets filled) * -* FIXME P6: try to avoid apiVersion -* * FIXME P6: review the cases in which this function returns false. Maybe many cases (or all them) * can be moved to checkGeoJson() in the parsing layer, as preconditions. */ @@ -313,8 +311,7 @@ static bool getGeoJson ( const ContextAttribute* caP, orion::BSONObjBuilder* geoJson, - std::string* errDetail, - ApiVersion apiVersion + std::string* errDetail ) { std::vector coordLat; @@ -367,7 +364,7 @@ static bool getGeoJson // Feature and FeatureCollection has an special treatment, done insise isSpecialGeoJsonType() // For other cases (i.e. when isSpecialGeoJsonType() returns false) do it in the "old way" - if (isSpecialGeoJsonType(caP, geoJson, apiVersion, errDetail)) + if (isSpecialGeoJsonType(caP, geoJson, errDetail)) { // Feature or FeatureCollection was found, but some error may happen if (!errDetail->empty()) @@ -377,9 +374,8 @@ static bool getGeoJson } else { - // Autocast doesn't make sense in this context, strings2numbers enabled in the case of NGSIv1 // FIXME P7: boolean return value should be managed? - caP->valueBson(std::string(ENT_ATTRS_VALUE), &bo, "", true, apiVersion == V1); + caP->valueBson(std::string(ENT_ATTRS_VALUE), &bo, ""); geoJson->appendElements(getObjectFieldF(bo.obj(), ENT_ATTRS_VALUE)); } @@ -524,7 +520,6 @@ bool processLocationAtEntityCreation std::string* locAttr, orion::BSONObjBuilder* geoJson, std::string* errDetail, - ApiVersion apiVersion, OrionError* oe ) { @@ -546,7 +541,7 @@ bool processLocationAtEntityCreation return false; } - if (!getGeoJson(caP, geoJson, errDetail, apiVersion)) + if (!getGeoJson(caP, geoJson, errDetail)) { oe->fill(SccBadRequest, "error parsing location attribute: " + *errDetail, ERROR_BAD_REQUEST); return false; @@ -571,7 +566,6 @@ bool processLocationAtUpdateAttribute const ContextAttribute* targetAttr, orion::BSONObjBuilder* geoJson, std::string* errDetail, - ApiVersion apiVersion, OrionError* oe ) { @@ -589,7 +583,7 @@ bool processLocationAtUpdateAttribute // if (*currentLocAttrName == "") { - if (!getGeoJson(targetAttr, geoJson, &subErr, apiVersion)) + if (!getGeoJson(targetAttr, geoJson, &subErr)) { *errDetail = "error parsing location attribute: " + subErr; oe->fill(SccBadRequest, *errDetail, ERROR_BAD_REQUEST); @@ -607,26 +601,14 @@ bool processLocationAtUpdateAttribute // if (*currentLocAttrName != targetAttr->name) { - if (apiVersion == V1) + if (!getGeoJson(targetAttr, geoJson, &subErr)) { - *errDetail = "attempt to define a geo location attribute [" + targetAttr->name + "]" + - " when another one has been previously defined [" + *currentLocAttrName + "]"; - - oe->fill(SccRequestEntityTooLarge, ERROR_DESC_NO_RESOURCES_AVAILABLE_GEOLOC, ERROR_NO_RESOURCES_AVAILABLE); - + *errDetail = "error parsing location attribute: " + subErr; + oe->fill(SccBadRequest, *errDetail, ERROR_BAD_REQUEST); return false; } - else - { - if (!getGeoJson(targetAttr, geoJson, &subErr, apiVersion)) - { - *errDetail = "error parsing location attribute: " + subErr; - oe->fill(SccBadRequest, *errDetail, ERROR_BAD_REQUEST); - return false; - } - *currentLocAttrName = targetAttr->name; - return true; - } + *currentLocAttrName = targetAttr->name; + return true; } // // Case 1c: @@ -635,7 +617,7 @@ bool processLocationAtUpdateAttribute // if (*currentLocAttrName == targetAttr->name) { - if (!getGeoJson(targetAttr, geoJson, &subErr, apiVersion)) + if (!getGeoJson(targetAttr, geoJson, &subErr)) { *errDetail = "error parsing location attribute: " + subErr; oe->fill(SccBadRequest, *errDetail, ERROR_BAD_REQUEST); @@ -652,22 +634,8 @@ bool processLocationAtUpdateAttribute // else if (*currentLocAttrName == targetAttr->name) { - if (apiVersion == V1) - { - /* In this case, no-location means that the target attribute doesn't have the "location" metadata. In order - * to mantain backwards compabitibility, this is interpreted as a location update */ - if (!getGeoJson(targetAttr, geoJson, &subErr, apiVersion)) - { - *errDetail = "error parsing location attribute: " + subErr; - oe->fill(SccBadRequest, *errDetail, ERROR_BAD_REQUEST); - return false; - } - } - else // v2 - { - // Location is null-ified - *currentLocAttrName = ""; - } + // Location is null-ified + *currentLocAttrName = ""; } return true; @@ -687,7 +655,6 @@ bool processLocationAtAppendAttribute bool actualAppend, orion::BSONObjBuilder* geoJson, std::string* errDetail, - ApiVersion apiVersion, OrionError* oe ) { @@ -710,7 +677,7 @@ bool processLocationAtAppendAttribute /* Case 1b: there isn't any previous location attribute -> new attribute becomes the location attribute */ else { - if (!getGeoJson(targetAttr, geoJson, &subErr, apiVersion)) + if (!getGeoJson(targetAttr, geoJson, &subErr)) { *errDetail = "error parsing location attribute for new attribute: " + subErr; oe->fill(SccBadRequest, *errDetail, ERROR_BAD_REQUEST); @@ -736,7 +703,7 @@ bool processLocationAtAppendAttribute /* Case 2b: there isn't any previous location attribute -> the updated attribute becomes the location attribute */ if (*currentLocAttrName == "") { - if (!getGeoJson(targetAttr, geoJson, &subErr, apiVersion)) + if (!getGeoJson(targetAttr, geoJson, &subErr)) { *errDetail = "error parsing location attribute for existing attribute: " + subErr; oe->fill(SccBadRequest, *errDetail, ERROR_BAD_REQUEST); @@ -746,7 +713,7 @@ bool processLocationAtAppendAttribute } /* Case 2c: all pre-conditions ok -> update location with the new value */ - if (!getGeoJson(targetAttr, geoJson, &subErr, apiVersion)) + if (!getGeoJson(targetAttr, geoJson, &subErr)) { *errDetail = "error parsing location attribute: " + subErr; oe->fill(SccBadRequest, *errDetail, ERROR_BAD_REQUEST); diff --git a/src/lib/mongoBackend/location.h b/src/lib/mongoBackend/location.h index 2db8cfa1ea..c18c551665 100644 --- a/src/lib/mongoBackend/location.h +++ b/src/lib/mongoBackend/location.h @@ -44,7 +44,6 @@ extern bool processLocationAtEntityCreation std::string* locAttr, orion::BSONObjBuilder* geoJson, std::string* errDetail, - ApiVersion apiVersion, OrionError* oe ); @@ -61,7 +60,6 @@ extern bool processLocationAtUpdateAttribute const ContextAttribute* targetAttr, orion::BSONObjBuilder* geoJson, std::string* errDetail, - ApiVersion apiVersion, OrionError* oe ); @@ -79,7 +77,6 @@ extern bool processLocationAtAppendAttribute bool actualAppend, orion::BSONObjBuilder* geoJson, std::string* errDetail, - ApiVersion apiVersion, OrionError* oe ); diff --git a/src/lib/mongoBackend/mongoCreateSubscription.cpp b/src/lib/mongoBackend/mongoCreateSubscription.cpp index d5579884bb..24951d65be 100644 --- a/src/lib/mongoBackend/mongoCreateSubscription.cpp +++ b/src/lib/mongoBackend/mongoCreateSubscription.cpp @@ -68,22 +68,22 @@ static void insertInCache // // StringFilter in Scope? // - // Any Scope of type SCOPE_TYPE_SIMPLE_QUERY sub.restriction.scopeVector? + // Any Scope of type SCOPE_TYPE_SIMPLE_QUERY sub.scopeVector? // If so, set it as string filter to the sub-cache item // StringFilter* stringFilterP = NULL; StringFilter* mdStringFilterP = NULL; - for (unsigned int ix = 0; ix < sub.restriction.scopeVector.size(); ++ix) + for (unsigned int ix = 0; ix < sub.scopeVector.size(); ++ix) { - if (sub.restriction.scopeVector[ix]->type == SCOPE_TYPE_SIMPLE_QUERY) + if (sub.scopeVector[ix]->type == SCOPE_TYPE_SIMPLE_QUERY) { - stringFilterP = sub.restriction.scopeVector[ix]->stringFilterP; + stringFilterP = sub.scopeVector[ix]->stringFilterP; } - if (sub.restriction.scopeVector[ix]->type == SCOPE_TYPE_SIMPLE_QUERY_MD) + if (sub.scopeVector[ix]->type == SCOPE_TYPE_SIMPLE_QUERY_MD) { - mdStringFilterP = sub.restriction.scopeVector[ix]->mdStringFilterP; + mdStringFilterP = sub.scopeVector[ix]->mdStringFilterP; } } diff --git a/src/lib/mongoBackend/mongoDiscoverContextAvailability.cpp b/src/lib/mongoBackend/mongoDiscoverContextAvailability.cpp deleted file mode 100644 index fae4e260d2..0000000000 --- a/src/lib/mongoBackend/mongoDiscoverContextAvailability.cpp +++ /dev/null @@ -1,160 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" -#include "common/statistics.h" -#include "common/sem.h" -#include "alarmMgr/alarmMgr.h" -#include "mongoBackend/mongoDiscoverContextAvailability.h" -#include "rest/HttpStatusCode.h" -#include "mongoBackend/MongoGlobal.h" -#include "ngsi/StatusCode.h" -#include "ngsi9/DiscoverContextAvailabilityRequest.h" -#include "ngsi9/DiscoverContextAvailabilityResponse.h" - - - -/* **************************************************************************** -* -* processDiscoverContextAvailability - -*/ -static HttpStatusCode processDiscoverContextAvailability -( - DiscoverContextAvailabilityRequest* requestP, - DiscoverContextAvailabilityResponse* responseP, - const std::string& tenant, - int offset, - int limit, - bool details, - const std::vector& servicePathV -) -{ - std::string err; - long long count = -1; - - LM_T(LmtPagination, ("Offset: %d, Limit: %d, Details: %s", offset, limit, (details == true)? "true" : "false")); - - if (!registrationsQuery(requestP->entityIdVector, - requestP->attributeList, - ngsiv2::ForwardNone, - &responseP->responseVector, - &err, - tenant, - servicePathV, - offset, - limit, - details, - &count)) - { - responseP->errorCode.fill(SccReceiverInternalError, err); - return SccOk; - } - - if (responseP->responseVector.size() == 0) - { - // - // If the responseV is empty, we haven't found any entity and have to fill the status code part in the response. - // - // However, if the response was empty due to a too high pagination offset, - // and if the user has asked for 'details' (as URI parameter), then the response should include information about - // the number of hits without pagination. - // - if (details) - { - if ((count > 0) && (offset >= count)) - { - char details[256]; - - snprintf(details, sizeof(details), "Number of matching registrations: %lld. Offset is %d", count, offset); - responseP->errorCode.fill(SccContextElementNotFound, details); - - return SccOk; - } - } - - responseP->errorCode.fill(SccContextElementNotFound); - return SccOk; - } - else if (details == true) - { - // - // If all is OK, but the details URI param has been set to 'on', then the response error code details - // MUST contain the total count of hits. - // - - char details[64]; - - snprintf(details, sizeof(details), "Count: %lld", count); - responseP->errorCode.fill(SccOk, details); - } - - return SccOk; -} - - - -/* **************************************************************************** -* -* mongoDiscoverContextAvailability - -*/ -HttpStatusCode mongoDiscoverContextAvailability -( - DiscoverContextAvailabilityRequest* requestP, - DiscoverContextAvailabilityResponse* responseP, - const std::string& tenant, - std::map& uriParams, - const std::vector& servicePathV -) -{ - int offset = atoi(uriParams[URI_PARAM_PAGINATION_OFFSET].c_str()); - int limit = atoi(uriParams[URI_PARAM_PAGINATION_LIMIT].c_str()); - std::string detailsString = uriParams[URI_PARAM_PAGINATION_DETAILS]; - bool details = (strcasecmp("on", detailsString.c_str()) == 0)? true : false; - bool reqSemTaken; - - reqSemTake(__FUNCTION__, "mongo ngsi9 discovery request", SemReadOp, &reqSemTaken); - - LM_T(LmtMongo, ("DiscoverContextAvailability Request")); - - HttpStatusCode hsCode = processDiscoverContextAvailability(requestP, - responseP, - tenant, - offset, - limit, - details, - servicePathV); - if (hsCode != SccOk) - { - ++noOfDiscoveryErrors; - } - - reqSemGive(__FUNCTION__, "mongo ngsi9 discovery request", reqSemTaken); - - return hsCode; -} diff --git a/src/lib/mongoBackend/mongoDiscoverContextAvailability.h b/src/lib/mongoBackend/mongoDiscoverContextAvailability.h deleted file mode 100644 index 6a7203877f..0000000000 --- a/src/lib/mongoBackend/mongoDiscoverContextAvailability.h +++ /dev/null @@ -1,51 +0,0 @@ -#ifndef SRC_LIB_MONGOBACKEND_MONGODISCOVERCONTEXTAVAILABILITY_H_ -#define SRC_LIB_MONGOBACKEND_MONGODISCOVERCONTEXTAVAILABILITY_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Fermin Galan Marquez -*/ -#include -#include -#include - -#include "rest/HttpStatusCode.h" -#include "ngsi9/DiscoverContextAvailabilityRequest.h" -#include "ngsi9/DiscoverContextAvailabilityResponse.h" - - - -/* **************************************************************************** -* -* mongoDiscoverContextAvailability - -*/ -extern HttpStatusCode mongoDiscoverContextAvailability -( - DiscoverContextAvailabilityRequest* requestP, - DiscoverContextAvailabilityResponse* responseP, - const std::string& tenant, - std::map& uriParams, - const std::vector& servicePathV -); - -#endif // SRC_LIB_MONGOBACKEND_MONGODISCOVERCONTEXTAVAILABILITY_H_ diff --git a/src/lib/mongoBackend/mongoGetSubscriptions.cpp b/src/lib/mongoBackend/mongoGetSubscriptions.cpp index c14866017c..b1a51be48a 100644 --- a/src/lib/mongoBackend/mongoGetSubscriptions.cpp +++ b/src/lib/mongoBackend/mongoGetSubscriptions.cpp @@ -51,7 +51,6 @@ * USING - */ using ngsiv2::Subscription; -using ngsiv2::EntID; @@ -94,7 +93,7 @@ static void setSubject(Subscription* s, const orion::BSONObj& r) bool isTypePattern = ent.hasField(CSUB_ENTITY_ISTYPEPATTERN)? getBoolFieldF(ent, CSUB_ENTITY_ISTYPEPATTERN) : false; - EntID en; + EntityId en; if (isFalse(isPattern)) { en.id = id; diff --git a/src/lib/mongoBackend/mongoNotifyContext.cpp b/src/lib/mongoBackend/mongoNotifyContext.cpp index 1dc946b7e4..63a7dfebd6 100644 --- a/src/lib/mongoBackend/mongoNotifyContext.cpp +++ b/src/lib/mongoBackend/mongoNotifyContext.cpp @@ -56,7 +56,7 @@ HttpStatusCode mongoNotifyContext { bool reqSemTaken; - reqSemTake(__FUNCTION__, "ngsi10 notification", SemWriteOp, &reqSemTaken); + reqSemTake(__FUNCTION__, "notification", SemWriteOp, &reqSemTaken); // Process each ContextElement for (unsigned int ix = 0; ix < requestP->contextElementResponseVector.size(); ++ix) @@ -70,8 +70,8 @@ HttpStatusCode mongoNotifyContext processContextElement(eP, &ucr, ActionTypeAppend, tenant, servicePathV, uriParams, xauthToken, fiwareCorrelator, ngsiV2AttrsFormat, forcedUpdate, overrideMetadata, 0); } - reqSemGive(__FUNCTION__, "ngsi10 notification", reqSemTaken); - responseP->responseCode.fill(SccOk); + reqSemGive(__FUNCTION__, "notification", reqSemTaken); + responseP->error.fill(SccOk); return SccOk; } diff --git a/src/lib/mongoBackend/mongoQueryContext.cpp b/src/lib/mongoBackend/mongoQueryContext.cpp index 32b51170f2..61c064abd6 100644 --- a/src/lib/mongoBackend/mongoQueryContext.cpp +++ b/src/lib/mongoBackend/mongoQueryContext.cpp @@ -31,7 +31,6 @@ #include "common/string.h" #include "common/sem.h" #include "alarmMgr/alarmMgr.h" -#include "ngsi/ContextRegistrationResponse.h" #include "ngsi10/QueryContextRequest.h" #include "ngsi10/QueryContextResponse.h" @@ -66,29 +65,30 @@ static bool someContextElementNotFound(const ContextElementResponseVector& cerV) * * fillContextProviders - * -* Looks in the elements of the CER vector passed as argument, searching for a suitable CPr in the CRR +* Looks in the elements of the CER vector passed as argument, searching for a suitable CPr in the Registrations * vector passed as argument. If a suitable CPr is found, it is added to the CER (and the 'found' field * is changed to true) */ -static void fillContextProviders(ContextElementResponseVector& cerV, const ContextRegistrationResponseVector& crrV) +static void fillContextProviders(ContextElementResponseVector& cerV, const std::vector& regV) { for (unsigned int ix = 0; ix < cerV.size(); ++ix) { - fillContextProviders(cerV[ix], crrV); + fillContextProviders(cerV[ix], regV); } } + /* **************************************************************************** * -* addContextProviderEntity - +* lookupProvider - */ -static bool lookupProvidingApplication(const std::vector& paV, const ProvidingApplication &pa) +static bool lookupProvider(const std::vector& providerV, const ngsiv2::Provider &provider) { - for (unsigned int ix = 0; ix < paV.size(); ++ix) + for (unsigned int ix = 0; ix < providerV.size(); ++ix) { - if ((paV[ix].string == pa.string) && (paV[ix].regId == pa.regId)) + if (providerV[ix].http.url == provider.http.url) { return true; } @@ -105,18 +105,20 @@ static bool lookupProvidingApplication(const std::vector& static void addContextProviderEntity ( ContextElementResponseVector& cerV, - EntityId* enP, - const ProvidingApplication& pa + const EntityId& regEn, + const ngsiv2::Provider& provider, + const std::string& regId ) { for (unsigned int ix = 0; ix < cerV.size(); ++ix) { - if ((cerV[ix]->entity.id == enP->id) && (cerV[ix]->entity.type == enP->type)) + if (cerV[ix]->entity.entityId == regEn) { - // Avoid duplicate PA in the vector - if (!lookupProvidingApplication(cerV[ix]->entity.providingApplicationList, pa)) + // Avoid duplicate Provider in the vector + if (!lookupProvider(cerV[ix]->entity.providerList, provider)) { - cerV[ix]->entity.providingApplicationList.push_back(pa); + cerV[ix]->entity.providerList.push_back(provider); + cerV[ix]->entity.providerRegIdList.push_back(regId); } return; /* by construction, no more than one CER with the same entity information should exist in the CERV) */ } @@ -125,10 +127,12 @@ static void addContextProviderEntity /* Reached this point, it means that the cerV doesn't contain a proper CER, so we create it */ ContextElementResponse* cerP = new ContextElementResponse(); - cerP->entity.fill(enP->id, enP->type, enP->isPattern); - cerP->entity.providingApplicationList.push_back(pa); + EntityId enId(regEn.id, regEn.idPattern, regEn.type, regEn.typePattern); + cerP->entity.fill(enId); + cerP->entity.providerList.push_back(provider); + cerP->entity.providerRegIdList.push_back(regId); - cerP->statusCode.fill(SccOk); + cerP->error.fill(SccOk); cerV.push_back(cerP); } @@ -144,15 +148,16 @@ static void addContextProviderEntity static void addContextProviderAttribute ( ContextElementResponseVector& cerV, - EntityId* enP, - ContextRegistrationAttribute* craP, - const ProvidingApplication& pa, + EntityId regEn, + const std::string& regAttr, + const ngsiv2::Provider& provider, + const std::string& regId, bool limitReached ) { for (unsigned int ix = 0; ix < cerV.size(); ++ix) { - if ((cerV[ix]->entity.id != enP->id) || (cerV[ix]->entity.type != enP->type)) + if ((cerV[ix]->entity.entityId.id != regEn.id) || (cerV[ix]->entity.entityId.type != regEn.type)) { continue; } @@ -161,7 +166,7 @@ static void addContextProviderAttribute { std::string attrName = cerV[ix]->entity.attributeVector[jx]->name; - if (attrName == craP->name) + if (attrName == regAttr) { /* In this case, the attribute has been already found in local database. CPr is unnecessary */ @@ -171,9 +176,10 @@ static void addContextProviderAttribute } /* Reached this point, no attribute was found, so adding it with corresponding CPr info */ - ContextAttribute* caP = new ContextAttribute(craP->name, "", ""); + ContextAttribute* caP = new ContextAttribute(regAttr, "", ""); - caP->providingApplication = pa; + caP->provider = provider; + caP->providerRegId = regId; cerV[ix]->entity.attributeVector.push_back(caP); return; } @@ -183,12 +189,14 @@ static void addContextProviderAttribute /* Reached this point, it means that the cerV doesn't contain a proper CER, so we create it */ ContextElementResponse* cerP = new ContextElementResponse(); - cerP->entity.fill(enP->id, enP->type, enP->isPattern); - cerP->statusCode.fill(SccOk); + EntityId enId(regEn.id, regEn.idPattern, regEn.type, regEn.typePattern); + cerP->entity.fill(enId); + cerP->error.fill(SccOk); - ContextAttribute* caP = new ContextAttribute(craP->name, "", ""); + ContextAttribute* caP = new ContextAttribute(regAttr, "", ""); - caP->providingApplication = pa; + caP->provider = provider; + caP->providerRegId = regId; cerP->entity.attributeVector.push_back(caP); cerV.push_back(cerP); } @@ -198,15 +206,15 @@ static void addContextProviderAttribute /* **************************************************************************** * -* matchEntityInCrr - +* matchEntityInRegistration - */ -static bool matchEntityInCrr(const ContextRegistration& cr, const EntityId* enP) +static bool matchEntityInRegistration(const ngsiv2::Registration& reg, const EntityId* enP) { - for (unsigned int ix = 0; ix < cr.entityIdVector.size(); ++ix) + for (unsigned int ix = 0; ix < reg.dataProvided.entities.size(); ++ix) { - EntityId* crEnP = cr.entityIdVector[ix]; + EntityId entId = reg.dataProvided.entities[ix]; - if (matchEntity(crEnP, enP)) + if (matchEntity(enP, entId)) { return true; } @@ -221,7 +229,7 @@ static bool matchEntityInCrr(const ContextRegistration& cr, const EntityId* enP) * * addContextProviders - * -* This function takes a CRR vector and adds the Context Providers in the CER vector +* This function takes a Registrations vector and adds the Context Providers in the CER vector * (except the ones corresponding to some locally found attribute, i.e. info already in the * CER vector) * @@ -229,50 +237,50 @@ static bool matchEntityInCrr(const ContextRegistration& cr, const EntityId* enP) * limit has been reached with local entities. * * The enP parameter is optional. If not NULL, then before adding a CPr the function checks that the -* containting CRR matches the entity (this is used for funcionality related to "generic queries", see +* containting Registrations matches the entity (this is used for funcionality related to "generic queries", see * processGenericEntities() function). */ static void addContextProviders ( - ContextElementResponseVector& cerV, - ContextRegistrationResponseVector& crrV, - bool limitReached, - const EntityId* enP = NULL + ContextElementResponseVector& cerV, + const std::vector& regV, + bool limitReached, + const EntityId* enP = NULL ) { - for (unsigned int ix = 0; ix < crrV.size(); ++ix) + for (unsigned int ix = 0; ix < regV.size(); ++ix) { - ContextRegistration cr = crrV[ix]->contextRegistration; - cr.providingApplication.setRegId(crrV[ix]->regId); + ngsiv2::Registration reg = regV[ix]; /* In case a "filtering" entity was provided, check that the current CRR matches or skip to next CRR */ - if (enP != NULL && !matchEntityInCrr(cr, enP)) + if (enP != NULL && !matchEntityInRegistration(reg, enP)) { continue; } - if (cr.contextRegistrationAttributeVector.size() == 0) + if (reg.dataProvided.attributes.size() == 0) { if (!limitReached) { /* Registration without attributes */ - for (unsigned int eIx = 0; eIx < cr.entityIdVector.size(); ++eIx) + for (unsigned int eIx = 0; eIx < reg.dataProvided.entities.size(); ++eIx) { - addContextProviderEntity(cerV, cr.entityIdVector[eIx], cr.providingApplication); + addContextProviderEntity(cerV, reg.dataProvided.entities[eIx], reg.provider, reg.id); } } } else { /* Registration with attributes */ - for (unsigned int eIx = 0; eIx < cr.entityIdVector.size(); ++eIx) + for (unsigned int eIx = 0; eIx < reg.dataProvided.entities.size(); ++eIx) { - for (unsigned int aIx = 0; aIx < cr.contextRegistrationAttributeVector.size(); ++aIx) + for (unsigned int aIx = 0; aIx < reg.dataProvided.attributes.size(); ++aIx) { addContextProviderAttribute(cerV, - cr.entityIdVector[eIx], - cr.contextRegistrationAttributeVector[aIx], - cr.providingApplication, + reg.dataProvided.entities[eIx], + reg.dataProvided.attributes[aIx], + reg.provider, + reg.id, limitReached); } } @@ -294,18 +302,18 @@ static void addContextProviders */ static void processGenericEntities ( - const EntityIdVector& enV, - ContextElementResponseVector& cerV, - ContextRegistrationResponseVector& crrV, - bool limitReached + const EntityIdVector& enV, + ContextElementResponseVector& cerV, + const std::vector& regV, + bool limitReached ) { for (unsigned int ix = 0; ix < enV.size(); ++ix) { const EntityId* enP = enV[ix]; - if (enP->type.empty() || isTrue(enP->isPattern)) + if (enP->type.empty() || !enP->idPattern.empty()) { - addContextProviders(cerV, crrV, limitReached, enP); + addContextProviders(cerV, regV, limitReached, enP); } } } @@ -319,9 +327,6 @@ static void processGenericEntities * NOTE * If the in/out-parameter countP is non-NULL then the number of matching entities * must be returned in *countP. -* -* This replaces the 'uriParams[URI_PARAM_PAGINATION_DETAILS]' way of passing this information. -* The old method was one-way, using the new method */ HttpStatusCode mongoQueryContext ( @@ -331,8 +336,7 @@ HttpStatusCode mongoQueryContext const std::vector& servicePathV, std::map& uriParams, std::map& options, - long long* countP, - ApiVersion apiVersion + long long* countP ) { int offset = atoi(uriParams[URI_PARAM_PAGINATION_OFFSET].c_str()); @@ -343,72 +347,60 @@ HttpStatusCode mongoQueryContext LM_T(LmtMongo, ("QueryContext Request")); LM_T(LmtPagination, ("Offset: %d, Limit: %d, Count: %s", offset, limit, (countP != NULL)? "true" : "false")); - /* FIXME: restriction not supported for the moment */ - if (!requestP->restriction.attributeExpression.isEmpty()) - { - alarmMgr.badInput(clientIp, "restriction found, but restrictions are not supported by mongo backend"); - } - std::string err; bool ok; bool limitReached = false; bool reqSemTaken; ContextElementResponseVector rawCerV; - reqSemTake(__FUNCTION__, "ngsi10 query request", SemReadOp, &reqSemTaken); + reqSemTake(__FUNCTION__, "query request", SemReadOp, &reqSemTaken); ok = entitiesQuery(requestP->entityIdVector, requestP->attributeList, - requestP->restriction, + requestP->scopeVector, &rawCerV, - &err, + &responseP->error, tenant, servicePathV, offset, limit, &limitReached, countP, - sortOrderList, - apiVersion); + sortOrderList); if (!ok) { - responseP->errorCode.fill(SccReceiverInternalError, err); rawCerV.release(); - reqSemGive(__FUNCTION__, "ngsi10 query request", reqSemTaken); + reqSemGive(__FUNCTION__, "query request", reqSemTaken); return SccOk; } - ContextRegistrationResponseVector crrV; - /* In the case of empty response, if only generic processing is needed */ if (rawCerV.size() == 0) { - if (registrationsQuery(requestP->entityIdVector, requestP->attributeList, ngsiv2::ForwardQuery, &crrV, &err, tenant, servicePathV, 0, 0, false)) + std::vector regV; + if (registrationsQuery(requestP->entityIdVector, requestP->attributeList, ngsiv2::ForwardQuery, ®V, &err, tenant, servicePathV)) { - if (crrV.size() > 0) + if (regV.size() > 0) { - processGenericEntities(requestP->entityIdVector, rawCerV, crrV, limitReached); + processGenericEntities(requestP->entityIdVector, rawCerV, regV, limitReached); } } - - crrV.release(); } /* First CPr lookup (in the case some CER is not found): looking in E-A registrations */ if (someContextElementNotFound(rawCerV)) { - if (registrationsQuery(requestP->entityIdVector, requestP->attributeList, ngsiv2::ForwardQuery, &crrV, &err, tenant, servicePathV, 0, 0, false)) + std::vector regV; + if (registrationsQuery(requestP->entityIdVector, requestP->attributeList, ngsiv2::ForwardQuery, ®V, &err, tenant, servicePathV)) { - if (crrV.size() > 0) + if (regV.size() > 0) { - fillContextProviders(rawCerV, crrV); - processGenericEntities(requestP->entityIdVector, rawCerV, crrV, limitReached); + fillContextProviders(rawCerV, regV); + processGenericEntities(requestP->entityIdVector, rawCerV, regV, limitReached); } } - - crrV.release(); } /* Second CPr lookup (in the case some elements still not being found): looking in E- registrations */ @@ -416,15 +408,14 @@ HttpStatusCode mongoQueryContext if (someContextElementNotFound(rawCerV)) { - if (registrationsQuery(requestP->entityIdVector, attrNullList, ngsiv2::ForwardQuery, &crrV, &err, tenant, servicePathV, 0, 0, false)) + std::vector regV; + if (registrationsQuery(requestP->entityIdVector, attrNullList, ngsiv2::ForwardQuery, ®V, &err, tenant, servicePathV)) { - if (crrV.size() > 0) + if (regV.size() > 0) { - fillContextProviders(rawCerV, crrV); + fillContextProviders(rawCerV, regV); } } - - crrV.release(); } /* Special case: request with attributes. In that case, entitiesQuery() may have captured some local attribute, but @@ -433,19 +424,18 @@ HttpStatusCode mongoQueryContext */ if (requestP->attributeList.size() == 0) { - if (registrationsQuery(requestP->entityIdVector, requestP->attributeList, ngsiv2::ForwardQuery, &crrV, &err, tenant, servicePathV, 0, 0, false)) + std::vector regV; + if (registrationsQuery(requestP->entityIdVector, requestP->attributeList, ngsiv2::ForwardQuery, ®V, &err, tenant, servicePathV)) { - if (crrV.size() > 0) + if (regV.size() > 0) { - addContextProviders(rawCerV, crrV, limitReached); + addContextProviders(rawCerV, regV, limitReached); } } - - crrV.release(); } /* Prune "not found" CERs */ - pruneContextElements(apiVersion, requestP->attrsList, rawCerV, &responseP->contextElementResponseVector); + pruneContextElements(requestP->attrsList, rawCerV, &responseP->contextElementResponseVector); /* Pagination stuff */ if (responseP->contextElementResponseVector.size() == 0) @@ -462,16 +452,17 @@ HttpStatusCode mongoQueryContext { char details[256]; - snprintf(details, sizeof(details), "Number of matching entities: %lld. Offset is %d", *countP, offset); - responseP->errorCode.fill(SccContextElementNotFound, details); + snprintf(details, sizeof(details), "Number of matching entities: %lld. Offset is %d", *countP, offset); // FIXME PR: this could be removed?? + responseP->error.fill(SccContextElementNotFound, details); } else { - responseP->errorCode.fill(SccContextElementNotFound); + responseP->error.fill(SccContextElementNotFound); } } else if (countP != NULL) { + // FIXME PR: Count: is a NGSIv1 thing... remove this // // If all was OK, but the details URI param was set to 'on', then the responses error code details // 'must' contain the total count of hits. @@ -480,11 +471,11 @@ HttpStatusCode mongoQueryContext char details[64]; snprintf(details, sizeof(details), "Count: %lld", *countP); - responseP->errorCode.fill(SccOk, details); + responseP->error.fill(SccOk, details); } rawCerV.release(); - reqSemGive(__FUNCTION__, "ngsi10 query request", reqSemTaken); + reqSemGive(__FUNCTION__, "query request", reqSemTaken); return SccOk; } diff --git a/src/lib/mongoBackend/mongoQueryContext.h b/src/lib/mongoBackend/mongoQueryContext.h index d249ea9c70..fa78e79684 100644 --- a/src/lib/mongoBackend/mongoQueryContext.h +++ b/src/lib/mongoBackend/mongoQueryContext.h @@ -48,8 +48,7 @@ extern HttpStatusCode mongoQueryContext const std::vector& servicePathV, std::map& uriParams, std::map& options, - long long* countP = NULL, - ApiVersion apiVersion = V1 + long long* countP = NULL ); #endif // SRC_LIB_MONGOBACKEND_MONGOQUERYCONTEXT_H_ diff --git a/src/lib/mongoBackend/mongoQueryTypes.cpp b/src/lib/mongoBackend/mongoQueryTypes.cpp index 32e0fb23ce..8a222f7e2b 100644 --- a/src/lib/mongoBackend/mongoQueryTypes.cpp +++ b/src/lib/mongoBackend/mongoQueryTypes.cpp @@ -268,9 +268,7 @@ static void sortStage(orion::BSONArrayBuilder* pipeline) * mongoEntityTypesValues - * * "Simplified" version of mongoEntityTypes(), using a simpler aggregation command -* and the processing logic afterwards. Note that apiVersion is not included in this -* operation as it can be used only in NGSIv2 -* +* and the processing logic afterwards. */ HttpStatusCode mongoEntityTypesValues ( @@ -371,7 +369,7 @@ HttpStatusCode mongoEntityTypesValues { TIME_STAT_MONGO_COMMAND_WAIT_STOP(); orion::releaseMongoConnection(connection); - responseP->statusCode.fill(SccReceiverInternalError, err); + responseP->error.fill(SccReceiverInternalError, err); reqSemGive(__FUNCTION__, "query types request", reqSemTaken); return SccOk; @@ -413,7 +411,7 @@ HttpStatusCode mongoEntityTypesValues *totalTypesP = docs; } - responseP->statusCode.fill(SccOk); + responseP->error.fill(SccOk); reqSemGive(__FUNCTION__, "query types request", reqSemTaken); return SccOk; @@ -432,7 +430,6 @@ HttpStatusCode mongoEntityTypes const std::string& tenant, const std::vector& servicePathV, std::map& uriParams, - ApiVersion apiVersion, unsigned int* totalTypesP, bool noAttrDetail ) @@ -560,7 +557,7 @@ HttpStatusCode mongoEntityTypes { TIME_STAT_MONGO_COMMAND_WAIT_STOP(); orion::releaseMongoConnection(connection); - responseP->statusCode.fill(SccReceiverInternalError, err); + responseP->error.fill(SccReceiverInternalError, err); reqSemGive(__FUNCTION__, "query types request", reqSemTaken); return SccOk; @@ -617,14 +614,7 @@ HttpStatusCode mongoEntityTypes for (unsigned int kx = 0; kx < attrTypes.size(); ++kx) { ContextAttribute* ca = new ContextAttribute(attrName, attrTypes[kx], ""); - entityType->contextAttributeVector.push_back(ca); - - // For backward compability, NGSIv1 only accepts one element - if (apiVersion == V1) - { - break; - } } } else @@ -652,11 +642,11 @@ HttpStatusCode mongoEntityTypes *totalTypesP = docs; char detailsMsg[256]; snprintf(detailsMsg, sizeof(detailsMsg), "Number of types: %u. Offset is %u", *totalTypesP, offset); - responseP->statusCode.fill(SccContextElementNotFound, detailsMsg); + responseP->error.fill(SccContextElementNotFound, detailsMsg); } else { - responseP->statusCode.fill(SccContextElementNotFound); + responseP->error.fill(SccContextElementNotFound); } } else @@ -666,11 +656,11 @@ HttpStatusCode mongoEntityTypes *totalTypesP = docs; char detailsMsg[256]; snprintf(detailsMsg, sizeof(detailsMsg), "Count: %u", *totalTypesP); - responseP->statusCode.fill(SccOk, detailsMsg); + responseP->error.fill(SccOk, detailsMsg); } else { - responseP->statusCode.fill(SccOk); + responseP->error.fill(SccOk); } } @@ -693,8 +683,7 @@ HttpStatusCode mongoAttributesForEntityType const std::string& tenant, const std::vector& servicePathV, std::map& uriParams, - bool noAttrDetail, - ApiVersion apiVersion + bool noAttrDetail ) { unsigned int offset = atoi(uriParams[URI_PARAM_PAGINATION_OFFSET].c_str()); @@ -702,14 +691,6 @@ HttpStatusCode mongoAttributesForEntityType bool reqSemTaken = false; bool count = false; - // Count only makes sense for this operation in the case of NGSIv1 - if (apiVersion == V1) - { - std::string detailsString = uriParams[URI_PARAM_PAGINATION_DETAILS]; - - count = (strcasecmp("on", detailsString.c_str()) == 0)? true : false; - } - // Setting the name of the entity type for the response responseP->entityType.type = entityType; @@ -789,7 +770,7 @@ HttpStatusCode mongoAttributesForEntityType { TIME_STAT_MONGO_COMMAND_WAIT_STOP(); orion::releaseMongoConnection(connection); - responseP->statusCode.fill(SccReceiverInternalError, err); + responseP->error.fill(SccReceiverInternalError, err); reqSemGive(__FUNCTION__, "query types request", reqSemTaken); return SccOk; @@ -849,14 +830,7 @@ HttpStatusCode mongoAttributesForEntityType for (unsigned int kx = 0; kx < attrTypes.size(); ++kx) { ContextAttribute* ca = new ContextAttribute(attrName, attrTypes[kx], ""); - responseP->entityType.contextAttributeVector.push_back(ca); - - // For backward compability, NGSIv1 only accepts one element - if (apiVersion == V1) - { - break; - } } } else @@ -875,7 +849,7 @@ HttpStatusCode mongoAttributesForEntityType if (docs == 0) { - responseP->statusCode.fill(SccContextElementNotFound); + responseP->error.fill(SccContextElementNotFound); reqSemGive(__FUNCTION__, "query types request", reqSemTaken); return SccOk; @@ -888,11 +862,11 @@ HttpStatusCode mongoAttributesForEntityType if (count) { snprintf(detailsMsg, sizeof(detailsMsg), "Count: %d", (int) docs); - responseP->statusCode.fill(SccOk, detailsMsg); + responseP->error.fill(SccOk, detailsMsg); } else { - responseP->statusCode.fill(SccOk); + responseP->error.fill(SccOk); } } else @@ -900,11 +874,11 @@ HttpStatusCode mongoAttributesForEntityType if (count) { snprintf(detailsMsg, sizeof(detailsMsg), "Number of attributes: %d. Offset is %u", docs, offset); - responseP->statusCode.fill(SccContextElementNotFound, detailsMsg); + responseP->error.fill(SccContextElementNotFound, detailsMsg); } else { - responseP->statusCode.fill(SccContextElementNotFound); + responseP->error.fill(SccContextElementNotFound); } } diff --git a/src/lib/mongoBackend/mongoQueryTypes.h b/src/lib/mongoBackend/mongoQueryTypes.h index d0f0dfca3d..a3e90b375c 100644 --- a/src/lib/mongoBackend/mongoQueryTypes.h +++ b/src/lib/mongoBackend/mongoQueryTypes.h @@ -61,7 +61,6 @@ extern HttpStatusCode mongoEntityTypes const std::string& tenant, const std::vector& servicePathV, std::map& uriParams, - ApiVersion apiVersion, unsigned int* totalTypesP, bool noAttrDetail ); @@ -94,8 +93,7 @@ extern HttpStatusCode mongoAttributesForEntityType const std::string& tenant, const std::vector& servicePathV, std::map& uriParams, - bool noAttrDetail, - ApiVersion apiVersion + bool noAttrDetail ); #endif // SRC_LIB_MONGOBACKEND_MONGOQUERYTYPES_H_ diff --git a/src/lib/mongoBackend/mongoRegisterContext.cpp b/src/lib/mongoBackend/mongoRegisterContext.cpp deleted file mode 100644 index 0771048b70..0000000000 --- a/src/lib/mongoBackend/mongoRegisterContext.cpp +++ /dev/null @@ -1,112 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Fermin Galan Marquez -*/ -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" -#include "common/globals.h" -#include "common/statistics.h" -#include "common/sem.h" -#include "common/defaultValues.h" -#include "alarmMgr/alarmMgr.h" -#include "ngsi/StatusCode.h" -#include "ngsi9/RegisterContextRequest.h" -#include "ngsi9/RegisterContextResponse.h" - -#include "mongoBackend/MongoGlobal.h" -#include "mongoBackend/MongoCommonRegister.h" -#include "mongoBackend/dbConstants.h" -#include "mongoBackend/mongoRegisterContext.h" - -#include "mongoDriver/safeMongo.h" -#include "mongoDriver/connectionOperations.h" -#include "mongoDriver/BSONObjBuilder.h" - - - -/* **************************************************************************** -* -* mongoRegisterContext - -*/ -HttpStatusCode mongoRegisterContext -( - RegisterContextRequest* requestP, - RegisterContextResponse* responseP, - std::map& uriParam, - const std::string& fiwareCorrelator, - const std::string& tenant, - const std::string& servicePath -) -{ - bool reqSemTaken; - - // FIXME P4: See issue #3078 - std::string sPath = (servicePath.empty())? SERVICE_PATH_ROOT : servicePath; - - reqSemTake(__FUNCTION__, "ngsi9 register request", SemWriteOp, &reqSemTaken); - - /* Check if new registration */ - if (requestP->registrationId.isEmpty()) - { - HttpStatusCode result = processRegisterContext(requestP, responseP, NULL, tenant, sPath, "JSON", fiwareCorrelator); - - reqSemGive(__FUNCTION__, "ngsi9 register request", reqSemTaken); - return result; - } - - /* It is not a new registration, so it must be an update */ - orion::BSONObj reg; - std::string err; - orion::OID id = orion::OID(requestP->registrationId.get()); - - orion::BSONObjBuilder bob; - bob.append("_id", id); - bob.append(REG_SERVICE_PATH, sPath); - - if (!orion::collectionFindOne(composeDatabaseName(tenant), COL_REGISTRATIONS, bob.obj(), ®, &err) && (err != "")) - { - reqSemGive(__FUNCTION__, "ngsi9 register request", reqSemTaken); - responseP->errorCode.fill(SccReceiverInternalError, err); - ++noOfRegistrationUpdateErrors; - - return SccOk; - } - - if (reg.isEmpty()) - { - reqSemGive(__FUNCTION__, "ngsi9 register request (no registrations found)", reqSemTaken); - responseP->errorCode.fill(SccContextElementNotFound, - std::string("registration id: /") + requestP->registrationId.get() + "/"); - responseP->registrationId = requestP->registrationId; - ++noOfRegistrationUpdateErrors; - - return SccOk; - } - - HttpStatusCode result = processRegisterContext(requestP, responseP, &id, tenant, sPath, "JSON", fiwareCorrelator); - reqSemGive(__FUNCTION__, "ngsi9 register request", reqSemTaken); - return result; -} diff --git a/src/lib/mongoBackend/mongoRegisterContext.h b/src/lib/mongoBackend/mongoRegisterContext.h deleted file mode 100644 index c3ac46be1f..0000000000 --- a/src/lib/mongoBackend/mongoRegisterContext.h +++ /dev/null @@ -1,51 +0,0 @@ -#ifndef SRC_LIB_MONGOBACKEND_MONGOREGISTERCONTEXT_H_ -#define SRC_LIB_MONGOBACKEND_MONGOREGISTERCONTEXT_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Fermin Galan Marquez -*/ -#include -#include - -#include "rest/HttpStatusCode.h" -#include "ngsi9/RegisterContextRequest.h" -#include "ngsi9/RegisterContextResponse.h" - - - -/* **************************************************************************** -* -* mongoRegisterContext - -*/ -extern HttpStatusCode mongoRegisterContext -( - RegisterContextRequest* requestP, - RegisterContextResponse* responseP, - std::map& uriParam, - const std::string& fiwareCorrelator = "no correlator", - const std::string& tenant = "", - const std::string& servicePath = "" -); - -#endif // SRC_LIB_MONGOBACKEND_MONGOREGISTERCONTEXT_H_ diff --git a/src/lib/mongoBackend/mongoRegistrationCreate.cpp b/src/lib/mongoBackend/mongoRegistrationCreate.cpp index fa17c450ea..d83017688d 100644 --- a/src/lib/mongoBackend/mongoRegistrationCreate.cpp +++ b/src/lib/mongoBackend/mongoRegistrationCreate.cpp @@ -115,7 +115,7 @@ static void setContextRegistrationVector(ngsiv2::Registration* regP, orion::BSON for (unsigned int eIx = 0; eIx < regP->dataProvided.entities.size(); ++eIx) { - ngsiv2::EntID* eP = ®P->dataProvided.entities[eIx]; + EntityId* eP = ®P->dataProvided.entities[eIx]; orion::BSONObjBuilder bob; if (eP->idPattern.empty()) diff --git a/src/lib/mongoBackend/mongoRegistrationGet.cpp b/src/lib/mongoBackend/mongoRegistrationGet.cpp index 41e677ac77..dbafb69191 100644 --- a/src/lib/mongoBackend/mongoRegistrationGet.cpp +++ b/src/lib/mongoBackend/mongoRegistrationGet.cpp @@ -45,202 +45,6 @@ -/* **************************************************************************** -* -* setRegistrationId - -*/ -static void setRegistrationId(ngsiv2::Registration* regP, const orion::BSONObj& r) -{ - regP->id = getFieldF(r, "_id").OID(); -} - - - -/* **************************************************************************** -* -* setDescription - -*/ -static void setDescription(ngsiv2::Registration* regP, const orion::BSONObj& r) -{ - if (r.hasField(REG_DESCRIPTION)) - { - regP->description = getStringFieldF(r, REG_DESCRIPTION); - regP->descriptionProvided = true; - } - else - { - regP->description = ""; - regP->descriptionProvided = false; - } -} - - - -/* **************************************************************************** -* -* setProvider - -*/ -static void setProvider(ngsiv2::Registration* regP, const ngsiv2::ForwardingMode forwardingMode, const std::string& format, const orion::BSONObj& r) -{ - regP->provider.http.url = (r.hasField(REG_PROVIDING_APPLICATION))? getStringFieldF(r, REG_PROVIDING_APPLICATION): ""; - - regP->provider.supportedForwardingMode = forwardingMode; - - if (format == "JSON") - { - __sync_fetch_and_add(&noOfDprLegacyForwarding, 1); - if (logDeprecate) - { - LM_W(("Deprecated usage of legacyForwarding mode detected in existing registration (regId: %s)", regP->id.c_str())); - } - regP->provider.legacyForwardingMode = true; - } - else - { - regP->provider.legacyForwardingMode = false; - } -} - - - -/* **************************************************************************** -* -* setEntities - -*/ -static void setEntities(ngsiv2::Registration* regP, const orion::BSONObj& cr0) -{ - std::vector dbEntityV = getFieldF(cr0, REG_ENTITIES).Array(); - - for (unsigned int ix = 0; ix < dbEntityV.size(); ++ix) - { - ngsiv2::EntID entity; - orion::BSONObj ce = dbEntityV[ix].embeddedObject(); - - if (ce.hasField(REG_ENTITY_ISPATTERN)) - { - std::string isPattern = getStringFieldF(ce, REG_ENTITY_ISPATTERN); - - if (isPattern == "true") - { - entity.idPattern = getStringFieldF(ce, REG_ENTITY_ID); - } - else - { - entity.id = getStringFieldF(ce, REG_ENTITY_ID); - } - } - else - { - entity.id = getStringFieldF(ce, REG_ENTITY_ID); - } - - if (ce.hasField(REG_ENTITY_ISTYPEPATTERN)) - { - std::string isPattern = getStringFieldF(ce, REG_ENTITY_ISTYPEPATTERN); - - if (isPattern == "true") - { - entity.typePattern = getStringFieldF(ce, REG_ENTITY_TYPE); - } - else - { - entity.type = getStringFieldF(ce, REG_ENTITY_TYPE); - } - } - else - { - entity.type = getStringFieldF(ce, REG_ENTITY_TYPE); - } - - regP->dataProvided.entities.push_back(entity); - } -} - - - -/* **************************************************************************** -* -* setAttributes - -*/ -static void setAttributes(ngsiv2::Registration* regP, const orion::BSONObj& cr0) -{ - std::vector dbAttributeV = getFieldF(cr0, REG_ATTRS).Array(); - - for (unsigned int ix = 0; ix < dbAttributeV.size(); ++ix) - { - orion::BSONObj aobj = dbAttributeV[ix].embeddedObject(); - std::string attrName = getStringFieldF(aobj, REG_ATTRS_NAME); - - if (!attrName.empty()) - { - regP->dataProvided.attributes.push_back(attrName); - } - } -} - - - -/* **************************************************************************** -* -* setDataProvided - -* -* Make sure there is only ONE "contextRegistration" in the vector -* If we have more than one, then the Registration is made in API V1 as this is not -* possible in V2 and we cannot respond to the request using the current implementation of V2. -* This function will be changed to work in a different way once issue #3044 is dealt with. -*/ -static bool setDataProvided(ngsiv2::Registration* regP, const orion::BSONObj& r, bool arrayAllowed) -{ - std::vector crV = getFieldF(r, REG_CONTEXT_REGISTRATION).Array(); - - if (crV.size() > 1) - { - return false; - } - - // Get the forwarding mode to be used later in setProvider() - ngsiv2::ForwardingMode forwardingMode = - ngsiv2::stringToForwardingMode(r.hasField(REG_FORWARDING_MODE)? getStringField(r, REG_FORWARDING_MODE) : "all"); - - // Get the format to be used later in setProvider() - std::string format = r.hasField(REG_FORMAT)? getStringFieldF(r, REG_FORMAT) : "JSON"; - - // - // Extract the first (and only) CR from the contextRegistration vector - // - orion::BSONObj cr0 = crV[0].embeddedObject(); - - setEntities(regP, cr0); - setAttributes(regP, cr0); - setProvider(regP, forwardingMode, format, cr0); - - return true; -} - - - -/* **************************************************************************** -* -* setExpires - -*/ -static void setExpires(ngsiv2::Registration* regP, const orion::BSONObj& r) -{ - regP->expires = (r.hasField(REG_EXPIRATION))? getIntOrLongFieldAsLongF(r, REG_EXPIRATION) : -1; -} - - - -/* **************************************************************************** -* -* setStatus - -*/ -static void setStatus(ngsiv2::Registration* regP, const orion::BSONObj& r) -{ - regP->status = (r.hasField(REG_STATUS))? getStringFieldF(r, REG_STATUS): ""; -} - - - /* **************************************************************************** * * mongoRegistrationGet - @@ -294,20 +98,15 @@ void mongoRegistrationGet // // Fill in the Registration with data retrieved from the data base // - setRegistrationId(regP, r); - setDescription(regP, r); - - if (setDataProvided(regP, r, false) == false) + if (!regP->fromBson(r)) { + // FIXME #4611: this check will be no longer needed after fixing the issue. fromBson return type could be changed to void orion::releaseMongoConnection(connection); - LM_W(("Bad Input (getting registrations with more than one CR is not yet implemented, see issue 3044)")); + LM_E(("Runtime Error (registrations with more than one CR are considered runtime errors since Orion 4.1.0, please fix reg %s at DB)", regP->id.c_str())); reqSemGive(__FUNCTION__, "Mongo Get Registration", reqSemTaken); oeP->fill(SccReceiverInternalError, err); return; } - - setExpires(regP, r); - setStatus(regP, r); } else { @@ -345,7 +144,7 @@ void mongoRegistrationsGet bool reqSemTaken = false; std::string err; orion::OID oid; - StatusCode sc; + OrionError oe; std::string servicePath = (servicePathV.size() == 0)? "/#" : servicePathV[0]; // FIXME P4: see #3100 reqSemTake(__FUNCTION__, "Mongo Get Registrations", SemReadOp, &reqSemTaken); @@ -392,21 +191,16 @@ void mongoRegistrationsGet // // Fill in the Registration with data retrieved from the data base // - setRegistrationId(®, r); - setDescription(®, r); - - if (setDataProvided(®, r, false) == false) + if (!reg.fromBson(r)) { + // FIXME #4611: this check will be no longer needed after fixing the issue. fromBson return type could be changed to void orion::releaseMongoConnection(connection); - LM_W(("Bad Input (getting registrations with more than one CR is not yet implemented, see issue 3044)")); + LM_E(("Runtime Error (registrations with more than one CR are considered runtime errors since Orion 4.1.0, please fix reg %s at DB)", reg.id.c_str())); reqSemGive(__FUNCTION__, "Mongo Get Registrations", reqSemTaken); oeP->fill(SccReceiverInternalError, err); return; } - setExpires(®, r); - setStatus(®, r); - regV->push_back(reg); } diff --git a/src/lib/mongoBackend/mongoSubCache.cpp b/src/lib/mongoBackend/mongoSubCache.cpp index dbf10cb6ea..f9516aeb65 100644 --- a/src/lib/mongoBackend/mongoSubCache.cpp +++ b/src/lib/mongoBackend/mongoSubCache.cpp @@ -97,9 +97,7 @@ int mongoSubCacheItemInsert(const char* tenant, const orion::BSONObj& sub) // // 04. Extract data from subP // - // NOTE: NGSIv1 JSON is 'default' (for old db-content) - // - std::string renderFormatString = sub.hasField(CSUB_FORMAT)? getStringFieldF(sub, CSUB_FORMAT) : "legacy"; + std::string renderFormatString = sub.hasField(CSUB_FORMAT)? getStringFieldF(sub, CSUB_FORMAT) : "normalized"; RenderFormat renderFormat = stringToRenderFormat(renderFormatString); cSubP->tenant = (tenant[0] == 0)? strdup("") : strdup(tenant); @@ -395,8 +393,6 @@ int mongoSubCacheItemInsert // 04. Extract data from subP // - // NOTE: NGSIv1 JSON is 'default' (for old db-content) - // cSubP->tenant = (tenant[0] == 0)? NULL : strdup(tenant); cSubP->subscriptionId = strdup(subscriptionId); cSubP->servicePath = strdup(servicePath); diff --git a/src/lib/mongoBackend/mongoSubscribeContext.cpp b/src/lib/mongoBackend/mongoSubscribeContext.cpp deleted file mode 100644 index 966d72d156..0000000000 --- a/src/lib/mongoBackend/mongoSubscribeContext.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Fermin Galan Marquez -*/ -#include -#include - -#include "rest/OrionError.h" -#include "ngsi/Duration.h" -#include "ngsi10/SubscribeContextRequest.h" -#include "ngsi10/SubscribeContextResponse.h" -#include "apiTypesV2/Subscription.h" - -#include "mongoBackend/mongoCreateSubscription.h" -#include "mongoBackend/mongoSubscribeContext.h" - - - -/* **************************************************************************** -* -* mongoSubscribeContext - -*/ -HttpStatusCode mongoSubscribeContext -( - SubscribeContextRequest* requestP, - SubscribeContextResponse* responseP, - const std::string& tenant, - const std::vector& servicePathV -) -{ - OrionError oe; - ngsiv2::Subscription sub; - - requestP->toNgsiv2Subscription(&sub); - std::string subId = mongoCreateSubscription(sub, &oe, tenant, servicePathV); - - if (!subId.empty()) - { - if (requestP->duration.isEmpty()) - { - responseP->subscribeResponse.duration.set(DEFAULT_DURATION); - } - else - { - responseP->subscribeResponse.duration = requestP->duration; - } - responseP->subscribeResponse.subscriptionId.set(subId); - responseP->subscribeResponse.throttling = requestP->throttling; - } - else - { - // Check OrionError - responseP->subscribeError.errorCode.fill(oe.code, oe.description); - } - - // free sub memory associated to subscription - sub.release(); - - return SccOk; -} diff --git a/src/lib/mongoBackend/mongoSubscribeContext.h b/src/lib/mongoBackend/mongoSubscribeContext.h deleted file mode 100644 index 417dccab16..0000000000 --- a/src/lib/mongoBackend/mongoSubscribeContext.h +++ /dev/null @@ -1,49 +0,0 @@ -#ifndef SRC_LIB_MONGOBACKEND_MONGOSUBSCRIBECONTEXT_H_ -#define SRC_LIB_MONGOBACKEND_MONGOSUBSCRIBECONTEXT_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Fermin Galan Marquez -*/ -#include -#include - -#include "rest/HttpStatusCode.h" -#include "ngsi10/SubscribeContextRequest.h" -#include "ngsi10/SubscribeContextResponse.h" - - - -/* **************************************************************************** -* -* mongoSubscribeContext - -*/ -extern HttpStatusCode mongoSubscribeContext -( - SubscribeContextRequest* requestP, - SubscribeContextResponse* responseP, - const std::string& tenant, - const std::vector& servicePathV -); - -#endif // SRC_LIB_MONGOBACKEND_MONGOSUBSCRIBECONTEXT_H_ diff --git a/src/lib/mongoBackend/mongoUnsubscribeContext.cpp b/src/lib/mongoBackend/mongoUnsubscribeContext.cpp index bd023474a9..ffd5646d63 100644 --- a/src/lib/mongoBackend/mongoUnsubscribeContext.cpp +++ b/src/lib/mongoBackend/mongoUnsubscribeContext.cpp @@ -35,8 +35,6 @@ #include "mongoBackend/dbConstants.h" #include "mongoBackend/mongoUnsubscribeContext.h" #include "cache/subCache.h" -#include "ngsi10/UnsubscribeContextRequest.h" -#include "ngsi10/UnsubscribeContextResponse.h" #include "mongoDriver/safeMongo.h" #include "mongoDriver/connectionOperations.h" @@ -50,28 +48,22 @@ */ HttpStatusCode mongoUnsubscribeContext ( - UnsubscribeContextRequest* requestP, - UnsubscribeContextResponse* responseP, - const std::string& tenant + const std::string& subId, + OrionError* responseP, + const std::string& tenant ) { bool reqSemTaken; std::string err; - reqSemTake(__FUNCTION__, "ngsi10 unsubscribe request", SemWriteOp, &reqSemTaken); + reqSemTake(__FUNCTION__, "unsubscribe request", SemWriteOp, &reqSemTaken); LM_T(LmtMongo, ("Unsubscribe Context")); - /* No matter if success or failure, the subscriptionId in the response is always the one - * in the request - */ - responseP->subscriptionId = requestP->subscriptionId; - - if (responseP->subscriptionId.get().empty()) + if (subId.empty()) { - reqSemGive(__FUNCTION__, "ngsi10 unsubscribe request (no subscriptions found)", reqSemTaken); - responseP->statusCode.fill(SccContextElementNotFound); - responseP->oe.fill(SccContextElementNotFound, ERROR_DESC_NOT_FOUND_SUBSCRIPTION, ERROR_NOT_FOUND); + reqSemGive(__FUNCTION__, "unsubscribe request (no subscriptions found)", reqSemTaken); + responseP->fill(SccContextElementNotFound, ERROR_DESC_NOT_FOUND_SUBSCRIPTION, ERROR_NOT_FOUND); alarmMgr.badInput(clientIp, "no subscriptionId"); return SccOk; @@ -79,28 +71,24 @@ HttpStatusCode mongoUnsubscribeContext /* Look for document */ orion::BSONObj sub; - orion::OID id = orion::OID(requestP->subscriptionId.get()); + orion::OID id = orion::OID(subId); orion::BSONObjBuilder bobId; bobId.append("_id", id); if (!orion::collectionFindOne(composeDatabaseName(tenant), COL_CSUBS, bobId.obj(), &sub, &err) && (err != "")) { - reqSemGive(__FUNCTION__, "ngsi10 unsubscribe request (mongo db exception)", reqSemTaken); - - responseP->statusCode.fill(SccReceiverInternalError, err); - responseP->oe.fill(SccReceiverInternalError, err, ERROR_INTERNAL_ERROR); + reqSemGive(__FUNCTION__, "unsubscribe request (mongo db exception)", reqSemTaken); + responseP->fill(SccReceiverInternalError, err, ERROR_INTERNAL_ERROR); return SccOk; } if (sub.isEmpty()) { - reqSemGive(__FUNCTION__, "ngsi10 unsubscribe request (no subscriptions found)", reqSemTaken); - - responseP->statusCode.fill(SccContextElementNotFound); - responseP->oe.fill(SccContextElementNotFound, ERROR_DESC_NOT_FOUND_SUBSCRIPTION, ERROR_NOT_FOUND); + reqSemGive(__FUNCTION__, "unsubscribe request (no subscriptions found)", reqSemTaken); + responseP->fill(SccContextElementNotFound, ERROR_DESC_NOT_FOUND_SUBSCRIPTION, ERROR_NOT_FOUND); return SccOk; } @@ -112,15 +100,13 @@ HttpStatusCode mongoUnsubscribeContext // orion::BSONObjBuilder bobId2; - bobId2.append("_id", orion::OID(requestP->subscriptionId.get())); + bobId2.append("_id", orion::OID(subId)); if (!orion::collectionRemove(composeDatabaseName(tenant), COL_CSUBS, bobId2.obj(), &err)) { - reqSemGive(__FUNCTION__, "ngsi10 unsubscribe request (mongo db exception)", reqSemTaken); - - responseP->statusCode.fill(SccReceiverInternalError, err); - responseP->oe.fill(SccReceiverInternalError, err, ERROR_INTERNAL_ERROR); + reqSemGive(__FUNCTION__, "unsubscribe request (mongo db exception)", reqSemTaken); + responseP->fill(SccReceiverInternalError, err, ERROR_INTERNAL_ERROR); return SccOk; } @@ -130,12 +116,12 @@ HttpStatusCode mongoUnsubscribeContext if (!noCache) { LM_T(LmtSubCache, ("removing subscription '%s' (tenant '%s') from mongo subscription cache", - requestP->subscriptionId.get().c_str(), + subId.c_str(), tenant.c_str())); cacheSemTake(__FUNCTION__, "Removing subscription from cache"); - CachedSubscription* cSubP = subCacheItemLookup(tenant.c_str(), requestP->subscriptionId.get().c_str()); + CachedSubscription* cSubP = subCacheItemLookup(tenant.c_str(), subId.c_str()); if (cSubP != NULL) { @@ -145,8 +131,7 @@ HttpStatusCode mongoUnsubscribeContext cacheSemGive(__FUNCTION__, "Removing subscription from cache"); } - reqSemGive(__FUNCTION__, "ngsi10 unsubscribe request", reqSemTaken); - responseP->statusCode.fill(SccOk); + reqSemGive(__FUNCTION__, "unsubscribe request", reqSemTaken); return SccOk; } diff --git a/src/lib/mongoBackend/mongoUnsubscribeContext.h b/src/lib/mongoBackend/mongoUnsubscribeContext.h index 405b2cc491..24ad591491 100644 --- a/src/lib/mongoBackend/mongoUnsubscribeContext.h +++ b/src/lib/mongoBackend/mongoUnsubscribeContext.h @@ -28,8 +28,6 @@ #include #include "rest/HttpStatusCode.h" -#include "ngsi10/UnsubscribeContextRequest.h" -#include "ngsi10/UnsubscribeContextResponse.h" @@ -39,9 +37,9 @@ */ extern HttpStatusCode mongoUnsubscribeContext ( - UnsubscribeContextRequest* requestP, - UnsubscribeContextResponse* responseP, - const std::string& tenant = "" + const std::string& subId, + OrionError* responseP, + const std::string& tenant = "" ); #endif // SRC_LIB_MONGOBACKEND_MONGOUNSUBSCRIBECONTEXT_H_ diff --git a/src/lib/mongoBackend/mongoUpdateContext.cpp b/src/lib/mongoBackend/mongoUpdateContext.cpp index c280ee6ca9..08f5a04bce 100644 --- a/src/lib/mongoBackend/mongoUpdateContext.cpp +++ b/src/lib/mongoBackend/mongoUpdateContext.cpp @@ -36,7 +36,6 @@ #include "alarmMgr/alarmMgr.h" #include "ngsi10/UpdateContextRequest.h" #include "ngsi10/UpdateContextResponse.h" -#include "ngsi/NotifyCondition.h" #include "rest/HttpStatusCode.h" #include "ngsiNotify/QueueNotifier.h" @@ -115,14 +114,13 @@ HttpStatusCode mongoUpdateContext const std::string& ngsiV2AttrsFormat, const bool& forcedUpdate, const bool& overrideMetadata, - ApiVersion apiVersion, Ngsiv2Flavour ngsiv2Flavour, bool flowControl ) { bool reqSemTaken; - reqSemTake(__FUNCTION__, "ngsi10 update request", SemWriteOp, &reqSemTaken); + reqSemTake(__FUNCTION__, "update request", SemWriteOp, &reqSemTaken); // Initial size of notification queue (could be used by flow control algorithm) unsigned int q0 = 0; @@ -144,8 +142,8 @@ HttpStatusCode mongoUpdateContext std::string details = std::string("service path length ") + lenV + " is greater than the one in update"; alarmMgr.badInput(clientIp, details); - responseP->errorCode.fill(SccBadRequest, "service path length greater than the one in update"); - responseP->oe.fill(SccBadRequest, "service path length greater than the one in update", ERROR_BAD_REQUEST); + responseP->error.fill(SccBadRequest, "service path length greater than the one in update"); + responseP->error.fill(SccBadRequest, "service path length greater than the one in update", ERROR_BAD_REQUEST); } else { @@ -166,7 +164,6 @@ HttpStatusCode mongoUpdateContext forcedUpdate, overrideMetadata, notifSent, - apiVersion, ngsiv2Flavour, &entityUpdateCoverage); switch(updateCoverage) @@ -221,22 +218,26 @@ HttpStatusCode mongoUpdateContext // Other cases follow the usual response processing flow (whatever it is :) if (updateCoverage == UC_PARTIAL) { - responseP->oe.code = SccInvalidModification; - responseP->oe.error = ERROR_PARTIAL_UPDATE; + responseP->error.code = SccInvalidModification; + responseP->error.error = ERROR_PARTIAL_UPDATE; } LM_T(LmtNotifier, ("total notifications sent during update: %d", notifSent)); /* Note that although individual processContextElements() invocations return ConnectionError, this - error gets "encapsulated" in the StatusCode of the corresponding ContextElementResponse and we + error gets "encapsulated" in the OrionError of the corresponding ContextElementResponse and we consider the overall mongoUpdateContext() as OK. + FIXME PR: we are removing the "corresponding ContextElementResposne" error. Review this wording */ - responseP->errorCode.fill(SccOk); + if (responseP->error.code == SccNone) + { + responseP->error.fill(SccOk); + } } - reqSemGive(__FUNCTION__, "ngsi10 update request", reqSemTaken); + reqSemGive(__FUNCTION__, "update request", reqSemTaken); - if (flowControl && fcEnabled && (responseP->errorCode.code == SccOk)) + if (flowControl && fcEnabled && (responseP->error.code == SccOk)) { LM_T(LmtNotifier, ("start notification flow control algorithm")); flowControlAwait(q0, notifSent, tenant); diff --git a/src/lib/mongoBackend/mongoUpdateContext.h b/src/lib/mongoBackend/mongoUpdateContext.h index 40ef1fea6a..71ce4f7aac 100644 --- a/src/lib/mongoBackend/mongoUpdateContext.h +++ b/src/lib/mongoBackend/mongoUpdateContext.h @@ -50,8 +50,7 @@ extern HttpStatusCode mongoUpdateContext const std::string& fiwareCorrelator, const std::string& ngsiV2AttrsFormat, const bool& forcedUpdate = false, - const bool& overrideMetadata = false, - ApiVersion apiVersion = V1, + const bool& overrideMetadata = false, Ngsiv2Flavour ngsiv2Flavour = NGSIV2_NO_FLAVOUR, bool flowControl = false ); diff --git a/src/lib/mongoBackend/mongoUpdateContextSubscription.cpp b/src/lib/mongoBackend/mongoUpdateContextSubscription.cpp deleted file mode 100644 index c27317b76f..0000000000 --- a/src/lib/mongoBackend/mongoUpdateContextSubscription.cpp +++ /dev/null @@ -1,94 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Fermin Galan Marquez -*/ -#include -#include - -#include "rest/OrionError.h" -#include "ngsi10/UpdateContextSubscriptionRequest.h" -#include "ngsi10/UpdateContextSubscriptionResponse.h" -#include "apiTypesV2/SubscriptionUpdate.h" - -#include "mongoBackend/mongoUpdateSubscription.h" -#include "mongoBackend/mongoUpdateContextSubscription.h" - - - -/* **************************************************************************** -* -* mongoUpdateContextSubscription - -*/ -HttpStatusCode mongoUpdateContextSubscription -( - UpdateContextSubscriptionRequest* requestP, - UpdateContextSubscriptionResponse* responseP, - const std::string& tenant, - const std::vector& servicePathV -) -{ - OrionError oe; - ngsiv2::SubscriptionUpdate sub; - - requestP->toNgsiv2Subscription(&sub); - - std::string subId = mongoUpdateSubscription(sub, &oe, tenant, servicePathV); - - if (!subId.empty()) - { - // Duration and throttling are optional parameters, they are only added in the case they were used for update - if (!requestP->duration.isEmpty()) - { - responseP->subscribeResponse.duration = requestP->duration; - } - - if (!requestP->throttling.isEmpty()) - { - responseP->subscribeResponse.throttling = requestP->throttling; - } - - responseP->subscribeResponse.subscriptionId = subId; - } - else - { - // - // Check OrionError. Depending on the kind of error, details are included or not - // in order to have a better backward compatiblity - // - // FIXME: should we? or it is better to modify .test and provide more accurate errors with 'details'? - // - if (oe.code == SccContextElementNotFound) - { - responseP->subscribeError.errorCode.fill(oe.code); - } - else - { - responseP->subscribeError.errorCode.fill(oe.code, oe.description); - } - } - - // free sub memory associated to subscription - sub.release(); - - return SccOk; -} diff --git a/src/lib/mongoBackend/mongoUpdateContextSubscription.h b/src/lib/mongoBackend/mongoUpdateContextSubscription.h deleted file mode 100644 index c52252ebd6..0000000000 --- a/src/lib/mongoBackend/mongoUpdateContextSubscription.h +++ /dev/null @@ -1,49 +0,0 @@ -#ifndef SRC_LIB_MONGOBACKEND_MONGOUPDATECONTEXTSUBSCRIPTION_H_ -#define SRC_LIB_MONGOBACKEND_MONGOUPDATECONTEXTSUBSCRIPTION_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Fermin Galan Marquez -*/ -#include -#include - -#include "rest/HttpStatusCode.h" -#include "ngsi10/UpdateContextSubscriptionRequest.h" -#include "ngsi10/UpdateContextSubscriptionResponse.h" - - - -/* **************************************************************************** -* -* mongoUpdateContextSubscription - -*/ -extern HttpStatusCode mongoUpdateContextSubscription -( - UpdateContextSubscriptionRequest* requestP, - UpdateContextSubscriptionResponse* responseP, - const std::string& tenant, - const std::vector& servicePathV -); - -#endif // SRC_LIB_MONGOBACKEND_MONGOUPDATECONTEXTSUBSCRIPTION_H_ diff --git a/src/lib/mongoBackend/mongoUpdateSubscription.cpp b/src/lib/mongoBackend/mongoUpdateSubscription.cpp index 134a9910e4..2fbf89a989 100644 --- a/src/lib/mongoBackend/mongoUpdateSubscription.cpp +++ b/src/lib/mongoBackend/mongoUpdateSubscription.cpp @@ -54,7 +54,6 @@ using ngsiv2::HttpInfo; using ngsiv2::Subscription; using ngsiv2::SubscriptionUpdate; -using ngsiv2::EntID; /* **************************************************************************** @@ -149,22 +148,22 @@ static void updateInCache // // StringFilter in Scope? // - // Any Scope of type SCOPE_TYPE_SIMPLE_QUERY in subUp.restriction.scopeVector? + // Any Scope of type SCOPE_TYPE_SIMPLE_QUERY in subUp.scopeVector? // If so, set it as string filter to the sub-cache item // StringFilter* stringFilterP = NULL; StringFilter* mdStringFilterP = NULL; - for (unsigned int ix = 0; ix < subUp.restriction.scopeVector.size(); ++ix) + for (unsigned int ix = 0; ix < subUp.scopeVector.size(); ++ix) { - if (subUp.restriction.scopeVector[ix]->type == SCOPE_TYPE_SIMPLE_QUERY) + if (subUp.scopeVector[ix]->type == SCOPE_TYPE_SIMPLE_QUERY) { - stringFilterP = subUp.restriction.scopeVector[ix]->stringFilterP; + stringFilterP = subUp.scopeVector[ix]->stringFilterP; } - if (subUp.restriction.scopeVector[ix]->type == SCOPE_TYPE_SIMPLE_QUERY_MD) + if (subUp.scopeVector[ix]->type == SCOPE_TYPE_SIMPLE_QUERY_MD) { - mdStringFilterP = subUp.restriction.scopeVector[ix]->mdStringFilterP; + mdStringFilterP = subUp.scopeVector[ix]->mdStringFilterP; } } @@ -353,7 +352,7 @@ std::string mongoUpdateSubscription setServicePath(servicePath, &setB); - if (subUp.subjectProvided) setEntities(subUp, &setB, subUp.fromNgsiv1); + if (subUp.subjectProvided) setEntities(subUp, &setB); if (subUp.subjectProvided) setConds(subUp, &setB); if (subUp.subjectProvided) setOperations(subUp, &setB); if (subUp.subjectProvided) setExpression(subUp, &setB); diff --git a/src/lib/mongoDriver/safeMongo.h b/src/lib/mongoDriver/safeMongo.h index fc196a721d..f6a7f61f4d 100644 --- a/src/lib/mongoDriver/safeMongo.h +++ b/src/lib/mongoDriver/safeMongo.h @@ -28,9 +28,7 @@ #include #include -#include "ngsi/SubscriptionId.h" -#include "ngsi/RegistrationId.h" -#include "ngsi/StatusCode.h" +#include "rest/OrionError.h" #include "mongoDriver/DBCursor.h" #include "mongoDriver/BSONObj.h" diff --git a/src/lib/ngsi/AttributeExpression.cpp b/src/lib/ngsi/AttributeExpression.cpp deleted file mode 100644 index d6d6c1d828..0000000000 --- a/src/lib/ngsi/AttributeExpression.cpp +++ /dev/null @@ -1,119 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/globals.h" -#include "common/tag.h" -#include "ngsi/Request.h" -#include "ngsi/AttributeExpression.h" - - -/* **************************************************************************** -* -* AttributeExpression::check - -*/ -std::string AttributeExpression::check(void) -{ - return "OK"; -} - - - -/* **************************************************************************** -* -* AttributeExpression::isEmpty - -*/ -bool AttributeExpression::isEmpty(void) -{ - if (string.empty()) - { - return true; - } - - return false; -} - - - -/* **************************************************************************** -* -* AttributeExpression::set - -*/ -void AttributeExpression::set(const std::string& value) -{ - string = value; -} - - - -/* **************************************************************************** -* -* AttributeExpression::get - -*/ -std::string AttributeExpression::get(void) -{ - return string; -} - - - -/* **************************************************************************** -* -* AttributeExpression::toJsonV1 - -*/ -std::string AttributeExpression::toJsonV1(bool comma) -{ - if (string.empty()) - { - return ""; - } - - return valueTag("attributeExpression", string, comma); -} - - - -/* **************************************************************************** -* -* AttributeExpression::c_str - -*/ -const char* AttributeExpression::c_str(void) -{ - return string.c_str(); -} - - - -/* **************************************************************************** -* -* AttributeExpression::release - -*/ -void AttributeExpression::release(void) -{ - /* This method is included for the sake of homogeneity */ -} diff --git a/src/lib/ngsi/AttributeExpression.h b/src/lib/ngsi/AttributeExpression.h deleted file mode 100644 index 5a642607b1..0000000000 --- a/src/lib/ngsi/AttributeExpression.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef SRC_LIB_NGSI_ATTRIBUTEEXPRESSION_H_ -#define SRC_LIB_NGSI_ATTRIBUTEEXPRESSION_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include - -#include "ngsi/Request.h" - - - -/* **************************************************************************** -* -* AttributeExpression - -*/ -typedef struct AttributeExpression -{ - std::string string; - - void set(const std::string& value); - std::string get(void); - bool isEmpty(void); - std::string toJsonV1(bool comma); - const char* c_str(); - void release(void); - - std::string check(void); -} AttributeExpression; - -#endif // SRC_LIB_NGSI_ATTRIBUTEEXPRESSION_H_ diff --git a/src/lib/ngsi/CMakeLists.txt b/src/lib/ngsi/CMakeLists.txt index 52a4d8bcf2..96cac53083 100644 --- a/src/lib/ngsi/CMakeLists.txt +++ b/src/lib/ngsi/CMakeLists.txt @@ -21,75 +21,31 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.0) SET (SOURCES - AttributeExpression.cpp - ConditionValueList.cpp ContextAttribute.cpp ContextAttributeVector.cpp ContextElementResponse.cpp ContextElementResponseVector.cpp - ContextRegistration.cpp - ContextRegistrationVector.cpp - ContextRegistrationAttribute.cpp - ContextRegistrationAttributeVector.cpp - ContextRegistrationResponse.cpp - ContextRegistrationResponseVector.cpp - Duration.cpp EntityId.cpp EntityIdVector.cpp Metadata.cpp MetadataVector.cpp - NotifyCondition.cpp - NotifyConditionVector.cpp - Originator.cpp - ProvidingApplication.cpp - Reference.cpp - RegistrationId.cpp Request.cpp - Restriction.cpp - RestrictionString.cpp Scope.cpp ScopeVector.cpp - StatusCode.cpp StringList.cpp - SubscribeResponse.cpp - SubscribeError.cpp - SubscriptionId.cpp - Throttling.cpp ) SET (HEADERS - AttributeExpression.h - ConditionValueList.h ContextAttribute.h ContextAttributeVector.h ContextElementResponse.h ContextElementResponseVector.h - ContextRegistrationAttribute.h - ContextRegistrationAttributeVector.h - ContextRegistration.h - ContextRegistrationVector.h - ContextRegistrationResponse.h - ContextRegistrationResponseVector.h - Duration.h EntityId.h EntityIdVector.h Metadata.h MetadataVector.h - NotifyCondition.h - NotifyConditionVector.h - Originator.h - ProvidingApplication.h - Reference.h - RegistrationId.h - Restriction.h - RestrictionString.h Scope.h - StatusCode.h StringList.h - SubscribeError.h - SubscribeResponse.h - SubscriptionId.h - Throttling.h ) diff --git a/src/lib/ngsi/ConditionValueList.cpp b/src/lib/ngsi/ConditionValueList.cpp deleted file mode 100644 index 2062cb0597..0000000000 --- a/src/lib/ngsi/ConditionValueList.cpp +++ /dev/null @@ -1,143 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/globals.h" -#include "common/tag.h" -#include "ngsi/ConditionValueList.h" - - - -/* **************************************************************************** -* -* toJsonV1 - -*/ -std::string ConditionValueList::toJsonV1(bool comma) -{ - std::string out = ""; - - if (vec.size() == 0) - { - return ""; - } - - out += startTag("condValueList", true); - - for (unsigned int ix = 0; ix < vec.size(); ++ix) - { - out += valueTag("", vec[ix], ix != vec.size() - 1, true); - } - - out += endTag(comma, true); - - return out; -} - - - -/* **************************************************************************** -* -* ConditionValueList::check - -*/ -std::string ConditionValueList::check(void) -{ - for (unsigned int ix = 0; ix < vec.size(); ++ix) - { - if (vec[ix].empty()) - { - return "empty condValue name"; - } - } - - return "OK"; -} - - - -/* **************************************************************************** -* -* ConditionValueList::release - -*/ -void ConditionValueList::release(void) -{ - vec.clear(); -} - - - -/* **************************************************************************** -* -* push_back - -*/ -void ConditionValueList::push_back(const std::string& attributeName) -{ - vec.push_back(attributeName); -} - - - -/* **************************************************************************** -* -* ConditionValueList::size - -*/ -unsigned int ConditionValueList::size(void) -{ - return vec.size(); -} - - - -/* **************************************************************************** -* -* ConditionValueList::operator -*/ -std::string ConditionValueList::operator[] (unsigned int ix) const -{ - if (ix < vec.size()) - { - return vec[ix]; - } - - return ""; -} - - - -/* **************************************************************************** -* -* ConditionValueList::fill - -*/ -void ConditionValueList::fill(ConditionValueList& list) -{ - for (unsigned int cvIx = 0; cvIx < list.size(); ++cvIx) - { - push_back(list[cvIx]); - } -} diff --git a/src/lib/ngsi/ConditionValueList.h b/src/lib/ngsi/ConditionValueList.h deleted file mode 100644 index c3fd9cd8fb..0000000000 --- a/src/lib/ngsi/ConditionValueList.h +++ /dev/null @@ -1,57 +0,0 @@ -#ifndef SRC_LIB_NGSI_CONDITIONVALUELIST_H_ -#define SRC_LIB_NGSI_CONDITIONVALUELIST_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "ngsi/Metadata.h" -#include "ngsi/Request.h" - - - -/* **************************************************************************** -* -* ConditionValueList - -*/ -typedef struct ConditionValueList -{ - std::vector vec; - - std::string toJsonV1(bool comma); - void release(void); - void push_back(const std::string& attributeName); - unsigned int size(void); - void fill(ConditionValueList& cvlP); - - std::string check(void); - - std::string operator[] (unsigned int ix) const; - - -} ConditionValueList; - -#endif // SRC_LIB_NGSI_CONDITIONVALUELIST_H_ diff --git a/src/lib/ngsi/ContextAttribute.cpp b/src/lib/ngsi/ContextAttribute.cpp index 0fc57e3053..92901c33b4 100644 --- a/src/lib/ngsi/ContextAttribute.cpp +++ b/src/lib/ngsi/ContextAttribute.cpp @@ -30,7 +30,6 @@ #include "common/string.h" #include "common/globals.h" -#include "common/tag.h" #include "common/limits.h" #include "common/RenderFormat.h" #include "common/JsonHelper.h" @@ -62,8 +61,7 @@ void ContextAttribute::bsonAppendAttrValue ( const std::string& valueKey, orion::BSONObjBuilder* bsonAttr, - const std::string& attrType, - bool autocast + const std::string& attrType ) const { std::string effectiveStringValue = stringValue; @@ -71,45 +69,6 @@ void ContextAttribute::bsonAppendAttrValue double effectiveNumberValue = numberValue; orion::ValueType effectiveValueType = valueType; - // Checking for ValueTypeString is an additional safety measure (ensuring that the attribute came from NGSIv1 in plain text) - if ((autocast) && (effectiveValueType == orion::ValueTypeString)) - { - // Autocast only for selected attribute types - if ((attrType == DEFAULT_ATTR_NUMBER_TYPE) || (attrType == NUMBER_TYPE_ALT)) - { - if (str2double(effectiveStringValue.c_str(), &effectiveNumberValue)) - { - effectiveValueType = orion::ValueTypeNumber; - } - // Note that if str2double() fails, we keep ValueTypeString and everything works like without autocast - } - if (attrType == DEFAULT_ATTR_BOOL_TYPE) - { - // Note that we cannot use isTrue() or isFalse() functions, as they consider also 0 and 1 as - // valid true/false values and JSON spec mandates exactly true or false - if (effectiveStringValue == "true") - { - effectiveBoolValue = true; - effectiveValueType = orion::ValueTypeBoolean; - } - else if (effectiveStringValue == "false") - { - effectiveBoolValue = false; - effectiveValueType = orion::ValueTypeBoolean; - } - // Note that if above checks fail, we keep ValueTypeString and everything works like without autocast - } - if ((attrType == DATE_TYPE) || (attrType == DATE_TYPE_ALT)) - { - effectiveNumberValue = parse8601Time(effectiveStringValue); - if (effectiveNumberValue != -1) - { - effectiveValueType = orion::ValueTypeNumber; - } - // Note that if parse8601Time() fails, we keep ValueTypeString and everything works like without autocast - } - } - switch (effectiveValueType) { case orion::ValueTypeString: @@ -149,8 +108,7 @@ bool ContextAttribute::calculateOperator ( const std::string& valueKey, orion::CompoundValueNode* upOp, - orion::BSONObjBuilder* bsonAttr, - bool strings2numbers + orion::BSONObjBuilder* bsonAttr ) const { std::string op = upOp->name; @@ -208,7 +166,7 @@ bool ContextAttribute::calculateOperator case orion::ValueTypeVector: case orion::ValueTypeObject: - compoundValueBson(compoundValueP->childV, ba2, strings2numbers); + compoundValueBson(compoundValueP->childV, ba2); ba.append(ba2.arr()); break; @@ -238,7 +196,7 @@ bool ContextAttribute::calculateOperator break; case orion::ValueTypeObject: - compoundValueBson(upOp->childV, bo, strings2numbers); + compoundValueBson(upOp->childV, bo); bsonAttr->append(valueKey, bo.obj()); break; @@ -276,21 +234,19 @@ bool ContextAttribute::valueBson ( const std::string& valueKey, orion::BSONObjBuilder* bsonAttr, - const std::string& attrType, - bool autocast, - bool strings2numbers + const std::string& attrType ) const { if (compoundValueP == NULL) { - bsonAppendAttrValue(valueKey, bsonAttr, attrType, autocast); + bsonAppendAttrValue(valueKey, bsonAttr, attrType); } else { if (compoundValueP->valueType == orion::ValueTypeVector) { orion::BSONArrayBuilder b; - compoundValueBson(compoundValueP->childV, b, strings2numbers); + compoundValueBson(compoundValueP->childV, b); bsonAttr->append(valueKey, b.arr()); } else if (compoundValueP->valueType == orion::ValueTypeObject) @@ -298,7 +254,7 @@ bool ContextAttribute::valueBson // Special processing of update operators if ((compoundValueP->childV.size() > 0) && (isUpdateOperator(compoundValueP->childV[0]->name))) { - if (!calculateOperator(valueKey, compoundValueP->childV[0], bsonAttr, strings2numbers)) + if (!calculateOperator(valueKey, compoundValueP->childV[0], bsonAttr)) { // in this case we return without generating any BSON return false; @@ -307,7 +263,7 @@ bool ContextAttribute::valueBson else { orion::BSONObjBuilder b; - compoundValueBson(compoundValueP->childV, b, strings2numbers); + compoundValueBson(compoundValueP->childV, b); bsonAttr->append(valueKey, b.obj()); } } @@ -383,7 +339,11 @@ ContextAttribute::ContextAttribute() creDate = 0; modDate = 0; - providingApplication.set(""); + provider.http.url = ""; + provider.legacyForwardingMode = false; + provider.supportedForwardingMode = ngsiv2::ForwardAll; + + providerRegId = ""; } @@ -459,9 +419,8 @@ ContextAttribute::ContextAttribute(ContextAttribute* caP, bool useDefaultType, b creDate = caP->creDate; modDate = caP->modDate; - providingApplication.set(caP->providingApplication.get()); - providingApplication.setProviderFormat(caP->providingApplication.getProviderFormat()); - providingApplication.setRegId(caP->providingApplication.getRegId()); + provider = caP->provider; + providerRegId = caP->providerRegId; LM_T(LmtClone, ("Creating a ContextAttribute: compoundValueP at %p for attribute '%s' at %p", compoundValueP, @@ -539,7 +498,11 @@ ContextAttribute::ContextAttribute creDate = 0; modDate = 0; - providingApplication.set(""); + provider.http.url = ""; + provider.legacyForwardingMode = false; + provider.supportedForwardingMode = ngsiv2::ForwardAll; + + providerRegId = ""; } @@ -578,7 +541,11 @@ ContextAttribute::ContextAttribute creDate = 0; modDate = 0; - providingApplication.set(""); + provider.http.url = ""; + provider.legacyForwardingMode = false; + provider.supportedForwardingMode = ngsiv2::ForwardAll; + + providerRegId = ""; } @@ -616,7 +583,11 @@ ContextAttribute::ContextAttribute creDate = 0; modDate = 0; - providingApplication.set(""); + provider.http.url = ""; + provider.legacyForwardingMode = false; + provider.supportedForwardingMode = ngsiv2::ForwardAll; + + providerRegId = ""; } @@ -655,42 +626,11 @@ ContextAttribute::ContextAttribute creDate = 0; modDate = 0; - providingApplication.set(""); -} - - - + provider.http.url = ""; + provider.legacyForwardingMode = false; + provider.supportedForwardingMode = ngsiv2::ForwardAll; -/* **************************************************************************** -* -* ContextAttribute::ContextAttribute - -*/ -ContextAttribute::ContextAttribute -( - const std::string& _name, - const std::string& _type, - orion::CompoundValueNode* _compoundValueP -) -{ - LM_T(LmtClone, ("Creating a ContextAttribute, maintaining a pointer to compound value (at %p)", _compoundValueP)); - - name = _name; - type = _type; - compoundValueP = _compoundValueP->clone(); - numberValue = 0; - found = false; - valueType = orion::ValueTypeObject; // FIXME P6: Could be ValueTypeVector ... - skip = false; - typeGiven = false; - onlyValue = false; - previousValue = NULL; - actionType = ""; - shadowed = false; - - creDate = 0; - modDate = 0; - - providingApplication.set(""); + providerRegId = ""; } @@ -783,222 +723,6 @@ double ContextAttribute::getEvalPriority(void) -/* **************************************************************************** -* -* toJsonV1AsObject - -*/ -std::string ContextAttribute::toJsonV1AsObject -( - RequestType request, - const std::vector& orderedMetadata, - bool comma, - bool omitValue -) -{ - std::string out = ""; - bool commaAfterContextValue = metadataVector.size() != 0; - bool commaAfterType = !omitValue || commaAfterContextValue; - - out += startTag(name, false); - out += valueTag("type", type, commaAfterType); - - if (compoundValueP == NULL) - { - if (omitValue == false) - { - std::string effectiveValue = ""; - bool withoutQuotes = false; - - switch (valueType) - { - case orion::ValueTypeString: - effectiveValue = stringValue; - break; - - case orion::ValueTypeBoolean: - effectiveValue = boolValue? "true" : "false"; - withoutQuotes = true; - break; - - case orion::ValueTypeNumber: - if ((type == DATE_TYPE) || (type == DATE_TYPE_ALT)) - { - effectiveValue = isodate2str(numberValue); - } - else // regular number - { - effectiveValue = double2string(numberValue); - withoutQuotes = true; - } - break; - - case orion::ValueTypeNull: - effectiveValue = "null"; - withoutQuotes = true; - break; - - case orion::ValueTypeNotGiven: - LM_E(("Runtime Error (value not given in compound value)")); - break; - - default: - LM_E(("Runtime Error (unknown value type: %d)", valueType)); - } - - // - // NOTE - // renderAsJsonObject is used in v1 only. - // => we only need to care about stringValue (not boolValue, numberValue nor nullValue) - // - out += valueTag("value", - (request != RtUpdateContextResponse)? effectiveValue : "", - commaAfterContextValue, false, withoutQuotes); - } - } - else - { - out += JSON_STR("value") + ":" + compoundValueP->toJson(); - } - - if (omitValue == false) - { - out += metadataVector.toJsonV1(orderedMetadata, false); - } - - out += endTag(comma); - - return out; -} - - - -/* **************************************************************************** -* -* toJsonV1AsNameString - -*/ -std::string ContextAttribute::toJsonV1AsNameString(bool comma) -{ - std::string out = ""; - - if (comma) - { - out += "\"" + name + "\","; - } - else - { - out += "\"" + name + "\""; - } - - return out; - -} - - - -/* **************************************************************************** -* -* toJsonV1 - -*/ -std::string ContextAttribute::toJsonV1 -( - bool asJsonObject, - RequestType request, - const std::vector& metadataFilter, - bool comma, - bool omitValue -) -{ - // Filter and order metadata - std::vector orderedMetadata; - filterAndOrderMetadata(metadataFilter, &orderedMetadata); - - std::string out = ""; - bool valueRendered = (compoundValueP != NULL) || (omitValue == false) || (request == RtUpdateContextResponse); - bool commaAfterContextValue = orderedMetadata.size() != 0; - bool commaAfterType = valueRendered; - - if (asJsonObject) - { - return toJsonV1AsObject(request, orderedMetadata, comma, omitValue); - } - - out += startTag(); - out += valueTag("name", name, true); // attribute.type is always rendered - out += valueTag("type", type, commaAfterType); - - if (compoundValueP == NULL) - { - if (omitValue == false) - { - std::string effectiveValue = ""; - bool withoutQuotes = false; - - switch (valueType) - { - case orion::ValueTypeString: - effectiveValue = stringValue; - break; - - case orion::ValueTypeBoolean: - effectiveValue = boolValue? "true" : "false"; - withoutQuotes = true; - break; - - case orion::ValueTypeNumber: - if ((type == DATE_TYPE) || (type == DATE_TYPE_ALT)) - { - effectiveValue = isodate2str(numberValue); - } - else // regular number - { - effectiveValue = double2string(numberValue); - withoutQuotes = true; - } - break; - - case orion::ValueTypeNull: - effectiveValue = "null"; - withoutQuotes = true; - break; - - case orion::ValueTypeNotGiven: - LM_E(("Runtime Error (value not given in compound value)")); - break; - - default: - LM_E(("Runtime Error (unknown value type: %d)", valueType)); - } - - out += valueTag("value", - (request != RtUpdateContextResponse)? effectiveValue : "", - commaAfterContextValue, - false, - withoutQuotes); - - } - else if (request == RtUpdateContextResponse) - { - out += valueTag("value", "", commaAfterContextValue); - } - } - else - { - out += JSON_STR("value") + ":" + compoundValueP->toJson(); - - if (commaAfterContextValue) - { - out += ','; - } - } - - out += metadataVector.toJsonV1(orderedMetadata, false); - out += endTag(comma); - - return out; -} - - - /* **************************************************************************** * * ContextAttribute::filterAndOrderMetadata - @@ -1217,7 +941,6 @@ std::string ContextAttribute::toJsonValue(ExprContextObject* exprContextObjectP) */ std::string ContextAttribute::toJsonAsValue ( - ApiVersion apiVersion, // in parameter bool acceptedTextPlain, // in parameter bool acceptedJson, // in parameter MimeType outFormatSelection, // in parameter @@ -1238,14 +961,7 @@ std::string ContextAttribute::toJsonAsValue switch (valueType) { case orion::ValueTypeString: - if (apiVersion == V2) - { - out = '"' + stringValue + '"'; - } - else - { - out = stringValue; - } + out = '"' + stringValue + '"'; break; case orion::ValueTypeNumber: @@ -1381,19 +1097,19 @@ void ContextAttribute::addToContext(ExprContextObject* exprContextObjectP, bool * * ContextAttribute::check - */ -std::string ContextAttribute::check(ApiVersion apiVersion, RequestType requestType, bool relaxForbiddenCheck) +std::string ContextAttribute::check(bool asValue, bool relaxForbiddenCheck) { size_t len; char errorMsg[128]; - if (((apiVersion == V2) && (len = strlen(name.c_str())) < MIN_ID_LEN) && (requestType != EntityAttributeValueRequest)) + if (((len = strlen(name.c_str())) < MIN_ID_LEN) && (!asValue)) { snprintf(errorMsg, sizeof errorMsg, "attribute name length: %zd, min length supported: %d", len, MIN_ID_LEN); alarmMgr.badInput(clientIp, errorMsg, name); return std::string(errorMsg); } - if ((name.empty()) && (requestType != EntityAttributeValueRequest)) + if ((name.empty()) && (!asValue)) { return "missing attribute name"; } @@ -1405,7 +1121,7 @@ std::string ContextAttribute::check(ApiVersion apiVersion, RequestType requestTy return std::string(errorMsg); } - if (forbiddenIdChars(apiVersion, name.c_str())) + if (forbiddenIdCharsV2(name.c_str())) { alarmMgr.badInput(clientIp, "found a forbidden character in the name of an attribute", name); return "Invalid characters in attribute name"; @@ -1419,14 +1135,14 @@ std::string ContextAttribute::check(ApiVersion apiVersion, RequestType requestTy } - if (apiVersion == V2 && (requestType != EntityAttributeValueRequest) && (len = strlen(type.c_str())) < MIN_ID_LEN) + if ((!asValue) && (len = strlen(type.c_str())) < MIN_ID_LEN) { snprintf(errorMsg, sizeof errorMsg, "attribute type length: %zd, min length supported: %d", len, MIN_ID_LEN); alarmMgr.badInput(clientIp, errorMsg, type); return std::string(errorMsg); } - if ((requestType != EntityAttributeValueRequest) && forbiddenIdChars(apiVersion, type.c_str())) + if ((!asValue) && forbiddenIdCharsV2(type.c_str())) { alarmMgr.badInput(clientIp, "found a forbidden character in the type of an attribute", type); return "Invalid characters in attribute type"; @@ -1446,7 +1162,7 @@ std::string ContextAttribute::check(ApiVersion apiVersion, RequestType requestTy } } - return metadataVector.check(apiVersion); + return metadataVector.check(); } @@ -1525,17 +1241,6 @@ std::string ContextAttribute::getValue(void) const -/* **************************************************************************** -* -* clone - -*/ -ContextAttribute* ContextAttribute::clone(void) -{ - return new ContextAttribute(this); -} - - - /* **************************************************************************** * * ContextAttribute::compoundItemExists - diff --git a/src/lib/ngsi/ContextAttribute.h b/src/lib/ngsi/ContextAttribute.h index 63e4551690..ef5d578ef1 100644 --- a/src/lib/ngsi/ContextAttribute.h +++ b/src/lib/ngsi/ContextAttribute.h @@ -30,14 +30,15 @@ #include "common/RenderFormat.h" #include "common/globals.h" +#include "common/MimeType.h" #include "orionTypes/OrionValueType.h" #include "ngsi/MetadataVector.h" #include "ngsi/Request.h" -#include "ngsi/ProvidingApplication.h" #include "parse/CompoundValueNode.h" #include "rest/HttpStatusCode.h" #include "mongoDriver/BSONObjBuilder.h" #include "expressions/ExprContext.h" +#include "apiTypesV2/Registration.h" @@ -52,18 +53,15 @@ typedef struct ContextAttribute std::string type; // Optional MetadataVector metadataVector; // Optional - // - // Value - Optional (FI-WARE changes - MANDATORY in OMA spec) - // Especially for the new convops, value is NOT mandatory - // E.g. /v1/contextTypes - // orion::ValueType valueType; // Type of value: taken from JSON parse std::string stringValue; // "value" as a String double numberValue; // "value" as a Number bool boolValue; // "value" as a Boolean - ProvidingApplication providingApplication; // Not part of NGSI, used internally for CPr forwarding functionality - bool found; // Not part of NGSI, used internally for CPr forwarding functionality (update case) + ngsiv2::Provider provider; // Used internally for CPr forwarding functionality + std::string providerRegId; // Side vector to provider, to hold the reg ids where they come (used for login purposes) + + bool found; // Used internally for CPr forwarding functionality (update case) // It means attribute found either locally or remotely in providing application bool skip; // For internal use in mongoBackend - in case of 'op=append' and the attribute already exists @@ -90,32 +88,17 @@ typedef struct ContextAttribute ContextAttribute(const std::string& _name, const std::string& _type, const std::string& _value, bool _found = true); ContextAttribute(const std::string& _name, const std::string& _type, double _value, bool _found = true); ContextAttribute(const std::string& _name, const std::string& _type, bool _value, bool _found = true); - ContextAttribute(const std::string& _name, const std::string& _type, orion::CompoundValueNode* _compoundValueP); /* Check if attribute means a location */ bool getLocation(orion::BSONObj* attrsP) const; double getEvalPriority(void); - std::string toJsonV1(bool asJsonObject, - RequestType request, - const std::vector& metadataFilter, - bool comma = false, - bool omitValue = false); - - std::string toJsonV1AsObject(RequestType request, - const std::vector& orderedMetadata, - bool comma, - bool omitValue = false); - - std::string toJsonV1AsNameString(bool comma); - std::string toJson(const std::vector& metadataFilter, bool renderNgsiField = false, ExprContextObject* exprContextObjectP = NULL); std::string toJsonValue(ExprContextObject* exprContextObjectP = NULL); - std::string toJsonAsValue(ApiVersion apiVersion, - bool acceptedTextPlain, + std::string toJsonAsValue(bool acceptedTextPlain, bool acceptedJson, MimeType outFormatSelection, MimeType* outMimeTypeP, @@ -129,15 +112,12 @@ typedef struct ContextAttribute /* Used to render attribute value to BSON */ bool valueBson(const std::string& valueKey, orion::BSONObjBuilder* bsonAttr, - const std::string& attrType, - bool autocast, - bool strings2numbers = false) const; + const std::string& attrType) const; /* Helper method to be use in some places wher '%s' is needed */ std::string getValue(void) const; - std::string check(ApiVersion apiVersion, RequestType requestType, bool relaxForbiddenCheck = false); - ContextAttribute* clone(); + std::string check(bool asValue, bool relaxForbiddenCheck = false); bool compoundItemExists(const std::string& compoundPath, orion::CompoundValueNode** compoundItemPP = NULL); private: @@ -146,15 +126,13 @@ typedef struct ContextAttribute void bsonAppendAttrValue(const std::string& valueKey, orion::BSONObjBuilder* bsonAttr, - const std::string& attrType, - bool autocast) const; + const std::string& attrType) const; bool hasIgnoreType(void) const; bool calculateOperator(const std::string& valueKey, orion::CompoundValueNode* upOp, - orion::BSONObjBuilder* bsonAttr, - bool strings2numbers) const; + orion::BSONObjBuilder* bsonAttr) const; } ContextAttribute; diff --git a/src/lib/ngsi/ContextAttributeVector.cpp b/src/lib/ngsi/ContextAttributeVector.cpp index 5a11b4d89e..8ebef692b3 100644 --- a/src/lib/ngsi/ContextAttributeVector.cpp +++ b/src/lib/ngsi/ContextAttributeVector.cpp @@ -31,7 +31,6 @@ #include "logMsg/traceLevels.h" #include "common/globals.h" -#include "common/tag.h" #include "common/string.h" #include "common/RenderFormat.h" #include "common/JsonHelper.h" @@ -119,88 +118,17 @@ std::string ContextAttributeVector::toJsonTypes(void) -/* **************************************************************************** -* -* ContextAttributeVector::toJsonV1 - -* -* FIXME P5: this method doesn't depend on the class object. Should be moved out of the class? -* Maybe included in the Entiy class render logic. -*/ -std::string ContextAttributeVector::toJsonV1 -( - bool asJsonObject, - RequestType request, - const std::vector& orderedAttrs, - const std::vector& metadataFilter, - bool comma, - bool omitValue, - bool attrsAsName -) -{ - std::string out = ""; - - if (orderedAttrs.size() == 0) - { - return ""; - } - - // - // NOTE: - // If the URI parameter 'attributeFormat' is set to 'object', then the attribute vector - // is to be rendered as objects for JSON, and not as a vector. - // - if (asJsonObject) - { - // Note that in the case of attribute as name, we have to use a vector, thus using - // attrsAsName variable as value for isVector parameter - out += startTag("attributes", attrsAsName); - for (unsigned int ix = 0; ix < orderedAttrs.size(); ++ix) - { - bool comma = (ix != orderedAttrs.size() -1); - if (attrsAsName) - { - out += orderedAttrs[ix]->toJsonV1AsNameString(comma); - } - else - { - out += orderedAttrs[ix]->toJsonV1(asJsonObject, request, metadataFilter, comma, omitValue); - } - } - out += endTag(comma, attrsAsName); - } - else - { - out += startTag("attributes", true); - for (unsigned int ix = 0; ix < orderedAttrs.size(); ++ix) - { - if (attrsAsName) - { - out += orderedAttrs[ix]->toJsonV1AsNameString(ix != orderedAttrs.size() - 1); - } - else - { - out += orderedAttrs[ix]->toJsonV1(asJsonObject, request, metadataFilter, ix != orderedAttrs.size() - 1, omitValue); - } - } - out += endTag(comma, true); - } - - return out; -} - - - /* **************************************************************************** * * ContextAttributeVector::check - */ -std::string ContextAttributeVector::check(ApiVersion apiVersion, RequestType requestType) +std::string ContextAttributeVector::check(bool asValue) { for (unsigned int ix = 0; ix < vec.size(); ++ix) { std::string res; - if ((res = vec[ix]->check(apiVersion, requestType)) != "OK") + if ((res = vec[ix]->check(asValue)) != "OK") return res; } @@ -465,8 +393,7 @@ void ContextAttributeVector::toBson ( double now, orion::BSONObjBuilder* attrsToAdd, - orion::BSONArrayBuilder* attrNamesToAdd, - ApiVersion apiVersion + orion::BSONArrayBuilder* attrNamesToAdd ) const { for (unsigned int ix = 0; ix < this->vec.size(); ++ix) @@ -475,7 +402,7 @@ void ContextAttributeVector::toBson std::string attrType; - if (!this->vec[ix]->typeGiven && (apiVersion == V2)) + if (!this->vec[ix]->typeGiven) { if ((this->vec[ix]->compoundValueP == NULL) || (this->vec[ix]->compoundValueP->valueType != orion::ValueTypeVector)) { @@ -502,7 +429,7 @@ void ContextAttributeVector::toBson } // FIXME P7: boolean return value should be managed? - this->vec[ix]->valueBson(std::string(ENT_ATTRS_VALUE), &bsonAttr, attrType, ngsiv1Autocast && (apiVersion == V1)); + this->vec[ix]->valueBson(std::string(ENT_ATTRS_VALUE), &bsonAttr, attrType); std::string effectiveName = dbEncode(this->vec[ix]->name); @@ -515,7 +442,7 @@ void ContextAttributeVector::toBson orion::BSONObjBuilder md; orion::BSONArrayBuilder mdNames; - this->vec[ix]->metadataVector.toBson(&md, &mdNames, apiVersion == V2); + this->vec[ix]->metadataVector.toBson(&md, &mdNames, true); if (mdNames.arrSize()) { bsonAttr.append(ENT_ATTRS_MD, md.obj()); diff --git a/src/lib/ngsi/ContextAttributeVector.h b/src/lib/ngsi/ContextAttributeVector.h index 6c32b17a4f..bec40f8d89 100644 --- a/src/lib/ngsi/ContextAttributeVector.h +++ b/src/lib/ngsi/ContextAttributeVector.h @@ -59,22 +59,13 @@ typedef struct ContextAttributeVector ContextAttribute* operator[](unsigned int ix) const; - std::string check(ApiVersion apiVersion, RequestType requestType); - - std::string toJsonV1(bool asJsonObject, - RequestType requestType, - const std::vector& orderedAttrs, - const std::vector& metadataFilter, - bool comma = false, - bool omitValue = false, - bool attrsAsName = false); + std::string check(bool asValue); std::string toJsonTypes(void); void toBson(double now, orion::BSONObjBuilder* attrsToAdd, - orion::BSONArrayBuilder* attrNamesToAdd, - ApiVersion apiVersion) const; + orion::BSONArrayBuilder* attrNamesToAdd) const; void applyUpdateOperators(void); diff --git a/src/lib/ngsi/ContextElementResponse.cpp b/src/lib/ngsi/ContextElementResponse.cpp index 8f5dace5ca..d08beef005 100644 --- a/src/lib/ngsi/ContextElementResponse.cpp +++ b/src/lib/ngsi/ContextElementResponse.cpp @@ -27,7 +27,6 @@ #include "logMsg/logMsg.h" #include "logMsg/traceLevels.h" -#include "common/tag.h" #include "common/RenderFormat.h" #include "alarmMgr/alarmMgr.h" #include "ngsi/ContextElementResponse.h" @@ -62,7 +61,7 @@ ContextElementResponse::ContextElementResponse(EntityId* eP, ContextAttribute* a { prune = false; - entity.fill(eP->id, eP->type, eP->isPattern); + entity.fill(eP); if (aP != NULL) { @@ -81,7 +80,7 @@ ContextElementResponse::ContextElementResponse(ContextElementResponse* cerP, boo prune = false; entity.fill(cerP->entity, false, cloneCompounds); - statusCode.fill(cerP->statusCode); + error.fill(cerP->error); } @@ -93,7 +92,7 @@ ContextElementResponse::ContextElementResponse(ContextElementResponse* cerP, boo * This constructor builds the CER object based in a BSON object taken from the * entities collection at DB. * -* Note that statusCode is not touched by this constructor. +* Note that error field is not touched by this constructor. */ ContextElementResponse::ContextElementResponse ( @@ -106,10 +105,9 @@ ContextElementResponse::ContextElementResponse // Entity orion::BSONObj id = getFieldF(entityDoc, "_id").embeddedObject(); - std::string entityId = getStringFieldF(id, ENT_ENTITY_ID); - std::string entityType = id.hasField(ENT_ENTITY_TYPE) ? getStringFieldF(id, ENT_ENTITY_TYPE) : ""; + EntityId entId(getStringFieldF(id, ENT_ENTITY_ID), "", id.hasField(ENT_ENTITY_TYPE) ? getStringFieldF(id, ENT_ENTITY_TYPE) : "", ""); - entity.fill(entityId, entityType, "false"); + entity.fill(entId); entity.servicePath = id.hasField(ENT_SERVICE_PATH) ? getStringFieldF(id, ENT_SERVICE_PATH) : ""; /* Get the location attribute (if it exists) */ @@ -142,7 +140,7 @@ ContextElementResponse::ContextElementResponse * * ContextElementResponse::ContextElementResponse - * -* This constructor builds the CER from a CEP. Note that statusCode is not touched. +* This constructor builds the CER from a CEP. Note that error field is not touched. */ ContextElementResponse::ContextElementResponse(Entity* eP, bool useDefaultType) { @@ -151,60 +149,6 @@ ContextElementResponse::ContextElementResponse(Entity* eP, bool useDefaultType) -/* **************************************************************************** -* -* ContextElementResponse::toJsonV1 - -*/ -std::string ContextElementResponse::toJsonV1 -( - bool asJsonObject, - RequestType requestType, - const std::vector& attrsFilter, - bool blacklist, - const std::vector& metadataFilter, - bool comma, - bool omitAttributeValues -) -{ - std::string out = ""; - - out += startTag(); - out += entity.toJsonV1(asJsonObject, requestType, attrsFilter, blacklist, metadataFilter, true, omitAttributeValues); - out += statusCode.toJsonV1(false); - out += endTag(comma, false); - - return out; -} - - - -/* **************************************************************************** -* -* ContextElementResponse::toJsonV1 - -* -* Wrapper of toJsonV1 with empty attrsFilter and metadataFilter -*/ -std::string ContextElementResponse::toJsonV1 -( - bool asJsonObject, - RequestType requestType, - bool blacklist, - bool comma, - bool omitAttributeValues -) -{ - std::string out = ""; - - out += startTag(); - out += entity.toJsonV1(asJsonObject, requestType, blacklist, true, omitAttributeValues); - out += statusCode.toJsonV1(false); - out += endTag(comma, false); - - return out; -} - - - /* **************************************************************************** * * ContextElementResponse::toJson - @@ -245,110 +189,4 @@ void ContextElementResponse::applyUpdateOperators(void) void ContextElementResponse::release(void) { entity.release(); - statusCode.release(); -} - - - -/* **************************************************************************** -* -* ContextElementResponse::check - -*/ -std::string ContextElementResponse::check -( - ApiVersion apiVersion, - RequestType requestType, - const std::string& predetectedError, - int counter -) -{ - std::string res; - - if ((res = entity.check(apiVersion, requestType)) != "OK") - { - return res; - } - - if ((res = statusCode.check()) != "OK") - { - return res; - } - - return "OK"; -} - - - -/* **************************************************************************** -* -* ContextElementResponse::fill - -*/ -void ContextElementResponse::fill(QueryContextResponse* qcrP, const std::string& entityId, const std::string& entityType) -{ - if (qcrP == NULL) - { - statusCode.fill(SccContextElementNotFound); - return; - } - - if (qcrP->contextElementResponseVector.size() == 0) - { - statusCode.fill(&qcrP->errorCode); - entity.fill(entityId, entityType, "false"); - - if ((statusCode.code != SccOk) && (statusCode.details.empty())) - { - statusCode.details = "Entity id: /" + entityId + "/"; - } - - return; - } - - // - // FIXME P7: If more than one context element is found, we simply select the first one. - // A better approach would be to change this convop to return a vector of responses. - // Adding a call to alarmMgr::badInput - with this I mean that the user that sends the - // query needs to avoid using this conv op to make any queries that can give more than - // one unique context element :-). - // This FIXME is related to github issue #588 and (probably) #650. - // Also, optimizing this would be part of issue #768 - // - if (qcrP->contextElementResponseVector.size() > 1) - { - alarmMgr.badInput(clientIp, "more than one context element found the this query - selecting the first one"); - } - - entity.fill(qcrP->contextElementResponseVector[0]->entity); - - if (qcrP->errorCode.code != SccNone) - { - statusCode.fill(&qcrP->errorCode); - } -} - - - -/* **************************************************************************** -* -* ContextElementResponse::fill - -*/ -void ContextElementResponse::fill(ContextElementResponse* cerP) -{ - entity.fill(cerP->entity); - statusCode.fill(cerP->statusCode); -} - - - -/* **************************************************************************** -* -* ContextElementResponse::clone - -*/ -ContextElementResponse* ContextElementResponse::clone(void) -{ - ContextElementResponse* cerP = new ContextElementResponse(); - - cerP->fill(this); - - return cerP; } diff --git a/src/lib/ngsi/ContextElementResponse.h b/src/lib/ngsi/ContextElementResponse.h index 2394183081..df57a79610 100644 --- a/src/lib/ngsi/ContextElementResponse.h +++ b/src/lib/ngsi/ContextElementResponse.h @@ -29,7 +29,7 @@ #include "common/RenderFormat.h" #include "common/globals.h" -#include "ngsi/StatusCode.h" +#include "rest/OrionError.h" #include "ngsi/StringList.h" #include "ngsi/ContextAttribute.h" #include "apiTypesV2/Entity.h" @@ -38,13 +38,6 @@ #include "mongoDriver/BSONObj.h" -/* **************************************************************************** -* -* Forward declarations -*/ -struct QueryContextResponse; - - /* **************************************************************************** * @@ -53,7 +46,7 @@ struct QueryContextResponse; typedef struct ContextElementResponse { Entity entity; // Mandatory (represents a Context Element) - StatusCode statusCode; // Mandatory + OrionError error; // Mandatory bool prune; // operational attribute used internally by the queryContext logic for not deleting entities that were // without attributes in the Orion DB @@ -65,20 +58,6 @@ typedef struct ContextElementResponse const StringList& attrL); ContextElementResponse(Entity* eP, bool useDefaultType = false); - std::string toJsonV1(bool asJsonObject, - RequestType requestType, - const std::vector& attrsFilter, - bool blacklist, - const std::vector& metadataFilter, - bool comma = false, - bool omitAttributeValues = false); - - std::string toJsonV1(bool asJsonObject, - RequestType requestType, - bool blacklist, - bool comma = false, - bool omitAttributeValues = false); - std::string toJson(RenderFormat renderFormat, const std::vector& attrsFilter, bool blacklist, @@ -89,16 +68,6 @@ typedef struct ContextElementResponse void release(void); - std::string check(ApiVersion apiVersion, - RequestType requestType, - const std::string& predetectedError, - int counter); - - void fill(struct QueryContextResponse* qcrP, - const std::string& entityId = "", - const std::string& entityType = ""); - void fill(ContextElementResponse* cerP); - ContextElementResponse* clone(void); } ContextElementResponse; #endif // SRC_LIB_NGSI_CONTEXTELEMENTRESPONSE_H_ diff --git a/src/lib/ngsi/ContextElementResponseVector.cpp b/src/lib/ngsi/ContextElementResponseVector.cpp index 24f40121f4..6550937e2e 100644 --- a/src/lib/ngsi/ContextElementResponseVector.cpp +++ b/src/lib/ngsi/ContextElementResponseVector.cpp @@ -30,85 +30,12 @@ #include "logMsg/traceLevels.h" #include "common/globals.h" -#include "common/tag.h" #include "common/RenderFormat.h" #include "common/JsonHelper.h" #include "ngsi/ContextElementResponseVector.h" -/* **************************************************************************** -* -* ContextElementResponseVector::toJsonV1 - -*/ -std::string ContextElementResponseVector::toJsonV1 -( - bool asJsonObject, - RequestType requestType, - const std::vector& attrsFilter, - bool blacklist, - const std::vector& metadataFilter, - bool comma, - bool omitAttributeValues -) -{ - std::string out = ""; - - if (vec.size() == 0) - { - return ""; - } - - out += startTag("contextResponses", true); - - for (unsigned int ix = 0; ix < vec.size(); ++ix) - { - out += vec[ix]->toJsonV1(asJsonObject, requestType, attrsFilter, blacklist, metadataFilter, ix < (vec.size() - 1), omitAttributeValues); - } - - out += endTag(comma, true); - - return out; -} - - - -/* **************************************************************************** -* -* ContextElementResponseVector::toJsonV1 - -* -* Wrapper of toJsonV1 with empty attrsFilter and metadataFilter -*/ -std::string ContextElementResponseVector::toJsonV1 -( - bool asJsonObject, - RequestType requestType, - bool blacklist, - bool comma, - bool omitAttributeValues -) -{ - std::string out = ""; - - if (vec.size() == 0) - { - return ""; - } - - out += startTag("contextResponses", true); - - for (unsigned int ix = 0; ix < vec.size(); ++ix) - { - out += vec[ix]->toJsonV1(asJsonObject, requestType, blacklist, ix < (vec.size() - 1), omitAttributeValues); - } - - out += endTag(comma, true); - - return out; -} - - - /* **************************************************************************** * * ContextElementResponseVector::toJson - @@ -134,33 +61,6 @@ std::string ContextElementResponseVector::toJson -/* **************************************************************************** -* -* ContextElementResponseVector::check - -*/ -std::string ContextElementResponseVector::check -( - ApiVersion apiVersion, - RequestType requestType, - const std::string& predetectedError, - int counter -) -{ - for (uint64_t ix = 0; ix < vec.size(); ++ix) - { - std::string res; - - if ((res = vec[ix]->check(apiVersion, requestType, predetectedError, counter)) != "OK") - { - return res; - } - } - - return "OK"; -} - - - /* **************************************************************************** * * ContextElementResponseVector::push_back - @@ -223,7 +123,7 @@ ContextElementResponse* ContextElementResponseVector::lookup(Entity* eP, HttpSta { if (vec[ix]->entity.equal(eP) == true) { - if ((code == SccNone) || (vec[ix]->statusCode.code == code)) + if ((code == SccNone) || (vec[ix]->error.code == code)) { return vec[ix]; } @@ -261,7 +161,7 @@ void ContextElementResponseVector::fill(EntityVector& erV, HttpStatusCode sc) { ContextElementResponse* cerP = new ContextElementResponse(erV[ix]); - cerP->statusCode.fill(sc, erV[ix]->id); + cerP->error.fill(sc, erV[ix]->entityId.id); push_back(cerP); } diff --git a/src/lib/ngsi/ContextElementResponseVector.h b/src/lib/ngsi/ContextElementResponseVector.h index 9a6102b990..4d0766f26a 100644 --- a/src/lib/ngsi/ContextElementResponseVector.h +++ b/src/lib/ngsi/ContextElementResponseVector.h @@ -43,20 +43,6 @@ typedef struct ContextElementResponseVector { std::vector vec; - std::string toJsonV1(bool asJsonObject, - RequestType requestType, - const std::vector& attrsFilter, - bool blacklist, - const std::vector& metadataFilter, - bool comma = false, - bool omitAttributeValues = false); - - std::string toJsonV1(bool asJsonObject, - RequestType requestType, - bool blacklist, - bool comma = false, - bool omitAttributeValues = false); - std::string toJson(RenderFormat renderFormat, const std::vector& attrsFilter, bool blacklist, @@ -69,12 +55,7 @@ typedef struct ContextElementResponseVector void fill(ContextElementResponseVector& cerV); void fill(EntityVector& erV, HttpStatusCode sc); // Needed by NGSIv2 forwarding logic ContextElementResponse* operator[] (unsigned int ix) const; - - std::string check(ApiVersion apiVersion, - RequestType requestType, - const std::string& predetectedError, - int counter); } ContextElementResponseVector; #endif // SRC_LIB_NGSI_CONTEXTELEMENTRESPONSEVECTOR_H_ diff --git a/src/lib/ngsi/ContextRegistration.cpp b/src/lib/ngsi/ContextRegistration.cpp deleted file mode 100644 index bd7ec0a79e..0000000000 --- a/src/lib/ngsi/ContextRegistration.cpp +++ /dev/null @@ -1,124 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/globals.h" -#include "common/tag.h" -#include "ngsi/Request.h" -#include "ngsi/ContextRegistration.h" -#include "ngsi/ContextRegistrationAttribute.h" -#include "ngsi/EntityId.h" - -/* **************************************************************************** -* -* ContextRegistration::ContextRegistration - -* -* Explicit constructor needed to initialize primitive types so they don't get -* random values from the stack -*/ -ContextRegistration::ContextRegistration() -{ - entityIdVectorPresent = false; -} - -/* **************************************************************************** -* -* ContextRegistration::toJsonV1 - -*/ -std::string ContextRegistration::toJsonV1(bool comma, bool isInVector) -{ - std::string out = ""; - - // - // About JSON commas; - // As providingApplication is MANDATORY and it is the last item in ContextRegistration, - // the problem with the JSON commas disappear. All fields will have 'comma set to true'. - // All, except providingApplication of course :-) - // - - out += startTag(!isInVector? "contextRegistration" : ""); - out += entityIdVector.toJsonV1(true); - out += contextRegistrationAttributeVector.toJsonV1(true); - out += providingApplication.toJsonV1(false); - out += endTag(comma); - - return out; -} - - - -/* **************************************************************************** -* -* ContextRegistration::check - -*/ -std::string ContextRegistration::check -( - ApiVersion apiVersion, - RequestType requestType, - const std::string& predetectedError, - int counter -) -{ - std::string res; - - if ((res = entityIdVector.check(requestType)) != "OK") - { - return res; - } - - if ((res = contextRegistrationAttributeVector.check(apiVersion)) != "OK") - { - return res; - } - - if ((res = providingApplication.check()) != "OK") - { - return res; - } - - if ((entityIdVectorPresent == true) && (entityIdVector.size() == 0)) - { - return "Empty entityIdVector"; - } - - return "OK"; -} - - - -/* **************************************************************************** -* -* ContextRegistration::release - -*/ -void ContextRegistration::release(void) -{ - entityIdVector.release(); - contextRegistrationAttributeVector.release(); - providingApplication.release(); -} diff --git a/src/lib/ngsi/ContextRegistration.h b/src/lib/ngsi/ContextRegistration.h deleted file mode 100644 index 7df39196c5..0000000000 --- a/src/lib/ngsi/ContextRegistration.h +++ /dev/null @@ -1,60 +0,0 @@ -#ifndef SRC_LIB_NGSI_CONTEXTREGISTRATION_H_ -#define SRC_LIB_NGSI_CONTEXTREGISTRATION_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "ngsi/EntityIdVector.h" -#include "ngsi/ProvidingApplication.h" -#include "ngsi/ContextRegistrationAttributeVector.h" -#include "ngsi/MetadataVector.h" - - - -/* **************************************************************************** -* -* ContextRegistration - -*/ -typedef struct ContextRegistration -{ - EntityIdVector entityIdVector; // Optional - ContextRegistrationAttributeVector contextRegistrationAttributeVector; // Optional - ProvidingApplication providingApplication; // Mandatory - - bool entityIdVectorPresent; // entityIdList present during parsing - - ContextRegistration(); - std::string toJsonV1(bool comma, bool isInVector); - void release(); - - std::string check(ApiVersion apiVersion, - RequestType requestType, - const std::string& predetectedError, - int counter); -} ContextRegistration; - -#endif // SRC_LIB_NGSI_CONTEXTREGISTRATION_H_ diff --git a/src/lib/ngsi/ContextRegistrationAttribute.cpp b/src/lib/ngsi/ContextRegistrationAttribute.cpp deleted file mode 100644 index 9ae12dba1f..0000000000 --- a/src/lib/ngsi/ContextRegistrationAttribute.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/globals.h" -#include "common/tag.h" -#include "ngsi/ContextRegistrationAttribute.h" - - - -/* **************************************************************************** -* -* ContextRegistrationAttribute::ContextRegistrationAttribute - -*/ -ContextRegistrationAttribute::ContextRegistrationAttribute() -{ - name = ""; - type = ""; -} - - - -/* **************************************************************************** -* -* ContextRegistrationAttribute::ContextRegistrationAttribute - -*/ -ContextRegistrationAttribute::ContextRegistrationAttribute -( - const std::string& _name, - const std::string& _type -) -{ - name = _name; - type = _type; -} - -/* **************************************************************************** -* -* ContextRegistrationAttribute::toJsonV1 - -*/ -std::string ContextRegistrationAttribute::toJsonV1(bool comma) -{ - std::string out = ""; - - out += startTag(); - out += valueTag("name", name, true); - out += valueTag("type", type, false); - out += endTag(comma); - - return out; -} - - - -/* **************************************************************************** -* -* ContextRegistrationAttribute::check - -*/ -std::string ContextRegistrationAttribute::check(ApiVersion apiVersion) -{ - - if (name.empty()) - { - return "missing name for registration attribute"; - } - - return "OK"; -} - diff --git a/src/lib/ngsi/ContextRegistrationAttribute.h b/src/lib/ngsi/ContextRegistrationAttribute.h deleted file mode 100644 index 8f02d62efb..0000000000 --- a/src/lib/ngsi/ContextRegistrationAttribute.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef SRC_LIB_NGSI_CONTEXTREGISTRATIONATTRIBUTE_H_ -#define SRC_LIB_NGSI_CONTEXTREGISTRATIONATTRIBUTE_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "common/globals.h" - -#include "ngsi/MetadataVector.h" -#include "ngsi/Request.h" - - - -/* **************************************************************************** -* -* ContextRegistrationAttribute - -*/ -typedef struct ContextRegistrationAttribute -{ - std::string name; // Mandatory - std::string type; // Optional - - ContextRegistrationAttribute(); - ContextRegistrationAttribute(const std::string& _name, const std::string& _type); - std::string toJsonV1(bool comma); - - std::string check(ApiVersion apiVersion); -} ContextRegistrationAttribute; - -#endif // SRC_LIB_NGSI_CONTEXTREGISTRATIONATTRIBUTE_H_ diff --git a/src/lib/ngsi/ContextRegistrationAttributeVector.cpp b/src/lib/ngsi/ContextRegistrationAttributeVector.cpp deleted file mode 100644 index 842e177b35..0000000000 --- a/src/lib/ngsi/ContextRegistrationAttributeVector.cpp +++ /dev/null @@ -1,133 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/globals.h" -#include "common/tag.h" -#include "ngsi/ContextRegistrationAttributeVector.h" - - - -/* **************************************************************************** -* -* ContextRegistrationAttributeVector::toJsonV1 - -*/ -std::string ContextRegistrationAttributeVector::toJsonV1(bool comma) -{ - std::string out = ""; - - if (vec.size() == 0) - { - return ""; - } - - out += startTag("attributes", true); - for (unsigned int ix = 0; ix < vec.size(); ++ix) - { - out += vec[ix]->toJsonV1(ix != vec.size() - 1); - } - out += endTag(comma, true); - - return out; -} - - - -/* **************************************************************************** -* -* ContextRegistrationAttributeVector::check - -*/ -std::string ContextRegistrationAttributeVector::check(ApiVersion apiVersion) -{ - for (unsigned int ix = 0; ix < vec.size(); ++ix) - { - std::string res; - - if ((res = vec[ix]->check(apiVersion)) != "OK") - { - return res; - } - } - - return "OK"; -} - - - -/* **************************************************************************** -* -* ContextRegistrationAttributeVector::push_back - -*/ -void ContextRegistrationAttributeVector::push_back(ContextRegistrationAttribute* item) -{ - vec.push_back(item); -} - - - -/* **************************************************************************** -* -* ContextRegistrationAttributeVector::operator[] - -*/ -ContextRegistrationAttribute* ContextRegistrationAttributeVector::operator[] (unsigned int ix) const -{ - if (ix < vec.size()) - { - return vec[ix]; - } - return NULL; -} - - - -/* **************************************************************************** -* -* ContextRegistrationAttributeVector::size - -*/ -unsigned int ContextRegistrationAttributeVector::size(void) -{ - return vec.size(); -} - - - -/* **************************************************************************** -* -* ContextRegistrationAttributeVector::release - -*/ -void ContextRegistrationAttributeVector::release(void) -{ - for (unsigned int ix = 0; ix < vec.size(); ++ix) - { - delete(vec[ix]); - } - - vec.clear(); -} diff --git a/src/lib/ngsi/ContextRegistrationAttributeVector.h b/src/lib/ngsi/ContextRegistrationAttributeVector.h deleted file mode 100644 index 7e171f100c..0000000000 --- a/src/lib/ngsi/ContextRegistrationAttributeVector.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef SRC_LIB_NGSI_CONTEXTREGISTRATIONATTRIBUTEVECTOR_H_ -#define SRC_LIB_NGSI_CONTEXTREGISTRATIONATTRIBUTEVECTOR_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "ngsi/ContextRegistrationAttribute.h" - - - -/* **************************************************************************** -* -* ContextRegistrationAttributeVector - -*/ -typedef struct ContextRegistrationAttributeVector -{ - std::vector vec; - - std::string toJsonV1(bool comma); - void push_back(ContextRegistrationAttribute* item); - unsigned int size(void); - void release(); - - std::string check(ApiVersion apiVersion); - - ContextRegistrationAttribute* operator[](unsigned int ix) const; - -} ContextRegistrationAttributeVector; - -#endif // SRC_LIB_NGSI_CONTEXTREGISTRATIONATTRIBUTEVECTOR_H_ diff --git a/src/lib/ngsi/ContextRegistrationResponse.cpp b/src/lib/ngsi/ContextRegistrationResponse.cpp deleted file mode 100644 index f319b7c9ed..0000000000 --- a/src/lib/ngsi/ContextRegistrationResponse.cpp +++ /dev/null @@ -1,94 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include - -#include "common/tag.h" -#include "ngsi/StatusCode.h" -#include "ngsi/ContextRegistrationResponse.h" -#include "ngsi/Request.h" - - - -/* **************************************************************************** -* -* ContextRegistrationResponse::ContextRegistrationResponse - -*/ -ContextRegistrationResponse::ContextRegistrationResponse() -{ - errorCode.keyNameSet("errorCode"); -} - - - -/* **************************************************************************** -* -* ContextRegistrationResponse::toJsonV1 - -*/ -std::string ContextRegistrationResponse::toJsonV1(bool comma) -{ - std::string out = ""; - bool errorCodeRendered = errorCode.code != SccNone; - - out += startTag(); - - out += contextRegistration.toJsonV1(errorCodeRendered, false); - - if (errorCodeRendered) - { - out += errorCode.toJsonV1(false); - } - - out += endTag(comma); - - return out; -} - - - -/* **************************************************************************** -* -* ContextRegistrationResponse::check - -*/ -std::string ContextRegistrationResponse::check -( - ApiVersion apiVersion, - RequestType requestType, - const std::string& predetectedError, - int counter -) -{ - return contextRegistration.check(apiVersion, requestType, predetectedError, counter); -} - - - -/* **************************************************************************** -* -* ContextRegistrationResponse::release - -*/ -void ContextRegistrationResponse::release(void) -{ - contextRegistration.release(); -} diff --git a/src/lib/ngsi/ContextRegistrationResponse.h b/src/lib/ngsi/ContextRegistrationResponse.h deleted file mode 100644 index 1983abe5b6..0000000000 --- a/src/lib/ngsi/ContextRegistrationResponse.h +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef SRC_LIB_NGSI_CONTEXTREGISTRATIONRESPONSE_H_ -#define SRC_LIB_NGSI_CONTEXTREGISTRATIONRESPONSE_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include - -#include "ngsi/ContextRegistration.h" -#include "ngsi/StatusCode.h" -#include "ngsi/Request.h" - - - -/* **************************************************************************** -* -* ContextRegistrationResponse - -*/ -typedef struct ContextRegistrationResponse -{ - ContextRegistration contextRegistration; // Mandatory - StatusCode errorCode; // Optional - ProviderFormat providerFormat; // During forwarding, this field is used to record the 'format' from the registration that provoked - // this Context Element to be forwarded. - std::string regId; // During forwarding, this field is used to record the regId (for logging purposes) - - ContextRegistrationResponse(); - - std::string toJsonV1(bool comma); - void release(void); - - std::string check(ApiVersion apiVersion, - RequestType requestType, - const std::string& predetectedError, - int counter); -} ContextRegistrationResponse; - -#endif // SRC_LIB_NGSI_CONTEXTREGISTRATIONRESPONSE_H_ diff --git a/src/lib/ngsi/ContextRegistrationResponseVector.cpp b/src/lib/ngsi/ContextRegistrationResponseVector.cpp deleted file mode 100644 index ca92bc4d7e..0000000000 --- a/src/lib/ngsi/ContextRegistrationResponseVector.cpp +++ /dev/null @@ -1,141 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/globals.h" -#include "common/tag.h" -#include "ngsi/ContextRegistrationResponseVector.h" - - - -/* **************************************************************************** -* -* ContextRegistrationResponseVector::push_back - -*/ -void ContextRegistrationResponseVector::push_back(ContextRegistrationResponse* item) -{ - vec.push_back(item); -} - - - -/* **************************************************************************** -* -* ContextRegistrationResponseVector::toJsonV1 - -*/ -std::string ContextRegistrationResponseVector::toJsonV1(bool comma) -{ - std::string out = ""; - - if (vec.size() == 0) - { - return ""; - } - - out += startTag("contextRegistrationResponses", true); - - for (unsigned int ix = 0; ix < vec.size(); ++ix) - { - out += vec[ix]->toJsonV1((ix != vec.size() - 1)); - } - - out += endTag(comma, true); - - return out; -} - - - -/* **************************************************************************** -* -* ContextRegistrationResponseVector::release - -*/ -void ContextRegistrationResponseVector::release(void) -{ - for (unsigned int ix = 0; ix < vec.size(); ++ix) - { - vec[ix]->release(); - delete(vec[ix]); - } - - vec.clear(); -} - - - -/* **************************************************************************** -* -* ContextRegistrationResponseVector::operator[] - -*/ -ContextRegistrationResponse* ContextRegistrationResponseVector::operator[] (unsigned int ix) const -{ - if (ix < vec.size()) - { - return vec[ix]; - } - return NULL; -} - - - -/* **************************************************************************** -* -* ContextRegistrationResponseVector::size - -*/ -unsigned int ContextRegistrationResponseVector::size(void) const -{ - return vec.size(); -} - - - -/* **************************************************************************** -* -* ContextRegistrationResponseVector::check - -*/ -std::string ContextRegistrationResponseVector::check -( - ApiVersion apiVersion, - RequestType requestType, - const std::string& predetectedError, - int counter -) -{ - for (unsigned int ix = 0; ix < vec.size(); ++ix) - { - std::string res; - - if ((res = vec[ix]->check(apiVersion, requestType, predetectedError, counter)) != "OK") - { - return res; - } - } - - return "OK"; -} diff --git a/src/lib/ngsi/ContextRegistrationResponseVector.h b/src/lib/ngsi/ContextRegistrationResponseVector.h deleted file mode 100644 index d1cc49d097..0000000000 --- a/src/lib/ngsi/ContextRegistrationResponseVector.h +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef SRC_LIB_NGSI_CONTEXTREGISTRATIONRESPONSEVECTOR_H_ -#define SRC_LIB_NGSI_CONTEXTREGISTRATIONRESPONSEVECTOR_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "ngsi/ContextRegistrationResponse.h" - - - -/* **************************************************************************** -* -* ContextRegistrationResponseVector - -*/ -typedef struct ContextRegistrationResponseVector -{ - std::vector vec; - - void push_back(ContextRegistrationResponse* item); - unsigned int size(void) const; - std::string toJsonV1(bool comma); - void release(void); - - ContextRegistrationResponse* operator[](unsigned int ix) const; - - - std::string check(ApiVersion apiVersion, - RequestType requestType, - const std::string& predetectedError, - int counter); - -} ContextRegistrationResponseVector; - - -#endif // SRC_LIB_NGSI_CONTEXTREGISTRATIONRESPONSEVECTOR_H_ diff --git a/src/lib/ngsi/ContextRegistrationVector.cpp b/src/lib/ngsi/ContextRegistrationVector.cpp deleted file mode 100644 index e8725f5557..0000000000 --- a/src/lib/ngsi/ContextRegistrationVector.cpp +++ /dev/null @@ -1,142 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/globals.h" -#include "common/tag.h" -#include "ngsi/ContextRegistrationVector.h" - - - -/* **************************************************************************** -* -* ContextRegistrationVector::push_back - -*/ -void ContextRegistrationVector::push_back(ContextRegistration* item) -{ - vec.push_back(item); -} - - - -/* **************************************************************************** -* -* ContextRegistrationVector::toJsonV1 - -*/ -std::string ContextRegistrationVector::toJsonV1(bool comma) -{ - std::string out = ""; - - if (vec.size() == 0) - { - return ""; - } - - out += startTag("contextRegistrations", true); - - for (unsigned int ix = 0; ix < vec.size(); ++ix) - { - out += vec[ix]->toJsonV1(ix != vec.size() - 1, true); - } - - out += endTag(comma, comma); - - return out; -} - - - -/* **************************************************************************** -* -* ContextRegistrationVector::release - -*/ -void ContextRegistrationVector::release(void) -{ - for (unsigned int ix = 0; ix < vec.size(); ++ix) - { - vec[ix]->release(); - delete(vec[ix]); - } - - vec.clear(); -} - - - -/* **************************************************************************** -* -* ContextRegistrationVector::operator[] - -*/ -ContextRegistration* ContextRegistrationVector::operator[](unsigned int ix) const -{ - if (ix < vec.size()) - { - return vec[ix]; - } - return NULL; -} - - - - -/* **************************************************************************** -* -* ContextRegistrationVector::size - -*/ -unsigned int ContextRegistrationVector::size(void) -{ - return vec.size(); -} - - - -/* **************************************************************************** -* -* ContextRegistrationVector::check - -*/ -std::string ContextRegistrationVector::check -( - ApiVersion apiVersion, - RequestType requestType, - const std::string& predetectedError, - int counter -) -{ - for (unsigned int ix = 0; ix < vec.size(); ++ix) - { - std::string res; - - if ((res = vec[ix]->check(apiVersion, requestType, predetectedError, counter)) != "OK") - { - return res; - } - } - - return "OK"; -} diff --git a/src/lib/ngsi/ContextRegistrationVector.h b/src/lib/ngsi/ContextRegistrationVector.h deleted file mode 100644 index 3fef835503..0000000000 --- a/src/lib/ngsi/ContextRegistrationVector.h +++ /dev/null @@ -1,57 +0,0 @@ -#ifndef SRC_LIB_NGSI_CONTEXTREGISTRATIONVECTOR_H_ -#define SRC_LIB_NGSI_CONTEXTREGISTRATIONVECTOR_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "ngsi/ContextRegistration.h" - - - -/* **************************************************************************** -* -* ContextRegistrationVector - -*/ -typedef struct ContextRegistrationVector -{ - std::vector vec; - - void push_back(ContextRegistration* item); - unsigned int size(void); - std::string toJsonV1(bool comma); - void release(void); - - std::string check(ApiVersion apiVersion, - RequestType requestType, - const std::string& predetectedError, - int counter); - - ContextRegistration* operator[](unsigned int ix) const; - -} ContextRegistrationVector; - -#endif // SRC_LIB_NGSI_CONTEXTREGISTRATIONVECTOR_H_ diff --git a/src/lib/ngsi/Duration.cpp b/src/lib/ngsi/Duration.cpp deleted file mode 100644 index 5d58df3c1e..0000000000 --- a/src/lib/ngsi/Duration.cpp +++ /dev/null @@ -1,165 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include // strdup -#include // free -#include // int64_t et al -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/globals.h" -#include "common/tag.h" -#include "alarmMgr/alarmMgr.h" -#include "ngsi/Request.h" -#include "ngsi/Duration.h" - - - -/* **************************************************************************** -* -* Duration::Duration -* -* Explicit constructor needed to initialize primitive types so they don't get -* random values from the stack -*/ -Duration::Duration() -{ - seconds = 0; - valid = false; - used = false; -} - - - -/* **************************************************************************** -* -* Duration::check - -*/ -std::string Duration::check(void) -{ - if (string.empty()) - { - return "OK"; - } - - if (parse() == -1) - { - valid = false; - alarmMgr.badInput(clientIp, "syntax error in duration string", string); - - return "syntax error in duration string"; - } - - valid = true; - - return "OK"; -} - - - -/* **************************************************************************** -* -* Duration::set - -*/ -void Duration::set(const std::string& value) -{ - string = value; - parse(); // just to flag valid/invalid -} - - - -/* **************************************************************************** -* -* Duration::get - -*/ -std::string Duration::get(void) -{ - return string; -} - - - -/* **************************************************************************** -* -* Duration::isEmpty - -*/ -bool Duration::isEmpty(void) -{ - if (string.empty()) - { - return true; - } - - return false; -} - - - -/* **************************************************************************** -* -* Duration::parse - -*/ -int64_t Duration::parse(void) -{ - seconds = parse8601(string); - - valid = (seconds == -1)? false : true; - - return seconds; -} - - - -/* **************************************************************************** -* -* Duration::toJsonV1 - -*/ -std::string Duration::toJsonV1(bool comma) -{ - if (string.empty()) - { - return ""; - } - - if (valid == false) - { - return ""; - } - - return valueTag("duration", string, comma); -} - - - -/* **************************************************************************** -* -* release - -*/ -void Duration::release(void) -{ - /* This method is included for the sake of homogeneity */ -} diff --git a/src/lib/ngsi/Duration.h b/src/lib/ngsi/Duration.h deleted file mode 100644 index 9a87c2fe8d..0000000000 --- a/src/lib/ngsi/Duration.h +++ /dev/null @@ -1,63 +0,0 @@ -#ifndef SRC_LIB_NGSI_DURATION_H_ -#define SRC_LIB_NGSI_DURATION_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include // int64_t et al -#include - -#include "ngsi/Request.h" - -#define DEFAULT_DURATION "PT24H" -#define DEFAULT_DURATION_IN_SECONDS 86400 - - -/* **************************************************************************** -* -* Duration - -*/ -class Duration -{ - public: - std::string string; - int64_t seconds; - - private: - bool used; - bool valid; - - public: - Duration(); - void set(const std::string& value); - std::string get(void); - bool isEmpty(void); - std::string toJsonV1(bool comma); - int64_t parse(void); - void release(void); - - std::string check(void); -}; - -#endif // SRC_LIB_NGSI_DURATION_H_ diff --git a/src/lib/ngsi/EntityId.cpp b/src/lib/ngsi/EntityId.cpp index 82ff46ecf0..8cb25ab740 100644 --- a/src/lib/ngsi/EntityId.cpp +++ b/src/lib/ngsi/EntityId.cpp @@ -32,7 +32,6 @@ #include "common/string.h" #include "common/JsonHelper.h" #include "ngsi/EntityId.h" -#include "common/tag.h" #include "common/JsonHelper.h" @@ -41,13 +40,11 @@ * * EntityId::EntityId - */ -EntityId::EntityId(): creDate(0), modDate(0) +EntityId::EntityId(): id(""), idPattern(""), type(""), typePattern("") { - isTypePattern = false; } - /* **************************************************************************** * * EntityId::EntityId - @@ -58,6 +55,7 @@ EntityId::EntityId(EntityId* eP) } + /* **************************************************************************** * * EntityId::EntityId - @@ -65,15 +63,13 @@ EntityId::EntityId(EntityId* eP) EntityId::EntityId ( const std::string& _id, + const std::string& _idPattern, const std::string& _type, - const std::string& _isPattern, - bool _isTypePattern + const std::string& _typePattern ) : id(_id), + idPattern(_idPattern), type(_type), - isPattern(_isPattern), - isTypePattern(_isTypePattern), - creDate(0), - modDate(0) + typePattern(_typePattern) { } @@ -88,128 +84,27 @@ std::string EntityId::toJson(void) { JsonObjectHelper jh; - if (isTrue(isPattern)) - { - jh.addString("idPattern", id); - } - else + if (!this->id.empty()) { - jh.addString("id", id); + jh.addString("id", this->id); } - if (!type.empty()) + if (!this->idPattern.empty()) { - jh.addString("type", type); + jh.addString("idPattern", this->idPattern); } - return jh.str(); -} - - - -/* **************************************************************************** -* -* EntityId::toJsonV1 - -* -*/ -std::string EntityId::toJsonV1(bool comma, bool isInVector) -{ - std::string out = ""; - char* isPatternEscaped = htmlEscape(isPattern.c_str()); - char* typeEscaped = htmlEscape(type.c_str()); - char* idEscaped = htmlEscape(id.c_str()); - - out += (isInVector? "{" : ""); - out = out + "\"type\":\"" + typeEscaped + "\","; - out = out + "\"isPattern\":\"" + isPatternEscaped + "\","; - out = out + "\"id\":\"" + idEscaped + "\""; - - if ((comma == true) && (isInVector == false)) - { - out += ","; - } - else + if (!this->type.empty()) { - out += (isInVector? "}" : ""); - out += (comma == true)? "," : ""; + jh.addString("type", this->type); } - free(typeEscaped); - free(idEscaped); - free(isPatternEscaped); - - return out; -} - - - -/* **************************************************************************** -* -* EntityId::toJson - -*/ -std::string EntityId::toJson(void) const -{ - JsonObjectHelper jh; - - char* typeEscaped = htmlEscape(type.c_str()); - char* idEscaped = htmlEscape(id.c_str()); - - jh.addString("id", idEscaped); - jh.addString("type", typeEscaped); - - free(typeEscaped); - free(idEscaped); - - return jh.str(); -} - - - -/* **************************************************************************** -* -* EntityId::check - -*/ -std::string EntityId::check(RequestType requestType) -{ - if (id.empty()) + if (!this->typePattern.empty()) { - return "empty entityId:id"; + jh.addString("typePattern", this->typePattern); } - if (!isTrue(isPattern) && !isFalse(isPattern) && !isPattern.empty()) - { - return std::string("invalid isPattern value for entity: /") + isPattern + "/"; - } - - if ((requestType == RegisterContext) && (isTrue(isPattern))) - { - return "isPattern set to true for registrations is currently not supported"; - } - - if (isTrue(isPattern)) - { - regex_t re; - if ((id.find('\0') != std::string::npos) || (!regComp(&re, id.c_str(), REG_EXTENDED))) - { - return "invalid regex for entity id pattern"; - } - regfree(&re); // If regcomp fails it frees up itself (see glibc sources for details) - } - return "OK"; -} - - - -/* **************************************************************************** -* -* EntityId::fill - -*/ -void EntityId::fill(const std::string& _id, const std::string& _type, const std::string& _isPattern, bool _isTypePattern) -{ - id = _id; - type = _type; - isPattern = _isPattern; - isTypePattern = _isTypePattern; + return jh.str(); } @@ -221,12 +116,9 @@ void EntityId::fill(const std::string& _id, const std::string& _type, const std: void EntityId::fill(const struct EntityId* eidP, bool useDefaultType) { id = eidP->id; + idPattern = eidP->idPattern; type = eidP->type; - isPattern = eidP->isPattern; - isTypePattern = eidP->isTypePattern; - servicePath = eidP->servicePath; - creDate = eidP->creDate; - modDate = eidP->modDate; + typePattern = eidP->typePattern; if (useDefaultType && (type.empty())) { @@ -238,54 +130,19 @@ void EntityId::fill(const struct EntityId* eidP, bool useDefaultType) /* **************************************************************************** * -* release - -*/ -void EntityId::release(void) -{ - /* This method is included for the sake of homogeneity */ -} - - - -/* **************************************************************************** -* -* toString - -*/ -std::string EntityId::toString(bool useIsPattern, const std::string& delimiter) -{ - std::string s; - - s = id + delimiter + type; - - if (useIsPattern) - { - s += delimiter + isPattern; - } - - return s; -} - - - -/* **************************************************************************** -* -* EntityId::equal - return TRUE if EXACT match +* EntityId::fill - */ -bool EntityId::equal(EntityId* eP) -{ - return ((eP->id == id) && - (eP->type == type) && - (eP->isPatternIsTrue() == isPatternIsTrue()) && - (eP->isTypePattern == isTypePattern)); -} - - -/* **************************************************************************** -* -* isPatternIsTrue - -*/ -bool EntityId::isPatternIsTrue(void) +void EntityId::fill +( + const std::string& _id, + const std::string& _idPattern, + const std::string& _type, + const std::string& _typePattern +) { - return isTrue(isPattern); + id = _id; + idPattern = _idPattern; + type = _type; + typePattern = _typePattern; } diff --git a/src/lib/ngsi/EntityId.h b/src/lib/ngsi/EntityId.h index bd1bb24398..ab66bc8655 100644 --- a/src/lib/ngsi/EntityId.h +++ b/src/lib/ngsi/EntityId.h @@ -39,37 +39,42 @@ class EntityId { public: - std::string id; // Mandatory - std::string type; // Optional - std::string isPattern; // Optional - bool isTypePattern; // Used by NGSIv2 API - - std::string servicePath; // Not part of payload, just an internal field - - double creDate; // used by dateCreated functionality in NGSIv2 - double modDate; // used by dateModified functionality in NGSIv2 + std::string id; + std::string idPattern; + std::string type; + std::string typePattern; EntityId(); - EntityId(EntityId* eP); - EntityId(const std::string& _id, - const std::string& _type, - const std::string& _isPattern = "", - bool _isTypePattern = false); - void fill(const std::string& _id, const std::string& _type, const std::string& _isPattern, bool _isTypePattern = false); - void fill(const struct EntityId* eidP, bool useDefaultType = false); + EntityId(EntityId* eP); + EntityId(const std::string& _id, + const std::string& _idPattern, + const std::string& _type, + const std::string& _typePattern); - void release(void); - std::string toString(bool useIsPattern = false, const std::string& delimiter = ", "); - bool equal(EntityId* eP); - bool isPatternIsTrue(void); + bool operator==(const EntityId& e) + { + return (id == e.id) && + (idPattern == e.idPattern) && + (type == e.type) && + (typePattern == e.typePattern); + } - std::string toJson(void); - std::string toJsonV1(bool comma, bool isInVector = false); + bool operator!=(const EntityId& e) + { + return (id != e.id) || + (idPattern != e.idPattern) || + (type != e.type) || + (typePattern != e.typePattern); + } - std::string check(RequestType requestType); + void fill(const struct EntityId* eidP, bool useDefaultType = false); + void fill(const std::string& _id, + const std::string& _idPattern, + const std::string& _type, + const std::string& _typePattern); - std::string toJson(void) const; + std::string toJson(void); }; #endif // SRC_LIB_NGSI_ENTITYID_H_ diff --git a/src/lib/ngsi/EntityIdVector.cpp b/src/lib/ngsi/EntityIdVector.cpp index 4477f27723..9b57ef98bf 100644 --- a/src/lib/ngsi/EntityIdVector.cpp +++ b/src/lib/ngsi/EntityIdVector.cpp @@ -30,7 +30,6 @@ #include "logMsg/traceLevels.h" #include "common/globals.h" -#include "common/tag.h" #include "common/JsonHelper.h" #include "alarmMgr/alarmMgr.h" #include "apiTypesV2/EntityVector.h" @@ -58,91 +57,15 @@ std::string EntityIdVector::toJson(void) -/* **************************************************************************** -* -* EntityIdVector::toJsonV1 - -*/ -std::string EntityIdVector::toJsonV1(bool comma) -{ - std::string out = ""; - - if (vec.size() == 0) - { - return ""; - } - - out += startTag("entities", true); - for (unsigned int ix = 0; ix < vec.size(); ++ix) - { - out += vec[ix]->toJsonV1(ix != vec.size() - 1, true); - } - - out += endTag(comma, true); - - return out; -} - - - -/* **************************************************************************** -* -* EntityIdVector::check - -*/ -std::string EntityIdVector::check(RequestType requestType) -{ - // Only OK to be empty if part of a ContextRegistration - if ((requestType == DiscoverContextAvailability) || - (requestType == QueryContext) || - (requestType == SubscribeContext)) - { - if (vec.size() == 0) - { - alarmMgr.badInput(clientIp, "mandatory entity list missing"); - return "No entities"; - } - } - - for (unsigned int ix = 0; ix < vec.size(); ++ix) - { - std::string res; - - if ((res = vec[ix]->check(requestType)) != "OK") - { - alarmMgr.badInput(clientIp, "invalid vector of EntityIds", res); - return res; - } - } - - return "OK"; -} - - - /* **************************************************************************** * * EntityIdVector::lookup - find a matching entity in the entity-vector */ -EntityId* EntityIdVector::lookup(const std::string& id, const std::string& type, const std::string& isPattern) +EntityId* EntityIdVector::lookup(const std::string& id, const std::string& idPattern, const std::string& type, const std::string& typePattern) { - // - // isPattern: "false" or "" is the same - // - std::string isPatternFromParam = isPattern; - if (isPatternFromParam.empty()) - { - isPatternFromParam = "false"; - } - for (unsigned int ix = 0; ix < vec.size(); ++ix) { - std::string isPatternFromVec = vec[ix]->isPattern; - - if (isPatternFromVec.empty()) - { - isPatternFromVec = "false"; - } - - if ((vec[ix]->id == id) && (vec[ix]->type == type) && (isPatternFromVec == isPatternFromParam)) + if ((vec[ix]->id == id) && (vec[ix]->type == type) && (vec[ix]->idPattern == idPattern) && (vec[ix]->typePattern == typePattern)) { return vec[ix]; } @@ -174,7 +97,7 @@ void EntityIdVector::push_back(EntityId* item) */ bool EntityIdVector::push_back_if_absent(EntityId* item) { - if (lookup(item->id, item->type, item->isPattern) == NULL) + if (lookup(item->id, item->idPattern, item->type, item->typePattern) == NULL) { vec.push_back(item); return true; @@ -218,7 +141,6 @@ void EntityIdVector::release(void) { for (unsigned int ix = 0; ix < vec.size(); ++ix) { - vec[ix]->release(); delete(vec[ix]); } @@ -237,7 +159,7 @@ void EntityIdVector::fill(EntityVector& _vec) for (unsigned int ix = 0; ix < _vec.size(); ++ix) { Entity* entityP = _vec[ix]; - EntityId* entityIdP = new EntityId(entityP->id, entityP->type, entityP->isPattern, entityP->isTypePattern); + EntityId* entityIdP = new EntityId(entityP->entityId.id, entityP->entityId.idPattern, entityP->entityId.type, entityP->entityId.typePattern); vec.push_back(entityIdP); } diff --git a/src/lib/ngsi/EntityIdVector.h b/src/lib/ngsi/EntityIdVector.h index c7d9bb1dc3..07ae40e1f1 100644 --- a/src/lib/ngsi/EntityIdVector.h +++ b/src/lib/ngsi/EntityIdVector.h @@ -49,18 +49,16 @@ typedef struct EntityIdVector { std::vector vec; - std::string toJsonV1(bool comma); std::string toJson(void); void push_back(EntityId* item); bool push_back_if_absent(EntityId* item); unsigned int size(void) const; - EntityId* lookup(const std::string& name, const std::string& type, const std::string& isPattern); + EntityId* lookup(const std::string& id, const std::string& idPattern, const std::string& type, const std::string& typePattern); void release(); void fill(EntityVector& _vec); EntityId* operator[](unsigned int ix) const; - std::string check(RequestType requestType); } EntityIdVector; #endif // SRC_LIB_NGSI_ENTITYIDVECTOR_H_ diff --git a/src/lib/ngsi/Metadata.cpp b/src/lib/ngsi/Metadata.cpp index 549502879a..21ddb73e91 100644 --- a/src/lib/ngsi/Metadata.cpp +++ b/src/lib/ngsi/Metadata.cpp @@ -30,7 +30,6 @@ #include "common/globals.h" #include "common/limits.h" -#include "common/tag.h" #include "common/string.h" #include "common/JsonHelper.h" #include "alarmMgr/alarmMgr.h" @@ -234,65 +233,16 @@ Metadata::Metadata(const std::string& _name, const orion::BSONObj& mdB) -/* **************************************************************************** -* -* Metadata::toJsonV1 - -*/ -std::string Metadata::toJsonV1(bool comma) -{ - std::string out = ""; - std::string xValue = toStringValue(); - - out += startTag(); - out += valueTag("name", name, true); - out += valueTag("type", type, true); - - if (compoundValueP != NULL) - { - out += JSON_STR("value") + ":" + compoundValueP->toJson(); - } - else if (valueType == orion::ValueTypeString) - { - out += valueTag("value", xValue, false); - } - else if (valueType == orion::ValueTypeNumber) - { - out += JSON_STR("value") + ":" + xValue; - } - else if (valueType == orion::ValueTypeBoolean) - { - out += JSON_STR("value") + ":" + xValue; - } - else if (valueType == orion::ValueTypeNull) - { - out += JSON_STR("value") + ":" + xValue; - } - else if (valueType == orion::ValueTypeNotGiven) - { - out += JSON_STR("value") + ":" + JSON_STR("not given"); - } - else - { - out += JSON_STR("value") + ":" + JSON_STR("unknown json type"); - } - - out += endTag(comma); - - return out; -} - - - /* **************************************************************************** * * Metadata::check - */ -std::string Metadata::check(ApiVersion apiVersion) +std::string Metadata::check(void) { size_t len; char errorMsg[128]; - if (apiVersion == V2 && (len = strlen(name.c_str())) < MIN_ID_LEN) + if ((len = strlen(name.c_str())) < MIN_ID_LEN) { snprintf(errorMsg, sizeof errorMsg, "metadata name length: %zd, min length supported: %d", len, MIN_ID_LEN); alarmMgr.badInput(clientIp, errorMsg); @@ -312,7 +262,7 @@ std::string Metadata::check(ApiVersion apiVersion) return std::string(errorMsg); } - if (forbiddenIdChars(apiVersion , name.c_str())) + if (forbiddenIdCharsV2(name.c_str())) { alarmMgr.badInput(clientIp, "found a forbidden character in the name of a Metadata", name); return "Invalid characters in metadata name"; @@ -326,14 +276,14 @@ std::string Metadata::check(ApiVersion apiVersion) } - if (apiVersion == V2 && (len = strlen(type.c_str())) < MIN_ID_LEN) + if ((len = strlen(type.c_str())) < MIN_ID_LEN) { snprintf(errorMsg, sizeof errorMsg, "metadata type length: %zd, min length supported: %d", len, MIN_ID_LEN); alarmMgr.badInput(clientIp, errorMsg); return std::string(errorMsg); } - if (forbiddenIdChars(apiVersion, type.c_str())) + if (forbiddenIdCharsV2(type.c_str())) { alarmMgr.badInput(clientIp, "found a forbidden character in the type of a Metadata", type); return "Invalid characters in metadata type"; @@ -346,12 +296,6 @@ std::string Metadata::check(ApiVersion apiVersion) alarmMgr.badInput(clientIp, "found a forbidden character in the value of a Metadata", stringValue); return "Invalid characters in metadata value"; } - - if (apiVersion == V1 && stringValue.empty()) - { - alarmMgr.badInput(clientIp, "missing metadata value", name); - return "missing metadata value"; - } } return "OK"; @@ -374,65 +318,6 @@ void Metadata::release(void) -/* **************************************************************************** -* -* fill - -*/ -void Metadata::fill(const struct Metadata& md) -{ - name = md.name; - type = md.type; - stringValue = md.stringValue; -} - - - -/* **************************************************************************** -* -* toStringValue - -*/ -std::string Metadata::toStringValue(void) const -{ - switch (valueType) - { - case orion::ValueTypeString: - return stringValue; - break; - - case orion::ValueTypeNumber: - if ((type == DATE_TYPE) || (type == DATE_TYPE_ALT)) - { - return JSON_STR(isodate2str(numberValue)); - } - else // regular number - { - return double2string(numberValue); - } - break; - - case orion::ValueTypeBoolean: - return boolValue ? "true" : "false"; - break; - - case orion::ValueTypeNull: - return "null"; - break; - - case orion::ValueTypeNotGiven: - return ""; - break; - - default: - return ""; - break; - } - - // Added to avoid warning when compiling with -fstack-check -fstack-protector - return ""; -} - - - /* **************************************************************************** * * toJson - diff --git a/src/lib/ngsi/Metadata.h b/src/lib/ngsi/Metadata.h index 6faabb18a8..d0d8800e17 100644 --- a/src/lib/ngsi/Metadata.h +++ b/src/lib/ngsi/Metadata.h @@ -89,18 +89,15 @@ typedef struct Metadata Metadata(const std::string& _name, const orion::BSONObj& mdB); ~Metadata(); - std::string toJsonV1(bool comma); std::string toJson(void); void release(void); - void fill(const struct Metadata& md); - std::string toStringValue(void) const; bool compoundItemExists(const std::string& compoundPath, orion::CompoundValueNode** compoundItemPP = NULL); void appendToBsoN(orion::BSONObjBuilder* md, orion::BSONArrayBuilder* mdNames, bool useDefaultType); void addToContext(ExprContextObject* exprContextObjectP, bool legacy); - std::string check(ApiVersion apiVersion); + std::string check(void); } Metadata; #endif // SRC_LIB_NGSI_METADATA_H_ diff --git a/src/lib/ngsi/MetadataVector.cpp b/src/lib/ngsi/MetadataVector.cpp index 3aa773551b..965bf53e1f 100644 --- a/src/lib/ngsi/MetadataVector.cpp +++ b/src/lib/ngsi/MetadataVector.cpp @@ -30,7 +30,6 @@ #include "logMsg/traceLevels.h" #include "common/globals.h" -#include "common/tag.h" #include "common/string.h" #include "common/JsonHelper.h" #include "ngsi/MetadataVector.h" @@ -48,63 +47,10 @@ MetadataVector::MetadataVector(void) -/* **************************************************************************** -* -* MetadataVector::toJsonV1 - -* -* FIXME P5: this method doesn't depend on the class object. Should be moved out of the class? -*/ -std::string MetadataVector::toJsonV1(const std::vector& orderedMetadata, bool comma) -{ - std::string out = ""; - - if (orderedMetadata.size() == 0) - { - return ""; - } - - out += startTag("metadatas", true); - for (unsigned int ix = 0; ix < orderedMetadata.size(); ++ix) - { - out += orderedMetadata[ix]->toJsonV1(ix != orderedMetadata.size() - 1); - } - out += endTag(comma, true); - - - return out; -} - - - -/* **************************************************************************** -* -* MetadataVector::matchFilter - -* -*/ -bool MetadataVector::matchFilter(const std::string& mdName, const std::vector& metadataFilter) -{ - /* Metadata filtering only in the case of actual metadata vector not containing "*" */ - if ((metadataFilter.size() == 0) || (std::find(metadataFilter.begin(), metadataFilter.end(), NGSI_MD_ALL) != metadataFilter.end())) - { - return true; - } - - return std::find(metadataFilter.begin(), metadataFilter.end(), mdName) != metadataFilter.end(); -} - - - /* **************************************************************************** * * MetadataVector::toJson - * -* Metadatas named 'value' or 'type' are not rendered in API version 2, due to the -* compact way in which API v2 is rendered. Metadatas named 'value' or 'type' would simply -* collide with the 'value' and 'type' of the attribute itself (holder of the metadata). -* -* If anybody needs a metadata named 'value' or 'type', then API v1 -* will have to be used to retreive that information. -* */ std::string MetadataVector::toJson(const std::vector& orderedMetadata) { @@ -124,13 +70,13 @@ std::string MetadataVector::toJson(const std::vector& orderedMetadata * * MetadataVector::check - */ -std::string MetadataVector::check(ApiVersion apiVersion) +std::string MetadataVector::check(void) { for (unsigned int ix = 0; ix < vec.size(); ++ix) { std::string res; - if ((res = vec[ix]->check(apiVersion)) != "OK") + if ((res = vec[ix]->check()) != "OK") { return res; } @@ -197,22 +143,6 @@ void MetadataVector::release(void) -/* **************************************************************************** -* -* MetadataVector::fill - -*/ -void MetadataVector::fill(MetadataVector* mvP) -{ - for (unsigned int ix = 0; ix < mvP->size(); ++ix) - { - Metadata* mP = new Metadata((*mvP)[ix]); - - push_back(mP); - } -} - - - /* **************************************************************************** * * MetadataVector::lookupByName - @@ -243,6 +173,6 @@ void MetadataVector::toBson(orion::BSONObjBuilder* md, orion::BSONArrayBuilder* this->vec[ix]->appendToBsoN(md, mdNames, useDefaultType); LM_T(LmtMongo, ("new custom metadata: {name: %s, type: %s, value: %s}", - this->vec[ix]->name.c_str(), this->vec[ix]->type.c_str(), this->vec[ix]->toStringValue().c_str())); + this->vec[ix]->name.c_str(), this->vec[ix]->type.c_str(), this->vec[ix]->toJson().c_str())); } } diff --git a/src/lib/ngsi/MetadataVector.h b/src/lib/ngsi/MetadataVector.h index 38ec041308..0fc5201363 100644 --- a/src/lib/ngsi/MetadataVector.h +++ b/src/lib/ngsi/MetadataVector.h @@ -48,22 +48,17 @@ typedef struct MetadataVector MetadataVector(void); - std::string toJsonV1(const std::vector& orderedMetadata, bool comma); std::string toJson(const std::vector& orderedMetadata); - std::string check(ApiVersion apiVersion); + std::string check(void); void push_back(Metadata* item); unsigned int size(void) const; Metadata* lookupByName(const std::string& _name) const; void release(void); - void fill(MetadataVector* mV); Metadata* operator[](unsigned int ix) const; void toBson(orion::BSONObjBuilder* md, orion::BSONArrayBuilder* mdNames, bool useDefaultType); - -private: - bool matchFilter(const std::string& mdName, const std::vector& metadataFilter); } MetadataVector; diff --git a/src/lib/ngsi/NotifyCondition.cpp b/src/lib/ngsi/NotifyCondition.cpp deleted file mode 100644 index 86453686a2..0000000000 --- a/src/lib/ngsi/NotifyCondition.cpp +++ /dev/null @@ -1,136 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/globals.h" -#include "common/tag.h" -#include "ngsi/Request.h" -#include "ngsi/NotifyCondition.h" - - - -/* **************************************************************************** -* -* NotifyCondition::NotifyCondition - -*/ -NotifyCondition::NotifyCondition() -{ -} - - - -/* **************************************************************************** -* -* NotifyCondition::NotifyCondition - -*/ -NotifyCondition::NotifyCondition(NotifyCondition* ncP) -{ - type = ncP->type; - condValueList.fill(ncP->condValueList); - restriction.set(ncP->restriction.get()); -} - - - -/* **************************************************************************** -* -* NotifyCondition::toJsonV1 - -*/ -std::string NotifyCondition::toJsonV1(bool notLastInVector) -{ - std::string out = ""; - - bool condValueListRendered = condValueList.size() != 0; - bool restrictionRendered = !restriction.get().empty(); - bool commaAfterRestriction = false; // last element - bool commaAfterCondValueList = restrictionRendered; - bool commaAfterType = condValueListRendered || restrictionRendered; - - out += startTag(); - out += valueTag("type", type, commaAfterType); - out += condValueList.toJsonV1(commaAfterCondValueList); - out += restriction.toJsonV1(commaAfterRestriction); - out += endTag(); - - return out; -} - - - -/* **************************************************************************** -* -* NotifyCondition::check - -* -* FIXME: P5 - in case of errors a formated result string should be returned ... ? -*/ -std::string NotifyCondition::check -( - RequestType requestType, - const std::string& predetectedError, - int counter -) -{ - std::string res; - - if (type.empty()) - { - return "empty type for NotifyCondition"; - } - else if (strcasecmp(type.c_str(), ON_CHANGE_CONDITION) == 0) - { - } - else - { - return std::string("invalid notify condition type: /") + type + "/"; - } - - if ((res = condValueList.check()) != "OK") - { - return res; - } - - if ((res = restriction.check()) != "OK") - { - return res; - } - - return "OK"; -} - - - -/* **************************************************************************** -* -* NotifyCondition::release - -*/ -void NotifyCondition::release(void) -{ - condValueList.release(); -} diff --git a/src/lib/ngsi/NotifyCondition.h b/src/lib/ngsi/NotifyCondition.h deleted file mode 100644 index 8b44308005..0000000000 --- a/src/lib/ngsi/NotifyCondition.h +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef SRC_LIB_NGSI_NOTIFYCONDITION_H_ -#define SRC_LIB_NGSI_NOTIFYCONDITION_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include - -#include "ngsi/Request.h" -#include "ngsi/RestrictionString.h" -#include "ngsi/ConditionValueList.h" - -#define ON_CHANGE_CONDITION "ONCHANGE" - - - -/* **************************************************************************** -* -* NotifyCondition - -*/ -typedef struct NotifyCondition -{ - std::string type; // Mandatory - ConditionValueList condValueList; // Optional - RestrictionString restriction; // Optional - - NotifyCondition(); - NotifyCondition(NotifyCondition* ncP); - - std::string toJsonV1(bool notLastInVector); - void release(void); - - std::string check(RequestType requestType, - const std::string& predetectedError, - int counter); -} NotifyCondition; - -#endif // SRC_LIB_NGSI_NOTIFYCONDITION_H_ diff --git a/src/lib/ngsi/NotifyConditionVector.cpp b/src/lib/ngsi/NotifyConditionVector.cpp deleted file mode 100644 index 5f9799c521..0000000000 --- a/src/lib/ngsi/NotifyConditionVector.cpp +++ /dev/null @@ -1,164 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/globals.h" -#include "common/tag.h" -#include "ngsi/NotifyConditionVector.h" - - - -/* **************************************************************************** -* -* NotifyConditionVector::NotifyConditionVector - -*/ -NotifyConditionVector::NotifyConditionVector() -{ -} - - - -/* **************************************************************************** -* -* NotifyConditionVector::toJsonV1 - -*/ -std::string NotifyConditionVector::toJsonV1(bool comma) -{ - std::string out = ""; - - if (vec.size() == 0) - { - return ""; - } - - out += startTag("notifyConditions", true); - for (unsigned int ix = 0; ix < vec.size(); ++ix) - { - out += vec[ix]->toJsonV1(ix != vec.size() - 1); - } - out += endTag(comma, true); - - return out; -} - - - -/* **************************************************************************** -* -* NotifyConditionVector::check - -*/ -std::string NotifyConditionVector::check -( - RequestType requestType, - const std::string& predetectedError, - int counter -) -{ - for (unsigned int ix = 0; ix < vec.size(); ++ix) - { - std::string res; - - if ((res = vec[ix]->check(requestType, predetectedError, counter)) != "OK") - { - return res; - } - } - - return "OK"; -} - - - -/* **************************************************************************** -* -* NotifyConditionVector::push_back - -*/ -void NotifyConditionVector::push_back(NotifyCondition* item) -{ - vec.push_back(item); -} - - - -/* **************************************************************************** -* -* NotifyConditionVector::operator[] - -*/ -NotifyCondition* NotifyConditionVector::operator[] (unsigned int ix) const -{ - if (ix < vec.size()) - { - return vec[ix]; - } - return NULL; -} - - - -/* **************************************************************************** -* -* NotifyConditionVector::size - -*/ -unsigned int NotifyConditionVector::size(void) const -{ - return vec.size(); -} - - - -/* **************************************************************************** -* -* NotifyConditionVector::release - -*/ -void NotifyConditionVector::release(void) -{ - for (unsigned int ix = 0; ix < vec.size(); ++ix) - { - vec[ix]->release(); - delete vec[ix]; - } - - vec.clear(); -} - - - -/* **************************************************************************** -* -* NotifyConditionVector::fill - -*/ -void NotifyConditionVector::fill(const NotifyConditionVector& nv) -{ - for (unsigned int ncIx = 0; ncIx < nv.size(); ++ncIx) - { - NotifyCondition* ncP = new NotifyCondition(nv[ncIx]); - push_back(ncP); - } -} diff --git a/src/lib/ngsi/NotifyConditionVector.h b/src/lib/ngsi/NotifyConditionVector.h deleted file mode 100644 index 0a77d6e231..0000000000 --- a/src/lib/ngsi/NotifyConditionVector.h +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef SRC_LIB_NGSI_NOTIFYCONDITIONVECTOR_H_ -#define SRC_LIB_NGSI_NOTIFYCONDITIONVECTOR_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "ngsi/NotifyCondition.h" - - - -/* **************************************************************************** -* -* NotifyConditionVector - -*/ -typedef struct NotifyConditionVector -{ - std::vector vec; - - NotifyConditionVector(); - - std::string toJsonV1(bool comma); - void push_back(NotifyCondition* item); - unsigned int size(void) const; - void release(void); - void fill(const NotifyConditionVector& nv); - - std::string check(RequestType requestType, - const std::string& predetectedError, - int counter); - - NotifyCondition* operator[] (unsigned int ix) const; - -} NotifyConditionVector; - -#endif // SRC_LIB_NGSI_NOTIFYCONDITIONVECTOR_H_ diff --git a/src/lib/ngsi/Originator.cpp b/src/lib/ngsi/Originator.cpp deleted file mode 100644 index 97d6c1052c..0000000000 --- a/src/lib/ngsi/Originator.cpp +++ /dev/null @@ -1,104 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Fermin Galan -*/ -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/globals.h" -#include "common/tag.h" -#include "ngsi/Request.h" -#include "ngsi/Originator.h" - - - -/* **************************************************************************** -* -* Originator::check - -*/ -std::string Originator::check(void) -{ - return "OK"; -} - - - -/* **************************************************************************** -* -* Originator::isEmpty - -*/ -bool Originator::isEmpty(void) -{ - return (string.empty())? true : false; -} - - - -/* **************************************************************************** -* -* Originator::set - -*/ -void Originator::set(const std::string& value) -{ - string = value; -} - - - -/* **************************************************************************** -* -* Originator::get - -*/ -std::string Originator::get(void) -{ - return string; -} - - - -/* **************************************************************************** -* -* Originator::toJsonV1 - -*/ -std::string Originator::toJsonV1(bool comma) -{ - if (string.empty()) - { - return ""; - } - - return valueTag("originator", string, comma); -} - - - -/* **************************************************************************** -* -* Originator::c_str - -*/ -const char* Originator::c_str(void) -{ - return string.c_str(); -} diff --git a/src/lib/ngsi/Originator.h b/src/lib/ngsi/Originator.h deleted file mode 100644 index fa6e67d01a..0000000000 --- a/src/lib/ngsi/Originator.h +++ /dev/null @@ -1,51 +0,0 @@ -#ifndef SRC_LIB_NGSI_ORIGINATOR_H_ -#define SRC_LIB_NGSI_ORIGINATOR_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Fermin Galan -*/ -#include - -#include "ngsi/Request.h" - - - -/* **************************************************************************** -* -* Originator - -*/ -typedef struct Originator -{ - std::string string; - - void set(const std::string& value); - std::string get(void); - bool isEmpty(void); - std::string toJsonV1(bool comma); - const char* c_str(); - - std::string check(void); -} Originator; - -#endif // SRC_LIB_NGSI_ORIGINATOR_H_ diff --git a/src/lib/ngsi/ParseData.h b/src/lib/ngsi/ParseData.h index e1ede102ec..ee62b5d7a5 100644 --- a/src/lib/ngsi/ParseData.h +++ b/src/lib/ngsi/ParseData.h @@ -29,25 +29,13 @@ #include "orionTypes/areas.h" #include "ngsi/EntityId.h" -#include "ngsi/ContextRegistrationAttribute.h" #include "ngsi/ContextElementResponse.h" #include "ngsi/Metadata.h" -#include "ngsi9/RegisterContextRequest.h" -#include "ngsi9/RegisterContextResponse.h" -#include "ngsi9/DiscoverContextAvailabilityRequest.h" -#include "ngsi9/DiscoverContextAvailabilityResponse.h" -#include "ngsi10/SubscribeContextRequest.h" #include "ngsi10/QueryContextRequest.h" #include "ngsi10/QueryContextResponse.h" -#include "ngsi10/UnsubscribeContextRequest.h" #include "ngsi10/UpdateContextRequest.h" #include "ngsi10/UpdateContextResponse.h" -#include "ngsi10/UpdateContextSubscriptionRequest.h" #include "ngsi10/NotifyContextRequest.h" -#include "convenience/RegisterProviderRequest.h" -#include "convenience/UpdateContextElementRequest.h" -#include "convenience/AppendContextElementRequest.h" -#include "convenience/UpdateContextAttributeRequest.h" #include "apiTypesV2/Entity.h" #include "apiTypesV2/BatchQuery.h" #include "apiTypesV2/BatchUpdate.h" @@ -56,59 +44,6 @@ -/* **************************************************************************** -* -* RegisterContextData - output data and help pointers for RegisterContextRequest -*/ -struct RegisterContextData -{ - RegisterContextData(): crP(NULL), entityIdP(NULL), attributeP(NULL), attributeMetadataP(NULL), registrationMetadataP(NULL) {} - RegisterContextRequest res; - ContextRegistration* crP; - EntityId* entityIdP; - ContextRegistrationAttribute* attributeP; - Metadata* attributeMetadataP; - Metadata* registrationMetadataP; -}; - - - -/* **************************************************************************** -* -* RegisterContextResponseData - output data and help pointers for RegisterContextRequest -*/ -typedef struct RegisterContextResponseData -{ - RegisterContextResponse res; -} RegisterContextResponseData; - - - -/* **************************************************************************** -* -* DiscoverContextAvailabilityData - -*/ -struct DiscoverContextAvailabilityData -{ - DiscoverContextAvailabilityData(): entityIdP(NULL), scopeP(NULL) {} - DiscoverContextAvailabilityRequest res; - EntityId* entityIdP; - Scope* scopeP; -}; - - - -/* **************************************************************************** -* -* DiscoverContextAvailabilityResponseData - -*/ -typedef struct DiscoverContextAvailabilityResponseData -{ - DiscoverContextAvailabilityResponse res; -} DiscoverContextAvailabilityResponseData; - - - /* **************************************************************************** * * QueryContextData - @@ -142,35 +77,6 @@ struct QueryContextResponseData -/* **************************************************************************** -* -* SubscribeContextData - -*/ -struct SubscribeContextData -{ - SubscribeContextData():entityIdP(NULL), attributeMetadataP(NULL), restrictionP(NULL), notifyConditionP(NULL), scopeP(NULL), vertexP(NULL) {} - SubscribeContextRequest res; - EntityId* entityIdP; - Metadata* attributeMetadataP; - Restriction* restrictionP; - NotifyCondition* notifyConditionP; - Scope* scopeP; - orion::Point* vertexP; -}; - - - -/* **************************************************************************** -* -* UnsubscribeContextData - -*/ -typedef struct UnsubscribeContextData -{ - UnsubscribeContextRequest res; -} UnsubscribeContextData; - - - /* **************************************************************************** * * NotifyContextData - @@ -217,76 +123,6 @@ struct UpdateContextResponseData -/* **************************************************************************** -* -* UpdateContextSubscriptionData - -*/ -struct UpdateContextSubscriptionData -{ - UpdateContextSubscriptionData(): notifyConditionP(NULL), scopeP(NULL), vertexP(NULL) {} - UpdateContextSubscriptionRequest res; - NotifyCondition* notifyConditionP; - Scope* scopeP; - orion::Point* vertexP; -}; - - - -/* **************************************************************************** -* -* RegisterProviderRequestData - -*/ -struct RegisterProviderRequestData -{ - RegisterProviderRequestData(): metadataP(NULL) {} - RegisterProviderRequest res; - Metadata* metadataP; -}; - - - -/* **************************************************************************** -* -* UpdateContextElementData - -*/ -struct UpdateContextElementData -{ - UpdateContextElementData(): attributeP(NULL), metadataP(NULL) {} - UpdateContextElementRequest res; - ContextAttribute* attributeP; - Metadata* metadataP; -}; - - - -/* **************************************************************************** -* -* AppendContextElementData - -*/ -struct AppendContextElementData -{ - AppendContextElementData(): attributeP(NULL), metadataP(NULL) {} - AppendContextElementRequest res; - ContextAttribute* attributeP; - Metadata* metadataP; -}; - - - -/* **************************************************************************** -* -* UpdateContextAttributeData - -*/ -struct UpdateContextAttributeData -{ - UpdateContextAttributeData(): metadataP(NULL) {} - UpdateContextAttributeRequest res; - Metadata* metadataP; - ContextAttribute attribute; -}; - - - /* **************************************************************************** * * EntityData - @@ -344,41 +180,27 @@ typedef struct BatchUpdateData /* **************************************************************************** * * ParseData - +* */ typedef struct ParseData { - ParseData(): lastContextAttribute(NULL) { } - - std::string errorString; - ContextAttribute* lastContextAttribute; - RegisterContextData rcr; - DiscoverContextAvailabilityData dcar; - - QueryContextData qcr; - SubscribeContextData scr; - UnsubscribeContextData uncr; - UpdateContextData upcr; - UpdateContextSubscriptionData ucsr; - NotifyContextData ncr; - - RegisterProviderRequestData rpr; - UpdateContextElementData ucer; - AppendContextElementData acer; - UpdateContextAttributeData upcar; - - RegisterContextResponseData rcrs; - DiscoverContextAvailabilityResponseData dcars; - QueryContextResponseData qcrs; - UpdateContextResponseData upcrs; - + // filled by jsonRequestTreat() function in jsonRequestTreat.cpp EntityData ent; AttributeData attr; AttributeValueData av; BatchQueryData bq; BatchUpdateData bu; - - ngsiv2::SubscriptionUpdate subsV2; + ngsiv2::SubscriptionUpdate sub; ngsiv2::Registration reg; + NotifyContextData ncr; + + // Used in postQueryContext() function for the forwarding logic + QueryContextData qcr; + QueryContextResponseData qcrs; + + // Used in postUpdateContext() function for the forwarding logic + UpdateContextData upcr; + UpdateContextResponseData upcrs; } ParseData; #endif // SRC_LIB_NGSI_PARSEDATA_H_ diff --git a/src/lib/ngsi/ProvidingApplication.cpp b/src/lib/ngsi/ProvidingApplication.cpp deleted file mode 100644 index d4927f12fb..0000000000 --- a/src/lib/ngsi/ProvidingApplication.cpp +++ /dev/null @@ -1,177 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/globals.h" -#include "common/tag.h" -#include "ngsi/Request.h" -#include "ngsi/ProvidingApplication.h" - - - -/* **************************************************************************** -* -* ProvidingApplication::ProvidingApplication - -*/ -ProvidingApplication::ProvidingApplication() -{ - /* It is better to have a default constructor than to leave mimeType with a random value */ - string = ""; - providerFormat = PfJson; -} - - - -/* **************************************************************************** -* -* ProvidingApplication::check - -*/ -std::string ProvidingApplication::check(void) -{ - if (isEmpty()) - { - return "no providing application"; - } - - return "OK"; -} - - - -/* **************************************************************************** -* -* ProvidingApplication::isEmpty - -*/ -bool ProvidingApplication::isEmpty(void) -{ - return (string.empty())? true : false; -} - - - -/* **************************************************************************** -* -* ProvidingApplication::set - -*/ -void ProvidingApplication::set(const std::string& value) -{ - string = value; -} - - - -/* **************************************************************************** -* -* ProvidingApplication::setProviderFormat - -*/ -void ProvidingApplication::setProviderFormat(const ProviderFormat _providerFormat) -{ - providerFormat = _providerFormat; -} - - - -/* **************************************************************************** -* -* ProvidingApplication::setRegId - -*/ -void ProvidingApplication::setRegId(const std::string& _regId) -{ - regId = _regId; -} - - - -/* **************************************************************************** -* -* ProvidingApplication::getProviderFormat - -*/ -ProviderFormat ProvidingApplication::getProviderFormat(void) -{ - return providerFormat; -} - - - -/* **************************************************************************** -* -* ProvidingApplication::getRegId - -*/ -std::string ProvidingApplication::getRegId(void) -{ - return regId; -} - - - -/* **************************************************************************** -* -* ProvidingApplication::getRegId - -*/ -std::string ProvidingApplication::get(void) -{ - return string; -} - - - -/* **************************************************************************** -* -* ProvidingApplication::toJsonV1 - -*/ -std::string ProvidingApplication::toJsonV1(bool comma) -{ - if (string.empty()) - { - return ""; - } - - return valueTag("providingApplication", string, comma); -} - - - -/* **************************************************************************** -* -* ProvidingApplication::c_str - -*/ -const char* ProvidingApplication::c_str(void) -{ - return string.c_str(); -} - - - -/* **************************************************************************** -* -* release - -*/ -void ProvidingApplication::release(void) -{ - /* This method is included for the sake of homogeneity */ -} diff --git a/src/lib/ngsi/ProvidingApplication.h b/src/lib/ngsi/ProvidingApplication.h deleted file mode 100644 index 4437dc4408..0000000000 --- a/src/lib/ngsi/ProvidingApplication.h +++ /dev/null @@ -1,72 +0,0 @@ -#ifndef SRC_LIB_NGSI_PROVIDINGAPPLICATION_H_ -#define SRC_LIB_NGSI_PROVIDINGAPPLICATION_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include - -#include "common/MimeType.h" -#include "ngsi/Request.h" - - - -/* **************************************************************************** -* -* ProviderFormat - -*/ -typedef enum ProviderFormat -{ - PfNone, - PfJson, - PfV2 -} ProviderFormat; - - - -/* **************************************************************************** -* -* ProvidingApplication - -*/ -typedef struct ProvidingApplication -{ - std::string string; - ProviderFormat providerFormat; // PfJson ("JSON" in mongo): NGSIv1, PfV2: NGSIv2 - std::string regId; // RegId associated to the provider (for log purposes) - - ProvidingApplication(); - void set(const std::string& value); - void setProviderFormat(const ProviderFormat _providerFormat); - void setRegId(const std::string& _regId); - std::string get(void); - ProviderFormat getProviderFormat(void); - std::string getRegId(void); - bool isEmpty(void); - std::string toJsonV1(bool comma); - const char* c_str(void); - void release(void); - std::string check(void); -} ProvidingApplication; - -#endif // SRC_LIB_NGSI_PROVIDINGAPPLICATION_H_ diff --git a/src/lib/ngsi/Reference.cpp b/src/lib/ngsi/Reference.cpp deleted file mode 100644 index 2d66653048..0000000000 --- a/src/lib/ngsi/Reference.cpp +++ /dev/null @@ -1,124 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/globals.h" -#include "common/tag.h" -#include "common/string.h" -#include "ngsi/Request.h" -#include "ngsi/Reference.h" - - - -/* **************************************************************************** -* -* Reference::check - -*/ -std::string Reference::check(RequestType requestType) -{ - if (string.empty()) - { - if (requestType == SubscribeContext) - { - return "Empty Reference"; - } - } - - std::string url = string; - std::string host; - int port; - std::string path; - std::string protocol; - - if (parseUrl(url, host, port, path, protocol) == false) - { - return "Invalid URL"; - } - - return "OK"; -} - - - -/* **************************************************************************** -* -* Reference::isEmpty - -*/ -bool Reference::isEmpty(void) -{ - return (string.empty())? true : false; -} - - - -/* **************************************************************************** -* -* Reference::set - -*/ -void Reference::set(const std::string& value) -{ - string = value; -} - - - -/* **************************************************************************** -* -* Reference::get - -*/ -std::string Reference::get(void) -{ - return string; -} - - - -/* **************************************************************************** -* -* Reference::toJsonV1 - -*/ -std::string Reference::toJsonV1(bool comma) -{ - if (string.empty()) - { - return ""; - } - - return valueTag("reference", string, comma); -} - - - -/* **************************************************************************** -* -* Reference::c_str - -*/ -const char* Reference::c_str(void) -{ - return string.c_str(); -} diff --git a/src/lib/ngsi/Reference.h b/src/lib/ngsi/Reference.h deleted file mode 100644 index 0e8b24b294..0000000000 --- a/src/lib/ngsi/Reference.h +++ /dev/null @@ -1,51 +0,0 @@ -#ifndef SRC_LIB_NGSI_REFERENCE_H_ -#define SRC_LIB_NGSI_REFERENCE_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include - -#include "ngsi/Request.h" - - - -/* **************************************************************************** -* -* Reference - -*/ -typedef struct Reference -{ - std::string string; - - void set(const std::string& value); - std::string get(void); - bool isEmpty(void); - std::string toJsonV1(bool comma); - const char* c_str(); - - std::string check(RequestType requestType); -} Reference; - -#endif // SRC_LIB_NGSI_REFERENCE_H_ diff --git a/src/lib/ngsi/RegistrationId.cpp b/src/lib/ngsi/RegistrationId.cpp deleted file mode 100644 index fed6c7caef..0000000000 --- a/src/lib/ngsi/RegistrationId.cpp +++ /dev/null @@ -1,140 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/globals.h" -#include "common/idCheck.h" -#include "common/tag.h" -#include "ngsi/Request.h" -#include "ngsi/RegistrationId.h" - - - -/* **************************************************************************** -* -* RegistrationId::RegistrationId - -*/ -RegistrationId::RegistrationId() -{ -} - - - -/* **************************************************************************** -* -* RegistrationId::RegistrationId - -*/ -RegistrationId::RegistrationId(const std::string& regId) : string(regId) -{ -} - - - -/* **************************************************************************** -* -* RegistrationId::check - -*/ -std::string RegistrationId::check(void) -{ - std::string out = "OK"; - - if (!string.empty()) - { - out = idCheck(string); - } - - return out; -} - - - -/* **************************************************************************** -* -* RegistrationId::isEmpty - -*/ -bool RegistrationId::isEmpty(void) -{ - return (string.empty())? true : false; -} - - - -/* **************************************************************************** -* -* RegistrationId::set - -*/ -void RegistrationId::set(const std::string& value) -{ - string = value; -} - - - -/* **************************************************************************** -* -* RegistrationId::get - -*/ -std::string RegistrationId::get(void) const -{ - return string; -} - - - -/* **************************************************************************** -* -* RegistrationId::toJsonV1 - -*/ -std::string RegistrationId::toJsonV1(RequestType requestType, bool comma) -{ - if (string.empty()) - { - if (requestType == RegisterResponse) // registrationId is MANDATORY for RegisterContextResponse - { - string = "000000000000000000000000"; - LM_T(LmtOldInfo, ("No registrationId - setting the registrationId to 24 zeroes")); - } - else - { - return ""; - } - } - - return valueTag("registrationId", string, comma); -} - - - -/* **************************************************************************** -* -* release - -*/ -void RegistrationId::release(void) -{ - /* This method is included for the sake of homogeneity */ -} diff --git a/src/lib/ngsi/RegistrationId.h b/src/lib/ngsi/RegistrationId.h deleted file mode 100644 index 6a9ba149e0..0000000000 --- a/src/lib/ngsi/RegistrationId.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef SRC_LIB_NGSI_REGISTRATIONID_H_ -#define SRC_LIB_NGSI_REGISTRATIONID_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include - -#include "ngsi/Request.h" - - - -/* **************************************************************************** -* -* RegistrationId - -*/ -typedef struct RegistrationId -{ - std::string string; - - RegistrationId(); - RegistrationId(const std::string& regId); - - void set(const std::string& value); - std::string get(void) const; - bool isEmpty(void); - std::string toJsonV1(RequestType requestType, bool comma); - void release(void); - - std::string check(void); -} RegistrationId; - -#endif // SRC_LIB_NGSI_REGISTRATIONID_H_ diff --git a/src/lib/ngsi/Request.cpp b/src/lib/ngsi/Request.cpp index b81db82c7d..3c0755dae2 100644 --- a/src/lib/ngsi/Request.cpp +++ b/src/lib/ngsi/Request.cpp @@ -33,92 +33,44 @@ /* **************************************************************************** * * requestType - +* +* FIXME PR: review this list */ const char* requestType(RequestType rt) { switch (rt) { case NoRequest: return "NoRequest"; - case RegisterContext: return "RegisterContextRequest"; - case RegisterResponse: return "RegisterContextResponse"; - case DiscoverContextAvailability: return "DiscoverContextAvailabilityRequest"; - case QueryContext: return "QueryContextRequest"; - case RtQueryContextResponse: return "QueryContextResponse"; - case SubscribeContext: return "SubscribeContextRequest"; - case UpdateContextSubscription: return "UpdateContextSubscriptionRequest"; - case UnsubscribeContext: return "UnsubscribeContextRequest"; - case NotifyContext: return "NotifyContextRequest"; - case NotifyContextSent: return "NotifyContextRequestSent"; - case UpdateContext: return "UpdateContextRequest"; - case RtUpdateContextResponse: return "UpdateContextResponse"; - - case ContextEntitiesByEntityId: return "ContextEntitiesByEntityId"; - case ContextEntityAttributes: return "ContextEntityAttributes"; - case EntityByIdAttributeByName: return "EntityByIdAttributeByName"; - case ContextEntityTypes: return "ContextEntityTypes"; - case ContextEntityTypeAttributeContainer: return "ContextEntityTypeAttributeContainer"; - case ContextEntityTypeAttribute: return "ContextEntityTypeAttribute"; - case IndividualContextEntity: return "IndividualContextEntity"; - case IndividualContextEntityAttributes: return "IndividualContextEntityAttributes"; - case AttributeValueInstance: return "AttributeValueInstance"; - case AttributeValueInstanceWithTypeAndId: return "AttributeValueInstanceWithTypeAndId"; - case IndividualContextEntityAttribute: return "IndividualContextEntityAttribute"; - case IndividualContextEntityAttributeWithTypeAndId: return "IndividualContextEntityAttributeWithTypeAndId"; - case UpdateContextElement: return "UpdateContextElement"; - case AppendContextElement: return "AppendContextElement"; - case UpdateContextAttribute: return "UpdateContextAttribute"; - case Ngsi10ContextEntityTypes: return "Ngsi10ContextEntityTypes"; - case Ngsi10ContextEntityTypesAttributeContainer: return "Ngsi10ContextEntityTypesAttributeContainer"; - case Ngsi10ContextEntityTypesAttribute: return "Ngsi10ContextEntityTypesAttribute"; - case Ngsi10SubscriptionsConvOp: return "Ngsi10SubscriptionsConvOp"; + // pure v2 + case EntryPointsRequest: return "EntryPointsRequest"; + case EntitiesRequest: return "EntitiesRequest"; + case EntityRequest: return "EntityRequest"; + case EntityAttributeRequest: return "EntityAttributeRequest"; + case EntityAttributeValueRequest: return "EntityAttributeValueRequest"; + case EntityAllTypesRequest: return "EntityAllTypesRequest"; + case EntityTypeRequest: return "EntityTypeRequest"; + case SubscriptionsRequest: return "SubscriptionsRequest"; + case SubscriptionRequest: return "SubscriptionRequest"; + case RegistrationRequest: return "RegistrationRequest"; + case RegistrationsRequest: return "RegistrationsRequest"; + case BatchQueryRequest: return "BatchQueryRequest"; + case BatchUpdateRequest: return "BatchUpdateRequest"; + case NotifyContext: return "NotifyContextRequest"; + // administrative requests case LogTraceRequest: return "LogTrace"; + case StatisticsRequest: return "Statistics"; case LogLevelRequest: return "LogLevel"; case SemStateRequest: return "SemState"; - case MetricsRequest: return "Metrics"; case VersionRequest: return "Version"; - case StatisticsRequest: return "Statistics"; + case MetricsRequest: return "Metrics"; + + // requests enabled in DEBUG compilation case ExitRequest: return "Exit"; case LeakRequest: return "Leak"; - case InvalidRequest: return "InvalidRequest"; - - case RtUnsubscribeContextResponse: return "UnsubscribeContextResponse"; - case RtSubscribeResponse: return "SubscribeResponse"; - case RtSubscribeError: return "SubscribeError"; - case RtContextElementResponse: return "ContextElementResponse"; - case RtContextAttributeResponse: return "ContextAttributeResponse"; - case RtEntityTypesResponse: return "EntityTypesResponse"; - case RtAttributesForEntityTypeResponse: return "AttributesForEntityTypeResponse"; - case EntityTypes: return "EntityTypes"; - case AttributesForEntityType: return "AttributesForEntityType"; - case AllContextEntities: return "AllContextEntities"; - case AllEntitiesWithTypeAndId: return "AllEntitiesWithTypeAndId"; - case ContextEntitiesByEntityIdAndType: return "ContextEntitiesByEntityIdAndType"; - case EntityByIdAttributeByNameIdAndType: return "EntityByIdAttributeByNameIdAndType"; - - case EntitiesRequest: return "EntitiesRequest"; - case EntitiesResponse: return "EntitiesResponse"; - case EntryPointsRequest: return "EntryPointsRequest"; - case EntryPointsResponse: return "EntryPointsResponse"; - - case EntityRequest: return "EntityRequest"; - case EntityResponse: return "EntityResponse"; - case EntityAttributeRequest: return "EntityAttributeRequest"; - case EntityAttributeResponse: return "EntityAttributeResponse"; - case EntityAttributeValueRequest: return "EntityAttributeValueRequest"; - case EntityAttributeValueResponse: return "EntityAttributeValueResponse"; - - case EntityTypeRequest: return "EntityTypeRequest"; - case EntityAllTypesRequest: return "EntityAllTypesRequest"; - case SubscriptionsRequest: return "SubscriptionsRequest"; - case SubscriptionRequest: return "SubscriptionRequest"; - case BatchQueryRequest: return "BatchQueryRequest"; - case BatchUpdateRequest: return "BatchUpdateRequest"; - - case RegistrationRequest: return "RegistrationRequest"; - case RegistrationsRequest: return "RegistrationsRequest"; + case InvalidRequest: return "InvalidRequest"; } return ""; @@ -152,6 +104,7 @@ std::string requestTypeForCounter(RequestType rt, const std::string& _prefix) case RegistrationRequest: return "/v2/registrations/{id}"; case BatchQueryRequest: return "/v2/op/query"; case BatchUpdateRequest: return "/v2/op/update"; + case NotifyContext: return "/v2/op/notify"; // administrative requests case LogTraceRequest: return "/log/trace[/{level}]"; @@ -171,102 +124,6 @@ std::string requestTypeForCounter(RequestType rt, const std::string& _prefix) return "/statistics"; } - // pure v1 - // FIXME: disable unused NGSv1 API routes in Orion 3.9.0, to be definetively removed at some point of the future - //case RegisterContext: return "/v1/registry/registerContext"; - //case ContextEntitiesByEntityId: return "/v1/registry/contextEntities/{id}"; - //case ContextEntitiesByEntityIdAndType: return "/v1/registry/contextEntities/type/{type}/id/{id}"; - //case ContextEntityAttributes: return "/v1/registry/contextEntities/{id}/attributes"; - //case ContextEntityTypeAttribute: return "/v1/registry/contextEntityTypes/{type}/attributes/{name}"; - //case ContextEntityTypeAttributeContainer: return "/v1/registry/contextEntityTypes/{type}/attributes"; - //case ContextEntityTypes: return "/v1/registry/contextEntityTypes/{type}"; - //case DiscoverContextAvailability: return "/v1/registry/discoverContextAvailability"; - //case EntityByIdAttributeByName: return "/v1/registry/contextEntities/{id}/attributes/{name}"; - //case EntityByIdAttributeByNameIdAndType: return "/v1/registry/contextEntities/type/{type}/id/{id}/attributes/{name}"; - //case EntityTypes: return "/v1/contextTypes"; - case RegisterContext: - case ContextEntitiesByEntityId: - case ContextEntitiesByEntityIdAndType: - case ContextEntityAttributes: - case ContextEntityTypeAttribute: - case ContextEntityTypeAttributeContainer: - case ContextEntityTypes: - case DiscoverContextAvailability: - case EntityByIdAttributeByName: - case EntityByIdAttributeByNameIdAndType: - case EntityTypes: - return "skip"; - - // v1 or NGSI10; - // FIXME: disable unused NGSv1 API routes in Orion 3.9.0, to be definetively removed at some point of the future - //case AllContextEntities: return prefix + "/contextEntitites"; - //case AllEntitiesWithTypeAndId: return prefix + "/contextEntities/type/{type}/id/{id}"; - //case AttributesForEntityType: return prefix + "/contextType/{type}"; - //case IndividualContextEntity: return prefix + "/contextEntities/{id}"; - case IndividualContextEntity: - if (prefix == "/v1") - { - return "/v1/contextEntities/{id}"; - } - else - { - // ngsi10 case - return "skip"; - } - - //case IndividualContextEntityAttribute: return prefix + "/contextEntities/{id}/attributes/{name}"; - case IndividualContextEntityAttribute: - if (prefix == "/v1") - { - return "/v1/contextEntities/{id}/attributes/{name}"; - } - else - { - // ngsi10 case - return "skip"; - } - //case IndividualContextEntityAttributes: return prefix + "/contextEntities/{id}/attributes/"; - //case IndividualContextEntityAttributeWithTypeAndId: return prefix + "/contextEntities/type/{type}/id/{id}/attributes/{name}"; - //case Ngsi10ContextEntityTypes: return prefix + "/contextEntityTypes/{type}"; - //case Ngsi10ContextEntityTypesAttribute: return prefix + "/contextEntityTypes/{type}/attributes/{name}"; - //case Ngsi10ContextEntityTypesAttributeContainer: return prefix + "/contextEntityTypes/{type}/attributes/"; - //case Ngsi10SubscriptionsConvOp: return prefix + "/contextSubscriptions/{id}"; - case QueryContext: return prefix + "/queryContext"; - //case SubscribeContext: return prefix + "/subscribeContext|contextSubscriptions"; - //case UnsubscribeContext: return prefix + "/unsubscribeContext"; - case UpdateContext: return prefix + "/updateContext"; - //case UpdateContextSubscription: return prefix + "/updateContextSubscription"; - case AllContextEntities: - case AllEntitiesWithTypeAndId: - case AttributesForEntityType: - //case IndividualContextEntity: - //case IndividualContextEntityAttribute: - case IndividualContextEntityAttributes: - case IndividualContextEntityAttributeWithTypeAndId: - case Ngsi10ContextEntityTypes: - case Ngsi10ContextEntityTypesAttribute: - case Ngsi10ContextEntityTypesAttributeContainer: - case Ngsi10SubscriptionsConvOp: - //case QueryContext: - case SubscribeContext: - case UnsubscribeContext: - //case UpdateContext: - case UpdateContextSubscription: - return "skip"; - - // v2, v1 or NGSIv2 - case NotifyContext: - if (prefix == "/v2") - { - return "/v2/op/notify"; - } - else // v1 or NGSI10 case - { - // FIXME: disable unused NGSv1 API routes in Orion 3.9.0, to be definetively removed at some point of the future - //return prefix + "/notifyContext"; - return "skip"; - } - default: LM_E(("Runtime Error (unclasified request %d, %s, prefix %s", rt, requestType(rt), prefix.c_str())); return "/unclasified"; diff --git a/src/lib/ngsi/Request.h b/src/lib/ngsi/Request.h index 5ce4cb2bf7..ec3ff4a8a9 100644 --- a/src/lib/ngsi/Request.h +++ b/src/lib/ngsi/Request.h @@ -34,94 +34,42 @@ struct ConnectionInfo; /* **************************************************************************** * * RequestType - +* +* FIXME PR: review this */ typedef enum RequestType { - NoRequest, - RegisterContext = 1, - DiscoverContextAvailability, - - QueryContext = 11, - RtQueryContextResponse, - SubscribeContext, - UpdateContextSubscription, - UnsubscribeContext, - RtUnsubscribeContextResponse, - NotifyContext, - UpdateContext, - RtUpdateContextResponse, - NotifyContextSent, - - ContextEntitiesByEntityId = 21, - ContextEntityAttributes, - EntityByIdAttributeByName, - ContextEntityTypes, - ContextEntityTypeAttributeContainer, - ContextEntityTypeAttribute, - - IndividualContextEntity = 31, - IndividualContextEntityAttributes, - IndividualContextEntityAttribute, - IndividualContextEntityAttributeWithTypeAndId, - AttributeValueInstance, - AttributeValueInstanceWithTypeAndId, - Ngsi10ContextEntityTypes, - Ngsi10ContextEntityTypesAttributeContainer, - Ngsi10ContextEntityTypesAttribute, - Ngsi10SubscriptionsConvOp, - - UpdateContextElement = 41, - AppendContextElement, - UpdateContextAttribute, - - LogTraceRequest = 51, - LogLevelRequest, - SemStateRequest, - MetricsRequest, - VersionRequest, - ExitRequest, + NoRequest = 0, - LeakRequest, - StatisticsRequest, - RegisterResponse, - RtSubscribeResponse, - RtSubscribeError, - - RtContextElementResponse, - RtContextAttributeResponse, - - EntityTypes = 65, - AttributesForEntityType, - RtEntityTypesResponse, - RtAttributesForEntityTypeResponse, - AllContextEntities, - AllEntitiesWithTypeAndId, - ContextEntitiesByEntityIdAndType, - EntityByIdAttributeByNameIdAndType, - - // /v2 API - EntitiesRequest = 75, - EntitiesResponse, + // pure v2 EntryPointsRequest, - EntryPointsResponse, + EntitiesRequest, EntityRequest, - EntityResponse, EntityAttributeRequest, - EntityAttributeResponse, EntityAttributeValueRequest, - EntityAttributeValueResponse, - EntityTypeRequest, EntityAllTypesRequest, + EntityTypeRequest, SubscriptionsRequest, SubscriptionRequest, + RegistrationsRequest, + RegistrationRequest, BatchQueryRequest, BatchUpdateRequest, + NotifyContext, - // v2 registration - RegistrationRequest, - RegistrationsRequest, + // administrative requests + LogTraceRequest, + StatisticsRequest, + LogLevelRequest, + SemStateRequest, + VersionRequest, + MetricsRequest, + + // requests enabled in DEBUG compilation + ExitRequest, + LeakRequest, - InvalidRequest = 100 + InvalidRequest } RequestType; diff --git a/src/lib/ngsi/ResponseData.h b/src/lib/ngsi/ResponseData.h deleted file mode 100644 index 3f80fe2c7b..0000000000 --- a/src/lib/ngsi/ResponseData.h +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef SRC_LIB_NGSI_RESPONSEDATA_H_ -#define SRC_LIB_NGSI_RESPONSEDATA_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include - -#include "ngsi/EntityId.h" -#include "ngsi/ContextRegistrationAttribute.h" -#include "ngsi/Metadata.h" - -#include "ngsi9/RegisterContextResponse.h" -#include "ngsi9/DiscoverContextAvailabilityResponse.h" -#include "ngsi10/SubscribeContextResponse.h" -#include "ngsi10/QueryContextResponse.h" -#include "ngsi10/UnsubscribeContextResponse.h" -#include "ngsi10/UpdateContextResponse.h" -#include "ngsi10/UpdateContextSubscriptionResponse.h" - - - -/* **************************************************************************** -* -* ResponseData - -*/ -typedef struct ResponseData -{ - RegisterContextResponse rcr; - DiscoverContextAvailabilityResponse dcar; - QueryContextResponse qcr; - SubscribeContextResponse scr; - UnsubscribeContextResponse uncr; - UpdateContextResponse upcr; - UpdateContextSubscriptionResponse ucsr; -} ResponseData; - -#endif // SRC_LIB_NGSI_RESPONSEDATA_H_ diff --git a/src/lib/ngsi/Restriction.cpp b/src/lib/ngsi/Restriction.cpp deleted file mode 100644 index 4f5cdf4374..0000000000 --- a/src/lib/ngsi/Restriction.cpp +++ /dev/null @@ -1,124 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/globals.h" -#include "common/tag.h" -#include "alarmMgr/alarmMgr.h" -#include "ngsi/Request.h" -#include "ngsi/Restriction.h" - - - -/* **************************************************************************** -* -* Restriction::check - -*/ -std::string Restriction::check(int counter) -{ - std::string res; - - LM_T(LmtRestriction, ("In Restriction::check")); - if (counter == 0) // Restriction is always optional - { - LM_T(LmtRestriction, ("Restriction::check returns OK (counter == 0)")); - return "OK"; - } - - if ((scopeVector.size() == 0) && (attributeExpression.isEmpty())) - { - alarmMgr.badInput(clientIp, "empty restriction"); - return "empty restriction"; - } - - if (((res = scopeVector.check()) != "OK") || - ((res = attributeExpression.check()) != "OK")) - { - LM_T(LmtRestriction, ("Restriction::check returns '%s'", res.c_str())); - alarmMgr.badInput(clientIp, res); - - return res; - } - - LM_T(LmtRestriction, ("Restriction::check returns OK (2)")); - return "OK"; -} - - - -/* **************************************************************************** -* -* Restriction::toJsonV1 - -*/ -std::string Restriction::toJsonV1(int restrictions, bool comma) -{ - std::string tag = "restriction"; - std::string out = ""; - bool scopeVectorRendered = scopeVector.size() != 0; - - if (restrictions == 0) - { - return ""; - } - - out += startTag(tag); - out += attributeExpression.toJsonV1(scopeVectorRendered); - out += scopeVector.toJsonV1(false); - out += endTag(comma); - - return out; -} - - - -/* **************************************************************************** -* -* Restriction::release - -*/ -void Restriction::release(void) -{ - attributeExpression.release(); - scopeVector.release(); -} - - - -/* **************************************************************************** -* -* Restriction::fill - -*/ -void Restriction::fill(Restriction* rP) -{ - const std::string ae = rP->attributeExpression.get(); - attributeExpression.set(ae); - - for (unsigned int ix = 0; ix < rP->scopeVector.size(); ++ix) - { - scopeVector.push_back(new Scope(rP->scopeVector[ix]->type, rP->scopeVector[ix]->value, rP->scopeVector[ix]->oper)); - } -} diff --git a/src/lib/ngsi/Restriction.h b/src/lib/ngsi/Restriction.h deleted file mode 100644 index c27c7dbdb7..0000000000 --- a/src/lib/ngsi/Restriction.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef SRC_LIB_NGSI_RESTRICTION_H_ -#define SRC_LIB_NGSI_RESTRICTION_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "ngsi/Request.h" -#include "ngsi/AttributeExpression.h" -#include "ngsi/ScopeVector.h" - - - -/* **************************************************************************** -* -* Restriction - -*/ -typedef struct Restriction -{ - AttributeExpression attributeExpression; // Optional (FI-WARE changes - MANDATORY in OMA spec) - ScopeVector scopeVector; // Optional - - std::string toJsonV1(int restrictions, bool comma); - void release(); - void fill(Restriction* rP); - - std::string check(int counter); -} Restriction; - -#endif // SRC_LIB_NGSI_RESTRICTION_H_ diff --git a/src/lib/ngsi/RestrictionString.cpp b/src/lib/ngsi/RestrictionString.cpp deleted file mode 100644 index 1045a2a106..0000000000 --- a/src/lib/ngsi/RestrictionString.cpp +++ /dev/null @@ -1,104 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/globals.h" -#include "common/tag.h" -#include "ngsi/Request.h" -#include "ngsi/RestrictionString.h" - - - -/* **************************************************************************** -* -* RestrictionString::check - -*/ -std::string RestrictionString::check(void) -{ - return "OK"; -} - - - -/* **************************************************************************** -* -* RestrictionString::isEmpty - -*/ -bool RestrictionString::isEmpty(void) -{ - return (string.empty())? true : false; -} - - - -/* **************************************************************************** -* -* RestrictionString::set - -*/ -void RestrictionString::set(const std::string& value) -{ - string = value; -} - - - -/* **************************************************************************** -* -* RestrictionString::get - -*/ -std::string RestrictionString::get(void) -{ - return string; -} - - - -/* **************************************************************************** -* -* RestrictionString::toJsonV1 - -*/ -std::string RestrictionString::toJsonV1(bool comma) -{ - if (string.empty()) - { - return ""; - } - - return valueTag("restriction", string, comma); -} - - - -/* **************************************************************************** -* -* RestrictionString::c_str - -*/ -const char* RestrictionString::c_str(void) -{ - return string.c_str(); -} diff --git a/src/lib/ngsi/RestrictionString.h b/src/lib/ngsi/RestrictionString.h deleted file mode 100644 index 3a7fc72cf3..0000000000 --- a/src/lib/ngsi/RestrictionString.h +++ /dev/null @@ -1,51 +0,0 @@ -#ifndef SRC_LIB_NGSI_RESTRICTIONSTRING_H_ -#define SRC_LIB_NGSI_RESTRICTIONSTRING_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include - -#include "ngsi/Request.h" - - - -/* **************************************************************************** -* -* RestrictionString - -*/ -typedef struct RestrictionString -{ - std::string string; - - void set(const std::string& value); - std::string get(void); - bool isEmpty(void); - std::string toJsonV1(bool comma); - const char* c_str(); - - std::string check(void); -} RestrictionString; - -#endif // SRC_LIB_NGSI_RESTRICTIONSTRING_H_ diff --git a/src/lib/ngsi/Scope.cpp b/src/lib/ngsi/Scope.cpp index 32735f983f..188a9a0f5f 100644 --- a/src/lib/ngsi/Scope.cpp +++ b/src/lib/ngsi/Scope.cpp @@ -28,7 +28,6 @@ #include "logMsg/traceLevels.h" #include "common/globals.h" -#include "common/tag.h" #include "common/string.h" #include "common/limits.h" #include "alarmMgr/alarmMgr.h" @@ -100,7 +99,6 @@ static void pointVectorRelease(const std::vector& pointV) */ int Scope::fill ( - ApiVersion apiVersion, const std::string& geometryString, const std::string& coordsString, const std::string& georelString, @@ -112,13 +110,13 @@ int Scope::fill int points; std::vector pointV; - type = (apiVersion == V1)? FIWARE_LOCATION : FIWARE_LOCATION_V2; + type = FIWARE_LOCATION_V2; // // parse geometry // std::string errorString; - if (geometry.parse(apiVersion, geometryString.c_str(), &errorString) != 0) + if (geometry.parse(geometryString.c_str(), &errorString) != 0) { *errorStringP = std::string("error parsing geometry: ") + errorString; return -1; @@ -229,48 +227,11 @@ int Scope::fill pointV.push_back(pointP); } - - if (geometry.areaType == "circle") - { - if (apiVersion == V2) - { - *errorStringP = "circle geometry is not supported by Orion API v2"; - pointVectorRelease(pointV); - pointV.clear(); - return -1; - } - else - { - if (pointV.size() != 1) - { - *errorStringP = "Too many coordinates for circle"; - pointVectorRelease(pointV); - pointV.clear(); - return -1; - } - - areaType = orion::CircleType; - - circle.radiusSet(geometry.radius); - circle.invertedSet(geometry.external); - circle.centerSet(pointV[0]); - - pointVectorRelease(pointV); - pointV.clear(); - } - } - else if (geometry.areaType == "polygon") + if (geometry.areaType == "polygon") { areaType = orion::PolygonType; - if ((apiVersion == V1) && (pointV.size() < 3)) - { - *errorStringP = "Too few coordinates for polygon"; - pointVectorRelease(pointV); - pointV.clear(); - return -1; - } - else if ((apiVersion == V2) && (pointV.size() < 4)) + if (pointV.size() < 4) { *errorStringP = "Too few coordinates for polygon"; pointVectorRelease(pointV); @@ -279,9 +240,9 @@ int Scope::fill } // - // If v2, first and last point must be identical + // First and last point must be identical // - if ((apiVersion == V2) && (pointV[0]->equals(pointV[pointV.size() - 1]) == false)) + if (pointV[0]->equals(pointV[pointV.size() - 1]) == false) { *errorStringP = "First and last point in polygon not the same"; pointVectorRelease(pointV); @@ -289,8 +250,6 @@ int Scope::fill return -1; } - polygon.invertedSet(geometry.external); - for (unsigned int ix = 0; ix < pointV.size(); ++ix) { polygon.vertexAdd(pointV[ix]); @@ -382,215 +341,13 @@ int Scope::fill -/* **************************************************************************** -* -* Scope::toJsonV1 - -*/ -std::string Scope::toJsonV1(bool notLastInVector) -{ - std::string out = ""; - const char* tTag = "type"; - const char* vTag = "value"; - - out += startTag(); - out += valueTag(tTag, type, true); - out += valueTag(vTag, value); - out += endTag(notLastInVector); - - return out; -} - - - -/* **************************************************************************** -* -* Scope::check - -*/ -std::string Scope::check(void) -{ - // - // Check for forbidden characters - // - if (forbiddenChars(type.c_str())) - { - alarmMgr.badInput(clientIp, "found a forbidden character in the type of a scope", type); - return "illegal chars in scope type"; - } - - if ((type != SCOPE_TYPE_SIMPLE_QUERY) && (type != SCOPE_TYPE_SIMPLE_QUERY_MD)) - { - if (forbiddenChars(value.c_str())) - { - alarmMgr.badInput(clientIp, "found a forbidden character in the value of a scope", value); - return "illegal chars in scope"; - } - } - - if (type == FIWARE_LOCATION || type == FIWARE_LOCATION_DEPRECATED) - { - if (areaType == orion::CircleType) - { - if (circle.radiusString() == "0") - { - alarmMgr.badInput(clientIp, "radius zero for a circle area"); - return "Radius zero for a circle area"; - } - else if (circle.radiusString().empty()) - { - alarmMgr.badInput(clientIp, "missing radius for circle area"); - return "Missing radius for circle area"; - } - else if (!circle.invertedString().empty()) - { - if (!isTrue(circle.invertedString()) && !isFalse(circle.invertedString())) - { - std::string details = std::string("bad value for circle/inverted: '") + circle.invertedString() + "'"; - alarmMgr.badInput(clientIp, details); - return "bad value for circle/inverted: /" + circle.invertedString() + "/"; - } - } - else if (circle.center.latitudeString().empty()) - { - alarmMgr.badInput(clientIp, "missing latitude for circle center"); - return "Missing latitude for circle center"; - } - else if (circle.center.longitudeString().empty()) - { - alarmMgr.badInput(clientIp, "missing longitude for circle center"); - return "Missing longitude for circle center"; - } - - double latitude; - double longitude; - bool ok; - - ok = str2double(circle.center.latitudeString().c_str(), &latitude); - if ((ok == false) || (latitude > 90) || (latitude < -90)) - { - std::string details = std::string("invalid value for latitude (") + circle.center.latitudeString() + ")"; - alarmMgr.badInput(clientIp, details); - return "invalid value for latitude"; - } - - ok = str2double(circle.center.longitudeString().c_str(), &longitude); - if ((ok == false) || (longitude > 180) || (longitude < -180)) - { - std::string details = std::string("invalid value for longitude: '") + circle.center.longitudeString() + "'"; - alarmMgr.badInput(clientIp, details); - return "invalid value for longitude"; - } - } - else if (areaType == orion::PolygonType) - { - if (polygon.vertexList.size() < 3) - { - char noOfV[STRING_SIZE_FOR_INT]; - - snprintf(noOfV, sizeof(noOfV), "%lu", polygon.vertexList.size()); - std::string details = std::string("too few vertices for a polygon (") + noOfV + " is less than three)"; - alarmMgr.badInput(clientIp, details); - - return "too few vertices for a polygon"; - } - else if (!polygon.invertedString().empty()) - { - if (!isTrue(polygon.invertedString()) && !isFalse(polygon.invertedString())) - { - std::string details = std::string("bad value for polygon/inverted: '") + polygon.invertedString() + "'"; - alarmMgr.badInput(clientIp, details); - return "bad value for polygon/inverted: /" + polygon.invertedString() + "/"; - } - } - - for (unsigned int ix = 0; ix < polygon.vertexList.size(); ++ix) - { - if (polygon.vertexList[ix]->latitudeString().empty()) - { - alarmMgr.badInput(clientIp, "missing latitude value for polygon vertex"); - return std::string("missing latitude value for polygon vertex"); - } - - if (polygon.vertexList[ix]->longitudeString().empty()) - { - alarmMgr.badInput(clientIp, "missing longitude value for polygon vertex"); - return std::string("missing longitude value for polygon vertex"); - } - - double latitude; - double longitude; - bool ok; - - - ok = str2double(polygon.vertexList[ix]->latitudeString().c_str(), &latitude); - if ((ok == false) || (latitude > 90) || (latitude < -90)) - { - std::string details = std::string("invalid value for latitude: '") + polygon.vertexList[ix]->latitudeString() + "'"; - alarmMgr.badInput(clientIp, details); - return "invalid value for latitude"; - } - - ok = str2double(polygon.vertexList[ix]->longitudeString().c_str(), &longitude); - if ((ok == false) || (longitude > 180) || (longitude < -180)) - { - std::string details = std::string("invalid value for longitude: '") + polygon.vertexList[ix]->longitudeString() + "'"; - alarmMgr.badInput(clientIp, details); - return "invalid value for longitude"; - } - } - } - } - - if ((type != FIWARE_LOCATION) && (type != FIWARE_LOCATION_DEPRECATED)) - { - if (type.empty()) - { - alarmMgr.badInput(clientIp, "empty type in restriction scope"); - return "Empty type in restriction scope"; - } - - if (value.empty()) - { - alarmMgr.badInput(clientIp, "empty value in restriction scope"); - return "Empty value in restriction scope"; - } - } - - if (type == FIWARE_LOCATION_V2) - { - if ((areaType == orion::PointType) && (georel.type == "coveredBy")) - { - alarmMgr.badInput(clientIp, "Query not supported: point geometry cannot be used with coveredBy georel"); - return "Query not supported: point geometry cannot be used with coveredBy georel"; - } - else if ((areaType == orion::LineType) && (georel.type == "coveredBy")) - { - alarmMgr.badInput(clientIp, "Query not supported: line geometry cannot be used with coveredBy georel"); - return "Query not supported: line geometry cannot be used with coveredBy georel"; - } - else if ((areaType == orion::LineType) && (line.pointList.size() < 2)) - { - alarmMgr.badInput(clientIp, "Query not supported: not enough points for a line"); - return "Query not supported: not enough points for a line"; - } - else if ((areaType == orion::PolygonType) && (polygon.vertexList.size() < 4)) - { - alarmMgr.badInput(clientIp, "Query not supported: not enough vertices for a polygon"); - return "Query not supported: not enough vertices for a polygon"; - } - } - - return "OK"; -} - - - /* **************************************************************************** * * release - */ void Scope::release(void) { - // NOTE: georel, circle, box, and point don't use dynamic memory, so they don't need release methods + // NOTE: georel, box, and point don't use dynamic memory, so they don't need release methods polygon.release(); line.release(); @@ -607,18 +364,3 @@ void Scope::release(void) } } - - -/* **************************************************************************** -* -* Scope::areaTypeSet - -*/ -void Scope::areaTypeSet(const std::string& areaTypeString) -{ - if (areaTypeString == "line") areaType = orion::LineType; - else if (areaTypeString == "polygon") areaType = orion::PolygonType; - else if (areaTypeString == "circle") areaType = orion::CircleType; - else if (areaTypeString == "point") areaType = orion::PointType; - else if (areaTypeString == "box") areaType = orion::BoxType; - else areaType = orion::NoArea; -} diff --git a/src/lib/ngsi/Scope.h b/src/lib/ngsi/Scope.h index 904209bb81..5e2045302d 100644 --- a/src/lib/ngsi/Scope.h +++ b/src/lib/ngsi/Scope.h @@ -46,7 +46,7 @@ #define SCOPE_TYPE_SIMPLE_QUERY "FIWARE::StringQuery" #define SCOPE_TYPE_SIMPLE_QUERY_MD "FIWARE::StringQuery::Metadata" -#define SCOPE_TYPE_LOCATION FIWARE_LOCATION +#define SCOPE_TYPE_LOCATION FIWARE_LOCATION_V2 #define SCOPE_VALUE_ENTITY_TYPE "entity::type" @@ -64,7 +64,6 @@ typedef struct Scope std::string oper; // Optional - used for filters orion::AreaType areaType; - orion::Circle circle; orion::Polygon polygon; orion::Point point; orion::Line line; @@ -76,17 +75,13 @@ typedef struct Scope Scope(); Scope(const std::string& _type, const std::string& _value, const std::string& _oper = ""); - int fill(ApiVersion apiVersion, - const std::string& geometry, + int fill(const std::string& geometry, const std::string& coords, const std::string& georelString, std::string* errorString); - std::string toJsonV1(bool notLastInVector); void release(void); - std::string check(void); - void areaTypeSet(const std::string& areaTypeString); } Scope; #endif // SRC_LIB_NGSI_SCOPE_H_ diff --git a/src/lib/ngsi/ScopeVector.cpp b/src/lib/ngsi/ScopeVector.cpp index a83e58e1e6..e5698609c0 100644 --- a/src/lib/ngsi/ScopeVector.cpp +++ b/src/lib/ngsi/ScopeVector.cpp @@ -30,63 +30,12 @@ #include "logMsg/traceLevels.h" #include "common/globals.h" -#include "common/tag.h" #include "common/limits.h" #include "alarmMgr/alarmMgr.h" #include "ngsi/ScopeVector.h" -/* **************************************************************************** -* -* ScopeVector::toJsonV1 - -*/ -std::string ScopeVector::toJsonV1(bool comma) -{ - std::string out = ""; - - if (vec.size() == 0) - { - return ""; - } - - out += startTag("scope", true); - for (unsigned int ix = 0; ix < vec.size(); ++ix) - { - out += vec[ix]->toJsonV1(ix != vec.size() - 1); - } - out += endTag(comma, true); - - return out; -} - - - -/* **************************************************************************** -* -* ScopeVector::check - -*/ -std::string ScopeVector::check(void) -{ - for (unsigned int ix = 0; ix < vec.size(); ++ix) - { - std::string res; - - if ((res = vec[ix]->check()) != "OK") - { - char ixV[STRING_SIZE_FOR_INT]; - snprintf(ixV, sizeof(ixV), "%d", ix); - std::string details = std::string("error in scope ") + ixV + ": " + res; - alarmMgr.badInput(clientIp, details); - return res; - } - } - - return "OK"; -} - - - /* **************************************************************************** * * ScopeVector::push_back - diff --git a/src/lib/ngsi/ScopeVector.h b/src/lib/ngsi/ScopeVector.h index d092c1c362..a3db746d59 100644 --- a/src/lib/ngsi/ScopeVector.h +++ b/src/lib/ngsi/ScopeVector.h @@ -40,12 +40,10 @@ typedef struct ScopeVector { std::vector vec; - std::string toJsonV1(bool comma); void push_back(Scope* item); unsigned int size(void) const; void release(); void fill(const ScopeVector& scopeV, bool copy); - std::string check(void); Scope* operator[](unsigned int ix) const; } ScopeVector; diff --git a/src/lib/ngsi/StatusCode.cpp b/src/lib/ngsi/StatusCode.cpp deleted file mode 100644 index e1ad73db7f..0000000000 --- a/src/lib/ngsi/StatusCode.cpp +++ /dev/null @@ -1,247 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/globals.h" -#include "common/string.h" -#include "common/tag.h" -#include "common/JsonHelper.h" -#include "common/limits.h" -#include "ngsi/Request.h" -#include "ngsi/StatusCode.h" -#include "ngsi10/UpdateContextResponse.h" -#include "rest/HttpStatusCode.h" - - - -/* **************************************************************************** -* -* StatusCode::StatusCode - -*/ -StatusCode::StatusCode() -{ - code = SccNone; - reasonPhrase = ""; - details = ""; - keyName = "statusCode"; -} - - - -/* **************************************************************************** -* -* StatusCode::StatusCode - -*/ -StatusCode::StatusCode(const std::string& _keyName) -{ - code = SccNone; - reasonPhrase = ""; - details = ""; - keyName = _keyName; -} - - - -/* **************************************************************************** -* -* StatusCode::StatusCode - -*/ -StatusCode::StatusCode(HttpStatusCode _code, const std::string& _details, const std::string& _keyName) -{ - code = _code; - reasonPhrase = httpStatusCodeString(code); - details = _details; - keyName = _keyName; -} - - - -/* **************************************************************************** -* -* StatusCode::toJsonV1 - -*/ -std::string StatusCode::toJsonV1(bool comma, bool showKey) -{ - std::string out = ""; - - if (strstr(details.c_str(), "\"") != NULL) - { - int len = details.length() * 2; - char* s = (char*) calloc(1, len + 1); - - strReplace(s, len, details.c_str(), "\"", "\\\""); - details = s; - free(s); - } - - if (code == SccNone) - { - fill(SccReceiverInternalError, ""); - details += " - ZERO code set to 500"; - } - - out += startTag(showKey? keyName : ""); - out += valueTag("code", code, true); - out += valueTag("reasonPhrase", reasonPhrase, !details.empty()); - - if (!details.empty()) - { - out += valueTag("details", details, false); - } - - out += endTag(comma); - - return out; -} - - - -/* **************************************************************************** -* -* StatusCode::toJson - -* -* For version 2 of the API, based on OrionError. -*/ -std::string StatusCode::toJson(void) -{ - OrionError oe(code, details, reasonPhrase); - return oe.smartRender(V2); -} - - - -/* **************************************************************************** -* -* StatusCode::fill - -*/ -void StatusCode::fill(HttpStatusCode _code, const std::string& _details) -{ - code = _code; - reasonPhrase = httpStatusCodeString(code); - details = _details; -} - - - -/* **************************************************************************** -* -* StatusCode::fill - -*/ -void StatusCode::fill(StatusCode* scP) -{ - fill(scP->code, scP->details); -} - - - -/* **************************************************************************** -* -* StatusCode::fill - -*/ -void StatusCode::fill(const StatusCode& sc) -{ - fill(sc.code, sc.details); -} - - - -/* **************************************************************************** -* -* StatusCode::fill - -*/ -void StatusCode::fill(const struct UpdateContextResponse& ucrs) -{ - if ((ucrs.errorCode.code != SccOk) && (ucrs.errorCode.code != SccNone)) - { - fill(ucrs.errorCode); - } - else if (ucrs.contextElementResponseVector.vec.size() == 1) - { - fill(ucrs.contextElementResponseVector.vec[0]->statusCode); - } - else if (ucrs.contextElementResponseVector.vec.size() > 1) - { - LM_W(("Filling StatusCode from UpdateContextResponse with more than one contextElementResponse, picking one of them ...")); - fill(ucrs.contextElementResponseVector.vec[0]->statusCode); - } - else - { - // Empty UpdateContextResponse::contextElementResponseVector AND unfilled UpdateContextResponse::errorCode - LM_E(("Runtime Error (can't fill StatusCode from UpdateContextResponse)")); - fill(SccReceiverInternalError, "can't fill StatusCode from UpdateContextResponse"); - } -} - - - -/* **************************************************************************** -* -* StatusCode::check - -*/ -std::string StatusCode::check(void) -{ - if (code == SccNone) - { - return "no code"; - } - - if (reasonPhrase.empty()) - { - return "no reason phrase"; - } - - return "OK"; -} - - - -/* **************************************************************************** -* -* release - -*/ -void StatusCode::release(void) -{ - code = SccNone; - reasonPhrase = ""; - details = ""; - keyName = "statusCode"; -} - - - -/* **************************************************************************** -* -* keyNameSet - -*/ -void StatusCode::keyNameSet(const std::string& _keyName) -{ - keyName = _keyName; -} diff --git a/src/lib/ngsi/StatusCode.h b/src/lib/ngsi/StatusCode.h deleted file mode 100644 index 2c034536e4..0000000000 --- a/src/lib/ngsi/StatusCode.h +++ /dev/null @@ -1,71 +0,0 @@ -#ifndef SRC_LIB_NGSI_STATUSCODE_H_ -#define SRC_LIB_NGSI_STATUSCODE_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include - -#include "ngsi/Request.h" -#include "rest/HttpStatusCode.h" - - - -/* **************************************************************************** -* -* Incomplete type declarations -*/ -struct UpdateContextResponse; - - - -/* **************************************************************************** -* -* StatusCode - -*/ -typedef struct StatusCode -{ - HttpStatusCode code; // Mandatory - std::string reasonPhrase; // Mandatory - std::string details; // Optional - - std::string keyName; // tag to be rendered - - StatusCode(); - StatusCode(const std::string& _keyName); - StatusCode(HttpStatusCode _code, const std::string& _details, const std::string& _keyName = "statusCode"); - - std::string toJsonV1(bool comma, bool showKey = true); - std::string toJson(void); - void fill(HttpStatusCode _code, const std::string& _details = ""); - void fill(StatusCode* scP); - void fill(const StatusCode& sc); - void fill(const struct UpdateContextResponse& ucrs); - void release(void); - void keyNameSet(const std::string& _tag); - - std::string check(void); -} StatusCode; - -#endif // SRC_LIB_NGSI_STATUSCODE_H_ diff --git a/src/lib/ngsi/StringList.cpp b/src/lib/ngsi/StringList.cpp index 50ca06628d..24739b6cd0 100644 --- a/src/lib/ngsi/StringList.cpp +++ b/src/lib/ngsi/StringList.cpp @@ -30,7 +30,6 @@ #include "logMsg/traceLevels.h" #include "common/globals.h" -#include "common/tag.h" #include "common/string.h" #include "common/JsonHelper.h" #include "ngsi/StringList.h" @@ -51,17 +50,6 @@ void StringList::fill(const std::vector& sVec) -/* **************************************************************************** -* -* StringList::fill - -*/ -void StringList::fill(const std::string& commaSeparatedList) -{ - stringSplit(commaSeparatedList, ',', stringV); -} - - - /* **************************************************************************** * * StringList::toJson - @@ -80,52 +68,6 @@ std::string StringList::toJson(void) -/* **************************************************************************** -* -* StringList::toJsonV1 - -*/ -std::string StringList::toJsonV1(bool comma, const std::string& fieldName) -{ - std::string out = ""; - - if (stringV.size() == 0) - { - return ""; - } - - out += startTag(fieldName, true); - - for (unsigned int ix = 0; ix < stringV.size(); ++ix) - { - out += valueTag(fieldName, stringV[ix], ix != stringV.size() - 1, true); - } - - out += endTag(comma, true); - - return out; -} - - - -/* **************************************************************************** -* -* StringList::check - -*/ -std::string StringList::check(void) -{ - for (unsigned int ix = 0; ix < stringV.size(); ++ix) - { - if (stringV[ix].empty()) - { - return "empty string"; - } - } - - return "OK"; -} - - - /* **************************************************************************** * * StringList::release - @@ -207,23 +149,3 @@ void StringList::clone(const StringList& sList) } } - -/* **************************************************************************** -* -* StringList::toString - -*/ -std::string StringList::toString(void) -{ - std::string out; - - for (unsigned int ix = 0; ix < stringV.size(); ++ix) - { - out += stringV[ix]; - if (ix < stringV.size() - 1) - { - out += ","; - } - } - - return out; -} diff --git a/src/lib/ngsi/StringList.h b/src/lib/ngsi/StringList.h index 94ec82029e..f164d88f87 100644 --- a/src/lib/ngsi/StringList.h +++ b/src/lib/ngsi/StringList.h @@ -42,10 +42,7 @@ typedef struct StringList std::vector stringV; void fill(const std::vector& aVec); - void fill(const std::string& commaSeparatedList); - std::string toJsonV1(bool comma, const std::string& fieldName); std::string toJson(void); - std::string toString(void); void release(void); bool lookup(const std::string& string, const std::string& wildCard = "") const; void push_back(const std::string& string); @@ -53,8 +50,6 @@ typedef struct StringList unsigned int size(void) const; void clone(const StringList& sList); - std::string check(void); - std::string operator[](unsigned int ix) const { return stringV[ix]; diff --git a/src/lib/ngsi/SubscribeError.cpp b/src/lib/ngsi/SubscribeError.cpp deleted file mode 100644 index 128c08c08c..0000000000 --- a/src/lib/ngsi/SubscribeError.cpp +++ /dev/null @@ -1,109 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include - -#include "common/tag.h" -#include "common/JsonHelper.h" -#include "ngsi/StatusCode.h" -#include "ngsi/Request.h" -#include "ngsi/SubscribeError.h" - - - -/* **************************************************************************** -* -* SubscribeError::SubscribeError - -*/ -SubscribeError::SubscribeError() -{ - errorCode.keyNameSet("errorCode"); -} - - - -/* **************************************************************************** -* -* SubscribeError::toJson - -*/ -std::string SubscribeError::toJson(void) -{ - JsonObjectHelper jh; - - jh.addString("error", errorCode.reasonPhrase); - jh.addString("description", errorCode.details); - - return jh.str(); -} - - - -/* **************************************************************************** -* -* SubscribeError::toJsonV1 - -*/ -std::string SubscribeError::toJsonV1(RequestType requestType, bool comma) -{ - std::string out = ""; - - out += startTag("subscribeError", false); - - // subscriptionId is Mandatory if part of updateContextSubscriptionResponse - // errorCode is Mandatory so, the JSON comma is always TRUE - if (requestType == UpdateContextSubscription) - { - // - // NOTE: the subscriptionId must have come from the request. - // If the field is empty, we are in unit tests and I here set it to all zeroes - // - if (subscriptionId.get().empty()) - { - subscriptionId.set("000000000000000000000000"); - } - out += subscriptionId.toJsonV1(requestType, true); - } - else if ((requestType == SubscribeContext) && - (subscriptionId.get() != "000000000000000000000000") && - (!subscriptionId.get().empty())) - { - out += subscriptionId.toJsonV1(requestType, true); - } - - out += errorCode.toJsonV1(false); - - out += endTag(comma); - - return out; -} - - - -/* **************************************************************************** -* -* check - -*/ -std::string SubscribeError::check(void) -{ - return "OK"; -} diff --git a/src/lib/ngsi/SubscribeError.h b/src/lib/ngsi/SubscribeError.h deleted file mode 100644 index 08c25db483..0000000000 --- a/src/lib/ngsi/SubscribeError.h +++ /dev/null @@ -1,51 +0,0 @@ -#ifndef SRC_LIB_NGSI_SUBSCRIBEERROR_H_ -#define SRC_LIB_NGSI_SUBSCRIBEERROR_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include - -#include "ngsi/StatusCode.h" -#include "ngsi/Request.h" -#include "ngsi/SubscriptionId.h" - - - -/* **************************************************************************** -* -* SubscribeError - -*/ -typedef struct SubscribeError -{ - SubscriptionId subscriptionId; // Optional - but TID always returns it - StatusCode errorCode; // Mandatory - - SubscribeError(); - std::string toJsonV1(RequestType requestType, bool comma); - std::string toJson(void); - std::string check(void); -} SubscribeError; - -#endif // SRC_LIB_NGSI_SUBSCRIBEERROR_H_ diff --git a/src/lib/ngsi/SubscribeResponse.cpp b/src/lib/ngsi/SubscribeResponse.cpp deleted file mode 100644 index d105282ff5..0000000000 --- a/src/lib/ngsi/SubscribeResponse.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include - -#include "common/globals.h" -#include "common/tag.h" -#include "ngsi/SubscribeResponse.h" - - - -/* **************************************************************************** -* -* SubscribeResponse::SubscribeResponse - -*/ -SubscribeResponse::SubscribeResponse() -{ -} - - - -/* **************************************************************************** -* -* SubscribeResponse::toJsonV1 - -*/ -std::string SubscribeResponse::toJsonV1(bool comma) -{ - std::string out = ""; - std::string tag = "subscribeResponse"; - bool durationRendered = !duration.isEmpty(); - bool throttlingRendered = !throttling.isEmpty(); - - out += startTag(tag); - out += subscriptionId.toJsonV1(RtSubscribeResponse, durationRendered || throttlingRendered); - out += duration.toJsonV1(throttlingRendered); - out += throttling.toJsonV1(false); - out += endTag(comma); - - return out; -} diff --git a/src/lib/ngsi/SubscribeResponse.h b/src/lib/ngsi/SubscribeResponse.h deleted file mode 100644 index 56179a4b07..0000000000 --- a/src/lib/ngsi/SubscribeResponse.h +++ /dev/null @@ -1,51 +0,0 @@ -#ifndef SRC_LIB_NGSI_SUBSCRIBERESPONSE_H_ -#define SRC_LIB_NGSI_SUBSCRIBERESPONSE_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include - -#include "ngsi/SubscriptionId.h" -#include "ngsi/Duration.h" -#include "ngsi/Throttling.h" - - - -/* **************************************************************************** -* -* SubscribeResponse - -*/ -typedef struct SubscribeResponse -{ - SubscriptionId subscriptionId; // Mandatory - Duration duration; // Optional - Throttling throttling; // Optional - - SubscribeResponse(); - - std::string toJsonV1(bool comma); -} SubscribeResponse; - -#endif // SRC_LIB_NGSI_SUBSCRIBERESPONSE_H_ diff --git a/src/lib/ngsi/SubscriptionId.cpp b/src/lib/ngsi/SubscriptionId.cpp deleted file mode 100644 index c2aa841b32..0000000000 --- a/src/lib/ngsi/SubscriptionId.cpp +++ /dev/null @@ -1,189 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/globals.h" -#include "common/idCheck.h" -#include "common/tag.h" -#include "ngsi/Request.h" -#include "ngsi/SubscriptionId.h" - - - -/* **************************************************************************** -* -* SubscriptionId::SubscriptionId - -*/ -SubscriptionId::SubscriptionId() -{ - string = ""; -} - - - -/* **************************************************************************** -* -* SubscriptionId::SubscriptionId - -*/ -SubscriptionId::SubscriptionId(const std::string& subId) -{ - string = subId; -} - - - -/* **************************************************************************** -* -* SubscriptionId::check - -*/ -std::string SubscriptionId::check(void) -{ - std::string out = "OK"; - - if (!string.empty()) - { - out = idCheck(string); - } - - return out; -} - - - -/* **************************************************************************** -* -* SubscriptionId::isEmpty - -*/ -bool SubscriptionId::isEmpty(void) -{ - return (string.empty())? true : false; -} - - - -/* **************************************************************************** -* -* SubscriptionId::set - -*/ -void SubscriptionId::set(const std::string& value) -{ - string = value; -} - - - -/* **************************************************************************** -* -* SubscriptionId::get - -*/ -std::string SubscriptionId::get(void) const -{ - return string; -} - - - -/* **************************************************************************** -* -* SubscriptionId::c_str - -*/ -const char* SubscriptionId::c_str(void) const -{ - return string.c_str(); -} - - - -/* **************************************************************************** -* -* SubscriptionId::toJsonV1 - -*/ -std::string SubscriptionId::toJsonV1(RequestType container, bool comma) -{ - std::string xString = string; - - if (xString.empty()) - { - if ((container == UpdateContextSubscription) || - (container == UnsubscribeContext) || - (container == RtUnsubscribeContextResponse) || - (container == NotifyContext) || - (container == RtSubscribeResponse) || - (container == RtSubscribeError)) - { - // subscriptionId is Mandatory - xString = "000000000000000000000000"; - } - else - { - return ""; // subscriptionId is Optional - } - } - - return valueTag("subscriptionId", xString, comma); -} - - - -/* **************************************************************************** -* -* release - -*/ -void SubscriptionId::release(void) -{ - /* This method is included for the sake of homogeneity */ - string = ""; -} - - - -/* **************************************************************************** -* -* SubscriptionId::rendered - -*/ -bool SubscriptionId::rendered(RequestType container) -{ - if ((string.empty()) || (string == "000000000000000000000000")) - { - if ((container == UpdateContextSubscription) || - (container == UnsubscribeContext) || - (container == RtUnsubscribeContextResponse) || - (container == NotifyContext) || - (container == RtSubscribeResponse) || - (container == RtSubscribeError)) - { - return true; - } - else - { - return false; // subscriptionId is Optional - } - } - - return true; -} diff --git a/src/lib/ngsi/SubscriptionId.h b/src/lib/ngsi/SubscriptionId.h deleted file mode 100644 index eab55627d9..0000000000 --- a/src/lib/ngsi/SubscriptionId.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef SRC_LIB_NGSI_SUBSCRIPTIONID_H_ -#define SRC_LIB_NGSI_SUBSCRIPTIONID_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include - -#include "ngsi/Request.h" - - - -/* **************************************************************************** -* -* SubscriptionId - -*/ -typedef struct SubscriptionId -{ - std::string string; - - SubscriptionId(); - SubscriptionId(const std::string& subId); - - void set(const std::string& value); - std::string get(void) const; - const char* c_str(void) const; - bool isEmpty(void); - std::string toJsonV1(RequestType container, bool comma); - void release(void); - bool rendered(RequestType container); - - std::string check(void); -} SubscriptionId; - -#endif // SRC_LIB_NGSI_SUBSCRIPTIONID_H_ diff --git a/src/lib/ngsi/Throttling.cpp b/src/lib/ngsi/Throttling.cpp deleted file mode 100644 index 85f22eb8b3..0000000000 --- a/src/lib/ngsi/Throttling.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/globals.h" -#include "common/tag.h" -#include "ngsi/Request.h" -#include "ngsi/Throttling.h" - - -/* **************************************************************************** -* -* Throttling::parse - -*/ -int64_t Throttling::parse(void) -{ - seconds = parse8601(string); - return seconds; -} - - - -/* **************************************************************************** -* -* Throttling::check - -*/ -std::string Throttling::check(void) -{ - // FIXME - make Throttling and Duration inherit from same class - // that implements the 'parse' method - - if (string.empty()) - { - return "OK"; - } - - if (parse() == -1) - { - return "syntax error in throttling string"; - } - - return "OK"; -} - - - -/* **************************************************************************** -* -* Throttling::isEmpty - -*/ -bool Throttling::isEmpty(void) -{ - return (string.empty())? true : false; -} - - - -/* **************************************************************************** -* -* Throttling::set - -*/ -void Throttling::set(const std::string& value) -{ - string = value; -} - - - -/* **************************************************************************** -* -* Throttling::get - -*/ -const std::string Throttling::get(void) -{ - return string; -} - - - -/* **************************************************************************** -* -* Throttling::toJsonV1 - -*/ -std::string Throttling::toJsonV1(bool comma) -{ - if (string.empty()) - { - return ""; - } - - return valueTag("throttling", string, comma); -} diff --git a/src/lib/ngsi/Throttling.h b/src/lib/ngsi/Throttling.h deleted file mode 100644 index a06ea794ea..0000000000 --- a/src/lib/ngsi/Throttling.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef SRC_LIB_NGSI_THROTTLING_H_ -#define SRC_LIB_NGSI_THROTTLING_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "ngsi/Request.h" - - - -/* **************************************************************************** -* -* Throttling - -*/ -typedef struct Throttling -{ - std::string string; - int64_t seconds; - - Throttling(): seconds(-1) {} - - void set(const std::string& value); - const std::string get(void); - bool isEmpty(void); - std::string toJsonV1(bool comma); - - std::string check(void); - - int64_t parse(void); -} Throttling; - -#endif // SRC_LIB_NGSI_THROTTLING_H_ diff --git a/src/lib/ngsi10/CMakeLists.txt b/src/lib/ngsi10/CMakeLists.txt index 4b18063d00..135c44f4ca 100644 --- a/src/lib/ngsi10/CMakeLists.txt +++ b/src/lib/ngsi10/CMakeLists.txt @@ -25,14 +25,8 @@ SET (SOURCES NotifyContextResponse.cpp QueryContextRequest.cpp QueryContextResponse.cpp - SubscribeContextRequest.cpp - SubscribeContextResponse.cpp - UnsubscribeContextRequest.cpp - UnsubscribeContextResponse.cpp UpdateContextRequest.cpp UpdateContextResponse.cpp - UpdateContextSubscriptionRequest.cpp - UpdateContextSubscriptionResponse.cpp ) SET (HEADERS @@ -40,14 +34,8 @@ SET (HEADERS NotifyContextResponse.h QueryContextRequest.h QueryContextResponse.h - SubscribeContextRequest.h - SubscribeContextResponse.h - UnsubscribeContextRequest.h - UnsubscribeContextResponse.h UpdateContextRequest.h UpdateContextResponse.h - UpdateContextSubscriptionRequest.h - UpdateContextSubscriptionResponse.h ) diff --git a/src/lib/ngsi10/NotifyContextRequest.cpp b/src/lib/ngsi10/NotifyContextRequest.cpp index f1ae7167d9..34885fab2f 100644 --- a/src/lib/ngsi10/NotifyContextRequest.cpp +++ b/src/lib/ngsi10/NotifyContextRequest.cpp @@ -28,7 +28,6 @@ #include "logMsg/traceLevels.h" #include "common/globals.h" -#include "common/tag.h" #include "common/RenderFormat.h" #include "common/JsonHelper.h" #include "ngsi10/NotifyContextRequest.h" @@ -38,38 +37,6 @@ -/* **************************************************************************** -* -* NotifyContextRequest::toJsonV1 - -*/ -std::string NotifyContextRequest::toJsonV1 -( - bool asJsonObject, - const std::vector& attrsFilter, - bool blacklist, - const std::vector& metadataFilter -) -{ - std::string out = ""; - bool contextElementResponseVectorRendered = contextElementResponseVector.size() != 0; - - // - // Note on JSON commas: - // subscriptionId and originator are MANDATORY. - // The only doubt here if whether originator should end in a comma. - // This doubt is taken care of by the variable 'contextElementResponseVectorRendered' - // - out += startTag(); - out += subscriptionId.toJsonV1(NotifyContext, true); - out += originator.toJsonV1(contextElementResponseVectorRendered); - out += contextElementResponseVector.toJsonV1(asJsonObject, NotifyContext, attrsFilter, blacklist, metadataFilter, false); - out += endTag(); - - return out; -} - - - /* **************************************************************************** * * NotifyContextRequest::toJson - @@ -122,7 +89,7 @@ std::string NotifyContextRequest::toJson { JsonObjectHelper jh; - jh.addString("subscriptionId", subscriptionId.get()); + jh.addString("subscriptionId", subscriptionId); jh.addRaw("data", contextElementResponseVector.toJson(renderFormat, attrsFilter, blacklist, metadataFilter, exprContextObjectP)); return jh.str(); } @@ -130,58 +97,14 @@ std::string NotifyContextRequest::toJson -/* **************************************************************************** -* -* NotifyContextRequest::check -*/ -std::string NotifyContextRequest::check(ApiVersion apiVersion, const std::string& predetectedError) -{ - std::string res; - NotifyContextResponse response; - - if (!predetectedError.empty()) - { - response.responseCode.fill(SccBadRequest, predetectedError); - } - else if (((res = subscriptionId.check()) != "OK") || - ((res = originator.check()) != "OK") || - ((res = contextElementResponseVector.check(apiVersion, QueryContext, predetectedError, 0)) != "OK")) - { - response.responseCode.fill(SccBadRequest, res); - } - else - { - return "OK"; - } - - return response.toJsonV1(); -} - - - /* **************************************************************************** * * NotifyContextRequest::release - +* +* FIXME PR: this method is not called (it can be removed without compilation errors). Possible memory leak? */ void NotifyContextRequest::release(void) { contextElementResponseVector.release(); } - - -/* **************************************************************************** -* -* NotifyContextRequest::clone - -*/ -NotifyContextRequest* NotifyContextRequest::clone(void) -{ - NotifyContextRequest* ncrP = new NotifyContextRequest(); - - ncrP->subscriptionId = subscriptionId; - ncrP->originator = originator; - - ncrP->contextElementResponseVector.fill(contextElementResponseVector); - - return ncrP; -} diff --git a/src/lib/ngsi10/NotifyContextRequest.h b/src/lib/ngsi10/NotifyContextRequest.h index c0d179a1f3..5b0c014331 100644 --- a/src/lib/ngsi10/NotifyContextRequest.h +++ b/src/lib/ngsi10/NotifyContextRequest.h @@ -29,8 +29,6 @@ #include "common/RenderFormat.h" #include "ngsi/Request.h" -#include "ngsi/SubscriptionId.h" -#include "ngsi/Originator.h" #include "ngsi/ContextElementResponseVector.h" @@ -41,22 +39,15 @@ */ typedef struct NotifyContextRequest { - SubscriptionId subscriptionId; // Mandatory - Originator originator; // Mandatory + std::string subscriptionId; // Mandatory ContextElementResponseVector contextElementResponseVector; // Optional - std::string toJsonV1(bool asJsonObject, - const std::vector& attrsFilter, - bool blacklist, - const std::vector& metadataFilter); std::string toJson(RenderFormat renderFormat, const std::vector& attrsFilter, bool blacklist, const std::vector& metadataFilter, ExprContextObject* exprContextObjectP = NULL); - std::string check(ApiVersion apiVersion, const std::string& predetectedError); void release(void); - NotifyContextRequest* clone(void); } NotifyContextRequest; #endif // SRC_LIB_NGSI10_NOTIFYCONTEXTREQUEST_H_ diff --git a/src/lib/ngsi10/NotifyContextResponse.cpp b/src/lib/ngsi10/NotifyContextResponse.cpp index bfb3218793..a02d7ac94c 100644 --- a/src/lib/ngsi10/NotifyContextResponse.cpp +++ b/src/lib/ngsi10/NotifyContextResponse.cpp @@ -28,9 +28,8 @@ #include "logMsg/logMsg.h" #include "logMsg/traceLevels.h" -#include "common/tag.h" #include "common/globals.h" -#include "ngsi/StatusCode.h" +#include "rest/OrionError.h" #include "ngsi10/NotifyContextResponse.h" #include "rest/HttpStatusCode.h" @@ -42,46 +41,5 @@ */ NotifyContextResponse::NotifyContextResponse() { - responseCode.fill(SccOk); -} - - - -/* **************************************************************************** -* -* NotifyContextResponse::NotifyContextResponse - -*/ -NotifyContextResponse::NotifyContextResponse(StatusCode& sc) -{ - responseCode.fill(&sc); -} - - - -/* **************************************************************************** -* -* NotifyContextResponse::toJsonV1 - -*/ -std::string NotifyContextResponse::toJsonV1(void) -{ - std::string out = ""; - - responseCode.keyNameSet("responseCode"); - - out += startTag(); - out += responseCode.toJsonV1(false); - out += endTag(); - - return out; -} - - - -/* **************************************************************************** -* -* NotifyContextResponse::release - -*/ -void NotifyContextResponse::release(void) -{ - responseCode.release(); + error.fill(SccOk); } diff --git a/src/lib/ngsi10/NotifyContextResponse.h b/src/lib/ngsi10/NotifyContextResponse.h index 88848dc84e..79cfa1ca38 100644 --- a/src/lib/ngsi10/NotifyContextResponse.h +++ b/src/lib/ngsi10/NotifyContextResponse.h @@ -29,23 +29,22 @@ #include #include "ngsi/Request.h" -#include "ngsi/StatusCode.h" +#include "rest/OrionError.h" /* **************************************************************************** * * NotifyContextResponse - +* +* FIXME: class really needed? */ typedef struct NotifyContextResponse { - StatusCode responseCode; // Mandatory + OrionError error; // Mandatory NotifyContextResponse(); - NotifyContextResponse(StatusCode& sc); - std::string toJsonV1(void); - void release(void); } NotifyContextResponse; #endif // SRC_LIB_NGSI10_NOTIFYCONTEXTRESPONSE_H_ diff --git a/src/lib/ngsi10/QueryContextRequest.cpp b/src/lib/ngsi10/QueryContextRequest.cpp index a3d3989d1a..196349d857 100644 --- a/src/lib/ngsi10/QueryContextRequest.cpp +++ b/src/lib/ngsi10/QueryContextRequest.cpp @@ -28,12 +28,10 @@ #include "logMsg/traceLevels.h" #include "common/globals.h" #include "common/JsonHelper.h" -#include "common/tag.h" #include "alarmMgr/alarmMgr.h" #include "ngsi/Request.h" #include "ngsi/StringList.h" #include "ngsi/EntityIdVector.h" -#include "ngsi/Restriction.h" #include "ngsi10/QueryContextResponse.h" #include "ngsi10/QueryContextRequest.h" #include "rest/EntityTypeInfo.h" @@ -45,12 +43,9 @@ * * QueryContextRequest::QueryContextRequest * -* Explicit constructor needed to initialize primitive types so they don't get -* random values from the stack */ QueryContextRequest::QueryContextRequest() { - restrictions = 0; } @@ -59,10 +54,10 @@ QueryContextRequest::QueryContextRequest() * * QueryContextRequest::QueryContextRequest */ -QueryContextRequest::QueryContextRequest(const std::string& _contextProvider, EntityId* eP, const std::string& attributeName, ProviderFormat _providerFormat) +QueryContextRequest::QueryContextRequest(const std::string& _contextProvider, EntityId* eP, const std::string& attributeName, bool _legacyProviderFormat) { - contextProvider = _contextProvider; - providerFormat = _providerFormat; + contextProvider = _contextProvider; + legacyProviderFormat = _legacyProviderFormat; entityIdVector.push_back(new EntityId(eP)); @@ -70,8 +65,6 @@ QueryContextRequest::QueryContextRequest(const std::string& _contextProvider, En { attributeList.push_back(attributeName); } - - restrictions = 0; } @@ -80,16 +73,14 @@ QueryContextRequest::QueryContextRequest(const std::string& _contextProvider, En * * QueryContextRequest::QueryContextRequest */ -QueryContextRequest::QueryContextRequest(const std::string& _contextProvider, EntityId* eP, const StringList& _attributeList, ProviderFormat _providerFormat) +QueryContextRequest::QueryContextRequest(const std::string& _contextProvider, EntityId* eP, const StringList& _attributeList, bool _legacyProviderFormat) { - contextProvider = _contextProvider; - providerFormat = _providerFormat; + contextProvider = _contextProvider; + legacyProviderFormat = _legacyProviderFormat; entityIdVector.push_back(new EntityId(eP)); attributeList.clone(_attributeList); - - restrictions = 0; } @@ -113,52 +104,60 @@ std::string QueryContextRequest::toJson(void) /* **************************************************************************** * * QueryContextRequest::toJsonV1 - +* +* This is used only in the legacyForwarding:true logic. It would remove once that deprecated feature +* would be removed. +* +* Example: +* { +* "entities": [ +* { +* "type": "Room", +* "isPattern": "true", +* "id": "ConferenceRoom.*" +* } +* ], +* "attributes": [ +* "temperature", +* "pressure", +* "lightstatus" +* ] +} */ std::string QueryContextRequest::toJsonV1(void) { - std::string out = ""; - bool attributeListRendered = attributeList.size() != 0; - bool restrictionRendered = restrictions != 0; - bool commaAfterAttributeList = restrictionRendered; - bool commaAfterEntityIdVector = attributeListRendered || restrictionRendered; - - out += startTag(); - out += entityIdVector.toJsonV1(commaAfterEntityIdVector); - out += attributeList.toJsonV1(commaAfterAttributeList, "attributes"); - out += restriction.toJsonV1(restrictions, false); - out += endTag(); - - return out; -} + // Diferent from original toJsonV1() we don't render restriction field (as it is not needed in the forwarding functionality) + JsonObjectHelper jh; - -/* **************************************************************************** -* -* QueryContextRequest::check - -*/ -std::string QueryContextRequest::check(ApiVersion apiVersion, bool asJsonObject, const std::string& predetectedError) -{ - std::string res; - QueryContextResponse response; - - if (!predetectedError.empty()) - { - response.errorCode.fill(SccBadRequest, predetectedError); - } - else if (((res = entityIdVector.check(QueryContext)) != "OK") || - ((res = attributeList.check()) != "OK") || - ((res = restriction.check(restrictions)) != "OK")) + JsonVectorHelper jhEntities; + for (unsigned int ix = 0; ix < entityIdVector.size(); ++ix) { - alarmMgr.badInput(clientIp, res); - response.errorCode.fill(SccBadRequest, res); + JsonObjectHelper jhEntity; + if (entityIdVector[ix]->idPattern.empty()) + { + jhEntity.addString("id", entityIdVector[ix]->id); + jhEntity.addString("isPattern", "false"); + } + else + { + jhEntity.addString("id", entityIdVector[ix]->idPattern); + jhEntity.addString("isPattern", "true"); + } + jhEntity.addString("type", entityIdVector[ix]->type); + + jhEntities.addRaw(jhEntity.str()); } - else + jh.addRaw("entities", jhEntities.str()); + + JsonVectorHelper jhAttributes; + for (unsigned int ix = 0; ix < attributeList.size(); ++ix) { - return "OK"; + jhAttributes.addString(attributeList[ix]); } + jh.addRaw("attributes", jhAttributes.str()); - return response.toJsonV1(asJsonObject); + return jh.str(); } @@ -170,25 +169,7 @@ std::string QueryContextRequest::check(ApiVersion apiVersion, bool asJsonObject, void QueryContextRequest::release(void) { entityIdVector.release(); - restriction.release(); -} - - - -/* **************************************************************************** -* -* QueryContextRequest::fill - -*/ -void QueryContextRequest::fill(const std::string& entityId, const std::string& entityType, const std::string& attributeName) -{ - EntityId* eidP = new EntityId(entityId, entityType, "true"); - - entityIdVector.push_back(eidP); - - if (!attributeName.empty()) - { - attributeList.push_back(attributeName); - } + scopeVector.release(); } @@ -200,13 +181,13 @@ void QueryContextRequest::fill(const std::string& entityId, const std::string& e void QueryContextRequest::fill ( const std::string& entityId, + const std::string& entityIdPattern, const std::string& entityType, - const std::string& isPattern, EntityTypeInfo typeInfo, const std::string& attributeName ) { - EntityId* eidP = new EntityId(entityId, entityType, isPattern); + EntityId* eidP = new EntityId(entityId, entityIdPattern, entityType, ""); entityIdVector.push_back(eidP); @@ -216,7 +197,7 @@ void QueryContextRequest::fill scopeP->oper = (typeInfo == EntityTypeEmpty)? SCOPE_OPERATOR_NOT : ""; - restriction.scopeVector.push_back(scopeP); + scopeVector.push_back(scopeP); } if (!attributeName.empty()) @@ -241,17 +222,17 @@ void QueryContextRequest::fill(BatchQuery* bqP) { if (bqP->entities.vec.size() != 0) { - entityIdVector.fill(bqP->entities.vec); + entityIdVector.fill(bqP->entities); } else { - EntityId* eP = new EntityId(".*", "", "true"); + EntityId* eP = new EntityId("", ".*", "", ""); entityIdVector.push_back(eP); } attributeList.fill(bqP->attributeV.stringV); // attributeV is deprecated attrsList.fill(bqP->attrsV.stringV); metadataList.fill(bqP->metadataV.stringV); - restriction.scopeVector.fill(bqP->scopeV, false); // false: DO NOT ALLOCATE NEW scopes - reference the 'old' ones - bqP->scopeV.vec.clear(); // QueryContextRequest::restriction.scopeVector has taken over the Scopes from bqP + scopeVector.fill(bqP->scopeV, false); // false: DO NOT ALLOCATE NEW scopes - reference the 'old' ones + bqP->scopeV.vec.clear(); // QueryContextRequest::scopeVector has taken over the Scopes from bqP } diff --git a/src/lib/ngsi10/QueryContextRequest.h b/src/lib/ngsi10/QueryContextRequest.h index 202d68015b..4bfa80785a 100644 --- a/src/lib/ngsi10/QueryContextRequest.h +++ b/src/lib/ngsi10/QueryContextRequest.h @@ -30,7 +30,7 @@ #include "ngsi/Request.h" #include "ngsi/StringList.h" #include "ngsi/EntityIdVector.h" -#include "ngsi/Restriction.h" +#include "ngsi/ScopeVector.h" #include "rest/EntityTypeInfo.h" @@ -54,25 +54,22 @@ typedef struct QueryContextRequest EntityIdVector entityIdVector; // Mandatory StringList attributeList; // Optional StringList attrsList; // Used by the NGSIv2 forwarding logic, to avoid over-querying attributes (see pruneContextElements) - Restriction restriction; // Optional + ScopeVector scopeVector; // Optional - int restrictions; - StringList metadataList; // From URI param 'metadata' - std::string contextProvider; // Not part of the payload - used internally only - ProviderFormat providerFormat; // Not part of the payload - used internally only + StringList metadataList; // From URI param 'metadata' + std::string contextProvider; // Not part of the payload - used internally only + bool legacyProviderFormat; // Not part of the payload - used internally only QueryContextRequest(); - QueryContextRequest(const std::string& _contextProvider, EntityId* eP, const std::string& attributeName, ProviderFormat _providerFormat); - QueryContextRequest(const std::string& _contextProvider, EntityId* eP, const StringList& attributeList, ProviderFormat _providerFormat); + QueryContextRequest(const std::string& _contextProvider, EntityId* eP, const std::string& attributeName, bool _legacyProviderFormat); + QueryContextRequest(const std::string& _contextProvider, EntityId* eP, const StringList& attributeList, bool _legacyProviderFormat); std::string toJsonV1(void); std::string toJson(void); - std::string check(ApiVersion apiVersion, bool asJsonObject, const std::string& predetectedError); void release(void); - void fill(const std::string& entityId, const std::string& entityType, const std::string& attributeName); void fill(const std::string& entityId, + const std::string& entityIdPattern, const std::string& entityType, - const std::string& isPattern, EntityTypeInfo typeInfo, const std::string& attributeName); void fill(BatchQuery* bqP); diff --git a/src/lib/ngsi10/QueryContextResponse.cpp b/src/lib/ngsi10/QueryContextResponse.cpp index 011a10298f..64a1a4dea4 100644 --- a/src/lib/ngsi10/QueryContextResponse.cpp +++ b/src/lib/ngsi10/QueryContextResponse.cpp @@ -28,10 +28,10 @@ #include "logMsg/logMsg.h" #include "common/string.h" -#include "common/tag.h" +#include "common/errorMessages.h" #include "alarmMgr/alarmMgr.h" #include "rest/HttpStatusCode.h" -#include "ngsi/StatusCode.h" +#include "rest/OrionError.h" #include "ngsi10/QueryContextResponse.h" @@ -42,38 +42,6 @@ */ QueryContextResponse::QueryContextResponse() { - errorCode.keyNameSet("errorCode"); -} - - - -/* **************************************************************************** -* -* QueryContextResponse::QueryContextResponse - -*/ -QueryContextResponse::QueryContextResponse(StatusCode& _errorCode) -{ - errorCode.fill(&_errorCode); - errorCode.keyNameSet("errorCode"); -} - - - -/* **************************************************************************** -* -* QueryContextResponse::QueryContextResponse - -*/ -QueryContextResponse::QueryContextResponse(EntityId* eP, ContextAttribute* aP) -{ - ContextElementResponse* cerP = new ContextElementResponse(); - ContextAttribute* caP = new ContextAttribute(aP); - - cerP->entity.fill(eP->id, eP->type, eP->isPattern); - cerP->entity.attributeVector.push_back(caP); - cerP->statusCode.fill(SccOk); - - contextElementResponseVector.push_back(cerP); - errorCode.fill(SccOk); } @@ -84,106 +52,11 @@ QueryContextResponse::QueryContextResponse(EntityId* eP, ContextAttribute* aP) */ QueryContextResponse::~QueryContextResponse() { - errorCode.release(); contextElementResponseVector.release(); } -/* **************************************************************************** -* -* QueryContextResponse::toJsonV1 - -*/ -std::string QueryContextResponse::toJsonV1(bool asJsonObject) -{ - std::string out = ""; - bool errorCodeRendered = false; - - // - // 01. Decide whether errorCode should be rendered - // - if ((errorCode.code != SccNone) && (errorCode.code != SccOk)) - { - errorCodeRendered = true; - } - else if (contextElementResponseVector.size() == 0) - { - errorCodeRendered = true; - } - else if (!errorCode.details.empty()) - { - if (errorCode.code == SccNone) - { - errorCode.code = SccOk; - } - - errorCodeRendered = true; - } - - - // - // 02. render - // - out += startTag(); - - if (contextElementResponseVector.size() > 0) - { - out += contextElementResponseVector.toJsonV1(asJsonObject, QueryContext, false, errorCodeRendered); - } - - if (errorCodeRendered == true) - { - out += errorCode.toJsonV1(false); - } - - - // - // 03. Safety Check - // - // If neither errorCode nor CER vector was filled by mongoBackend, then we - // report a special kind of error. - // - if ((errorCode.code == SccNone) && (contextElementResponseVector.size() == 0)) - { - LM_E(("Runtime Error (Both error-code and response vector empty)")); - errorCode.fill(SccReceiverInternalError, "Both the error-code structure and the response vector were empty"); - out += errorCode.toJsonV1(false); - } - - out += endTag(); - - return out; -} - - - -/* **************************************************************************** -* -* QueryContextResponse::check - -*/ -std::string QueryContextResponse::check(ApiVersion apiVersion, bool asJsonObject, const std::string& predetectedError) -{ - std::string res; - - if (!predetectedError.empty()) - { - errorCode.fill(SccBadRequest, predetectedError); - } - else if ((res = contextElementResponseVector.check(apiVersion, QueryContext, predetectedError, 0)) != "OK") - { - alarmMgr.badInput(clientIp, res); - errorCode.fill(SccBadRequest, res); - } - else - { - return "OK"; - } - - return toJsonV1(asJsonObject); -} - - - /* **************************************************************************** * * QueryContextResponse::release - @@ -191,7 +64,6 @@ std::string QueryContextResponse::check(ApiVersion apiVersion, bool asJsonObject void QueryContextResponse::release(void) { contextElementResponseVector.release(); - errorCode.release(); } @@ -200,46 +72,66 @@ void QueryContextResponse::release(void) * * QueryContextResponse::fill - */ -void QueryContextResponse::fill(QueryContextResponse* qcrsP) +void QueryContextResponse::fill(const EntityVector& entities) { - errorCode.fill(qcrsP->errorCode); - - for (unsigned int cerIx = 0; cerIx < qcrsP->contextElementResponseVector.size(); ++cerIx) + for (unsigned int eIx = 0; eIx < entities.vec.size(); eIx++) { - ContextElementResponse* cerP = new ContextElementResponse(); - - cerP->fill(qcrsP->contextElementResponseVector[cerIx]); - + ContextElementResponse* cerP = new ContextElementResponse(entities.vec[eIx]); contextElementResponseVector.push_back(cerP); } } - /* **************************************************************************** * -* QueryContextResponse::fill - +* QueryContextResponse::getAttr - +* +* If attribute is found: +* - It is returned by the function +* - The OrionError is set to SccNone +* +* If attribute is not found +* - Function returns NULL +* - The OrionError is not touched +* */ -void QueryContextResponse::fill(const Entities& entities) +ContextAttribute* QueryContextResponse::getAttr(const std::string& attrName, OrionError* oeP) { - for (int eIx = 0; eIx < entities.size(); eIx++) + if (error.code == SccContextElementNotFound) { - ContextElementResponse* cerP = new ContextElementResponse(entities.vec.vec[eIx]); - contextElementResponseVector.push_back(cerP); + oeP->fill(SccContextElementNotFound, ERROR_DESC_NOT_FOUND_ENTITY, ERROR_NOT_FOUND); + return NULL; } -} + if (error.code != SccOk) + { + // + // any other error distinct from Not Found + // + oeP->fill(error.code, error.description, error.error); + return NULL; + } + if (contextElementResponseVector.size() > 1) // error.code == SccOk + { + // + // If there are more than one entity, we return an error + // + oeP->fill(SccConflict, ERROR_DESC_TOO_MANY_ENTITIES, ERROR_TOO_MANY); + return NULL; + } -/* **************************************************************************** -* -* QueryContextResponse::clone - -*/ -QueryContextResponse* QueryContextResponse::clone(void) -{ - QueryContextResponse* clon = new QueryContextResponse(); + // Look for the attribute by name + ContextElementResponse* cerP = contextElementResponseVector[0]; - clon->fill(this); + for (std::size_t i = 0; i < cerP->entity.attributeVector.size(); ++i) + { + if (cerP->entity.attributeVector[i]->name == attrName) + { + return cerP->entity.attributeVector[i]; + } + } - return clon; + oeP->fill(SccContextElementNotFound, ERROR_DESC_NOT_FOUND_ATTRIBUTE, ERROR_NOT_FOUND); + return NULL; } diff --git a/src/lib/ngsi10/QueryContextResponse.h b/src/lib/ngsi10/QueryContextResponse.h index 75e03df6a1..82deb20f1e 100644 --- a/src/lib/ngsi10/QueryContextResponse.h +++ b/src/lib/ngsi10/QueryContextResponse.h @@ -30,8 +30,7 @@ #include #include "ngsi/ContextElementResponseVector.h" -#include "apiTypesV2/Entities.h" -#include "ngsi/StatusCode.h" +#include "rest/OrionError.h" @@ -46,19 +45,14 @@ typedef struct QueryContextResponse { ContextElementResponseVector contextElementResponseVector; // Optional - StatusCode errorCode; // Optional + OrionError error; // Optional QueryContextResponse(); - QueryContextResponse(EntityId* eP, ContextAttribute* aP); - QueryContextResponse(StatusCode& _errorCode); ~QueryContextResponse(); - std::string toJsonV1(bool asJsonObject); - std::string check(ApiVersion apiVersion, bool asJsonObject, const std::string& predetectedError); void release(void); - void fill(QueryContextResponse* qcrsP); - void fill(const Entities& entities); - QueryContextResponse* clone(void); + void fill(const EntityVector& entities); + ContextAttribute* getAttr(const std::string& attrName, OrionError* oeP); } QueryContextResponse; #endif // SRC_LIB_NGSI10_QUERYCONTEXTRESPONSE_H_ diff --git a/src/lib/ngsi10/SubscribeContextRequest.cpp b/src/lib/ngsi10/SubscribeContextRequest.cpp deleted file mode 100644 index a0e2b19022..0000000000 --- a/src/lib/ngsi10/SubscribeContextRequest.cpp +++ /dev/null @@ -1,188 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include - -#include "common/globals.h" -#include "common/tag.h" -#include "ngsi/Request.h" -#include "ngsi/StatusCode.h" -#include "rest/EntityTypeInfo.h" -#include "ngsi10/SubscribeContextResponse.h" -#include "ngsi10/SubscribeContextRequest.h" -#include "mongoBackend/dbConstants.h" -#include "alarmMgr/alarmMgr.h" - - -using namespace ngsiv2; - - - -/* **************************************************************************** -* -* SubscribeContextRequest::check - -*/ -std::string SubscribeContextRequest::check(const std::string& predetectedError, int counter) -{ - SubscribeContextResponse response; - std::string res; - - /* First, check optional fields only in the case they are present */ - /* Second, check the other (mandatory) fields */ - - if (((res = entityIdVector.check(SubscribeContext)) != "OK") || - ((res = attributeList.check()) != "OK") || - ((res = reference.check(SubscribeContext)) != "OK") || - ((res = duration.check()) != "OK") || - ((res = restriction.check(restrictions)) != "OK") || - ((res = notifyConditionVector.check(SubscribeContext, predetectedError, counter)) != "OK") || - ((res = throttling.check()) != "OK")) - { - alarmMgr.badInput(clientIp, res); - response.subscribeError.errorCode.fill(SccBadRequest, std::string("invalid payload: ") + res); - return response.toJsonV1(); - } - - return "OK"; -} - - - -/* **************************************************************************** -* -* SubscribeContextRequest::release - -* -* Old versions of this method also include a 'restriction.release()' call. However, now each time -* a SubscribeContextRequest is created, the method toNgsiv2Subscription() is used on it and the -* 'ownership' of the Restriction is transferred to the corresponding NGSIv2 class. Thus, leaving -* that 'restriction.release()' would cause double-free problems. -* -* What causes the problem is the following line in SubscribeContextRequest::toNgsiv2Subscription: -* -* sub->restriction = restriction; -* -* After doing this, we have TWO vectors pointing to the same scopes. -* -*/ -void SubscribeContextRequest::release(void) -{ - entityIdVector.release(); - attributeList.release(); - notifyConditionVector.release(); -} - - - -/* **************************************************************************** -* -* SubscribeContextRequest::fill - -*/ -void SubscribeContextRequest::fill(EntityTypeInfo typeInfo) -{ - if ((typeInfo == EntityTypeEmpty) || (typeInfo == EntityTypeNotEmpty)) - { - Scope* scopeP = new Scope(SCOPE_FILTER_EXISTENCE, SCOPE_VALUE_ENTITY_TYPE); - - scopeP->oper = (typeInfo == EntityTypeEmpty)? SCOPE_OPERATOR_NOT : ""; - - restriction.scopeVector.push_back(scopeP); - } -} - - -/* **************************************************************************** -* -* SubscribeContextRequest::toNgsiv2Subscription - -*/ -void SubscribeContextRequest::toNgsiv2Subscription(Subscription* sub) -{ - // Convert entityIdVector - for (unsigned int ix = 0; ix < entityIdVector.size(); ++ix) - { - EntityId* enP = entityIdVector[ix]; - EntID en; - - if (enP->isPatternIsTrue()) - { - en.idPattern = enP->id; - } - else - { - en.id = enP->id; - } - en.type = enP->type; - - sub->subject.entities.push_back(en); - } - - // Convert attributeList - for (unsigned int ix = 0; ix < attributeList.size(); ++ix) - { - sub->notification.attributes.push_back(attributeList[ix]); - } - - // Convert reference - sub->notification.httpInfo.url = reference.get(); - - // Convert duration - if (duration.isEmpty()) - { - sub->expires = DEFAULT_DURATION_IN_SECONDS + getCurrentTime(); - } - else - { - sub->expires = duration.parse() + getCurrentTime(); - } - - // Convert restriction - sub->restriction = restriction; - - // Convert notifyConditionVector - for (unsigned int ix = 0; ix < notifyConditionVector.size(); ++ix) - { - NotifyCondition* ncP = notifyConditionVector[ix]; - if (ncP->type == ON_CHANGE_CONDITION) // this is just a sanity measure: all types should be ONCHANGE - { - for (unsigned int jx = 0; jx < ncP->condValueList.size(); ++jx) - { - sub->subject.condition.attributes.push_back(ncP->condValueList[jx]); - } - } - } - - // Convert throttling - sub->throttling = throttling.parse(); - - // Note that we don't do anything with 'restrictions': it is not needed by the NGSIv2 logic - - // Fill NGSIv2 fields not used in NGSIv1 with default values - // description and expression are not touched, so default empty string provided by constructor will be used - sub->status = STATUS_ACTIVE; - sub->descriptionProvided = false; - sub->attrsFormat = NGSI_V2_NORMALIZED; - sub->notification.blacklist = false; - sub->notification.httpInfo.custom = false; - - sub->notification.metadata.clear(); -} diff --git a/src/lib/ngsi10/SubscribeContextRequest.h b/src/lib/ngsi10/SubscribeContextRequest.h deleted file mode 100644 index edd7abe476..0000000000 --- a/src/lib/ngsi10/SubscribeContextRequest.h +++ /dev/null @@ -1,70 +0,0 @@ -#ifndef SRC_LIB_NGSI10_SUBSCRIBECONTEXTREQUEST_H_ -#define SRC_LIB_NGSI10_SUBSCRIBECONTEXTREQUEST_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include - -#include "common/RenderFormat.h" -#include "ngsi/Request.h" -#include "ngsi/StringList.h" -#include "ngsi/EntityIdVector.h" -#include "ngsi/Duration.h" -#include "ngsi/NotifyConditionVector.h" -#include "ngsi/Reference.h" -#include "ngsi/Restriction.h" -#include "ngsi/Throttling.h" -#include "rest/EntityTypeInfo.h" -#include "apiTypesV2//Subscription.h" - - - -/* **************************************************************************** -* -* SubscribeContextRequest - -*/ -typedef struct SubscribeContextRequest -{ - EntityIdVector entityIdVector; // Mandatory - StringList attributeList; // Optional - Reference reference; // Mandatory - Duration duration; // Optional - Restriction restriction; // Optional - NotifyConditionVector notifyConditionVector; // Optional - Throttling throttling; // Optional - - /* The number of restrictions */ - int restrictions; - - SubscribeContextRequest(): restrictions(0) {} - - std::string check(const std::string& predetectedError, int counter); - void release(void); - void toNgsiv2Subscription(ngsiv2::Subscription* sub); - - void fill(EntityTypeInfo typeInfo); -} SubscribeContextRequest; - -#endif // SRC_LIB_NGSI10_SUBSCRIBECONTEXTREQUEST_H_ diff --git a/src/lib/ngsi10/SubscribeContextResponse.cpp b/src/lib/ngsi10/SubscribeContextResponse.cpp deleted file mode 100644 index 69baa9a8ba..0000000000 --- a/src/lib/ngsi10/SubscribeContextResponse.cpp +++ /dev/null @@ -1,107 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include - -#include "logMsg/traceLevels.h" -#include "logMsg/logMsg.h" -#include "common/tag.h" -#include "common/JsonHelper.h" -#include "ngsi10/SubscribeContextResponse.h" - -/* **************************************************************************** -* -* SubscribeContextResponse::~SubscribeContextResponse - -*/ -SubscribeContextResponse::~SubscribeContextResponse() { - LM_T(LmtDestructor,("destroyed")); -} - -/* **************************************************************************** -* -* SubscribeContextResponse::SubscribeContextResponse - -*/ -SubscribeContextResponse::SubscribeContextResponse() -{ - subscribeError.errorCode.keyNameSet("errorCode"); - subscribeError.subscriptionId.set("000000000000000000000000"); -} - -/* **************************************************************************** -* -* SubscribeContextResponse::SubscribeContextResponse - -*/ -SubscribeContextResponse::SubscribeContextResponse(StatusCode& errorCode) -{ - subscribeError.subscriptionId.set("000000000000000000000000"); - subscribeError.errorCode.fill(&errorCode); - subscribeError.errorCode.keyNameSet("errorCode"); -} - -/* **************************************************************************** -* -* SubscribeContextResponse::toJson - -*/ -std::string SubscribeContextResponse::toJson(void) -{ - if (subscribeError.errorCode.code == SccNone) - { - std::string out; - // FIXME P5: it is a bit weird to call a toJsonV1() method from a toJson() method. However, - // SubscribeResponse doesn't have another option. This should be looked into detail. - out += "{"; - out += subscribeResponse.toJsonV1(false); - out += "}"; - return out; - } - else - { - return subscribeError.toJson(); - } - -} - -/* **************************************************************************** -* -* SubscribeContextResponse::toJsonV1 - -*/ -std::string SubscribeContextResponse::toJsonV1(void) -{ - std::string out = ""; - - out += startTag(); - - if (subscribeError.errorCode.code == SccNone) - { - out += subscribeResponse.toJsonV1(false); - } - else - { - out += subscribeError.toJsonV1(SubscribeContext, false); - } - - out += endTag(false); - - return out; -} diff --git a/src/lib/ngsi10/SubscribeContextResponse.h b/src/lib/ngsi10/SubscribeContextResponse.h deleted file mode 100644 index dc795040dc..0000000000 --- a/src/lib/ngsi10/SubscribeContextResponse.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef SRC_LIB_NGSI10_SUBSCRIBECONTEXTRESPONSE_H_ -#define SRC_LIB_NGSI10_SUBSCRIBECONTEXTRESPONSE_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include - -#include "ngsi/StatusCode.h" -#include "ngsi/SubscribeResponse.h" -#include "ngsi/SubscribeError.h" - - - -/* **************************************************************************** -* -* SubscribeContextResponse - -*/ -typedef struct SubscribeContextResponse -{ - SubscribeResponse subscribeResponse; // Optional - but one of the two MUST be present! - SubscribeError subscribeError; // Optional - but one of the two MUST be present! - - SubscribeContextResponse(); - SubscribeContextResponse(StatusCode& errorCode); - ~SubscribeContextResponse(); - - std::string toJsonV1(void); - std::string toJson(void); -} SubscribeContextResponse; - -#endif // SRC_LIB_NGSI10_SUBSCRIBECONTEXTRESPONSE_H_ diff --git a/src/lib/ngsi10/UnsubscribeContextRequest.cpp b/src/lib/ngsi10/UnsubscribeContextRequest.cpp deleted file mode 100644 index af727ad495..0000000000 --- a/src/lib/ngsi10/UnsubscribeContextRequest.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include - -#include "common/globals.h" -#include "common/tag.h" -#include "ngsi10/UnsubscribeContextResponse.h" -#include "ngsi10/UnsubscribeContextRequest.h" - - - -/* **************************************************************************** -* -* UnsubscribeContextRequest::toJsonV1 - -*/ -std::string UnsubscribeContextRequest::toJsonV1(void) -{ - std::string out = ""; - - out += startTag(); - out += subscriptionId.toJsonV1(UnsubscribeContext, false); - out += endTag(); - - return out; -} - - - -/* **************************************************************************** -* -* UnsubscribeContextRequest::check - -*/ -std::string UnsubscribeContextRequest::check() -{ - UnsubscribeContextResponse response; - std::string res; - - if ((res = subscriptionId.check()) != "OK") - { - response.statusCode.fill(SccBadRequest, std::string("Invalid Subscription Id: /") + subscriptionId.get() + "/: " + res); - return response.toJsonV1(); - } - - return "OK"; -} - - - -/* **************************************************************************** -* -* UnsubscribeContextRequest::release - -*/ -void UnsubscribeContextRequest::release(void) -{ -} diff --git a/src/lib/ngsi10/UnsubscribeContextRequest.h b/src/lib/ngsi10/UnsubscribeContextRequest.h deleted file mode 100644 index d8b9d2a101..0000000000 --- a/src/lib/ngsi10/UnsubscribeContextRequest.h +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef SRC_LIB_NGSI10_UNSUBSCRIBECONTEXTREQUEST_H_ -#define SRC_LIB_NGSI10_UNSUBSCRIBECONTEXTREQUEST_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include - -#include "ngsi/SubscriptionId.h" - - - -/* **************************************************************************** -* -* UnsubscribeContextRequest - -*/ -typedef struct UnsubscribeContextRequest -{ - SubscriptionId subscriptionId; // Mandatory - - std::string toJsonV1(void); - std::string check(void); - void release(void); -} UnsubscribeContextRequest; - -#endif // SRC_LIB_NGSI10_UNSUBSCRIBECONTEXTREQUEST_H_ diff --git a/src/lib/ngsi10/UnsubscribeContextResponse.cpp b/src/lib/ngsi10/UnsubscribeContextResponse.cpp deleted file mode 100644 index 1e8b80d37c..0000000000 --- a/src/lib/ngsi10/UnsubscribeContextResponse.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include - -#include "logMsg/traceLevels.h" -#include "logMsg/logMsg.h" -#include "common/tag.h" -#include "ngsi/StatusCode.h" -#include "ngsi10/UnsubscribeContextResponse.h" - -/* **************************************************************************** -* -* UnsubscribeContextResponse::UnsubscribeContextResponse - -*/ -UnsubscribeContextResponse::UnsubscribeContextResponse() -{ - LM_T(LmtDestructor,("created")); -} - - - -/* **************************************************************************** -* -* UnsubscribeContextResponse::UnsubscribeContextResponse - -*/ -UnsubscribeContextResponse::UnsubscribeContextResponse(StatusCode& _statusCode) -{ - statusCode.fill(&_statusCode); - subscriptionId.set("000000000000000000000000"); -} - - - -/* **************************************************************************** -* -* UnsubscribeContextResponse::~UnsubscribeContextResponse - -*/ -UnsubscribeContextResponse::~UnsubscribeContextResponse() -{ - LM_T(LmtDestructor,("destroyed")); -} - -/* **************************************************************************** -* -* UnsubscribeContextResponse::toJsonV1 - -*/ -std::string UnsubscribeContextResponse::toJsonV1(void) -{ - std::string out = ""; - - out += startTag(); - out += subscriptionId.toJsonV1(RtUnsubscribeContextResponse, true); - out += statusCode.toJsonV1(false); - out += endTag(); - - return out; -} - - - -/* **************************************************************************** -* -* UnsubscribeContextResponse::release - -*/ -void UnsubscribeContextResponse::release(void) -{ -} diff --git a/src/lib/ngsi10/UnsubscribeContextResponse.h b/src/lib/ngsi10/UnsubscribeContextResponse.h deleted file mode 100644 index 732e12280d..0000000000 --- a/src/lib/ngsi10/UnsubscribeContextResponse.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef SRC_LIB_NGSI10_UNSUBSCRIBECONTEXTRESPONSE_H_ -#define SRC_LIB_NGSI10_UNSUBSCRIBECONTEXTRESPONSE_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include - -#include "ngsi/SubscriptionId.h" -#include "ngsi/StatusCode.h" - -#include "rest/OrionError.h" - - - -/* **************************************************************************** -* -* UnsubscribeContextResponse - -*/ -typedef struct UnsubscribeContextResponse -{ - SubscriptionId subscriptionId; // Mandatory - StatusCode statusCode; // Mandatory - - OrionError oe; // Used by NGSIv2 - - UnsubscribeContextResponse(); - UnsubscribeContextResponse(StatusCode& statusCode); - ~UnsubscribeContextResponse(); - - std::string toJsonV1(void); - void release(void); -} UnsubscribeContextResponse; - -#endif // SRC_LIB_NGSI10_UNSUBSCRIBECONTEXTRESPONSE_H_ diff --git a/src/lib/ngsi10/UpdateContextRequest.cpp b/src/lib/ngsi10/UpdateContextRequest.cpp index db3a910e75..435a61781b 100644 --- a/src/lib/ngsi10/UpdateContextRequest.cpp +++ b/src/lib/ngsi10/UpdateContextRequest.cpp @@ -29,15 +29,11 @@ #include "logMsg/traceLevels.h" #include "common/globals.h" -#include "common/tag.h" #include "common/JsonHelper.h" #include "alarmMgr/alarmMgr.h" -#include "convenience/UpdateContextElementRequest.h" -#include "convenience/AppendContextElementRequest.h" #include "ngsi/ContextAttribute.h" #include "ngsi10/UpdateContextRequest.h" #include "ngsi10/UpdateContextResponse.h" -#include "convenience/UpdateContextAttributeRequest.h" @@ -55,11 +51,12 @@ UpdateContextRequest::UpdateContextRequest() * * UpdateContextRequest::UpdateContextRequest - */ -UpdateContextRequest::UpdateContextRequest(const std::string& _contextProvider, ProviderFormat _providerFormat, Entity* eP) +UpdateContextRequest::UpdateContextRequest(const std::string& _contextProvider, bool _legacyProviderFormat, Entity* eP) { - contextProvider = _contextProvider; - providerFormat = _providerFormat; - Entity* neweP = new Entity(eP->id, eP->type, eP->isPattern); + contextProvider = _contextProvider; + legacyProviderFormat = _legacyProviderFormat; + + Entity* neweP = new Entity(eP->entityId.id, eP->entityId.idPattern, eP->entityId.type, eP->entityId.typePattern); neweP->renderId = eP->renderId; entityVector.push_back(neweP); } @@ -76,7 +73,7 @@ std::string UpdateContextRequest::toJson(void) jh.addRaw("entities", entityVector.toJson(NGSI_V2_NORMALIZED)); - jh.addString("actionType", actionTypeString(V2, updateActionType)); + jh.addString("actionType", actionTypeString(updateActionType)); return jh.str(); } @@ -86,47 +83,116 @@ std::string UpdateContextRequest::toJson(void) /* **************************************************************************** * * UpdateContextRequest::toJsonV1 - +* +* This is used only in the legacyForwarding:true logic. It would remove once that deprecated feature +* would be removed +* +* Example: +* +* { +* "contextElements": [ +* { +* "type": "Room", +* "isPattern": "false", +* "id": "ConferenceRoom", +* "attributes": [ +* { +* "name": "temperature", +* "type": "degree", +* "value": "c23", +* "metadatas": [ +* { +* "name": "ID", +* "type": "integer", +* "value": "3" +* } +* ] +* } +* ] +* } +* ], +* "updateAction": "APPEND" +* } */ -std::string UpdateContextRequest::toJsonV1(bool asJsonObject) +std::string UpdateContextRequest::toJsonV1(void) { - std::string out = ""; - - // - // About JSON commas: - // Both fields are MANDATORY, so, always comma after "entityVector" - // - out += startTag(); - out += entityVector.toJsonV1(asJsonObject, UpdateContext, true); - out += valueTag("updateAction", actionTypeString(V1, updateActionType), false); - out += endTag(false); - - return out; -} + JsonObjectHelper jh; + + JsonVectorHelper jhContextElements; + for (unsigned int ix = 0; ix < entityVector.size(); ++ix) + { + JsonObjectHelper jhEntity; + Entity* eP = entityVector[ix]; + if (eP->entityId.idPattern.empty()) + { + jhEntity.addString("id", eP->entityId.id); + jhEntity.addString("isPattern", "false"); + } + else + { + jhEntity.addString("id", eP->entityId.idPattern); + jhEntity.addString("isPattern", "true"); + } + jhEntity.addString("type", eP->entityId.type); + JsonVectorHelper jhAttributes; + for (unsigned int jx = 0; jx < eP->attributeVector.size(); ++jx) + { + JsonObjectHelper jhAttribute; + ContextAttribute* caP = eP->attributeVector[jx]; -/* **************************************************************************** -* -* UpdateContextRequest::check - -*/ -std::string UpdateContextRequest::check(ApiVersion apiVersion, bool asJsonObject, const std::string& predetectedError) -{ - std::string res; - UpdateContextResponse response; + jhAttribute.addString("name", caP->name); + jhAttribute.addString("type", caP->type); + jhAttribute.addRaw("value", caP->toJsonValue()); - if (!predetectedError.empty()) - { - response.errorCode.fill(SccBadRequest, predetectedError); - return response.toJsonV1(asJsonObject); + if (caP->metadataVector.size() > 0) + { + JsonVectorHelper jhMetadatas; + for (unsigned int kx = 0; kx < caP->metadataVector.size(); ++kx) + { + JsonObjectHelper jhMetadata; + Metadata *mdP = caP->metadataVector[kx]; + + jhMetadata.addString("name", mdP->name); + jhMetadata.addString("type", mdP->type); + jhMetadata.addRaw("value", mdP->toJson()); + + jhMetadatas.addRaw(jhMetadata.str()); + } + jhAttribute.addRaw("metadatas", jhMetadatas.str()); + } + + jhAttributes.addRaw(jhAttribute.str()); + } + jhEntity.addRaw("attributes", jhAttributes.str()); + + jhContextElements.addRaw(jhEntity.str()); } + jh.addRaw("contextElements", jhContextElements.str()); - if ((res = entityVector.check(apiVersion, UpdateContext)) != "OK") + switch (updateActionType) { - response.errorCode.fill(SccBadRequest, res); - return response.toJsonV1(asJsonObject); + case ActionTypeUpdate: + jh.addString("updateAction", "UPDATE"); + break; + case ActionTypeAppend: + jh.addString("updateAction", "APPEND"); + break; + case ActionTypeAppendStrict: + jh.addString("updateAction", "APPEND_STRICT"); + break; + case ActionTypeDelete: + jh.addString("updateAction", "DELETE"); + break; + case ActionTypeReplace: + jh.addString("updateAction", "REPLACE"); + break; + default: + jh.addString("updateAction", "UNKNOWN"); } - return "OK"; + return jh.str(); } @@ -142,49 +208,6 @@ void UpdateContextRequest::release(void) -/* **************************************************************************** -* -* UpdateContextRequest::fill - -*/ -void UpdateContextRequest::fill -( - const UpdateContextElementRequest* ucerP, - const std::string& entityId, - const std::string& entityType -) -{ - Entity* eP = new Entity(entityId, entityType, "false"); - - eP->attributeVector.fill(ucerP->contextAttributeVector); - - entityVector.push_back(eP); - - updateActionType = ActionTypeUpdate; // Coming from an UpdateContextElementRequest (PUT), must be UPDATE -} - - - -/* **************************************************************************** -* -* UpdateContextRequest::fill - -*/ -void UpdateContextRequest::fill -( - const AppendContextElementRequest* acerP, - const std::string& entityId, - const std::string& entityType -) -{ - Entity* eP = new Entity(entityId, entityType, "false"); - - eP->attributeVector.fill(acerP->contextAttributeVector); - - entityVector.push_back(eP); - updateActionType = ActionTypeAppend; // Coming from an AppendContextElementRequest (POST), must be APPEND -} - - - /* **************************************************************************** * * UpdateContextRequest::fill - @@ -192,15 +215,17 @@ void UpdateContextRequest::fill void UpdateContextRequest::fill ( const std::string& entityId, + const std::string& entityIdPattern, const std::string& entityType, - const std::string& isPattern, const std::string& attributeName, ActionType _updateActionType ) { Entity* eP = new Entity(); - eP->fill(entityId, entityType, isPattern); + EntityId enId(entityId, entityIdPattern, entityType, ""); + + eP->fill(enId); entityVector.push_back(eP); updateActionType = _updateActionType; @@ -214,49 +239,13 @@ void UpdateContextRequest::fill -/* **************************************************************************** -* -* UpdateContextRequest::fill - -*/ -void UpdateContextRequest::fill -( - const UpdateContextAttributeRequest* ucarP, - const std::string& entityId, - const std::string& entityType, - const std::string& attributeName, - ActionType _updateActionType -) -{ - Entity* eP = new Entity(entityId, entityType, "false"); - ContextAttribute* caP; - - if (ucarP->compoundValueP != NULL) - { - caP = new ContextAttribute(attributeName, ucarP->type, ucarP->compoundValueP); - } - else - { - caP = new ContextAttribute(attributeName, ucarP->type, ucarP->contextValue); - caP->valueType = ucarP->valueType; - } - - caP->metadataVector.fill((MetadataVector*) &ucarP->metadataVector); - eP->attributeVector.push_back(caP); - - entityVector.push_back(eP); - - updateActionType = _updateActionType; -} - - - /* **************************************************************************** * * UpdateContextRequest::fill - */ void UpdateContextRequest::fill(const Entity* entP, ActionType _updateActionType) { - Entity* eP = new Entity(entP->id, entP->type, "false"); + Entity* eP = new Entity(entP->entityId.id, "", entP->entityId.type, ""); eP->attributeVector.fill(entP->attributeVector); @@ -278,7 +267,7 @@ void UpdateContextRequest::fill const std::string& type ) { - Entity* eP = new Entity(entityId, type, "false"); + Entity* eP = new Entity(entityId, "", type, ""); ContextAttribute* aP = new ContextAttribute(attributeP); eP->attributeVector.push_back(aP); @@ -298,8 +287,8 @@ void UpdateContextRequest::fill */ void UpdateContextRequest::fill ( - Entities* entities, - ActionType _updateActionType + EntityVector* entities, + ActionType _updateActionType ) { updateActionType = _updateActionType; @@ -307,7 +296,7 @@ void UpdateContextRequest::fill for (unsigned int eIx = 0; eIx < entities->vec.size(); ++eIx) { Entity* eP = entities->vec[eIx]; - Entity* neweP = new Entity(eP->id, eP->type, eP->isPattern); + Entity* neweP = new Entity(eP->entityId.id, eP->entityId.idPattern, eP->entityId.type, eP->entityId.typePattern); for (unsigned int aIx = 0; aIx < eP->attributeVector.size(); ++aIx) { @@ -333,7 +322,7 @@ ContextAttribute* UpdateContextRequest::attributeLookup(Entity* eP, const std::s Entity* enP = entityVector[ceIx]; // empty type in request (enP) is always a match - if ((enP->id != eP->id) || ((enP->type != "") && (enP->type != eP->type))) + if ((enP->entityId.id != eP->entityId.id) || ((enP->entityId.type != "") && (enP->entityId.type != eP->entityId.type))) { continue; } diff --git a/src/lib/ngsi10/UpdateContextRequest.h b/src/lib/ngsi10/UpdateContextRequest.h index 2f70914cf5..14d70483c4 100644 --- a/src/lib/ngsi10/UpdateContextRequest.h +++ b/src/lib/ngsi10/UpdateContextRequest.h @@ -31,17 +31,6 @@ #include "apiTypesV2/EntityVector.h" #include "orionTypes/UpdateActionType.h" #include "apiTypesV2/Entity.h" -#include "apiTypesV2/Entities.h" - - - -/* **************************************************************************** -* -* Forward declarations -*/ -struct UpdateContextElementRequest; -struct AppendContextElementRequest; -struct UpdateContextAttributeRequest; @@ -55,45 +44,29 @@ typedef struct UpdateContextRequest ActionType updateActionType; // Mandatory std::string contextProvider; // Not part of the payload - used internally only - ProviderFormat providerFormat; // Not part of the payload - used internally only + bool legacyProviderFormat; // Not part of the payload - used internally only UpdateContextRequest(); - UpdateContextRequest(const std::string& _contextProvider, ProviderFormat _providerFormat, Entity* eP); + UpdateContextRequest(const std::string& _contextProvider, bool _providerFormat, Entity* eP); - std::string toJsonV1(bool asJsonObject); + std::string toJsonV1(void); std::string toJson(void); - std::string check(ApiVersion apiVersion, bool asJsonObject, const std::string& predetectedError); void release(void); ContextAttribute* attributeLookup(Entity* eP, const std::string& attributeName); - - void fill(const UpdateContextElementRequest* ucerP, - const std::string& entityId, - const std::string& entityType); - - void fill(const AppendContextElementRequest* acerP, - const std::string& entityId, - const std::string& entityType); - void fill(const std::string& entityId, + const std::string& entityIdPattern, const std::string& entityType, - const std::string& isPattern, const std::string& attributeName, ActionType _updateActionType); - void fill(const UpdateContextAttributeRequest* ucarP, - const std::string& entityId, - const std::string& entityType, - const std::string& attributeName, - ActionType _updateActionType); - void fill(const Entity* entP, ActionType _updateActionType); void fill(const std::string& entityId, ContextAttribute* attributeP, ActionType _updateActionType, const std::string& type = ""); - void fill(Entities* entities, ActionType _updateActionType); + void fill(EntityVector* entities, ActionType _updateActionType); } UpdateContextRequest; #endif // SRC_LIB_NGSI10_UPDATECONTEXTREQUEST_H_ diff --git a/src/lib/ngsi10/UpdateContextResponse.cpp b/src/lib/ngsi10/UpdateContextResponse.cpp index b7a0c5a4bb..995af4129c 100644 --- a/src/lib/ngsi10/UpdateContextResponse.cpp +++ b/src/lib/ngsi10/UpdateContextResponse.cpp @@ -30,11 +30,10 @@ #include "common/globals.h" #include "common/string.h" -#include "common/tag.h" #include "alarmMgr/alarmMgr.h" #include "ngsi/ContextElementResponse.h" -#include "ngsi/StatusCode.h" +#include "rest/OrionError.h" #include "ngsi10/UpdateContextResponse.h" @@ -45,20 +44,6 @@ */ UpdateContextResponse::UpdateContextResponse() { - errorCode.keyNameSet("errorCode"); -} - - - -/* **************************************************************************** -* -* UpdateContextResponse::UpdateContextResponse - -*/ -UpdateContextResponse::UpdateContextResponse(StatusCode& _errorCode) -{ - errorCode.fill(&_errorCode); - errorCode.keyNameSet("errorCode"); - LM_T(LmtDestructor, ("destroyed")); } @@ -69,79 +54,12 @@ UpdateContextResponse::UpdateContextResponse(StatusCode& _errorCode) */ UpdateContextResponse::~UpdateContextResponse() { - errorCode.release(); contextElementResponseVector.release(); LM_T(LmtDestructor, ("destroyed")); } -/* **************************************************************************** -* -* UpdateContextResponse::toJsonV1 - -*/ -std::string UpdateContextResponse::toJsonV1(bool asJsonObject) -{ - std::string out = ""; - - out += startTag(); - - if ((errorCode.code != SccNone) && (errorCode.code != SccOk)) - { - out += errorCode.toJsonV1(false); - } - else - { - if (contextElementResponseVector.size() == 0) - { - errorCode.fill(SccContextElementNotFound, errorCode.details); - out += errorCode.toJsonV1(false); - } - else - { - out += contextElementResponseVector.toJsonV1(asJsonObject, RtUpdateContextResponse, false, false); - } - } - - out += endTag(); - - return out; -} - - - -/* **************************************************************************** -* -* UpdateContextResponse::check - -*/ -std::string UpdateContextResponse::check -( - ApiVersion apiVersion, - bool asJsonObject, - const std::string& predetectedError -) -{ - std::string res; - - if (!predetectedError.empty()) - { - errorCode.fill(SccBadRequest, predetectedError); - } - else if (contextElementResponseVector.check(apiVersion, UpdateContext, predetectedError, 0) != "OK") - { - alarmMgr.badInput(clientIp, res); - errorCode.fill(SccBadRequest, res); - } - else - { - return "OK"; - } - - return toJsonV1(asJsonObject); -} - - - /* **************************************************************************** * * UpdateContextResponse::release - @@ -150,7 +68,6 @@ void UpdateContextResponse::release(void) { LM_T(LmtRelease, ("In UpdateContextResponse::release")); contextElementResponseVector.release(); - errorCode.release(); } @@ -163,7 +80,7 @@ void UpdateContextResponse::release(void) * 2. If not found: create a new one. * */ -void UpdateContextResponse::notFoundPush(Entity* eP, ContextAttribute* aP, StatusCode* scP) +void UpdateContextResponse::notFoundPush(Entity* eP, ContextAttribute* aP, OrionError* oeP) { ContextElementResponse* cerP = contextElementResponseVector.lookup(eP, SccContextElementNotFound); @@ -171,20 +88,21 @@ void UpdateContextResponse::notFoundPush(Entity* eP, ContextAttribute* aP, Statu { // Build ContextElementResponse cerP = new ContextElementResponse(); - cerP->entity.fill(eP->id, eP->type, eP->isPattern); + EntityId enId(eP->entityId.id, eP->entityId.idPattern, eP->entityId.type, eP->entityId.typePattern); + cerP->entity.fill(enId); if (aP != NULL) { // We copy ContextAttribute given Entity destructor does release() on the vector cerP->entity.attributeVector.push_back(new ContextAttribute(aP)); } - if (scP != NULL) + if (oeP != NULL) { - cerP->statusCode.fill(scP); + cerP->error.fill(oeP); } else { - cerP->statusCode.fill(SccContextElementNotFound, eP->id); + cerP->error.fill(SccContextElementNotFound, eP->entityId.id); } contextElementResponseVector.push_back(cerP); @@ -214,14 +132,15 @@ void UpdateContextResponse::foundPush(Entity* eP, ContextAttribute* aP) { // Build ContextElementResponse cerP = new ContextElementResponse(); - cerP->entity.fill(eP->id, eP->type, eP->isPattern); + EntityId enId(eP->entityId.id, eP->entityId.idPattern, eP->entityId.type, eP->entityId.typePattern); + cerP->entity.fill(enId); if (aP != NULL) { // We copy ContextAttribute given Entity destructor does release() on the vector cerP->entity.attributeVector.push_back(new ContextAttribute(aP)); } - cerP->statusCode.fill(SccOk); + cerP->error.fill(SccOk); contextElementResponseVector.push_back(cerP); } else @@ -239,7 +158,7 @@ void UpdateContextResponse::foundPush(Entity* eP, ContextAttribute* aP) void UpdateContextResponse::fill(UpdateContextResponse* upcrsP) { contextElementResponseVector.fill(upcrsP->contextElementResponseVector); - errorCode.fill(upcrsP->errorCode); + error.fill(upcrsP->error); } @@ -251,8 +170,9 @@ void UpdateContextResponse::fill(UpdateContextRequest* upcrP, HttpStatusCode sc) { contextElementResponseVector.fill(upcrP->entityVector, sc); - // Note that "external" StatusCode is always SccOk, sc is not used here - errorCode.fill(SccOk); + // Note that "external" OrionError is always SccOk, sc is not used here + // FIXME PR: internal error should be avoided. Review this + error.fill(sc, ""); } @@ -270,28 +190,28 @@ void UpdateContextResponse::merge(UpdateContextResponse* upcrsP) if (upcrsP->contextElementResponseVector.size() == 0) { // If no contextElementResponses, copy errorCode if empty - if ((errorCode.code == SccNone) || (errorCode.code == SccOk)) + if ((error.code == SccNone) || (error.code == SccOk)) { - errorCode.fill(upcrsP->errorCode); + error.fill(upcrsP->error); } - else if (errorCode.details.empty()) + else if (error.description.empty()) { - errorCode.details = upcrsP->errorCode.details; + error.description = upcrsP->error.description; } } for (unsigned int cerIx = 0; cerIx < upcrsP->contextElementResponseVector.size(); ++cerIx) { Entity* eP = &upcrsP->contextElementResponseVector[cerIx]->entity; - StatusCode* scP = &upcrsP->contextElementResponseVector[cerIx]->statusCode; + OrionError* oeP = &upcrsP->contextElementResponseVector[cerIx]->error; for (unsigned int aIx = 0; aIx < eP->attributeVector.size(); ++aIx) { ContextAttribute* aP = eP->attributeVector[aIx]; - if (scP->code != SccOk) + if (oeP->code != SccOk) { - notFoundPush(eP, aP, scP); + notFoundPush(eP, aP, oeP); } else { diff --git a/src/lib/ngsi10/UpdateContextResponse.h b/src/lib/ngsi10/UpdateContextResponse.h index 796a853c6d..0ccc2dd55c 100644 --- a/src/lib/ngsi10/UpdateContextResponse.h +++ b/src/lib/ngsi10/UpdateContextResponse.h @@ -29,11 +29,8 @@ #include #include "ngsi/ContextElementResponseVector.h" -#include "ngsi/StatusCode.h" -#include "ngsi10/UpdateContextRequest.h" - #include "rest/OrionError.h" - +#include "ngsi10/UpdateContextRequest.h" /* **************************************************************************** @@ -43,20 +40,15 @@ typedef struct UpdateContextResponse { ContextElementResponseVector contextElementResponseVector; // Optional - StatusCode errorCode; // Optional - - OrionError oe; // Used by NGSIv2 + OrionError error; UpdateContextResponse(); - UpdateContextResponse(StatusCode& _errorCode); ~UpdateContextResponse(); - std::string toJsonV1(bool asJsonObject); - std::string check(ApiVersion apiVersion, bool asJsonObject, const std::string& predetectedError); void release(void); void fill(UpdateContextResponse* upcrsP); void fill(UpdateContextRequest* upcrP, HttpStatusCode sc); // Needed by NGSIv2 forwarding logic - void notFoundPush(Entity* eP, ContextAttribute* aP, StatusCode* scP); + void notFoundPush(Entity* eP, ContextAttribute* aP, OrionError* oeP); void foundPush(Entity* eP, ContextAttribute* aP); void merge(UpdateContextResponse* upcrsP); } UpdateContextResponse; diff --git a/src/lib/ngsi10/UpdateContextSubscriptionRequest.cpp b/src/lib/ngsi10/UpdateContextSubscriptionRequest.cpp deleted file mode 100644 index c888956db3..0000000000 --- a/src/lib/ngsi10/UpdateContextSubscriptionRequest.cpp +++ /dev/null @@ -1,128 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "common/globals.h" -#include "common/tag.h" -#include "ngsi/StatusCode.h" -#include "ngsi10/UpdateContextSubscriptionResponse.h" -#include "ngsi10/UpdateContextSubscriptionRequest.h" -#include "ngsi10/SubscribeContextRequest.h" - -using namespace ngsiv2; - - - -/* **************************************************************************** -* -* UpdateContextSubscriptionRequest::UpdateContextSubscriptionRequest -* -* Explicit constructor needed to initialize primitive types so they don't get -* random values from the stack -*/ -UpdateContextSubscriptionRequest::UpdateContextSubscriptionRequest() -{ - restrictions = 0; -} - - - -/* **************************************************************************** -* -* UpdateContextSubscriptionRequest::check - -*/ -std::string UpdateContextSubscriptionRequest::check(const std::string& predetectedError, int counter) -{ - std::string res; - UpdateContextSubscriptionResponse response; - - if (!predetectedError.empty()) - { - response.subscribeError.subscriptionId = subscriptionId; - response.subscribeError.errorCode.fill(SccBadRequest, predetectedError); - } - else if (((res = duration.check()) != "OK") || - ((res = restriction.check(restrictions)) != "OK") || - ((res = subscriptionId.check()) != "OK") || - ((res = notifyConditionVector.check(UpdateContextSubscription, predetectedError, counter)) != "OK") || - ((res = throttling.check()) != "OK")) - { - response.subscribeError.subscriptionId = subscriptionId; - response.subscribeError.errorCode.fill(SccBadRequest, res); - } - else - return "OK"; - - return response.toJsonV1(); -} - - - -/* **************************************************************************** -* -* UpdateContextSubscriptionRequest::release - -*/ -void UpdateContextSubscriptionRequest::release(void) -{ - // Old versions of this method also include a 'restriction.release()' call. However, now each time - // a UpdateContextSubscriptionRequest is created, the method toNgsiv2Subscription() is used on it and the - // 'ownership' of the Restriction is transferred to the corresponding NGSIv2 class. Thus, leaving - // that 'restriction.release()' would cause double-free problems - - notifyConditionVector.release(); -} - - - -/* **************************************************************************** -* -* UpdateContextSubscriptionRequest::toNgsiv2Subscription - -*/ -void UpdateContextSubscriptionRequest::toNgsiv2Subscription(SubscriptionUpdate* subUp) -{ - // Parent method will do most of the work - SubscribeContextRequest::toNgsiv2Subscription(subUp); - - // Fill remaining fields in SubscriptionUpdate - subUp->id = subscriptionId.get(); - subUp->fromNgsiv1 = true; - - // Fields that can be modified in a NGSIv1 subscription - // (See https://fiware-orion.readthedocs.io/en/master/user/updating_regs_and_subs/index.html) - // - // * notifyConditions (within subject in NGSIv2) - // * throttling (root field in NGSIv2) - // * duration (root field -as 'expires'- in NGSIv2) - // * restriction (already processed in the parent method) - - subUp->subjectProvided = (notifyConditionVector.size() > 0); - subUp->expiresProvided = !duration.isEmpty(); - subUp->statusProvided = false; // not supported in NGSIv1 - subUp->notificationProvided = false; // NGSIv1 doesn's allow changes in that part - subUp->attrsFormatProvided = true; // updating in NGSIv1 involves and implicit change to NGSIv1 legacy format - subUp->throttlingProvided = !throttling.isEmpty(); - -} diff --git a/src/lib/ngsi10/UpdateContextSubscriptionRequest.h b/src/lib/ngsi10/UpdateContextSubscriptionRequest.h deleted file mode 100644 index e96d8e435d..0000000000 --- a/src/lib/ngsi10/UpdateContextSubscriptionRequest.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef SRC_LIB_NGSI10_UPDATECONTEXTSUBSCRIPTIONREQUEST_H_ -#define SRC_LIB_NGSI10_UPDATECONTEXTSUBSCRIPTIONREQUEST_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include - -#include "ngsi/Request.h" -#include "ngsi/EntityId.h" -#include "ngsi/Duration.h" -#include "ngsi/NotifyCondition.h" -#include "ngsi/Restriction.h" -#include "ngsi/SubscriptionId.h" -#include "ngsi/NotifyConditionVector.h" -#include "ngsi/Throttling.h" -#include "ngsi10/SubscribeContextRequest.h" -#include "apiTypesV2/SubscriptionUpdate.h" - - -/* **************************************************************************** -* -* UpdateContextSubscriptionRequest - -*/ -struct UpdateContextSubscriptionRequest : public SubscribeContextRequest -{ - SubscriptionId subscriptionId; // Mandatory - - UpdateContextSubscriptionRequest(); - std::string check(const std::string& predetectedError, int counter); - void release(void); - void toNgsiv2Subscription(ngsiv2::SubscriptionUpdate* subUp); -}; - -#endif // SRC_LIB_NGSI10_UPDATECONTEXTSUBSCRIPTIONREQUEST_H_ diff --git a/src/lib/ngsi10/UpdateContextSubscriptionResponse.cpp b/src/lib/ngsi10/UpdateContextSubscriptionResponse.cpp deleted file mode 100644 index 8acf4835ab..0000000000 --- a/src/lib/ngsi10/UpdateContextSubscriptionResponse.cpp +++ /dev/null @@ -1,84 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include - -#include "logMsg/traceLevels.h" -#include "logMsg/logMsg.h" -#include "common/tag.h" -#include "ngsi/StatusCode.h" -#include "ngsi/SubscribeResponse.h" -#include "ngsi/SubscribeError.h" -#include "ngsi10/UpdateContextSubscriptionResponse.h" - - -/* **************************************************************************** -* -* UpdateContextSubscriptionResponse::UpdateContextSubscriptionResponse - -*/ -UpdateContextSubscriptionResponse::UpdateContextSubscriptionResponse() { - subscribeError.errorCode.keyNameSet("errorCode"); -} - -/* **************************************************************************** -* -* UpdateContextSubscriptionResponse::UpdateContextSubscriptionResponse - -*/ -UpdateContextSubscriptionResponse::UpdateContextSubscriptionResponse(StatusCode& errorCode) { - subscribeError.subscriptionId.set("000000000000000000000000"); - subscribeError.errorCode.fill(&errorCode); - subscribeError.errorCode.keyNameSet("errorCode"); -} - -/* **************************************************************************** -* -* UpdateContextSubscriptionResponse::~UpdateContextSubscriptionResponse - -*/ -UpdateContextSubscriptionResponse::~UpdateContextSubscriptionResponse() { - LM_T(LmtDestructor,("destroyed")); -} - -/* **************************************************************************** -* -* UpdateContextSubscriptionResponse::toJsonV1 - -*/ -std::string UpdateContextSubscriptionResponse::toJsonV1(void) -{ - std::string out = ""; - - out += startTag(); - - if (subscribeError.errorCode.code == SccNone) - { - out += subscribeResponse.toJsonV1(false); - } - else - { - out += subscribeError.toJsonV1(UpdateContextSubscription, false); - } - - out += endTag(); - - return out; -} diff --git a/src/lib/ngsi10/UpdateContextSubscriptionResponse.h b/src/lib/ngsi10/UpdateContextSubscriptionResponse.h deleted file mode 100644 index 2a01fc4379..0000000000 --- a/src/lib/ngsi10/UpdateContextSubscriptionResponse.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef SRC_LIB_NGSI10_UPDATECONTEXTSUBSCRIPTIONRESPONSE_H_ -#define SRC_LIB_NGSI10_UPDATECONTEXTSUBSCRIPTIONRESPONSE_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include - -#include "ngsi/SubscribeResponse.h" -#include "ngsi/SubscribeError.h" -#include "ngsi/StatusCode.h" - - - -/* **************************************************************************** -* -* UpdateContextSubscriptionResponse - -*/ -typedef struct UpdateContextSubscriptionResponse -{ - SubscribeResponse subscribeResponse; // Optional - but one of the two MUST be present! - SubscribeError subscribeError; // Optional - but one of the two MUST be present! - - UpdateContextSubscriptionResponse(); - UpdateContextSubscriptionResponse(StatusCode& errorCode); - ~UpdateContextSubscriptionResponse(); - - std::string toJsonV1(void); -} UpdateContextSubscriptionResponse; - -#endif // SRC_LIB_NGSI10_UPDATECONTEXTSUBSCRIPTIONRESPONSE_H_ diff --git a/src/lib/ngsi9/CMakeLists.txt b/src/lib/ngsi9/CMakeLists.txt deleted file mode 100644 index 3d1d676c15..0000000000 --- a/src/lib/ngsi9/CMakeLists.txt +++ /dev/null @@ -1,46 +0,0 @@ -# Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -# -# This file is part of Orion Context Broker. -# -# Orion Context Broker is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Orion Context Broker is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -# General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -# -# For those usages not covered by this license please contact with -# iot_support at tid dot es - -CMAKE_MINIMUM_REQUIRED(VERSION 3.0) - -SET (SOURCES - RegisterContextRequest.cpp - RegisterContextResponse.cpp - DiscoverContextAvailabilityRequest.cpp - DiscoverContextAvailabilityResponse.cpp -) - -SET (HEADERS - DiscoverContextAvailabilityRequest.h - DiscoverContextAvailabilityResponse.h - RegisterContextRequest.h - RegisterContextResponse.h -) - - - -# Include directories -# ----------------------------------------------------------------- -include_directories("${PROJECT_SOURCE_DIR}/src/lib") - - -# Library declaration -# ----------------------------------------------------------------- -ADD_LIBRARY(ngsi9 STATIC ${SOURCES} ${HEADERS}) diff --git a/src/lib/ngsi9/DiscoverContextAvailabilityRequest.cpp b/src/lib/ngsi9/DiscoverContextAvailabilityRequest.cpp deleted file mode 100644 index 699e0807e3..0000000000 --- a/src/lib/ngsi9/DiscoverContextAvailabilityRequest.cpp +++ /dev/null @@ -1,158 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include - -#include "logMsg/logMsg.h" - -#include "ngsi/StatusCode.h" -#include "ngsi/Request.h" -#include "ngsi/EntityIdVector.h" -#include "ngsi/StringList.h" -#include "ngsi/Restriction.h" -#include "ngsi9/DiscoverContextAvailabilityRequest.h" -#include "ngsi9/DiscoverContextAvailabilityResponse.h" - -/* **************************************************************************** -* -* DiscoverContextAvailabilityRequest::DiscoverContextAvailabilityRequest -* -* Explicit constructor needed to initialize primitive types so they don't get -* random values from the stack -*/ -DiscoverContextAvailabilityRequest::DiscoverContextAvailabilityRequest() -{ - restrictions = 0; -} - -/* **************************************************************************** -* -* DiscoverContextAvailabilityRequest::release - -*/ -void DiscoverContextAvailabilityRequest::release(void) -{ - entityIdVector.release(); - attributeList.release(); - restriction.release(); -} - - - -/* **************************************************************************** -* -* DiscoverContextAvailabilityRequest::check - -*/ -std::string DiscoverContextAvailabilityRequest::check(const std::string& predetectedError) -{ - DiscoverContextAvailabilityResponse response; - std::string res; - - if (!predetectedError.empty()) - { - response.errorCode.fill(SccBadRequest, predetectedError); - } - else if (entityIdVector.size() == 0) - { - response.errorCode.fill(SccContextElementNotFound); - } - else if (((res = entityIdVector.check(DiscoverContextAvailability)) != "OK") || - ((res = attributeList.check()) != "OK") || - ((restrictions != 0) && ((res = restriction.check(restrictions)) != "OK"))) - { - response.errorCode.fill(SccBadRequest, res); - } - else - return "OK"; - - return response.toJsonV1(); -} - - - -/* **************************************************************************** -* -* DiscoverContextAvailabilityRequest::fill - -*/ -void DiscoverContextAvailabilityRequest::fill -( - EntityId& eid, - const std::vector& attributeV, - const Restriction& restriction -) -{ - entityIdVector.push_back(&eid); - - for (unsigned int ix = 0; ix < attributeV.size(); ++ix) - { - attributeList.push_back(attributeV[ix]); - } - - // FIXME P9: restriction with scope-vector must be copied to this->restriction -} - - - -/* **************************************************************************** -* -* DiscoverContextAvailabilityRequest::fill - -*/ -void DiscoverContextAvailabilityRequest::fill(const std::string& entityId, const std::string& entityType) -{ - EntityId* eidP = new EntityId(entityId, entityType, "false"); - - entityIdVector.push_back(eidP); -} - - - -/* **************************************************************************** -* -* DiscoverContextAvailabilityRequest::fill - -*/ -void DiscoverContextAvailabilityRequest::fill -( - const std::string& entityId, - const std::string& entityType, - EntityTypeInfo typeInfo, - const std::string& attributeName -) -{ - EntityId* eidP = new EntityId(entityId, entityType, "false"); - - entityIdVector.push_back(eidP); - - if ((typeInfo == EntityTypeEmpty) || (typeInfo == EntityTypeNotEmpty)) - { - Scope* scopeP = new Scope(SCOPE_FILTER_EXISTENCE, SCOPE_VALUE_ENTITY_TYPE); - - scopeP->oper = (typeInfo == EntityTypeEmpty)? SCOPE_OPERATOR_NOT : ""; - - restriction.scopeVector.push_back(scopeP); - } - - if (!attributeName.empty()) - { - attributeList.push_back(attributeName); - } -} diff --git a/src/lib/ngsi9/DiscoverContextAvailabilityRequest.h b/src/lib/ngsi9/DiscoverContextAvailabilityRequest.h deleted file mode 100644 index 211e975a6a..0000000000 --- a/src/lib/ngsi9/DiscoverContextAvailabilityRequest.h +++ /dev/null @@ -1,70 +0,0 @@ -#ifndef SRC_LIB_NGSI9_DISCOVERCONTEXTAVAILABILITYREQUEST_H_ -#define SRC_LIB_NGSI9_DISCOVERCONTEXTAVAILABILITYREQUEST_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include - -#include "ngsi/Request.h" -#include "ngsi/EntityIdVector.h" -#include "ngsi/StringList.h" -#include "ngsi/Restriction.h" -#include "rest/EntityTypeInfo.h" - - - -/* **************************************************************************** -* -* DiscoverContextAvailabilityRequest - -*/ -typedef struct DiscoverContextAvailabilityRequest -{ - EntityIdVector entityIdVector; // Mandatory - StringList attributeList; // Optional - Restriction restriction; // Optional - - int restrictions; // Auxiliar - the parameter for check should be removed - - DiscoverContextAvailabilityRequest(); - - void release(void); - - std::string check(const std::string& predetectedError); - - void fill(EntityId& eid, - const std::vector& attributeV, - const Restriction& restriction); - - void fill(const std::string& entityId, - const std::string& entityType); - - void fill(const std::string& entityId, - const std::string& entityType, - EntityTypeInfo typeInfo, - const std::string& attributeName); - -} DiscoverContextAvailabilityRequest; - -#endif // SRC_LIB_NGSI9_DISCOVERCONTEXTAVAILABILITYREQUEST_H_ diff --git a/src/lib/ngsi9/DiscoverContextAvailabilityResponse.cpp b/src/lib/ngsi9/DiscoverContextAvailabilityResponse.cpp deleted file mode 100644 index 30a8fbd61a..0000000000 --- a/src/lib/ngsi9/DiscoverContextAvailabilityResponse.cpp +++ /dev/null @@ -1,118 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/traceLevels.h" -#include "logMsg/logMsg.h" -#include "common/globals.h" -#include "common/string.h" -#include "common/tag.h" -#include "ngsi9/DiscoverContextAvailabilityResponse.h" - - - -/* **************************************************************************** -* -* DiscoverContextAvailabilityResponse::DiscoverContextAvailabilityResponse - -*/ -DiscoverContextAvailabilityResponse::DiscoverContextAvailabilityResponse() -{ - errorCode.keyNameSet("errorCode"); -} - -/* **************************************************************************** -* -* DiscoverContextAvailabilityResponse::~DiscoverContextAvailabilityResponse - -*/ -DiscoverContextAvailabilityResponse::~DiscoverContextAvailabilityResponse() -{ - responseVector.release(); - errorCode.release(); -} - - -/* **************************************************************************** -* -* DiscoverContextAvailabilityResponse::DiscoverContextAvailabilityResponse - -*/ -DiscoverContextAvailabilityResponse::DiscoverContextAvailabilityResponse(StatusCode& _errorCode) -{ - errorCode.fill(&_errorCode); - errorCode.keyNameSet("errorCode"); -} - - - -/* **************************************************************************** -* -* DiscoverContextAvailabilityResponse::toJsonV1 - -*/ -std::string DiscoverContextAvailabilityResponse::toJsonV1(void) -{ - std::string out = ""; - - // - // JSON commas: - // Exactly ONE of responseVector|errorCode is included in the discovery response so, - // no JSON commas necessary - // - out += startTag(); - - if (responseVector.size() > 0) - { - bool commaNeeded = (errorCode.code != SccNone); - out += responseVector.toJsonV1(commaNeeded); - } - - if (errorCode.code != SccNone) - { - out += errorCode.toJsonV1(false); - } - - /* Safety check: neither errorCode nor CER vector was filled by mongoBackend */ - if (errorCode.code == SccNone && responseVector.size() == 0) - { - errorCode.fill(SccReceiverInternalError, "Both the error-code structure and the response vector were empty"); - out += errorCode.toJsonV1(false); - } - - out += endTag(); - - return out; -} - - - -/* **************************************************************************** -* -* DiscoverContextAvailabilityResponse::release - -*/ -void DiscoverContextAvailabilityResponse::release(void) -{ - responseVector.release(); - errorCode.release(); - errorCode.keyNameSet("errorCode"); -} diff --git a/src/lib/ngsi9/DiscoverContextAvailabilityResponse.h b/src/lib/ngsi9/DiscoverContextAvailabilityResponse.h deleted file mode 100644 index c8e86c4f5b..0000000000 --- a/src/lib/ngsi9/DiscoverContextAvailabilityResponse.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef SRC_LIB_NGSI9_DISCOVERCONTEXTAVAILABILITYRESPONSE_H_ -#define SRC_LIB_NGSI9_DISCOVERCONTEXTAVAILABILITYRESPONSE_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include -#include - -#include "ngsi/ContextRegistrationResponseVector.h" -#include "ngsi/StatusCode.h" - - - -/* **************************************************************************** -* -* DiscoverContextAvailabilityResponse - -*/ -typedef struct DiscoverContextAvailabilityResponse -{ - ContextRegistrationResponseVector responseVector; // Optional - StatusCode errorCode; // Optional - - DiscoverContextAvailabilityResponse(); - ~DiscoverContextAvailabilityResponse(); - DiscoverContextAvailabilityResponse(StatusCode& _errorCode); - - std::string toJsonV1(void); - void release(void); -} DiscoverContextAvailabilityResponse; - -#endif // SRC_LIB_NGSI9_DISCOVERCONTEXTAVAILABILITYRESPONSE_H_ diff --git a/src/lib/ngsi9/RegisterContextRequest.cpp b/src/lib/ngsi9/RegisterContextRequest.cpp deleted file mode 100644 index c0e533b25b..0000000000 --- a/src/lib/ngsi9/RegisterContextRequest.cpp +++ /dev/null @@ -1,141 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/globals.h" -#include "common/tag.h" -#include "alarmMgr/alarmMgr.h" -#include "ngsi/StatusCode.h" -#include "ngsi/Duration.h" -#include "ngsi/ContextRegistrationVector.h" -#include "ngsi9/RegisterContextResponse.h" -#include "ngsi9/RegisterContextRequest.h" - - - -/* **************************************************************************** -* -* RegisterContextRequest::toJsonV1 - -*/ -std::string RegisterContextRequest::toJsonV1(void) -{ - std::string out = ""; - bool durationRendered = !duration.get().empty(); - bool registrationIdRendered = !registrationId.get().empty(); - bool commaAfterRegistrationId = false; // Last element - bool commaAfterDuration = registrationIdRendered; - bool commaAfterContextRegistrationVector = registrationIdRendered || durationRendered; - - out += startTag(); - - out += contextRegistrationVector.toJsonV1( commaAfterContextRegistrationVector); - out += duration.toJsonV1( commaAfterDuration); - out += registrationId.toJsonV1(RegisterContext, commaAfterRegistrationId); - - out += endTag(false); - - return out; -} - - - -/* **************************************************************************** -* -* RegisterContextRequest::check - -*/ -std::string RegisterContextRequest::check(ApiVersion apiVersion, const std::string& predetectedError, int counter) -{ - RegisterContextResponse response(this); - std::string res; - - if (!predetectedError.empty()) - { - alarmMgr.badInput(clientIp, predetectedError); - response.errorCode.fill(SccBadRequest, predetectedError); - } - else if (contextRegistrationVector.size() == 0) - { - alarmMgr.badInput(clientIp, "empty contextRegistration list"); - response.errorCode.fill(SccBadRequest, "Empty Context Registration List"); - } - else if (((res = contextRegistrationVector.check(apiVersion, RegisterContext, predetectedError, counter)) != "OK") || - ((res = duration.check()) != "OK") || - ((res = registrationId.check()) != "OK")) - { - alarmMgr.badInput(clientIp, res); - response.errorCode.fill(SccBadRequest, res); - } - else - { - return "OK"; - } - - return response.toJsonV1(); -} - - - -/* **************************************************************************** -* -* RegisterContextRequest::release - -*/ -void RegisterContextRequest::release(void) -{ - contextRegistrationVector.release(); - duration.release(); - registrationId.release(); -} - - - -/* **************************************************************************** -* -* RegisterContextRequest::fill - -*/ -void RegisterContextRequest::fill(RegisterProviderRequest& rpr, const std::string& entityId, const std::string& entityType, const std::string& attributeName) -{ - ContextRegistration* crP = new ContextRegistration(); - EntityId* entityIdP = new EntityId(entityId, entityType, "false"); - - duration = rpr.duration; - registrationId = rpr.registrationId; - - crP->providingApplication = rpr.providingApplication; - - crP->entityIdVector.push_back(entityIdP); - crP->entityIdVectorPresent = true; - - if (!attributeName.empty()) - { - ContextRegistrationAttribute* attributeP = new ContextRegistrationAttribute(attributeName, ""); - - crP->contextRegistrationAttributeVector.push_back(attributeP); - } - - contextRegistrationVector.push_back(crP); -} diff --git a/src/lib/ngsi9/RegisterContextRequest.h b/src/lib/ngsi9/RegisterContextRequest.h deleted file mode 100644 index 9879d4a952..0000000000 --- a/src/lib/ngsi9/RegisterContextRequest.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef SRC_LIB_NGSI9_REGISTERCONTEXTREQUEST_H_ -#define SRC_LIB_NGSI9_REGISTERCONTEXTREQUEST_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "convenience/RegisterProviderRequest.h" -#include "ngsi/ContextRegistrationVector.h" -#include "ngsi/Duration.h" -#include "ngsi/RegistrationId.h" - - - -/* **************************************************************************** -* -* RegisterContextRequest - -*/ -typedef struct RegisterContextRequest -{ - ContextRegistrationVector contextRegistrationVector; // Mandatory - Duration duration; // Optional - RegistrationId registrationId; // Optional - - std::string servicePath; // Not part of payload, just an internal field - - std::string toJsonV1(void); - std::string check(ApiVersion apiVersion, const std::string& predetectedError, int counter); - void release(void); - void fill(RegisterProviderRequest& rpr, const std::string& entityId, const std::string& entityType, const std::string& attributeName); -} RegisterContextRequest; - -#endif // SRC_LIB_NGSI9_REGISTERCONTEXTREQUEST_H_ diff --git a/src/lib/ngsi9/RegisterContextResponse.cpp b/src/lib/ngsi9/RegisterContextResponse.cpp deleted file mode 100644 index 34281467ee..0000000000 --- a/src/lib/ngsi9/RegisterContextResponse.cpp +++ /dev/null @@ -1,163 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include - -#include "logMsg/traceLevels.h" -#include "logMsg/logMsg.h" -#include "common/globals.h" -#include "common/tag.h" -#include "ngsi/StatusCode.h" -#include "ngsi/StatusCode.h" -#include "ngsi9/RegisterContextRequest.h" -#include "ngsi9/RegisterContextResponse.h" - - - -/* **************************************************************************** -* -* RegisterContextResponse::RegisterContextResponse - -*/ -RegisterContextResponse::RegisterContextResponse() -{ - registrationId.set(""); - duration.set(""); - errorCode.keyNameSet("errorCode"); -} - -/* **************************************************************************** -* -* RegisterContextResponse::~RegisterContextResponse - -*/ -RegisterContextResponse::~RegisterContextResponse() -{ - LM_T(LmtDestructor,("destroyed")); -} - - -/* **************************************************************************** -* -* RegisterContextResponse::RegisterContextResponse - -*/ -RegisterContextResponse::RegisterContextResponse(RegisterContextRequest* rcrP) -{ - registrationId.set(rcrP->registrationId.get()); - duration.set(rcrP->duration.get()); - errorCode.keyNameSet("errorCode"); -} - - - -/* **************************************************************************** -* -* RegisterContextResponse::RegisterContextResponse - -*/ -RegisterContextResponse::RegisterContextResponse(const std::string& _registrationId, const std::string& _duration) -{ - registrationId.set(_registrationId); - duration.set(_duration); - errorCode.keyNameSet("errorCode"); -} - - - -/* **************************************************************************** -* -* RegisterContextResponse::RegisterContextResponse - -*/ -RegisterContextResponse::RegisterContextResponse(const std::string& _registrationId, StatusCode& _errorCode) -{ - registrationId.set(_registrationId); - errorCode = _errorCode; - errorCode.keyNameSet("errorCode"); -} - - - -/* **************************************************************************** -* -* RegisterContextResponse::toJsonV1 - -*/ -std::string RegisterContextResponse::toJsonV1(void) -{ - std::string out = ""; - bool errorCodeRendered = (errorCode.code != SccNone) && (errorCode.code != SccOk); - - out += startTag(); - - if (!errorCodeRendered) - { - out += duration.toJsonV1(true); - } - - out += registrationId.toJsonV1(RegisterResponse, errorCodeRendered); - - if (errorCodeRendered) - { - out += errorCode.toJsonV1(false); - } - - out += endTag(); - - return out; -} - - - -/* **************************************************************************** -* -* RegisterContextResponse::check - -*/ -std::string RegisterContextResponse::check(const std::string& predetectedError) -{ - RegisterContextResponse response; - std::string res; - - if (!predetectedError.empty()) - { - response.errorCode.fill(SccBadRequest, predetectedError); - } - else if (((res = duration.check()) != "OK") || - ((res = registrationId.check()) != "OK")) - { - response.errorCode.fill(SccBadRequest, res); - } - else - return "OK"; - - return response.toJsonV1(); -} - - - -/* **************************************************************************** -* -* release - -*/ -void RegisterContextResponse::release(void) -{ - duration.release(); - registrationId.release(); - errorCode.release(); -} diff --git a/src/lib/ngsi9/RegisterContextResponse.h b/src/lib/ngsi9/RegisterContextResponse.h deleted file mode 100644 index 15c7134d6e..0000000000 --- a/src/lib/ngsi9/RegisterContextResponse.h +++ /dev/null @@ -1,58 +0,0 @@ -#ifndef SRC_LIB_NGSI9_REGISTERCONTEXTRESPONSE_H_ -#define SRC_LIB_NGSI9_REGISTERCONTEXTRESPONSE_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include - -#include "ngsi/StatusCode.h" -#include "ngsi/RegistrationId.h" -#include "ngsi/Duration.h" -#include "ngsi9/RegisterContextRequest.h" - - - -/* **************************************************************************** -* -* RegisterContextResponse - -*/ -typedef struct RegisterContextResponse -{ - Duration duration; // Optional - RegistrationId registrationId; // Mandatory - StatusCode errorCode; // Optional - - RegisterContextResponse(); - ~RegisterContextResponse(); - RegisterContextResponse(RegisterContextRequest* rcrP); - RegisterContextResponse(const std::string& _registrationId, const std::string& _duration); - RegisterContextResponse(const std::string& _registrationId, StatusCode& _errorCode); - - std::string toJsonV1(void); - std::string check(const std::string& predetectedError); - void release(void); -} RegisterContextResponse; - -#endif // SRC_LIB_NGSI9_REGISTERCONTEXTRESPONSE_H_ diff --git a/src/lib/ngsiNotify/CMakeLists.txt b/src/lib/ngsiNotify/CMakeLists.txt index 704fd86b4e..706d9bee25 100644 --- a/src/lib/ngsiNotify/CMakeLists.txt +++ b/src/lib/ngsiNotify/CMakeLists.txt @@ -24,7 +24,6 @@ SET (SOURCES doNotify.cpp Notifier.cpp senderThread.cpp - ContextSubscriptionInfo.cpp QueueWorkers.cpp ServiceQueue.cpp QueueNotifier.cpp @@ -33,7 +32,6 @@ SET (SOURCES SET (HEADERS doNotify.h - ContextSubscriptionInfo.h Notifier.h senderThread.h QueueWorkers.h diff --git a/src/lib/ngsiNotify/ContextSubscriptionInfo.cpp b/src/lib/ngsiNotify/ContextSubscriptionInfo.cpp deleted file mode 100644 index 3c49619f27..0000000000 --- a/src/lib/ngsiNotify/ContextSubscriptionInfo.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Fermin Galan -*/ - -#include "ContextSubscriptionInfo.h" - -/* **************************************************************************** -* -* ContextSubscriptionInfo::release - -*/ -void ContextSubscriptionInfo::release(void) { - - this->entityIdVector.release(); - this->attributeList.release(); -} diff --git a/src/lib/ngsiNotify/ContextSubscriptionInfo.h b/src/lib/ngsiNotify/ContextSubscriptionInfo.h deleted file mode 100644 index 067cc21c60..0000000000 --- a/src/lib/ngsiNotify/ContextSubscriptionInfo.h +++ /dev/null @@ -1,51 +0,0 @@ -#ifndef SRC_LIB_NGSINOTIFY_CONTEXTSUBSCRIPTIONINFO_H_ -#define SRC_LIB_NGSINOTIFY_CONTEXTSUBSCRIPTIONINFO_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Fermin Galan -*/ -#include "common/MimeType.h" -#include "ngsi/EntityIdVector.h" -#include "ngsi/StringList.h" - - - -/* **************************************************************************** -* -* ContextSubscriptionInfo - -*/ -typedef struct ContextSubscriptionInfo -{ - EntityIdVector entityIdVector; - StringList attributeList; - std::string url; - MimeType mimeType; - int lastNotification; - long long expiration; - long long throttling; - - void release(void); -} ContextSubscriptionInfo; - -#endif // SRC_LIB_NGSINOTIFY_CONTEXTSUBSCRIPTIONINFO_H_ diff --git a/src/lib/ngsiNotify/Notifier.cpp b/src/lib/ngsiNotify/Notifier.cpp index 490eb88e20..1c3f251c6a 100644 --- a/src/lib/ngsiNotify/Notifier.cpp +++ b/src/lib/ngsiNotify/Notifier.cpp @@ -119,7 +119,7 @@ static bool setPayload ( bool includePayload, const std::string& notifPayload, - const SubscriptionId& subscriptionId, + const std::string& subscriptionId, Entity& en, ExprContextObject* exprContextObjectP, const std::vector& attrsFilter, @@ -140,13 +140,15 @@ static bool setPayload NotifyContextRequest ncr; ContextElementResponse cer; - cer.entity.fill(en.id, en.type, en.isPattern, en.servicePath); + EntityId enId(en.entityId.id, en.entityId.idPattern, en.entityId.type, en.entityId.typePattern); + + cer.entity.fill(enId, en.servicePath); // cloneCompount set to true. Otherwise nasty things as the one // described in issue #4263 will happend cer.entity.attributeVector.push_back(en.attributeVector, true); - cer.statusCode.code = SccOk; + cer.error.code = SccOk; ncr.subscriptionId = subscriptionId; ncr.contextElementResponseVector.push_back(&cer); @@ -247,7 +249,7 @@ static void orderByPriority static bool setNgsiPayload ( const Entity& ngsi, - const SubscriptionId& subscriptionId, + const std::string& subscriptionId, Entity& en, ExprContextObject* exprContextObjectP, const std::vector& attrsFilter, @@ -262,28 +264,29 @@ static bool setNgsiPayload ContextElementResponse cer; std::string effectiveId; - if (ngsi.id.empty()) + if (ngsi.entityId.id.empty()) { - effectiveId = en.id; + effectiveId = en.entityId.id; } else { // If id is not found in the replacements macro, we use en.id. - effectiveId = removeQuotes(smartStringValue(ngsi.id, exprContextObjectP, '"' + en.id + '"')); + effectiveId = removeQuotes(smartStringValue(ngsi.entityId.id, exprContextObjectP, '"' + en.entityId.id + '"')); } std::string effectiveType; - if (ngsi.type.empty()) + if (ngsi.entityId.type.empty()) { - effectiveType = en.type; + effectiveType = en.entityId.type; } else { // If type is not found in the replacements macro, we use en.type. - effectiveType = removeQuotes(smartStringValue(ngsi.type, exprContextObjectP, '"' + en.type + '"')); + effectiveType = removeQuotes(smartStringValue(ngsi.entityId.type, exprContextObjectP, '"' + en.entityId.type + '"')); } - cer.entity.fill(effectiveId, effectiveType, en.isPattern, en.servicePath); + EntityId entId(effectiveId, "", effectiveType, ""); + cer.entity.fill(entId, en.servicePath); // First we add attributes in the ngsi field, adding calculated expressions to context in order of priority std::vector orderedNgsiAttrs; @@ -310,7 +313,7 @@ static bool setNgsiPayload } } - cer.statusCode.code = SccOk; + cer.error.code = SccOk; ncr.subscriptionId = subscriptionId; ncr.contextElementResponseVector.push_back(&cer); @@ -335,7 +338,7 @@ static bool setNgsiPayload */ static SenderThreadParams* buildSenderParamsCustom ( - const SubscriptionId& subscriptionId, + const std::string& subscriptionId, ContextElementResponse* notifyCerP, const ngsiv2::Notification& notification, const std::string& tenant, @@ -375,8 +378,8 @@ static SenderThreadParams* buildSenderParamsCustom // into account that in the case of an attribute with name "service", "servicePath" or "authToken", it must have precedence // over the ones comming from headers of the same name, we conditionally add them depending the case TIME_EXPR_CTXBLD_START(); - exprContext.add("id", en.id); - exprContext.add("type", en.type); + exprContext.add("id", en.entityId.id); + exprContext.add("type", en.entityId.type); if (!basic) { @@ -603,7 +606,7 @@ static SenderThreadParams* buildSenderParamsCustom paramsP->renderFormat = renderFormatToString(renderFormat); paramsP->extraHeaders = headers; paramsP->registration = false; - paramsP->subscriptionId = subscriptionId.get(); + paramsP->subscriptionId = subscriptionId; paramsP->qos = notification.mqttInfo.qos; // unspecified in case of HTTP notifications paramsP->retain = notification.mqttInfo.retain; // unspecified in case of HTTP notifications paramsP->timeout = notification.httpInfo.timeout; // unspecified in case of MQTT notifications @@ -713,16 +716,12 @@ SenderThreadParams* Notifier::buildSenderParams /* Note we use cloneCompound=true in cer.entity.fill(). This is due to * cer.entity destructor does release() on the attrs vector */ cer.entity.fill(notifyCerP->entity, false, true); - cer.statusCode.fill(SccOk); + cer.error.fill(SccOk); ncr.contextElementResponseVector.push_back(&cer); /* Complete the fields in NotifyContextRequest */ - ncr.subscriptionId.set(subId); - // FIXME: we use a proper origin name - ncr.originator.set("localhost"); - - ncr.subscriptionId.set(subId); + ncr.subscriptionId = subId; // // Creating the value of the Fiware-ServicePath HTTP header. @@ -777,7 +776,7 @@ SenderThreadParams* Notifier::buildSenderParams paramsP->content = payloadString; paramsP->mimeType = JSON; paramsP->renderFormat = renderFormatToString(renderFormat); - paramsP->subscriptionId = ncr.subscriptionId.get(); + paramsP->subscriptionId = ncr.subscriptionId; paramsP->registration = false; paramsP->qos = notification.mqttInfo.qos; // unspecified in case of HTTP notifications paramsP->retain = notification.mqttInfo.retain; // unspecified in case of HTTP notifications diff --git a/src/lib/orionTypes/EntityType.cpp b/src/lib/orionTypes/EntityType.cpp index 73698cec12..ade483befc 100755 --- a/src/lib/orionTypes/EntityType.cpp +++ b/src/lib/orionTypes/EntityType.cpp @@ -29,7 +29,6 @@ #include "logMsg/traceLevels.h" #include "logMsg/logMsg.h" -#include "common/tag.h" #include "common/limits.h" #include "common/JsonHelper.h" #include "ngsi/Request.h" @@ -58,77 +57,6 @@ EntityType::EntityType(std::string _type): type(_type), count(0) } -/* **************************************************************************** -* -* EntityType::toJsonV1 - -* -* This method is used by: -* o EntityTypeVector -* o EntityTypeResponse -* -* 'typeNameBefore' is set to TRUE when called from EntityTypeResponse -*/ -std::string EntityType::toJsonV1 -( - bool asJsonObject, - bool asJsonOut, - bool collapsed, - bool comma, - bool typeNameBefore -) -{ - std::string out = ""; - - // No metadata filter in this case, an empty vector is used to fulfil method signature. - // For attribute filter, we use the ContextAttributeVector itself - std::vector emptyMdV; - - if (typeNameBefore && asJsonOut) - { - out += valueTag("name", type, true); - out += contextAttributeVector.toJsonV1(asJsonObject, EntityTypes, contextAttributeVector.vec, emptyMdV, true, true, true); - } - else - { - out += startTag(); - - if (collapsed || contextAttributeVector.size() == 0) - { - out += valueTag("name", type, false); - } - else - { - out += valueTag("name", type, true); - out += contextAttributeVector.toJsonV1(asJsonObject, EntityTypes, contextAttributeVector.vec, emptyMdV, false, true, true); - } - - out += endTag(comma, false); - } - - return out; -} - - - -/* **************************************************************************** -* -* EntityType::check - -*/ -std::string EntityType::check(ApiVersion apiVersion, const std::string& predetectedError) -{ - if (!predetectedError.empty()) - { - return predetectedError; - } - else if (type.empty()) - { - return "Empty Type"; - } - - return contextAttributeVector.check(apiVersion, EntityTypes); -} - - /* **************************************************************************** * diff --git a/src/lib/orionTypes/EntityType.h b/src/lib/orionTypes/EntityType.h index b2ed1da00f..6ffad0c24c 100644 --- a/src/lib/orionTypes/EntityType.h +++ b/src/lib/orionTypes/EntityType.h @@ -45,12 +45,6 @@ class EntityType EntityType(); explicit EntityType(std::string _type); - std::string check(ApiVersion apiVersion, const std::string& predetectedError); - std::string toJsonV1(bool asJsonObject, - bool asJsonOut, - bool collapsed, - bool comma = false, - bool typeNameBefore = false); void release(void); std::string toJson(bool includeType = false); }; diff --git a/src/lib/orionTypes/EntityTypeResponse.cpp b/src/lib/orionTypes/EntityTypeResponse.cpp index 8e8a2ac800..a56988eaf0 100755 --- a/src/lib/orionTypes/EntityTypeResponse.cpp +++ b/src/lib/orionTypes/EntityTypeResponse.cpp @@ -30,7 +30,6 @@ #include "logMsg/logMsg.h" #include "common/globals.h" -#include "common/tag.h" #include "common/limits.h" #include "common/JsonHelper.h" #include "alarmMgr/alarmMgr.h" @@ -40,63 +39,6 @@ -/* **************************************************************************** -* -* EntityTypeResponse::toJsonV1 - -*/ -std::string EntityTypeResponse::toJsonV1 -( - bool asJsonObject, - bool asJsonOut, - bool collapsed -) -{ - std::string out = ""; - - out += startTag(); - - out += entityType.toJsonV1(asJsonObject, asJsonOut, collapsed, true, true); - out += statusCode.toJsonV1(false); - - out += endTag(); - - return out; -} - - - -/* **************************************************************************** -* -* EntityTypeResponse::check - -*/ -std::string EntityTypeResponse::check -( - ApiVersion apiVersion, - bool asJsonObject, - bool asJsonOut, - bool collapsed, - const std::string& predetectedError -) -{ - std::string res; - - if (!predetectedError.empty()) - { - statusCode.fill(SccBadRequest, predetectedError); - } - else if ((res = entityType.check(apiVersion, predetectedError)) != "OK") - { - alarmMgr.badInput(clientIp, res); - statusCode.fill(SccBadRequest, res); - } - else - return "OK"; - - return toJsonV1(asJsonObject, asJsonOut, collapsed); -} - - - /* **************************************************************************** * * EntityTypeResponse::release - @@ -104,7 +46,6 @@ std::string EntityTypeResponse::check void EntityTypeResponse::release(void) { entityType.release(); - statusCode.release(); } diff --git a/src/lib/orionTypes/EntityTypeResponse.h b/src/lib/orionTypes/EntityTypeResponse.h index 5b53cde387..645c11587b 100644 --- a/src/lib/orionTypes/EntityTypeResponse.h +++ b/src/lib/orionTypes/EntityTypeResponse.h @@ -29,7 +29,7 @@ #include #include "ngsi/Request.h" -#include "ngsi/StatusCode.h" +#include "rest/OrionError.h" #include "orionTypes/EntityType.h" @@ -42,17 +42,9 @@ class EntityTypeResponse { public: EntityType entityType; - StatusCode statusCode; + OrionError error; - std::string toJsonV1(bool asJsonObject, - bool asJsonOut, - bool collapsed); std::string toJson(void); - std::string check(ApiVersion apiVersion, - bool asJsonObject, - bool asJsonOut, - bool collapsed, - const std::string& predetectedError); void release(void); }; diff --git a/src/lib/orionTypes/EntityTypeVector.cpp b/src/lib/orionTypes/EntityTypeVector.cpp index 04d8194bb4..b7d90b9ef0 100755 --- a/src/lib/orionTypes/EntityTypeVector.cpp +++ b/src/lib/orionTypes/EntityTypeVector.cpp @@ -31,7 +31,7 @@ #include "logMsg/traceLevels.h" #include "common/globals.h" -#include "common/tag.h" +#include "common/MimeType.h" #include "ngsi/Request.h" #include "orionTypes/EntityType.h" #include "orionTypes/EntityTypeVector.h" @@ -48,56 +48,6 @@ EntityTypeVector::EntityTypeVector() } -/* **************************************************************************** -* -* EntityTypeVector::toJsonV1 - -*/ -std::string EntityTypeVector::toJsonV1 -( - bool asJsonObject, - bool asJsonOut, - bool collapsed, - bool comma -) -{ - std::string out = ""; - - if (vec.size() > 0) - { - out += startTag("types", true); - - for (unsigned int ix = 0; ix < vec.size(); ++ix) - { - out += vec[ix]->toJsonV1(asJsonObject, asJsonOut, collapsed, ix != vec.size() - 1); - } - out += endTag(comma, true); - } - - return out; -} - - - -/* **************************************************************************** -* -* EntityTypeVector::check - -*/ -std::string EntityTypeVector::check(ApiVersion apiVersion, const std::string& predetectedError) -{ - for (unsigned int ix = 0; ix < vec.size(); ++ix) - { - std::string res; - - if ((res = vec[ix]->check(apiVersion, predetectedError)) != "OK") - { - return res; - } - } - - return "OK"; -} - - /* **************************************************************************** * @@ -110,32 +60,6 @@ void EntityTypeVector::push_back(EntityType* item) -/* **************************************************************************** -* -* EntityTypeVector::operator[] - -*/ -EntityType* EntityTypeVector::operator[] (unsigned int ix) const -{ - if (ix < vec.size()) - { - return vec[ix]; - } - return NULL; -} - - - -/* **************************************************************************** -* -* EntityTypeVector::size - -*/ -unsigned int EntityTypeVector::size(void) -{ - return vec.size(); -} - - - /* **************************************************************************** * * EntityTypeVector::release - diff --git a/src/lib/orionTypes/EntityTypeVector.h b/src/lib/orionTypes/EntityTypeVector.h index 145306dfff..b7f3490aa5 100644 --- a/src/lib/orionTypes/EntityTypeVector.h +++ b/src/lib/orionTypes/EntityTypeVector.h @@ -44,16 +44,7 @@ class EntityTypeVector EntityTypeVector(); void push_back(EntityType* item); - unsigned int size(void); void release(void); - std::string check(ApiVersion apiVersion, const std::string& predetectedError); - std::string toJsonV1(bool asJsonObject, - bool asJsonOut, - bool collapsed, - bool comma = false); - - EntityType* operator[] (unsigned int ix) const; - }; #endif // SRC_LIB_ORIONTYPES_ENTITYTYPEVECTOR_H_ diff --git a/src/lib/orionTypes/EntityTypeVectorResponse.cpp b/src/lib/orionTypes/EntityTypeVectorResponse.cpp index 6eb863558e..0194f624b1 100755 --- a/src/lib/orionTypes/EntityTypeVectorResponse.cpp +++ b/src/lib/orionTypes/EntityTypeVectorResponse.cpp @@ -30,7 +30,6 @@ #include "logMsg/logMsg.h" #include "common/globals.h" -#include "common/tag.h" #include "common/JsonHelper.h" #include "alarmMgr/alarmMgr.h" @@ -39,68 +38,6 @@ -/* **************************************************************************** -* -* EntityTypeVectorResponse::toJsonV1 - -*/ -std::string EntityTypeVectorResponse::toJsonV1 -( - bool asJsonObject, - bool asJsonOut, - bool collapsed -) -{ - std::string out = ""; - - out += startTag(); - - if (entityTypeVector.size() > 0) - { - out += entityTypeVector.toJsonV1(asJsonObject, asJsonOut, collapsed, true); - } - - out += statusCode.toJsonV1(false); - - out += endTag(); - - return out; -} - - - -/* **************************************************************************** -* -* EntityTypeVectorResponse::check - -*/ -std::string EntityTypeVectorResponse::check -( - ApiVersion apiVersion, - bool asJsonObject, - bool asJsonOut, - bool collapsed, - const std::string& predetectedError) -{ - std::string res; - - if (!predetectedError.empty()) - { - statusCode.fill(SccBadRequest, predetectedError); - } - else if ((res = entityTypeVector.check(apiVersion, predetectedError)) != "OK") - { - alarmMgr.badInput(clientIp, res); - statusCode.fill(SccBadRequest, res); - } - else - { - return "OK"; - } - - return toJsonV1(asJsonObject, asJsonOut, collapsed); -} - - - /* **************************************************************************** * * EntityTypeVectorResponse::release - @@ -108,7 +45,6 @@ std::string EntityTypeVectorResponse::check void EntityTypeVectorResponse::release(void) { entityTypeVector.release(); - statusCode.release(); } diff --git a/src/lib/orionTypes/EntityTypeVectorResponse.h b/src/lib/orionTypes/EntityTypeVectorResponse.h index bfcca6f9f3..614b33620e 100644 --- a/src/lib/orionTypes/EntityTypeVectorResponse.h +++ b/src/lib/orionTypes/EntityTypeVectorResponse.h @@ -29,7 +29,7 @@ #include #include "ngsi/Request.h" -#include "ngsi/StatusCode.h" +#include "rest/OrionError.h" #include "orionTypes/EntityTypeVector.h" @@ -42,17 +42,8 @@ class EntityTypeVectorResponse { public: EntityTypeVector entityTypeVector; - StatusCode statusCode; + OrionError error; - std::string toJsonV1(bool asJsonObject, - bool asJsonOut, - bool collapsed); - - std::string check(ApiVersion apiVersion, - bool asJsonObject, - bool asJsonOut, - bool collapsed, - const std::string& predetectedError); void release(void); std::string toJson(bool values); }; diff --git a/src/lib/orionTypes/OrionValueType.h b/src/lib/orionTypes/OrionValueType.h index b0ecccc3d2..c6872b3991 100644 --- a/src/lib/orionTypes/OrionValueType.h +++ b/src/lib/orionTypes/OrionValueType.h @@ -33,13 +33,7 @@ namespace orion /* **************************************************************************** * -* ValueType - -* -* Note that ValueTypeNotGiven is only used by NGSIv1 parsing logic. In NGSIv2 parsing, -* attribute or metatadata value is implicit if omitted (in particular, it -* takes null value in that case). However, this could change if we implement at -* some point PATCH on attribute and metadata. In that case, we would need to -* use ValueTypeNotGiven also in the cases value is omitted. +* ValueType - * */ typedef enum ValueType diff --git a/src/lib/orionTypes/QueryContextRequestVector.cpp b/src/lib/orionTypes/QueryContextRequestVector.cpp index 472a67b75d..cfb1119b2b 100644 --- a/src/lib/orionTypes/QueryContextRequestVector.cpp +++ b/src/lib/orionTypes/QueryContextRequestVector.cpp @@ -30,7 +30,6 @@ #include "logMsg/traceLevels.h" #include "common/globals.h" -#include "common/tag.h" #include "orionTypes/QueryContextRequestVector.h" #include "ngsi/Request.h" diff --git a/src/lib/orionTypes/QueryContextResponseVector.cpp b/src/lib/orionTypes/QueryContextResponseVector.cpp index 4a6f21ba8d..f2464819c1 100644 --- a/src/lib/orionTypes/QueryContextResponseVector.cpp +++ b/src/lib/orionTypes/QueryContextResponseVector.cpp @@ -30,7 +30,6 @@ #include "logMsg/traceLevels.h" #include "common/globals.h" -#include "common/tag.h" #include "orionTypes/QueryContextResponseVector.h" #include "ngsi/Request.h" @@ -84,127 +83,6 @@ void QueryContextResponseVector::release(void) -/* **************************************************************************** -* -* QueryContextResponseVector::toJsonV1 - -*/ -std::string QueryContextResponseVector::toJsonV1(bool asJsonObject, bool details, const std::string& detailsString) -{ - QueryContextResponse* responseP = new QueryContextResponse(); - std::string answer; - - // - // Here we have a vector of QueryContextResponse. - // What we need is ONE QueryContextResponse, so, we'll take all the - // contextElementResponses from each of the QueryContextResponses in the vector and - // move them to ONE QueryContextResponse (responseP) - // - // [ This might give me some problems with freeing the memory afterwards ...] - // - - - if (vec.size() == 0) - { - // - // Special case: vector is empty: translate to 404 - // - if ((responseP->errorCode.code == SccOk) || (responseP->errorCode.code == SccNone)) - { - responseP->errorCode.fill(SccContextElementNotFound); - } - } - else if ((vec.size() == 1) && (vec[0]->contextElementResponseVector.size() == 0)) - { - // - // Special case: only one QueryContextResponse in vec, and it has 0 contextElementResponses - // This is clearly a Not Found ... - // - if ((responseP->errorCode.code == SccOk) || (responseP->errorCode.code == SccNone)) - { - responseP->errorCode.fill(SccContextElementNotFound); - } - - if ((vec[0]->errorCode.code == SccOk) ||(vec[0]->errorCode.code == SccNone)) - { - vec[0]->errorCode.fill(SccContextElementNotFound); - } - - // - // Also, if same errorCode.code but no details ... - // - if ((responseP->errorCode.code == vec[0]->errorCode.code) && (responseP->errorCode.details.empty())) - { - responseP->errorCode.details = vec[0]->errorCode.details; - } - } - else - { - // - // We have found something, so, all good - // - responseP->errorCode.fill(SccOk); - } - - if (details) - { - responseP->errorCode.fill(SccOk, detailsString); - } - - for (unsigned int qIx = 0; qIx < vec.size(); ++qIx) - { - // - // If the response vector is empty and the errorCode also, then a 404 Not Found - // is inserted. - // - if (vec[qIx]->contextElementResponseVector.size() == 0) - { - if ((vec[qIx]->errorCode.code == SccOk) || (vec[qIx]->errorCode.code == SccNone)) - { - ContextElementResponse* cerP = new ContextElementResponse(); - - cerP->statusCode.fill(SccContextElementNotFound); - responseP->contextElementResponseVector.push_back(cerP); - } - } - - for (unsigned int cerIx = 0; cerIx < vec[qIx]->contextElementResponseVector.size(); ++cerIx) - { - ContextElementResponse* cerP = vec[qIx]->contextElementResponseVector[cerIx]; - - if ((cerP->statusCode.code != SccOk) && (cerP->statusCode.code != SccNone)) // Error - not to be added to output - { - continue; - } - - // - // Does the EntityId of cerP already exist in any of the contextElementResponses in the contextElementResponseVector? - // If so, we just add the attributes of cerP to that contextElementResponse - // - ContextElementResponse* targetCerP = responseP->contextElementResponseVector.lookup(&cerP->entity); - - if (targetCerP != NULL) - { - targetCerP->entity.attributeVector.push_back(cerP->entity.attributeVector, true); - } - else // Not found so we will have to create a new ContextElementResponse - { - ContextElementResponse* newCerP = new ContextElementResponse(cerP, true); - - newCerP->statusCode.fill(SccOk); - responseP->contextElementResponseVector.push_back(newCerP); - } - } - } - - answer = responseP->toJsonV1(asJsonObject); - responseP->release(); - delete responseP; - - return answer; -} - - - /* **************************************************************************** * * QueryContextResponseVector::populate - @@ -223,7 +101,7 @@ void QueryContextResponseVector::populate(QueryContextResponse* responseP) // // Special case: vector is empty: translate to 404 // - responseP->errorCode.fill(SccContextElementNotFound); + responseP->error.fill(SccContextElementNotFound); } else if ((vec.size() == 1) && (vec[0]->contextElementResponseVector.size() == 0)) { @@ -231,15 +109,15 @@ void QueryContextResponseVector::populate(QueryContextResponse* responseP) // Special case: only one QueryContextResponse in vec, and it has 0 contextElementResponses // This is clearly a Not Found ... // - responseP->errorCode.fill(SccContextElementNotFound); - vec[0]->errorCode.fill(SccContextElementNotFound); + responseP->error.fill(SccContextElementNotFound); + vec[0]->error.fill(SccContextElementNotFound); } else { // // We have found something, so, all good // - responseP->errorCode.fill(SccOk); + responseP->error.fill(SccOk); } for (unsigned int qIx = 0; qIx < vec.size(); ++qIx) @@ -250,11 +128,11 @@ void QueryContextResponseVector::populate(QueryContextResponse* responseP) // if (vec[qIx]->contextElementResponseVector.size() == 0) { - if ((vec[qIx]->errorCode.code == SccOk) || (vec[qIx]->errorCode.code == SccNone)) + if ((vec[qIx]->error.code == SccOk) || (vec[qIx]->error.code == SccNone)) { ContextElementResponse* cerP = new ContextElementResponse(); - cerP->statusCode.fill(SccContextElementNotFound); + cerP->error.fill(SccContextElementNotFound); responseP->contextElementResponseVector.push_back(cerP); } } @@ -263,7 +141,7 @@ void QueryContextResponseVector::populate(QueryContextResponse* responseP) { ContextElementResponse* cerP = vec[qIx]->contextElementResponseVector[cerIx]; - if ((cerP->statusCode.code != SccOk) && (cerP->statusCode.code != SccNone)) // Error - not to be added to output + if ((cerP->error.code != SccOk) && (cerP->error.code != SccNone)) // Error - not to be added to output { continue; } @@ -282,7 +160,7 @@ void QueryContextResponseVector::populate(QueryContextResponse* responseP) { ContextElementResponse* newCerP = new ContextElementResponse(cerP); - newCerP->statusCode.fill(SccOk); + newCerP->error.fill(SccOk); responseP->contextElementResponseVector.push_back(newCerP); } } diff --git a/src/lib/orionTypes/QueryContextResponseVector.h b/src/lib/orionTypes/QueryContextResponseVector.h index beeca40b2e..80030a5470 100644 --- a/src/lib/orionTypes/QueryContextResponseVector.h +++ b/src/lib/orionTypes/QueryContextResponseVector.h @@ -43,7 +43,6 @@ typedef struct QueryContextResponseVector unsigned int size(void); void push_back(QueryContextResponse* item); void release(void); - std::string toJsonV1(bool asJsonObject, bool details, const std::string& detailsString); void populate(QueryContextResponse* responseP); QueryContextResponse* operator[](unsigned int ix) const; diff --git a/src/lib/orionTypes/UpdateActionType.cpp b/src/lib/orionTypes/UpdateActionType.cpp index e937a210b8..3e26ab0144 100644 --- a/src/lib/orionTypes/UpdateActionType.cpp +++ b/src/lib/orionTypes/UpdateActionType.cpp @@ -35,31 +35,16 @@ * * actionTypeString - */ -std::string actionTypeString(ApiVersion apiVersion, ActionType action) +std::string actionTypeString(ActionType action) { - if (apiVersion == V2) + switch (action) { - switch (action) - { - case ActionTypeUpdate: return "update"; - case ActionTypeAppend: return "append"; - case ActionTypeAppendStrict: return "appendStrict"; - case ActionTypeDelete: return "delete"; - case ActionTypeReplace: return "replace"; - default: return "unknownAction"; - } - } - else - { - switch (action) - { - case ActionTypeUpdate: return "UPDATE"; - case ActionTypeAppend: return "APPEND"; - case ActionTypeAppendStrict: return "APPEND_STRICT"; - case ActionTypeDelete: return "DELETE"; - case ActionTypeReplace: return "REPLACE"; - default: return "UNKNOWN_ACTION"; - } + case ActionTypeUpdate: return "update"; + case ActionTypeAppend: return "append"; + case ActionTypeAppendStrict: return "appendStrict"; + case ActionTypeDelete: return "delete"; + case ActionTypeReplace: return "replace"; + default: return "unknownAction"; } } diff --git a/src/lib/orionTypes/UpdateActionType.h b/src/lib/orionTypes/UpdateActionType.h index 56514533bb..0e22b99ce7 100644 --- a/src/lib/orionTypes/UpdateActionType.h +++ b/src/lib/orionTypes/UpdateActionType.h @@ -52,7 +52,7 @@ typedef enum ActionType * * actionTypeString - */ -extern std::string actionTypeString(ApiVersion apiVersion, ActionType action); +extern std::string actionTypeString(ActionType action); diff --git a/src/lib/orionTypes/UpdateContextRequestVector.cpp b/src/lib/orionTypes/UpdateContextRequestVector.cpp index b9c499adb5..e6b4931569 100644 --- a/src/lib/orionTypes/UpdateContextRequestVector.cpp +++ b/src/lib/orionTypes/UpdateContextRequestVector.cpp @@ -30,7 +30,6 @@ #include "logMsg/traceLevels.h" #include "common/globals.h" -#include "common/tag.h" #include "orionTypes/UpdateContextRequestVector.h" #include "ngsi/Request.h" diff --git a/src/lib/orionTypes/areas.cpp b/src/lib/orionTypes/areas.cpp index 230ef343d4..aa487bbf5b 100644 --- a/src/lib/orionTypes/areas.cpp +++ b/src/lib/orionTypes/areas.cpp @@ -48,20 +48,6 @@ Point::Point(): valid(true), lat(0), lon(0) -/* **************************************************************************** -* -* Point::Point - -*/ -Point::Point(::std::string latitude, ::std::string longitude): valid(true) -{ - if ((str2double(latitude.c_str(), &lat) == false) || (str2double(longitude.c_str(), &lon) == false)) - { - valid = false; - } -} - - - /* **************************************************************************** * * Point::Point - @@ -106,27 +92,6 @@ double Point::longitude(void) const } -/* **************************************************************************** -* -* Point::latitudeSet - -*/ -void Point::latitudeSet(::std::string latitude) -{ - valid = str2double(latitude.c_str(), &lat); -} - - - -/* **************************************************************************** -* -* Point::longitudeSet - -*/ -void Point::longitudeSet(::std::string longitude) -{ - valid = str2double(longitude.c_str(), &lon); -} - - /* **************************************************************************** * @@ -166,33 +131,6 @@ bool Point::equals(Point* p) -/* **************************************************************************** -* -* Point::latitudeString - -*/ -::std::string Point::latitudeString(void) -{ - char cV[STRING_SIZE_FOR_DOUBLE]; - - snprintf(cV, sizeof(cV), "%f", lat); - return cV; -} - - -/* **************************************************************************** -* -* Point::longitudeString - -*/ -::std::string Point::longitudeString(void) -{ - char cV[STRING_SIZE_FOR_DOUBLE]; - - snprintf(cV, sizeof(cV), "%f", lon); - return cV; -} - - - /* **************************************************************************** * * Line::Line - @@ -240,18 +178,6 @@ Box::Box() -/* **************************************************************************** -* -* Box::Box - -*/ -Box::Box(Point* lowerLeftP, Point* upperRightP) -{ - lowerLeft.fill(lowerLeftP); - upperRight.fill(upperRightP); -} - - - /* **************************************************************************** * * Box::fill - @@ -263,166 +189,6 @@ void Box::fill(Point* lowerLeftP, Point* upperRightP) } -/* **************************************************************************** -* -* Circle::inverted - -*/ -bool Circle::inverted(void) const -{ - if ((_inverted == "true") || (_inverted == "1")) - { - return true; - } - - return false; -} - - - -/* **************************************************************************** -* -* Circle::radius - -* -*/ -double Circle::radius(void) const -{ - // NOTE: here we use atof and not str2double on purpose - float r = atof(_radius.c_str()); - - return r; -} - - - -/* **************************************************************************** -* -* Circle::radiusString - -*/ -::std::string Circle::radiusString(void) const -{ - return _radius; -} - - - -/* **************************************************************************** -* -* Circle::invertedString - -* -*/ -::std::string Circle::invertedString(void) const -{ - return _inverted; -} - - - -/* **************************************************************************** -* -* Circle::radiusSet - -*/ -void Circle::radiusSet(::std::string radius) -{ - _radius = radius; -} - - - -/* **************************************************************************** -* -* Circle::radiusSet - -*/ -void Circle::radiusSet(float radius) -{ - char buffer[64]; - - snprintf(buffer, sizeof(buffer), "%f", radius); - _radius = buffer; -} - - - -/* **************************************************************************** -* -* Circle::invertedSet - -*/ -void Circle::invertedSet(::std::string inverted) -{ - _inverted = inverted; -} - - - -/* **************************************************************************** -* -* Circle::invertedSet - -*/ -void Circle::invertedSet(bool inverted) -{ - _inverted = (inverted == true)? "true" : "false"; -} - - - -/* **************************************************************************** -* -* Circle::centerSet - -*/ -void Circle::centerSet(Point* centerP) -{ - center.fill(centerP); -} - - - -/* **************************************************************************** -* -* Polygon::inverted - -*/ -bool Polygon::inverted(void) const -{ - if ((_inverted == "true") || (_inverted == "1")) - { - return true; - } - - return false; -} - - - -/* **************************************************************************** -* -* Polygon::invertedSet - -*/ -void Polygon::invertedSet(::std::string inverted) -{ - _inverted = inverted; -} - - - -/* **************************************************************************** -* -* Polygon::invertedSet - -*/ -void Polygon::invertedSet(bool inverted) -{ - _inverted = (inverted == true)? "true" : "false"; -} - - - -/* **************************************************************************** -* -* Polygon::invertedString - -*/ -::std::string Polygon::invertedString(void) const -{ - return _inverted; -} - - /* **************************************************************************** * @@ -556,24 +322,11 @@ int Georel::parse(const char* in, std::string* errorString) -/* **************************************************************************** -* -* Georel::fill - -*/ -void Georel::fill(Georel* georelP) -{ - type = georelP->type; - maxDistance = georelP->maxDistance; - minDistance = georelP->minDistance; -} - - - /* **************************************************************************** * * Geometry::Geometry - */ -Geometry::Geometry(): areaType(""), radius(-1), external(false) +Geometry::Geometry(): areaType("") { } @@ -583,7 +336,7 @@ Geometry::Geometry(): areaType(""), radius(-1), external(false) * * Geometry::parse - */ -int Geometry::parse(ApiVersion apiVersion, const char* in, std::string* errorString) +int Geometry::parse(const char* in, std::string* errorString) { std::vector items; @@ -595,16 +348,7 @@ int Geometry::parse(ApiVersion apiVersion, const char* in, std::string* errorStr for (unsigned int ix = 0; ix < items.size(); ++ix) { - if ((apiVersion == V1) && ((items[ix] == "polygon") || (items[ix] == "circle"))) - { - if (!areaType.empty()) - { - *errorString = "polygon/circle present more than once"; - return -1; - } - areaType = items[ix]; - } - else if ((apiVersion == V2) && ((items[ix] == "point") || (items[ix] == "line") || (items[ix] == "box") || (items[ix] == "polygon"))) + if (((items[ix] == "point") || (items[ix] == "line") || (items[ix] == "box") || (items[ix] == "polygon"))) { if (!areaType.empty()) { @@ -614,20 +358,6 @@ int Geometry::parse(ApiVersion apiVersion, const char* in, std::string* errorStr areaType = items[ix]; } - else if (strncmp(items[ix].c_str(), "radius", 6) == 0) - { - radius = atoi((char*) &items[ix].c_str()[7]); - - if (radius == 0) - { - *errorString = "Invalid value of /radius/"; - return -1; - } - } - else if (items[ix] == "external") - { - external = true; - } else { *errorString = "Invalid selector in geometry specification"; @@ -635,18 +365,6 @@ int Geometry::parse(ApiVersion apiVersion, const char* in, std::string* errorStr } } - if ((areaType == "circle") && (radius == -1)) - { - *errorString = "no radius for circle"; - return -1; - } - - if ((areaType == "polygon") && (radius != -1)) - { - *errorString = "radius set for polygon"; - return -1; - } - return 0; } diff --git a/src/lib/orionTypes/areas.h b/src/lib/orionTypes/areas.h index 868af20495..df07aa4aec 100644 --- a/src/lib/orionTypes/areas.h +++ b/src/lib/orionTypes/areas.h @@ -40,7 +40,6 @@ namespace orion typedef enum AreaType { NoArea, - CircleType, PolygonType, PointType, LineType, @@ -62,20 +61,14 @@ class Point public: Point(); - Point(::std::string latitude, ::std::string longitude); Point(double _lat, double _lon); void fill(Point* p); double latitude(void) const; double longitude(void) const; void latitudeSet(double latitude); - void latitudeSet(::std::string latitude); void longitudeSet(double longitude); - void longitudeSet(::std::string longitude); bool equals(Point* p); - - ::std::string latitudeString(void); - ::std::string longitudeString(void); }; @@ -108,54 +101,20 @@ class Box Point upperRight; Box(); - Box(Point* lowerLeftP, Point* upperRightP); void fill(Point* lowerLeftP, Point* upperRightP); }; -/* **************************************************************************** -* -* Circle - -*/ -class Circle -{ - private: - ::std::string _radius; - ::std::string _inverted; - - public: - Point center; - bool inverted(void) const; - double radius(void) const; - - ::std::string radiusString(void) const; - ::std::string invertedString(void) const; - void radiusSet(::std::string radius); - void radiusSet(float _radius); - void invertedSet(::std::string inverted); - void invertedSet(bool _inverted); - void centerSet(Point* _center); -}; - - - /* **************************************************************************** * * Polygon - */ class Polygon { - private: - ::std::string _inverted; - public: ::std::vector vertexList; - bool inverted(void) const; - void invertedSet(::std::string inverted); - void invertedSet(bool inverted); - ::std::string invertedString(void) const; void vertexAdd(Point* p); void release(void); }; @@ -171,7 +130,6 @@ class Georel public: Georel(); - void fill(Georel* georelP); int parse(const char* in, std::string* errorString); std::string type; @@ -189,11 +147,9 @@ class Geometry { public: Geometry(); - int parse(ApiVersion apiVersion, const char* in, std::string* errorString); + int parse(const char* in, std::string* errorString); std::string areaType; - float radius; - bool external; }; } diff --git a/src/lib/parse/CMakeLists.txt b/src/lib/parse/CMakeLists.txt index 0ab9b01611..3db72f676f 100644 --- a/src/lib/parse/CMakeLists.txt +++ b/src/lib/parse/CMakeLists.txt @@ -22,16 +22,12 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.0) SET (SOURCES CompoundValueNode.cpp - compoundValue.cpp - nullTreat.cpp forbiddenChars.cpp textParse.cpp ) SET (HEADERS CompoundValueNode.h - compoundValue.h - nullTreat.h forbiddenChars.h textParse.h ) diff --git a/src/lib/parse/CompoundValueNode.cpp b/src/lib/parse/CompoundValueNode.cpp index fdf0fa2008..a7e042b4a2 100644 --- a/src/lib/parse/CompoundValueNode.cpp +++ b/src/lib/parse/CompoundValueNode.cpp @@ -29,7 +29,6 @@ #include "common/globals.h" #include "common/string.h" -#include "common/tag.h" #include "common/JsonHelper.h" #include "common/macroSubstitute.h" #include "alarmMgr/alarmMgr.h" @@ -203,12 +202,7 @@ CompoundValueNode::~CompoundValueNode() */ std::string CompoundValueNode::finish(void) { - LM_T(LmtCompoundValue, ("Finishing a compound")); - - if (lmTraceIsSet(LmtCompoundValueShow)) - { - show(""); - } + LM_T(LmtCompoundValue, ("Finishing a compound: s (%s)", name.c_str(), toJson().c_str())); return check(""); } @@ -310,145 +304,6 @@ CompoundValueNode* CompoundValueNode::add -/* **************************************************************************** -* -* shortShow - -*/ -void CompoundValueNode::shortShow(const std::string& indent) -{ - if (valueType == orion::ValueTypeVector) - { - LM_T(LmtCompoundValue, ("%s%s (vector)", - indent.c_str(), - name.c_str())); - } - else if (valueType == orion::ValueTypeObject) - { - LM_T(LmtCompoundValue, ("%s%s (object)", - indent.c_str(), - name.c_str())); - } - else if (valueType == orion::ValueTypeString) - { - LM_T(LmtCompoundValue, ("%s%s (%s)", - indent.c_str(), - name.c_str(), - stringValue.c_str())); - return; - } - else if (valueType == orion::ValueTypeBoolean) - { - LM_T(LmtCompoundValue, ("%s%s (%s)", - indent.c_str(), - name.c_str(), - (boolValue == true)? "true" : "false")); - return; - } - else if (valueType == orion::ValueTypeNull) - { - LM_T(LmtCompoundValue, ("%s%s (null)", - indent.c_str(), - name.c_str())); - return; - } - else if (valueType == orion::ValueTypeNotGiven) - { - LM_T(LmtCompoundValue, ("%s%s (not given)", - indent.c_str(), - name.c_str())); - return; - } - else if (valueType == orion::ValueTypeNumber) - { - LM_T(LmtCompoundValue, ("%s%s (%f)", - indent.c_str(), - name.c_str(), - numberValue)); - return; - } - - for (uint64_t ix = 0; ix < childV.size(); ++ix) - { - childV[ix]->shortShow(indent + " "); - } -} - - - -/* **************************************************************************** -* -* show - -*/ -void CompoundValueNode::show(const std::string& indent) -{ - if (!name.empty()) - { - LM_T(LmtCompoundValueShow, ("%sname: %s", - indent.c_str(), - name.c_str())); - } - - LM_T(LmtCompoundValueShow, ("%stype: %s", - indent.c_str(), - orion::valueTypeName(valueType))); - - if (valueType == orion::ValueTypeString) - { - LM_T(LmtCompoundValueShow, ("%sString Value: %s", - indent.c_str(), - stringValue.c_str())); - } - else if (valueType == orion::ValueTypeBoolean) - { - LM_T(LmtCompoundValueShow, ("%sBool Value: %s", - indent.c_str(), - (boolValue == false)? "false" : "true")); - } - else if (valueType == orion::ValueTypeNumber) - { - LM_T(LmtCompoundValueShow, ("%sNumber Value: %f", - indent.c_str(), - numberValue)); - } - else if (valueType == orion::ValueTypeNull) - { - LM_T(LmtCompoundValueShow, ("%sNull", - indent.c_str())); - } - else if (valueType == orion::ValueTypeNotGiven) - { - LM_T(LmtCompoundValueShow, ("%sNotGiven", - indent.c_str())); - } - else if (childV.size() != 0) - { - std::string childrenString; - - for (uint64_t ix = 0; ix < childV.size(); ++ix) - { - childrenString += childV[ix]->name; - if (ix != childV.size() - 1) - { - childrenString += ", "; - } - } - - LM_T(LmtCompoundValueShow, ("%s%lu children (%s)", - indent.c_str(), - childV.size(), - childrenString.c_str())); - - for (uint64_t ix = 0; ix < childV.size(); ++ix) - { - childV[ix]->show(indent + " "); - } - } - - LM_T(LmtCompoundValueShow, ("")); -} - - - /* **************************************************************************** * * check - @@ -840,15 +695,4 @@ bool CompoundValueNode::isString(void) { return (valueType == orion::ValueTypeString); } - - - -/* **************************************************************************** -* -* cname - -*/ -const char* CompoundValueNode::cname(void) -{ - return name.c_str(); -} } diff --git a/src/lib/parse/CompoundValueNode.h b/src/lib/parse/CompoundValueNode.h index bd15aefe64..53aaedbf84 100644 --- a/src/lib/parse/CompoundValueNode.h +++ b/src/lib/parse/CompoundValueNode.h @@ -124,14 +124,9 @@ class CompoundValueNode ExprContextObject toExprContextObject(void); ExprContextList toExprContextList(void); - void shortShow(const std::string& indent); - void show(const std::string& indent); - bool isVector(void); bool isObject(void); bool isString(void); - - const char* cname(void); }; } // namespace orion diff --git a/src/lib/parse/compoundValue.cpp b/src/lib/parse/compoundValue.cpp index f97135f8a0..2826ae3d04 100644 --- a/src/lib/parse/compoundValue.cpp +++ b/src/lib/parse/compoundValue.cpp @@ -60,36 +60,6 @@ void compoundValueEnd(ConnectionInfo* ciP, ParseData* parseDataP) alarmMgr.badInput(clientIp, ciP->answer); } - // - // Give the root pointer of this Compound to the active ContextAttribute - // lastContextAttribute is set in the JSON v1 parsing routines, to point at the - // latest contextAttribute, i.e. the attribute whose 'contextValue' is the - // owner of this compound value tree. - // - - LM_T(LmtCompoundValue, ("Set compoundValueP (%p) for attribute at %p", - ciP->compoundValueRoot, - parseDataP->lastContextAttribute)); - - // - // Special case for updateContextAttributeRequest. This payload has no - // ContextAttribute to point to by lastContextAttribute, as the whole payload - // is a part of a ContextAttribute. - // - RequestType requestType = ciP->restServiceP->request; - - if ((requestType == AttributeValueInstance) || - (requestType == AttributeValueInstanceWithTypeAndId) || - (requestType == IndividualContextEntityAttribute) || - (requestType == IndividualContextEntityAttributeWithTypeAndId)) - { - parseDataP->upcar.res.compoundValueP = ciP->compoundValueRoot; - } - else - { - parseDataP->lastContextAttribute->compoundValueP = ciP->compoundValueRoot; - } - // Reset the Compound stuff in ConnectionInfo ciP->compoundValueRoot = NULL; ciP->compoundValueP = NULL; diff --git a/src/lib/parse/forbiddenChars.cpp b/src/lib/parse/forbiddenChars.cpp index 6fc9e72812..ecff81e833 100644 --- a/src/lib/parse/forbiddenChars.cpp +++ b/src/lib/parse/forbiddenChars.cpp @@ -87,22 +87,6 @@ bool forbiddenChars(const char* s, const char* exceptions) -/* **************************************************************************** -* -* forbiddenIdChars - -*/ -bool forbiddenIdChars(int api, const char* s, const char* exceptions) -{ - if (api == 1 && !checkIdv1) - { - return forbiddenChars(s, exceptions); // old behavior - } - - return forbiddenIdCharsV2(s, exceptions); -} - - - /* **************************************************************************** * * forbiddenIdCharsV2 - diff --git a/src/lib/parse/forbiddenChars.h b/src/lib/parse/forbiddenChars.h index a92f2662ff..c1f87eeb9a 100644 --- a/src/lib/parse/forbiddenChars.h +++ b/src/lib/parse/forbiddenChars.h @@ -36,14 +36,6 @@ extern bool forbiddenChars(const char* s, const char* exceptions = NULL); -/* **************************************************************************** -* -* forbiddenIdChars - -*/ -extern bool forbiddenIdChars(int api, const char* s, const char* exceptions = NULL); - - - /* **************************************************************************** * * forbiddenIdCharsV2 - diff --git a/src/lib/parse/textParse.cpp b/src/lib/parse/textParse.cpp index f9ad221844..7603099700 100644 --- a/src/lib/parse/textParse.cpp +++ b/src/lib/parse/textParse.cpp @@ -56,7 +56,7 @@ static std::string textParseAttributeValue(ConnectionInfo* ciP, ContextAttribute else { OrionError oe(SccBadRequest, "Missing citation-mark at end of string"); - return oe.setStatusCodeAndSmartRender(ciP->apiVersion, &(ciP->httpStatusCode)); + return oe.setSCAndRender(&(ciP->httpStatusCode)); } } @@ -88,7 +88,7 @@ static std::string textParseAttributeValue(ConnectionInfo* ciP, ContextAttribute else // 5. None of the above - it's an error { OrionError oe(SccBadRequest, "attribute value type not recognized"); - return oe.setStatusCodeAndSmartRender(ciP->apiVersion, &(ciP->httpStatusCode)); + return oe.setSCAndRender(&(ciP->httpStatusCode)); } return "OK"; @@ -113,17 +113,17 @@ std::string textRequestTreat(ConnectionInfo* ciP, ParseData* parseDataP, Request return answer; } - if ((answer = parseDataP->av.attribute.check(ciP->apiVersion, EntityAttributeValueRequest)) != "OK") + if ((answer = parseDataP->av.attribute.check(true)) != "OK") { OrionError oe(SccBadRequest, answer); - return oe.setStatusCodeAndSmartRender(ciP->apiVersion, &(ciP->httpStatusCode)); + return oe.setSCAndRender(&(ciP->httpStatusCode)); } break; default: OrionError oe(SccUnsupportedMediaType, "not supported content type: text/plain"); - answer = oe.setStatusCodeAndSmartRender(ciP->apiVersion, &(ciP->httpStatusCode)); + answer = oe.setSCAndRender(&(ciP->httpStatusCode)); alarmMgr.badInput(clientIp, "not supported content type", "text/plain"); break; diff --git a/src/lib/rest/ConnectionInfo.h b/src/lib/rest/ConnectionInfo.h index 9d9600ca0f..6a92823c97 100644 --- a/src/lib/rest/ConnectionInfo.h +++ b/src/lib/rest/ConnectionInfo.h @@ -74,7 +74,6 @@ class ConnectionInfo parseDataP (NULL), port (0), ip (""), - apiVersion (V1), inCompoundValue (false), compoundValueP (NULL), compoundValueRoot (NULL), @@ -95,7 +94,6 @@ class ConnectionInfo parseDataP (NULL), port (0), ip (""), - apiVersion (V1), inCompoundValue (false), compoundValueP (NULL), compoundValueRoot (NULL), @@ -119,7 +117,6 @@ class ConnectionInfo parseDataP (NULL), port (0), ip (""), - apiVersion (V1), requestType (NoRequest), inCompoundValue (false), compoundValueP (NULL), @@ -166,7 +163,6 @@ class ConnectionInfo ParseData* parseDataP; unsigned short port; std::string ip; - ApiVersion apiVersion; RequestType requestType; // FIXME P2: To Be Removed (found inside restServiceP->request (restServiceP->type)) std::string acceptHeaderError; struct timeval transactionStart; // For metrics diff --git a/src/lib/rest/EntityTypeInfo.h b/src/lib/rest/EntityTypeInfo.h index adcdac7047..fc7e09e1f6 100644 --- a/src/lib/rest/EntityTypeInfo.h +++ b/src/lib/rest/EntityTypeInfo.h @@ -31,6 +31,8 @@ /* **************************************************************************** * * EntityTypeInfo - entity::type empty, not empty OR either +* +* FIXME PR: review usage of this class */ typedef enum EntityTypeInfo { diff --git a/src/lib/rest/HttpStatusCode.cpp b/src/lib/rest/HttpStatusCode.cpp index 6aea018adc..34b28761e5 100644 --- a/src/lib/rest/HttpStatusCode.cpp +++ b/src/lib/rest/HttpStatusCode.cpp @@ -36,25 +36,19 @@ std::string httpStatusCodeString(HttpStatusCode code) { case SccOk: return "OK"; case SccCreated: return "Created"; - case SccBadRequest: return "Bad Request"; + case SccBadRequest: return "BadRequest"; case SccForbidden: return "Forbidden"; - case SccContextElementNotFound: return "No context element found"; // Standard HTTP for 404: "Not Found" - case SccBadVerb: return "Method Not Allowed"; - case SccNotAcceptable: return "Not Acceptable"; - case SccConflict: return "Too Many Results"; - case SccContentLengthRequired: return "Content Length Required"; - case SccRequestEntityTooLarge: return "Request Entity Too Large"; - case SccUnsupportedMediaType: return "Unsupported Media Type"; - case SccInvalidModification: return "Invalid Modification"; - case SccSubscriptionIdNotFound: return "subscriptionId does not correspond to an active subscription"; // FI-WARE - case SccMissingParameter: return "parameter missing in the request"; // FI-WARE - case SccInvalidParameter: return "request parameter is invalid/not allowed"; // FI-WARE - case SccErrorInMetadata: return "Generic error in metadata"; - case SccEntityIdReNotAllowed: return "Regular Expression for EntityId is not allowed by receiver"; - case SccEntityTypeRequired: return "EntityType required by the receiver"; - case SccAttributeListRequired: return "Attribute List required by the receiver"; - case SccReceiverInternalError: return "Internal Server Error"; - case SccNotImplemented: return "Not Implemented"; + case SccContextElementNotFound: return "NotFound"; + case SccBadVerb: return "MethodNotAllowed"; + case SccNotAcceptable: return "NotAcceptable"; + case SccConflict: return "TooManyResults"; + case SccContentLengthRequired: return "ContentLengthRequired"; + case SccRequestEntityTooLarge: return "RequestEntityTooLarge"; + case SccUnsupportedMediaType: return "UnsupportedMediaType"; + case SccInvalidModification: return "InvalidModification"; + case SccInvalidParameter: return "request parameter is invalid/not allowed"; // FI-WARE // FIXME PR: remove + case SccReceiverInternalError: return "InternalServerError"; + case SccNotImplemented: return "NotImplemented"; default: return "Undefined"; } } diff --git a/src/lib/rest/HttpStatusCode.h b/src/lib/rest/HttpStatusCode.h index e71201ff6c..adb3861122 100644 --- a/src/lib/rest/HttpStatusCode.h +++ b/src/lib/rest/HttpStatusCode.h @@ -48,13 +48,7 @@ typedef enum HttpStatusCode SccRequestEntityTooLarge = 413, // Request Entity Too Large - over 1Mb of payload SccUnsupportedMediaType = 415, // Unsupported Media Type (only support and application/json and -in some cases- text/plain) SccInvalidModification = 422, // InvalidModification (unprocessable entity) - SccSubscriptionIdNotFound = 470, // The subscriptionId does not correspond to an active subscription - SccMissingParameter = 471, // A parameter is missing in the request SccInvalidParameter = 472, // A parameter of the request is invalid/not allowed - SccErrorInMetadata = 473, // Generic error in metadata (e.g. 'expires' older than 'timestamp') - SccEntityIdReNotAllowed = 480, // Regular Expression for EntityId is not allowed by receiver - SccEntityTypeRequired = 481, // The EntityType is required by the receiver - SccAttributeListRequired = 482, // The Attribute List is required by the receiver SccReceiverInternalError = 500, // An unknown error at the receiver has occurred SccNotImplemented = 501 // The given operation is not implemented } HttpStatusCode; diff --git a/src/lib/rest/OrionError.cpp b/src/lib/rest/OrionError.cpp index 710e1fa810..991c99d17e 100644 --- a/src/lib/rest/OrionError.cpp +++ b/src/lib/rest/OrionError.cpp @@ -25,10 +25,9 @@ #include #include -#include "common/tag.h" +#include "common/string.h" #include "common/JsonHelper.h" #include "rest/ConnectionInfo.h" -#include "ngsi/StatusCode.h" #include "rest/OrionError.h" @@ -61,15 +60,16 @@ OrionError::OrionError(HttpStatusCode _code, const std::string& _description, co + /* **************************************************************************** * -* OrionError::OrionError - +* OrionError::fill - */ -OrionError::OrionError(StatusCode& sc) +void OrionError::fill(HttpStatusCode _code, const std::string& _description, const std::string& _error) { - code = sc.code; - error = httpStatusCodeString(code); - description = sc.details; + code = _code; + error = _error.empty()? httpStatusCodeString(code) : _error; + description = _description; filled = true; } @@ -79,12 +79,9 @@ OrionError::OrionError(StatusCode& sc) * * OrionError::fill - */ -void OrionError::fill(HttpStatusCode _code, const std::string& _description, const std::string& _error) +void OrionError::fill(const OrionError& oe) { - code = _code; - error = _error.empty()? httpStatusCodeString(code) : _error; - description = _description; - filled = true; + fill(oe.code, oe.description, oe.error); } @@ -93,12 +90,9 @@ void OrionError::fill(HttpStatusCode _code, const std::string& _description, con * * OrionError::fill - */ -void OrionError::fill(const StatusCode& sc) +void OrionError::fill(OrionError* oeP) { - code = sc.code; - error = (sc.reasonPhrase.empty())? httpStatusCodeString(code) : sc.reasonPhrase; - description = sc.details; - filled = true; + fill(oeP->code, oeP->description, oeP->error); } @@ -127,35 +121,12 @@ void OrionError::fillOrAppend(HttpStatusCode _code, const std::string& fullDetai /* **************************************************************************** * -* OrionError::smartRender - -*/ -std::string OrionError::smartRender(ApiVersion apiVersion) -{ - if (apiVersion == V1 || apiVersion == NO_VERSION) - { - return toJsonV1(); - } - else // admin or v2 - { - shrinkError(); - return toJson(); - } -} - - - -/* **************************************************************************** -* -* OrionError::setStatusCodeAndSmartRender - +* OrionError::setSCAndRender - */ -std::string OrionError::setStatusCodeAndSmartRender(ApiVersion apiVersion, HttpStatusCode* scP) +std::string OrionError::setSCAndRender(HttpStatusCode* scP) { - if ((apiVersion == V2) || (apiVersion == ADMIN_API)) - { - *scP = code; - } - - return smartRender(apiVersion); + *scP = code; + return toJson(); } @@ -180,106 +151,3 @@ std::string OrionError::toJson(void) return jh.str(); } - - -/* **************************************************************************** -* -* OrionError::toJsonV1 - -* -*/ -std::string OrionError::toJsonV1(void) -{ - std::string out = "{"; - - // - // OrionError is NEVER part of any other payload, so the JSON start/end braces must be added here - // - out += startTag("orionError", false); - out += valueTag("code", code, true); - out += valueTag("reasonPhrase", error, !description.empty()); - - if (!description.empty()) - { - out += valueTag("details", description); - } - - out += endTag(); - - out += "}"; - - return out; -} - - - -/* **************************************************************************** -* -* OrionError::shrinkError - -* -* This method removes any whitespace in the error field, i.e. -* transforms "Not Found" to "NotFound". -* -* It is used by smartRender method, in order to prepare to render in API v2 case -* -* FIXME P4: The following alternative (more compact) way has been proposed: -* -* #include // std::remove_if -* #include // std::isspace -* -* ... -* -* reasonPhrase.erase(std::remove_if(error.begin(), error.end(), std::isspace), error.end()); -* -* However, 'std::isspace' doesn't directly work. We have been able to make it work with -* 'static_cast(isspace)'. However, that is obscure so until we can find -* a way of using just 'std::isspace', the current implementation stills. -* -*/ -void OrionError::shrinkError(void) -{ - char buf[80]; // 80 should be enough to hold any reason phrase - -#if 0 - strncpy(buf, error.c_str(), sizeof(buf)); - - // See: http://stackoverflow.com/questions/1726302/removing-spaces-from-a-string-in-c - if (*j != ' ') - { - *i = *j; - ++i; - } - ++j; - - char* i = buf; - char* j = buf; - while (*j != 0) - { - *i = *j++; - if (*i != ' ') - { - i++; - } - } - *i = 0; -#endif - - char* fromP = (char*) error.c_str(); - char* toP = buf; - unsigned int toLen = 0; - - while ((*fromP != 0) && (toLen < sizeof(buf))) - { - // If next char is not whitespace: copy to outgoing - if (*fromP != ' ') - { - *toP = *fromP; - ++toP; - ++toLen; - } - - ++fromP; - } - *toP = 0; // End-of string - - error = std::string(buf); -} diff --git a/src/lib/rest/OrionError.h b/src/lib/rest/OrionError.h index 2418ce8e64..5e8fd7c516 100644 --- a/src/lib/rest/OrionError.h +++ b/src/lib/rest/OrionError.h @@ -29,7 +29,7 @@ #include "common/globals.h" -#include "ngsi/StatusCode.h" +#include "rest/OrionError.h" #include "rest/HttpStatusCode.h" @@ -47,21 +47,15 @@ typedef struct OrionError bool filled; OrionError(); - OrionError(StatusCode& statusCode); OrionError(HttpStatusCode _code, const std::string& _description = "", const std::string& _error = ""); - std::string smartRender(ApiVersion apiVersion); - std::string setStatusCodeAndSmartRender(ApiVersion apiVersion, HttpStatusCode* scP); + std::string setSCAndRender(HttpStatusCode* scP); std::string toJson(void); - std::string toJsonV1(void); void fill(HttpStatusCode _code, const std::string& _description, const std::string& _error = ""); - void fill(const StatusCode& sc); + void fill(const OrionError& oe); + void fill(OrionError* oeP); void fillOrAppend(HttpStatusCode _code, const std::string& fullDetails, const std::string& appendDetail, const std::string& _error); - -private: - void shrinkError(void); - } OrionError; #endif diff --git a/src/lib/rest/RestService.cpp b/src/lib/rest/RestService.cpp index ec3341910c..6d988f3c53 100644 --- a/src/lib/rest/RestService.cpp +++ b/src/lib/rest/RestService.cpp @@ -24,8 +24,6 @@ */ #include -#include "jsonParse/jsonRequest.h" - #include "logMsg/logMsg.h" #include "logMsg/traceLevels.h" @@ -144,18 +142,6 @@ static void delayedRelease(JsonDelayedRelease* releaseP) releaseP->attribute = NULL; } - if (releaseP->scrP != NULL) - { - releaseP->scrP->release(); - releaseP->scrP = NULL; - } - - if (releaseP->ucsrP != NULL) - { - releaseP->ucsrP->release(); - releaseP->ucsrP = NULL; - } - if (releaseP->subsP != NULL) { delete releaseP->subsP; @@ -174,7 +160,6 @@ std::string payloadParse ConnectionInfo* ciP, ParseData* parseDataP, RestService* service, - JsonRequest** jsonPP, JsonDelayedRelease* jsonReleaseP, std::vector& compV ) @@ -188,20 +173,11 @@ std::string payloadParse if (ciP->inMimeType == JSON) { - if (ciP->apiVersion == V2) - { - // - // FIXME #3151: jsonRequestTreat should return 'bool' and accept an output parameter 'OrionError* oeP'. - // Same same for all underlying JSON APIv2 parsing functions - // Not sure the same thing can be done for 'jsonTreat' in the else-part, but this should AT LEAST - // be fixed for V2. - // - result = jsonRequestTreat(ciP, parseDataP, service->request, jsonReleaseP, compV); - } - else - { - result = jsonTreat(ciP->payload, ciP, parseDataP, service->request, jsonPP); - } + // + // FIXME #3151: jsonRequestTreat should return 'bool' and accept an output parameter 'OrionError* oeP'. + // Same same for all underlying JSON APIv2 parsing functions + // + result = jsonRequestTreat(ciP, parseDataP, service->request, jsonReleaseP, compV); } else if (ciP->inMimeType == TEXT) { @@ -226,6 +202,7 @@ std::string payloadParse + /* **************************************************************************** * * tenantCheck - @@ -287,35 +264,19 @@ static void commonFilters // if (ciP->uriParam[URI_PARAM_NOT_EXIST] == SCOPE_VALUE_ENTITY_TYPE) { - Restriction* restrictionP = NULL; - - // - // Lookup the restriction of the correct parseData, where to add the new scope. - // - if (serviceP->request == EntityTypes) - { - restrictionP = &parseDataP->qcr.res.restriction; - } - else if (serviceP->request == AllContextEntities) - { - restrictionP = &parseDataP->qcr.res.restriction; - } - + ScopeVector* scopeVectorP = &parseDataP->qcr.res.scopeVector; - if (restrictionP == NULL) + if (scopeVectorP == NULL) { - // There are two possibilities to be here: - // 1. A filter given for a request NOT SUPPORTING the filter - // 2. The restrictionP-lookup is MISSING (not implemented) - // - // Either way, we just silently return. + // The scopeVectorP-lookup is MISSING (not implemented + // We just silently return. // return; } Scope* scopeP = new Scope(SCOPE_FILTER_EXISTENCE, SCOPE_VALUE_ENTITY_TYPE); scopeP->oper = SCOPE_OPERATOR_NOT; - restrictionP->scopeVector.push_back(scopeP); + scopeVectorP->push_back(scopeP); } @@ -325,34 +286,19 @@ static void commonFilters // if (ciP->uriParam[URI_PARAM_EXIST] == SCOPE_VALUE_ENTITY_TYPE) { - Restriction* restrictionP = NULL; + ScopeVector* scopeVectorP = &parseDataP->qcr.res.scopeVector; - // - // Lookup the restriction of the correct parseData, where to add the new scope. - // - if (serviceP->request == EntityTypes) - { - restrictionP = &parseDataP->qcr.res.restriction; - } - else if (serviceP->request == AllContextEntities) - { - restrictionP = &parseDataP->qcr.res.restriction; - } - - if (restrictionP == NULL) + if (scopeVectorP == NULL) { - // There are two possibilities to be here: - // 1. A filter given for a request NOT SUPPORTING the filter - // 2. The restrictionP-lookup is MISSING (not implemented) - // - // Either way, we just silently return. + // The scopeVectorP-lookup is MISSING (not implemented) + // We just silently return. // return; } Scope* scopeP = new Scope(SCOPE_FILTER_EXISTENCE, SCOPE_VALUE_ENTITY_TYPE); scopeP->oper = ""; - restrictionP->scopeVector.push_back(scopeP); + scopeVectorP->push_back(scopeP); } } @@ -369,32 +315,11 @@ static void scopeFilter RestService* serviceP ) { - Restriction* restrictionP = NULL; + ScopeVector* scopeVectorP = &parseDataP->qcr.res.scopeVector; - if (ciP->restServiceP->request == DiscoverContextAvailability) + for (unsigned int ix = 0; ix < scopeVectorP->size(); ++ix) { - restrictionP = &parseDataP->dcar.res.restriction; - } - else if (ciP->restServiceP->request == QueryContext) - { - restrictionP = &parseDataP->qcr.res.restriction; - } - else if (ciP->restServiceP->request == SubscribeContext) - { - restrictionP = &parseDataP->scr.res.restriction; - } - else if (ciP->restServiceP->request == UpdateContextSubscription) - { - restrictionP = &parseDataP->ucsr.res.restriction; - } - else - { - return; - } - - for (unsigned int ix = 0; ix < restrictionP->scopeVector.size(); ++ix) - { - Scope* scopeP = restrictionP->scopeVector[ix]; + Scope* scopeP = (*scopeVectorP)[ix]; if (scopeP->type == SCOPE_FILTER_NOT_EXISTENCE) { @@ -412,19 +337,12 @@ static void scopeFilter */ static void filterRelease(ParseData* parseDataP, RequestType request) { - Restriction* restrictionP = NULL; + ScopeVector* scopeVectorP = &parseDataP->qcr.res.scopeVector; - if (request == EntityTypes) - { - restrictionP = &parseDataP->qcr.res.restriction; - } - else if (request == AllContextEntities) + if (scopeVectorP != NULL) { - restrictionP = &parseDataP->qcr.res.restriction; + scopeVectorP->release(); } - - if (restrictionP != NULL) - restrictionP->release(); } @@ -453,7 +371,6 @@ static bool compCheck(int components, const std::vector& compV) */ static bool compErrorDetect ( - ApiVersion apiVersion, int components, const std::vector& compV, OrionError* oeP @@ -461,7 +378,7 @@ static bool compErrorDetect { std::string details; - if ((apiVersion == V2) && (compV[1] == "entities")) + if ((compV[1] == "entities")) { if ((components == 4) && (compV[3] == "attrs")) // URL: /v2/entities//attrs { @@ -528,14 +445,13 @@ static std::string restService(ConnectionInfo* ciP, RestService* serviceV) { std::vector compV; int components; - JsonRequest* jsonReqP = NULL; ParseData parseData; JsonDelayedRelease jsonRelease; if ((ciP->url.empty()) || ((ciP->url.length() == 1) && (ciP->url.c_str()[0] == '/'))) { OrionError error(SccBadRequest, "The Orion Context Broker is a REST service, not a 'web page'"); - std::string response = error.toJsonV1(); + std::string response = error.toJson(); alarmMgr.badInput(clientIp, "The Orion Context Broker is a REST service, not a 'web page'"); restReply(ciP, response); @@ -554,11 +470,11 @@ static std::string restService(ConnectionInfo* ciP, RestService* serviceV) { OrionError oe; - if (compErrorDetect(ciP->apiVersion, components, compV, &oe)) + if (compErrorDetect(components, compV, &oe)) { alarmMgr.badInput(clientIp, oe.description); ciP->httpStatusCode = SccBadRequest; - restReply(ciP, oe.smartRender(ciP->apiVersion)); + restReply(ciP, oe.toJson()); return "URL PATH component error"; } } @@ -583,21 +499,10 @@ static std::string restService(ConnectionInfo* ciP, RestService* serviceV) continue; } - if (ciP->apiVersion == V1) - { - if (strcasecmp(component, compV[compNo].c_str()) != 0) - { - match = false; - break; - } - } - else + if (strcmp(component, compV[compNo].c_str()) != 0) { - if (strcmp(component, compV[compNo].c_str()) != 0) - { - match = false; - break; - } + match = false; + break; } } @@ -619,7 +524,7 @@ static std::string restService(ConnectionInfo* ciP, RestService* serviceV) ciP->parseDataP = &parseData; metricsMgr.add(ciP->httpHeaders.tenant, spath, METRIC_TRANS_IN_REQ_SIZE, ciP->payloadSize); LM_T(LmtPayload, ("Parsing payload '%s'", ciP->payload)); - response = payloadParse(ciP, &parseData, &serviceV[ix], &jsonReqP, &jsonRelease, compV); + response = payloadParse(ciP, &parseData, &serviceV[ix], &jsonRelease, compV); LM_T(LmtParsedPayload, ("payloadParse returns '%s'", response.c_str())); if (response != "OK") @@ -627,15 +532,7 @@ static std::string restService(ConnectionInfo* ciP, RestService* serviceV) alarmMgr.badInput(clientIp, response); restReply(ciP, response); - if (jsonReqP != NULL) - { - jsonReqP->release(&parseData); - } - - if (ciP->apiVersion == V2) - { - delayedRelease(&jsonRelease); - } + delayedRelease(&jsonRelease); compV.clear(); return response; @@ -661,24 +558,14 @@ static std::string restService(ConnectionInfo* ciP, RestService* serviceV) { OrionError oe(SccBadRequest, result); - std::string response = oe.setStatusCodeAndSmartRender(ciP->apiVersion, &(ciP->httpStatusCode)); + std::string response = oe.setSCAndRender(&(ciP->httpStatusCode)); alarmMgr.badInput(clientIp, result); - restReply(ciP, response); - if (jsonReqP != NULL) - { - jsonReqP->release(&parseData); - } - - if (ciP->apiVersion == V2) - { - delayedRelease(&jsonRelease); - } + delayedRelease(&jsonRelease); compV.clear(); - return response; } @@ -701,15 +588,7 @@ static std::string restService(ConnectionInfo* ciP, RestService* serviceV) filterRelease(&parseData, serviceV[ix].request); - if (jsonReqP != NULL) - { - jsonReqP->release(&parseData); - } - - if (ciP->apiVersion == V2) - { - delayedRelease(&jsonRelease); - } + delayedRelease(&jsonRelease); compV.clear(); @@ -749,9 +628,9 @@ static std::string restService(ConnectionInfo* ciP, RestService* serviceV) // ... and this here is the error that is returned. A 400 Bad Request with "service XXX not recognized" as payload // std::string details = std::string("service '") + ciP->url + "' not recognized"; - std::string answer; - restErrorReplyGet(ciP, SccBadRequest, ERROR_DESC_BAD_REQUEST_SERVICE_NOT_FOUND, &answer); + OrionError oe(SccBadRequest, ERROR_DESC_BAD_REQUEST_SERVICE_NOT_FOUND, ERROR_BAD_REQUEST); + std::string answer = oe.toJson(); alarmMgr.badInput(clientIp, details); ciP->httpStatusCode = SccBadRequest; restReply(ciP, answer); diff --git a/src/lib/rest/RestService.h b/src/lib/rest/RestService.h index 20d229a173..b6fe67faf4 100644 --- a/src/lib/rest/RestService.h +++ b/src/lib/rest/RestService.h @@ -31,7 +31,6 @@ #include "rest/ConnectionInfo.h" #include "ngsi/ParseData.h" #include "ngsi/Request.h" -#include "jsonParse/jsonRequest.h" #include "jsonParseV2/jsonRequestTreat.h" @@ -76,7 +75,6 @@ extern std::string payloadParse ConnectionInfo* ciP, ParseData* parseDataP, RestService* service, - JsonRequest** jsonPP, JsonDelayedRelease* jsonReleaseP, std::vector& compV ); diff --git a/src/lib/rest/orionLogReply.cpp b/src/lib/rest/orionLogReply.cpp index 322ad9e14f..851897f335 100644 --- a/src/lib/rest/orionLogReply.cpp +++ b/src/lib/rest/orionLogReply.cpp @@ -24,7 +24,6 @@ */ #include -#include "common/tag.h" #include "rest/ConnectionInfo.h" #include "rest/restReply.h" @@ -36,11 +35,10 @@ */ std::string orionLogReply(ConnectionInfo* ciP, const std::string& what, const std::string& value) { - std::string out = ""; + JsonObjectHelper jh; - out += '{'; - out += valueTag(what, value); - out += '}'; + jh.addString(what, value); + std::string out = jh.str(); ciP->httpStatusCode = SccOk; restReply(ciP, out); diff --git a/src/lib/rest/rest.cpp b/src/lib/rest/rest.cpp index f0ce3fc4c0..f3c70f8e25 100644 --- a/src/lib/rest/rest.cpp +++ b/src/lib/rest/rest.cpp @@ -43,7 +43,6 @@ #include "common/defaultValues.h" #include "common/clockFunctions.h" #include "common/statistics.h" -#include "common/tag.h" #include "common/limits.h" // SERVICE_NAME_MAX_LEN #include "common/logTracing.h" @@ -118,17 +117,9 @@ static MHD_Result uriArgumentGet(void* cbDataP, MHD_ValueKind kind, const char* { std::string errorString = std::string("Empty right-hand-side for URI param /") + ckey + "/"; - if (ciP->apiVersion == V2) - { - OrionError error(SccBadRequest, errorString); - ciP->httpStatusCode = error.code; - ciP->answer = error.smartRender(ciP->apiVersion); - } - else if (ciP->apiVersion == ADMIN_API) - { - ciP->httpStatusCode = SccBadRequest; - ciP->answer = "{" + JSON_STR("error") + ":" + JSON_STR(errorString) + "}"; - } + OrionError error(SccBadRequest, errorString); + ciP->httpStatusCode = error.code; + ciP->answer = error.toJson(); return MHD_YES; } @@ -143,7 +134,7 @@ static MHD_Result uriArgumentGet(void* cbDataP, MHD_ValueKind kind, const char* { OrionError error(SccBadRequest, std::string("Bad pagination offset: /") + value + "/ [must be a decimal number]"); ciP->httpStatusCode = error.code; - ciP->answer = error.smartRender(ciP->apiVersion); + ciP->answer = error.toJson(); return MHD_YES; } @@ -160,7 +151,7 @@ static MHD_Result uriArgumentGet(void* cbDataP, MHD_ValueKind kind, const char* { OrionError error(SccBadRequest, std::string("Bad pagination limit: /") + value + "/ [must be a positive integer number]"); ciP->httpStatusCode = error.code; - ciP->answer = error.smartRender(ciP->apiVersion); + ciP->answer = error.toJson(); return MHD_YES; } @@ -172,17 +163,7 @@ static MHD_Result uriArgumentGet(void* cbDataP, MHD_ValueKind kind, const char* { OrionError error(SccBadRequest, std::string("Bad pagination limit: /") + value + "/ [max: " + MAX_PAGINATION_LIMIT + "]"); ciP->httpStatusCode = error.code; - ciP->answer = error.smartRender(ciP->apiVersion); - return MHD_YES; - } - } - else if (key == URI_PARAM_PAGINATION_DETAILS) - { - if ((strcasecmp(value.c_str(), "on") != 0) && (strcasecmp(value.c_str(), "off") != 0)) - { - OrionError error(SccBadRequest, std::string("Bad value for /details/: /") + value + "/ [accepted: /on/, /ON/, /off/, /OFF/. Default is /off/]"); - ciP->httpStatusCode = error.code; - ciP->answer = error.smartRender(ciP->apiVersion); + ciP->answer = error.toJson(); return MHD_YES; } } @@ -204,7 +185,7 @@ static MHD_Result uriArgumentGet(void* cbDataP, MHD_ValueKind kind, const char* { OrionError error(SccBadRequest, "Invalid value for URI param /options/"); ciP->httpStatusCode = error.code; - ciP->answer = error.smartRender(ciP->apiVersion); + ciP->answer = error.toJson(); } } else if (key == URI_PARAM_TYPE) @@ -267,7 +248,7 @@ static MHD_Result uriArgumentGet(void* cbDataP, MHD_ValueKind kind, const char* alarmMgr.badInput(clientIp, details); ciP->httpStatusCode = error.code; - ciP->answer = error.smartRender(ciP->apiVersion); + ciP->answer = error.toJson(); } return MHD_YES; @@ -479,7 +460,7 @@ static void acceptParse(ConnectionInfo* ciP, const char* value) { OrionError oe(ciP->httpStatusCode, ciP->acceptHeaderError); - ciP->answer = oe.smartRender(ciP->apiVersion); + ciP->answer = oe.toJson(); } } @@ -612,7 +593,6 @@ static void requestCompleted clock_subtime(&threadLastTimeStat.mongoBackendTime, &threadLastTimeStat.mongoWriteWaitTime); clock_subtime(&threadLastTimeStat.mongoBackendTime, &threadLastTimeStat.mongoCommandWaitTime); - clock_addtime(&accTimeStat.jsonV1ParseTime, &threadLastTimeStat.jsonV1ParseTime); clock_addtime(&accTimeStat.jsonV2ParseTime, &threadLastTimeStat.jsonV2ParseTime); clock_addtime(&accTimeStat.mongoBackendTime, &threadLastTimeStat.mongoBackendTime); clock_addtime(&accTimeStat.mongoWriteWaitTime, &threadLastTimeStat.mongoWriteWaitTime); @@ -704,14 +684,14 @@ int servicePathCheck(ConnectionInfo* ciP, const char* servicePath) if (servicePath[0] != '/') { OrionError oe(SccBadRequest, "Only /absolute/ Service Paths allowed [a service path must begin with /]"); - ciP->answer = oe.setStatusCodeAndSmartRender(ciP->apiVersion, &(ciP->httpStatusCode)); + ciP->answer = oe.setSCAndRender(&(ciP->httpStatusCode)); return 1; } if (servicePath[1] == '/') { OrionError oe(SccBadRequest, "empty component in ServicePath"); - ciP->answer = oe.setStatusCodeAndSmartRender(ciP->apiVersion, &(ciP->httpStatusCode)); + ciP->answer = oe.setSCAndRender(&(ciP->httpStatusCode)); return 1; } @@ -720,13 +700,13 @@ int servicePathCheck(ConnectionInfo* ciP, const char* servicePath) if (ciP->verb == PATCH) { OrionError oe(SccBadRequest, "more than one servicepath in patch update request is not allowed"); - ciP->answer = oe.setStatusCodeAndSmartRender(ciP->apiVersion, &(ciP->httpStatusCode)); + ciP->answer = oe.setSCAndRender(&(ciP->httpStatusCode)); return 1; } if (ciP->verb == DELETE) { OrionError oe(SccBadRequest, "more than one servicepath is not allowed in DELETE operation"); - ciP->answer = oe.setStatusCodeAndSmartRender(ciP->apiVersion, &(ciP->httpStatusCode)); + ciP->answer = oe.setSCAndRender(&(ciP->httpStatusCode)); return 1; } } @@ -736,7 +716,7 @@ int servicePathCheck(ConnectionInfo* ciP, const char* servicePath) if (components > SERVICE_PATH_MAX_LEVELS) { OrionError oe(SccBadRequest, "too many components in ServicePath"); - ciP->answer = oe.setStatusCodeAndSmartRender(ciP->apiVersion, &(ciP->httpStatusCode)); + ciP->answer = oe.setSCAndRender(&(ciP->httpStatusCode)); return 2; } @@ -745,14 +725,14 @@ int servicePathCheck(ConnectionInfo* ciP, const char* servicePath) if (strlen(compV[ix].c_str()) > SERVICE_PATH_MAX_COMPONENT_LEN) { OrionError oe(SccBadRequest, "component-name too long in ServicePath"); - ciP->answer = oe.setStatusCodeAndSmartRender(ciP->apiVersion, &(ciP->httpStatusCode)); + ciP->answer = oe.setSCAndRender(&(ciP->httpStatusCode)); return 3; } if (compV[ix].c_str()[0] == 0) { OrionError oe(SccBadRequest, "empty component in ServicePath"); - ciP->answer = oe.setStatusCodeAndSmartRender(ciP->apiVersion, &(ciP->httpStatusCode)); + ciP->answer = oe.setSCAndRender(&(ciP->httpStatusCode)); return 3; } @@ -764,13 +744,13 @@ int servicePathCheck(ConnectionInfo* ciP, const char* servicePath) if (ciP->verb == PATCH) { OrionError oe(SccBadRequest, "servicepath with wildcard # is not allowed in patch update request"); - ciP->answer = oe.setStatusCodeAndSmartRender(ciP->apiVersion, &(ciP->httpStatusCode)); + ciP->answer = oe.setSCAndRender(&(ciP->httpStatusCode)); return 3; } else if (ciP->verb == DELETE) { OrionError oe(SccBadRequest, "servicepath with wildcard # is not allowed in DELETE operation"); - ciP->answer = oe.setStatusCodeAndSmartRender(ciP->apiVersion, &(ciP->httpStatusCode)); + ciP->answer = oe.setSCAndRender(&(ciP->httpStatusCode)); return 3; } else @@ -786,7 +766,7 @@ int servicePathCheck(ConnectionInfo* ciP, const char* servicePath) if (!isalnum(comp[cIx]) && (comp[cIx] != '_')) { OrionError oe(SccBadRequest, "a component of ServicePath contains an illegal character"); - ciP->answer = oe.setStatusCodeAndSmartRender(ciP->apiVersion, &(ciP->httpStatusCode)); + ciP->answer = oe.setSCAndRender(&(ciP->httpStatusCode)); return 4; } } @@ -899,7 +879,7 @@ int servicePathSplit(ConnectionInfo* ciP) if (servicePaths > SERVICE_PATH_MAX_COMPONENTS) { OrionError e(SccBadRequest, "too many service paths - a maximum of ten service paths is allowed"); - ciP->answer = e.toJsonV1(); + ciP->answer = e.toJson(); if (servicePathCopy != NULL) { @@ -982,30 +962,18 @@ static int contentTypeCheck(ConnectionInfo* ciP) if (ciP->httpHeaders.contentType.empty()) { std::string details = "Content-Type header not used, default application/octet-stream is not supported"; + OrionError oe(SccUnsupportedMediaType, details); + ciP->answer = oe.toJson(); ciP->httpStatusCode = SccUnsupportedMediaType; - restErrorReplyGet(ciP, SccUnsupportedMediaType, details, &ciP->answer); - ciP->httpStatusCode = SccUnsupportedMediaType; - return 1; } // Case 3 - if ((ciP->apiVersion == V1) && (ciP->httpHeaders.contentType != "application/json")) + if ((ciP->httpHeaders.contentType != "application/json") && (ciP->httpHeaders.contentType != "text/plain")) { std::string details = std::string("not supported content type: ") + ciP->httpHeaders.contentType; - ciP->httpStatusCode = SccUnsupportedMediaType; - restErrorReplyGet(ciP, SccUnsupportedMediaType, details, &ciP->answer); - ciP->httpStatusCode = SccUnsupportedMediaType; - return 1; - } - - - // Case 4 - if ((ciP->apiVersion == V2) && (ciP->httpHeaders.contentType != "application/json") && (ciP->httpHeaders.contentType != "text/plain")) - { - std::string details = std::string("not supported content type: ") + ciP->httpHeaders.contentType; - ciP->httpStatusCode = SccUnsupportedMediaType; - restErrorReplyGet(ciP, SccUnsupportedMediaType, details, &ciP->answer); + OrionError oe(SccUnsupportedMediaType, details); + ciP->answer = oe.toJson(); ciP->httpStatusCode = SccUnsupportedMediaType; return 1; } @@ -1029,7 +997,7 @@ bool urlCheck(ConnectionInfo* ciP, const std::string& url) { OrionError error(SccBadRequest, ERROR_DESC_BAD_REQUEST_INVALID_CHAR_URI); ciP->httpStatusCode = error.code; - ciP->answer = error.smartRender(ciP->apiVersion); + ciP->answer = error.toJson(); return false; } @@ -1047,56 +1015,6 @@ bool urlCheck(ConnectionInfo* ciP, const std::string& url) -/* **************************************************************************** -* -* apiVersionGet - -* -* This function returns the version of the API for the incoming message, -* based on the URL according to: -* -* V2: for URLs in the /v2 path -* V1: for URLs in the /v1 or with an equivalence (e.g. /ngi10, /log, etc.) -* ADMIN_API: admin operations without /v1 alias -* NO_VERSION: others (invalid paths) -* -*/ -static ApiVersion apiVersionGet(const char* path) -{ - if ((path[1] == 'v') && (path[2] == '2')) - { - return V2; - } - - // Unlike v2, v1 is case-insensitive (see case/2057 test) - if (((path[1] == 'v') || (path[1] == 'V')) && (path[2] == '1')) - { - return V1; - } - - if ((strncasecmp("/ngsi9", path, strlen("/ngsi9")) == 0) || - (strncasecmp("/ngsi10", path, strlen("/ngsi10")) == 0)) - { - return V1; - } - - if ((strncasecmp("/log", path, strlen("/log")) == 0) || - (strncasecmp("/cache", path, strlen("/cache")) == 0) || - (strncasecmp("/statistics", path, strlen("/statistics")) == 0)) - { - return V1; - } - - if ((strncmp("/admin", path, strlen("/admin")) == 0) || - (strncmp("/version", path, strlen("/version")) == 0)) - { - return ADMIN_API; - } - - return NO_VERSION; -} - - - /* **************************************************************************** * * acceptHeadersAcceptable - @@ -1307,14 +1225,6 @@ static MHD_Result connectionTreat return MHD_NO; } - - // Get API version - // FIXME #3109-PR: this assignment will be removed in a subsequent PR, where the function apiVersionGet() is used instead - // - ciP->apiVersion = (url[2] == '2')? V2 : V1; // If an APIv2 request, the URL starts with "/v2/". Only V2 requests. - - // LM_TMP(("--------------------- Serving APIv%d request %s %s -----------------", ciP->apiVersion, method, url)); - // Lookup Rest Service bool badVerb = false; ciP->restServiceP = restServiceLookup(ciP, &badVerb); @@ -1356,12 +1266,6 @@ static MHD_Result connectionTreat // ciP->uriParam[URI_PARAM_PAGINATION_OFFSET] = DEFAULT_PAGINATION_OFFSET; ciP->uriParam[URI_PARAM_PAGINATION_LIMIT] = DEFAULT_PAGINATION_LIMIT; - ciP->uriParam[URI_PARAM_PAGINATION_DETAILS] = DEFAULT_PAGINATION_DETAILS; - - // Note that we need to get API version before MHD_get_connection_values() as the later - // function may result in an error after processing Accept headers (and the - // render for the error depends on API version) - ciP->apiVersion = apiVersionGet(ciP->url.c_str()); MHD_get_connection_values(connection, MHD_HEADER_KIND, httpHeaderGet, ciP); @@ -1383,7 +1287,7 @@ static MHD_Result connectionTreat ciP->httpHeader.push_back(HTTP_FIWARE_CORRELATOR); ciP->httpHeaderValue.push_back(ciP->httpHeaders.correlator); - if ((ciP->httpHeaders.contentLength > inReqPayloadMaxSize) && (ciP->apiVersion == V2)) + if ((ciP->httpHeaders.contentLength > inReqPayloadMaxSize)) { char details[256]; snprintf(details, sizeof(details), "payload size: %d, max size supported: %llu", ciP->httpHeaders.contentLength, inReqPayloadMaxSize); @@ -1392,7 +1296,7 @@ static MHD_Result connectionTreat OrionError oe(SccRequestEntityTooLarge, details); ciP->httpStatusCode = oe.code; - restReply(ciP, oe.smartRender(ciP->apiVersion)); + restReply(ciP, oe.toJson()); return MHD_YES; } @@ -1536,8 +1440,8 @@ static MHD_Result connectionTreat snprintf(details, sizeof(details), "payload size: %d, max size supported: %llu", ciP->httpHeaders.contentLength, inReqPayloadMaxSize); alarmMgr.badInput(clientIp, details); - restErrorReplyGet(ciP, SccRequestEntityTooLarge, details, &ciP->answer); - + OrionError oe(SccRequestEntityTooLarge, details); + ciP->answer = oe.toJson(); ciP->httpStatusCode = SccRequestEntityTooLarge; } @@ -1551,7 +1455,7 @@ static MHD_Result connectionTreat ciP->httpStatusCode = oe.code; alarmMgr.badInput(clientIp, ciP->acceptHeaderError); - restReply(ciP, oe.smartRender(ciP->apiVersion)); + restReply(ciP, oe.toJson()); return MHD_YES; } @@ -1575,7 +1479,7 @@ static MHD_Result connectionTreat ciP->httpStatusCode = oe.code; alarmMgr.badInput(clientIp, oe.description); - restReply(ciP, oe.smartRender(ciP->apiVersion)); + restReply(ciP, oe.toJson()); return MHD_YES; } @@ -1601,7 +1505,7 @@ static MHD_Result connectionTreat ciP->httpStatusCode = oe.code; alarmMgr.badInput(clientIp, oe.description); - restReply(ciP, oe.smartRender(ciP->apiVersion)); + restReply(ciP, oe.toJson()); return MHD_YES; } @@ -1616,7 +1520,7 @@ static MHD_Result connectionTreat ciP->httpStatusCode = oe.code; alarmMgr.badInput(clientIp, details); - restReply(ciP, oe.smartRender(ciP->apiVersion)); + restReply(ciP, oe.toJson()); return MHD_YES; } @@ -1631,9 +1535,8 @@ static MHD_Result connectionTreat (ciP->httpHeaders.contentLength == 0) && ((strncasecmp(ciP->url.c_str(), "/log/", 5) != 0) && (strncasecmp(ciP->url.c_str(), "/admin/log", 10) != 0))) { - std::string errorMsg; - - restErrorReplyGet(ciP, SccContentLengthRequired, "Zero/No Content-Length in PUT/POST/PATCH request", &errorMsg); + OrionError oe(SccContentLengthRequired, "Zero/No Content-Length in PUT/POST/PATCH request"); + std::string errorMsg = oe.toJson(); ciP->httpStatusCode = SccContentLengthRequired; restReply(ciP, errorMsg); alarmMgr.badInput(clientIp, errorMsg); diff --git a/src/lib/rest/restReply.cpp b/src/lib/rest/restReply.cpp index 9934a03324..dae9891410 100644 --- a/src/lib/rest/restReply.cpp +++ b/src/lib/rest/restReply.cpp @@ -28,17 +28,10 @@ #include "common/MimeType.h" #include "common/limits.h" -#include "ngsi/StatusCode.h" #include "metricsMgr/metricsMgr.h" -#include "ngsi9/DiscoverContextAvailabilityResponse.h" -#include "ngsi9/RegisterContextResponse.h" - #include "ngsi10/QueryContextResponse.h" -#include "ngsi10/SubscribeContextResponse.h" -#include "ngsi10/UnsubscribeContextResponse.h" #include "ngsi10/UpdateContextResponse.h" -#include "ngsi10/UpdateContextSubscriptionResponse.h" #include "ngsi10/NotifyContextResponse.h" #include "rest/rest.h" @@ -102,44 +95,41 @@ void restReply(ConnectionInfo* ciP, const std::string& answer) } // Check if CORS is enabled, the Origin header is present in the request and the response is not a bad verb response - if ((corsEnabled == true) && (!ciP->httpHeaders.origin.empty()) && (ciP->httpStatusCode != SccBadVerb)) + // Only for NGSIv2 methods (this exclusdes eg. "GET /version") + if ((corsEnabled == true) && (!ciP->httpHeaders.origin.empty()) && (ciP->httpStatusCode != SccBadVerb) && (ciP->url.compare(0, 3, "/v2") == 0)) { - // Only GET method is supported for V1 API - if ((ciP->apiVersion == V2) || (ciP->apiVersion == V1 && ciP->verb == GET)) + bool originAllowed = true; + + // If any origin is allowed, the header is sent always with "any" as value + if (strcmp(corsOrigin, "__ALL") == 0) + { + MHD_add_response_header(response, HTTP_ACCESS_CONTROL_ALLOW_ORIGIN, "*"); + } + // If a specific origin is allowed, the header is only sent if the origins match + else if (strcmp(ciP->httpHeaders.origin.c_str(), corsOrigin) == 0) + { + MHD_add_response_header(response, HTTP_ACCESS_CONTROL_ALLOW_ORIGIN, corsOrigin); + } + // If there is no match, originAllowed flag is set to false + else { - bool originAllowed = true; + originAllowed = false; + } - // If any origin is allowed, the header is sent always with "any" as value - if (strcmp(corsOrigin, "__ALL") == 0) - { - MHD_add_response_header(response, HTTP_ACCESS_CONTROL_ALLOW_ORIGIN, "*"); - } - // If a specific origin is allowed, the header is only sent if the origins match - else if (strcmp(ciP->httpHeaders.origin.c_str(), corsOrigin) == 0) - { - MHD_add_response_header(response, HTTP_ACCESS_CONTROL_ALLOW_ORIGIN, corsOrigin); - } - // If there is no match, originAllowed flag is set to false - else - { - originAllowed = false; - } + // If the origin is not allowed, no headers are added to the response + if (originAllowed) + { + // Add Access-Control-Expose-Headers to the response + MHD_add_response_header(response, HTTP_ACCESS_CONTROL_EXPOSE_HEADERS, CORS_EXPOSED_HEADERS); - // If the origin is not allowed, no headers are added to the response - if (originAllowed) + if (ciP->verb == OPTIONS) { - // Add Access-Control-Expose-Headers to the response - MHD_add_response_header(response, HTTP_ACCESS_CONTROL_EXPOSE_HEADERS, CORS_EXPOSED_HEADERS); - - if (ciP->verb == OPTIONS) - { - MHD_add_response_header(response, HTTP_ACCESS_CONTROL_ALLOW_HEADERS, CORS_ALLOWED_HEADERS); + MHD_add_response_header(response, HTTP_ACCESS_CONTROL_ALLOW_HEADERS, CORS_ALLOWED_HEADERS); - char maxAge[STRING_SIZE_FOR_INT]; - snprintf(maxAge, sizeof(maxAge), "%d", corsMaxAge); + char maxAge[STRING_SIZE_FOR_INT]; + snprintf(maxAge, sizeof(maxAge), "%d", corsMaxAge); - MHD_add_response_header(response, HTTP_ACCESS_CONTROL_MAX_AGE, maxAge); - } + MHD_add_response_header(response, HTTP_ACCESS_CONTROL_MAX_AGE, maxAge); } } } @@ -148,73 +138,3 @@ void restReply(ConnectionInfo* ciP, const std::string& answer) MHD_destroy_response(response); } - - -/* **************************************************************************** -* -* restErrorReplyGet - -* -* This function renders an error reply depending on the type of the request (ciP->restServiceP->request). -* -* The function is called from more than one place, especially from -* restErrorReply(), but also from where the payload type is matched against the request URL. -* Where the payload type is matched against the request URL, the incoming 'request' is a -* request and not a response. -*/ -void restErrorReplyGet(ConnectionInfo* ciP, HttpStatusCode code, const std::string& details, std::string* outStringP) -{ - StatusCode errorCode(code, details, "errorCode"); - - ciP->httpStatusCode = SccOk; - - if (ciP->restServiceP->request == RegisterContext) - { - RegisterContextResponse rcr("000000000000000000000000", errorCode); - *outStringP = rcr.toJsonV1(); - } - else if (ciP->restServiceP->request == DiscoverContextAvailability) - { - DiscoverContextAvailabilityResponse dcar(errorCode); - *outStringP = dcar.toJsonV1(); - } - else if (ciP->restServiceP->request == QueryContext) - { - QueryContextResponse qcr(errorCode); - bool asJsonObject = (ciP->uriParam[URI_PARAM_ATTRIBUTE_FORMAT] == "object" && ciP->outMimeType == JSON); - *outStringP = qcr.toJsonV1(asJsonObject); - } - else if (ciP->restServiceP->request == SubscribeContext) - { - SubscribeContextResponse scr(errorCode); - *outStringP = scr.toJsonV1(); - } - else if ((ciP->restServiceP->request == UpdateContextSubscription) || (ciP->restServiceP->request == Ngsi10SubscriptionsConvOp)) - { - UpdateContextSubscriptionResponse ucsr(errorCode); - *outStringP = ucsr.toJsonV1(); - } - else if (ciP->restServiceP->request == UnsubscribeContext) - { - UnsubscribeContextResponse uncr(errorCode); - *outStringP = uncr.toJsonV1(); - } - else if (ciP->restServiceP->request == UpdateContext) - { - UpdateContextResponse ucr(errorCode); - bool asJsonObject = (ciP->uriParam[URI_PARAM_ATTRIBUTE_FORMAT] == "object" && ciP->outMimeType == JSON); - *outStringP = ucr.toJsonV1(asJsonObject); - } - else if (ciP->restServiceP->request == NotifyContext) - { - NotifyContextResponse ncr(errorCode); - *outStringP = ncr.toJsonV1(); - } - else - { - OrionError oe(errorCode); - - LM_T(LmtRest, ("Unknown request type: '%d'", ciP->restServiceP->request)); - ciP->httpStatusCode = oe.code; - *outStringP = oe.setStatusCodeAndSmartRender(ciP->apiVersion, &ciP->httpStatusCode); - } -} diff --git a/src/lib/rest/restReply.h b/src/lib/rest/restReply.h index 3272087472..7b58eb64a9 100644 --- a/src/lib/rest/restReply.h +++ b/src/lib/rest/restReply.h @@ -40,10 +40,4 @@ extern void restReply(ConnectionInfo* ciP, const std::string& answer); -/* **************************************************************************** -* -* restErrorReplyGet - -*/ -extern void restErrorReplyGet(ConnectionInfo* ciP, HttpStatusCode code, const std::string& detail, std::string* outStringP); - #endif diff --git a/src/lib/rest/restServiceLookup.cpp b/src/lib/rest/restServiceLookup.cpp index 888b91783b..0e471fcdbb 100644 --- a/src/lib/rest/restServiceLookup.cpp +++ b/src/lib/rest/restServiceLookup.cpp @@ -71,21 +71,10 @@ RestService* restServiceLookup(ConnectionInfo* ciP, bool* badVerbP) continue; } - if (ciP->apiVersion == V1) + if (strcmp(component, compV[compNo].c_str()) != 0) { - if (strcasecmp(component, compV[compNo].c_str()) != 0) - { - match = false; - break; - } - } - else - { - if (strcmp(component, compV[compNo].c_str()) != 0) - { - match = false; - break; - } + match = false; + break; } } diff --git a/src/lib/rest/uriParamNames.h b/src/lib/rest/uriParamNames.h index 4e99db831c..6badb38dd6 100644 --- a/src/lib/rest/uriParamNames.h +++ b/src/lib/rest/uriParamNames.h @@ -35,7 +35,6 @@ */ #define URI_PARAM_PAGINATION_OFFSET "offset" #define URI_PARAM_PAGINATION_LIMIT "limit" -#define URI_PARAM_PAGINATION_DETAILS "details" #define URI_PARAM_COLLAPSE "collapse" #define URI_PARAM_ENTITY_TYPE SCOPE_VALUE_ENTITY_TYPE #define URI_PARAM_NOT_EXIST "!exist" @@ -66,6 +65,4 @@ #define DEFAULT_PAGINATION_OFFSET "0" #define DEFAULT_PAGINATION_OFFSET_INT 0 -#define DEFAULT_PAGINATION_DETAILS "off" - #endif diff --git a/src/lib/serviceRoutines/CMakeLists.txt b/src/lib/serviceRoutines/CMakeLists.txt index 9b9c8d6a4d..b9fa7db560 100644 --- a/src/lib/serviceRoutines/CMakeLists.txt +++ b/src/lib/serviceRoutines/CMakeLists.txt @@ -25,66 +25,18 @@ versionTreat.cpp exitTreat.cpp leakTreat.cpp logTraceTreat.cpp -postRegisterContext.cpp -postDiscoverContextAvailability.cpp -getContextEntitiesByEntityId.cpp postUpdateContext.cpp postQueryContext.cpp -postSubscribeContext.cpp -postUpdateContextSubscription.cpp -postUnsubscribeContext.cpp -postContextEntitiesByEntityId.cpp -getContextEntityAttributes.cpp -postContextEntityAttributes.cpp -getEntityByIdAttributeByName.cpp -postEntityByIdAttributeByName.cpp -getContextEntityTypes.cpp -postContextEntityTypes.cpp -getContextEntityTypeAttribute.cpp -postContextEntityTypeAttribute.cpp -getIndividualContextEntity.cpp -putIndividualContextEntity.cpp -postIndividualContextEntity.cpp -putIndividualContextEntityAttribute.cpp -getIndividualContextEntityAttribute.cpp -postIndividualContextEntityAttribute.cpp -deleteIndividualContextEntityAttribute.cpp -deleteIndividualContextEntity.cpp -getNgsi10ContextEntityTypes.cpp -getNgsi10ContextEntityTypesAttribute.cpp -putSubscriptionConvOp.cpp -deleteSubscriptionConvOp.cpp badVerbPostOnly.cpp -badVerbAllFour.cpp -badVerbAllFive.cpp badVerbGetPostOnly.cpp -badVerbGetPostDeleteOnly.cpp badVerbGetOnly.cpp badVerbGetDeleteOnly.cpp badVerbPutDeleteOnly.cpp badVerbGetPutDeleteOnly.cpp badVerbPutOnly.cpp -badNgsi9Request.cpp -badNgsi10Request.cpp badRequest.cpp postNotifyContext.cpp statisticsTreat.cpp -getEntityTypes.cpp -getAttributesForEntityType.cpp -getAllContextEntities.cpp -getAllEntitiesWithTypeAndId.cpp -postAllEntitiesWithTypeAndId.cpp -putAllEntitiesWithTypeAndId.cpp -deleteAllEntitiesWithTypeAndId.cpp -getIndividualContextEntityAttributeWithTypeAndId.cpp -deleteIndividualContextEntityAttributeWithTypeAndId.cpp -postIndividualContextEntityAttributeWithTypeAndId.cpp -putIndividualContextEntityAttributeWithTypeAndId.cpp -getContextEntitiesByEntityIdAndType.cpp -postContextEntitiesByEntityIdAndType.cpp -getEntityByIdAttributeByNameWithTypeAndId.cpp -postEntityByIdAttributeByNameWithTypeAndId.cpp -postSubscribeContextConvOp.cpp optionsVersionRequest.cpp ) @@ -92,61 +44,18 @@ SET (HEADERS versionTreat.h exitTreat.h logTraceTreat.h -postRegisterContext.h -postDiscoverContextAvailability.h -getContextEntitiesByEntityId.h postUpdateContext.h postQueryContext.h -postSubscribeContext.h -postUpdateContextSubscription.h -postUnsubscribeContext.h -postContextEntitiesByEntityId.h -getContextEntityAttributes.h -postContextEntityAttributes.h -getEntityByIdAttributeByName.h -postEntityByIdAttributeByName.h -getContextEntityTypes.h -postContextEntityTypes.h -getContextEntityTypeAttribute.h -postContextEntityTypeAttribute.h -getIndividualContextEntity.h -putIndividualContextEntity.h -postIndividualContextEntity.h -putIndividualContextEntityAttribute.h -getIndividualContextEntityAttribute.h -postIndividualContextEntityAttribute.h -deleteIndividualContextEntityAttribute.h -deleteIndividualContextEntity.h -getNgsi10ContextEntityTypes.h badVerbPostOnly.h -badVerbAllFour.h -badVerbAllFive.h badVerbGetPostOnly.h -badVerbGetPostDeleteOnly.h badVerbGetOnly.h badVerbGetDeleteOnly.h badVerbPutDeleteOnly.h badVerbGetPutDeleteOnly.h badVerbPutOnly.h -# FIXME: disable NGSI9 API routes in Orion 3.8.0, to be definetively removed at some point of the future -# (along with badNgsi9Request.h|cpp files themselves) -#badNgsi9Request.h -badNgsi10Request.h badRequest.h postNotifyContext.h statisticsTreat.h -getEntityTypes.h -getAttributesForEntityType.h -getAllContextEntities.h -getIndividualContextEntityAttributeWithTypeAndId.h -deleteIndividualContextEntityAttributeWithTypeAndId.h -postIndividualContextEntityAttributeWithTypeAndId.h -putIndividualContextEntityAttributeWithTypeAndId.h -getContextEntitiesByEntityIdAndType.h -postContextEntitiesByEntityIdAndType.h -getEntityByIdAttributeByNameWithTypeAndId.h -postEntityByIdAttributeByNameWithTypeAndId.h -postSubscribeContextConvOp.h optionsVersionRequest.h ) diff --git a/src/lib/serviceRoutines/badNgsi10Request.cpp b/src/lib/serviceRoutines/badNgsi10Request.cpp deleted file mode 100644 index 56617446bc..0000000000 --- a/src/lib/serviceRoutines/badNgsi10Request.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" -#include "common/errorMessages.h" -#include "alarmMgr/alarmMgr.h" -#include "ngsi/ParseData.h" -#include "rest/ConnectionInfo.h" -#include "rest/restReply.h" -#include "serviceRoutines/badNgsi10Request.h" - - - -/* **************************************************************************** -* -* badNgsi10Request - -*/ -std::string badNgsi10Request -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -) -{ - std::string answer; - std::string details = std::string("service '") + ciP->url + "' not found"; - - alarmMgr.badInput(clientIp, details); - restErrorReplyGet(ciP, SccBadRequest, ERROR_DESC_BAD_REQUEST_SERVICE_NOT_FOUND, &answer); - - return answer; -} diff --git a/src/lib/serviceRoutines/badNgsi10Request.h b/src/lib/serviceRoutines/badNgsi10Request.h deleted file mode 100644 index 0c7d81b1fe..0000000000 --- a/src/lib/serviceRoutines/badNgsi10Request.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef SRC_LIB_SERVICEROUTINES_BADNGSI10REQUEST_H_ -#define SRC_LIB_SERVICEROUTINES_BADNGSI10REQUEST_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "rest/ConnectionInfo.h" -#include "ngsi/ParseData.h" - - - -/* **************************************************************************** -* -* badNgsi10Request - -*/ -extern std::string badNgsi10Request -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -); - -#endif // SRC_LIB_SERVICEROUTINES_BADNGSI10REQUEST_H_ diff --git a/src/lib/serviceRoutines/badNgsi9Request.cpp b/src/lib/serviceRoutines/badNgsi9Request.cpp deleted file mode 100644 index d47e861f2a..0000000000 --- a/src/lib/serviceRoutines/badNgsi9Request.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" -#include "common/errorMessages.h" -#include "alarmMgr/alarmMgr.h" -#include "ngsi/ParseData.h" -#include "rest/ConnectionInfo.h" -#include "rest/restReply.h" -#include "serviceRoutines/badNgsi9Request.h" - - - -/* **************************************************************************** -* -* badNgsi9Request - -*/ -std::string badNgsi9Request -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -) -{ - std::string details = std::string("service '") + ciP->url + "' not found"; - std::string answer; - - alarmMgr.badInput(clientIp, details); - - restErrorReplyGet(ciP, SccBadRequest, ERROR_DESC_BAD_REQUEST_SERVICE_NOT_FOUND, &answer); - - return answer; -} diff --git a/src/lib/serviceRoutines/badRequest.cpp b/src/lib/serviceRoutines/badRequest.cpp index 57ed2c75a3..2928892923 100644 --- a/src/lib/serviceRoutines/badRequest.cpp +++ b/src/lib/serviceRoutines/badRequest.cpp @@ -53,7 +53,8 @@ std::string badRequest alarmMgr.badInput(ciP->ip, details); - restErrorReplyGet(ciP, SccBadRequest, ERROR_DESC_BAD_REQUEST_SERVICE_NOT_FOUND, &answer); + OrionError oe(SccBadRequest, ERROR_DESC_BAD_REQUEST_SERVICE_NOT_FOUND); + ciP->httpStatusCode = SccBadRequest; - return answer; + return oe.toJson(); } diff --git a/src/lib/serviceRoutines/badVerbAllFive.cpp b/src/lib/serviceRoutines/badVerbAllFive.cpp deleted file mode 100644 index 7a11d1f066..0000000000 --- a/src/lib/serviceRoutines/badVerbAllFive.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/* -* -* Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/errorMessages.h" -#include "alarmMgr/alarmMgr.h" - -#include "ngsi/ParseData.h" -#include "rest/ConnectionInfo.h" -#include "rest/HttpHeaders.h" -#include "rest/OrionError.h" -#include "serviceRoutines/badVerbAllFive.h" - - - -/* **************************************************************************** -* -* badVerbAllFive - -*/ -std::string badVerbAllFive -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -) -{ - std::string details = std::string("bad verb for url '") + ciP->url + "', method '" + ciP->method + "'"; - OrionError oe(SccBadVerb, ERROR_DESC_BAD_VERB); - - ciP->httpHeader.push_back(HTTP_ALLOW); - ciP->httpHeaderValue.push_back("POST, GET, PUT, DELETE, PATCH"); - ciP->httpStatusCode = SccBadVerb; - - alarmMgr.badInput(clientIp, details); - - return (ciP->apiVersion == V1 || ciP->apiVersion == NO_VERSION)? "" : oe.smartRender(ciP->apiVersion); -} diff --git a/src/lib/serviceRoutines/badVerbAllFive.h b/src/lib/serviceRoutines/badVerbAllFive.h deleted file mode 100644 index f883a01eb6..0000000000 --- a/src/lib/serviceRoutines/badVerbAllFive.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef SRC_LIB_SERVICEROUTINES_BADVERBALLFIVE_H_ -#define SRC_LIB_SERVICEROUTINES_BADVERBALLFIVE_H_ - -/* -* -* Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "rest/ConnectionInfo.h" -#include "ngsi/ParseData.h" - - - -/* **************************************************************************** -* -* badVerbAllFive - -*/ -extern std::string badVerbAllFive -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -); - -#endif // SRC_LIB_SERVICEROUTINES_BADVERBALLFIVE_H_ diff --git a/src/lib/serviceRoutines/badVerbAllFour.cpp b/src/lib/serviceRoutines/badVerbAllFour.cpp deleted file mode 100644 index 416c2e014b..0000000000 --- a/src/lib/serviceRoutines/badVerbAllFour.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/errorMessages.h" -#include "alarmMgr/alarmMgr.h" - -#include "ngsi/ParseData.h" -#include "rest/ConnectionInfo.h" -#include "rest/HttpHeaders.h" -#include "rest/OrionError.h" -#include "serviceRoutines/badVerbAllFour.h" - - - -/* **************************************************************************** -* -* badVerbAllFour - -*/ -std::string badVerbAllFour -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -) -{ - std::string details = std::string("bad verb for url '") + ciP->url + "', method '" + ciP->method + "'"; - OrionError oe(SccBadVerb, ERROR_DESC_BAD_VERB); - - ciP->httpHeader.push_back(HTTP_ALLOW); - ciP->httpHeaderValue.push_back("POST, GET, PUT, DELETE"); - ciP->httpStatusCode = SccBadVerb; - - alarmMgr.badInput(clientIp, details); - - return (ciP->apiVersion == V1 || ciP->apiVersion == NO_VERSION)? "" : oe.smartRender(ciP->apiVersion); -} diff --git a/src/lib/serviceRoutines/badVerbAllFour.h b/src/lib/serviceRoutines/badVerbAllFour.h deleted file mode 100644 index 9087fdcf2b..0000000000 --- a/src/lib/serviceRoutines/badVerbAllFour.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef SRC_LIB_SERVICEROUTINES_BADVERBALLFOUR_H_ -#define SRC_LIB_SERVICEROUTINES_BADVERBALLFOUR_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "rest/ConnectionInfo.h" -#include "ngsi/ParseData.h" - - - -/* **************************************************************************** -* -* badVerbAllFour - -*/ -extern std::string badVerbAllFour -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -); - -#endif // SRC_LIB_SERVICEROUTINES_BADVERBALLFOUR_H_ diff --git a/src/lib/serviceRoutines/badVerbGetDeleteOnly.cpp b/src/lib/serviceRoutines/badVerbGetDeleteOnly.cpp index 255b09b421..e7dea178b4 100644 --- a/src/lib/serviceRoutines/badVerbGetDeleteOnly.cpp +++ b/src/lib/serviceRoutines/badVerbGetDeleteOnly.cpp @@ -57,8 +57,8 @@ std::string badVerbGetDeleteOnly ciP->httpHeader.push_back(HTTP_ALLOW); std::string headerValue = "GET, DELETE"; - //OPTIONS verb is only available for V2 API - if ((corsEnabled == true) && (ciP->apiVersion == V2)) + //OPTIONS verb is only available for V2 API, e.g. not available for GET /version + if ((corsEnabled == true) && (ciP->url.compare(0, 3, "/v2") == 0)) { headerValue = headerValue + ", OPTIONS"; } @@ -67,5 +67,5 @@ std::string badVerbGetDeleteOnly alarmMgr.badInput(clientIp, details); - return (ciP->apiVersion == V1 || ciP->apiVersion == NO_VERSION)? "" : oe.smartRender(ciP->apiVersion); + return oe.toJson(); } diff --git a/src/lib/serviceRoutines/badVerbGetOnly.cpp b/src/lib/serviceRoutines/badVerbGetOnly.cpp index b5fbf5e34c..5bd27ecc41 100644 --- a/src/lib/serviceRoutines/badVerbGetOnly.cpp +++ b/src/lib/serviceRoutines/badVerbGetOnly.cpp @@ -57,8 +57,8 @@ std::string badVerbGetOnly ciP->httpHeader.push_back(HTTP_ALLOW); std::string headerValue = "GET"; - //OPTIONS verb is only available for V2 API - if ((corsEnabled == true) && (ciP->apiVersion == V2)) + //OPTIONS verb is only available for V2 API, e.g. not available for GET /version + if ((corsEnabled == true) && (ciP->url.compare(0, 3, "/v2") == 0)) { headerValue = headerValue + ", OPTIONS"; } @@ -67,5 +67,5 @@ std::string badVerbGetOnly alarmMgr.badInput(clientIp, details); - return (ciP->apiVersion == V1 || ciP->apiVersion == NO_VERSION)? "" : oe.smartRender(ciP->apiVersion); + return oe.toJson(); } diff --git a/src/lib/serviceRoutines/badVerbGetPostDeleteOnly.cpp b/src/lib/serviceRoutines/badVerbGetPostDeleteOnly.cpp deleted file mode 100644 index 4a58ee0d43..0000000000 --- a/src/lib/serviceRoutines/badVerbGetPostDeleteOnly.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/errorMessages.h" -#include "alarmMgr/alarmMgr.h" - -#include "ngsi/ParseData.h" -#include "rest/ConnectionInfo.h" -#include "rest/HttpHeaders.h" -#include "rest/OrionError.h" -#include "serviceRoutines/badVerbGetPostDeleteOnly.h" - - - -/* **************************************************************************** -* -* badVerbGetPostDeleteOnly - -*/ -std::string badVerbGetPostDeleteOnly -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -) -{ - std::string details = std::string("bad verb for url '") + ciP->url + "', method '" + ciP->method + "'"; - OrionError oe(SccBadVerb, ERROR_DESC_BAD_VERB); - - ciP->httpHeader.push_back(HTTP_ALLOW); - ciP->httpHeaderValue.push_back("GET, POST, DELETE"); - ciP->httpStatusCode = SccBadVerb; - - alarmMgr.badInput(clientIp, details); - - return (ciP->apiVersion == V1 || ciP->apiVersion == NO_VERSION)? "" : oe.smartRender(ciP->apiVersion); -} diff --git a/src/lib/serviceRoutines/badVerbGetPostDeleteOnly.h b/src/lib/serviceRoutines/badVerbGetPostDeleteOnly.h deleted file mode 100644 index eb66b50874..0000000000 --- a/src/lib/serviceRoutines/badVerbGetPostDeleteOnly.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef SRC_LIB_SERVICEROUTINES_BADVERBGETPOSTDELETEONLY_H_ -#define SRC_LIB_SERVICEROUTINES_BADVERBGETPOSTDELETEONLY_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "rest/ConnectionInfo.h" -#include "ngsi/ParseData.h" - - - -/* **************************************************************************** -* -* badVerbGetPostDeleteOnly - -*/ -extern std::string badVerbGetPostDeleteOnly -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -); - -#endif // SRC_LIB_SERVICEROUTINES_BADVERBGETPOSTDELETEONLY_H_ diff --git a/src/lib/serviceRoutines/badVerbGetPostOnly.cpp b/src/lib/serviceRoutines/badVerbGetPostOnly.cpp index ab37135214..7d0d8ee454 100644 --- a/src/lib/serviceRoutines/badVerbGetPostOnly.cpp +++ b/src/lib/serviceRoutines/badVerbGetPostOnly.cpp @@ -57,8 +57,8 @@ std::string badVerbGetPostOnly ciP->httpHeader.push_back(HTTP_ALLOW); std::string headerValue = "POST, GET"; - //OPTIONS verb is only available for V2 API - if ((corsEnabled == true) && (ciP->apiVersion == V2)) + //OPTIONS verb is only available for V2 API, e.g. not available for GET /version + if ((corsEnabled == true) && (ciP->url.compare(0, 3, "/v2") == 0)) { headerValue = headerValue + ", OPTIONS"; } @@ -67,5 +67,5 @@ std::string badVerbGetPostOnly alarmMgr.badInput(clientIp, details); - return (ciP->apiVersion == V1 || ciP->apiVersion == NO_VERSION)? "" : oe.smartRender(ciP->apiVersion); + return oe.toJson(); } diff --git a/src/lib/serviceRoutines/badVerbGetPutDeleteOnly.cpp b/src/lib/serviceRoutines/badVerbGetPutDeleteOnly.cpp index 843448d380..0306619f76 100644 --- a/src/lib/serviceRoutines/badVerbGetPutDeleteOnly.cpp +++ b/src/lib/serviceRoutines/badVerbGetPutDeleteOnly.cpp @@ -57,8 +57,8 @@ std::string badVerbGetPutDeleteOnly ciP->httpHeader.push_back(HTTP_ALLOW); std::string headerValue = "GET, PUT, DELETE"; - //OPTIONS verb is only available for V2 API - if ((corsEnabled == true) && (ciP->apiVersion == V2)) + //OPTIONS verb is only available for V2 API, e.g. not available for GET /version + if ((corsEnabled == true) && (ciP->url.compare(0, 3, "/v2") == 0)) { headerValue = headerValue + ", OPTIONS"; } @@ -67,5 +67,5 @@ std::string badVerbGetPutDeleteOnly alarmMgr.badInput(clientIp, details); - return (ciP->apiVersion == V1 || ciP->apiVersion == NO_VERSION)? "" : oe.smartRender(ciP->apiVersion); + return oe.toJson(); } diff --git a/src/lib/serviceRoutines/badVerbPostOnly.cpp b/src/lib/serviceRoutines/badVerbPostOnly.cpp index 74c49256e5..adc0da2501 100644 --- a/src/lib/serviceRoutines/badVerbPostOnly.cpp +++ b/src/lib/serviceRoutines/badVerbPostOnly.cpp @@ -57,8 +57,8 @@ std::string badVerbPostOnly ciP->httpHeader.push_back(HTTP_ALLOW); std::string headerValue = "POST"; - //OPTIONS verb is only available for V2 API - if ((corsEnabled == true) && (ciP->apiVersion == V2)) + //OPTIONS verb is only available for V2 API, e.g. not available for GET /version + if ((corsEnabled == true) && (ciP->url.compare(0, 3, "/v2") == 0)) { headerValue = headerValue + ", OPTIONS"; } @@ -67,5 +67,5 @@ std::string badVerbPostOnly alarmMgr.badInput(clientIp, details); - return (ciP->apiVersion == V1 || ciP->apiVersion == NO_VERSION)? "" : oe.smartRender(ciP->apiVersion); + return oe.toJson(); } diff --git a/src/lib/serviceRoutines/badVerbPutDeleteOnly.cpp b/src/lib/serviceRoutines/badVerbPutDeleteOnly.cpp index efb8f43bf1..2d1d5e5479 100644 --- a/src/lib/serviceRoutines/badVerbPutDeleteOnly.cpp +++ b/src/lib/serviceRoutines/badVerbPutDeleteOnly.cpp @@ -58,5 +58,5 @@ std::string badVerbPutDeleteOnly ciP->httpHeaderValue.push_back("PUT, DELETE"); ciP->httpStatusCode = SccBadVerb; - return (ciP->apiVersion == V1 || ciP->apiVersion == NO_VERSION)? "" : oe.smartRender(ciP->apiVersion); + return oe.toJson(); } diff --git a/src/lib/serviceRoutines/badVerbPutOnly.cpp b/src/lib/serviceRoutines/badVerbPutOnly.cpp index dcd9dbfac8..e9ece69fcf 100644 --- a/src/lib/serviceRoutines/badVerbPutOnly.cpp +++ b/src/lib/serviceRoutines/badVerbPutOnly.cpp @@ -60,5 +60,5 @@ std::string badVerbPutOnly alarmMgr.badInput(clientIp, details); - return (ciP->apiVersion == V1 || ciP->apiVersion == NO_VERSION)? "" : oe.smartRender(ciP->apiVersion); + return oe.toJson(); } diff --git a/src/lib/serviceRoutines/deleteAllEntitiesWithTypeAndId.cpp b/src/lib/serviceRoutines/deleteAllEntitiesWithTypeAndId.cpp deleted file mode 100644 index ee5917365b..0000000000 --- a/src/lib/serviceRoutines/deleteAllEntitiesWithTypeAndId.cpp +++ /dev/null @@ -1,135 +0,0 @@ -/* -* -* Copyright 2014 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/statistics.h" -#include "common/clockFunctions.h" -#include "alarmMgr/alarmMgr.h" - -#include "ngsi/ParseData.h" -#include "ngsi/EntityId.h" -#include "ngsi/StatusCode.h" -#include "rest/ConnectionInfo.h" -#include "rest/uriParamNames.h" -#include "rest/EntityTypeInfo.h" -#include "serviceRoutines/postUpdateContext.h" -#include "serviceRoutines/deleteAllEntitiesWithTypeAndId.h" - - - -/* **************************************************************************** -* -* deleteAllEntitiesWithTypeAndId - -* -* DELETE /v1/contextEntities/type/{entity::type}/id/{entity::id} -* -* Payload In: None -* Payload Out: StatusCode -* -* URI parameters: -* - entity::type=TYPE (must coincide with type in URL-path) -* - !exist=entity::type (if set - error -- entity::type cannot be empty) -* - exist=entity::type (not supported - ok if present, ok if not present ...) -* -* 01. Get values from URL (+ entityId::type, exist, !exist) -* 02. Check validity of URI params -* 03. Fill in UpdateContextRequest -* 04. Call Standard Operation -* 05. Fill in response from UpdateContextResponse -* 06. Cleanup and return result -*/ -std::string deleteAllEntitiesWithTypeAndId -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -) -{ - std::string entityType = compV[3]; - std::string entityId = compV[5]; - EntityTypeInfo typeInfo = EntityTypeEmptyOrNotEmpty; - std::string typeNameFromUriParam = ciP->uriParam[URI_PARAM_ENTITY_TYPE]; - std::string answer; - StatusCode response; - - // 01. Get values from URL (+ entityId::type, exist, !exist) - if (ciP->uriParam[URI_PARAM_NOT_EXIST] == URI_PARAM_ENTITY_TYPE) - { - typeInfo = EntityTypeEmpty; - } - else if (ciP->uriParam[URI_PARAM_EXIST] == URI_PARAM_ENTITY_TYPE) - { - typeInfo = EntityTypeNotEmpty; - } - - - // 02. Check validity of URI params - if (typeInfo == EntityTypeEmpty) - { - alarmMgr.badInput(clientIp, "entity::type cannot be empty for this request"); - - response.fill(SccBadRequest, "entity::type cannot be empty for this request"); - - TIMED_RENDER(answer = response.toJsonV1(false, false)); - - return answer; - } - else if ((typeNameFromUriParam != entityType) && (!typeNameFromUriParam.empty())) - { - alarmMgr.badInput(clientIp, "non-matching entity::types in URL", typeNameFromUriParam); - - response.fill(SccBadRequest, "non-matching entity::types in URL"); - - TIMED_RENDER(answer = response.toJsonV1(false, false)); - - return answer; - } - - - // 03. Fill in UpdateContextRequest - parseDataP->upcr.res.fill(entityId, entityType, "", "", ActionTypeDelete); - - - // 04. Call Standard Operation - postUpdateContext(ciP, components, compV, parseDataP); - - - // 05. Fill in response from UpdateContextResponse - response.fill(parseDataP->upcrs.res); - - - // 06. Cleanup and return result - TIMED_RENDER(answer = response.toJsonV1(false, false)); - - parseDataP->upcr.res.release(); - response.release(); - - return answer; -} diff --git a/src/lib/serviceRoutines/deleteAllEntitiesWithTypeAndId.h b/src/lib/serviceRoutines/deleteAllEntitiesWithTypeAndId.h deleted file mode 100644 index 4ebd292d17..0000000000 --- a/src/lib/serviceRoutines/deleteAllEntitiesWithTypeAndId.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef SRC_LIB_SERVICEROUTINES_DELETEALLENTITIESWITHTYPEANDID_H_ -#define SRC_LIB_SERVICEROUTINES_DELETEALLENTITIESWITHTYPEANDID_H_ - -/* -* -* Copyright 2014 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "rest/ConnectionInfo.h" -#include "ngsi/ParseData.h" - - - -/* **************************************************************************** -* -* deleteAllEntitiesWithTypeAndId - -*/ -extern std::string deleteAllEntitiesWithTypeAndId -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -); - -#endif // SRC_LIB_SERVICEROUTINES_DELETEALLENTITIESWITHTYPEANDID_H_ diff --git a/src/lib/serviceRoutines/deleteIndividualContextEntity.cpp b/src/lib/serviceRoutines/deleteIndividualContextEntity.cpp deleted file mode 100644 index 72eadb2ed6..0000000000 --- a/src/lib/serviceRoutines/deleteIndividualContextEntity.cpp +++ /dev/null @@ -1,102 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/statistics.h" -#include "common/clockFunctions.h" - -#include "ngsi/ParseData.h" -#include "ngsi/StatusCode.h" -#include "ngsi10/UpdateContextResponse.h" -#include "rest/ConnectionInfo.h" -#include "rest/uriParamNames.h" -#include "serviceRoutines/postUpdateContext.h" -#include "serviceRoutines/deleteIndividualContextEntity.h" - - - -/* **************************************************************************** -* -* deleteIndividualContextEntity - -* -* Corresponding Standard Operation: UpdateContext/DELETE -* -* DELETE /v1/contextEntities/{entityId::id} -* -* Payload In: None -* Payload Out: StatusCode -* -* URI parameters: -* - entity::type=TYPE -* - note that '!exist=entity::type' and 'exist=entity::type' are not supported by convenience operations -* that use the standard operation UpdateContext as there is no restriction within UpdateContext. -* -* 00. URI params -* 01. Fill in UpdateContextRequest from URL-data + URI params -* 02. Call postUpdateContext standard service routine -* 03. Translate UpdateContextResponse to StatusCode -* 04. If not found, put entity info in details -* 05. Cleanup and return result -*/ -std::string deleteIndividualContextEntity -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -) -{ - std::string answer; - std::string entityId = compV[2]; - std::string entityType = ciP->uriParam[URI_PARAM_ENTITY_TYPE]; - StatusCode response; - - // 01. Fill in UpdateContextRequest fromURL-data + URI params - parseDataP->upcr.res.fill(entityId, entityType, "false", "", ActionTypeDelete); - - // 02. Call postUpdateContext standard service routine - answer = postUpdateContext(ciP, components, compV, parseDataP); - - // 03. Translate UpdateContextResponse to StatusCode - response.fill(parseDataP->upcrs.res); - - // 04. If not found, put entity info in details - if ((response.code == SccContextElementNotFound) && (response.details.empty())) - { - response.details = entityId; - } - - // 05. Cleanup and return result - TIMED_RENDER(answer = response.toJsonV1(false, false)); - - response.release(); - parseDataP->upcr.res.release(); - - return answer; -} diff --git a/src/lib/serviceRoutines/deleteIndividualContextEntity.h b/src/lib/serviceRoutines/deleteIndividualContextEntity.h deleted file mode 100644 index 3df16fa8c1..0000000000 --- a/src/lib/serviceRoutines/deleteIndividualContextEntity.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef SRC_LIB_SERVICEROUTINES_DELETEINDIVIDUALCONTEXTENTITY_H_ -#define SRC_LIB_SERVICEROUTINES_DELETEINDIVIDUALCONTEXTENTITY_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "rest/ConnectionInfo.h" -#include "ngsi/ParseData.h" - - - -/* **************************************************************************** -* -* deleteIndividualContextEntity - -*/ -extern std::string deleteIndividualContextEntity -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -); - -#endif // SRC_LIB_SERVICEROUTINES_DELETEINDIVIDUALCONTEXTENTITY_H_ diff --git a/src/lib/serviceRoutines/deleteIndividualContextEntityAttribute.cpp b/src/lib/serviceRoutines/deleteIndividualContextEntityAttribute.cpp deleted file mode 100644 index ea7a55aa35..0000000000 --- a/src/lib/serviceRoutines/deleteIndividualContextEntityAttribute.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/statistics.h" -#include "common/clockFunctions.h" - -#include "ngsi/ParseData.h" -#include "ngsi/StatusCode.h" -#include "rest/ConnectionInfo.h" -#include "rest/uriParamNames.h" -#include "rest/EntityTypeInfo.h" -#include "serviceRoutines/postUpdateContext.h" -#include "serviceRoutines/deleteIndividualContextEntityAttribute.h" - - - -/* **************************************************************************** -* -* deleteIndividualContextEntityAttribute - -* -* DELETE /v1/contextEntities/{entityId::id}/attributes/{attributeName} -* DELETE /ngsi10/contextEntities/{entityId::id}/attributes/{attributeName} -* -* Payload In: None -* Payload Out: StatusCode -* -* URI parameters: -* - entity::type=TYPE -* - note that '!exist=entity::type' and 'exist=entity::type' are not supported by convenience operations -* that use the standard operation UpdateContext as there is no restriction within UpdateContext. -* [ attributesFormat=object: makes no sense for this operation as StatusCode is returned ] -* -* 0. Take care of URI params -* 1. Fill in UpdateContextRequest from URL-path components -* 2. Call postUpdateContext standard service routine -* 3. Translate UpdateContextResponse to StatusCode -* 4. Cleanup and return result -*/ -std::string deleteIndividualContextEntityAttribute -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -) -{ - std::string answer; - std::string entityId = compV[2]; - std::string entityType = ciP->uriParam[URI_PARAM_ENTITY_TYPE]; - std::string attributeName = compV[4]; - StatusCode response; - - - // 1. Fill in UpdateContextRequest from URL-path components - parseDataP->upcr.res.fill(entityId, entityType, "false", attributeName, ActionTypeDelete); - - - // 2. Call postUpdateContext standard service routine - postUpdateContext(ciP, components, compV, parseDataP); - - - // 3. Translate UpdateContextResponse to StatusCode - response.fill(parseDataP->upcrs.res); - - - // 4. Cleanup and return result - TIMED_RENDER(answer = response.toJsonV1(false, false)); - - response.release(); - parseDataP->upcr.res.release(); - - return answer; -} diff --git a/src/lib/serviceRoutines/deleteIndividualContextEntityAttribute.h b/src/lib/serviceRoutines/deleteIndividualContextEntityAttribute.h deleted file mode 100644 index 716015ed91..0000000000 --- a/src/lib/serviceRoutines/deleteIndividualContextEntityAttribute.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef SRC_LIB_SERVICEROUTINES_DELETEINDIVIDUALCONTEXTENTITYATTRIBUTE_H_ -#define SRC_LIB_SERVICEROUTINES_DELETEINDIVIDUALCONTEXTENTITYATTRIBUTE_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "rest/ConnectionInfo.h" -#include "ngsi/ParseData.h" - - - -/* **************************************************************************** -* -* deleteIndividualContextEntityAttribute - -*/ -extern std::string deleteIndividualContextEntityAttribute -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -); - -#endif // SRC_LIB_SERVICEROUTINES_DELETEINDIVIDUALCONTEXTENTITYATTRIBUTE_H_ diff --git a/src/lib/serviceRoutines/deleteIndividualContextEntityAttributeWithTypeAndId.cpp b/src/lib/serviceRoutines/deleteIndividualContextEntityAttributeWithTypeAndId.cpp deleted file mode 100644 index 35f343be6a..0000000000 --- a/src/lib/serviceRoutines/deleteIndividualContextEntityAttributeWithTypeAndId.cpp +++ /dev/null @@ -1,128 +0,0 @@ -/* -* -* Copyright 2014 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/statistics.h" -#include "common/clockFunctions.h" -#include "alarmMgr/alarmMgr.h" - -#include "ngsi/ParseData.h" -#include "ngsi/StatusCode.h" -#include "rest/ConnectionInfo.h" -#include "rest/uriParamNames.h" -#include "rest/EntityTypeInfo.h" -#include "serviceRoutines/postUpdateContext.h" -#include "serviceRoutines/deleteIndividualContextEntityAttributeWithTypeAndId.h" - - - -/* **************************************************************************** -* -* deleteIndividualContextEntityAttributeWithTypeAndId - -* -* DELETE /v1/contextEntities/type/{entity::type}/id/{entity::id}/attributes/{attribute::name} -* -* Payload In: None -* Payload Out: StatusCode -* -* URI parameters: -* - entity::type=TYPE (must coincide with type in URL-path) -* - !exist=entity::type (if set - error -- entity::type cannot be empty) -* - exist=entity::type (not supported - ok if present, ok if not present ...) -* -* 01. Get values from URL (+ entityId::type, exist, !exist) -* 02. Check validity of URI params -* 03. Fill in UpdateContextRequest -* 04. Call Standard Operation -* 05. Fill in response from UpdateContextResponse -* 06. Cleanup and return result -*/ -std::string deleteIndividualContextEntityAttributeWithTypeAndId -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -) -{ - std::string entityType = compV[3]; - std::string entityId = compV[5]; - std::string attributeName = compV[7]; - EntityTypeInfo typeInfo = EntityTypeEmptyOrNotEmpty; - std::string typeNameFromUriParam = ciP->uriParam[URI_PARAM_ENTITY_TYPE]; - std::string answer; - StatusCode response; - - // 01. Get values from URL (+ entityId::type, exist, !exist) - if (ciP->uriParam[URI_PARAM_NOT_EXIST] == URI_PARAM_ENTITY_TYPE) - { - typeInfo = EntityTypeEmpty; - } - else if (ciP->uriParam[URI_PARAM_EXIST] == URI_PARAM_ENTITY_TYPE) - { - typeInfo = EntityTypeNotEmpty; - } - - - // 02. Check validity of URI params - if (typeInfo == EntityTypeEmpty) - { - alarmMgr.badInput(clientIp, "entity::type cannot be empty for this request"); - response.fill(SccBadRequest, "entity::type cannot be empty for this request"); - TIMED_RENDER(answer = response.toJsonV1(false, false)); - return answer; - } - else if ((typeNameFromUriParam != entityType) && (!typeNameFromUriParam.empty())) - { - alarmMgr.badInput(clientIp, "non-matching entity::types in URL", typeNameFromUriParam); - response.fill(SccBadRequest, "non-matching entity::types in URL"); - TIMED_RENDER(answer = response.toJsonV1(false, false)); - return answer; - } - - - // 03. Fill in UpdateContextRequest - parseDataP->upcr.res.fill(entityId, entityType, "", attributeName, ActionTypeDelete); - - - // 04. Call Standard Operation - postUpdateContext(ciP, components, compV, parseDataP); - - - // 05. Fill in response from UpdateContextResponse - response.fill(parseDataP->upcrs.res); - - - // 06. Cleanup and return result - TIMED_RENDER(answer = response.toJsonV1(false, false)); - - parseDataP->upcr.res.release(); - - return answer; -} diff --git a/src/lib/serviceRoutines/deleteIndividualContextEntityAttributeWithTypeAndId.h b/src/lib/serviceRoutines/deleteIndividualContextEntityAttributeWithTypeAndId.h deleted file mode 100644 index 606414804a..0000000000 --- a/src/lib/serviceRoutines/deleteIndividualContextEntityAttributeWithTypeAndId.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef SRC_LIB_SERVICEROUTINES_DELETEINDIVIDUALCONTEXTENTITYATTRIBUTEWITHTYPEANDID_H_ -#define SRC_LIB_SERVICEROUTINES_DELETEINDIVIDUALCONTEXTENTITYATTRIBUTEWITHTYPEANDID_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "rest/ConnectionInfo.h" -#include "ngsi/ParseData.h" - - - -/* **************************************************************************** -* -* deleteIndividualContextEntityAttributeWithTypeAndId - -*/ -extern std::string deleteIndividualContextEntityAttributeWithTypeAndId -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -); - -#endif // SRC_LIB_SERVICEROUTINES_DELETEINDIVIDUALCONTEXTENTITYATTRIBUTEWITHTYPEANDID_H_ diff --git a/src/lib/serviceRoutines/deleteSubscriptionConvOp.cpp b/src/lib/serviceRoutines/deleteSubscriptionConvOp.cpp deleted file mode 100644 index 9c3bdb0297..0000000000 --- a/src/lib/serviceRoutines/deleteSubscriptionConvOp.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "ngsi/ParseData.h" -#include "rest/ConnectionInfo.h" -#include "serviceRoutines/postUnsubscribeContext.h" -#include "serviceRoutines/deleteSubscriptionConvOp.h" - - - -/* **************************************************************************** -* -* deleteSubscriptionConvOp - -* -* DELETE /v1/contextSubscriptions/{subscriptionId} -* DELETE /ngsi10/contextSubscriptions/{subscriptionId} -* -* Payload In: None -* Payload Out: UnsubscribeContextResponse -* -* URI parameters: -* NONE -*/ -std::string deleteSubscriptionConvOp -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -) -{ - std::string subscriptionId = compV[2]; - - // 'Fill In' UnsubscribeContextRequest - parseDataP->uncr.res.subscriptionId.set(subscriptionId); - - return postUnsubscribeContext(ciP, components, compV, parseDataP); -} diff --git a/src/lib/serviceRoutines/deleteSubscriptionConvOp.h b/src/lib/serviceRoutines/deleteSubscriptionConvOp.h deleted file mode 100644 index 36a2cdb05b..0000000000 --- a/src/lib/serviceRoutines/deleteSubscriptionConvOp.h +++ /dev/null @@ -1,49 +0,0 @@ -#ifndef SRC_LIB_SERVICEROUTINES_DELETESUBSCRIPTIONCONVOP_H_ -#define SRC_LIB_SERVICEROUTINES_DELETESUBSCRIPTIONCONVOP_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "ngsi/ParseData.h" -#include "rest/ConnectionInfo.h" - - - -/* **************************************************************************** -* -* deleteSubscriptionConvOp - -*/ -extern std::string deleteSubscriptionConvOp -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -); - -#endif // SRC_LIB_SERVICEROUTINES_DELETESUBSCRIPTIONCONVOP_H_ - diff --git a/src/lib/serviceRoutines/exitTreat.cpp b/src/lib/serviceRoutines/exitTreat.cpp index 06090cea60..3c4410d126 100644 --- a/src/lib/serviceRoutines/exitTreat.cpp +++ b/src/lib/serviceRoutines/exitTreat.cpp @@ -64,7 +64,7 @@ std::string exitTreat OrionError orionError(SccBadRequest, "no such service"); ciP->httpStatusCode = SccOk; - out = orionError.toJsonV1(); + out = orionError.toJson(); return out; } @@ -77,13 +77,13 @@ std::string exitTreat { OrionError orionError(SccBadRequest, "Password requested"); ciP->httpStatusCode = SccOk; - out = orionError.toJsonV1(); + out = orionError.toJson(); } else if (password != "harakiri") { OrionError orionError(SccBadRequest, "Request denied - password erroneous"); ciP->httpStatusCode = SccOk; - out = orionError.toJsonV1(); + out = orionError.toJson(); } else { diff --git a/src/lib/serviceRoutines/getAllContextEntities.cpp b/src/lib/serviceRoutines/getAllContextEntities.cpp deleted file mode 100644 index 05ac984291..0000000000 --- a/src/lib/serviceRoutines/getAllContextEntities.cpp +++ /dev/null @@ -1,97 +0,0 @@ -/* -* -* Copyright 2014 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "ngsi/ParseData.h" -#include "ngsi/EntityId.h" -#include "ngsi10/QueryContextRequest.h" -#include "rest/ConnectionInfo.h" -#include "rest/EntityTypeInfo.h" -#include "rest/uriParamNames.h" -#include "serviceRoutines/getAllContextEntities.h" -#include "serviceRoutines/postQueryContext.h" - - - -/* **************************************************************************** -* -* getAllContextEntities - -* -* GET /v1/contextEntities -* -* Payload In: None -* Payload Out: QueryContextResponse -* -* URI parameters: -* - attributesFormat=object -* - entity::type=XXX -* - !exist=entity::type -* - exist=entity::type -* - offset=XXX -* - limit=XXX -* - details=on -* -* 01. Get values from URL (entityId::type, exist, !exist -* 02. Fill in QueryContextRequest -* 03. Call standard op postQueryContext -* 04. Cleanup and return result -*/ -std::string getAllContextEntities -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -) -{ - std::string typeName = ciP->uriParam[URI_PARAM_ENTITY_TYPE]; - EntityTypeInfo typeInfo = EntityTypeEmptyOrNotEmpty; - std::string answer; - - - // 01. Get values from URL (entityId::type, exist, !exist) - if (ciP->uriParam[URI_PARAM_NOT_EXIST] == URI_PARAM_ENTITY_TYPE) - { - typeInfo = EntityTypeEmpty; - } - else if (ciP->uriParam[URI_PARAM_EXIST] == URI_PARAM_ENTITY_TYPE) - { - typeInfo = EntityTypeNotEmpty; - } - - - // 02. Fill in QueryContextRequest - parseDataP->qcr.res.fill(".*", typeName, "true", typeInfo, ""); - - - // 03. Call standard op postQueryContext - answer = postQueryContext(ciP, components, compV, parseDataP); - - - // 04. Cleanup and return result - parseDataP->qcr.res.release(); - return answer; -} diff --git a/src/lib/serviceRoutines/getAllContextEntities.h b/src/lib/serviceRoutines/getAllContextEntities.h deleted file mode 100644 index d6ea637102..0000000000 --- a/src/lib/serviceRoutines/getAllContextEntities.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef SRC_LIB_SERVICEROUTINES_GETALLCONTEXTENTITIES_H_ -#define SRC_LIB_SERVICEROUTINES_GETALLCONTEXTENTITIES_H_ - -/* -* -* Copyright 2014 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "rest/ConnectionInfo.h" -#include "ngsi/ParseData.h" - - - -/* **************************************************************************** -* -* getAllContextEntities - -*/ -extern std::string getAllContextEntities -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -); - -#endif // SRC_LIB_SERVICEROUTINES_GETALLCONTEXTENTITIES_H_ diff --git a/src/lib/serviceRoutines/getAllEntitiesWithTypeAndId.cpp b/src/lib/serviceRoutines/getAllEntitiesWithTypeAndId.cpp deleted file mode 100644 index 347acdb657..0000000000 --- a/src/lib/serviceRoutines/getAllEntitiesWithTypeAndId.cpp +++ /dev/null @@ -1,147 +0,0 @@ -/* -* -* Copyright 2014 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/statistics.h" -#include "common/clockFunctions.h" -#include "alarmMgr/alarmMgr.h" - -#include "ngsi/ParseData.h" -#include "ngsi/ContextElementResponse.h" -#include "rest/ConnectionInfo.h" -#include "rest/EntityTypeInfo.h" -#include "rest/uriParamNames.h" -#include "serviceRoutines/postQueryContext.h" -#include "serviceRoutines/getAllEntitiesWithTypeAndId.h" - - - -/* **************************************************************************** -* -* getAllEntitiesWithTypeAndId - -* -* GET /v1/contextEntities/type/{entity::type}/id/{entity::id} -* GET /ngsi10/contextEntities/type/{entity::type}/id/{entity::id} -* -* Payload In: None -* Payload Out: ContextElementResponse -* -* URI parameters: -* - attributesFormat=object -* - entity::type=XXX (must coincide with entity::type in URL) -* - !exist=entity::type (if set - error -- entity::type cannot be empty) -* - exist=entity::type (not supported - ok if present, ok if not present ...) -* -* 00. Default value for response: OK -* 01. Get values from URL (entityId::type, esist, !exist) -* 02. Check validity of URI params -* 03. Fill in QueryContextRequest -* 04. Call standard operation postQueryContext -* 05. If 404 Not Found - enter request info into response context element -* 06. Translate QueryContextResponse to ContextElementResponse -* 07. Cleanup and return result -* -*/ -std::string getAllEntitiesWithTypeAndId -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -) -{ - std::string answer; - std::string entityType = compV[3]; - std::string entityId = compV[5]; - std::string entityTypeFromUriParam = ciP->uriParam[URI_PARAM_ENTITY_TYPE]; - EntityTypeInfo typeInfo = EntityTypeEmptyOrNotEmpty; - ContextElementResponse response; - - bool asJsonObject = (ciP->uriParam[URI_PARAM_ATTRIBUTE_FORMAT] == "object" && ciP->outMimeType == JSON); - - // 00. Default value for response: OK - response.statusCode.fill(SccOk); - - - // 01. Get values from URL (entityId::type, exist, !exist) - if (ciP->uriParam[URI_PARAM_NOT_EXIST] == URI_PARAM_ENTITY_TYPE) - { - typeInfo = EntityTypeEmpty; - } - else if (ciP->uriParam[URI_PARAM_EXIST] == URI_PARAM_ENTITY_TYPE) - { - typeInfo = EntityTypeNotEmpty; - } - - - // - // 02. Check validity of URI params ... - // and if OK: - // 03. Fill in QueryContextRequest - // 04. Call standard operation postQueryContext - // - if (typeInfo == EntityTypeEmpty) - { - parseDataP->qcrs.res.errorCode.fill(SccBadRequest, "entity::type cannot be empty for this request"); - alarmMgr.badInput(clientIp, "entity::type cannot be empty for this request"); - } - else if ((entityTypeFromUriParam != entityType) && (!entityTypeFromUriParam.empty())) - { - parseDataP->qcrs.res.errorCode.fill(SccBadRequest, "non-matching entity::types in URL"); - alarmMgr.badInput(clientIp, "non-matching entity::types in URL", entityTypeFromUriParam); - } - else - { - // 03. Fill in QueryContextRequest - parseDataP->qcr.res.fill(entityId, entityType, "false", typeInfo, ""); - - - // 04. Call standard operation postQueryContext - postQueryContext(ciP, components, compV, parseDataP); - } - - - // 05. If 404 Not Found - enter request info into response context element - if (response.statusCode.code == SccContextElementNotFound) - { - response.statusCode.details = "entityId::type/attribute::name pair not found"; - } - - // 06. Translate QueryContextResponse to ContextElementResponse - - response.fill(&parseDataP->qcrs.res, entityId, entityType); - TIMED_RENDER(answer = response.toJsonV1(asJsonObject, RtContextElementResponse, false)); - - // 07. Cleanup and return result - parseDataP->qcr.res.release(); - parseDataP->qcrs.res.release(); - response.release(); - - return answer; -} diff --git a/src/lib/serviceRoutines/getAllEntitiesWithTypeAndId.h b/src/lib/serviceRoutines/getAllEntitiesWithTypeAndId.h deleted file mode 100644 index 9fa0108de1..0000000000 --- a/src/lib/serviceRoutines/getAllEntitiesWithTypeAndId.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef SRC_LIB_SERVICEROUTINES_GETALLENTITIESWITHTYPEANDID_H_ -#define SRC_LIB_SERVICEROUTINES_GETALLENTITIESWITHTYPEANDID_H_ - -/* -* -* Copyright 2014 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "rest/ConnectionInfo.h" -#include "ngsi/ParseData.h" - - - -/* **************************************************************************** -* -* getAllEntitiesWithTypeAndId - -*/ -extern std::string getAllEntitiesWithTypeAndId -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -); - -#endif // SRC_LIB_SERVICEROUTINES_GETALLENTITIESWITHTYPEANDID_H_ diff --git a/src/lib/serviceRoutines/getAttributesForEntityType.cpp b/src/lib/serviceRoutines/getAttributesForEntityType.cpp deleted file mode 100644 index fd02925ebd..0000000000 --- a/src/lib/serviceRoutines/getAttributesForEntityType.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/* -* -* Copyright 2014 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "common/statistics.h" -#include "common/clockFunctions.h" - -#include "rest/ConnectionInfo.h" -#include "ngsi/ParseData.h" -#include "orionTypes/EntityTypeResponse.h" -#include "rest/uriParamNames.h" -#include "serviceRoutines/getAttributesForEntityType.h" - -#include "mongoBackend/mongoQueryTypes.h" - - - -/* **************************************************************************** -* -* getAttributesForEntityType - -* -* GET /v1/contextTypes/{entity::type} -* -* Payload In: None -* Payload Out: EntityTypeResponse -* -* URI parameters: -* - attributesFormat=object -* -*/ -std::string getAttributesForEntityType -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -) -{ - EntityTypeResponse response; - std::string entityTypeName = compV[2]; - - bool asJsonObject = (ciP->uriParam[URI_PARAM_ATTRIBUTE_FORMAT] == "object" && ciP->outMimeType == JSON); - - response.statusCode.fill(SccOk); - - // - // NOTE - // The second to last parameter for mongoAttributesForEntityType 'bool noAttrDetail' is always - // set to true (meaning to skip the attribute detail) for NGSIv1 requests. - // The parameter is only used for NGSIv2. - // - TIMED_MONGO(mongoAttributesForEntityType(entityTypeName, &response, ciP->tenant, ciP->servicePathV, ciP->uriParam, true, ciP->apiVersion)); - - std::string rendered; - TIMED_RENDER(rendered = response.toJsonV1(asJsonObject, - ciP->outMimeType == JSON, - ciP->uriParam[URI_PARAM_COLLAPSE] == "true")); - - response.release(); - - return rendered; -} diff --git a/src/lib/serviceRoutines/getAttributesForEntityType.h b/src/lib/serviceRoutines/getAttributesForEntityType.h deleted file mode 100644 index d75b9a4dfa..0000000000 --- a/src/lib/serviceRoutines/getAttributesForEntityType.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef SRC_LIB_SERVICEROUTINES_GETATTRIBUTESFORENTITYTYPE_H_ -#define SRC_LIB_SERVICEROUTINES_GETATTRIBUTESFORENTITYTYPE_H_ - -/* -* -* Copyright 2014 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "rest/ConnectionInfo.h" -#include "ngsi/ParseData.h" - - - -/* **************************************************************************** -* -* getAttributesForEntityType - -*/ -extern std::string getAttributesForEntityType -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -); - -#endif // SRC_LIB_SERVICEROUTINES_GETATTRIBUTESFORENTITYTYPE_H_ diff --git a/src/lib/serviceRoutines/getContextEntitiesByEntityId.cpp b/src/lib/serviceRoutines/getContextEntitiesByEntityId.cpp deleted file mode 100644 index c2fb2e1dbc..0000000000 --- a/src/lib/serviceRoutines/getContextEntitiesByEntityId.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "ngsi/ParseData.h" -#include "ngsi9/DiscoverContextAvailabilityRequest.h" -#include "rest/ConnectionInfo.h" -#include "serviceRoutines/postDiscoverContextAvailability.h" -#include "serviceRoutines/getContextEntitiesByEntityId.h" - - - -/* **************************************************************************** -* -* getContextEntitiesByEntityId - -* -* GET /v1/registry/contextEntities/{entityId::id} -* GET /NGSI9/contextEntities/{entityId::id} -* -* This convenience operation performs an ngsi9 discovery of a fixed -* entityId::id (no wildcards allowed), isPattern == false and type empty, -* which matches ANY type. -* -* However, if the URI parameter '!exist=entity::type', then instead only -* entities with EMPTY types will be discovered. -* -* Service routine to call: postDiscoverContextAvailability. -* -* As this convop shares output format (DiscoverContextAvailabilityResponse) with its -* corresponding standard operation, there is no need to convert the output. -*/ -std::string getContextEntitiesByEntityId -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -) -{ - std::string entityId = (compV.size() == 4)? compV[3] : compV[2]; - std::string answer; - - // - // Fill in parseDataP->dcar.res to pass to postDiscoverContextAvailability - // - EntityId eId(entityId, "", ""); - std::vector attributeV; - Restriction restriction; - - parseDataP->dcar.res.fill(eId, attributeV, restriction); - - - // - // Call the standard operation - // - answer = postDiscoverContextAvailability(ciP, components, compV, parseDataP); - - return answer; -} diff --git a/src/lib/serviceRoutines/getContextEntitiesByEntityId.h b/src/lib/serviceRoutines/getContextEntitiesByEntityId.h deleted file mode 100644 index dad755c351..0000000000 --- a/src/lib/serviceRoutines/getContextEntitiesByEntityId.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef SRC_LIB_SERVICEROUTINES_GETCONTEXTENTITIESBYENTITYID_H_ -#define SRC_LIB_SERVICEROUTINES_GETCONTEXTENTITIESBYENTITYID_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "rest/ConnectionInfo.h" -#include "ngsi/ParseData.h" - - - -/* **************************************************************************** -* -* getContextEntitiesByEntityId - -*/ -extern std::string getContextEntitiesByEntityId -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -); - -#endif // SRC_LIB_SERVICEROUTINES_GETCONTEXTENTITIESBYENTITYID_H_ diff --git a/src/lib/serviceRoutines/getContextEntitiesByEntityIdAndType.cpp b/src/lib/serviceRoutines/getContextEntitiesByEntityIdAndType.cpp deleted file mode 100644 index b6db5928ac..0000000000 --- a/src/lib/serviceRoutines/getContextEntitiesByEntityIdAndType.cpp +++ /dev/null @@ -1,124 +0,0 @@ -/* -* -* Copyright 2014 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/statistics.h" -#include "common/clockFunctions.h" -#include "alarmMgr/alarmMgr.h" - -#include "ngsi/ParseData.h" -#include "ngsi9/DiscoverContextAvailabilityResponse.h" -#include "rest/ConnectionInfo.h" -#include "rest/EntityTypeInfo.h" -#include "rest/uriParamNames.h" -#include "serviceRoutines/postDiscoverContextAvailability.h" -#include "serviceRoutines/getContextEntitiesByEntityId.h" - - - -/* **************************************************************************** -* -* getContextEntitiesByEntityIdAndType - -* -* GET /v1/registry/contextEntities/type/{ETYPE}/id/{EID} -* -* URI parameters: -* - entity::type=XXX (must coincide with entity::type in URL) -* - !exist=entity::type (if set - error -- entity::type cannot be empty) -* - exist=entity::type (not supported - ok if present, ok if not present ...) -* -* 01. Get values from URL (entityId::type, esist, !exist) -* 02. Check validity of URI params -* 03. Fill in DiscoverContextAvailabilityRequest -* 04. Call standard operation postDiscoverContextAvailability -* 05. Cleanup and return result -*/ -std::string getContextEntitiesByEntityIdAndType -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -) -{ - std::string entityType = compV[4]; - std::string entityId = compV[6]; - std::string entityTypeFromUriParam = ciP->uriParam[URI_PARAM_ENTITY_TYPE]; - EntityTypeInfo typeInfo = EntityTypeEmptyOrNotEmpty; - std::string answer; - DiscoverContextAvailabilityResponse response; - - - // 01. Get values from URL (entityId::type, esist, !exist) - if (ciP->uriParam[URI_PARAM_NOT_EXIST] == URI_PARAM_ENTITY_TYPE) - { - typeInfo = EntityTypeEmpty; - } - else if (ciP->uriParam[URI_PARAM_EXIST] == URI_PARAM_ENTITY_TYPE) - { - typeInfo = EntityTypeNotEmpty; - } - - - // - // 02. Check validity of URI params ... - // and if OK: - // 03. Fill in DiscoverContextAvailabilityRequest - // 04. Call standard operation postDiscoverContextAvailability - // - if (typeInfo == EntityTypeEmpty) - { - parseDataP->dcars.res.errorCode.fill(SccBadRequest, "entity::type cannot be empty for this request"); - alarmMgr.badInput(clientIp, "entity::type cannot be empty for this request"); - - TIMED_RENDER(answer = parseDataP->dcars.res.toJsonV1()); - } - else if ((entityTypeFromUriParam != entityType) && (!entityTypeFromUriParam.empty())) - { - parseDataP->dcars.res.errorCode.fill(SccBadRequest, "non-matching entity::types in URL"); - alarmMgr.badInput(clientIp, "non-matching entity::types in URL", entityTypeFromUriParam); - - TIMED_RENDER(answer = parseDataP->dcars.res.toJsonV1()); - } - else - { - // 03. Fill in DiscoverContextAvailabilityRequest - parseDataP->dcar.res.fill(entityId, entityType); - - // 04. Call standard operation postDiscoverContextAvailability - answer = postDiscoverContextAvailability(ciP, components, compV, parseDataP); - } - - // 05. Cleanup and return result - parseDataP->dcar.res.release(); - parseDataP->dcars.res.release(); - - return answer; -} diff --git a/src/lib/serviceRoutines/getContextEntitiesByEntityIdAndType.h b/src/lib/serviceRoutines/getContextEntitiesByEntityIdAndType.h deleted file mode 100644 index c3f9f8397d..0000000000 --- a/src/lib/serviceRoutines/getContextEntitiesByEntityIdAndType.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef SRC_LIB_SERVICEROUTINES_GETCONTEXTENTITIESBYENTITYIDANDTYPE_H_ -#define SRC_LIB_SERVICEROUTINES_GETCONTEXTENTITIESBYENTITYIDANDTYPE_H_ - -/* -* -* Copyright 2014 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "rest/ConnectionInfo.h" -#include "ngsi/ParseData.h" - - - -/* **************************************************************************** -* -* getContextEntitiesByEntityIdAndType - -*/ -extern std::string getContextEntitiesByEntityIdAndType -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -); - -#endif // SRC_LIB_SERVICEROUTINES_GETCONTEXTENTITIESBYENTITYIDANDTYPE_H_ diff --git a/src/lib/serviceRoutines/getContextEntityAttributes.cpp b/src/lib/serviceRoutines/getContextEntityAttributes.cpp deleted file mode 100644 index 6a21634942..0000000000 --- a/src/lib/serviceRoutines/getContextEntityAttributes.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "ngsi/ParseData.h" -#include "rest/ConnectionInfo.h" -#include "serviceRoutines/postDiscoverContextAvailability.h" -#include "serviceRoutines/getContextEntityAttributes.h" - - - -/* **************************************************************************** -* -* getContextEntityAttributes - -* -* GET /v1/registry/contextEntities/{entityId::id}/attributes -* GET /ngsi9/contextEntities/{entityId::id}/attributes -* -* Payload In: None -* Payload Out: DiscoverContextAvailabilityResponse -* -* 1. Fill in DiscoverContextAvailabilityRequest -* 2. Call postDiscoverContextAvailability -*/ -std::string getContextEntityAttributes -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -) -{ - std::string entityId = (compV.size() == 5)? compV[3] : compV[2]; - std::string answer; - - // - // 1. Fill in parseDataP->dcar.res to pass to postDiscoverContextAvailability - // - EntityId eId(entityId, "", ""); - std::vector attributeV; - Restriction restriction; - - parseDataP->dcar.res.fill(eId, attributeV, restriction); - - // - // 2. Call the standard operation - // - answer = postDiscoverContextAvailability(ciP, components, compV, parseDataP); - - return answer; -} diff --git a/src/lib/serviceRoutines/getContextEntityAttributes.h b/src/lib/serviceRoutines/getContextEntityAttributes.h deleted file mode 100644 index 2c9349e0e1..0000000000 --- a/src/lib/serviceRoutines/getContextEntityAttributes.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef SRC_LIB_SERVICEROUTINES_GETCONTEXTENTITYATTRIBUTES_H_ -#define SRC_LIB_SERVICEROUTINES_GETCONTEXTENTITYATTRIBUTES_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "rest/ConnectionInfo.h" -#include "ngsi/ParseData.h" - - - -/* **************************************************************************** -* -* getContextEntityAttributes - -*/ -extern std::string getContextEntityAttributes -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -); - -#endif // SRC_LIB_SERVICEROUTINES_GETCONTEXTENTITYATTRIBUTES_H_ diff --git a/src/lib/serviceRoutines/getContextEntityTypeAttribute.cpp b/src/lib/serviceRoutines/getContextEntityTypeAttribute.cpp deleted file mode 100644 index ae66d60b7f..0000000000 --- a/src/lib/serviceRoutines/getContextEntityTypeAttribute.cpp +++ /dev/null @@ -1,84 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "ngsi/ParseData.h" -#include "rest/ConnectionInfo.h" -#include "serviceRoutines/postDiscoverContextAvailability.h" -#include "serviceRoutines/getContextEntityTypeAttribute.h" - - - -/* **************************************************************************** -* -* getContextEntityTypeAttribute - -* -* GET /v1/registry/contextEntityTypes/{entityId::type}/attributes/{attributeName} -* GET /ngsi9/contextEntityTypes/{entityId::type}/attributes/{attributeName} -* -* Payload In: None -* Payload Out: DiscoverContextAvailabilityResponse -* -* 1. Fill in DiscoverContextAvailabilityRequest -* 2. Call postDiscoverContextAvailability -*/ -std::string getContextEntityTypeAttribute -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -) -{ - std::string entityType = (compV.size() == 6)? compV[3] : compV[2]; - std::string attributeName = (compV.size() == 6)? compV[5] : compV[4]; - std::string answer; - - LM_T(LmtConvenience, - ("CONVENIENCE: got a 'GET' request for entity type '%s', attribute: '%s'", - entityType.c_str(), attributeName.c_str())); - - // - // 1. Fill in parseDataP->dcar.res to pass to postDiscoverContextAvailability - // - EntityId eId(".*", entityType, "true"); - std::vector attributeV; - Restriction restriction; - - attributeV.push_back(attributeName); - parseDataP->dcar.res.fill(eId, attributeV, restriction); - - - // - // 2. Call the standard operation - // - answer = postDiscoverContextAvailability(ciP, components, compV, parseDataP); - - return answer; -} diff --git a/src/lib/serviceRoutines/getContextEntityTypeAttribute.h b/src/lib/serviceRoutines/getContextEntityTypeAttribute.h deleted file mode 100644 index 763cc6a645..0000000000 --- a/src/lib/serviceRoutines/getContextEntityTypeAttribute.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef SRC_LIB_SERVICEROUTINES_GETCONTEXTENTITYTYPEATTRIBUTE_H_ -#define SRC_LIB_SERVICEROUTINES_GETCONTEXTENTITYTYPEATTRIBUTE_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "rest/ConnectionInfo.h" -#include "ngsi/ParseData.h" - - - -/* **************************************************************************** -* -* getContextEntityTypeAttribute - -*/ -extern std::string getContextEntityTypeAttribute -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -); - -#endif // SRC_LIB_SERVICEROUTINES_GETCONTEXTENTITYTYPEATTRIBUTE_H_ diff --git a/src/lib/serviceRoutines/getContextEntityTypes.cpp b/src/lib/serviceRoutines/getContextEntityTypes.cpp deleted file mode 100644 index dd9c6b0a9b..0000000000 --- a/src/lib/serviceRoutines/getContextEntityTypes.cpp +++ /dev/null @@ -1,82 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "ngsi/ParseData.h" -#include "rest/ConnectionInfo.h" -#include "serviceRoutines/postDiscoverContextAvailability.h" -#include "serviceRoutines/getContextEntityTypes.h" - - - -/* **************************************************************************** -* -* getContextEntityTypes - -* -* GET /v1/registry/contextEntityTypes/{entityId::type} -* GET /v1/registry/contextEntityTypes/{entityId::type}/attributes -* GET /ngsi9/contextEntityTypes/{entityId::type} -* GET /ngsi9/contextEntityTypes/{entityId::type}/attributes -* -* Payload In: None -* Payload Out: DiscoverContextAvailabilityResponse -* -* 1. Fill in DiscoverContextAvailabilityRequest -* 2. Call postDiscoverContextAvailability -*/ -std::string getContextEntityTypes -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -) -{ - // Other similar functions use a condition based on compV.size(), but in this - // case is ambiguous so we use compV[0] - std::string typeName = (compV[0] == "v1")? compV[3] : compV[2]; - std::string answer; - - // - // 1. Fill in parseDataP->dcar.res to pass to postDiscoverContextAvailability - // - EntityId eId(".*", typeName, "true"); - std::vector attributeV; - Restriction restriction; - - parseDataP->dcar.res.fill(eId, attributeV, restriction); - - - // - // 2. Call the standard operation - // - answer = postDiscoverContextAvailability(ciP, components, compV, parseDataP); - - return answer; -} diff --git a/src/lib/serviceRoutines/getContextEntityTypes.h b/src/lib/serviceRoutines/getContextEntityTypes.h deleted file mode 100644 index 58087e181f..0000000000 --- a/src/lib/serviceRoutines/getContextEntityTypes.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef SRC_LIB_SERVICEROUTINES_GETCONTEXTENTITYTYPES_H_ -#define SRC_LIB_SERVICEROUTINES_GETCONTEXTENTITYTYPES_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "rest/ConnectionInfo.h" -#include "ngsi/ParseData.h" - - - -/* **************************************************************************** -* -* getContextEntityTypes - -*/ -extern std::string getContextEntityTypes -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -); - -#endif // SRC_LIB_SERVICEROUTINES_GETCONTEXTENTITYTYPES_H_ diff --git a/src/lib/serviceRoutines/getEntityByIdAttributeByName.cpp b/src/lib/serviceRoutines/getEntityByIdAttributeByName.cpp deleted file mode 100644 index 43319f8584..0000000000 --- a/src/lib/serviceRoutines/getEntityByIdAttributeByName.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "ngsi/ParseData.h" -#include "rest/ConnectionInfo.h" -#include "serviceRoutines/postDiscoverContextAvailability.h" -#include "serviceRoutines/getEntityByIdAttributeByName.h" - - - -/* **************************************************************************** -* -* getEntityByIdAttributeByName - -* -* GET /v1/registry/contextEntities/{entityId::id}/attributes/{attributeName} -* GET /ngsi9/contextEntities/{entityId::id}/attributes/{attributeName} -* -* Payload In: None -* Payload Out: DiscoverContextAvailabilityResponse -*/ -std::string getEntityByIdAttributeByName -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -) -{ - std::string entityId = (compV.size() == 6)? compV[3] : compV[2]; - std::string attributeName = (compV.size() == 6)? compV[5] : compV[4]; - std::string answer; - - // - // 1. Fill in parseDataP->dcar.res to pass to postDiscoverContextAvailability - // - EntityId eId(entityId, "", ""); - std::vector attributeV; - Restriction restriction; - - attributeV.push_back(attributeName); - - parseDataP->dcar.res.fill(eId, attributeV, restriction); - - - // - // 2. Call the standard operation - // - answer = postDiscoverContextAvailability(ciP, components, compV, parseDataP); - - return answer; -} diff --git a/src/lib/serviceRoutines/getEntityByIdAttributeByName.h b/src/lib/serviceRoutines/getEntityByIdAttributeByName.h deleted file mode 100644 index f701e43ec4..0000000000 --- a/src/lib/serviceRoutines/getEntityByIdAttributeByName.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef SRC_LIB_SERVICEROUTINES_GETENTITYBYIDATTRIBUTEBYNAME_H_ -#define SRC_LIB_SERVICEROUTINES_GETENTITYBYIDATTRIBUTEBYNAME_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "rest/ConnectionInfo.h" -#include "ngsi/ParseData.h" - - - -/* **************************************************************************** -* -* getEntityByIdAttributeByName - -*/ -extern std::string getEntityByIdAttributeByName -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -); - -#endif // SRC_LIB_SERVICEROUTINES_GETENTITYBYIDATTRIBUTEBYNAME_H_ diff --git a/src/lib/serviceRoutines/getEntityByIdAttributeByNameWithTypeAndId.cpp b/src/lib/serviceRoutines/getEntityByIdAttributeByNameWithTypeAndId.cpp deleted file mode 100644 index 1ff3eda668..0000000000 --- a/src/lib/serviceRoutines/getEntityByIdAttributeByNameWithTypeAndId.cpp +++ /dev/null @@ -1,127 +0,0 @@ -/* -* -* Copyright 2014 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/statistics.h" -#include "common/clockFunctions.h" -#include "alarmMgr/alarmMgr.h" - -#include "ngsi/ParseData.h" -#include "rest/ConnectionInfo.h" -#include "rest/EntityTypeInfo.h" -#include "rest/uriParamNames.h" -#include "serviceRoutines/postDiscoverContextAvailability.h" -#include "serviceRoutines/getEntityByIdAttributeByName.h" - - - -/* **************************************************************************** -* -* getEntityByIdAttributeByNameWithTypeAndId - -* -* GET /v1/registry/contextEntities/type/{entity::type}/id/{entity::id}/attributes/{attribute::name} -* -* Payload In: None -* Payload Out: DiscoverContextAvailabilityResponse -* -* URI parameters: -* - attributesFormat=object -* - entity::type=XXX (must coincide with entity::type in URL) -* - !exist=entity::type (if set - error -- entity::type cannot be empty) -* - exist=entity::type (not supported - ok if present, ok if not present ...) -* -* 01. Get values from URL (entityId::type, exist, !exist) -* 02. Check validity of URI params -* 03. Fill in DiscoverContextAvailabilityRequest -* 04. Call standard operation discoverContextAvailability -* 05. Cleanup and return result -*/ -std::string getEntityByIdAttributeByNameWithTypeAndId -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -) -{ - std::string entityType = compV[4]; - std::string entityId = compV[6]; - std::string attributeName = compV[8]; - std::string entityTypeFromUriParam = ciP->uriParam[URI_PARAM_ENTITY_TYPE]; - EntityTypeInfo typeInfo = EntityTypeEmptyOrNotEmpty; - std::string answer; - DiscoverContextAvailabilityResponse response; - - - // 01. Get values from URL (entityId::type, exist, !exist) - if (ciP->uriParam[URI_PARAM_NOT_EXIST] == URI_PARAM_ENTITY_TYPE) - { - typeInfo = EntityTypeEmpty; - } - else if (ciP->uriParam[URI_PARAM_EXIST] == URI_PARAM_ENTITY_TYPE) - { - typeInfo = EntityTypeNotEmpty; - } - - - // - // 02. Check validity of URI params ... - // and if OK: - // 03. Fill in DiscoverContextAvailabilityRequest - // 04. Call standard operation discoverContextAvailability - // - if (typeInfo == EntityTypeEmpty) - { - parseDataP->dcars.res.errorCode.fill(SccBadRequest, "entity::type cannot be empty for this request"); - alarmMgr.badInput(clientIp, "entity::type cannot be empty for this request"); - - TIMED_RENDER(answer = parseDataP->dcars.res.toJsonV1()); - } - else if ((entityTypeFromUriParam != entityType) && (!entityTypeFromUriParam.empty())) - { - parseDataP->dcars.res.errorCode.fill(SccBadRequest, "non-matching entity::types in URL"); - alarmMgr.badInput(clientIp, "non-matching entity::types in URL", entityTypeFromUriParam); - - TIMED_RENDER(answer = parseDataP->dcars.res.toJsonV1()); - } - else - { - // 03. Fill in DiscoverContextAvailabilityRequest - parseDataP->dcar.res.fill(entityId, entityType, typeInfo, attributeName); - - - // 04. Call standard operation - answer = postDiscoverContextAvailability(ciP, components, compV, parseDataP); - } - - - // 05. Cleanup and return result - parseDataP->dcar.res.release(); - return answer; -} diff --git a/src/lib/serviceRoutines/getEntityByIdAttributeByNameWithTypeAndId.h b/src/lib/serviceRoutines/getEntityByIdAttributeByNameWithTypeAndId.h deleted file mode 100644 index ce8585fbbb..0000000000 --- a/src/lib/serviceRoutines/getEntityByIdAttributeByNameWithTypeAndId.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef SRC_LIB_SERVICEROUTINES_GETENTITYBYIDATTRIBUTEBYNAMEWITHTYPEANDID_H_ -#define SRC_LIB_SERVICEROUTINES_GETENTITYBYIDATTRIBUTEBYNAMEWITHTYPEANDID_H_ - -/* -* -* Copyright 2014 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "rest/ConnectionInfo.h" -#include "ngsi/ParseData.h" - - - -/* **************************************************************************** -* -* getEntityByIdAttributeByNameWithTypeAndId - -*/ -extern std::string getEntityByIdAttributeByNameWithTypeAndId -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -); - -#endif // SRC_LIB_SERVICEROUTINES_GETENTITYBYIDATTRIBUTEBYNAMEWITHTYPEANDID_H_ diff --git a/src/lib/serviceRoutines/getEntityTypes.cpp b/src/lib/serviceRoutines/getEntityTypes.cpp deleted file mode 100644 index 3ade4bcda6..0000000000 --- a/src/lib/serviceRoutines/getEntityTypes.cpp +++ /dev/null @@ -1,90 +0,0 @@ -/* -* -* Copyright 2014 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "common/statistics.h" -#include "common/clockFunctions.h" - -#include "rest/ConnectionInfo.h" -#include "ngsi/ParseData.h" -#include "orionTypes/EntityTypeVectorResponse.h" -#include "serviceRoutines/getEntityTypes.h" -#include "mongoBackend/mongoQueryTypes.h" - - - -/* **************************************************************************** -* -* getEntityTypes - -* -* GET /v1/contextTypes -* -* Payload In: None -* Payload Out: EntityTypeVectorResponse -* -* URI parameters: -* - attributesFormat=object -* - collapse=true -*/ -std::string getEntityTypes -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -) -{ - EntityTypeVectorResponse response; - unsigned int totalTypes = 0; - unsigned int* totalTypesP = NULL; - - bool asJsonObject = (ciP->uriParam[URI_PARAM_ATTRIBUTE_FORMAT] == "object" && ciP->outMimeType == JSON); - - response.statusCode.fill(SccOk); - - // NGSIv1 uses details=on to request count - if (ciP->uriParam["details"] == "on") - { - totalTypesP = &totalTypes; - } - - // - // NOTE - // The last parameter for mongoEntityTypes 'bool noAttrDetail' is always - // set to true (meaning to skip the attribute detail) for NGSIv1 requests. - // The parameter is only used for NGSIv2 - // - TIMED_MONGO(mongoEntityTypes(&response, ciP->tenant, ciP->servicePathV, ciP->uriParam, ciP->apiVersion, totalTypesP, true)); - - std::string rendered; - TIMED_RENDER(rendered = response.toJsonV1(asJsonObject, - ciP->outMimeType == JSON, - ciP->uriParam[URI_PARAM_COLLAPSE] == "true")); - - response.release(); - - return rendered; -} diff --git a/src/lib/serviceRoutines/getEntityTypes.h b/src/lib/serviceRoutines/getEntityTypes.h deleted file mode 100644 index fe9c8f05c5..0000000000 --- a/src/lib/serviceRoutines/getEntityTypes.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef SRC_LIB_SERVICEROUTINES_GETENTITYTYPES_H_ -#define SRC_LIB_SERVICEROUTINES_GETENTITYTYPES_H_ - -/* -* -* Copyright 2014 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "rest/ConnectionInfo.h" -#include "ngsi/ParseData.h" - - - -/* **************************************************************************** -* -* getEntityTypes - -*/ -extern std::string getEntityTypes -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -); - -#endif // SRC_LIB_SERVICEROUTINES_GETENTITYTYPES_H_ diff --git a/src/lib/serviceRoutines/getIndividualContextEntity.cpp b/src/lib/serviceRoutines/getIndividualContextEntity.cpp deleted file mode 100644 index 8ae9b39936..0000000000 --- a/src/lib/serviceRoutines/getIndividualContextEntity.cpp +++ /dev/null @@ -1,126 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/statistics.h" -#include "common/clockFunctions.h" - -#include "ngsi/ParseData.h" -#include "ngsi/ContextElementResponse.h" -#include "rest/ConnectionInfo.h" -#include "rest/uriParamNames.h" -#include "rest/EntityTypeInfo.h" -#include "serviceRoutines/getIndividualContextEntity.h" -#include "serviceRoutines/postQueryContext.h" - - - -/* **************************************************************************** -* -* getIndividualContextEntity - -* -* GET /v1/contextEntities/{entityId::id} -* GET /ngsi10/contextEntities/{entityId::id} -* -* Payload In: None -* Payload Out: ContextElementResponse -* -* URI parameters: -* - !exist=entity::type -* - exist=entity::type -* - entity::type=TYPE -* - attributesFormat=object -* -* 0. Take care of URI params -* 1. Fill in QueryContextRequest (includes adding URI parameters as Scope in restriction) -* 2. Call standard operation -* 3. Fill in ContextElementResponse from QueryContextResponse -* 4. If 404 Not Found - enter request entity data into response context element -* 5. Render the ContextElementResponse -* 6. Cleanup and return result -*/ -std::string getIndividualContextEntity -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -) -{ - std::string answer; - std::string entityId = compV[2]; - std::string entityType = ""; - EntityTypeInfo typeInfo = EntityTypeEmptyOrNotEmpty; - ContextElementResponse response; - - bool asJsonObject = (ciP->uriParam[URI_PARAM_ATTRIBUTE_FORMAT] == "object" && ciP->outMimeType == JSON); - - // 0. Take care of URI params - if (ciP->uriParam[URI_PARAM_NOT_EXIST] == URI_PARAM_ENTITY_TYPE) - { - typeInfo = EntityTypeEmpty; - } - else if (ciP->uriParam[URI_PARAM_EXIST] == URI_PARAM_ENTITY_TYPE) - { - typeInfo = EntityTypeNotEmpty; - } - entityType = ciP->uriParam[URI_PARAM_ENTITY_TYPE]; - - - // 1. Fill in QueryContextRequest (includes adding URI parameters as Scope in restriction) - parseDataP->qcr.res.fill(entityId, entityType, "false", typeInfo, ""); - - - // 2. Call standard operation - answer = postQueryContext(ciP, components, compV, parseDataP); - - - // 3. Fill in ContextElementResponse from QueryContextResponse - response.statusCode.fill(SccOk); - response.fill(&parseDataP->qcrs.res); - - - // 4. If 404 Not Found - enter request entity data into response context element - if (response.statusCode.code == SccContextElementNotFound) - { - response.entity.fill(entityId, entityType, "false"); - response.statusCode.details = "Entity id: /" + entityId + "/"; - } - - - // 5. Render the ContextElementResponse - TIMED_RENDER(answer = response.toJsonV1(asJsonObject, IndividualContextEntity, false)); - - - // 6. Cleanup and return result - response.release(); - parseDataP->qcr.res.release(); - - return answer; -} diff --git a/src/lib/serviceRoutines/getIndividualContextEntity.h b/src/lib/serviceRoutines/getIndividualContextEntity.h deleted file mode 100644 index 325c0e8d2b..0000000000 --- a/src/lib/serviceRoutines/getIndividualContextEntity.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef SRC_LIB_SERVICEROUTINES_GETINDIVIDUALCONTEXTENTITY_H_ -#define SRC_LIB_SERVICEROUTINES_GETINDIVIDUALCONTEXTENTITY_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "ngsi/ParseData.h" -#include "rest/ConnectionInfo.h" - - - -/* **************************************************************************** -* -* getIndividualContextEntity - -*/ -extern std::string getIndividualContextEntity -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -); - -#endif // SRC_LIB_SERVICEROUTINES_GETINDIVIDUALCONTEXTENTITY_H_ diff --git a/src/lib/serviceRoutines/getIndividualContextEntityAttribute.cpp b/src/lib/serviceRoutines/getIndividualContextEntityAttribute.cpp deleted file mode 100644 index 4f46d69b48..0000000000 --- a/src/lib/serviceRoutines/getIndividualContextEntityAttribute.cpp +++ /dev/null @@ -1,133 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/statistics.h" -#include "common/clockFunctions.h" - -#include "convenience/ContextAttributeResponse.h" -#include "ngsi/ParseData.h" -#include "rest/ConnectionInfo.h" -#include "rest/uriParamNames.h" -#include "rest/EntityTypeInfo.h" -#include "serviceRoutines/postQueryContext.h" -#include "serviceRoutines/getIndividualContextEntityAttribute.h" - - - -/* **************************************************************************** -* -* getIndividualContextEntityAttribute - -* -* GET /v1/contextEntities/{entityId::id}/attributes/{attributeName} -* GET /ngsi10/contextEntities/{entityId::id}/attributes/{attributeName} -* -* Payload In: None -* Payload Out: ContextAttributeResponse -* -* URI parameters: -* - !exist=entity::type -* - exist=entity::type -* - entity::type=TYPE -* - attributesFormat=object -* -* 0. Take care of URI params -* 1. Fill in QueryContextRequest (includes adding URI parameters as Scope in restriction) -* 2. Call standard operation -* 3. Fill in ContextAttributeResponse from QueryContextResponse -* 4. If 404 Not Found - enter request entity data into response StatusCode::details -* 5. Render the ContextAttributeResponse -* 6. Cleanup and return result -*/ -std::string getIndividualContextEntityAttribute -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -) -{ - std::string answer; - std::string entityId = compV[2]; - std::string entityType = ""; - EntityTypeInfo typeInfo = EntityTypeEmptyOrNotEmpty; - std::string attributeName = compV[4]; - ContextAttributeResponse response; - - bool asJsonObject = (ciP->uriParam[URI_PARAM_ATTRIBUTE_FORMAT] == "object" && ciP->outMimeType == JSON); - - // 0. Take care of URI params - if (ciP->uriParam[URI_PARAM_NOT_EXIST] == URI_PARAM_ENTITY_TYPE) - { - typeInfo = EntityTypeEmpty; - } - else if (ciP->uriParam[URI_PARAM_EXIST] == URI_PARAM_ENTITY_TYPE) - { - typeInfo = EntityTypeNotEmpty; - } - entityType = ciP->uriParam[URI_PARAM_ENTITY_TYPE]; - - - // 1. Fill in QueryContextRequest (includes adding URI parameters as Scope in restriction) - parseDataP->qcr.res.fill(entityId, entityType, "false", typeInfo, attributeName); - - - // 2. Call standard operation - answer = postQueryContext(ciP, components, compV, parseDataP); - - - // 3. Fill in ContextAttributeResponse from QueryContextResponse - if (parseDataP->qcrs.res.contextElementResponseVector.size() != 0) - { - response.contextAttributeVector.fill(parseDataP->qcrs.res.contextElementResponseVector[0]->entity.attributeVector); - response.statusCode.fill(parseDataP->qcrs.res.contextElementResponseVector[0]->statusCode); - } - else - { - response.statusCode.fill(parseDataP->qcrs.res.errorCode); - } - - - // 4. If 404 Not Found - enter request entity data into response StatusCode::details - if (response.statusCode.code == SccContextElementNotFound) - { - response.statusCode.details = "Entity id: /" + entityId + "/"; - } - - - // 5. Render the ContextAttributeResponse - TIMED_RENDER(answer = response.toJsonV1(asJsonObject, IndividualContextEntityAttribute)); - - - // 6. Cleanup and return result - response.release(); - parseDataP->qcr.res.release(); - - return answer; -} diff --git a/src/lib/serviceRoutines/getIndividualContextEntityAttribute.h b/src/lib/serviceRoutines/getIndividualContextEntityAttribute.h deleted file mode 100644 index 32fc0aee33..0000000000 --- a/src/lib/serviceRoutines/getIndividualContextEntityAttribute.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef SRC_LIB_SERVICEROUTINES_GETINDIVIDUALCONTEXTENTITYATTRIBUTE_H_ -#define SRC_LIB_SERVICEROUTINES_GETINDIVIDUALCONTEXTENTITYATTRIBUTE_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "rest/ConnectionInfo.h" -#include "ngsi/ParseData.h" - - - -/* **************************************************************************** -* -* getIndividualContextEntityAttribute - -*/ -extern std::string getIndividualContextEntityAttribute -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -); - -#endif // SRC_LIB_SERVICEROUTINES_GETINDIVIDUALCONTEXTENTITYATTRIBUTE_H_ diff --git a/src/lib/serviceRoutines/getIndividualContextEntityAttributeWithTypeAndId.cpp b/src/lib/serviceRoutines/getIndividualContextEntityAttributeWithTypeAndId.cpp deleted file mode 100644 index c330873f62..0000000000 --- a/src/lib/serviceRoutines/getIndividualContextEntityAttributeWithTypeAndId.cpp +++ /dev/null @@ -1,146 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/statistics.h" -#include "common/clockFunctions.h" -#include "alarmMgr/alarmMgr.h" - -#include "convenience/ContextAttributeResponse.h" -#include "ngsi/ParseData.h" -#include "rest/ConnectionInfo.h" -#include "rest/EntityTypeInfo.h" -#include "rest/uriParamNames.h" -#include "serviceRoutines/postQueryContext.h" -#include "serviceRoutines/getIndividualContextEntityAttributeWithTypeAndId.h" - - - -/* **************************************************************************** -* -* getIndividualContextEntityAttributeWithTypeAndId - -* -* GET /v1/contextEntities/type/{entity::type}/id/{entity::id}/attributes/{attribute::name} -* -* Payload In: None -* Payload Out: ContextAttributeResponse -* -* URI parameters: -* - attributesFormat=object -* - entity::type=XXX (must coincide with entity::type in URL) -* - !exist=entity::type (if set - error -- entity::type cannot be empty) -* - exist=entity::type (not supported - ok if present, ok if not present ...) -* -* 01. Get values from URL (entityId::type, esist, !exist) -* 02. Check validity of URI params -* 03. Fill in QueryContextRequest -* 04. Call standard operation postQueryContext -* 05. If 404 Not Found - enter request info into response context element -* 06. Translate QueryContextResponse to ContextElementResponse -* 07. Cleanup and return result -*/ -std::string getIndividualContextEntityAttributeWithTypeAndId -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -) -{ - std::string answer; - std::string entityType = compV[3]; - std::string entityId = compV[5]; - std::string attributeName = compV[7]; - std::string entityTypeFromUriParam = ciP->uriParam[URI_PARAM_ENTITY_TYPE]; - EntityTypeInfo typeInfo = EntityTypeEmptyOrNotEmpty; - ContextAttributeResponse response; - - bool asJsonObject = (ciP->uriParam[URI_PARAM_ATTRIBUTE_FORMAT] == "object" && ciP->outMimeType == JSON); - - - // 01. Get values from URL (entityId::type, esist, !exist) - if (ciP->uriParam[URI_PARAM_NOT_EXIST] == URI_PARAM_ENTITY_TYPE) - { - typeInfo = EntityTypeEmpty; - } - else if (ciP->uriParam[URI_PARAM_EXIST] == URI_PARAM_ENTITY_TYPE) - { - typeInfo = EntityTypeNotEmpty; - } - - - // - // 02. Check validity of URI params ... - // and if OK; - // 03. Fill in QueryContextRequest - // 04. Call standard operation postQueryContext - // 05. If 404 Not Found - enter request info into response context element - // - if (typeInfo == EntityTypeEmpty) - { - parseDataP->qcrs.res.errorCode.fill(SccBadRequest, "entity::type cannot be empty for this request"); - alarmMgr.badInput(clientIp, "entity::type cannot be empty for this request"); - } - else if ((entityTypeFromUriParam != entityType) && (!entityTypeFromUriParam.empty())) - { - parseDataP->qcrs.res.errorCode.fill(SccBadRequest, "non-matching entity::types in URL"); - alarmMgr.badInput(clientIp, "non-matching entity::types in URL", entityTypeFromUriParam); - } - else - { - // 03. Fill in QueryContextRequest - parseDataP->qcr.res.fill(entityId, entityType, attributeName); - - - // 04. Call standard operation postQueryContext - parseDataP->qcrs.res.errorCode.fill(SccOk); - postQueryContext(ciP, components, compV, parseDataP); - - // 05. If 404 Not Found - enter request info into response context element - if (parseDataP->qcrs.res.errorCode.code == SccContextElementNotFound) - { - response.statusCode.details = "entityId::type/attribute::name pair not found"; - } - } - - - // 06. Translate QueryContextResponse to ContextAttributeResponse - response.fill(&parseDataP->qcrs.res, entityId, entityType, attributeName); - - - // 07. Cleanup and return result - TIMED_RENDER(answer = response.toJsonV1(asJsonObject, RtContextAttributeResponse)); - - - parseDataP->qcr.res.release(); - parseDataP->qcrs.res.release(); - response.release(); - - return answer; -} diff --git a/src/lib/serviceRoutines/getIndividualContextEntityAttributeWithTypeAndId.h b/src/lib/serviceRoutines/getIndividualContextEntityAttributeWithTypeAndId.h deleted file mode 100644 index 0493ec1ac3..0000000000 --- a/src/lib/serviceRoutines/getIndividualContextEntityAttributeWithTypeAndId.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef SRC_LIB_SERVICEROUTINES_GETINDIVIDUALCONTEXTENTITYATTRIBUTEWITHTYPEANDID_H_ -#define SRC_LIB_SERVICEROUTINES_GETINDIVIDUALCONTEXTENTITYATTRIBUTEWITHTYPEANDID_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "rest/ConnectionInfo.h" -#include "ngsi/ParseData.h" - - - -/* **************************************************************************** -* -* getIndividualContextEntityAttributeWithTypeAndId - -*/ -extern std::string getIndividualContextEntityAttributeWithTypeAndId -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -); - -#endif // SRC_LIB_SERVICEROUTINES_GETINDIVIDUALCONTEXTENTITYATTRIBUTEWITHTYPEANDID_H_ diff --git a/src/lib/serviceRoutines/getNgsi10ContextEntityTypes.cpp b/src/lib/serviceRoutines/getNgsi10ContextEntityTypes.cpp deleted file mode 100644 index afed554ab4..0000000000 --- a/src/lib/serviceRoutines/getNgsi10ContextEntityTypes.cpp +++ /dev/null @@ -1,137 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/statistics.h" -#include "common/clockFunctions.h" -#include "alarmMgr/alarmMgr.h" - -#include "ngsi/ParseData.h" -#include "rest/ConnectionInfo.h" -#include "rest/uriParamNames.h" -#include "rest/EntityTypeInfo.h" -#include "serviceRoutines/postQueryContext.h" -#include "serviceRoutines/getNgsi10ContextEntityTypes.h" - - - -/* **************************************************************************** -* -* getNgsi10ContextEntityTypes - -* -* GET /v1/contextEntityTypes/{entity::type} -* GET /ngsi10/contextEntityTypes/{entity::type} -* -* Payload In: None -* Payload Out: QueryContextResponse -* -* URI parameters: -* - attributesFormat=object -* - entity::type=XXX (must coincide with entity::type in URL) -* - !exist=entity::type (if set - error -- entity::type cannot be empty) -* - exist=entity::type (not supported - ok if present, ok if not present ...) -* -* 01. Get values from URL (entityId::type, esist, !exist) -* 02. Check validity of URI params -* 03. Fill in QueryContextRequest -* 04. Call standard operation postQueryContext (that renders the QueryContextResponse) -* 05. If 404 Not Found - enter request entityId::type into response context element -* 06. Cleanup and return result -*/ -std::string getNgsi10ContextEntityTypes -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -) -{ - std::string answer; - std::string typeName = compV[2]; - EntityTypeInfo typeInfo = EntityTypeEmptyOrNotEmpty; - std::string typeNameFromUriParam = ciP->uriParam[URI_PARAM_ENTITY_TYPE]; - - bool asJsonObject = (ciP->uriParam[URI_PARAM_ATTRIBUTE_FORMAT] == "object" && ciP->outMimeType == JSON); - - - // 01. Get values from URL (entityId::type, esist, !exist) - if (ciP->uriParam[URI_PARAM_NOT_EXIST] == URI_PARAM_ENTITY_TYPE) - { - typeInfo = EntityTypeEmpty; - } - else if (ciP->uriParam[URI_PARAM_EXIST] == URI_PARAM_ENTITY_TYPE) - { - typeInfo = EntityTypeNotEmpty; - } - - - // 02. Check validity of URI params - if (typeInfo == EntityTypeEmpty) - { - parseDataP->qcrs.res.errorCode.fill(SccBadRequest, "entity::type cannot be empty for this request"); - alarmMgr.badInput(clientIp, "entity::type cannot be empty for this request"); - - TIMED_RENDER(answer = parseDataP->qcrs.res.toJsonV1(asJsonObject)); - - parseDataP->qcr.res.release(); - return answer; - } - else if ((typeNameFromUriParam != typeName) && (!typeNameFromUriParam.empty())) - { - parseDataP->qcrs.res.errorCode.fill(SccBadRequest, "non-matching entity::types in URL"); - alarmMgr.badInput(clientIp, "non-matching entity::types in URL", typeNameFromUriParam); - - TIMED_RENDER(answer = parseDataP->qcrs.res.toJsonV1(asJsonObject)); - - parseDataP->qcr.res.release(); - return answer; - } - - - // 03. Fill in QueryContextRequest - parseDataP->qcr.res.fill(".*", typeName, ""); - - - // 04. Call standard operation postQueryContext (that renders the QueryContextResponse) - answer = postQueryContext(ciP, components, compV, parseDataP); - - - // 05. If 404 Not Found - enter request entityId::type into response context element - if (parseDataP->qcrs.res.errorCode.code == SccContextElementNotFound) - { - parseDataP->qcrs.res.errorCode.details = std::string("entityId::type /") + typeName + "/ non-existent"; - - TIMED_RENDER(answer = parseDataP->qcrs.res.toJsonV1(asJsonObject)); - } - - - // 06. Cleanup and return result - parseDataP->qcr.res.release(); - return answer; -} diff --git a/src/lib/serviceRoutines/getNgsi10ContextEntityTypes.h b/src/lib/serviceRoutines/getNgsi10ContextEntityTypes.h deleted file mode 100644 index 2908d7553c..0000000000 --- a/src/lib/serviceRoutines/getNgsi10ContextEntityTypes.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef SRC_LIB_SERVICEROUTINES_GETNGSI10CONTEXTENTITYTYPES_H_ -#define SRC_LIB_SERVICEROUTINES_GETNGSI10CONTEXTENTITYTYPES_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "rest/ConnectionInfo.h" -#include "ngsi/ParseData.h" - - - -/* **************************************************************************** -* -* getNgsi10ContextEntityTypes - -*/ -extern std::string getNgsi10ContextEntityTypes -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -); - -#endif // SRC_LIB_SERVICEROUTINES_GETNGSI10CONTEXTENTITYTYPES_H_ diff --git a/src/lib/serviceRoutines/getNgsi10ContextEntityTypesAttribute.cpp b/src/lib/serviceRoutines/getNgsi10ContextEntityTypesAttribute.cpp deleted file mode 100644 index c3c5554311..0000000000 --- a/src/lib/serviceRoutines/getNgsi10ContextEntityTypesAttribute.cpp +++ /dev/null @@ -1,136 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/statistics.h" -#include "common/clockFunctions.h" -#include "alarmMgr/alarmMgr.h" - -#include "ngsi/ParseData.h" -#include "rest/ConnectionInfo.h" -#include "rest/uriParamNames.h" -#include "rest/EntityTypeInfo.h" -#include "serviceRoutines/postQueryContext.h" -#include "serviceRoutines/getNgsi10ContextEntityTypesAttribute.h" - - - -/* **************************************************************************** -* -* getNgsi10ContextEntityTypesAttribute - -* -* GET /v1/contextEntityTypes/{entity::type}/attributes/{attribute::name} -* GET /ngsi10/contextEntityTypes/{entity::type}/attributes/{attribute::name} -* -* Payload In: None -* Payload Out: QueryContextResponse -* -* URI parameters: -* - attributesFormat=object -* - entity::type=XXX (must coincide with entity::type in URL) -* - !exist=entity::type (if set - error -- entity::type cannot be empty) -* - exist=entity::type (not supported - ok if present, ok if not present ...) -* -* 01. Get values from URL (entityId::type, esist, !exist) -* 02. Check validity of URI params -* 03. Fill in QueryContextRequest -* 04. Call standard operation postQueryContext (that renders the QueryContextResponse) -* 05. If 404 Not Found - enter request entityId::type into response context element -* 06. Cleanup and return result -*/ -std::string getNgsi10ContextEntityTypesAttribute -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -) -{ - std::string answer; - std::string typeName = compV[2]; - std::string attributeName = compV[4]; - EntityTypeInfo typeInfo = EntityTypeEmptyOrNotEmpty; - std::string typeNameFromUriParam = ciP->uriParam[URI_PARAM_ENTITY_TYPE]; - - bool asJsonObject = (ciP->uriParam[URI_PARAM_ATTRIBUTE_FORMAT] == "object" && ciP->outMimeType == JSON); - - - // 01. Get values from URL (entityId::type, esist, !exist) - if (ciP->uriParam[URI_PARAM_NOT_EXIST] == URI_PARAM_ENTITY_TYPE) - { - typeInfo = EntityTypeEmpty; - } - else if (ciP->uriParam[URI_PARAM_EXIST] == URI_PARAM_ENTITY_TYPE) - { - typeInfo = EntityTypeNotEmpty; - } - - - // 02. Check validity of URI params - if (typeInfo == EntityTypeEmpty) - { - parseDataP->qcrs.res.errorCode.fill(SccBadRequest, "entity::type cannot be empty for this request"); - alarmMgr.badInput(clientIp, "entity::type cannot be empty for this request"); - - TIMED_RENDER(answer = parseDataP->qcrs.res.toJsonV1(asJsonObject)); - parseDataP->qcr.res.release(); - return answer; - } - else if ((typeNameFromUriParam != typeName) && (!typeNameFromUriParam.empty())) - { - parseDataP->qcrs.res.errorCode.fill(SccBadRequest, "non-matching entity::types in URL"); - alarmMgr.badInput(clientIp, "non-matching entity::types in URL", typeNameFromUriParam); - - TIMED_RENDER(answer = parseDataP->qcrs.res.toJsonV1(asJsonObject)); - parseDataP->qcr.res.release(); - return answer; - } - - - // 03. Fill in QueryContextRequest - parseDataP->qcr.res.fill(".*", typeName, attributeName); - - - // 04. Call standard operation postQueryContext (that renders the QueryContextResponse) - answer = postQueryContext(ciP, components, compV, parseDataP); - - - // 05. If 404 Not Found - enter request ifo into response context element - if (parseDataP->qcrs.res.errorCode.code == SccContextElementNotFound) - { - parseDataP->qcrs.res.errorCode.details = "entityId::type/attribute::name pair not found"; - - TIMED_RENDER(answer = parseDataP->qcrs.res.toJsonV1(asJsonObject)); - } - - - // 06. Cleanup and return result - parseDataP->qcr.res.release(); - return answer; -} diff --git a/src/lib/serviceRoutines/getNgsi10ContextEntityTypesAttribute.h b/src/lib/serviceRoutines/getNgsi10ContextEntityTypesAttribute.h deleted file mode 100644 index 06b7752aa3..0000000000 --- a/src/lib/serviceRoutines/getNgsi10ContextEntityTypesAttribute.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef SRC_LIB_SERVICEROUTINES_GETNGSI10CONTEXTENTITYTYPESATTRIBUTE_H_ -#define SRC_LIB_SERVICEROUTINES_GETNGSI10CONTEXTENTITYTYPESATTRIBUTE_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "rest/ConnectionInfo.h" -#include "ngsi/ParseData.h" - - - -/* **************************************************************************** -* -* getNgsi10ContextEntityTypesAttribute - -*/ -extern std::string getNgsi10ContextEntityTypesAttribute -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -); - -#endif // SRC_LIB_SERVICEROUTINES_GETNGSI10CONTEXTENTITYTYPESATTRIBUTE_H_ diff --git a/src/lib/serviceRoutines/leakTreat.cpp b/src/lib/serviceRoutines/leakTreat.cpp index 24fcd54183..fe42f4f09d 100644 --- a/src/lib/serviceRoutines/leakTreat.cpp +++ b/src/lib/serviceRoutines/leakTreat.cpp @@ -61,7 +61,7 @@ std::string leakTreat OrionError orionError(SccBadRequest, "no such service"); ciP->httpStatusCode = SccOk; - TIMED_RENDER(out = orionError.toJsonV1()); + TIMED_RENDER(out = orionError.toJson()); return out; } @@ -75,14 +75,14 @@ std::string leakTreat OrionError orionError(SccBadRequest, "Password requested"); ciP->httpStatusCode = SccOk; - TIMED_RENDER(out = orionError.toJsonV1()); + TIMED_RENDER(out = orionError.toJson()); } else if (password != "harakiri") { OrionError orionError(SccBadRequest, "Request denied - password erroneous"); ciP->httpStatusCode = SccOk; - TIMED_RENDER(out = orionError.toJsonV1()); + TIMED_RENDER(out = orionError.toJson()); } else { @@ -90,7 +90,7 @@ std::string leakTreat std::string pwd = strdup("Leak test done"); OrionError orionError(SccOk, "Leak test: " + pwd); - TIMED_RENDER(out = orionError.toJsonV1()); + TIMED_RENDER(out = orionError.toJson()); } return out; diff --git a/src/lib/serviceRoutines/logTraceTreat.cpp b/src/lib/serviceRoutines/logTraceTreat.cpp index 4a49199d5a..aacfa4af67 100644 --- a/src/lib/serviceRoutines/logTraceTreat.cpp +++ b/src/lib/serviceRoutines/logTraceTreat.cpp @@ -100,7 +100,7 @@ std::string logTraceTreat { OrionError error(SccBadRequest, std::string("bad URL/Verb: ") + ciP->method + " " + path); - TIMED_RENDER(out = error.toJsonV1()); + TIMED_RENDER(out = error.toJson()); } return out; diff --git a/src/lib/serviceRoutines/postAllEntitiesWithTypeAndId.cpp b/src/lib/serviceRoutines/postAllEntitiesWithTypeAndId.cpp deleted file mode 100644 index d702d36e66..0000000000 --- a/src/lib/serviceRoutines/postAllEntitiesWithTypeAndId.cpp +++ /dev/null @@ -1,165 +0,0 @@ -/* -* -* Copyright 2014 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/statistics.h" -#include "common/clockFunctions.h" -#include "alarmMgr/alarmMgr.h" - -#include "ngsi/ParseData.h" -#include "rest/ConnectionInfo.h" -#include "rest/uriParamNames.h" -#include "rest/EntityTypeInfo.h" -#include "convenience/AppendContextElementRequest.h" -#include "convenience/AppendContextElementResponse.h" -#include "serviceRoutines/postUpdateContext.h" -#include "serviceRoutines/postAllEntitiesWithTypeAndId.h" - - - -/* **************************************************************************** -* -* postAllEntitiesWithTypeAndId - -* -* POST /v1/contextEntities/type/{entity::type}/id/{entity::id} -* -* Payload In: AppendContextElementRequest -* Payload Out: AppendContextElementResponse -* -* URI parameters: -* - attributesFormat=object -* - entity::type=TYPE (must coincide with type in URL-path) -* - !exist=entity::type (if set - error -- entity::type cannot be empty) -* - exist=entity::type (not supported - ok if present, ok if not present ...) -* -* NOTE: -* This service routine responds with an error if any part of the EntityId in -* the payload is filled in. -* -* 01. Get values from URL (entityId::type, exist, !exist) -* 02. Check that the entity is NOT filled in in the payload -* 03. Check validity of URI params -* 04. Fill in UpdateContextRequest -* 05. Call Standard Operation -* 06. Fill in response from UpdateContextReSponse -* 07. Cleanup and return result -*/ -std::string postAllEntitiesWithTypeAndId -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -) -{ - std::string entityType = compV[3]; - std::string entityId = compV[5]; - EntityTypeInfo typeInfo = EntityTypeEmptyOrNotEmpty; - std::string typeNameFromUriParam = ciP->uriParam[URI_PARAM_ENTITY_TYPE]; - AppendContextElementRequest* reqP = &parseDataP->acer.res; - std::string answer; - AppendContextElementResponse response; - - bool asJsonObject = (ciP->uriParam[URI_PARAM_ATTRIBUTE_FORMAT] == "object" && ciP->outMimeType == JSON); - - // 01. Get values from URL (entityId::type, esist, !exist) - if (ciP->uriParam[URI_PARAM_NOT_EXIST] == URI_PARAM_ENTITY_TYPE) - { - typeInfo = EntityTypeEmpty; - } - else if (ciP->uriParam[URI_PARAM_EXIST] == URI_PARAM_ENTITY_TYPE) - { - typeInfo = EntityTypeNotEmpty; - } - - - // 02. Check that the entity is NOT filled in the payload - if ((!reqP->entity.id.empty()) || (!reqP->entity.type.empty()) || (!reqP->entity.isPattern.empty())) - { - std::string out; - - alarmMgr.badInput(clientIp, "some of entity id, type or isPattern is not empty"); - response.errorCode.fill(SccBadRequest, "invalid payload: unknown fields"); - - TIMED_RENDER(out = response.toJsonV1(asJsonObject, IndividualContextEntity)); - - return out; - } - - - // 03. Check validity of URI params - if (typeInfo == EntityTypeEmpty) - { - alarmMgr.badInput(clientIp, "entity::type cannot be empty for this request"); - - response.errorCode.fill(SccBadRequest, "entity::type cannot be empty for this request"); - response.entity.fill(entityId, entityType, "false"); - - TIMED_RENDER(answer = response.toJsonV1(asJsonObject, AllEntitiesWithTypeAndId)); - - parseDataP->acer.res.release(); - return answer; - } - else if ((typeNameFromUriParam != entityType) && (!typeNameFromUriParam.empty())) - { - alarmMgr.badInput(clientIp, "non-matching entity::types in URL", typeNameFromUriParam); - - response.errorCode.fill(SccBadRequest, "non-matching entity::types in URL"); - response.entity.fill(entityId, entityType, "false"); - - TIMED_RENDER(answer = response.toJsonV1(asJsonObject, AllEntitiesWithTypeAndId)); - - parseDataP->acer.res.release(); - return answer; - } - - // Now, forward Entity to response - response.entity.fill(entityId, entityType, "false"); - - - // 04. Fill in UpdateContextRequest - parseDataP->upcr.res.fill(&parseDataP->acer.res, entityId, entityType); - - - // 05. Call Standard Operation - postUpdateContext(ciP, components, compV, parseDataP); - - - // 06. Fill in response from UpdateContextReSponse - response.fill(&parseDataP->upcrs.res, entityId, entityType); - - - // 07. Cleanup and return result - TIMED_RENDER(answer = response.toJsonV1(asJsonObject, IndividualContextEntity)); - - parseDataP->upcr.res.release(); - response.release(); - - return answer; -} diff --git a/src/lib/serviceRoutines/postAllEntitiesWithTypeAndId.h b/src/lib/serviceRoutines/postAllEntitiesWithTypeAndId.h deleted file mode 100644 index 6d421d63dd..0000000000 --- a/src/lib/serviceRoutines/postAllEntitiesWithTypeAndId.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef SRC_LIB_SERVICEROUTINES_POSTALLENTITIESWITHTYPEANDID_H_ -#define SRC_LIB_SERVICEROUTINES_POSTALLENTITIESWITHTYPEANDID_H_ - -/* -* -* Copyright 2014 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "rest/ConnectionInfo.h" -#include "ngsi/ParseData.h" - - - -/* **************************************************************************** -* -* postAllEntitiesWithTypeAndId - -*/ -extern std::string postAllEntitiesWithTypeAndId -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -); - -#endif // SRC_LIB_SERVICEROUTINES_POSTALLENTITIESWITHTYPEANDID_H_ diff --git a/src/lib/serviceRoutines/postContextEntitiesByEntityId.cpp b/src/lib/serviceRoutines/postContextEntitiesByEntityId.cpp deleted file mode 100644 index 0f90ab151e..0000000000 --- a/src/lib/serviceRoutines/postContextEntitiesByEntityId.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "rest/ConnectionInfo.h" -#include "ngsi/ParseData.h" -#include "serviceRoutines/postRegisterContext.h" -#include "serviceRoutines/postContextEntitiesByEntityId.h" - - - -/* **************************************************************************** -* -* postContextEntitiesByEntityId - -* -* POST /v1/registry/contextEntities/{entityId} -* POST /ngsi9/contextEntities/{entityId} -* -* Payload In: RegisterProviderRequest -* Payload Out: RegisterContextResponse -* -* 1. Transform RegisterProviderRequest+entityId into a RegisterContextRequest -* 2. Call the Standard operation for RegisterContextRequest -*/ -std::string postContextEntitiesByEntityId -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -) -{ - std::string entityId = (compV.size() == 4)? compV[3] : compV[2]; - std::string answer; - - parseDataP->rcr.res.fill(parseDataP->rpr.res, entityId, "", ""); - answer = postRegisterContext(ciP, components, compV, parseDataP); - - parseDataP->rcr.res.release(); - - return answer; -} diff --git a/src/lib/serviceRoutines/postContextEntitiesByEntityId.h b/src/lib/serviceRoutines/postContextEntitiesByEntityId.h deleted file mode 100644 index c0dfa14e78..0000000000 --- a/src/lib/serviceRoutines/postContextEntitiesByEntityId.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef SRC_LIB_SERVICEROUTINES_POSTCONTEXTENTITIESBYENTITYID_H_ -#define SRC_LIB_SERVICEROUTINES_POSTCONTEXTENTITIESBYENTITYID_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "rest/ConnectionInfo.h" -#include "ngsi/ParseData.h" - - - -/* **************************************************************************** -* -* postContextEntitiesByEntityId - -*/ -extern std::string postContextEntitiesByEntityId -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -); - -#endif // SRC_LIB_SERVICEROUTINES_POSTCONTEXTENTITIESBYENTITYID_H_ diff --git a/src/lib/serviceRoutines/postContextEntitiesByEntityIdAndType.cpp b/src/lib/serviceRoutines/postContextEntitiesByEntityIdAndType.cpp deleted file mode 100644 index 860ff4814e..0000000000 --- a/src/lib/serviceRoutines/postContextEntitiesByEntityIdAndType.cpp +++ /dev/null @@ -1,128 +0,0 @@ -/* -* -* Copyright 2014 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/statistics.h" -#include "common/clockFunctions.h" -#include "alarmMgr/alarmMgr.h" - -#include "ngsi/ParseData.h" -#include "ngsi9/RegisterContextRequest.h" -#include "rest/ConnectionInfo.h" -#include "rest/uriParamNames.h" -#include "rest/EntityTypeInfo.h" -#include "serviceRoutines/postRegisterContext.h" -#include "serviceRoutines/postContextEntitiesByEntityIdAndType.h" - - - -/* **************************************************************************** -* -* postContextEntitiesByEntityIdAndType - -* -* POST /v1/registry/contextEntities/type/{entity::type}/id/{entity::id} -* -* Payload In: RegisterProviderRequest -* Payload Out: RegisterContextResponse -* -* URI parameters: -* - entity::type=TYPE (must coincide with type in URL-path) -* - !exist=entity::type (if set - error -- entity::type cannot be empty) -* - exist=entity::type (not supported - ok if present, ok if not present ...) -* -* 01. Get values from URL (entityId::type, exist, !exist) -* 02. Check validity of URI params -* 03. Fill in RegisterContextRequest from RegisterProviderRequest -* 04. Call standard op postRegisterContext -* 05. Cleanup and return answer -*/ -std::string postContextEntitiesByEntityIdAndType -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -) -{ - std::string entityType = compV[4]; - std::string entityId = compV[6]; - EntityTypeInfo typeInfo = EntityTypeEmptyOrNotEmpty; - std::string typeNameFromUriParam = ciP->uriParam[URI_PARAM_ENTITY_TYPE]; - std::string answer; - RegisterContextResponse response; - - // 01. Get values from URL (entityId::type, exist, !exist) - if (ciP->uriParam[URI_PARAM_NOT_EXIST] == URI_PARAM_ENTITY_TYPE) - { - typeInfo = EntityTypeEmpty; - } - else if (ciP->uriParam[URI_PARAM_EXIST] == URI_PARAM_ENTITY_TYPE) - { - typeInfo = EntityTypeNotEmpty; - } - - - // 02. Check validity of URI params - if (typeInfo == EntityTypeEmpty) - { - alarmMgr.badInput(clientIp, "entity::type cannot be empty for this request"); - - response.errorCode.fill(SccBadRequest, "entity::type cannot be empty for this request"); - response.registrationId.set("000000000000000000000000"); - - TIMED_RENDER(answer = response.toJsonV1()); - - return answer; - } - else if ((typeNameFromUriParam != entityType) && (!typeNameFromUriParam.empty())) - { - alarmMgr.badInput(clientIp, "non-matching entity::types in URL", typeNameFromUriParam); - - response.errorCode.fill(SccBadRequest, "non-matching entity::types in URL"); - response.registrationId.set("000000000000000000000000"); - - TIMED_RENDER(answer = response.toJsonV1()); - - return answer; - } - - - // 03. Fill in RegisterContextRequest from RegisterProviderRequest - parseDataP->rcr.res.fill(parseDataP->rpr.res, entityId, entityType, ""); - - - // 04. Call standard op postRegisterContext - answer = postRegisterContext(ciP, components, compV, parseDataP); - - - // 05. Cleanup and return answer - parseDataP->rcr.res.release(); - - return answer; -} diff --git a/src/lib/serviceRoutines/postContextEntitiesByEntityIdAndType.h b/src/lib/serviceRoutines/postContextEntitiesByEntityIdAndType.h deleted file mode 100644 index fcbd307e5c..0000000000 --- a/src/lib/serviceRoutines/postContextEntitiesByEntityIdAndType.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef SRC_LIB_SERVICEROUTINES_POSTCONTEXTENTITIESBYENTITYIDANDTYPE_H_ -#define SRC_LIB_SERVICEROUTINES_POSTCONTEXTENTITIESBYENTITYIDANDTYPE_H_ - -/* -* -* Copyright 2014 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "rest/ConnectionInfo.h" -#include "ngsi/ParseData.h" - - - -/* **************************************************************************** -* -* postContextEntitiesByEntityIdAndType - -*/ -extern std::string postContextEntitiesByEntityIdAndType -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -); - -#endif // SRC_LIB_SERVICEROUTINES_POSTCONTEXTENTITIESBYENTITYIDANDTYPE_H_ diff --git a/src/lib/serviceRoutines/postContextEntityAttributes.cpp b/src/lib/serviceRoutines/postContextEntityAttributes.cpp deleted file mode 100644 index 4bacc80b06..0000000000 --- a/src/lib/serviceRoutines/postContextEntityAttributes.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "rest/ConnectionInfo.h" -#include "ngsi/ParseData.h" -#include "serviceRoutines/postRegisterContext.h" -#include "serviceRoutines/postContextEntityAttributes.h" - - - -/* **************************************************************************** -* -* postContextEntityAttributes - -* -* POST /v1/registry/contextEntities/{entityId}/attributes -* POST /ngsi9/contextEntities/{entityId}/attributes -* -* Payload In: RegisterProviderRequest -* Payload Out: RegisterContextResponse -* -* 1. Transform RegisterProviderRequest+entityId into a RegisterContextRequest -* 2. Call the Standard operation for RegisterContextRequest -*/ -std::string postContextEntityAttributes -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -) -{ - std::string entityId = (compV.size() == 5)? compV[3] : compV[2]; - std::string answer; - - parseDataP->rcr.res.fill(parseDataP->rpr.res, entityId, "", ""); - answer = postRegisterContext(ciP, components, compV, parseDataP); - - parseDataP->rcr.res.release(); - - return answer; -} diff --git a/src/lib/serviceRoutines/postContextEntityAttributes.h b/src/lib/serviceRoutines/postContextEntityAttributes.h deleted file mode 100644 index 3e0b8bf1cd..0000000000 --- a/src/lib/serviceRoutines/postContextEntityAttributes.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef SRC_LIB_SERVICEROUTINES_POSTCONTEXTENTITYATTRIBUTES_H_ -#define SRC_LIB_SERVICEROUTINES_POSTCONTEXTENTITYATTRIBUTES_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "rest/ConnectionInfo.h" -#include "ngsi/ParseData.h" - - - -/* **************************************************************************** -* -* postContextEntityAttributes - -*/ -extern std::string postContextEntityAttributes -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -); - -#endif // SRC_LIB_SERVICEROUTINES_POSTCONTEXTENTITYATTRIBUTES_H_ diff --git a/src/lib/serviceRoutines/postContextEntityTypeAttribute.cpp b/src/lib/serviceRoutines/postContextEntityTypeAttribute.cpp deleted file mode 100644 index cff9bb3cc3..0000000000 --- a/src/lib/serviceRoutines/postContextEntityTypeAttribute.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "rest/ConnectionInfo.h" -#include "ngsi/ParseData.h" -#include "serviceRoutines/postRegisterContext.h" -#include "serviceRoutines/postContextEntityTypeAttribute.h" - - - -/* **************************************************************************** -* -* postContextEntityTypeAttribute - -* -* POST /ngsi9/contextEntityTypes/{typeName}/attributes/{attributeName} -* POST /v1/registry/contextEntityTypes/{typeName}/attributes/{attributeName} -* -* Payload In: RegisterProviderRequest -* Payload Out: RegisterContextResponse -* -* 1. Transform RegisterProviderRequest+typeName+attributeName into a RegisterContextRequest -* 2. Call the Standard operation for RegisterContextRequest -*/ -std::string postContextEntityTypeAttribute -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -) -{ - std::string entityIdType = (compV.size() == 6)? compV[3] : compV[2]; - std::string attributeName = (compV.size() == 6)? compV[5] : compV[4]; - std::string answer; - - parseDataP->rcr.res.fill(parseDataP->rpr.res, "", entityIdType, attributeName); - answer = postRegisterContext(ciP, components, compV, parseDataP); - - parseDataP->rcr.res.release(); - - return answer; -} diff --git a/src/lib/serviceRoutines/postContextEntityTypeAttribute.h b/src/lib/serviceRoutines/postContextEntityTypeAttribute.h deleted file mode 100644 index 5037b8d412..0000000000 --- a/src/lib/serviceRoutines/postContextEntityTypeAttribute.h +++ /dev/null @@ -1,51 +0,0 @@ -#ifndef SRC_LIB_SERVICEROUTINES_POSTCONTEXTENTITYTYPEATTRIBUTE_H_ -#define SRC_LIB_SERVICEROUTINES_POSTCONTEXTENTITYTYPEATTRIBUTE_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "ngsi/ParseData.h" -#include "rest/ConnectionInfo.h" - - - -/* **************************************************************************** -* -* postContextEntityTypeAttribute - -*/ -extern std::string postContextEntityTypeAttribute -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -); - -#endif // SRC_LIB_SERVICEROUTINES_POSTCONTEXTENTITYTYPEATTRIBUTE_H_ diff --git a/src/lib/serviceRoutines/postContextEntityTypes.cpp b/src/lib/serviceRoutines/postContextEntityTypes.cpp deleted file mode 100644 index d2b373c964..0000000000 --- a/src/lib/serviceRoutines/postContextEntityTypes.cpp +++ /dev/null @@ -1,73 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "ngsi/ParseData.h" -#include "ngsi9/RegisterContextResponse.h" -#include "rest/ConnectionInfo.h" -#include "serviceRoutines/postRegisterContext.h" -#include "serviceRoutines/postContextEntityTypes.h" - - - -/* **************************************************************************** -* -* postContextEntityTypes - -* -* POST /v1/registry/contextEntityTypes/{entityType} -* POST /v1/registry/contextEntityTypes/{entityType}/attributes -* POST /ngsi9/contextEntityTypes/{entityType} -* POST /ngsi9/contextEntityTypes/{entityType}/attributes -* -* Payload In: RegisterProviderRequest -* Payload Out: RegisterContextResponse -* -* 1. Transform RegisterProviderRequest+entityType into a RegisterContextRequest -* 2. Call the Standard operation for RegisterContextRequest -*/ -std::string postContextEntityTypes -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -) -{ - // Other similar functions use a condition based on compV.size(), but in this - // case is ambiguous so we use compV[0] - std::string entityType = (compV[0] == "v1")? compV[3] : compV[2]; - std::string answer; - - parseDataP->rcr.res.fill(parseDataP->rpr.res, "", entityType, ""); - answer = postRegisterContext(ciP, components, compV, parseDataP); - - parseDataP->rcr.res.release(); - - return answer; -} diff --git a/src/lib/serviceRoutines/postContextEntityTypes.h b/src/lib/serviceRoutines/postContextEntityTypes.h deleted file mode 100644 index 34fdc67fad..0000000000 --- a/src/lib/serviceRoutines/postContextEntityTypes.h +++ /dev/null @@ -1,51 +0,0 @@ -#ifndef SRC_LIB_SERVICEROUTINES_POSTCONTEXTENTITYTYPES_H_ -#define SRC_LIB_SERVICEROUTINES_POSTCONTEXTENTITYTYPES_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "ngsi/ParseData.h" -#include "rest/ConnectionInfo.h" - - - -/* **************************************************************************** -* -* postContextEntityTypes - -*/ -extern std::string postContextEntityTypes -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -); - -#endif // SRC_LIB_SERVICEROUTINES_POSTCONTEXTENTITYTYPES_H_ diff --git a/src/lib/serviceRoutines/postDiscoverContextAvailability.cpp b/src/lib/serviceRoutines/postDiscoverContextAvailability.cpp deleted file mode 100644 index 9c726b7250..0000000000 --- a/src/lib/serviceRoutines/postDiscoverContextAvailability.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/statistics.h" -#include "common/clockFunctions.h" - -#include "mongoBackend/mongoDiscoverContextAvailability.h" -#include "ngsi/ParseData.h" -#include "ngsi9/DiscoverContextAvailabilityResponse.h" -#include "rest/ConnectionInfo.h" -#include "serviceRoutines/postDiscoverContextAvailability.h" -#include "jsonParse/jsonDiscoverContextAvailabilityRequest.h" - - - -/* **************************************************************************** -* -* postDiscoverContextAvailability - -*/ -std::string postDiscoverContextAvailability -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -) -{ - DiscoverContextAvailabilityResponse* dcarP = &parseDataP->dcars.res; - std::string answer; - - TIMED_MONGO(ciP->httpStatusCode = mongoDiscoverContextAvailability(&parseDataP->dcar.res, dcarP, ciP->tenant, ciP->uriParam, ciP->servicePathV)); - TIMED_RENDER(answer = dcarP->toJsonV1()); - - return answer; -} diff --git a/src/lib/serviceRoutines/postDiscoverContextAvailability.h b/src/lib/serviceRoutines/postDiscoverContextAvailability.h deleted file mode 100644 index 6a7d5a64f0..0000000000 --- a/src/lib/serviceRoutines/postDiscoverContextAvailability.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef SRC_LIB_SERVICEROUTINES_POSTDISCOVERCONTEXTAVAILABILITY_H_ -#define SRC_LIB_SERVICEROUTINES_POSTDISCOVERCONTEXTAVAILABILITY_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "rest/ConnectionInfo.h" -#include "ngsi/ParseData.h" - - - -/* **************************************************************************** -* -* postDiscoverContextAvailability - -*/ -extern std::string postDiscoverContextAvailability -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -); - -#endif // SRC_LIB_SERVICEROUTINES_POSTDISCOVERCONTEXTAVAILABILITY_H_ diff --git a/src/lib/serviceRoutines/postEntityByIdAttributeByName.cpp b/src/lib/serviceRoutines/postEntityByIdAttributeByName.cpp deleted file mode 100644 index 643cd91f66..0000000000 --- a/src/lib/serviceRoutines/postEntityByIdAttributeByName.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "rest/ConnectionInfo.h" -#include "ngsi/ParseData.h" -#include "serviceRoutines/postRegisterContext.h" -#include "serviceRoutines/postEntityByIdAttributeByName.h" - - - -/* **************************************************************************** -* -* postEntityByIdAttributeByName - -* -* POST /v1/registry/contextEntities/{entityId}/attributes/{attributeName} -* POST /ngsi9/contextEntities/{entityId}/attributes/{attributeName} -* -* Payload In: RegisterProviderRequest -* Payload Out: RegisterContextResponse -* -* 1. Transform RegisterProviderRequest+entityId+attributeName into a RegisterContextRequest -* 2. Call the Standard operation for RegisterContextRequest -*/ -std::string postEntityByIdAttributeByName -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -) -{ - std::string entityId = (compV.size() == 6)? compV[3] : compV[2]; - std::string attributeName = (compV.size() == 6)? compV[5] : compV[4]; - std::string answer; - - parseDataP->rcr.res.fill(parseDataP->rpr.res, entityId, "", attributeName); - answer = postRegisterContext(ciP, components, compV, parseDataP); - - parseDataP->rcr.res.release(); - - return answer; -} diff --git a/src/lib/serviceRoutines/postEntityByIdAttributeByName.h b/src/lib/serviceRoutines/postEntityByIdAttributeByName.h deleted file mode 100644 index 5cfee90102..0000000000 --- a/src/lib/serviceRoutines/postEntityByIdAttributeByName.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef SRC_LIB_SERVICEROUTINES_POSTENTITYBYIDATTRIBUTEBYNAME_H_ -#define SRC_LIB_SERVICEROUTINES_POSTENTITYBYIDATTRIBUTEBYNAME_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "ngsi/ParseData.h" -#include "rest/ConnectionInfo.h" - - - -/* **************************************************************************** -* -* postEntityByIdAttributeByName - -*/ -extern std::string postEntityByIdAttributeByName -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -); - -#endif // SRC_LIB_SERVICEROUTINES_POSTENTITYBYIDATTRIBUTEBYNAME_H_ diff --git a/src/lib/serviceRoutines/postEntityByIdAttributeByNameWithTypeAndId.cpp b/src/lib/serviceRoutines/postEntityByIdAttributeByNameWithTypeAndId.cpp deleted file mode 100644 index ac25494427..0000000000 --- a/src/lib/serviceRoutines/postEntityByIdAttributeByNameWithTypeAndId.cpp +++ /dev/null @@ -1,126 +0,0 @@ -/* -* -* Copyright 2014 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/statistics.h" -#include "common/clockFunctions.h" -#include "alarmMgr/alarmMgr.h" - -#include "ngsi/ParseData.h" -#include "ngsi9/RegisterContextRequest.h" -#include "rest/ConnectionInfo.h" -#include "rest/EntityTypeInfo.h" -#include "rest/uriParamNames.h" -#include "serviceRoutines/postRegisterContext.h" -#include "serviceRoutines/postEntityByIdAttributeByNameWithTypeAndId.h" - - - -/* **************************************************************************** -* -* postEntityByIdAttributeByNameWithTypeAndId - -* -* POST /v1/registry/contextEntities/type/{entity::type}/id/{entity::id}/attributes/{attribute::name} -* -* Payload In: RegisterProviderRequest -* Payload Out: RegisterContextResponse -* -* URI parameters: -* - entity::type=XXX (must coincide with entity::type in URL) -* - !exist=entity::type (if set - error -- entity::type cannot be empty) -* - exist=entity::type (not supported - ok if present, ok if not present ...) -* -* 01. Get values from URL (entityId::type, exist, !exist) -* 02. Check validity of URI params -* 03. Fill in RegisterContextRequest -* 04. Call standard operation postRegisterContext -* 05. Cleanup and return result -*/ -std::string postEntityByIdAttributeByNameWithTypeAndId -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -) -{ - std::string entityType = compV[4]; - std::string entityId = compV[6]; - std::string attributeName = compV[8]; - std::string entityTypeFromUriParam = ciP->uriParam[URI_PARAM_ENTITY_TYPE]; - EntityTypeInfo typeInfo = EntityTypeEmptyOrNotEmpty; - std::string answer; - - - // 01. Get values from URL (entityId::type, exist, !exist) - if (ciP->uriParam[URI_PARAM_NOT_EXIST] == URI_PARAM_ENTITY_TYPE) - { - typeInfo = EntityTypeEmpty; - } - else if (ciP->uriParam[URI_PARAM_EXIST] == URI_PARAM_ENTITY_TYPE) - { - typeInfo = EntityTypeNotEmpty; - } - - - // - // 02. Check validity of URI params ... - // and if OK: - // 03. Fill in RegisterContextRequest - // 04. Call standard operation postRegisterContext - // - if (typeInfo == EntityTypeEmpty) - { - parseDataP->rcrs.res.errorCode.fill(SccBadRequest, "entity::type cannot be empty for this request"); - alarmMgr.badInput(clientIp, "entity::type cannot be empty for this request"); - - TIMED_RENDER(answer = parseDataP->rcrs.res.toJsonV1()); - } - else if ((entityTypeFromUriParam != entityType) && (!entityTypeFromUriParam.empty())) - { - parseDataP->rcrs.res.errorCode.fill(SccBadRequest, "non-matching entity::types in URL"); - alarmMgr.badInput(clientIp, "non-matching entity::types in URL", entityTypeFromUriParam); - - TIMED_RENDER(answer = parseDataP->rcrs.res.toJsonV1()); - } - else - { - // 03. Fill in RegisterContextRequest - parseDataP->rcr.res.fill(parseDataP->rpr.res, entityId, entityType, attributeName); - - // 04. Call standard operation postRegisterContext - answer = postRegisterContext(ciP, components, compV, parseDataP); - } - - - // 05. Cleanup and return result - parseDataP->rcr.res.release(); - - return answer; -} diff --git a/src/lib/serviceRoutines/postEntityByIdAttributeByNameWithTypeAndId.h b/src/lib/serviceRoutines/postEntityByIdAttributeByNameWithTypeAndId.h deleted file mode 100644 index b036be4d7f..0000000000 --- a/src/lib/serviceRoutines/postEntityByIdAttributeByNameWithTypeAndId.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef SRC_LIB_SERVICEROUTINES_POSTENTITYBYIDATTRIBUTEBYNAMEWITHTYPEANDID_H_ -#define SRC_LIB_SERVICEROUTINES_POSTENTITYBYIDATTRIBUTEBYNAMEWITHTYPEANDID_H_ - -/* -* -* Copyright 2014 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "ngsi/ParseData.h" -#include "rest/ConnectionInfo.h" - - - -/* **************************************************************************** -* -* postEntityByIdAttributeByNameWithTypeAndId - -*/ -extern std::string postEntityByIdAttributeByNameWithTypeAndId -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -); - -#endif // SRC_LIB_SERVICEROUTINES_POSTENTITYBYIDATTRIBUTEBYNAMEWITHTYPEANDID_H_ diff --git a/src/lib/serviceRoutines/postIndividualContextEntity.cpp b/src/lib/serviceRoutines/postIndividualContextEntity.cpp deleted file mode 100644 index 49f875a086..0000000000 --- a/src/lib/serviceRoutines/postIndividualContextEntity.cpp +++ /dev/null @@ -1,182 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/statistics.h" -#include "common/clockFunctions.h" -#include "alarmMgr/alarmMgr.h" - -#include "convenience/AppendContextElementRequest.h" -#include "convenience/AppendContextElementResponse.h" -#include "ngsi/ParseData.h" -#include "rest/ConnectionInfo.h" -#include "rest/uriParamNames.h" -#include "serviceRoutines/postUpdateContext.h" -#include "serviceRoutines/postIndividualContextEntity.h" - - - -/* **************************************************************************** -* -* postIndividualContextEntity - -* -* Corresponding Standard Operation: UpdateContext/APPEND -* -* NOTE -* This function is used for two different URLs: -* o /v1/contextEntities -* o /v1/contextEntities/{entityId::id} -* -* In the longer URL (with entityId::id), the payload (AppendContextElementRequest) cannot contain any -* entityId data (id, type, isPattern). -* In the first case, the entityId data of the payload is mandatory. -* entityId::type can be empty, as always, but entityId::id MUST be filled in. -* -* POST /v1/contextEntities -* POST /ngsi10/contextEntities -* POST /v1/contextEntities/{entityId::id} -* POST /ngsi10/contextEntities/{entityId::id} -* -* Payload In: AppendContextElementRequest -* Payload Out: AppendContextElementResponse -* -* URI parameters: -* - attributesFormat=object -* - entity::type=TYPE -* - note that '!exist=entity::type' and 'exist=entity::type' are not supported by convenience operations -* that use the standard operation UpdateContext as there is no restriction within UpdateContext. -* -* 00. Take care of URI params -* 01. Check that total input in consistent and correct -* 02. Fill in UpdateContextRequest from AppendContextElementRequest + URL-data + URI params -* 03. Call postUpdateContext standard service routine -* 04. Translate UpdateContextResponse to AppendContextElementResponse -* 05. Cleanup and return result -*/ -std::string postIndividualContextEntity -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -) -{ - AppendContextElementRequest* reqP = &parseDataP->acer.res; - AppendContextElementResponse response; - std::string entityIdFromPayload = reqP->entity.id; - std::string entityIdFromURL = ((compV.size() == 3) || (compV.size() == 4))? compV[2] : ""; - std::string entityId; - std::string entityTypeFromPayload = reqP->entity.type; - std::string entityTypeFromURL = ciP->uriParam[URI_PARAM_ENTITY_TYPE]; - std::string entityType; - std::string answer; - std::string out; - - bool asJsonObject = (ciP->uriParam[URI_PARAM_ATTRIBUTE_FORMAT] == "object" && ciP->outMimeType == JSON); - - // - // 01. Check that total input in consistent and correct - // - - // 01.01. entityId::id - if ((!entityIdFromPayload.empty()) && (!entityIdFromURL.empty()) && (entityIdFromPayload != entityIdFromURL)) - { - std::string error = "entityId::id differs in URL and payload"; - - alarmMgr.badInput(clientIp, error, "url: " + entityIdFromURL + ", payload: " + entityIdFromPayload); - response.errorCode.fill(SccBadRequest, error); - - TIMED_RENDER(out = response.toJsonV1(asJsonObject, IndividualContextEntity)); - return out; - } - entityId = (!entityIdFromPayload.empty())? entityIdFromPayload : entityIdFromURL; - - // 01.02. entityId::type - if ((!entityTypeFromPayload.empty()) && (!entityTypeFromURL.empty()) && (entityTypeFromPayload != entityTypeFromURL)) - { - std::string error = "entityId::type differs in URL and payload"; - - alarmMgr.badInput(clientIp, error, "url: " + entityTypeFromURL + ", payload: " + entityTypeFromPayload); - response.errorCode.fill(SccBadRequest, error); - - TIMED_RENDER(out = response.toJsonV1(asJsonObject, IndividualContextEntity)); - return out; - } - entityType = (!entityTypeFromPayload.empty())? entityTypeFromPayload :entityTypeFromURL; - - - // 01.03. entityId::isPattern - if (reqP->entity.isPattern == "true") - { - std::string error = "entityId::isPattern set to true in contextUpdate convenience operation"; - - alarmMgr.badInput(clientIp, error); - response.errorCode.fill(SccBadRequest, error); - - TIMED_RENDER(out = response.toJsonV1(asJsonObject, IndividualContextEntity)); - return out; - } - - // 01.04. Entity::id must be present, somewhere ... - if (entityId.empty()) - { - std::string error = "invalid request: mandatory entityId::id missing"; - - alarmMgr.badInput(clientIp, error); - response.errorCode.fill(SccBadRequest, error); - - TIMED_RENDER(out = response.toJsonV1(asJsonObject, IndividualContextEntity)); - return out; - } - - // Now, forward Entity to response - response.entity.fill(entityId, entityType, "false"); - - - // - // 02. Fill in UpdateContextRequest from AppendContextElementRequest + URL-data + URI params - // - parseDataP->upcr.res.fill(&parseDataP->acer.res, entityId, entityType); - - - // 03. Call postUpdateContext standard service routine - postUpdateContext(ciP, components, compV, parseDataP); - - - // 04. Translate UpdateContextResponse to AppendContextElementResponse - response.fill(&parseDataP->upcrs.res); - - // 05. Cleanup and return result - TIMED_RENDER(answer = response.toJsonV1(asJsonObject, IndividualContextEntity)); - - response.release(); - parseDataP->upcr.res.release(); - - return answer; -} diff --git a/src/lib/serviceRoutines/postIndividualContextEntity.h b/src/lib/serviceRoutines/postIndividualContextEntity.h deleted file mode 100644 index 926556dab4..0000000000 --- a/src/lib/serviceRoutines/postIndividualContextEntity.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef SRC_LIB_SERVICEROUTINES_POSTINDIVIDUALCONTEXTENTITY_H_ -#define SRC_LIB_SERVICEROUTINES_POSTINDIVIDUALCONTEXTENTITY_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "rest/ConnectionInfo.h" -#include "ngsi/ParseData.h" - - - -/* **************************************************************************** -* -* postIndividualContextEntity - -*/ -extern std::string postIndividualContextEntity -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -); - -#endif // SRC_LIB_SERVICEROUTINES_POSTINDIVIDUALCONTEXTENTITY_H_ diff --git a/src/lib/serviceRoutines/postIndividualContextEntityAttribute.cpp b/src/lib/serviceRoutines/postIndividualContextEntityAttribute.cpp deleted file mode 100644 index f6a05c8320..0000000000 --- a/src/lib/serviceRoutines/postIndividualContextEntityAttribute.cpp +++ /dev/null @@ -1,99 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/statistics.h" -#include "common/clockFunctions.h" - -#include "ngsi/ParseData.h" -#include "ngsi/StatusCode.h" -#include "rest/ConnectionInfo.h" -#include "rest/uriParamNames.h" -#include "rest/EntityTypeInfo.h" -#include "serviceRoutines/postUpdateContext.h" -#include "serviceRoutines/postIndividualContextEntityAttribute.h" - - - -/* **************************************************************************** -* -* postIndividualContextEntityAttribute - -* -* POST /v1/contextEntities/{entityId::id}/attributes/{attributeName} -* POST /ngsi10/contextEntities/{entityId::id}/attributes/{attributeName} -* -* Payload In: UpdateContextAttributeRequest -* Payload Out: StatusCode -* -* URI parameters: -* - entity::type=TYPE -* - note that '!exist=entity::type' and 'exist=entity::type' are not supported by convenience operations -* that use the standard operation UpdateContext as there is no restriction within UpdateContext. -* [ attributesFormat=object: makes no sense for this operation as StatusCode is returned ] -* -* 0. Take care of URI params -* 1. Fill in UpdateContextRequest from UpdateContextAttributeRequest and URL-path components -* 2. Call postUpdateContext standard service routine -* 3. Translate UpdateContextResponse to StatusCode -* 4. Cleanup and return result -*/ -std::string postIndividualContextEntityAttribute -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -) -{ - std::string answer; - std::string entityId = compV[2]; - std::string entityType = ciP->uriParam[URI_PARAM_ENTITY_TYPE]; - std::string attributeName = compV[4]; - StatusCode response; - - // 1. Fill in UpdateContextRequest from UpdateContextAttributeRequest and URL-path components - parseDataP->upcr.res.fill(&parseDataP->upcar.res, entityId, entityType, attributeName, ActionTypeAppend); - - - // 2. Call postUpdateContext standard service routine - postUpdateContext(ciP, components, compV, parseDataP); - - - // 3. Translate UpdateContextResponse to StatusCode - response.fill(parseDataP->upcrs.res); - - - // 4. Cleanup and return result - TIMED_RENDER(answer = response.toJsonV1(false, false)); - - response.release(); - parseDataP->upcr.res.release(); - - return answer; -} diff --git a/src/lib/serviceRoutines/postIndividualContextEntityAttribute.h b/src/lib/serviceRoutines/postIndividualContextEntityAttribute.h deleted file mode 100644 index 0d1f2d29f5..0000000000 --- a/src/lib/serviceRoutines/postIndividualContextEntityAttribute.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef SRC_LIB_SERVICEROUTINES_POSTINDIVIDUALCONTEXTENTITYATTRIBUTE_H_ -#define SRC_LIB_SERVICEROUTINES_POSTINDIVIDUALCONTEXTENTITYATTRIBUTE_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "rest/ConnectionInfo.h" -#include "ngsi/ParseData.h" - - - -/* **************************************************************************** -* -* postIndividualContextEntityAttribute - -*/ -extern std::string postIndividualContextEntityAttribute -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -); - -#endif // SRC_LIB_SERVICEROUTINES_POSTINDIVIDUALCONTEXTENTITYATTRIBUTE_H_ diff --git a/src/lib/serviceRoutines/postIndividualContextEntityAttributeWithTypeAndId.cpp b/src/lib/serviceRoutines/postIndividualContextEntityAttributeWithTypeAndId.cpp deleted file mode 100644 index 18fb650c5d..0000000000 --- a/src/lib/serviceRoutines/postIndividualContextEntityAttributeWithTypeAndId.cpp +++ /dev/null @@ -1,131 +0,0 @@ -/* -* -* Copyright 2014 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/statistics.h" -#include "common/clockFunctions.h" -#include "alarmMgr/alarmMgr.h" - -#include "ngsi/ParseData.h" -#include "ngsi/StatusCode.h" -#include "rest/ConnectionInfo.h" -#include "rest/EntityTypeInfo.h" -#include "rest/uriParamNames.h" -#include "serviceRoutines/postUpdateContext.h" -#include "serviceRoutines/postIndividualContextEntityAttribute.h" - - - -/* **************************************************************************** -* -* postIndividualContextEntityAttributeWithTypeAndId - -* -* POST /v1/contextEntities/type/{entity::type}/id/{entity::id}/attributes/{attribute::name} -* -* Payload In: UpdateContextAttributeRequest -* Payload Out: StatusCode -* -* URI parameters: -* - entity::type=XXX (must coincide with entity::type in URL) -* - !exist=entity::type (if set - error -- entity::type cannot be empty) -* - exist=entity::type (not supported - ok if present, ok if not present ...) -* x attributesFormat=object (cannot be supported as the response is a StatusCode) -* -* 01. Get values from URL (entityId::type, esist, !exist) -* 02. Check validity of URI params -* 03. Fill in UpdateContextRequest -* 04. Call standard operation postUpdateContext -* 05. Translate UpdateContextResponse to StatusCode -* 06. Cleanup and return result -*/ -std::string postIndividualContextEntityAttributeWithTypeAndId -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -) -{ - std::string entityType = compV[3]; - std::string entityId = compV[5]; - std::string attributeName = compV[7]; - std::string entityTypeFromUriParam = ciP->uriParam[URI_PARAM_ENTITY_TYPE]; - EntityTypeInfo typeInfo = EntityTypeEmptyOrNotEmpty; - std::string answer; - StatusCode response; - - // 01. Get values from URL (entityId::type, esist, !exist) - if (ciP->uriParam[URI_PARAM_NOT_EXIST] == URI_PARAM_ENTITY_TYPE) - { - typeInfo = EntityTypeEmpty; - } - else if (ciP->uriParam[URI_PARAM_EXIST] == URI_PARAM_ENTITY_TYPE) - { - typeInfo = EntityTypeNotEmpty; - } - - - // 02. Check validity of URI params ... - // And if OK; - // 03. Fill in UpdateContextRequest - // 04. Call standard operation postUpdateContext - // 05. Translate UpdateContextResponse to StatusCode - // - if (typeInfo == EntityTypeEmpty) - { - response.fill(SccBadRequest, "entity::type cannot be empty for this request"); - alarmMgr.badInput(clientIp, "entity::type cannot be empty for this request"); - } - else if ((entityTypeFromUriParam != entityType) && (!entityTypeFromUriParam.empty())) - { - response.fill(SccBadRequest, "non-matching entity::types in URL"); - alarmMgr.badInput(clientIp, "non-matching entity::types in URL", entityTypeFromUriParam); - } - else - { - // 03. Fill in UpdateContextRequest - parseDataP->upcr.res.fill(&parseDataP->upcar.res, entityId, entityType, attributeName, ActionTypeAppend); - - // 04. Call standard operation postUpdateContext - postUpdateContext(ciP, components, compV, parseDataP); - - // 05. Translate UpdateContextResponse to StatusCode - response.fill(parseDataP->upcrs.res); - parseDataP->upcr.res.release(); - } - - - // 06. Cleanup and return result - TIMED_RENDER(answer = response.toJsonV1(false, false)); - - parseDataP->upcar.res.release(); - parseDataP->upcrs.res.release(); - - return answer; -} diff --git a/src/lib/serviceRoutines/postIndividualContextEntityAttributeWithTypeAndId.h b/src/lib/serviceRoutines/postIndividualContextEntityAttributeWithTypeAndId.h deleted file mode 100644 index 8bea2d4490..0000000000 --- a/src/lib/serviceRoutines/postIndividualContextEntityAttributeWithTypeAndId.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef SRC_LIB_SERVICEROUTINES_POSTINDIVIDUALCONTEXTENTITYATTRIBUTEWITHTYPEANDID_H_ -#define SRC_LIB_SERVICEROUTINES_POSTINDIVIDUALCONTEXTENTITYATTRIBUTEWITHTYPEANDID_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "rest/ConnectionInfo.h" -#include "ngsi/ParseData.h" - - - -/* **************************************************************************** -* -* postIndividualContextEntityAttributeWithTypeAndId - -*/ -extern std::string postIndividualContextEntityAttributeWithTypeAndId -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -); - -#endif // SRC_LIB_SERVICEROUTINES_POSTINDIVIDUALCONTEXTENTITYATTRIBUTEWITHTYPEANDID_H_ diff --git a/src/lib/serviceRoutines/postNotifyContext.cpp b/src/lib/serviceRoutines/postNotifyContext.cpp index 5a1ec9a8ab..75f32311f2 100644 --- a/src/lib/serviceRoutines/postNotifyContext.cpp +++ b/src/lib/serviceRoutines/postNotifyContext.cpp @@ -62,7 +62,10 @@ std::string postNotifyContext ciP->servicePathV, ciP->httpHeaders.correlator, ciP->httpHeaders.ngsiv2AttrsFormat)); - TIMED_RENDER(answer = ncr.toJsonV1()); + + //FIXME PR: this should be toJSON() + // check this with a .test + //TIMED_RENDER(answer = ncr.toJsonV1()); return answer; } diff --git a/src/lib/serviceRoutines/postQueryContext.cpp b/src/lib/serviceRoutines/postQueryContext.cpp index 5439fcf01a..cd98780df6 100644 --- a/src/lib/serviceRoutines/postQueryContext.cpp +++ b/src/lib/serviceRoutines/postQueryContext.cpp @@ -48,8 +48,8 @@ #include "rest/uriParamNames.h" #include "rest/OrionError.h" #include "serviceRoutines/postQueryContext.h" -#include "jsonParse/jsonRequest.h" #include "jsonParseV2/parseEntitiesResponse.h" +#include "jsonParseV2/parseEntitiesResponseV1.h" // FIXME P3: matchEntity() should be in a better place, and the following include to be removed #include "mongoBackend/MongoGlobal.h" // matchEntity() @@ -131,7 +131,7 @@ static void getProviderCount(std::string cpResponse, long long* totalCount) * 3. Send the request to the providing application (and await the response) * 4. Parse the response and fill in a binary QueryContextResponse * 5. Fill in the response from the redirection into the response of this function -* 6. 'Fix' StatusCode +* 6. 'Fix' OrionError * 7. Freeing memory * */ @@ -182,16 +182,13 @@ static bool queryForward std::string mimeType; std::string op; - if (qcrP->providerFormat == PfJson) + if (qcrP->legacyProviderFormat) { op = "/queryContext"; - __sync_fetch_and_add(&noOfDprLegacyForwarding, 1); - if (logDeprecate) - { - LM_W(("Deprecated usage of legacyForwarding mode in query forwarding operation (regId: %s)", regId.c_str())); - } - + // Note we don't include log deprecation here as it would cause double-loging + // (this flow involves Registration::fromBson() which already logs that) + TIMED_RENDER(payload = qcrP->toJsonV1()); } else @@ -334,8 +331,8 @@ static bool queryForward noHeaders, mimeType, -1, // default timeout - qcrP->providerFormat == PfJson? -1 : providerLimit, - qcrP->providerFormat == PfJson? -1 : providerOffset); + qcrP->legacyProviderFormat? -1 : providerLimit, + qcrP->legacyProviderFormat? -1 : providerOffset); if (r != 0) { @@ -368,94 +365,55 @@ static bool queryForward logInfoFwdRequest(regId.c_str(), verb.c_str(), (qcrP->contextProvider + op).c_str(), payload.c_str(), cleanPayload, statusCode); - if (ciP->apiVersion == V2 && strstr(out.c_str(), "Fiware-Total-Count")) + if (strstr(out.c_str(), "Fiware-Total-Count")) { getProviderCount(out.c_str(), totalCount); } - if (qcrP->providerFormat == PfJson) + bool result; + EntityVector entities; + OrionError oe; + + // Depending NGSIv1 or NGSIv2 in the CPr we use parseEntitiesResponseV1() or parseEntitiesResponseV2() + + // Note that parseEntitiesResponse() is thought for client-to-CB interactions, so it takes into account + // ciP->uriParamOptions[OPT_KEY_VALUES]. In this case, we never use keyValues in the CB-to-CPr so we + // set to false and restore its original value later. In this case it seems it is not needed to preserve + // ciP->httpStatusCode as in the similar case above + // FIXME P5: not sure if I like this approach... very "hacking-style". Probably it would be better + // to make JSON parsing logic (internal to parseEntitiesResponse()) independent of ciP and to pass the + // keyValue directly as function parameter. + bool previousKeyValues = ciP->uriParamOptions[OPT_KEY_VALUES]; + ciP->uriParamOptions[OPT_KEY_VALUES] = false; + result = qcrP->legacyProviderFormat? parseEntitiesResponseV1(ciP, cleanPayload, &entities, &oe) : parseEntitiesResponse(ciP, cleanPayload, &entities, &oe); + ciP->uriParamOptions[OPT_KEY_VALUES] = previousKeyValues; + + if (result == false) { - std::string s; - - // - // NOTE - // When coming from a convenience operation, such as GET /v1/contextEntities/EID/attributes/attrName, - // the verb/method in ciP is GET. However, the parsing function expects a POST, as if it came from a - // POST /v1/queryContext. - // So, here we change the verb/method for POST. - // - ciP->verb = POST; - ciP->method = "POST"; - - // Note that jsonTreat() is thought for client-to-CB interactions, thus it modifies ciP->httpStatusCode - // Thus, we need to preserve it before (and recover after) in order a fail in the CB-to-CPr interaction doesn't - // "corrupt" the status code in the client-to-CB interaction. - // FIXME P5: not sure if I like this approach... very "hacking-style". Probably it would be better - // to make JSON parsing logic (internal to jsonTreat()) independent of ciP (in fact, parsing process - // hasn't anything to do with connection). - HttpStatusCode sc = ciP->httpStatusCode; - s = jsonTreat(cleanPayload, ciP, &parseData, RtQueryContextResponse, NULL); - ciP->httpStatusCode = sc; - - if (s != "OK") - { - alarmMgr.forwardingError(url, "error parsing reply from prov app: " + s); - parseData.qcr.res.release(); - parseData.qcrs.res.release(); - return false; - } - + alarmMgr.forwardingError(url, "error parsing reply from context provider: " + oe.description); + parseData.qcr.res.release(); + parseData.qcrs.res.release(); + return false; + } - // - // 5. Fill in the response from the redirection into the response of this function - // - qcrsP->fill(&parseData.qcrs.res); + // + // 5. Fill in the response from the redirection into the response of this function + // + if (entities.size() > 0) + { + qcrsP->fill(entities); } else { - bool b; - Entities entities; - OrionError oe; - - // Note that parseEntitiesResponse() is thought for client-to-CB interactions, so it takes into account - // ciP->uriParamOptions[OPT_KEY_VALUES]. In this case, we never use keyValues in the CB-to-CPr so we - // set to false and restore its original value later. In this case it seems it is not needed to preserve - // ciP->httpStatusCode as in the similar case above - // FIXME P5: not sure if I like this approach... very "hacking-style". Probably it would be better - // to make JSON parsing logic (internal to parseEntitiesResponse()) independent of ciP and to pass the - // keyValue directly as function parameter. - bool previousKeyValues = ciP->uriParamOptions[OPT_KEY_VALUES]; - ciP->uriParamOptions[OPT_KEY_VALUES] = false; - b = parseEntitiesResponse(ciP, cleanPayload, &entities, &oe); - ciP->uriParamOptions[OPT_KEY_VALUES] = previousKeyValues; - - if (b == false) - { - alarmMgr.forwardingError(url, "error parsing reply from context provider: " + oe.description); - parseData.qcr.res.release(); - parseData.qcrs.res.release(); - return false; - } - - // - // 5. Fill in the response from the redirection into the response of this function - // - if (entities.size() > 0) - { - qcrsP->fill(entities); - } - else - { - qcrsP->errorCode.fill(SccContextElementNotFound); - } + qcrsP->error.fill(SccContextElementNotFound); } // - // 6. 'Fix' StatusCode + // 6. 'Fix' OrionError // - if (qcrsP->errorCode.code == SccNone) + if (qcrsP->error.code == SccNone) { - qcrsP->errorCode.fill(SccOk); + qcrsP->error.fill(SccOk); } @@ -480,7 +438,7 @@ static bool forwardsPending(QueryContextResponse* qcrsP) { ContextElementResponse* cerP = qcrsP->contextElementResponseVector[ix]; - if (cerP->entity.providingApplicationList.size() != 0) + if (cerP->entity.providerList.size() != 0) { return true; } @@ -489,7 +447,7 @@ static bool forwardsPending(QueryContextResponse* qcrsP) { ContextAttribute* aP = cerP->entity.attributeVector[aIx]; - if (!aP->providingApplication.get().empty()) + if (!aP->provider.http.url.empty()) { return true; } @@ -505,7 +463,7 @@ static bool forwardsPending(QueryContextResponse* qcrsP) * * postQueryContext - */ -std::string postQueryContext +void postQueryContext ( ConnectionInfo* ciP, int components, @@ -519,7 +477,6 @@ std::string postQueryContext // QueryContextResponse* qcrsP = &parseDataP->qcrs.res; QueryContextRequest* qcrP = &parseDataP->qcr.res; - std::string answer; QueryContextRequestVector requestV; std::vector regIdsV; QueryContextResponseVector responseV; @@ -528,26 +485,18 @@ std::string postQueryContext bool skipForwarding = ciP->uriParamOptions[OPT_SKIPFORWARDING]; - bool asJsonObject = (ciP->uriParam[URI_PARAM_ATTRIBUTE_FORMAT] == "object" && ciP->outMimeType == JSON); - // // 00. Count or not count? That is the question ... // - // For API version 1, if the URI parameter 'details' is set to 'on', then the total of local - // entities is returned in the errorCode of the payload. - // - // In API version 2, this has changed completely. The total count is returned to client the HTTP header Fiware-Total-Count + // The total count is returned to client the HTTP header Fiware-Total-Count // only when count option is enabled, but we enable internally the countP variable, as if CPrs are involved in the // query execution we need it - if ((ciP->apiVersion == V2) || ((ciP->apiVersion == V1) && (ciP->uriParam["details"] == "on"))) - { - countP = &count; - } + countP = &count; // // 01. Call mongoBackend/mongoQueryContext // - qcrsP->errorCode.fill(SccOk); + qcrsP->error.fill(SccOk); TIMED_MONGO(ciP->httpStatusCode = mongoQueryContext(qcrP, qcrsP, @@ -555,17 +504,15 @@ std::string postQueryContext ciP->servicePathV, ciP->uriParam, ciP->uriParamOptions, - countP, - ciP->apiVersion)); + countP)); - if ((qcrsP->errorCode.code == SccBadRequest) || (qcrsP->errorCode.code == SccReceiverInternalError)) + if ((qcrsP->error.code == SccBadRequest) || (qcrsP->error.code == SccReceiverInternalError)) { // Bad Input or Internal Error detected by Mongo Backend - request ends here ! - OrionError oe(qcrsP->errorCode); + OrionError oe(qcrsP->error); - TIMED_RENDER(answer = oe.toJsonV1()); qcrP->release(); - return answer; + return; } @@ -581,7 +528,7 @@ std::string postQueryContext // if (forwardsPending(qcrsP) == false) { - if ((ciP->apiVersion == V2) && (ciP->uriParamOptions["count"])) + if (ciP->uriParamOptions["count"]) { char cV[32]; @@ -589,10 +536,9 @@ std::string postQueryContext ciP->httpHeader.push_back(HTTP_FIWARE_TOTAL_COUNT); ciP->httpHeaderValue.push_back(cV); } - TIMED_RENDER(answer = qcrsP->toJsonV1(asJsonObject)); qcrP->release(); - return answer; + return; } // @@ -616,7 +562,7 @@ std::string postQueryContext for (unsigned int ix = 0 ; ix < qcrsP->contextElementResponseVector.size(); ++ix) { ContextElementResponse* cerP = qcrsP->contextElementResponseVector[ix]; - EntityId en(cerP->entity.id, cerP->entity.type, cerP->entity.isPattern); + EntityId en(cerP->entity.entityId); // // If a Context Provider has been registered with an empty attribute list for @@ -626,20 +572,20 @@ std::string postQueryContext // When there is a Context Provider in ContextElement::providingApplicationList, then the // request must be sent to that Context Provider also // - for (unsigned int ix = 0; ix < cerP->entity.providingApplicationList.size(); ++ix) + for (unsigned int ix = 0; ix < cerP->entity.providerList.size(); ++ix) { QueryContextRequest* requestP; - requestP = new QueryContextRequest(cerP->entity.providingApplicationList[ix].get(), &en, qcrP->attributeList, cerP->entity.providingApplicationList[ix].providerFormat); + requestP = new QueryContextRequest(cerP->entity.providerList[ix].http.url, &en, qcrP->attributeList, cerP->entity.providerList[ix].legacyForwardingMode); requestV.push_back(requestP); - regIdsV.push_back(cerP->entity.providingApplicationList[ix].getRegId()); + regIdsV.push_back(cerP->entity.providerRegIdList[ix]); } // // What if the Attribute Vector of the ContextElementResponse is empty? // For now, just push it into localQcrsP, but only if its local, i.e. its contextElement.providingApplicationList is empty // - if ((cerP->entity.attributeVector.size() == 0) && (cerP->entity.providingApplicationList.size() == 0)) + if ((cerP->entity.attributeVector.size() == 0) && (cerP->entity.providerList.size() == 0)) { localQcrsP->contextElementResponseVector.push_back(new ContextElementResponse(&en, NULL)); } @@ -653,7 +599,7 @@ std::string postQueryContext // An empty providingApplication means the attribute is local // In such a case, the response is already in our hand, we just need to copy it to responseV // - if (aP->providingApplication.get().empty()) + if (aP->provider.http.url.empty()) { if (aP->found == false) { @@ -685,13 +631,13 @@ std::string postQueryContext // // Not a local attribute - aP->providingApplication is not empty // - QueryContextRequest* requestP = requestV.lookup(aP->providingApplication.get(), &en); + QueryContextRequest* requestP = requestV.lookup(aP->provider.http.url, &en); if (requestP == NULL) { - requestP = new QueryContextRequest(aP->providingApplication.get(), &en, aP->name, aP->providingApplication.providerFormat); + requestP = new QueryContextRequest(aP->provider.http.url, &en, aP->name, aP->provider.legacyForwardingMode); requestV.push_back(requestP); - regIdsV.push_back(aP->providingApplication.getRegId()); + regIdsV.push_back(aP->providerRegId); } else { @@ -703,7 +649,6 @@ std::string postQueryContext pushed = requestP->entityIdVector.push_back_if_absent(entityP); if (pushed == false) { - entityP->release(); delete entityP; } } @@ -718,20 +663,17 @@ std::string postQueryContext int providerOffset = 0; int brokerCount = 0; - if (ciP->apiVersion == V2) + brokerCount = *countP; + // Setting providerOffset + if (totalOffset >= (*countP)) { - brokerCount = *countP; - // Setting providerOffset - if (totalOffset >= (*countP)) - { - providerOffset = totalOffset - (*countP); - } + providerOffset = totalOffset - (*countP); + } - // Setting providerLimit - if (localQcrsP->contextElementResponseVector.size() >= 0) - { - providerLimit = providerLimit - localQcrsP->contextElementResponseVector.size(); - } + // Setting providerLimit + if (localQcrsP->contextElementResponseVector.size() >= 0) + { + providerLimit = providerLimit - localQcrsP->contextElementResponseVector.size(); } // @@ -784,24 +726,22 @@ std::string postQueryContext } qP = new QueryContextResponse(); - qP->errorCode.fill(SccOk); + qP->error.fill(SccOk); if (queryForward(ciP, requestV[fIx], regIdsV[fIx], providerLimit, providerOffset, countP, fIx + 1, qP) == true) { - if (ciP->apiVersion == V2) - { - providerLimit = providerLimit - qP->contextElementResponseVector.size(); + providerLimit = providerLimit - qP->contextElementResponseVector.size(); - if (providerOffset > (*countP - brokerCount)) - { - providerOffset -= (*countP - brokerCount); - brokerCount += (*countP - brokerCount); - } - else - { - providerOffset = 0; - } + if (providerOffset > (*countP - brokerCount)) + { + providerOffset -= (*countP - brokerCount); + brokerCount += (*countP - brokerCount); + } + else + { + providerOffset = 0; } + // // Each ContextElementResponse of qP should be tested to see whether there // is already an existing ContextElementResponse in responseV @@ -810,7 +750,7 @@ std::string postQueryContext } else { - qP->errorCode.fill(SccContextElementNotFound, "invalid context provider response"); + qP->error.fill(SccContextElementNotFound, "invalid context provider response"); responseV.push_back(qP); } } @@ -834,7 +774,7 @@ std::string postQueryContext for (unsigned int jx = 0; jx < responseV[ix]->contextElementResponseVector.size(); ++jx) { bool found = false; - EntityId tempEn(responseV[ix]->contextElementResponseVector[jx]->entity.id, responseV[ix]->contextElementResponseVector[jx]->entity.type, "false"); + EntityId tempEn(responseV[ix]->contextElementResponseVector[jx]->entity.entityId); for (unsigned int kx = 0; kx < qcrP->entityIdVector.size(); ++kx) { if (matchEntity(&tempEn, qcrP->entityIdVector[kx])) @@ -861,7 +801,7 @@ std::string postQueryContext // Before implementing pagination for CPrs, this block of code was part of step 02. // However, in that step we only have the count for CB entities. It is in the new location // (after queryForward() invocation) when we have the total count CB+CPr - if ((ciP->apiVersion == V2) && (ciP->uriParamOptions["count"])) + if (ciP->uriParamOptions["count"]) { char cV[32]; @@ -871,12 +811,6 @@ std::string postQueryContext ciP->httpHeaderValue.push_back(cV); } - std::string detailsString = ciP->uriParam[URI_PARAM_PAGINATION_DETAILS]; - bool details = (strcasecmp("on", detailsString.c_str()) == 0)? true : false; - - TIMED_RENDER(answer = responseV.toJsonV1(asJsonObject, details, qcrsP->errorCode.details)); - - // // Time to cleanup. // But before doing that ... @@ -895,5 +829,5 @@ std::string postQueryContext requestV.release(); responseV.release(); - return answer; + return; } diff --git a/src/lib/serviceRoutines/postQueryContext.h b/src/lib/serviceRoutines/postQueryContext.h index 9ccad74ee2..f6d4b81e50 100644 --- a/src/lib/serviceRoutines/postQueryContext.h +++ b/src/lib/serviceRoutines/postQueryContext.h @@ -37,7 +37,7 @@ * * postQueryContext - */ -extern std::string postQueryContext +extern void postQueryContext ( ConnectionInfo* ciP, int components, diff --git a/src/lib/serviceRoutines/postRegisterContext.cpp b/src/lib/serviceRoutines/postRegisterContext.cpp deleted file mode 100644 index 945ae5bcdb..0000000000 --- a/src/lib/serviceRoutines/postRegisterContext.cpp +++ /dev/null @@ -1,115 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/globals.h" -#include "common/string.h" -#include "common/defaultValues.h" -#include "common/statistics.h" -#include "common/clockFunctions.h" -#include "alarmMgr/alarmMgr.h" - -#include "serviceRoutines/postRegisterContext.h" -#include "mongoBackend/mongoRegisterContext.h" -#include "ngsi/ParseData.h" -#include "rest/ConnectionInfo.h" -#include "rest/uriParamNames.h" - - - -/* **************************************************************************** -* -* postRegisterContext - -*/ -std::string postRegisterContext -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -) -{ - RegisterContextResponse rcr; - std::string answer; - RegisterContextRequest* rcrP = &parseDataP->rcr.res; - - // - // Check for isPatterns in request - // - for (unsigned int crIx = 0; crIx < rcrP->contextRegistrationVector.size(); ++crIx) - { - ContextRegistration* crP = rcrP->contextRegistrationVector[crIx]; - - for (unsigned int eIx = 0; eIx < crP->entityIdVector.size(); ++eIx) - { - if (isTrue(crP->entityIdVector[eIx]->isPattern)) - { - std::string details = "isPattern set to true for registrations is currently not supported"; - OrionError oe(SccBadRequest, details); - - alarmMgr.badInput(clientIp, details); - ciP->httpStatusCode = SccBadRequest; - return oe.toJsonV1(); - } - } - } - - // - // If more than ONE service-path is input, an error is returned as response. - // If NO service-path is issued, then the default service-path "/" is used. - // After these checks, the service-path is checked to be 'correct'. - // - if (ciP->servicePathV.size() > 1) - { - alarmMgr.badInput(clientIp, "more than one service path for a registration"); - rcr.errorCode.fill(SccBadRequest, "more than one service path for notification"); - - TIMED_RENDER(answer = rcr.toJsonV1()); - - return answer; - } - else if (ciP->servicePathV.size() == 0) - { - ciP->servicePathV.push_back(SERVICE_PATH_ROOT); - } - - std::string res = servicePathCheck(ciP->servicePathV[0].c_str()); - if (res != "OK") - { - rcr.errorCode.fill(SccBadRequest, res); - - TIMED_RENDER(answer = rcr.toJsonV1()); - return answer; - } - - TIMED_MONGO(ciP->httpStatusCode = mongoRegisterContext(&parseDataP->rcr.res, &rcr, ciP->uriParam, ciP->httpHeaders.correlator, ciP->tenant, ciP->servicePathV[0])); - TIMED_RENDER(answer = rcr.toJsonV1()); - - return answer; -} diff --git a/src/lib/serviceRoutines/postRegisterContext.h b/src/lib/serviceRoutines/postRegisterContext.h deleted file mode 100644 index 2d8d90a6c1..0000000000 --- a/src/lib/serviceRoutines/postRegisterContext.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef SRC_LIB_SERVICEROUTINES_POSTREGISTERCONTEXT_H_ -#define SRC_LIB_SERVICEROUTINES_POSTREGISTERCONTEXT_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "rest/ConnectionInfo.h" -#include "ngsi/ParseData.h" - - - -/* **************************************************************************** -* -* postRegisterContext - -*/ -extern std::string postRegisterContext -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -); - -#endif // SRC_LIB_SERVICEROUTINES_POSTREGISTERCONTEXT_H_ diff --git a/src/lib/serviceRoutines/postSubscribeContext.cpp b/src/lib/serviceRoutines/postSubscribeContext.cpp deleted file mode 100644 index f1d30e22aa..0000000000 --- a/src/lib/serviceRoutines/postSubscribeContext.cpp +++ /dev/null @@ -1,90 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "common/statistics.h" -#include "common/clockFunctions.h" -#include "common/limits.h" -#include "alarmMgr/alarmMgr.h" - -#include "mongoBackend/mongoSubscribeContext.h" -#include "ngsi/ParseData.h" -#include "ngsi10/SubscribeContextResponse.h" -#include "rest/ConnectionInfo.h" -#include "rest/uriParamNames.h" -#include "rest/OrionError.h" -#include "serviceRoutines/postSubscribeContext.h" - - - -/* **************************************************************************** -* -* postSubscribeContext - -* -* POST /v1/subscribeContext -* POST /ngsi10/subscribeContext -* -* Payload In: SubscribeContextRequest -* Payload Out: SubscribeContextResponse -* -*/ -std::string postSubscribeContext -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -) -{ - SubscribeContextResponse scr; - std::string answer; - // - // FIXME P0: Only *one* service path is allowed for subscriptions. - // Personally (kz) I kind of like that. If you want additional service-paths, just add another subscription! - // However, we need to at least state that HERE is where we limit the number of service paths to *one*. - // - if (ciP->servicePathV.size() > 1) - { - char noOfV[STRING_SIZE_FOR_INT]; - snprintf(noOfV, sizeof(noOfV), "%lu", ciP->servicePathV.size()); - ciP->httpStatusCode = SccOk; // NGSIv1 is weird... it uses 200 OK at HTTP level for errors - std::string details = std::string("max *one* service-path allowed for subscriptions (") + noOfV + " given"; - - alarmMgr.badInput(clientIp, details); - - scr.subscribeError.errorCode.fill(SccBadRequest, "max one service-path allowed for subscriptions"); - - TIMED_RENDER(answer = scr.toJsonV1()); - return answer; - } - - TIMED_MONGO(ciP->httpStatusCode = mongoSubscribeContext(&parseDataP->scr.res, &scr, ciP->tenant, ciP->servicePathV)); - TIMED_RENDER(answer = scr.toJsonV1()); - - parseDataP->scr.res.release(); - - return answer; -} diff --git a/src/lib/serviceRoutines/postSubscribeContext.h b/src/lib/serviceRoutines/postSubscribeContext.h deleted file mode 100644 index 29ddc339bf..0000000000 --- a/src/lib/serviceRoutines/postSubscribeContext.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef SRC_LIB_SERVICEROUTINES_POSTSUBSCRIBECONTEXT_H_ -#define SRC_LIB_SERVICEROUTINES_POSTSUBSCRIBECONTEXT_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "ngsi/ParseData.h" -#include "rest/ConnectionInfo.h" - - - -/* **************************************************************************** -* -* postSubscribeContext - -*/ -extern std::string postSubscribeContext -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -); - -#endif // SRC_LIB_SERVICEROUTINES_POSTSUBSCRIBECONTEXT_H_ diff --git a/src/lib/serviceRoutines/postSubscribeContextConvOp.cpp b/src/lib/serviceRoutines/postSubscribeContextConvOp.cpp deleted file mode 100644 index b32d81a41d..0000000000 --- a/src/lib/serviceRoutines/postSubscribeContextConvOp.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/* -* -* Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/logMsg.h" - -#include "ngsi/ParseData.h" -#include "rest/ConnectionInfo.h" -#include "rest/uriParamNames.h" -#include "rest/EntityTypeInfo.h" -#include "serviceRoutines/postSubscribeContext.h" -#include "serviceRoutines/postSubscribeContextConvOp.h" - - - -/* **************************************************************************** -* -* postSubscribeContextConvOp - -* -* POST /v1/contextSubscriptions -* POST /ngsi10/contextSubscriptions -* -* Payload In: SubscribeContextRequest -* Payload Out: SubscribeContextResponse -* -* URI parameters -* - !exist=entity::type -* - exist=entity::type -* x entity::type=TYPE (NOT TREATED) -*/ -std::string postSubscribeContextConvOp -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -) -{ - std::string answer; - EntityTypeInfo typeInfo = EntityTypeEmptyOrNotEmpty; - - - // 01. Take care of URI params - if (ciP->uriParam[URI_PARAM_NOT_EXIST] == URI_PARAM_ENTITY_TYPE) - { - typeInfo = EntityTypeEmpty; - } - else if (ciP->uriParam[URI_PARAM_EXIST] == URI_PARAM_ENTITY_TYPE) - { - typeInfo = EntityTypeNotEmpty; - } - - - // 02. Fill in SubscribeContextRequest (actually, modify it) - parseDataP->scr.res.fill(typeInfo); - - - // 03. Call standard operation - answer = postSubscribeContext(ciP, components, compV, parseDataP); - - - // 04. Cleanup and return result - parseDataP->scr.res.release(); - - return answer; -} diff --git a/src/lib/serviceRoutines/postSubscribeContextConvOp.h b/src/lib/serviceRoutines/postSubscribeContextConvOp.h deleted file mode 100644 index fc62af0af3..0000000000 --- a/src/lib/serviceRoutines/postSubscribeContextConvOp.h +++ /dev/null @@ -1,49 +0,0 @@ -#ifndef SRC_LIB_SERVICEROUTINES_POSTSUBSCRIBECONTEXTCONVOP_H_ -#define SRC_LIB_SERVICEROUTINES_POSTSUBSCRIBECONTEXTCONVOP_H_ - -/* -* -* Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - - -#include "rest/ConnectionInfo.h" -#include "ngsi/ParseData.h" - - - -/* **************************************************************************** -* -* postSubscribeContextConvOp - -*/ -extern std::string postSubscribeContextConvOp -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -); - -#endif // SRC_LIB_SERVICEROUTINES_POSTSUBSCRIBECONTEXTCONVOP_H_ diff --git a/src/lib/serviceRoutines/postUnsubscribeContext.cpp b/src/lib/serviceRoutines/postUnsubscribeContext.cpp deleted file mode 100644 index 8189f6f930..0000000000 --- a/src/lib/serviceRoutines/postUnsubscribeContext.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "common/statistics.h" -#include "common/clockFunctions.h" - -#include "mongoBackend/mongoUnsubscribeContext.h" -#include "ngsi/ParseData.h" -#include "ngsi10/UnsubscribeContextResponse.h" -#include "rest/ConnectionInfo.h" -#include "serviceRoutines/postUnsubscribeContext.h" - - - -/* **************************************************************************** -* -* postUnsubscribeContext - -*/ -std::string postUnsubscribeContext -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -) -{ - UnsubscribeContextResponse uncr; - std::string answer; - - TIMED_MONGO(ciP->httpStatusCode = mongoUnsubscribeContext(&parseDataP->uncr.res, &uncr, ciP->tenant)); - TIMED_RENDER(answer = uncr.toJsonV1()); - - return answer; -} diff --git a/src/lib/serviceRoutines/postUnsubscribeContext.h b/src/lib/serviceRoutines/postUnsubscribeContext.h deleted file mode 100644 index 6d06817345..0000000000 --- a/src/lib/serviceRoutines/postUnsubscribeContext.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef SRC_LIB_SERVICEROUTINES_POSTUNSUBSCRIBECONTEXT_H_ -#define SRC_LIB_SERVICEROUTINES_POSTUNSUBSCRIBECONTEXT_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "ngsi/ParseData.h" -#include "rest/ConnectionInfo.h" - - - -/* **************************************************************************** -* -* postUnsubscribeContext - -*/ -extern std::string postUnsubscribeContext -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -); - -#endif // SRC_LIB_SERVICEROUTINES_POSTUNSUBSCRIBECONTEXT_H_ diff --git a/src/lib/serviceRoutines/postUpdateContext.cpp b/src/lib/serviceRoutines/postUpdateContext.cpp index 820e074b9d..2e9dfe1dfb 100644 --- a/src/lib/serviceRoutines/postUpdateContext.cpp +++ b/src/lib/serviceRoutines/postUpdateContext.cpp @@ -37,7 +37,7 @@ #include "common/logTracing.h" #include "alarmMgr/alarmMgr.h" -#include "jsonParse/jsonRequest.h" +#include "jsonParseV2/parseEntitiesResponseV1.h" #include "mongoBackend/mongoUpdateContext.h" #include "ngsi/ParseData.h" #include "ngsi10/UpdateContextResponse.h" @@ -74,7 +74,7 @@ static bool forwardsPending(UpdateContextResponse* upcrsP) { ContextAttribute* aP = cerP->entity.attributeVector[aIx]; - if (!aP->providingApplication.get().empty()) + if (!aP->provider.http.url.empty()) { return true; } @@ -98,7 +98,7 @@ static bool forwardsPending(UpdateContextResponse* upcrsP) * 3. Send the request to the providing application (and await the response) * 4. Parse the response and fill in a binary UpdateContextResponse * 5. Fill in the response from the redirection into the response of this function -* 6. 'Fix' StatusCode +* 6. 'Fix' OrionError * 7. Freeing memory * */ @@ -115,8 +115,6 @@ static bool updateForward int port; std::string prefix; - bool asJsonObject = (ciP->uriParam[URI_PARAM_ATTRIBUTE_FORMAT] == "object" && ciP->outMimeType == JSON); - // // 1. Parse the providing application to extract IP, port and URI-path // @@ -130,7 +128,7 @@ static bool updateForward // Somehow, if we accepted this providing application, it is the brokers fault ... // SccBadRequest should have been returned before, when it was registered! // - upcrsP->errorCode.fill(SccContextElementNotFound, ""); + upcrsP->error.fill(SccContextElementNotFound, ""); return false; } @@ -152,17 +150,14 @@ static bool updateForward std::string out; int r; - if (upcrP->providerFormat == PfJson) + if (upcrP->legacyProviderFormat) { - TIMED_RENDER(payload = upcrP->toJsonV1(asJsonObject)); + TIMED_RENDER(payload = upcrP->toJsonV1()); op = "/updateContext"; - __sync_fetch_and_add(&noOfDprLegacyForwarding, 1); - if (logDeprecate) - { - LM_W(("Deprecated usage of legacyForwarding mode in update forwarding operation (regId: %s)", regId.c_str())); - } + // Note we don't include log deprecation here as it would cause double-loging + // (this flow involves Registration::fromBson() which already logs that) } else { @@ -235,7 +230,7 @@ static bool updateForward if (r != 0) { - upcrsP->errorCode.fill(SccContextElementNotFound, "error forwarding update"); + upcrsP->error.fill(SccContextElementNotFound, "error forwarding update"); logInfoFwdRequest(regId.c_str(), verb.c_str(), (upcrP->contextProvider + op).c_str(), payload.c_str(), "", out.c_str()); alarmMgr.forwardingError(url, "forwarding failure for sender-thread: " + out); return false; @@ -247,25 +242,27 @@ static bool updateForward LM_T(LmtCPrForwardResponsePayload, ("forward updateContext response payload: %s", out.c_str())); + cleanPayload = jsonPayloadClean(out.c_str()); + // - // If NGSIv1 (providerFormat == PfJson): + // If NGSIv1 (legacyProviderFormat): // 4. Parse the response and fill in a binary UpdateContextResponse // 5. Fill in the response from the redirection into the response of this function - // 6. 'Fix' StatusCode + // 6. 'Fix' OrionError // 7. Free up memory // // If NGSIv2: // 4. Look for "204 No Content" in the response of the forwarded request // 5. If found: OK, else, error // - if (upcrP->providerFormat == PfJson) + if (upcrP->legacyProviderFormat) { // // 4. Parse the response and fill in a binary UpdateContextResponse // - std::string s; - - cleanPayload = jsonPayloadClean(out.c_str()); + bool result; + EntityVector entities; + OrionError oe; if ((cleanPayload == NULL) || (cleanPayload[0] == 0)) { @@ -274,7 +271,7 @@ static bool updateForward // It is not in the orion broker though, so 404 is returned // alarmMgr.forwardingError(url, "context provider response to UpdateContext is empty"); - upcrsP->errorCode.fill(SccContextElementNotFound, "invalid context provider response"); + upcrsP->error.fill(SccContextElementNotFound, "invalid context provider response"); return false; } @@ -292,14 +289,14 @@ static bool updateForward ciP->verb = POST; ciP->method = "POST"; - parseData.upcrs.res.errorCode.fill(SccOk); + parseData.upcrs.res.error.fill(SccOk); - s = jsonTreat(cleanPayload, ciP, &parseData, RtUpdateContextResponse, NULL); + result = parseEntitiesResponseV1(ciP, cleanPayload, &entities, &oe); - if (s != "OK") + if (!result) { - alarmMgr.forwardingError(url, "error parsing reply from prov app: " + s); - upcrsP->errorCode.fill(SccContextElementNotFound, ""); + alarmMgr.forwardingError(url, "error parsing reply from context provider: " + oe.error + " (" + oe.description + ")"); + upcrsP->error.fill(SccContextElementNotFound, ""); parseData.upcr.res.release(); parseData.upcrs.res.release(); return false; @@ -313,16 +310,16 @@ static bool updateForward // - // 6. 'Fix' StatusCode + // 6. 'Fix' OrionError // - if (upcrsP->errorCode.code == SccNone) + if (upcrsP->error.code == SccNone) { - upcrsP->errorCode.fill(SccOk); + upcrsP->error.fill(SccOk); } - if ((upcrsP->contextElementResponseVector.size() == 1) && (upcrsP->contextElementResponseVector[0]->statusCode.code == SccContextElementNotFound)) + if ((upcrsP->contextElementResponseVector.size() == 1) && (upcrsP->contextElementResponseVector[0]->error.code == SccContextElementNotFound)) { - upcrsP->errorCode.fill(SccContextElementNotFound); + upcrsP->error.fill(SccContextElementNotFound); } // @@ -337,7 +334,7 @@ static bool updateForward { // NGSIv2 forward - no payload to be received - logInfoFwdRequest(regId.c_str(), verb.c_str(), (upcrP->contextProvider + op).c_str(), payload.c_str(), "", statusCode); + logInfoFwdRequest(regId.c_str(), verb.c_str(), (upcrP->contextProvider + op).c_str(), payload.c_str(), cleanPayload, statusCode); if (statusCode == SccNoContent) { @@ -352,7 +349,7 @@ static bool updateForward } alarmMgr.forwardingError(url, "unexpected response from context provider: %s" + out); - upcrsP->errorCode.fill(SccReceiverInternalError); + upcrsP->error.fill(SccReceiverInternalError); return false; } @@ -401,9 +398,9 @@ static void foundAndNotFoundAttributeSeparation(UpdateContextResponse* upcrsP, U // if ((noOfFounds == 0) && (noOfNotFounds > 0)) { - if ((cerP->statusCode.code == SccOk) || (cerP->statusCode.code == SccNone)) + if ((cerP->error.code == SccOk) || (cerP->error.code == SccNone)) { - cerP->statusCode.fill(SccContextElementNotFound, cerP->entity.id); + cerP->error.fill(SccContextElementNotFound, cerP->entity.entityId.id); } } else if ((noOfFounds > 0) && (noOfNotFounds > 0)) @@ -411,17 +408,17 @@ static void foundAndNotFoundAttributeSeparation(UpdateContextResponse* upcrsP, U // Adding a ContextElementResponse for the 'Not-Founds' ContextElementResponse* notFoundCerP = new ContextElementResponse(); - notFoundCerP->entity.fill(cerP->entity.id, cerP->entity.type, cerP->entity.isPattern); + notFoundCerP->entity.fill(cerP->entity.entityId); // - // Filling in StatusCode (SccContextElementNotFound) for NotFound + // Filling in OrionError (SccContextElementNotFound) for NotFound // - notFoundCerP->statusCode.fill(SccContextElementNotFound, cerP->entity.id); + notFoundCerP->error.fill(SccContextElementNotFound, cerP->entity.entityId.id); // - // Setting StatusCode to OK for Found + // Setting OrionError to OK for Found // - cerP->statusCode.fill(SccOk); + cerP->error.fill(SccOk); // // And, pushing to NotFound-vector @@ -449,11 +446,11 @@ static void foundAndNotFoundAttributeSeparation(UpdateContextResponse* upcrsP, U } // - // Add EntityId::id to StatusCode::details if 404, but only if StatusCode::details is empty + // Add EntityId::id to OrionError::details if 404, but only if OrionError::description is empty // - if ((cerP->statusCode.code == SccContextElementNotFound) && (cerP->statusCode.details.empty())) + if ((cerP->error.code == SccContextElementNotFound) && (cerP->error.description.empty())) { - cerP->statusCode.details = cerP->entity.id; + cerP->error.description = cerP->entity.entityId.id; } } @@ -476,9 +473,9 @@ static void foundAndNotFoundAttributeSeparation(UpdateContextResponse* upcrsP, U { if (upcrsP->contextElementResponseVector.size() == 0) { - if (upcrsP->errorCode.code == SccOk) + if (upcrsP->error.code == SccOk) { - upcrsP->errorCode.fill(SccContextElementNotFound, upcrP->entityVector[0]->id); + upcrsP->error.fill(SccContextElementNotFound, ERROR_DESC_NOT_FOUND_ENTITY); } } } @@ -488,17 +485,19 @@ static void foundAndNotFoundAttributeSeparation(UpdateContextResponse* upcrsP, U // Add entityId::id to details if Not Found and only one element in response. // And, if 0 elements in response, take entityId::id from the request. // - if (upcrsP->errorCode.code == SccContextElementNotFound) + // FIXME PR: this should be no longer needed. == 0 is redundant (the previous fill does that) + // == 1 is no longer needed is we remove the "internal" OrionError + /*if (upcrsP->error.code == SccContextElementNotFound) { if (upcrsP->contextElementResponseVector.size() == 1) { - upcrsP->errorCode.details = upcrsP->contextElementResponseVector[0]->entity.id; + upcrsP->error.description = upcrsP->contextElementResponseVector[0]->entity.entityId.id; } else if (upcrsP->contextElementResponseVector.size() == 0) { - upcrsP->errorCode.details = upcrP->entityVector[0]->id; + upcrsP->error.description = upcrP->entityVector[0]->entityId.id; } - } + }*/ } @@ -528,13 +527,12 @@ static void attributesToNotFound(UpdateContextRequest* upcrP) * * postUpdateContext - * -* POST /v1/updateContext -* POST /ngsi10/updateContext +* Internal functions used by serviceRoutinesV2 functions * * Payload In: UpdateContextRequest * Payload Out: UpdateContextResponse */ -std::string postUpdateContext +void postUpdateContext ( ConnectionInfo* ciP, int components, @@ -545,9 +543,7 @@ std::string postUpdateContext { UpdateContextResponse* upcrsP = &parseDataP->upcrs.res; UpdateContextRequest* upcrP = &parseDataP->upcr.res; - std::string answer; - bool asJsonObject = (ciP->uriParam[URI_PARAM_ATTRIBUTE_FORMAT] == "object" && ciP->outMimeType == JSON); bool forcedUpdate = ciP->uriParamOptions[OPT_FORCEDUPDATE]; bool overrideMetadata = ciP->uriParamOptions[OPT_OVERRIDEMETADATA]; bool flowControl = ciP->uriParamOptions[OPT_FLOW_CONTROL]; @@ -561,13 +557,12 @@ std::string postUpdateContext // if (ciP->servicePathV.size() > 1) { - upcrsP->errorCode.fill(SccBadRequest, "more than one service path in context update request"); + upcrsP->error.fill(SccBadRequest, "more than one service path in context update request"); alarmMgr.badInput(clientIp, "more than one service path for an update request"); - TIMED_RENDER(answer = upcrsP->toJsonV1(asJsonObject)); upcrP->release(); - return answer; + return; } else if (ciP->servicePathV[0].empty()) { @@ -577,19 +572,15 @@ std::string postUpdateContext std::string res = servicePathCheck(ciP->servicePathV[0].c_str()); if (res != "OK") { - upcrsP->errorCode.fill(SccBadRequest, res); - - TIMED_RENDER(answer = upcrsP->toJsonV1(asJsonObject)); - + upcrsP->error.fill(SccBadRequest, res); upcrP->release(); - return answer; + return; } // // 02. Send the request to mongoBackend/mongoUpdateContext // - upcrsP->errorCode.fill(SccOk); attributesToNotFound(upcrP); HttpStatusCode httpStatusCode; @@ -603,7 +594,6 @@ std::string postUpdateContext ciP->httpHeaders.ngsiv2AttrsFormat, forcedUpdate, overrideMetadata, - ciP->apiVersion, ngsiV2Flavour, flowControl)); @@ -624,10 +614,8 @@ std::string postUpdateContext bool forwarding = forwardsPending(upcrsP); if (forwarding == false) { - TIMED_RENDER(answer = upcrsP->toJsonV1(asJsonObject)); - upcrP->release(); - return answer; + return; } @@ -676,7 +664,7 @@ std::string postUpdateContext std::vector regIdsV; - response.errorCode.fill(SccOk); + response.error.fill(SccOk); for (unsigned int cerIx = 0; cerIx < upcrsP->contextElementResponseVector.size(); ++cerIx) { ContextElementResponse* cerP = upcrsP->contextElementResponseVector[cerIx]; @@ -699,7 +687,7 @@ std::string postUpdateContext // // 1. If the attribute is found locally - just add the attribute to the outgoing response // - if (aP->providingApplication.get().empty()) + if (aP->provider.http.url.empty()) { ContextAttribute ca(aP); response.foundPush(&cerP->entity, &ca); @@ -708,26 +696,26 @@ std::string postUpdateContext // - // 2. Lookup UpdateContextRequest in requestV according to providingApplication. + // 2. Lookup UpdateContextRequest in requestV according to provider. // If not found, add one. - UpdateContextRequest* reqP = requestV.lookup(aP->providingApplication.get()); + UpdateContextRequest* reqP = requestV.lookup(aP->provider.http.url); if (reqP == NULL) { - reqP = new UpdateContextRequest(aP->providingApplication.get(), aP->providingApplication.providerFormat, &cerP->entity); + reqP = new UpdateContextRequest(aP->provider.http.url, aP->provider.legacyForwardingMode, &cerP->entity); reqP->updateActionType = ActionTypeUpdate; requestV.push_back(reqP); - regIdsV.push_back(aP->providingApplication.getRegId()); + regIdsV.push_back(aP->providerRegId); } // // 3. Lookup ContextElement in UpdateContextRequest according to EntityId. // If not found, add one (to the EntityVector of the UpdateContextRequest). // - Entity* eP = reqP->entityVector.lookup(cerP->entity.id, cerP->entity.type); + Entity* eP = reqP->entityVector.lookup(cerP->entity.entityId.id, cerP->entity.entityId.type); if (eP == NULL) { eP = new Entity(); - eP->fill(cerP->entity.id, cerP->entity.type, cerP->entity.isPattern); + eP->fill(cerP->entity.entityId); reqP->entityVector.push_back(eP); } @@ -792,73 +780,59 @@ std::string postUpdateContext transactionIdSet(prevTransId.c_str()); // - // Note this is a slight break in the separation of concerns among the different layers (i.e. - // serviceRoutine/ logic should work in a "NGSIv1 isolated context"). However, it seems to be - // a smart way of dealing with partial update situations + // Adjust OrionError response in the case of partial updates. This may happen in CPr forwarding + // scenarios. Note that mongoBackend logic "splits" successfull updates and failing updates in + // two different CER (maybe using the same entity) // - if (ciP->apiVersion == V2) + std::string failing = ""; + unsigned int failures = 0; + + for (unsigned int ix = 0; ix < response.contextElementResponseVector.size(); ++ix) { - // - // Adjust OrionError response in the case of partial updates. This may happen in CPr forwarding - // scenarios. Note that mongoBackend logic "splits" successfull updates and failing updates in - // two different CER (maybe using the same entity) - // - std::string failing = ""; - unsigned int failures = 0; + ContextElementResponse *cerP = response.contextElementResponseVector[ix]; - for (unsigned int ix = 0; ix < response.contextElementResponseVector.size(); ++ix) + if (cerP->error.code != SccOk) { - ContextElementResponse* cerP = response.contextElementResponseVector[ix]; + failures++; - if (cerP->statusCode.code != SccOk) + std::string failingPerCer = ""; + for (unsigned int jx = 0; jx < cerP->entity.attributeVector.size(); ++jx) { - failures++; - - std::string failingPerCer = ""; - for (unsigned int jx = 0; jx < cerP->entity.attributeVector.size(); ++jx) + failingPerCer += cerP->entity.attributeVector[jx]->name; + if (jx != cerP->entity.attributeVector.size() - 1) { - failingPerCer += cerP->entity.attributeVector[jx]->name; - if (jx != cerP->entity.attributeVector.size() - 1) - { - failingPerCer +=", "; - } + failingPerCer += ", "; } - - failing += cerP->entity.id + "-" + cerP->entity.type + " : [" + failingPerCer + "], "; } - } - // - // Note that we modify parseDataP->upcrs.res.oe and not response.oe, as the former is the - // one used by the calling postBatchUpdate() function at serviceRoutineV2 library - // - if ((forwardOk == true) && (failures == 0)) - { - parseDataP->upcrs.res.oe.fill(SccNone, ""); + failing += cerP->entity.entityId.id + "-" + cerP->entity.entityId.type + " : [" + failingPerCer + "], "; } - else if (failures == response.contextElementResponseVector.size()) - { - parseDataP->upcrs.res.oe.fill(SccContextElementNotFound, ERROR_DESC_NOT_FOUND_ENTITY, ERROR_NOT_FOUND); - } - else if (failures > 0) - { - // Removing trailing ", " - failing = failing.substr(0, failing.size() - 2); + } - // If some CER (but not all) fail, then it is a partial update - parseDataP->upcrs.res.oe.fill(SccContextElementNotFound, "Some of the following attributes were not updated: { " + failing + " }", ERROR_PARTIAL_UPDATE); - } - else // failures == 0 - { - // No failure, so invalidate any possible OrionError filled by mongoBackend on the mongoUpdateContext step - parseDataP->upcrs.res.oe.fill(SccNone, ""); - } + // + // Note that we modify parseDataP->upcrs.res.error and not response.oe, as the former is the + // one used by the calling postBatchUpdate() function at serviceRoutineV2 library + // + if ((forwardOk == true) && (failures == 0)) + { + parseDataP->upcrs.res.error.fill(SccNone, ""); + } + else if (failures == response.contextElementResponseVector.size()) + { + parseDataP->upcrs.res.error.fill(SccContextElementNotFound, ERROR_DESC_NOT_FOUND_ENTITY, ERROR_NOT_FOUND); + } + else if (failures > 0) + { + // Removing trailing ", " + failing = failing.substr(0, failing.size() - 2); + + // If some CER (but not all) fail, then it is a partial update + parseDataP->upcrs.res.error.fill(SccContextElementNotFound, "Some of the following attributes were not updated: { " + failing + " }", ERROR_PARTIAL_UPDATE); } - else // v1 + else // failures == 0 { - // Note that v2 case doesn't use an actual response (so no need to waste time rendering it). - // We render in the v1 case only - TIMED_RENDER(answer = response.toJsonV1(asJsonObject)); + // No failure, so invalidate any possible OrionError filled by mongoBackend on the mongoUpdateContext step + parseDataP->upcrs.res.error.fill(SccNone, ""); } // @@ -867,8 +841,7 @@ std::string postUpdateContext upcrP->release(); requestV.release(); upcrsP->release(); - upcrsP->fill(&response); response.release(); - return answer; + return; } diff --git a/src/lib/serviceRoutines/postUpdateContext.h b/src/lib/serviceRoutines/postUpdateContext.h index 7e94776fc9..5b865b46f4 100644 --- a/src/lib/serviceRoutines/postUpdateContext.h +++ b/src/lib/serviceRoutines/postUpdateContext.h @@ -37,7 +37,7 @@ * * postUpdateContext - */ -extern std::string postUpdateContext +extern void postUpdateContext ( ConnectionInfo* ciP, int components, diff --git a/src/lib/serviceRoutines/postUpdateContextSubscription.cpp b/src/lib/serviceRoutines/postUpdateContextSubscription.cpp deleted file mode 100644 index 4e64d85619..0000000000 --- a/src/lib/serviceRoutines/postUpdateContextSubscription.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "common/statistics.h" -#include "common/clockFunctions.h" - -#include "mongoBackend/mongoUpdateContextSubscription.h" -#include "ngsi/ParseData.h" -#include "ngsi10/UpdateContextSubscriptionResponse.h" -#include "rest/ConnectionInfo.h" -#include "rest/uriParamNames.h" -#include "serviceRoutines/postUpdateContextSubscription.h" - - - -/* **************************************************************************** -* -* postUpdateContextSubscription - -*/ -std::string postUpdateContextSubscription -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -) -{ - UpdateContextSubscriptionResponse ucsr; - std::string answer; - - ucsr.subscribeError.subscriptionId = parseDataP->ucsr.res.subscriptionId; - - TIMED_MONGO(ciP->httpStatusCode = mongoUpdateContextSubscription(&parseDataP->ucsr.res, - &ucsr, - ciP->tenant, - ciP->servicePathV)); - - TIMED_RENDER(answer = ucsr.toJsonV1()); - - return answer; -} diff --git a/src/lib/serviceRoutines/postUpdateContextSubscription.h b/src/lib/serviceRoutines/postUpdateContextSubscription.h deleted file mode 100644 index abbd23e894..0000000000 --- a/src/lib/serviceRoutines/postUpdateContextSubscription.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef SRC_LIB_SERVICEROUTINES_POSTUPDATECONTEXTSUBSCRIPTION_H_ -#define SRC_LIB_SERVICEROUTINES_POSTUPDATECONTEXTSUBSCRIPTION_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "ngsi/ParseData.h" -#include "rest/ConnectionInfo.h" - - - -/* **************************************************************************** -* -* postUpdateContextSubscription - -*/ -extern std::string postUpdateContextSubscription -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -); - -#endif // SRC_LIB_SERVICEROUTINES_POSTUPDATECONTEXTSUBSCRIPTION_H_ diff --git a/src/lib/serviceRoutines/putAllEntitiesWithTypeAndId.cpp b/src/lib/serviceRoutines/putAllEntitiesWithTypeAndId.cpp deleted file mode 100644 index 66cab99410..0000000000 --- a/src/lib/serviceRoutines/putAllEntitiesWithTypeAndId.cpp +++ /dev/null @@ -1,131 +0,0 @@ -/* -* -* Copyright 2014 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/statistics.h" -#include "common/clockFunctions.h" -#include "alarmMgr/alarmMgr.h" - -#include "ngsi/ParseData.h" -#include "ngsi/EntityId.h" -#include "rest/ConnectionInfo.h" -#include "rest/uriParamNames.h" -#include "convenience/UpdateContextElementResponse.h" -#include "serviceRoutines/putAllEntitiesWithTypeAndId.h" -#include "serviceRoutines/postUpdateContext.h" - - - -/* **************************************************************************** -* -* putAllEntitiesWithTypeAndId - -* -* PUT /v1/contextEntities/type/{entity::type}/id/{entity::id} -* -* Payload In: UpdateContextElementRequest -* Payload Out: UpdateContextElementResponse -* -* URI parameters: -* - attributesFormat=object -* - entity::type=TYPE (must coincide with type in URL-path) -* - !exist=entity::type (if set - error -- entity::type cannot be empty) -* - exist=entity::type (not supported - ok if present, ok if not present ...) -* -* 01. Get values from URL (entityId::type, exist, !exist) -* 02. Check validity of URI params -* 03. Fill in UpdateContextRequest -* 04. Call Standard Operation -* 05. Fill in response from UpdateContextResponse -* 06. Cleanup and return result -*/ -extern std::string putAllEntitiesWithTypeAndId -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -) -{ - std::string entityType = compV[3]; - std::string entityId = compV[5]; - EntityTypeInfo typeInfo = EntityTypeEmptyOrNotEmpty; - std::string typeNameFromUriParam = ciP->uriParam[URI_PARAM_ENTITY_TYPE]; - std::string answer; - UpdateContextElementResponse response; - - bool asJsonObject = (ciP->uriParam[URI_PARAM_ATTRIBUTE_FORMAT] == "object" && ciP->outMimeType == JSON); - - // 01. Get values from URL (entityId::type, esist, !exist) - if (ciP->uriParam[URI_PARAM_NOT_EXIST] == URI_PARAM_ENTITY_TYPE) - { - typeInfo = EntityTypeEmpty; - } - else if (ciP->uriParam[URI_PARAM_EXIST] == URI_PARAM_ENTITY_TYPE) - { - typeInfo = EntityTypeNotEmpty; - } - - - // 02. Check validity of URI params - if (typeInfo == EntityTypeEmpty) - { - alarmMgr.badInput(clientIp, "entity::type cannot be empty for this request"); - response.errorCode.fill(SccBadRequest, "entity::type cannot be empty for this request"); - TIMED_RENDER(answer = response.toJsonV1(asJsonObject, AllEntitiesWithTypeAndId)); - return answer; - } - else if ((typeNameFromUriParam != entityType) && (!typeNameFromUriParam.empty())) - { - alarmMgr.badInput(clientIp, "non-matching entity::types in URL", typeNameFromUriParam); - response.errorCode.fill(SccBadRequest, "non-matching entity::types in URL"); - TIMED_RENDER(answer = response.toJsonV1( asJsonObject, AllEntitiesWithTypeAndId)); - return answer; - } - - - // 03. Fill in UpdateContextRequest - parseDataP->upcr.res.fill(&parseDataP->ucer.res, entityId, entityType); - - - // 04. Call Standard Operation - postUpdateContext(ciP, components, compV, parseDataP); - - - // 05. Fill in response from UpdateContextResponse - response.fill(&parseDataP->upcrs.res); - - - // 06. Cleanup and return result - TIMED_RENDER(answer = response.toJsonV1(asJsonObject, IndividualContextEntity)); - - parseDataP->upcr.res.release(); - response.release(); - - return answer; -} diff --git a/src/lib/serviceRoutines/putAllEntitiesWithTypeAndId.h b/src/lib/serviceRoutines/putAllEntitiesWithTypeAndId.h deleted file mode 100644 index 84de9e194b..0000000000 --- a/src/lib/serviceRoutines/putAllEntitiesWithTypeAndId.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef SRC_LIB_SERVICEROUTINES_PUTALLENTITIESWITHTYPEANDID_H_ -#define SRC_LIB_SERVICEROUTINES_PUTALLENTITIESWITHTYPEANDID_H_ - -/* -* -* Copyright 2014 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "rest/ConnectionInfo.h" -#include "ngsi/ParseData.h" - - - -/* **************************************************************************** -* -* putAllEntitiesWithTypeAndId - -*/ -extern std::string putAllEntitiesWithTypeAndId -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -); - -#endif // SRC_LIB_SERVICEROUTINES_PUTALLENTITIESWITHTYPEANDID_H_ diff --git a/src/lib/serviceRoutines/putIndividualContextEntity.cpp b/src/lib/serviceRoutines/putIndividualContextEntity.cpp deleted file mode 100644 index d96eaffeb0..0000000000 --- a/src/lib/serviceRoutines/putIndividualContextEntity.cpp +++ /dev/null @@ -1,109 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/statistics.h" -#include "common/clockFunctions.h" - -#include "ngsi/ParseData.h" -#include "rest/ConnectionInfo.h" -#include "rest/uriParamNames.h" -#include "convenience/UpdateContextElementResponse.h" -#include "serviceRoutines/postUpdateContext.h" -#include "serviceRoutines/putIndividualContextEntity.h" - - - -/* **************************************************************************** -* -* putIndividualContextEntity - -* -* Corresponding Standard Operation: UpdateContext/UPDATE -* -* PUT /v1/contextEntities/{entityId::id} -* PUT /ngsi10/contextEntities/{entityId::id} -* -* Payload In: UpdateContextElementRequest -* Payload Out: UpdateContextElementResponse -* -* URI parameters: -* - attributesFormat=object -* - entity::type=TYPE -* - note that '!exist=entity::type' and 'exist=entity::type' are not supported by convenience operations -* that use the standard operation UpdateContext as there is no restriction within UpdateContext. -* -* 01. Take care of URI params -* 02. Fill in UpdateContextRequest from UpdateContextElementRequest -* 03. Call postUpdateContext standard service routine -* 04. Translate UpdateContextResponse to UpdateContextElementResponse -* 05. Cleanup and return result -*/ -std::string putIndividualContextEntity -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -) -{ - std::string answer; - std::string entityId = compV[2]; - UpdateContextElementResponse response; - std::string entityType; - - bool asJsonObject = (ciP->uriParam[URI_PARAM_ATTRIBUTE_FORMAT] == "object" && ciP->outMimeType == JSON); - - // 01. Take care of URI params - entityType = ciP->uriParam[URI_PARAM_ENTITY_TYPE]; - - - // 02. Fill in UpdateContextRequest from UpdateContextElementRequest and entityId - parseDataP->upcr.res.fill(&parseDataP->ucer.res, entityId, entityType); - - // And, set the UpdateActionType to UPDATE - parseDataP->upcr.res.updateActionType = ActionTypeUpdate; - - - // 03. Call postUpdateContext standard service routine - postUpdateContext(ciP, components, compV, parseDataP); - - - // 04. Translate UpdateContextResponse to UpdateContextElementResponse - response.fill(&parseDataP->upcrs.res); - - - // 05. Cleanup and return result - TIMED_RENDER(answer = response.toJsonV1(asJsonObject, IndividualContextEntity)); - - - response.release(); - parseDataP->upcr.res.release(); - - return answer; -} diff --git a/src/lib/serviceRoutines/putIndividualContextEntity.h b/src/lib/serviceRoutines/putIndividualContextEntity.h deleted file mode 100644 index 8312012991..0000000000 --- a/src/lib/serviceRoutines/putIndividualContextEntity.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef SRC_LIB_SERVICEROUTINES_PUTINDIVIDUALCONTEXTENTITY_H_ -#define SRC_LIB_SERVICEROUTINES_PUTINDIVIDUALCONTEXTENTITY_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "rest/ConnectionInfo.h" -#include "ngsi/ParseData.h" - - - -/* **************************************************************************** -* -* putIndividualContextEntity - -*/ -extern std::string putIndividualContextEntity -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -); - -#endif // SRC_LIB_SERVICEROUTINES_PUTINDIVIDUALCONTEXTENTITY_H_ diff --git a/src/lib/serviceRoutines/putIndividualContextEntityAttribute.cpp b/src/lib/serviceRoutines/putIndividualContextEntityAttribute.cpp deleted file mode 100644 index 1921c10caf..0000000000 --- a/src/lib/serviceRoutines/putIndividualContextEntityAttribute.cpp +++ /dev/null @@ -1,102 +0,0 @@ -/* -* -* Copyright 2014 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/statistics.h" -#include "common/clockFunctions.h" - -#include "ngsi/ParseData.h" -#include "ngsi/StatusCode.h" -#include "rest/uriParamNames.h" -#include "rest/EntityTypeInfo.h" -#include "rest/ConnectionInfo.h" -#include "ngsi10/UpdateContextRequest.h" -#include "serviceRoutines/postUpdateContext.h" -#include "serviceRoutines/putIndividualContextEntityAttribute.h" - - - -/* **************************************************************************** -* -* putIndividualContextEntityAttribute - -* -* PUT /v1/contextEntities/{entityId::id}/attributes/{attributeName} -* PUT /ngsi10/contextEntities/{entityId::id}/attributes/{attributeName} -* -* Payload In: UpdateContextAttributeRequest -* Payload Out: StatusCode -* -* URI parameters: -* - entity::type=TYPE -* - note that '!exist=entity::type' and 'exist=entity::type' are not supported by convenience operations -* that use the standard operation UpdateContext as there is no restriction within UpdateContext. -* [ attributesFormat=object: makes no sense for this operation as StatusCode is returned ] -* -* 0. Take care of URI params -* 1. Fill in UpdateContextRequest from UpdateContextAttributeRequest and URL-path components -* 2. Call postUpdateContext standard service routine -* 3. Translate UpdateContextResponse to StatusCode -* 4. Cleanup and return result -*/ -std::string putIndividualContextEntityAttribute -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -) -{ - std::string answer; - std::string entityId = compV[2]; - std::string entityType = ciP->uriParam[URI_PARAM_ENTITY_TYPE]; - std::string attributeName = compV[4]; - StatusCode response; - - - // 1. Fill in UpdateContextRequest from UpdateContextAttributeRequest and URL-path components - parseDataP->upcr.res.fill(&parseDataP->upcar.res, entityId, entityType, attributeName, ActionTypeUpdate); - - - // 2. Call postUpdateContext standard service routine - postUpdateContext(ciP, components, compV, parseDataP); - - - // 3. Translate UpdateContextResponse to StatusCode - response.fill(parseDataP->upcrs.res); - - - // 4. Cleanup and return result - TIMED_RENDER(answer = response.toJsonV1(false, false)); - - response.release(); - parseDataP->upcr.res.release(); // This call to release() crashed the functional test - // 647_crash_with_compounds/PUT_v1_contextEntities_E1_attributes_A1.test - - return answer; -} diff --git a/src/lib/serviceRoutines/putIndividualContextEntityAttribute.h b/src/lib/serviceRoutines/putIndividualContextEntityAttribute.h deleted file mode 100644 index 4560abbb9f..0000000000 --- a/src/lib/serviceRoutines/putIndividualContextEntityAttribute.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef SRC_LIB_SERVICEROUTINES_PUTINDIVIDUALCONTEXTENTITYATTRIBUTE_H_ -#define SRC_LIB_SERVICEROUTINES_PUTINDIVIDUALCONTEXTENTITYATTRIBUTE_H_ - -/* -* -* Copyright 2014 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: TID Developer -*/ -#include -#include - -#include "rest/ConnectionInfo.h" -#include "ngsi/ParseData.h" - - - -/* **************************************************************************** -* -* putIndividualContextEntityAttribute - -*/ -extern std::string putIndividualContextEntityAttribute -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -); - -#endif // SRC_LIB_SERVICEROUTINES_PUTINDIVIDUALCONTEXTENTITYATTRIBUTE_H_ diff --git a/src/lib/serviceRoutines/putIndividualContextEntityAttributeWithTypeAndId.cpp b/src/lib/serviceRoutines/putIndividualContextEntityAttributeWithTypeAndId.cpp deleted file mode 100644 index a7fbb65f07..0000000000 --- a/src/lib/serviceRoutines/putIndividualContextEntityAttributeWithTypeAndId.cpp +++ /dev/null @@ -1,125 +0,0 @@ -/* -* -* Copyright 2014 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/statistics.h" -#include "common/clockFunctions.h" -#include "alarmMgr/alarmMgr.h" - -#include "ngsi/ParseData.h" -#include "ngsi/StatusCode.h" -#include "rest/ConnectionInfo.h" -#include "rest/EntityTypeInfo.h" -#include "rest/uriParamNames.h" -#include "serviceRoutines/postUpdateContext.h" -#include "serviceRoutines/putIndividualContextEntityAttribute.h" - - - -/* **************************************************************************** -* -* putIndividualContextEntityAttributeWithTypeAndId - -* -* PUT /v1/contextEntities/type/{entity::type}/id/{entity::id}/attributes/{attribute::name} -* -* Payload In: UpdateContextAttributeRequest -* Payload Out: StatusCode -* -* URI parameters: -* - entity::type=XXX (must coincide with entity::type in URL) -* - !exist=entity::type (if set - error -- entity::type cannot be empty) -* - exist=entity::type (not supported - ok if present, ok if not present ...) -* x attributesFormat=object (cannot be supported as the response is a StatusCode) -* -*/ -std::string putIndividualContextEntityAttributeWithTypeAndId -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -) -{ - std::string entityType = compV[3]; - std::string entityId = compV[5]; - std::string attributeName = compV[7]; - std::string entityTypeFromUriParam = ciP->uriParam[URI_PARAM_ENTITY_TYPE]; - EntityTypeInfo typeInfo = EntityTypeEmptyOrNotEmpty; - std::string answer; - StatusCode response; - - // 01. Get values from URL (entityId::type, esist, !exist) - if (ciP->uriParam[URI_PARAM_NOT_EXIST] == URI_PARAM_ENTITY_TYPE) - { - typeInfo = EntityTypeEmpty; - } - else if (ciP->uriParam[URI_PARAM_EXIST] == URI_PARAM_ENTITY_TYPE) - { - typeInfo = EntityTypeNotEmpty; - } - - - // 02. Check validity of URI params ... - // And if OK; - // 03. Fill in UpdateContextRequest - // 04. Call standard operation postUpdateContext - // 05. Translate UpdateContextResponse to StatusCode - // - if (typeInfo == EntityTypeEmpty) - { - response.fill(SccBadRequest, "entity::type cannot be empty for this request"); - alarmMgr.badInput(clientIp, "entity::type cannot be empty for this request"); - } - else if ((entityTypeFromUriParam != entityType) && (!entityTypeFromUriParam.empty())) - { - response.fill(SccBadRequest, "non-matching entity::types in URL"); - alarmMgr.badInput(clientIp, "non-matching entity::types in URL", entityTypeFromUriParam); - } - else - { - // 03. Fill in UpdateContextRequest - parseDataP->upcr.res.fill(&parseDataP->upcar.res, entityId, entityType, attributeName, ActionTypeUpdate); - - // 04. Call standard operation postUpdateContext - postUpdateContext(ciP, components, compV, parseDataP); - - // 05. Translate UpdateContextResponse to StatusCode - response.fill(parseDataP->upcrs.res); - } - - - // 06. Cleanup and return result - TIMED_RENDER(answer = response.toJsonV1(false, false)); - - parseDataP->upcar.res.release(); - parseDataP->upcrs.res.release(); - parseDataP->upcr.res.release(); - - return answer; -} diff --git a/src/lib/serviceRoutines/putIndividualContextEntityAttributeWithTypeAndId.h b/src/lib/serviceRoutines/putIndividualContextEntityAttributeWithTypeAndId.h deleted file mode 100644 index c5663b52f6..0000000000 --- a/src/lib/serviceRoutines/putIndividualContextEntityAttributeWithTypeAndId.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef SRC_LIB_SERVICEROUTINES_PUTINDIVIDUALCONTEXTENTITYATTRIBUTEWITHTYPEANDID_H_ -#define SRC_LIB_SERVICEROUTINES_PUTINDIVIDUALCONTEXTENTITYATTRIBUTEWITHTYPEANDID_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "rest/ConnectionInfo.h" -#include "ngsi/ParseData.h" - - - -/* **************************************************************************** -* -* putIndividualContextEntityAttributeWithTypeAndId - -*/ -extern std::string putIndividualContextEntityAttributeWithTypeAndId -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -); - -#endif // SRC_LIB_SERVICEROUTINES_PUTINDIVIDUALCONTEXTENTITYATTRIBUTEWITHTYPEANDID_H_ diff --git a/src/lib/serviceRoutines/putSubscriptionConvOp.cpp b/src/lib/serviceRoutines/putSubscriptionConvOp.cpp deleted file mode 100644 index 03521ef567..0000000000 --- a/src/lib/serviceRoutines/putSubscriptionConvOp.cpp +++ /dev/null @@ -1,72 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "ngsi/ParseData.h" -#include "rest/ConnectionInfo.h" -#include "rest/restReply.h" -#include "serviceRoutines/postUpdateContextSubscription.h" -#include "serviceRoutines/putSubscriptionConvOp.h" - - - -/* **************************************************************************** -* -* putSubscriptionConvOp - -* -* PUT /v1/contextSubscriptions/{subscriptionId} -* -* Payload In: UpdateContextSubscriptionRequest -* Payload Out: UpdateContextSubscriptionResponse -* -* URI parameters -* x entity::type=TYPE (NOT TREATED) -* x !exist=entity::type (NOT TREATED) -* x exist=entity::type (NOT TREATED) -*/ -std::string putSubscriptionConvOp -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -) -{ - std::string subscriptionId = compV[2]; - UpdateContextSubscriptionRequest* ucsrP = &parseDataP->ucsr.res; - - if (subscriptionId != ucsrP->subscriptionId.get()) - { - std::string out; - std::string details = std::string("unmatching subscriptionId URI/payload: /") + subscriptionId + "/ vs /" + ucsrP->subscriptionId.get() + "/"; - - restErrorReplyGet(ciP, SccBadRequest, details, &out); - - return out; - } - - return postUpdateContextSubscription(ciP, components, compV, parseDataP); -} diff --git a/src/lib/serviceRoutines/putSubscriptionConvOp.h b/src/lib/serviceRoutines/putSubscriptionConvOp.h deleted file mode 100644 index 1501736290..0000000000 --- a/src/lib/serviceRoutines/putSubscriptionConvOp.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef SRC_LIB_SERVICEROUTINES_PUTSUBSCRIPTIONCONVOP_H_ -#define SRC_LIB_SERVICEROUTINES_PUTSUBSCRIPTIONCONVOP_H_ - -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "ngsi/ParseData.h" -#include "rest/ConnectionInfo.h" - - - -/* **************************************************************************** -* -* putSubscriptionConvOp - -*/ -extern std::string putSubscriptionConvOp -( - ConnectionInfo* ciP, - int components, - std::vector& compV, - ParseData* parseDataP -); - -#endif // SRC_LIB_SERVICEROUTINES_PUTSUBSCRIPTIONCONVOP_H_ diff --git a/src/lib/serviceRoutines/statisticsTreat.cpp b/src/lib/serviceRoutines/statisticsTreat.cpp index ec734f51a9..ced5268ded 100644 --- a/src/lib/serviceRoutines/statisticsTreat.cpp +++ b/src/lib/serviceRoutines/statisticsTreat.cpp @@ -30,7 +30,6 @@ #include "common/string.h" #include "common/globals.h" -#include "common/tag.h" #include "common/statistics.h" #include "common/sem.h" #include "metricsMgr/metricsMgr.h" @@ -91,7 +90,6 @@ static void resetStatistics(void) noOfNotificationsSent = -1; noOfSimulatedNotifications = -1; - noOfDprNgsiv1Request = -1; noOfDprLegacyForwarding = -1; noOfDprGeoformat = -1; @@ -174,13 +172,6 @@ std::string renderCounterStats(bool fullCounters) (noOfRequestCounters[ix].patch != -1) || (noOfRequestCounters[ix].put != -1) || (noOfRequestCounters[ix]._delete != -1) || (noOfRequestCounters[ix].options != -1)) { - // FIXME: in 3.9.0 most of the NGSIv1/NGSI10 requests were removed. We have invented and speciall value "skip" - // for these cases. This "skip" hack should be removed when we definitively remove all that code - if (requestTypeForCounter(noOfRequestCounters[ix].request, std::string(noOfRequestCounters[ix].prefix)) == "skip") - { - continue; - } - // We add in the accumulator corresponing do the request kind if (((strncmp(noOfRequestCounters[ix].prefix, "v1", strlen("v1"))) == 0) || (strncmp(noOfRequestCounters[ix].prefix, "ngsi10", strlen("ngsi10")) == 0)) { @@ -218,7 +209,6 @@ std::string renderCounterStats(bool fullCounters) renderUsedCounter(&js, "notificationsSent", noOfNotificationsSent, fullCounters); JsonObjectHelper jsDeprecated; - renderUsedCounter(&jsDeprecated, "ngsiv1Requests", noOfDprNgsiv1Request, fullCounters); renderUsedCounter(&jsDeprecated, "ngsiv1Forwarding", noOfDprLegacyForwarding, fullCounters); renderUsedCounter(&jsDeprecated, "geoFormat", noOfDprGeoformat, fullCounters); diff --git a/src/lib/serviceRoutines/versionTreat.cpp b/src/lib/serviceRoutines/versionTreat.cpp index 1b71e28125..1d904a4d8f 100644 --- a/src/lib/serviceRoutines/versionTreat.cpp +++ b/src/lib/serviceRoutines/versionTreat.cpp @@ -30,7 +30,6 @@ #include "common/string.h" #include "common/globals.h" -#include "common/tag.h" #include "common/compileInfo.h" #include "common/defaultValues.h" #include "rest/HttpHeaders.h" @@ -163,7 +162,6 @@ std::string versionTreat } std::string out = ""; - std::string indent = ""; #ifdef UNIT_TEST std::string uptime = "0 d, 0 h, 0 m, 0 s"; diff --git a/src/lib/serviceRoutinesV2/badVerbAllNotDelete.cpp b/src/lib/serviceRoutinesV2/badVerbAllNotDelete.cpp index 8731fd7df0..93b9d913c9 100644 --- a/src/lib/serviceRoutinesV2/badVerbAllNotDelete.cpp +++ b/src/lib/serviceRoutinesV2/badVerbAllNotDelete.cpp @@ -58,8 +58,8 @@ std::string badVerbAllNotDelete ciP->httpHeader.push_back(HTTP_ALLOW); std::string headerValue = "GET, PATCH, POST, PUT"; - // OPTIONS verb is only available for V2 API - if ((corsEnabled == true) && (ciP->apiVersion == V2)) + //OPTIONS verb is only available for V2 API, e.g. not available for GET /version + if ((corsEnabled == true) && (ciP->url.compare(0, 3, "/v2") == 0)) { headerValue = headerValue + ", OPTIONS"; } @@ -68,5 +68,5 @@ std::string badVerbAllNotDelete alarmMgr.badInput(clientIp, details); - return (ciP->apiVersion == V1 || ciP->apiVersion == NO_VERSION)? "" : oe.smartRender(ciP->apiVersion); + return oe.toJson(); } diff --git a/src/lib/serviceRoutinesV2/badVerbGetDeletePatchOnly.cpp b/src/lib/serviceRoutinesV2/badVerbGetDeletePatchOnly.cpp index 4d3c5fc5da..ae9d77e493 100644 --- a/src/lib/serviceRoutinesV2/badVerbGetDeletePatchOnly.cpp +++ b/src/lib/serviceRoutinesV2/badVerbGetDeletePatchOnly.cpp @@ -57,8 +57,8 @@ std::string badVerbGetDeletePatchOnly ciP->httpHeader.push_back(HTTP_ALLOW); std::string headerValue = "GET, DELETE, PATCH"; - // OPTIONS verb is only available for V2 API - if ((corsEnabled == true) && (ciP->apiVersion == V2)) + //OPTIONS verb is only available for V2 API, e.g. not available for GET /version + if ((corsEnabled == true) && (ciP->url.compare(0, 3, "/v2") == 0)) { headerValue = headerValue + ", OPTIONS"; } @@ -67,5 +67,5 @@ std::string badVerbGetDeletePatchOnly alarmMgr.badInput(clientIp, details); - return (ciP->apiVersion == V1 || ciP->apiVersion == NO_VERSION)? "" : oe.smartRender(ciP->apiVersion); + return oe.toJson(); } diff --git a/src/lib/serviceRoutinesV2/badVerbGetPutOnly.cpp b/src/lib/serviceRoutinesV2/badVerbGetPutOnly.cpp index ee091b82bb..829213140a 100644 --- a/src/lib/serviceRoutinesV2/badVerbGetPutOnly.cpp +++ b/src/lib/serviceRoutinesV2/badVerbGetPutOnly.cpp @@ -57,8 +57,8 @@ std::string badVerbGetPutOnly ciP->httpHeader.push_back(HTTP_ALLOW); std::string headerValue = "GET, PUT"; - // OPTIONS verb is only available for V2 API - if ((corsEnabled == true) && (ciP->apiVersion == V2)) + //OPTIONS verb is only available for V2 API, e.g. not available for GET /version + if ((corsEnabled == true) && (ciP->url.compare(0, 3, "/v2") == 0)) { headerValue = headerValue + ", OPTIONS"; } @@ -67,5 +67,5 @@ std::string badVerbGetPutOnly alarmMgr.badInput(clientIp, details); - return (ciP->apiVersion == V1 || ciP->apiVersion == NO_VERSION)? "" : oe.smartRender(ciP->apiVersion); + return oe.toJson(); } diff --git a/src/lib/serviceRoutinesV2/deleteEntity.cpp b/src/lib/serviceRoutinesV2/deleteEntity.cpp index f70eaa226c..009876bacd 100644 --- a/src/lib/serviceRoutinesV2/deleteEntity.cpp +++ b/src/lib/serviceRoutinesV2/deleteEntity.cpp @@ -31,7 +31,6 @@ #include "rest/ConnectionInfo.h" #include "ngsi/ParseData.h" -#include "apiTypesV2/Entities.h" #include "rest/OrionError.h" #include "rest/EntityTypeInfo.h" #include "serviceRoutinesV2/deleteEntity.h" @@ -67,16 +66,16 @@ std::string deleteEntity { Entity* eP; - if (forbiddenIdChars(ciP->apiVersion, compV[2].c_str() , NULL)) + if (forbiddenIdCharsV2(compV[2].c_str() , NULL)) { OrionError oe(SccBadRequest, ERROR_DESC_BAD_REQUEST_INVALID_CHAR_URI, ERROR_BAD_REQUEST); ciP->httpStatusCode = oe.code; return oe.toJson(); } - eP = new Entity(); - eP->id = compV[2]; - eP->type = ciP->uriParam["type"]; + eP = new Entity(); + eP->entityId.id = compV[2]; + eP->entityId.type = ciP->uriParam["type"]; if (compV.size() == 5) // Deleting an attribute { @@ -92,16 +91,16 @@ std::string deleteEntity postUpdateContext(ciP, components, compV, parseDataP); // Adjust error code if needed - adaptErrorCodeForSingleEntityOperation(&(parseDataP->upcrs.res.oe), true); + adaptErrorCodeForSingleEntityOperation(&(parseDataP->upcrs.res.error), true); ciP->outMimeType = JSON; // Check for potential error string answer = ""; - if (parseDataP->upcrs.res.oe.code != SccNone ) + if ((parseDataP->upcrs.res.error.code != SccNone ) && (parseDataP->upcrs.res.error.code != SccOk)) { - TIMED_RENDER(answer = parseDataP->upcrs.res.oe.toJson()); - ciP->httpStatusCode = parseDataP->upcrs.res.oe.code; + TIMED_RENDER(answer = parseDataP->upcrs.res.error.toJson()); + ciP->httpStatusCode = parseDataP->upcrs.res.error.code; } else { diff --git a/src/lib/serviceRoutinesV2/deleteSubscription.cpp b/src/lib/serviceRoutinesV2/deleteSubscription.cpp index f9ea240cd4..c3172040c3 100644 --- a/src/lib/serviceRoutinesV2/deleteSubscription.cpp +++ b/src/lib/serviceRoutinesV2/deleteSubscription.cpp @@ -31,7 +31,6 @@ #include "ngsi/ParseData.h" #include "rest/OrionError.h" #include "mongoBackend/mongoUnsubscribeContext.h" -#include "ngsi10/UnsubscribeContextResponse.h" #include "serviceRoutinesV2/deleteSubscription.h" @@ -57,20 +56,17 @@ std::string deleteSubscription ParseData* parseDataP ) { - std::string subscriptionId = compV[2]; - UnsubscribeContextResponse uncr; + std::string subscriptionId = compV[2]; + OrionError oe; - // 'Fill In' UnsubscribeContextRequest - parseDataP->uncr.res.subscriptionId.set(subscriptionId); - - TIMED_MONGO(mongoUnsubscribeContext(&parseDataP->uncr.res, &uncr, ciP->tenant)); + TIMED_MONGO(mongoUnsubscribeContext(subscriptionId, &oe, ciP->tenant)); // Check for potential error std::string answer = ""; - if (uncr.oe.code != SccNone ) + if (oe.code != SccNone ) { - TIMED_RENDER(answer = uncr.oe.toJson()); - ciP->httpStatusCode = uncr.oe.code; + TIMED_RENDER(answer = oe.toJson()); + ciP->httpStatusCode = oe.code; } else { diff --git a/src/lib/serviceRoutinesV2/entryPointsTreat.cpp b/src/lib/serviceRoutinesV2/entryPointsTreat.cpp index 7f4beb6c7d..25b43e726d 100644 --- a/src/lib/serviceRoutinesV2/entryPointsTreat.cpp +++ b/src/lib/serviceRoutinesV2/entryPointsTreat.cpp @@ -30,7 +30,6 @@ #include "common/string.h" #include "common/globals.h" -#include "common/tag.h" #include "common/JsonHelper.h" #include "ngsi/ParseData.h" diff --git a/src/lib/serviceRoutinesV2/getEntities.cpp b/src/lib/serviceRoutinesV2/getEntities.cpp index ef12312fbd..7c0b8bcf66 100644 --- a/src/lib/serviceRoutinesV2/getEntities.cpp +++ b/src/lib/serviceRoutinesV2/getEntities.cpp @@ -35,7 +35,6 @@ #include "rest/uriParamNames.h" #include "rest/EntityTypeInfo.h" #include "ngsi/ParseData.h" -#include "apiTypesV2/Entities.h" #include "serviceRoutinesV2/getEntities.h" #include "serviceRoutinesV2/serviceRoutinesCommon.h" #include "serviceRoutines/postQueryContext.h" @@ -43,6 +42,70 @@ +/* **************************************************************************** +* +* fillEntityVector - +* +* NOTE +* The errorCode field from qcrsP is not used at all if errorCode::code equals SccOk. +* This means that e.g. the "Count:" in errorCode::details (from v1 logic) will not be +* present in the Entities for v2 (that number is in the HTTP header Fiware-Total-Count for v2). +* Other values for "details" are lost as well, if errorCode::code equals SccOk. +* +* FIXME PR: v1 is mentioned above... review this closely +*/ +static void fillEntityVector(const QueryContextResponse& qcrs, EntityVector* enVP, OrionError* oeP) +{ + if (qcrs.error.code == SccContextElementNotFound) + { + // + // If no entities are found, we respond with a 200 OK + // and an empty vector of entities ( [] ) + // + + oeP->fill(SccOk, "", "OK"); + return; + } + else if (qcrs.error.code != SccOk) + { + // + // If any other error - use the error for the response + // + + oeP->fill(qcrs.error.code, qcrs.error.description, qcrs.error.error); + return; + } + + for (unsigned int ix = 0; ix < qcrs.contextElementResponseVector.size(); ++ix) + { + Entity* eP = &qcrs.contextElementResponseVector[ix]->entity; + + if ((&qcrs.contextElementResponseVector[ix]->error)->code == SccReceiverInternalError) + { + // FIXME P4: Do we need to release the memory allocated in 'vec' before returning? I don't + // think so, as the releasing logic in the upper layer will deal with that but + // let's do anyway just in case... (we don't have a ft covering this, so valgrind suite + // cannot help here and it is better to ensure) + oeP->fill(&qcrs.contextElementResponseVector[ix]->error); + enVP->release(); + return; + } + else + { + Entity* newP = new Entity(); + + newP->entityId = eP->entityId; + newP->creDate = eP->creDate; + newP->modDate = eP->modDate; + + newP->attributeVector.fill(eP->attributeVector); + enVP->push_back(newP); + } + } +} + + + /* **************************************************************************** * * getEntities - @@ -82,7 +145,7 @@ std::string getEntities ParseData* parseDataP ) { - Entities entities; + EntityVector entities; std::string answer; std::string pattern = ".*"; // all entities, default value std::string id = ciP->uriParam["id"]; @@ -184,7 +247,7 @@ std::string getEntities Scope* scopeP = new Scope(SCOPE_TYPE_LOCATION, ""); std::string errorString; - if (scopeP->fill(ciP->apiVersion, geometry, coords, georel, &errorString) != 0) + if (scopeP->fill(geometry, coords, georel, &errorString) != 0) { OrionError oe(SccBadRequest, std::string("Invalid query: ") + errorString, ERROR_BAD_REQUEST); @@ -197,7 +260,7 @@ std::string getEntities return out; } - parseDataP->qcr.res.restriction.scopeVector.push_back(scopeP); + parseDataP->qcr.res.scopeVector.push_back(scopeP); } @@ -227,7 +290,7 @@ std::string getEntities return out; } - parseDataP->qcr.res.restriction.scopeVector.push_back(scopeP); + parseDataP->qcr.res.scopeVector.push_back(scopeP); } @@ -256,7 +319,7 @@ std::string getEntities return out; } - parseDataP->qcr.res.restriction.scopeVector.push_back(scopeP); + parseDataP->qcr.res.scopeVector.push_back(scopeP); } @@ -272,22 +335,16 @@ std::string getEntities if (!typePattern.empty()) { - bool isIdPattern = (!idPattern.empty() || pattern == ".*"); - EntityId* entityId = new EntityId(pattern, typePattern, isIdPattern ? "true" : "false", true); - + EntityId* entityId = new EntityId("", pattern, "", typePattern); parseDataP->qcr.res.entityIdVector.push_back(entityId); } else if (ciP->uriParamTypes.size() == 0) { - parseDataP->qcr.res.fill(pattern, "", "true", EntityTypeEmptyOrNotEmpty, ""); + parseDataP->qcr.res.fill("", pattern, "", EntityTypeEmptyOrNotEmpty, ""); } else if (ciP->uriParamTypes.size() == 1) { - parseDataP->qcr.res.fill(pattern, type, "true", EntityTypeNotEmpty, ""); - } - else if (ciP->uriParamTypes.size() == 1) - { - parseDataP->qcr.res.fill(pattern, type, "true", EntityTypeNotEmpty, ""); + parseDataP->qcr.res.fill("", pattern, type, EntityTypeNotEmpty, ""); } else { @@ -297,7 +354,7 @@ std::string getEntities // for (unsigned int ix = 0; ix < ciP->uriParamTypes.size(); ++ix) { - EntityId* entityId = new EntityId(pattern, ciP->uriParamTypes[ix], "true"); + EntityId* entityId = new EntityId("", pattern, ciP->uriParamTypes[ix], ""); parseDataP->qcr.res.entityIdVector.push_back(entityId); } @@ -308,14 +365,14 @@ std::string getEntities setMetadataFilter(ciP->uriParam, &parseDataP->qcr.res.metadataList); // 02. Call standard op postQueryContext - answer = postQueryContext(ciP, components, compV, parseDataP); + postQueryContext(ciP, components, compV, parseDataP); // 03. Check Internal Errors - if (parseDataP->qcrs.res.errorCode.code == SccReceiverInternalError) + if (parseDataP->qcrs.res.error.code == SccReceiverInternalError) { OrionError oe; - entities.fill(parseDataP->qcrs.res, &oe); - TIMED_RENDER(answer = oe.smartRender(V2)); + fillEntityVector(parseDataP->qcrs.res, &entities, &oe); + TIMED_RENDER(answer = oe.toJson()); ciP->httpStatusCode = oe.code; } // 04. Render Entities response @@ -327,7 +384,7 @@ std::string getEntities else { OrionError oe; - entities.fill(parseDataP->qcrs.res, &oe); + fillEntityVector(parseDataP->qcrs.res, &entities, &oe); if (oe.code != SccNone) { diff --git a/src/lib/serviceRoutinesV2/getEntity.cpp b/src/lib/serviceRoutinesV2/getEntity.cpp index a9af9bd284..8add44a5e8 100644 --- a/src/lib/serviceRoutinesV2/getEntity.cpp +++ b/src/lib/serviceRoutinesV2/getEntity.cpp @@ -33,7 +33,6 @@ #include "rest/ConnectionInfo.h" #include "rest/uriParamNames.h" #include "ngsi/ParseData.h" -#include "apiTypesV2/Entities.h" #include "rest/EntityTypeInfo.h" #include "serviceRoutinesV2/getEntities.h" #include "serviceRoutinesV2/serviceRoutinesCommon.h" @@ -76,7 +75,7 @@ std::string getEntity return oe.toJson(); } - if (forbiddenIdChars(ciP->apiVersion, entityId.c_str(), NULL)) + if (forbiddenIdCharsV2(entityId.c_str(), NULL)) { OrionError oe(SccBadRequest, ERROR_DESC_BAD_REQUEST_INVALID_CHAR_URI, ERROR_BAD_REQUEST); ciP->httpStatusCode = oe.code; @@ -84,7 +83,7 @@ std::string getEntity } // Fill in QueryContextRequest - parseDataP->qcr.res.fill(entityId, type, "false", EntityTypeEmptyOrNotEmpty, ""); + parseDataP->qcr.res.fill(entityId, "", type, EntityTypeEmptyOrNotEmpty, ""); // Get attrs and metadata filters from URL params setAttrsFilter(ciP->uriParam, ciP->uriParamOptions, &parseDataP->qcr.res.attrsList); @@ -117,7 +116,7 @@ std::string getEntity parseDataP->qcr.res.metadataList.stringV)); // response code the same of the wrapped operation - ciP->httpStatusCode = parseDataP->qcrs.res.errorCode.code; + ciP->httpStatusCode = parseDataP->qcrs.res.error.code; } else { diff --git a/src/lib/serviceRoutinesV2/getEntityAllTypes.cpp b/src/lib/serviceRoutinesV2/getEntityAllTypes.cpp index 39d4481bd3..3ba193c12e 100644 --- a/src/lib/serviceRoutinesV2/getEntityAllTypes.cpp +++ b/src/lib/serviceRoutinesV2/getEntityAllTypes.cpp @@ -80,7 +80,6 @@ std::string getEntityAllTypes ciP->tenant, ciP->servicePathV, ciP->uriParam, - ciP->apiVersion, totalTypesP, noAttrDetail)); } diff --git a/src/lib/serviceRoutinesV2/getEntityAttribute.cpp b/src/lib/serviceRoutinesV2/getEntityAttribute.cpp index ae9145b4ed..854fd44375 100644 --- a/src/lib/serviceRoutinesV2/getEntityAttribute.cpp +++ b/src/lib/serviceRoutinesV2/getEntityAttribute.cpp @@ -30,7 +30,6 @@ #include "common/errorMessages.h" #include "rest/uriParamNames.h" -#include "apiTypesV2/Attribute.h" #include "rest/ConnectionInfo.h" #include "ngsi/ParseData.h" #include "rest/EntityTypeInfo.h" @@ -65,10 +64,9 @@ std::string getEntityAttribute { std::string type = ciP->uriParam["type"]; std::string answer; - Attribute attribute; - if (forbiddenIdChars(ciP->apiVersion, compV[2].c_str(), NULL) || - forbiddenIdChars(ciP->apiVersion, compV[4].c_str(), NULL)) + if (forbiddenIdCharsV2(compV[2].c_str(), NULL) || + forbiddenIdCharsV2(compV[4].c_str(), NULL)) { OrionError oe(SccBadRequest, ERROR_DESC_BAD_REQUEST_INVALID_CHAR_URI, ERROR_BAD_REQUEST); ciP->httpStatusCode = oe.code; @@ -76,29 +74,28 @@ std::string getEntityAttribute } // 01. Fill in QueryContextRequest - parseDataP->qcr.res.fill(compV[2], type, "false", EntityTypeEmptyOrNotEmpty, ""); - + parseDataP->qcr.res.fill(compV[2], "", type, EntityTypeEmptyOrNotEmpty, ""); // 02. Call standard op postQueryContext + OrionError oe; postQueryContext(ciP, components, compV, parseDataP); - + ContextAttribute* caP = parseDataP->qcrs.res.getAttr(compV[4], &oe); // 03. Render entity attribute response - OrionError oe; - attribute.fill(parseDataP->qcrs.res, compV[4], &oe); - - if (oe.code == SccNone) + if (caP != NULL) { - StringList metadataFilter; - setMetadataFilter(ciP->uriParam, &metadataFilter); - TIMED_RENDER(answer = attribute.toJson(ciP->httpHeaders.accepted("text/plain"), - ciP->httpHeaders.accepted("application/json"), - ciP->httpHeaders.outformatSelect(), - &(ciP->outMimeType), - &(ciP->httpStatusCode), - ciP->uriParamOptions[OPT_KEY_VALUES], - metadataFilter.stringV, - EntityAttributeResponse)); + if (ciP->uriParamOptions[OPT_KEY_VALUES]) // NGSI_V2_KEYVALUES + { + JsonObjectHelper jh; + jh.addRaw(caP->name, caP->toJsonValue()); + TIMED_RENDER(answer = jh.str()); + } + else // NGSI_V2_NORMALIZED + { + StringList metadataFilter; + setMetadataFilter(ciP->uriParam, &metadataFilter); + TIMED_RENDER(answer = caP->toJson(metadataFilter.stringV)); + } } else { @@ -116,7 +113,7 @@ std::string getEntityAttribute else { // the same of the wrapped operation - ciP->httpStatusCode = parseDataP->qcrs.res.errorCode.code; + ciP->httpStatusCode = parseDataP->qcrs.res.error.code; } // 04. Cleanup and return result diff --git a/src/lib/serviceRoutinesV2/getEntityAttributeValue.cpp b/src/lib/serviceRoutinesV2/getEntityAttributeValue.cpp index be1e783da2..0110d4edbc 100644 --- a/src/lib/serviceRoutinesV2/getEntityAttributeValue.cpp +++ b/src/lib/serviceRoutinesV2/getEntityAttributeValue.cpp @@ -30,7 +30,6 @@ #include "common/errorMessages.h" #include "common/string.h" -#include "apiTypesV2/Attribute.h" #include "rest/ConnectionInfo.h" #include "ngsi/ParseData.h" #include "ngsi/ContextAttribute.h" @@ -65,12 +64,11 @@ std::string getEntityAttributeValue ParseData* parseDataP ) { - Attribute attribute; std::string answer; std::string type = ciP->uriParam["type"]; - if (forbiddenIdChars(ciP->apiVersion, compV[2].c_str(), NULL) || - (forbiddenIdChars(ciP->apiVersion, compV[4].c_str(), NULL))) + if (forbiddenIdCharsV2( compV[2].c_str(), NULL) || + (forbiddenIdCharsV2(compV[4].c_str(), NULL))) { OrionError oe(SccBadRequest, ERROR_DESC_BAD_REQUEST_INVALID_CHAR_URI, ERROR_BAD_REQUEST); ciP->httpStatusCode = oe.code; @@ -78,14 +76,14 @@ std::string getEntityAttributeValue } // Fill in QueryContextRequest - parseDataP->qcr.res.fill(compV[2], type, "false", EntityTypeEmptyOrNotEmpty, ""); + parseDataP->qcr.res.fill("", compV[2], type, EntityTypeEmptyOrNotEmpty, ""); // Call standard op postQueryContext OrionError oe; postQueryContext(ciP, components, compV, parseDataP); - attribute.fill(parseDataP->qcrs.res, compV[4], &oe); + ContextAttribute* caP = parseDataP->qcrs.res.getAttr(compV[4], &oe); - if (oe.code != SccNone) + if (caP == NULL) { TIMED_RENDER(answer = oe.toJson()); ciP->httpStatusCode = oe.code; @@ -93,48 +91,41 @@ std::string getEntityAttributeValue else { // save the original attribute type - std::string attributeType = attribute.contextAttributeP->type; + std::string attributeType = caP->type; // the same of the wrapped operation - ciP->httpStatusCode = parseDataP->qcrs.res.errorCode.code; + ciP->httpStatusCode = parseDataP->qcrs.res.error.code; // Remove unwanted fields from attribute before rendering - attribute.contextAttributeP->type = ""; - attribute.contextAttributeP->metadataVector.release(); + caP->type = ""; + caP->metadataVector.release(); if (ciP->outMimeType == JSON) { // Do not use attribute name, change to 'value' - attribute.contextAttributeP->name = "value"; - - StringList metadataFilter; - setMetadataFilter(ciP->uriParam, &metadataFilter); - - TIMED_RENDER(answer = attribute.toJson(ciP->httpHeaders.accepted("text/plain"), - ciP->httpHeaders.accepted("application/json"), - ciP->httpHeaders.outformatSelect(), - &(ciP->outMimeType), - &(ciP->httpStatusCode), - ciP->uriParamOptions[OPT_KEY_VALUES], - metadataFilter.stringV, - EntityAttributeValueRequest)); + caP->name = "value"; + TIMED_RENDER(answer = caP->toJsonAsValue(ciP->httpHeaders.accepted("text/plain"), + ciP->httpHeaders.accepted("application/json"), + ciP->httpHeaders.outformatSelect(), + &(ciP->outMimeType), + &(ciP->httpStatusCode))); } else { - if (attribute.contextAttributeP->compoundValueP != NULL) + if (caP->compoundValueP != NULL) { - TIMED_RENDER(answer = attribute.contextAttributeP->compoundValueP->toJson()); + TIMED_RENDER(answer = caP->compoundValueP->toJson()); } else { if ((attributeType == DATE_TYPE) || (attributeType == DATE_TYPE_ALT)) { - TIMED_RENDER(answer = isodate2str(attribute.contextAttributeP->numberValue)); + TIMED_RENDER(answer = isodate2str(caP->numberValue)); } else { - TIMED_RENDER(answer = attribute.contextAttributeP->getValue()); - if (attribute.contextAttributeP->valueType == orion::ValueTypeString) + TIMED_RENDER(answer = caP->getValue()); + if (caP->valueType == orion::ValueTypeString) { answer = '"' + answer + '"'; } diff --git a/src/lib/serviceRoutinesV2/getEntityType.cpp b/src/lib/serviceRoutinesV2/getEntityType.cpp index 33c704feb6..71b36f51dc 100644 --- a/src/lib/serviceRoutinesV2/getEntityType.cpp +++ b/src/lib/serviceRoutinesV2/getEntityType.cpp @@ -76,8 +76,7 @@ std::string getEntityType ciP->tenant, ciP->servicePathV, ciP->uriParam, - noAttrDetail, - ciP->apiVersion)); + noAttrDetail)); if (response.entityType.count == 0) { diff --git a/src/lib/serviceRoutinesV2/patchEntity.cpp b/src/lib/serviceRoutinesV2/patchEntity.cpp index ad767b632c..d88c752819 100644 --- a/src/lib/serviceRoutinesV2/patchEntity.cpp +++ b/src/lib/serviceRoutinesV2/patchEntity.cpp @@ -31,7 +31,6 @@ #include "parse/forbiddenChars.h" #include "rest/ConnectionInfo.h" #include "ngsi/ParseData.h" -#include "apiTypesV2/Entities.h" #include "rest/EntityTypeInfo.h" #include "serviceRoutinesV2/patchEntity.h" #include "serviceRoutinesV2/serviceRoutinesCommon.h" @@ -69,10 +68,10 @@ std::string patchEntity std::string answer = ""; Entity* eP = &parseDataP->ent.res; - eP->id = compV[2]; - eP->type = ciP->uriParam["type"]; + eP->entityId.id = compV[2]; + eP->entityId.type = ciP->uriParam["type"]; - if (forbiddenIdChars(ciP->apiVersion, eP->id.c_str() , NULL)) + if (forbiddenIdCharsV2(eP->entityId.id.c_str() , NULL)) { OrionError oe(SccBadRequest, ERROR_DESC_BAD_REQUEST_INVALID_CHAR_URI, ERROR_BAD_REQUEST); ciP->httpStatusCode = oe.code; @@ -87,13 +86,13 @@ std::string patchEntity postUpdateContext(ciP, components, compV, parseDataP); // Adjust error code if needed - adaptErrorCodeForSingleEntityOperation(&(parseDataP->upcrs.res.oe), false); + adaptErrorCodeForSingleEntityOperation(&(parseDataP->upcrs.res.error), false); // 03. Check output from mongoBackend - any errors? - if (parseDataP->upcrs.res.oe.code != SccNone ) + if ((parseDataP->upcrs.res.error.code != SccNone ) && (parseDataP->upcrs.res.error.code != SccOk)) { - TIMED_RENDER(answer = parseDataP->upcrs.res.oe.toJson()); - ciP->httpStatusCode = parseDataP->upcrs.res.oe.code; + TIMED_RENDER(answer = parseDataP->upcrs.res.error.toJson()); + ciP->httpStatusCode = parseDataP->upcrs.res.error.code; } else { diff --git a/src/lib/serviceRoutinesV2/patchSubscription.cpp b/src/lib/serviceRoutinesV2/patchSubscription.cpp index 529fe2ac77..553513d306 100644 --- a/src/lib/serviceRoutinesV2/patchSubscription.cpp +++ b/src/lib/serviceRoutinesV2/patchSubscription.cpp @@ -32,7 +32,6 @@ #include "ngsi/ParseData.h" #include "rest/OrionError.h" #include "mongoBackend/mongoUpdateSubscription.h" -#include "ngsi10/UpdateContextSubscriptionResponse.h" #include "serviceRoutinesV2/patchSubscription.h" @@ -59,7 +58,7 @@ std::string patchSubscription { std::string subscriptionId = compV[2]; // 'Fill In' SusbcriptionUpdate - parseDataP->subsV2.id = subscriptionId; + parseDataP->sub.id = subscriptionId; OrionError beError; @@ -68,7 +67,7 @@ std::string patchSubscription // jsonParseV2/parseSubscription.cpp, function parseNotifyConditionVector() and // the resulting StringFilter object resides in a Scope in parseDataP->subsV2.restriction.scopeVector // - TIMED_MONGO(mongoUpdateSubscription(parseDataP->subsV2, + TIMED_MONGO(mongoUpdateSubscription(parseDataP->sub, &beError, ciP->tenant, ciP->servicePathV)); @@ -85,7 +84,7 @@ std::string patchSubscription } // free sub memory associated to subscriptions - parseDataP->subsV2.release(); + parseDataP->sub.release(); return answer; } diff --git a/src/lib/serviceRoutinesV2/postBatchQuery.cpp b/src/lib/serviceRoutinesV2/postBatchQuery.cpp index f35efc8964..3f84a3b05d 100644 --- a/src/lib/serviceRoutinesV2/postBatchQuery.cpp +++ b/src/lib/serviceRoutinesV2/postBatchQuery.cpp @@ -32,7 +32,6 @@ #include "ngsi/ParseData.h" #include "rest/OrionError.h" #include "rest/uriParamNames.h" -#include "apiTypesV2/Entities.h" #include "ngsi10/QueryContextRequest.h" #include "alarmMgr/alarmMgr.h" #include "serviceRoutines/postQueryContext.h" @@ -41,6 +40,71 @@ +/* **************************************************************************** +* +* fillEntityVector - +* +* NOTE +* The errorCode field from qcrsP is not used at all if errorCode::code equals SccOk. +* This means that e.g. the "Count:" in errorCode::details (from v1 logic) will not be +* present in the Entities for v2 (that number is in the HTTP header Fiware-Total-Count for v2). +* Other values for "details" are lost as well, if errorCode::code equals SccOk. +* +* FIXME PR: v1 is mentioned above... review this closely +* FIXME PR: copied from getEntities.cpp. Move to common place +*/ +static void fillEntityVector(const QueryContextResponse& qcrs, EntityVector* enVP, OrionError* oeP) +{ + if (qcrs.error.code == SccContextElementNotFound) + { + // + // If no entities are found, we respond with a 200 OK + // and an empty vector of entities ( [] ) + // + + oeP->fill(SccOk, "", "OK"); + return; + } + else if (qcrs.error.code != SccOk) + { + // + // If any other error - use the error for the response + // + + oeP->fill(qcrs.error.code, qcrs.error.description, qcrs.error.error); + return; + } + + for (unsigned int ix = 0; ix < qcrs.contextElementResponseVector.size(); ++ix) + { + Entity* eP = &qcrs.contextElementResponseVector[ix]->entity; + + if ((&qcrs.contextElementResponseVector[ix]->error)->code == SccReceiverInternalError) + { + // FIXME P4: Do we need to release the memory allocated in 'vec' before returning? I don't + // think so, as the releasing logic in the upper layer will deal with that but + // let's do anyway just in case... (we don't have a ft covering this, so valgrind suite + // cannot help here and it is better to ensure) + oeP->fill(&qcrs.contextElementResponseVector[ix]->error); + enVP->release(); + return; + } + else + { + Entity* newP = new Entity(); + + newP->entityId = eP->entityId; + newP->creDate = eP->creDate; + newP->modDate = eP->modDate; + + newP->attributeVector.fill(eP->attributeVector); + enVP->push_back(newP); + } + } +} + + + /* **************************************************************************** * * postBatchQuery - @@ -65,7 +129,7 @@ std::string postBatchQuery { BatchQuery* bqP = &parseDataP->bq.res; QueryContextRequest* qcrP = &parseDataP->qcr.res; - Entities entities; + EntityVector entities; std::string answer; // To be used later in the render stage @@ -89,7 +153,7 @@ std::string postBatchQuery else { OrionError oe; - entities.fill(parseDataP->qcrs.res, &oe); + fillEntityVector(parseDataP->qcrs.res, &entities, &oe); TIMED_RENDER(answer = entities.toJson(getRenderFormat(ciP->uriParamOptions), filterAttrs.stringV, false, qcrP->metadataList.stringV)); diff --git a/src/lib/serviceRoutinesV2/postBatchUpdate.cpp b/src/lib/serviceRoutinesV2/postBatchUpdate.cpp index 91697958e9..22871bfda8 100644 --- a/src/lib/serviceRoutinesV2/postBatchUpdate.cpp +++ b/src/lib/serviceRoutinesV2/postBatchUpdate.cpp @@ -34,7 +34,6 @@ #include "rest/ConnectionInfo.h" #include "ngsi/ParseData.h" #include "rest/OrionError.h" -#include "apiTypesV2/Entities.h" #include "serviceRoutinesV2/postBatchUpdate.h" #include "ngsi10/UpdateContextRequest.h" #include "serviceRoutines/postUpdateContext.h" @@ -67,7 +66,7 @@ std::string postBatchUpdate { BatchUpdate* buP = &parseDataP->bu.res; UpdateContextRequest* upcrP = &parseDataP->upcr.res; - Entities entities; + EntityVector entities; upcrP->fill(&buP->entities, buP->updateActionType); buP->release(); // upcrP just 'took over' the data from buP, buP is no longer needed @@ -78,7 +77,7 @@ std::string postBatchUpdate OrionError oe(SccBadRequest, ERROR_DESC_BAD_REQUEST_EMPTY_ENTITIES_VECTOR); alarmMgr.badInput(clientIp, ERROR_DESC_BAD_REQUEST_EMPTY_ENTITIES_VECTOR); - TIMED_RENDER(answer = oe.smartRender(V2)); + TIMED_RENDER(answer = oe.toJson()); ciP->httpStatusCode = SccBadRequest; return answer; @@ -87,10 +86,10 @@ std::string postBatchUpdate postUpdateContext(ciP, components, compV, parseDataP); // Check potential error - if (parseDataP->upcrs.res.oe.code != SccNone ) + if ((parseDataP->upcrs.res.error.code != SccNone ) && (parseDataP->upcrs.res.error.code != SccOk)) { - TIMED_RENDER(answer = parseDataP->upcrs.res.oe.toJson()); - ciP->httpStatusCode = parseDataP->upcrs.res.oe.code; + TIMED_RENDER(answer = parseDataP->upcrs.res.error.toJson()); + ciP->httpStatusCode = parseDataP->upcrs.res.error.code; } else { diff --git a/src/lib/serviceRoutinesV2/postEntities.cpp b/src/lib/serviceRoutinesV2/postEntities.cpp index 00ce0ad4ed..dd5a6bb715 100644 --- a/src/lib/serviceRoutinesV2/postEntities.cpp +++ b/src/lib/serviceRoutinesV2/postEntities.cpp @@ -29,7 +29,6 @@ #include "common/clockFunctions.h" #include "common/errorMessages.h" -#include "apiTypesV2/Entities.h" #include "ngsi/ParseData.h" #include "rest/ConnectionInfo.h" #include "rest/EntityTypeInfo.h" @@ -51,7 +50,7 @@ static const int STRUCTURAL_OVERHEAD_BSON_ID = 10; static bool legalEntityLength(Entity* eP, const std::string& servicePath) { - return (servicePath.size() + eP->id.size() + eP->type.size() + STRUCTURAL_OVERHEAD_BSON_ID) < 1024; + return (servicePath.size() + eP->entityId.id.size() + eP->entityId.type.size() + STRUCTURAL_OVERHEAD_BSON_ID) < 1024; } @@ -121,28 +120,22 @@ std::string postEntities postUpdateContext(ciP, components, compV, parseDataP, ngsiv2flavour); // - // 03. Check error - 3 different ways to get an error from postUpdateContext ... :-( - // FIXME P4: make postUpdateContext have ONE way to return errors. See github issue #2763 + // 03. Check error // std::string answer = ""; - if (parseDataP->upcrs.res.oe.code != SccNone) + if (parseDataP->upcrs.res.error.code != SccOk) { - TIMED_RENDER(answer = parseDataP->upcrs.res.oe.toJson()); - ciP->httpStatusCode = parseDataP->upcrs.res.oe.code; - } - else if (parseDataP->upcrs.res.errorCode.code != SccOk) - { - ciP->httpStatusCode = parseDataP->upcrs.res.errorCode.code; - TIMED_RENDER(answer = parseDataP->upcrs.res.errorCode.toJson()); + ciP->httpStatusCode = parseDataP->upcrs.res.error.code; + TIMED_RENDER(answer = parseDataP->upcrs.res.error.toJson()); ciP->answer = answer; } else { // Prepare HTTP headers - std::string location = "/v2/entities/" + eP->id; - if (!eP->type.empty()) + std::string location = "/v2/entities/" + eP->entityId.id; + if (!eP->entityId.type.empty()) { - location += "?type=" + eP->type; + location += "?type=" + eP->entityId.type; } else { diff --git a/src/lib/serviceRoutinesV2/postEntity.cpp b/src/lib/serviceRoutinesV2/postEntity.cpp index 1403cd93ea..d89c17fb5d 100644 --- a/src/lib/serviceRoutinesV2/postEntity.cpp +++ b/src/lib/serviceRoutinesV2/postEntity.cpp @@ -32,7 +32,6 @@ #include "common/clockFunctions.h" #include "common/errorMessages.h" -#include "apiTypesV2/Entities.h" #include "ngsi/ParseData.h" #include "rest/ConnectionInfo.h" #include "rest/EntityTypeInfo.h" @@ -65,10 +64,10 @@ std::string postEntity Entity* eP = &parseDataP->ent.res; ActionType op; - eP->id = compV[2]; - eP->type = ciP->uriParam["type"]; + eP->entityId.id = compV[2]; + eP->entityId.type = ciP->uriParam["type"]; - if (forbiddenIdChars(ciP->apiVersion, compV[2].c_str() , NULL)) + if (forbiddenIdCharsV2(compV[2].c_str() , NULL)) { OrionError oe(SccBadRequest, ERROR_DESC_BAD_REQUEST_INVALID_CHAR_URI, ERROR_BAD_REQUEST); ciP->httpStatusCode = oe.code; @@ -93,10 +92,10 @@ std::string postEntity // Any error in the response? std::string answer = ""; - if (parseDataP->upcrs.res.oe.code != SccNone) + if ((parseDataP->upcrs.res.error.code != SccNone ) && (parseDataP->upcrs.res.error.code != SccOk)) { - TIMED_RENDER(answer = parseDataP->upcrs.res.oe.toJson()); - ciP->httpStatusCode = parseDataP->upcrs.res.oe.code; + TIMED_RENDER(answer = parseDataP->upcrs.res.error.toJson()); + ciP->httpStatusCode = parseDataP->upcrs.res.error.code; } else { diff --git a/src/lib/serviceRoutinesV2/postRegistration.cpp b/src/lib/serviceRoutinesV2/postRegistration.cpp index 6ecbffe486..d14f86a90c 100644 --- a/src/lib/serviceRoutinesV2/postRegistration.cpp +++ b/src/lib/serviceRoutinesV2/postRegistration.cpp @@ -70,7 +70,7 @@ std::string postRegistration if (oe.code != SccOk) { - TIMED_RENDER(answer = oe.smartRender(ciP->apiVersion)); + TIMED_RENDER(answer = oe.toJson()); } else { diff --git a/src/lib/serviceRoutinesV2/postSubscriptions.cpp b/src/lib/serviceRoutinesV2/postSubscriptions.cpp index f4a8399bcf..26b7c8f8c2 100644 --- a/src/lib/serviceRoutinesV2/postSubscriptions.cpp +++ b/src/lib/serviceRoutinesV2/postSubscriptions.cpp @@ -28,7 +28,6 @@ #include "alarmMgr/alarmMgr.h" #include "mongoBackend/mongoCreateSubscription.h" #include "ngsi/ParseData.h" -#include "ngsi10/SubscribeContextResponse.h" #include "common/statistics.h" #include "rest/HttpHeaders.h" #include "rest/uriParamNames.h" @@ -53,7 +52,6 @@ extern std::string postSubscriptions ParseData* parseDataP ) { - SubscribeContextResponse scr; std::string answer = ""; if (ciP->servicePathV.size() > 1) @@ -64,10 +62,11 @@ extern std::string postSubscriptions snprintf(errMsg, MSG_SIZE, "max *one* service-path allowed for subscriptions (%lu given)", (unsigned long) ciP->servicePathV.size()); + + OrionError oe(SccBadRequest, "max one service-path allowed for subscriptions"); alarmMgr.badInput(clientIp, errMsg); - scr.subscribeError.errorCode.fill(SccBadRequest, "max one service-path allowed for subscriptions"); - TIMED_RENDER(answer = scr.toJson()); + TIMED_RENDER(answer = oe.toJson()); } else // ciP->servicePathV.size() == 1 { @@ -75,7 +74,7 @@ extern std::string postSubscriptions std::string subsID; TIMED_MONGO(subsID = mongoCreateSubscription( - parseDataP->subsV2, + parseDataP->sub, &beError, ciP->tenant, ciP->servicePathV)); @@ -97,7 +96,7 @@ extern std::string postSubscriptions } // free sub memory associated to subscriptions - parseDataP->subsV2.release(); + parseDataP->sub.release(); return answer; } diff --git a/src/lib/serviceRoutinesV2/putEntity.cpp b/src/lib/serviceRoutinesV2/putEntity.cpp index 0a6f88580d..b614f090b7 100644 --- a/src/lib/serviceRoutinesV2/putEntity.cpp +++ b/src/lib/serviceRoutinesV2/putEntity.cpp @@ -31,7 +31,6 @@ #include "rest/ConnectionInfo.h" #include "ngsi/ParseData.h" -#include "apiTypesV2/Entities.h" #include "rest/EntityTypeInfo.h" #include "serviceRoutinesV2/putEntity.h" #include "serviceRoutinesV2/serviceRoutinesCommon.h" @@ -68,10 +67,10 @@ std::string putEntity { Entity* eP = &parseDataP->ent.res; - eP->id = compV[2]; - eP->type = ciP->uriParam["type"]; + eP->entityId.id = compV[2]; + eP->entityId.type = ciP->uriParam["type"]; - if (forbiddenIdChars(ciP->apiVersion, compV[2].c_str() , NULL)) + if (forbiddenIdCharsV2(compV[2].c_str() , NULL)) { OrionError oe(SccBadRequest, ERROR_DESC_BAD_REQUEST_INVALID_CHAR_URI, ERROR_BAD_REQUEST); ciP->httpStatusCode = oe.code; @@ -86,14 +85,14 @@ std::string putEntity postUpdateContext(ciP, components, compV, parseDataP); // Adjust error code if needed - adaptErrorCodeForSingleEntityOperation(&(parseDataP->upcrs.res.oe), false); + adaptErrorCodeForSingleEntityOperation(&(parseDataP->upcrs.res.error), false); // 03. Check error std::string answer = ""; - if (parseDataP->upcrs.res.oe.code != SccNone ) + if ((parseDataP->upcrs.res.error.code != SccNone ) && (parseDataP->upcrs.res.error.code != SccOk)) { - TIMED_RENDER(answer = parseDataP->upcrs.res.oe.toJson()); - ciP->httpStatusCode = parseDataP->upcrs.res.oe.code; + TIMED_RENDER(answer = parseDataP->upcrs.res.error.toJson()); + ciP->httpStatusCode = parseDataP->upcrs.res.error.code; } else { diff --git a/src/lib/serviceRoutinesV2/putEntityAttribute.cpp b/src/lib/serviceRoutinesV2/putEntityAttribute.cpp index e49c262f95..ae831c53cb 100644 --- a/src/lib/serviceRoutinesV2/putEntityAttribute.cpp +++ b/src/lib/serviceRoutinesV2/putEntityAttribute.cpp @@ -52,7 +52,7 @@ * * * 01. Fill in UpdateContextRequest -* 02. Call standard op postQueryContext +* 02. Call standard op postUpdateContext * 03. Check output from mongoBackend - any errors? * 04. Prepare HTTP headers * 05. Cleanup and return result @@ -69,8 +69,8 @@ std::string putEntityAttribute std::string attributeName = compV[4]; std::string type = ciP->uriParam["type"]; - if (forbiddenIdChars(ciP->apiVersion, entityId.c_str(), NULL) || - (forbiddenIdChars(ciP->apiVersion, attributeName.c_str(), NULL))) + if (forbiddenIdCharsV2( entityId.c_str(), NULL) || + (forbiddenIdCharsV2(attributeName.c_str(), NULL))) { OrionError oe(SccBadRequest, ERROR_DESC_BAD_REQUEST_INVALID_CHAR_URI, ERROR_BAD_REQUEST); ciP->httpStatusCode = oe.code; @@ -86,15 +86,15 @@ std::string putEntityAttribute postUpdateContext(ciP, components, compV, parseDataP); // Adjust error code if needed - adaptErrorCodeForSingleEntityOperation(&(parseDataP->upcrs.res.oe), true); + adaptErrorCodeForSingleEntityOperation(&(parseDataP->upcrs.res.error), true); // 03. Check error std::string answer = ""; - if (parseDataP->upcrs.res.oe.code != SccNone ) + if ((parseDataP->upcrs.res.error.code != SccNone ) && (parseDataP->upcrs.res.error.code != SccOk)) { - TIMED_RENDER(answer = parseDataP->upcrs.res.oe.toJson()); - alarmMgr.badInput(clientIp, parseDataP->upcrs.res.oe.description); - ciP->httpStatusCode = parseDataP->upcrs.res.oe.code; + TIMED_RENDER(answer = parseDataP->upcrs.res.error.toJson()); + alarmMgr.badInput(clientIp, parseDataP->upcrs.res.error.description); + ciP->httpStatusCode = parseDataP->upcrs.res.error.code; } else { diff --git a/src/lib/serviceRoutinesV2/putEntityAttributeValue.cpp b/src/lib/serviceRoutinesV2/putEntityAttributeValue.cpp index 0f41e87f36..95c85fc2a2 100644 --- a/src/lib/serviceRoutinesV2/putEntityAttributeValue.cpp +++ b/src/lib/serviceRoutinesV2/putEntityAttributeValue.cpp @@ -66,8 +66,8 @@ std::string putEntityAttributeValue std::string attributeName = compV[4]; std::string type = ciP->uriParam["type"]; - if (forbiddenIdChars(ciP->apiVersion, entityId.c_str(), NULL) || - forbiddenIdChars(ciP->apiVersion, attributeName.c_str(), NULL)) + if (forbiddenIdCharsV2(entityId.c_str(), NULL) || + forbiddenIdCharsV2(attributeName.c_str(), NULL)) { OrionError oe(SccBadRequest, ERROR_DESC_BAD_REQUEST_INVALID_CHAR_URI, ERROR_BAD_REQUEST); ciP->httpStatusCode = oe.code; @@ -79,7 +79,7 @@ std::string putEntityAttributeValue parseDataP->av.attribute.type = ""; // Overwrite 'none', as no type can be given in 'value' payload parseDataP->av.attribute.onlyValue = true; - std::string err = parseDataP->av.attribute.check(ciP->apiVersion, ciP->requestType); + std::string err = parseDataP->av.attribute.check(ciP->requestType); if (err != "OK") { OrionError oe(SccBadRequest, err, ERROR_BAD_REQUEST); @@ -93,14 +93,14 @@ std::string putEntityAttributeValue postUpdateContext(ciP, components, compV, parseDataP); // Adjust error code if needed - adaptErrorCodeForSingleEntityOperation(&(parseDataP->upcrs.res.oe), true); + adaptErrorCodeForSingleEntityOperation(&(parseDataP->upcrs.res.error), true); // 03. Check output from mongoBackend std::string answer = ""; - if (parseDataP->upcrs.res.oe.code != SccNone) + if ((parseDataP->upcrs.res.error.code != SccNone ) && (parseDataP->upcrs.res.error.code != SccOk)) { - TIMED_RENDER(answer = parseDataP->upcrs.res.oe.toJson()); - ciP->httpStatusCode = parseDataP->upcrs.res.oe.code; + TIMED_RENDER(answer = parseDataP->upcrs.res.error.toJson()); + ciP->httpStatusCode = parseDataP->upcrs.res.error.code; } else { diff --git a/src/lib/serviceRoutinesV2/semStateTreat.cpp b/src/lib/serviceRoutinesV2/semStateTreat.cpp index 45c8387f6f..1219bf3e7e 100644 --- a/src/lib/serviceRoutinesV2/semStateTreat.cpp +++ b/src/lib/serviceRoutinesV2/semStateTreat.cpp @@ -30,7 +30,6 @@ #include "common/statistics.h" #include "common/clockFunctions.h" -#include "common/tag.h" #include "common/JsonHelper.h" #include "ngsi/ParseData.h" diff --git a/test/functionalTest/cases/0000_cli/bool_option_with_value.test b/test/functionalTest/cases/0000_cli/bool_option_with_value.test index 111fb8dde8..e3992f036e 100644 --- a/test/functionalTest/cases/0000_cli/bool_option_with_value.test +++ b/test/functionalTest/cases/0000_cli/bool_option_with_value.test @@ -84,16 +84,13 @@ Usage: contextBroker [option '-U' (extended usage)] [option '-statNotifQueue' (enable thread pool notifications queue statistics)] [option '-logSummary' ] [option '-relogAlarms' (log messages for existing alarms beyond the raising alarm log message itself)] - [option '-strictNgsiv1Ids' (additional checks for id fields in the NGSIv1 API)] [option '-disableCustomNotifications' (disable NGSIv2 custom notifications)] [option '-disableFileLog' (disable logging into file)] [option '-logForHumans' (human readible log to screen)] [option '-logLineMaxSize' ] [option '-logInfoPayloadMaxSize' ] [option '-disableMetrics' (turn off the 'metrics' feature)] - [option '-disableNgsiv1' (turn off NGSIv1 request endpoints)] [option '-insecureNotif' (allow HTTPS notifications to peers which certificate cannot be authenticated with known CA certificates)] - [option '-ngsiv1Autocast' (automatic cast for number, booleans and dates in NGSIv1 update/create attribute operations)] [option '-mqttMaxAge' ] [option '-logDeprecate' (log deprecation usages as warnings)] diff --git a/test/functionalTest/cases/0000_cli/command_line_options.test b/test/functionalTest/cases/0000_cli/command_line_options.test index f97b786889..2c69f23c96 100644 --- a/test/functionalTest/cases/0000_cli/command_line_options.test +++ b/test/functionalTest/cases/0000_cli/command_line_options.test @@ -73,16 +73,13 @@ Usage: contextBroker [option '-U' (extended usage)] [option '-statNotifQueue' (enable thread pool notifications queue statistics)] [option '-logSummary' ] [option '-relogAlarms' (log messages for existing alarms beyond the raising alarm log message itself)] - [option '-strictNgsiv1Ids' (additional checks for id fields in the NGSIv1 API)] [option '-disableCustomNotifications' (disable NGSIv2 custom notifications)] [option '-disableFileLog' (disable logging into file)] [option '-logForHumans' (human readible log to screen)] [option '-logLineMaxSize' ] [option '-logInfoPayloadMaxSize' ] [option '-disableMetrics' (turn off the 'metrics' feature)] - [option '-disableNgsiv1' (turn off NGSIv1 request endpoints)] [option '-insecureNotif' (allow HTTPS notifications to peers which certificate cannot be authenticated with known CA certificates)] - [option '-ngsiv1Autocast' (automatic cast for number, booleans and dates in NGSIv1 update/create attribute operations)] [option '-mqttMaxAge' ] [option '-logDeprecate' (log deprecation usages as warnings)] diff --git a/test/functionalTest/cases/0000_cli/tracelevel_without_logLevel_as_DEBUG.test b/test/functionalTest/cases/0000_cli/tracelevel_without_logLevel_as_DEBUG.test index 8c92e4fffc..095efa1c8c 100644 --- a/test/functionalTest/cases/0000_cli/tracelevel_without_logLevel_as_DEBUG.test +++ b/test/functionalTest/cases/0000_cli/tracelevel_without_logLevel_as_DEBUG.test @@ -74,16 +74,13 @@ Usage: contextBroker [option '-U' (extended usage)] [option '-statNotifQueue' (enable thread pool notifications queue statistics)] [option '-logSummary' ] [option '-relogAlarms' (log messages for existing alarms beyond the raising alarm log message itself)] - [option '-strictNgsiv1Ids' (additional checks for id fields in the NGSIv1 API)] [option '-disableCustomNotifications' (disable NGSIv2 custom notifications)] [option '-disableFileLog' (disable logging into file)] [option '-logForHumans' (human readible log to screen)] [option '-logLineMaxSize' ] [option '-logInfoPayloadMaxSize' ] [option '-disableMetrics' (turn off the 'metrics' feature)] - [option '-disableNgsiv1' (turn off NGSIv1 request endpoints)] [option '-insecureNotif' (allow HTTPS notifications to peers which certificate cannot be authenticated with known CA certificates)] - [option '-ngsiv1Autocast' (automatic cast for number, booleans and dates in NGSIv1 update/create attribute operations)] [option '-mqttMaxAge' ] [option '-logDeprecate' (log deprecation usages as warnings)] diff --git a/test/functionalTest/cases/0000_deprecated_checkings/disable_ngsi_cli.test.DISABLED b/test/functionalTest/cases/0000_deprecated_checkings/disable_ngsi_cli.test.DISABLED deleted file mode 100644 index 2f3121a671..0000000000 --- a/test/functionalTest/cases/0000_deprecated_checkings/disable_ngsi_cli.test.DISABLED +++ /dev/null @@ -1,71 +0,0 @@ -# Copyright 2023 Telefonica Investigacion y Desarrollo, S.A.U -# -# This file is part of Orion Context Broker. -# -# Orion Context Broker is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Orion Context Broker is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -# General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -# -# For those usages not covered by this license please contact with -# iot_support at tid dot es - -# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh - ---NAME-- -Disable NGSIv1 CLI - ---SHELL-INIT-- -dbInit CB -brokerStart CB 0 IPV4 -disableNgsiv1 - ---SHELL-- - -# -# 01. Query E1-T1, get 400 service not found error -# - -echo "01. Query E1-T1, get 400 service not found error" -echo "================================================" -payload='{ - "entities": [ - { - "type": "T1", - "id": "E1" - } - ] -}' -orionCurl --url /v1/queryContext --payload "${payload}" -echo -echo - - ---REGEXPECT-- -01. Query E1-T1, get 400 service not found error -================================================ -HTTP/1.1 400 Bad Request -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 129 - -{ - "orionError": { - "code": "400", - "details": "Service not found. Check your URL as probably it is wrong.", - "reasonPhrase": "Bad Request" - } -} - - ---TEARDOWN-- -brokerStop CB -dbDrop CB diff --git a/test/functionalTest/cases/0000_deprecated_checkings/log_deprecate_warning.test b/test/functionalTest/cases/0000_deprecated_checkings/log_deprecate_warning.test index 4fc18294fd..47cc330133 100644 --- a/test/functionalTest/cases/0000_deprecated_checkings/log_deprecate_warning.test +++ b/test/functionalTest/cases/0000_deprecated_checkings/log_deprecate_warning.test @@ -213,9 +213,9 @@ Content-Length: 95 Deprecated usage of geo:point detected in attribute location at entity update, please use geo:json instead Deprecated usage of legacyForwarding mode in registration creation (regId: REG_ID) Deprecated usage of legacyForwarding mode detected in existing registration (regId: REG_ID) -Deprecated usage of legacyForwarding mode in query forwarding operation (regId: REG_ID) +Deprecated usage of legacyForwarding mode detected in existing registration (regId: REG_ID) Raising alarm ForwardingError localhost:9801/v2/queryContext: forwarding failure for sender-thread: Couldn't connect to server -Deprecated usage of legacyForwarding mode in update forwarding operation (regId: REG_ID) +Deprecated usage of legacyForwarding mode detected in existing registration (regId: REG_ID) Raising alarm ForwardingError localhost:9801/v2/updateContext: forwarding failure for sender-thread: Couldn't connect to server Raising alarm BadInput 127.0.0.1: The requested entity has not been found. Check type and id diff --git a/test/functionalTest/cases/0000_deprecated_checkings/xml_support.test b/test/functionalTest/cases/0000_deprecated_checkings/xml_support.test index 4e4a51d2de..4fb4a71707 100644 --- a/test/functionalTest/cases/0000_deprecated_checkings/xml_support.test +++ b/test/functionalTest/cases/0000_deprecated_checkings/xml_support.test @@ -67,14 +67,11 @@ HTTP/1.1 415 Unsupported Media Type Date: REGEX(.*) Fiware-Correlator: REGEX([0-9a-f\-]{36}) Content-Type: application/json -Content-Length: 125 +Content-Length: 92 { - "orionError": { - "code": "415", - "details": "not supported content type: application/xml", - "reasonPhrase": "Unsupported Media Type" - } + "description": "not supported content type: application/xml", + "error": "UnsupportedMediaType" } @@ -84,14 +81,11 @@ HTTP/1.1 406 Not Acceptable Date: REGEX(.*) Fiware-Correlator: REGEX([0-9a-f\-]{36}) Content-Type: application/json -Content-Length: 114 +Content-Length: 82 { - "orionError": { - "code": "406", - "details": "no acceptable mime-type in accept header", - "reasonPhrase": "Not Acceptable" - } + "description": "no acceptable mime-type in accept header", + "error": "NotAcceptable" } diff --git a/test/functionalTest/cases/0000_log_operation/log_rest.test b/test/functionalTest/cases/0000_log_operation/log_rest.test index 36c5538988..cb13313d57 100644 --- a/test/functionalTest/cases/0000_log_operation/log_rest.test +++ b/test/functionalTest/cases/0000_log_operation/log_rest.test @@ -132,8 +132,13 @@ HTTP/1.1 405 Method Not Allowed Date: REGEX(.*) Fiware-Correlator: REGEX([0-9a-f\-]{36}) Allow: PUT, DELETE -Content-Length: 0 +Content-Type: application/json +Content-Length: 63 +{ + "description": "method not allowed", + "error": "MethodNotAllowed" +} === 5. PUT trace level diff --git a/test/functionalTest/cases/0000_statistics_operation/statistics_with_full_counters.test b/test/functionalTest/cases/0000_statistics_operation/statistics_with_full_counters.test index dfc021a52d..8e9b9b8b75 100644 --- a/test/functionalTest/cases/0000_statistics_operation/statistics_with_full_counters.test +++ b/test/functionalTest/cases/0000_statistics_operation/statistics_with_full_counters.test @@ -46,14 +46,13 @@ HTTP/1.1 200 OK Date: REGEX(.*) Fiware-Correlator: REGEX([0-9a-f\-]{36}) Content-Type: application/json -Content-Length: 1602 +Content-Length: 1331 { "counters": { "deprecatedFeatures": { "geoFormat": 0, - "ngsiv1Forwarding": 0, - "ngsiv1Requests": 0 + "ngsiv1Forwarding": 0 }, "discoveryErrors": 0, "invalidRequests": 0, @@ -166,27 +165,6 @@ Content-Length: 1602 "GET": 0 } }, - "requestsLegacy": { - "/ngsi10/queryContext": { - "POST": 0 - }, - "/ngsi10/updateContext": { - "POST": 0 - }, - "/v1/contextEntities/{id}": { - "DELETE": 0, - "PUT": 0 - }, - "/v1/contextEntities/{id}/attributes/{name}": { - "GET": 0 - }, - "/v1/queryContext": { - "POST": 0 - }, - "/v1/updateContext": { - "POST": 0 - } - }, "textRequests": 0 }, "measuring_interval_in_secs": REGEX(\d+), diff --git a/test/functionalTest/cases/0117_convop_using_standard_ops/deleteAllEntitiesWithTypeAndId.test.DISABLED b/test/functionalTest/cases/0117_convop_using_standard_ops/deleteAllEntitiesWithTypeAndId.test.DISABLED deleted file mode 100644 index d6346b0fb3..0000000000 --- a/test/functionalTest/cases/0117_convop_using_standard_ops/deleteAllEntitiesWithTypeAndId.test.DISABLED +++ /dev/null @@ -1,385 +0,0 @@ -# Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U -# -# This file is part of Orion Context Broker. -# -# Orion Context Broker is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Orion Context Broker is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -# General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -# -# For those usages not covered by this license please contact with -# iot_support at tid dot es - -# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh - ---NAME-- -ConvOp deleteAllEntitiesWithTypeAndId: DELETE /v1/contextEntities/type/{entity::type}/id/{entity::id} - ---SHELL-INIT-- -dbInit CB -brokerStart CB - ---SHELL-- - -# -# 01. POST /v1/contextEntities/E1?entity::type=T1 -# 02. POST /v1/contextEntities/E2?entity::type=T2 -# 03. GET /v1/contextEntities - see 2 entities -# 04. DELETE /v1/contextEntities/type/T1/id/E4, and see it fail -# 05. DELETE /v1/contextEntities/type/T1/id/E1?entity::type=T2, and see it fail -# 06. DELETE /v1/contextEntities/type/T1/id/E1?!exist=entity::type, and see it fail -# 07. GET /v1/contextEntities - see 2 entities -# 08. DELETE /v1/contextEntities/T1/id/E1?exist=entity::type -# 09. DELETE /v1/contextEntities/T1/id/E2?entity::type=T1 -# 10. GET /v1/contextEntities - see 0 entities -# - -echo "01. POST /v1/contextEntities/E1?entity::type=T1" -echo "===============================================" -payload='{ - "attributes": [ - { - "name": "A1", - "type": "AT", - "value": "10" - } - ] -}' -orionCurl --url /v1/contextEntities/E1?entity::type=T1 --payload "${payload}" -echo -echo - - -echo "02. POST /v1/contextEntities/E2?entity::type=T2" -echo "===============================================" -payload='{ - "attributes": [ - { - "name": "A2", - "type": "AT", - "value": "20" - } - ] -}' -orionCurl --url /v1/contextEntities/E2?entity::type=T2 --payload "${payload}" -echo -echo - - -echo "03. GET /v1/contextEntities - see 2 entities" -echo "============================================" -orionCurl --url /v1/contextEntities -echo -echo - - -echo "04. DELETE /v1/contextEntities/type/T1/id/E4, and see it fail" -echo "=============================================================" -orionCurl --url /v1/contextEntities/type/T1/id/E4 -X DELETE -echo -echo - - -echo "05. DELETE /v1/contextEntities/type/T1/id/E1?entity::type=T2, and see it fail" -echo "=============================================================================" -orionCurl --url /v1/contextEntities/type/T1/id/E1?entity::type=T2 -X DELETE -echo -echo - - -echo "06. DELETE /v1/contextEntities/type/T1/id/E1?!exist=entity::type, and see it fail" -echo "=================================================================================" -orionCurl --url /v1/contextEntities/type/T1/id/E1?!exist=entity::type -X DELETE -echo -echo - - -echo "07. GET /v1/contextEntities - see 2 entities" -echo "============================================" -orionCurl --url /v1/contextEntities -echo -echo - - -echo "08. DELETE /v1/contextEntities/T1/id/E1?exist=entity::type" -echo "==========================================================" -orionCurl --url /v1/contextEntities/type/T1/id/E1?exist=entity::type -X DELETE -echo -echo - - -echo "09. DELETE /v1/contextEntities/T2/id/E2?entity::type=T2" -echo "=======================================================" -orionCurl --url /v1/contextEntities/type/T2/id/E2?entity::type=T2 -X DELETE -echo -echo - - -echo "10. GET /v1/contextEntities - see 0 entities" -echo "============================================" -orionCurl --url /v1/contextEntities -echo -echo - - ---REGEXPECT-- -01. POST /v1/contextEntities/E1?entity::type=T1 -=============================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 166 - -{ - "contextResponses": [ - { - "attributes": [ - { - "name": "A1", - "type": "AT", - "value": "" - } - ], - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" -} - - -02. POST /v1/contextEntities/E2?entity::type=T2 -=============================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 166 - -{ - "contextResponses": [ - { - "attributes": [ - { - "name": "A2", - "type": "AT", - "value": "" - } - ], - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ], - "id": "E2", - "isPattern": "false", - "type": "T2" -} - - -03. GET /v1/contextEntities - see 2 entities -============================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 352 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "AT", - "value": "10" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - }, - { - "contextElement": { - "attributes": [ - { - "name": "A2", - "type": "AT", - "value": "20" - } - ], - "id": "E2", - "isPattern": "false", - "type": "T2" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -04. DELETE /v1/contextEntities/type/T1/id/E4, and see it fail -============================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 71 - -{ - "code": "404", - "details": "E4", - "reasonPhrase": "No context element found" -} - - -05. DELETE /v1/contextEntities/type/T1/id/E1?entity::type=T2, and see it fail -============================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 89 - -{ - "code": "400", - "details": "non-matching entity::types in URL", - "reasonPhrase": "Bad Request" -} - - -06. DELETE /v1/contextEntities/type/T1/id/E1?!exist=entity::type, and see it fail -================================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 101 - -{ - "code": "400", - "details": "entity::type cannot be empty for this request", - "reasonPhrase": "Bad Request" -} - - -07. GET /v1/contextEntities - see 2 entities -============================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 352 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "AT", - "value": "10" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - }, - { - "contextElement": { - "attributes": [ - { - "name": "A2", - "type": "AT", - "value": "20" - } - ], - "id": "E2", - "isPattern": "false", - "type": "T2" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -08. DELETE /v1/contextEntities/T1/id/E1?exist=entity::type -========================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 34 - -{ - "code": "200", - "reasonPhrase": "OK" -} - - -09. DELETE /v1/contextEntities/T2/id/E2?entity::type=T2 -======================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 34 - -{ - "code": "200", - "reasonPhrase": "OK" -} - - -10. GET /v1/contextEntities - see 0 entities -============================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 70 - -{ - "errorCode": { - "code": "404", - "reasonPhrase": "No context element found" - } -} - - ---TEARDOWN-- -brokerStop CB -dbDrop CB diff --git a/test/functionalTest/cases/0117_convop_using_standard_ops/deleteIndividualContextEntityAttribute.test.DISABLED b/test/functionalTest/cases/0117_convop_using_standard_ops/deleteIndividualContextEntityAttribute.test.DISABLED deleted file mode 100644 index 8229df8d5d..0000000000 --- a/test/functionalTest/cases/0117_convop_using_standard_ops/deleteIndividualContextEntityAttribute.test.DISABLED +++ /dev/null @@ -1,412 +0,0 @@ -# Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U -# -# This file is part of Orion Context Broker. -# -# Orion Context Broker is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Orion Context Broker is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -# General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -# -# For those usages not covered by this license please contact with -# iot_support at tid dot es - -# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh - ---NAME-- -ConvOp deleteIndividualContextEntityAttribute: DELETE /v1/contextEntities/{entityId::id}/attributes/{attribute::name} - ---SHELL-INIT-- -dbInit CB -brokerStart CB - ---SHELL-- - -# -# 00. Try to delete an attribute with TWO service-paths -# 01. Create an entity E1/T1 with attributes A1, A2 and A3 -# 02. Query for E1/T1 and all its attributes (see all three of them) -# 03. Remove E1/A2, using URI param entity::type=T1 -# 04. Query for E1/T1 and all its attributes (A2 should not be there) -# 05. Try to remove E1/T2/A2 and see it fail -# 06. Try to remove E1/T1/A2 again and see it fail -# 07. Try to remove E1/T1/A1, with service-path /bad and see it fail -# 08. Remove E1/A1, with service-path / and see it work -# 09. Query for E1 and all its attributes (only A3 left) -# - -echo "00. Try to delete an attribute with TWO service-paths" -echo "=====================================================" -orionCurl --url /v1/contextEntities/E1/attributes/A2?entity::type=T1 -X DELETE --servicePath /a,/b -echo -echo - - -echo "01. Create an entity E1/T1 with attributes A1, A2 and A3" -echo "========================================================" -payload='{ - "contextElements": [ - { - "type" : "T1", - "isPattern" : "false", - "id" : "E1", - "attributes" : [ - { - "name" : "A1", - "type" : "a", - "value" : "1" - }, - { - "name" : "A2", - "type" : "a", - "value" : "2" - }, - { - "name" : "A3", - "type" : "a", - "value" : "3" - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" -echo -echo - - -echo "02. Query for E1/T1 and all its attributes (see all three of them)" -echo "==================================================================" -payload='{ - "entities": [ - { - "type": "T1", - "id": "E1" - } - ] -}' -orionCurl --url /v1/queryContext --payload "${payload}" -echo -echo - - -echo "03. Remove E1/A2, using URI param entity::type=T1" -echo "=================================================" -orionCurl --url /v1/contextEntities/E1/attributes/A2?entity::type=T1 -X DELETE -echo -echo - - -echo "04. Query for E1/T1 and all its attributes (A2 should not be there)" -echo "===================================================================" -payload='{ - "entities": [ - { - "type": "T1", - "id": "E1" - } - ] -}' -orionCurl --url /v1/queryContext --payload "${payload}" -echo -echo - - -echo "05. Try to remove E1/T2/A2 and see it fail" -echo "==========================================" -orionCurl --url /v1/contextEntities/E1/attributes/A2?entity::type=T2 -X DELETE -echo -echo - - -echo "06. Try to remove E1/T1/A2 again and see it fail" -echo "================================================" -orionCurl --url /v1/contextEntities/E1/attributes/A2?entity::type=T1 -X DELETE -echo -echo - - -echo "07. Try to remove E1/T1/A1, with service-path /bad and see it fail" -echo "==================================================================" -orionCurl --url /v1/contextEntities/E1/attributes/A1?entity::type=T1 -X DELETE --servicePath /bad -echo -echo - - -echo "08. Remove E1/A1, with service-path / and see it work" -echo "=====================================================" -orionCurl --url /v1/contextEntities/E1/attributes/A1?entity::type=T1 -X DELETE --servicePath / -echo -echo - - -echo "09. Query for E1 and all its attributes (only A3 left)" -echo "======================================================" -payload='{ - "entities": [ - { - "type": "T1", - "id": "E1" - } - ] -}' -orionCurl --url /v1/queryContext --payload "${payload}" -echo -echo - - ---REGEXPECT-- -00. Try to delete an attribute with TWO service-paths -===================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 131 - -{ - "orionError": { - "code": "400", - "details": "more than one servicepath is not allowed in DELETE operation", - "reasonPhrase": "Bad Request" - } -} - - -01. Create an entity E1/T1 with attributes A1, A2 and A3 -======================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 256 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "a", - "value": "" - }, - { - "name": "A2", - "type": "a", - "value": "" - }, - { - "name": "A3", - "type": "a", - "value": "" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -02. Query for E1/T1 and all its attributes (see all three of them) -================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 259 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "a", - "value": "1" - }, - { - "name": "A2", - "type": "a", - "value": "2" - }, - { - "name": "A3", - "type": "a", - "value": "3" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -03. Remove E1/A2, using URI param entity::type=T1 -================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 34 - -{ - "code": "200", - "reasonPhrase": "OK" -} - - -04. Query for E1/T1 and all its attributes (A2 should not be there) -=================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 222 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "a", - "value": "1" - }, - { - "name": "A3", - "type": "a", - "value": "3" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -05. Try to remove E1/T2/A2 and see it fail -========================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 71 - -{ - "code": "404", - "details": "E1", - "reasonPhrase": "No context element found" -} - - -06. Try to remove E1/T1/A2 again and see it fail -================================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 166 - -{ - "code": "472", - "details": "action: DELETE - entity: [E1, T1] - offending attribute: A2 - attribute not found", - "reasonPhrase": "request parameter is invalid/not allowed" -} - - -07. Try to remove E1/T1/A1, with service-path /bad and see it fail -================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 71 - -{ - "code": "404", - "details": "E1", - "reasonPhrase": "No context element found" -} - - -08. Remove E1/A1, with service-path / and see it work -===================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 34 - -{ - "code": "200", - "reasonPhrase": "OK" -} - - -09. Query for E1 and all its attributes (only A3 left) -====================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 185 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A3", - "type": "a", - "value": "3" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - ---TEARDOWN-- -brokerStop CB -dbDrop CB diff --git a/test/functionalTest/cases/0117_convop_using_standard_ops/deleteIndividualContextEntityAttributeWithTypeAndId.test.DISABLED b/test/functionalTest/cases/0117_convop_using_standard_ops/deleteIndividualContextEntityAttributeWithTypeAndId.test.DISABLED deleted file mode 100644 index 6ac194536a..0000000000 --- a/test/functionalTest/cases/0117_convop_using_standard_ops/deleteIndividualContextEntityAttributeWithTypeAndId.test.DISABLED +++ /dev/null @@ -1,676 +0,0 @@ -# Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U -# -# This file is part of Orion Context Broker. -# -# Orion Context Broker is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Orion Context Broker is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -# General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -# -# For those usages not covered by this license please contact with -# iot_support at tid dot es - -# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh - ---NAME-- -ConvOp deleteIndividualContextEntityAttributeWithTypeAndId: DELETE /v1/contextEntities/type/{entity::type}/id/{entity::id}/attributes/{attribute::name} - ---SHELL-INIT-- -dbInit CB -brokerStart CB 0 - ---SHELL-- - -# -# 01. DELETE /v1/contextEntities/type/T1/id/E1/attributes/A1, and see it fail -# 02. POST /v1/contextEntities/type/T1/id/E1/attributes/A1 -# 03. POST /v1/contextEntities/type/T1/id/E1/attributes/A2 -# 04. GET /v1/contextEntities - see 2 attributes -# 05. DELETE /v1/contextEntities/type/T1/id/E2/attributes/A1, and see it fail -# 06. DELETE /v1/contextEntities/type/T1/id/E1/attributes/A3, and see it fail -# 07. DELETE /v1/contextEntities/type/T1/id/E1/attributes/A1?entity::type=T2, and see it fail -# 08. DELETE /v1/contextEntities/type/T1/id/E1/attributes/A1?!exist=entity::type, and see it fail -# 09. GET /v1/contextEntities - see 2 attributes -# 10. DELETE /v1/contextEntities/type/T1/id/E1/attributes/A1?entity::type=T1 -# 11. GET /v1/contextEntities - see 1 attribute (A2) -# 12. DELETE /v1/contextEntities/type/T1/id/E1/attributes/A2 -# 13. GET /v1/contextEntities - see 0 attributes -# 14. POST /v1/contextEntities/type/T1/id/E1/attributes/A3, service-path /s1 -# 15. POST /v1/contextEntities/type/T1/id/E1/attributes/A3, service-path /s2 -# 16. GET /v1/contextEntities - see 2 attributes -# 17. DELETE /v1/contextEntities/type/T1/id/E1/attributes/A3, service-path /s3, and see it fail -# 18. DELETE /v1/contextEntities/type/T1/id/E1/attributes/A3, service-path /s1 -# 19. DELETE /v1/contextEntities/type/T1/id/E1/attributes/A3, service-path /s1, and see it fail -# 20. DELETE /v1/contextEntities/type/T1/id/E1/attributes/A3, service-path /s2 -# 21. GET /v1/contextEntities - see 0 attributes -# - -echo "01. DELETE /v1/contextEntities/type/T1/id/E1/attributes/A1, and see it fail" -echo "===========================================================================" -orionCurl --url /v1/contextEntities/type/T1/id/E1/attributes/A1 -X DELETE -echo -echo - - -echo "02. POST /v1/contextEntities/type/T1/id/E1/attributes/A1" -echo "========================================================" -payload='{ - "value": 2 -}' -orionCurl --url /v1/contextEntities/type/T1/id/E1/attributes/A1 --payload "$payload" -echo -echo - - -echo "03. POST /v1/contextEntities/type/T1/id/E1/attributes/A2" -echo "========================================================" -payload='{ - "value": 3 -}' -orionCurl --url /v1/contextEntities/type/T1/id/E1/attributes/A2 --payload "$payload" -echo -echo - - -echo "04. GET /v1/contextEntities - see 2 attributes" -echo "==============================================" -orionCurl --url /v1/contextEntities -echo -echo - - -echo "05. DELETE /v1/contextEntities/type/T1/id/E2/attributes/A1, and see it fail" -echo "===========================================================================" -orionCurl --url /v1/contextEntities/type/T1/id/E2/attributes/A1 -X DELETE -echo -echo - - -echo "06. DELETE /v1/contextEntities/type/T1/id/E1/attributes/A3, and see it fail" -echo "===========================================================================" -orionCurl --url /v1/contextEntities/type/T1/id/E1/attributes/A3 -X DELETE -echo -echo - - -echo "07. DELETE /v1/contextEntities/type/T1/id/E1/attributes/A1?entity::type=T2, and see it fail" -echo "===========================================================================================" -orionCurl --url /v1/contextEntities/type/T1/id/E1/attributes/A1?entity::type=T2 -X DELETE -echo -echo - - -echo "08. DELETE /v1/contextEntities/type/T1/id/E1/attributes/A1?!exist=entity::type, and see it fail" -echo "===============================================================================================" -orionCurl --url /v1/contextEntities/type/T1/id/E1/attributes/A1?!exist=entity::type -X DELETE -echo -echo - - -echo "09. GET /v1/contextEntities - see 2 attributes" -echo "==============================================" -orionCurl --url /v1/contextEntities -echo -echo - - -echo "10. DELETE /v1/contextEntities/type/T1/id/E1/attributes/A1?entity::type=T1" -echo "==========================================================================" -orionCurl --url /v1/contextEntities/type/T1/id/E1/attributes/A1?entity::type=T1 -X DELETE -echo -echo - - -echo "11. GET /v1/contextEntities - see 1 attribute (A2)" -echo "==================================================" -orionCurl --url /v1/contextEntities -echo -echo - - -echo "12. DELETE /v1/contextEntities/type/T1/id/E1/attributes/A2" -echo "==========================================================" -orionCurl --url /v1/contextEntities/type/T1/id/E1/attributes/A2 -X DELETE -echo -echo - - -echo "13. GET /v1/contextEntities - see 0 attributes" -echo "==============================================" -orionCurl --url /v1/contextEntities -echo -echo - - -echo "14. POST /v1/contextEntities/type/T1/id/E1/attributes/A3, service-path /s1" -echo "==========================================================================" -payload='{ - "value": 14 -}' -orionCurl --url /v1/contextEntities/type/T1/id/E1/attributes/A3 --payload "$payload" --servicePath /s1 -echo -echo - - -echo "15. POST /v1/contextEntities/type/T1/id/E1/attributes/A3, service-path /s2" -echo "==========================================================================" -payload='{ - "value": 15 -}' -orionCurl --url /v1/contextEntities/type/T1/id/E1/attributes/A3 --payload "$payload" --servicePath /s2 -echo -echo - - -echo "16. GET /v1/contextEntities - see 2 attributes" -echo "==============================================" -orionCurl --url /v1/contextEntities -echo -echo - - -echo "17. DELETE /v1/contextEntities/type/T1/id/E1/attributes/A3, service-path /s3, and see it fail" -echo "=============================================================================================" -orionCurl --url /v1/contextEntities/type/T1/id/E1/attributes/A3 -X DELETE --servicePath /s3 -echo -echo - - -echo "18. DELETE /v1/contextEntities/type/T1/id/E1/attributes/A3, service-path /s1" -echo "============================================================================" -orionCurl --url /v1/contextEntities/type/T1/id/E1/attributes/A3 -X DELETE --servicePath /s1 -echo -echo - - -echo "19. DELETE /v1/contextEntities/type/T1/id/E1/attributes/A3, service-path /s1, and see it fail" -echo "=============================================================================================" -orionCurl --url /v1/contextEntities/type/T1/id/E1/attributes/A3 -X DELETE --servicePath /s1 -echo -echo - - -echo "20. DELETE /v1/contextEntities/type/T1/id/E1/attributes/A3, service-path /s2" -echo "============================================================================" -orionCurl --url /v1/contextEntities/type/T1/id/E1/attributes/A3 -X DELETE --servicePath /s2 -echo -echo - - -echo "21. GET /v1/contextEntities - see 0 attributes" -echo "==============================================" -orionCurl --url /v1/contextEntities -echo -echo - - ---REGEXPECT-- -01. DELETE /v1/contextEntities/type/T1/id/E1/attributes/A1, and see it fail -=========================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 71 - -{ - "code": "404", - "details": "E1", - "reasonPhrase": "No context element found" -} - - -02. POST /v1/contextEntities/type/T1/id/E1/attributes/A1 -======================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 34 - -{ - "code": "200", - "reasonPhrase": "OK" -} - - -03. POST /v1/contextEntities/type/T1/id/E1/attributes/A2 -======================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 34 - -{ - "code": "200", - "reasonPhrase": "OK" -} - - -04. GET /v1/contextEntities - see 2 attributes -============================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 220 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "", - "value": "2" - }, - { - "name": "A2", - "type": "", - "value": "3" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -05. DELETE /v1/contextEntities/type/T1/id/E2/attributes/A1, and see it fail -=========================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 71 - -{ - "code": "404", - "details": "E2", - "reasonPhrase": "No context element found" -} - - -06. DELETE /v1/contextEntities/type/T1/id/E1/attributes/A3, and see it fail -=========================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 166 - -{ - "code": "472", - "details": "action: DELETE - entity: [E1, T1] - offending attribute: A3 - attribute not found", - "reasonPhrase": "request parameter is invalid/not allowed" -} - - -07. DELETE /v1/contextEntities/type/T1/id/E1/attributes/A1?entity::type=T2, and see it fail -=========================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 89 - -{ - "code": "400", - "details": "non-matching entity::types in URL", - "reasonPhrase": "Bad Request" -} - - -08. DELETE /v1/contextEntities/type/T1/id/E1/attributes/A1?!exist=entity::type, and see it fail -=============================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 101 - -{ - "code": "400", - "details": "entity::type cannot be empty for this request", - "reasonPhrase": "Bad Request" -} - - -09. GET /v1/contextEntities - see 2 attributes -============================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 220 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "", - "value": "2" - }, - { - "name": "A2", - "type": "", - "value": "3" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -10. DELETE /v1/contextEntities/type/T1/id/E1/attributes/A1?entity::type=T1 -========================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 34 - -{ - "code": "200", - "reasonPhrase": "OK" -} - - -11. GET /v1/contextEntities - see 1 attribute (A2) -================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 184 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A2", - "type": "", - "value": "3" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -12. DELETE /v1/contextEntities/type/T1/id/E1/attributes/A2 -========================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 34 - -{ - "code": "200", - "reasonPhrase": "OK" -} - - -13. GET /v1/contextEntities - see 0 attributes -============================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 133 - -{ - "contextResponses": [ - { - "contextElement": { - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -14. POST /v1/contextEntities/type/T1/id/E1/attributes/A3, service-path /s1 -========================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 34 - -{ - "code": "200", - "reasonPhrase": "OK" -} - - -15. POST /v1/contextEntities/type/T1/id/E1/attributes/A3, service-path /s2 -========================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 34 - -{ - "code": "200", - "reasonPhrase": "OK" -} - - -16. GET /v1/contextEntities - see 2 attributes -============================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 459 - -#SORT_START -{ - "contextResponses": [ - { - "contextElement": { - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - }, - { - "contextElement": { - "attributes": [ - { - "name": "A3", - "type": "", - "value": "14" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - }, - { - "contextElement": { - "attributes": [ - { - "name": "A3", - "type": "", - "value": "15" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} -#SORT_END - - -17. DELETE /v1/contextEntities/type/T1/id/E1/attributes/A3, service-path /s3, and see it fail -============================================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 71 - -{ - "code": "404", - "details": "E1", - "reasonPhrase": "No context element found" -} - - -18. DELETE /v1/contextEntities/type/T1/id/E1/attributes/A3, service-path /s1 -============================================================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 34 - -{ - "code": "200", - "reasonPhrase": "OK" -} - - -19. DELETE /v1/contextEntities/type/T1/id/E1/attributes/A3, service-path /s1, and see it fail -============================================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 166 - -{ - "code": "472", - "details": "action: DELETE - entity: [E1, T1] - offending attribute: A3 - attribute not found", - "reasonPhrase": "request parameter is invalid/not allowed" -} - - -20. DELETE /v1/contextEntities/type/T1/id/E1/attributes/A3, service-path /s2 -============================================================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 34 - -{ - "code": "200", - "reasonPhrase": "OK" -} - - -21. GET /v1/contextEntities - see 0 attributes -============================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 355 - -{ - "contextResponses": [ - { - "contextElement": { - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - }, - { - "contextElement": { - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - }, - { - "contextElement": { - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - ---TEARDOWN-- -brokerStop CB -dbDrop CB diff --git a/test/functionalTest/cases/0117_convop_using_standard_ops/deleteIndividualContextEntity_v1_contextEntities_EID.test.DISABLED b/test/functionalTest/cases/0117_convop_using_standard_ops/deleteIndividualContextEntity_v1_contextEntities_EID.test.DISABLED deleted file mode 100644 index 331082685c..0000000000 --- a/test/functionalTest/cases/0117_convop_using_standard_ops/deleteIndividualContextEntity_v1_contextEntities_EID.test.DISABLED +++ /dev/null @@ -1,362 +0,0 @@ -# Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U -# -# This file is part of Orion Context Broker. -# -# Orion Context Broker is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Orion Context Broker is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -# General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -# -# For those usages not covered by this license please contact with -# iot_support at tid dot es - -# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh - ---NAME-- -ConvOp deleteIndividualContextEntity: DELETE /v1/contextEntities/EID - ---SHELL-INIT-- -dbInit CB -brokerStart CB - ---SHELL-- - -# -# 01. POST /v1/contextEntities/E1?entity::type=T1 -# 02. POST /v1/contextEntities/E2?entity::type=T2 -# 03. GET /v1/contextEntities - see 2 entities -# 04. DELETE /v1/contextEntities/E4, and see it fail -# 05. DELETE /v1/contextEntities/E1?entity::type=T4, and see it fail -# 06. GET /v1/contextEntities - see 2 entities -# 07. DELETE /v1/contextEntities/E1 -# 08. DELETE /v1/contextEntities/E2?entity::type=T2 -# 09. GET /v1/contextEntities - see 0 entities -# - -echo "01. POST /v1/contextEntities/E1?entity::type=T1" -echo "===============================================" -payload='{ - "attributes": [ - { - "name": "A1", - "type": "AT", - "value": "10" - } - ] -}' -orionCurl --url /v1/contextEntities/E1?entity::type=T1 --payload "${payload}" -echo -echo - - -echo "02. POST /v1/contextEntities/E2?entity::type=T2" -echo "===============================================" -payload='{ - "attributes": [ - { - "name": "A2", - "type": "AT", - "value": "20" - } - ] -}' -orionCurl --url /v1/contextEntities/E2?entity::type=T2 --payload "${payload}" -echo -echo - - -echo "03. GET /v1/contextEntities - see 2 entities" -echo "============================================" -orionCurl --url /v1/contextEntities -echo -echo - - -echo "04. DELETE /v1/contextEntities/E4, and see it fail" -echo "==================================================" -orionCurl --url /v1/contextEntities/E4 -X DELETE -echo -echo - - -echo "05. DELETE /v1/contextEntities/E1?entity::type=T4, and see it fail" -echo "==================================================================" -orionCurl --url /v1/contextEntities/E1?entity::type=T4 -X DELETE -echo -echo - - -echo "06. GET /v1/contextEntities - see 2 entities" -echo "============================================" -orionCurl --url /v1/contextEntities -echo -echo - - -echo "07. DELETE /v1/contextEntities/E1" -echo "=================================" -orionCurl --url /v1/contextEntities/E1 -X DELETE -echo -echo - - -echo "08. DELETE /v1/contextEntities/E2?entity::type=T2" -echo "=================================================" -orionCurl --url /v1/contextEntities/E2?entity::type=T2 -X DELETE -echo -echo - - -echo "09. GET /v1/contextEntities - see 0 entities" -echo "============================================" -orionCurl --url /v1/contextEntities -echo -echo - - ---REGEXPECT-- -01. POST /v1/contextEntities/E1?entity::type=T1 -=============================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 166 - -{ - "contextResponses": [ - { - "attributes": [ - { - "name": "A1", - "type": "AT", - "value": "" - } - ], - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" -} - - -02. POST /v1/contextEntities/E2?entity::type=T2 -=============================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 166 - -{ - "contextResponses": [ - { - "attributes": [ - { - "name": "A2", - "type": "AT", - "value": "" - } - ], - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ], - "id": "E2", - "isPattern": "false", - "type": "T2" -} - - -03. GET /v1/contextEntities - see 2 entities -============================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 352 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "AT", - "value": "10" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - }, - { - "contextElement": { - "attributes": [ - { - "name": "A2", - "type": "AT", - "value": "20" - } - ], - "id": "E2", - "isPattern": "false", - "type": "T2" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -04. DELETE /v1/contextEntities/E4, and see it fail -================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 71 - -{ - "code": "404", - "details": "E4", - "reasonPhrase": "No context element found" -} - - -05. DELETE /v1/contextEntities/E1?entity::type=T4, and see it fail -================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 71 - -{ - "code": "404", - "details": "E1", - "reasonPhrase": "No context element found" -} - - -06. GET /v1/contextEntities - see 2 entities -============================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 352 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "AT", - "value": "10" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - }, - { - "contextElement": { - "attributes": [ - { - "name": "A2", - "type": "AT", - "value": "20" - } - ], - "id": "E2", - "isPattern": "false", - "type": "T2" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -07. DELETE /v1/contextEntities/E1 -================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 34 - -{ - "code": "200", - "reasonPhrase": "OK" -} - - -08. DELETE /v1/contextEntities/E2?entity::type=T2 -================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 34 - -{ - "code": "200", - "reasonPhrase": "OK" -} - - -09. GET /v1/contextEntities - see 0 entities -============================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 70 - -{ - "errorCode": { - "code": "404", - "reasonPhrase": "No context element found" - } -} - - ---TEARDOWN-- -brokerStop CB -dbDrop CB diff --git a/test/functionalTest/cases/0117_convop_using_standard_ops/deleteIndividualContextEntity_v1_contextEntities_EID_attributes.test.DISABLED b/test/functionalTest/cases/0117_convop_using_standard_ops/deleteIndividualContextEntity_v1_contextEntities_EID_attributes.test.DISABLED deleted file mode 100644 index 24db3438bc..0000000000 --- a/test/functionalTest/cases/0117_convop_using_standard_ops/deleteIndividualContextEntity_v1_contextEntities_EID_attributes.test.DISABLED +++ /dev/null @@ -1,362 +0,0 @@ -# Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U -# -# This file is part of Orion Context Broker. -# -# Orion Context Broker is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Orion Context Broker is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -# General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -# -# For those usages not covered by this license please contact with -# iot_support at tid dot es - -# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh - ---NAME-- -ConvOp deleteIndividualContextEntity: DELETE /v1/contextEntities/EID/attributes - ---SHELL-INIT-- -dbInit CB -brokerStart CB - ---SHELL-- - -# -# 01. POST /v1/contextEntities/E1?entity::type=T1 -# 02. POST /v1/contextEntities/E2?entity::type=T2 -# 03. GET /v1/contextEntities - see 2 entities -# 04. DELETE /v1/contextEntities/E4/attributes, and see it fail -# 05. DELETE /v1/contextEntities/E1/attributes?entity::type=T4, and see it fail -# 06. GET /v1/contextEntities - see 2 entities -# 07. DELETE /v1/contextEntities/E1/attributes -# 08. DELETE /v1/contextEntities/E2/attributes?entity::type=T2 -# 09. GET /v1/contextEntities - see 0 entities -# - -echo "01. POST /v1/contextEntities/E1?entity::type=T1" -echo "===============================================" -payload='{ - "attributes": [ - { - "name": "A1", - "type": "AT", - "value": "10" - } - ] -}' -orionCurl --url /v1/contextEntities/E1?entity::type=T1 --payload "${payload}" -echo -echo - - -echo "02. POST /v1/contextEntities/E2?entity::type=T2" -echo "===============================================" -payload='{ - "attributes": [ - { - "name": "A2", - "type": "AT", - "value": "20" - } - ] -}' -orionCurl --url /v1/contextEntities/E2?entity::type=T2 --payload "${payload}" -echo -echo - - -echo "03. GET /v1/contextEntities - see 2 entities" -echo "============================================" -orionCurl --url /v1/contextEntities -echo -echo - - -echo "04. DELETE /v1/contextEntities/E4/attributes, and see it fail" -echo "=============================================================" -orionCurl --url /v1/contextEntities/E4/attributes -X DELETE -echo -echo - - -echo "05. DELETE /v1/contextEntities/E1/attributes?entity::type=T4, and see it fail" -echo "=============================================================================" -orionCurl --url /v1/contextEntities/E1/attributes?entity::type=T4 -X DELETE -echo -echo - - -echo "06. GET /v1/contextEntities - see 2 entities" -echo "============================================" -orionCurl --url /v1/contextEntities -echo -echo - - -echo "07. DELETE /v1/contextEntities/E1/attributes" -echo "============================================" -orionCurl --url /v1/contextEntities/E1/attributes -X DELETE -echo -echo - - -echo "08. DELETE /v1/contextEntities/E2/attributes?entity::type=T2" -echo "============================================================" -orionCurl --url /v1/contextEntities/E2/attributes?entity::type=T2 -X DELETE -echo -echo - - -echo "09. GET /v1/contextEntities - see 0 entities" -echo "============================================" -orionCurl --url /v1/contextEntities -echo -echo - - ---REGEXPECT-- -01. POST /v1/contextEntities/E1?entity::type=T1 -=============================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 166 - -{ - "contextResponses": [ - { - "attributes": [ - { - "name": "A1", - "type": "AT", - "value": "" - } - ], - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" -} - - -02. POST /v1/contextEntities/E2?entity::type=T2 -=============================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 166 - -{ - "contextResponses": [ - { - "attributes": [ - { - "name": "A2", - "type": "AT", - "value": "" - } - ], - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ], - "id": "E2", - "isPattern": "false", - "type": "T2" -} - - -03. GET /v1/contextEntities - see 2 entities -============================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 352 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "AT", - "value": "10" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - }, - { - "contextElement": { - "attributes": [ - { - "name": "A2", - "type": "AT", - "value": "20" - } - ], - "id": "E2", - "isPattern": "false", - "type": "T2" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -04. DELETE /v1/contextEntities/E4/attributes, and see it fail -============================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 71 - -{ - "code": "404", - "details": "E4", - "reasonPhrase": "No context element found" -} - - -05. DELETE /v1/contextEntities/E1/attributes?entity::type=T4, and see it fail -============================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 71 - -{ - "code": "404", - "details": "E1", - "reasonPhrase": "No context element found" -} - - -06. GET /v1/contextEntities - see 2 entities -============================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 352 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "AT", - "value": "10" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - }, - { - "contextElement": { - "attributes": [ - { - "name": "A2", - "type": "AT", - "value": "20" - } - ], - "id": "E2", - "isPattern": "false", - "type": "T2" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -07. DELETE /v1/contextEntities/E1/attributes -============================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 34 - -{ - "code": "200", - "reasonPhrase": "OK" -} - - -08. DELETE /v1/contextEntities/E2/attributes?entity::type=T2 -============================================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 34 - -{ - "code": "200", - "reasonPhrase": "OK" -} - - -09. GET /v1/contextEntities - see 0 entities -============================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 70 - -{ - "errorCode": { - "code": "404", - "reasonPhrase": "No context element found" - } -} - - ---TEARDOWN-- -brokerStop CB -dbDrop CB diff --git a/test/functionalTest/cases/0117_convop_using_standard_ops/deleteSubscriptionConvOp.test.DISABLED b/test/functionalTest/cases/0117_convop_using_standard_ops/deleteSubscriptionConvOp.test.DISABLED deleted file mode 100644 index ba549129f2..0000000000 --- a/test/functionalTest/cases/0117_convop_using_standard_ops/deleteSubscriptionConvOp.test.DISABLED +++ /dev/null @@ -1,367 +0,0 @@ -# Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U -# -# This file is part of Orion Context Broker. -# -# Orion Context Broker is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Orion Context Broker is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -# General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -# -# For those usages not covered by this license please contact with -# iot_support at tid dot es - -# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh - ---NAME-- -ConvOp deleteSubscriptionConvOp: DELETE /v1/contextSubscriptions/{subscriptionId} - ---SHELL-INIT-- -dbInit CB -brokerStart CB 0-255 -accumulatorStart --pretty-print - ---SHELL-- - -# -# 01. DELETE /v1/contextSubscriptions/1234567890 and see it fail -# 02. DELETE /v1/contextSubscriptions/123456789012345678901234 and see it fail -# 03. Subscribe to E1/T1/A1 (save SUB_ID) -# 04. Create E1/T1/A1 -# 05. Dump accumulator, see E1/T1/A1 -# 06. DELETE /v1/contextSubscriptions/SUB_ID -# 07. Update E1/T1/A1 -# 08. Dump accumulator, still only the one notification -# - -echo "01. DELETE /v1/contextSubscriptions/1234567890 and see it fail" -echo "==============================================================" -orionCurl --url /v1/contextSubscriptions/1234567890 -X DELETE -echo -echo - - -echo "02. DELETE /v1/contextSubscriptions/123456789012345678901234 and see it fail" -echo "============================================================================" -orionCurl --url /v1/contextSubscriptions/123456789012345678901234 -X DELETE -echo -echo - - -echo "03. Subscribe to E1/T1/A1 (save SUB_ID)" -echo "=======================================" -payload='{ - "entities": [ - { - "id": "E1", - "type": "T1" - } - ], - "attributes": [ - "A1" - ], - "reference": "http://localhost:'${LISTENER_PORT}'/notify", - "duration": "P1M", - "throttling": "PT1S", - "notifyConditions": [ - { - "type": "ONCHANGE", - "condValues": [ - "A1" - ] - } - ] -}' -orionCurl --url /v1/subscribeContext --payload "$payload" -SUB_ID=$(echo "$_response" | grep subscriptionId | awk -F\" '{ print $4}') -echo -echo - - -echo "04. Create E1/T1/A1" -echo "===================" -payload='{ - "contextElements": [ - { - "type": "T1", - "id": "E1", - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "4" - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" -echo -echo - - -echo "05. Dump accumulator, see E1/T1/A1" -echo "==================================" -accumulatorDump -echo -echo - - -echo "06. DELETE /v1/contextSubscriptions/SUB_ID" -echo "==========================================" -orionCurl --url /v1/contextSubscriptions/$SUB_ID -X DELETE -echo -echo - - -echo "07. Update E1/T1/A1" -echo "===================" -payload='{ - "contextElements": [ - { - "type": "T1", - "id": "E1", - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "8" - } - ] - } - ], - "updateAction": "UPDATE" -}' -orionCurl --url /v1/updateContext --payload "$payload" -echo -echo - - -echo "08. Dump accumulator, still only the one notification" -echo "=====================================================" -accumulatorDump -echo -echo - - ---REGEXPECT-- -01. DELETE /v1/contextSubscriptions/1234567890 and see it fail -============================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 101 - -{ - "statusCode": { - "code": "404", - "reasonPhrase": "No context element found" - }, - "subscriptionId": "1234567890" -} - - -02. DELETE /v1/contextSubscriptions/123456789012345678901234 and see it fail -============================================================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 115 - -{ - "statusCode": { - "code": "404", - "reasonPhrase": "No context element found" - }, - "subscriptionId": "123456789012345678901234" -} - - -03. Subscribe to E1/T1/A1 (save SUB_ID) -======================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 104 - -{ - "subscribeResponse": { - "duration": "P1M", - "subscriptionId": "REGEX([0-9a-f]{24})", - "throttling": "PT1S" - } -} - - -04. Create E1/T1/A1 -=================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 189 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -05. Dump accumulator, see E1/T1/A1 -================================== -POST http://localhost:REGEX(\d+)/notify -Fiware-Servicepath: / -Content-Length: 259 -User-Agent: orion/REGEX(\d+\.\d+\.\d+.*) -Host: localhost:REGEX(\d+) -Accept: application/json -Content-Type: application/json; charset=utf-8 -Fiware-Correlator: REGEX([0-9a-f\-]{36}); cbnotif=1 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "4" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ], - "originator": "localhost", - "subscriptionId": "REGEX([0-9a-f]{24})" -} -======================================= - - -06. DELETE /v1/contextSubscriptions/SUB_ID -========================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 93 - -{ - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - }, - "subscriptionId": "REGEX([0-9a-f]{24})" -} - - -07. Update E1/T1/A1 -=================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 189 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -08. Dump accumulator, still only the one notification -===================================================== -POST http://localhost:REGEX(\d+)/notify -Fiware-Servicepath: / -Content-Length: 259 -User-Agent: orion/REGEX(\d+\.\d+\.\d+.*) -Host: localhost:REGEX(\d+) -Accept: application/json -Content-Type: application/json; charset=utf-8 -Fiware-Correlator: REGEX([0-9a-f\-]{36}); cbnotif=1 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "4" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ], - "originator": "localhost", - "subscriptionId": "REGEX([0-9a-f]{24})" -} -======================================= - - ---TEARDOWN-- -brokerStop CB -accumulatorStop -dbDrop CB diff --git a/test/functionalTest/cases/0117_convop_using_standard_ops/discovery_pagination.test.DISABLED b/test/functionalTest/cases/0117_convop_using_standard_ops/discovery_pagination.test.DISABLED deleted file mode 100644 index adfebdc102..0000000000 --- a/test/functionalTest/cases/0117_convop_using_standard_ops/discovery_pagination.test.DISABLED +++ /dev/null @@ -1,1811 +0,0 @@ -# Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U -# -# This file is part of Orion Context Broker. -# -# Orion Context Broker is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Orion Context Broker is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -# General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -# -# For those usages not covered by this license please contact with -# iot_support at tid dot es - -# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh - ---NAME-- -Pagination in discovery-convOps - ---SHELL-INIT-- -dbInit CB -brokerStart CB - ---SHELL-- - -# -# 01. Register E1/T1/A0 -# 02. Register E1/T1/A1 -# 03. Register E1/T1/A2 -# 04. Register E1/T1/A3 -# 05. Register E1/T1/A4 -# 06. Register E1/T1/A5 -# 07. Register E1/T1/A6 -# 08. Register E1/T1/A7 -# 09. Register E1/T1/A8 -# 10. Register E1/T1/A9 -# 11. Register E2/T2/A9 -# 12. Register E2/T3/A9 -# 13. Register E3/T4/A10 -# 14. Register E4/T4/A10 -# 15. Register E5/T4/A10 -# -# 16. Discover E1 using /v1/registry/contextEntities/E1, pagination '0-2' -# 17. Discover E1 using /v1/registry/contextEntities/E1, pagination '3-23' -# 18. Discover E1 using /v1/registry/contextEntities/E1, pagination '5', with details -# 19. Discover E1 using /v1/registry/contextEntities/E1/attributes, pagination '0-2' -# 20. Discover E1 using /v1/registry/contextEntities/E1/attributes, pagination '3-23' -# 21. Discover E1 using /v1/registry/contextEntities/E1/attributes, pagination '5', with details -# 22. Discover E2 using /v1/registry/contextEntities/E2/attributes/A9, pagination '0-1' -# 23. Discover E2 using /v1/registry/contextEntities/E2/attributes/A9, pagination '1-21' -# 24. Discover E2 using /v1/registry/contextEntities/E2/attributes/A9, pagination '0', with details -# 25. Discover type T1 using /v1/registry/contextEntityTypes/T1, pagination '0-1' -# 26. Discover type T1 using /v1/registry/contextEntityTypes/T1, pagination '1-21' -# 27. Discover type T1 using /v1/registry/contextEntityTypes/T1, pagination '0', with details -# 28. Discover type T4, attribute A10, using /v1/registry/contextEntityTypes/T4/attributes/A10, pagination '0-1' -# 29. Discover type T4, attribute A10, using /v1/registry/contextEntityTypes/T4/attributes/A10, pagination '1-21' -# 30. Discover type T4, attribute A10, using /v1/registry/contextEntityTypes/T4/attributes/A10, pagination '0', with details -# - -echo "01. Register E1/T1/A0" -echo "=====================" -payload='{ - "contextRegistrations": [ - { - "entities": [ - { - "type": "T1", - "isPattern": "false", - "id": "E1" - } - ], - "attributes": [ - { - "name": "A0", - "type": "string" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - ], - "duration": "P1M" -}' -orionCurl --url /v1/registry/registerContext --payload "$payload" -echo -echo - - -echo "02. Register E1/T1/A1" -echo "=====================" -payload='{ - "contextRegistrations": [ - { - "entities": [ - { - "type": "T1", - "isPattern": "false", - "id": "E1" - } - ], - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - ], - "duration": "P1M" -}' -orionCurl --url /v1/registry/registerContext --payload "$payload" -echo -echo - - -echo "03. Register E1/T1/A2" -echo "=====================" -payload='{ - "contextRegistrations": [ - { - "entities": [ - { - "type": "T1", - "isPattern": "false", - "id": "E1" - } - ], - "attributes": [ - { - "name": "A2", - "type": "string" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - ], - "duration": "P1M" -}' -orionCurl --url /v1/registry/registerContext --payload "$payload" -echo -echo - - -echo "04. Register E1/T1/A3" -echo "=====================" -payload='{ - "contextRegistrations": [ - { - "entities": [ - { - "type": "T1", - "isPattern": "false", - "id": "E1" - } - ], - "attributes": [ - { - "name": "A3", - "type": "string" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - ], - "duration": "P1M" -}' -orionCurl --url /v1/registry/registerContext --payload "$payload" -echo -echo - - -echo "05. Register E1/T1/A4" -echo "=====================" -payload='{ - "contextRegistrations": [ - { - "entities": [ - { - "type": "T1", - "isPattern": "false", - "id": "E1" - } - ], - "attributes": [ - { - "name": "A4", - "type": "string" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - ], - "duration": "P1M" -}' -orionCurl --url /v1/registry/registerContext --payload "$payload" -echo -echo - - -echo "06. Register E1/T1/A5" -echo "=====================" -payload='{ - "contextRegistrations": [ - { - "entities": [ - { - "type": "T1", - "isPattern": "false", - "id": "E1" - } - ], - "attributes": [ - { - "name": "A5", - "type": "string" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - ], - "duration": "P1M" -}' -orionCurl --url /v1/registry/registerContext --payload "$payload" -echo -echo - - -echo "07. Register E1/T1/A6" -echo "=====================" -payload='{ - "contextRegistrations": [ - { - "entities": [ - { - "type": "T1", - "isPattern": "false", - "id": "E1" - } - ], - "attributes": [ - { - "name": "A6", - "type": "string" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - ], - "duration": "P1M" -}' -orionCurl --url /v1/registry/registerContext --payload "$payload" -echo -echo - - -echo "08. Register E1/T1/A7" -echo "=====================" -payload='{ - "contextRegistrations": [ - { - "entities": [ - { - "type": "T1", - "isPattern": "false", - "id": "E1" - } - ], - "attributes": [ - { - "name": "A7", - "type": "string" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - ], - "duration": "P1M" -}' -orionCurl --url /v1/registry/registerContext --payload "$payload" -echo -echo - - -echo "09. Register E1/T1/A8" -echo "=====================" -payload='{ - "contextRegistrations": [ - { - "entities": [ - { - "type": "T1", - "isPattern": "false", - "id": "E1" - } - ], - "attributes": [ - { - "name": "A8", - "type": "string" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - ], - "duration": "P1M" -}' -orionCurl --url /v1/registry/registerContext --payload "$payload" -echo -echo - - -echo "10. Register E1/T1/A9" -echo "=====================" -payload='{ - "contextRegistrations": [ - { - "entities": [ - { - "type": "T1", - "isPattern": "false", - "id": "E1" - } - ], - "attributes": [ - { - "name": "A9", - "type": "string" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - ], - "duration": "P1M" -}' -orionCurl --url /v1/registry/registerContext --payload "$payload" -echo -echo - - -echo "11. Register E2/T2/A9" -echo "=====================" -payload='{ - "contextRegistrations": [ - { - "entities": [ - { - "type": "T2", - "isPattern": "false", - "id": "E2" - } - ], - "attributes": [ - { - "name": "A9", - "type": "string" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - ], - "duration": "P1M" -}' -orionCurl --url /v1/registry/registerContext --payload "$payload" -echo -echo - - -echo "12. Register E2/T3/A9" -echo "=====================" -payload='{ - "contextRegistrations": [ - { - "entities": [ - { - "type": "T3", - "isPattern": "false", - "id": "E2" - } - ], - "attributes": [ - { - "name": "A9", - "type": "string" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - ], - "duration": "P1M" -}' -orionCurl --url /v1/registry/registerContext --payload "$payload" -echo -echo - - -echo "13. Register E3/T4/A10" -echo "======================" -payload='{ - "contextRegistrations": [ - { - "entities": [ - { - "type": "T4", - "isPattern": "false", - "id": "E3" - } - ], - "attributes": [ - { - "name": "A10", - "type": "string" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - ], - "duration": "P1M" -}' -orionCurl --url /v1/registry/registerContext --payload "$payload" -echo -echo - - -echo "14. Register E4/T4/A10" -echo "======================" -payload='{ - "contextRegistrations": [ - { - "entities": [ - { - "type": "T4", - "isPattern": "false", - "id": "E4" - } - ], - "attributes": [ - { - "name": "A10", - "type": "string" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - ], - "duration": "P1M" -}' -orionCurl --url /v1/registry/registerContext --payload "$payload" -echo -echo - - -echo "15. Register E5/T4/A10" -echo "======================" -payload='{ - "contextRegistrations": [ - { - "entities": [ - { - "type": "T4", - "isPattern": "false", - "id": "E5" - } - ], - "attributes": [ - { - "name": "A10", - "type": "string" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - ], - "duration": "P1M" -}' -orionCurl --url /v1/registry/registerContext --payload "$payload" -echo -echo - - -echo "16. Discover E1 using /v1/registry/contextEntities/E1, pagination '0-2'" -echo "=======================================================================" -orionCurl --url "/v1/registry/contextEntities/E1?offset=0&limit=3" -echo -echo - - -echo "17. Discover E1 using /v1/registry/contextEntities/E1, pagination '3-23'" -echo "========================================================================" -orionCurl --url "/v1/registry/contextEntities/E1?offset=3&limit=20" -echo -echo - -echo "18. Discover E1 using /v1/registry/contextEntities/E1, pagination '5', with details" -echo "===================================================================================" -orionCurl --url "/v1/registry/contextEntities/E1?offset=5&limit=1&details=on" -echo -echo - - -echo "19. Discover E1 using /v1/registry/contextEntities/E1/attributes, pagination '0-2'" -echo "==================================================================================" -orionCurl --url "/v1/registry/contextEntities/E1/attributes?offset=0&limit=3" -echo -echo - - -echo "20. Discover E1 using /v1/registry/contextEntities/E1/attributes, pagination '3-23'" -echo "===================================================================================" -orionCurl --url "/v1/registry/contextEntities/E1/attributes?offset=3&limit=20" -echo -echo - -echo "21. Discover E1 using /v1/registry/contextEntities/E1/attributes, pagination '5', with details" -echo "==============================================================================================" -orionCurl --url "/v1/registry/contextEntities/E1/attributes?offset=5&limit=1&details=on" -echo -echo - - -echo "22. Discover E2 using /v1/registry/contextEntities/E2/attributes/A9, pagination '0-1'" -echo "=====================================================================================" -orionCurl --url "/v1/registry/contextEntities/E2/attributes/A9?offset=0&limit=2" -echo -echo - - -echo "23. Discover E2 using /v1/registry/contextEntities/E2/attributes/A9, pagination '1-21'" -echo "======================================================================================" -orionCurl --url "/v1/registry/contextEntities/E2/attributes/A9?offset=1&limit=20" -echo -echo - - -echo "24. Discover E2 using /v1/registry/contextEntities/E2/attributes/A9, pagination '0', with details" -echo "=================================================================================================" -orionCurl --url "/v1/registry/contextEntities/E2/attributes/A9?offset=0&limit=1&details=on" -echo -echo - - -echo "25. Discover type T1 using /v1/registry/contextEntityTypes/T1, pagination '0-1'" -echo "===============================================================================" -orionCurl --url "/v1/registry/contextEntityTypes/T1?offset=0&limit=2" -echo -echo - - -echo "26. Discover type T1 using /v1/registry/contextEntityTypes/T1, pagination '1-21'" -echo "================================================================================" -orionCurl --url "/v1/registry/contextEntityTypes/T1?offset=1&limit=20" -echo -echo - - -echo "27. Discover type T1 using /v1/registry/contextEntityTypes/T1, pagination '0', with details" -echo "===========================================================================================" -orionCurl --url "/v1/registry/contextEntityTypes/T1?offset=0&limit=1&details=on" -echo -echo - - -echo "28. Discover type T4, attribute A10, using /v1/registry/contextEntityTypes/T4/attributes/A10, pagination '0-1'" -echo "==============================================================================================================" -orionCurl --url "/v1/registry/contextEntityTypes/T4/attributes/A10?offset=0&limit=2" -echo -echo - - -echo "29. Discover type T4, attribute A10, using /v1/registry/contextEntityTypes/T4/attributes/A10, pagination '1-21'" -echo "===============================================================================================================" -orionCurl --url "/v1/registry/contextEntityTypes/T4/attributes/A10?offset=1&limit=20" -echo -echo - - -echo "30. Discover type T4, attribute A10, using /v1/registry/contextEntityTypes/T4/attributes/A10, pagination '0', with details" -echo "==========================================================================================================================" -orionCurl --url "/v1/registry/contextEntityTypes/T4/attributes/A10?offset=0&limit=1&details=on" -echo -echo - - ---REGEXPECT-- -01. Register E1/T1/A0 -===================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 62 - -{ - "duration": "P1M", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -02. Register E1/T1/A1 -===================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 62 - -{ - "duration": "P1M", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -03. Register E1/T1/A2 -===================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 62 - -{ - "duration": "P1M", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -04. Register E1/T1/A3 -===================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 62 - -{ - "duration": "P1M", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -05. Register E1/T1/A4 -===================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 62 - -{ - "duration": "P1M", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -06. Register E1/T1/A5 -===================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 62 - -{ - "duration": "P1M", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -07. Register E1/T1/A6 -===================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 62 - -{ - "duration": "P1M", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -08. Register E1/T1/A7 -===================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 62 - -{ - "duration": "P1M", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -09. Register E1/T1/A8 -===================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 62 - -{ - "duration": "P1M", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -10. Register E1/T1/A9 -===================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 62 - -{ - "duration": "P1M", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -11. Register E2/T2/A9 -===================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 62 - -{ - "duration": "P1M", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -12. Register E2/T3/A9 -===================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 62 - -{ - "duration": "P1M", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -13. Register E3/T4/A10 -====================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 62 - -{ - "duration": "P1M", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -14. Register E4/T4/A10 -====================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 62 - -{ - "duration": "P1M", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -15. Register E5/T4/A10 -====================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 62 - -{ - "duration": "P1M", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -16. Discover E1 using /v1/registry/contextEntities/E1, pagination '0-2' -======================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 556 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A0", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A2", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - } - ] -} - - -17. Discover E1 using /v1/registry/contextEntities/E1, pagination '3-23' -======================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 1252 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A3", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A4", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A5", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A6", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A7", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A8", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A9", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - } - ] -} - - -18. Discover E1 using /v1/registry/contextEntities/E1, pagination '5', with details -=================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 277 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A5", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - } - ], - "errorCode": { - "code": "200", - "details": "Count: 10", - "reasonPhrase": "OK" - } -} - - -19. Discover E1 using /v1/registry/contextEntities/E1/attributes, pagination '0-2' -================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 556 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A0", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A2", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - } - ] -} - - -20. Discover E1 using /v1/registry/contextEntities/E1/attributes, pagination '3-23' -=================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 1252 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A3", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A4", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A5", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A6", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A7", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A8", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A9", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - } - ] -} - - -21. Discover E1 using /v1/registry/contextEntities/E1/attributes, pagination '5', with details -============================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 277 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A5", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - } - ], - "errorCode": { - "code": "200", - "details": "Count: 10", - "reasonPhrase": "OK" - } -} - - -22. Discover E2 using /v1/registry/contextEntities/E2/attributes/A9, pagination '0-1' -===================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 382 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A9", - "type": "string" - } - ], - "entities": [ - { - "id": "E2", - "isPattern": "false", - "type": "T2" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A9", - "type": "string" - } - ], - "entities": [ - { - "id": "E2", - "isPattern": "false", - "type": "T3" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - } - ] -} - - -23. Discover E2 using /v1/registry/contextEntities/E2/attributes/A9, pagination '1-21' -====================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 208 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A9", - "type": "string" - } - ], - "entities": [ - { - "id": "E2", - "isPattern": "false", - "type": "T3" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - } - ] -} - - -24. Discover E2 using /v1/registry/contextEntities/E2/attributes/A9, pagination '0', with details -================================================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 276 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A9", - "type": "string" - } - ], - "entities": [ - { - "id": "E2", - "isPattern": "false", - "type": "T2" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - } - ], - "errorCode": { - "code": "200", - "details": "Count: 2", - "reasonPhrase": "OK" - } -} - - -25. Discover type T1 using /v1/registry/contextEntityTypes/T1, pagination '0-1' -=============================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 382 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A0", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - } - ] -} - - -26. Discover type T1 using /v1/registry/contextEntityTypes/T1, pagination '1-21' -================================================================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 1600 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A2", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A3", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A4", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A5", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A6", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A7", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A8", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A9", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - } - ] -} - - -27. Discover type T1 using /v1/registry/contextEntityTypes/T1, pagination '0', with details -=========================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 277 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A0", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - } - ], - "errorCode": { - "code": "200", - "details": "Count: 10", - "reasonPhrase": "OK" - } -} - - -28. Discover type T4, attribute A10, using /v1/registry/contextEntityTypes/T4/attributes/A10, pagination '0-1' -============================================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 384 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A10", - "type": "string" - } - ], - "entities": [ - { - "id": "E3", - "isPattern": "false", - "type": "T4" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A10", - "type": "string" - } - ], - "entities": [ - { - "id": "E4", - "isPattern": "false", - "type": "T4" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - } - ] -} - - -29. Discover type T4, attribute A10, using /v1/registry/contextEntityTypes/T4/attributes/A10, pagination '1-21' -=============================================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 384 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A10", - "type": "string" - } - ], - "entities": [ - { - "id": "E4", - "isPattern": "false", - "type": "T4" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A10", - "type": "string" - } - ], - "entities": [ - { - "id": "E5", - "isPattern": "false", - "type": "T4" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - } - ] -} - - -30. Discover type T4, attribute A10, using /v1/registry/contextEntityTypes/T4/attributes/A10, pagination '0', with details -========================================================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 277 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A10", - "type": "string" - } - ], - "entities": [ - { - "id": "E3", - "isPattern": "false", - "type": "T4" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - } - ], - "errorCode": { - "code": "200", - "details": "Count: 3", - "reasonPhrase": "OK" - } -} - - ---TEARDOWN-- -brokerStop CB -dbDrop CB diff --git a/test/functionalTest/cases/0117_convop_using_standard_ops/getAllContextEntities.test.DISABLED b/test/functionalTest/cases/0117_convop_using_standard_ops/getAllContextEntities.test.DISABLED deleted file mode 100644 index 5dd8c09b29..0000000000 --- a/test/functionalTest/cases/0117_convop_using_standard_ops/getAllContextEntities.test.DISABLED +++ /dev/null @@ -1,717 +0,0 @@ -# Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U -# -# This file is part of Orion Context Broker. -# -# Orion Context Broker is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Orion Context Broker is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -# General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -# -# For those usages not covered by this license please contact with -# iot_support at tid dot es - -# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh - ---NAME-- -ExtraOp getAllContextEntities: GET /v1/contextEntities - ---SHELL-INIT-- -dbInit CB -dbInit CP1 -brokerStart CB -brokerStart CP1 - ---SHELL-- - -# -# 01. GET /v1/contextEntities and see it fail -# 02. Update/APPEND E1/T1/A1 -# 03. GET /v1/contextEntities and see it work -# 04. GET /v1/contextEntities?attributesFormat=object and see it work -# 05. GET /v1/contextEntities?entity::type=T1 and see it work -# 06. GET /v1/contextEntities?exist=entity::type and see it work -# 07. GET /v1/contextEntities?entity::type=T2 and see it fail -# 08. GET /v1/contextEntities?!exist=entity::type and see it fail -# 09. Update/APPEND E2/T1/A1 -# 10. Update/APPEND E3/T1/A1 -# 11. Update/APPEND E4/T1/A1 -# 12. GET /v1/contextEntities?limit=2&details=on -# 13. GET /v1/contextEntities?offset=2&details=on -# 14. Update/APPEND E5//A1 -# 15. GET /v1/contextEntities?!exist=entity::type and see it work -# - -echo "01. GET /v1/contextEntities and see it fail" -echo "===========================================" -orionCurl --url /v1/contextEntities -echo -echo - - -echo "02. Update/APPEND E1/T1/A1" -echo "==========================" -payload='{ - "contextElements": [ - { - "type": "T1", - "id": "E1", - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "02" - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" -echo -echo - - -echo "03. GET /v1/contextEntities and see it work" -echo "===========================================" -orionCurl --url /v1/contextEntities -echo -echo - - -echo "04. GET /v1/contextEntities?attributesFormat=object and see it work" -echo "===================================================================" -orionCurl --url /v1/contextEntities?attributesFormat=object -echo -echo - - -echo "05. GET /v1/contextEntities?entity::type=T1 and see it work" -echo "===========================================================" -orionCurl --url /v1/contextEntities?entity::type=T1 -echo -echo - - -echo "06. GET /v1/contextEntities?exist=entity::type and see it work" -echo "==============================================================" -orionCurl --url /v1/contextEntities?exist=entity::type -echo -echo - - -echo "07. GET /v1/contextEntities?entity::type=T2 and see it fail" -echo "===========================================================" -orionCurl --url /v1/contextEntities?entity::type=T2 -echo -echo - - -echo "08. GET /v1/contextEntities?!exist=entity::type and see it fail" -echo "===============================================================" -orionCurl --url /v1/contextEntities?!exist=entity::type -echo -echo - - -echo "09. Update/APPEND E2/T1/A1" -echo "==========================" -payload='{ - "contextElements": [ - { - "type": "T1", - "id": "E2", - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "02" - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" -echo -echo - - -echo "10. Update/APPEND E3/T1/A1" -echo "==========================" -payload='{ - "contextElements": [ - { - "type": "T1", - "id": "E3", - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "02" - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" -echo -echo - - -echo "11. Update/APPEND E4/T1/A1" -echo "==========================" -payload='{ - "contextElements": [ - { - "type": "T1", - "id": "E4", - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "02" - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" -echo -echo - - -echo "12. GET /v1/contextEntities?limit=2&details=on" -echo "==============================================" -orionCurl --url '/v1/contextEntities?limit=2&details=on' -echo -echo - - -echo "13. GET /v1/contextEntities?offset=2&details=on" -echo "===============================================" -orionCurl --url '/v1/contextEntities?offset=2&details=on' -echo -echo - - -echo "14. Update/APPEND E5//A1" -echo "========================" -payload='{ - "contextElements": [ - { - "id": "E5", - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "15" - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" -echo -echo - - -echo "15. GET /v1/contextEntities?!exist=entity::type and see it work" -echo "===============================================================" -orionCurl --url /v1/contextEntities?!exist=entity::type -echo -echo - - ---REGEXPECT-- -01. GET /v1/contextEntities and see it fail -=========================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 70 - -{ - "errorCode": { - "code": "404", - "reasonPhrase": "No context element found" - } -} - - -02. Update/APPEND E1/T1/A1 -========================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 189 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -03. GET /v1/contextEntities and see it work -=========================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 191 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "02" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -04. GET /v1/contextEntities?attributesFormat=object and see it work -=================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 184 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": { - "A1": { - "type": "string", - "value": "02" - } - }, - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -05. GET /v1/contextEntities?entity::type=T1 and see it work -=========================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 191 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "02" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -06. GET /v1/contextEntities?exist=entity::type and see it work -============================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 191 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "02" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -07. GET /v1/contextEntities?entity::type=T2 and see it fail -=========================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 70 - -{ - "errorCode": { - "code": "404", - "reasonPhrase": "No context element found" - } -} - - -08. GET /v1/contextEntities?!exist=entity::type and see it fail -=============================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 70 - -{ - "errorCode": { - "code": "404", - "reasonPhrase": "No context element found" - } -} - - -09. Update/APPEND E2/T1/A1 -========================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 189 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "" - } - ], - "id": "E2", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -10. Update/APPEND E3/T1/A1 -========================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 189 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "" - } - ], - "id": "E3", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -11. Update/APPEND E4/T1/A1 -========================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 189 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "" - } - ], - "id": "E4", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -12. GET /v1/contextEntities?limit=2&details=on -============================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 428 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "02" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - }, - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "02" - } - ], - "id": "E2", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ], - "errorCode": { - "code": "200", - "details": "Count: 4", - "reasonPhrase": "OK" - } -} - - -13. GET /v1/contextEntities?offset=2&details=on -=============================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 428 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "02" - } - ], - "id": "E3", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - }, - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "02" - } - ], - "id": "E4", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ], - "errorCode": { - "code": "200", - "details": "Count: 4", - "reasonPhrase": "OK" - } -} - - -14. Update/APPEND E5//A1 -======================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 187 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "" - } - ], - "id": "E5", - "isPattern": "false", - "type": "" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -15. GET /v1/contextEntities?!exist=entity::type and see it work -=============================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 189 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "15" - } - ], - "id": "E5", - "isPattern": "false", - "type": "" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - ---TEARDOWN-- -brokerStop CB -dbDrop CP1 -dbDrop CB diff --git a/test/functionalTest/cases/0117_convop_using_standard_ops/getAllEntitiesWithTypeAndId.test.DISABLED b/test/functionalTest/cases/0117_convop_using_standard_ops/getAllEntitiesWithTypeAndId.test.DISABLED deleted file mode 100644 index 6b2dc8c60d..0000000000 --- a/test/functionalTest/cases/0117_convop_using_standard_ops/getAllEntitiesWithTypeAndId.test.DISABLED +++ /dev/null @@ -1,542 +0,0 @@ -# Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U -# -# This file is part of Orion Context Broker. -# -# Orion Context Broker is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Orion Context Broker is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -# General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -# -# For those usages not covered by this license please contact with -# iot_support at tid dot es - -# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh - ---NAME-- -ConvOp getAllEntitiesWithTypeAndId: GET /v1/contextEntities/type/{entity::type}/id/{entity::id} - ---SHELL-INIT-- -dbInit CB -brokerStart CB 0 - ---SHELL-- - -# -# 01. GET /v1/contextEntities/type/T1/id/E1 and see it fail -# 02. Update/APPEND E1-T1 -# 03. Update/APPEND E1-T2 -# 04. GET /v1/contextEntities/type/T1/id/E1 and see it work -# 05. GET /v1/contextEntities/type/T1/id/E1?entity::type=T1 and see it work -# 06. GET /v1/contextEntities/type/T1/id/E1?entity::type=T2 and see it fail -# 07. GET /v1/contextEntities/type/T2/id/E1?entity::type=T2 and see it work -# 08. GET /v1/contextEntities/type/T1/id/E1?!exist=entity::type and see it fail -# 09. GET /v1/contextEntities/type/T1/id/E1?entity::type=T1&exist=entity::type and see it work -# 10. Update/APPEND E1-T1, service-path /test -# 11. GET /v1/contextEntities/type/T1/id/E1, service-path /test and see it work -# 12. GET /v1/contextEntities/type/T1/id/E1, service-path /test2 and see it fail -# 13. GET /v1/contextEntities/type/T1/id/E1?attributesFormat=object -# - -echo "01. GET /v1/contextEntities/type/T1/id/E1 and see it fail" -echo "=========================================================" -orionCurl --url /v1/contextEntities/type/T1/id/E1 -echo -echo - - -echo "02. Update/APPEND E1-T1" -echo "=======================" -payload='{ - "contextElements": [ - { - "type": "T1", - "id": "E1", - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "1" - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" -echo -echo - - -echo "03. Update/APPEND E1-T2" -echo "=======================" -payload='{ - "contextElements": [ - { - "type": "T2", - "id": "E1", - "attributes": [ - { - "name": "A2", - "type": "string", - "value": "2" - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" -echo -echo - - -echo "04. GET /v1/contextEntities/type/T1/id/E1 and see it work" -echo "=========================================================" -orionCurl --url /v1/contextEntities/type/T1/id/E1 -echo -echo - - -echo "05. GET /v1/contextEntities/type/T1/id/E1?entity::type=T1 and see it work" -echo "=========================================================================" -orionCurl --url /v1/contextEntities/type/T1/id/E1?entity::type=T1 -echo -echo - - -echo "06. GET /v1/contextEntities/type/T1/id/E1?entity::type=T2 and see it fail" -echo "=========================================================================" -orionCurl --url /v1/contextEntities/type/T1/id/E1?entity::type=T2 -echo -echo - - -echo "07. GET /v1/contextEntities/type/T2/id/E1?entity::type=T2 and see it work" -echo "=========================================================================" -orionCurl --url /v1/contextEntities/type/T2/id/E1?entity::type=T2 -echo -echo - - -echo "08. GET /v1/contextEntities/type/T1/id/E1?!exist=entity::type and see it fail" -echo "=============================================================================" -orionCurl --url /v1/contextEntities/type/T1/id/E1?!exist=entity::type -echo -echo - - -echo "09. GET /v1/contextEntities/type/T1/id/E1?entity::type=T1&exist=entity::type and see it work" -echo "============================================================================================" -orionCurl --url '/v1/contextEntities/type/T1/id/E1?entity::type=T1&exist=entity::type' -echo -echo - - -echo "10. Update/APPEND E1-T1, service-path /test" -echo "===========================================" -payload='{ - "contextElements": [ - { - "type": "T1", - "id": "E1", - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "E1-T1-/test" - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" --servicePath /test -echo -echo - - -echo "11. GET /v1/contextEntities/type/T1/id/E1, service-path /test and see it work" -echo "=============================================================================" -orionCurl --url /v1/contextEntities/type/T1/id/E1 --servicePath /test -echo -echo - - -echo "12. GET /v1/contextEntities/type/T1/id/E1, service-path /test2 and see it fail" -echo "==============================================================================" -orionCurl --url /v1/contextEntities/type/T1/id/E1 --servicePath /test2 -echo -echo - - -echo "13. GET /v1/contextEntities/type/T1/id/E1?attributesFormat=object" -echo "=================================================================" -orionCurl --url /v1/contextEntities/type/T1/id/E1?attributesFormat=object -echo -echo - - - ---REGEXPECT-- -01. GET /v1/contextEntities/type/T1/id/E1 and see it fail -========================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 160 - -{ - "contextElement": { - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "404", - "details": "Entity id: /E1/", - "reasonPhrase": "No context element found" - } -} - - -02. Update/APPEND E1-T1 -======================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 189 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -03. Update/APPEND E1-T2 -======================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 189 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A2", - "type": "string", - "value": "" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T2" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -04. GET /v1/contextEntities/type/T1/id/E1 and see it work -========================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 167 - -{ - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "1" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } -} - - -05. GET /v1/contextEntities/type/T1/id/E1?entity::type=T1 and see it work -========================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 167 - -{ - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "1" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } -} - - -06. GET /v1/contextEntities/type/T1/id/E1?entity::type=T2 and see it fail -========================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 165 - -{ - "contextElement": { - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "400", - "details": "non-matching entity::types in URL", - "reasonPhrase": "Bad Request" - } -} - - -07. GET /v1/contextEntities/type/T2/id/E1?entity::type=T2 and see it work -========================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 167 - -{ - "contextElement": { - "attributes": [ - { - "name": "A2", - "type": "string", - "value": "2" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T2" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } -} - - -08. GET /v1/contextEntities/type/T1/id/E1?!exist=entity::type and see it fail -============================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 177 - -{ - "contextElement": { - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "400", - "details": "entity::type cannot be empty for this request", - "reasonPhrase": "Bad Request" - } -} - - -09. GET /v1/contextEntities/type/T1/id/E1?entity::type=T1&exist=entity::type and see it work -============================================================================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 167 - -{ - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "1" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } -} - - -10. Update/APPEND E1-T1, service-path /test -=========================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 189 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -11. GET /v1/contextEntities/type/T1/id/E1, service-path /test and see it work -============================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 177 - -{ - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "E1-T1-/test" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } -} - - -12. GET /v1/contextEntities/type/T1/id/E1, service-path /test2 and see it fail -============================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 160 - -{ - "contextElement": { - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "404", - "details": "Entity id: /E1/", - "reasonPhrase": "No context element found" - } -} - - -13. GET /v1/contextEntities/type/T1/id/E1?attributesFormat=object -================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 160 - -{ - "contextElement": { - "attributes": { - "A1": { - "type": "string", - "value": "1" - } - }, - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } -} - - ---TEARDOWN-- -brokerStop CB -dbDrop CB diff --git a/test/functionalTest/cases/0117_convop_using_standard_ops/getAttributesForEntityType.test.DISABLED b/test/functionalTest/cases/0117_convop_using_standard_ops/getAttributesForEntityType.test.DISABLED deleted file mode 100644 index 9cb4619a8b..0000000000 --- a/test/functionalTest/cases/0117_convop_using_standard_ops/getAttributesForEntityType.test.DISABLED +++ /dev/null @@ -1,313 +0,0 @@ -# Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U -# -# This file is part of Orion Context Broker. -# -# Orion Context Broker is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Orion Context Broker is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -# General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -# -# For those usages not covered by this license please contact with -# iot_support at tid dot es - -# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh - ---NAME-- -ExtraOp getAttributesForEntityType: GET /v1/contextTypes/{entity::type} - ---SHELL-INIT-- -dbInit CB -brokerStart CB 0-255 - ---SHELL-- - -# -# 01. GET /v1/contextTypes/T1 and see it fail -# 02. POST /v1/updateContext, creating E1-T1-A1+A2 -# 03. GET /v1/contextTypes/T1 and see it work -# 04. POST /v1/updateContext, creating E1-T1-A3+A4, servicePath /s1 -# 05. GET /v1/contextTypes/T1, without servicePath, see four types -# 06. GET /v1/contextTypes/T1, with servicePath /s1, see two types -# 07. GET /v1/contextTypes/T1, with servicePath /, see two types -# - -echo "01. GET /v1/contextTypes/T1 and see it fail" -echo "===========================================" -orionCurl --url /v1/contextTypes/T1 -echo -echo - - -echo "02. POST /v1/updateContext, creating E1-T1-A1+A2" -echo "================================================" -payload='{ - "contextElements": [ - { - "type": "T1", - "id": "E1", - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "1" - }, - { - "name": "A2", - "type": "string", - "value": "2" - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" -echo -echo - - -echo "03. GET /v1/contextTypes/T1 and see it work" -echo "===========================================" -orionCurl --url /v1/contextTypes/T1 -echo -echo - - -echo "04. POST /v1/updateContext, creating E1-T1-A3+A4, servicePath /s1" -echo "=================================================================" -payload='{ - "contextElements": [ - { - "type": "T1", - "id": "E1", - "attributes": [ - { - "name": "A3", - "type": "string", - "value": "3" - }, - { - "name": "A4", - "type": "string", - "value": "4" - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" --servicePath /s1 -echo -echo - - -echo "05. GET /v1/contextTypes/T1, without servicePath, see four types" -echo "================================================================" -orionCurl --url /v1/contextTypes/T1 -echo -echo - - -echo "06. GET /v1/contextTypes/T1, with servicePath /s1, see two types" -echo "================================================================" -orionCurl --url /v1/contextTypes/T1 --servicePath /s1 -echo -echo - - -echo "07. GET /v1/contextTypes/T1, with servicePath /, see two types" -echo "==============================================================" -orionCurl --url /v1/contextTypes/T1 --servicePath / -echo -echo - - ---REGEXPECT-- -01. GET /v1/contextTypes/T1 and see it fail -=========================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 83 - -{ - "name": "T1", - "statusCode": { - "code": "404", - "reasonPhrase": "No context element found" - } -} - - -02. POST /v1/updateContext, creating E1-T1-A1+A2 -================================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 230 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "" - }, - { - "name": "A2", - "type": "string", - "value": "" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -03. GET /v1/contextTypes/T1 and see it work -=========================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 86 - -{ - "attributes": [ - "A1", - "A2" - ], - "name": "T1", - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } -} - - -04. POST /v1/updateContext, creating E1-T1-A3+A4, servicePath /s1 -================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 230 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A3", - "type": "string", - "value": "" - }, - { - "name": "A4", - "type": "string", - "value": "" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -05. GET /v1/contextTypes/T1, without servicePath, see four types -================================================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 96 - -{ - "attributes": [ - "A1", - "A2", - "A3", - "A4" - ], - "name": "T1", - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } -} - - -06. GET /v1/contextTypes/T1, with servicePath /s1, see two types -================================================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 86 - -{ - "attributes": [ - "A3", - "A4" - ], - "name": "T1", - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } -} - - -07. GET /v1/contextTypes/T1, with servicePath /, see two types -============================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 86 - -{ - "attributes": [ - "A1", - "A2" - ], - "name": "T1", - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } -} - - ---TEARDOWN-- -brokerStop CB -dbDrop CB diff --git a/test/functionalTest/cases/0117_convop_using_standard_ops/getContextEntitiesByEntityId.test.DISABLED b/test/functionalTest/cases/0117_convop_using_standard_ops/getContextEntitiesByEntityId.test.DISABLED deleted file mode 100644 index bc83bba865..0000000000 --- a/test/functionalTest/cases/0117_convop_using_standard_ops/getContextEntitiesByEntityId.test.DISABLED +++ /dev/null @@ -1,638 +0,0 @@ -# Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U -# -# This file is part of Orion Context Broker. -# -# Orion Context Broker is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Orion Context Broker is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -# General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -# -# For those usages not covered by this license please contact with -# iot_support at tid dot es - -# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh - ---NAME-- -ConvOp getContextEntitiesByEntityId: /v1/registry/contextEntities/{entityId::id} - ---SHELL-INIT-- -dbInit CB -brokerStart CB - ---SHELL-- - -# -# This test case verifies that the convop 'getContextEntitiesByEntityId' does everything -# that ngsi9 discovery does, including URI parameters, etc. -# - -# -# 01. Register E1/T1/A1 with Service-Path /A1 -# 02. Register E1//A2 (type is empty) with Service-Path /A2 -# 03. Register E1/T2/A3 with Service-Path /A3 -# 04. Discover E1 using /v1/registry/contextEntities/E1 with Service-Path /A1 -# 05. Discover E1 using /v1/registry/contextEntities/E1 with Service-Path /A1,/A2 -# 06. Discover E1 using /v1/registry/contextEntities/E1 with Service-Path /A1,/A3 -# 07. Discover E1 using /v1/registry/contextEntities/E1 with Service-Path /A2,/A3 -# 08. Discover E1 using /v1/registry/contextEntities/E1 with Service-Path /A1,/A2,/A3 -# 09. Discover E1 using /v1/registry/contextEntities/E1 with Service-Path /B1 -# 10. Discover E1 using /v1/registry/contextEntities/E1 without Service-Path -# 11. Discover E1 using /v1/registry/contextEntities/E1 with Service-Path /# -# - -echo "01. Register E1/T1/A1 with Service-Path /A1" -echo "===========================================" -payload='{ - "contextRegistrations": [ - { - "entities": [ - { - "type": "T1", - "isPattern": "false", - "id": "E1" - } - ], - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - ], - "duration": "P1M" -}' -orionCurl --url /v1/registry/registerContext --payload "$payload" --servicePath /A1 -echo -echo - - -echo "02. Register E1//A2 (type is empty) with Service-Path /A2" -echo "=========================================================" -payload='{ - "contextRegistrations": [ - { - "entities": [ - { - "type": "", - "isPattern": "false", - "id": "E1" - } - ], - "attributes": [ - { - "name": "A2", - "type": "string" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - ], - "duration": "P1M" -}' -orionCurl --url /v1/registry/registerContext --payload "$payload" --servicePath /A2 -echo -echo - - -echo "03. Register E1/T2/A3 with Service-Path /A3" -echo "===========================================" -payload='{ - "contextRegistrations": [ - { - "entities": [ - { - "type": "T2", - "isPattern": "false", - "id": "E1" - } - ], - "attributes": [ - { - "name": "A3", - "type": "string" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - ], - "duration": "P1M" -}' -orionCurl --url /v1/registry/registerContext --payload "$payload" --servicePath /A3 -echo -echo - - -echo "04. Discover E1 using /v1/registry/contextEntities/E1 with Service-Path /A1" -echo "===========================================================================" -orionCurl --url "/v1/registry/contextEntities/E1" --servicePath /A1 -echo -echo - - -echo "05. Discover E1 using /v1/registry/contextEntities/E1 with Service-Path /A1,/A2" -echo "===============================================================================" -orionCurl --url "/v1/registry/contextEntities/E1" --servicePath /A1,/A2 -echo -echo - - -echo "06. Discover E1 using /v1/registry/contextEntities/E1 with Service-Path /A1,/A3" -echo "===============================================================================" -orionCurl --url "/v1/registry/contextEntities/E1" --servicePath /A1,/A3 -echo -echo - - -echo "07. Discover E1 using /v1/registry/contextEntities/E1 with Service-Path /A2,/A3" -echo "===============================================================================" -orionCurl --url "/v1/registry/contextEntities/E1" --servicePath /A2,/A3 -echo -echo - - -echo "08. Discover E1 using /v1/registry/contextEntities/E1 with Service-Path /A1,/A2,/A3" -echo "===================================================================================" -orionCurl --url "/v1/registry/contextEntities/E1" --servicePath /A1,/A2,/A3 -echo -echo - - -echo "09. Discover E1 using /v1/registry/contextEntities/E1 with Service-Path /B1" -echo "===========================================================================" -orionCurl --url "/v1/registry/contextEntities/E1" --servicePath /B1 -echo -echo - - -echo "10. Discover E1 using /v1/registry/contextEntities/E1 without Service-Path" -echo "==========================================================================" -orionCurl --url "/v1/registry/contextEntities/E1" -echo -echo - - -echo "11. Discover E1 using /v1/registry/contextEntities/E1 with Service-Path /#" -echo "==========================================================================" -orionCurl --url "/v1/registry/contextEntities/E1" --servicePath /# -echo -echo - - ---REGEXPECT-- -01. Register E1/T1/A1 with Service-Path /A1 -=========================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 62 - -{ - "duration": "P1M", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -02. Register E1//A2 (type is empty) with Service-Path /A2 -========================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 62 - -{ - "duration": "P1M", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -03. Register E1/T2/A3 with Service-Path /A3 -=========================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 62 - -{ - "duration": "P1M", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -04. Discover E1 using /v1/registry/contextEntities/E1 with Service-Path /A1 -=========================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 208 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - } - ] -} - - -05. Discover E1 using /v1/registry/contextEntities/E1 with Service-Path /A1,/A2 -=============================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 380 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A2", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - } - ] -} - - -06. Discover E1 using /v1/registry/contextEntities/E1 with Service-Path /A1,/A3 -=============================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 382 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A3", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T2" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - } - ] -} - - -07. Discover E1 using /v1/registry/contextEntities/E1 with Service-Path /A2,/A3 -=============================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 380 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A2", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A3", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T2" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - } - ] -} - - -08. Discover E1 using /v1/registry/contextEntities/E1 with Service-Path /A1,/A2,/A3 -=================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 554 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A2", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A3", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T2" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - } - ] -} - - -09. Discover E1 using /v1/registry/contextEntities/E1 with Service-Path /B1 -=========================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 70 - -{ - "errorCode": { - "code": "404", - "reasonPhrase": "No context element found" - } -} - - -10. Discover E1 using /v1/registry/contextEntities/E1 without Service-Path -========================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 554 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A2", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A3", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T2" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - } - ] -} - - -11. Discover E1 using /v1/registry/contextEntities/E1 with Service-Path /# -========================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 554 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A2", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A3", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T2" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - } - ] -} - - ---TEARDOWN-- -brokerStop CB -dbDrop CB diff --git a/test/functionalTest/cases/0117_convop_using_standard_ops/getContextEntitiesByEntityIdAndType.test.DISABLED b/test/functionalTest/cases/0117_convop_using_standard_ops/getContextEntitiesByEntityIdAndType.test.DISABLED deleted file mode 100644 index 8b9e80e59f..0000000000 --- a/test/functionalTest/cases/0117_convop_using_standard_ops/getContextEntitiesByEntityIdAndType.test.DISABLED +++ /dev/null @@ -1,705 +0,0 @@ -# Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U -# -# This file is part of Orion Context Broker. -# -# Orion Context Broker is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Orion Context Broker is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -# General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -# -# For those usages not covered by this license please contact with -# iot_support at tid dot es - -# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh - ---NAME-- -ConvOp getContextEntitiesByEntityIdAndType: /v1/registry/contextEntities/type/{entity::type}/id/{entity::id}/ - ---SHELL-INIT-- -dbInit CB -brokerStart CB - ---SHELL-- - -# -# 01. GET /v1/registry/contextEntities/type/T1/id/E1 and see it fail -# 02. Register E1/T1/A1 -# 03. GET /v1/registry/contextEntities/type/T1/id/E1 and see it work -# 04. GET /v1/registry/contextEntities/type/T1/id/E1?exist=entity::type and see it work -# 05. GET /v1/registry/contextEntities/type/T1/id/E1?entity::type=T1 and see it work -# 06. GET /v1/registry/contextEntities/type/T1/id/E2 and see it fail -# 07. GET /v1/registry/contextEntities/type/T2/id/E1 and see it fail -# 08. GET /v1/registry/contextEntities/type/T1/id/E1?entity::type=T2 and see it fail -# 09. GET /v1/registry/contextEntities/type/T1/id/E1?!exist=entity::type and see it fail -# 10. Register E1/T1/A1 with Service-Path /s1 -# 11. Register E1/T1/A1 with Service-Path /s2 -# 12. GET /v1/registry/contextEntities/type/T1/id/E1 with Service-Path /s1 -# 13. GET /v1/registry/contextEntities/type/T1/id/E1 with Service-Path /s2 -# 14. GET /v1/registry/contextEntities/type/T1/id/E1 with Service-Path /s3 and see it fail -# 15. GET /v1/registry/contextEntities/type/T1/id/E1 without Service-Path -# 16. GET /v1/registry/contextEntities/type/T1/id/E1 with Service-Path /# -# 17. GET /v1/registry/contextEntities/type/T1/id/E1 with Service-Path / -# - -echo "01. GET /v1/registry/contextEntities/type/T1/id/E1 and see it fail" -echo "========================================================================" -orionCurl --url /v1/registry/contextEntities/type/T1/id/E1 -echo -echo - - -echo "02. Register E1/T1/A1" -echo "=====================" -payload='{ - "contextRegistrations": [ - { - "entities": [ - { - "type": "T1", - "isPattern": "false", - "id": "E1" - } - ], - "attributes": [ - { - "name": "A1", - "type": "slash" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - ], - "duration": "P1M" -}' -orionCurl --url /v1/registry/registerContext --payload "$payload" -echo -echo - - -echo "03. GET /v1/registry/contextEntities/type/T1/id/E1 and see it work" -echo "==================================================================" -orionCurl --url /v1/registry/contextEntities/type/T1/id/E1 -echo -echo - - -echo "04. GET /v1/registry/contextEntities/type/T1/id/E1?exist=entity::type and see it work" -echo "=====================================================================================" -orionCurl --url /v1/registry/contextEntities/type/T1/id/E1?exist=entity::type -echo -echo - - -echo "05. GET /v1/registry/contextEntities/type/T1/id/E1?entity::type=T1 and see it work" -echo "==================================================================================" -orionCurl --url /v1/registry/contextEntities/type/T1/id/E1?entity::type=T1 -echo -echo - - -echo "06. GET /v1/registry/contextEntities/type/T1/id/E2 and see it fail" -echo "==================================================================" -orionCurl --url /v1/registry/contextEntities/type/T1/id/E2 -echo -echo - - -echo "07. GET /v1/registry/contextEntities/type/T2/id/E1 and see it fail" -echo "==================================================================" -orionCurl --url /v1/registry/contextEntities/type/T2/id/E1 -echo -echo - - -echo "08. GET /v1/registry/contextEntities/type/T1/id/E1?entity::type=T2 and see it fail" -echo "==================================================================================" -orionCurl --url /v1/registry/contextEntities/type/T1/id/E1?entity::type=T2 -echo -echo - - -echo "09. GET /v1/registry/contextEntities/type/T1/id/E1?!exist=entity::type and see it fail" -echo "======================================================================================" -orionCurl --url /v1/registry/contextEntities/type/T1/id/E1?!exist=entity::type -echo -echo - - -echo "10. Register E1/T1/A1 with Service-Path /s1" -echo "===========================================" -payload='{ - "contextRegistrations": [ - { - "entities": [ - { - "type": "T1", - "isPattern": "false", - "id": "E1" - } - ], - "attributes": [ - { - "name": "A1", - "type": "s1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - ], - "duration": "P1M" -}' -orionCurl --url /v1/registry/registerContext --payload "$payload" --servicePath /s1 -echo -echo - - -echo "11. Register E1/T1/A1 with Service-Path /s2" -echo "===========================================" -payload='{ - "contextRegistrations": [ - { - "entities": [ - { - "type": "T1", - "isPattern": "false", - "id": "E1" - } - ], - "attributes": [ - { - "name": "A1", - "type": "s2" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - ], - "duration": "P1M" -}' -orionCurl --url /v1/registry/registerContext --payload "$payload" --servicePath /s2 -echo -echo - - -echo "12. GET /v1/registry/contextEntities/type/T1/id/E1 with Service-Path /s1" -echo "========================================================================" -orionCurl --url /v1/registry/contextEntities/type/T1/id/E1 --servicePath /s1 -echo -echo - - -echo "13. GET /v1/registry/contextEntities/type/T1/id/E1 with Service-Path /s2" -echo "========================================================================" -orionCurl --url /v1/registry/contextEntities/type/T1/id/E1 --servicePath /s2 -echo -echo - - -echo "14. GET /v1/registry/contextEntities/type/T1/id/E1 with Service-Path /s3 and see it fail" -echo "========================================================================================" -orionCurl --url /v1/registry/contextEntities/type/T1/id/E1 --servicePath /s3 -echo -echo - - -echo "15. GET /v1/registry/contextEntities/type/T1/id/E1 without Service-Path" -echo "=======================================================================" -orionCurl --url /v1/registry/contextEntities/type/T1/id/E1 -echo -echo - - -echo "16. GET /v1/registry/contextEntities/type/T1/id/E1 with Service-Path /#" -echo "=======================================================================" -orionCurl --url /v1/registry/contextEntities/type/T1/id/E1 --servicePath /# -echo -echo - - -echo "17. GET /v1/registry/contextEntities/type/T1/id/E1 with Service-Path /" -echo "======================================================================" -orionCurl --url /v1/registry/contextEntities/type/T1/id/E1 --servicePath / -echo -echo - - ---REGEXPECT-- -01. GET /v1/registry/contextEntities/type/T1/id/E1 and see it fail -======================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 70 - -{ - "errorCode": { - "code": "404", - "reasonPhrase": "No context element found" - } -} - - -02. Register E1/T1/A1 -===================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 62 - -{ - "duration": "P1M", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -03. GET /v1/registry/contextEntities/type/T1/id/E1 and see it work -================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 207 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "slash" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - } - ] -} - - -04. GET /v1/registry/contextEntities/type/T1/id/E1?exist=entity::type and see it work -===================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 207 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "slash" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - } - ] -} - - -05. GET /v1/registry/contextEntities/type/T1/id/E1?entity::type=T1 and see it work -================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 207 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "slash" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - } - ] -} - - -06. GET /v1/registry/contextEntities/type/T1/id/E2 and see it fail -================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 70 - -{ - "errorCode": { - "code": "404", - "reasonPhrase": "No context element found" - } -} - - -07. GET /v1/registry/contextEntities/type/T2/id/E1 and see it fail -================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 70 - -{ - "errorCode": { - "code": "404", - "reasonPhrase": "No context element found" - } -} - - -08. GET /v1/registry/contextEntities/type/T1/id/E1?entity::type=T2 and see it fail -================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 103 - -{ - "errorCode": { - "code": "400", - "details": "non-matching entity::types in URL", - "reasonPhrase": "Bad Request" - } -} - - -09. GET /v1/registry/contextEntities/type/T1/id/E1?!exist=entity::type and see it fail -====================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 115 - -{ - "errorCode": { - "code": "400", - "details": "entity::type cannot be empty for this request", - "reasonPhrase": "Bad Request" - } -} - - -10. Register E1/T1/A1 with Service-Path /s1 -=========================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 62 - -{ - "duration": "P1M", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -11. Register E1/T1/A1 with Service-Path /s2 -=========================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 62 - -{ - "duration": "P1M", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -12. GET /v1/registry/contextEntities/type/T1/id/E1 with Service-Path /s1 -======================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 204 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "s1" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - } - ] -} - - -13. GET /v1/registry/contextEntities/type/T1/id/E1 with Service-Path /s2 -======================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 204 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "s2" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - } - ] -} - - -14. GET /v1/registry/contextEntities/type/T1/id/E1 with Service-Path /s3 and see it fail -======================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 70 - -{ - "errorCode": { - "code": "404", - "reasonPhrase": "No context element found" - } -} - - -15. GET /v1/registry/contextEntities/type/T1/id/E1 without Service-Path -======================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 547 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "slash" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "s1" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "s2" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - } - ] -} - - -16. GET /v1/registry/contextEntities/type/T1/id/E1 with Service-Path /# -======================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 547 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "slash" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "s1" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "s2" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - } - ] -} - - -17. GET /v1/registry/contextEntities/type/T1/id/E1 with Service-Path / -====================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 207 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "slash" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - } - ] -} - - ---TEARDOWN-- -brokerStop CB -dbDrop CB diff --git a/test/functionalTest/cases/0117_convop_using_standard_ops/getContextEntityAttributes.test.DISABLED b/test/functionalTest/cases/0117_convop_using_standard_ops/getContextEntityAttributes.test.DISABLED deleted file mode 100644 index 63aaf022a5..0000000000 --- a/test/functionalTest/cases/0117_convop_using_standard_ops/getContextEntityAttributes.test.DISABLED +++ /dev/null @@ -1,633 +0,0 @@ -# Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U -# -# This file is part of Orion Context Broker. -# -# Orion Context Broker is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Orion Context Broker is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -# General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -# -# For those usages not covered by this license please contact with -# iot_support at tid dot es - -# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh - ---NAME-- -ConvOp getContextEntityAttributes: /v1/registry/contextEntities/{entityId::id}/attributes - ---SHELL-INIT-- -dbInit CB -brokerStart CB - ---SHELL-- - -# -# 01. Register E1/T1/A1 with Service-Path /A1 -# 02. Register E1//A2 (type is empty) with Service-Path /A2 -# 03. Register E1/T2/A3 with Service-Path /A3 -# 04. Discover E1 using /v1/registry/contextEntities/E1/attributes with Service-Path /A1 -# 05. Discover E1 using /v1/registry/contextEntities/E1/attributes with Service-Path /A1,/A2 -# 06. Discover E1 using /v1/registry/contextEntities/E1/attributes with Service-Path /A1,/A3 -# 07. Discover E1 using /v1/registry/contextEntities/E1/attributes with Service-Path /A2,/A3 -# 08. Discover E1 using /v1/registry/contextEntities/E1/attributes with Service-Path /A1,/A2,/A3 -# 09. Discover E1 using /v1/registry/contextEntities/E1/attributes with Service-Path /B1 -# 10. Discover E1 using /v1/registry/contextEntities/E1/attributes without Service-Path -# 11. Discover E1 using /v1/registry/contextEntities/E1/attributes with Service-Path /# -# - -echo "01. Register E1/T1/A1 with Service-Path /A1" -echo "===========================================" -payload='{ - "contextRegistrations": [ - { - "entities": [ - { - "type": "T1", - "isPattern": "false", - "id": "E1" - } - ], - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - ], - "duration": "P1M" -}' -orionCurl --url /v1/registry/registerContext --payload "$payload" --servicePath /A1 -echo -echo - - -echo "02. Register E1//A2 (type is empty) with Service-Path /A2" -echo "=========================================================" -payload='{ - "contextRegistrations": [ - { - "entities": [ - { - "type": "", - "isPattern": "false", - "id": "E1" - } - ], - "attributes": [ - { - "name": "A2", - "type": "string" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - ], - "duration": "P1M" -}' -orionCurl --url /v1/registry/registerContext --payload "$payload" --servicePath /A2 -echo -echo - - -echo "03. Register E1/T2/A3 with Service-Path /A3" -echo "===========================================" -payload='{ - "contextRegistrations": [ - { - "entities": [ - { - "type": "T2", - "isPattern": "false", - "id": "E1" - } - ], - "attributes": [ - { - "name": "A3", - "type": "string" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - ], - "duration": "P1M" -}' -orionCurl --url /v1/registry/registerContext --payload "$payload" --servicePath /A3 -echo -echo - - -echo "04. Discover E1 using /v1/registry/contextEntities/E1/attributes with Service-Path /A1" -echo "======================================================================================" -orionCurl --url "/v1/registry/contextEntities/E1/attributes" --servicePath /A1 -echo -echo - - -echo "05. Discover E1 using /v1/registry/contextEntities/E1/attributes with Service-Path /A1,/A2" -echo "==========================================================================================" -orionCurl --url "/v1/registry/contextEntities/E1/attributes" --servicePath /A1,/A2 -echo -echo - - -echo "06. Discover E1 using /v1/registry/contextEntities/E1/attributes with Service-Path /A1,/A3" -echo "==========================================================================================" -orionCurl --url "/v1/registry/contextEntities/E1/attributes" --servicePath /A1,/A3 -echo -echo - - -echo "07. Discover E1 using /v1/registry/contextEntities/E1/attributes with Service-Path /A2,/A3" -echo "==========================================================================================" -orionCurl --url "/v1/registry/contextEntities/E1/attributes" --servicePath /A2,/A3 -echo -echo - - -echo "08. Discover E1 using /v1/registry/contextEntities/E1/attributes with Service-Path /A1,/A2,/A3" -echo "==============================================================================================" -orionCurl --url "/v1/registry/contextEntities/E1/attributes" --servicePath /A1,/A2,/A3 -echo -echo - - -echo "09. Discover E1 using /v1/registry/contextEntities/E1/attributes with Service-Path /B1" -echo "======================================================================================" -orionCurl --url "/v1/registry/contextEntities/E1/attributes" --servicePath /B1 -echo -echo - - -echo "10. Discover E1 using /v1/registry/contextEntities/E1/attributes without Service-Path" -echo "=====================================================================================" -orionCurl --url "/v1/registry/contextEntities/E1/attributes" -echo -echo - - -echo "11. Discover E1 using /v1/registry/contextEntities/E1/attributes with Service-Path /#" -echo "=====================================================================================" -orionCurl --url "/v1/registry/contextEntities/E1/attributes" --servicePath /# -echo -echo - - ---REGEXPECT-- -01. Register E1/T1/A1 with Service-Path /A1 -=========================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 62 - -{ - "duration": "P1M", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -02. Register E1//A2 (type is empty) with Service-Path /A2 -========================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 62 - -{ - "duration": "P1M", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -03. Register E1/T2/A3 with Service-Path /A3 -=========================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 62 - -{ - "duration": "P1M", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -04. Discover E1 using /v1/registry/contextEntities/E1/attributes with Service-Path /A1 -====================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 208 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - } - ] -} - - -05. Discover E1 using /v1/registry/contextEntities/E1/attributes with Service-Path /A1,/A2 -========================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 380 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A2", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - } - ] -} - - -06. Discover E1 using /v1/registry/contextEntities/E1/attributes with Service-Path /A1,/A3 -========================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 382 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A3", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T2" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - } - ] -} - - -07. Discover E1 using /v1/registry/contextEntities/E1/attributes with Service-Path /A2,/A3 -========================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 380 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A2", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A3", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T2" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - } - ] -} - - -08. Discover E1 using /v1/registry/contextEntities/E1/attributes with Service-Path /A1,/A2,/A3 -============================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 554 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A2", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A3", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T2" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - } - ] -} - - -09. Discover E1 using /v1/registry/contextEntities/E1/attributes with Service-Path /B1 -====================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 70 - -{ - "errorCode": { - "code": "404", - "reasonPhrase": "No context element found" - } -} - - -10. Discover E1 using /v1/registry/contextEntities/E1/attributes without Service-Path -===================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 554 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A2", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A3", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T2" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - } - ] -} - - -11. Discover E1 using /v1/registry/contextEntities/E1/attributes with Service-Path /# -===================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 554 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A2", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A3", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T2" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - } - ] -} - - ---TEARDOWN-- -brokerStop CB -dbDrop CB diff --git a/test/functionalTest/cases/0117_convop_using_standard_ops/getContextEntityTypeAttribute.test.DISABLED b/test/functionalTest/cases/0117_convop_using_standard_ops/getContextEntityTypeAttribute.test.DISABLED deleted file mode 100644 index 6b4a7b236c..0000000000 --- a/test/functionalTest/cases/0117_convop_using_standard_ops/getContextEntityTypeAttribute.test.DISABLED +++ /dev/null @@ -1,768 +0,0 @@ -# Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U -# -# This file is part of Orion Context Broker. -# -# Orion Context Broker is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Orion Context Broker is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -# General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -# -# For those usages not covered by this license please contact with -# iot_support at tid dot es - -# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh - ---NAME-- -ConvOp getContextEntityTypes: /v1/registry/contextEntityTypes/{entityId::type} - ---SHELL-INIT-- -dbInit CB -brokerStart CB - ---SHELL-- - -# -# 01. Register E1/T1/A1 with Service-Path /E1 -# 02. Register E2/T1/A1 with Service-Path /E2 -# 03. Register E3//A1 (type is empty) with Service-Path /E3 -# 04. Register E4/T1/A1 with Service-Path /E4 -# 05. Register E5/T1/A1 with Service-Path /E5 - -# 06. Discover entity type T1 using /v1/registry/contextEntityTypes/T1/attributes/A1 with Service-Path /E1 -# 07. Discover entity type T1 using /v1/registry/contextEntityTypes/T1/attributes/A1 with Service-Path /E1,/E2 -# 08. Discover entity type T1 using /v1/registry/contextEntityTypes/T1/attributes/A1 with Service-Path /E1,/E2,/E3 -# 09. Discover entity type T1 using /v1/registry/contextEntityTypes/T1/attributes/A1 with Service-Path /E1,/E2,/E3,/E4 -# 10. Discover entity type T1 using /v1/registry/contextEntityTypes/T1/attributes/A1 with Service-Path /E1,/E2,/E3,/E4,/E5 -# 11. Discover entity type T1 using /v1/registry/contextEntityTypes/T1/attributes/A1 without Service-Path -# 12. Discover entity type T2 using /v1/registry/contextEntityTypes/T1/attributes/A1 with Service-Path /# -# - -echo "01. Register E1/T1/A1 with Service-Path /E1" -echo "===========================================" -payload='{ - "contextRegistrations": [ - { - "entities": [ - { - "type": "T1", - "isPattern": "false", - "id": "E1" - } - ], - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - ], - "duration": "P1M" -}' -orionCurl --url /v1/registry/registerContext --payload "$payload" --servicePath /E1 -echo -echo - - -echo "02. Register E2/T1/A1 with Service-Path /E2" -echo "===========================================" -payload='{ - "contextRegistrations": [ - { - "entities": [ - { - "type": "T1", - "isPattern": "false", - "id": "E2" - } - ], - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - ], - "duration": "P1M" -}' -orionCurl --url /v1/registry/registerContext --payload "$payload" --servicePath /E2 -echo -echo - - -echo "03. Register E3//A1 (type is empty) with Service-Path /E3" -echo "=========================================================" -payload='{ - "contextRegistrations": [ - { - "entities": [ - { - "type": "", - "isPattern": "false", - "id": "E3" - } - ], - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - ], - "duration": "P1M" -}' -orionCurl --url /v1/registry/registerContext --payload "$payload" --servicePath /E3 -echo -echo - - -echo "04. Register E4/T1/A1 with Service-Path /E4" -echo "===========================================" -payload='{ - "contextRegistrations": [ - { - "entities": [ - { - "type": "T1", - "isPattern": "false", - "id": "E4" - } - ], - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - ], - "duration": "P1M" -}' -orionCurl --url /v1/registry/registerContext --payload "$payload" --servicePath /E4 -echo -echo - - -echo "05. Register E5/T1/A1 with Service-Path /E5" -echo "===========================================" -payload='{ - "contextRegistrations": [ - { - "entities": [ - { - "type": "T1", - "isPattern": "false", - "id": "E5" - } - ], - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - ], - "duration": "P1M" -}' -orionCurl --url /v1/registry/registerContext --payload "$payload" --servicePath /E5 -echo -echo - - -echo "06. Discover entity type T1 using /v1/registry/contextEntityTypes/T1/attributes/A1 with Service-Path /E1" -echo "========================================================================================================" -orionCurl --url /v1/registry/contextEntityTypes/T1/attributes/A1 --servicePath /E1 -echo -echo - - -echo "07. Discover entity type T1 using /v1/registry/contextEntityTypes/T1/attributes/A1 with Service-Path /E1,/E2" -echo "============================================================================================================" -orionCurl --url /v1/registry/contextEntityTypes/T1/attributes/A1 --servicePath /E1,/E2 -echo -echo - - -echo "08. Discover entity type T1 using /v1/registry/contextEntityTypes/T1/attributes/A1 with Service-Path /E1,/E2,/E3" -echo "================================================================================================================" -orionCurl --url /v1/registry/contextEntityTypes/T1/attributes/A1 --servicePath /E1,/E2,/E3 -echo -echo - - -echo "09. Discover entity type T1 using /v1/registry/contextEntityTypes/T1/attributes/A1 with Service-Path /E1,/E2,/E3,/E4" -echo "====================================================================================================================" -orionCurl --url /v1/registry/contextEntityTypes/T1/attributes/A1 --servicePath /E1,/E2,/E3,/E4 -echo -echo - - -echo "10. Discover entity type T1 using /v1/registry/contextEntityTypes/T1/attributes/A1 with Service-Path /E1,/E2,/E3,/E4,/E5" -echo "========================================================================================================================" -orionCurl --url /v1/registry/contextEntityTypes/T1/attributes/A1 --servicePath /E1,/E2,/E3,/E4,/E5 -echo -echo - - -echo "11. Discover entity type T1 using /v1/registry/contextEntityTypes/T1/attributes/A1 without Service-Path" -echo "=======================================================================================================" -orionCurl --url /v1/registry/contextEntityTypes/T1/attributes/A1 -echo -echo - - -echo "12. Discover entity type T2 using /v1/registry/contextEntityTypes/T1/attributes/A1 with Service-Path /#" -echo "=======================================================================================================" -orionCurl --url /v1/registry/contextEntityTypes/T1/attributes/A1 --servicePath /# -echo -echo - - ---REGEXPECT-- -01. Register E1/T1/A1 with Service-Path /E1 -=========================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 62 - -{ - "duration": "P1M", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -02. Register E2/T1/A1 with Service-Path /E2 -=========================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 62 - -{ - "duration": "P1M", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -03. Register E3//A1 (type is empty) with Service-Path /E3 -========================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 62 - -{ - "duration": "P1M", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -04. Register E4/T1/A1 with Service-Path /E4 -=========================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 62 - -{ - "duration": "P1M", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -05. Register E5/T1/A1 with Service-Path /E5 -=========================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 62 - -{ - "duration": "P1M", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -06. Discover entity type T1 using /v1/registry/contextEntityTypes/T1/attributes/A1 with Service-Path /E1 -======================================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 208 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - } - ] -} - - -07. Discover entity type T1 using /v1/registry/contextEntityTypes/T1/attributes/A1 with Service-Path /E1,/E2 -============================================================================================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 382 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "entities": [ - { - "id": "E2", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - } - ] -} - - -08. Discover entity type T1 using /v1/registry/contextEntityTypes/T1/attributes/A1 with Service-Path /E1,/E2,/E3 -================================================================================================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 382 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "entities": [ - { - "id": "E2", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - } - ] -} - - -09. Discover entity type T1 using /v1/registry/contextEntityTypes/T1/attributes/A1 with Service-Path /E1,/E2,/E3,/E4 -==================================================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 556 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "entities": [ - { - "id": "E2", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "entities": [ - { - "id": "E4", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - } - ] -} - - -10. Discover entity type T1 using /v1/registry/contextEntityTypes/T1/attributes/A1 with Service-Path /E1,/E2,/E3,/E4,/E5 -======================================================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 730 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "entities": [ - { - "id": "E2", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "entities": [ - { - "id": "E4", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "entities": [ - { - "id": "E5", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - } - ] -} - - -11. Discover entity type T1 using /v1/registry/contextEntityTypes/T1/attributes/A1 without Service-Path -======================================================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 730 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "entities": [ - { - "id": "E2", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "entities": [ - { - "id": "E4", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "entities": [ - { - "id": "E5", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - } - ] -} - - -12. Discover entity type T2 using /v1/registry/contextEntityTypes/T1/attributes/A1 with Service-Path /# -======================================================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 730 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "entities": [ - { - "id": "E2", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "entities": [ - { - "id": "E4", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "entities": [ - { - "id": "E5", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - } - ] -} - - ---TEARDOWN-- -brokerStop CB -dbDrop CB diff --git a/test/functionalTest/cases/0117_convop_using_standard_ops/getContextEntityTypes.test.DISABLED b/test/functionalTest/cases/0117_convop_using_standard_ops/getContextEntityTypes.test.DISABLED deleted file mode 100644 index e7ced2686d..0000000000 --- a/test/functionalTest/cases/0117_convop_using_standard_ops/getContextEntityTypes.test.DISABLED +++ /dev/null @@ -1,645 +0,0 @@ -# Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U -# -# This file is part of Orion Context Broker. -# -# Orion Context Broker is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Orion Context Broker is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -# General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -# -# For those usages not covered by this license please contact with -# iot_support at tid dot es - -# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh - ---NAME-- -ConvOp getContextEntityTypes: /v1/registry/contextEntityTypes/{entityId::type} - ---SHELL-INIT-- -dbInit CB -brokerStart CB - ---SHELL-- - -# -# 01. Register E1/T1/A1 with Service-Path /A1 -# 02. Register E1/T1/A2 with Service-Path /A2 -# 03. Register E1//A3 (type is empty) with Service-Path /A3 -# 04. Register E1/T2/A4 with Service-Path /A4 -# 05. Register E1/T2/A5 with Service-Path /A5 -# 06. Discover entity type T1 using /v1/registry/contextEntityTypes/T1 with Service-Path /A1 -# 07. Discover entity type T1 using /v1/registry/contextEntityTypes/T1 with Service-Path /A2 -# 08. Discover entity type T1 using /v1/registry/contextEntityTypes/T1 with Service-Path /A1,/A2 -# 09. Discover entity type T2 using /v1/registry/contextEntityTypes/T2 with Service-Path /A4 -# 10. Discover entity type T2 using /v1/registry/contextEntityTypes/T2 with Service-Path /A5 -# 11. Discover entity type T2 using /v1/registry/contextEntityTypes/T2 with Service-Path /A4,/A5 -# 12. Discover entity type T1 using /v1/registry/contextEntityTypes/T1 without Service-Path -# 13. Discover entity type T2 using /v1/registry/contextEntityTypes/T2 with Service-Path /# -# - -echo "01. Register E1/T1/A1 with Service-Path /A1" -echo "===========================================" -payload='{ - "contextRegistrations": [ - { - "entities": [ - { - "type": "T1", - "isPattern": "false", - "id": "E1" - } - ], - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - ], - "duration": "P1M" -}' -orionCurl --url /v1/registry/registerContext --payload "$payload" --servicePath /A1 -echo -echo - - -echo "02. Register E1/T1/A2 with Service-Path /A2" -echo "===========================================" -payload='{ - "contextRegistrations": [ - { - "entities": [ - { - "type": "T1", - "isPattern": "false", - "id": "E1" - } - ], - "attributes": [ - { - "name": "A2", - "type": "string" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - ], - "duration": "P1M" -}' -orionCurl --url /v1/registry/registerContext --payload "$payload" --servicePath /A2 -echo -echo - - -echo "03. Register E1//A3 (type is empty) with Service-Path /A3" -echo "=========================================================" -payload='{ - "contextRegistrations": [ - { - "entities": [ - { - "type": "", - "isPattern": "false", - "id": "E1" - } - ], - "attributes": [ - { - "name": "A3", - "type": "string" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - ], - "duration": "P1M" -}' -orionCurl --url /v1/registry/registerContext --payload "$payload" --servicePath /A3 -echo -echo - - -echo "04. Register E1/T2/A4 with Service-Path /A4" -echo "===========================================" -payload='{ - "contextRegistrations": [ - { - "entities": [ - { - "type": "T2", - "isPattern": "false", - "id": "E1" - } - ], - "attributes": [ - { - "name": "A4", - "type": "string" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - ], - "duration": "P1M" -}' -orionCurl --url /v1/registry/registerContext --payload "$payload" --servicePath /A4 -echo -echo - - -echo "05. Register E1/T2/A5 with Service-Path /A5" -echo "===========================================" -payload='{ - "contextRegistrations": [ - { - "entities": [ - { - "type": "T2", - "isPattern": "false", - "id": "E1" - } - ], - "attributes": [ - { - "name": "A5", - "type": "string" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - ], - "duration": "P1M" -}' -orionCurl --url /v1/registry/registerContext --payload "$payload" --servicePath /A5 -echo -echo - - -echo "06. Discover entity type T1 using /v1/registry/contextEntityTypes/T1 with Service-Path /A1" -echo "==========================================================================================" -orionCurl --url "/v1/registry/contextEntityTypes/T1" --servicePath /A1 -echo -echo - - -echo "07. Discover entity type T1 using /v1/registry/contextEntityTypes/T1 with Service-Path /A2" -echo "==========================================================================================" -orionCurl --url "/v1/registry/contextEntityTypes/T1" --servicePath /A2 -echo -echo - - -echo "08. Discover entity type T1 using /v1/registry/contextEntityTypes/T1 with Service-Path /A1,/A2" -echo "==============================================================================================" -orionCurl --url "/v1/registry/contextEntityTypes/T1" --servicePath /A1,/A2 -echo -echo - - -echo "09. Discover entity type T2 using /v1/registry/contextEntityTypes/T2 with Service-Path /A4" -echo "==========================================================================================" -orionCurl --url "/v1/registry/contextEntityTypes/T2" --servicePath /A4 -echo -echo - - -echo "10. Discover entity type T2 using /v1/registry/contextEntityTypes/T2 with Service-Path /A5" -echo "==========================================================================================" -orionCurl --url "/v1/registry/contextEntityTypes/T2" --servicePath /A5 -echo -echo - - -echo "11. Discover entity type T2 using /v1/registry/contextEntityTypes/T2 with Service-Path /A4,/A5" -echo "==============================================================================================" -orionCurl --url "/v1/registry/contextEntityTypes/T2" --servicePath /A4,/A5 -echo -echo - - -echo "12. Discover entity type T1 using /v1/registry/contextEntityTypes/T1 without Service-Path" -echo "=========================================================================================" -orionCurl --url "/v1/registry/contextEntityTypes/T1" -echo -echo - - -echo "13. Discover entity type T2 using /v1/registry/contextEntityTypes/T2 with Service-Path /#" -echo "=========================================================================================" -orionCurl --url "/v1/registry/contextEntityTypes/T2" --servicePath /# -echo -echo - - ---REGEXPECT-- -01. Register E1/T1/A1 with Service-Path /A1 -=========================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 62 - -{ - "duration": "P1M", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -02. Register E1/T1/A2 with Service-Path /A2 -=========================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 62 - -{ - "duration": "P1M", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -03. Register E1//A3 (type is empty) with Service-Path /A3 -========================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 62 - -{ - "duration": "P1M", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -04. Register E1/T2/A4 with Service-Path /A4 -=========================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 62 - -{ - "duration": "P1M", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -05. Register E1/T2/A5 with Service-Path /A5 -=========================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 62 - -{ - "duration": "P1M", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -06. Discover entity type T1 using /v1/registry/contextEntityTypes/T1 with Service-Path /A1 -========================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 208 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - } - ] -} - - -07. Discover entity type T1 using /v1/registry/contextEntityTypes/T1 with Service-Path /A2 -========================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 208 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A2", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - } - ] -} - - -08. Discover entity type T1 using /v1/registry/contextEntityTypes/T1 with Service-Path /A1,/A2 -============================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 382 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A2", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - } - ] -} - - -09. Discover entity type T2 using /v1/registry/contextEntityTypes/T2 with Service-Path /A4 -========================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 208 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A4", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T2" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - } - ] -} - - -10. Discover entity type T2 using /v1/registry/contextEntityTypes/T2 with Service-Path /A5 -========================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 208 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A5", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T2" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - } - ] -} - - -11. Discover entity type T2 using /v1/registry/contextEntityTypes/T2 with Service-Path /A4,/A5 -============================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 382 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A4", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T2" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A5", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T2" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - } - ] -} - - -12. Discover entity type T1 using /v1/registry/contextEntityTypes/T1 without Service-Path -========================================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 382 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A2", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - } - ] -} - - -13. Discover entity type T2 using /v1/registry/contextEntityTypes/T2 with Service-Path /# -========================================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 382 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A4", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T2" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A5", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T2" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - } - ] -} - - ---TEARDOWN-- -brokerStop CB -dbDrop CB diff --git a/test/functionalTest/cases/0117_convop_using_standard_ops/getEntityByIdAttributeByName.test.DISABLED b/test/functionalTest/cases/0117_convop_using_standard_ops/getEntityByIdAttributeByName.test.DISABLED deleted file mode 100644 index b0cb55d43b..0000000000 --- a/test/functionalTest/cases/0117_convop_using_standard_ops/getEntityByIdAttributeByName.test.DISABLED +++ /dev/null @@ -1,563 +0,0 @@ -# Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U -# -# This file is part of Orion Context Broker. -# -# Orion Context Broker is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Orion Context Broker is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -# General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -# -# For those usages not covered by this license please contact with -# iot_support at tid dot es - -# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh - ---NAME-- -ConvOp getEntityByIdAttributeByName: /v1/registry/contextEntities/{entityId::id}/attributes/{attributeName} - ---SHELL-INIT-- -dbInit CB -brokerStart CB - ---SHELL-- - -# -# 01. Register E1/T1/A1 with Service-Path /A1 -# 02. Register E1//A2 (type is empty) with Service-Path /A2 -# 03. Register E1/T2/A3 with Service-Path /A3 - -# 04. Discover E1 using /v1/registry/contextEntities/E1/attributes/A1 with Service-Path /A1 -# 05. Discover E1 using /v1/registry/contextEntities/E1/attributes/A1 with Service-Path /A1,/A2 -# 06. Discover E1 using /v1/registry/contextEntities/E1/attributes/A1 with Service-Path /A2 - -# 07. Discover E1 using /v1/registry/contextEntities/E1/attributes/A2 with Service-Path /A1 -# 08. Discover E1 using /v1/registry/contextEntities/E1/attributes/A2 with Service-Path /A1,/A2 -# 09. Discover E1 using /v1/registry/contextEntities/E1/attributes/A2 with Service-Path /A2 - -# 10. Discover E1 using /v1/registry/contextEntities/E1/attributes/A3 with Service-Path /A2 -# 11. Discover E1 using /v1/registry/contextEntities/E1/attributes/A3 with Service-Path /A2,/A3 -# 12. Discover E1 using /v1/registry/contextEntities/E1/attributes/A3 with Service-Path /A3 - -# 13. Discover E1 using /v1/registry/contextEntities/E1/attributes/A1 without Service-Path -# 14. Discover E1 using /v1/registry/contextEntities/E1/attributes/A2 with Service-Path /# -# - -echo "01. Register E1/T1/A1 with Service-Path /A1" -echo "===========================================" -payload='{ - "contextRegistrations": [ - { - "entities": [ - { - "type": "T1", - "isPattern": "false", - "id": "E1" - } - ], - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - ], - "duration": "P1M" -}' -orionCurl --url /v1/registry/registerContext --payload "$payload" --servicePath /A1 -echo -echo - - -echo "02. Register E1//A2 (type is empty) with Service-Path /A2" -echo "=========================================================" -payload='{ - "contextRegistrations": [ - { - "entities": [ - { - "type": "", - "isPattern": "false", - "id": "E1" - } - ], - "attributes": [ - { - "name": "A2", - "type": "string" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - ], - "duration": "P1M" -}' -orionCurl --url /v1/registry/registerContext --payload "$payload" --servicePath /A2 -echo -echo - - -echo "03. Register E1/T2/A3 with Service-Path /A3" -echo "===========================================" -payload='{ - "contextRegistrations": [ - { - "entities": [ - { - "type": "T2", - "isPattern": "false", - "id": "E1" - } - ], - "attributes": [ - { - "name": "A3", - "type": "string" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - ], - "duration": "P1M" -}' -orionCurl --url /v1/registry/registerContext --payload "$payload" --servicePath /A3 -echo -echo - - -echo "04. Discover E1 using /v1/registry/contextEntities/E1/attributes/A1 with Service-Path /A1" -echo "=========================================================================================" -orionCurl --url "/v1/registry/contextEntities/E1/attributes/A1" --servicePath /A1 -echo -echo - - -echo "05. Discover E1 using /v1/registry/contextEntities/E1/attributes/A1 with Service-Path /A1,/A2" -echo "=============================================================================================" -orionCurl --url "/v1/registry/contextEntities/E1/attributes/A1" --servicePath /A1,/A2 -echo -echo - - -echo "06. Discover E1 using /v1/registry/contextEntities/E1/attributes/A1 with Service-Path /A2" -echo "=========================================================================================" -orionCurl --url "/v1/registry/contextEntities/E1/attributes/A1" --servicePath /A2 -echo -echo - - -echo "07. Discover E1 using /v1/registry/contextEntities/E1/attributes/A2 with Service-Path /A1" -echo "=========================================================================================" -orionCurl --url "/v1/registry/contextEntities/E1/attributes/A2" --servicePath /A1 -echo -echo - - -echo "08. Discover E1 using /v1/registry/contextEntities/E1/attributes/A2 with Service-Path /A1,/A2" -echo "=============================================================================================" -orionCurl --url "/v1/registry/contextEntities/E1/attributes/A2" --servicePath /A1,/A2 -echo -echo - - -echo "09. Discover E1 using /v1/registry/contextEntities/E1/attributes/A2 with Service-Path /A2" -echo "=========================================================================================" -orionCurl --url "/v1/registry/contextEntities/E1/attributes/A2" --servicePath /A2 -echo -echo - - -echo "10. Discover E1 using /v1/registry/contextEntities/E1/attributes/A3 with Service-Path /A2" -echo "=========================================================================================" -orionCurl --url "/v1/registry/contextEntities/E1/attributes/A3" --servicePath /A2 -echo -echo - - -echo "11. Discover E1 using /v1/registry/contextEntities/E1/attributes/A3 with Service-Path /A2,/A3" -echo "=============================================================================================" -orionCurl --url "/v1/registry/contextEntities/E1/attributes/A3" --servicePath /A2,/A3 -echo -echo - - -echo "12. Discover E1 using /v1/registry/contextEntities/E1/attributes/A3 with Service-Path /A3" -echo "=========================================================================================" -orionCurl --url "/v1/registry/contextEntities/E1/attributes/A3" --servicePath /A3 -echo -echo - - -echo "13. Discover E1 using /v1/registry/contextEntities/E1/attributes/A1 without Service-Path" -echo "========================================================================================" -orionCurl --url "/v1/registry/contextEntities/E1/attributes/A1" -echo -echo - - -echo "14. Discover E1 using /v1/registry/contextEntities/E1/attributes/A1 with Service-Path /#" -echo "========================================================================================" -orionCurl --url "/v1/registry/contextEntities/E1/attributes/A1" --servicePath /# -echo -echo - - ---REGEXPECT-- -01. Register E1/T1/A1 with Service-Path /A1 -=========================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 62 - -{ - "duration": "P1M", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -02. Register E1//A2 (type is empty) with Service-Path /A2 -========================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 62 - -{ - "duration": "P1M", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -03. Register E1/T2/A3 with Service-Path /A3 -=========================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 62 - -{ - "duration": "P1M", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -04. Discover E1 using /v1/registry/contextEntities/E1/attributes/A1 with Service-Path /A1 -========================================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 208 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - } - ] -} - - -05. Discover E1 using /v1/registry/contextEntities/E1/attributes/A1 with Service-Path /A1,/A2 -============================================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 208 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - } - ] -} - - -06. Discover E1 using /v1/registry/contextEntities/E1/attributes/A1 with Service-Path /A2 -========================================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 70 - -{ - "errorCode": { - "code": "404", - "reasonPhrase": "No context element found" - } -} - - -07. Discover E1 using /v1/registry/contextEntities/E1/attributes/A2 with Service-Path /A1 -========================================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 70 - -{ - "errorCode": { - "code": "404", - "reasonPhrase": "No context element found" - } -} - - -08. Discover E1 using /v1/registry/contextEntities/E1/attributes/A2 with Service-Path /A1,/A2 -============================================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 206 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A2", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - } - ] -} - - -09. Discover E1 using /v1/registry/contextEntities/E1/attributes/A2 with Service-Path /A2 -========================================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 206 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A2", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - } - ] -} - - -10. Discover E1 using /v1/registry/contextEntities/E1/attributes/A3 with Service-Path /A2 -========================================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 70 - -{ - "errorCode": { - "code": "404", - "reasonPhrase": "No context element found" - } -} - - -11. Discover E1 using /v1/registry/contextEntities/E1/attributes/A3 with Service-Path /A2,/A3 -============================================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 208 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A3", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T2" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - } - ] -} - - -12. Discover E1 using /v1/registry/contextEntities/E1/attributes/A3 with Service-Path /A3 -========================================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 208 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A3", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T2" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - } - ] -} - - -13. Discover E1 using /v1/registry/contextEntities/E1/attributes/A1 without Service-Path -======================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 208 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - } - ] -} - - -14. Discover E1 using /v1/registry/contextEntities/E1/attributes/A1 with Service-Path /# -======================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 208 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/abc" - } - } - ] -} - - ---TEARDOWN-- -brokerStop CB -dbDrop CB diff --git a/test/functionalTest/cases/0117_convop_using_standard_ops/getEntityByIdAttributeByNameWithTypeAndId.test.DISABLED b/test/functionalTest/cases/0117_convop_using_standard_ops/getEntityByIdAttributeByNameWithTypeAndId.test.DISABLED deleted file mode 100644 index 095c328580..0000000000 --- a/test/functionalTest/cases/0117_convop_using_standard_ops/getEntityByIdAttributeByNameWithTypeAndId.test.DISABLED +++ /dev/null @@ -1,582 +0,0 @@ -# Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U -# -# This file is part of Orion Context Broker. -# -# Orion Context Broker is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Orion Context Broker is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -# General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -# -# For those usages not covered by this license please contact with -# iot_support at tid dot es - -# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh - ---NAME-- -ConvOp getEntityByIdAttributeByNameWithTypeAndId: GET /v1/registry/contextEntities/type/{entity::type}/id/{entity::id}/attributes/{attribute::name} - ---SHELL-INIT-- -dbInit CB -dbInit CP1 -brokerStart CB 0 -brokerStart CP1 0 - ---SHELL-- - -# -# 01. GET /v1/registry/contextEntities/type/T1/id/E1/attributes/A1 and see it fail -# 02. Register E1/T1/A1 (without service-path) -# 03. GET /v1/registry/contextEntities/type/T1/id/E1/attributes/A1 and see it work -# 04. GET /v1/registry/contextEntities/type/T1/id/E1/attributes/A1?exist=entity::type and see it work -# 05. GET /v1/registry/contextEntities/type/T1/id/E1/attributes/A1?entity::type=T1 and see it work -# 06. GET /v1/registry/contextEntities/type/T1/id/E1/attributes/A1?!exist=entity::type and see it fail -# 07. GET /v1/registry/contextEntities/type/T1/id/E1/attributes/A1?entity::type=T2 and see it fail -# 08. GET /v1/registry/contextEntities/type/T1/id/E1/attributes/A1?attributesFormat=object and see it work -# 09. Register E1/T1/A1, service-path /s1 (service-path /s1) -# 10. GET /v1/registry/contextEntities/type/T1/id/E1/attributes/A1, without service-path, see two hits -# 11. GET /v1/registry/contextEntities/type/T1/id/E1/attributes/A1, with service-path /#, see two hits -# 12. GET /v1/registry/contextEntities/type/T1/id/E1/attributes/A1, with service-path /, see one hit -# 13. GET /v1/registry/contextEntities/type/T1/id/E1/attributes/A1, with service-path /s1, see one hit -# 14. GET /v1/registry/contextEntities/type/T1/id/E1/attributes/A1, with service-path /s2, see no hits -# - -echo "01. GET /v1/registry/contextEntities/type/T1/id/E1/attributes/A1 and see it fail" -echo "================================================================================" -orionCurl --url /v1/registry/contextEntities/type/T1/id/E1/attributes/A1 -echo -echo - - -echo "02. Register E1/T1/A1 (without service-path)" -echo "============================================" -payload='{ - "contextRegistrations": [ - { - "entities": [ - { - "type": "T1", - "isPattern": "false", - "id": "E1" - } - ], - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "providingApplication": "http://kz.tid.es/spath-none" - } - ], - "duration": "P1M" -}' -orionCurl --url /v1/registry/registerContext --payload "$payload" -echo -echo - - -echo "03. GET /v1/registry/contextEntities/type/T1/id/E1/attributes/A1 and see it work" -echo "================================================================================" -orionCurl --url /v1/registry/contextEntities/type/T1/id/E1/attributes/A1 -echo -echo - - -echo "04. GET /v1/registry/contextEntities/type/T1/id/E1/attributes/A1?exist=entity::type and see it work" -echo "===================================================================================================" -orionCurl --url /v1/registry/contextEntities/type/T1/id/E1/attributes/A1?exist=entity::type -echo -echo - - -echo "05. GET /v1/registry/contextEntities/type/T1/id/E1/attributes/A1?entity::type=T1 and see it work" -echo "================================================================================================" -orionCurl --url /v1/registry/contextEntities/type/T1/id/E1/attributes/A1?entity::type=T1 -echo -echo - - -echo "06. GET /v1/registry/contextEntities/type/T1/id/E1/attributes/A1?!exist=entity::type and see it fail" -echo "====================================================================================================" -orionCurl --url /v1/registry/contextEntities/type/T1/id/E1/attributes/A1?!exist=entity::type -echo -echo - - -echo "07. GET /v1/registry/contextEntities/type/T1/id/E1/attributes/A1?entity::type=T2 and see it fail" -echo "================================================================================================" -orionCurl --url /v1/registry/contextEntities/type/T1/id/E1/attributes/A1?entity::type=T2 -echo -echo - - -echo "08. GET /v1/registry/contextEntities/type/T1/id/E1/attributes/A1?attributesFormat=object and see it work" -echo "========================================================================================================" -orionCurl --url /v1/registry/contextEntities/type/T1/id/E1/attributes/A1?attributesFormat=object -echo -echo - - -echo "09. Register E1/T1/A1, service-path /s1 (service-path /s1)" -echo "==========================================================" -payload='{ - "contextRegistrations": [ - { - "entities": [ - { - "type": "T1", - "isPattern": "false", - "id": "E1" - } - ], - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "providingApplication": "http://kz.tid.es/spath-s1" - } - ], - "duration": "P1M" -}' -orionCurl --url /v1/registry/registerContext --payload "$payload" --servicePath /s1 -echo -echo - - -echo "10. GET /v1/registry/contextEntities/type/T1/id/E1/attributes/A1, without service-path, see two hits" -echo "====================================================================================================" -orionCurl --url /v1/registry/contextEntities/type/T1/id/E1/attributes/A1 -echo -echo - - -echo "11. GET /v1/registry/contextEntities/type/T1/id/E1/attributes/A1, with service-path /#, see two hits" -echo "====================================================================================================" -orionCurl --url /v1/registry/contextEntities/type/T1/id/E1/attributes/A1 --servicePath /# -echo -echo - - -echo "12. GET /v1/registry/contextEntities/type/T1/id/E1/attributes/A1, with service-path /, see one hit" -echo "==================================================================================================" -orionCurl --url /v1/registry/contextEntities/type/T1/id/E1/attributes/A1 --servicePath / -echo -echo - - -echo "13. GET /v1/registry/contextEntities/type/T1/id/E1/attributes/A1, with service-path /s1, see one hit" -echo "====================================================================================================" -orionCurl --url /v1/registry/contextEntities/type/T1/id/E1/attributes/A1 --servicePath /s1 -echo -echo - - -echo "14. GET /v1/registry/contextEntities/type/T1/id/E1/attributes/A1, with service-path /s2, see no hits" -echo "====================================================================================================" -orionCurl --url /v1/registry/contextEntities/type/T1/id/E1/attributes/A1 --servicePath /s2 -echo -echo - - ---REGEXPECT-- -01. GET /v1/registry/contextEntities/type/T1/id/E1/attributes/A1 and see it fail -================================================================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 70 - -{ - "errorCode": { - "code": "404", - "reasonPhrase": "No context element found" - } -} - - -02. Register E1/T1/A1 (without service-path) -============================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 62 - -{ - "duration": "P1M", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -03. GET /v1/registry/contextEntities/type/T1/id/E1/attributes/A1 and see it work -================================================================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 215 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/spath-none" - } - } - ] -} - - -04. GET /v1/registry/contextEntities/type/T1/id/E1/attributes/A1?exist=entity::type and see it work -=================================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 215 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/spath-none" - } - } - ] -} - - -05. GET /v1/registry/contextEntities/type/T1/id/E1/attributes/A1?entity::type=T1 and see it work -================================================================================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 215 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/spath-none" - } - } - ] -} - - -06. GET /v1/registry/contextEntities/type/T1/id/E1/attributes/A1?!exist=entity::type and see it fail -==================================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 115 - -{ - "errorCode": { - "code": "400", - "details": "entity::type cannot be empty for this request", - "reasonPhrase": "Bad Request" - } -} - - -07. GET /v1/registry/contextEntities/type/T1/id/E1/attributes/A1?entity::type=T2 and see it fail -================================================================================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 103 - -{ - "errorCode": { - "code": "400", - "details": "non-matching entity::types in URL", - "reasonPhrase": "Bad Request" - } -} - - -08. GET /v1/registry/contextEntities/type/T1/id/E1/attributes/A1?attributesFormat=object and see it work -======================================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 215 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/spath-none" - } - } - ] -} - - -09. Register E1/T1/A1, service-path /s1 (service-path /s1) -========================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 62 - -{ - "duration": "P1M", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -10. GET /v1/registry/contextEntities/type/T1/id/E1/attributes/A1, without service-path, see two hits -==================================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 394 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/spath-none" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/spath-s1" - } - } - ] -} - - -11. GET /v1/registry/contextEntities/type/T1/id/E1/attributes/A1, with service-path /#, see two hits -==================================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 394 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/spath-none" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/spath-s1" - } - } - ] -} - - -12. GET /v1/registry/contextEntities/type/T1/id/E1/attributes/A1, with service-path /, see one hit -================================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 215 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/spath-none" - } - } - ] -} - - -13. GET /v1/registry/contextEntities/type/T1/id/E1/attributes/A1, with service-path /s1, see one hit -==================================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 213 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/spath-s1" - } - } - ] -} - - -14. GET /v1/registry/contextEntities/type/T1/id/E1/attributes/A1, with service-path /s2, see no hits -==================================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 70 - -{ - "errorCode": { - "code": "404", - "reasonPhrase": "No context element found" - } -} - - ---TEARDOWN-- -brokerStop CB -brokerStop CP1 -dbDrop CB -dbDrop CP1 diff --git a/test/functionalTest/cases/0117_convop_using_standard_ops/getEntityTypes.test.DISABLED b/test/functionalTest/cases/0117_convop_using_standard_ops/getEntityTypes.test.DISABLED deleted file mode 100644 index 3fd0eb6a6a..0000000000 --- a/test/functionalTest/cases/0117_convop_using_standard_ops/getEntityTypes.test.DISABLED +++ /dev/null @@ -1,578 +0,0 @@ -# Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U -# -# This file is part of Orion Context Broker. -# -# Orion Context Broker is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Orion Context Broker is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -# General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -# -# For those usages not covered by this license please contact with -# iot_support at tid dot es - -# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh - ---NAME-- -ExtraOp getEntityTypes: GET /v1/contextTypes - ---SHELL-INIT-- -dbInit CB -brokerStart CB 0 - ---SHELL-- - -# -# 01. GET /v1/contextTypes and see a list of zero types -# 02. POST /v1/updateContext, creating E1-T1-A1+A2 -# 03. POST /v1/updateContext, creating E1-T2-A1 -# 04. POST /v1/updateContext, creating E1-T3-A1+A2 -# 05. GET /v1/contextTypes and see a list of three types -# 06. POST /v1/updateContext, creating E1-T4-A1, servicePath /s1 -# 07. POST /v1/updateContext, creating E1-T5-A1, servicePath /s2 -# 08. GET /v1/contextTypes, servicePath /s1 and see a list of one type (T4) -# 09. GET /v1/contextTypes, servicePath /s2 and see a list of one type (T5) -# 10. GET /v1/contextTypes and see a list of five types -# 11. GET /v1/contextTypes?collapse=true and see the list without attributes -# - -echo "01. GET /v1/contextTypes and see a list of zero types" -echo "=====================================================" -orionCurl --url /v1/contextTypes -echo -echo - - -echo "02. POST /v1/updateContext, creating E1-T1-A1+A2" -echo "================================================" -payload='{ - "contextElements": [ - { - "type": "T1", - "id": "E1", - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "1" - }, - { - "name": "A2", - "type": "string", - "value": "2" - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" -echo -echo - - -echo "03. POST /v1/updateContext, creating E1-T2-A1" -echo "=============================================" -payload='{ - "contextElements": [ - { - "type": "T2", - "id": "E1", - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "21" - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" -echo -echo - - -echo "04. POST /v1/updateContext, creating E1-T3-A1+A2" -echo "================================================" -payload='{ - "contextElements": [ - { - "type": "T3", - "id": "E1", - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "31" - }, - { - "name": "A2", - "type": "string", - "value": "32" - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" -echo -echo - - -echo "05. GET /v1/contextTypes and see a list of three types" -echo "======================================================" -orionCurl --url /v1/contextTypes -echo -echo - - -echo "06. POST /v1/updateContext, creating E1-T4-A1, servicePath /s1" -echo "==============================================================" -payload='{ - "contextElements": [ - { - "type": "T4", - "id": "E1", - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "s1" - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" --servicePath /s1 -echo -echo - - -echo "07. POST /v1/updateContext, creating E1-T5-A1, servicePath /s2" -echo "==============================================================" -payload='{ - "contextElements": [ - { - "type": "T5", - "id": "E1", - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "s2" - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" --servicePath /s2 -echo -echo - - -echo "08. GET /v1/contextTypes, servicePath /s1 and see a list of one type (T4)" -echo "=========================================================================" -orionCurl --url /v1/contextTypes --servicePath /s1 -echo -echo - - -echo "09. GET /v1/contextTypes, servicePath /s2 and see a list of one type (T5)" -echo "=========================================================================" -orionCurl --url /v1/contextTypes --servicePath /s2 -echo -echo - - -echo "10. GET /v1/contextTypes and see a list of five types" -echo "=====================================================" -orionCurl --url /v1/contextTypes -echo -echo - -echo "11. GET /v1/contextTypes?collapse=true and see the list without attributes" -echo "==========================================================================" -orionCurl --url /v1/contextTypes?collapse=true -echo -echo - - ---REGEXPECT-- -01. GET /v1/contextTypes and see a list of zero types -===================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 71 - -{ - "statusCode": { - "code": "404", - "reasonPhrase": "No context element found" - } -} - - -02. POST /v1/updateContext, creating E1-T1-A1+A2 -================================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 230 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "" - }, - { - "name": "A2", - "type": "string", - "value": "" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -03. POST /v1/updateContext, creating E1-T2-A1 -============================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 189 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T2" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -04. POST /v1/updateContext, creating E1-T3-A1+A2 -================================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 230 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "" - }, - { - "name": "A2", - "type": "string", - "value": "" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T3" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -05. GET /v1/contextTypes and see a list of three types -====================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 171 - -{ - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - }, - "types": [ - { - "attributes": [ -#SORT_START - "A2"REGEX(,?) - "A1"REGEX(,?) -#SORT_END - ], - "name": "T1" - }, - { - "attributes": [ - "A1" - ], - "name": "T2" - }, - { - "attributes": [ -#SORT_START - "A2"REGEX(,?) - "A1"REGEX(,?) -#SORT_END - ], - "name": "T3" - } - ] -} - - -06. POST /v1/updateContext, creating E1-T4-A1, servicePath /s1 -============================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 189 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T4" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -07. POST /v1/updateContext, creating E1-T5-A1, servicePath /s2 -============================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 189 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T5" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -08. GET /v1/contextTypes, servicePath /s1 and see a list of one type (T4) -========================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 93 - -{ - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - }, - "types": [ - { - "attributes": [ - "A1" - ], - "name": "T4" - } - ] -} - - -09. GET /v1/contextTypes, servicePath /s2 and see a list of one type (T5) -========================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 93 - -{ - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - }, - "types": [ - { - "attributes": [ - "A1" - ], - "name": "T5" - } - ] -} - - -10. GET /v1/contextTypes and see a list of five types -===================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 239 - -{ - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - }, - "types": [ - { - "attributes": [ -#SORT_START - "A2"REGEX(,?) - "A1"REGEX(,?) -#SORT_END - ], - "name": "T1" - }, - { - "attributes": [ - "A1" - ], - "name": "T2" - }, - { - "attributes": [ -#SORT_START - "A2"REGEX(,?) - "A1"REGEX(,?) -#SORT_END - ], - "name": "T3" - }, - { - "attributes": [ - "A1" - ], - "name": "T4" - }, - { - "attributes": [ - "A1" - ], - "name": "T5" - } - ] -} - - -11. GET /v1/contextTypes?collapse=true and see the list without attributes -========================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 129 - -{ - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - }, - "types": [ - { - "name": "T1" - }, - { - "name": "T2" - }, - { - "name": "T3" - }, - { - "name": "T4" - }, - { - "name": "T5" - } - ] -} - - ---TEARDOWN-- -brokerStop CB -dbDrop CB diff --git a/test/functionalTest/cases/0117_convop_using_standard_ops/getIndividualContextEntity.test.DISABLED b/test/functionalTest/cases/0117_convop_using_standard_ops/getIndividualContextEntity.test.DISABLED deleted file mode 100644 index 4f6d3d8460..0000000000 --- a/test/functionalTest/cases/0117_convop_using_standard_ops/getIndividualContextEntity.test.DISABLED +++ /dev/null @@ -1,597 +0,0 @@ -# Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U -# -# This file is part of Orion Context Broker. -# -# Orion Context Broker is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Orion Context Broker is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -# General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -# -# For those usages not covered by this license please contact with -# iot_support at tid dot es - -# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh - ---NAME-- -ConvOp getIndividualContextEntity: GET /v1/contextEntities/{entityId::id} - ---SHELL-INIT-- -dbInit CB -brokerStart CB 0 - ---SHELL-- -# -# FIXME P5: Once the broker implements forward queries for empty entity types, this test case should -# include forwarding. -# -# FIXME P5: This convenience operation can only respond with ONE entity. -# So, to avoid problems, this functest is designed to have only one matching entity -# for each query. -# Once/If the broker changes this behaviour and permits the response to this conv op -# to include a vector of context elements, this func test should be enhanced to include -# tests of this. -# -# 01. Update/APPEND E1/T1/A1 without service-path -# 02. Update/APPEND E1//A1 with service-path /A1 -# 03. Update/APPEND E1/T1/A2 with service-path /A2 -# 04. Update/APPEND E1//A2 with service-path /A3 -# 05. Update/APPEND E2/T2/A2 with service-path /A2 -# 06. Update/APPEND E3//A2 with service-path /A2 -# 07. Query E2 with service-path '/A2' -# 08. Query E1 with service-path '/A2' and URI param !exist=entity::type -# 09. Query E1 with service-path '/A2' and URI param exist=entity::type -# 10. Query E1 without service-path and URI param entity::type=T1 -# 11. Query E3 with service-path '/A2' and URI param !exist=entity::type -# 12. Query E2 with service-path '/A2' and attributesFormat set to JSON-object -# - -echo "01. Update/APPEND E1/T1/A1 without service-path" -echo "===============================================" -payload='{ - "contextElements": [ - { - "type": "T1", - "isPattern": "false", - "id": "E1", - "attributes": [ - { - "name": "A1", - "type": "degree", - "value": "a1t1e1" - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" -echo -echo - - -echo "02. Update/APPEND E1//A1 with service-path /A1" -echo "==============================================" -payload='{ - "contextElements": [ - { - "type": "", - "isPattern": "false", - "id": "E1", - "attributes": [ - { - "name": "A1", - "type": "degree", - "value": "a1__e1" - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" --servicePath /A1 -echo -echo - - -echo "03. Update/APPEND E1/T1/A2 with service-path /A2" -echo "================================================" -payload='{ - "contextElements": [ - { - "type": "T1", - "isPattern": "false", - "id": "E1", - "attributes": [ - { - "name": "A2", - "type": "degree", - "value": "a2t1e1" - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" --servicePath /A2 -echo -echo - - -echo "04. Update/APPEND E1//A2 with service-path /A3" -echo "==============================================" -payload='{ - "contextElements": [ - { - "type": "", - "isPattern": "false", - "id": "E1", - "attributes": [ - { - "name": "A2", - "type": "degree", - "value": "a2__e1" - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" --servicePath /A3 -echo -echo - - -echo "05. Update/APPEND E2/T2/A2 with service-path /A2" -echo "================================================" -payload='{ - "contextElements": [ - { - "type": "T2", - "isPattern": "false", - "id": "E2", - "attributes": [ - { - "name": "A2", - "type": "degree", - "value": "a2_t2_e2" - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" --servicePath /A2 -echo -echo - - -echo "06. Update/APPEND E3//A2 with service-path /A2" -echo "==============================================" -payload='{ - "contextElements": [ - { - "type": "", - "isPattern": "false", - "id": "E3", - "attributes": [ - { - "name": "A2", - "type": "degree", - "value": "a2__e3" - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" --servicePath /A2 -echo -echo - - -echo "07. Query E2 with service-path '/A2'" -echo "====================================" -orionCurl --url /v1/contextEntities/E2 --servicePath /A2 -echo -echo - - -echo "08. Query E1 with service-path '/A2' and URI param !exist=entity::type" -echo "======================================================================" -orionCurl --url /v1/contextEntities/E1?!exist=entity::type --servicePath /A2 -echo -echo - - -echo "09. Query E1 with service-path '/A2' and URI param exist=entity::type" -echo "=====================================================================" -orionCurl --url /v1/contextEntities/E1?exist=entity::type --servicePath /A2 -echo -echo - -echo "10. Query E1 with service-path '/A2' and URI param entity::type=T1" -echo "==================================================================" -orionCurl --url /v1/contextEntities/E1?entity::type=T1 --servicePath /A2 -echo -echo - - -echo "11. Query E3 with service-path '/A2' and URI param !exist=entity::type" -echo "======================================================================" -orionCurl --url /v1/contextEntities/E3?!exist=entity::type --servicePath /A2 -echo -echo - - -echo "12. Query E2 with service-path '/A2' and attributesFormat set to JSON-object" -echo "============================================================================" -orionCurl --url /v1/contextEntities/E2 --servicePath /A2 --urlParams attributesFormat=object -echo -echo - - ---REGEXPECT-- -01. Update/APPEND E1/T1/A1 without service-path -=============================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 189 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "degree", - "value": "" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -02. Update/APPEND E1//A1 with service-path /A1 -============================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 187 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "degree", - "value": "" - } - ], - "id": "E1", - "isPattern": "false", - "type": "" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -03. Update/APPEND E1/T1/A2 with service-path /A2 -================================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 189 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A2", - "type": "degree", - "value": "" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -04. Update/APPEND E1//A2 with service-path /A3 -============================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 187 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A2", - "type": "degree", - "value": "" - } - ], - "id": "E1", - "isPattern": "false", - "type": "" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -05. Update/APPEND E2/T2/A2 with service-path /A2 -================================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 189 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A2", - "type": "degree", - "value": "" - } - ], - "id": "E2", - "isPattern": "false", - "type": "T2" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -06. Update/APPEND E3//A2 with service-path /A2 -============================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 187 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A2", - "type": "degree", - "value": "" - } - ], - "id": "E3", - "isPattern": "false", - "type": "" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -07. Query E2 with service-path '/A2' -==================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 174 - -{ - "contextElement": { - "attributes": [ - { - "name": "A2", - "type": "degree", - "value": "a2_t2_e2" - } - ], - "id": "E2", - "isPattern": "false", - "type": "T2" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } -} - - -08. Query E1 with service-path '/A2' and URI param !exist=entity::type -====================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 158 - -{ - "contextElement": { - "id": "E1", - "isPattern": "false", - "type": "" - }, - "statusCode": { - "code": "404", - "details": "Entity id: /E1/", - "reasonPhrase": "No context element found" - } -} - - -09. Query E1 with service-path '/A2' and URI param exist=entity::type -===================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 172 - -{ - "contextElement": { - "attributes": [ - { - "name": "A2", - "type": "degree", - "value": "a2t1e1" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } -} - - -10. Query E1 with service-path '/A2' and URI param entity::type=T1 -================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 172 - -{ - "contextElement": { - "attributes": [ - { - "name": "A2", - "type": "degree", - "value": "a2t1e1" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } -} - - -11. Query E3 with service-path '/A2' and URI param !exist=entity::type -====================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 170 - -{ - "contextElement": { - "attributes": [ - { - "name": "A2", - "type": "degree", - "value": "a2__e3" - } - ], - "id": "E3", - "isPattern": "false", - "type": "" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } -} - - -12. Query E2 with service-path '/A2' and attributesFormat set to JSON-object -============================================================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 167 - -{ - "contextElement": { - "attributes": { - "A2": { - "type": "degree", - "value": "a2_t2_e2" - } - }, - "id": "E2", - "isPattern": "false", - "type": "T2" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } -} - - ---TEARDOWN-- -brokerStop CB -dbDrop CB diff --git a/test/functionalTest/cases/0117_convop_using_standard_ops/getIndividualContextEntityAttribute.test.DISABLED b/test/functionalTest/cases/0117_convop_using_standard_ops/getIndividualContextEntityAttribute.test.DISABLED deleted file mode 100644 index 6f2f6d0733..0000000000 --- a/test/functionalTest/cases/0117_convop_using_standard_ops/getIndividualContextEntityAttribute.test.DISABLED +++ /dev/null @@ -1,512 +0,0 @@ -# Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U -# -# This file is part of Orion Context Broker. -# -# Orion Context Broker is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Orion Context Broker is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -# General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -# -# For those usages not covered by this license please contact with -# iot_support at tid dot es - -# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh - ---NAME-- -ConvOp getIndividualContextEntityAttribute: GET /v1/contextEntities/{entityId::id}/attributes/{attribute::name} - ---SHELL-INIT-- -dbInit CB -dbInit CP1 -brokerStart CB 0 -brokerStart CP1 0 - ---SHELL-- - -# -# 01. GET /v1/contextEntities/E1/attributes/A1 and see it fail -# 02. Update/APPEND E1/T1/A1 -# 03. GET /v1/contextEntities/E1/attributes/A1 and see it work -# 04. GET /v1/contextEntities/E1/attributes/A1?!exist=entity::type and see it fail -# 05. Update/APPEND E2//A1 -# 06. GET /v1/contextEntities/E2/attributes/A1?!exist=entity::type: E2//A1 -# 07. GET /v1/contextEntities/E1/attributes/A1?exist=entity::type: E1/T1/A1 -# 08. GET /v1/contextEntities/E1/attributes/A1?entity::type=T2 and see it fail -# 09. GET /v1/contextEntities/E1/attributes/A1?entity::type=T1: E1/T1/A1 -# 10. GET /v1/contextEntities/E1/attributes/A1?attributesFormat=object -# 11. Update/APPEND E3/T1/A1 in CP1 -# 12. Register E3/T1/A1 in CB, CP1 as provApp -# 13. GET /v1/contextEntities/E3/attributes/A1?entity::type=T1 (from CP1) -# - -echo "01. GET /v1/contextEntities/E1/attributes/A1 and see it fail" -echo "============================================================" -orionCurl --url /v1/contextEntities/E1/attributes/A1 -echo -echo - - -echo "02. Update/APPEND E1/T1/A1" -echo "==========================" -payload='{ - "contextElements": [ - { - "type": "T1", - "id": "E1", - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "1" - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" -echo -echo - - -echo "03. GET /v1/contextEntities/E1/attributes/A1 and see it work" -echo "============================================================" -orionCurl --url /v1/contextEntities/E1/attributes/A1 -echo -echo - - -echo "04. GET /v1/contextEntities/E1/attributes/A1?!exist=entity::type and see it fail" -echo "================================================================================" -orionCurl --url /v1/contextEntities/E1/attributes/A1?!exist=entity::type -echo -echo - - -echo "05. Update/APPEND E2//A1" -echo "========================" -payload='{ - "contextElements": [ - { - "id": "E2", - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "E2 without type" - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" -echo -echo - - -echo "06. GET /v1/contextEntities/E2/attributes/A1?!exist=entity::type: E2//A1" -echo "========================================================================" -orionCurl --url /v1/contextEntities/E2/attributes/A1?!exist=entity::type -echo -echo - - -echo "07. GET /v1/contextEntities/E1/attributes/A1?exist=entity::type: E1/T1/A1" -echo "=========================================================================" -orionCurl --url /v1/contextEntities/E1/attributes/A1?exist=entity::type -echo -echo - - -echo "08. GET /v1/contextEntities/E1/attributes/A1?entity::type=T2 and see it fail" -echo "============================================================================" -orionCurl --url /v1/contextEntities/E1/attributes/A1?entity::type=T2 -echo -echo - - -echo "09. GET /v1/contextEntities/E1/attributes/A1?entity::type=T1: E1/T1/A1" -echo "======================================================================" -orionCurl --url /v1/contextEntities/E1/attributes/A1?entity::type=T1 -echo -echo - - -echo "10. GET /v1/contextEntities/E1/attributes/A1?attributesFormat=object" -echo "====================================================================" -orionCurl --url /v1/contextEntities/E1/attributes/A1?attributesFormat=object -echo -echo - - -echo "11. Update/APPEND E3/T1/A1 in CP1" -echo "=================================" -payload='{ - "contextElements": [ - { - "type": "T1", - "id": "E3", - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "On CP1" - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" --port $CP1_PORT -echo -echo - - -echo "12. Register E3/T1/A1 in CB, CP1 as provApp" -echo "===========================================" -payload='{ - "contextRegistrations": [ - { - "entities": [ - { - "type": "T1", - "isPattern": "false", - "id": "E3" - } - ], - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "providingApplication": "http://localhost:'${CP1_PORT}'/v1" - } - ], - "duration": "P1M" -}' -orionCurl --url /v1/registry/registerContext --payload "$payload" --servicePath /A1 -echo -echo - - -echo "13. GET /v1/contextEntities/E3/attributes/A1?entity::type=T1 (from CP1)" -echo "=========================================================================" -orionCurl --url /v1/contextEntities/E3/attributes/A1?entity::type=T1 -echo -echo - - ---REGEXPECT-- -01. GET /v1/contextEntities/E1/attributes/A1 and see it fail -============================================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 99 - -{ - "statusCode": { - "code": "404", - "details": "Entity id: /E1/", - "reasonPhrase": "No context element found" - } -} - - -02. Update/APPEND E1/T1/A1 -========================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 189 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -03. GET /v1/contextEntities/E1/attributes/A1 and see it work -============================================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 106 - -{ - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "1" - } - ], - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } -} - - -04. GET /v1/contextEntities/E1/attributes/A1?!exist=entity::type and see it fail -================================================================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 99 - -{ - "statusCode": { - "code": "404", - "details": "Entity id: /E1/", - "reasonPhrase": "No context element found" - } -} - - -05. Update/APPEND E2//A1 -======================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 187 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "" - } - ], - "id": "E2", - "isPattern": "false", - "type": "" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -06. GET /v1/contextEntities/E2/attributes/A1?!exist=entity::type: E2//A1 -======================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 120 - -{ - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "E2 without type" - } - ], - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } -} - - -07. GET /v1/contextEntities/E1/attributes/A1?exist=entity::type: E1/T1/A1 -========================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 106 - -{ - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "1" - } - ], - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } -} - - -08. GET /v1/contextEntities/E1/attributes/A1?entity::type=T2 and see it fail -============================================================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 99 - -{ - "statusCode": { - "code": "404", - "details": "Entity id: /E1/", - "reasonPhrase": "No context element found" - } -} - - -09. GET /v1/contextEntities/E1/attributes/A1?entity::type=T1: E1/T1/A1 -====================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 106 - -{ - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "1" - } - ], - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } -} - - -10. GET /v1/contextEntities/E1/attributes/A1?attributesFormat=object -==================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 99 - -{ - "attributes": { - "A1": { - "type": "string", - "value": "1" - } - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } -} - - -11. Update/APPEND E3/T1/A1 in CP1 -================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 189 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "" - } - ], - "id": "E3", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -12. Register E3/T1/A1 in CB, CP1 as provApp -=========================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 62 - -{ - "duration": "P1M", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -13. GET /v1/contextEntities/E3/attributes/A1?entity::type=T1 (from CP1) -========================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 111 - -{ - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "On CP1" - } - ], - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } -} - - ---TEARDOWN-- -brokerStop CB -brokerStop CP1 -dbDrop CB -dbDrop CP1 diff --git a/test/functionalTest/cases/0117_convop_using_standard_ops/getIndividualContextEntityAttributeWithTypeAndId.test.DISABLED b/test/functionalTest/cases/0117_convop_using_standard_ops/getIndividualContextEntityAttributeWithTypeAndId.test.DISABLED deleted file mode 100644 index 4c8a75f771..0000000000 --- a/test/functionalTest/cases/0117_convop_using_standard_ops/getIndividualContextEntityAttributeWithTypeAndId.test.DISABLED +++ /dev/null @@ -1,654 +0,0 @@ -# Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U -# -# This file is part of Orion Context Broker. -# -# Orion Context Broker is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Orion Context Broker is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -# General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -# -# For those usages not covered by this license please contact with -# iot_support at tid dot es - -# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh - ---NAME-- -ConvOp getIndividualContextEntityAttributeWithTypeAndId: GET /v1/contextEntities/type/{entity::type}/id/{entity::id}/attributes/{attribute::name} - ---SHELL-INIT-- -dbInit CB -dbInit CP1 -brokerStart CB 0 -brokerStart CP1 0 - ---SHELL-- - -# -# 01. GET /v1/contextEntities/type/T1/id/E1/attributes/A1 and see it fail -# 02. Update/APPEND E1/T1/A1, service-path /s1 -# 03. Update/APPEND E1/T1/A1, service-path /s2 -# 04. Update/APPEND E1/T1/A1, service-path /s3 -# 05. GET /v1/contextEntities/type/T1/id/E1/attributes/A1, no service-path, and see ONLY ONE hit -# 06. GET /v1/contextEntities/type/T1/id/E1/attributes/A1, service-path /#, and see ONLY ONE hit -# 07. GET /v1/contextEntities/type/T1/id/E1/attributes/A1, service-path /s1, and see 1 hit -# 08. GET /v1/contextEntities/type/T1/id/E1/attributes/A1?attributesFormat=object, service-path /s1, and see it work -# 09. GET /v1/contextEntities/type/T1/id/E1/attributes/A1?entity::type=T1, service-path /s1, and see it work -# 10. GET /v1/contextEntities/type/T1/id/E1/attributes/A1?entity::type=T2, service-path /s1, and see it fail -# 11. GET /v1/contextEntities/type/T1/id/E1/attributes/A1?!exist=entity::type, service-path /s1, and see it fail -# 12. GET /v1/contextEntities/type/T1/id/E1/attributes/A1?exist=entity::type, service-path /s1, and see it work -# 13. GET /v1/contextEntities/type/T1/id/E2/attributes/A1 and see it fail -# 14. Register E2/T1/A1 with providing application CP1 -# 15. GET /v1/contextEntities/type/T1/id/E2/attributes/A1 and see it fail, as E2/T1/A1 does not exist in CP1 -# 16. Update/APPEND E2/T1/A1 in CP1 -# 17. GET /v1/contextEntities/type/T1/id/E2/attributes/A1 and see it work -# - - -echo "01. GET /v1/contextEntities/type/T1/id/E1/attributes/A1 and see it fail" -echo "=======================================================================" -orionCurl --url /v1/contextEntities/type/T1/id/E1/attributes/A1 -echo -echo - - -echo "02. Update/APPEND E1/T1/A1, service-path /s1" -echo "============================================" -payload='{ - "contextElements": [ - { - "type": "T1", - "isPattern": "false", - "id": "E1", - "attributes": [ - { - "name": "A1", - "type": "degree", - "value": "a1t1e1-s1" - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" --servicePath /s1 -echo -echo - - -echo "03. Update/APPEND E1/T1/A1, service-path /s2" -echo "============================================" -payload='{ - "contextElements": [ - { - "type": "T1", - "isPattern": "false", - "id": "E1", - "attributes": [ - { - "name": "A1", - "type": "degree", - "value": "a1t1e1-s2" - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" --servicePath /s2 -echo -echo - - -echo "04. Update/APPEND E1/T1/A1, service-path /s3" -echo "============================================" -payload='{ - "contextElements": [ - { - "type": "T1", - "isPattern": "false", - "id": "E1", - "attributes": [ - { - "name": "A1", - "type": "degree", - "value": "a1t1e1-s3" - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" --servicePath /s3 -echo -echo - - -echo "05. GET /v1/contextEntities/type/T1/id/E1/attributes/A1, no service-path, and see ONLY ONE hit" -echo "==============================================================================================" -orionCurl --url /v1/contextEntities/type/T1/id/E1/attributes/A1 -echo -echo - - -echo "06. GET /v1/contextEntities/type/T1/id/E1/attributes/A1, service-path /#, and see ONLY ONE hit" -echo "==============================================================================================" -orionCurl --url /v1/contextEntities/type/T1/id/E1/attributes/A1 --servicePath /# -echo -echo - - -echo "07. GET /v1/contextEntities/type/T1/id/E1/attributes/A1, service-path /s1, and see 1 hit" -echo "========================================================================================" -orionCurl --url /v1/contextEntities/type/T1/id/E1/attributes/A1 --servicePath /s1 -echo -echo - - -echo "08. GET /v1/contextEntities/type/T1/id/E1/attributes/A1?attributesFormat=object, service-path /s1, and see it work" -echo "==================================================================================================================" -orionCurl --url /v1/contextEntities/type/T1/id/E1/attributes/A1?attributesFormat=object --servicePath /s1 -echo -echo - - -echo "09. GET /v1/contextEntities/type/T1/id/E1/attributes/A1?entity::type=T1, service-path /s2, and see it work" -echo "==========================================================================================================" -orionCurl --url /v1/contextEntities/type/T1/id/E1/attributes/A1?entity::type=T1 --servicePath /s2 -echo -echo - - -echo "10. GET /v1/contextEntities/type/T1/id/E1/attributes/A1?entity::type=T2, service-path /s1, and see it fail" -echo "==========================================================================================================" -orionCurl --url /v1/contextEntities/type/T1/id/E1/attributes/A1?entity::type=T2 --servicePath /s1 -echo -echo - - -echo "11. GET /v1/contextEntities/type/T1/id/E1/attributes/A1?!exist=entity::type, service-path /s1, and see it fail" -echo "==============================================================================================================" -orionCurl --url /v1/contextEntities/type/T1/id/E1/attributes/A1?!exist=entity::type --servicePath /s1 -echo -echo - - -echo "12. GET /v1/contextEntities/type/T1/id/E1/attributes/A1?exist=entity::type, service-path /s3, and see it work" -echo "=============================================================================================================" -orionCurl --url /v1/contextEntities/type/T1/id/E1/attributes/A1?exist=entity::type --servicePath /s3 -echo -echo - - -echo "13. GET /v1/contextEntities/type/T1/id/E2/attributes/A1 and see it fail" -echo "=======================================================================" -orionCurl --url /v1/contextEntities/type/T1/id/E2/attributes/A1 -echo -echo - - -echo "14. Register E2/T1/A1 with providing application CP1" -echo "====================================================" -payload='{ - "contextRegistrations": [ - { - "entities": [ - { - "type": "T1", - "id": "E2" - } - ], - "attributes": [ - { - "name": "A1", - "type": "string" - } - ], - "providingApplication": "http://localhost:'${CP1_PORT}'/v1" - } - ], - "duration": "P1M" -}' -orionCurl --url /v1/registry/registerContext --payload "$payload" -echo -echo - - -echo "15. GET /v1/contextEntities/type/T1/id/E2/attributes/A1 and see it fail, as E2/T1/A1 does not exist in CP1" -echo "==========================================================================================================" -orionCurl --url /v1/contextEntities/type/T1/id/E2/attributes/A1 -echo -echo - - -echo "16. Update/APPEND E2/T1/A1 in CP1" -echo "=================================" -payload='{ - "contextElements": [ - { - "type" : "T1", - "isPattern" : "false", - "id" : "E2", - "attributes" : [ - { - "name" : "A1", - "type" : "a", - "value" : "E1-T1-A1 in CP1" - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" --port $CP1_PORT -echo -echo - - -echo "17. GET /v1/contextEntities/type/T1/id/E2/attributes/A1 and see it work" -echo "=======================================================================" -orionCurl --url /v1/contextEntities/type/T1/id/E2/attributes/A1 -echo -echo - - ---REGEXPECT-- -01. GET /v1/contextEntities/type/T1/id/E1/attributes/A1 and see it fail -======================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 114 - -{ - "statusCode": { - "code": "404", - "details": "Entity-Attribute pair: /E1-A1/", - "reasonPhrase": "No context element found" - } -} - - -02. Update/APPEND E1/T1/A1, service-path /s1 -============================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 189 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "degree", - "value": "" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -03. Update/APPEND E1/T1/A1, service-path /s2 -============================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 189 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "degree", - "value": "" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -04. Update/APPEND E1/T1/A1, service-path /s3 -============================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 189 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "degree", - "value": "" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -05. GET /v1/contextEntities/type/T1/id/E1/attributes/A1, no service-path, and see ONLY ONE hit -============================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 114 - -{ - "attributes": [ - { - "name": "A1", - "type": "degree", - "value": "a1t1e1-s1" - } - ], - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } -} - - -06. GET /v1/contextEntities/type/T1/id/E1/attributes/A1, service-path /#, and see ONLY ONE hit -============================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 114 - -{ - "attributes": [ - { - "name": "A1", - "type": "degree", - "value": "a1t1e1-s1" - } - ], - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } -} - - -07. GET /v1/contextEntities/type/T1/id/E1/attributes/A1, service-path /s1, and see 1 hit -======================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 114 - -{ - "attributes": [ - { - "name": "A1", - "type": "degree", - "value": "a1t1e1-s1" - } - ], - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } -} - - -08. GET /v1/contextEntities/type/T1/id/E1/attributes/A1?attributesFormat=object, service-path /s1, and see it work -================================================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 107 - -{ - "attributes": { - "A1": { - "type": "degree", - "value": "a1t1e1-s1" - } - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } -} - - -09. GET /v1/contextEntities/type/T1/id/E1/attributes/A1?entity::type=T1, service-path /s2, and see it work -========================================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 114 - -{ - "attributes": [ - { - "name": "A1", - "type": "degree", - "value": "a1t1e1-s2" - } - ], - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } -} - - -10. GET /v1/contextEntities/type/T1/id/E1/attributes/A1?entity::type=T2, service-path /s1, and see it fail -========================================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 104 - -{ - "statusCode": { - "code": "400", - "details": "non-matching entity::types in URL", - "reasonPhrase": "Bad Request" - } -} - - -11. GET /v1/contextEntities/type/T1/id/E1/attributes/A1?!exist=entity::type, service-path /s1, and see it fail -============================================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 116 - -{ - "statusCode": { - "code": "400", - "details": "entity::type cannot be empty for this request", - "reasonPhrase": "Bad Request" - } -} - - -12. GET /v1/contextEntities/type/T1/id/E1/attributes/A1?exist=entity::type, service-path /s3, and see it work -============================================================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 114 - -{ - "attributes": [ - { - "name": "A1", - "type": "degree", - "value": "a1t1e1-s3" - } - ], - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } -} - - -13. GET /v1/contextEntities/type/T1/id/E2/attributes/A1 and see it fail -======================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 114 - -{ - "statusCode": { - "code": "404", - "details": "Entity-Attribute pair: /E2-A1/", - "reasonPhrase": "No context element found" - } -} - - -14. Register E2/T1/A1 with providing application CP1 -==================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 62 - -{ - "duration": "P1M", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -15. GET /v1/contextEntities/type/T1/id/E2/attributes/A1 and see it fail, as E2/T1/A1 does not exist in CP1 -========================================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 114 - -{ - "statusCode": { - "code": "404", - "details": "Entity-Attribute pair: /E2-A1/", - "reasonPhrase": "No context element found" - } -} - - -16. Update/APPEND E2/T1/A1 in CP1 -================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 184 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "a", - "value": "" - } - ], - "id": "E2", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -17. GET /v1/contextEntities/type/T1/id/E2/attributes/A1 and see it work -======================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 115 - -{ - "attributes": [ - { - "name": "A1", - "type": "a", - "value": "E1-T1-A1 in CP1" - } - ], - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } -} - - ---TEARDOWN-- -brokerStop CB -brokerStop CP1 -dbDrop CB -dbDrop CP1 diff --git a/test/functionalTest/cases/0117_convop_using_standard_ops/getIndividualContextEntityAttributes.test.DISABLED b/test/functionalTest/cases/0117_convop_using_standard_ops/getIndividualContextEntityAttributes.test.DISABLED deleted file mode 100644 index 451d33d867..0000000000 --- a/test/functionalTest/cases/0117_convop_using_standard_ops/getIndividualContextEntityAttributes.test.DISABLED +++ /dev/null @@ -1,597 +0,0 @@ -# Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U -# -# This file is part of Orion Context Broker. -# -# Orion Context Broker is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Orion Context Broker is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -# General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -# -# For those usages not covered by this license please contact with -# iot_support at tid dot es - -# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh - ---NAME-- -ConvOp getIndividualContextEntityAttributes: GET /v1/contextEntities/{entityId::id}/attributes - ---SHELL-INIT-- -dbInit CB -brokerStart CB 0 - ---SHELL-- -# -# FIXME P5: Once the broker implements forward queries for empty entity types, this test case should -# include forwarding. -# -# FIXME P5: This convenience operation can only respond with ONE entity. -# So, to avoid problems, this functest is designed to have only one matching entity -# for each query. -# Once/If the broker changes this behaviour and permits the response to this conv op -# to include a vector of context elements, this func test should be enhanced to include -# tests of this. -# -# 01. Update/APPEND E1/T1/A1 without service-path -# 02. Update/APPEND E1//A1 with service-path /A1 -# 03. Update/APPEND E1/T1/A2 with service-path /A2 -# 04. Update/APPEND E1//A2 with service-path /A3 -# 05. Update/APPEND E2/T2/A2 with service-path /A2 -# 06. Update/APPEND E3//A2 with service-path /A2 -# 07. Query E2 with service-path '/A2' -# 08. Query E1 with service-path '/A2' and URI param !exist=entity::type -# 09. Query E1 with service-path '/A2' and URI param exist=entity::type -# 10. Query E1 without service-path and URI param entity::type=T1 -# 11. Query E3 with service-path '/A2' and URI param !exist=entity::type -# 12. Query E2 with service-path '/A2' and attributesFormat set to JSON-object -# - -echo "01. Update/APPEND E1/T1/A1 without service-path" -echo "===============================================" -payload='{ - "contextElements": [ - { - "type": "T1", - "isPattern": "false", - "id": "E1", - "attributes": [ - { - "name": "A1", - "type": "degree", - "value": "a1t1e1" - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" -echo -echo - - -echo "02. Update/APPEND E1//A1 with service-path /A1" -echo "==============================================" -payload='{ - "contextElements": [ - { - "type": "", - "isPattern": "false", - "id": "E1", - "attributes": [ - { - "name": "A1", - "type": "degree", - "value": "a1__e1" - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" --servicePath /A1 -echo -echo - - -echo "03. Update/APPEND E1/T1/A2 with service-path /A2" -echo "================================================" -payload='{ - "contextElements": [ - { - "type": "T1", - "isPattern": "false", - "id": "E1", - "attributes": [ - { - "name": "A2", - "type": "degree", - "value": "a2t1e1" - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" --servicePath /A2 -echo -echo - - -echo "04. Update/APPEND E1//A2 with service-path /A3" -echo "==============================================" -payload='{ - "contextElements": [ - { - "type": "", - "isPattern": "false", - "id": "E1", - "attributes": [ - { - "name": "A2", - "type": "degree", - "value": "a2__e1" - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" --servicePath /A3 -echo -echo - - -echo "05. Update/APPEND E2/T2/A2 with service-path /A2" -echo "================================================" -payload='{ - "contextElements": [ - { - "type": "T2", - "isPattern": "false", - "id": "E2", - "attributes": [ - { - "name": "A2", - "type": "degree", - "value": "a2_t2_e2" - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" --servicePath /A2 -echo -echo - - -echo "06. Update/APPEND E3//A2 with service-path /A2" -echo "==============================================" -payload='{ - "contextElements": [ - { - "type": "", - "isPattern": "false", - "id": "E3", - "attributes": [ - { - "name": "A2", - "type": "degree", - "value": "a2__e3" - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" --servicePath /A2 -echo -echo - - -echo "07. Query E2 with service-path '/A2'" -echo "====================================" -orionCurl --url /v1/contextEntities/E2/attributes --servicePath /A2 -echo -echo - - -echo "08. Query E1 with service-path '/A2' and URI param !exist=entity::type" -echo "======================================================================" -orionCurl --url /v1/contextEntities/E1/attributes?!exist=entity::type --servicePath /A2 -echo -echo - - -echo "09. Query E1 with service-path '/A2' and URI param exist=entity::type" -echo "=====================================================================" -orionCurl --url /v1/contextEntities/E1/attributes?exist=entity::type --servicePath /A2 -echo -echo - -echo "10. Query E1 with service-path '/A2' and URI param entity::type=T1" -echo "==================================================================" -orionCurl --url /v1/contextEntities/E1/attributes?entity::type=T1 --servicePath /A2 -echo -echo - - -echo "11. Query E3 with service-path '/A2' and URI param !exist=entity::type" -echo "======================================================================" -orionCurl --url /v1/contextEntities/E3/attributes?!exist=entity::type --servicePath /A2 -echo -echo - - -echo "12. Query E2 with service-path '/A2' and attributesFormat set to JSON-object" -echo "============================================================================" -orionCurl --url /v1/contextEntities/E2/attributes --servicePath /A2 --urlParams attributesFormat=object -echo -echo - - ---REGEXPECT-- -01. Update/APPEND E1/T1/A1 without service-path -=============================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 189 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "degree", - "value": "" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -02. Update/APPEND E1//A1 with service-path /A1 -============================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 187 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "degree", - "value": "" - } - ], - "id": "E1", - "isPattern": "false", - "type": "" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -03. Update/APPEND E1/T1/A2 with service-path /A2 -================================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 189 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A2", - "type": "degree", - "value": "" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -04. Update/APPEND E1//A2 with service-path /A3 -============================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 187 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A2", - "type": "degree", - "value": "" - } - ], - "id": "E1", - "isPattern": "false", - "type": "" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -05. Update/APPEND E2/T2/A2 with service-path /A2 -================================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 189 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A2", - "type": "degree", - "value": "" - } - ], - "id": "E2", - "isPattern": "false", - "type": "T2" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -06. Update/APPEND E3//A2 with service-path /A2 -============================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 187 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A2", - "type": "degree", - "value": "" - } - ], - "id": "E3", - "isPattern": "false", - "type": "" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -07. Query E2 with service-path '/A2' -==================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 174 - -{ - "contextElement": { - "attributes": [ - { - "name": "A2", - "type": "degree", - "value": "a2_t2_e2" - } - ], - "id": "E2", - "isPattern": "false", - "type": "T2" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } -} - - -08. Query E1 with service-path '/A2' and URI param !exist=entity::type -====================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 158 - -{ - "contextElement": { - "id": "E1", - "isPattern": "false", - "type": "" - }, - "statusCode": { - "code": "404", - "details": "Entity id: /E1/", - "reasonPhrase": "No context element found" - } -} - - -09. Query E1 with service-path '/A2' and URI param exist=entity::type -===================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 172 - -{ - "contextElement": { - "attributes": [ - { - "name": "A2", - "type": "degree", - "value": "a2t1e1" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } -} - - -10. Query E1 with service-path '/A2' and URI param entity::type=T1 -================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 172 - -{ - "contextElement": { - "attributes": [ - { - "name": "A2", - "type": "degree", - "value": "a2t1e1" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } -} - - -11. Query E3 with service-path '/A2' and URI param !exist=entity::type -====================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 170 - -{ - "contextElement": { - "attributes": [ - { - "name": "A2", - "type": "degree", - "value": "a2__e3" - } - ], - "id": "E3", - "isPattern": "false", - "type": "" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } -} - - -12. Query E2 with service-path '/A2' and attributesFormat set to JSON-object -============================================================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 167 - -{ - "contextElement": { - "attributes": { - "A2": { - "type": "degree", - "value": "a2_t2_e2" - } - }, - "id": "E2", - "isPattern": "false", - "type": "T2" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } -} - - ---TEARDOWN-- -brokerStop CB -dbDrop CB diff --git a/test/functionalTest/cases/0117_convop_using_standard_ops/getNgsi10ContextEntityTypes.test.DISABLED b/test/functionalTest/cases/0117_convop_using_standard_ops/getNgsi10ContextEntityTypes.test.DISABLED deleted file mode 100644 index d480f15fbf..0000000000 --- a/test/functionalTest/cases/0117_convop_using_standard_ops/getNgsi10ContextEntityTypes.test.DISABLED +++ /dev/null @@ -1,469 +0,0 @@ -# Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U -# -# This file is part of Orion Context Broker. -# -# Orion Context Broker is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Orion Context Broker is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -# General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -# -# For those usages not covered by this license please contact with -# iot_support at tid dot es - -# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh - ---NAME-- -ConvOp getNgsi10ContextEntityTypes: GET /v1/contextEntityTypes/{entity::type} - ---SHELL-INIT-- -dbInit CB -brokerStart CB 0 - ---SHELL-- - -# FIXME P5: Once the broker implements forward queries for entity id patterns, this test case should -# include forwarding. - -# -# 01. GET /v1/contextEntityTypes/ET1 and see 0 responses -# 02. Update/APPEND E1/ET1 -# 03. GET /v1/contextEntityTypes/ET1 and see 1 response -# 04. Update/APPEND E1/ET2 -# 05. GET /v1/contextEntityTypes/ET1 and see 1 response -# 06. GET /v1/contextEntityTypes/ET2 and see 1 response -# 07. GET /v1/contextEntityTypes/ET1?attributesFormat=object -# 08. GET /v1/contextEntityTypes/ET1?entity::type=ET1 and see 1 response -# 09. GET /v1/contextEntityTypes/ET1?exist=entity::type and see 1 response -# 10. GET /v1/contextEntityTypes/ET1?!exist=entity::type end see it fail -# 11. GET /v1/contextEntityTypes/ET1?entity::type=ET2 and see it fail -# - -echo "01. GET /v1/contextEntityTypes/ET1 and see 0 responses" -echo "======================================================" -orionCurl --url /v1/contextEntityTypes/ET1 -echo -echo - - -echo "02. Update/APPEND E1/ET1" -echo "========================" -payload='{ - "contextElements": [ - { - "type" : "ET1", - "isPattern" : "false", - "id" : "E1", - "attributes" : [ - { - "name" : "A1", - "type" : "a", - "value" : "1" - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" -echo -echo - - -echo "03. GET /v1/contextEntityTypes/ET1 and see 1 response" -echo "=====================================================" -orionCurl --url /v1/contextEntityTypes/ET1 -echo -echo - - -echo "04. Update/APPEND E1/ET2" -echo "========================" -payload='{ - "contextElements": [ - { - "type" : "ET2", - "isPattern" : "false", - "id" : "E1", - "attributes" : [ - { - "name" : "A2", - "type" : "a", - "value" : "2" - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" -echo -echo - - -echo "05. GET /v1/contextEntityTypes/ET1 and see 1 response" -echo "=====================================================" -orionCurl --url /v1/contextEntityTypes/ET1 -echo -echo - - -echo "06. GET /v1/contextEntityTypes/ET2 and see 1 response" -echo "=====================================================" -orionCurl --url /v1/contextEntityTypes/ET2 -echo -echo - - -echo "07. GET /v1/contextEntityTypes/ET1?attributesFormat=object" -echo "==========================================================" -orionCurl --url /v1/contextEntityTypes/ET1?attributesFormat=object -echo -echo - - -echo "08. GET /v1/contextEntityTypes/ET1?entity::type=ET1 and see 1 response" -echo "======================================================================" -orionCurl --url /v1/contextEntityTypes/ET1?entity::type=ET1 -echo -echo - - -echo "09. GET /v1/contextEntityTypes/ET1?exist=entity::type and see 1 response" -echo "========================================================================" -orionCurl --url /v1/contextEntityTypes/ET1?exist=entity::type -echo -echo - - -echo "10. GET /v1/contextEntityTypes/ET1?!exist=entity::type end see it fail" -echo "======================================================================" -orionCurl --url /v1/contextEntityTypes/ET1?!exist=entity::type -echo -echo - - -echo "11. GET /v1/contextEntityTypes/ET1?entity::type=ET2 and see it fail" -echo "===================================================================" -orionCurl --url /v1/contextEntityTypes/ET1?entity::type=ET2 -echo -echo - - ---REGEXPECT-- -01. GET /v1/contextEntityTypes/ET1 and see 0 responses -====================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 116 - -{ - "errorCode": { - "code": "404", - "details": "entityId::type /ET1/ non-existent", - "reasonPhrase": "No context element found" - } -} - - -02. Update/APPEND E1/ET1 -======================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 185 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "a", - "value": "" - } - ], - "id": "E1", - "isPattern": "false", - "type": "ET1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -03. GET /v1/contextEntityTypes/ET1 and see 1 response -===================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 186 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "a", - "value": "1" - } - ], - "id": "E1", - "isPattern": "false", - "type": "ET1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -04. Update/APPEND E1/ET2 -======================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 185 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A2", - "type": "a", - "value": "" - } - ], - "id": "E1", - "isPattern": "false", - "type": "ET2" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -05. GET /v1/contextEntityTypes/ET1 and see 1 response -===================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 186 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "a", - "value": "1" - } - ], - "id": "E1", - "isPattern": "false", - "type": "ET1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -06. GET /v1/contextEntityTypes/ET2 and see 1 response -===================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 186 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A2", - "type": "a", - "value": "2" - } - ], - "id": "E1", - "isPattern": "false", - "type": "ET2" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -07. GET /v1/contextEntityTypes/ET1?attributesFormat=object -========================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 179 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": { - "A1": { - "type": "a", - "value": "1" - } - }, - "id": "E1", - "isPattern": "false", - "type": "ET1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -08. GET /v1/contextEntityTypes/ET1?entity::type=ET1 and see 1 response -====================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 186 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "a", - "value": "1" - } - ], - "id": "E1", - "isPattern": "false", - "type": "ET1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -09. GET /v1/contextEntityTypes/ET1?exist=entity::type and see 1 response -======================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 186 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "a", - "value": "1" - } - ], - "id": "E1", - "isPattern": "false", - "type": "ET1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -10. GET /v1/contextEntityTypes/ET1?!exist=entity::type end see it fail -====================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 115 - -{ - "errorCode": { - "code": "400", - "details": "entity::type cannot be empty for this request", - "reasonPhrase": "Bad Request" - } -} - - -11. GET /v1/contextEntityTypes/ET1?entity::type=ET2 and see it fail -=================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 103 - -{ - "errorCode": { - "code": "400", - "details": "non-matching entity::types in URL", - "reasonPhrase": "Bad Request" - } -} - - ---TEARDOWN-- -brokerStop CB -dbDrop CB diff --git a/test/functionalTest/cases/0117_convop_using_standard_ops/getNgsi10ContextEntityTypesAttribute.test.DISABLED b/test/functionalTest/cases/0117_convop_using_standard_ops/getNgsi10ContextEntityTypesAttribute.test.DISABLED deleted file mode 100644 index f2aee382a6..0000000000 --- a/test/functionalTest/cases/0117_convop_using_standard_ops/getNgsi10ContextEntityTypesAttribute.test.DISABLED +++ /dev/null @@ -1,526 +0,0 @@ -# Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U -# -# This file is part of Orion Context Broker. -# -# Orion Context Broker is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Orion Context Broker is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -# General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -# -# For those usages not covered by this license please contact with -# iot_support at tid dot es - -# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh - ---NAME-- -ConvOp getNgsi10ContextEntityTypesAttribute: GET /v1/contextEntityTypes/{entity::type}/attribute/{attribute::name} - ---SHELL-INIT-- -dbInit CB -brokerStart CB 0 - ---SHELL-- - -# FIXME P5: Once the broker implements forward queries for entity id patterns, this test case should -# include forwarding. - -# -# 01. GET /v1/contextEntityTypes/ET1/attributes/A and see 0 responses -# 02. Update/APPEND E1/ET1/A -# 03. GET /v1/contextEntityTypes/ET1/attributes/A and see 1 response -# 04. Update/APPEND E1/ET2/A -# 05. GET /v1/contextEntityTypes/ET1/attributes/A and see 1 response -# 06. Update/APPEND E1/ET1/B -# 07. GET /v1/contextEntityTypes/ET1/attributes/A and see 1 response -# 08. GET /v1/contextEntityTypes/ET1/attributes/A?attributesFormat=object -# 09. GET /v1/contextEntityTypes/ET1/attributes/A?entity::type=ET1 and see 1 response -# 10. GET /v1/contextEntityTypes/ET1/attributes/A?exist=entity::type and see 1 response -# 11. GET /v1/contextEntityTypes/ET1/attributes/A?!exist=entity::type end see it fail -# 12. GET /v1/contextEntityTypes/ET1/attributes/A?entity::type=ET2 and see it fail -# - -echo "01. GET /v1/contextEntityTypes/ET1/attributes/A and see 0 responses" -echo "===================================================================" -orionCurl --url /v1/contextEntityTypes/ET1/attributes/A -echo -echo - - -echo "02. Update/APPEND E1/ET1/A" -echo "==========================" -payload='{ - "contextElements": [ - { - "type" : "ET1", - "isPattern" : "false", - "id" : "E1", - "attributes" : [ - { - "name" : "A", - "type" : "a", - "value" : "1" - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" -echo -echo - - -echo "03. GET /v1/contextEntityTypes/ET1/attributes/A and see 1 response" -echo "==================================================================" -orionCurl --url /v1/contextEntityTypes/ET1/attributes/A -echo -echo - - -echo "04. Update/APPEND E1/ET2/A" -echo "==========================" -payload='{ - "contextElements": [ - { - "type" : "ET2", - "isPattern" : "false", - "id" : "E1", - "attributes" : [ - { - "name" : "A", - "type" : "a", - "value" : "2" - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" -echo -echo - - -echo "05. GET /v1/contextEntityTypes/ET1/attributes/A and see 1 response" -echo "==================================================================" -orionCurl --url /v1/contextEntityTypes/ET1/attributes/A -echo -echo - - -echo "06. Update/APPEND E1/ET1/B" -echo "==========================" -payload='{ - "contextElements": [ - { - "type" : "ET1", - "isPattern" : "false", - "id" : "E1", - "attributes" : [ - { - "name" : "B", - "type" : "b", - "value" : "3" - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" -echo -echo - - -echo "07. GET /v1/contextEntityTypes/ET1/attributes/A and see 1 response" -echo "==================================================================" -orionCurl --url /v1/contextEntityTypes/ET1/attributes/A -echo -echo - - -echo "08. GET /v1/contextEntityTypes/ET1/attributes/A?attributesFormat=object" -echo "=======================================================================" -orionCurl --url /v1/contextEntityTypes/ET1/attributes/A?attributesFormat=object -echo -echo - - -echo "09. GET /v1/contextEntityTypes/ET1/attributes/A?entity::type=ET1 and see 1 response" -echo "===================================================================================" -orionCurl --url /v1/contextEntityTypes/ET1/attributes/A?entity::type=ET1 -echo -echo - - -echo "10. GET /v1/contextEntityTypes/ET1/attributes/A?exist=entity::type and see 1 response" -echo "=====================================================================================" -orionCurl --url /v1/contextEntityTypes/ET1/attributes/A?exist=entity::type -echo -echo - - -echo "11. GET /v1/contextEntityTypes/ET1/attributes/A?!exist=entity::type end see it fail" -echo "===================================================================================" -orionCurl --url /v1/contextEntityTypes/ET1/attributes/A?!exist=entity::type -echo -echo - - -echo "12. GET /v1/contextEntityTypes/ET1/attributes/A?entity::type=ET2 and see it fail" -echo "================================================================================" -orionCurl --url /v1/contextEntityTypes/ET1/attributes/A?entity::type=ET2 -echo -echo - - ---REGEXPECT-- -01. GET /v1/contextEntityTypes/ET1/attributes/A and see 0 responses -=================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 128 - -{ - "errorCode": { - "code": "404", - "details": "entityId::type/attribute::name pair not found", - "reasonPhrase": "No context element found" - } -} - - -02. Update/APPEND E1/ET1/A -========================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 184 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A", - "type": "a", - "value": "" - } - ], - "id": "E1", - "isPattern": "false", - "type": "ET1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -03. GET /v1/contextEntityTypes/ET1/attributes/A and see 1 response -================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 185 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A", - "type": "a", - "value": "1" - } - ], - "id": "E1", - "isPattern": "false", - "type": "ET1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -04. Update/APPEND E1/ET2/A -========================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 184 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A", - "type": "a", - "value": "" - } - ], - "id": "E1", - "isPattern": "false", - "type": "ET2" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -05. GET /v1/contextEntityTypes/ET1/attributes/A and see 1 response -================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 185 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A", - "type": "a", - "value": "1" - } - ], - "id": "E1", - "isPattern": "false", - "type": "ET1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -06. Update/APPEND E1/ET1/B -========================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 184 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "B", - "type": "b", - "value": "" - } - ], - "id": "E1", - "isPattern": "false", - "type": "ET1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -07. GET /v1/contextEntityTypes/ET1/attributes/A and see 1 response -================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 185 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A", - "type": "a", - "value": "1" - } - ], - "id": "E1", - "isPattern": "false", - "type": "ET1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -08. GET /v1/contextEntityTypes/ET1/attributes/A?attributesFormat=object -======================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 178 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": { - "A": { - "type": "a", - "value": "1" - } - }, - "id": "E1", - "isPattern": "false", - "type": "ET1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -09. GET /v1/contextEntityTypes/ET1/attributes/A?entity::type=ET1 and see 1 response -=================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 185 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A", - "type": "a", - "value": "1" - } - ], - "id": "E1", - "isPattern": "false", - "type": "ET1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -10. GET /v1/contextEntityTypes/ET1/attributes/A?exist=entity::type and see 1 response -===================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 185 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A", - "type": "a", - "value": "1" - } - ], - "id": "E1", - "isPattern": "false", - "type": "ET1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -11. GET /v1/contextEntityTypes/ET1/attributes/A?!exist=entity::type end see it fail -=================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 115 - -{ - "errorCode": { - "code": "400", - "details": "entity::type cannot be empty for this request", - "reasonPhrase": "Bad Request" - } -} - - -12. GET /v1/contextEntityTypes/ET1/attributes/A?entity::type=ET2 and see it fail -================================================================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 103 - -{ - "errorCode": { - "code": "400", - "details": "non-matching entity::types in URL", - "reasonPhrase": "Bad Request" - } -} - - ---TEARDOWN-- -brokerStop CB -dbDrop CB diff --git a/test/functionalTest/cases/0117_convop_using_standard_ops/postAllEntitiesWithTypeAndId.test.DISABLED b/test/functionalTest/cases/0117_convop_using_standard_ops/postAllEntitiesWithTypeAndId.test.DISABLED deleted file mode 100644 index 63145ecc46..0000000000 --- a/test/functionalTest/cases/0117_convop_using_standard_ops/postAllEntitiesWithTypeAndId.test.DISABLED +++ /dev/null @@ -1,690 +0,0 @@ -# Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U -# -# This file is part of Orion Context Broker. -# -# Orion Context Broker is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Orion Context Broker is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -# General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -# -# For those usages not covered by this license please contact with -# iot_support at tid dot es - -# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh - ---NAME-- -ConvOp postAllEntitiesWithTypeAndId: POST /v1/contextEntities/type/{entity::type}/id/{entity::id} - ---SHELL-INIT-- -dbInit CB -brokerStart CB 0 - ---SHELL-- - -# -# 01. POST /v1/contextEntities/type/T1/id/E1, with entityId::id in payload, see it fail -# 02. POST /v1/contextEntities/type/T1/id/E1, with entityId::type in payload, see it fail -# 03. POST /v1/contextEntities/type/T1/id/E1, attribute A1=1 -# 04. Query E1/A1, see A1=1 -# 05. POST /v1/contextEntities/type/T1/id/E1, attribute A1=2 -# 06. Query E1/A1, see A1=2 -# 07. POST /v1/contextEntities/type/T1/id/E1?attributesFormat=object, attribute A1=3 -# 08. POST /v1/contextEntities/type/T1/id/E1?entity::type=T1, attribute A1=4 -# 09. POST /v1/contextEntities/type/T1/id/E1?entity::type=T2 and see it fail -# 10. POST /v1/contextEntities/type/T1/id/E1?!exist=entity::type and see it fail -# 11. Query E1/T1, see A1=4 -# 12. POST /v1/contextEntities/type/T1/id/E1?exist=entity::type -# 13. POST /v1/contextEntities/type/T1/id/E1,A1=7 servicePath=/test -# 14. Query E1/A1, servicePath=/, see A1=6 -# 15. Query E1/A1, servicePath=/test, see A1=7 -# - -echo "01. POST /v1/contextEntities/type/T1/id/E1, with entityId::id in payload, see it fail" -echo "=====================================================================================" -payload='{ - "id": "E1" -}' -orionCurl --url /v1/contextEntities/type/T1/id/E1 --payload "$payload" -echo -echo - - -echo "02. POST /v1/contextEntities/type/T1/id/E1, with entityId::type in payload, see it fail" -echo "=======================================================================================" -payload='{ - "type": "T1" -}' -orionCurl --url /v1/contextEntities/type/T1/id/E1 --payload "$payload" -echo -echo - - -echo "03. POST /v1/contextEntities/type/T1/id/E1, attribute A1=1" -echo "==========================================================" -payload='{ - "attributes": [ - { - "name": "A1", - "value": 1 - } - ] -}' -orionCurl --url /v1/contextEntities/type/T1/id/E1 --payload "$payload" -echo -echo - - -echo "04. Query E1/A1, see A1=1" -echo "=========================" -payload='{ - "entities": [ - { - "id": "E1", - "type": "T1" - } - ], - "attributes": [ - "A1" - ] -}' -orionCurl --url /v1/queryContext --payload "$payload" -echo -echo - - -echo "05. POST /v1/contextEntities/type/T1/id/E1, attribute A1=2" -echo "==========================================================" -payload='{ - "attributes": [ - { - "name": "A1", - "value": 2 - } - ] -}' -orionCurl --url /v1/contextEntities/type/T1/id/E1 --payload "$payload" -echo -echo - - -echo "06. Query E1/A1, see A1=2" -echo "=========================" -payload='{ - "entities": [ - { - "id": "E1", - "type": "T1" - } - ], - "attributes": [ - "A1" - ] -}' -orionCurl --url /v1/queryContext --payload "$payload" -echo -echo - - -echo "07. POST /v1/contextEntities/type/T1/id/E1?attributesFormat=object" -echo "==================================================================" -payload='{ - "attributes": [ - { - "name": "A1", - "value": 3 - } - ] -}' -orionCurl --url /v1/contextEntities/type/T1/id/E1?attributesFormat=object --payload "$payload" -echo -echo - - -echo "08. POST /v1/contextEntities/type/T1/id/E1?entity::type=T1" -echo "==========================================================" -payload='{ - "attributes": [ - { - "name": "A1", - "value": 4 - } - ] -}' -orionCurl --url /v1/contextEntities/type/T1/id/E1?entity::type=T1 --payload "$payload" -echo -echo - - -echo "09. POST /v1/contextEntities/type/T1/id/E1?entity::type=T2 and see it fail" -echo "==========================================================================" -payload='{ - "attributes": [ - { - "name": "A1", - "value": 4 - } - ] -}' -orionCurl --url /v1/contextEntities/type/T1/id/E1?entity::type=T2 --payload "$payload" -echo -echo - - -echo "10. POST /v1/contextEntities/type/T1/id/E1?!exist=entity::type and see it fail" -echo "==============================================================================" -payload='{ - "attributes": [ - { - "name": "A1", - "value": 5 - } - ] -}' -orionCurl --url /v1/contextEntities/type/T1/id/E1?!exist=entity::type --payload "$payload" -echo -echo - - -echo "11. Query E1/T1, see A1=4" -echo "=========================" -payload='{ - "entities": [ - { - "id": "E1", - "type": "T1" - } - ], - "attributes": [ - "A1" - ] -}' -orionCurl --url /v1/queryContext --payload "$payload" -echo -echo - - -echo "12. POST /v1/contextEntities/type/T1/id/E1?exist=entity::type" -echo "=============================================================" -payload='{ - "attributes": [ - { - "name": "A1", - "value": 5 - } - ] -}' -orionCurl --url /v1/contextEntities/type/T1/id/E1?exist=entity::type --payload "$payload" -echo -echo - - -echo "13. POST /v1/contextEntities/type/T1/id/E1,A1=7 servicePath=/test" -echo "=================================================================" -payload='{ - "attributes": [ - { - "name": "A1", - "value": 6 - } - ] -}' -orionCurl --url /v1/contextEntities/type/T1/id/E1 --payload "$payload" --servicePath /test -echo -echo - - -echo "14. Query E1/A1, servicePath=/, see A1=6" -echo "========================================" -payload='{ - "entities": [ - { - "id": "E1", - "type": "T1" - } - ], - "attributes": [ - "A1" - ] -}' -orionCurl --url /v1/queryContext --payload "$payload" --servicePath / -echo -echo - - -echo "15. Query E1/A1, servicePath=/test, see A1=6" -echo "============================================" -payload='{ - "entities": [ - { - "id": "E1", - "type": "T1" - } - ], - "attributes": [ - "A1" - ] -}' -orionCurl --url /v1/queryContext --payload "$payload" --servicePath /test -echo -echo - - ---REGEXPECT-- -01. POST /v1/contextEntities/type/T1/id/E1, with entityId::id in payload, see it fail -===================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 101 - -{ - "errorCode": { - "code": "400", - "details": "invalid payload: unknown fields", - "reasonPhrase": "Bad Request" - } -} - - -02. POST /v1/contextEntities/type/T1/id/E1, with entityId::type in payload, see it fail -======================================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 101 - -{ - "errorCode": { - "code": "400", - "details": "invalid payload: unknown fields", - "reasonPhrase": "Bad Request" - } -} - - -03. POST /v1/contextEntities/type/T1/id/E1, attribute A1=1 -========================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 164 - -{ - "contextResponses": [ - { - "attributes": [ - { - "name": "A1", - "type": "", - "value": "" - } - ], - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" -} - - -04. Query E1/A1, see A1=1 -========================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 184 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "", - "value": "1" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -05. POST /v1/contextEntities/type/T1/id/E1, attribute A1=2 -========================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 164 - -{ - "contextResponses": [ - { - "attributes": [ - { - "name": "A1", - "type": "", - "value": "" - } - ], - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" -} - - -06. Query E1/A1, see A1=2 -========================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 184 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "", - "value": "2" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -07. POST /v1/contextEntities/type/T1/id/E1?attributesFormat=object -================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 157 - -{ - "contextResponses": [ - { - "attributes": { - "A1": { - "type": "", - "value": "" - } - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" -} - - -08. POST /v1/contextEntities/type/T1/id/E1?entity::type=T1 -========================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 164 - -{ - "contextResponses": [ - { - "attributes": [ - { - "name": "A1", - "type": "", - "value": "" - } - ], - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" -} - - -09. POST /v1/contextEntities/type/T1/id/E1?entity::type=T2 and see it fail -========================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 103 - -{ - "errorCode": { - "code": "400", - "details": "non-matching entity::types in URL", - "reasonPhrase": "Bad Request" - } -} - - -10. POST /v1/contextEntities/type/T1/id/E1?!exist=entity::type and see it fail -============================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 115 - -{ - "errorCode": { - "code": "400", - "details": "entity::type cannot be empty for this request", - "reasonPhrase": "Bad Request" - } -} - - -11. Query E1/T1, see A1=4 -========================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 184 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "", - "value": "4" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -12. POST /v1/contextEntities/type/T1/id/E1?exist=entity::type -============================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 164 - -{ - "contextResponses": [ - { - "attributes": [ - { - "name": "A1", - "type": "", - "value": "" - } - ], - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" -} - - -13. POST /v1/contextEntities/type/T1/id/E1,A1=7 servicePath=/test -================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 164 - -{ - "contextResponses": [ - { - "attributes": [ - { - "name": "A1", - "type": "", - "value": "" - } - ], - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" -} - - -14. Query E1/A1, servicePath=/, see A1=6 -======================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 184 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "", - "value": "5" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -15. Query E1/A1, servicePath=/test, see A1=6 -============================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 184 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "", - "value": "6" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - ---TEARDOWN-- -brokerStop CB -dbDrop CB diff --git a/test/functionalTest/cases/0117_convop_using_standard_ops/postContextEntitiesByEntityId.test.DISABLED b/test/functionalTest/cases/0117_convop_using_standard_ops/postContextEntitiesByEntityId.test.DISABLED deleted file mode 100644 index 32aa74c7df..0000000000 --- a/test/functionalTest/cases/0117_convop_using_standard_ops/postContextEntitiesByEntityId.test.DISABLED +++ /dev/null @@ -1,336 +0,0 @@ -# Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U -# -# This file is part of Orion Context Broker. -# -# Orion Context Broker is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Orion Context Broker is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -# General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -# -# For those usages not covered by this license please contact with -# iot_support at tid dot es - -# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh - ---NAME-- -ConvOp postContextEntitiesByEntityId: POST /v1/registry/contextEntities/{entityId::id} - ---SHELL-INIT-- -dbInit CB -dbInit CP1 -brokerStart CB -brokerStart CP1 - ---SHELL-- - -# -# 01. Register E1 using POST /v1/registry/contextEntities/E1 -# 02. Discover E1 -# 03. Update the registration of E1, CP1 as providing application, using postEntityByIdAttributeByName -# 04. Discover E1 -# 05. Create E1/A1 in CP1 -# 06. Update/UPDATE E1/A1 in CB -# 07. Query E1/A1 in CB -# - -echo "01. Register E1 using POST /v1/registry/contextEntities/E1" -echo "==========================================================" -payload='{ - "duration": "PT1M", - "providingApplication": "none" -}' -orionCurl --url /v1/registry/contextEntities/E1 --payload "$payload" -REG_ID=$(echo "$_response" | grep registrationId | awk -F\" '{ print $4}') -echo -echo - - -echo "02. Discover E1" -echo "===============" -orionCurl --url /v1/registry/contextEntities/E1 -echo -echo - - -echo "03. Update the registration of E1, CP1 as providing application, using postEntityByIdAttributeByName" -echo "====================================================================================================" -payload='{ - "duration": "PT1M", - "providingApplication": "http://localhost:'$CP1_PORT'/v1", - "registrationId": "'$REG_ID'" -}' -orionCurl --url /v1/registry/contextEntities/E1/attributes/A1 --payload "$payload" -echo -echo - - -echo "04. Discover E1" -echo "===============" -orionCurl --url /v1/registry/contextEntities/E1 -echo -echo - - -echo "05. Create E1/A1 in CP1" -echo "=======================" -payload='{ - "contextElements": [ - { - "type": "", - "isPattern": "false", - "id": "E1", - "attributes": [ - { - "name": "A1", - "type": "degree", - "value": "20" - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" --port $CP1_PORT -echo -echo - - -echo "06. Update/UPDATE E1/A1 in CB" -echo "=============================" -payload='{ - "contextElements": [ - { - "type": "", - "isPattern": "false", - "id": "E1", - "attributes": [ - { - "name": "A1", - "type": "degree", - "value": "30" - } - ] - } - ], - "updateAction": "UPDATE" -}' -orionCurl --url /v1/updateContext --payload "$payload" -echo -echo - - -echo "07. Query E1/A1 in CB" -echo "=====================" -payload='{ - "entities": [ - { - "type": "", - "isPattern": "", - "id": "E1" - } - ], - "attributes": [ - "A1" - ] -}' -orionCurl --url /v1/queryContext --payload "$payload" -echo -echo - - ---REGEXPECT-- -01. Register E1 using POST /v1/registry/contextEntities/E1 -========================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 63 - -{ - "duration": "PT1M", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -02. Discover E1 -=============== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 145 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "" - } - ], - "providingApplication": "none" - } - } - ] -} - - -03. Update the registration of E1, CP1 as providing application, using postEntityByIdAttributeByName -==================================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 63 - -{ - "duration": "PT1M", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -04. Discover E1 -=============== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 204 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "" - } - ], - "providingApplication": "http://localhost:REGEX(\d*)/v1" - } - } - ] -} - - -05. Create E1/A1 in CP1 -======================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 187 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "degree", - "value": "" - } - ], - "id": "E1", - "isPattern": "false", - "type": "" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -06. Update/UPDATE E1/A1 in CB -============================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 187 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "degree", - "value": "" - } - ], - "id": "E1", - "isPattern": "false", - "type": "" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -07. Query E1/A1 in CB -===================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 189 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "degree", - "value": "30" - } - ], - "id": "E1", - "isPattern": "false", - "type": "" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - ---TEARDOWN-- -brokerStop CB -brokerStop CP1 -dbDrop CB -dbDrop CP1 diff --git a/test/functionalTest/cases/0117_convop_using_standard_ops/postContextEntitiesByEntityIdAndType.test.DISABLED b/test/functionalTest/cases/0117_convop_using_standard_ops/postContextEntitiesByEntityIdAndType.test.DISABLED deleted file mode 100644 index 2befd465e3..0000000000 --- a/test/functionalTest/cases/0117_convop_using_standard_ops/postContextEntitiesByEntityIdAndType.test.DISABLED +++ /dev/null @@ -1,762 +0,0 @@ -# Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U -# -# This file is part of Orion Context Broker. -# -# Orion Context Broker is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Orion Context Broker is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -# General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -# -# For those usages not covered by this license please contact with -# iot_support at tid dot es - -# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh - ---NAME-- -ConvOp postContextEntitiesByEntityIdAndType: POST /v1/registry/contextEntities/type/{entity::type}/id/{entity::id} - ---SHELL-INIT-- -dbInit CB -brokerStart CB - ---SHELL-- - -# -# 01. Discover E1-T1, and see 0 results -# 02. POST /v1/registry/contextEntities/type/T1/id/E1 -# 03. Discover E1-T1, and see 1 result -# 04. Modify registration -# 05. Discover E1-T1, and see modified result -# 06. POST /v1/registry/contextEntities/type/T1/id/E2?!exist=entity::type, and see it fail -# 07. POST /v1/registry/contextEntities/type/T1/id/E2?exist=entity::type, and see it work -# 08. POST /v1/registry/contextEntities/type/T1/id/E2?entity::type=T2, and see it fail -# 09. POST /v1/registry/contextEntities/type/T1/id/E2?entity::type=T1, and see it work -# 10. POST /v1/registry/contextEntities/type/T1/id/E2, servicePath /s1 -# 11. POST /v1/registry/contextEntities/type/T1/id/E2, servicePath /s2 -# 12. Discover E2-T1, without service-path and see four results -# 13. Discover E2-T1, with service-path /# and see four results -# 14. Discover E2-T1, with service-path / and see two results -# 15. Discover E2-T1, with service-path /s1 and see one result -# 16. Discover E2-T1, with service-path /s2 and see one result -# 17. Discover E2-T1, with service-path /s3 and see zero results -# 18. Discover E2-T1, with service-path /s1,/s2,/s3 and see two results -# - -echo "01. Discover E1-T1, and see 0 results" -echo "=====================================" -payload='{ - "entities": [ - { - "type": "T1", - "isPattern": "false", - "id": "E1" - } - ] -}' -orionCurl --url /v1/registry/discoverContextAvailability --payload "$payload" -echo -echo - - -echo "02. POST /v1/registry/contextEntities/type/T1/id/E1" -echo "===================================================" -payload='{ - "duration": "PT1H", - "providingApplication": "http://kz.tid.es/part02" -}' -orionCurl --url /v1/registry/contextEntities/type/T1/id/E1 --payload "$payload" -REG_ID=$(echo "$_response" | grep registrationId | awk -F\" '{ print $4}') -echo -echo - - -echo "03. Discover E1-T1, and see 1 result" -echo "====================================" -payload='{ - "entities": [ - { - "type": "T1", - "isPattern": "false", - "id": "E1" - } - ] -}' -orionCurl --url /v1/registry/discoverContextAvailability --payload "$payload" -echo -echo - - -echo "04. Modify registration" -echo "=======================" -payload='{ - "duration": "PT2H", - "providingApplication": "http://kz.tid.es/part04", - "registrationId": "'$REG_ID'" -}' -orionCurl --url /v1/registry/contextEntities/type/T1/id/E1 --payload "$payload" -echo -echo - - -echo "05. Discover E1-T1, and see modified result" -echo "===========================================" -payload='{ - "entities": [ - { - "type": "T1", - "isPattern": "false", - "id": "E1" - } - ] -}' -orionCurl --url /v1/registry/discoverContextAvailability --payload "$payload" -echo -echo - - -echo "06. POST /v1/registry/contextEntities/type/T1/id/E2?!exist=entity::type, and see it fail" -echo "========================================================================================" -payload='{ - "duration": "PT2H", - "providingApplication": "http://kz.tid.es/part06" -}' -orionCurl --url /v1/registry/contextEntities/type/T1/id/E2?!exist=entity::type --payload "$payload" -echo -echo - - -echo "07. POST /v1/registry/contextEntities/type/T1/id/E2?exist=entity::type, and see it work" -echo "=======================================================================================" -payload='{ - "duration": "PT2H", - "providingApplication": "http://kz.tid.es/part07" -}' -orionCurl --url /v1/registry/contextEntities/type/T1/id/E2?exist=entity::type --payload "$payload" -echo -echo - - -echo "08. POST /v1/registry/contextEntities/type/T1/id/E2?entity::type=T2, and see it fail" -echo "====================================================================================" -payload='{ - "duration": "PT2H", - "providingApplication": "http://kz.tid.es/part08" -}' -orionCurl --url /v1/registry/contextEntities/type/T1/id/E2?entity::type=T2 --payload "$payload" -echo -echo - - -echo "09. POST /v1/registry/contextEntities/type/T1/id/E2?entity::type=T1, and see it work" -echo "====================================================================================" -payload='{ - "duration": "PT2H", - "providingApplication": "http://kz.tid.es/part09" -}' -orionCurl --url /v1/registry/contextEntities/type/T1/id/E2?entity::type=T1 --payload "$payload" -echo -echo - - -echo "10. POST /v1/registry/contextEntities/type/T1/id/E2, servicePath /s1" -echo "====================================================================" -payload='{ - "duration": "PT2H", - "providingApplication": "http://kz.tid.es/part10" -}' -orionCurl --url /v1/registry/contextEntities/type/T1/id/E2 --servicePath /s1 --payload "$payload" -echo -echo - - -echo "11. POST /v1/registry/contextEntities/type/T1/id/E2, servicePath /s2" -echo "====================================================================" -payload='{ - "duration": "PT2H", - "providingApplication": "http://kz.tid.es/part11" -}' -orionCurl --url /v1/registry/contextEntities/type/T1/id/E2 --servicePath /s2 --payload "$payload" -echo -echo - - -echo "12. Discover E2-T1, without service-path and see four results" -echo "=============================================================" -payload='{ - "entities": [ - { - "type": "T1", - "isPattern": "false", - "id": "E2" - } - ] -}' -orionCurl --url /v1/registry/discoverContextAvailability --payload "$payload" -echo -echo - - -echo "13. Discover E2-T1, with service-path /# and see four results" -echo "=============================================================" -payload='{ - "entities": [ - { - "type": "T1", - "isPattern": "false", - "id": "E2" - } - ] -}' -orionCurl --url /v1/registry/discoverContextAvailability --servicePath '/#' --payload "$payload" -echo -echo - - -echo "14. Discover E2-T1, with service-path / and see two results" -echo "===========================================================" -payload='{ - "entities": [ - { - "type": "T1", - "isPattern": "false", - "id": "E2" - } - ] -}' -orionCurl --url /v1/registry/discoverContextAvailability --servicePath / --payload "$payload" -echo -echo - - -echo "15. Discover E2-T1, with service-path /s1 and see one result" -echo "============================================================" -payload='{ - "entities": [ - { - "type": "T1", - "isPattern": "false", - "id": "E2" - } - ] -}' -orionCurl --url /v1/registry/discoverContextAvailability --servicePath /s1 --payload "$payload" -echo -echo - - -echo "16. Discover E2-T1, with service-path /s2 and see one result" -echo "============================================================" -payload='{ - "entities": [ - { - "type": "T1", - "isPattern": "false", - "id": "E2" - } - ] -}' -orionCurl --url /v1/registry/discoverContextAvailability --servicePath /s2 --payload "$payload" -echo -echo - - -echo "17. Discover E2-T1, with service-path /s3 and see zero results" -echo "==============================================================" -payload='{ - "entities": [ - { - "type": "T1", - "isPattern": "false", - "id": "E2" - } - ] -}' -orionCurl --url /v1/registry/discoverContextAvailability --servicePath /s3 --payload "$payload" -echo -echo - - -echo "18. Discover E2-T1, with service-path /s1,/s2,/s3 and see two results" -echo "=====================================================================" -payload='{ - "entities": [ - { - "type": "T1", - "isPattern": "false", - "id": "E2" - } - ] -}' -orionCurl --url /v1/registry/discoverContextAvailability --servicePath /s1,/s2,/s3 --payload "$payload" -echo -echo - - -----REGEXPECT-- -01. Discover E1-T1, and see 0 results -===================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 70 - -{ - "errorCode": { - "code": "404", - "reasonPhrase": "No context element found" - } -} - - -02. POST /v1/registry/contextEntities/type/T1/id/E1 -=================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 63 - -{ - "duration": "PT1H", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -03. Discover E1-T1, and see 1 result -==================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 166 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/part02" - } - } - ] -} - - -04. Modify registration -======================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 63 - -{ - "duration": "PT2H", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -05. Discover E1-T1, and see modified result -=========================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 166 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/part04" - } - } - ] -} - - -06. POST /v1/registry/contextEntities/type/T1/id/E2?!exist=entity::type, and see it fail -======================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 159 - -{ - "errorCode": { - "code": "400", - "details": "entity::type cannot be empty for this request", - "reasonPhrase": "Bad Request" - }, - "registrationId": "000000000000000000000000" -} - - -07. POST /v1/registry/contextEntities/type/T1/id/E2?exist=entity::type, and see it work -======================================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 63 - -{ - "duration": "PT2H", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -08. POST /v1/registry/contextEntities/type/T1/id/E2?entity::type=T2, and see it fail -==================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 147 - -{ - "errorCode": { - "code": "400", - "details": "non-matching entity::types in URL", - "reasonPhrase": "Bad Request" - }, - "registrationId": "000000000000000000000000" -} - - -09. POST /v1/registry/contextEntities/type/T1/id/E2?entity::type=T1, and see it work -==================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 63 - -{ - "duration": "PT2H", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -10. POST /v1/registry/contextEntities/type/T1/id/E2, servicePath /s1 -==================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 63 - -{ - "duration": "PT2H", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -11. POST /v1/registry/contextEntities/type/T1/id/E2, servicePath /s2 -==================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 63 - -{ - "duration": "PT2H", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -12. Discover E2-T1, without service-path and see four results -============================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 562 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "entities": [ - { - "id": "E2", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/part07" - } - }, - { - "contextRegistration": { - "entities": [ - { - "id": "E2", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/part09" - } - }, - { - "contextRegistration": { - "entities": [ - { - "id": "E2", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/part10" - } - }, - { - "contextRegistration": { - "entities": [ - { - "id": "E2", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/part11" - } - } - ] -} - - -13. Discover E2-T1, with service-path /# and see four results -============================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 562 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "entities": [ - { - "id": "E2", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/part07" - } - }, - { - "contextRegistration": { - "entities": [ - { - "id": "E2", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/part09" - } - }, - { - "contextRegistration": { - "entities": [ - { - "id": "E2", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/part10" - } - }, - { - "contextRegistration": { - "entities": [ - { - "id": "E2", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/part11" - } - } - ] -} - - -14. Discover E2-T1, with service-path / and see two results -=========================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 298 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "entities": [ - { - "id": "E2", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/part07" - } - }, - { - "contextRegistration": { - "entities": [ - { - "id": "E2", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/part09" - } - } - ] -} - - -15. Discover E2-T1, with service-path /s1 and see one result -============================================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 166 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "entities": [ - { - "id": "E2", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/part10" - } - } - ] -} - - -16. Discover E2-T1, with service-path /s2 and see one result -============================================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 166 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "entities": [ - { - "id": "E2", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/part11" - } - } - ] -} - - -17. Discover E2-T1, with service-path /s3 and see zero results -============================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 70 - -{ - "errorCode": { - "code": "404", - "reasonPhrase": "No context element found" - } -} - - -18. Discover E2-T1, with service-path /s1,/s2,/s3 and see two results -===================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 298 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "entities": [ - { - "id": "E2", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/part10" - } - }, - { - "contextRegistration": { - "entities": [ - { - "id": "E2", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/part11" - } - } - ] -} - - ---TEARDOWN-- -brokerStop CB -dbDrop CB diff --git a/test/functionalTest/cases/0117_convop_using_standard_ops/postContextEntityAttributes.test.DISABLED b/test/functionalTest/cases/0117_convop_using_standard_ops/postContextEntityAttributes.test.DISABLED deleted file mode 100644 index 1026e9272d..0000000000 --- a/test/functionalTest/cases/0117_convop_using_standard_ops/postContextEntityAttributes.test.DISABLED +++ /dev/null @@ -1,336 +0,0 @@ -# Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U -# -# This file is part of Orion Context Broker. -# -# Orion Context Broker is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Orion Context Broker is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -# General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -# -# For those usages not covered by this license please contact with -# iot_support at tid dot es - -# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh - ---NAME-- -ConvOp postContextEntityAttributes: POST /v1/registry/contextEntities/{entityId::id}/attributes - ---SHELL-INIT-- -dbInit CB -dbInit CP1 -brokerStart CB -brokerStart CP1 - ---SHELL-- - -# -# 01. Register E1 using POST /v1/registry/contextEntities/E1/attributes -# 02. Discover E1 -# 03. Update the registration of E1, CP1 as providing application, using postEntityByIdAttributeByName -# 04. Discover E1 -# 05. Create E1/A1 in CP1 -# 06. Update/UPDATE E1/A1 in CB -# 07. Query E1/A1 in CB -# - -echo "01. Register E1 using POST /v1/registry/contextEntities/E1/attributes" -echo "=====================================================================" -payload='{ - "duration": "PT1M", - "providingApplication": "none" -}' -orionCurl --url /v1/registry/contextEntities/E1 --payload "$payload" -REG_ID=$(echo "$_response" | grep registrationId | awk -F\" '{ print $4}') -echo -echo - - -echo "02. Discover E1" -echo "===============" -orionCurl --url /v1/registry/contextEntities/E1 -echo -echo - - -echo "03. Update the registration of E1, CP1 as providing application, using postEntityByIdAttributeByName" -echo "====================================================================================================" -payload='{ - "duration": "PT1M", - "providingApplication": "http://localhost:'$CP1_PORT'/v1", - "registrationId": "'$REG_ID'" -}' -orionCurl --url /v1/registry/contextEntities/E1/attributes/A1 --payload "$payload" -echo -echo - - -echo "04. Discover E1" -echo "===============" -orionCurl --url /v1/registry/contextEntities/E1 -echo -echo - - -echo "05. Create E1/A1 in CP1" -echo "=======================" -payload='{ - "contextElements": [ - { - "type": "", - "isPattern": "false", - "id": "E1", - "attributes": [ - { - "name": "A1", - "type": "degree", - "value": "20" - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" --port $CP1_PORT -echo -echo - - -echo "06. Update/UPDATE E1/A1 in CB" -echo "=============================" -payload='{ - "contextElements": [ - { - "type": "", - "isPattern": "false", - "id": "E1", - "attributes": [ - { - "name": "A1", - "type": "degree", - "value": "30" - } - ] - } - ], - "updateAction": "UPDATE" -}' -orionCurl --url /v1/updateContext --payload "$payload" -echo -echo - - -echo "07. Query E1/A1 in CB" -echo "=====================" -payload='{ - "entities": [ - { - "type": "", - "isPattern": "", - "id": "E1" - } - ], - "attributes": [ - "A1" - ] -}' -orionCurl --url /v1/queryContext --payload "$payload" -echo -echo - - ---REGEXPECT-- -01. Register E1 using POST /v1/registry/contextEntities/E1/attributes -===================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 63 - -{ - "duration": "PT1M", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -02. Discover E1 -=============== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 145 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "" - } - ], - "providingApplication": "none" - } - } - ] -} - - -03. Update the registration of E1, CP1 as providing application, using postEntityByIdAttributeByName -==================================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 63 - -{ - "duration": "PT1M", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -04. Discover E1 -=============== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 204 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "" - } - ], - "providingApplication": "http://localhost:REGEX(\d*)/v1" - } - } - ] -} - - -05. Create E1/A1 in CP1 -======================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 187 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "degree", - "value": "" - } - ], - "id": "E1", - "isPattern": "false", - "type": "" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -06. Update/UPDATE E1/A1 in CB -============================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 187 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "degree", - "value": "" - } - ], - "id": "E1", - "isPattern": "false", - "type": "" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -07. Query E1/A1 in CB -===================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 189 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "degree", - "value": "30" - } - ], - "id": "E1", - "isPattern": "false", - "type": "" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - ---TEARDOWN-- -brokerStop CB -brokerStop CP1 -dbDrop CB -dbDrop CP1 diff --git a/test/functionalTest/cases/0117_convop_using_standard_ops/postContextEntityTypeAttribute.test.DISABLED b/test/functionalTest/cases/0117_convop_using_standard_ops/postContextEntityTypeAttribute.test.DISABLED deleted file mode 100644 index 7dd9e36ccd..0000000000 --- a/test/functionalTest/cases/0117_convop_using_standard_ops/postContextEntityTypeAttribute.test.DISABLED +++ /dev/null @@ -1,175 +0,0 @@ -# Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U -# -# This file is part of Orion Context Broker. -# -# Orion Context Broker is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Orion Context Broker is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -# General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -# -# For those usages not covered by this license please contact with -# iot_support at tid dot es - -# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh - ---NAME-- -ConvOp postContextEntityTypeAttribute: POST /v1/registry/contextEntityTypes/{entityId::type}/attributes/A1 - ---SHELL-INIT-- -dbInit CB -brokerStart CB - ---SHELL-- - -# -# FIXME P5: Once the broker implements forward queries for entityId::type matches, this test case should -# include forwarding. -# -# 01. Register entities of type ET using POST /v1/registry/contextEntityTypes/ET/attributes/A1 and payload -# 02. Discover entities of type ET -# 03. Update registration using POST /v1/registry/contextEntityTypes/ET/attributes/A1 and payload -# 04. Discover entities of type ET -# - -echo "01. Register entities of type ET using POST /v1/registry/contextEntityTypes/ET/attributes/A1 and payload" -echo "========================================================================================================" -payload='{ - "duration": "PT1M", - "providingApplication": "none" -}' -orionCurl --url /v1/registry/contextEntityTypes/ET/attributes/A1 --payload "$payload" -REG_ID=$(echo "$_response" | grep registrationId | awk -F\" '{ print $4}') -echo -echo - - -echo "02. Discover entities of type ET" -echo "================================" -orionCurl --url /v1/registry/contextEntityTypes/ET -echo -echo - - -echo "03. Update registration using POST /v1/registry/contextEntityTypes/ET/attributes/A1 and payload" -echo "===============================================================================================" -payload='{ - "duration": "PT2M", - "providingApplication": "some", - "registrationId": "'$REG_ID'" -}' -orionCurl --url /v1/registry/contextEntityTypes/ET/attributes/A1 --payload "$payload" -echo -echo - - -echo "04. Discover entities of type ET" -echo "================================" -orionCurl --url /v1/registry/contextEntityTypes/ET -echo -echo - - ---REGEXPECT-- -01. Register entities of type ET using POST /v1/registry/contextEntityTypes/ET/attributes/A1 and payload -======================================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 63 - -{ - "duration": "PT1M", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -02. Discover entities of type ET -================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 184 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "" - } - ], - "entities": [ - { - "id": "", - "isPattern": "false", - "type": "ET" - } - ], - "providingApplication": "none" - } - } - ] -} - - -03. Update registration using POST /v1/registry/contextEntityTypes/ET/attributes/A1 and payload -=============================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 63 - -{ - "duration": "PT2M", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -04. Discover entities of type ET -================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 184 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "" - } - ], - "entities": [ - { - "id": "", - "isPattern": "false", - "type": "ET" - } - ], - "providingApplication": "some" - } - } - ] -} - - ---TEARDOWN-- -brokerStop CB -dbDrop CB diff --git a/test/functionalTest/cases/0117_convop_using_standard_ops/postContextEntityTypes.test.DISABLED b/test/functionalTest/cases/0117_convop_using_standard_ops/postContextEntityTypes.test.DISABLED deleted file mode 100644 index 10606fb26c..0000000000 --- a/test/functionalTest/cases/0117_convop_using_standard_ops/postContextEntityTypes.test.DISABLED +++ /dev/null @@ -1,163 +0,0 @@ -# Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U -# -# This file is part of Orion Context Broker. -# -# Orion Context Broker is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Orion Context Broker is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -# General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -# -# For those usages not covered by this license please contact with -# iot_support at tid dot es - -# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh - ---NAME-- -ConvOp postContextEntityTypes: POST /v1/registry/contextEntityTypes/{entityId::type} - ---SHELL-INIT-- -dbInit CB -brokerStart CB - ---SHELL-- - -# -# FIXME P5: Once the broker implements forward queries for entityId::type matches, this test case should -# include forwarding. -# -# 01. Register entities of type ET using POST /v1/registry/contextEntityTypes/ET and payload -# 02. Discover entities of type ET -# 03. Update registration using POST /v1/registry/contextEntityTypes/ET and payload -# 04. Discover entities of type ET -# - -echo "01. Register entities of type ET using POST /v1/registry/contextEntityTypes/ET and payload" -echo "==========================================================================================" -payload='{ - "duration": "PT1M", - "providingApplication": "none" -}' -orionCurl --url /v1/registry/contextEntityTypes/ET --payload "$payload" -REG_ID=$(echo "$_response" | grep registrationId | awk -F\" '{ print $4}') -echo -echo - - -echo "02. Discover entities of type ET" -echo "================================" -orionCurl --url /v1/registry/contextEntityTypes/ET -echo -echo - - -echo "03. Update registration using POST /v1/registry/contextEntityTypes/ET and payload" -echo "=================================================================================" -payload='{ - "duration": "PT2M", - "providingApplication": "some", - "registrationId": "'$REG_ID'" -}' -orionCurl --url /v1/registry/contextEntityTypes/ET --payload "$payload" -echo -echo - - -echo "04. Discover entities of type ET" -echo "================================" -orionCurl --url /v1/registry/contextEntityTypes/ET -echo -echo - - ---REGEXPECT-- -01. Register entities of type ET using POST /v1/registry/contextEntityTypes/ET and payload -========================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 63 - -{ - "duration": "PT1M", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -02. Discover entities of type ET -================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 145 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "entities": [ - { - "id": "", - "isPattern": "false", - "type": "ET" - } - ], - "providingApplication": "none" - } - } - ] -} - - -03. Update registration using POST /v1/registry/contextEntityTypes/ET and payload -================================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 63 - -{ - "duration": "PT2M", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -04. Discover entities of type ET -================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 145 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "entities": [ - { - "id": "", - "isPattern": "false", - "type": "ET" - } - ], - "providingApplication": "some" - } - } - ] -} - - ---TEARDOWN-- -brokerStop CB -dbDrop CB diff --git a/test/functionalTest/cases/0117_convop_using_standard_ops/postEntityByIdAttributeByName.test.DISABLED b/test/functionalTest/cases/0117_convop_using_standard_ops/postEntityByIdAttributeByName.test.DISABLED deleted file mode 100644 index df8056cba0..0000000000 --- a/test/functionalTest/cases/0117_convop_using_standard_ops/postEntityByIdAttributeByName.test.DISABLED +++ /dev/null @@ -1,274 +0,0 @@ -# Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U -# -# This file is part of Orion Context Broker. -# -# Orion Context Broker is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Orion Context Broker is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -# General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -# -# For those usages not covered by this license please contact with -# iot_support at tid dot es - -# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh - ---NAME-- -ConvOp postContextEntityAttributeByName: POST /v1/registry/contextEntities/{entityId::id}/attributes/{attributeName} - ---SHELL-INIT-- -dbInit CB -dbInit CP1 -brokerStart CB -brokerStart CP1 - ---SHELL-- - -# -# 01. Register E1/A1 using POST /v1/registry/contextEntities/E1/attributes/A1, CP1 as providing application -# 02. Discover E1/A1 -# 03. Create E1/A1 in CP1 -# 04. Update/UPDATE E1/A1 in CB -# 05. Query E1/A1 in CB -# - -echo "01. Register E1/A1 using POST /v1/registry/contextEntities/E1/attributes/A1, CP1 as providing application" -echo "=========================================================================================================" -payload='{ - "duration": "PT1M", - "providingApplication": "http://localhost:'$CP1_PORT'/v1" -}' -orionCurl --url /v1/registry/contextEntities/E1/attributes/A1 --payload "$payload" -echo -echo - - -echo "02. Discover E1/A1" -echo "==================" -orionCurl --url /v1/registry/contextEntities/E1/attributes/A1 -echo -echo - - -echo "03. Create E1/A1 in CP1" -echo "=======================" -payload='{ - "contextElements": [ - { - "type": "", - "isPattern": "false", - "id": "E1", - "attributes": [ - { - "name": "A1", - "type": "degree", - "value": "20" - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" --port $CP1_PORT -echo -echo - - -echo "04. Update/UPDATE E1/A1 in CB" -echo "=============================" -payload='{ - "contextElements": [ - { - "type": "", - "isPattern": "false", - "id": "E1", - "attributes": [ - { - "name": "A1", - "type": "degree", - "value": "30" - } - ] - } - ], - "updateAction": "UPDATE" -}' -orionCurl --url /v1/updateContext --payload "$payload" -echo -echo - - -echo "05. Query E1/A1 in CB" -echo "=====================" -payload='{ - "entities": [ - { - "type": "", - "isPattern": "", - "id": "E1" - } - ], - "attributes": [ - "A1" - ] -}' -orionCurl --url /v1/queryContext --payload "$payload" -echo -echo - - ---REGEXPECT-- -01. Register E1/A1 using POST /v1/registry/contextEntities/E1/attributes/A1, CP1 as providing application -========================================================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 63 - -{ - "duration": "PT1M", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -02. Discover E1/A1 -================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 204 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "" - } - ], - "providingApplication": "http://localhost:REGEX(\d*)/v1" - } - } - ] -} - - -03. Create E1/A1 in CP1 -======================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 187 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "degree", - "value": "" - } - ], - "id": "E1", - "isPattern": "false", - "type": "" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -04. Update/UPDATE E1/A1 in CB -============================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 187 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "degree", - "value": "" - } - ], - "id": "E1", - "isPattern": "false", - "type": "" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -05. Query E1/A1 in CB -===================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 189 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "degree", - "value": "30" - } - ], - "id": "E1", - "isPattern": "false", - "type": "" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - ---TEARDOWN-- -brokerStop CB -brokerStop CP1 -dbDrop CB -dbDrop CP1 diff --git a/test/functionalTest/cases/0117_convop_using_standard_ops/postEntityByIdAttributeByNameWithTypeAndId.test.DISABLED b/test/functionalTest/cases/0117_convop_using_standard_ops/postEntityByIdAttributeByNameWithTypeAndId.test.DISABLED deleted file mode 100644 index 31b7126844..0000000000 --- a/test/functionalTest/cases/0117_convop_using_standard_ops/postEntityByIdAttributeByNameWithTypeAndId.test.DISABLED +++ /dev/null @@ -1,706 +0,0 @@ -# Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U -# -# This file is part of Orion Context Broker. -# -# Orion Context Broker is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Orion Context Broker is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -# General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -# -# For those usages not covered by this license please contact with -# iot_support at tid dot es - -# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh - ---NAME-- -ConvOp postEntityByIdAttributeByNameWithTypeAndId: POST /v1/registry/contextEntities/type/{entity::type}/id/{entity::id}/attributes/{attribute::name} - ---SHELL-INIT-- -dbInit CB -brokerStart CB 0 - ---SHELL-- - -# -# 01. POST /v1/registry/contextEntities/type/T1/id/E1/attributes/A1?entity::type=T2 and see it fail -# 02. POST /v1/registry/contextEntities/type/T1/id/E1/attributes/A1?!exist=entity::type and see it fail -# 03. POST /v1/registry/contextEntities/type/T1/id/E1/attributes/A1 and see it work -# 04. POST /v1/registry/contextEntities/type/T1/id/E1/attributes/A2?exist=entity::type and see it work -# 05. POST /v1/registry/contextEntities/type/T1/id/E1/attributes/A4?entity::type=T1 and see it work -# 06. Discover E1-T1, get three hits -# 07. POST /v1/registry/contextEntities/type/T1/id/E1/attributes/A3, without service-path -# 08. POST /v1/registry/contextEntities/type/T1/id/E1/attributes/A3, service-path /s1 -# 09. POST /v1/registry/contextEntities/type/T1/id/E1/attributes/A3, service-path /s2 -# 10. Discover E1-T1-A3, without service-path, get three hits -# 11. Discover E1-T1-A3, with service-path /#, get three hits -# 12. Discover E1-T1-A3, with service-path /, get one hit -# 13. Discover E1-T1-A3, with service-path /s1, get one hit -# 14. Discover E1-T1-A3, with service-path /s2, get one hit -# 15. Discover E1-T1-A3, with service-path /s3, get zero hits -# - -echo "01. POST /v1/registry/contextEntities/type/T1/id/E1/attributes/A1?entity::type=T2 and see it fail" -echo "=================================================================================================" -payload='{ - "duration": "PT1H", - "providingApplication": "http://kz.tid.es/part01" -}' -orionCurl --url /v1/registry/contextEntities/type/T1/id/E1/attributes/A1?entity::type=T2 --payload "$payload" -echo -echo - - -echo "02. POST /v1/registry/contextEntities/type/T1/id/E1/attributes/A1?!exist=entity::type and see it fail" -echo "=====================================================================================================" -payload='{ - "duration": "PT1H", - "providingApplication": "http://kz.tid.es/part02" -}' -orionCurl --url /v1/registry/contextEntities/type/T1/id/E1/attributes/A1?!exist=entity::type --payload "$payload" -echo -echo - - -echo "03. POST /v1/registry/contextEntities/type/T1/id/E1/attributes/A1 and see it work" -echo "=================================================================================" -payload='{ - "duration": "PT1H", - "providingApplication": "http://kz.tid.es/part03" -}' -orionCurl --url /v1/registry/contextEntities/type/T1/id/E1/attributes/A1 --payload "$payload" -echo -echo - - -echo "04. POST /v1/registry/contextEntities/type/T1/id/E1/attributes/A2?exist=entity::type and see it work" -echo "====================================================================================================" -payload='{ - "duration": "PT1H", - "providingApplication": "http://kz.tid.es/part04" -}' -orionCurl --url /v1/registry/contextEntities/type/T1/id/E1/attributes/A2?exist=entity::type --payload "$payload" -echo -echo - - -echo "05. POST /v1/registry/contextEntities/type/T1/id/E1/attributes/A4?entity::type=T1 and see it work" -echo "=================================================================================================" -payload='{ - "duration": "PT1H", - "providingApplication": "http://kz.tid.es/part05" -}' -orionCurl --url /v1/registry/contextEntities/type/T1/id/E1/attributes/A4?entity::type=T1 --payload "$payload" -echo -echo - - -echo "06. Discover E1-T1, get three hits" -echo "==================================" -payload='{ - "entities": [ - { - "type": "T1", - "isPattern": "false", - "id": "E1" - } - ] -}' -orionCurl --url /v1/registry/discoverContextAvailability --payload "$payload" -echo -echo - - -echo "07. POST /v1/registry/contextEntities/type/T1/id/E1/attributes/A3, without service-path" -echo "=======================================================================================" -payload='{ - "duration": "PT1H", - "providingApplication": "http://kz.tid.es/part07" -}' -orionCurl --url /v1/registry/contextEntities/type/T1/id/E1/attributes/A3 --payload "$payload" -echo -echo - - -echo "08. POST /v1/registry/contextEntities/type/T1/id/E1/attributes/A3, service-path /s1" -echo "===================================================================================" -payload='{ - "duration": "PT1H", - "providingApplication": "http://kz.tid.es/part08" -}' -orionCurl --url /v1/registry/contextEntities/type/T1/id/E1/attributes/A3 --payload "$payload" --servicePath /s1 -echo -echo - - -echo "09. POST /v1/registry/contextEntities/type/T1/id/E1/attributes/A3, service-path /s2" -echo "===================================================================================" -payload='{ - "duration": "PT1H", - "providingApplication": "http://kz.tid.es/part09" -}' -orionCurl --url /v1/registry/contextEntities/type/T1/id/E1/attributes/A3 --payload "$payload" --servicePath /s2 -echo -echo - - -echo "10. Discover E1-T1-A3, without service-path, get three hits" -echo "===========================================================" -payload='{ - "entities": [ - { - "type": "T1", - "isPattern": "false", - "id": "E1" - } - ], - "attributes": [ - "A3" - ] -}' -orionCurl --url /v1/registry/discoverContextAvailability --payload "$payload" -echo -echo - - -echo "11. Discover E1-T1-A3, with service-path /#, get three hits" -echo "===========================================================" -payload='{ - "entities": [ - { - "type": "T1", - "isPattern": "false", - "id": "E1" - } - ], - "attributes": [ - "A3" - ] -}' -orionCurl --url /v1/registry/discoverContextAvailability --payload "$payload" --servicePath /# -echo -echo - - -echo "12. Discover E1-T1-A3, with service-path /, get one hit" -echo "=======================================================" -payload='{ - "entities": [ - { - "type": "T1", - "isPattern": "false", - "id": "E1" - } - ], - "attributes": [ - "A3" - ] -}' -orionCurl --url /v1/registry/discoverContextAvailability --payload "$payload" --servicePath / -echo -echo - - -echo "13. Discover E1-T1-A3, with service-path /s1, get one hit" -echo "=========================================================" -payload='{ - "entities": [ - { - "type": "T1", - "isPattern": "false", - "id": "E1" - } - ], - "attributes": [ - "A3" - ] -}' -orionCurl --url /v1/registry/discoverContextAvailability --payload "$payload" --servicePath /s1 -echo -echo - - -echo "14. Discover E1-T1-A3, with service-path /s2, get one hit" -echo "=========================================================" -payload='{ - "entities": [ - { - "type": "T1", - "isPattern": "false", - "id": "E1" - } - ], - "attributes": [ - "A3" - ] -}' -orionCurl --url /v1/registry/discoverContextAvailability --payload "$payload" --servicePath /s2 -echo -echo - - -echo "15. Discover E1-T1-A3, with service-path /s3, get zero hits" -echo "===========================================================" -payload='{ - "entities": [ - { - "type": "T1", - "isPattern": "false", - "id": "E1" - } - ], - "attributes": [ - "A3" - ] -}' -orionCurl --url /v1/registry/discoverContextAvailability --payload "$payload" --servicePath /s3 -echo -echo - ---REGEXPECT-- -01. POST /v1/registry/contextEntities/type/T1/id/E1/attributes/A1?entity::type=T2 and see it fail -================================================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 147 - -{ - "errorCode": { - "code": "400", - "details": "non-matching entity::types in URL", - "reasonPhrase": "Bad Request" - }, - "registrationId": "000000000000000000000000" -} - - -02. POST /v1/registry/contextEntities/type/T1/id/E1/attributes/A1?!exist=entity::type and see it fail -===================================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 159 - -{ - "errorCode": { - "code": "400", - "details": "entity::type cannot be empty for this request", - "reasonPhrase": "Bad Request" - }, - "registrationId": "000000000000000000000000" -} - - -03. POST /v1/registry/contextEntities/type/T1/id/E1/attributes/A1 and see it work -================================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 63 - -{ - "duration": "PT1H", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -04. POST /v1/registry/contextEntities/type/T1/id/E1/attributes/A2?exist=entity::type and see it work -==================================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 63 - -{ - "duration": "PT1H", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -05. POST /v1/registry/contextEntities/type/T1/id/E1/attributes/A4?entity::type=T1 and see it work -================================================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 63 - -{ - "duration": "PT1H", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -06. Discover E1-T1, get three hits -================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 547 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A1", - "type": "" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/part03" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A2", - "type": "" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/part04" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A4", - "type": "" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/part05" - } - } - ] -} - - -07. POST /v1/registry/contextEntities/type/T1/id/E1/attributes/A3, without service-path -======================================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 63 - -{ - "duration": "PT1H", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -08. POST /v1/registry/contextEntities/type/T1/id/E1/attributes/A3, service-path /s1 -=================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 63 - -{ - "duration": "PT1H", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -09. POST /v1/registry/contextEntities/type/T1/id/E1/attributes/A3, service-path /s2 -=================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 63 - -{ - "duration": "PT1H", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -10. Discover E1-T1-A3, without service-path, get three hits -=========================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 547 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A3", - "type": "" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/part07" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A3", - "type": "" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/part08" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A3", - "type": "" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/part09" - } - } - ] -} - - -11. Discover E1-T1-A3, with service-path /#, get three hits -=========================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 547 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A3", - "type": "" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/part07" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A3", - "type": "" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/part08" - } - }, - { - "contextRegistration": { - "attributes": [ - { - "name": "A3", - "type": "" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/part09" - } - } - ] -} - - -12. Discover E1-T1-A3, with service-path /, get one hit -======================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 205 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A3", - "type": "" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/part07" - } - } - ] -} - - -13. Discover E1-T1-A3, with service-path /s1, get one hit -========================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 205 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A3", - "type": "" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/part08" - } - } - ] -} - - -14. Discover E1-T1-A3, with service-path /s2, get one hit -========================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 205 - -{ - "contextRegistrationResponses": [ - { - "contextRegistration": { - "attributes": [ - { - "name": "A3", - "type": "" - } - ], - "entities": [ - { - "id": "E1", - "isPattern": "false", - "type": "T1" - } - ], - "providingApplication": "http://kz.tid.es/part09" - } - } - ] -} - - -15. Discover E1-T1-A3, with service-path /s3, get zero hits -=========================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 70 - -{ - "errorCode": { - "code": "404", - "reasonPhrase": "No context element found" - } -} - - ---TEARDOWN-- -brokerStop CB -dbDrop CB diff --git a/test/functionalTest/cases/0117_convop_using_standard_ops/postIndividualContextEntityAttribute.test.DISABLED b/test/functionalTest/cases/0117_convop_using_standard_ops/postIndividualContextEntityAttribute.test.DISABLED deleted file mode 100644 index ad3bb99ec1..0000000000 --- a/test/functionalTest/cases/0117_convop_using_standard_ops/postIndividualContextEntityAttribute.test.DISABLED +++ /dev/null @@ -1,471 +0,0 @@ -# Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U -# -# This file is part of Orion Context Broker. -# -# Orion Context Broker is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Orion Context Broker is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -# General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -# -# For those usages not covered by this license please contact with -# iot_support at tid dot es - -# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh - ---NAME-- -ConvOp postIndividualContextEntityAttribute: POST /v1/contextEntities/{entityId::id}/attributes/{attribute::name} - ---SHELL-INIT-- -dbInit CB -brokerStart CB - ---SHELL-- - -# -# 01. POST /v1/contextEntities/E1/attributes/A1?entity::type=T1 (A1 == 1) -# 02. POST /v1/contextEntities/E1/attributes/A2?entity::type=T2 (A2 == 2) -# 03. Query CB for E1/T1 (E1/A1) -# 04. Query CB for E1/T2 (E1/A2) -# 05. POST /v1/contextEntities/E1/attributes/A3?entity::type=T1 (A3 == 3), service-path /e1/a3 -# 06. POST /v1/contextEntities/E1/attributes/A4?entity::type=T1 (A4 == 4), service-path /e1/a4 -# 07. POST /v1/contextEntities/E1/attributes/A5?entity::type=T1 (A5 == 5), service-path /e1/a5 -# 08. Query CB for E1, service-path /e1/# -# 09. Query CB for E1, service-path /e1/a4 -# - -echo "01. POST /v1/contextEntities/E1/attributes/A1?entity::type=T1 (A1 == 1)" -echo "=======================================================================" -payload='{ - "type": "AT1", - "value": "1", - "metadatas": [ - { - "name": "m1", - "type": "M1", - "value": "mmmmm 1111" - } - ] -}' -orionCurl --url /v1/contextEntities/E1/attributes/A1?entity::type=T1 --payload "$payload" -echo -echo - - -echo "02. POST /v1/contextEntities/E1/attributes/A2?entity::type=T2 (A2 == 2)" -echo "=======================================================================" -payload='{ - "type": "AT2", - "value": "2", - "metadatas": [ - { - "name": "m2", - "type": "M2", - "value": "mmmmm 2222" - } - ] -}' -orionCurl --url /v1/contextEntities/E1/attributes/A2?entity::type=T2 --payload "$payload" -echo -echo - - -echo "03. Query CB for E1/T1 (E1/A1)" -echo "==============================" -payload='{ - "entities": [ - { - "id": "E1", - "type": "T1" - } - ] -}' -orionCurl --url /v1/queryContext --payload "$payload" -echo -echo - - -echo "04. Query CB for E1/T2 (E1/A2)" -echo "==============================" -payload='{ - "entities": [ - { - "id": "E1", - "type": "T2" - } - ] -}' -orionCurl --url /v1/queryContext --payload "$payload" -echo -echo - - -echo "05. POST /v1/contextEntities/E1/attributes/A3?entity::type=T1 (A3 == 3), service-path /e1/a3" -echo "============================================================================================" -payload='{ - "type": "AT3", - "value": "3", - "metadatas": [ - { - "name": "m3", - "type": "M3", - "value": "mmmmm 3333" - } - ] -}' -orionCurl --url /v1/contextEntities/E1/attributes/A3?entity::type=T1 --payload "$payload" --servicePath /e1/a3 -echo -echo - - -echo "06. POST /v1/contextEntities/E1/attributes/A4?entity::type=T1 (A4 == 4), service-path /e1/a4" -echo "============================================================================================" -payload='{ - "type": "AT4", - "value": "4", - "metadatas": [ - { - "name": "m4", - "type": "M4", - "value": "mmmmm 4444" - } - ] -}' -orionCurl --url /v1/contextEntities/E1/attributes/A4?entity::type=T1 --payload "$payload" --servicePath /e1/a4 -echo -echo - - -echo "07. POST /v1/contextEntities/E1/attributes/A5?entity::type=T1 (A5 == 5), service-path /e1/a5" -echo "============================================================================================" -payload='{ - "type": "AT5", - "value": "5", - "metadatas": [ - { - "name": "m5", - "type": "M5", - "value": "mmmmm 5555" - } - ] -}' -orionCurl --url /v1/contextEntities/E1/attributes/A5?entity::type=T1 --payload "$payload" --servicePath /e1/a5 -echo -echo - - -echo "08. Query CB for E1, service-path /e1/#" -echo "=======================================" -payload='{ - "entities": [ - { - "id": "E1" - } - ] -}' -orionCurl --url /v1/queryContext --payload "$payload" --servicePath /e1/# -echo -echo - - -echo "09. Query CB for E1, service-path /e1/a4" -echo "=======================================" -payload='{ - "entities": [ - { - "id": "E1" - } - ] -}' -orionCurl --url /v1/queryContext --payload "$payload" --servicePath /e1/a4 -echo -echo - - ---REGEXPECT-- -01. POST /v1/contextEntities/E1/attributes/A1?entity::type=T1 (A1 == 1) -======================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 34 - -{ - "code": "200", - "reasonPhrase": "OK" -} - - -02. POST /v1/contextEntities/E1/attributes/A2?entity::type=T2 (A2 == 2) -======================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 34 - -{ - "code": "200", - "reasonPhrase": "OK" -} - - -03. Query CB for E1/T1 (E1/A1) -============================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 248 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "metadatas": [ - { - "name": "m1", - "type": "M1", - "value": "mmmmm 1111" - } - ], - "name": "A1", - "type": "AT1", - "value": "1" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -04. Query CB for E1/T2 (E1/A2) -============================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 248 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "metadatas": [ - { - "name": "m2", - "type": "M2", - "value": "mmmmm 2222" - } - ], - "name": "A2", - "type": "AT2", - "value": "2" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T2" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -05. POST /v1/contextEntities/E1/attributes/A3?entity::type=T1 (A3 == 3), service-path /e1/a3 -============================================================================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 34 - -{ - "code": "200", - "reasonPhrase": "OK" -} - - -06. POST /v1/contextEntities/E1/attributes/A4?entity::type=T1 (A4 == 4), service-path /e1/a4 -============================================================================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 34 - -{ - "code": "200", - "reasonPhrase": "OK" -} - - -07. POST /v1/contextEntities/E1/attributes/A5?entity::type=T1 (A5 == 5), service-path /e1/a5 -============================================================================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 34 - -{ - "code": "200", - "reasonPhrase": "OK" -} - - -08. Query CB for E1, service-path /e1/# -======================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 700 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "metadatas": [ - { - "name": "m3", - "type": "M3", - "value": "mmmmm 3333" - } - ], - "name": "A3", - "type": "AT3", - "value": "3" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - }, - { - "contextElement": { - "attributes": [ - { - "metadatas": [ - { - "name": "m4", - "type": "M4", - "value": "mmmmm 4444" - } - ], - "name": "A4", - "type": "AT4", - "value": "4" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - }, - { - "contextElement": { - "attributes": [ - { - "metadatas": [ - { - "name": "m5", - "type": "M5", - "value": "mmmmm 5555" - } - ], - "name": "A5", - "type": "AT5", - "value": "5" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -09. Query CB for E1, service-path /e1/a4 -======================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 248 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "metadatas": [ - { - "name": "m4", - "type": "M4", - "value": "mmmmm 4444" - } - ], - "name": "A4", - "type": "AT4", - "value": "4" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - ---TEARDOWN-- -brokerStop CB -dbDrop CB diff --git a/test/functionalTest/cases/0117_convop_using_standard_ops/postIndividualContextEntityAttributeWithTypeAndId.test.DISABLED b/test/functionalTest/cases/0117_convop_using_standard_ops/postIndividualContextEntityAttributeWithTypeAndId.test.DISABLED deleted file mode 100644 index bcd51a8180..0000000000 --- a/test/functionalTest/cases/0117_convop_using_standard_ops/postIndividualContextEntityAttributeWithTypeAndId.test.DISABLED +++ /dev/null @@ -1,380 +0,0 @@ -# Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U -# -# This file is part of Orion Context Broker. -# -# Orion Context Broker is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Orion Context Broker is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -# General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -# -# For those usages not covered by this license please contact with -# iot_support at tid dot es - -# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh - ---NAME-- -ConvOp postIndividualContextEntityAttributeWithTypeAndId: POST /v1/contextEntities/type/{entity::type}/id/{entity::id}/attributes/{attribute::name} - ---SHELL-INIT-- -dbInit CB -brokerStart CB 0 - ---SHELL-- - -# -# 01. POST /v1/contextEntities/type/T1/id/E1/attributes/A1, A1=1 -# 02. GET /v1/contextEntities/type/T1/id/E1/attributes/A1 -# 03. POST /v1/contextEntities/type/T1/id/E1/attributes/A1?entity::type=T2, and see it fail -# 04. POST /v1/contextEntities/type/T1/id/E1/attributes/A1?entity::type=T1, and see it work -# 05. POST /v1/contextEntities/type/T1/id/E1/attributes/A1?!exist=entity::type, and see it fail -# 06. POST /v1/contextEntities/type/T1/id/E1/attributes/A1?exist=entity::type, A1=2 -# 07. GET /v1/contextEntities/type/T1/id/E1/attributes/A1 -# 08. POST /v1/contextEntities/type/T1/id/E1/attributes/A1, A1=s1, with servicePath=/s1 -# 09. GET /v1/contextEntities/type/T1/id/E1/attributes/A1, with servicePath=/s1 -# 10. GET /v1/contextEntities/type/T1/id/E1/attributes/A1, with servicePath=/ -# 11. POST /v1/queryContext, without servicePath, see two results -# - -echo "01. POST /v1/contextEntities/type/T1/id/E1/attributes/A1, A1=1" -echo "==============================================================" -payload='{ - "value": 1 -}' -orionCurl --url /v1/contextEntities/type/T1/id/E1/attributes/A1 --payload "$payload" -echo -echo - - -echo "02. GET /v1/contextEntities/type/T1/id/E1/attributes/A1" -echo "=======================================================" -orionCurl --url /v1/contextEntities/type/T1/id/E1/attributes/A1 -echo -echo - - -echo "03. POST /v1/contextEntities/type/T1/id/E1/attributes/A1?entity::type=T2, and see it fail" -echo "=========================================================================================" -payload='{ - "value": 3 -}' -orionCurl --url /v1/contextEntities/type/T1/id/E1/attributes/A1?entity::type=T2 --payload "$payload" -echo -echo - - -echo "04. POST /v1/contextEntities/type/T1/id/E1/attributes/A1?entity::type=T1, and see it work" -echo "=========================================================================================" -payload='{ - "value": 4 -}' -orionCurl --url /v1/contextEntities/type/T1/id/E1/attributes/A1?entity::type=T1 --payload "$payload" -echo -echo - - -echo "05. POST /v1/contextEntities/type/T1/id/E1/attributes/A1?!exist=entity::type, and see it fail" -echo "=============================================================================================" -payload='{ - "value": 1 -}' -orionCurl --url /v1/contextEntities/type/T1/id/E1/attributes/A1?!exist=entity::type --payload "$payload" -echo -echo - - -echo "06. POST /v1/contextEntities/type/T1/id/E1/attributes/A1?exist=entity::type, A1=2" -echo "=================================================================================" -payload='{ - "value": 2 -}' -orionCurl --url /v1/contextEntities/type/T1/id/E1/attributes/A1?exist=entity::type --payload "$payload" -echo -echo - - -echo "07. GET /v1/contextEntities/type/T1/id/E1/attributes/A1" -echo "=======================================================" -orionCurl --url /v1/contextEntities/type/T1/id/E1/attributes/A1 -echo -echo - - -echo "08. POST /v1/contextEntities/type/T1/id/E1/attributes/A1, A1=s1, with servicePath=/s1" -echo "=====================================================================================" -payload='{ - "value": "s1" -}' -orionCurl --url /v1/contextEntities/type/T1/id/E1/attributes/A1 --payload "$payload" --servicePath /s1 -echo -echo - - -echo "09. GET /v1/contextEntities/type/T1/id/E1/attributes/A1, with servicePath=/s1" -echo "=============================================================================" -orionCurl --url /v1/contextEntities/type/T1/id/E1/attributes/A1 --servicePath /s1 -echo -echo - - -echo "10. GET /v1/contextEntities/type/T1/id/E1/attributes/A1, with servicePath=/" -echo "===========================================================================" -orionCurl --url /v1/contextEntities/type/T1/id/E1/attributes/A1 --servicePath / -echo -echo - - -echo "11. POST /v1/queryContext, without servicePath, see two results" -echo "===============================================================" -payload='{ - "entities": [ - { - "type": "T1", - "id": "E1" - } - ] -}' -orionCurl --url /v1/queryContext --payload "$payload" -echo -echo - - ---REGEXPECT-- -01. POST /v1/contextEntities/type/T1/id/E1/attributes/A1, A1=1 -============================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 34 - -{ - "code": "200", - "reasonPhrase": "OK" -} - - -02. GET /v1/contextEntities/type/T1/id/E1/attributes/A1 -======================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 100 - -{ - "attributes": [ - { - "name": "A1", - "type": "", - "value": "1" - } - ], - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } -} - - -03. POST /v1/contextEntities/type/T1/id/E1/attributes/A1?entity::type=T2, and see it fail -========================================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 89 - -{ - "code": "400", - "details": "non-matching entity::types in URL", - "reasonPhrase": "Bad Request" -} - - -04. POST /v1/contextEntities/type/T1/id/E1/attributes/A1?entity::type=T1, and see it work -========================================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 34 - -{ - "code": "200", - "reasonPhrase": "OK" -} - - -05. POST /v1/contextEntities/type/T1/id/E1/attributes/A1?!exist=entity::type, and see it fail -============================================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 101 - -{ - "code": "400", - "details": "entity::type cannot be empty for this request", - "reasonPhrase": "Bad Request" -} - - -06. POST /v1/contextEntities/type/T1/id/E1/attributes/A1?exist=entity::type, A1=2 -================================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 34 - -{ - "code": "200", - "reasonPhrase": "OK" -} - - -07. GET /v1/contextEntities/type/T1/id/E1/attributes/A1 -======================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 100 - -{ - "attributes": [ - { - "name": "A1", - "type": "", - "value": "2" - } - ], - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } -} - - -08. POST /v1/contextEntities/type/T1/id/E1/attributes/A1, A1=s1, with servicePath=/s1 -===================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 34 - -{ - "code": "200", - "reasonPhrase": "OK" -} - - -09. GET /v1/contextEntities/type/T1/id/E1/attributes/A1, with servicePath=/s1 -============================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 101 - -{ - "attributes": [ - { - "name": "A1", - "type": "", - "value": "s1" - } - ], - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } -} - - -10. GET /v1/contextEntities/type/T1/id/E1/attributes/A1, with servicePath=/ -=========================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 100 - -{ - "attributes": [ - { - "name": "A1", - "type": "", - "value": "2" - } - ], - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } -} - - -11. POST /v1/queryContext, without servicePath, see two results -=============================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 347 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "", - "value": "2" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - }, - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "", - "value": "s1" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - ---TEARDOWN-- -brokerStop CB -dbDrop CB diff --git a/test/functionalTest/cases/0117_convop_using_standard_ops/postIndividualContextEntity_v1_contextEntities.test.DISABLED b/test/functionalTest/cases/0117_convop_using_standard_ops/postIndividualContextEntity_v1_contextEntities.test.DISABLED deleted file mode 100644 index f6d72c12f7..0000000000 --- a/test/functionalTest/cases/0117_convop_using_standard_ops/postIndividualContextEntity_v1_contextEntities.test.DISABLED +++ /dev/null @@ -1,459 +0,0 @@ -# Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U -# -# This file is part of Orion Context Broker. -# -# Orion Context Broker is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Orion Context Broker is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -# General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -# -# For those usages not covered by this license please contact with -# iot_support at tid dot es - -# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh - ---NAME-- -ConvOp postIndividualContextEntity: POST /v1/contextEntities - ---SHELL-INIT-- -dbInit CB -brokerStart CB - ---SHELL-- - -# -# 01. POST /v1/contextEntities -# 02. Query the entity 'E1' that was just created -# 03. Query the entity 'E1' with URI-param attributesFormat=object -# 04. POST /v1/contextEntities?entity::type=E (id='E2', type='F' in payload) and see it fail -# 05. POST /v1/contextEntities?entity::type=E (isPattern='true' in payload) and see it fail -# 06. POST /v1/contextEntities?entity::type=E (id='E2', type='E' in payload) and see it work -# 07. Query the entity 'E2' that was just created -# 08. Change attribute 'A' of the entity 'E2' -# 09. Query the entity 'E2' that was just modified -# - - -echo "01. POST /v1/contextEntities" -echo "============================" -payload='{ - "id": "E1", - "type": "E", - "isPattern": "false", - "attributes": [ - { - "name": "A1", - "type": "AT", - "value": "10" - } - ] -}' -orionCurl --url /v1/contextEntities --payload "${payload}" -echo -echo - - -echo "02. Query the entity 'E1' that was just created" -echo "===============================================" -payload='{ - "entities": [ - { - "type": "E", - "isPattern": "false", - "id": "E1" - } - ] -}' -orionCurl --url /v1/queryContext --payload "${payload}" -echo -echo - - -echo "03. Query the entity 'E1' with URI-param attributesFormat=object" -echo "================================================================" -payload='{ - "entities": [ - { - "type": "E", - "isPattern": "false", - "id": "E1" - } - ] -}' -orionCurl --url /v1/queryContext --payload "${payload}" --urlParams attributesFormat=object -echo -echo - - -echo "04. POST /v1/contextEntities?entity::type=E (id='E2', type='F' in payload) and see it fail" -echo "==========================================================================================" -payload='{ - "id": "E2", - "type": "F", - "isPattern": "false", - "attributes": [ - { - "name": "A1", - "type": "AT", - "value": "10" - } - ] -}' -orionCurl --url /v1/contextEntities?entity::type=E --payload "${payload}" -echo -echo - - -echo "05. POST /v1/contextEntities?entity::type=E (isPattern='true' in payload) and see it fail" -echo "=========================================================================================" -payload='{ - "id": "E2", - "type": "E", - "isPattern": "true", - "attributes": [ - { - "name": "A1", - "type": "AT", - "value": "10" - } - ] -}' -orionCurl --url /v1/contextEntities?entity::type=E --payload "${payload}" -echo -echo - - -echo "06. POST /v1/contextEntities?entity::type=E (id='E2', type='E' in payload) and see it work" -echo "==========================================================================================" -payload='{ - "id": "E2", - "type": "E", - "isPattern": "false", - "attributes": [ - { - "name": "A1", - "type": "AT", - "value": "10" - } - ] -}' -orionCurl --url /v1/contextEntities?entity::type=E --payload "${payload}" -echo -echo - - -echo "07. Query the entity 'E2' that was just created" -echo "===============================================" -payload='{ - "entities": [ - { - "type": "E", - "isPattern": "false", - "id": "E2" - } - ] -}' -orionCurl --url /v1/queryContext --payload "${payload}" -echo -echo - - - -echo "08. Change attribute 'A' of the entity 'E2'" -echo "===========================================" -payload='{ - "id": "E2", - "type": "E", - "isPattern": "false", - "attributes": [ - { - "name": "A1", - "type": "AT", - "value": "200" - } - ] -}' -orionCurl --url /v1/contextEntities?entity::type=E --payload "${payload}" -echo -echo - - -echo "09. Query the entity 'E2' that was just modified" -echo "================================================" -payload='{ - "entities": [ - { - "type": "E", - "isPattern": "false", - "id": "E2" - } - ] -}' -orionCurl --url /v1/queryContext --payload "${payload}" -echo -echo - - ---REGEXPECT-- -01. POST /v1/contextEntities -============================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 165 - -{ - "contextResponses": [ - { - "attributes": [ - { - "name": "A1", - "type": "AT", - "value": "" - } - ], - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ], - "id": "E1", - "isPattern": "false", - "type": "E" -} - - -02. Query the entity 'E1' that was just created -=============================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 186 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "AT", - "value": "10" - } - ], - "id": "E1", - "isPattern": "false", - "type": "E" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -03. Query the entity 'E1' with URI-param attributesFormat=object -================================================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 179 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": { - "A1": { - "type": "AT", - "value": "10" - } - }, - "id": "E1", - "isPattern": "false", - "type": "E" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -04. POST /v1/contextEntities?entity::type=E (id='E2', type='F' in payload) and see it fail -========================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 111 - -{ - "errorCode": { - "code": "400", - "details": "entityId::type differs in URL and payload", - "reasonPhrase": "Bad Request" - } -} - - -05. POST /v1/contextEntities?entity::type=E (isPattern='true' in payload) and see it fail -========================================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 140 - -{ - "errorCode": { - "code": "400", - "details": "entityId::isPattern set to true in contextUpdate convenience operation", - "reasonPhrase": "Bad Request" - } -} - - -06. POST /v1/contextEntities?entity::type=E (id='E2', type='E' in payload) and see it work -========================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 165 - -{ - "contextResponses": [ - { - "attributes": [ - { - "name": "A1", - "type": "AT", - "value": "" - } - ], - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ], - "id": "E2", - "isPattern": "false", - "type": "E" -} - - -07. Query the entity 'E2' that was just created -=============================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 186 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "AT", - "value": "10" - } - ], - "id": "E2", - "isPattern": "false", - "type": "E" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -08. Change attribute 'A' of the entity 'E2' -=========================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 165 - -{ - "contextResponses": [ - { - "attributes": [ - { - "name": "A1", - "type": "AT", - "value": "" - } - ], - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ], - "id": "E2", - "isPattern": "false", - "type": "E" -} - - -09. Query the entity 'E2' that was just modified -================================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 187 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "AT", - "value": "200" - } - ], - "id": "E2", - "isPattern": "false", - "type": "E" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - ---TEARDOWN-- -brokerStop CB -dbDrop CB diff --git a/test/functionalTest/cases/0117_convop_using_standard_ops/postIndividualContextEntity_v1_contextEntities_EID.test.DISABLED b/test/functionalTest/cases/0117_convop_using_standard_ops/postIndividualContextEntity_v1_contextEntities_EID.test.DISABLED deleted file mode 100644 index 5bc2a62fe4..0000000000 --- a/test/functionalTest/cases/0117_convop_using_standard_ops/postIndividualContextEntity_v1_contextEntities_EID.test.DISABLED +++ /dev/null @@ -1,496 +0,0 @@ -# Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U -# -# This file is part of Orion Context Broker. -# -# Orion Context Broker is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Orion Context Broker is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -# General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -# -# For those usages not covered by this license please contact with -# iot_support at tid dot es - -# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh - ---NAME-- -ConvOp postIndividualContextEntity: POST /v1/contextEntities/{entityId::id} - ---SHELL-INIT-- -dbInit CB -brokerStart CB - ---SHELL-- - -# -# 01. POST /v1/contextEntities/E1 -# 02. Query the entity 'E1' that was just created -# 03. Query the entity 'E1' with URI-param attributesFormat=object -# 04. POST /v1/contextEntities/E2?entity::type=E (id='E2', type='F' in payload) and see it fail -# 05. POST /v1/contextEntities/E2?entity::type=E (id='E3', type='E' in payload) and see it fail -# 06. POST /v1/contextEntities/E2?entity::type=E (isPattern='true' in payload) and see it fail -# 07. POST /v1/contextEntities/E2?entity::type=E (id='E2', type='E' in payload) and see it work -# 08. Query the entity 'E2' that was just created -# 09. Change attribute 'A' of the entity 'E2' -# 10. Query the entity 'E2' that was just modified -# - - -echo "01. POST /v1/contextEntities/E1" -echo "===============================" -payload='{ - "id": "E1", - "type": "E", - "isPattern": "false", - "attributes": [ - { - "name": "A1", - "type": "AT", - "value": "10" - } - ] -}' -orionCurl --url /v1/contextEntities/E1 --payload "${payload}" -echo -echo - - -echo "02. Query the entity 'E1' that was just created" -echo "===============================================" -payload='{ - "entities": [ - { - "type": "E", - "isPattern": "false", - "id": "E1" - } - ] -}' -orionCurl --url /v1/queryContext --payload "${payload}" -echo -echo - - -echo "03. Query the entity 'E1' with URI-param attributesFormat=object" -echo "================================================================" -payload='{ - "entities": [ - { - "type": "E", - "isPattern": "false", - "id": "E1" - } - ] -}' -orionCurl --url /v1/queryContext --payload "${payload}" --urlParams attributesFormat=object -echo -echo - - -echo "04. POST /v1/contextEntities/E2?entity::type=E (id='E2', type='F' in payload) and see it fail" -echo "=============================================================================================" -payload='{ - "id": "E2", - "type": "F", - "isPattern": "false", - "attributes": [ - { - "name": "A1", - "type": "AT", - "value": "10" - } - ] -}' -orionCurl --url /v1/contextEntities/E2?entity::type=E --payload "${payload}" -echo -echo - - -echo "05. POST /v1/contextEntities/E2?entity::type=E (id='E3', type='E' in payload) and see it fail" -echo "=============================================================================================" -payload='{ - "id": "E3", - "type": "E", - "isPattern": "false", - "attributes": [ - { - "name": "A1", - "type": "AT", - "value": "10" - } - ] -}' -orionCurl --url /v1/contextEntities/E2?entity::type=E --payload "${payload}" -echo -echo - - -echo "06. POST /v1/contextEntities/E2?entity::type=E (isPattern='true' in payload) and see it fail" -echo "============================================================================================" -payload='{ - "id": "E2", - "type": "E", - "isPattern": "true", - "attributes": [ - { - "name": "A1", - "type": "AT", - "value": "10" - } - ] -}' -orionCurl --url /v1/contextEntities/E2?entity::type=E --payload "${payload}" -echo -echo - - -echo "07. POST /v1/contextEntities/E2?entity::type=E (id='E2', type='E' in payload) and see it work" -echo "=============================================================================================" -payload='{ - "id": "E2", - "type": "E", - "isPattern": "false", - "attributes": [ - { - "name": "A1", - "type": "AT", - "value": "10" - } - ] -}' -orionCurl --url /v1/contextEntities/E2?entity::type=E --payload "${payload}" -echo -echo - - -echo "08. Query the entity 'E2' that was just created" -echo "===============================================" -payload='{ - "entities": [ - { - "type": "E", - "isPattern": "false", - "id": "E2" - } - ] -}' -orionCurl --url /v1/queryContext --payload "${payload}" -echo -echo - - - -echo "09. Change attribute 'A' of the entity 'E2'" -echo "===========================================" -payload='{ - "id": "E2", - "type": "E", - "isPattern": "false", - "attributes": [ - { - "name": "A1", - "type": "AT", - "value": "200" - } - ] -}' -orionCurl --url /v1/contextEntities/E2?entity::type=E --payload "${payload}" -echo -echo - - -echo "10. Query the entity 'E2' that was just modified" -echo "================================================" -payload='{ - "entities": [ - { - "type": "E", - "isPattern": "false", - "id": "E2" - } - ] -}' -orionCurl --url /v1/queryContext --payload "${payload}" -echo -echo - - ---REGEXPECT-- -01. POST /v1/contextEntities/E1 -=============================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 165 - -{ - "contextResponses": [ - { - "attributes": [ - { - "name": "A1", - "type": "AT", - "value": "" - } - ], - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ], - "id": "E1", - "isPattern": "false", - "type": "E" -} - - -02. Query the entity 'E1' that was just created -=============================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 186 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "AT", - "value": "10" - } - ], - "id": "E1", - "isPattern": "false", - "type": "E" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -03. Query the entity 'E1' with URI-param attributesFormat=object -================================================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 179 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": { - "A1": { - "type": "AT", - "value": "10" - } - }, - "id": "E1", - "isPattern": "false", - "type": "E" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -04. POST /v1/contextEntities/E2?entity::type=E (id='E2', type='F' in payload) and see it fail -============================================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 111 - -{ - "errorCode": { - "code": "400", - "details": "entityId::type differs in URL and payload", - "reasonPhrase": "Bad Request" - } -} - - -05. POST /v1/contextEntities/E2?entity::type=E (id='E3', type='E' in payload) and see it fail -============================================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 109 - -{ - "errorCode": { - "code": "400", - "details": "entityId::id differs in URL and payload", - "reasonPhrase": "Bad Request" - } -} - - -06. POST /v1/contextEntities/E2?entity::type=E (isPattern='true' in payload) and see it fail -============================================================================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 140 - -{ - "errorCode": { - "code": "400", - "details": "entityId::isPattern set to true in contextUpdate convenience operation", - "reasonPhrase": "Bad Request" - } -} - - -07. POST /v1/contextEntities/E2?entity::type=E (id='E2', type='E' in payload) and see it work -============================================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 165 - -{ - "contextResponses": [ - { - "attributes": [ - { - "name": "A1", - "type": "AT", - "value": "" - } - ], - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ], - "id": "E2", - "isPattern": "false", - "type": "E" -} - - -08. Query the entity 'E2' that was just created -=============================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 186 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "AT", - "value": "10" - } - ], - "id": "E2", - "isPattern": "false", - "type": "E" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -09. Change attribute 'A' of the entity 'E2' -=========================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 165 - -{ - "contextResponses": [ - { - "attributes": [ - { - "name": "A1", - "type": "AT", - "value": "" - } - ], - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ], - "id": "E2", - "isPattern": "false", - "type": "E" -} - - -10. Query the entity 'E2' that was just modified -================================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 187 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "AT", - "value": "200" - } - ], - "id": "E2", - "isPattern": "false", - "type": "E" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - ---TEARDOWN-- -brokerStop CB -dbDrop CB diff --git a/test/functionalTest/cases/0117_convop_using_standard_ops/postSubscribeContextConvOp.test.DISABLED b/test/functionalTest/cases/0117_convop_using_standard_ops/postSubscribeContextConvOp.test.DISABLED deleted file mode 100644 index cc47c7a7ef..0000000000 --- a/test/functionalTest/cases/0117_convop_using_standard_ops/postSubscribeContextConvOp.test.DISABLED +++ /dev/null @@ -1,269 +0,0 @@ -# Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U -# -# This file is part of Orion Context Broker. -# -# Orion Context Broker is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Orion Context Broker is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -# General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -# -# For those usages not covered by this license please contact with -# iot_support at tid dot es - -# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh - ---NAME-- -ConvOp postSubscribeContextConvOp: POST /v1/contextSubscriptions - ---SHELL-INIT-- -dbInit CB -brokerStart CB 0 -accumulatorStart --pretty-print - ---SHELL-- - -# -# 01. Subscribe to E1/T1:ONCHANGE (POST /v1/contextSubscriptions) -# 02. Create E1/T2 -# 03. Dump accumulator to see NOTHING -# 04. Create E1/T1 -# 05. Dump accumulator to see E1/T1 -# -# FIXME: Once NGSI10 Subscriptions implement Restrictions 'exist=entity::type' and '!exist=entity::type' -# 06. Subscribe to E2/:ONCHANGE (POST /v1/contextSubscriptions?!exist=entity::type) -# 07. Create E2/ -# 08. Create E2/T1 -# 09. Dump accumulator to see 'E2/' only -# 10. Reset accumulator -# 11. Subscribe to E2/ -# 12. Dump accumulator to see 'E2/T1' only -# 13. Reset accumulator -# 14. Subscribe to E2/:ONCHANGE (POST /v1/contextSubscriptions?exist=entity::type) -# 15. Dump accumulator to see 'E2/T1' only -# 16. Reset accumulator -# 17. Update E2/T1 -# 18. Dump accumulator to see one notification of 'E2/T1' only -# - -echo "01. Subscribe to E1/T1:ONCHANGE (POST /v1/contextSubscriptions)" -echo "===============================================================" -payload='{ - "entities": [ - { - "id": "E1", - "type": "T1" - } - ], - "reference": "http://localhost:'$LISTENER_PORT'/notify", - "duration": "P5Y", - "throttling": "P5Y", - "notifyConditions": [ - { - "type": "ONCHANGE", - "condValues": [ - "A1" - ] - } - ] -}' -orionCurl --url /v1/contextSubscriptions --payload "$payload" -echo -echo - - -echo "02. Create E1/T2" -echo "================" -payload='{ - "contextElements": [ - { - "id": "E1", - "type": "T2", - "attributes" : [ - { - "name" : "A1", - "type" : "a", - "value" : "E1/T2/A1" - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" -echo -echo - - -echo "03. Dump accumulator to see NOTHING" -echo "===================================" -accumulatorDump -echo -echo - - -echo "04. Create E1/T1" -echo "================" -payload='{ - "contextElements": [ - { - "id": "E1", - "type": "T1", - "attributes" : [ - { - "name" : "A1", - "type" : "a", - "value" : "E1/T1/A1" - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" -echo -echo - - -echo "05. Dump accumulator to see E1/T1" -echo "=================================" -accumulatorDump -echo -echo - - ---REGEXPECT-- -01. Subscribe to E1/T1:ONCHANGE (POST /v1/contextSubscriptions) -=============================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 103 - -{ - "subscribeResponse": { - "duration": "P5Y", - "subscriptionId": "REGEX([0-9a-f]{24})", - "throttling": "P5Y" - } -} - - -02. Create E1/T2 -================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 184 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "a", - "value": "" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T2" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -03. Dump accumulator to see NOTHING -=================================== - - -04. Create E1/T1 -================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 184 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "a", - "value": "" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -05. Dump accumulator to see E1/T1 -================================= -POST http://localhost:REGEX(\d+)/notify -Fiware-Servicepath: / -Content-Length: 261 -User-Agent: orion/REGEX(\d+\.\d+\.\d+.*) -Host: localhost:REGEX(\d+) -Accept: application/json -Content-Type: application/json; charset=utf-8 -Fiware-Correlator: REGEX([0-9a-f\-]{36}); cbnotif=1 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "a", - "value": "E1/T1/A1" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ], - "originator": "localhost", - "subscriptionId": "REGEX([0-9a-f]{24})" -} -======================================= - - ---TEARDOWN-- -brokerStop CB -accumulatorStop -dbDrop CB diff --git a/test/functionalTest/cases/0117_convop_using_standard_ops/putAllEntitiesWithTypeAndId.test.DISABLED b/test/functionalTest/cases/0117_convop_using_standard_ops/putAllEntitiesWithTypeAndId.test.DISABLED deleted file mode 100644 index 938ac9ce74..0000000000 --- a/test/functionalTest/cases/0117_convop_using_standard_ops/putAllEntitiesWithTypeAndId.test.DISABLED +++ /dev/null @@ -1,539 +0,0 @@ -# Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U -# -# This file is part of Orion Context Broker. -# -# Orion Context Broker is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Orion Context Broker is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -# General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -# -# For those usages not covered by this license please contact with -# iot_support at tid dot es - -# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh - ---NAME-- -ConvOp putAllEntitiesWithTypeAndId: PUT /v1/contextEntities/type/{entity::type}/id/{entity::id} - ---SHELL-INIT-- -dbInit CB -dbInit CP1 -brokerStart CB 0 -brokerStart CP1 0 - ---SHELL-- - -# -# 01. PUT /v1/contextEntities/type/T1/id/E1, see it fail -# 02. Update/APPEND E1-T1 -# 03. PUT /v1/contextEntities/type/T1/id/E1,A1=3 see it work -# 04. PUT /v1/contextEntities/type/T1/id/E1?attributeFormat=object,A1=4 see it work -# 05. PUT /v1/contextEntities/type/T1/id/E1?entity::type=T1,A1=5 see it work -# 06. PUT /v1/contextEntities/type/T1/id/E1?entity::type=T2, and see it fail -# 07. PUT /v1/contextEntities/type/T1/id/E1?!exist=entity::type and see it fail -# 08. PUT /v1/contextEntities/type/T1/id/E1?exist=entity::type and see it work -# 09. Register E2-T1 in CB for CP1 -# 10. PUT /v1/contextEntities/type/T1/id/E2, see it fail (does not exist in CP1) -# 11. Update/APPEND E2-T1 in CP1 -# 12. PUT /v1/contextEntities/type/T1/id/E2, see it work -# - -echo "01. PUT /v1/contextEntities/type/T1/id/E1, see it fail" -echo "======================================================" -payload='{ - "attributes": [ - { - "name": "A1", - "value": 1 - } - ] -}' -orionCurl --url /v1/contextEntities/type/T1/id/E1 --payload "$payload" -X PUT -echo -echo - - -echo "02. Update/APPEND E1-T1" -echo "=======================" -payload='{ - "contextElements": [ - { - "type" : "T1", - "id" : "E1", - "attributes" : [ - { - "name" : "A1", - "value" : 1 - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" -echo -echo - - -echo "03. PUT /v1/contextEntities/type/T1/id/E1,A1=3 see it work" -echo "==========================================================" -payload='{ - "attributes": [ - { - "name": "A1", - "value": 3 - } - ] -}' -orionCurl --url /v1/contextEntities/type/T1/id/E1 --payload "$payload" -X PUT -echo -echo - - -echo "04. PUT /v1/contextEntities/type/T1/id/E1?attributeFormat=object,A1=4 see it work" -echo "=================================================================================" -payload='{ - "attributes": [ - { - "name": "A1", - "value": 4 - } - ] -}' -orionCurl --url /v1/contextEntities/type/T1/id/E1?attributeFormat=object --payload "$payload" -X PUT -echo -echo - - -echo "05. PUT /v1/contextEntities/type/T1/id/E1?entity::type=T1,A1=5 see it work" -echo "==========================================================================" -payload='{ - "attributes": [ - { - "name": "A1", - "value": 5 - } - ] -}' -orionCurl --url /v1/contextEntities/type/T1/id/E1?entity::type=T1 --payload "$payload" -X PUT -echo -echo - - -echo "06. PUT /v1/contextEntities/type/T1/id/E1?entity::type=T2, and see it fail" -echo "==========================================================================" -payload='{ - "attributes": [ - { - "name": "A1", - "value": 6 - } - ] -}' -orionCurl --url /v1/contextEntities/type/T1/id/E1?entity::type=T2 --payload "$payload" -X PUT -echo -echo - - -echo "07. PUT /v1/contextEntities/type/T1/id/E1?!exist=entity::type and see it fail" -echo "=============================================================================" -payload='{ - "attributes": [ - { - "name": "A1", - "value": 7 - } - ] -}' -orionCurl --url /v1/contextEntities/type/T1/id/E1?!exist=entity::type --payload "$payload" -X PUT -echo -echo - - -echo "08. PUT /v1/contextEntities/type/T1/id/E1?exist=entity::type and see it work" -echo "============================================================================" -payload='{ - "attributes": [ - { - "name": "A1", - "value": 8 - } - ] -}' -orionCurl --url /v1/contextEntities/type/T1/id/E1?exist=entity::type --payload "$payload" -X PUT -echo -echo - - -echo "09. Register E2-T1 in CB for CP1" -echo "================================" -payload='{ - "contextRegistrations": [ - { - "entities": [ - { - "type": "T1", - "id": "E2" - } - ], - "attributes": [ - { - "name": "A1" - } - ], - "providingApplication": "http://localhost:'${CP1_PORT}'/v1" - } - ], - "duration": "P1M" -}' -orionCurl --url /v1/registry/registerContext --payload "$payload" -echo -echo - - -echo "10. PUT /v1/contextEntities/type/T1/id/E2, see it fail (does not exist in CP1)" -echo "==============================================================================" -payload='{ - "attributes": [ - { - "name": "A1", - "value": 5 - } - ] -}' -orionCurl --url /v1/contextEntities/type/T1/id/E2 --payload "$payload" -X PUT -echo -echo - - -echo "11. Update/APPEND E2-T1 in CP1" -echo "==============================" -payload='{ - "contextElements": [ - { - "type": "T1", - "id": "E2", - "attributes": [ - { - "name": "A1", - "value": 6 - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" --port $CP1_PORT -echo -echo - - -echo "12. PUT /v1/contextEntities/type/T1/id/E2, see it work" -echo "======================================================" -payload='{ - "attributes": [ - { - "name": "A1", - "value": 7 - } - ] -}' -orionCurl --url /v1/contextEntities/type/T1/id/E2 --payload "$payload" -X PUT -echo -echo - - ---REGEXPECT-- -01. PUT /v1/contextEntities/type/T1/id/E1, see it fail -====================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 85 - -{ - "errorCode": { - "code": "404", - "details": "E1", - "reasonPhrase": "No context element found" - } -} - - -02. Update/APPEND E1-T1 -======================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 183 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "", - "value": "" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -03. PUT /v1/contextEntities/type/T1/id/E1,A1=3 see it work -========================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 122 - -{ - "contextResponses": [ - { - "attributes": [ - { - "name": "A1", - "type": "", - "value": "" - } - ], - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -04. PUT /v1/contextEntities/type/T1/id/E1?attributeFormat=object,A1=4 see it work -================================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 115 - -{ - "contextResponses": [ - { - "attributes": { - "A1": { - "type": "", - "value": "" - } - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -05. PUT /v1/contextEntities/type/T1/id/E1?entity::type=T1,A1=5 see it work -========================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 122 - -{ - "contextResponses": [ - { - "attributes": [ - { - "name": "A1", - "type": "", - "value": "" - } - ], - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -06. PUT /v1/contextEntities/type/T1/id/E1?entity::type=T2, and see it fail -========================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 103 - -{ - "errorCode": { - "code": "400", - "details": "non-matching entity::types in URL", - "reasonPhrase": "Bad Request" - } -} - - -07. PUT /v1/contextEntities/type/T1/id/E1?!exist=entity::type and see it fail -============================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 115 - -{ - "errorCode": { - "code": "400", - "details": "entity::type cannot be empty for this request", - "reasonPhrase": "Bad Request" - } -} - - -08. PUT /v1/contextEntities/type/T1/id/E1?exist=entity::type and see it work -============================================================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 122 - -{ - "contextResponses": [ - { - "attributes": [ - { - "name": "A1", - "type": "", - "value": "" - } - ], - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -09. Register E2-T1 in CB for CP1 -================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 62 - -{ - "duration": "P1M", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -10. PUT /v1/contextEntities/type/T1/id/E2, see it fail (does not exist in CP1) -============================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 85 - -{ - "errorCode": { - "code": "404", - "details": "E2", - "reasonPhrase": "No context element found" - } -} - - -11. Update/APPEND E2-T1 in CP1 -============================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 183 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "", - "value": "" - } - ], - "id": "E2", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -12. PUT /v1/contextEntities/type/T1/id/E2, see it work -====================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 122 - -{ - "contextResponses": [ - { - "attributes": [ - { - "name": "A1", - "type": "", - "value": "" - } - ], - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - ---TEARDOWN-- -brokerStop CB -brokerStop CP1 -dbDrop CB -dbDrop CP1 diff --git a/test/functionalTest/cases/0117_convop_using_standard_ops/putIndividualContextEntity.test.DISABLED b/test/functionalTest/cases/0117_convop_using_standard_ops/putIndividualContextEntity.test.DISABLED deleted file mode 100644 index bf15c8623c..0000000000 --- a/test/functionalTest/cases/0117_convop_using_standard_ops/putIndividualContextEntity.test.DISABLED +++ /dev/null @@ -1,624 +0,0 @@ -# Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U -# -# This file is part of Orion Context Broker. -# -# Orion Context Broker is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Orion Context Broker is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -# General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -# -# For those usages not covered by this license please contact with -# iot_support at tid dot es - -# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh - ---NAME-- -ConvOp putIndividualContextEntity: PUT /v1/contextEntities/{entityId::id} - ---SHELL-INIT-- -dbInit CB -dbInit CP1 -brokerStart CB -brokerStart CP1 - ---SHELL-- - -# -# 01. Update/UPDATE E1/A1=1 and see it fail (PUT /v1/contextEntities/E1) -# 02. Update/APPEND E1/A1=10 (POST /v1/updateContext) -# 03. Update/UPDATE E1/A1=1 and see it work (PUT /v1/contextEntities/E1) -# 04. Query CB for E1/A1 -# 05. Update/APPEND E2/A2=1 in CP1 -# 06. Register E2/A2 in CB with CP1 as providing application -# 07. Update/UPDATE E2/A2=22 in CB, making it being forwarded to CP1 (PUT /v1/contextEntities/E2) -# 08. Query CP1 for E2/A2 -# 09. Query CP1 for E2/A2, with URI param attributesFormat=object -# 10. Update/APPEND E3/A1=1 in CB, with type EEE in standard payload -# 11. Update/APPEND E3/A1=13, in CB, with type EEE sent via URI param entity::type=EEE -# 12. Query CB for E3/A1, E3 of type 'EEE' -# - -echo "01. Update/UPDATE E1/A1=1 and see it fail (PUT /v1/contextEntities/E1)" -echo "======================================================================" -payload='{ - "attributes": [ - { - "name": "A1", - "type": "", - "value": 1 - } - ] -}' -orionCurl --url /v1/contextEntities/E1 --payload "$payload" -X PUT -echo -echo - - -echo "02. Update/APPEND E1/A1=10 (POST /v1/updateContext)" -echo "===================================================" -payload='{ - "contextElements": [ - { - "type": "", - "id": "E1", - "attributes": [ - { - "name": "A1", - "type": "", - "value": 10 - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" -echo -echo - - -echo "03. Update/UPDATE E1/A1=1 and see it work (PUT /v1/contextEntities/E1)" -echo "======================================================================" -payload='{ - "attributes": [ - { - "name": "A1", - "type": "", - "value": 3 - } - ] -}' -orionCurl --url /v1/contextEntities/E1 --payload "$payload" -X PUT -echo -echo - - -echo "04. Query CB for E1/A1" -echo "======================" -payload='{ - "entities": [ - { - "type": "", - "isPattern": "", - "id": "E1" - } - ], - "attributes": [ - "A1" - ] -}' -orionCurl --url /v1/queryContext --payload "$payload" -echo -echo - - -echo "05. Update/APPEND E2/A2=1 in CP1" -echo "================================" -payload='{ - "contextElements": [ - { - "type": "", - "id": "E2", - "attributes": [ - { - "name": "A2", - "type": "A", - "value": 1 - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" --port $CP1_PORT -echo -echo - - -echo "06. Register E2/A2 in CB with CP1 as providing application" -echo "==========================================================" -payload='{ - "contextRegistrations": [ - { - "entities": [ - { - "type": "", - "isPattern": "false", - "id": "E2" - } - ], - "attributes": [ - { - "name": "A2", - "type": "A" - } - ], - "providingApplication": "http://localhost:'${CP1_PORT}'/v1" - } - ], - "duration": "P1M" -}' -orionCurl --url /v1/registry/registerContext --payload "$payload" -echo -echo - - -echo "07. Update/UPDATE E2/A2=22 in CB, making it being forwarded to CP1 (PUT /v1/contextEntities/E2)" -echo "===============================================================================================" -payload='{ - "attributes": [ - { - "name": "A2", - "type": "A", - "value": 22 - } - ] -}' -orionCurl --url /v1/contextEntities/E2 --payload "$payload" -X PUT -echo -echo - - -echo "08. Query CP1 for E2/A2" -echo "=======================" -payload='{ - "entities": [ - { - "id": "E2", - "type": "" - } - ], - "attributes": [ - "A2" - ] -}' -orionCurl --url /v1/queryContext --payload "$payload" -echo -echo - - -echo "09. Query CP1 for E2/A2, with URI param attributesFormat=object" -echo "===============================================================" -payload='{ - "entities": [ - { - "id": "E2", - "type": "" - } - ], - "attributes": [ - "A2" - ] -}' -orionCurl --url /v1/queryContext --payload "$payload" --urlParams 'attributesFormat=object' -echo -echo - - -echo "10. Update/APPEND E3/A1=1 in CB, with type EEE in standard payload" -echo "==================================================================" -payload='{ - "contextElements": [ - { - "type": "EEE", - "id": "E3", - "attributes": [ - { - "name": "A1", - "type": "", - "value": 1 - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" -echo -echo - - -echo "11. Update/APPEND E3/A1=13, in CB, with type E sent via URI param entity::type=EEE" -echo "==================================================================================" -payload='{ - "attributes": [ - { - "name": "A1", - "type": "A", - "value": 13 - } - ] -}' -orionCurl --url /v1/contextEntities/E3 --payload "$payload" -X PUT --urlParams entity::type=EEE -echo -echo - - -echo "12. Query CB for E3/A1, E3 of type 'EEE'" -echo "========================================" -payload='{ - "entities": [ - { - "type": "EEE", - "isPattern": "", - "id": "E3" - } - ], - "attributes": [ - "A1" - ] -}' -orionCurl --url /v1/queryContext --payload "$payload" -echo -echo - - -----REGEXPECT-- -01. Update/UPDATE E1/A1=1 and see it fail (PUT /v1/contextEntities/E1) -====================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 85 - -{ - "errorCode": { - "code": "404", - "details": "E1", - "reasonPhrase": "No context element found" - } -} - - -02. Update/APPEND E1/A1=10 (POST /v1/updateContext) -=================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 181 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "", - "value": "" - } - ], - "id": "E1", - "isPattern": "false", - "type": "" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -03. Update/UPDATE E1/A1=1 and see it work (PUT /v1/contextEntities/E1) -====================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 122 - -{ - "contextResponses": [ - { - "attributes": [ - { - "name": "A1", - "type": "", - "value": "" - } - ], - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -04. Query CB for E1/A1 -====================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 182 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "", - "value": "3" - } - ], - "id": "E1", - "isPattern": "false", - "type": "" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -05. Update/APPEND E2/A2=1 in CP1 -================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 182 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A2", - "type": "A", - "value": "" - } - ], - "id": "E2", - "isPattern": "false", - "type": "" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -06. Register E2/A2 in CB with CP1 as providing application -========================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 62 - -{ - "duration": "P1M", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -07. Update/UPDATE E2/A2=22 in CB, making it being forwarded to CP1 (PUT /v1/contextEntities/E2) -=============================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 123 - -{ - "contextResponses": [ - { - "attributes": [ - { - "name": "A2", - "type": "A", - "value": "" - } - ], - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -08. Query CP1 for E2/A2 -======================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 184 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A2", - "type": "A", - "value": "22" - } - ], - "id": "E2", - "isPattern": "false", - "type": "" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -09. Query CP1 for E2/A2, with URI param attributesFormat=object -=============================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 177 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": { - "A2": { - "type": "A", - "value": "22" - } - }, - "id": "E2", - "isPattern": "false", - "type": "" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -10. Update/APPEND E3/A1=1 in CB, with type EEE in standard payload -================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 184 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "", - "value": "" - } - ], - "id": "E3", - "isPattern": "false", - "type": "EEE" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -11. Update/APPEND E3/A1=13, in CB, with type E sent via URI param entity::type=EEE -================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 123 - -{ - "contextResponses": [ - { - "attributes": [ - { - "name": "A1", - "type": "A", - "value": "" - } - ], - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -12. Query CB for E3/A1, E3 of type 'EEE' -======================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 187 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "A", - "value": "13" - } - ], - "id": "E3", - "isPattern": "false", - "type": "EEE" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - ---TEARDOWN-- -brokerStop CB -brokerStop CP1 -dbDrop CB -dbDrop CP1 diff --git a/test/functionalTest/cases/0117_convop_using_standard_ops/putIndividualContextEntityAttribute.test.DISABLED b/test/functionalTest/cases/0117_convop_using_standard_ops/putIndividualContextEntityAttribute.test.DISABLED deleted file mode 100644 index 8fc7ab7b13..0000000000 --- a/test/functionalTest/cases/0117_convop_using_standard_ops/putIndividualContextEntityAttribute.test.DISABLED +++ /dev/null @@ -1,415 +0,0 @@ -# Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U -# -# This file is part of Orion Context Broker. -# -# Orion Context Broker is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Orion Context Broker is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -# General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -# -# For those usages not covered by this license please contact with -# iot_support at tid dot es - -# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh - ---NAME-- -ConvOp putIndividualContextEntityAttribute: PUT /v1/contextEntities/{entityId::id}/attributes/{attribute::name} - ---SHELL-INIT-- -dbInit CB -dbInit CP1 -brokerStart CB -brokerStart CP1 - ---SHELL-- - -# -# 01. Update/UPDATE E1/T1/A1=1 and see it fail (PUT /v1/contextEntities/E1/attributes/A1?entity::type=T1) -# 02. Update/APPEND E1/T1/A1=10 (POST /v1/updateContext) -# 03. Update/UPDATE E1/T1/A1=1 and see it work (PUT /v1/contextEntities/E1/attributes/A1?entity::type=T1) -# 04. Query CB for E1/T1/A1: A1 == 1 -# 05. Update/APPEND E2/T2/A2=1 in CP1 -# 06. Register E2/T2/A2 in CB with CP1 as providing application -# 07. Update/UPDATE E2/T2/A2=22 in CB, making it being forwarded to CP1 (PUT /v1/contextEntities/E2/attributes/A2?entity::type=T2) -# 08. Query CP1 for E2/T2/A2 -# -# - -echo "01. Update/UPDATE E1/T1/A1=1 and see it fail (PUT /v1/contextEntities/E1/attributes/A1?entity::type=T1)" -echo "=======================================================================================================" -payload='{ - "type": "AT1", - "value": "1", - "metadatas": [ - { - "name": "m1", - "type": "M1", - "value": "mmmmm 1111" - } - ] -}' -orionCurl --url /v1/contextEntities/E1/attributes/A1?entity::type=T1 --payload "$payload" -X PUT -echo -echo - - -echo "02. Update/APPEND E1/T1/A1=10 (POST /v1/updateContext)" -echo "======================================================" -payload='{ - "contextElements": [ - { - "type": "T1", - "id": "E1", - "attributes": [ - { - "name": "A1", - "type": "", - "value": 10 - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" -echo -echo - - -echo "03. Update/UPDATE E1/T1/A1=1 and see it work (PUT /v1/contextEntities/E1/attributes/A1?entity::type=T1)" -echo "=======================================================================================================" -payload='{ - "type": "AT1", - "value": "1", - "metadatas": [ - { - "name": "m1", - "type": "M1", - "value": "mmmmm 1111" - } - ] -}' -orionCurl --url /v1/contextEntities/E1/attributes/A1?entity::type=T1 --payload "$payload" -X PUT -echo -echo - - -echo "04. Query CB for E1/T1/A1: A1 == 1" -echo "==================================" -payload='{ - "entities": [ - { - "type": "T1", - "isPattern": "", - "id": "E1" - } - ], - "attributes": [ - "A1" - ] -}' -orionCurl --url /v1/queryContext --payload "$payload" -echo -echo - - -echo "05. Update/APPEND E2/T2/A2=1 in CP1" -echo "===================================" -payload='{ - "contextElements": [ - { - "type": "T2", - "id": "E2", - "attributes": [ - { - "name": "A2", - "type": "A", - "value": 1 - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" --port $CP1_PORT -echo -echo - - -echo "06. Register E2/T2/A2 in CB with CP1 as providing application" -echo "=============================================================" -payload='{ - "contextRegistrations": [ - { - "entities": [ - { - "type": "T2", - "isPattern": "false", - "id": "E2" - } - ], - "attributes": [ - { - "name": "A2", - "type": "AT2" - } - ], - "providingApplication": "http://localhost:'${CP1_PORT}'/v1" - } - ], - "duration": "P1M" -}' -orionCurl --url /v1/registry/registerContext --payload "$payload" -echo -echo - - -echo "07. Update/UPDATE E2/T2/A2=22 in CB, making it being forwarded to CP1 (PUT /v1/contextEntities/E2/attributes/A2?entity::type=T2)" -echo "================================================================================================================================" -payload='{ - "type": "AT2", - "value": "22", - "metadatas": [ - { - "name": "m2", - "type": "M2", - "value": "mmmmm 2222" - } - ] -}' -orionCurl --url /v1/contextEntities/E2/attributes/A2?entity::type=T2 --payload "$payload" -X PUT -echo -echo - - -echo "08. Query CP1 for E2/T2/A2" -echo "==========================" -payload='{ - "entities": [ - { - "id": "E2", - "type": "T2" - } - ], - "attributes": [ - "A2" - ] -}' -orionCurl --url /v1/queryContext --payload "$payload" --port $CP1_PORT -echo -echo - - ---REGEXPECT-- -01. Update/UPDATE E1/T1/A1=1 and see it fail (PUT /v1/contextEntities/E1/attributes/A1?entity::type=T1) -======================================================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 71 - -{ - "code": "404", - "details": "E1", - "reasonPhrase": "No context element found" -} - - -02. Update/APPEND E1/T1/A1=10 (POST /v1/updateContext) -====================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 183 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "", - "value": "" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -03. Update/UPDATE E1/T1/A1=1 and see it work (PUT /v1/contextEntities/E1/attributes/A1?entity::type=T1) -======================================================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 34 - -{ - "code": "200", - "reasonPhrase": "OK" -} - - -04. Query CB for E1/T1/A1: A1 == 1 -================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 248 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "metadatas": [ - { - "name": "m1", - "type": "M1", - "value": "mmmmm 1111" - } - ], - "name": "A1", - "type": "AT1", - "value": "1" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -05. Update/APPEND E2/T2/A2=1 in CP1 -=================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 184 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A2", - "type": "A", - "value": "" - } - ], - "id": "E2", - "isPattern": "false", - "type": "T2" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -06. Register E2/T2/A2 in CB with CP1 as providing application -============================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 62 - -{ - "duration": "P1M", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -07. Update/UPDATE E2/T2/A2=22 in CB, making it being forwarded to CP1 (PUT /v1/contextEntities/E2/attributes/A2?entity::type=T2) -================================================================================================================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 34 - -{ - "code": "200", - "reasonPhrase": "OK" -} - - -08. Query CP1 for E2/T2/A2 -========================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 249 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "metadatas": [ - { - "name": "m2", - "type": "M2", - "value": "mmmmm 2222" - } - ], - "name": "A2", - "type": "AT2", - "value": "22" - } - ], - "id": "E2", - "isPattern": "false", - "type": "T2" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - ---TEARDOWN-- -brokerStop CB -brokerStop CP1 -dbDrop CB -dbDrop CP1 diff --git a/test/functionalTest/cases/0117_convop_using_standard_ops/putIndividualContextEntityAttributeWithTypeAndId.test.DISABLED b/test/functionalTest/cases/0117_convop_using_standard_ops/putIndividualContextEntityAttributeWithTypeAndId.test.DISABLED deleted file mode 100644 index 65d7ebf788..0000000000 --- a/test/functionalTest/cases/0117_convop_using_standard_ops/putIndividualContextEntityAttributeWithTypeAndId.test.DISABLED +++ /dev/null @@ -1,428 +0,0 @@ -# Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U -# -# This file is part of Orion Context Broker. -# -# Orion Context Broker is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Orion Context Broker is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -# General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -# -# For those usages not covered by this license please contact with -# iot_support at tid dot es - -# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh - ---NAME-- -ConvOp putIndividualContextEntityAttributeWithTypeAndId: PUT /v1/contextEntities/type/{entity::type}/id/{entity::id}/attributes/{attribute::name} - ---SHELL-INIT-- -dbInit CB -dbInit CP1 -brokerStart CB 0 -brokerStart CP1 0 - ---SHELL-- - -# -# 01. PUT /v1/contextEntities/type/T1/id/E1/attributes/A1, and see it fail -# 02. Update/APPEND E1-T1-A1=2 -# 03. PUT /v1/contextEntities/type/T1/id/E1/attributes/A1,A1=3 and see it work -# 04. PUT /v1/contextEntities/type/T1/id/E1/attributes/A1?!exist=entity::type, and see it fail -# 05. PUT /v1/contextEntities/type/T1/id/E1/attributes/A1?exist=entity::type, and see it work -# 06. PUT /v1/contextEntities/type/T1/id/E1/attributes/A1?entity::type=T2, and see it fail -# 07. PUT /v1/contextEntities/type/T1/id/E1/attributes/A1?entity::type=T1, and see it work -# 08. Register E2-T1-A1 in CB for CP1 -# 09. PUT /v1/contextEntities/type/T1/id/E2/attributes/A1, see it fail (does not exist in CP1) -# 10. Update/APPEND E2-T1-A1 in CP1 -# 11. PUT /v1/contextEntities/type/T1/id/E2/attributes/A1, see it work -# 12. Query E2-T1-A1 to make sure the update took place -# - -echo "01. PUT /v1/contextEntities/type/T1/id/E1/attributes/A1, and see it fail" -echo "========================================================================" -payload='{ - "value": 1 -}' -orionCurl --url /v1/contextEntities/type/T1/id/E1/attributes/A1 --payload "$payload" -X PUT -echo -echo - - -echo "02. Update/APPEND E1-T1-A1=2" -echo "============================" -payload='{ - "contextElements": [ - { - "type" : "T1", - "id" : "E1", - "attributes" : [ - { - "name" : "A1", - "value" : 2 - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" -echo -echo - - -echo "03. PUT /v1/contextEntities/type/T1/id/E1/attributes/A1,A1=3 and see it work" -echo "============================================================================" -payload='{ - "value": 3 -}' -orionCurl --url /v1/contextEntities/type/T1/id/E1/attributes/A1 --payload "$payload" -X PUT -echo -echo - - -echo "04. PUT /v1/contextEntities/type/T1/id/E1/attributes/A1?!exist=entity::type, and see it fail" -echo "============================================================================================" -payload='{ - "value": 4 -}' -orionCurl --url /v1/contextEntities/type/T1/id/E1/attributes/A1?!exist=entity::type --payload "$payload" -X PUT -echo -echo - - -echo "05. PUT /v1/contextEntities/type/T1/id/E1/attributes/A1?exist=entity::type, and see it work" -echo "===========================================================================================" -payload='{ - "value": 5 -}' -orionCurl --url /v1/contextEntities/type/T1/id/E1/attributes/A1?exist=entity::type --payload "$payload" -X PUT -echo -echo - - -echo "06. PUT /v1/contextEntities/type/T1/id/E1/attributes/A1?entity::type=T2, and see it fail" -echo "========================================================================================" -payload='{ - "value": 6 -}' -orionCurl --url /v1/contextEntities/type/T1/id/E1/attributes/A1?entity::type=T2 --payload "$payload" -X PUT -echo -echo - - -echo "07. PUT /v1/contextEntities/type/T1/id/E1/attributes/A1?entity::type=T1, and see it work" -echo "========================================================================================" -payload='{ - "value": 7 -}' -orionCurl --url /v1/contextEntities/type/T1/id/E1/attributes/A1?entity::type=T1 --payload "$payload" -X PUT -echo -echo - - -echo "08. Register E2-T1-A1 in CB for CP1" -echo "===================================" -payload='{ - "contextRegistrations": [ - { - "entities": [ - { - "type": "T1", - "id": "E2" - } - ], - "attributes": [ - { - "name": "A1" - } - ], - "providingApplication": "http://localhost:'${CP1_PORT}'/v1" - } - ], - "duration": "P1M" -}' -orionCurl --url /v1/registry/registerContext --payload "$payload" -echo -echo - - -echo "09. PUT /v1/contextEntities/type/T1/id/E2/attributes/A1, see it fail (does not exist in CP1)" -echo "============================================================================================" -payload='{ - "value": 9 -}' -orionCurl --url /v1/contextEntities/type/T1/id/E2/attributes/A1 --payload "$payload" -X PUT -echo -echo - - -echo "10. Update/APPEND E2-T1-A1 in CP1" -echo "=================================" -payload='{ - "contextElements": [ - { - "type": "T1", - "id": "E2", - "attributes": [ - { - "name": "A1", - "value": 10 - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" --port $CP1_PORT -echo -echo - - -echo "11. PUT /v1/contextEntities/type/T1/id/E2/attributes/A1, see it work" -echo "====================================================================" -payload='{ - "value": 11 -}' -orionCurl --url /v1/contextEntities/type/T1/id/E2/attributes/A1 --payload "$payload" -X PUT -echo -echo - - -echo "12. Query E2-T1-A1 to make sure the update took place" -echo "=====================================================" -orionCurl --url /v1/contextEntities/type/T1/id/E2/attributes/A1 -echo -echo - - ---REGEXPECT-- -01. PUT /v1/contextEntities/type/T1/id/E1/attributes/A1, and see it fail -======================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 71 - -{ - "code": "404", - "details": "E1", - "reasonPhrase": "No context element found" -} - - -02. Update/APPEND E1-T1-A1=2 -============================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 183 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "", - "value": "" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -03. PUT /v1/contextEntities/type/T1/id/E1/attributes/A1,A1=3 and see it work -============================================================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 34 - -{ - "code": "200", - "reasonPhrase": "OK" -} - - -04. PUT /v1/contextEntities/type/T1/id/E1/attributes/A1?!exist=entity::type, and see it fail -============================================================================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 101 - -{ - "code": "400", - "details": "entity::type cannot be empty for this request", - "reasonPhrase": "Bad Request" -} - - -05. PUT /v1/contextEntities/type/T1/id/E1/attributes/A1?exist=entity::type, and see it work -=========================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 34 - -{ - "code": "200", - "reasonPhrase": "OK" -} - - -06. PUT /v1/contextEntities/type/T1/id/E1/attributes/A1?entity::type=T2, and see it fail -======================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 89 - -{ - "code": "400", - "details": "non-matching entity::types in URL", - "reasonPhrase": "Bad Request" -} - - -07. PUT /v1/contextEntities/type/T1/id/E1/attributes/A1?entity::type=T1, and see it work -======================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 34 - -{ - "code": "200", - "reasonPhrase": "OK" -} - - -08. Register E2-T1-A1 in CB for CP1 -=================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 62 - -{ - "duration": "P1M", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -09. PUT /v1/contextEntities/type/T1/id/E2/attributes/A1, see it fail (does not exist in CP1) -============================================================================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 71 - -{ - "code": "404", - "details": "E2", - "reasonPhrase": "No context element found" -} - - -10. Update/APPEND E2-T1-A1 in CP1 -================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 183 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "", - "value": "" - } - ], - "id": "E2", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -11. PUT /v1/contextEntities/type/T1/id/E2/attributes/A1, see it work -==================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 34 - -{ - "code": "200", - "reasonPhrase": "OK" -} - - -12. Query E2-T1-A1 to make sure the update took place -===================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 101 - -{ - "attributes": [ - { - "name": "A1", - "type": "", - "value": "11" - } - ], - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } -} - - ---TEARDOWN-- -brokerStop CB -brokerStop CP1 -dbDrop CB -dbDrop CP1 diff --git a/test/functionalTest/cases/0117_convop_using_standard_ops/putIndividualContextEntityAttributes.test.DISABLED b/test/functionalTest/cases/0117_convop_using_standard_ops/putIndividualContextEntityAttributes.test.DISABLED deleted file mode 100644 index 71685b9c7f..0000000000 --- a/test/functionalTest/cases/0117_convop_using_standard_ops/putIndividualContextEntityAttributes.test.DISABLED +++ /dev/null @@ -1,624 +0,0 @@ -# Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U -# -# This file is part of Orion Context Broker. -# -# Orion Context Broker is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Orion Context Broker is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -# General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -# -# For those usages not covered by this license please contact with -# iot_support at tid dot es - -# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh - ---NAME-- -ConvOp putIndividualContextEntityAttributes: PUT /v1/contextEntities/{entityId::id}/attributes - ---SHELL-INIT-- -dbInit CB -dbInit CP1 -brokerStart CB -brokerStart CP1 - ---SHELL-- - -# -# 01. Update/UPDATE E1/A1=1 and see it fail (PUT /v1/contextEntities/E1/attributes) -# 02. Update/APPEND E1/A1=10 (POST /v1/updateContext) -# 03. Update/UPDATE E1/A1=1 and see it work (PUT /v1/contextEntities/E1/attributes) -# 04. Query CB for E1/A1 -# 05. Update/APPEND E2/A2=1 in CP1 -# 06. Register E2/A2 in CB with CP1 as providing application -# 07. Update/UPDATE E2/A2=22 in CB, making it being forwarded to CP1 (PUT /v1/contextEntities/E2/attributes) -# 08. Query CP1 for E2/A2 -# 09. Query CP1 for E2/A2, with URI param attributesFormat=object -# 10. Update/APPEND E3/A1=1 in CB, with type EEE in standard payload -# 11. Update/APPEND E3/A1=13, in CB, with type EEE sent via URI param entity::type=EEE -# 12. Query CB for E3/A1, E3 of type 'EEE' -# - -echo "01. Update/UPDATE E1/A1=1 and see it fail (PUT /v1/contextEntities/E1/attributes)" -echo "=================================================================================" -payload='{ - "attributes": [ - { - "name": "A1", - "type": "", - "value": 1 - } - ] -}' -orionCurl --url /v1/contextEntities/E1/attributes --payload "$payload" -X PUT -echo -echo - - -echo "02. Update/APPEND E1/A1=10 (POST /v1/updateContext)" -echo "===================================================" -payload='{ - "contextElements": [ - { - "type": "", - "id": "E1", - "attributes": [ - { - "name": "A1", - "type": "", - "value": 10 - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" -echo -echo - - -echo "03. Update/UPDATE E1/A1=1 and see it work (PUT /v1/contextEntities/E1/attributes)" -echo "=================================================================================" -payload='{ - "attributes": [ - { - "name": "A1", - "type": "", - "value": 3 - } - ] -}' -orionCurl --url /v1/contextEntities/E1/attributes --payload "$payload" -X PUT -echo -echo - - -echo "04. Query CB for E1/A1" -echo "======================" -payload='{ - "entities": [ - { - "type": "", - "isPattern": "", - "id": "E1" - } - ], - "attributes": [ - "A1" - ] -}' -orionCurl --url /v1/queryContext --payload "$payload" -echo -echo - - -echo "05. Update/APPEND E2/A2=1 in CP1" -echo "================================" -payload='{ - "contextElements": [ - { - "type": "", - "id": "E2", - "attributes": [ - { - "name": "A2", - "type": "A", - "value": 1 - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" --port $CP1_PORT -echo -echo - - -echo "06. Register E2/A2 in CB with CP1 as providing application" -echo "==========================================================" -payload='{ - "contextRegistrations": [ - { - "entities": [ - { - "type": "", - "isPattern": "false", - "id": "E2" - } - ], - "attributes": [ - { - "name": "A2", - "type": "A" - } - ], - "providingApplication": "http://localhost:'${CP1_PORT}'/v1" - } - ], - "duration": "P1M" -}' -orionCurl --url /v1/registry/registerContext --payload "$payload" -echo -echo - - -echo "07. Update/UPDATE E2/A2=22 in CB, making it being forwarded to CP1 (PUT /v1/contextEntities/E2/attributes)" -echo "==========================================================================================================" -payload='{ - "attributes": [ - { - "name": "A2", - "type": "A", - "value": 22 - } - ] -}' -orionCurl --url /v1/contextEntities/E2/attributes --payload "$payload" -X PUT -echo -echo - - -echo "08. Query CP1 for E2/A2" -echo "=======================" -payload='{ - "entities": [ - { - "id": "E2", - "type": "" - } - ], - "attributes": [ - "A2" - ] -}' -orionCurl --url /v1/queryContext --payload "$payload" -echo -echo - - -echo "09. Query CP1 for E2/A2, with URI param attributesFormat=object" -echo "===============================================================" -payload='{ - "entities": [ - { - "id": "E2", - "type": "" - } - ], - "attributes": [ - "A2" - ] -}' -orionCurl --url /v1/queryContext --payload "$payload" --urlParams 'attributesFormat=object' -echo -echo - - -echo "10. Update/APPEND E3/A1=1 in CB, with type EEE in standard payload" -echo "==================================================================" -payload='{ - "contextElements": [ - { - "type": "EEE", - "id": "E3", - "attributes": [ - { - "name": "A1", - "type": "", - "value": 1 - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" -echo -echo - - -echo "11. Update/APPEND E3/A1=13, in CB, with type E sent via URI param entity::type=EEE" -echo "==================================================================================" -payload='{ - "attributes": [ - { - "name": "A1", - "type": "A", - "value": 13 - } - ] -}' -orionCurl --url /v1/contextEntities/E3/attributes --payload "$payload" -X PUT --urlParams entity::type=EEE -echo -echo - - -echo "12. Query CB for E3/A1, E3 of type 'EEE'" -echo "========================================" -payload='{ - "entities": [ - { - "type": "EEE", - "isPattern": "", - "id": "E3" - } - ], - "attributes": [ - "A1" - ] -}' -orionCurl --url /v1/queryContext --payload "$payload" -echo -echo - - -----REGEXPECT-- -01. Update/UPDATE E1/A1=1 and see it fail (PUT /v1/contextEntities/E1/attributes) -================================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 85 - -{ - "errorCode": { - "code": "404", - "details": "E1", - "reasonPhrase": "No context element found" - } -} - - -02. Update/APPEND E1/A1=10 (POST /v1/updateContext) -=================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 181 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "", - "value": "" - } - ], - "id": "E1", - "isPattern": "false", - "type": "" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -03. Update/UPDATE E1/A1=1 and see it work (PUT /v1/contextEntities/E1/attributes) -================================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 122 - -{ - "contextResponses": [ - { - "attributes": [ - { - "name": "A1", - "type": "", - "value": "" - } - ], - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -04. Query CB for E1/A1 -====================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 182 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "", - "value": "3" - } - ], - "id": "E1", - "isPattern": "false", - "type": "" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -05. Update/APPEND E2/A2=1 in CP1 -================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 182 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A2", - "type": "A", - "value": "" - } - ], - "id": "E2", - "isPattern": "false", - "type": "" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -06. Register E2/A2 in CB with CP1 as providing application -========================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 62 - -{ - "duration": "P1M", - "registrationId": "REGEX([0-9a-f]{24})" -} - - -07. Update/UPDATE E2/A2=22 in CB, making it being forwarded to CP1 (PUT /v1/contextEntities/E2/attributes) -========================================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 123 - -{ - "contextResponses": [ - { - "attributes": [ - { - "name": "A2", - "type": "A", - "value": "" - } - ], - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -08. Query CP1 for E2/A2 -======================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 184 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A2", - "type": "A", - "value": "22" - } - ], - "id": "E2", - "isPattern": "false", - "type": "" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -09. Query CP1 for E2/A2, with URI param attributesFormat=object -=============================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 177 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": { - "A2": { - "type": "A", - "value": "22" - } - }, - "id": "E2", - "isPattern": "false", - "type": "" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -10. Update/APPEND E3/A1=1 in CB, with type EEE in standard payload -================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 184 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "", - "value": "" - } - ], - "id": "E3", - "isPattern": "false", - "type": "EEE" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -11. Update/APPEND E3/A1=13, in CB, with type E sent via URI param entity::type=EEE -================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 123 - -{ - "contextResponses": [ - { - "attributes": [ - { - "name": "A1", - "type": "A", - "value": "" - } - ], - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -12. Query CB for E3/A1, E3 of type 'EEE' -======================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 187 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "A", - "value": "13" - } - ], - "id": "E3", - "isPattern": "false", - "type": "EEE" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - ---TEARDOWN-- -brokerStop CB -brokerStop CP1 -dbDrop CB -dbDrop CP1 diff --git a/test/functionalTest/cases/0117_convop_using_standard_ops/putSubscriptionConvOp.test.DISABLED b/test/functionalTest/cases/0117_convop_using_standard_ops/putSubscriptionConvOp.test.DISABLED deleted file mode 100644 index a532a38027..0000000000 --- a/test/functionalTest/cases/0117_convop_using_standard_ops/putSubscriptionConvOp.test.DISABLED +++ /dev/null @@ -1,673 +0,0 @@ -# Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U -# -# This file is part of Orion Context Broker. -# -# Orion Context Broker is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Orion Context Broker is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -# General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -# -# For those usages not covered by this license please contact with -# iot_support at tid dot es - -# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh - ---NAME-- -ConvOp putSubscriptionConvOp: PUT /v1/contextSubscriptions/{subscriptionId} - ---SHELL-INIT-- -dbInit CB -brokerStart CB 0 -accumulatorStart --pretty-print - ---SHELL-- - -# -# 01. PUT /v1/contextSubscriptions/1234567890 and see it fail -# 02. PUT /v1/contextSubscriptions/123456789012345678901234 with 000000000000000000000000 in payload and see it fail -# 03. PUT /v1/contextSubscriptions/123456789012345678901234 and see it fail -# 04. Subscribe to E1/T1/A1+A2 -# 05. Create E1/T1/A1+A2 -# 06. Dump accumulator, see E1/T1/A1+A2 -# 07. PUT /v1/contextSubscriptions/SUB_ID, removing A2 from notifyConditions -# 08. Dump accumulator, see same notification -# 09. Update E1/T1/A2 -# 10. Dump accumulator, still the same notifications -# 11. Update E1/T1/A1 -# 12. Dump accumulator, see two notifications -# - -echo "01. PUT /v1/contextSubscriptions/1234567890 and see it fail" -echo "===========================================================" -payload='{ - "duration": "P1Y", - "subscriptionId": "1234567890", - "throttling": "PT1S", - "notifyConditions": [ - { - "type": "ONCHANGE", - "condValues": [ - "A1" - ] - } - ] -}' -orionCurl --url /v1/contextSubscriptions/1234567890 --payload "$payload" -X PUT -echo -echo - - -echo "02. PUT /v1/contextSubscriptions/123456789012345678901234 with 000000000000000000000000 in payload and see it fail" -echo "==================================================================================================================" -payload='{ - "duration": "P1Y", - "subscriptionId": "000000000000000000000000", - "throttling": "PT1S", - "notifyConditions": [ - { - "type": "ONCHANGE", - "condValues": [ - "A1" - ] - } - ] -}' -orionCurl --url /v1/contextSubscriptions/123456789012345678901234 --payload "$payload" -X PUT -echo -echo - - -echo "03. PUT /v1/contextSubscriptions/123456789012345678901234 and see it fail" -echo "=========================================================================" -payload='{ - "duration": "P1Y", - "subscriptionId": "123456789012345678901234", - "throttling": "PT1S", - "notifyConditions": [ - { - "type": "ONCHANGE", - "condValues": [ - "A1" - ] - } - ] -}' -orionCurl --url /v1/contextSubscriptions/123456789012345678901234 --payload "$payload" -X PUT -echo -echo - - -echo "04. Subscribe to E1/T1/A1+A2" -echo "============================" -payload='{ - "entities": [ - { - "id": "E1", - "type": "T1" - } - ], - "attributes": [ - "A1", - "A2" - ], - "reference": "http://localhost:'${LISTENER_PORT}'/notify", - "duration": "P1M", - "throttling": "PT1S", - "notifyConditions": [ - { - "type": "ONCHANGE", - "condValues": [ - "A1", "A2" - ] - } - ] -}' -orionCurl --url /v1/subscribeContext --payload "$payload" -SUB_ID=$(echo "$_response" | grep subscriptionId | awk -F\" '{ print $4}') -echo -echo - - -echo "05. Create E1/T1/A1+A2" -echo "======================" -payload='{ - "contextElements": [ - { - "type": "T1", - "id": "E1", - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "1" - }, - { - "name": "A2", - "type": "string", - "value": "2" - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" -echo -echo - - -echo "06. Dump accumulator, see E1/T1/A1+A2" -echo "=====================================" -accumulatorDump -echo -echo - - -echo "07. PUT /v1/contextSubscriptions/SUB_ID, removing A2 from notifyConditions" -echo "==========================================================================" -payload='{ - "duration": "P1Y", - "subscriptionId": "'$SUB_ID'", - "throttling": "PT1S", - "notifyConditions": [ - { - "type": "ONCHANGE", - "condValues": [ - "A1" - ] - } - ] -}' -orionCurl --url /v1/contextSubscriptions/$SUB_ID --payload "$payload" -X PUT -echo -echo - - -echo "08. Dump accumulator, see same notification" -echo "===========================================" -accumulatorDump -echo -echo - - -echo "09. Update E1/T1/A2" -echo "===================" -payload='{ - "contextElements": [ - { - "type": "T1", - "id": "E1", - "attributes": [ - { - "name": "A2", - "type": "string", - "value": "09" - } - ] - } - ], - "updateAction": "UPDATE" -}' -orionCurl --url /v1/updateContext --payload "$payload" -echo -echo - - -echo "10. Dump accumulator, still the same notification" -echo "=================================================" -accumulatorDump -echo -echo - - -# Avoid throttling (1 second) for the subscription -sleep 2 - -echo "11. Update E1/T1/A1" -echo "===================" -payload='{ - "contextElements": [ - { - "type": "T1", - "id": "E1", - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "11" - } - ] - } - ], - "updateAction": "UPDATE" -}' -orionCurl --url /v1/updateContext --payload "$payload" -echo -echo - - -echo "12. Dump accumulator, see two notifications" -echo "===========================================" -accumulatorDump -echo -echo - - ---REGEXPECT-- -01. PUT /v1/contextSubscriptions/1234567890 and see it fail -=========================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 149 - -{ - "subscribeError": { - "errorCode": { - "code": "400", - "details": "bad length - 24 chars expected", - "reasonPhrase": "Bad Request" - }, - "subscriptionId": "1234567890" - } -} - - -02. PUT /v1/contextSubscriptions/123456789012345678901234 with 000000000000000000000000 in payload and see it fail -================================================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 228 - -{ - "subscribeError": { - "errorCode": { - "code": "400", - "details": "unmatching subscriptionId URI/payload: /123456789012345678901234/ vs /000000000000000000000000/", - "reasonPhrase": "Bad Request" - }, - "subscriptionId": "000000000000000000000000" - } -} - - -03. PUT /v1/contextSubscriptions/123456789012345678901234 and see it fail -========================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 133 - -{ - "subscribeError": { - "errorCode": { - "code": "404", - "reasonPhrase": "No context element found" - }, - "subscriptionId": "123456789012345678901234" - } -} - - -04. Subscribe to E1/T1/A1+A2 -============================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 104 - -{ - "subscribeResponse": { - "duration": "P1M", - "subscriptionId": "REGEX([0-9a-f]{24})", - "throttling": "PT1S" - } -} - - -05. Create E1/T1/A1+A2 -====================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 230 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "" - }, - { - "name": "A2", - "type": "string", - "value": "" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -06. Dump accumulator, see E1/T1/A1+A2 -===================================== -POST http://localhost:REGEX(\d+)/notify -Fiware-Servicepath: / -Content-Length: 301 -User-Agent: orion/REGEX(\d+\.\d+\.\d+.*) -Host: localhost:REGEX(\d+) -Accept: application/json -Content-Type: application/json; charset=utf-8 -Fiware-Correlator: REGEX([0-9a-f\-]{36}); cbnotif=1 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "1" - }, - { - "name": "A2", - "type": "string", - "value": "2" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ], - "originator": "localhost", - "subscriptionId": "REGEX([0-9a-f]{24})" -} -======================================= - - -07. PUT /v1/contextSubscriptions/SUB_ID, removing A2 from notifyConditions -========================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 104 - -{ - "subscribeResponse": { - "duration": "P1Y", - "subscriptionId": "REGEX([0-9a-f]{24})", - "throttling": "PT1S" - } -} - - -08. Dump accumulator, see same notification -=========================================== -POST http://localhost:REGEX(\d+)/notify -Fiware-Servicepath: / -Content-Length: 301 -User-Agent: orion/REGEX(\d+\.\d+\.\d+.*) -Host: localhost:REGEX(\d+) -Accept: application/json -Content-Type: application/json; charset=utf-8 -Fiware-Correlator: REGEX([0-9a-f\-]{36}); cbnotif=1 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "1" - }, - { - "name": "A2", - "type": "string", - "value": "2" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ], - "originator": "localhost", - "subscriptionId": "REGEX([0-9a-f]{24})" -} -======================================= - - -09. Update E1/T1/A2 -=================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 189 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A2", - "type": "string", - "value": "" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -10. Dump accumulator, still the same notification -================================================= -POST http://localhost:REGEX(\d+)/notify -Fiware-Servicepath: / -Content-Length: 301 -User-Agent: orion/REGEX(\d+\.\d+\.\d+.*) -Host: localhost:REGEX(\d+) -Accept: application/json -Content-Type: application/json; charset=utf-8 -Fiware-Correlator: REGEX([0-9a-f\-]{36}); cbnotif=1 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "1" - }, - { - "name": "A2", - "type": "string", - "value": "2" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ], - "originator": "localhost", - "subscriptionId": "REGEX([0-9a-f]{24})" -} -======================================= - - -11. Update E1/T1/A1 -=================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 189 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -12. Dump accumulator, see two notifications -=========================================== -POST http://localhost:REGEX(\d+)/notify -Fiware-Servicepath: / -Content-Length: 301 -User-Agent: orion/REGEX(\d+\.\d+\.\d+.*) -Host: localhost:REGEX(\d+) -Accept: application/json -Content-Type: application/json; charset=utf-8 -Fiware-Correlator: REGEX([0-9a-f\-]{36}); cbnotif=1 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "1" - }, - { - "name": "A2", - "type": "string", - "value": "2" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ], - "originator": "localhost", - "subscriptionId": "REGEX([0-9a-f]{24})" -} -======================================= -POST http://localhost:REGEX(\d+)/notify -Fiware-Servicepath: / -Content-Length: 303 -User-Agent: orion/REGEX(\d+\.\d+\.\d+.*) -Host: localhost:REGEX(\d+) -Accept: application/json -Content-Type: application/json; charset=utf-8 -Fiware-Correlator: REGEX([0-9a-f\-]{36}); cbnotif=1 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "A1", - "type": "string", - "value": "11" - }, - { - "name": "A2", - "type": "string", - "value": "09" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T1" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ], - "originator": "localhost", - "subscriptionId": "REGEX([0-9a-f]{24})" -} -======================================= - - ---TEARDOWN-- -brokerStop CB -accumulatorStop -dbDrop CB diff --git a/test/functionalTest/cases/0672_forbidden_chars_in_url/all_forbidden_chars_in_uri.test b/test/functionalTest/cases/0672_forbidden_chars_in_url/all_forbidden_chars_in_uri.test index 62a577b80b..00d0a7d49c 100644 --- a/test/functionalTest/cases/0672_forbidden_chars_in_url/all_forbidden_chars_in_uri.test +++ b/test/functionalTest/cases/0672_forbidden_chars_in_url/all_forbidden_chars_in_uri.test @@ -112,14 +112,11 @@ HTTP/1.1 400 Bad Request Date: REGEX(.*) Fiware-Correlator: REGEX([0-9a-f\-]{36}) Content-Type: application/json -Content-Length: 95 +Content-Length: 63 { - "orionError": { - "code": "400", - "details": "invalid character in URI", - "reasonPhrase": "Bad Request" - } + "description": "invalid character in URI", + "error": "BadRequest" } @@ -129,14 +126,11 @@ HTTP/1.1 400 Bad Request Date: REGEX(.*) Fiware-Correlator: REGEX([0-9a-f\-]{36}) Content-Type: application/json -Content-Length: 95 +Content-Length: 63 { - "orionError": { - "code": "400", - "details": "invalid character in URI", - "reasonPhrase": "Bad Request" - } + "description": "invalid character in URI", + "error": "BadRequest" } @@ -146,14 +140,11 @@ HTTP/1.1 400 Bad Request Date: REGEX(.*) Fiware-Correlator: REGEX([0-9a-f\-]{36}) Content-Type: application/json -Content-Length: 95 +Content-Length: 63 { - "orionError": { - "code": "400", - "details": "invalid character in URI", - "reasonPhrase": "Bad Request" - } + "description": "invalid character in URI", + "error": "BadRequest" } @@ -163,14 +154,11 @@ HTTP/1.1 400 Bad Request Date: REGEX(.*) Fiware-Correlator: REGEX([0-9a-f\-]{36}) Content-Type: application/json -Content-Length: 95 +Content-Length: 63 { - "orionError": { - "code": "400", - "details": "invalid character in URI", - "reasonPhrase": "Bad Request" - } + "description": "invalid character in URI", + "error": "BadRequest" } @@ -180,14 +168,11 @@ HTTP/1.1 400 Bad Request Date: REGEX(.*) Fiware-Correlator: REGEX([0-9a-f\-]{36}) Content-Type: application/json -Content-Length: 95 +Content-Length: 63 { - "orionError": { - "code": "400", - "details": "invalid character in URI", - "reasonPhrase": "Bad Request" - } + "description": "invalid character in URI", + "error": "BadRequest" } @@ -197,14 +182,11 @@ HTTP/1.1 400 Bad Request Date: REGEX(.*) Fiware-Correlator: REGEX([0-9a-f\-]{36}) Content-Type: application/json -Content-Length: 95 +Content-Length: 63 { - "orionError": { - "code": "400", - "details": "invalid character in URI", - "reasonPhrase": "Bad Request" - } + "description": "invalid character in URI", + "error": "BadRequest" } @@ -214,14 +196,11 @@ HTTP/1.1 400 Bad Request Date: REGEX(.*) Fiware-Correlator: REGEX([0-9a-f\-]{36}) Content-Type: application/json -Content-Length: 95 +Content-Length: 63 { - "orionError": { - "code": "400", - "details": "invalid character in URI", - "reasonPhrase": "Bad Request" - } + "description": "invalid character in URI", + "error": "BadRequest" } @@ -231,14 +210,11 @@ HTTP/1.1 400 Bad Request Date: REGEX(.*) Fiware-Correlator: REGEX([0-9a-f\-]{36}) Content-Type: application/json -Content-Length: 95 +Content-Length: 63 { - "orionError": { - "code": "400", - "details": "invalid character in URI", - "reasonPhrase": "Bad Request" - } + "description": "invalid character in URI", + "error": "BadRequest" } @@ -248,14 +224,11 @@ HTTP/1.1 400 Bad Request Date: REGEX(.*) Fiware-Correlator: REGEX([0-9a-f\-]{36}) Content-Type: application/json -Content-Length: 129 +Content-Length: 97 { - "orionError": { - "code": "400", - "details": "Service not found. Check your URL as probably it is wrong.", - "reasonPhrase": "Bad Request" - } + "description": "Service not found. Check your URL as probably it is wrong.", + "error": "BadRequest" } diff --git a/test/functionalTest/cases/1913_log_level_change_via_rest/log_level_change_via_rest.test b/test/functionalTest/cases/1913_log_level_change_via_rest/log_level_change_via_rest.test index 628df2f8bc..c1738a84dd 100644 --- a/test/functionalTest/cases/1913_log_level_change_via_rest/log_level_change_via_rest.test +++ b/test/functionalTest/cases/1913_log_level_change_via_rest/log_level_change_via_rest.test @@ -146,10 +146,11 @@ HTTP/1.1 400 Bad Request Date: REGEX(.*) Fiware-Correlator: REGEX([0-9a-f\-]{36}) Content-Type: application/json -Content-Length: 55 +Content-Length: 82 { - "error": "Empty right-hand-side for URI param /level/" + "description": "Empty right-hand-side for URI param /level/", + "error": "BadRequest" } diff --git a/test/functionalTest/cases/2420_logLevel_error_message/logLevel_error_message.test b/test/functionalTest/cases/2420_logLevel_error_message/logLevel_error_message.test index 97dd7c958e..ae31ef190d 100644 --- a/test/functionalTest/cases/2420_logLevel_error_message/logLevel_error_message.test +++ b/test/functionalTest/cases/2420_logLevel_error_message/logLevel_error_message.test @@ -46,10 +46,11 @@ HTTP/1.1 400 Bad Request Date: REGEX(.*) Fiware-Correlator: REGEX([0-9a-f\-]{36}) Content-Type: application/json -Content-Length: 55 +Content-Length: 82 { - "error": "Empty right-hand-side for URI param /level/" + "description": "Empty right-hand-side for URI param /level/", + "error": "BadRequest" } diff --git a/test/functionalTest/cases/2527_crash_with_empty_uri_path/crash_with_empty_uri_path.test b/test/functionalTest/cases/2527_crash_with_empty_uri_path/crash_with_empty_uri_path.test index c161e432ca..da6ffd3942 100644 --- a/test/functionalTest/cases/2527_crash_with_empty_uri_path/crash_with_empty_uri_path.test +++ b/test/functionalTest/cases/2527_crash_with_empty_uri_path/crash_with_empty_uri_path.test @@ -47,14 +47,11 @@ HTTP/1.1 400 Bad Request Date: REGEX(.*) Fiware-Correlator: REGEX([0-9a-f\-]{36}) Content-Type: application/json -Content-Length: 129 +Content-Length: 97 { - "orionError": { - "code": "400", - "details": "Service not found. Check your URL as probably it is wrong.", - "reasonPhrase": "Bad Request" - } + "description": "Service not found. Check your URL as probably it is wrong.", + "error": "BadRequest" } diff --git a/test/functionalTest/cases/2659_bugfix_op_update_id_min_max_length/bugfix_op_update_id_min_max_length.test b/test/functionalTest/cases/2659_bugfix_op_update_id_min_max_length/bugfix_op_update_id_min_max_length.test index 3c4d38535f..235d61b132 100644 --- a/test/functionalTest/cases/2659_bugfix_op_update_id_min_max_length/bugfix_op_update_id_min_max_length.test +++ b/test/functionalTest/cases/2659_bugfix_op_update_id_min_max_length/bugfix_op_update_id_min_max_length.test @@ -100,10 +100,10 @@ HTTP/1.1 400 Bad Request Date: REGEX(.*) Fiware-Correlator: REGEX([0-9a-f\-]{36}) Content-Type: application/json -Content-Length: 83 +Content-Length: 93 { - "description": "entity id length: 0, min length supported: 1", + "description": "id and idPattern cannot be both empty at the same time", "error": "BadRequest" } diff --git a/test/functionalTest/cases/2750_common_metrics/2750_metrics_off.test b/test/functionalTest/cases/2750_common_metrics/2750_metrics_off.test index 2a8519a9cf..ed8db9fb74 100644 --- a/test/functionalTest/cases/2750_common_metrics/2750_metrics_off.test +++ b/test/functionalTest/cases/2750_common_metrics/2750_metrics_off.test @@ -47,11 +47,11 @@ HTTP/1.1 400 Bad Request Date: REGEX(.*) Fiware-Correlator: REGEX([0-9a-f\-]{36}) Content-Type: application/json -Content-Length: 60 +Content-Length: 59 { "description": "metrics desactivated", - "error": "Bad Request" + "error": "BadRequest" } diff --git a/test/functionalTest/cases/2948_wrong_max_one_service_path_response/wrong_max_one_service_path_response.test b/test/functionalTest/cases/2948_wrong_max_one_service_path_response/wrong_max_one_service_path_response.test index 6b6d8c0d36..072192b95e 100644 --- a/test/functionalTest/cases/2948_wrong_max_one_service_path_response/wrong_max_one_service_path_response.test +++ b/test/functionalTest/cases/2948_wrong_max_one_service_path_response/wrong_max_one_service_path_response.test @@ -64,11 +64,11 @@ HTTP/1.1 400 Bad Request Date: REGEX(.*) Fiware-Correlator: REGEX([0-9a-f\-]{36}) Content-Type: application/json -Content-Length: 86 +Content-Length: 85 { "description": "max one service-path allowed for subscriptions", - "error": "Bad Request" + "error": "BadRequest" } diff --git a/test/functionalTest/cases/3068_cprs_full_functional_v2/fwd_v1_ngsiv2_query_forward.test b/test/functionalTest/cases/3068_cprs_full_functional_v2/fwd_v1_ngsiv2_query_forward.test new file mode 100644 index 0000000000..8a36c3d8ba --- /dev/null +++ b/test/functionalTest/cases/3068_cprs_full_functional_v2/fwd_v1_ngsiv2_query_forward.test @@ -0,0 +1,283 @@ +# Copyright 2024 Telefonica Investigacion y Desarrollo, S.A.U +# +# This file is part of Orion Context Broker. +# +# Orion Context Broker is free software: you can redistribute it and/or +# modify it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# Orion Context Broker is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero +# General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. +# +# For those usages not covered by this license please contact with +# iot_support at tid dot es + +# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh + +--NAME-- +Forward Query (NGSIv1 legacy forwarding) + +--SHELL-INIT-- +dbInit CB +brokerStart CB +accumulatorStart --pretty-print + +--SHELL-- + +# +# This test is to check the parseEntitiesResponseV1() logic in CB. Accumulator is used as "fake" CPr +# +# 01. Register ConferenceRoom on CB with accumulator as providing application +# 02. Register ConferenceRoom2 on CB with accumulator as providing application +# 03. Register ConferenceRoom3 pressure on CB with accumulator as providing application +# 04. Query ConferenceRoom in CB +# 05. Query ConferenceRoom2 in CB +# 06. Query ConferenceRoom3 pressure in CB +# 07. Check three forwarded requests in logs +# + +echo "01. Register ConferenceRoom on CB with accumulator as providing application" +echo "===========================================================================" +payload='{ + "dataProvided": { + "entities": [ + { + "type": "Room", + "id": "ConferenceRoom" + } + ] + }, + "provider": { + "http": { + "url": "http://localhost:'${LISTENER_PORT}'/cpr" + }, + "legacyForwarding": true + } +}' +orionCurl --url /v2/registrations --payload "$payload" +echo +echo + + +REG1_ID=$(echo "$_responseHeaders" | grep Location | awk -F/ '{ print $4 }' | tr -d "\r\n") + + +echo "02. Register ConferenceRoom2 on CB with accumulator as providing application" +echo "============================================================================" +payload='{ + "dataProvided": { + "entities": [ + { + "type": "Room", + "id": "ConferenceRoom2" + } + ] + }, + "provider": { + "http": { + "url": "http://localhost:'${LISTENER_PORT}'/cpr" + }, + "legacyForwarding": true + } +}' +orionCurl --url /v2/registrations --payload "$payload" +echo +echo + + +REG2_ID=$(echo "$_responseHeaders" | grep Location | awk -F/ '{ print $4 }' | tr -d "\r\n") + + +echo "03. Register ConferenceRoom3 pressure on CB with accumulator as providing application" +echo "=====================================================================================" +payload='{ + "dataProvided": { + "entities": [ + { + "type": "Room", + "id": "ConferenceRoom3" + } + ], + "attrs": [ "pressure" ] + }, + "provider": { + "http": { + "url": "http://localhost:'${LISTENER_PORT}'/cpr" + }, + "legacyForwarding": true + } +}' +orionCurl --url /v2/registrations --payload "$payload" +echo +echo + + +REG3_ID=$(echo "$_responseHeaders" | grep Location | awk -F/ '{ print $4 }' | tr -d "\r\n") + + +echo "04. Query ConferenceRoom in CB" +echo "==============================" +orionCurl --url /v2/entities/ConferenceRoom +echo +echo + + +echo "05. Query ConferenceRoom2 in CB" +echo "===============================" +orionCurl --url /v2/entities/ConferenceRoom2 +echo +echo + + +echo "06. Query ConferenceRoom3 pressure in CB" +echo "=======================================" +orionCurl --url /v2/entities/ConferenceRoom3/attrs/pressure +echo +echo + + +echo "07. Check three forwarded requests in logs" +echo "==========================================" +cat /tmp/contextBroker.log | grep "Request forwarded" | awk -F 'msg=' '{print $2}' | sed "s/${REG1_ID}/REG1_ID/" | sed "s/${REG2_ID}/REG2_ID/" | sed "s/${REG3_ID}/REG3_ID/" +echo +echo + + +--REGEXPECT-- +01. Register ConferenceRoom on CB with accumulator as providing application +=========================================================================== +HTTP/1.1 201 Created +Date: REGEX(.*) +Fiware-Correlator: REGEX([0-9a-f\-]{36}) +Location: /v2/registrations/REGEX([0-9a-f\-]{24}) +Content-Length: 0 + + + +02. Register ConferenceRoom2 on CB with accumulator as providing application +============================================================================ +HTTP/1.1 201 Created +Date: REGEX(.*) +Fiware-Correlator: REGEX([0-9a-f\-]{36}) +Location: /v2/registrations/REGEX([0-9a-f\-]{24}) +Content-Length: 0 + + + +03. Register ConferenceRoom3 pressure on CB with accumulator as providing application +===================================================================================== +HTTP/1.1 201 Created +Date: REGEX(.*) +Fiware-Correlator: REGEX([0-9a-f\-]{36}) +Location: /v2/registrations/REGEX([0-9a-f\-]{24}) +Content-Length: 0 + + + +04. Query ConferenceRoom in CB +============================== +HTTP/1.1 200 OK +Date: REGEX(.*) +Fiware-Correlator: REGEX([0-9a-f\-]{36}) +Content-Type: application/json +Content-Length: 375 + +{ + "id": "ConferenceRoom", + "lightstatus": { + "metadata": {}, + "type": "StructuredValue", + "value": { + "x": 1, + "y": 2 + } + }, + "pressure": { + "metadata": {}, + "type": "StructuredValue", + "value": [ + "a", + "b", + "c" + ] + }, + "temperature": { + "metadata": { + "ID1": { + "type": "Text", + "value": { + "x": 1, + "y": 2 + } + }, + "ID2": { + "type": "Text", + "value": [ + "a", + "b", + "c" + ] + }, + "ID3": { + "type": "Text", + "value": "ThisIsID" + } + }, + "type": "degree", + "value": "14" + }, + "type": "Room" +} + + +05. Query ConferenceRoom2 in CB +=============================== +HTTP/1.1 200 OK +Date: REGEX(.*) +Fiware-Correlator: REGEX([0-9a-f\-]{36}) +Content-Type: application/json +Content-Length: 97 + +{ + "id": "ConferenceRoom2", + "temperature": { + "metadata": {}, + "type": "degree", + "value": "14" + }, + "type": "Room" +} + + +06. Query ConferenceRoom3 pressure in CB +======================================= +HTTP/1.1 200 OK +Date: REGEX(.*) +Fiware-Correlator: REGEX([0-9a-f\-]{36}) +Content-Type: application/json +Content-Length: 44 + +{ + "metadata": {}, + "type": "degree", + "value": "14" +} + + +07. Check three forwarded requests in logs +========================================== +Request forwarded (regId: REG1_ID): POST http://localhost:9997/cpr/queryContext, request payload (88 bytes): {"entities":[{"id":"ConferenceRoom","isPattern":"false","type":"Room"}],"attributes":[]}, response payload (3912 bytes): +Request forwarded (regId: REG2_ID): POST http://localhost:9997/cpr/queryContext, request payload (89 bytes): {"entities":[{"id":"ConferenceRoom2","isPattern":"false","type":"Room"}],"attributes":[]}, response payload (3912 bytes): +Request forwarded (regId: REG3_ID): POST http://localhost:9997/cpr/queryContext, request payload (99 bytes): {"entities":[{"id":"ConferenceRoom3","isPattern":"false","type":"Room"}],"attributes":["pressure"]}, response payload (3912 bytes): + + +--TEARDOWN-- +brokerStop CB +accumulatorStop $LISTENER_PORT +dbDrop CB diff --git a/test/functionalTest/cases/3068_cprs_full_functional_v2/fwd_v1_ngsiv2_update_forward.test b/test/functionalTest/cases/3068_cprs_full_functional_v2/fwd_v1_ngsiv2_update_forward.test new file mode 100644 index 0000000000..83fbb38ce1 --- /dev/null +++ b/test/functionalTest/cases/3068_cprs_full_functional_v2/fwd_v1_ngsiv2_update_forward.test @@ -0,0 +1,142 @@ +# Copyright 2024 Telefonica Investigacion y Desarrollo, S.A.U +# +# This file is part of Orion Context Broker. +# +# Orion Context Broker is free software: you can redistribute it and/or +# modify it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# Orion Context Broker is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero +# General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. +# +# For those usages not covered by this license please contact with +# iot_support at tid dot es + +# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh + +--NAME-- +Forward Update (NGSIv1 legacy forwarding) + +--SHELL-INIT-- +dbInit CB +brokerStart CB +accumulatorStart --pretty-print + +--SHELL-- + +# +# This test is to check the parseEntitiesResponseV1() logic in CB. Accumulator is used as "fake" CPr +# +# 01. Register ConferenceRoom on CB with accumulator as providing application +# 02. Update ConferenceRoom in CB +# 03. Check one forwarded requests in logs +# + +echo "01. Register ConferenceRoom on CB with accumulator as providing application" +echo "===========================================================================" +payload='{ + "dataProvided": { + "entities": [ + { + "type": "Room", + "id": "ConferenceRoom" + } + ] + }, + "provider": { + "http": { + "url": "http://localhost:'${LISTENER_PORT}'/cpr" + }, + "legacyForwarding": true + } +}' +orionCurl --url /v2/registrations --payload "$payload" +echo +echo + + +REG1_ID=$(echo "$_responseHeaders" | grep Location | awk -F/ '{ print $4 }' | tr -d "\r\n") + + +echo "02. Update ConferenceRoom in CB" +echo "===============================" +payload='{ + "lightstatus": { + "type": "StructuredValue", + "value": { + "x": 1, + "y": 2 + } + }, + "pressure": { + "type": "StructuredValue", + "value": ["a", "b", "c"] + }, + "temperature": { + "value": 14, + "type": "Number", + "metadata": { + "ID1": { + "type": "Text", + "value": { + "x": 1, + "y": 2 + } + }, + "ID2": { + "type": "Text", + "value": ["a", "b", "c"] + }, + "ID3": { + "type": "Text", + "value": "ThisIsID3" + } + } + } +}' +orionCurl --url /v2/entities/ConferenceRoom/attrs?type=Room --payload "$payload" -X PATCH +echo +echo + + +echo "03. Check one forwarded requests in logs" +echo "========================================" +cat /tmp/contextBroker.log | grep "Request forwarded" | awk -F 'msg=' '{print $2}' | sed "s/${REG1_ID}/REG1_ID/" +echo +echo + + +--REGEXPECT-- +01. Register ConferenceRoom on CB with accumulator as providing application +=========================================================================== +HTTP/1.1 201 Created +Date: REGEX(.*) +Fiware-Correlator: REGEX([0-9a-f\-]{36}) +Location: /v2/registrations/REGEX([0-9a-f\-]{24}) +Content-Length: 0 + + + +02. Update ConferenceRoom in CB +=============================== +HTTP/1.1 204 No Content +Date: REGEX(.*) +Fiware-Correlator: REGEX([0-9a-f\-]{36}) + + + +03. Check one forwarded requests in logs +======================================== +Request forwarded (regId: REG1_ID): POST http://localhost:9997/cpr/updateContext, request payload (542 bytes): {"contextElements":[{"id":"ConferenceRoom","isPattern":"false","type":"Room","attributes":[{"name":"lightstatus","type":"StructuredValue","value":{"x":1,"y":2}},{"name":"pressure","type":"StructuredValue","value":["a","b","c"]},{"name":"temperature","type":"Number","value":14,"metadatas":[{"name":"ID1","type":"Text","value":{"type":"Text","value":{"x":1,"y":2}}},{"name":"ID2","type":"Text","value":{"type":"Text","value":["a","b","c"]}},{"name":"ID3","type":"Text","value":{"type":"Text","value":"ThisIsID3"}}]}]}],"updateAction":"UPDATE"}, response payload (3899 bytes): { + + +--TEARDOWN-- +brokerStop CB +accumulatorStop $LISTENER_PORT +dbDrop CB diff --git a/test/functionalTest/cases/3068_cprs_full_functional_v2/fwd_v1_ngsiv2_update_forward_with_fail.test b/test/functionalTest/cases/3068_cprs_full_functional_v2/fwd_v1_ngsiv2_update_forward_with_fail.test new file mode 100644 index 0000000000..af02a8aad8 --- /dev/null +++ b/test/functionalTest/cases/3068_cprs_full_functional_v2/fwd_v1_ngsiv2_update_forward_with_fail.test @@ -0,0 +1,163 @@ +# Copyright 2024 Telefonica Investigacion y Desarrollo, S.A.U +# +# This file is part of Orion Context Broker. +# +# Orion Context Broker is free software: you can redistribute it and/or +# modify it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# Orion Context Broker is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero +# General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. +# +# For those usages not covered by this license please contact with +# iot_support at tid dot es + +# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh + +--NAME-- +Forward Update with fail (NGSIv1 legacy forwarding) + +--SHELL-INIT-- +dbInit CB +brokerStart CB +accumulatorStart --pretty-print + +--SHELL-- + +# +# This test is to check the parseEntitiesResponseV1() logic in CB. Accumulator is used as "fake" CPr +# +# 01. Register ConferenceRoom on CB with accumulator as providing application +# 02. Update ConferenceRoom in CB +# 03. Check the error in CB logs +# 04. Check one forwarded requests in logs +# + +echo "01. Register ConferenceRoom on CB with accumulator as providing application" +echo "===========================================================================" +payload='{ + "dataProvided": { + "entities": [ + { + "type": "Room", + "id": "ConferenceRoom" + } + ] + }, + "provider": { + "http": { + "url": "http://localhost:'${LISTENER_PORT}'/cprfail" + }, + "legacyForwarding": true + } +}' +orionCurl --url /v2/registrations --payload "$payload" +echo +echo + + +REG1_ID=$(echo "$_responseHeaders" | grep Location | awk -F/ '{ print $4 }' | tr -d "\r\n") + + +echo "02. Update ConferenceRoom in CB" +echo "===============================" +payload='{ + "lightstatus": { + "type": "StructuredValue", + "value": { + "x": 1, + "y": 2 + } + }, + "pressure": { + "type": "StructuredValue", + "value": ["a", "b", "c"] + }, + "temperature": { + "value": 14, + "type": "Number", + "metadata": { + "ID1": { + "type": "Text", + "value": { + "x": 1, + "y": 2 + } + }, + "ID2": { + "type": "Text", + "value": ["a", "b", "c"] + }, + "ID3": { + "type": "Text", + "value": "ThisIsID3" + } + } + } +}' +orionCurl --url /v2/entities/ConferenceRoom/attrs?type=Room --payload "$payload" -X PATCH +echo +echo + + +echo "03. Check the error in CB logs" +echo "==============================" +# parentheis are problematic in combintation with REGEX(), so we change to | symbol +cat /tmp/contextBroker.log | grep WARN | awk -F 'msg=' '{print $2}' | sed 's/(/|/' | sed 's/)/|/' +echo +echo + + +echo "04. Check one forwarded requests in logs" +echo "========================================" +cat /tmp/contextBroker.log | grep "Request forwarded" | awk -F 'msg=' '{print $2}' | sed "s/${REG1_ID}/REG1_ID/" +echo +echo + + +--REGEXPECT-- +01. Register ConferenceRoom on CB with accumulator as providing application +=========================================================================== +HTTP/1.1 201 Created +Date: REGEX(.*) +Fiware-Correlator: REGEX([0-9a-f\-]{36}) +Location: /v2/registrations/REGEX([0-9a-f\-]{24}) +Content-Length: 0 + + + +02. Update ConferenceRoom in CB +=============================== +HTTP/1.1 404 Not Found +Date: REGEX(.*) +Fiware-Correlator: REGEX([0-9a-f\-]{36}) +Content-Type: application/json +Content-Length: 95 + +{ + "description": "The requested entity has not been found. Check type and id", + "error": "NotFound" +} + + +03. Check the error in CB logs +============================== +Raising alarm BadInput REGEX((0.0.0.0|127.0.0.1)): JSON Parse Error |non-200 code: 422| +Raising alarm ForwardingError localhost:9997/cprfail/updateContext: error parsing reply from context provider: BadRequest |non-200 code: 422| + + +04. Check one forwarded requests in logs +======================================== +Request forwarded (regId: REG1_ID): POST http://localhost:9997/cprfail/updateContext, request payload (542 bytes): {"contextElements":[{"id":"ConferenceRoom","isPattern":"false","type":"Room","attributes":[{"name":"lightstatus","type":"StructuredValue","value":{"x":1,"y":2}},{"name":"pressure","type":"StructuredValue","value":["a","b","c"]},{"name":"temperature","type":"Number","value":14,"metadatas":[{"name":"ID1","type":"Text","value":{"type":"Text","value":{"x":1,"y":2}}},{"name":"ID2","type":"Text","value":{"type":"Text","value":["a","b","c"]}},{"name":"ID3","type":"Text","value":{"type":"Text","value":"ThisIsID3"}}]}]}],"updateAction":"UPDATE"}, response payload (3188 bytes): { + + +--TEARDOWN-- +brokerStop CB +accumulatorStop $LISTENER_PORT +dbDrop CB diff --git a/test/functionalTest/cases/3112_ngsiv1_autocast/create_attributes_with_autocast.test.DISABLED b/test/functionalTest/cases/3112_ngsiv1_autocast/create_attributes_with_autocast.test.DISABLED deleted file mode 100644 index ad8aa4d3cc..0000000000 --- a/test/functionalTest/cases/3112_ngsiv1_autocast/create_attributes_with_autocast.test.DISABLED +++ /dev/null @@ -1,353 +0,0 @@ -# Copyright 2018 Telefonica Investigacion y Desarrollo, S.A.U -# -# This file is part of Orion Context Broker. -# -# Orion Context Broker is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Orion Context Broker is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -# General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -# -# For those usages not covered by this license please contact with -# iot_support at tid dot es - -# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh - ---NAME-- -Create attributes using NGSIv1 autocast functionality - ---SHELL-INIT-- -dbInit CB -brokerStart CB 0 IPV4 -ngsiv1Autocast - ---SHELL-- - -# -# 01. Create entity with Quantity, Number, Boolean, DateTime and ISO8601 types -# 02. Get entity using NGSIv2 and check values are right -# 03. Append five new attributes with Quantity, Number, Boolean, DateTime and ISO8601 types -# 04. Get entity using NGSIv2 and check values are right -# -# Test is focused in updateContext operation. Note that we have several convenience operations -# in NGSIv1 to do attribute creation/update, but all them are the end are mapped internally -# to updateContext so focusing on it we get proper testing coverage - - -echo "01. Create entity with Quantity, Number, Boolean, DateTime and ISO8601 types" -echo "============================================================================" -payload='{ - "contextElements": [ - { - "type": "T", - "id": "E", - "attributes": [ - { - "name": "N", - "type": "Number", - "value": "-23" - }, - { - "name": "Q", - "type": "Quantity", - "value": "11.31" - }, - { - "name": "B", - "type": "Boolean", - "value": "true" - }, - { - "name": "D", - "type": "DateTime", - "value": "2016-01-12T15:25:00.000Z" - }, - { - "name": "I", - "type": "ISO8601", - "value": "2016-02-24T10:00:00.000Z" - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" -echo -echo - - -echo "02. Get entity using NGSIv2 and check values are right " -echo "======================================================" -orionCurl --url /v2/entities/E -echo -echo - - -echo "03. Append five new attributes with Quantity, Number, Boolean, DateTime and ISO8601 types" -echo "=========================================================================================" -payload='{ - "contextElements": [ - { - "type": "T", - "id": "E", - "attributes": [ - { - "name": "N1", - "type": "Number", - "value": "11" - }, - { - "name": "Q1", - "type": "Quantity", - "value": "-41.31" - }, - { - "name": "B1", - "type": "Boolean", - "value": "false" - }, - { - "name": "D1", - "type": "DateTime", - "value": "2018-01-12T15:25:00.000Z" - }, - { - "name": "I1", - "type": "ISO8601", - "value": "2019-02-24T10:00:00.000Z" - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" -echo -echo - - -echo "04. Get entity using NGSIv2 and check values are right " -echo "======================================================" -orionCurl --url /v2/entities/E -echo -echo - - ---REGEXPECT-- -01. Create entity with Quantity, Number, Boolean, DateTime and ISO8601 types -============================================================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 352 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "N", - "type": "Number", - "value": "" - }, - { - "name": "Q", - "type": "Quantity", - "value": "" - }, - { - "name": "B", - "type": "Boolean", - "value": "" - }, - { - "name": "D", - "type": "DateTime", - "value": "" - }, - { - "name": "I", - "type": "ISO8601", - "value": "" - } - ], - "id": "E", - "isPattern": "false", - "type": "T" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -02. Get entity using NGSIv2 and check values are right -====================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 316 - -{ - "B": { - "metadata": {}, - "type": "Boolean", - "value": true - }, - "D": { - "metadata": {}, - "type": "DateTime", - "value": "2016-01-12T15:25:00.000Z" - }, - "I": { - "metadata": {}, - "type": "ISO8601", - "value": "2016-02-24T10:00:00.000Z" - }, - "N": { - "metadata": {}, - "type": "Number", - "value": -23 - }, - "Q": { - "metadata": {}, - "type": "Quantity", - "value": 11.31 - }, - "id": "E", - "type": "T" -} - - -03. Append five new attributes with Quantity, Number, Boolean, DateTime and ISO8601 types -========================================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 357 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "N1", - "type": "Number", - "value": "" - }, - { - "name": "Q1", - "type": "Quantity", - "value": "" - }, - { - "name": "B1", - "type": "Boolean", - "value": "" - }, - { - "name": "D1", - "type": "DateTime", - "value": "" - }, - { - "name": "I1", - "type": "ISO8601", - "value": "" - } - ], - "id": "E", - "isPattern": "false", - "type": "T" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -04. Get entity using NGSIv2 and check values are right -====================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 617 - -{ - "B": { - "metadata": {}, - "type": "Boolean", - "value": true - }, - "B1": { - "metadata": {}, - "type": "Boolean", - "value": false - }, - "D": { - "metadata": {}, - "type": "DateTime", - "value": "2016-01-12T15:25:00.000Z" - }, - "D1": { - "metadata": {}, - "type": "DateTime", - "value": "2018-01-12T15:25:00.000Z" - }, - "I": { - "metadata": {}, - "type": "ISO8601", - "value": "2016-02-24T10:00:00.000Z" - }, - "I1": { - "metadata": {}, - "type": "ISO8601", - "value": "2019-02-24T10:00:00.000Z" - }, - "N": { - "metadata": {}, - "type": "Number", - "value": -23 - }, - "N1": { - "metadata": {}, - "type": "Number", - "value": 11 - }, - "Q": { - "metadata": {}, - "type": "Quantity", - "value": 11.31 - }, - "Q1": { - "metadata": {}, - "type": "Quantity", - "value": -41.31 - }, - "id": "E", - "type": "T" -} - - ---TEARDOWN-- -brokerStop CB -dbDrop CB diff --git a/test/functionalTest/cases/3112_ngsiv1_autocast/filters_in_autocasted_attributes.test.DISABLED b/test/functionalTest/cases/3112_ngsiv1_autocast/filters_in_autocasted_attributes.test.DISABLED deleted file mode 100644 index c8fdb6a63c..0000000000 --- a/test/functionalTest/cases/3112_ngsiv1_autocast/filters_in_autocasted_attributes.test.DISABLED +++ /dev/null @@ -1,336 +0,0 @@ -# Copyright 2018 Telefonica Investigacion y Desarrollo, S.A.U -# -# This file is part of Orion Context Broker. -# -# Orion Context Broker is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Orion Context Broker is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -# General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -# -# For those usages not covered by this license please contact with -# iot_support at tid dot es - -# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh - ---NAME-- -Filtering on attribute values created with NGSIv1 autocast - ---SHELL-INIT-- -dbInit CB -brokerStart CB 0 IPV4 -ngsiv1Autocast - ---SHELL-- - -# -# 01. Create E1 entity, with attribute level = 70, date = 2016-01-12T15:25:00.000Z -# 02. Create E2 entity, with attribute level = 80, date = 2016-01-12T14:25:00.000Z -# 03. Create E3 entity, with attribute level = 90, date = 2016-01-12T13:25:00.000Z -# 04. Query level<85, get E1 and E2 -# 05. Query date<2016-01-12T15:00:00.000Z, get E2 and E3 -# -# Test is focused in updateContext operation. Note that we have several convenience operations -# in NGSIv1 to do attribute creation/update, but all them are the end are mapped internally -# to updateContext so focusing on it we get proper testing coverage - - -echo "01. Create E1 entity, with attribute level = 70, date = 20160112T15:25:00.000Z" -echo "==============================================================================" -payload='{ - "contextElements": [ - { - "type": "T", - "id": "E1", - "attributes": [ - { - "name": "level", - "type": "Number", - "value": "70" - }, - { - "name": "date", - "type": "ISO8601", - "value": "2016-01-12T15:25:00.000Z" - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" -echo -echo - - -echo "02. Create E2 entity, with attribute level = 80, date = 2016-01-12T14:25:00.000Z" -echo "================================================================================" -payload='{ - "contextElements": [ - { - "type": "T", - "id": "E2", - "attributes": [ - { - "name": "level", - "type": "Number", - "value": "80" - }, - { - "name": "date", - "type": "ISO8601", - "value": "2016-01-12T14:25:00.000Z" - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" -echo -echo - - -echo "03. Create E3 entity, with attribute level = 90, date = 2016-01-12T13:25:00.000Z" -echo "================================================================================" -payload='{ - "contextElements": [ - { - "type": "T", - "id": "E3", - "attributes": [ - { - "name": "level", - "type": "Number", - "value": "90" - }, - { - "name": "date", - "type": "ISO8601", - "value": "2016-01-12T13:25:00.000Z" - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" -echo -echo - - -echo "04. Query level<85, get E1 and E2" -echo "=================================" -orionCurl --url '/v2/entities?q=level<85' -echo -echo - - -echo "05. Query date<2016-01-12T15:00:00.000Z, get E2 and E3" -echo "======================================================" -orionCurl --url '/v2/entities?q=date<2016-01-12T15:00:00.000Z' -echo -echo - - ---REGEXPECT-- -01. Create E1 entity, with attribute level = 70, date = 20160112T15:25:00.000Z -============================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 235 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "level", - "type": "Number", - "value": "" - }, - { - "name": "date", - "type": "ISO8601", - "value": "" - } - ], - "id": "E1", - "isPattern": "false", - "type": "T" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -02. Create E2 entity, with attribute level = 80, date = 2016-01-12T14:25:00.000Z -================================================================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 235 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "level", - "type": "Number", - "value": "" - }, - { - "name": "date", - "type": "ISO8601", - "value": "" - } - ], - "id": "E2", - "isPattern": "false", - "type": "T" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -03. Create E3 entity, with attribute level = 90, date = 2016-01-12T13:25:00.000Z -================================================================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 235 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "level", - "type": "Number", - "value": "" - }, - { - "name": "date", - "type": "ISO8601", - "value": "" - } - ], - "id": "E3", - "isPattern": "false", - "type": "T" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -04. Query level<85, get E1 and E2 -================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 299 - -[ - { - "date": { - "metadata": {}, - "type": "ISO8601", - "value": "2016-01-12T15:25:00.000Z" - }, - "id": "E1", - "level": { - "metadata": {}, - "type": "Number", - "value": 70 - }, - "type": "T" - }, - { - "date": { - "metadata": {}, - "type": "ISO8601", - "value": "2016-01-12T14:25:00.000Z" - }, - "id": "E2", - "level": { - "metadata": {}, - "type": "Number", - "value": 80 - }, - "type": "T" - } -] - - -05. Query date<2016-01-12T15:00:00.000Z, get E2 and E3 -====================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 299 - -[ - { - "date": { - "metadata": {}, - "type": "ISO8601", - "value": "2016-01-12T14:25:00.000Z" - }, - "id": "E2", - "level": { - "metadata": {}, - "type": "Number", - "value": 80 - }, - "type": "T" - }, - { - "date": { - "metadata": {}, - "type": "ISO8601", - "value": "2016-01-12T13:25:00.000Z" - }, - "id": "E3", - "level": { - "metadata": {}, - "type": "Number", - "value": 90 - }, - "type": "T" - } -] - - ---TEARDOWN-- -brokerStop CB -dbDrop CB diff --git a/test/functionalTest/cases/3112_ngsiv1_autocast/update_attributes_with_autocast.test.DISABLED b/test/functionalTest/cases/3112_ngsiv1_autocast/update_attributes_with_autocast.test.DISABLED deleted file mode 100644 index fd1f23ed88..0000000000 --- a/test/functionalTest/cases/3112_ngsiv1_autocast/update_attributes_with_autocast.test.DISABLED +++ /dev/null @@ -1,328 +0,0 @@ -# Copyright 2018 Telefonica Investigacion y Desarrollo, S.A.U -# -# This file is part of Orion Context Broker. -# -# Orion Context Broker is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Orion Context Broker is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -# General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -# -# For those usages not covered by this license please contact with -# iot_support at tid dot es - -# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh - ---NAME-- -Update attributes using NGSIv1 autocast functionality - ---SHELL-INIT-- -dbInit CB -brokerStart CB 0 IPV4 -ngsiv1Autocast - ---SHELL-- - -# -# 01. Create entity with Quantity, Number, Boolean, DateTime and ISO8601 types but with 'wrong' values -# 02. Get entity using NGSIv2 and check values (all strings) -# 03. Update attributes with 'right' Quantity, Number, Boolean, DateTime and ISO8601 values -# 04. Get entity using NGSIv2 and check values (right types) -# -# Test is focused in updateContext operation. Note that we have several convenience operations -# in NGSIv1 to do attribute creation/update, but all them are the end are mapped internally -# to updateContext so focusing on it we get proper testing coverage - - -echo "01. Create entity with Quantity, Number, Boolean, DateTime and ISO8601 types but with 'wrong' values" -echo "====================================================================================================" -payload='{ - "contextElements": [ - { - "type": "T", - "id": "E", - "attributes": [ - { - "name": "N", - "type": "Number", - "value": "-2x3" - }, - { - "name": "Q", - "type": "Quantity", - "value": "11,,31" - }, - { - "name": "B", - "type": "Boolean", - "value": "truex" - }, - { - "name": "D", - "type": "DateTime", - "value": "20160112T15:25:00.000Z" - }, - { - "name": "I", - "type": "ISO8601", - "value": "year-02-24T10:00:00.000Z" - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" -echo -echo - - -echo "02. Get entity using NGSIv2 and check values (all strings)" -echo "==========================================================" -orionCurl --url /v2/entities/E -echo -echo - - -echo "03. Update attributes with 'right' Quantity, Number, Boolean, DateTime and ISO8601 values" -echo "=========================================================================================" -payload='{ - "contextElements": [ - { - "type": "T", - "id": "E", - "attributes": [ - { - "name": "N", - "type": "Number", - "value": "11" - }, - { - "name": "Q", - "type": "Quantity", - "value": "-41.31" - }, - { - "name": "B", - "type": "Boolean", - "value": "false" - }, - { - "name": "D", - "type": "DateTime", - "value": "2018-01-12T15:25:00.000Z" - }, - { - "name": "I", - "type": "ISO8601", - "value": "2019-02-24T10:00:00.000Z" - } - ] - } - ], - "updateAction": "UPDATE" -}' -orionCurl --url /v1/updateContext --payload "$payload" -echo -echo - - -echo "04. Get entity using NGSIv2 and check values (right types)" -echo "==========================================================" -orionCurl --url /v2/entities/E -echo -echo - - ---REGEXPECT-- -01. Create entity with Quantity, Number, Boolean, DateTime and ISO8601 types but with 'wrong' values -==================================================================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 352 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "N", - "type": "Number", - "value": "" - }, - { - "name": "Q", - "type": "Quantity", - "value": "" - }, - { - "name": "B", - "type": "Boolean", - "value": "" - }, - { - "name": "D", - "type": "DateTime", - "value": "" - }, - { - "name": "I", - "type": "ISO8601", - "value": "" - } - ], - "id": "E", - "isPattern": "false", - "type": "T" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -02. Get entity using NGSIv2 and check values (all strings) -========================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 323 - -{ - "B": { - "metadata": {}, - "type": "Boolean", - "value": "truex" - }, - "D": { - "metadata": {}, - "type": "DateTime", - "value": "20160112T15:25:00.000Z" - }, - "I": { - "metadata": {}, - "type": "ISO8601", - "value": "year-02-24T10:00:00.000Z" - }, - "N": { - "metadata": {}, - "type": "Number", - "value": "-2x3" - }, - "Q": { - "metadata": {}, - "type": "Quantity", - "value": "11,,31" - }, - "id": "E", - "type": "T" -} - - -03. Update attributes with 'right' Quantity, Number, Boolean, DateTime and ISO8601 values -========================================================================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 352 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "N", - "type": "Number", - "value": "" - }, - { - "name": "Q", - "type": "Quantity", - "value": "" - }, - { - "name": "B", - "type": "Boolean", - "value": "" - }, - { - "name": "D", - "type": "DateTime", - "value": "" - }, - { - "name": "I", - "type": "ISO8601", - "value": "" - } - ], - "id": "E", - "isPattern": "false", - "type": "T" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -04. Get entity using NGSIv2 and check values (right types) -========================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 317 - -{ - "B": { - "metadata": {}, - "type": "Boolean", - "value": false - }, - "D": { - "metadata": {}, - "type": "DateTime", - "value": "2018-01-12T15:25:00.000Z" - }, - "I": { - "metadata": {}, - "type": "ISO8601", - "value": "2019-02-24T10:00:00.000Z" - }, - "N": { - "metadata": {}, - "type": "Number", - "value": 11 - }, - "Q": { - "metadata": {}, - "type": "Quantity", - "value": -41.31 - }, - "id": "E", - "type": "T" -} - - ---TEARDOWN-- -brokerStop CB -dbDrop CB diff --git a/test/functionalTest/cases/3112_ngsiv1_autocast/update_only_value_with_autocast.test.DISABLED b/test/functionalTest/cases/3112_ngsiv1_autocast/update_only_value_with_autocast.test.DISABLED deleted file mode 100644 index 6a8357c484..0000000000 --- a/test/functionalTest/cases/3112_ngsiv1_autocast/update_only_value_with_autocast.test.DISABLED +++ /dev/null @@ -1,507 +0,0 @@ -# Copyright 2018 Telefonica Investigacion y Desarrollo, S.A.U -# -# This file is part of Orion Context Broker. -# -# Orion Context Broker is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# Orion Context Broker is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -# General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -# -# For those usages not covered by this license please contact with -# iot_support at tid dot es - -# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh - ---NAME-- -Update only value in attributes using NGSIv1 autocast functionality - ---SHELL-INIT-- -dbInit CB -brokerStart CB 0 IPV4 -ngsiv1Autocast - ---SHELL-- - -# -# 01. Create entity with Quantity, Number, Boolean, DateTime and ISO8601 types -# 02. Get entity using NGSIv2 and check values are right -# 03. Update only the value of the Quantity -# 04. Update only the value of the Number -# 05. Update only the value of the Boolean -# 06. Update only the value of the DateTime -# 07. Update only the value of the ISO8601 -# 08. Get entity using NGSIv2 and check values are right -# -# Test is focused in updateContext operation. Note that we have several convenience operations -# in NGSIv1 to do attribute creation/update, but all them are the end are mapped internally -# to updateContext so focusing on it we get proper testing coverage - - -echo "01. Create entity with Quantity, Number, Boolean, DateTime and ISO8601 types" -echo "============================================================================" -payload='{ - "contextElements": [ - { - "type": "T", - "id": "E", - "attributes": [ - { - "name": "N", - "type": "Number", - "value": "-23" - }, - { - "name": "Q", - "type": "Quantity", - "value": "11.31" - }, - { - "name": "B", - "type": "Boolean", - "value": "true" - }, - { - "name": "D", - "type": "DateTime", - "value": "2016-01-12T15:25:00.000Z" - }, - { - "name": "I", - "type": "ISO8601", - "value": "2016-02-24T10:00:00.000Z" - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" -echo -echo - - -echo "02. Get entity using NGSIv2 and check types are right " -echo "=====================================================" -orionCurl --url /v2/entities/E -echo -echo - - -echo "03. Update only the value of the Quantity" -echo "=========================================" -payload='{ - "contextElements": [ - { - "type": "T", - "id": "E", - "attributes": [ - { - "name": "Q", - "value": "-42" - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" -echo -echo - - -echo "04. Update only the value of the Number" -echo "=======================================" -payload='{ - "contextElements": [ - { - "type": "T", - "id": "E", - "attributes": [ - { - "name": "N", - "value": "2.22" - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" -echo -echo - - -echo "05. Update only the value of the Boolean" -echo "========================================" -payload='{ - "contextElements": [ - { - "type": "T", - "id": "E", - "attributes": [ - { - "name": "B", - "value": "false" - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" -echo -echo - - -echo "06. Update only the value of the DateTime" -echo "=========================================" -payload='{ - "contextElements": [ - { - "type": "T", - "id": "E", - "attributes": [ - { - "name": "D", - "value": "2010-01-12T15:25:00.000Z" - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" -echo -echo - - -echo "07 Update only the value of the ISO8601" -echo "=======================================" -payload='{ - "contextElements": [ - { - "type": "T", - "id": "E", - "attributes": [ - { - "name": "I", - "value": "2008-01-12T15:25:00.000Z" - } - ] - } - ], - "updateAction": "APPEND" -}' -orionCurl --url /v1/updateContext --payload "$payload" -echo -echo - - -echo "08. Get entity using NGSIv2 and check types are right " -echo "=====================================================" -orionCurl --url /v2/entities/E -echo -echo - - ---REGEXPECT-- -01. Create entity with Quantity, Number, Boolean, DateTime and ISO8601 types -============================================================================ -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 352 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "N", - "type": "Number", - "value": "" - }, - { - "name": "Q", - "type": "Quantity", - "value": "" - }, - { - "name": "B", - "type": "Boolean", - "value": "" - }, - { - "name": "D", - "type": "DateTime", - "value": "" - }, - { - "name": "I", - "type": "ISO8601", - "value": "" - } - ], - "id": "E", - "isPattern": "false", - "type": "T" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -02. Get entity using NGSIv2 and check types are right -===================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 316 - -{ - "B": { - "metadata": {}, - "type": "Boolean", - "value": true - }, - "D": { - "metadata": {}, - "type": "DateTime", - "value": "2016-01-12T15:25:00.000Z" - }, - "I": { - "metadata": {}, - "type": "ISO8601", - "value": "2016-02-24T10:00:00.000Z" - }, - "N": { - "metadata": {}, - "type": "Number", - "value": -23 - }, - "Q": { - "metadata": {}, - "type": "Quantity", - "value": 11.31 - }, - "id": "E", - "type": "T" -} - - -03. Update only the value of the Quantity -========================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 180 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "Q", - "type": "", - "value": "" - } - ], - "id": "E", - "isPattern": "false", - "type": "T" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -04. Update only the value of the Number -======================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 180 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "N", - "type": "", - "value": "" - } - ], - "id": "E", - "isPattern": "false", - "type": "T" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -05. Update only the value of the Boolean -======================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 180 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "B", - "type": "", - "value": "" - } - ], - "id": "E", - "isPattern": "false", - "type": "T" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -06. Update only the value of the DateTime -========================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 180 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "D", - "type": "", - "value": "" - } - ], - "id": "E", - "isPattern": "false", - "type": "T" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -07 Update only the value of the ISO8601 -======================================= -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 180 - -{ - "contextResponses": [ - { - "contextElement": { - "attributes": [ - { - "name": "I", - "type": "", - "value": "" - } - ], - "id": "E", - "isPattern": "false", - "type": "T" - }, - "statusCode": { - "code": "200", - "reasonPhrase": "OK" - } - } - ] -} - - -08. Get entity using NGSIv2 and check types are right -===================================================== -HTTP/1.1 200 OK -Date: REGEX(.*) -Fiware-Correlator: REGEX([0-9a-f\-]{36}) -Content-Type: application/json -Content-Length: 316 - -{ - "B": { - "metadata": {}, - "type": "Boolean", - "value": false - }, - "D": { - "metadata": {}, - "type": "DateTime", - "value": "2010-01-12T15:25:00.000Z" - }, - "I": { - "metadata": {}, - "type": "ISO8601", - "value": "2008-01-12T15:25:00.000Z" - }, - "N": { - "metadata": {}, - "type": "Number", - "value": 2.22 - }, - "Q": { - "metadata": {}, - "type": "Quantity", - "value": -42 - }, - "id": "E", - "type": "T" -} - - ---TEARDOWN-- -brokerStop CB -dbDrop CB diff --git a/test/functionalTest/cases/3658_env_vars/env_vars.test b/test/functionalTest/cases/3658_env_vars/env_vars.test index 60222b9c14..49b7c3818e 100644 --- a/test/functionalTest/cases/3658_env_vars/env_vars.test +++ b/test/functionalTest/cases/3658_env_vars/env_vars.test @@ -119,16 +119,13 @@ Extended Usage: contextBroker [option '-U' (extended usage)] [option '-statNotifQueue' (enable thread pool notifications queue statistics)] ORION_STAT_NOTIF_QUEUE FALSE /FALSE/ [option '-logSummary' ] ORION_LOG_LINE_MAX_SIZE 32768 /32768/ >= 100 [option '-logInfoPayloadMaxSize' = 0 [option '-disableMetrics' (turn off the 'metrics' feature)] ORION_DISABLE_METRICS FALSE /FALSE/ - [option '-disableNgsiv1' (turn off NGSIv1 request endpoints)] ORION_DISABLE_NGSIV1 FALSE /FALSE/ [option '-insecureNotif' (allow HTTPS notifications to peers which certificate c] ORION_INSECURE_NOTIF FALSE /FALSE/ - [option '-ngsiv1Autocast' (automatic cast for number, booleans and dates in NGSI] ORION_NGSIV1_AUTOCAST FALSE /FALSE/ [option '-mqttMaxAge' id = "E"; - enP->type = "T"; - enP->isPattern = "false"; - Entities ens1; - ens1.vec.push_back(enP); - - // Entities with nok Entity inside - enP = new Entity(); - enP->id = ""; - enP->type = "T"; - enP->isPattern = "false"; - Entities ens2; - ens2.vec.push_back(enP); - - EXPECT_EQ("OK", ens1.check(EntitiesRequest)); - EXPECT_EQ("entity id length: 0, min length supported: 1", ens2.check(EntitiesRequest)); - - utExit(); -} diff --git a/test/unittests/apiTypesV2/EntityVector_test.cpp b/test/unittests/apiTypesV2/EntityVector_test.cpp index e54c44e8ce..99351710cb 100644 --- a/test/unittests/apiTypesV2/EntityVector_test.cpp +++ b/test/unittests/apiTypesV2/EntityVector_test.cpp @@ -29,39 +29,6 @@ -/* **************************************************************************** -* -* check -*/ -TEST(EntityVector, check) -{ - utInit(); - - Entity* enP; - - // EntityVector with ok Entity inside - enP = new Entity(); - enP->id = "E"; - enP->type = "T"; - enP->isPattern = "false"; - EntityVector enV1; - enV1.push_back(enP); - - // EntityVector with nok Entity inside - enP = new Entity(); - enP->id = ""; - enP->type = "T"; - enP->isPattern = "false"; - EntityVector enV2; - enV2.push_back(enP); - - EXPECT_EQ("OK", enV1.check(V2, EntitiesRequest)); - EXPECT_EQ("entity id length: 0, min length supported: 1", enV2.check(V2, EntitiesRequest)); - - utExit(); -} - - /* **************************************************************************** * * render - @@ -69,18 +36,22 @@ TEST(EntityVector, check) */ TEST(EntityVector, render) { + utInit(); + Entity* eP = new Entity(); std::string rendered; EntityVector eV; - rendered = eV.toJsonV1(false, UpdateContextElement, false); - EXPECT_STREQ("", rendered.c_str()); + rendered = eV.toJson(NGSI_V2_NORMALIZED); + EXPECT_STREQ("[]", rendered.c_str()); - eP->id = "E_ID"; - eP->type = "E_TYPE"; + eP->entityId.id = "E_ID"; + eP->entityId.type = "E_TYPE"; eV.push_back(eP); - rendered = eV.toJsonV1(false, UpdateContextElement, false); + rendered = eV.toJson(NGSI_V2_NORMALIZED); eV.release(); + + utExit(); } diff --git a/test/unittests/apiTypesV2/Entity_test.cpp b/test/unittests/apiTypesV2/Entity_test.cpp index 6238fd7994..8fbdcc94db 100644 --- a/test/unittests/apiTypesV2/Entity_test.cpp +++ b/test/unittests/apiTypesV2/Entity_test.cpp @@ -43,34 +43,36 @@ TEST(Entity, check) utInit(); Entity* enP = new Entity(); - enP->id = "E"; - enP->type = "T"; - enP->isPattern = "false"; - enP->isTypePattern = false; + enP->entityId.id = "E"; + enP->entityId.type = "T"; ContextAttribute* caP = new ContextAttribute("A", "T", "val"); enP->attributeVector.push_back(caP); - EXPECT_EQ("OK", enP->check(V2, EntitiesRequest)); + EXPECT_EQ("OK", enP->check(EntitiesRequest)); - enP->id = ""; - EXPECT_EQ("entity id length: 0, min length supported: 1", enP->check(V2, EntitiesRequest)); + enP->entityId.id = ""; + EXPECT_EQ("id and idPattern cannot be both empty at the same time", enP->check(EntitiesRequest)); - enP->id = "E<1>"; - EXPECT_EQ(ERROR_DESC_BAD_REQUEST_INVALID_CHAR_ENTID, enP->check(V2, EntitiesRequest)); - enP->isPattern = "true"; - EXPECT_EQ("OK", enP->check(V2, EntitiesRequest)); - enP->id = "E"; - enP->isPattern = "false"; + enP->entityId.id = "E<1>"; + EXPECT_EQ(ERROR_DESC_BAD_REQUEST_INVALID_CHAR_ENTID, enP->check(EntitiesRequest)); - enP->type = "T<1>"; - EXPECT_EQ(ERROR_DESC_BAD_REQUEST_INVALID_CHAR_ENTTYPE, enP->check(V2, EntitiesRequest)); - enP->isTypePattern = true; - EXPECT_EQ("OK", enP->check(V2, EntitiesRequest)); - enP->type = "T"; + enP->entityId.idPattern = "E<1>"; + enP->entityId.id = ""; + EXPECT_EQ("OK", enP->check(EntitiesRequest)); - enP->isPattern = ""; - EXPECT_EQ("Invalid value for isPattern", enP->check(V2, EntitiesRequest)); + enP->entityId.id = "E"; + enP->entityId.idPattern = ""; + + enP->entityId.type = "T<1>"; + enP->typeGiven = true; + EXPECT_EQ(ERROR_DESC_BAD_REQUEST_INVALID_CHAR_ENTTYPE, enP->check(EntitiesRequest)); + + enP->entityId.typePattern = "T<1>"; + enP->entityId.type = ""; + EXPECT_EQ("OK", enP->check(EntitiesRequest)); + + delete enP; utExit(); } @@ -84,42 +86,41 @@ TEST(Entity, check) */ TEST(Entity, checkV1) { - Entity* enP = new Entity(); - utInit(); - enP->id = ""; - EXPECT_EQ(enP->check(V1, UpdateContext), "empty entityId:id"); + Entity* enP = new Entity(); + + enP->entityId.id = ""; + EXPECT_EQ(enP->check(BatchUpdateRequest), "id and idPattern cannot be both empty at the same time"); - enP->id = "id"; - EXPECT_EQ(enP->check(V1, UpdateContext), "OK"); + enP->entityId.id = "id"; + enP->typeGiven = true; + EXPECT_EQ(enP->check(BatchUpdateRequest), "type and typePattern cannot be both empty at the same time"); ContextAttribute* aP = new ContextAttribute(); aP->name = ""; aP->stringValue = "V"; enP->attributeVector.push_back(aP); - EXPECT_EQ(enP->check(V1, UpdateContext), "missing attribute name"); + EXPECT_EQ(enP->check(BatchUpdateRequest), "type and typePattern cannot be both empty at the same time"); aP->name = "name"; - Entity* en2P = new Entity("id", "", "false"); + Entity* en2P = new Entity("id", "", "", ""); + en2P->renderId = true; EntityVector* ceVectorP = new EntityVector(); - EXPECT_EQ(ceVectorP->check(V1, UpdateContext), "No context elements"); - ceVectorP->push_back(enP); ceVectorP->push_back(en2P); - EXPECT_EQ(ceVectorP->check(V1, UpdateContext), "OK"); // render const char* outfile1 = "ngsi.contextelement.check.middle.json"; std::string out; - out = en2P->toJsonV1(false, UpdateContextElement, false, false, false); + out = en2P->toJson(NGSI_V2_NORMALIZED, false); EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'"; EXPECT_STREQ(expectedBuf, out.c_str()); - EXPECT_EQ("OK", ceVectorP->check(V1, UpdateContext)); + delete ceVectorP; utExit(); } diff --git a/test/unittests/cache/SubscriptionCache_test.cpp b/test/unittests/cache/SubscriptionCache_test.cpp index 11a2777836..41a995ef3b 100644 --- a/test/unittests/cache/SubscriptionCache_test.cpp +++ b/test/unittests/cache/SubscriptionCache_test.cpp @@ -27,9 +27,7 @@ #include "gtest/gtest.h" -#include "ngsi/Restriction.h" #include "ngsi/Reference.h" -#include "ngsi/NotifyConditionVector.h" #include "ngsi/EntityId.h" #include "ngsi/ContextAttribute.h" #include "cache/SubscriptionCache.h" @@ -50,7 +48,6 @@ extern void setMongoConnectionForUnitTest(orion::DBClientBase _connection); */ TEST(cache, SubscriptionCache) { - LM_M(("In SubscriptionCache test")); utInit(); std::vector entityIdInfos; diff --git a/test/unittests/common/commonGlobals_test.cpp b/test/unittests/common/commonGlobals_test.cpp index ef8548526c..a456db15d0 100644 --- a/test/unittests/common/commonGlobals_test.cpp +++ b/test/unittests/common/commonGlobals_test.cpp @@ -85,181 +85,4 @@ TEST(commonGlobals, isFalse) EXPECT_FALSE(bFalse); bFalse = isFalse("1"); EXPECT_FALSE(bFalse); -} - - - -/* **************************************************************************** -* -* parse8601 - -*/ -TEST(commonGlobals, parse8601) -{ - int secs; - const int oneYear = 365 * 24 * 3600 * 1; - const int oneMonth = 30 * 24 * 3600 * 1; - const int oneWeek = 7 * 24 * 3600 * 1; - const int oneDay = 24 * 3600 * 1; - const int oneHour = 3600 * 1; - const int oneMinute = 60 * 1; - const int oneSecond = 1; - const int twoYears = 365 * 24 * 3600 * 2; - const int twoMonths = 30 * 24 * 3600 * 2; - const int twoWeeks = oneWeek * 2; - const int twoDays = 24 * 3600 * 2; - const int twoHours = 3600 * 2; - const int twoMinutes = 60 * 2; - const int twoSeconds = oneSecond * 2; - const int threeYearsOneMonthOneDayOneHourOneMinuteAndElevenSeconds = 3 * oneYear + oneMonth + oneDay + oneHour + oneMinute + 11; - - secs = parse8601("P2Y"); - EXPECT_EQ(twoYears, secs) << "bad value for two years"; - secs = parse8601("PT2Y"); - EXPECT_EQ(-1, secs) << "PT2Y should return -1 - parse error ..."; - - secs = parse8601("P2M"); - EXPECT_EQ(twoMonths, secs) << "bad value for two months"; - - secs = parse8601("P2W"); - EXPECT_EQ(twoWeeks, secs) << "bad value for two weeks"; - secs = parse8601("PT2W"); - EXPECT_EQ(-1, secs) << "PT2W should return -1 - parse error ..."; - - secs = parse8601("P2D"); - EXPECT_EQ(twoDays, secs) << "bad value for two days"; - secs = parse8601("PT2D"); - EXPECT_EQ(-1, secs) << "PT2D should return -1 - parse error ..."; - - secs = parse8601("PT2H"); - EXPECT_EQ(twoHours, secs) << "bad value for two hours"; - secs = parse8601("P2H"); - EXPECT_EQ(-1, secs) << "P2H should return -1 - parse error ..."; - - secs = parse8601("PT2M"); - EXPECT_EQ(twoMinutes, secs) << "bad value for two minutes"; - - secs = parse8601("PT2S"); - EXPECT_EQ(twoSeconds, secs) << "bad value for two seconds"; - secs = parse8601("P2S"); - EXPECT_EQ(-1, secs) << "P2S should return -1 - parse error ..."; - - secs = parse8601("P3Y1M1DT1H1M11S"); - EXPECT_EQ(threeYearsOneMonthOneDayOneHourOneMinuteAndElevenSeconds, secs) << "parse error for 'P3Y1M1DT1H1M11S'"; - - secs = parse8601("P0YT12.005S"); - EXPECT_EQ(12, secs) << "parse error for 'P0YT12.005S'"; - - secs = parse8601("P0YT12.49999S"); - EXPECT_EQ(12, secs) << "round error for 'P0YT12.49999S'"; - - secs = parse8601("P0YT12.50S"); - EXPECT_EQ(13, secs) << "round error for 'P0YT12.50S'"; - - secs = parse8601("P0YT12.51S"); - EXPECT_EQ(13, secs) << "round error for 'P0YT12.51S'"; - - - // - // Errors - // - secs = parse8601(""); - EXPECT_EQ(-1, secs); - - secs = parse8601("Q1"); - EXPECT_EQ(-1, secs); - - secs = parse8601("P"); - EXPECT_EQ(-1, secs); - - secs = parse8601("Px"); - EXPECT_EQ(-1, secs); - - secs = parse8601("P4"); - EXPECT_EQ(-1, secs); - - secs = parse8601("P4Y1"); - EXPECT_EQ(-1, secs); - - secs = parse8601("PT4Y"); - EXPECT_EQ(-1, secs); - - secs = parse8601("PT99Y"); - EXPECT_EQ(-1, secs); - - secs = parse8601("PY99"); - EXPECT_EQ(-1, secs); -} - - - -/* **************************************************************************** -* -* toSeconds - -*/ -TEST(commonGlobals, toSeconds) -{ - int secs; - long long longsecs; - - // 3 years - secs = toSeconds(3, 'Y', true); - EXPECT_EQ(3 * 365 * 24 * 3600, secs); - - // error - secs = toSeconds(3, 'Y', false); - EXPECT_EQ(-1, secs); - - // 3 months - secs = toSeconds(3, 'M', true); - EXPECT_EQ(3 * 30 * 24 * 3600, secs); - - // 3 weeks - secs = toSeconds(3, 'W', true); - EXPECT_EQ(3 * 7 * 24 * 3600, secs); - - // 3 days - secs = toSeconds(3, 'D', true); - EXPECT_EQ(3 * 24 * 3600, secs); - - // 3 hours - secs = toSeconds(3, 'H', false); - EXPECT_EQ(3 * 3600, secs); - - // 3 minutes - secs = toSeconds(3, 'M', false); - EXPECT_EQ(3 * 60, secs); - - // 3 seconds - secs = toSeconds(3, 'S', false); - EXPECT_EQ(3, secs); - - // error - secs = toSeconds(3, 'f', false); - EXPECT_EQ(-1, secs); - - longsecs = toSeconds(30, 'Y', true); - EXPECT_EQ(946080000, longsecs); - - longsecs = toSeconds(300, 'Y', true); - EXPECT_EQ(9460800000L, longsecs); -} - - -/* **************************************************************************** -* -* getCurrentTime - -*/ -TEST(commonGlobals, getCurrentTime) -{ - int now; - - // 1. No timer - setTimer(NULL); - now = getCurrentTime(); - EXPECT_EQ(-1, now); - - utInit(); // timer is set up inside utInit - now = getCurrentTime(); - EXPECT_TRUE(now != -1); - utExit(); -} +} \ No newline at end of file diff --git a/test/unittests/common/commonMacroSubstitute_test.cpp b/test/unittests/common/commonMacroSubstitute_test.cpp index 90011a3708..2b079770c1 100644 --- a/test/unittests/common/commonMacroSubstitute_test.cpp +++ b/test/unittests/common/commonMacroSubstitute_test.cpp @@ -39,7 +39,7 @@ */ TEST(commonMacroSubstitute, simple) { - Entity en("E1", "T1", "false"); + Entity en("E1", "", "T1", ""); ContextAttribute* caP = new ContextAttribute("A1", "T1", "attr1"); bool b; @@ -50,8 +50,8 @@ TEST(commonMacroSubstitute, simple) std::string result; ExprContextObject exprContext(true); - exprContext.add("id", en.id); - exprContext.add("type", en.type); + exprContext.add("id", en.entityId.id); + exprContext.add("type", en.entityId.type); exprContext.add(caP->name, caP->stringValue); b = macroSubstitute(&result, s1, &exprContext, "", true); @@ -67,7 +67,7 @@ TEST(commonMacroSubstitute, simple) */ TEST(commonMacroSubstitute, withRealloc) { - Entity en("E1", "T1", "false"); + Entity en("E1", "", "T1", ""); ContextAttribute* caP = new ContextAttribute("A1", "T1", "attr1"); bool b; @@ -92,8 +92,8 @@ TEST(commonMacroSubstitute, withRealloc) std::string result; ExprContextObject exprContext(true); - exprContext.add("id", en.id); - exprContext.add("type", en.type); + exprContext.add("id", en.entityId.id); + exprContext.add("type", en.entityId.type); exprContext.add(caP->name, caP->stringValue); b = macroSubstitute(&result, s1, &exprContext, "", true); @@ -112,7 +112,7 @@ TEST(commonMacroSubstitute, withRealloc) TEST(commonMacroSubstitute, bufferTooBigInitially) { bool b; - Entity en("EntityId000001", "EntityType000001", "false"); + Entity en("EntityId000001", "", "EntityType000001", ""); ContextAttribute* caP = new ContextAttribute("A1", "T1", "attr1"); en.attributeVector.push_back(caP); @@ -127,8 +127,8 @@ TEST(commonMacroSubstitute, bufferTooBigInitially) std::string result; ExprContextObject exprContext; - exprContext.add("id", en.id); - exprContext.add("type", en.type); + exprContext.add("id", en.entityId.id); + exprContext.add("type", en.entityId.type); exprContext.add(caP->name, caP->stringValue); b = macroSubstitute(&result, s1, &exprContext, "", true); @@ -152,7 +152,7 @@ TEST(commonMacroSubstitute, bufferTooBigInitially) TEST(commonMacroSubstitute, bufferTooBigAfterSubstitution) { bool b; - Entity en("EntityId000001", "EntityType000001", "false"); + Entity en("EntityId000001", "", "EntityType000001", ""); ContextAttribute* caP = new ContextAttribute("A1", "T1", "attr1"); en.attributeVector.push_back(caP); @@ -168,8 +168,8 @@ TEST(commonMacroSubstitute, bufferTooBigAfterSubstitution) std::string result; ExprContextObject exprContext(true); - exprContext.add("id", en.id); - exprContext.add("type", en.type); + exprContext.add("id", en.entityId.id); + exprContext.add("type", en.entityId.type); exprContext.add(caP->name, caP->stringValue); b = macroSubstitute(&result, s1, &exprContext, "", true); diff --git a/test/unittests/common/commonString_test.cpp b/test/unittests/common/commonString_test.cpp index da128b51d9..3e90b1b1e9 100644 --- a/test/unittests/common/commonString_test.cpp +++ b/test/unittests/common/commonString_test.cpp @@ -307,18 +307,7 @@ TEST(string, parseEmptyUrl) EXPECT_FALSE(result) << "wrong result (shall be false)"; } -/* **************************************************************************** -* -* i2s - -*/ -TEST(commonString, i2s) -{ - char ph[32]; - char* p; - p = i2s(19, ph, sizeof(ph)); - EXPECT_STREQ("19", p); -} /* **************************************************************************** * diff --git a/test/unittests/common/commonTag_test.cpp b/test/unittests/common/commonTag_test.cpp deleted file mode 100644 index ff0ab05489..0000000000 --- a/test/unittests/common/commonTag_test.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include "gtest/gtest.h" - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" -#include "common/tag.h" - - -/* **************************************************************************** -* -* startTag - -*/ -TEST(commonTag, startTag) -{ - std::string tag = "TAG"; - std::string out; - - out = startTag(tag, false); - EXPECT_EQ("\"TAG\":{", out); - - out = startTag(tag, true); - EXPECT_EQ("\"TAG\":[", out); - - out = startTag(); - EXPECT_EQ("{", out); -} - - - -/* **************************************************************************** -* -* endTag - -*/ -TEST(commonTag, endTag) -{ - std::string json = "}"; - std::string out; - - out = endTag(); - EXPECT_EQ(json, out); -} - - - -/* **************************************************************************** -* -* valueTag - -*/ -TEST(commonTag, valueTag) -{ - std::string tag = "TAG"; - std::string value = "tag"; - std::string jsonComma = "\"TAG\":\"tag\","; - std::string jsonNoComma = "\"TAG\":\"tag\""; - std::string integerJsonNoComma = "\"TAG\":\"8\""; - std::string stringJsonComma = "\"TAG\":\"8\","; - std::string stringJsonNoComma = "\"TAG\":\"8\""; - std::string out; - - out = valueTag(tag, value); - EXPECT_EQ(jsonNoComma, out); - - out = valueTag(tag, value, true); - EXPECT_EQ(jsonComma, out); - - out = valueTag(tag, value); - EXPECT_EQ(jsonNoComma, out); - - out = valueTag(tag, 8, false); - EXPECT_EQ(integerJsonNoComma, out); - - out = valueTag(tag, "8", true, false); - EXPECT_EQ(stringJsonComma, out); - - out = valueTag(tag, "8", false, false); - EXPECT_EQ(stringJsonNoComma, out); -} diff --git a/test/unittests/convenience/AppendContextElementRequest_test.cpp b/test/unittests/convenience/AppendContextElementRequest_test.cpp deleted file mode 100644 index fc7cc9fe5f..0000000000 --- a/test/unittests/convenience/AppendContextElementRequest_test.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/MimeType.h" -#include "convenience/AppendContextElementRequest.h" -#include "ngsi/Metadata.h" -#include "rest/ConnectionInfo.h" - -#include "unittest.h" - - - -/* **************************************************************************** -* -* render_json - -*/ -TEST(AppendContextElementRequest, render_json) -{ - AppendContextElementRequest acer; - std::string out; - ContextAttribute ca("caName", "caType", "121"); - const char* outfile = "ngsi10.appendContextElementRequest.adn.valid.json"; - - - utInit(); - - acer.contextAttributeVector.push_back(&ca); - - out = acer.toJsonV1(false, UpdateContext); - - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile)) << "Error getting test data from '" << outfile << "'"; - EXPECT_STREQ(expectedBuf, out.c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* check_json - -*/ -TEST(AppendContextElementRequest, check_json) -{ - AppendContextElementRequest acer; - std::string out; - ContextAttribute ca("caName", "caType", "121"); - const char* outfile1 = "ngsi10.appendContextElementResponse.predetectedError.valid.json"; - const char* outfile2 = "ngsi10.appendContextElementResponse.missingAttributeName.valid.json"; - - utInit(); - - acer.contextAttributeVector.push_back(&ca); - - // 1. ok - out = acer.check(V1, false, AppendContextElement, ""); - EXPECT_STREQ("OK", out.c_str()); - - - // 2. Predetected error - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'"; - out = acer.check(V1, false, AppendContextElement, "Error is predetected"); - EXPECT_STREQ(expectedBuf, out.c_str()); - - - // 3. bad ContextAttribute - ContextAttribute ca2("", "caType", "121"); - - acer.contextAttributeVector.push_back(&ca2); - out = acer.check(V1, false, AppendContextElement, ""); - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile2)) << "Error getting test data from '" << outfile2 << "'"; - EXPECT_STREQ(expectedBuf, out.c_str()); - ca2.name = "ca2Name"; - - utExit(); -} - - - -/* **************************************************************************** -* -* release - just exercise the code -*/ -TEST(AppendContextElementRequest, release) -{ - AppendContextElementRequest acer; - std::string out; - ContextAttribute* caP = new ContextAttribute("caName", "caType", "121"); - - acer.contextAttributeVector.push_back(caP); - - acer.release(); -} diff --git a/test/unittests/convenience/AppendContextElementResponse_test.cpp b/test/unittests/convenience/AppendContextElementResponse_test.cpp deleted file mode 100644 index 83620f9477..0000000000 --- a/test/unittests/convenience/AppendContextElementResponse_test.cpp +++ /dev/null @@ -1,126 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include "gtest/gtest.h" - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/MimeType.h" -#include "convenience/AppendContextElementResponse.h" -#include "rest/ConnectionInfo.h" - -#include "unittest.h" - - - -/* **************************************************************************** -* -* render_json - -*/ -TEST(AppendContextElementResponse, render_json) -{ - AppendContextElementResponse acer; - ContextAttributeResponse car; - std::string out; - const char* outfile1 = "ngsi10.appendContextElementResponse.empty.valid.json"; - const char* outfile2 = "ngsi10.appendContextElementResponse.badRequest.valid.json"; - - utInit(); - - // 1. empty acer - out = acer.toJsonV1(false, AppendContextElement); - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'"; - EXPECT_STREQ(expectedBuf, out.c_str()); - - // 2. errorCode 'active' - acer.errorCode.fill(SccBadRequest, "very bad request"); - out = acer.toJsonV1(false, AppendContextElement); - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile2)) << "Error getting test data from '" << outfile2 << "'"; - EXPECT_STREQ(expectedBuf, out.c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* check_json - -*/ -TEST(AppendContextElementResponse, check_json) -{ - AppendContextElementResponse acer; - ContextAttributeResponse car; - ContextAttribute ca("", "TYPE", "VALUE"); // empty name, thus provoking error - std::string out; - const char* outfile1 = "ngsi10.appendContextElementRequest.check1.postponed.json"; - const char* outfile2 = "ngsi10.appendContextElementRequest.check2.postponed.json"; - - utInit(); - - // 1. predetected error - out = acer.check(V1, false, IndividualContextEntity, "PRE ERR"); - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'"; - EXPECT_STREQ(expectedBuf, out.c_str()); - - // 2. bad contextAttributeResponseVector - car.contextAttributeVector.push_back(&ca); - acer.contextAttributeResponseVector.push_back(&car); - out = acer.check(V1, false, IndividualContextEntity, ""); - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile2)) << "Error getting test data from '" << outfile2 << "'"; - EXPECT_STREQ(expectedBuf, out.c_str()); - - // 3. OK - ca.name = "NAME"; - out = acer.check(V1, false, IndividualContextEntity, ""); - EXPECT_EQ("OK", out); - - utExit(); -} - - - -/* **************************************************************************** -* -* release - -*/ -TEST(AppendContextElementResponse, release) -{ - AppendContextElementResponse acer; - ContextAttributeResponse* carP = new ContextAttributeResponse(); - ContextAttribute* caP = new ContextAttribute("NAME", "TYPE", "VALUE"); - - utInit(); - - carP->contextAttributeVector.push_back(caP); - acer.contextAttributeResponseVector.push_back(carP); - - EXPECT_EQ(1, carP->contextAttributeVector.size()); - EXPECT_EQ(1, acer.contextAttributeResponseVector.size()); - acer.release(); - EXPECT_EQ(0, acer.contextAttributeResponseVector.size()); - - utExit(); -} diff --git a/test/unittests/convenience/ContextAttributeResponseVector_test.cpp b/test/unittests/convenience/ContextAttributeResponseVector_test.cpp deleted file mode 100644 index 952fac78b0..0000000000 --- a/test/unittests/convenience/ContextAttributeResponseVector_test.cpp +++ /dev/null @@ -1,141 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include "gtest/gtest.h" - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/MimeType.h" -#include "convenience/ContextAttributeResponseVector.h" -#include "convenience/ContextAttributeResponse.h" -#include "ngsi/ContextAttribute.h" -#include "rest/ConnectionInfo.h" - -#include "unittest.h" - - - -/* **************************************************************************** -* -* render_json - -*/ -TEST(ContextAttributeResponseVector, render_json) -{ - ContextAttributeResponseVector carV; - ContextAttribute ca("caName", "caType", "caValue"); - ContextAttributeResponse car; - std::string out; - const char* outfile = "ngsi10.contextResponseList.render.invalid.json"; - - // 1. empty vector - car.statusCode.fill(SccBadRequest, "Empty Vector"); - out = carV.toJsonV1(false, ContextEntityAttributes); - EXPECT_STREQ("", out.c_str()); - - // 2. normal case - car.contextAttributeVector.push_back(&ca); - carV.push_back(&car); - - out = carV.toJsonV1(false, ContextEntityAttributes); - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile)) << "Error getting test data from '" << outfile << "'"; - EXPECT_STREQ(expectedBuf, out.c_str()); -} - - - -/* **************************************************************************** -* -* check_json - -*/ -TEST(ContextAttributeResponseVector, check_json) -{ - ContextAttributeResponseVector carV; - ContextAttribute ca("caName", "caType", "caValue"); - ContextAttributeResponse car; - std::string out; - const char* outfile1 = "ngsi10.contextAttributeResponse.check1.valid.json"; - const char* outfile2 = "ngsi10.contextAttributeResponse.check2.valid.json"; - - // 1. ok - car.contextAttributeVector.push_back(&ca); - carV.push_back(&car); - out = carV.check(V1, false, UpdateContextAttribute, ""); - EXPECT_STREQ("OK", out.c_str()); - - // 2. Predetected Error - out = carV.check(V1, false, UpdateContextAttribute, "PRE ERROR"); - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'"; - EXPECT_STREQ(expectedBuf, out.c_str()); - - // 3. Bad ContextAttribute - ContextAttribute ca2("", "caType", "caValue"); - - car.contextAttributeVector.push_back(&ca2); - out = carV.check(V1, false, UpdateContextAttribute, ""); - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile2)) << "Error getting test data from '" << outfile2 << "'"; - EXPECT_STREQ(expectedBuf, out.c_str()); -} - - - -/* **************************************************************************** -* -* getAndSize - -*/ -TEST(ContextAttributeResponseVector, getAndSize) -{ - ContextAttributeResponse car; - ContextAttribute ca("caName", "caType", "caValue"); - ContextAttributeResponseVector carV; - - car.contextAttributeVector.push_back(&ca); - - EXPECT_EQ(0, carV.size()); - carV.push_back(&car); - ASSERT_EQ(1, carV.size()); - - ContextAttributeResponse* carP = carV[0]; - EXPECT_TRUE(carP != NULL); -} - - - -/* **************************************************************************** -* -* release - just exercise the code -*/ -TEST(ContextAttributeResponseVector, release) -{ - ContextAttribute* caP = new ContextAttribute("caName", "caType", "caValue"); - ContextAttributeResponse* carP = new ContextAttributeResponse(); - ContextAttributeResponseVector carV; - - carP->contextAttributeVector.push_back(caP); - carP->statusCode.fill(SccOk); - - carV.push_back(carP); - - carV.release(); -} diff --git a/test/unittests/convenience/ContextAttributeResponse_test.cpp b/test/unittests/convenience/ContextAttributeResponse_test.cpp deleted file mode 100644 index e99ca03293..0000000000 --- a/test/unittests/convenience/ContextAttributeResponse_test.cpp +++ /dev/null @@ -1,119 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include "gtest/gtest.h" - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/MimeType.h" -#include "convenience/ContextAttributeResponse.h" -#include "rest/ConnectionInfo.h" - -#include "unittest.h" - - - -/* **************************************************************************** -* -* render_json - -*/ -TEST(ContextAttributeResponse, render_json) -{ - ContextAttribute ca("caName", "caType", "caValue"); - ContextAttributeResponse car; - std::string out; - - utInit(); - - car.contextAttributeVector.push_back(&ca); - car.statusCode.fill(SccOk, "OK"); - - out = car.toJsonV1(false, ContextEntityAttributes); - - utExit(); -} - - - -/* **************************************************************************** -* -* check_json - -*/ -TEST(ContextAttributeResponse, check_json) -{ - ContextAttribute ca("caName", "caType", "caValue"); - ContextAttributeResponse car; - std::string out; - const char* outfile1 = "ngsi10.contextAttributeResponse.check3.valid.json"; - const char* outfile2 = "ngsi10.contextAttributeResponse.check4.valid.json"; - - utInit(); - - // 1. OK - car.contextAttributeVector.push_back(&ca); - car.statusCode.fill(SccOk, "OK"); - - out = car.check(V1, false, UpdateContextAttribute, ""); - EXPECT_STREQ("OK", out.c_str()); - - - // 2. predetectedError - out = car.check(V1, false, UpdateContextAttribute, "PRE Error"); - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'"; - EXPECT_STREQ(expectedBuf, out.c_str()); - - - // 3. Bad ContextAttribute - ContextAttribute ca2("", "caType", "caValue"); - car.contextAttributeVector.push_back(&ca2); - - LM_M(("car.contextAttributeVector.size: %d - calling ContextAttributeResponse::check", car.contextAttributeVector.size())); - out = car.check(V1, false, UpdateContextAttribute, ""); - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile2)) << "Error getting test data from '" << outfile2 << "'"; - EXPECT_STREQ(expectedBuf, out.c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* release - just exercise the code -*/ -TEST(ContextAttributeResponse, release) -{ - ContextAttribute* caP = new ContextAttribute("caName", "caType", "caValue"); - ContextAttributeResponse car; - - utInit(); - - car.contextAttributeVector.push_back(caP); - car.statusCode.fill(SccOk); - - car.release(); - - utExit(); -} diff --git a/test/unittests/convenience/Convenience_test.cpp b/test/unittests/convenience/Convenience_test.cpp deleted file mode 100644 index 37a5c67030..0000000000 --- a/test/unittests/convenience/Convenience_test.cpp +++ /dev/null @@ -1,181 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include "gtest/gtest.h" - -#include "unittest.h" - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "convenience/Convenience.h" - -#include "common/Timer.h" -#include "common/globals.h" - -#include "rest/RestService.h" -#include "rest/rest.h" -#include "serviceRoutines/getContextEntitiesByEntityId.h" -#include "serviceRoutines/badVerbGetOnly.h" - - - -/* **************************************************************************** -* -* getV - -*/ -RestService getV[] = -{ - { ContextEntitiesByEntityId, 3, { "ngsi9", "contextEntities", "*" }, getContextEntitiesByEntityId }, - { InvalidRequest, 0, { }, NULL } -}; - -RestService badVerbV[] = -{ - { ContextEntitiesByEntityId, 3, { "ngsi9", "contextEntities", "*" }, badVerbGetOnly }, - { InvalidRequest, 0, { }, NULL } -}; - - - -/* **************************************************************************** -* -* emptyPath - -*/ -TEST(Convenience, emptyPath) -{ - ConnectionInfo ci("", "GET", "1.1"); - std::string response; - std::string expected = "Empty URL"; - - utInit(); - - serviceVectorsSet(getV, NULL, NULL, NULL, NULL, NULL, badVerbV); - - response = orion::requestServe(&ci); - EXPECT_STREQ(expected.c_str(), response.c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* shortPath - -*/ -TEST(Convenience, shortPath) -{ - ConnectionInfo ci1("ngsi9", "GET", "1.1"); - ConnectionInfo ci2("ngsi10", "GET", "1.1"); - ConnectionInfo ci3("ngsi8", "GET", "1.1"); - ConnectionInfo ci4("ngsi10/nada", "GET", "1.1"); - std::string out; - const char* outfile = "ngsi.unrecognizedRequest.json"; - RestService restService1 = { InvalidRequest, 1, { "ngsi10" }, NULL }; - RestService restService2 = { InvalidRequest, 1, { "ngsi9" }, NULL }; - RestService restService3 = { InvalidRequest, 1, { "ngsi8" }, NULL }; - RestService restService4 = { InvalidRequest, 2, { "ngsi10", "json" }, NULL }; - - utInit(); - - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile)) << "Error getting test data from '" << outfile << "'"; - - serviceVectorsSet(getV, NULL, NULL, NULL, NULL, NULL, badVerbV); - - ci1.apiVersion = V1; - ci1.restServiceP = &restService1; - out = orion::requestServe(&ci1); - EXPECT_STREQ(expectedBuf, out.c_str()); - - ci2.apiVersion = V1; - ci2.restServiceP = &restService2; - out = orion::requestServe(&ci2); - EXPECT_STREQ(expectedBuf, out.c_str()); - - ci3.apiVersion = V1; - ci3.restServiceP = &restService3; - out = orion::requestServe(&ci3); - EXPECT_STREQ(expectedBuf, out.c_str()); - - ci4.apiVersion = V1; - ci4.restServiceP = &restService4; - out = orion::requestServe(&ci4); - EXPECT_STREQ(expectedBuf, out.c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* badPathNgsi9 - -*/ -TEST(Convenience, badPathNgsi9) -{ - ConnectionInfo ci("ngsi9/badpathcomponent", "GET", "1.1"); - std::string out; - const char* outfile = "ngsi.unrecognizedRequest.json"; - RestService restService = { InvalidRequest, 2, { "ngsi9", "badpathcomponent" }, NULL }; - - utInit(); - - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile)) << "Error getting test data from '" << outfile << "'"; - - serviceVectorsSet(getV, NULL, NULL, NULL, NULL, NULL, badVerbV); - - ci.apiVersion = V1; - ci.restServiceP = &restService; - out = orion::requestServe(&ci); - EXPECT_STREQ(expectedBuf, out.c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* badPathNgsi10 - -*/ -TEST(Convenience, badPathNgsi10) -{ - ConnectionInfo ci("ngsi10/badpathcomponent", "GET", "1.1"); - std::string out; - const char* outfile = "ngsi.unrecognizedRequest.json"; - RestService restService = { InvalidRequest, 2, { "ngsi10", "badpathcomponent" }, NULL }; - - utInit(); - - serviceVectorsSet(getV, NULL, NULL, NULL, NULL, NULL, badVerbV); - - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile)) << "Error getting test data from '" << outfile << "'"; - ci.apiVersion = V1; - ci.restServiceP = &restService; - out = orion::requestServe(&ci); - EXPECT_STREQ(expectedBuf, out.c_str()); - - utExit(); -} diff --git a/test/unittests/convenience/RegisterProviderRequest_test.cpp b/test/unittests/convenience/RegisterProviderRequest_test.cpp deleted file mode 100644 index 12c49bbf12..0000000000 --- a/test/unittests/convenience/RegisterProviderRequest_test.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include "gtest/gtest.h" - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/globals.h" -#include "convenience/RegisterProviderRequest.h" -#include "jsonParse/jsonRequest.h" -#include "ngsi/ParseData.h" -#include "rest/ConnectionInfo.h" -#include "jsonParse/jsonRequest.h" -#include "jsonParse/jsonRegisterProviderRequest.h" - -#include "testDataFromFile.h" - - - -/* **************************************************************************** -* -* json_ok - -*/ -TEST(RegisterProviderRequest, json_ok) -{ - // FIXME P2: gap in outFile - ParseData reqData; - const char* inFile1 = "ngsi9.registerProviderRequest.noRegistrationId.valid.json"; - const char* inFile2 = "ngsi9.registerProviderRequest.ok.valid.json"; - const char* outFile1 = "ngsi9.registerProviderRequestRendered.noRegistrationId.valid.json"; - const char* outFile3 = "ngsi9.registerProviderRequest.predetectedError.valid.json"; - const char* outFile4 = "ngsi9.registerProviderRequestRendered.ok.valid.json"; - std::string result; - std::string rendered; - std::string checked; - ConnectionInfo ci("", "POST", "1.1"); - - - // 1. Normal registerProviderRequest - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile1)) << "Error getting test data from '" << inFile1 << "'"; - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outFile1)) << "Error getting test data from '" << outFile1 << "'"; - - result = jsonTreat(testBuf, &ci, &reqData, ContextEntitiesByEntityId, NULL); - EXPECT_EQ("OK", result) << "this test should be OK"; - - rendered = reqData.rpr.res.toJsonV1(); - EXPECT_STREQ(expectedBuf, rendered.c_str()); - - - // 3. sending a 'predetected error' to the check function - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outFile3)) << "Error getting test data from '" << outFile3 << "'"; - - checked = reqData.rpr.res.check(V1, DiscoverContextAvailability, "forced predetectedError"); - EXPECT_STREQ(expectedBuf, checked.c_str()); - - - // 4. Second file - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile2)) << "Error getting test data from '" << inFile2 << "'"; - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outFile4)) << "Error getting test data from '" << outFile4 << "'"; - - result = jsonTreat(testBuf, &ci, &reqData, ContextEntitiesByEntityId, NULL); - EXPECT_EQ("OK", result); - rendered = reqData.rpr.res.toJsonV1(); - EXPECT_STREQ(expectedBuf, rendered.c_str()); -} diff --git a/test/unittests/convenience/UpdateContextAttributeRequest_test.cpp b/test/unittests/convenience/UpdateContextAttributeRequest_test.cpp deleted file mode 100644 index 8f8cb83aca..0000000000 --- a/test/unittests/convenience/UpdateContextAttributeRequest_test.cpp +++ /dev/null @@ -1,118 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "convenience/UpdateContextAttributeRequest.h" -#include "convenience/ContextAttributeResponseVector.h" - -#include "unittest.h" - - - -/* **************************************************************************** -* -* render_json - -*/ -TEST(UpdateContextAttributeRequest, render_json) -{ - UpdateContextAttributeRequest ucar; - Metadata mdata("name", "type", "value"); - std::string out; - const char* outfile = "ngsi10.updateContextAttributeRequest.render.valid.json"; - - utInit(); - - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile)) << "Error getting test data from '" << outfile << "'"; - - ucar.type = "TYPE"; - ucar.contextValue = "Context Value"; - - ucar.metadataVector.push_back(&mdata); - out = ucar.toJsonV1(); - EXPECT_STREQ(expectedBuf, out.c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* check_json - -*/ -TEST(UpdateContextAttributeRequest, check_json) -{ - UpdateContextAttributeRequest ucar; - Metadata mdata("name", "type", "value"); - Metadata mdata2("", "type", "value"); - std::string out; - const char* outfile1 = "ngsi10.updateContextAttributeRequest.check1.valid.json"; - const char* outfile2 = "ngsi10.updateContextAttributeRequest.check3.valid.json"; - - utInit(); - - ucar.metadataVector.push_back(&mdata); - - // 1. predetectedError - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'"; - out = ucar.check(V1, "PRE Error"); - EXPECT_STREQ(expectedBuf, out.c_str()); - - - // 2. empty contextValue - out = ucar.check(V1, ""); - EXPECT_STREQ("OK", out.c_str()); - - // 3. OK - ucar.contextValue = "CValue"; - out = ucar.check(V1,""); - EXPECT_STREQ("OK", out.c_str()); - - // 4. bad metadata - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile2)) << "Error getting test data from '" << outfile2 << "'"; - ucar.metadataVector.push_back(&mdata2); - out = ucar.check(V1, ""); - EXPECT_STREQ(expectedBuf, out.c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* release - -*/ -TEST(UpdateContextAttributeRequest, release) -{ - UpdateContextAttributeRequest ucar; - Metadata* mdataP = new Metadata("name", "type", "value"); - - ucar.metadataVector.push_back(mdataP); - ASSERT_EQ(1, ucar.metadataVector.size()); - ucar.release(); - EXPECT_EQ(0, ucar.metadataVector.size()); -} diff --git a/test/unittests/convenience/UpdateContextElementRequest_test.cpp b/test/unittests/convenience/UpdateContextElementRequest_test.cpp deleted file mode 100644 index 7c4c743f21..0000000000 --- a/test/unittests/convenience/UpdateContextElementRequest_test.cpp +++ /dev/null @@ -1,115 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include "gtest/gtest.h" - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "convenience/UpdateContextElementRequest.h" -#include "convenience/ContextAttributeResponseVector.h" -#include "rest/ConnectionInfo.h" - -#include "unittest.h" - - - -/* **************************************************************************** -* -* render_json - -*/ -TEST(UpdateContextElementRequest, render_json) -{ - UpdateContextElementRequest ucer; - ContextAttribute ca("caName", "caType", "caValue"); - std::string out; - const char* outfile = "ngsi10.updateContextElementRequest.render.valid.json"; - - utInit(); - - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile)) << "Error getting test data from '" << outfile << "'"; - - // Just the normal case - ucer.contextAttributeVector.push_back(&ca); - - out = ucer.toJsonV1(false, UpdateContext); - EXPECT_STREQ(expectedBuf, out.c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* check_json - -*/ -TEST(UpdateContextElementRequest, check_json) -{ - UpdateContextElementRequest ucer; - ContextAttribute ca("caName", "caType", "caValue"); - std::string out; - const char* outfile1 = "ngsi10.updateContextElementRequest.check1.valid.json"; - const char* outfile2 = "ngsi10.updateContextElementRequest.check2.valid.json"; - - utInit(); - - // 1. predetectedError - ucer.contextAttributeVector.push_back(&ca); - out = ucer.check(V1, false, UpdateContextElement, "PRE Error"); - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'"; - EXPECT_STREQ(expectedBuf, out.c_str()); - - // 2. ok - out = ucer.check(V1, false, UpdateContextElement, ""); - EXPECT_STREQ("OK", out.c_str()); - - // 3. bad contextAttributeVector - ContextAttribute ca2("", "caType", "caValue"); - ucer.contextAttributeVector.push_back(&ca2); - out = ucer.check(V1, false, UpdateContextElement, ""); - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile2)) << "Error getting test data from '" << outfile2 << "'"; - EXPECT_STREQ(expectedBuf, out.c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* release - -*/ -TEST(UpdateContextElementRequest, release) -{ - UpdateContextElementRequest ucer; - ContextAttribute* caP = new ContextAttribute("caName", "caType", "caValue"); - - ucer.contextAttributeVector.push_back(caP); - - ASSERT_EQ(1, ucer.contextAttributeVector.size()); - - ucer.release(); - EXPECT_EQ(0, ucer.contextAttributeVector.size()); -} diff --git a/test/unittests/convenience/UpdateContextElementResponse_test.cpp b/test/unittests/convenience/UpdateContextElementResponse_test.cpp deleted file mode 100644 index 1cfb9f5a04..0000000000 --- a/test/unittests/convenience/UpdateContextElementResponse_test.cpp +++ /dev/null @@ -1,91 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include "gtest/gtest.h" - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "convenience/UpdateContextElementResponse.h" -#include "convenience/ContextAttributeResponseVector.h" -#include "rest/ConnectionInfo.h" - -#include "unittest.h" - - - -/* **************************************************************************** -* -* render_json - -*/ -TEST(UpdateContextElementResponse, render_json) -{ - UpdateContextElementResponse ucer; - ContextAttributeResponse car; - ContextAttribute ca("caName", "caType", "caValue"); - std::string out; - const char* outfile = "ngsi10.updateContextElementResponse.ok.valid.json"; - - // Just the normal case - ucer.contextAttributeResponseVector.push_back(&car); - car.contextAttributeVector.push_back(&ca); - car.statusCode.fill(SccOk, "details"); - - out = ucer.toJsonV1(false, UpdateContext); - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile)) << "Error getting test data from '" << outfile << "'"; - EXPECT_STREQ(expectedBuf, out.c_str()); -} - - - -/* **************************************************************************** -* -* check_json - -*/ -TEST(UpdateContextElementResponse, check_json) -{ - UpdateContextElementResponse ucer; - ContextAttributeResponse car; - ContextAttribute ca("", "TYPE", "VALUE"); // empty name, thus provoking error - std::string out; - const char* outfile1 = "ngsi10.updateContextElementResponse.check1.valid.json"; - const char* outfile2 = "ngsi10.updateContextElementResponse.check2.valid.json"; - - // 1. predetected error - out = ucer.check(V1, false, IndividualContextEntity, "PRE ERR"); - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'"; - EXPECT_STREQ(expectedBuf, out.c_str()); - - // 2. bad contextAttributeResponseVector - car.contextAttributeVector.push_back(&ca); - ucer.contextAttributeResponseVector.push_back(&car); - out = ucer.check(V1, false, IndividualContextEntity, ""); - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile2)) << "Error getting test data from '" << outfile2 << "'"; - EXPECT_STREQ(expectedBuf, out.c_str()); - - // 3. OK - ca.name = "NAME"; - out = ucer.check(V1, false, IndividualContextEntity, ""); - EXPECT_EQ("OK", out); -} diff --git a/test/unittests/jsonParse/jsonRequest_test.cpp b/test/unittests/jsonParse/jsonRequest_test.cpp deleted file mode 100644 index 9b53eb7aad..0000000000 --- a/test/unittests/jsonParse/jsonRequest_test.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "jsonParse/jsonRequest.h" -#include "ngsi/ParseData.h" -#include "ngsi/Request.h" -#include "rest/ConnectionInfo.h" -#include "rest/RestService.h" - -#include "unittests/unittest.h" - - - -/* **************************************************************************** -* -* jsonTreat - -*/ -TEST(jsonRequest, jsonTreat) -{ - ConnectionInfo ci("/ngsi9/registerContext", "POST", "1.1"); - ParseData parseData; - std::string out; - const char* outfile1 = "orion.jsonRequest.jsonTreat.valid.json"; - RestService restService = { InvalidRequest, 2, { "ngsi9", "registerContext" }, NULL }; - - utInit(); - - ci.outMimeType = JSON; - ci.apiVersion = V1; - ci.restServiceP = &restService; - - out = jsonTreat("non-empty content", &ci, &parseData, InvalidRequest, NULL); - EXPECT_EQ("OK", testDataFromFile(expectedBuf, - sizeof(expectedBuf), - outfile1)) << "Error getting test data from '" << outfile1 << "'"; - - EXPECT_STREQ(expectedBuf, out.c_str()); - - out = jsonTreat("", &ci, &parseData, InvalidRequest, NULL); - EXPECT_STREQ("OK", out.c_str()); - - utExit(); -} diff --git a/test/unittests/main_UnitTest.cpp b/test/unittests/main_UnitTest.cpp index e003cb1fa9..2b4fd0d9f2 100644 --- a/test/unittests/main_UnitTest.cpp +++ b/test/unittests/main_UnitTest.cpp @@ -68,7 +68,6 @@ int subCacheInterval = 10; unsigned int cprForwardLimit = 1000; bool noCache = false; bool insecureNotif = false; -bool ngsiv1Autocast = false; char fwdHost[64]; char notificationMode[64]; char notifFlowControl[64]; @@ -145,7 +144,7 @@ int main(int argC, char** argV) paParse(paArgs, argC, (char**) argV, 1, false); LM_M(("Init tests")); - orionInit(exitFunction, orionUnitTestVersion, SemReadWriteOp, false, false, false, false, false); + orionInit(exitFunction, orionUnitTestVersion, SemReadWriteOp, false, false, false, false); // Note that multitenancy and mutex time stats are disabled for unit test mongo init mongoInit(dbURI, dbName, pwd, false, writeConcern, dbPoolSize, false); alarmMgr.init(false); diff --git a/test/unittests/mongoBackend/mongoContextProvidersUpdate_test.cpp b/test/unittests/mongoBackend/mongoContextProvidersUpdate_test.cpp index 3b26324cab..bbb211ac6f 100644 --- a/test/unittests/mongoBackend/mongoContextProvidersUpdate_test.cpp +++ b/test/unittests/mongoBackend/mongoContextProvidersUpdate_test.cpp @@ -33,7 +33,7 @@ #include "mongoBackend/MongoGlobal.h" #include "mongoBackend/mongoConnectionPool.h" #include "mongoBackend/mongoUpdateContext.h" -#include "ngsi/StatusCode.h" +#include "rest/OrionError.h" #include "ngsi/EntityId.h" #include "ngsi/Scope.h" #include "ngsi10/UpdateContextRequest.h" diff --git a/test/unittests/mongoBackend/mongoCreateSubscription_test.cpp b/test/unittests/mongoBackend/mongoCreateSubscription_test.cpp index 688b1e1b3c..9508d8e5c1 100644 --- a/test/unittests/mongoBackend/mongoCreateSubscription_test.cpp +++ b/test/unittests/mongoBackend/mongoCreateSubscription_test.cpp @@ -52,7 +52,6 @@ using mongo::BSONObj; using mongo::BSONArray; using mongo::OID; using ngsiv2::Subscription; -using ngsiv2::EntID; @@ -74,8 +73,8 @@ TEST(mongoCreateSubscriptions, createSubscriptionNotCustomOK) sub.throttling = 5; sub.attrsFormat = NGSI_V2_NORMALIZED; - EntID en1("E1", "", "T1", ""); - EntID en2("", "E.*", "T2", ""); + EntityId en1("E1", "", "T1", ""); + EntityId en2("", "E.*", "T2", ""); sub.subject.entities.push_back(en1); sub.subject.entities.push_back(en2); sub.subject.condition.attributes.push_back("A"); @@ -92,7 +91,7 @@ TEST(mongoCreateSubscriptions, createSubscriptionNotCustomOK) sub.notification.httpInfo.custom = false; /* Invoke the function in mongoBackend library */ - std::string result = mongoCreateSubscription(sub, &oe, "", servicePathVector, "", "", false, V2); + std::string result = mongoCreateSubscription(sub, &oe, "", servicePathVector, "", "", false); /* Check response is as expected */ EXPECT_EQ(SccNone, oe.code); @@ -165,8 +164,8 @@ TEST(mongoCreateSubscriptions, createSubscriptionCustomOK) sub.throttling = 5; sub.attrsFormat = NGSI_V2_NORMALIZED; - EntID en1("E1", "", "T1", ""); - EntID en2("", "E.*", "T2", ""); + EntityId en1("E1", "", "T1", ""); + EntityId en2("", "E.*", "T2", ""); sub.subject.entities.push_back(en1); sub.subject.entities.push_back(en2); sub.subject.condition.attributes.push_back("A"); @@ -189,7 +188,7 @@ TEST(mongoCreateSubscriptions, createSubscriptionCustomOK) sub.notification.httpInfo.payload = "Hey!"; /* Invoke the function in mongoBackend library */ - std::string result = mongoCreateSubscription(sub, &oe, "", servicePathVector, "", "", false, V2); + std::string result = mongoCreateSubscription(sub, &oe, "", servicePathVector, "", "", false); /* Check response is as expected */ EXPECT_EQ(SccNone, oe.code); diff --git a/test/unittests/mongoBackend/mongoDiscoverContextAvailability_test.cpp b/test/unittests/mongoBackend/mongoDiscoverContextAvailability_test.cpp index 09b6694682..e8904b8490 100644 --- a/test/unittests/mongoBackend/mongoDiscoverContextAvailability_test.cpp +++ b/test/unittests/mongoBackend/mongoDiscoverContextAvailability_test.cpp @@ -30,7 +30,7 @@ #include "mongoBackend/MongoGlobal.h" #include "mongoBackend/mongoConnectionPool.h" #include "mongoBackend/mongoDiscoverContextAvailability.h" -#include "ngsi/StatusCode.h" +#include "rest/OrionError.h" #include "ngsi/EntityId.h" #include "ngsi/Scope.h" #include "ngsi9/DiscoverContextAvailabilityRequest.h" diff --git a/test/unittests/mongoBackend/mongoGetSubscriptions_test.cpp b/test/unittests/mongoBackend/mongoGetSubscriptions_test.cpp index 07c0a6cbc0..26e3b79a14 100644 --- a/test/unittests/mongoBackend/mongoGetSubscriptions_test.cpp +++ b/test/unittests/mongoBackend/mongoGetSubscriptions_test.cpp @@ -53,7 +53,6 @@ using ::testing::_; using ::testing::Throw; using ::testing::Return; using ngsiv2::Subscription; -using ngsiv2::EntID; @@ -145,7 +144,7 @@ TEST(mongoListSubscriptions, getAllSubscriptionsV1Info) ASSERT_EQ(3, subs.size()); Subscription s; - std::vector ents; + std::vector ents; std::vector attrs; /* Subscription #1 */ @@ -247,7 +246,7 @@ TEST(mongoGetSubscription, getSubscription) EXPECT_EQ("OK", oe.error); EXPECT_EQ("", oe.description); - std::vector ents; + std::vector ents; std::vector attrs; /* Subscription #1 */ diff --git a/test/unittests/mongoBackend/mongoNotifyContext_test.cpp b/test/unittests/mongoBackend/mongoNotifyContext_test.cpp index 2c708f18ed..ae697b02fd 100644 --- a/test/unittests/mongoBackend/mongoNotifyContext_test.cpp +++ b/test/unittests/mongoBackend/mongoNotifyContext_test.cpp @@ -197,7 +197,7 @@ TEST(mongoNotifyContextRequest, Ent1Attr1) cerP->entity.fill("E1", "T1", "false"); ContextAttribute* caP = new ContextAttribute("A1", "TA1", "new_val"); cerP->entity.attributeVector.push_back(caP); - cerP->statusCode.fill(SccOk, ""); + cerP->error.fill(SccOk, ""); req.contextElementResponseVector.push_back(cerP); /* Invoke the function in mongoBackend library */ @@ -339,7 +339,7 @@ TEST(mongoNotifyContextRequest, Ent1AttrN) ContextAttribute* ca2P = new ContextAttribute("A2", "TA2", "new_val2"); cerP->entity.attributeVector.push_back(ca1P); cerP->entity.attributeVector.push_back(ca2P); - cerP->statusCode.fill(SccOk); + cerP->error.fill(SccOk); req.contextElementResponseVector.push_back(cerP); /* Invoke the function in mongoBackend library */ @@ -481,12 +481,12 @@ TEST(mongoNotifyContextRequest, EntNAttr1) cer1P->entity.fill("E1", "T1", "false"); ContextAttribute* ca1P = new ContextAttribute("A1", "TA1", "new_val"); cer1P->entity.attributeVector.push_back(ca1P); - cer1P->statusCode.fill(SccOk); + cer1P->error.fill(SccOk); req.contextElementResponseVector.push_back(cer1P); cer2P->entity.fill("E2", "T2", "false"); ContextAttribute* ca2P = new ContextAttribute("A3", "TA3", "new_val2"); cer2P->entity.attributeVector.push_back(ca2P); - cer2P->statusCode.fill(SccOk); + cer2P->error.fill(SccOk); req.contextElementResponseVector.push_back(cer2P); /* Invoke the function in mongoBackend library */ @@ -630,14 +630,14 @@ TEST(mongoNotifyContextRequest, EntNAttrN) ContextAttribute* ca2P = new ContextAttribute("A2", "TA2", "new_val2"); cer1P->entity.attributeVector.push_back(ca1P); cer1P->entity.attributeVector.push_back(ca2P); - cer1P->statusCode.fill(SccOk); + cer1P->error.fill(SccOk); req.contextElementResponseVector.push_back(cer1P); cer2P->entity.fill("E2", "T2", "false"); ContextAttribute* ca3P = new ContextAttribute("A3", "TA3", "new_val3"); ContextAttribute* ca4P = new ContextAttribute("A4", "TA4", "new_val4"); cer2P->entity.attributeVector.push_back(ca3P); cer2P->entity.attributeVector.push_back(ca4P); - cer2P->statusCode.fill(SccOk); + cer2P->error.fill(SccOk); req.contextElementResponseVector.push_back(cer2P); /* Invoke the function in mongoBackend library */ @@ -777,7 +777,7 @@ TEST(mongoNotifyContextRequest, createEntity) cerP->entity.fill("E10", "T10", "false"); ContextAttribute* caP = new ContextAttribute("A1", "TA1", "new_val"); cerP->entity.attributeVector.push_back(caP); - cerP->statusCode.fill(SccOk); + cerP->error.fill(SccOk); req.contextElementResponseVector.push_back(cerP); /* Invoke the function in mongoBackend library */ diff --git a/test/unittests/mongoBackend/mongoQueryContextGeo_test.cpp b/test/unittests/mongoBackend/mongoQueryContextGeo_test.cpp index ea10ab7dc8..ebab55e50c 100644 --- a/test/unittests/mongoBackend/mongoQueryContextGeo_test.cpp +++ b/test/unittests/mongoBackend/mongoQueryContextGeo_test.cpp @@ -58,10 +58,6 @@ extern void setMongoConnectionForUnitTest(orion::DBClientBase _connection); * * Tests * -* -* - queryGeoCircleIn1 -* - queryGeoCircleIn2 -* - queryGeoCircleOut * - queryGeoPolygonIn1 * - queryGeoPolygonIn2 * - queryGeoPolygonIn3 @@ -167,286 +163,6 @@ int getEntityIndex(ContextElementResponseVector& v, const std::string& id) -/* **************************************************************************** -* -* queryGeoCircleIn1 - -* -* Area: 14 km circle centered in Madrid -* Result: Madrid, Alcobendas -* -*/ -TEST(mongoQueryContextGeoRequest, queryGeoCircleIn1) -{ - utInit(); - - HttpStatusCode ms; - QueryContextRequest req; - QueryContextResponse res; - - /* Prepare database */ - prepareDatabase(); - - /* Forge the request (from "inside" to "outside") */ - EntityId en(".*", "City", "true"); - req.entityIdVector.push_back(&en); - - /* Define area scope */ - Scope sc; - sc.type = "FIWARE::Location"; - sc.areaType = orion::CircleType; - sc.circle.center.latitudeSet("40.418889"); - sc.circle.center.longitudeSet("-3.691944"); - sc.circle.radiusSet("13600"); - req.restriction.scopeVector.push_back(&sc); - - /* Invoke the function in mongoBackend library */ - ms = mongoQueryContext(&req, &res, "", servicePathVector, uriParams, options); - - /* Check response is as expected */ - EXPECT_EQ(SccOk, ms); - - EXPECT_EQ(0, res.errorCode.code); - EXPECT_EQ(0, res.errorCode.reasonPhrase.size()); - EXPECT_EQ(0, res.errorCode.details.size()); - - ASSERT_EQ(2, res.contextElementResponseVector.size()); - int i; - - /* Context Element response # 1 */ - i = getEntityIndex(res.contextElementResponseVector, "Madrid"); - ASSERT_GE(i, 0); - EXPECT_EQ("Madrid", RES_CER(i).id); - EXPECT_EQ("City", RES_CER(i).type); - EXPECT_EQ("false", RES_CER(i).isPattern); - ASSERT_EQ(2, RES_CER(i).attributeVector.size()); - EXPECT_EQ("foo", RES_CER_ATTR(i, 0)->name); - EXPECT_EQ("string", RES_CER_ATTR(i, 0)->type); - EXPECT_EQ("attr_Mad", RES_CER_ATTR(i, 0)->stringValue); - EXPECT_EQ("pos", RES_CER_ATTR(i, 1)->name); - EXPECT_EQ("location", RES_CER_ATTR(i, 1)->type); - EXPECT_EQ("40.418889, -3.691944", RES_CER_ATTR(i, 1)->stringValue); - ASSERT_EQ(1, RES_CER_ATTR(i, 1)->metadataVector.size()); - EXPECT_EQ("location", RES_CER_ATTR(i, 1)->metadataVector[0]->name); - EXPECT_EQ("string", RES_CER_ATTR(i, 1)->metadataVector[0]->type); - EXPECT_EQ("WGS84", RES_CER_ATTR(i, 1)->metadataVector[0]->stringValue); - EXPECT_EQ(SccOk, RES_CER_STATUS(i).code); - EXPECT_EQ("OK", RES_CER_STATUS(i).reasonPhrase); - EXPECT_EQ(0, RES_CER_STATUS(i).details.size()); - - /* Context Element response # 2 */ - i = getEntityIndex(res.contextElementResponseVector, "Leganes"); - ASSERT_GE(i, 0); - EXPECT_EQ("Leganes", RES_CER(i).id); - EXPECT_EQ("City", RES_CER(i).type); - EXPECT_EQ("false", RES_CER(i).isPattern); - ASSERT_EQ(2, RES_CER(i).attributeVector.size()); - EXPECT_EQ("foo", RES_CER_ATTR(i, 0)->name); - EXPECT_EQ("string", RES_CER_ATTR(i, 0)->type); - EXPECT_EQ("attr_Leg", RES_CER_ATTR(i, 0)->stringValue); - EXPECT_EQ("pos", RES_CER_ATTR(i, 1)->name); - EXPECT_EQ("location", RES_CER_ATTR(i, 1)->type); - EXPECT_EQ("40.316667, -3.75", RES_CER_ATTR(i, 1)->stringValue); - ASSERT_EQ(1, RES_CER_ATTR(i, 1)->metadataVector.size()); - EXPECT_EQ("location", RES_CER_ATTR(i, 1)->metadataVector[0]->name); - EXPECT_EQ("string", RES_CER_ATTR(i, 1)->metadataVector[0]->type); - EXPECT_EQ("WGS84", RES_CER_ATTR(i, 1)->metadataVector[0]->stringValue); - EXPECT_EQ(SccOk, RES_CER_STATUS(i).code); - EXPECT_EQ("OK", RES_CER_STATUS(i).reasonPhrase); - EXPECT_EQ(0, RES_CER_STATUS(i).details.size()); - - /* Release dynamic memory used by response (mongoBackend allocates it) */ - res.contextElementResponseVector.release(); - - utExit(); -} - -/* **************************************************************************** -* -* queryGeoCircleIn2 - -* -* Area: 15 km circle centered in Madrid -* Result: Madrid, Alcobendas, Leganes -* -*/ -TEST(mongoQueryContextGeoRequest, queryGeoCircleIn2) -{ - utInit(); - - HttpStatusCode ms; - QueryContextRequest req; - QueryContextResponse res; - - /* Prepare database */ - prepareDatabase(); - - /* Forge the request (from "inside" to "outside") */ - EntityId en(".*", "City", "true"); - req.entityIdVector.push_back(&en); - - /* Define area scope */ - Scope sc; - sc.type = "FIWARE::Location"; - sc.areaType = orion::CircleType; - sc.circle.center.latitudeSet("40.418889"); - sc.circle.center.longitudeSet("-3.691944"); - sc.circle.radiusSet("15000"); - req.restriction.scopeVector.push_back(&sc); - - /* Invoke the function in mongoBackend library */ - ms = mongoQueryContext(&req, &res, "", servicePathVector, uriParams, options); - - /* Check response is as expected */ - EXPECT_EQ(SccOk, ms); - - EXPECT_EQ(0, res.errorCode.code); - EXPECT_EQ(0, res.errorCode.reasonPhrase.size()); - EXPECT_EQ(0, res.errorCode.details.size()); - - ASSERT_EQ(3, res.contextElementResponseVector.size()); - int i; - /* Context Element response # 1 */ - - i = getEntityIndex(res.contextElementResponseVector, "Madrid"); - ASSERT_GE(i, 0); - EXPECT_EQ("Madrid", RES_CER(i).id); - EXPECT_EQ("City", RES_CER(i).type); - EXPECT_EQ("false", RES_CER(i).isPattern); - ASSERT_EQ(2, RES_CER(i).attributeVector.size()); - EXPECT_EQ("foo", RES_CER_ATTR(i, 0)->name); - EXPECT_EQ("string", RES_CER_ATTR(i, 0)->type); - EXPECT_EQ("attr_Mad", RES_CER_ATTR(i, 0)->stringValue); - EXPECT_EQ("pos", RES_CER_ATTR(i, 1)->name); - EXPECT_EQ("location", RES_CER_ATTR(i, 1)->type); - EXPECT_EQ("40.418889, -3.691944", RES_CER_ATTR(i, 1)->stringValue); - ASSERT_EQ(1, RES_CER_ATTR(i, 1)->metadataVector.size()); - EXPECT_EQ("location", RES_CER_ATTR(i, 1)->metadataVector[0]->name); - EXPECT_EQ("string", RES_CER_ATTR(i, 1)->metadataVector[0]->type); - EXPECT_EQ("WGS84", RES_CER_ATTR(i, 1)->metadataVector[0]->stringValue); - EXPECT_EQ(SccOk, RES_CER_STATUS(i).code); - EXPECT_EQ("OK", RES_CER_STATUS(i).reasonPhrase); - EXPECT_EQ(0, RES_CER_STATUS(i).details.size()); - - /* Context Element response # 2 */ - i = getEntityIndex(res.contextElementResponseVector, "Alcobendas"); - ASSERT_GE(i, 0); - EXPECT_EQ("Alcobendas", RES_CER(i).id); - EXPECT_EQ("City", RES_CER(i).type); - EXPECT_EQ("false", RES_CER(i).isPattern); - ASSERT_EQ(2, RES_CER(i).attributeVector.size()); - EXPECT_EQ("foo", RES_CER_ATTR(i, 0)->name); - EXPECT_EQ("string", RES_CER_ATTR(i, 0)->type); - EXPECT_EQ("attr_Alc", RES_CER_ATTR(i, 0)->stringValue); - EXPECT_EQ("pos", RES_CER_ATTR(i, 1)->name); - EXPECT_EQ("location", RES_CER_ATTR(i, 1)->type); - EXPECT_EQ("40.533333, -3.633333", RES_CER_ATTR(i, 1)->stringValue); - ASSERT_EQ(1, RES_CER_ATTR(i, 1)->metadataVector.size()); - EXPECT_EQ("location", RES_CER_ATTR(i, 1)->metadataVector[0]->name); - EXPECT_EQ("string", RES_CER_ATTR(i, 1)->metadataVector[0]->type); - EXPECT_EQ("WGS84", RES_CER_ATTR(i, 1)->metadataVector[0]->stringValue); - EXPECT_EQ(SccOk, RES_CER_STATUS(i).code); - EXPECT_EQ("OK", RES_CER_STATUS(i).reasonPhrase); - EXPECT_EQ(0, RES_CER_STATUS(i).details.size()); - - /* Context Element response # 3 */ - i = getEntityIndex(res.contextElementResponseVector, "Leganes"); - ASSERT_GE(i, 0); - EXPECT_EQ("Leganes", RES_CER(i).id); - EXPECT_EQ("City", RES_CER(i).type); - EXPECT_EQ("false", RES_CER(i).isPattern); - ASSERT_EQ(2, RES_CER(i).attributeVector.size()); - EXPECT_EQ("foo", RES_CER_ATTR(i, 0)->name); - EXPECT_EQ("string", RES_CER_ATTR(i, 0)->type); - EXPECT_EQ("attr_Leg", RES_CER_ATTR(i, 0)->stringValue); - EXPECT_EQ("pos", RES_CER_ATTR(i, 1)->name); - EXPECT_EQ("location", RES_CER_ATTR(i, 1)->type); - EXPECT_EQ("40.316667, -3.75", RES_CER_ATTR(i, 1)->stringValue); - ASSERT_EQ(1, RES_CER_ATTR(i, 1)->metadataVector.size()); - EXPECT_EQ("location", RES_CER_ATTR(i, 1)->metadataVector[0]->name); - EXPECT_EQ("string", RES_CER_ATTR(i, 1)->metadataVector[0]->type); - EXPECT_EQ("WGS84", RES_CER_ATTR(i, 1)->metadataVector[0]->stringValue); - EXPECT_EQ(SccOk, RES_CER_STATUS(i).code); - EXPECT_EQ("OK", RES_CER_STATUS(i).reasonPhrase); - EXPECT_EQ(0, RES_CER_STATUS(i).details.size()); - - /* Release dynamic memory used by response (mongoBackend allocates it) */ - res.contextElementResponseVector.release(); - - utExit(); -} - -/* **************************************************************************** -* -* queryGeoCircleOut - -* -* Area: 14 km circle centered in Madrid -* Result: Leganes -* -*/ -TEST(mongoQueryContextGeoRequest, queryGeoCircleOut) -{ - utInit(); - - HttpStatusCode ms; - QueryContextRequest req; - QueryContextResponse res; - - /* Prepare database */ - prepareDatabase(); - - /* Forge the request (from "inside" to "outside") */ - EntityId en(".*", "City", "true"); - req.entityIdVector.push_back(&en); - - /* Define area scope */ - Scope sc; - sc.type = "FIWARE::Location"; - sc.areaType = orion::CircleType; - sc.circle.center.latitudeSet("40.418889"); - sc.circle.center.longitudeSet("-3.691944"); - sc.circle.radiusSet("13600"); - sc.circle.invertedSet("true"); - req.restriction.scopeVector.push_back(&sc); - - /* Invoke the function in mongoBackend library */ - ms = mongoQueryContext(&req, &res, "", servicePathVector, uriParams, options); - - /* Check response is as expected */ - EXPECT_EQ(SccOk, ms); - - EXPECT_EQ(0, res.errorCode.code); - EXPECT_STREQ("", res.errorCode.reasonPhrase.c_str()); - EXPECT_STREQ("", res.errorCode.details.c_str()); - - ASSERT_EQ(1, res.contextElementResponseVector.size()); - int i; - - /* Context Element response # 1 */ - i = getEntityIndex(res.contextElementResponseVector, "Alcobendas"); - ASSERT_GE(i, 0); - EXPECT_EQ("Alcobendas", RES_CER(i).id); - EXPECT_EQ("City", RES_CER(i).type); - EXPECT_EQ("false", RES_CER(i).isPattern); - ASSERT_EQ(2, RES_CER(i).attributeVector.size()); - EXPECT_EQ("foo", RES_CER_ATTR(i, 0)->name); - EXPECT_EQ("string", RES_CER_ATTR(i, 0)->type); - EXPECT_EQ("attr_Alc", RES_CER_ATTR(i, 0)->stringValue); - EXPECT_EQ("pos", RES_CER_ATTR(i, 1)->name); - EXPECT_EQ("location", RES_CER_ATTR(i, 1)->type); - EXPECT_EQ("40.533333, -3.633333", RES_CER_ATTR(i, 1)->stringValue); - ASSERT_EQ(1, RES_CER_ATTR(i, 1)->metadataVector.size()); - EXPECT_EQ("location", RES_CER_ATTR(i, 1)->metadataVector[0]->name); - EXPECT_EQ("string", RES_CER_ATTR(i, 1)->metadataVector[0]->type); - EXPECT_EQ("WGS84", RES_CER_ATTR(i, 1)->metadataVector[0]->stringValue); - EXPECT_EQ(SccOk, RES_CER_STATUS(i).code); - EXPECT_EQ("OK", RES_CER_STATUS(i).reasonPhrase); - EXPECT_EQ(0, RES_CER_STATUS(i).details.size()); - - /* Release dynamic memory used by response (mongoBackend allocates it) */ - res.contextElementResponseVector.release(); - - utExit(); -} - /* **************************************************************************** * * queryGeoPolygonIn1 - diff --git a/test/unittests/mongoBackend/mongoQueryTypes_test.cpp b/test/unittests/mongoBackend/mongoQueryTypes_test.cpp index e2c63f0f0e..1cbb63f84b 100644 --- a/test/unittests/mongoBackend/mongoQueryTypes_test.cpp +++ b/test/unittests/mongoBackend/mongoQueryTypes_test.cpp @@ -217,14 +217,14 @@ TEST(mongoQueryTypes, queryAllType) prepareDatabase(); /* Invoke the function in mongoBackend library */ - ms = mongoEntityTypes(&res, "", servicePathVector, uriParams, V1, NULL, false); + ms = mongoEntityTypes(&res, "", servicePathVector, uriParams, NULL, false); /* Check response is as expected */ EXPECT_EQ(SccOk, ms); - EXPECT_EQ(SccOk, res.statusCode.code); - EXPECT_EQ("OK", res.statusCode.reasonPhrase); - EXPECT_EQ("", res.statusCode.details); + EXPECT_EQ(SccOk, res.error.code); + EXPECT_EQ("OK", res.error.reasonPhrase); + EXPECT_EQ("", res.error.details); ASSERT_EQ(3, res.entityTypeVector.size()); ContextAttribute* ca; @@ -335,14 +335,14 @@ TEST(mongoQueryTypes, queryAllPaginationDetails) /* Invoke the function in mongoBackend library */ /* Using default offset/limit */ unsigned int totalTypes = 0; // enables count details - ms = mongoEntityTypes(&res, "", servicePathVector, uriParams, V1, &totalTypes, false); + ms = mongoEntityTypes(&res, "", servicePathVector, uriParams, &totalTypes, false); /* Check response is as expected */ EXPECT_EQ(SccOk, ms); - EXPECT_EQ(SccOk, res.statusCode.code); - EXPECT_EQ("OK", res.statusCode.reasonPhrase); - EXPECT_EQ("Count: 3", res.statusCode.details); + EXPECT_EQ(SccOk, res.error.code); + EXPECT_EQ("OK", res.error.reasonPhrase); + EXPECT_EQ("Count: 3", res.error.details); ASSERT_EQ(3, res.entityTypeVector.size()); ContextAttribute* ca; @@ -452,14 +452,14 @@ TEST(mongoQueryTypes, queryAllPaginationAll) /* Invoke the function in mongoBackend library */ /* Using default offset/limit */ - ms = mongoEntityTypes(&res, "", servicePathVector, uriParams, V1, NULL, false); + ms = mongoEntityTypes(&res, "", servicePathVector, uriParams, NULL, false); /* Check response is as expected */ EXPECT_EQ(SccOk, ms); - EXPECT_EQ(SccOk, res.statusCode.code); - EXPECT_EQ("OK", res.statusCode.reasonPhrase); - EXPECT_EQ("", res.statusCode.details); + EXPECT_EQ(SccOk, res.error.code); + EXPECT_EQ("OK", res.error.reasonPhrase); + EXPECT_EQ("", res.error.details); ASSERT_EQ(3, res.entityTypeVector.size()); ContextAttribute* ca; @@ -569,14 +569,14 @@ TEST(mongoQueryTypes, queryAllPaginationOnlyFirst) /* Invoke the function in mongoBackend library */ uriParams[URI_PARAM_PAGINATION_LIMIT] = "1"; - ms = mongoEntityTypes(&res, "", servicePathVector, uriParams, V1, NULL, false); + ms = mongoEntityTypes(&res, "", servicePathVector, uriParams, NULL, false); /* Check response is as expected */ EXPECT_EQ(SccOk, ms); - EXPECT_EQ(SccOk, res.statusCode.code); - EXPECT_EQ("OK", res.statusCode.reasonPhrase); - EXPECT_EQ("", res.statusCode.details); + EXPECT_EQ(SccOk, res.error.code); + EXPECT_EQ("OK", res.error.reasonPhrase); + EXPECT_EQ("", res.error.details); ASSERT_EQ(1, res.entityTypeVector.size()); ContextAttribute* ca; @@ -642,14 +642,14 @@ TEST(mongoQueryTypes, queryAllPaginationOnlySecond) /* Invoke the function in mongoBackend library */ uriParams[URI_PARAM_PAGINATION_OFFSET] = "1"; uriParams[URI_PARAM_PAGINATION_LIMIT] = "1"; - ms = mongoEntityTypes(&res, "", servicePathVector, uriParams, V1, NULL, false); + ms = mongoEntityTypes(&res, "", servicePathVector, uriParams, NULL, false); /* Check response is as expected */ EXPECT_EQ(SccOk, ms); - EXPECT_EQ(SccOk, res.statusCode.code); - EXPECT_EQ("OK", res.statusCode.reasonPhrase); - EXPECT_EQ("", res.statusCode.details); + EXPECT_EQ(SccOk, res.error.code); + EXPECT_EQ("OK", res.error.reasonPhrase); + EXPECT_EQ("", res.error.details); ASSERT_EQ(1, res.entityTypeVector.size()); ContextAttribute* ca; @@ -694,14 +694,14 @@ TEST(mongoQueryTypes, queryAllPaginationRange) /* Invoke the function in mongoBackend library */ uriParams[URI_PARAM_PAGINATION_OFFSET] = "1"; uriParams[URI_PARAM_PAGINATION_LIMIT] = "2"; - ms = mongoEntityTypes(&res, "", servicePathVector, uriParams, V1, NULL, false); + ms = mongoEntityTypes(&res, "", servicePathVector, uriParams, NULL, false); /* Check response is as expected */ EXPECT_EQ(SccOk, ms); - EXPECT_EQ(SccOk, res.statusCode.code); - EXPECT_EQ("OK", res.statusCode.reasonPhrase); - EXPECT_EQ("", res.statusCode.details); + EXPECT_EQ(SccOk, res.error.code); + EXPECT_EQ("OK", res.error.reasonPhrase); + EXPECT_EQ("", res.error.details); ASSERT_EQ(2, res.entityTypeVector.size()); ContextAttribute* ca; @@ -772,14 +772,14 @@ TEST(mongoQueryTypes, queryAllPaginationNonExisting) /* Invoke the function in mongoBackend library */ uriParams[URI_PARAM_PAGINATION_OFFSET] = "7"; uriParams[URI_PARAM_PAGINATION_LIMIT] = "3"; - ms = mongoEntityTypes(&res, "", servicePathVector, uriParams, V1, NULL, false); + ms = mongoEntityTypes(&res, "", servicePathVector, uriParams, NULL, false); /* Check response is as expected */ EXPECT_EQ(SccOk, ms); - EXPECT_EQ(SccContextElementNotFound, res.statusCode.code); - EXPECT_EQ("No context element found", res.statusCode.reasonPhrase); - EXPECT_EQ("", res.statusCode.details); + EXPECT_EQ(SccContextElementNotFound, res.error.code); + EXPECT_EQ("No context element found", res.error.reasonPhrase); + EXPECT_EQ("", res.error.details); ASSERT_EQ(0, res.entityTypeVector.size()); @@ -804,14 +804,14 @@ TEST(mongoQueryTypes, queryAllPaginationNonExistingOverlap) /* Invoke the function in mongoBackend library */ uriParams[URI_PARAM_PAGINATION_OFFSET] = "2"; uriParams[URI_PARAM_PAGINATION_LIMIT] = "4"; - ms = mongoEntityTypes(&res, "", servicePathVector, uriParams, V1, NULL, false); + ms = mongoEntityTypes(&res, "", servicePathVector, uriParams, NULL, false); /* Check response is as expected */ EXPECT_EQ(SccOk, ms); - EXPECT_EQ(SccOk, res.statusCode.code); - EXPECT_EQ("OK", res.statusCode.reasonPhrase); - EXPECT_EQ("", res.statusCode.details); + EXPECT_EQ(SccOk, res.error.code); + EXPECT_EQ("OK", res.error.reasonPhrase); + EXPECT_EQ("", res.error.details); ASSERT_EQ(1, res.entityTypeVector.size()); ContextAttribute* ca; @@ -864,14 +864,14 @@ TEST(mongoQueryTypes, queryAllPaginationNonExistingDetails) uriParams[URI_PARAM_PAGINATION_OFFSET] = "7"; uriParams[URI_PARAM_PAGINATION_LIMIT] = "3"; unsigned int totalTypes = 0; // enables count details - ms = mongoEntityTypes(&res, "", servicePathVector, uriParams, V1, &totalTypes, false); + ms = mongoEntityTypes(&res, "", servicePathVector, uriParams, &totalTypes, false); /* Check response is as expected */ EXPECT_EQ(SccOk, ms); - EXPECT_EQ(SccContextElementNotFound, res.statusCode.code); - EXPECT_EQ("No context element found", res.statusCode.reasonPhrase); - EXPECT_EQ("Number of types: 3. Offset is 7", res.statusCode.details); + EXPECT_EQ(SccContextElementNotFound, res.error.code); + EXPECT_EQ("No context element found", res.error.reasonPhrase); + EXPECT_EQ("Number of types: 3. Offset is 7", res.error.details); ASSERT_EQ(0, res.entityTypeVector.size()); @@ -901,12 +901,12 @@ TEST(mongoQueryTypes, queryAllDbException) setMongoConnectionForUnitTest(connectionMock); /* Invoke the function in mongoBackend library */ - ms = mongoEntityTypes(&res, "", servicePathVector, uriParams, V1, NULL, false); + ms = mongoEntityTypes(&res, "", servicePathVector, uriParams, NULL, false); /* Check response is as expected */ EXPECT_EQ(SccOk, ms); - EXPECT_EQ(SccReceiverInternalError, res.statusCode.code); - EXPECT_EQ("Internal Server Error", res.statusCode.reasonPhrase); + EXPECT_EQ(SccReceiverInternalError, res.error.code); + EXPECT_EQ("Internal Server Error", res.error.reasonPhrase); EXPECT_EQ("Database Error (collection: utest " "- runCommand(): { aggregate: \"entities\", " "cursor: { batchSize: 1000 }, " @@ -916,7 +916,7 @@ TEST(mongoQueryTypes, queryAllDbException) "{ $unwind: \"$attrNames\" }, " "{ $group: { _id: { $cond: [ { $in: [ \"$_id.type\", [ null, \"\" ] ] }, \"\", \"$_id.type\" ] }, attrs: { $addToSet: \"$attrNames\" } } }, " "{ $sort: { _id: 1 } }, { $skip: 0 }, { $limit: 20 } ] } " - "- exception: boom!!)", res.statusCode.details); + "- exception: boom!!)", res.error.details); EXPECT_EQ(0, res.entityTypeVector.size()); /* Restore real DB connection */ @@ -953,13 +953,13 @@ TEST(mongoQueryTypes, queryAllGenericException) setMongoConnectionForUnitTest(connectionMock); /* Invoke the function in mongoBackend library */ - ms = mongoEntityTypes(&res, "", servicePathVector, uriParams, V1, NULL, false); + ms = mongoEntityTypes(&res, "", servicePathVector, uriParams, NULL, false); /* Check response is as expected */ EXPECT_EQ(SccOk, ms); - EXPECT_EQ(SccReceiverInternalError, res.statusCode.code); - EXPECT_EQ("Internal Server Error", res.statusCode.reasonPhrase); + EXPECT_EQ(SccReceiverInternalError, res.error.code); + EXPECT_EQ("Internal Server Error", res.error.reasonPhrase); EXPECT_EQ("Database Error (collection: utest " "- runCommand(): { aggregate: \"entities\", " "cursor: { batchSize: 1000 }, " @@ -969,7 +969,7 @@ TEST(mongoQueryTypes, queryAllGenericException) "{ $unwind: \"$attrNames\" }, " "{ $group: { _id: { $cond: [ { $in: [ \"$_id.type\", [ null, \"\" ] ] }, \"\", \"$_id.type\" ] }, attrs: { $addToSet: \"$attrNames\" } } }, " "{ $sort: { _id: 1 } }, { $skip: 0 }, { $limit: 20 } ] } " - "- exception: std::exception)", res.statusCode.details); + "- exception: std::exception)", res.error.details); EXPECT_EQ(0, res.entityTypeVector.size()); /* Restore real DB connection */ @@ -999,14 +999,14 @@ TEST(mongoQueryTypes, queryGivenTypeBasic) prepareDatabase(); /* Invoke the function in mongoBackend library */ - ms = mongoAttributesForEntityType("Car", &res, "", servicePathVector, uriParams, false, V1); + ms = mongoAttributesForEntityType("Car", &res, "", servicePathVector, uriParams, false); /* Check response is as expected */ EXPECT_EQ(SccOk, ms); - EXPECT_EQ(SccOk, res.statusCode.code); - EXPECT_EQ("OK", res.statusCode.reasonPhrase); - EXPECT_EQ("", res.statusCode.details); + EXPECT_EQ(SccOk, res.error.code); + EXPECT_EQ("OK", res.error.reasonPhrase); + EXPECT_EQ("", res.error.details); EXPECT_EQ(3, res.entityType.count); ASSERT_EQ(5, res.entityType.contextAttributeVector.size()); @@ -1067,14 +1067,14 @@ TEST(mongoQueryTypes, queryGivenTypePaginationDetails) /* Invoke the function in mongoBackend library */ uriParams[URI_PARAM_PAGINATION_DETAILS] = "on"; /* Using default offset/limit */ - ms = mongoAttributesForEntityType("Car", &res, "", servicePathVector, uriParams, false, V1); + ms = mongoAttributesForEntityType("Car", &res, "", servicePathVector, uriParams, false); /* Check response is as expected */ EXPECT_EQ(SccOk, ms); - EXPECT_EQ(SccOk, res.statusCode.code); - EXPECT_EQ("OK", res.statusCode.reasonPhrase); - EXPECT_EQ("Count: 5", res.statusCode.details); + EXPECT_EQ(SccOk, res.error.code); + EXPECT_EQ("OK", res.error.reasonPhrase); + EXPECT_EQ("Count: 5", res.error.details); EXPECT_EQ(3, res.entityType.count); ASSERT_EQ(5, res.entityType.contextAttributeVector.size()); @@ -1135,14 +1135,14 @@ TEST(mongoQueryTypes, queryGivenTypePaginationAll) /* Invoke the function in mongoBackend library */ uriParams[URI_PARAM_PAGINATION_DETAILS] = "off"; /* Using default offset/limit */ - ms = mongoAttributesForEntityType("Car", &res, "", servicePathVector, uriParams, false, V1); + ms = mongoAttributesForEntityType("Car", &res, "", servicePathVector, uriParams, false); /* Check response is as expected */ EXPECT_EQ(SccOk, ms); - EXPECT_EQ(SccOk, res.statusCode.code); - EXPECT_EQ("OK", res.statusCode.reasonPhrase); - EXPECT_EQ("", res.statusCode.details); + EXPECT_EQ(SccOk, res.error.code); + EXPECT_EQ("OK", res.error.reasonPhrase); + EXPECT_EQ("", res.error.details); EXPECT_EQ(3, res.entityType.count); ASSERT_EQ(5, res.entityType.contextAttributeVector.size()); @@ -1203,14 +1203,14 @@ TEST(mongoQueryTypes, queryGivenTypePaginationOnlyFirst) /* Invoke the function in mongoBackend library */ uriParams[URI_PARAM_PAGINATION_DETAILS] = "off"; uriParams[URI_PARAM_PAGINATION_LIMIT] = "1"; - ms = mongoAttributesForEntityType("Car", &res, "", servicePathVector, uriParams, false, V1); + ms = mongoAttributesForEntityType("Car", &res, "", servicePathVector, uriParams, false); /* Check response is as expected */ EXPECT_EQ(SccOk, ms); - EXPECT_EQ(SccOk, res.statusCode.code); - EXPECT_EQ("OK", res.statusCode.reasonPhrase); - EXPECT_EQ("", res.statusCode.details); + EXPECT_EQ(SccOk, res.error.code); + EXPECT_EQ("OK", res.error.reasonPhrase); + EXPECT_EQ("", res.error.details); ASSERT_EQ(1, res.entityType.contextAttributeVector.size()); @@ -1243,14 +1243,14 @@ TEST(mongoQueryTypes, queryGivenTypePaginationOnlySecond) uriParams[URI_PARAM_PAGINATION_DETAILS] = "off"; uriParams[URI_PARAM_PAGINATION_OFFSET] = "1"; uriParams[URI_PARAM_PAGINATION_LIMIT] = "1"; - ms = mongoAttributesForEntityType("Car", &res, "", servicePathVector, uriParams, false, V1); + ms = mongoAttributesForEntityType("Car", &res, "", servicePathVector, uriParams, false); /* Check response is as expected */ EXPECT_EQ(SccOk, ms); - EXPECT_EQ(SccOk, res.statusCode.code); - EXPECT_EQ("OK", res.statusCode.reasonPhrase); - EXPECT_EQ("", res.statusCode.details); + EXPECT_EQ(SccOk, res.error.code); + EXPECT_EQ("OK", res.error.reasonPhrase); + EXPECT_EQ("", res.error.details); EXPECT_EQ(3, res.entityType.count); ASSERT_EQ(1, res.entityType.contextAttributeVector.size()); @@ -1284,14 +1284,14 @@ TEST(mongoQueryTypes, queryGivenTypePaginationRange) uriParams[URI_PARAM_PAGINATION_DETAILS] = "off"; uriParams[URI_PARAM_PAGINATION_OFFSET] = "2"; uriParams[URI_PARAM_PAGINATION_LIMIT] = "3"; - ms = mongoAttributesForEntityType("Car", &res, "", servicePathVector, uriParams, false, V1); + ms = mongoAttributesForEntityType("Car", &res, "", servicePathVector, uriParams, false); /* Check response is as expected */ EXPECT_EQ(SccOk, ms); - EXPECT_EQ(SccOk, res.statusCode.code); - EXPECT_EQ("OK", res.statusCode.reasonPhrase); - EXPECT_EQ("", res.statusCode.details); + EXPECT_EQ(SccOk, res.error.code); + EXPECT_EQ("OK", res.error.reasonPhrase); + EXPECT_EQ("", res.error.details); EXPECT_EQ(3, res.entityType.count); ASSERT_EQ(3, res.entityType.contextAttributeVector.size()); @@ -1339,14 +1339,14 @@ TEST(mongoQueryTypes, queryGivenTypePaginationNonExisting) uriParams[URI_PARAM_PAGINATION_DETAILS] = "off"; uriParams[URI_PARAM_PAGINATION_OFFSET] = "7"; uriParams[URI_PARAM_PAGINATION_LIMIT] = "3"; - ms = mongoAttributesForEntityType("Car", &res, "", servicePathVector, uriParams, false, V1); + ms = mongoAttributesForEntityType("Car", &res, "", servicePathVector, uriParams, false); /* Check response is as expected */ EXPECT_EQ(SccOk, ms); - EXPECT_EQ(SccContextElementNotFound, res.statusCode.code); - EXPECT_EQ("No context element found", res.statusCode.reasonPhrase); - EXPECT_EQ("", res.statusCode.details); + EXPECT_EQ(SccContextElementNotFound, res.error.code); + EXPECT_EQ("No context element found", res.error.reasonPhrase); + EXPECT_EQ("", res.error.details); ASSERT_EQ(0, res.entityType.contextAttributeVector.size()); @@ -1372,14 +1372,14 @@ TEST(mongoQueryTypes, queryGivenTypePaginationNonExistingOverlap) uriParams[URI_PARAM_PAGINATION_DETAILS] = "off"; uriParams[URI_PARAM_PAGINATION_OFFSET] = "3"; uriParams[URI_PARAM_PAGINATION_LIMIT] = "3"; - ms = mongoAttributesForEntityType("Car", &res, "", servicePathVector, uriParams, false, V1); + ms = mongoAttributesForEntityType("Car", &res, "", servicePathVector, uriParams, false); /* Check response is as expected */ EXPECT_EQ(SccOk, ms); - EXPECT_EQ(SccOk, res.statusCode.code); - EXPECT_EQ("OK", res.statusCode.reasonPhrase); - EXPECT_EQ("", res.statusCode.details); + EXPECT_EQ(SccOk, res.error.code); + EXPECT_EQ("OK", res.error.reasonPhrase); + EXPECT_EQ("", res.error.details); EXPECT_EQ(3, res.entityType.count); ASSERT_EQ(2, res.entityType.contextAttributeVector.size()); @@ -1420,14 +1420,14 @@ TEST(mongoQueryTypes, queryGivenTypePaginationNonExistingDetails) uriParams[URI_PARAM_PAGINATION_DETAILS] = "on"; uriParams[URI_PARAM_PAGINATION_OFFSET] = "7"; uriParams[URI_PARAM_PAGINATION_LIMIT] = "3"; - ms = mongoAttributesForEntityType("Car", &res, "", servicePathVector, uriParams, false, V1); + ms = mongoAttributesForEntityType("Car", &res, "", servicePathVector, uriParams, false); /* Check response is as expected */ EXPECT_EQ(SccOk, ms); - EXPECT_EQ(SccContextElementNotFound, res.statusCode.code); - EXPECT_EQ("No context element found", res.statusCode.reasonPhrase); - EXPECT_EQ("Number of attributes: 5. Offset is 7", res.statusCode.details); + EXPECT_EQ(SccContextElementNotFound, res.error.code); + EXPECT_EQ("No context element found", res.error.reasonPhrase); + EXPECT_EQ("Number of attributes: 5. Offset is 7", res.error.details); ASSERT_EQ(0, res.entityType.contextAttributeVector.size()); @@ -1457,13 +1457,13 @@ TEST(mongoQueryTypes, queryGivenTypeDbException) setMongoConnectionForUnitTest(connectionMock); /* Invoke the function in mongoBackend library */ - ms = mongoAttributesForEntityType("Car", &res, "", servicePathVector, uriParams, false, V1); + ms = mongoAttributesForEntityType("Car", &res, "", servicePathVector, uriParams, false); /* Check response is as expected */ EXPECT_EQ(SccOk, ms); - EXPECT_EQ(SccReceiverInternalError, res.statusCode.code); - EXPECT_EQ("Internal Server Error", res.statusCode.reasonPhrase); + EXPECT_EQ(SccReceiverInternalError, res.error.code); + EXPECT_EQ("Internal Server Error", res.error.reasonPhrase); EXPECT_EQ("Database Error (collection: utest " "- runCommand(): { aggregate: \"entities\", " "cursor: { batchSize: 1000 }, " @@ -1474,7 +1474,7 @@ TEST(mongoQueryTypes, queryGivenTypeDbException) "{ $unwind: \"$attrs\" }, " "{ $group: { _id: \"$attrs\" } }, " "{ $sort: { _id: 1 } } ] } " - "- exception: boom!!)", res.statusCode.details); + "- exception: boom!!)", res.error.details); EXPECT_EQ(0, res.entityType.contextAttributeVector.size()); /* Restore real DB connection */ @@ -1509,13 +1509,13 @@ TEST(mongoQueryTypes, queryGivenTypeGenericException) setMongoConnectionForUnitTest(connectionMock); /* Invoke the function in mongoBackend library */ - ms = mongoAttributesForEntityType("Car", &res, "", servicePathVector, uriParams, false, V1); + ms = mongoAttributesForEntityType("Car", &res, "", servicePathVector, uriParams, false); /* Check response is as expected */ EXPECT_EQ(SccOk, ms); - EXPECT_EQ(SccReceiverInternalError, res.statusCode.code); - EXPECT_EQ("Internal Server Error", res.statusCode.reasonPhrase); + EXPECT_EQ(SccReceiverInternalError, res.error.code); + EXPECT_EQ("Internal Server Error", res.error.reasonPhrase); EXPECT_EQ("Database Error (collection: utest " "- runCommand(): { aggregate: \"entities\", " "cursor: { batchSize: 1000 }, " @@ -1526,7 +1526,7 @@ TEST(mongoQueryTypes, queryGivenTypeGenericException) "{ $unwind: \"$attrs\" }, " "{ $group: { _id: \"$attrs\" } }, " "{ $sort: { _id: 1 } } ] } " - "- exception: std::exception)", res.statusCode.details); + "- exception: std::exception)", res.error.details); EXPECT_EQ(0, res.entityType.contextAttributeVector.size()); /* Restore real DB connection */ diff --git a/test/unittests/mongoBackend/mongoRegisterContext_test.cpp b/test/unittests/mongoBackend/mongoRegisterContext_test.cpp index efe0ed1788..0fa9452dc3 100644 --- a/test/unittests/mongoBackend/mongoRegisterContext_test.cpp +++ b/test/unittests/mongoBackend/mongoRegisterContext_test.cpp @@ -35,7 +35,7 @@ #include "mongoBackend/MongoGlobal.h" #include "mongoBackend/mongoConnectionPool.h" #include "mongoBackend/mongoRegisterContext.h" -#include "ngsi/StatusCode.h" +#include "rest/OrionError.h" #include "ngsi/ContextRegistration.h" #include "ngsi/EntityId.h" #include "ngsi/ContextRegistrationAttribute.h" diff --git a/test/unittests/mongoBackend/mongoRegisterContext_update_test.cpp b/test/unittests/mongoBackend/mongoRegisterContext_update_test.cpp index d3dd252c26..ef678ecfe6 100644 --- a/test/unittests/mongoBackend/mongoRegisterContext_update_test.cpp +++ b/test/unittests/mongoBackend/mongoRegisterContext_update_test.cpp @@ -38,7 +38,7 @@ #include "ngsi/EntityId.h" #include "ngsi/ContextRegistrationAttribute.h" #include "ngsi/Metadata.h" -#include "ngsi/StatusCode.h" +#include "rest/OrionError.h" #include "ngsi9/RegisterContextRequest.h" #include "ngsi9/RegisterContextResponse.h" diff --git a/test/unittests/mongoBackend/mongoSubscribeContext_test.cpp b/test/unittests/mongoBackend/mongoSubscribeContext_test.cpp index 314969b4d3..cdefab9e58 100644 --- a/test/unittests/mongoBackend/mongoSubscribeContext_test.cpp +++ b/test/unittests/mongoBackend/mongoSubscribeContext_test.cpp @@ -36,7 +36,6 @@ #include "ngsi10/SubscribeContextResponse.h" #include "ngsi/EntityId.h" -#include "ngsi/NotifyCondition.h" #include "apiTypesV2/HttpInfo.h" #include "mongo/client/dbclient.h" diff --git a/test/unittests/mongoBackend/mongoUnsubscribeContext_test.cpp b/test/unittests/mongoBackend/mongoUnsubscribeContext_test.cpp index 6a4ce9f849..2be5b17459 100644 --- a/test/unittests/mongoBackend/mongoUnsubscribeContext_test.cpp +++ b/test/unittests/mongoBackend/mongoUnsubscribeContext_test.cpp @@ -133,9 +133,9 @@ TEST(mongoUnsubscribeContext, subscriptionNotFound) /* Check response is as expected */ EXPECT_EQ(SccOk, ms); EXPECT_EQ("51307b66f481db11bf869999", res.subscriptionId.get()); - EXPECT_EQ(SccContextElementNotFound, res.statusCode.code); - EXPECT_EQ("No context element found", res.statusCode.reasonPhrase); - EXPECT_EQ("subscriptionId: /51307b66f481db11bf869999/", res.statusCode.details); + EXPECT_EQ(SccContextElementNotFound, res.error.code); + EXPECT_EQ("No context element found", res.error.reasonPhrase); + EXPECT_EQ("subscriptionId: /51307b66f481db11bf869999/", res.error.details); /* Check database (untouched) */ DBClientBase* connection = getMongoConnection(); @@ -173,9 +173,9 @@ TEST(mongoUnsubscribeContext, unsubscribe) /* Check response is as expected */ EXPECT_EQ(SccOk, ms); EXPECT_EQ("51307b66f481db11bf860001", res.subscriptionId.get()); - EXPECT_EQ(SccOk, res.statusCode.code); - EXPECT_EQ("OK", res.statusCode.reasonPhrase); - EXPECT_EQ(0, res.statusCode.details.size()); + EXPECT_EQ(SccOk, res.error.code); + EXPECT_EQ("OK", res.error.reasonPhrase); + EXPECT_EQ(0, res.error.details.size()); /* Check database (one document, but not the deleted one) */ DBClientBase* connection = getMongoConnection(); @@ -225,11 +225,11 @@ TEST(mongoUnsubscribeContext, MongoDbFindOneFail) /* Check response is as expected */ EXPECT_EQ(SccOk, ms); EXPECT_EQ("51307b66f481db11bf860001", res.subscriptionId.get()); - EXPECT_EQ(SccReceiverInternalError, res.statusCode.code); - EXPECT_EQ("Internal Server Error", res.statusCode.reasonPhrase); + EXPECT_EQ(SccReceiverInternalError, res.error.code); + EXPECT_EQ("Internal Server Error", res.error.reasonPhrase); EXPECT_EQ("Database Error (collection: utest.csubs " "- findOne(): { _id: ObjectId('51307b66f481db11bf860001') } " - "- exception: boom!!)", res.statusCode.details); + "- exception: boom!!)", res.error.details); // Sleeping a little to "give mongod time to process its input". // Without this sleep, this tests fails around 10% of the times (in Ubuntu 13.04) @@ -297,11 +297,11 @@ TEST(mongoUnsubscribeContext, MongoDbRemoveFail) /* Check response is as expected */ EXPECT_EQ(SccOk, ms); EXPECT_EQ("51307b66f481db11bf860001", res.subscriptionId.get()); - EXPECT_EQ(SccReceiverInternalError, res.statusCode.code); - EXPECT_EQ("Internal Server Error", res.statusCode.reasonPhrase); + EXPECT_EQ(SccReceiverInternalError, res.error.code); + EXPECT_EQ("Internal Server Error", res.error.reasonPhrase); EXPECT_EQ("Database Error (collection: utest.csubs " "- remove(): { _id: ObjectId('51307b66f481db11bf860001') } " - "- exception: boom!!)", res.statusCode.details); + "- exception: boom!!)", res.error.details); // Sleeping a little to "give mongod time to process its input". usleep(1000); diff --git a/test/unittests/mongoBackend/mongoUpdateContextGeo_test.cpp b/test/unittests/mongoBackend/mongoUpdateContextGeo_test.cpp index b111484ed1..60b01c3dab 100644 --- a/test/unittests/mongoBackend/mongoUpdateContextGeo_test.cpp +++ b/test/unittests/mongoBackend/mongoUpdateContextGeo_test.cpp @@ -520,7 +520,7 @@ TEST(mongoUpdateContextGeoRequest, replaceLocAttributeWithSameLocAttribute) /* Invoke the function in mongoBackend library */ servicePathVector.clear(); - ms = mongoUpdateContext(&req, &res, "", servicePathVector, uriParams, "", "", "", false, V2); + ms = mongoUpdateContext(&req, &res, "", servicePathVector, uriParams, "", "", "", false); /* Check response is as expected */ EXPECT_EQ(SccOk, ms); @@ -621,7 +621,7 @@ TEST(mongoUpdateContextGeoRequest, replaceLocAttributeWithDifferentLocAttribute) bool forcedUpdate = false; /* Invoke the function in mongoBackend library */ servicePathVector.clear(); - ms = mongoUpdateContext(&req, &res, "", servicePathVector, uriParams, "", "", "", forcedUpdate, V2); + ms = mongoUpdateContext(&req, &res, "", servicePathVector, uriParams, "", "", "", forcedUpdate); /* Check response is as expected */ EXPECT_EQ(SccOk, ms); @@ -722,7 +722,7 @@ TEST(mongoUpdateContextGeoRequest, replaceLocAttributeWithNoLocAttribute) bool forcedUpdate = false; /* Invoke the function in mongoBackend library */ servicePathVector.clear(); - ms = mongoUpdateContext(&req, &res, "", servicePathVector, uriParams, "", "", "", forcedUpdate, V2); + ms = mongoUpdateContext(&req, &res, "", servicePathVector, uriParams, "", "", "", forcedUpdate); /* Check response is as expected */ EXPECT_EQ(SccOk, ms); @@ -819,7 +819,7 @@ TEST(mongoUpdateContextGeoRequest, replaceNoLocAttributeWithLocAttribute) /* Invoke the function in mongoBackend library */ servicePathVector.clear(); - ms = mongoUpdateContext(&req, &res, "", servicePathVector, uriParams, "", "", "", false, V2); + ms = mongoUpdateContext(&req, &res, "", servicePathVector, uriParams, "", "", "", false); /* Check response is as expected */ EXPECT_EQ(SccOk, ms); diff --git a/test/unittests/mongoBackend/mongoUpdateContextSubscription_test.cpp b/test/unittests/mongoBackend/mongoUpdateContextSubscription_test.cpp index 6e26762847..6fa0421dfb 100644 --- a/test/unittests/mongoBackend/mongoUpdateContextSubscription_test.cpp +++ b/test/unittests/mongoBackend/mongoUpdateContextSubscription_test.cpp @@ -37,7 +37,6 @@ #include "ngsi10/UpdateContextSubscriptionRequest.h" #include "ngsi10/UpdateContextSubscriptionResponse.h" #include "ngsi/EntityId.h" -#include "ngsi/NotifyCondition.h" #include "unittests/testInit.h" #include "unittests/unittest.h" diff --git a/test/unittests/mongoBackend/mongoUpdateContext_2_test.cpp b/test/unittests/mongoBackend/mongoUpdateContext_2_test.cpp index eb53744693..4dbf6c814a 100644 --- a/test/unittests/mongoBackend/mongoUpdateContext_2_test.cpp +++ b/test/unittests/mongoBackend/mongoUpdateContext_2_test.cpp @@ -2013,7 +2013,7 @@ TEST(mongoUpdateContextRequest, updateNativeTypes) req.updateActionType = ActionTypeUpdate; /* Invoke the function in mongoBackend library */ - ms = mongoUpdateContext(&req, &res, "", servicePathVector, uriParams, "", "", "", false, V2); + ms = mongoUpdateContext(&req, &res, "", servicePathVector, uriParams, "", "", "", false); /* Check response is as expected */ EXPECT_EQ(SccOk, ms); @@ -2884,7 +2884,7 @@ TEST(mongoUpdateContextRequest, tooManyEntitiesNGSIv2) bool forcedUpdate = false; /* Invoke the function in mongoBackend library (note the 2 to activate NGSIv2 special behaviours) */ - ms = mongoUpdateContext(&req, &res, "", servicePathVector, uriParams, "", "", "", forcedUpdate, V2); + ms = mongoUpdateContext(&req, &res, "", servicePathVector, uriParams, "", "", "", forcedUpdate); /* Check response is as expected */ EXPECT_EQ(SccOk, ms); @@ -3034,7 +3034,7 @@ TEST(mongoUpdateContextRequest, onlyOneEntityNGSIv2) req.updateActionType = ActionTypeUpdate; /* Invoke the function in mongoBackend library (note the 2 to activate NGSIv2 special behaviours) */ - ms = mongoUpdateContext(&req, &res, "", servicePathVector, uriParams, "", "", "", false, V2); + ms = mongoUpdateContext(&req, &res, "", servicePathVector, uriParams, "", "", "", false); /* Check response is as expected */ EXPECT_EQ(SccOk, ms); diff --git a/test/unittests/ngsi/AttributeExpression_test.cpp b/test/unittests/ngsi/AttributeExpression_test.cpp deleted file mode 100644 index 5b04bd3933..0000000000 --- a/test/unittests/ngsi/AttributeExpression_test.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "ngsi/AttributeExpression.h" - -#include "unittest.h" - - - -/* **************************************************************************** -* -* ok - -*/ -TEST(AttributeExpression, ok) -{ - AttributeExpression ae; - const char* outfile1 = "ngsi10.attributeExpression.ok.middle.json"; - std::string out; - - utInit(); - - ae.set("AE"); - EXPECT_STREQ("AE", ae.get().c_str()); - - ae.set(""); - EXPECT_STREQ("", ae.toJsonV1(false).c_str()); - - ae.set("AE"); - - out = ae.toJsonV1(false); - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'"; - EXPECT_STREQ(expectedBuf, out.c_str()); - - EXPECT_STREQ("AE", ae.c_str()); - - utExit(); -} diff --git a/test/unittests/ngsi/AttributeList_test.cpp b/test/unittests/ngsi/AttributeList_test.cpp index c927d63814..f4c9fdb2fa 100644 --- a/test/unittests/ngsi/AttributeList_test.cpp +++ b/test/unittests/ngsi/AttributeList_test.cpp @@ -37,25 +37,21 @@ */ TEST(AttributeList, ok) { + utInit(); + StringList al; std::string out; - const char* outfile1 = "ngsi.attributeList.ok.middle.json"; + const char* outfile1 = "ngsi.attributeList.ok.middle.json"; - utInit(); - - out = al.toJsonV1(false, "attributes"); - EXPECT_STREQ("", out.c_str()); + out = al.toJson(); + EXPECT_STREQ("[]", out.c_str()); al.push_back("a1"); al.push_back("a2"); - out = al.toJsonV1(false, "attributes"); + out = al.toJson(); EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'"; EXPECT_STREQ(expectedBuf, out.c_str()); - al.push_back(""); - out = al.check(); - EXPECT_STREQ("empty string", out.c_str()); - utExit(); } diff --git a/test/unittests/ngsi/ConditionValueList_test.cpp b/test/unittests/ngsi/ConditionValueList_test.cpp deleted file mode 100644 index 1cef0597d5..0000000000 --- a/test/unittests/ngsi/ConditionValueList_test.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" -#include "ngsi/ConditionValueList.h" - -#include "unittest.h" - - - -/* **************************************************************************** -* -* ok - -*/ -TEST(ConditionValueList, ok) -{ - ConditionValueList cvList; - std::string out; - const char* outfile1 = "ngsi.conditionValueList.ok2.middle.json"; - const char* outfile2 = "ngsi.conditionValueList.ok3.middle.json"; - - out = cvList.toJsonV1(false); - EXPECT_STREQ("", out.c_str()); - - cvList.push_back("cv1"); - - out = cvList.toJsonV1(false); - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'"; - EXPECT_STREQ(expectedBuf, out.c_str()); - - cvList.push_back("cv2"); - out = cvList.toJsonV1(false); - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile2)) << "Error getting test data from '" << outfile2 << "'"; - EXPECT_STREQ(expectedBuf, out.c_str()); - - out = cvList.check(); - EXPECT_STREQ("OK", out.c_str()); - - cvList.push_back(""); - out = cvList.check(); - EXPECT_STREQ("empty condValue name", out.c_str()); - - cvList.release(); - EXPECT_EQ(0, cvList.size()); -} diff --git a/test/unittests/ngsi/ContextAttributeVector_test.cpp b/test/unittests/ngsi/ContextAttributeVector_test.cpp deleted file mode 100644 index 27001aaa3f..0000000000 --- a/test/unittests/ngsi/ContextAttributeVector_test.cpp +++ /dev/null @@ -1,74 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "ngsi/ContextAttributeVector.h" - -#include "unittest.h" - - - -/* **************************************************************************** -* -* render - -* -*/ -TEST(ContextAttributeVector, render) -{ - ContextAttributeVector cav; - std::string out; - - utInit(); - - const std::vector emptyAttrsV; - const std::vector emptyMdV; - - // FIXME P3: "" is a string, signature tells bool... - out = cav.toJsonV1(false, UpdateContextAttribute, emptyAttrsV, emptyMdV, ""); - EXPECT_STREQ("", out.c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* get - -*/ -TEST(ContextAttributeVector, get) -{ -} - - - -/* **************************************************************************** -* -* size - -*/ -TEST(ContextAttributeVector, size) -{ -} diff --git a/test/unittests/ngsi/ContextAttribute_test.cpp b/test/unittests/ngsi/ContextAttribute_test.cpp index f0acb5e8a6..8f4db3dbaa 100644 --- a/test/unittests/ngsi/ContextAttribute_test.cpp +++ b/test/unittests/ngsi/ContextAttribute_test.cpp @@ -37,24 +37,24 @@ */ TEST(ContextAttribute, checkOne) { - ContextAttribute* caP = new ContextAttribute(); - std::string res; - utInit(); + ContextAttribute* caP = new ContextAttribute(); + std::string res; + caP->name = ""; - res = caP->check(V1, RegisterContext); - EXPECT_TRUE(res == "missing attribute name"); + res = caP->check(false); + EXPECT_EQ(res, "attribute name length: 0, min length supported: 1"); caP->name = "Algo, lo que sea!"; caP->stringValue = ""; // FIXME P10: automacit value -> stringValue change, please review to check if it is safe - res = caP->check(V1, RegisterContext); - EXPECT_TRUE(res == "OK"); + res = caP->check(false); + EXPECT_EQ(res, "Invalid characters in attribute name"); caP->stringValue = "Algun valor cualquiera"; // FIXME P10: automacit value -> stringValue change, please review to check if it is safe - res = caP->check(V1, RegisterContext); - EXPECT_TRUE(res == "OK"); + res = caP->check(false); + EXPECT_EQ(res, "Invalid characters in attribute name"); utExit(); } @@ -82,8 +82,8 @@ TEST(ContextAttribute, checkVector) caVectorP->push_back(ca0P); caVectorP->push_back(ca1P); - res = caVectorP->check(V1, RegisterContext); - EXPECT_TRUE(res == "OK"); + res = caVectorP->check(false); + EXPECT_EQ(res, "Invalid characters in attribute name"); utExit(); } @@ -104,7 +104,7 @@ TEST(ContextAttribute, render) std::vector emptyMdV; - out = caP->toJsonV1(false, UpdateContext, emptyMdV, false); + out = caP->toJson(emptyMdV, false, NULL); EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'"; EXPECT_STREQ(expectedBuf, out.c_str()); diff --git a/test/unittests/ngsi/ContextElementResponseVector_test.cpp b/test/unittests/ngsi/ContextElementResponseVector_test.cpp index 0f8e3c9f28..656d8e8b7d 100644 --- a/test/unittests/ngsi/ContextElementResponseVector_test.cpp +++ b/test/unittests/ngsi/ContextElementResponseVector_test.cpp @@ -31,35 +31,6 @@ -/* **************************************************************************** -* -* check - -*/ -TEST(ContextElementResponseVector, check) -{ - ContextElementResponseVector cerv; - ContextElementResponse cer; - std::string out; - - utInit(); - - out = cerv.check(V1, UpdateContext, "", 0); - EXPECT_STREQ("OK", out.c_str()); - - cer.entity.id = "ID"; - cer.entity.type = "Type"; - cer.entity.isPattern = "false"; - cer.statusCode.fill(SccOk, "details"); - - cerv.push_back(&cer); - out = cerv.check(V1, UpdateContext, "", 0); - EXPECT_STREQ("OK", out.c_str()); - - utExit(); -} - - - /* **************************************************************************** * * render - @@ -67,20 +38,20 @@ TEST(ContextElementResponseVector, check) */ TEST(ContextElementResponseVector, render) { + utInit(); + ContextElementResponseVector cerv; ContextElementResponse cer; std::string out; - utInit(); + std::vector emptyV; - // FIXME P2: "" is string, function signature says bool.. - out = cerv.toJsonV1(false, UpdateContextElement, false, ""); - EXPECT_STREQ("", out.c_str()); + out = cerv.toJson(NGSI_V2_NORMALIZED, emptyV, false, emptyV, NULL); + EXPECT_STREQ("[]", out.c_str()); - cer.entity.id = "ID"; - cer.entity.type = "Type"; - cer.entity.isPattern = "false"; - cer.statusCode.fill(SccOk, "details"); + cer.entity.entityId.id = "ID"; + cer.entity.entityId.type = "Type"; + cer.error.fill(SccOk, "details"); utExit(); } diff --git a/test/unittests/ngsi/ContextElementResponse_test.cpp b/test/unittests/ngsi/ContextElementResponse_test.cpp index 6be001b674..005b800bb9 100644 --- a/test/unittests/ngsi/ContextElementResponse_test.cpp +++ b/test/unittests/ngsi/ContextElementResponse_test.cpp @@ -31,57 +31,28 @@ -/* **************************************************************************** -* -* check - -*/ -TEST(ContextElementResponse, check) -{ - ContextElementResponse cer; - std::string out; - - utInit(); - - out = cer.check(V1, UpdateContext, "", 0); - EXPECT_STREQ("empty entityId:id", out.c_str()); - - cer.entity.id = "ID"; - cer.entity.type = "Type"; - cer.entity.isPattern = "false"; - - out = cer.check(V1, UpdateContext, "", 0); - EXPECT_STREQ("no code", out.c_str()); - - cer.statusCode.fill(SccOk, "details"); - out = cer.check(V1, UpdateContext, "", 0); - EXPECT_STREQ("OK", out.c_str()); - - utExit(); -} - - - /* **************************************************************************** * * render - */ TEST(ContextElementResponse, render) { + utInit(); + ContextElementResponse cer; const char* outfile = "ngsi.contextElementResponse.render.middle.json"; std::string out; - utInit(); - - cer.entity.id = "ID"; - cer.entity.type = "Type"; - cer.entity.isPattern = "false"; + std::vector emptyV; + + cer.entity.entityId.id = "ID"; + cer.entity.entityId.type = "Type"; - cer.statusCode.fill(SccOk, "details"); + cer.error.fill(SccOk, "details"); - out = cer.toJsonV1(false, UpdateContextElement, false, false); - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile)) << "Error getting test data from '" << outfile << "'"; - EXPECT_STREQ(expectedBuf, out.c_str()); + out = cer.toJson(NGSI_V2_NORMALIZED, emptyV, false, emptyV, NULL);; + EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile)) << "Error getting test data from '" << outfile << "'"; + EXPECT_STREQ(expectedBuf, out.c_str()); - utExit(); + utExit(); } diff --git a/test/unittests/ngsi/ContextRegistrationAttributeVector_test.cpp b/test/unittests/ngsi/ContextRegistrationAttributeVector_test.cpp deleted file mode 100644 index d940170c9e..0000000000 --- a/test/unittests/ngsi/ContextRegistrationAttributeVector_test.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "ngsi/ContextRegistrationAttributeVector.h" - -#include "unittest.h" - - - -/* **************************************************************************** -* -* render - -*/ -TEST(ContextRegistrationAttributeVector, render) -{ - ContextRegistrationAttributeVector crav; - ContextRegistrationAttribute cra("name", "type"); - ContextRegistrationAttribute cra2("name2", "type2"); - std::string out; - const char* outfile1 = "ngsi.contextRegistrationAttributeVector.render1.middle.json"; - const char* outfile2 = "ngsi.contextRegistrationAttributeVector.render2.middle.json"; - - utInit(); - - out = crav.toJsonV1(false); - EXPECT_STREQ("", out.c_str()); - - out = crav.toJsonV1(false); - EXPECT_STREQ("", out.c_str()); - - crav.push_back(&cra); - out = crav.toJsonV1(false); - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'"; - EXPECT_STREQ(expectedBuf, out.c_str()); - - crav.push_back(&cra2); - out = crav.toJsonV1(false); - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile2)) << "Error getting test data from '" << outfile2 << "'"; - EXPECT_STREQ(expectedBuf, out.c_str()); - - utExit(); -} diff --git a/test/unittests/ngsi/ContextRegistrationAttribute_test.cpp b/test/unittests/ngsi/ContextRegistrationAttribute_test.cpp deleted file mode 100644 index 202711f378..0000000000 --- a/test/unittests/ngsi/ContextRegistrationAttribute_test.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "ngsi/ContextRegistrationAttribute.h" - -#include "unittest.h" - - - -/* **************************************************************************** -* -* render - -*/ -TEST(ContextRegistrationAttribute, render) -{ - ContextRegistrationAttribute cra("name", "type"); - std::string out; - const char* outfile1 = "ngsi.contextRegistrationAttribute.render.middle.json"; - - utInit(); - - out = cra.toJsonV1(false); - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'"; - EXPECT_STREQ(expectedBuf, out.c_str()); - - utExit(); -} diff --git a/test/unittests/ngsi/ContextRegistrationResponseVector_test.cpp b/test/unittests/ngsi/ContextRegistrationResponseVector_test.cpp deleted file mode 100644 index 0437aef7c9..0000000000 --- a/test/unittests/ngsi/ContextRegistrationResponseVector_test.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include "gtest/gtest.h" - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "ngsi/ContextRegistrationResponseVector.h" - - - -/* **************************************************************************** -* -* all - -*/ -TEST(ContextRegistrationResponseVector, all) -{ - ContextRegistrationResponse crr; - ContextRegistrationResponseVector crrV; - std::string rendered; - - crr.contextRegistration.providingApplication.set("10.1.1.1://nada"); - - // Empty vector gives empty rendered result - rendered = crrV.toJsonV1(false); - EXPECT_EQ("", rendered); - - crrV.push_back(&crr); - - // check OK - rendered = crrV.check(V1, RegisterContext, "", 0); - EXPECT_EQ("OK", rendered); - - // Now telling the crr that we've found an instance of ' - // but without any entities inside the vector - crr.contextRegistration.entityIdVectorPresent = true; - rendered = crrV.check(V1, RegisterContext, "", 0); - EXPECT_EQ("Empty entityIdVector", rendered); - - EntityId eId; // Empty ID - - crr.contextRegistration.entityIdVector.push_back(&eId); - rendered = crrV.check(V1, RegisterContext, "", 0); - EXPECT_EQ("empty entityId:id", rendered); -} diff --git a/test/unittests/ngsi/ContextRegistrationResponse_test.cpp b/test/unittests/ngsi/ContextRegistrationResponse_test.cpp deleted file mode 100644 index 97c1f61dec..0000000000 --- a/test/unittests/ngsi/ContextRegistrationResponse_test.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "ngsi/ContextRegistrationResponse.h" - -#include "unittest.h" - - - -/* **************************************************************************** -* -* render - -*/ -TEST(ContextRegistrationResponse, render) -{ - ContextRegistrationResponse crr; - std::string rendered; - const char* outfile1 = "ngsi.contextRegistrationResponse.renderOk.middle.json"; - const char* outfile2 = "ngsi.contextRegistrationResponse.renderError.middle.json"; - - utInit(); - - crr.errorCode.fill(SccNone); - rendered = crr.toJsonV1(false); - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'"; - EXPECT_STREQ(expectedBuf, rendered.c_str()); - - crr.errorCode.fill(SccBadRequest); - rendered = crr.toJsonV1(false); - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile2)) << "Error getting test data from '" << outfile2 << "'"; - EXPECT_STREQ(expectedBuf, rendered.c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* check - -*/ -TEST(ContextRegistrationResponse, check) -{ - ContextRegistrationResponse crr; - std::string checked; - std::string expected = "no providing application"; - - utInit(); - - checked = crr.check(V1, RegisterContext, "", 0); - EXPECT_STREQ(expected.c_str(), checked.c_str()); - - utExit(); -} diff --git a/test/unittests/ngsi/ContextRegistrationVector_test.cpp b/test/unittests/ngsi/ContextRegistrationVector_test.cpp deleted file mode 100644 index 675ae99ba4..0000000000 --- a/test/unittests/ngsi/ContextRegistrationVector_test.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "ngsi/ContextRegistrationVector.h" - -#include "unittest.h" - - - -/* **************************************************************************** -* -* render - -* -*/ -TEST(ContextRegistrationVector, render) -{ - ContextRegistrationVector crv; - ContextRegistration cr; - std::string out; - - utInit(); - - out = crv.toJsonV1(false); - EXPECT_STREQ("", out.c_str()); - - utExit(); -} diff --git a/test/unittests/ngsi/Duration_test.cpp b/test/unittests/ngsi/Duration_test.cpp deleted file mode 100644 index 429deb0f10..0000000000 --- a/test/unittests/ngsi/Duration_test.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include "gtest/gtest.h" - -#include "ngsi/Duration.h" - - - -/* **************************************************************************** -* -* check - -*/ -TEST(Duration, check) -{ - Duration d; - std::string out; - - out = d.check(); - EXPECT_STREQ("OK", out.c_str()); - - d.set("PT1S"); - out = d.check(); - EXPECT_STREQ("OK", out.c_str()); - - d.set("PT1A"); - out = d.check(); - EXPECT_STREQ("syntax error in duration string", out.c_str()); -} - - - -/* **************************************************************************** -* -* isEmpty - -*/ -TEST(Duration, isEmpty) -{ - Duration d; - - d.set(""); - EXPECT_EQ(true, d.isEmpty()); -} diff --git a/test/unittests/ngsi/EntityId_test.cpp b/test/unittests/ngsi/EntityId_test.cpp index 467dc2f4a6..c0d278914d 100644 --- a/test/unittests/ngsi/EntityId_test.cpp +++ b/test/unittests/ngsi/EntityId_test.cpp @@ -34,13 +34,13 @@ */ TEST(EntityId, render) { + utInit(); + EntityId eId; std::string out; - const char* outfile1 = "ngsi.entityId.render.middle.json"; - - utInit(); + const char* outfile1 = "ngsi.entityId.render.middle.json"; - out = eId.toJsonV1(false); + out = eId.toJson(); EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'"; EXPECT_STREQ(expectedBuf, out.c_str()); diff --git a/test/unittests/ngsi/ErrorCode_test.cpp b/test/unittests/ngsi/ErrorCode_test.cpp index 00ab4da52d..c2148c6d52 100644 --- a/test/unittests/ngsi/ErrorCode_test.cpp +++ b/test/unittests/ngsi/ErrorCode_test.cpp @@ -34,12 +34,12 @@ */ TEST(ErrorCode, render) { + utInit(); + ErrorCode e1; std::string out; const char* outfile1 = "ngsi.errorCode.render1.middle.json"; - utInit(); - out = e1.render(); EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'"; EXPECT_STREQ(expectedBuf, out.c_str()); @@ -55,6 +55,8 @@ TEST(ErrorCode, render) */ TEST(ErrorCode, check) { + utInit(); + ErrorCode e1(0, "REASON", "DETAILS"); ErrorCode e2(200, "", "DETAILS"); ErrorCode e3(200, "REASON", "DETAILS"); @@ -63,8 +65,6 @@ TEST(ErrorCode, check) std::string expected2 = "no reason phrase"; std::string expected3 = "OK"; - utInit(); - rendered = e1.check(RegisterContext, "", "", 0); EXPECT_STREQ(expected1.c_str(), rendered.c_str()); diff --git a/test/unittests/ngsi/MetadataVector_test.cpp b/test/unittests/ngsi/MetadataVector_test.cpp index 0b4a36400c..95fcba09fa 100644 --- a/test/unittests/ngsi/MetadataVector_test.cpp +++ b/test/unittests/ngsi/MetadataVector_test.cpp @@ -34,6 +34,8 @@ */ TEST(MetadataVector, render) { + utInit(); + Metadata m("Name", "Type", "Value"); Metadata m2("Name2", "Type2", "Value2"); MetadataVector mV; @@ -41,22 +43,20 @@ TEST(MetadataVector, render) const char* outfile2 = "ngsi.metadataVector.render3.middle.json"; std::string out; - utInit(); - mV.push_back(&m); std::vector metadataFilter; metadataFilter.push_back(&m); - out = mV.toJsonV1(metadataFilter, false); + out = mV.toJson(metadataFilter); EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'"; EXPECT_STREQ(expectedBuf, out.c_str()); metadataFilter.push_back(&m2); mV.push_back(&m2); - out = mV.toJsonV1(metadataFilter, false); + out = mV.toJson(metadataFilter); EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile2)) << "Error getting test data from '" << outfile2 << "'"; EXPECT_STREQ(expectedBuf, out.c_str()); diff --git a/test/unittests/ngsi/Metadata_test.cpp b/test/unittests/ngsi/Metadata_test.cpp index 46ed9c2ca8..a3a6a90c08 100644 --- a/test/unittests/ngsi/Metadata_test.cpp +++ b/test/unittests/ngsi/Metadata_test.cpp @@ -34,12 +34,12 @@ */ TEST(Metadata, constructor) { + utInit(); + Metadata m1; Metadata m2("n2", "t2", "v2"); Metadata m3(&m2); - utInit(); - EXPECT_EQ("", m1.name); EXPECT_EQ("n2", m2.name); EXPECT_EQ("n2", m3.name); @@ -56,6 +56,8 @@ TEST(Metadata, constructor) */ TEST(Metadata, render) { + utInit(); + std::string out; Metadata m1; Metadata m2("Name", "Integer", "19"); @@ -63,13 +65,11 @@ TEST(Metadata, render) const char* outfile1 = "ngsi.metdata.render1.middle.json"; const char* outfile2 = "ngsi.metdata.render2.middle.json"; - utInit(); - - out = m1.toJsonV1(false); + out = m1.toJson(); EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'"; EXPECT_STREQ(expectedBuf, out.c_str()); - out = m2.toJsonV1(false); + out = m2.toJson(); EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile2)) << "Error getting test data from '" << outfile2 << "'"; EXPECT_STREQ(expectedBuf, out.c_str()); @@ -91,13 +91,13 @@ TEST(Metadata, check) utInit(); - checked = m1.check(V1); - EXPECT_STREQ("missing metadata name", checked.c_str()); + checked = m1.check(); + EXPECT_STREQ("metadata name length: 0, min length supported: 1", checked.c_str()); - checked = m2.check(V1); - EXPECT_STREQ("missing metadata value", checked.c_str()); + checked = m2.check(); + EXPECT_STREQ("OK", checked.c_str()); - checked = m3.check(V1); + checked = m3.check(); EXPECT_STREQ("OK", checked.c_str()); utExit(); diff --git a/test/unittests/ngsi/NotifyConditionVector_test.cpp b/test/unittests/ngsi/NotifyConditionVector_test.cpp deleted file mode 100644 index 7b1cf7f5b8..0000000000 --- a/test/unittests/ngsi/NotifyConditionVector_test.cpp +++ /dev/null @@ -1,133 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "ngsi/NotifyConditionVector.h" - -#include "unittest.h" - - - -/* **************************************************************************** -* -* render - -*/ -TEST(NotifyConditionVector, render) -{ - NotifyCondition* ncP = new NotifyCondition(); - NotifyConditionVector ncV; - std::string out; - const char* outfile1 = "ngsi.notifyConditionVector.render.middle.json"; - - utInit(); - - out = ncV.toJsonV1(false); - EXPECT_STREQ("", out.c_str()); - - ncP->type = "Type"; - ncV.push_back(ncP); - - out = ncV.toJsonV1(false); - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'"; - EXPECT_STREQ(expectedBuf, out.c_str()); - - ncV.release(); - - out = ncV.toJsonV1(false); - EXPECT_STREQ("", out.c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* check - -*/ -TEST(NotifyConditionVector, check) -{ - NotifyCondition nc; - NotifyConditionVector ncV; - std::string checked; - std::string expected2 = "invalid notify condition type: /Type/"; - std::string expected3 = "empty type for NotifyCondition"; - - utInit(); - - checked = ncV.check(RegisterContext, "", 0); - EXPECT_STREQ("OK", checked.c_str()); - - nc.type = "Type"; - ncV.push_back(&nc); - - checked = ncV.check(RegisterContext, "", 0); - EXPECT_STREQ(expected2.c_str(), checked.c_str()); - - nc.type = ""; - checked = ncV.check(RegisterContext, "", 0); - EXPECT_STREQ(expected3.c_str(), checked.c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* get - -*/ -TEST(NotifyConditionVector, get) -{ - NotifyCondition nc0; - NotifyCondition nc1; - NotifyCondition nc2; - NotifyConditionVector ncV; - NotifyCondition* ncP; - - utInit(); - - nc0.type = "Type0"; - nc1.type = "Type1"; - nc2.type = "Type2"; - - ncV.push_back(&nc0); - ncV.push_back(&nc1); - ncV.push_back(&nc2); - - ncP = ncV[0]; - EXPECT_STREQ("Type0", ncP->type.c_str()); - - ncP = ncV[1]; - EXPECT_STREQ("Type1", ncP->type.c_str()); - - ncP = ncV[2]; - EXPECT_STREQ("Type2", ncP->type.c_str()); - - EXPECT_EQ(3, ncV.size()); - - utExit(); -} diff --git a/test/unittests/ngsi/NotifyCondition_test.cpp b/test/unittests/ngsi/NotifyCondition_test.cpp deleted file mode 100644 index 80baae1ce2..0000000000 --- a/test/unittests/ngsi/NotifyCondition_test.cpp +++ /dev/null @@ -1,94 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "ngsi/NotifyCondition.h" - -#include "unittest.h" - - - -/* **************************************************************************** -* -* Creation - -*/ -TEST(NotifyCondition, Creation) -{ - NotifyCondition nc; - - utInit(); - - nc.restriction.set("Hola"); - EXPECT_TRUE(nc.restriction.get() == "Hola"); - - utExit(); -} - - - -/* **************************************************************************** -* -* render - -*/ -TEST(NotifyCondition, render) -{ - NotifyCondition nc; - const char* outfile1 = "ngsi.notifyCondition.render.middle.json"; - std::string out; - - utInit(); - - out = nc.toJsonV1(false); - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'"; - EXPECT_STREQ(expectedBuf, out.c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* check - -*/ -TEST(NotifyCondition, check) -{ - NotifyCondition nc; - std::string checked; - - utInit(); - - checked = nc.check(RegisterContext, "", 0); - EXPECT_STREQ("empty type for NotifyCondition", checked.c_str()); - - nc.type = "XXX"; - checked = nc.check(RegisterContext, "", 0); - EXPECT_STREQ("invalid notify condition type: /XXX/", checked.c_str()); - - nc.release(); - - utExit(); -} diff --git a/test/unittests/ngsi/Originator_test.cpp b/test/unittests/ngsi/Originator_test.cpp deleted file mode 100644 index 5c80355780..0000000000 --- a/test/unittests/ngsi/Originator_test.cpp +++ /dev/null @@ -1,124 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "ngsi/Originator.h" - -#include "unittest.h" - - - -/* **************************************************************************** -* -* check - should Originator::check always return "OK"? -*/ -TEST(Originator, check) -{ - Originator originator; - std::string checked; - - utInit(); - - checked = originator.check(); - EXPECT_STREQ("OK", checked.c_str()); - - originator.string = "String"; - - checked = originator.check(); - EXPECT_STREQ("OK", checked.c_str()); - - checked = originator.check(); - EXPECT_STREQ("OK", checked.c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* isEmptSetAndGet - -*/ -TEST(Originator, isEmptySetAndGet) -{ - Originator originator; - - utInit(); - - originator.string = ""; - EXPECT_TRUE(originator.isEmpty()); - - originator.set("STR"); - EXPECT_FALSE(originator.isEmpty()); - - EXPECT_STREQ("STR", originator.get().c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* render - -*/ -TEST(Originator, render) -{ - Originator originator; - std::string out; - const char* outfile1 = "ngsi.originator.render.middle.json"; - - utInit(); - - out = originator.toJsonV1(false); - EXPECT_STREQ("", out.c_str()); - - originator.string = "String"; - - out = originator.toJsonV1(false); - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'"; - EXPECT_STREQ(expectedBuf, out.c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* c_str - -*/ -TEST(Originator, c_str) -{ - Originator originator; - - utInit(); - - originator.set("STR"); - EXPECT_STREQ("STR", originator.c_str()); - - utExit(); -} diff --git a/test/unittests/ngsi/ProvidingApplication_test.cpp b/test/unittests/ngsi/ProvidingApplication_test.cpp deleted file mode 100644 index 467af2e78a..0000000000 --- a/test/unittests/ngsi/ProvidingApplication_test.cpp +++ /dev/null @@ -1,74 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "ngsi/ProvidingApplication.h" - -#include "unittest.h" - - - -/* **************************************************************************** -* -* render - -*/ -TEST(ProvidingApplication, render) -{ - ProvidingApplication pa; - std::string out; - const char* outfile1 = "ngsi.providingApplication.render.middle.json"; - - utInit(); - - out = pa.toJsonV1(false); - EXPECT_STREQ("", out.c_str()); - - pa.set("PA"); - - out = pa.toJsonV1(false); - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'"; - EXPECT_STREQ(expectedBuf, out.c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* c_str - -*/ -TEST(ProvidingApplication, c_str) -{ - ProvidingApplication pa; - - utInit(); - - pa.set("PA"); - EXPECT_STREQ("PA", pa.c_str()); - - utExit(); -} diff --git a/test/unittests/ngsi/Reference_test.cpp b/test/unittests/ngsi/Reference_test.cpp deleted file mode 100644 index 31e28979a1..0000000000 --- a/test/unittests/ngsi/Reference_test.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "ngsi/Reference.h" - -#include "unittest.h" - - - -/* **************************************************************************** -* -* check - should Reference::check always return "OK"? -*/ -TEST(Reference, check) -{ - Reference reference; - std::string checked; - - utInit(); - - reference.string = "http://ip:12"; - checked = reference.check(RegisterContext); - EXPECT_STREQ("OK", checked.c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* isEmptySetAndGet - -*/ -TEST(Reference, isEmptySetAndGet) -{ - Reference reference; - - utInit(); - - reference.set("REF"); - EXPECT_STREQ("REF", reference.get().c_str()); - EXPECT_FALSE(reference.isEmpty()); - - reference.set(""); - EXPECT_TRUE(reference.isEmpty()); - - utExit(); -} - - - -/* **************************************************************************** -* -* render - -*/ -TEST(Reference, render) -{ - Reference reference; - std::string out; - const char* outfile1 = "ngsi.reference.render.middle.json"; - - utInit(); - - reference .set(""); - out = reference.toJsonV1(false); - EXPECT_STREQ("", out.c_str()); - - reference .set("REF"); - - out = reference.toJsonV1(false); - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'"; - EXPECT_STREQ(expectedBuf, out.c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* c_str - -*/ -TEST(Reference, c_str) -{ - Reference reference; - - utInit(); - - reference.set("STR"); - EXPECT_STREQ("STR", reference.c_str()); - - utExit(); -} diff --git a/test/unittests/ngsi/Request_test.cpp b/test/unittests/ngsi/Request_test.cpp index d63d6324a1..d873cd8b7f 100644 --- a/test/unittests/ngsi/Request_test.cpp +++ b/test/unittests/ngsi/Request_test.cpp @@ -45,34 +45,7 @@ TEST(Request, requestType) { Req req[] = { - { RegisterContext, "RegisterContextRequest" }, - { DiscoverContextAvailability, "DiscoverContextAvailabilityRequest" }, - - { QueryContext, "QueryContextRequest" }, - { SubscribeContext, "SubscribeContextRequest" }, - { UpdateContextSubscription, "UpdateContextSubscriptionRequest" }, - { UnsubscribeContext, "UnsubscribeContextRequest" }, { NotifyContext, "NotifyContextRequest" }, - { UpdateContext, "UpdateContextRequest" }, - - { ContextEntitiesByEntityId, "ContextEntitiesByEntityId" }, - { ContextEntityAttributes, "ContextEntityAttributes" }, - { ContextEntityTypes, "ContextEntityTypes" }, - { ContextEntityTypeAttributeContainer, "ContextEntityTypeAttributeContainer" }, - { ContextEntityTypeAttribute, "ContextEntityTypeAttribute" }, - { EntityByIdAttributeByName, "EntityByIdAttributeByName" }, - - { IndividualContextEntity, "IndividualContextEntity" }, - { IndividualContextEntityAttributes, "IndividualContextEntityAttributes" }, - { IndividualContextEntityAttribute, "IndividualContextEntityAttribute" }, - { AttributeValueInstance, "AttributeValueInstance" }, - { UpdateContextElement, "UpdateContextElement" }, - { AppendContextElement, "AppendContextElement" }, - { UpdateContextAttribute, "UpdateContextAttribute" }, - { Ngsi10ContextEntityTypes, "Ngsi10ContextEntityTypes" }, - { Ngsi10ContextEntityTypesAttributeContainer, "Ngsi10ContextEntityTypesAttributeContainer" }, - { Ngsi10ContextEntityTypesAttribute, "Ngsi10ContextEntityTypesAttribute" }, - { Ngsi10SubscriptionsConvOp, "Ngsi10SubscriptionsConvOp" }, { LogTraceRequest, "LogTrace" }, { LogLevelRequest, "LogLevel" }, @@ -80,15 +53,6 @@ TEST(Request, requestType) { StatisticsRequest, "Statistics" }, { ExitRequest, "Exit" }, { LeakRequest, "Leak" }, - { RegisterResponse, "RegisterContextResponse" }, - - { RtSubscribeResponse, "SubscribeResponse" }, - { RtSubscribeError, "SubscribeError" }, - - { EntityTypes, "EntityTypes" }, - { AttributesForEntityType, "AttributesForEntityType" }, - { RtEntityTypesResponse, "EntityTypesResponse" }, - { RtAttributesForEntityTypeResponse, "AttributesForEntityTypeResponse" }, { InvalidRequest, "InvalidRequest" }, diff --git a/test/unittests/ngsi/RestrictionString_test.cpp b/test/unittests/ngsi/RestrictionString_test.cpp deleted file mode 100644 index a785b52802..0000000000 --- a/test/unittests/ngsi/RestrictionString_test.cpp +++ /dev/null @@ -1,120 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "ngsi/RestrictionString.h" - -#include "unittest.h" - - -/* **************************************************************************** -* -* check - should RestrictionString::check always return "OK"? -*/ -TEST(RestrictionString, check) -{ - RestrictionString restrictionString; - std::string checked; - - utInit(); - - checked = restrictionString.check(); - EXPECT_STREQ("OK", checked.c_str()); - - restrictionString.string = "String"; - - checked = restrictionString.check(); - EXPECT_STREQ("OK", checked.c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* isEmptSetAndGet - -*/ -TEST(RestrictionString, isEmptySetAndGet) -{ - RestrictionString restrictionString; - - utInit(); - - restrictionString.string = ""; - EXPECT_TRUE(restrictionString.isEmpty()); - - restrictionString.set("STR"); - EXPECT_FALSE(restrictionString.isEmpty()); - - EXPECT_STREQ("STR", restrictionString.get().c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* render - -*/ -TEST(RestrictionString, render) -{ - RestrictionString restrictionString; - std::string out; - const char* outfile1 = "ngsi.restrictionString.render.middle.json"; - - utInit(); - - out = restrictionString.toJsonV1(false); - EXPECT_STREQ("", out.c_str()); - - restrictionString.string = "String"; - - out = restrictionString.toJsonV1(false); - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'"; - EXPECT_STREQ(expectedBuf, out.c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* c_str - -*/ -TEST(RestrictionString, c_str) -{ - RestrictionString restrictionString; - - utInit(); - - restrictionString.set("STR"); - EXPECT_STREQ("STR", restrictionString.c_str()); - - utExit(); -} diff --git a/test/unittests/ngsi/Restriction_test.cpp b/test/unittests/ngsi/Restriction_test.cpp deleted file mode 100644 index f97894902f..0000000000 --- a/test/unittests/ngsi/Restriction_test.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include "gtest/gtest.h" - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "ngsi/Restriction.h" -#include "ngsi/Scope.h" - - - -/* **************************************************************************** -* -* check - should Restriction::check always return "OK"? -*/ -TEST(Restriction, check) -{ - Restriction restriction; - std::string checked; - std::string expected0 = "OK"; - std::string expected1 = "empty restriction"; - std::string expected2 = "Empty type in restriction scope"; - std::string expected3 = "OK"; - Scope* scopeP = new Scope("", "Value"); - - checked = restriction.check(0); - EXPECT_EQ(expected0, checked); - - checked = restriction.check(1); - EXPECT_EQ(expected1, checked); - - restriction.scopeVector.push_back(scopeP); - checked = restriction.check(1); - EXPECT_EQ(expected2, checked); - - scopeP->type = "Type"; - checked = restriction.check(1); - EXPECT_EQ(expected3, checked); -} - - - -/* **************************************************************************** -* -* render - -*/ -TEST(Restriction, render) -{ - Restriction restriction; - std::string rendered; - std::string expected = ""; - - rendered = restriction.toJsonV1(0, false); - EXPECT_STREQ(expected.c_str(), rendered.c_str()); -} diff --git a/test/unittests/ngsi/ScopeVector_test.cpp b/test/unittests/ngsi/ScopeVector_test.cpp index 4c7e078fc4..cc9cc887bc 100644 --- a/test/unittests/ngsi/ScopeVector_test.cpp +++ b/test/unittests/ngsi/ScopeVector_test.cpp @@ -29,77 +29,20 @@ -/* **************************************************************************** -* -* renderAndRelease - -* -*/ -TEST(ScopeVector, renderAndRelease) -{ - Scope* s = new Scope("Type", "Value"); - ScopeVector sV; - std::string out; - - utInit(); - - out = sV.toJsonV1(false); - EXPECT_STREQ("", out.c_str()); - - sV.push_back(s); - - out = sV.toJsonV1(false); - - EXPECT_EQ(sV.size(), 1); - sV.release(); - EXPECT_EQ(sV.size(), 0); - - utExit(); -} - - - -/* **************************************************************************** -* -* check - -*/ -TEST(ScopeVector, check) -{ - Scope* s1 = new Scope("Type", "Value"); - Scope* s2 = new Scope("", "Value"); - ScopeVector sV; - std::string expected1 = "OK"; - std::string expected2 = "Empty type in restriction scope"; - std::string rendered; - - utInit(); - - sV.push_back(s1); - rendered = sV.check(); - EXPECT_STREQ(expected1.c_str(), rendered.c_str()); - - sV.push_back(s2); - rendered = sV.check(); - EXPECT_STREQ(expected2.c_str(), rendered.c_str()); - - utExit(); -} - - - /* **************************************************************************** * * getAndSize - */ TEST(ScopeVector, getAndSize) { + utInit(); + ScopeVector sV; Scope scope0("Type", "Value0"); Scope scope1("Type", "Value1"); Scope scope2("Type", "Value2"); Scope* scopeP; - utInit(); - sV.push_back(&scope0); sV.push_back(&scope1); sV.push_back(&scope2); diff --git a/test/unittests/ngsi/Scope_test.cpp b/test/unittests/ngsi/Scope_test.cpp deleted file mode 100644 index 4220fd1786..0000000000 --- a/test/unittests/ngsi/Scope_test.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "ngsi/Scope.h" - -#include "unittest.h" - - - -/* **************************************************************************** -* -* render - -*/ -TEST(Scope, render) -{ - Scope scope("Type", "Value"); - std::string out; - const char* outfile1 = "ngsi.scope.render.middle.json"; - - utInit(); - - out = scope.toJsonV1(false); - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'"; - EXPECT_STREQ(expectedBuf, out.c_str()); - - scope.release(); - - utExit(); -} - - - -/* **************************************************************************** -* -* check - should Scope::check always return "OK"? -*/ -TEST(Scope, check) -{ - Scope scope; - Scope scope1("", "value"); - Scope scope2("type", ""); - Scope scope3("type", "value"); - std::string checked; - std::string expected = "Empty type in restriction scope"; - std::string expected1 = "Empty type in restriction scope"; - std::string expected2 = "Empty value in restriction scope"; - std::string expected3 = "OK"; - - utInit(); - - checked = scope.check(); - EXPECT_STREQ(checked.c_str(), expected.c_str()); - - checked = scope1.check(); - EXPECT_STREQ(checked.c_str(), expected1.c_str()); - - checked = scope2.check(); - EXPECT_STREQ(checked.c_str(), expected2.c_str()); - - checked = scope3.check(); - EXPECT_STREQ(checked.c_str(), expected3.c_str()); - - utExit(); -} diff --git a/test/unittests/ngsi/StatusCode_test.cpp b/test/unittests/ngsi/StatusCode_test.cpp deleted file mode 100644 index d6e1e4b002..0000000000 --- a/test/unittests/ngsi/StatusCode_test.cpp +++ /dev/null @@ -1,114 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "ngsi/StatusCode.h" - -#include "unittest.h" - - - -/* **************************************************************************** -* -* render - -*/ -TEST(StatusCode, render) -{ - StatusCode sc1; - StatusCode sc2(SccOk, "DETAILS"); - std::string out; - const char* outfile1 = "ngsi.statusCode.render4.middle.json"; - - utInit(); - - out = sc2.toJsonV1(false); - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'"; - EXPECT_STREQ(expectedBuf, out.c_str()); - - sc1.release(); // just to exercise the code ... - - utExit(); -} - - - -/* **************************************************************************** -* -* fill - -*/ -TEST(StatusCode, fill) -{ - StatusCode sc; - StatusCode sc2(SccOk, "Details"); - StatusCode ec(SccBadRequest, "Very bad request :-)"); - std::string out; - - utInit(); - - sc.fill(SccForbidden, "D"); - EXPECT_EQ(sc.code, SccForbidden); - EXPECT_STREQ(sc.reasonPhrase.c_str(), "Forbidden"); - EXPECT_STREQ(sc.details.c_str(), "D"); - - sc.fill(&sc2); - EXPECT_EQ(sc.code, SccOk); - EXPECT_STREQ(sc.reasonPhrase.c_str(), "OK"); - EXPECT_STREQ(sc.details.c_str(), "Details"); - - sc.fill(&ec); - EXPECT_EQ(sc.code, SccBadRequest); - EXPECT_STREQ(sc.reasonPhrase.c_str(), "Bad Request"); - EXPECT_STREQ(sc.details.c_str(), "Very bad request :-)"); - - utExit(); -} - - - -/* **************************************************************************** -* -* check - -*/ -TEST(StatusCode, check) -{ - StatusCode sc(SccOk, ""); - std::string out; - - utInit(); - - out = sc.check(); - EXPECT_STREQ("OK", out.c_str()); - - sc.fill(SccNone, "YYY"); - out = sc.check(); - EXPECT_STREQ("no code", out.c_str()); - - sc.fill(SccOk, "YYY"); - out = sc.check(); - EXPECT_STREQ("OK", out.c_str()); - - utExit(); -} diff --git a/test/unittests/ngsi/SubscribeError_test.cpp b/test/unittests/ngsi/SubscribeError_test.cpp deleted file mode 100644 index b1c4845553..0000000000 --- a/test/unittests/ngsi/SubscribeError_test.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "ngsi/SubscribeError.h" - -#include "unittest.h" - - - -/* **************************************************************************** -* -* render - -*/ -TEST(SubscribeError, render) -{ - SubscribeError se; - std::string out; - const char* outfile1 = "ngsi.subscribeError.render1.middle.json"; - const char* outfile2 = "ngsi.subscribeError.render2.middle.json"; - - utInit(); - - se.subscriptionId.set("SUB_123"); - se.errorCode.fill(SccBadRequest, "detail"); - - out = se.toJsonV1(RegisterContext, false); - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'"; - EXPECT_STREQ(expectedBuf, out.c_str()); - - out = se.toJsonV1(SubscribeContext, false); - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile2)) << "Error getting test data from '" << outfile2 << "'"; - EXPECT_STREQ(expectedBuf, out.c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* check - -*/ -TEST(SubscribeError, check) -{ - SubscribeError se; - std::string checked; - - utInit(); - - checked = se.check(); - EXPECT_STREQ("OK", checked.c_str()); - - utExit(); -} diff --git a/test/unittests/ngsi/SubscriptionId_test.cpp b/test/unittests/ngsi/SubscriptionId_test.cpp deleted file mode 100644 index 0f36fbe9ab..0000000000 --- a/test/unittests/ngsi/SubscriptionId_test.cpp +++ /dev/null @@ -1,126 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "ngsi/SubscriptionId.h" - -#include "unittest.h" - - - -/* **************************************************************************** -* -* constructors - -*/ -TEST(SubscriptionId, constructors) -{ - SubscriptionId s1; - SubscriptionId s2("subId"); - - utInit(); - - EXPECT_EQ("", s1.string); - EXPECT_EQ("subId", s2.string); - - utExit(); -} - - - -/* **************************************************************************** -* -* check - -*/ -TEST(SubscriptionId, check) -{ - SubscriptionId sId; - std::string checked; - - utInit(); - - sId.set("SUB_123"); - checked = sId.check(); - EXPECT_STREQ("bad length - 24 chars expected", checked.c_str()); - - sId.set("SUB_12345678901234567890"); - checked = sId.check(); - EXPECT_STREQ("invalid char in ID string", checked.c_str()); - - sId.set("012345678901234567890123"); - checked = sId.check(); - EXPECT_STREQ("OK", checked.c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* setGetAndIsEmpty - -*/ -TEST(SubscriptionId, setGetAndIsEmpty) -{ - SubscriptionId sId; - std::string out; - - utInit(); - - sId.set("SUB_123"); - out = sId.get(); - EXPECT_STREQ("SUB_123", out.c_str()); - - EXPECT_FALSE(sId.isEmpty()); - sId.set(""); - EXPECT_TRUE(sId.isEmpty()); - - utExit(); -} - - - -/* **************************************************************************** -* -* render -*/ -TEST(SubscriptionId, render) -{ - SubscriptionId sId; - std::string out; - const char* outfile1 = "ngsi.subscriptionId.render2.middle.json"; - - utInit(); - - sId.set("012345012345012345012345"); - - out = sId.toJsonV1(UnsubscribeContext, false); - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'"; - EXPECT_STREQ(expectedBuf, out.c_str()); - - sId.release(); // just to exercise the code - - utExit(); -} diff --git a/test/unittests/ngsi/Throttling_test.cpp b/test/unittests/ngsi/Throttling_test.cpp deleted file mode 100644 index 232dfa1495..0000000000 --- a/test/unittests/ngsi/Throttling_test.cpp +++ /dev/null @@ -1,111 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "ngsi/Throttling.h" - -#include "unittest.h" - - - -/* **************************************************************************** -* -* setGetIsEmptyAndParse - -*/ -TEST(Throttling, setGetIsEmptyAndParse) -{ - Throttling t; - - utInit(); - - t.set("PT5S"); - EXPECT_STREQ("PT5S", t.get().c_str()); - EXPECT_EQ(5, t.parse()); - EXPECT_FALSE(t.isEmpty()); - - t.set(""); - EXPECT_TRUE(t.isEmpty()); - - utExit(); -} - - - -/* **************************************************************************** -* -* check - -*/ -TEST(Throttling, check) -{ - Throttling t; - std::string checked; - - utInit(); - - t.set(""); - checked = t.check(); - EXPECT_EQ("OK", checked); - - t.set("PT5S"); - checked = t.check(); - EXPECT_EQ("OK", checked); - - t.set("xxxPT5S"); - checked = t.check(); - EXPECT_EQ("syntax error in throttling string", checked); - - utExit(); -} - - - -/* **************************************************************************** -* -* render - -*/ -TEST(Throttling, render) -{ - Throttling t; - std::string out; - const char* outfile1 = "ngsi.throttling.render.middle.json"; - - utInit(); - - t.set(""); - out = t.toJsonV1(false); - EXPECT_STREQ("", out.c_str()); - - out = t.toJsonV1(false); - EXPECT_STREQ("", out.c_str()); - - t.set("PT1S"); - - out = t.toJsonV1(false); - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'"; - EXPECT_STREQ(expectedBuf, out.c_str()); - - utExit(); -} diff --git a/test/unittests/ngsi10/NotifyContextRequest_test.cpp b/test/unittests/ngsi10/NotifyContextRequest_test.cpp index 24ed7a9e59..e19fa587d2 100644 --- a/test/unittests/ngsi10/NotifyContextRequest_test.cpp +++ b/test/unittests/ngsi10/NotifyContextRequest_test.cpp @@ -25,10 +25,8 @@ #include "logMsg/logMsg.h" #include "logMsg/traceLevels.h" -#include "jsonParse/jsonRequest.h" - #include "ngsi/ParseData.h" -#include "ngsi/StatusCode.h" +#include "rest/OrionError.h" #include "ngsi10/NotifyContextRequest.h" #include "ngsi10/NotifyContextResponse.h" @@ -36,145 +34,54 @@ -/* **************************************************************************** -* -* json_ok - -*/ -TEST(NotifyContextRequest, json_ok) -{ - ParseData reqData; - ConnectionInfo ci("", "POST", "1.1"); - NotifyContextRequest* ncrP = &reqData.ncr.res; - const char* infile = "notifyContextRequest_ok.json"; - const char* outfile = "ngsi10.notifyContextRequest_ok.expected1.valid.json"; - std::string rendered; - - utInit(); - - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), infile)) << "Error getting test data from '" << infile << "'"; - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - lmTraceLevelSet(LmtDump, true); - std::string result = jsonTreat(testBuf, &ci, &reqData, NotifyContext, NULL); - EXPECT_EQ("OK", result); - lmTraceLevelSet(LmtDump, false); - - // - // With the data obtained, render, present and release methods are exercised - // - std::vector emptyV; - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile)) << "Error getting test data from '" << outfile << "'"; - rendered = ncrP->toJsonV1(false, emptyV, false, emptyV); - EXPECT_STREQ(expectedBuf, rendered.c_str()); - - ncrP->release(); - - utExit(); -} - - - -/* **************************************************************************** -* -* json_badIsPattern - -*/ -TEST(NotifyContextRequest, json_badIsPattern) -{ - ParseData reqData; - ConnectionInfo ci("", "POST", "1.1"); - const char* infile = "ngsi10.notifyContextRequest.badIsPattern.invalid.json"; - const char* outfile = "ngsi10.notifyContextResponse.badIsPattern.valid.json"; - - utInit(); - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), infile)) << "Error getting test data from '" << infile << "'"; - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile)) << "Error getting test data from '" << outfile << "'"; - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - std::string out = jsonTreat(testBuf, &ci, &reqData, NotifyContext, NULL); - EXPECT_STREQ(expectedBuf, out.c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* Constructor - -*/ -TEST(NotifyContextResponse, Constructor) -{ - StatusCode sc(SccOk, "2"); - NotifyContextResponse ncr(sc); - - utInit(); - - EXPECT_EQ(SccOk, ncr.responseCode.code); - ncr.release(); - - StatusCode ec(SccOk, "4"); - NotifyContextResponse ncr2(ec); - EXPECT_EQ(SccOk, ncr2.responseCode.code); - - utExit(); -} - - - /* **************************************************************************** * * json_render - */ TEST(NotifyContextRequest, json_render) { + utInit(); + const char* filename1 = "ngsi10.notifyContextRequest.jsonRender1.valid.json"; const char* filename2 = "ngsi10.notifyContextRequest.jsonRender2.valid.json"; const char* filename3 = "ngsi10.notifyContextRequest.jsonRender3.valid.json"; NotifyContextRequest* ncrP; ContextElementResponse* cerP; - std::string rendered; - - utInit(); + std::string rendered; // Preparation ncrP = new NotifyContextRequest(); - ncrP->subscriptionId.set("012345678901234567890123"); - ncrP->originator.set("http://www.tid.es/NotifyContextRequestUnitTest"); + ncrP->subscriptionId = "012345678901234567890123"; std::vector emptyV; // 1. Without ContextResponseList EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename1)) << "Error getting test data from '" << filename1 << "'"; - rendered = ncrP->toJsonV1(false, emptyV, false, emptyV); + rendered = ncrP->toJson(NGSI_V2_NORMALIZED, emptyV, false, emptyV, NULL); EXPECT_STREQ(expectedBuf, rendered.c_str()); // 2. With ContextResponseList cerP = new ContextElementResponse(); - cerP->entity.fill("E01", "EType", "false"); + EntityId enId1("E01", "", "EType", ""); + cerP->entity.fill(enId1); ncrP->contextElementResponseVector.push_back(cerP); - cerP->statusCode.fill(SccOk); + cerP->error.fill(SccOk); EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename2)) << "Error getting test data from '" << filename2 << "'"; - rendered = ncrP->toJsonV1(false, emptyV, false, emptyV); + rendered = ncrP->toJson(NGSI_V2_NORMALIZED, emptyV, false, emptyV, NULL); EXPECT_STREQ(expectedBuf, rendered.c_str()); // 3. ContextResponseList with two instances cerP = new ContextElementResponse(); - cerP->entity.fill("E02", "EType", "false"); + EntityId enId2("E02", "", "EType", ""); + cerP->entity.fill(enId2); ncrP->contextElementResponseVector.push_back(cerP); - cerP->statusCode.fill(SccOk); + cerP->error.fill(SccOk); EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename3)) << "Error getting test data from '" << filename3 << "'"; - rendered = ncrP->toJsonV1(false, emptyV, false, emptyV); + rendered = ncrP->toJson(NGSI_V2_NORMALIZED, emptyV, false, emptyV, NULL); EXPECT_STREQ(expectedBuf, rendered.c_str()); utExit(); diff --git a/test/unittests/ngsi10/QueryContextRequest_test.cpp b/test/unittests/ngsi10/QueryContextRequest_test.cpp deleted file mode 100644 index 373f43e305..0000000000 --- a/test/unittests/ngsi10/QueryContextRequest_test.cpp +++ /dev/null @@ -1,446 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/globals.h" -#include "ngsi/Request.h" -#include "jsonParse/jsonRequest.h" -#include "serviceRoutines/postQueryContext.h" - -#include "unittest.h" - - - -/* **************************************************************************** -* -* Tests -* - ok -* - entityIdIdAsAttribute -* - badIsPattern -* - unsupportedEntityIdAttribute -* - entityIdType -* - entityIdIsPattern -* - overwriteEntityIdType -* - overwriteEntityIdIsPattern -* - overwriteEntityIdId -* - noEntityList -* - emptyEntityList -* - emptyEntityIdId -* - noAttributeExpression -* - emptyAttributeExpression -* - emptyScopeType -* - emptyScopeValue -* - noScopeType -* - noScopeValue -* - noRestriction -* -*/ - - - -/* **************************************************************************** -* -* ok_json - -*/ -TEST(QueryContextRequest, ok_json) -{ - ParseData parseData; - ConnectionInfo ci("", "POST", "1.1"); - const char* infile = "ngsi10.queryContextRequest_ok.valid.json"; - const char* outfile = "ngsi10.queryContextRequest_ok.expected.valid.json"; - std::string rendered; - - utInit(); - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), infile)) << "Error getting test data from '" << infile << "'"; - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - lmTraceLevelSet(LmtDump, true); - std::string out = jsonTreat(testBuf, &ci, &parseData, QueryContext, NULL); - lmTraceLevelSet(LmtDump, false); - - EXPECT_EQ("OK", out) << "this test should be OK"; - - - // - // With the data obtained, render, present and release methods are exercised - // - QueryContextRequest* qcrP = &parseData.qcr.res; - - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile)) << "Error getting test data from '" << outfile << "'"; - rendered = qcrP->toJsonV1(); - EXPECT_STREQ(expectedBuf, rendered.c_str()); - - qcrP->release(); - - utExit(); -} - - - -/* **************************************************************************** -* -* badIsPattern_json - -*/ -TEST(QueryContextRequest, badIsPattern_json) -{ - ParseData parseData; - ConnectionInfo ci("", "POST", "1.1"); - const char* infile = "ngsi10.queryContextRequest.badIsPattern.invalid.json"; - const char* outfile = "ngsi10.queryContextResponse.badIsPattern.valid.json"; - - utInit(); - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), infile)) << "Error getting test data from '" << infile << "'"; - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile)) << "Error getting test data from '" << outfile << "'"; - std::string out = jsonTreat(testBuf, &ci, &parseData, QueryContext, NULL); - EXPECT_STREQ(expectedBuf, out.c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* emptyAttribute_json - -*/ -TEST(QueryContextRequest, emptyAttribute_json) -{ - ParseData parseData; - ConnectionInfo ci("", "POST", "1.1"); - const char* infile = "ngsi10.queryContextRequest.emptyAttribute.valid.json"; - const char* outfile = "ngsi10.queryContextResponse.emptyAttribute.valid.json"; - - utInit(); - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), infile)) << "Error getting test data from '" << infile << "'"; - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile)) << "Error getting test data from '" << outfile << "'"; - std::string out = jsonTreat(testBuf, &ci, &parseData, QueryContext, NULL); - EXPECT_STREQ(expectedBuf, out.c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* emptyAttributeExpression_json - -*/ -TEST(QueryContextRequest, emptyAttributeExpression_json) -{ - ParseData parseData; - ConnectionInfo ci("", "POST", "1.1"); - const char* infile = "ngsi10.queryContextRequest.emptyAttributeExpression.invalid.json"; - const char* outfile = "ngsi10.queryContextResponse.emptyAttributeExpression.valid.json"; - - utInit(); - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), infile)) << "Error getting test data from '" << infile << "'"; - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile)) << "Error getting test data from '" << outfile << "'"; - std::string out = jsonTreat(testBuf, &ci, &parseData, QueryContext, NULL); - EXPECT_STREQ(expectedBuf, out.c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* scopeGeolocationCircleOkJson - -*/ -TEST(QueryContextRequest, scopeGeolocationCircleOkJson) -{ - ParseData reqData; - const char* inFile = "ngsi10.queryContextRequest.circleOk.postponed.json"; - ConnectionInfo ci("/ngsi10/queryContext", "POST", "1.1"); - std::string out; - - utInit(); - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - out = jsonTreat(testBuf, &ci, &reqData, SubscribeContext, NULL); - EXPECT_STREQ("OK", out.c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* scopeGeolocationCircleInvertedJson - -*/ -TEST(QueryContextRequest, scopeGeolocationCircleInvertedJson) -{ - ParseData reqData; - const char* inFile = "ngsi10.queryContextRequest.circleInverted.postponed.json"; - ConnectionInfo ci("/ngsi10/queryContext", "POST", "1.1"); - std::string out; - - utInit(); - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - out = jsonTreat(testBuf, &ci, &reqData, SubscribeContext, NULL); - EXPECT_STREQ("OK", out.c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* scopeGeolocationCircleInvertedBadValueJson - -*/ -TEST(QueryContextRequest, scopeGeolocationCircleInvertedBadValueJson) -{ - ParseData reqData; - const char* inFile = "ngsi10.queryContextRequest.circleInvertedBadValue.postponed.json"; - const char* outFile = "ngsi10.queryContextRequest.circleInvertedBadValue.valid.json"; - ConnectionInfo ci("/ngsi10/queryContext", "POST", "1.1"); - std::string out; - - utInit(); - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outFile)) << "Error getting test data from '" << outFile << "'"; - out = jsonTreat(testBuf, &ci, &reqData, SubscribeContext, NULL); - EXPECT_STREQ(expectedBuf, out.c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* scopeGeolocationCircleZeroRadiusJson - -*/ -TEST(QueryContextRequest, scopeGeolocationCircleZeroRadiusJson) -{ - ParseData reqData; - const char* inFile = "ngsi10.queryContextRequest.circleZeroRadius.postponed.json"; - const char* outFile = "ngsi10.queryContextRequest.circleZeroRadius.valid.json"; - ConnectionInfo ci("/ngsi10/queryContext", "POST", "1.1"); - std::string out; - - utInit(); - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outFile)) << "Error getting test data from '" << outFile << "'"; - out = jsonTreat(testBuf, &ci, &reqData, SubscribeContext, NULL); - EXPECT_STREQ(expectedBuf, out.c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* scopeGeolocationPolygonOkJson - -*/ -TEST(QueryContextRequest, scopeGeolocationPolygonOkJson) -{ - ParseData reqData; - const char* inFile = "ngsi10.queryContextRequest.polygonOk.postponed.json"; - ConnectionInfo ci("/ngsi10/queryContext", "POST", "1.1"); - std::string result; - - utInit(); - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - result = jsonTreat(testBuf, &ci, &reqData, QueryContext, NULL); - EXPECT_STREQ("OK", result.c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* scopeGeolocationPolygonInvertedJson - -*/ -TEST(QueryContextRequest, scopeGeolocationPolygonInvertedJson) -{ - ParseData reqData; - const char* inFile = "ngsi10.queryContextRequest.polygonInverted.postponed.json"; - ConnectionInfo ci("/ngsi10/queryContext", "POST", "1.1"); - std::string result; - - utInit(); - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - result = jsonTreat(testBuf, &ci, &reqData, QueryContext, NULL); - EXPECT_STREQ("OK", result.c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* scopeGeolocationPolygonInvertedBadValueJson - -*/ -TEST(QueryContextRequest, scopeGeolocationPolygonInvertedBadValueJson) -{ - ParseData reqData; - const char* inFile = "ngsi10.queryContextRequest.polygonInvertedBadValue.postponed.json"; - const char* outfile = "ngsi10.queryContextResponse.polygonInvertedBadValue.valid.json"; - ConnectionInfo ci("/ngsi10/queryContext", "POST", "1.1"); - std::string out; - - utInit(); - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile)) << "Error getting test data from '" << outfile << "'"; - - out = jsonTreat(testBuf, &ci, &reqData, QueryContext, NULL); - EXPECT_STREQ(expectedBuf, out.c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* scopeGeolocationPolygonNoVerticesJson - -*/ -TEST(QueryContextRequest, scopeGeolocationPolygonNoVerticesJson) -{ - ParseData reqData; - const char* inFile = "ngsi10.queryContextRequest.polygonNoVertices.postponed.json"; - const char* outfile = "ngsi10.queryContextResponse.polygonNoVertices.valid.json"; - ConnectionInfo ci("/ngsi10/queryContext", "POST", "1.1"); - std::string out; - - utInit(); - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile)) << "Error getting test data from '" << outfile << "'"; - - out = jsonTreat(testBuf, &ci, &reqData, QueryContext, NULL); - EXPECT_STREQ(expectedBuf, out.c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* scopeGeolocationPolygonOneVertexJson - -*/ -TEST(QueryContextRequest, scopeGeolocationPolygonOneVertexJson) -{ - ParseData reqData; - const char* inFile = "ngsi10.queryContextRequest.polygonOneVertex.postponed.json"; - const char* outfile = "ngsi10.queryContextResponse.polygonOneVertex.valid.json"; - ConnectionInfo ci("/ngsi10/queryContext", "POST", "1.1"); - std::string out; - - utInit(); - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile)) << "Error getting test data from '" << outfile << "'"; - - out = jsonTreat(testBuf, &ci, &reqData, QueryContext, NULL); - EXPECT_STREQ(expectedBuf, out.c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* scopeGeolocationPolygonTwoVerticesJson - -*/ -TEST(QueryContextRequest, scopeGeolocationPolygonTwoVerticesJson) -{ - ParseData reqData; - const char* inFile = "ngsi10.queryContextRequest.polygonTwoVertices.postponed.json"; - const char* outfile = "ngsi10.queryContextResponse.polygonTwoVertices.valid.json"; - ConnectionInfo ci("/ngsi10/queryContext", "POST", "1.1"); - std::string out; - - utInit(); - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile)) << "Error getting test data from '" << outfile << "'"; - - out = jsonTreat(testBuf, &ci, &reqData, QueryContext, NULL); - EXPECT_STREQ(expectedBuf, out.c_str()); - - utExit(); -} diff --git a/test/unittests/ngsi10/QueryContextResponse_test.cpp b/test/unittests/ngsi10/QueryContextResponse_test.cpp deleted file mode 100644 index 8643b23496..0000000000 --- a/test/unittests/ngsi10/QueryContextResponse_test.cpp +++ /dev/null @@ -1,179 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include "gtest/gtest.h" - -#include "ngsi10/QueryContextResponse.h" - -#include "unittest.h" - - - -/* **************************************************************************** -* -* json_render - -*/ -TEST(QueryContextResponse, json_render) -{ - // FIXME P1: numbering gap, reorder - const char* filename1 = "ngsi10.queryContextResponse.jsonRender1.valid.json"; - const char* filename2 = "ngsi10.queryContextResponse.jsonRender2.valid.json"; - const char* filename3 = "ngsi10.queryContextResponse.jsonRender3.valid.json"; - const char* filename4 = "ngsi10.queryContextResponse.jsonRender4.valid.json"; - const char* filename5 = "ngsi10.queryContextResponse.jsonRender5.valid.json"; - const char* filename6 = "ngsi10.queryContextResponse.jsonRender6.valid.json"; - const char* filename7 = "ngsi10.queryContextResponse.jsonRender7.valid.json"; - const char* filename8 = "ngsi10.queryContextResponse.jsonRender8.valid.json"; - const char* filename9 = "ngsi10.queryContextResponse.jsonRender9.valid.json"; - const char* filename11 = "ngsi10.queryContextResponse.jsonRender11.valid.json"; - const char* filename12 = "ngsi10.queryContextResponse.jsonRender12.valid.json"; - const char* filename13 = "ngsi10.queryContextResponse.jsonRender13.valid.json"; - const char* filename14 = "ngsi10.queryContextResponse.jsonRender14.valid.json"; - QueryContextResponse* qcrP; - ContextElementResponse* cerP; - ContextAttribute* caP; - std::string out; - - utInit(); - - // Preparations - qcrP = new QueryContextResponse(); - - // 1. ContextElement: +entityId -contextAttributeVector - cerP = new ContextElementResponse(); - - cerP->entity.fill("E01", "EType", "false"); - cerP->statusCode.fill(SccOk); - qcrP->contextElementResponseVector.push_back(cerP); - - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename1)) << "Error getting test data from '" << filename1 << "'"; - out = qcrP->toJsonV1(false); - EXPECT_STREQ(expectedBuf, out.c_str()); - - - // 2. ContextElement: +entityId -contextAttributeVector - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename2)) << "Error getting test data from '" << filename2 << "'"; - out = qcrP->toJsonV1(false); - EXPECT_STREQ(expectedBuf, out.c_str()); - - - - // 3. ContextElement: +entityId +contextAttributeVector - caP = new ContextAttribute("ca", "string", "a context attribute"); - cerP->entity.attributeVector.push_back(caP); - - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename3)) << "Error getting test data from '" << filename3 << "'"; - out = qcrP->toJsonV1(false); - EXPECT_STREQ(expectedBuf, out.c_str()); - - - - // 4. ContextElement: +entityId +contextAttributeVector - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename4)) << "Error getting test data from '" << filename4 << "'"; - out = qcrP->toJsonV1(false); - EXPECT_STREQ(expectedBuf, out.c_str()); - - - - // 5. ContextElement: +entityId -contextAttributeVector - cerP->entity.attributeVector.release(); - - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename5)) << "Error getting test data from '" << filename5 << "'"; - out = qcrP->toJsonV1(false); - EXPECT_STREQ(expectedBuf, out.c_str()); - - - - // 6. ContextElement: +entityId -contextAttributeVector - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename6)) << "Error getting test data from '" << filename6 << "'"; - out = qcrP->toJsonV1(false); - EXPECT_STREQ(expectedBuf, out.c_str()); - - - - // 7. ContextElement: +entityId +contextAttributeVector - caP = new ContextAttribute("ca7", "string", "context attribute 7"); - cerP->entity.attributeVector.push_back(caP); - - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename7)) << "Error getting test data from '" << filename7 << "'"; - out = qcrP->toJsonV1(false); - EXPECT_STREQ(expectedBuf, out.c_str()); - - - - // 8. ContextElement: +entityId +contextAttributeVector - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename8)) << "Error getting test data from '" << filename8 << "'"; - out = qcrP->toJsonV1(false); - EXPECT_STREQ(expectedBuf, out.c_str()); - - - - // 9. ContextElement: contextAttributeVector of two attributes - caP = new ContextAttribute("ca9", "string", "context attribute 9"); - cerP->entity.attributeVector.push_back(caP); - - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename9)) << "Error getting test data from '" << filename9 << "'"; - out = qcrP->toJsonV1(false); - EXPECT_STREQ(expectedBuf, out.c_str()); - - - - // 10. QueryContextResponse::contextElementResponseVector of TWO responses - cerP = new ContextElementResponse(); - - cerP->entity.fill("E02", "EType", "false"); - cerP->statusCode.fill(SccOk); - qcrP->contextElementResponseVector.push_back(cerP); - - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename11)) << "Error getting test data from '" << filename11 << "'"; - out = qcrP->toJsonV1(false); - EXPECT_STREQ(expectedBuf, out.c_str()); - - - - // 11. QueryContextResponse::errorCode OK and contextElementResponseVector filled id (no details) - qcrP->errorCode.fill(SccOk); - - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename12)) << "Error getting test data from '" << filename12 << "'"; - qcrP->errorCode.code = SccNone; - out = qcrP->toJsonV1(false); - EXPECT_STREQ(expectedBuf, out.c_str()); - - - // 12. QueryContextResponse::errorCode NOT OK and contextElementResponseVector filled id (with details) - qcrP->errorCode.fill(SccBadRequest, "no details"); - - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename13)) << "Error getting test data from '" << filename13 << "'"; - out = qcrP->toJsonV1(false); - EXPECT_STREQ(expectedBuf, out.c_str()); - - // 13. contextElementResponseVector is released and the render method should give an almost empty response - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename14)) << "Error getting test data from '" << filename14 << "'"; - qcrP->contextElementResponseVector.release(); - out = qcrP->toJsonV1(false); - EXPECT_STREQ(expectedBuf, out.c_str()); - - - utExit(); -} diff --git a/test/unittests/ngsi10/SubscribeContextRequest_test.cpp b/test/unittests/ngsi10/SubscribeContextRequest_test.cpp deleted file mode 100644 index fb97ff80c6..0000000000 --- a/test/unittests/ngsi10/SubscribeContextRequest_test.cpp +++ /dev/null @@ -1,382 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/globals.h" -#include "ngsi/ParseData.h" -#include "jsonParse/jsonRequest.h" - -#include "unittest.h" - - - -/* **************************************************************************** -* -* ok_json - -*/ -TEST(SubscribeContextRequest, ok_json) -{ - ParseData parseData; - ConnectionInfo ci("", "POST", "1.1"); - const char* infile = "ngsi10.subscribeContextRequest.ok.valid.json"; - - utInit(); - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), infile)) << "Error getting test data from '" << infile << "'"; - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - lmTraceLevelSet(LmtDump, true); - std::string result = jsonTreat(testBuf, &ci, &parseData, SubscribeContext, NULL); - EXPECT_EQ("OK", result); - lmTraceLevelSet(LmtDump, false); - - - // - // With the data obtained present and release methods are exercised - // - SubscribeContextRequest* scrP = &parseData.scr.res; - scrP->release(); - - utExit(); -} - - - -/* **************************************************************************** -* -* badIsPattern_json - -*/ -TEST(SubscribeContextRequest, badIsPattern_json) -{ - ParseData parseData; - ConnectionInfo ci("", "POST", "1.1"); - const char* infile = "ngsi10.subscribeContextRequest.badIsPattern.invalid.json"; - const char* outfile = "ngsi10.subscribeContextResponse.badIsPattern.valid.json"; - - utInit(); - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), infile)) << "Error getting test data from '" << infile << "'"; - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile)) << "Error getting test data from '" << outfile << "'"; - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - std::string out = jsonTreat(testBuf, &ci, &parseData, SubscribeContext, NULL); - EXPECT_STREQ(expectedBuf, out.c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* invalidDuration_json - -*/ -TEST(SubscribeContextRequest, invalidDuration_json) -{ - ParseData parseData; - ConnectionInfo ci("", "POST", "1.1"); - const char* infile = "ngsi10.subscribeContextRequest.duration.invalid.json"; - const char* outfile = "ngsi10.subscribeContextResponse.durationInvalid.valid.json"; - - utInit(); - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), infile)) << "Error getting test data from '" << infile << "'"; - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile)) << "Error getting test data from '" << outfile << "'"; - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - std::string out = jsonTreat(testBuf, &ci, &parseData, SubscribeContext, NULL); - EXPECT_STREQ(expectedBuf, out.c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* scopeGeolocationCircleOkJson - -*/ -TEST(SubscribeContextRequest, scopeGeolocationCircleOkJson) -{ - ParseData reqData; - const char* inFile = "ngsi10.subscribeContextRequest.circleOk.postponed.json"; - ConnectionInfo ci("/ngsi10/subscribeContext", "POST", "1.1"); - std::string result; - - utInit(); - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - result = jsonTreat(testBuf, &ci, &reqData, SubscribeContext, NULL); - EXPECT_STREQ("OK", result.c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* scopeGeolocationCircleInvertedJson - -*/ -TEST(SubscribeContextRequest, scopeGeolocationCircleInvertedJson) -{ - ParseData reqData; - const char* inFile = "ngsi10.subscribeContextRequest.circleInverted.postponed.json"; - ConnectionInfo ci("/ngsi10/subscribeContext", "POST", "1.1"); - std::string result; - - utInit(); - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - result = jsonTreat(testBuf, &ci, &reqData, SubscribeContext, NULL); - EXPECT_STREQ("OK", result.c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* scopeGeolocationCircleInvertedBadValueJson - -*/ -TEST(SubscribeContextRequest, scopeGeolocationCircleInvertedBadValueJson) -{ - ParseData reqData; - const char* inFile = "ngsi10.subscribeContextRequest.circleInvertedBadValue.invalid.json"; - const char* outFile = "ngsi10.subscribeContextResponse.circleInvertedBadValue.ok.json"; - ConnectionInfo ci("/ngsi10/subscribeContext", "POST", "1.1"); - std::string result; - - utInit(); - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outFile)) << "Error getting test data from '" << outFile << "'"; - result = jsonTreat(testBuf, &ci, &reqData, SubscribeContext, NULL); - EXPECT_STREQ(expectedBuf, result.c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* scopeGeolocationCircleZeroRadiusJson - -*/ -TEST(SubscribeContextRequest, scopeGeolocationCircleZeroRadiusJson) -{ - ParseData reqData; - const char* inFile = "ngsi10.subscribeContextRequest.circleZeroRadius.postponed.json"; - const char* outFile = "ngsi10.subscribeContextResponse.circleZeroRadius.valid.json"; - ConnectionInfo ci("/ngsi10/subscribeContext", "POST", "1.1"); - std::string result; - - utInit(); - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outFile)) << "Error getting test data from '" << outFile << "'"; - result = jsonTreat(testBuf, &ci, &reqData, SubscribeContext, NULL); - EXPECT_STREQ(expectedBuf, result.c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* scopeGeolocationPolygonOkJson - -*/ -TEST(SubscribeContextRequest, scopeGeolocationPolygonOkJson) -{ - ParseData parseData; - const char* inFile = "ngsi10.subscribeContextRequest.polygonOk.postponed.json"; - ConnectionInfo ci("/ngsi10/subscribeContext", "POST", "1.1"); - std::string result; - - utInit(); - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - result = jsonTreat(testBuf, &ci, &parseData, SubscribeContext, NULL); - EXPECT_STREQ("OK", result.c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* scopeGeolocationPolygonInvertedJson - -*/ -TEST(SubscribeContextRequest, scopeGeolocationPolygonInvertedJson) -{ - ParseData parseData; - const char* inFile = "ngsi10.subscribeContextRequest.polygonInverted.postponed.json"; - ConnectionInfo ci("/ngsi10/subscribeContext", "POST", "1.1"); - std::string result; - - utInit(); - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - result = jsonTreat(testBuf, &ci, &parseData, SubscribeContext, NULL); - EXPECT_STREQ("OK", result.c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* scopeGeolocationPolygonInvertedBadValueJson - -*/ -TEST(SubscribeContextRequest, scopeGeolocationPolygonInvertedBadValueJson) -{ - ParseData parseData; - const char* inFile = "ngsi10.subscribeContextRequest.polygonInvertedBadValue.invalid.json"; - const char* outFile = "ngsi10.subscribeContextResponse.polygonInvertedBadValue.valid.json"; - ConnectionInfo ci("/ngsi10/subscribeContext", "POST", "1.1"); - std::string result; - - utInit(); - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outFile)) << "Error getting test data from '" << outFile << "'"; - result = jsonTreat(testBuf, &ci, &parseData, SubscribeContext, NULL); - EXPECT_STREQ(expectedBuf, result.c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* scopeGeolocationPolygonNoVerticesJson - -*/ -TEST(SubscribeContextRequest, scopeGeolocationPolygonNoVerticesJson) -{ - ParseData parseData; - const char* inFile = "ngsi10.subscribeContextRequest.polygonInvertedNoVertices.postponed.json"; - const char* outFile = "ngsi10.subscribeContextResponse.polygonInvertedNoVertices.valid.json"; - ConnectionInfo ci("/ngsi10/subscribeContext", "POST", "1.1"); - std::string result; - - utInit(); - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outFile)) << "Error getting test data from '" << outFile << "'"; - result = jsonTreat(testBuf, &ci, &parseData, SubscribeContext, NULL); - EXPECT_STREQ(expectedBuf, result.c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* scopeGeolocationPolygonOneVertexJson - -*/ -TEST(SubscribeContextRequest, scopeGeolocationPolygonOneVertexJson) -{ - ParseData parseData; - const char* inFile = "ngsi10.subscribeContextRequest.polygonInvertedOneVertex.postponed.json"; - const char* outFile = "ngsi10.subscribeContextResponse.polygonInvertedOneVertex.valid.json"; - ConnectionInfo ci("/ngsi10/subscribeContext", "POST", "1.1"); - std::string result; - - utInit(); - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outFile)) << "Error getting test data from '" << outFile << "'"; - result = jsonTreat(testBuf, &ci, &parseData, SubscribeContext, NULL); - EXPECT_STREQ(expectedBuf, result.c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* scopeGeolocationPolygonTwoVerticesJson - -*/ -TEST(SubscribeContextRequest, scopeGeolocationPolygonTwoVerticesJson) -{ - ParseData parseData; - const char* inFile = "ngsi10.subscribeContextRequest.polygonTwoVertices.postponed.json"; - const char* outFile = "ngsi10.subscribeContextResponse.polygonTwoVertices.valid.json"; - ConnectionInfo ci("/ngsi10/subscribeContext", "POST", "1.1"); - std::string result; - - utInit(); - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outFile)) << "Error getting test data from '" << outFile << "'"; - result = jsonTreat(testBuf, &ci, &parseData, SubscribeContext, NULL); - EXPECT_STREQ(expectedBuf, result.c_str()); - - utExit(); -} diff --git a/test/unittests/ngsi10/SubscribeContextResponse_test.cpp b/test/unittests/ngsi10/SubscribeContextResponse_test.cpp deleted file mode 100644 index d6dd218684..0000000000 --- a/test/unittests/ngsi10/SubscribeContextResponse_test.cpp +++ /dev/null @@ -1,138 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include "ngsi10/SubscribeContextResponse.h" - -#include "unittest.h" - - - -/* **************************************************************************** -* -* constructorsAndRender - -* -*/ -TEST(SubscribeContextResponse, constructorsAndRender) -{ - SubscribeContextResponse scr1; - StatusCode ec(SccOk, "D"); - SubscribeContextResponse scr2(ec); - std::string out; - - utInit(); - - EXPECT_STREQ("000000000000000000000000", scr1.subscribeError.subscriptionId.get().c_str()); - EXPECT_STREQ("000000000000000000000000", scr2.subscribeError.subscriptionId.get().c_str()); - EXPECT_STREQ("OK", scr2.subscribeError.errorCode.reasonPhrase.c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* jsonRender - -*/ -TEST(SubscribeContextResponse, json_render) -{ - const char* filename1 = "ngsi10.subscribeContextResponse.jsonRender1.valid.json"; - const char* filename2 = "ngsi10.subscribeContextResponse.jsonRender2.valid.json"; - const char* filename3 = "ngsi10.subscribeContextResponse.jsonRender3.valid.json"; - const char* filename4 = "ngsi10.subscribeContextResponse.jsonRender4.valid.json"; - const char* filename5 = "ngsi10.subscribeContextResponse.jsonRender5.valid.json"; - const char* filename6 = "ngsi10.subscribeContextResponse.jsonRender6.valid.json"; - SubscribeContextResponse* scrP; - std::string out; - - utInit(); - - // Preparations - scrP = new SubscribeContextResponse(); - - // 1. subscribeError, -subscriptionId, with details - // 2. subscribeError, +subscriptionId, no details - // 3. subscribeResponse: +subscription -duration -throttling - // 4. subscribeResponse: +subscription -duration +throttling - // 5. subscribeResponse: +subscription +duration -throttling - // 6. subscribeResponse: +subscription +duration +throttling - - // 1. - scrP->subscribeError.errorCode.fill(SccBadRequest, "details"); - - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename1)) << "Error getting test data from '" << filename1 << "'"; - out = scrP->toJsonV1(); - EXPECT_STREQ(expectedBuf, out.c_str()); - - - - // 2. - scrP->subscribeError.errorCode.fill(SccBadRequest); - scrP->subscribeError.subscriptionId.set("012345678901234567890123"); - - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename2)) << "Error getting test data from '" << filename2 << "'"; - out = scrP->toJsonV1(); - EXPECT_STREQ(expectedBuf, out.c_str()); - - scrP->subscribeError.errorCode.fill(SccNone); - - - - // 3. - scrP->subscribeResponse.subscriptionId.set("012345678901234567890123"); - - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename3)) << "Error getting test data from '" << filename3 << "'"; - out = scrP->toJsonV1(); - EXPECT_STREQ(expectedBuf, out.c_str()); - - - - // 4. - scrP->subscribeResponse.throttling.set("PT1M"); - - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename4)) << "Error getting test data from '" << filename4 << "'"; - out = scrP->toJsonV1(); - EXPECT_STREQ(expectedBuf, out.c_str()); - - - - // 5. - scrP->subscribeResponse.throttling.set(""); - scrP->subscribeResponse.duration.set("PT1H"); - - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename5)) << "Error getting test data from '" << filename5 << "'"; - out = scrP->toJsonV1(); - EXPECT_STREQ(expectedBuf, out.c_str()); - - - - // 6. - scrP->subscribeResponse.throttling.set("PT1M"); - - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename6)) << "Error getting test data from '" << filename6 << "'"; - out = scrP->toJsonV1(); - EXPECT_STREQ(expectedBuf, out.c_str()); - - utExit(); -} diff --git a/test/unittests/ngsi10/UnsubscribeContextRequest_test.cpp b/test/unittests/ngsi10/UnsubscribeContextRequest_test.cpp deleted file mode 100644 index 5c2235fe33..0000000000 --- a/test/unittests/ngsi10/UnsubscribeContextRequest_test.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "testDataFromFile.h" -#include "common/globals.h" -#include "ngsi/ParseData.h" -#include "jsonParse/jsonRequest.h" - -#include "unittest.h" - - - -/* **************************************************************************** -* -* badSubscriptionId_json - -*/ -TEST(UnsubscribeContextRequest, badSubscriptionId_json) -{ - ParseData reqData; - ConnectionInfo ci("", "POST", "1.1"); - const char* infile = "ngsi10.unsubscribeContextRequest.badSubscriptionId.invalid.json"; - std::string out; - const char* outfile2 = "ngsi10.unsubscribeContextResponse.badSubscriptionId2.valid.json"; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), infile)) << "Error getting test data from '" << infile << "'"; - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - lmTraceLevelSet(LmtDump, true); - out = jsonTreat(testBuf, &ci, &reqData, UnsubscribeContext, NULL); - lmTraceLevelSet(LmtDump, false); - EXPECT_STREQ("OK", out.c_str()); - - UnsubscribeContextRequest* ucrP = &reqData.uncr.res; - - - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile2)) << "Error getting test data from '" << outfile2 << "'"; - out = ucrP->toJsonV1(); - EXPECT_STREQ(expectedBuf, out.c_str()); - - ucrP->release(); -} diff --git a/test/unittests/ngsi10/UnsubscribeContextResponse_test.cpp b/test/unittests/ngsi10/UnsubscribeContextResponse_test.cpp deleted file mode 100644 index 426d7c63b9..0000000000 --- a/test/unittests/ngsi10/UnsubscribeContextResponse_test.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include "ngsi10/UnsubscribeContextResponse.h" -#include "ngsi/StatusCode.h" - -#include "unittest.h" - - - -/* **************************************************************************** -* -* constructorsAndRender - -* -*/ -TEST(UnsubscribeContextResponse, constructorsAndRender) -{ - UnsubscribeContextResponse uncr1; - StatusCode sc(SccOk, "D"); - UnsubscribeContextResponse uncr2(sc); - StatusCode ec(SccBadRequest, "D"); - UnsubscribeContextResponse uncr3(ec); - std::string out; - - utInit(); - - EXPECT_EQ(0, uncr1.statusCode.code); - EXPECT_EQ(SccOk, uncr2.statusCode.code); - EXPECT_EQ(SccBadRequest, uncr3.statusCode.code); - - uncr1.release(); - - utExit(); -} - - - -/* **************************************************************************** -* -* jsonRender - -*/ -TEST(UnsubscribeContextResponse, jsonRender) -{ - const char* infile1 = "ngsi10.unsubscribeContextResponse.jsonRender1.valid.json"; - const char* infile2 = "ngsi10.unsubscribeContextResponse.jsonRender2.valid.json"; - UnsubscribeContextResponse* uncrP; - std::string out; - - utInit(); - - // Preparations - uncrP = new UnsubscribeContextResponse(); - - // 1. 400, with details - uncrP->subscriptionId.set("012345678901234567890123"); - uncrP->statusCode.fill(SccBadRequest, "details"); - - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), infile1)) << "Error getting test data from '" << infile1 << "'"; - out = uncrP->toJsonV1(); - EXPECT_STREQ(expectedBuf, out.c_str()); - - - // 2. 200, no details - uncrP->subscriptionId.set("012345678901234567890123"); - uncrP->statusCode.fill(SccOk); - - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), infile2)) << "Error getting test data from '" << infile2 << "'"; - out = uncrP->toJsonV1(); - EXPECT_STREQ(expectedBuf, out.c_str()); - - delete uncrP; - - utExit(); -} diff --git a/test/unittests/ngsi10/UpdateContextRequest_test.cpp b/test/unittests/ngsi10/UpdateContextRequest_test.cpp deleted file mode 100644 index 9c8be3cb26..0000000000 --- a/test/unittests/ngsi10/UpdateContextRequest_test.cpp +++ /dev/null @@ -1,104 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "testDataFromFile.h" -#include "common/globals.h" -#include "jsonParse/jsonRequest.h" - -#include "unittest.h" - - - -/* **************************************************************************** -* -* Tests -* - ok_json -* - badIsPattern_json -*/ - - - -/* **************************************************************************** -* -* ok_json - -*/ -TEST(UpdateContextRequest, ok_json) -{ - ParseData reqData; - ConnectionInfo ci("", "POST", "1.1"); - const char* infile = "ngsi10.updateContext.ok.valid.json"; - - utInit(); - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), infile)) << "Error getting test data from '" << infile << "'"; - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - lmTraceLevelSet(LmtDump, true); - std::string result = jsonTreat(testBuf, &ci, &reqData, UpdateContext, NULL); - lmTraceLevelSet(LmtDump, false); - - EXPECT_EQ("OK", result); - - // - // With the data obtained, render, present and release methods are exercised - // - UpdateContextRequest* upcrP = &reqData.upcr.res; - - upcrP->release(); - utExit(); -} - - - -/* **************************************************************************** -* -* badIsPattern_json - -*/ -TEST(UpdateContextRequest, badIsPattern_json) -{ - ParseData parseData; - ConnectionInfo ci("", "POST", "1.1"); - const char* infile = "ngsi10.updateContextRequest.badIsPattern.invalid.json"; - const char* outfile = "ngsi10.updateContextResponse.badIsPattern.invalid.json"; - JsonRequest* reqP; - - utInit(); - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), infile)) << "Error getting test data from '" << infile << "'"; - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile)) << "Error getting test data from '" << outfile; - - std::string out = jsonTreat(testBuf, &ci, &parseData, UpdateContext, &reqP); - EXPECT_STREQ(expectedBuf, out.c_str()); - reqP->release(&parseData); - - utExit(); -} diff --git a/test/unittests/ngsi10/UpdateContextResponse_test.cpp b/test/unittests/ngsi10/UpdateContextResponse_test.cpp deleted file mode 100644 index 1544fbdc9e..0000000000 --- a/test/unittests/ngsi10/UpdateContextResponse_test.cpp +++ /dev/null @@ -1,125 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include "ngsi10/UpdateContextResponse.h" - -#include "unittest.h" - - - -/* **************************************************************************** -* -* jsonRender - -*/ -TEST(UpdateContextResponse, jsonRender) -{ - // FIXME P1: numbering gap, reorder - const char* filename1 = "ngsi10.updateContextResponse.jsonRender1.valid.json"; - const char* filename2 = "ngsi10.updateContextResponse.jsonRender2.valid.json"; - const char* filename3 = "ngsi10.updateContextResponse.jsonRender3.valid.json"; - const char* filename5 = "ngsi10.updateContextResponse.jsonRender5.valid.json"; - const char* filename11 = "ngsi10.updateContextResponse.jsonRender11.valid.json"; - const char* filename13 = "ngsi10.updateContextResponse.jsonRender13.valid.json"; - - UpdateContextResponse* ucrP; - ContextElementResponse* cerP; - ContextAttribute* caP; - std::string out; - - // Preparations - utInit(); - ucrP = new UpdateContextResponse(); - - // Test 01. UpdateContextResponse::errorCode OK and contextElementResponseVector filled id (no details) - // Test 02. UpdateContextResponse::errorCode NOT OK and contextElementResponseVector filled id (with details) - // Test 03. ContextElement: +entityId -contextAttributeVector - // Test 04. ContextElement: +entityId +contextAttributeVector - // Test 05. ContextElement: contextAttributeVector of two attributes - // Test 06. UpdateContextResponse::contextElementResponseVector of TWO responses - - - // Test 01. UpdateContextResponse::errorCode OK and contextElementResponseVector filled id (no details) - ucrP->errorCode.fill(SccOk); - - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename1)) << "Error getting test data from '" << filename1 << "'"; - out = ucrP->toJsonV1(false); - EXPECT_STREQ(expectedBuf, out.c_str()); - - - - // Test 02. UpdateContextResponse::errorCode NOT OK and contextElementResponseVector filled id (with details) - ucrP->errorCode.fill(SccBadRequest, "no details"); - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename2)) << "Error getting test data from '" << filename2 << "'"; - out = ucrP->toJsonV1(false); - EXPECT_STREQ(expectedBuf, out.c_str()); - ucrP->errorCode.fill(SccOk); // Cleanup - - - - // Test 03. ContextElement: +entityId -contextAttributeVector - cerP = new ContextElementResponse(); - - cerP->entity.fill("E01", "EType", "false"); - cerP->statusCode.fill(SccOk); - ucrP->contextElementResponseVector.push_back(cerP); - - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename3)) << "Error getting test data from '" << filename3 << "'"; - out = ucrP->toJsonV1(false); - EXPECT_STREQ(expectedBuf, out.c_str()); - - - - // Test 04. ContextElement: +entityId +contextAttributeVector - caP = new ContextAttribute("ca5", "string", "context attribute 5"); - cerP->entity.attributeVector.push_back(caP); - - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename5)) << "Error getting test data from '" << filename5 << "'"; - out = ucrP->toJsonV1(false); - EXPECT_STREQ(expectedBuf, out.c_str()); - - - - // Test 05. ContextElement: contextAttributeVector of two attributes - caP = new ContextAttribute("ca11", "string", "context attribute 11"); - cerP->entity.attributeVector.push_back(caP); - - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename11)) << "Error getting test data from '" << filename11 << "'"; - out = ucrP->toJsonV1(false); - EXPECT_STREQ(expectedBuf, out.c_str()); - - - - // Test 06. UpdateContextResponse::contextElementResponseVector of TWO responses - cerP = new ContextElementResponse(); - - cerP->entity.fill("E02", "EType", "false"); - cerP->statusCode.fill(SccOk); - ucrP->contextElementResponseVector.push_back(cerP); - - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename13)) << "Error getting test data from '" << filename13 << "'"; - out = ucrP->toJsonV1(false); - EXPECT_STREQ(expectedBuf, out.c_str()); - - utExit(); -} diff --git a/test/unittests/ngsi10/UpdateContextSubscriptionRequest_test.cpp b/test/unittests/ngsi10/UpdateContextSubscriptionRequest_test.cpp deleted file mode 100644 index e36f5cead9..0000000000 --- a/test/unittests/ngsi10/UpdateContextSubscriptionRequest_test.cpp +++ /dev/null @@ -1,384 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/globals.h" -#include "jsonParse/jsonRequest.h" - -#include "unittest.h" - - - -/* **************************************************************************** -* -* Tests -* - badLength_json -* - invalidDuration_json -* -*/ - - - -/* **************************************************************************** -* -* badLength_json - -*/ -TEST(UpdateContextSubscriptionRequest, badLength_json) -{ - ParseData parseData; - ConnectionInfo ci("", "POST", "1.1"); - std::string out; - const char* infile = "ngsi10.updateContextSubscriptionRequest.badLength.invalid.json"; - const char* outfile1 = "ngsi10.updateContextSubscriptionRequest.badLength.expected1.valid.json"; - const char* outfile3 = "ngsi10.updateContextSubscriptionRequest.badLength.expected3.valid.json"; - const char* outfile4 = "ngsi10.updateContextSubscriptionRequest.badLength.expected4.valid.json"; - - utInit(); - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), infile)) << "Error getting test data from '" << infile << "'"; - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'"; - lmTraceLevelSet(LmtDump, true); - out = jsonTreat(testBuf, &ci, &parseData, UpdateContextSubscription, NULL); - lmTraceLevelSet(LmtDump, false); - EXPECT_STREQ(expectedBuf, out.c_str()); - - // - // With the data obtained, render, present and release methods are exercised - // - UpdateContextSubscriptionRequest* ucsrP = &parseData.ucsr.res; - - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile3)) << "Error getting test data from '" << outfile3 << "'"; - out = ucsrP->check("FORCED ERROR", 0); - EXPECT_STREQ(expectedBuf, out.c_str()); - - ucsrP->duration.set("XXXYYYZZZ"); - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile4)) << "Error getting test data from '" << outfile4 << "'"; - out = ucsrP->check("", 0); - EXPECT_STREQ(expectedBuf, out.c_str()); - - ucsrP->release(); - - utExit(); -} - - - -/* **************************************************************************** -* -* invalidDuration_json - -*/ -TEST(UpdateContextSubscriptionRequest, invalidDuration_json) -{ - ParseData parseData; - ConnectionInfo ci("", "POST", "1.1"); - const char* infile = "ngsi10.updateContextSubscriptionRequest.duration.invalid.json"; - const char* outfile = "ngsi10.updateContextSubscriptionResponse.invalidDuration.valid.json"; - - utInit(); - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), infile)) << "Error getting test data from '" << infile << "'"; - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile)) << "Error getting test data from '" << outfile << "'"; - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - std::string out = jsonTreat(testBuf, &ci, &parseData, UpdateContextSubscription, NULL); - EXPECT_STREQ(expectedBuf, out.c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* scopeGeolocationCircleOkJson - -*/ -TEST(UpdateContextSubscriptionRequest, scopeGeolocationCircleOkJson) -{ - ParseData reqData; - const char* inFile = "ngsi10.updateContextSubscriptionRequest.circleOk.postponed.json"; - ConnectionInfo ci("/ngsi10/updateContextSubscription", "POST", "1.1"); - std::string result; - - utInit(); - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - result = jsonTreat(testBuf, &ci, &reqData, UpdateContextSubscription, NULL); - EXPECT_STREQ("OK", result.c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* scopeGeolocationCircleInvertedJson - -*/ -TEST(UpdateContextSubscriptionRequest, scopeGeolocationCircleInvertedJson) -{ - ParseData reqData; - const char* inFile = "ngsi10.updateContextSubscriptionRequest.circleInverted.postponed.json"; - ConnectionInfo ci("/ngsi10/updateContextSubscription", "POST", "1.1"); - std::string out; - - utInit(); - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - out = jsonTreat(testBuf, &ci, &reqData, UpdateContextSubscription, NULL); - EXPECT_STREQ("OK", out.c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* scopeGeolocationCircleInvertedBadValueJson - -*/ -TEST(UpdateContextSubscriptionRequest, scopeGeolocationCircleInvertedBadValueJson) -{ - ParseData reqData; - const char* inFile = "ngsi10.updateContextSubscriptionRequest.circleInvertedBadValue.postponed.json"; - const char* outfile = "ngsi10.updateContextSubscriptionResponse.circleInvertedBadValue.valid.json"; - ConnectionInfo ci("/ngsi10/updateContextSubscription", "POST", "1.1"); - std::string out; - - utInit(); - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile)) << "Error getting test data from '" << outfile << "'"; - - out = jsonTreat(testBuf, &ci, &reqData, UpdateContextSubscription, NULL); - EXPECT_STREQ(expectedBuf, out.c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* scopeGeolocationCircleZeroRadiusJson - -*/ -TEST(UpdateContextSubscriptionRequest, scopeGeolocationCircleZeroRadiusJson) -{ - ParseData reqData; - const char* inFile = "ngsi10.updateContextSubscriptionRequest.circleZeroRadius.postponed.json"; - const char* outfile = "ngsi10.updateContextSubscriptionResponse.circleZeroRadius.valid.json"; - ConnectionInfo ci("/ngsi10/updateContextSubscription", "POST", "1.1"); - std::string out; - - utInit(); - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile)) << "Error getting test data from '" << outfile << "'"; - - out = jsonTreat(testBuf, &ci, &reqData, UpdateContextSubscription, NULL); - EXPECT_STREQ(expectedBuf, out.c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* scopeGeolocationPolygonOkJson - -*/ -TEST(UpdateContextSubscriptionRequest, scopeGeolocationPolygonOkJson) -{ - ParseData reqData; - const char* inFile = "ngsi10.updateContextSubscriptionRequest.polygonOk.postponed.json"; - ConnectionInfo ci("/ngsi10/updateContextSubscription", "POST", "1.1"); - std::string result; - - utInit(); - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - result = jsonTreat(testBuf, &ci, &reqData, UpdateContextSubscription, NULL); - EXPECT_STREQ("OK", result.c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* scopeGeolocationPolygonInvertedJson - -*/ -TEST(UpdateContextSubscriptionRequest, scopeGeolocationPolygonInvertedJson) -{ - ParseData reqData; - const char* inFile = "ngsi10.updateContextSubscriptionRequest.polygonInverted.postponed.json"; - ConnectionInfo ci("/ngsi10/updateContextSubscription", "POST", "1.1"); - std::string result; - - utInit(); - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - result = jsonTreat(testBuf, &ci, &reqData, UpdateContextSubscription, NULL); - EXPECT_STREQ("OK", result.c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* scopeGeolocationPolygonInvertedBadValueJson - -*/ -TEST(UpdateContextSubscriptionRequest, scopeGeolocationPolygonInvertedBadValueJson) -{ - ParseData reqData; - const char* inFile = "ngsi10.updateContextSubscriptionRequest.polygonInvertedBadValue.postponed.json"; - const char* outfile = "ngsi10.updateContextSubscriptionResponse.polygonInvertedBadValue.valid.json"; - ConnectionInfo ci("/ngsi10/updateContextSubscription", "POST", "1.1"); - std::string out; - - utInit(); - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile)) << "Error getting test data from '" << outfile << "'"; - - out = jsonTreat(testBuf, &ci, &reqData, UpdateContextSubscription, NULL); - EXPECT_STREQ(expectedBuf, out.c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* scopeGeolocationPolygonNoVerticesJson - -*/ -TEST(UpdateContextSubscriptionRequest, scopeGeolocationPolygonNoVerticesJson) -{ - ParseData reqData; - const char* inFile = "ngsi10.updateContextSubscriptionRequest.polygonNoVertices.postponed.json"; - const char* outfile = "ngsi10.updateContextSubscriptionResponse.polygonNoVertices.valid.json"; - ConnectionInfo ci("/ngsi10/updateContextSubscription", "POST", "1.1"); - std::string out; - - utInit(); - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile)) << "Error getting test data from '" << outfile << "'"; - - out = jsonTreat(testBuf, &ci, &reqData, UpdateContextSubscription, NULL); - EXPECT_STREQ(expectedBuf, out.c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* scopeGeolocationPolygonOneVertexJson - -*/ -TEST(UpdateContextSubscriptionRequest, scopeGeolocationPolygonOneVertexJson) -{ - ParseData reqData; - const char* inFile = "ngsi10.updateContextSubscriptionRequest.polygonOneVertex.postponed.json"; - const char* outfile = "ngsi10.updateContextSubscriptionResponse.polygonOneVertex.valid.json"; - ConnectionInfo ci("/ngsi10/updateContextSubscription", "POST", "1.1"); - std::string out; - - utInit(); - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile)) << "Error getting test data from '" << outfile << "'"; - - out = jsonTreat(testBuf, &ci, &reqData, UpdateContextSubscription, NULL); - EXPECT_STREQ(expectedBuf, out.c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* scopeGeolocationPolygonTwoVerticesJson - -*/ -TEST(UpdateContextSubscriptionRequest, scopeGeolocationPolygonTwoVerticesJson) -{ - ParseData reqData; - const char* inFile = "ngsi10.updateContextSubscriptionRequest.polygonTwoVertices.postponed.json"; - const char* outfile = "ngsi10.updateContextSubscriptionResponse.polygonTwoVertices.valid.json"; - ConnectionInfo ci("/ngsi10/updateContextSubscription", "POST", "1.1"); - std::string out; - - utInit(); - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile)) << "Error getting test data from '" << outfile << "'"; - - out = jsonTreat(testBuf, &ci, &reqData, UpdateContextSubscription, NULL); - EXPECT_STREQ(expectedBuf, out.c_str()); - - utExit(); -} diff --git a/test/unittests/ngsi10/UpdateContextSubscriptionResponse_test.cpp b/test/unittests/ngsi10/UpdateContextSubscriptionResponse_test.cpp deleted file mode 100644 index c46091b1a9..0000000000 --- a/test/unittests/ngsi10/UpdateContextSubscriptionResponse_test.cpp +++ /dev/null @@ -1,118 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "ngsi10/UpdateContextSubscriptionResponse.h" - -#include "unittest.h" - - - -/* **************************************************************************** -* -* jsonRender - -*/ -TEST(UpdateContextSubscriptionResponse, json_render) -{ - const char* filename1 = "ngsi10.updateContextSubscriptionResponse.jsonRender1.valid.json"; - const char* filename2 = "ngsi10.updateContextSubscriptionResponse.jsonRender2.valid.json"; - const char* filename3 = "ngsi10.updateContextSubscriptionResponse.jsonRender3.valid.json"; - const char* filename4 = "ngsi10.updateContextSubscriptionResponse.jsonRender4.valid.json"; - const char* filename5 = "ngsi10.updateContextSubscriptionResponse.jsonRender5.valid.json"; - const char* filename6 = "ngsi10.updateContextSubscriptionResponse.jsonRender6.valid.json"; - UpdateContextSubscriptionResponse* ucsrP; - std::string out; - - utInit(); - - // Preparations - ucsrP = new UpdateContextSubscriptionResponse(); - - // 1. subscribeError, -subscriptionId, with details - // 2. subscribeError, +subscriptionId, no details - // 3. subscribeResponse: +subscription -duration -throttling - // 4. subscribeResponse: +subscription -duration +throttling - // 5. subscribeResponse: +subscription +duration -throttling - // 6. subscribeResponse: +subscription +duration +throttling - - // 1. - ucsrP->subscribeError.errorCode.fill(SccBadRequest, "details"); - - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename1)) << "Error getting test data from '" << filename1 << "'"; - out = ucsrP->toJsonV1(); - EXPECT_STREQ(expectedBuf, out.c_str()); - - - - // 2. - ucsrP->subscribeError.errorCode.fill(SccBadRequest); - ucsrP->subscribeError.subscriptionId.set("012345678901234567890123"); - - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename2)) << "Error getting test data from '" << filename2 << "'"; - out = ucsrP->toJsonV1(); - EXPECT_STREQ(expectedBuf, out.c_str()); - - ucsrP->subscribeError.errorCode.fill(SccNone); - - - - // 3. - ucsrP->subscribeResponse.subscriptionId.set("012345678901234567890123"); - - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename3)) << "Error getting test data from '" << filename3 << "'"; - out = ucsrP->toJsonV1(); - EXPECT_STREQ(expectedBuf, out.c_str()); - - - - // 4. - ucsrP->subscribeResponse.throttling.set("PT1M"); - - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename4)) << "Error getting test data from '" << filename4 << "'"; - out = ucsrP->toJsonV1(); - EXPECT_STREQ(expectedBuf, out.c_str()); - - - - // 5. - ucsrP->subscribeResponse.throttling.set(""); - ucsrP->subscribeResponse.duration.set("PT1H"); - - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename5)) << "Error getting test data from '" << filename5 << "'"; - out = ucsrP->toJsonV1(); - EXPECT_STREQ(expectedBuf, out.c_str()); - - - - // 6. - ucsrP->subscribeResponse.throttling.set("PT1M"); - - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename6)) << "Error getting test data from '" << filename6 << "'"; - out = ucsrP->toJsonV1(); - EXPECT_STREQ(expectedBuf, out.c_str()); - - utExit(); -} diff --git a/test/unittests/ngsi9/DiscoverContextAvailabilityRequest_test.cpp b/test/unittests/ngsi9/DiscoverContextAvailabilityRequest_test.cpp deleted file mode 100644 index 1d6dcb3aea..0000000000 --- a/test/unittests/ngsi9/DiscoverContextAvailabilityRequest_test.cpp +++ /dev/null @@ -1,545 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include "gtest/gtest.h" - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "ngsi/ParseData.h" -#include "common/globals.h" -#include "jsonParse/jsonRequest.h" -#include "rest/RestService.h" - -#include "unittest.h" - - - -/* **************************************************************************** -* -* Tests -* - ok -* - okNoRestrictions -* - noEntityIdList -* - emptyEntityIdList -* - invalidIsPatternValue -* - unsupportedAttributeForEntityId -* - entityIdIdAsAttribute -* - entityIdType -* - entityIdIsPattern -* - overrideEntityIdType -* - overrideEntityIdIsPattern -* - emptyEntityIdId -* - noEntityIdId -* - noAttributeExpression -* - emptyAttributeExpression -* - noScopeType -* - noScopeValue -* - emptyScopeType -* - emptyScopeValue -* - emptyAttributeName -*/ - - - -/* **************************************************************************** -* -* ok_json - -*/ -TEST(DiscoverContextAvailabilityRequest, ok_json) -{ - ParseData reqData; - const char* inFile = "ngsi9.discoverContextAvailabilityRequest.ok2.valid.json"; - ConnectionInfo ci("", "POST", "1.1"); - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - - lmTraceLevelSet(LmtDump, true); - std::string result = jsonTreat(testBuf, &ci, &reqData, DiscoverContextAvailability, NULL); - EXPECT_EQ("OK", result) << "this test should be OK"; - lmTraceLevelSet(LmtDump, false); -} - - - -/* **************************************************************************** -* -* okNoRestrictions_json - -*/ -TEST(DiscoverContextAvailabilityRequest, okNoRestrictions_json) -{ - ParseData reqData; - const char* inFile = "ngsi9.discoverContextAvailabilityRequest.noRestrictions.ok.valid.json"; - ConnectionInfo ci("", "POST", "1.1"); - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - - std::string result = jsonTreat(testBuf, &ci, &reqData, DiscoverContextAvailability, NULL); - EXPECT_EQ("OK", result) << "OK with no Restriction"; -} - - - -/* **************************************************************************** -* -* noEntityIdList_json - -*/ -TEST(DiscoverContextAvailabilityRequest, noEntityIdList_json) -{ - ParseData reqData; - const char* inFile = "ngsi9.discoverContextAvailabilityRequest.noEntityIdList.invalid.json"; - const char* outFile = "ngsi9.discoverContextAvailabilityRequest.noEntityIdListResponse.valid.json"; - ConnectionInfo ci("", "POST", "1.1"); - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outFile)) << "Error getting test data from '" << outFile << "'"; - - std::string result = jsonTreat(testBuf, &ci, &reqData, DiscoverContextAvailability, NULL); - - EXPECT_STREQ(expectedBuf, result.c_str()); -} - - - -/* **************************************************************************** -* -* emptyEntityIdList_json - -*/ -TEST(DiscoverContextAvailabilityRequest, emptyEntityIdList_json) -{ - ParseData reqData; - const char* inFile = "ngsi9.discoverContextAvailabilityRequest.emptyEntityIdList.invalid.json"; - const char* outFile = "ngsi9.discoverContextAvailabilityRequest.emptyEntityIdListResponse.valid.json"; - ConnectionInfo ci("", "POST", "1.1"); - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outFile)) << "Error getting test data from '" << outFile << "'"; - - std::string result = jsonTreat(testBuf, &ci, &reqData, DiscoverContextAvailability, NULL); - - EXPECT_STREQ(expectedBuf, result.c_str()); -} - - - -/* **************************************************************************** -* -* invalidIsPatternValue_json - -*/ -TEST(DiscoverContextAvailabilityRequest, invalidIsPatternValue_json) -{ - ParseData reqData; - const char* inFile = "ngsi9.discoverContextAvailabilityRequest.isPatternValue.invalid.json"; - const char* outFile = "ngsi9.discoverContextAvailabilityRequest.isPatternValueResponse.valid.json"; - ConnectionInfo ci("", "POST", "1.1"); - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outFile)) << "Error getting test data from '" << outFile << "'"; - - std::string result = jsonTreat(testBuf, &ci, &reqData, DiscoverContextAvailability, NULL); - - EXPECT_STREQ(expectedBuf, result.c_str()); -} - - - -/* **************************************************************************** -* -* unsupportedAttributeForEntityId_json - -*/ -TEST(DiscoverContextAvailabilityRequest, unsupportedAttributeForEntityId_json) -{ - ParseData reqData; - const char* inFile = "ngsi9.discoverContextAvailabilityRequest.unsupportedAttributeForEntityId.invalid.json"; - const char* outFile = "ngsi9.discoverContextAvailabilityResponse.unsupportedAttributeForEntityId.valid.json"; - ConnectionInfo ci("", "POST", "1.1"); - RestService restService = { DiscoverContextAvailability, 1, { "" }, NULL }; - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - ci.restServiceP = &restService; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - - std::string result = jsonTreat(testBuf, &ci, &reqData, DiscoverContextAvailability, NULL); - - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outFile)) << "Error getting test data from '" << outFile << "'"; - EXPECT_STREQ(expectedBuf, result.c_str()); -} - - - -/* **************************************************************************** -* -* twoEntityIdIds_json - -*/ -TEST(DiscoverContextAvailabilityRequest, twoEntityIdIds_json) -{ - ParseData reqData; - const char* inFile = "ngsi9.discoverContextAvailabilityRequest.twoEntityIds.invalid.json"; - ConnectionInfo ci("", "POST", "1.1"); - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - - std::string result = jsonTreat(testBuf, &ci, &reqData, DiscoverContextAvailability, NULL); - - EXPECT_EQ("OK", result) << "invalid 'isPattern' value"; -} - - - -/* **************************************************************************** -* -* entityIdTwoTypes_json - -*/ -TEST(DiscoverContextAvailabilityRequest, entityIdTwoTypes_json) -{ - ParseData reqData; - const char* inFile = "ngsi9.discoverContextAvailabilityRequest.entityIdTwoTypes.invalid.json"; - ConnectionInfo ci("", "POST", "1.1"); - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - - std::string result = jsonTreat(testBuf, &ci, &reqData, DiscoverContextAvailability, NULL); - - EXPECT_EQ("OK", result) << "invalid 'isPattern' value"; -} - - - -/* **************************************************************************** -* -* entityIdTwoIsPatterns_json - -*/ -TEST(DiscoverContextAvailabilityRequest, entityIdTwoIsPatterns_json) -{ - ParseData reqData; - const char* inFile = "ngsi9.discoverContextAvailabilityRequest.entityIdTwoIsPatterns.invalid.json"; - ConnectionInfo ci("", "POST", "1.1"); - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - - std::string result = jsonTreat(testBuf, &ci, &reqData, DiscoverContextAvailability, NULL); - - EXPECT_EQ("OK", result) << "invalid 'isPattern' value"; -} - - - -/* **************************************************************************** -* -* twoEntityIdTypes_json - -*/ -TEST(DiscoverContextAvailabilityRequest, twoEntityIdTypes_json) -{ - ParseData reqData; - const char* inFile = "ngsi9.discoverContextAvailabilityRequest.twoEntityIdTypes.invalid.json"; - ConnectionInfo ci("", "POST", "1.1"); - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - - std::string result = jsonTreat(testBuf, &ci, &reqData, DiscoverContextAvailability, NULL); - - EXPECT_EQ("OK", result) << "invalid 'isPattern' value"; -} - - - -/* **************************************************************************** -* -* overrideEntityIdIsPattern_json - -*/ -TEST(DiscoverContextAvailabilityRequest, overrideEntityIdIsPattern_json) -{ - ParseData reqData; - const char* inFile = "ngsi9.discoverContextAvailabilityRequest.overrideEntityIdIsPattern.invalid.json"; - const char* outFile = "ngsi9.discoverContextAvailabilityResponse.overrideEntityIdIsPattern.valid.json"; - ConnectionInfo ci("", "POST", "1.1"); - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outFile)) << "Error getting test data from '" << outFile << "'"; - - std::string result = jsonTreat(testBuf, &ci, &reqData, DiscoverContextAvailability, NULL); - EXPECT_STREQ(expectedBuf, result.c_str()); -} - - - -/* **************************************************************************** -* -* emptyEntityIdId_json - -*/ -TEST(DiscoverContextAvailabilityRequest, emptyEntityIdId_json) -{ - ParseData reqData; - const char* inFile = "ngsi9.discoverContextAvailabilityRequest.emptyEntityIdId.valid.json"; - const char* outFile = "ngsi9.discoverContextAvailabilityResponse.emptyEntityIdId.valid.json"; - ConnectionInfo ci("", "POST", "1.1"); - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outFile)) << "Error getting test data from '" << outFile << "'"; - - std::string result = jsonTreat(testBuf, &ci, &reqData, DiscoverContextAvailability, NULL); - EXPECT_STREQ(expectedBuf, result.c_str()); -} - - - -/* **************************************************************************** -* -* noEntityIdId_json - -*/ -TEST(DiscoverContextAvailabilityRequest, noEntityIdId_json) -{ - ParseData reqData; - const char* inFile = "ngsi9.discoverContextAvailabilityRequest.noEntityIdId.invalid.json"; - const char* outFile = "ngsi9.discoverContextAvailabilityResponse.noEntityIdId.valid.json"; - ConnectionInfo ci("", "POST", "1.1"); - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outFile)) << "Error getting test data from '" << outFile << "'"; - - std::string result = jsonTreat(testBuf, &ci, &reqData, DiscoverContextAvailability, NULL); - EXPECT_STREQ(expectedBuf, result.c_str()); -} - - - -/* **************************************************************************** -* -* noAttributeExpression_json - -*/ -TEST(DiscoverContextAvailabilityRequest, noAttributeExpression_json) -{ - ParseData reqData; - const char* inFile = "ngsi9.discoverContextAvailabilityRequest.noAttributeExpression.invalid.json"; - const char* expect = "OK"; - ConnectionInfo ci("", "POST", "1.1"); - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - - std::string result = jsonTreat(testBuf, &ci, &reqData, DiscoverContextAvailability, NULL); - - EXPECT_EQ(expect, result) << "noAttributeExpression"; -} - - - -/* **************************************************************************** -* -* emptyAttributeExpression_json - -*/ -TEST(DiscoverContextAvailabilityRequest, emptyAttributeExpression_json) -{ - ParseData reqData; - const char* inFile = "ngsi9.discoverContextAvailabilityRequest.emptyAttributeExpression.invalid.json"; - const char* expect = "OK"; - ConnectionInfo ci("", "POST", "1.1"); - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - - std::string result = jsonTreat(testBuf, &ci, &reqData, DiscoverContextAvailability, NULL); - - EXPECT_EQ(expect, result) << "Empty Attribute Expression"; -} - - - -/* **************************************************************************** -* -* noScopeType_json - -*/ -TEST(DiscoverContextAvailabilityRequest, noScopeType_json) -{ - ParseData reqData; - const char* inFile = "ngsi9.discoverContextAvailabilityRequest.noScopeType.invalid.json"; - const char* outFile = "ngsi9.discoverContextAvailabilityResponse.noScopeType.valid.json"; - ConnectionInfo ci("", "POST", "1.1"); - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outFile)) << "Error getting test data from '" << outFile << "'"; - - std::string result = jsonTreat(testBuf, &ci, &reqData, DiscoverContextAvailability, NULL); - EXPECT_STREQ(expectedBuf, result.c_str()); -} - - - -/* **************************************************************************** -* -* noScopeValue_json - -*/ -TEST(DiscoverContextAvailabilityRequest, noScopeValue_json) -{ - ParseData reqData; - const char* inFile = "ngsi9.discoverContextAvailabilityRequest.noScopeValue.invalid.json"; - const char* outFile = "ngsi9.discoverContextAvailabilityResponse.noScopeValue.valid.json"; - ConnectionInfo ci("", "POST", "1.1"); - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outFile)) << "Error getting test data from '" << outFile << "'"; - - std::string result = jsonTreat(testBuf, &ci, &reqData, DiscoverContextAvailability, NULL); - EXPECT_STREQ(expectedBuf, result.c_str()); -} - - - -/* **************************************************************************** -* -* emptyScopeType_json - -*/ -TEST(DiscoverContextAvailabilityRequest, emptyScopeType_json) -{ - ParseData reqData; - const char* inFile = "ngsi9.discoverContextAvailabilityRequest.emptyScopeType.invalid.json"; - const char* outFile = "ngsi9.discoverContextAvailabilityResponse.emptyScopeType.valid.json"; - ConnectionInfo ci("", "POST", "1.1"); - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outFile)) << "Error getting test data from '" << outFile << "'"; - - std::string result = jsonTreat(testBuf, &ci, &reqData, DiscoverContextAvailability, NULL); - EXPECT_STREQ(expectedBuf, result.c_str()); -} - - - -/* **************************************************************************** -* -* emptyScopeValue_json - -*/ -TEST(DiscoverContextAvailabilityRequest, emptyScopeValue_json) -{ - ParseData reqData; - const char* inFile = "ngsi9.discoverContextAvailabilityRequest.emptyScopeValue.invalid.json"; - const char* outFile = "ngsi9.discoverContextAvailabilityResponse.emptyScopeValue.valid.json"; - ConnectionInfo ci("", "POST", "1.1"); - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outFile)) << "Error getting test data from '" << outFile << "'"; - - std::string result = jsonTreat(testBuf, &ci, &reqData, DiscoverContextAvailability, NULL); - EXPECT_STREQ(expectedBuf, result.c_str()); -} - - - -/* **************************************************************************** -* -* parseError_json - -*/ -TEST(DiscoverContextAvailabilityRequest, parseError_json) -{ - ParseData reqData; - const char* inFile = "ngsi9.discoverContextAvailabilityRequest.parseError.invalid.json"; - ConnectionInfo ci("", "POST", "1.1"); - RestService restService = { InvalidRequest, 1, { "" }, NULL }; - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - ci.restServiceP = &restService; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - - std::string result = jsonTreat(testBuf, &ci, &reqData, DiscoverContextAvailability, NULL); - EXPECT_NE("OK", result) << "Parse Error not detected"; -} - - - -/* **************************************************************************** -* -* emptyAttributeName_json - -*/ -TEST(DiscoverContextAvailabilityRequest, emptyAttributeName_json) -{ - ParseData reqData; - const char* inFile = "ngsi9.discoverContextAvailabilityRequest.emptyAttributeName.invalid.json"; - const char* outFile = "ngsi9.discoverContextAvailabilityResponse.emptyAttributeName.valid.json"; - ConnectionInfo ci("", "POST", "1.1"); - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outFile)) << "Error getting test data from '" << outFile << "'"; - - std::string result = jsonTreat(testBuf, &ci, &reqData, DiscoverContextAvailability, NULL); - EXPECT_STREQ(expectedBuf, result.c_str()); -} diff --git a/test/unittests/ngsi9/DiscoverContextAvailabilityResponse_test.cpp b/test/unittests/ngsi9/DiscoverContextAvailabilityResponse_test.cpp deleted file mode 100644 index 8fb0b75c38..0000000000 --- a/test/unittests/ngsi9/DiscoverContextAvailabilityResponse_test.cpp +++ /dev/null @@ -1,348 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "ngsi9/DiscoverContextAvailabilityResponse.h" - -#include "unittest.h" - - - - -/* **************************************************************************** -* -* EMPTY_JSON - -*/ -#define EMPTY_JSON "{\n}\n" - - - -/* **************************************************************************** -* -* render - -* -*/ -TEST(DiscoverContextAvailabilityResponse, render) -{ - DiscoverContextAvailabilityResponse dcar1; - std::string out; - StatusCode ec(SccBadRequest, "Detail"); - DiscoverContextAvailabilityResponse dcar2(ec); - - utInit(); - - out = dcar1.toJsonV1(); - EXPECT_EQ(SccReceiverInternalError, dcar1.errorCode.code); - - out = dcar2.toJsonV1(); - EXPECT_EQ(SccBadRequest, dcar2.errorCode.code); - - utExit(); -} - - - -/* **************************************************************************** -* -* jsonRender - -* -* NOTE -* - providingApplication is MANDATORY inside ContextRegistration -*/ -TEST(DiscoverContextAvailabilityResponse, jsonRender) -{ - // FIXME P2: gaps in numbering, rename - // FIXME P2: review files. After removing medatata, isDomain, etc. some of them could be equal - const char* filename1 = "ngsi9.discoverContextAvailabilityResponse.jsonRender1.valid.json"; - const char* filename2 = "ngsi9.discoverContextAvailabilityResponse.jsonRender2.valid.json"; - const char* filename3 = "ngsi9.discoverContextAvailabilityResponse.jsonRender3.valid.json"; - const char* filename4 = "ngsi9.discoverContextAvailabilityResponse.jsonRender4.valid.json"; - const char* filename5 = "ngsi9.discoverContextAvailabilityResponse.jsonRender5.valid.json"; - const char* filename6 = "ngsi9.discoverContextAvailabilityResponse.jsonRender6.valid.json"; - const char* filename7 = "ngsi9.discoverContextAvailabilityResponse.jsonRender7.valid.json"; - const char* filename10 = "ngsi9.discoverContextAvailabilityResponse.jsonRender10.valid.json"; - const char* filename14 = "ngsi9.discoverContextAvailabilityResponse.jsonRender14.valid.json"; - const char* filename16 = "ngsi9.discoverContextAvailabilityResponse.jsonRender16.valid.json"; - const char* filename18 = "ngsi9.discoverContextAvailabilityResponse.jsonRender18.valid.json"; - const char* filename19 = "ngsi9.discoverContextAvailabilityResponse.jsonRender19.valid.json"; - const char* filename20 = "ngsi9.discoverContextAvailabilityResponse.jsonRender20.valid.json"; - const char* emptyFilename = "ngsi9.discoverContextAvailabilityResponse.jsonRender.empty.valid.json"; - std::string rendered; - DiscoverContextAvailabilityResponse* dcarP = new DiscoverContextAvailabilityResponse(); - ContextRegistrationResponse* crrP; - EntityId* eidP; - ContextRegistrationAttribute* attrP; - - utInit(); - - // 1. One contextRegistrationResponse - no errorCode inside ContextRegistrationResponse - crrP = new ContextRegistrationResponse(); - eidP = new EntityId("E01", "EType", "false"); - - crrP->contextRegistration.entityIdVector.push_back(eidP); - crrP->contextRegistration.providingApplication.set("http://tid.test.com/unitTest"); - dcarP->responseVector.push_back(crrP); - - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename1)) << "Error getting test data from '" << filename1 << "'"; - rendered = dcarP->toJsonV1(); - EXPECT_STREQ(expectedBuf, rendered.c_str()); - - dcarP->release(); - dcarP->release(); - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), emptyFilename)) << "Error getting test data from '" << emptyFilename << "'"; - rendered = dcarP->toJsonV1(); - EXPECT_STREQ(expectedBuf, rendered.c_str()); - dcarP->release(); // ... otherwise the 500 remains and "pollutes" next tests - delete dcarP; - - - // 2. One contextRegistrationResponse - errorCode inside ContextRegistrationResponse - only providingApplication in ContextRegistration - dcarP = new DiscoverContextAvailabilityResponse(); - crrP = new ContextRegistrationResponse(); - - crrP->contextRegistration.providingApplication.set("http://tid.test.com/unitTest2"); - crrP->errorCode.fill(SccBadRequest, "errorCode inside ContextRegistrationResponse"); - dcarP->responseVector.push_back(crrP); - - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename2)) << "Error getting test data from '" << filename2 << "'"; - rendered = dcarP->toJsonV1(); - EXPECT_STREQ(expectedBuf, rendered.c_str()); - // No release here - the data stays - to be used in the following test scenario - - - - // 3. Two contextRegistrationResponses - one with errorCode and one without errorCode - // We're reusing the ContextRegistrationResponse from test 2 (it has StatusCode set - crrP = new ContextRegistrationResponse(); - crrP->contextRegistration.providingApplication.set("http://tid.test.com/unitTest3"); - - dcarP->responseVector.push_back(crrP); - - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename3)) << "Error getting test data from '" << filename3 << "'"; - rendered = dcarP->toJsonV1(); - EXPECT_STREQ(expectedBuf, rendered.c_str()); - - dcarP->release(); - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), emptyFilename)) << "Error getting test data from '" << emptyFilename << "'"; - rendered = dcarP->toJsonV1(); - EXPECT_STREQ(expectedBuf, rendered.c_str()); - dcarP->release(); // ... otherwise the 500 remains and "pollutes" next tests - - - // 4. ContextRegistration: One entityId inside entityIdVector - crrP = new ContextRegistrationResponse(); - eidP = new EntityId("E04", "EType", "false"); - - crrP->contextRegistration.entityIdVector.push_back(eidP); - crrP->contextRegistration.providingApplication.set("http://tid.test.com/unitTest4"); - dcarP->responseVector.push_back(crrP); - - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename4)) << "Error getting test data from '" << filename4 << "'"; - rendered = dcarP->toJsonV1(); - EXPECT_STREQ(expectedBuf, rendered.c_str()); - // No release here - the data stays - to be used in the following test scenario - - - // 5. ContextRegistration: Two entityIds inside entityIdVector - eidP = new EntityId("E05", "EType", "false"); - - crrP->contextRegistration.entityIdVector.push_back(eidP); - crrP->contextRegistration.providingApplication.set("http://tid.test.com/unitTest5"); - - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename5)) << "Error getting test data from '" << filename5 << "'"; - rendered = dcarP->toJsonV1(); - EXPECT_STREQ(expectedBuf, rendered.c_str()); - - dcarP->release(); - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), emptyFilename)) << "Error getting test data from '" << emptyFilename << "'"; - rendered = dcarP->toJsonV1(); - EXPECT_STREQ(expectedBuf, rendered.c_str()); - dcarP->release(); // ... otherwise the 500 remains and "pollutes" next tests - - - // 6. ContextRegistration: one attribute in contextRegistrationAttributeVector - crrP = new ContextRegistrationResponse(); - attrP = new ContextRegistrationAttribute("Attr1", "AType"); - - crrP->contextRegistration.contextRegistrationAttributeVector.push_back(attrP); - crrP->contextRegistration.providingApplication.set("http://tid.test.com/unitTest6"); - dcarP->responseVector.push_back(crrP); - - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename6)) << "Error getting test data from '" << filename6 << "'"; - rendered = dcarP->toJsonV1(); - EXPECT_STREQ(expectedBuf, rendered.c_str()); - // No release here - the data stays - to be used in the following test scenario - - - - // 7. ContextRegistration: two attributes in contextRegistrationAttributeVector - attrP = new ContextRegistrationAttribute("Attr2", "AType"); - - crrP->contextRegistration.contextRegistrationAttributeVector.push_back(attrP); - crrP->contextRegistration.providingApplication.set("http://tid.test.com/unitTest7"); - - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename7)) << "Error getting test data from '" << filename7 << "'"; - rendered = dcarP->toJsonV1(); - EXPECT_STREQ(expectedBuf, rendered.c_str()); - - dcarP->release(); - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), emptyFilename)) << "Error getting test data from '" << emptyFilename << "'"; - rendered = dcarP->toJsonV1(); - EXPECT_STREQ(expectedBuf, rendered.c_str()); - dcarP->release(); // ... otherwise the 500 remains and "pollutes" next tests - - - // 10. !entityIdVector !contextRegistrationAttributeVector +providingApplication - crrP = new ContextRegistrationResponse(); - - crrP->contextRegistration.providingApplication.set("http://tid.test.com/unitTest10"); - dcarP->responseVector.push_back(crrP); - - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename10)) << "Error getting test data from '" << filename10 << "'"; - rendered = dcarP->toJsonV1(); - EXPECT_STREQ(expectedBuf, rendered.c_str()); - - dcarP->release(); - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), emptyFilename)) << "Error getting test data from '" << emptyFilename << "'"; - rendered = dcarP->toJsonV1(); - EXPECT_STREQ(expectedBuf, rendered.c_str()); - dcarP->release(); // ... otherwise the 500 remains and "pollutes" next tests - - - - // 12. !entityIdVector +contextRegistrationAttributeVector +providingApplication - crrP = new ContextRegistrationResponse(); - attrP = new ContextRegistrationAttribute("Attr12", "AType"); - - crrP->contextRegistration.contextRegistrationAttributeVector.push_back(attrP); - crrP->contextRegistration.providingApplication.set("http://tid.test.com/unitTest12"); - dcarP->responseVector.push_back(crrP); - - dcarP->release(); - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), emptyFilename)) << "Error getting test data from '" << emptyFilename << "'"; - rendered = dcarP->toJsonV1(); - EXPECT_STREQ(expectedBuf, rendered.c_str()); - dcarP->release(); // ... otherwise the 500 remains and "pollutes" next tests - - - - // 14. +entityIdVector !contextRegistrationAttributeVector +providingApplication - crrP = new ContextRegistrationResponse(); - eidP = new EntityId("E14", "EType", "false"); - - crrP->contextRegistration.entityIdVector.push_back(eidP); - crrP->contextRegistration.providingApplication.set("http://tid.test.com/unitTest14"); - dcarP->responseVector.push_back(crrP); - - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename14)) << "Error getting test data from '" << filename14 << "'"; - rendered = dcarP->toJsonV1(); - EXPECT_STREQ(expectedBuf, rendered.c_str()); - - dcarP->release(); - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), emptyFilename)) << "Error getting test data from '" << emptyFilename << "'"; - rendered = dcarP->toJsonV1(); - EXPECT_STREQ(expectedBuf, rendered.c_str()); - dcarP->release(); // ... otherwise the 500 remains and "pollutes" next tests - - - - // 16. +entityIdVector +contextRegistrationAttributeVector +providingApplication - crrP = new ContextRegistrationResponse(); - eidP = new EntityId("E16", "EType", "false"); - attrP = new ContextRegistrationAttribute("Attr16", "AType"); - - crrP->contextRegistration.entityIdVector.push_back(eidP); - crrP->contextRegistration.contextRegistrationAttributeVector.push_back(attrP); - crrP->contextRegistration.providingApplication.set("http://tid.test.com/unitTest16"); - dcarP->responseVector.push_back(crrP); - - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename16)) << "Error getting test data from '" << filename16 << "'"; - rendered = dcarP->toJsonV1(); - EXPECT_STREQ(expectedBuf, rendered.c_str()); - - dcarP->release(); - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), emptyFilename)) << "Error getting test data from '" << emptyFilename << "'"; - rendered = dcarP->toJsonV1(); - EXPECT_STREQ(expectedBuf, rendered.c_str()); - dcarP->release(); // ... otherwise the 500 remains and "pollutes" next tests - - - // 18. StatusCode - dcarP->errorCode.fill(SccBadRequest, "DiscoverContextAvailabilityResponse Unit Test 18"); - - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename18)) << "Error getting test data from '" << filename18 << "'"; - rendered = dcarP->toJsonV1(); - EXPECT_STREQ(expectedBuf, rendered.c_str()); - - dcarP->release(); - rendered = dcarP->toJsonV1(); - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), emptyFilename)) << "Error getting test data from '" << emptyFilename << "'"; - EXPECT_STREQ(expectedBuf, rendered.c_str()); - dcarP->release(); // ... otherwise the 500 remains and "pollutes" next tests - - - // 19. StatusCode - dcarP->errorCode.fill(SccBadRequest); - - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename19)) << "Error getting test data from '" << filename19 << "'"; - rendered = dcarP->toJsonV1(); - EXPECT_STREQ(expectedBuf, rendered.c_str()); - - dcarP->release(); - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), emptyFilename)) << "Error getting test data from '" << emptyFilename << "'"; - rendered = dcarP->toJsonV1(); - EXPECT_STREQ(expectedBuf, rendered.c_str()); - dcarP->release(); // ... otherwise the 500 remains and "pollutes" next tests - - - // 20. Two ContextRegistrationResponses - crrP = new ContextRegistrationResponse(); - eidP = new EntityId("E01", "EType", "false"); - - crrP->contextRegistration.entityIdVector.push_back(eidP); - crrP->contextRegistration.providingApplication.set("http://tid.test.com/unitTest"); - dcarP->responseVector.push_back(crrP); - - crrP = new ContextRegistrationResponse(); - eidP = new EntityId("E02", "EType", "false"); - - crrP->contextRegistration.entityIdVector.push_back(eidP); - crrP->contextRegistration.providingApplication.set("http://tid.test.com/unitTest2"); - dcarP->responseVector.push_back(crrP); - - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename20)) << "Error getting test data from '" << filename20 << "'"; - rendered = dcarP->toJsonV1(); - EXPECT_STREQ(expectedBuf, rendered.c_str()); - - dcarP->release(); - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), emptyFilename)) << "Error getting test data from '" << emptyFilename << "'"; - rendered = dcarP->toJsonV1(); - EXPECT_STREQ(expectedBuf, rendered.c_str()); - - delete dcarP; - - utExit(); -} diff --git a/test/unittests/ngsi9/RegisterContextRequest_test.cpp b/test/unittests/ngsi9/RegisterContextRequest_test.cpp deleted file mode 100644 index a8928fd938..0000000000 --- a/test/unittests/ngsi9/RegisterContextRequest_test.cpp +++ /dev/null @@ -1,257 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include "gtest/gtest.h" - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "common/globals.h" -#include "jsonParse/jsonRequest.h" -#include "ngsi/ParseData.h" - -#include "unittest.h" - - - -/* **************************************************************************** -* -* Tests -* xml_ok -* json_ok -* noContextRegistrationList -* json_noContextRegistration -* emptyContextRegistration -* noProvidingApplication -* json_noProvidingApplication -* emptyProvidingApplication -* json_emptyProvidingApplication -* noEntityIdList -* emptyEntityIdList -* entityIdWithEmptyId -* entityIdWithNoId -* entityIdWithIsPatternTrue -* json_entityIdWithIsPatternTrue -* present -* invalidIsPatternString -* json_invalidIsPatternString -* invalidAttributeName -* overwriteEntityIdType -* json_overwriteEntityIdType -* durationError -* emptyContextRegistrationAttributeName -* emptyContextMetadataName -* emptyContextMetadataValue -* emptyRegistrationMetadataValue -* -*/ - - - -/* **************************************************************************** -* -* json_ok - -*/ -TEST(RegisterContextRequest, json_ok) -{ - ParseData parseData; - const char* inFile = "ngsi9.registerContextRequest.ok.valid.json"; - const char* outFile = "ngsi9.registerContextRequestRendered.ok.valid.json"; - RegisterContextRequest* rcrP = &parseData.rcr.res; - ConnectionInfo ci("", "POST", "1.1"); - JsonRequest* reqP; - std::string out; - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outFile)) << "Error getting test data from '" << outFile << "'"; - - std::string result = jsonTreat(testBuf, &ci, &parseData, RegisterContext, &reqP); - EXPECT_EQ("OK", result) << "this test should be OK"; - - out = rcrP->toJsonV1(); - EXPECT_STREQ(expectedBuf, out.c_str()); - - reqP->release(&parseData); -} - - - -/* **************************************************************************** -* -* json_noContextRegistration - -*/ -TEST(RegisterContextRequest, json_noContextRegistration) -{ - ParseData parseData; - const char* inFile = "ngsi9.registerContextRequest.noContextRegistration.invalid.json"; - const char* outFile = "ngsi9.registerContextResponse.noContextRegistration.valid.json"; - - ConnectionInfo ci("", "POST", "1.1"); - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outFile)) << "Error getting test data from '" << outFile << "'"; - - std::string result = jsonTreat(testBuf, &ci, &parseData, RegisterContext, NULL); - EXPECT_STREQ(expectedBuf, result.c_str()); -} - - - -/* **************************************************************************** -* -* json_noProvidingApplication - -*/ -TEST(RegisterContextRequest, json_noProvidingApplication) -{ - ParseData parseData; - const char* inFile = "ngsi9.registerContextRequest.noProvidingApplication.invalid.json"; - const char* outFile = "ngsi9.registerContextResponse.noProvidingApplication.valid.json"; - ConnectionInfo ci("", "POST", "1.1"); - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outFile)) << "Error getting test data from '" << outFile << "'"; - - std::string result = jsonTreat(testBuf, &ci, &parseData, RegisterContext, NULL); - EXPECT_STREQ(expectedBuf, result.c_str()); -} - - - -/* **************************************************************************** -* -* json_emptyProvidingApplication - -*/ -TEST(RegisterContextRequest, json_emptyProvidingApplication) -{ - ParseData parseData; - const char* inFile = "ngsi9.registerContextRequest.emptyProvidingApplication.invalid.json"; - const char* outFile = "ngsi9.registerContextResponse.emptyProvidingApplication.valid.json"; - ConnectionInfo ci("", "POST", "1.1"); - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outFile)) << "Error getting test data from '" << outFile << "'"; - - std::string result = jsonTreat(testBuf, &ci, &parseData, RegisterContext, NULL); - EXPECT_STREQ(expectedBuf, result.c_str()); -} - - - -/* **************************************************************************** -* -* json_entityIdWithIsPatternTrue - -*/ -TEST(RegisterContextRequest, json_entityIdWithIsPatternTrue) -{ - ParseData parseData; - const char* inFile = "ngsi9.registerContextRequest.entityIdWithIsPatternTrue.valid.json"; - const char* outFile = "ngsi9.registerContextResponse.entityIdWithIsPatternTrue.valid.json"; - ConnectionInfo ci("", "POST", "1.1"); - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outFile)) << "Error getting test data from '" << outFile << "'"; - - std::string result = jsonTreat(testBuf, &ci, &parseData, RegisterContext, NULL); - EXPECT_STREQ(expectedBuf, result.c_str()) << "entityIdWithIsPatternTrue error"; -} - - - -/* **************************************************************************** -* -* json_invalidIsPatternString - -*/ -TEST(RegisterContextRequest, json_invalidIsPatternString) -{ - ParseData parseData; - const char* inFile = "ngsi9.registerContextRequest.invalidIsPatternString.invalid.json"; - const char* expect = "OK"; - ConnectionInfo ci("", "POST", "1.1"); - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - - std::string result = jsonTreat(testBuf, &ci, &parseData, RegisterContext, NULL); - EXPECT_EQ(expect, result); -} - - - -/* **************************************************************************** -* -* json_overwriteEntityIdType - -*/ -TEST(RegisterContextRequest, json_overwriteEntityIdType) -{ - ParseData parseData; - const char* inFile = "ngsi9.registerContextRequest.overwriteEntityIdType.invalid.json"; - ConnectionInfo ci("", "POST", "1.1"); - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - - std::string result = jsonTreat(testBuf, &ci, &parseData, RegisterContext, NULL); - EXPECT_EQ("OK", result) << "error at overwriting EntityIdType"; -} - - - -/* **************************************************************************** -* -* json_reregistration - -*/ -TEST(RegisterContextRequest, json_reregistration) -{ - ParseData parseData; - const char* inFile = "ngsi9.registerContextRequest.reregistration.valid.json"; - const char* expect = "OK"; - ConnectionInfo ci("", "POST", "1.1"); - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - - std::string result = jsonTreat(testBuf, &ci, &parseData, RegisterContext, NULL); - EXPECT_EQ(expect, result); -} diff --git a/test/unittests/ngsi9/RegisterContextResponse_test.cpp b/test/unittests/ngsi9/RegisterContextResponse_test.cpp deleted file mode 100644 index b04e9737f3..0000000000 --- a/test/unittests/ngsi9/RegisterContextResponse_test.cpp +++ /dev/null @@ -1,114 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include "gtest/gtest.h" - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "ngsi9/RegisterContextResponse.h" - -#include "unittest.h" - - - -/* **************************************************************************** -* -* constructors - -* -*/ -TEST(RegisterContextResponse, constructors) -{ - RegisterContextResponse* rcr1 = new RegisterContextResponse(); - RegisterContextResponse rcr2("012301230123012301230123", "PT1S"); - RegisterContextRequest rcr; - RegisterContextResponse rcr3(&rcr); - StatusCode ec(SccBadRequest, "Detail"); - RegisterContextResponse rcr4("012345678901234567890123", ec); - RegisterContextResponse rcr5("012345678901234567890123", "PT1M"); - - std::string out; - - std::string expected5 = "OK"; - - EXPECT_STREQ("", rcr1->registrationId.get().c_str()); - rcr1->release(); - delete rcr1; - - EXPECT_EQ("012301230123012301230123", rcr2.registrationId.get()); - EXPECT_STREQ("", rcr3.registrationId.get().c_str()); - EXPECT_EQ("012345678901234567890123", rcr4.registrationId.get()); - EXPECT_EQ(SccBadRequest, rcr4.errorCode.code); - - out = rcr5.check(""); - - EXPECT_EQ(expected5, out); - -} - - - -/* **************************************************************************** -* -* jsonRender - -*/ -TEST(RegisterContextResponse, jsonRender) -{ - RegisterContextResponse rcr; - std::string rendered; - const char* filename1 = "ngsi9.registerContextResponse.registrationIdOnly.valid.json"; - const char* filename2 = "ngsi9.registerContextResponse.registrationIdAndDuration.valid.json"; - const char* filename3 = "ngsi9.registerContextResponse.registrationIdAndErrorCode.valid.json"; - const char* filename4 = "ngsi9.registerContextResponse.registrationIdAndDurationAndErrorCode.valid.json"; - - utInit(); - - // 1. Only registrationId - rcr.registrationId.set("012345678901234567890123"); - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename1)) << "Error getting test data from '" << filename1 << "'"; - rendered = rcr.toJsonV1(); - EXPECT_STREQ(expectedBuf, rendered.c_str()); - - // 2. registrationId and duration - rcr.duration.set("PT1S"); - - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename2)) << "Error getting test data from '" << filename2 << "'"; - rendered = rcr.toJsonV1(); - EXPECT_STREQ(expectedBuf, rendered.c_str()); - - // 3. registrationId and errorCode - rcr.duration.set(""); - rcr.errorCode.fill(SccBadRequest, "no details"); - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename3)) << "Error getting test data from '" << filename3 << "'"; - rendered = rcr.toJsonV1(); - EXPECT_STREQ(expectedBuf, rendered.c_str()); - - // 4. registrationId and duration and errorCode - rcr.duration.set("PT2S"); - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), filename4)) << "Error getting test data from '" << filename4 << "'"; - rendered = rcr.toJsonV1(); - EXPECT_STREQ(expectedBuf, rendered.c_str()); - - utExit(); -} diff --git a/test/unittests/orionTypes/EntityTypeResponse_test.cpp b/test/unittests/orionTypes/EntityTypeResponse_test.cpp deleted file mode 100644 index 417f693619..0000000000 --- a/test/unittests/orionTypes/EntityTypeResponse_test.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/* -* -* Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Fermin Galan -*/ -#include "orionTypes/EntityTypeResponse.h" -#include "unittests/unittest.h" - - - -/* **************************************************************************** -* -* check -*/ -TEST(EntityTypeResponse, check) -{ - utInit(); - - EntityTypeResponse etR1; - EntityTypeResponse etR2; - - etR1.entityType.type = "myType"; - etR2.entityType.type = ""; - - EXPECT_EQ("OK", etR1.check(V1, false, false, false, "")); - EXPECT_NE("OK", etR2.check(V1, false, false, false, "")); - EXPECT_NE("OK", etR1.check(V1, false, false, false, "foo")); - - utExit(); -} diff --git a/test/unittests/orionTypes/EntityTypeVectorResponse_test.cpp b/test/unittests/orionTypes/EntityTypeVectorResponse_test.cpp deleted file mode 100644 index 3156335e6d..0000000000 --- a/test/unittests/orionTypes/EntityTypeVectorResponse_test.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/* -* -* Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Fermin Galan -*/ -#include "orionTypes/EntityTypeVectorResponse.h" -#include "unittests/unittest.h" - - - -/* **************************************************************************** -* -* check -*/ -TEST(EntityTypeVectorResponse, check) -{ - utInit(); - - EntityType et1("myType"); - EntityType et2(""); - - // EntityTypeVectorResponse with a EntityType (in the vector) that will not fail - EntityTypeVectorResponse etRV1; - etRV1.entityTypeVector.push_back((&et1)); - - // EntityTypeVectorResponse with a EntityType (in the vector) that will fail - EntityTypeVectorResponse etRV2; - etRV2.entityTypeVector.push_back((&et2)); - - EXPECT_EQ("OK", etRV1.check(V1, false, false, false, "")); - - EXPECT_NE("OK", etRV1.check(V1, false, false, false, "foo")); - - EXPECT_NE("OK", etRV2.check(V1, false, false, false, "")); - - utExit(); -} diff --git a/test/unittests/orionTypes/EntityTypeVector_test.cpp b/test/unittests/orionTypes/EntityTypeVector_test.cpp deleted file mode 100644 index 96bf8cbac3..0000000000 --- a/test/unittests/orionTypes/EntityTypeVector_test.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/* -* -* Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Fermin Galan -*/ -#include "orionTypes/EntityTypeVector.h" -#include "unittests/unittest.h" - - - -/* **************************************************************************** -* -* check -*/ -TEST(EntityTypeVector, check) -{ - utInit(); - - EntityType et1("myType"); - EntityType et2(""); - - // EntityTypeVector with a EntityType that will not fail - EntityTypeVector etV1; - etV1.push_back(&et1); - - // EntityTypeVector with a EntityType that will fail - EntityTypeVector etV2; - etV2.push_back(&et2); - - EXPECT_EQ("OK", etV1.check(V1, "")); - - EXPECT_EQ("foo", etV1.check(V1, "foo")); - - EXPECT_EQ("Empty Type", etV2.check(V1, "")); - - utExit(); -} diff --git a/test/unittests/orionTypes/EntityType_test.cpp b/test/unittests/orionTypes/EntityType_test.cpp deleted file mode 100644 index 8042b71f44..0000000000 --- a/test/unittests/orionTypes/EntityType_test.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/* -* -* Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Fermin Galan -*/ -#include "orionTypes/EntityType.h" -#include "unittests/unittest.h" - - - -/* **************************************************************************** -* -* check -*/ -TEST(EntityType, check) -{ - utInit(); - - EntityType et1("myType"); - EntityType et2(""); - - EXPECT_EQ("OK", et1.check(V1, "")); - EXPECT_EQ("Empty Type", et2.check(V1, "")); - EXPECT_EQ("foo", et1.check(V1, "foo")); - - utExit(); -} diff --git a/test/unittests/parse/CompoundValueNode_test.cpp b/test/unittests/parse/CompoundValueNode_test.cpp index 7464b33370..d619427556 100644 --- a/test/unittests/parse/CompoundValueNode_test.cpp +++ b/test/unittests/parse/CompoundValueNode_test.cpp @@ -38,12 +38,12 @@ */ TEST(CompoundValueNode, tree) { + utInit(); + orion::CompoundValueNode* tree = new orion::CompoundValueNode(orion::ValueTypeObject); orion::CompoundValueNode* vec; orion::CompoundValueNode* vecItem; - char* name = (char*) "vecItem"; - - utInit(); + char* name = (char*) "vecItem"; lmTraceLevelSet(LmtCompoundValueAdd, true); vec = tree->add(orion::ValueTypeVector, "vec", ""); @@ -129,9 +129,6 @@ TEST(CompoundValueNode, vectorInvalidAndOk) rendered = tree->toJson(); EXPECT_STREQ(expectedBuf, rendered.c_str()); - tree->shortShow(""); - tree->show(""); - lmTraceLevelSet(LmtCompoundValueAdd, false); delete tree; @@ -175,9 +172,6 @@ TEST(CompoundValueNode, structInvalidAndOk) rendered = tree->toJson(); EXPECT_STREQ(expectedBuf, rendered.c_str()); - tree->shortShow(""); - tree->show(""); - delete tree; lmTraceLevelSet(LmtCompoundValueAdd, false); diff --git a/test/unittests/parse/compoundValue_test.cpp b/test/unittests/parse/compoundValue_test.cpp index 478f4410f9..fca42ac720 100644 --- a/test/unittests/parse/compoundValue_test.cpp +++ b/test/unittests/parse/compoundValue_test.cpp @@ -27,702 +27,9 @@ #include "parse/CompoundValueNode.h" #include "rest/ConnectionInfo.h" #include "rest/RestService.h" -#include "jsonParse/jsonRequest.h" #include "unittest.h" - - -/* **************************************************************************** -* -* updateNoCompoundValue - -*/ -TEST(compoundValue, updateNoCompoundValue) -{ - ParseData reqData; - const char* inFileJson = "ngsi10.updateContextRequest.updateNoCompoundValue.valid.json"; - ConnectionInfo ci("/ngsi10/updateContext", "POST", "1.1"); - ContextAttribute* caP; - std::string result; - - utInit(); - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFileJson)) << "Error getting test data from '" << inFileJson << "'"; - ci.inMimeType = JSON; - result = jsonTreat(testBuf, &ci, &reqData, UpdateContext, NULL); - EXPECT_STREQ("OK", result.c_str()); - caP = reqData.upcr.res.entityVector[0]->attributeVector[0]; - EXPECT_EQ("1", caP->stringValue); - - utExit(); -} - - - -/* **************************************************************************** -* -* updateUnknownPath - -*/ -TEST(compoundValue, updateUnknownPath) -{ - ParseData reqData; - const char* inFileJson = "ngsi10.updateContextRequest.updateUnknownPath.invalid.json"; - const char* outFileJson = "ngsi10.updateContextResponse.updateUnknownPath.valid.json"; - ConnectionInfo ciJson("/ngsi10/updateContext", "POST", "1.1"); - std::string result; - RestService restService = { UpdateContext, 2, { "ngsi10", "updateContext" }, NULL }; - - utInit(); - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFileJson)) << "Error getting test data from '" << inFileJson << "'"; - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outFileJson)) << "Error getting test data from '" << outFileJson << "'"; - - ciJson.inMimeType = JSON; - ciJson.outMimeType = JSON; - ciJson.restServiceP = &restService; - - result = jsonTreat(testBuf, &ciJson, &reqData, UpdateContext, NULL); - EXPECT_STREQ(expectedBuf, result.c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* updateOneStringJson - -*/ -TEST(compoundValue, updateOneStringJson) -{ - ParseData reqData; - const char* inFile = "ngsi10.updateContextRequest.updateOneString.valid.json"; - ConnectionInfo ci("/ngsi10/updateContext", "POST", "1.1"); - ContextAttribute* caP; - orion::CompoundValueNode* cvnRootP; - orion::CompoundValueNode* childP; - RestService restService = { UpdateContext, 2, { "ngsi10", "updateContext" }, NULL }; - - utInit(); - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - ci.restServiceP = &restService; - - std::string result = jsonTreat(testBuf, &ci, &reqData, UpdateContext, NULL); - - EXPECT_STREQ("OK", result.c_str()); - - caP = reqData.upcr.res.entityVector[0]->attributeVector[0]; - - EXPECT_TRUE(caP != NULL); - EXPECT_TRUE(caP->compoundValueP != NULL); - - // Get root of compound value - cvnRootP = caP->compoundValueP; - - // The root should be a struct in this test case - EXPECT_EQ(orion::ValueTypeObject, cvnRootP->valueType); - - // The root should have exactly one child - EXPECT_EQ(1, cvnRootP->childV.size()); - - // The child - childP = cvnRootP->childV[0]; - - EXPECT_EQ("s1", childP->name); - EXPECT_EQ(orion::ValueTypeString, childP->valueType); - EXPECT_EQ("STRING", childP->stringValue); - EXPECT_EQ(0, childP->childV.size()); - - utExit(); -} - - - -/* **************************************************************************** -* -* updateTwoStringsJson - -*/ -TEST(compoundValue, updateTwoStringsJson) -{ - ParseData reqData; - const char* inFile = "ngsi10.updateContextRequest.updateTwoStrings.valid.json"; - ConnectionInfo ci("/ngsi10/updateContext", "POST", "1.1"); - ContextAttribute* caP; - orion::CompoundValueNode* cvnRootP; - orion::CompoundValueNode* childP; - RestService restService = { UpdateContext, 2, { "ngsi10", "updateContext" }, NULL }; - - utInit(); - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - ci.restServiceP = &restService; - - std::string result = jsonTreat(testBuf, &ci, &reqData, UpdateContext, NULL); - - EXPECT_STREQ("OK", result.c_str()); - - caP = reqData.upcr.res.entityVector[0]->attributeVector[0]; - EXPECT_TRUE(caP != NULL); - EXPECT_TRUE(caP->compoundValueP != NULL); - - // Get root of compound value - cvnRootP = caP->compoundValueP; - - // The root should be a struct in this test case - EXPECT_EQ(orion::ValueTypeObject, cvnRootP->valueType); - - // The root should have exactly two children - EXPECT_EQ(2, cvnRootP->childV.size()); - - // child 1 - childP = cvnRootP->childV[0]; - - EXPECT_EQ("s1", childP->name); - EXPECT_EQ(orion::ValueTypeString, childP->valueType); - EXPECT_EQ("STRING", childP->stringValue); - EXPECT_EQ(0, childP->childV.size()); - - // child 2 - childP = cvnRootP->childV[1]; - - EXPECT_EQ("s2", childP->name); - EXPECT_EQ(orion::ValueTypeString, childP->valueType); - EXPECT_EQ("STRING", childP->stringValue); - EXPECT_EQ(0, childP->childV.size()); - - utExit(); -} - - - -/* **************************************************************************** -* -* updateTwoItemsSameNameInStructJson - -*/ -TEST(compoundValue, updateTwoItemsSameNameInStructJson) -{ - ParseData reqData; - const char* inFile = "ngsi10.updateContextRequest.updateTwoItemsSameNameInStruct.valid.json"; - const char* outFile = "ngsi10.updateContextResponse.updateTwoItemsSameNameInStruct.valid.json"; - ConnectionInfo ci("/ngsi10/updateContext", "POST", "1.1"); - RestService restService = { UpdateContext, 2, { "ngsi10", "updateContext" }, NULL }; - - utInit(); - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outFile)) << "Error getting test data from '" << outFile << "'"; - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - ci.restServiceP = &restService; - - std::string result = jsonTreat(testBuf, &ci, &reqData, UpdateContext, NULL); - - EXPECT_STREQ(expectedBuf, result.c_str()); - - utExit(); -} - - - -/* **************************************************************************** -* -* updateContextValueVectorOneItemJson - -*/ -TEST(compoundValue, updateContextValueVectorOneItemJson) -{ - ParseData reqData; - const char* inFile = "ngsi10.updateContextRequest.updateContextValueVectorOneItem.valid.json"; - ConnectionInfo ci("/ngsi10/updateContext", "POST", "1.1"); - ContextAttribute* caP; - orion::CompoundValueNode* cvnRootP; - orion::CompoundValueNode* childP; - RestService restService = { UpdateContext, 2, { "ngsi10", "updateContext" }, NULL }; - - utInit(); - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - ci.restServiceP = &restService; - - std::string result = jsonTreat(testBuf, &ci, &reqData, UpdateContext, NULL); - EXPECT_STREQ("OK", result.c_str()); - - caP = reqData.upcr.res.entityVector[0]->attributeVector[0]; - - EXPECT_TRUE(caP != NULL); - EXPECT_TRUE(caP->compoundValueP != NULL); - - // Get root of compound value - cvnRootP = caP->compoundValueP; - - // The root should be a 'vector' in this test case - EXPECT_EQ(orion::ValueTypeVector, cvnRootP->valueType); - - // The root should have exactly one child - EXPECT_EQ(1, cvnRootP->childV.size()); - - // The child - childP = cvnRootP->childV[0]; - - EXPECT_EQ("item", childP->name); - EXPECT_EQ(orion::ValueTypeString, childP->valueType); - EXPECT_EQ("1", childP->stringValue); - EXPECT_EQ(0, childP->childV.size()); - - utExit(); -} - - - -/* **************************************************************************** -* -* updateContextValueVectorFiveItemsJson - -*/ -TEST(compoundValue, updateContextValueVectorFiveItemsJson) -{ - ParseData reqData; - const char* inFile = "ngsi10.updateContextRequest.updateContextValueVectorFiveItems.valid.json"; - ConnectionInfo ci("/ngsi10/updateContext", "POST", "1.1"); - ContextAttribute* caP; - orion::CompoundValueNode* cvnRootP; - orion::CompoundValueNode* childP; - RestService restService = { UpdateContext, 2, { "ngsi10", "updateContext" }, NULL }; - - utInit(); - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - ci.restServiceP = &restService; - - std::string result = jsonTreat(testBuf, &ci, &reqData, UpdateContext, NULL); - EXPECT_STREQ("OK", result.c_str()); - - caP = reqData.upcr.res.entityVector[0]->attributeVector[0]; - - EXPECT_TRUE(caP != NULL); - EXPECT_TRUE(caP->compoundValueP != NULL); - - // Get root of compound value - cvnRootP = caP->compoundValueP; - - // The root should be a 'vector' in this test case - EXPECT_EQ(orion::ValueTypeVector, cvnRootP->valueType); - - // The root should have five children - EXPECT_EQ(5, cvnRootP->childV.size()); - - // Child 1-5 - std::string value[] = { "1", "2", "3", "4", "5" }; - for (unsigned int childIx = 0; childIx < 5; ++childIx) - { - childP = cvnRootP->childV[childIx]; - - EXPECT_EQ("item", childP->name); - EXPECT_EQ(orion::ValueTypeString, childP->valueType); - EXPECT_EQ(value[childIx], childP->stringValue); - EXPECT_EQ(0, childP->childV.size()); - } - - utExit(); -} - - - -/* **************************************************************************** -* -* updateTwoStructsJson - -*/ -TEST(compoundValue, updateTwoStructsJson) -{ - ParseData reqData; - const char* inFile = "ngsi10.updateContextRequest.updateTwoStructs.valid.json"; - const char* renderedFile = "ngsi.contextAttribute.updateTwoStructsRendered.valid.json"; - ConnectionInfo ci("/ngsi10/updateContext", "POST", "1.1"); - ContextAttribute* caP; - std::string rendered; - RestService restService = { UpdateContext, 2, { "ngsi10", "updateContext" }, NULL }; - - utInit(); - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - ci.restServiceP = &restService; - - std::string result = jsonTreat(testBuf, &ci, &reqData, UpdateContext, NULL); - EXPECT_STREQ("OK", result.c_str()); - - caP = reqData.upcr.res.entityVector[0]->attributeVector[0]; - - - EXPECT_TRUE(caP != NULL); - EXPECT_TRUE(caP->compoundValueP != NULL); - - std::vector emptyMdV; - - ci.outMimeType = JSON; - rendered = caP->toJsonV1(false, UpdateContext, emptyMdV, false); - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), renderedFile)) << "Error getting test data from '" << renderedFile << "'"; - EXPECT_STREQ(expectedBuf, rendered.c_str()); - - orion::CompoundValueNode* cvnRootP; - orion::CompoundValueNode* structP; - orion::CompoundValueNode* childP; - - // Get root of compound value - cvnRootP = caP->compoundValueP; - - // The root should be a 'struct' in this test case - EXPECT_EQ(orion::ValueTypeObject, cvnRootP->valueType); - - // The root should have two children - EXPECT_EQ(2, cvnRootP->childV.size()); - - // Now, child struct 1 - structP = cvnRootP->childV[0]; - - EXPECT_EQ("struct1", structP->name); - EXPECT_EQ(orion::ValueTypeObject, structP->valueType); - EXPECT_EQ(2, structP->childV.size()); - - // Child 1 of struct1 - childP = structP->childV[0]; - - EXPECT_EQ("s1-1", childP->name); - EXPECT_EQ(orion::ValueTypeString, childP->valueType); - EXPECT_EQ("1-1", childP->stringValue); - EXPECT_EQ(0, childP->childV.size()); - - - // Child 2 of struct1 - childP = cvnRootP->childV[0]->childV[1]; - - EXPECT_EQ("s1-2", childP->name); - EXPECT_EQ(orion::ValueTypeString, childP->valueType); - EXPECT_EQ("1-2", childP->stringValue); - EXPECT_EQ(0, childP->childV.size()); - - - - // child struct 2 - structP = cvnRootP->childV[1]; - - EXPECT_EQ("struct2", structP->name); - EXPECT_EQ(orion::ValueTypeObject, structP->valueType); - EXPECT_EQ(2, structP->childV.size()); - - // Child 1 of struct2 - childP = cvnRootP->childV[1]->childV[0]; - - EXPECT_EQ("s2-1", childP->name); - EXPECT_EQ(orion::ValueTypeString, childP->valueType); - EXPECT_EQ("2-1", childP->stringValue); - EXPECT_EQ(0, childP->childV.size()); - - - // Child 2 of struct2 - childP = cvnRootP->childV[1]->childV[1]; - - EXPECT_EQ("s2-2", childP->name); - EXPECT_EQ(orion::ValueTypeString, childP->valueType); - EXPECT_EQ("2-2", childP->stringValue); - EXPECT_EQ(0, childP->childV.size()); - - utExit(); -} - - - -/* **************************************************************************** -* -* sixLevelsJson - -*/ -TEST(compoundValue, sixLevelsJson) -{ - ParseData reqData; - const char* inFile = "ngsi10.updateContextRequest.sixLevels.valid.json"; - const char* renderedFile = "ngsi.contextAttribute.updateSixLevelsRendered.valid.json"; - ConnectionInfo ci("/ngsi10/updateContext", "POST", "1.1"); - ContextAttribute* caP; - std::string rendered; - RestService restService = { UpdateContext, 2, { "ngsi10", "updateContext" }, NULL }; - - utInit(); - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - ci.restServiceP = &restService; - - std::string result = jsonTreat(testBuf, &ci, &reqData, UpdateContext, NULL); - EXPECT_STREQ("OK", result.c_str()); - - caP = reqData.upcr.res.entityVector[0]->attributeVector[0]; - - EXPECT_TRUE(caP != NULL); - EXPECT_TRUE(caP->compoundValueP != NULL); - - std::vector emptyMdV; - - ci.outMimeType = JSON; - rendered = caP->toJsonV1(false, UpdateContext, emptyMdV, false); - EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), renderedFile)) << "Error getting test data from '" << renderedFile << "'"; - EXPECT_STREQ(expectedBuf, rendered.c_str()); - - orion::CompoundValueNode* cvnRootP; - orion::CompoundValueNode* level1; - orion::CompoundValueNode* level2; - orion::CompoundValueNode* level3; - orion::CompoundValueNode* childP; - orion::CompoundValueNode* vitemP; - orion::CompoundValueNode* structP; - - // Get root of compound value - cvnRootP = caP->compoundValueP; - EXPECT_TRUE(cvnRootP != NULL); - - // The root should be a 'struct' in this test case - EXPECT_EQ(orion::ValueTypeObject, cvnRootP->valueType); - - // The root should have one child - EXPECT_EQ(1, cvnRootP->childV.size()); - - - // Now, child 1: level1 - level1 = cvnRootP->childV[0]; - - EXPECT_EQ("level1", level1->name); - EXPECT_EQ(orion::ValueTypeObject, level1->valueType); - EXPECT_EQ("", level1->stringValue); - EXPECT_EQ(2, level1->childV.size()); - - // /level1/level == 1 - childP = level1->childV[0]; - - EXPECT_EQ("level", childP->name); - EXPECT_EQ(orion::ValueTypeString, childP->valueType); - EXPECT_EQ("2", childP->stringValue); - EXPECT_EQ(0, childP->childV.size()); - - - // /level1/level2 == Struct - level2 = level1->childV[1]; - - EXPECT_EQ("level2", level2->name); - EXPECT_EQ(orion::ValueTypeObject, level2->valueType); - EXPECT_EQ(2, level2->childV.size()); - - - // /level1/level2/level == 2 - childP = level2->childV[0]; - - EXPECT_EQ("level", childP->name); - EXPECT_EQ(orion::ValueTypeString, childP->valueType); - EXPECT_EQ("3", childP->stringValue); - EXPECT_EQ(0, childP->childV.size()); - - // /level1/level2/level3 == Vector - level3 = level2->childV[1]; - - EXPECT_EQ("level3", level3->name); - EXPECT_EQ(orion::ValueTypeVector, level3->valueType); - EXPECT_EQ(2, level3->childV.size()); - - // /level1/level2/level3/level4item[0] - vitemP = level3->childV[0]; - - EXPECT_EQ("item", vitemP->name); - EXPECT_EQ(orion::ValueTypeObject, vitemP->valueType); - EXPECT_EQ(2, vitemP->childV.size()); - - // /level1/level2/level3/item[0]/level - childP = vitemP->childV[0]; - - EXPECT_EQ("level", childP->name); - EXPECT_EQ(orion::ValueTypeString, childP->valueType); - EXPECT_EQ("5", childP->stringValue); - EXPECT_EQ(0, childP->childV.size()); - - // /level1/level2/level3/item[0]/struct1 - structP = vitemP->childV[1]; - - EXPECT_EQ("struct1", structP->name); - EXPECT_EQ(orion::ValueTypeObject, structP->valueType); - EXPECT_EQ(3, structP->childV.size()); - - // /level1/level2/level3/item[0]/struct1/level - childP = structP->childV[0]; - - EXPECT_EQ("level", childP->name); - EXPECT_EQ(orion::ValueTypeString, childP->valueType); - EXPECT_EQ("6", childP->stringValue); - EXPECT_EQ(0, childP->childV.size()); - - // /level1/level2/level3/item[0]/struct1/s1-1 - childP = structP->childV[1]; - - EXPECT_EQ("s1-1" , childP->name); - EXPECT_EQ(orion::ValueTypeString, childP->valueType); - EXPECT_EQ("1-1", childP->stringValue); - EXPECT_EQ(0, childP->childV.size()); - - // /level1/level2/level3/item[0]/struct1/s1-2 - childP = structP->childV[2]; - - EXPECT_EQ("s1-2" , childP->name); - EXPECT_EQ(orion::ValueTypeString, childP->valueType); - EXPECT_EQ("1-2", childP->stringValue); - EXPECT_EQ(0, childP->childV.size()); - - - // /level1/level2/level3/item[1] - vitemP = level3->childV[1]; - - EXPECT_EQ("item", vitemP->name); - EXPECT_EQ(orion::ValueTypeObject, vitemP->valueType); - EXPECT_EQ(2, vitemP->childV.size()); - - // /level1/level2/level3/item[1]/level - childP = vitemP->childV[0]; - - EXPECT_EQ("level", childP->name); - EXPECT_EQ(orion::ValueTypeString, childP->valueType); - EXPECT_EQ("5", childP->stringValue); - EXPECT_EQ(0, childP->childV.size()); - - // /level1/level2/level3/item[1]/struct2 - structP = vitemP->childV[1]; - - EXPECT_EQ("struct2", structP->name); - EXPECT_EQ(orion::ValueTypeObject, structP->valueType); - EXPECT_EQ(3, structP->childV.size()); - - // /level1/level2/level3/item[1]/struct2/level - childP = structP->childV[0]; - - EXPECT_EQ("level", childP->name); - EXPECT_EQ(orion::ValueTypeString, childP->valueType); - EXPECT_EQ("6", childP->stringValue); - EXPECT_EQ(0, childP->childV.size()); - - // /level1/level2/level3/item[1]/struct2/s2-1 - childP = structP->childV[1]; - - EXPECT_EQ("s2-1" , childP->name); - EXPECT_EQ(orion::ValueTypeString, childP->valueType); - EXPECT_EQ("2-1", childP->stringValue); - EXPECT_EQ(0, childP->childV.size()); - - // /level1/level2/level3/item[1]/struct2/s2-2 - childP = structP->childV[2]; - - EXPECT_EQ("s2-2" , childP->name); - EXPECT_EQ(orion::ValueTypeString, childP->valueType); - EXPECT_EQ("2-2", childP->stringValue); - EXPECT_EQ(0, childP->childV.size()); - - utExit(); -} - - - -/* **************************************************************************** -* -* updateOneStringAndOneVectorInSeparateContextValuesJson - -*/ -TEST(compoundValue, updateOneStringAndOneVectorInSeparateContextValuesJson) -{ - ParseData reqData; - const char* inFile = "ngsi10.updateContextRequest.updateOneStringAndOneVectorInSeparateContextValues.valid.json"; - ConnectionInfo ci("/ngsi10/updateContext", "POST", "1.1"); - ContextAttribute* caP; - orion::CompoundValueNode* cvnRootP; - orion::CompoundValueNode* childP; - RestService restService = { UpdateContext, 2, { "ngsi10", "updateContext" }, NULL }; - - utInit(); - - EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), inFile)) << "Error getting test data from '" << inFile << "'"; - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - ci.restServiceP = &restService; - - std::string result = jsonTreat(testBuf, &ci, &reqData, UpdateContext, NULL); - EXPECT_STREQ("OK", result.c_str()); - - caP = reqData.upcr.res.entityVector[0]->attributeVector[0]; - - EXPECT_TRUE(caP != NULL); - EXPECT_TRUE(caP->compoundValueP != NULL); - - // Get root of compound value - cvnRootP = caP->compoundValueP; - - // The root should be a struct in this test case - EXPECT_EQ(orion::ValueTypeObject, cvnRootP->valueType); - - // The root should have exactly one child - EXPECT_EQ(1, cvnRootP->childV.size()); - - // The child - childP = cvnRootP->childV[0]; - - EXPECT_EQ("s1", childP->name); - EXPECT_EQ(orion::ValueTypeString, childP->valueType); - EXPECT_EQ("STRING", childP->stringValue); - EXPECT_EQ(0, childP->childV.size()); - - - // - // Now the second ContextAttribute, that also has a Compound value - // - caP = reqData.upcr.res.entityVector[0]->attributeVector[1]; - - EXPECT_TRUE(caP != NULL); - EXPECT_TRUE(caP->compoundValueP != NULL); - - // Get root of compound value - cvnRootP = caP->compoundValueP; - - // The root should be a vector in this test case - EXPECT_EQ(orion::ValueTypeVector, cvnRootP->valueType); - - // The root should have four children - EXPECT_EQ(4, cvnRootP->childV.size()); - - // The children - const char* value[] = { "I-0", "I-1", "I-2", "I-3" }; - for (unsigned int ix = 0; ix < 4; ++ix) - { - childP = cvnRootP->childV[ix]; - - EXPECT_EQ("item", childP->name); - EXPECT_EQ(orion::ValueTypeString, childP->valueType); - EXPECT_EQ(value[ix], childP->stringValue); - EXPECT_EQ(0, childP->childV.size()); - - } - - utExit(); -} - - - /* **************************************************************************** * * tenCompounds - @@ -730,14 +37,14 @@ TEST(compoundValue, updateOneStringAndOneVectorInSeparateContextValuesJson) */ TEST(compoundValue, tenCompounds) { + utInit(); + ParseData reqData; UpdateContextRequest* upcrP; - std::string rendered; - - utInit(); + std::string rendered; upcrP = &reqData.upcr.res; - rendered = upcrP->toJsonV1(false); + rendered = upcrP->toJsonV1(); utExit(); } diff --git a/test/unittests/parse/nullTreat_test.cpp b/test/unittests/parse/nullTreat_test.cpp deleted file mode 100644 index 4efa4db249..0000000000 --- a/test/unittests/parse/nullTreat_test.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/* -* -* Copyright 2014 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "unittest.h" - -#include "parse/nullTreat.h" - - - -/* **************************************************************************** -* -* all - -*/ -TEST(nullTreat, all) -{ - std::string s; - - utInit(); - s = jsonNullTreat("/1/2/3", "27", NULL); - EXPECT_EQ("OK", s); - - utExit(); -} diff --git a/test/unittests/rest/OrionError_test.cpp b/test/unittests/rest/OrionError_test.cpp index 83a697d112..ee4d76c797 100644 --- a/test/unittests/rest/OrionError_test.cpp +++ b/test/unittests/rest/OrionError_test.cpp @@ -39,17 +39,20 @@ */ TEST(OrionError, all) { - StatusCode sc(SccBadRequest, "no details 2"); OrionError e0; - OrionError e1(SccOk, "no details 3"); - OrionError e3(sc); - OrionError e4(SccOk, "Good Request"); + OrionError e1; + OrionError e3; + OrionError e4; std::string out; const char* outfile1 = "orion.orionError.all1.valid.json"; const char* outfile2 = "orion.orionError.all3.valid.json"; const char* outfile3 = "orion.orionError.all4.valid.json"; ConnectionInfo ci; + e1.fill(SccOk, "no details 3"); + e3.fill(SccBadRequest, "no details 2"); + e4.fill(SccOk, "Good Request"); + ci.outMimeType = JSON; EXPECT_EQ(SccNone, e0.code); @@ -60,9 +63,9 @@ TEST(OrionError, all) EXPECT_EQ("OK", e1.error); EXPECT_EQ("no details 3", e1.description); - EXPECT_EQ(sc.code, e3.code); - EXPECT_EQ(sc.reasonPhrase, e3.error); - EXPECT_EQ(sc.details, e3.description); + EXPECT_EQ(SccBadRequest, e3.code); + EXPECT_EQ("BadRequest", e3.error); + EXPECT_EQ("no details 2", e3.description); EXPECT_EQ(SccOk, e4.code); EXPECT_EQ("OK", e4.error); @@ -70,19 +73,19 @@ TEST(OrionError, all) ci.outMimeType = JSON; - out = e1.toJsonV1(); + out = e1.toJson(); EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'"; EXPECT_STREQ(expectedBuf, out.c_str()); - out = e3.toJsonV1(); + out = e3.toJson(); EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile2)) << "Error getting test data from '" << outfile2 << "'"; EXPECT_STREQ(expectedBuf, out.c_str()); - out = e4.toJsonV1(); + out = e4.toJson(); EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile3)) << "Error getting test data from '" << outfile3 << "'"; diff --git a/test/unittests/rest/RestService_test.cpp b/test/unittests/rest/RestService_test.cpp deleted file mode 100644 index 4dc2e1da73..0000000000 --- a/test/unittests/rest/RestService_test.cpp +++ /dev/null @@ -1,189 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include -#include - -#include "logMsg/logMsg.h" -#include "logMsg/traceLevels.h" - -#include "ngsi/ParseData.h" -#include "ngsi/Request.h" -#include "serviceRoutines/postRegisterContext.h" -#include "serviceRoutines/postDiscoverContextAvailability.h" -#include "serviceRoutines/badVerbPostOnly.h" - -#include "rest/restReply.h" -#include "rest/ConnectionInfo.h" -#include "rest/RestService.h" -#include "rest/rest.h" - -#include "unittests/unittest.h" - - - -/* **************************************************************************** -* -* service routine vectors - -*/ -#define RC RegisterContext -#define DCA DiscoverContextAvailability - -RestService postV[] = -{ - { RC, 2, { "ngsi9", "registerContext" }, postRegisterContext }, - { InvalidRequest, 0, {}, NULL } -}; - -RestService badVerbs[] = -{ - { RC, 2, { "ngsi9", "registerContext" }, badVerbPostOnly }, - { InvalidRequest, 0, {}, NULL } -}; - -RestService postV2[] = -{ - { RC, 2, { "ngsi9", "registerContext" }, postRegisterContext }, - { DCA, 2, { "ngsi9", "discoverContextAvailability" }, postDiscoverContextAvailability }, - { InvalidRequest, 0, {}, NULL } -}; - -RestService badVerbs2[] = -{ - { DCA, 2, { "ngsi9", "discoverContextAvailability" }, badVerbPostOnly }, - { RC, 2, { "ngsi9", "registerContext" }, badVerbPostOnly }, - { InvalidRequest, 0, {}, NULL } -}; - - - -/* **************************************************************************** -* -* payloadParse - -*/ -TEST(RestService, payloadParse) -{ - ConnectionInfo ci("/ngsi9/registerContext", "POST", "1.1"); - ParseData parseData; - const char* infile1 = "ngsi9.registerContext.ok.valid.json"; - std::string out; - std::vector compV; - JsonDelayedRelease jsonRelease; - - compV.push_back("ngsi9"); - compV.push_back("registerContext"); - - utInit(); - - // - // 1. JSON - // - EXPECT_EQ("OK", testDataFromFile(testBuf, - sizeof(testBuf), - infile1)) << "Error getting test data from '" << infile1 << "'"; - - ci.inMimeType = JSON; - ci.outMimeType = JSON; - ci.payload = testBuf; - ci.payloadSize = strlen(testBuf); - - out = payloadParse(&ci, &parseData, &postV[0], NULL, &jsonRelease, compV); - EXPECT_EQ("OK", out); - - - // - // 2. NOMIMETYPE - // - EXPECT_EQ("OK", testDataFromFile(testBuf, - sizeof(testBuf), - infile1)) << "Error getting test data from '" << infile1 << "'"; - - ci.inMimeType = NOMIMETYPE; - ci.outMimeType = JSON; - ci.payload = (char*) "123"; - ci.payloadSize = strlen(ci.payload); - - out = payloadParse(&ci, &parseData, &postV[0], NULL, &jsonRelease, compV); - EXPECT_EQ("Bad inMimeType", out); - - utExit(); -} - - - -/* **************************************************************************** -* -* noSuchService - -*/ -TEST(RestService, noSuchServiceAndNotFound) -{ - ConnectionInfo ci("/ngsi9/discoverContextAvailability", "POST", "1.1"); - ci.servicePathV.push_back(""); - - const char* infile = "ngsi9.discoverContextAvailabilityRequest.ok.valid.json"; - const char* outfile1 = "ngsi9.discoverContextAvailabilityRsponse.serviceNotRecognized.valid.json"; - const char* outfile2 = "ngsi9.discoverContextAvailabilityRsponse.notFound.valid.json"; - std::string out; - RestService restService = { DiscoverContextAvailability, 2, { "ngsi9", "discoverContextAvailability" }, NULL }; - - utInit(); - - // No such service - EXPECT_EQ("OK", testDataFromFile(testBuf, - sizeof(testBuf), - infile)) << "Error getting test data from '" << infile << "'"; - EXPECT_EQ("OK", testDataFromFile(expectedBuf, - sizeof(expectedBuf), - outfile1)) << "Error getting test data from '" << outfile1 << "'"; - - ci.outMimeType = JSON; - ci.inMimeType = JSON; - ci.payload = testBuf; - ci.payloadSize = strlen(testBuf); - ci.restServiceP = &restService; - - serviceVectorsSet(NULL, NULL, postV, NULL, NULL, NULL, badVerbs); - out = orion::requestServe(&ci); - EXPECT_STREQ(expectedBuf, out.c_str()); - - // Not found - EXPECT_EQ("OK", testDataFromFile(testBuf, - sizeof(testBuf), - infile)) << "Error getting test data from '" << infile << "'"; - EXPECT_EQ("OK", testDataFromFile(expectedBuf, - sizeof(expectedBuf), - outfile2)) << "Error getting test data from '" << outfile2 << "'"; - - ci.outMimeType = JSON; - ci.inMimeType = JSON; - ci.payload = testBuf; - ci.payloadSize = strlen(testBuf); - - serviceVectorsSet(NULL, NULL, postV2, NULL, NULL, NULL, badVerbs2); - out = orion::requestServe(&ci); - - EXPECT_STREQ(expectedBuf, out.c_str()); - - utExit(); -} diff --git a/test/unittests/rest/restReply_test.cpp b/test/unittests/rest/restReply_test.cpp index 86dc9c1208..203b8c351c 100644 --- a/test/unittests/rest/restReply_test.cpp +++ b/test/unittests/rest/restReply_test.cpp @@ -45,10 +45,10 @@ #define TEST_SIZE (4 * 1024 * 1024) TEST(restReply, MHD_create_response_from_data_error) { - ConnectionInfo ci("/ngsi/XXX", "GET", "1.1"); - char* answer = (char*) malloc(TEST_SIZE); - utInit(); + + ConnectionInfo ci("/ngsi/XXX", "GET", "1.1"); + char* answer = (char*) malloc(TEST_SIZE); if (answer != NULL) { diff --git a/test/unittests/rest/rest_test.cpp b/test/unittests/rest/rest_test.cpp index e0199e643b..da35a027fe 100644 --- a/test/unittests/rest/rest_test.cpp +++ b/test/unittests/rest/rest_test.cpp @@ -95,7 +95,6 @@ TEST(rest, servicePathSplit) // 1. OK - as no Service Path has been received ... LM_M(("---- 1 -----")); ci1.httpHeaders.servicePath = ""; - ci1.apiVersion = V1; r = servicePathSplit(&ci1); EXPECT_EQ(0, r); LM_M(("---- 1 -----")); @@ -105,7 +104,6 @@ TEST(rest, servicePathSplit) ci2.httpHeaders.servicePathReceived = true; LM_M(("---- 2 -----")); ci2.httpHeaders.servicePath = "/h1/_h2/h3/_h4/h5/_h6/h7/_h8/h9/_h10h10h10"; - ci2.apiVersion = V1; r = servicePathSplit(&ci2); EXPECT_EQ(0, r); LM_M(("---- 2 -----")); @@ -114,7 +112,6 @@ TEST(rest, servicePathSplit) LM_M(("---- 3 -----")); ci3.httpHeaders.servicePathReceived = true; ci3.httpHeaders.servicePath = "/h1/_h2/h3/_h4/h5/_h6/h7/_h8/h9/_h10h10h10, /1/2/3"; - ci3.apiVersion = V1; r = servicePathSplit(&ci3); EXPECT_EQ(0, r); EXPECT_STREQ("", ci3.answer.c_str()); @@ -124,7 +121,6 @@ TEST(rest, servicePathSplit) LM_M(("---- 4 -----")); ci4.httpHeaders.servicePathReceived = true; ci4.httpHeaders.servicePath = "/home/kz/01, /home/kz/02, /home/kz/03, /home/kz/04, /home/kz/05, /home/kz/06, /home/kz/07, /home/kz/08, /home/kz/09"; - ci4.apiVersion = V1; r = servicePathSplit(&ci4); EXPECT_EQ(0, r); EXPECT_STREQ("", ci4.answer.c_str()); @@ -134,9 +130,8 @@ TEST(rest, servicePathSplit) LM_M(("---- 5 -----")); ci5.httpHeaders.servicePathReceived = true; ci5.httpHeaders.servicePath = "/home/kz/01, /home/kz/02, /home/kz/03, /home/kz/04, /home/kz/05, /home/kz/06, /home/kz/07, /home/kz/08, /home/kz/09, /home/kz/10, /home/kz/11"; - ci5.apiVersion = V1; r = servicePathSplit(&ci5); EXPECT_EQ(-1, r); - EXPECT_EQ(137, ci5.answer.size()); + EXPECT_EQ(105, ci5.answer.size()); LM_M(("---- 5 -----")); } diff --git a/test/unittests/serviceRoutines/badVerbAllFour_test.cpp b/test/unittests/serviceRoutines/badVerbAllFour_test.cpp deleted file mode 100644 index 73ab65de9b..0000000000 --- a/test/unittests/serviceRoutines/badVerbAllFour_test.cpp +++ /dev/null @@ -1,82 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include - -#include "serviceRoutines/badVerbAllFour.h" -#include "rest/RestService.h" -#include "rest/rest.h" - -#include "unittests/unittest.h" - - - -/* **************************************************************************** -* -* badVerbV - -*/ -static RestService badVerbV[] = -{ - { IndividualContextEntity, 3, { "ngsi10", "contextEntities", "*" }, badVerbAllFour }, - { IndividualContextEntity, 2, { "ngsi10", "contextEntities" }, badVerbAllFour }, - { IndividualContextEntity, 1, { "ngsi10" }, badVerbAllFour }, - { InvalidRequest, 0, { }, NULL } -}; - - - -/* **************************************************************************** -* -* error - -*/ -TEST(badVerbAllFour, error) -{ - ConnectionInfo ci1("/ngsi10/contextEntities/123", "PUST", "1.1"); - ConnectionInfo ci2("/ngsi10/contextEntities", "PUST", "1.1"); - std::string out; - RestService restService1 = { VersionRequest, 3, { "ngsi10", "contextEntities", "123" }, NULL }; - RestService restService2 = { VersionRequest, 2, { "ngsi10", "contextEntities" }, NULL }; - - utInit(); - - ci1.apiVersion = V1; - ci1.restServiceP = &restService1; - - serviceVectorsSet(NULL, NULL, NULL, NULL, NULL, NULL, badVerbV); - out = orion::requestServe(&ci1); - - EXPECT_EQ("", out); - EXPECT_EQ("Allow", ci1.httpHeader[0]); - EXPECT_EQ("POST, GET, PUT, DELETE", ci1.httpHeaderValue[0]); - - ci2.apiVersion = V1; - ci2.restServiceP = &restService2; - - out = orion::requestServe(&ci2); - EXPECT_EQ("", out); - EXPECT_EQ("Allow", ci2.httpHeader[0]); - EXPECT_EQ("POST, GET, PUT, DELETE", ci2.httpHeaderValue[0]); - - utExit(); -} diff --git a/test/unittests/serviceRoutines/badVerbGetDeleteOnly_test.cpp b/test/unittests/serviceRoutines/badVerbGetDeleteOnly_test.cpp index 4f94893709..1fe84b2a2c 100644 --- a/test/unittests/serviceRoutines/badVerbGetDeleteOnly_test.cpp +++ b/test/unittests/serviceRoutines/badVerbGetDeleteOnly_test.cpp @@ -64,11 +64,10 @@ static RestService badVerbV[] = TEST(badVerbGetDeleteOnly, ok) { ConnectionInfo ci("/statistics", "PUT", "1.1"); - std::string expected = ""; // Bad verb gives no payload, only HTTP headers + std::string expected = "{\"error\":\"MethodNotAllowed\",\"description\":\"method not allowed\"}"; std::string out; RestService restService = { StatisticsRequest, 1, { "statistics" }, NULL }; - ci.apiVersion = V1; ci.restServiceP = &restService; serviceVectorsSet(getV, NULL, NULL, NULL, deleteV, NULL, badVerbV); diff --git a/test/unittests/serviceRoutines/badVerbGetOnly_test.cpp b/test/unittests/serviceRoutines/badVerbGetOnly_test.cpp index 26e7afe23d..ee56623c74 100644 --- a/test/unittests/serviceRoutines/badVerbGetOnly_test.cpp +++ b/test/unittests/serviceRoutines/badVerbGetOnly_test.cpp @@ -58,7 +58,7 @@ static RestService badVerbV[] = TEST(badVerbGetOnly, ok) { ConnectionInfo ci("/version", "PUT", "1.1"); - std::string expected = ""; // Bad verb gives no payload, only HTTP headers + std::string expected = "{\"error\":\"MethodNotAllowed\",\"description\":\"method not allowed\"}"; std::string out; RestService restService = { VersionRequest, 1, { "version", }, NULL }; diff --git a/test/unittests/serviceRoutines/badVerbGetPostDeleteOnly_test.cpp b/test/unittests/serviceRoutines/badVerbGetPostDeleteOnly_test.cpp deleted file mode 100644 index b32da1b1be..0000000000 --- a/test/unittests/serviceRoutines/badVerbGetPostDeleteOnly_test.cpp +++ /dev/null @@ -1,75 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include - -#include "gtest/gtest.h" - -#include "serviceRoutines/badVerbGetPostDeleteOnly.h" -#include "rest/RestService.h" -#include "rest/rest.h" - - - -/* **************************************************************************** -* -* badVerbV - -*/ -#define ICEA IndividualContextEntityAttribute -#define IR InvalidRequest - -static RestService badVerbV[] = -{ - { ICEA, 5, { "ngsi10", "contextEntities", "*", "attributes", "*" }, badVerbGetPostDeleteOnly }, - { IR, 0, { }, NULL } -}; - - - -/* **************************************************************************** -* -* ok - -*/ -TEST(badVerbGetPostDeleteOnly, ok) -{ - ConnectionInfo ci("/ngsi10/contextEntities/entityId01/attributes/temperature", "PUT", "1.1"); - std::string expected = ""; // Bad verb gives no payload, only HTTP headers - std::string out; - RestService restService = - { - VersionRequest, - 5, { "ngsi10", "contextEntities", "entityId01", "attributes", "temperature" }, - NULL - }; - - ci.apiVersion = V1; - ci.restServiceP = &restService; - - serviceVectorsSet(NULL, NULL, NULL, NULL, NULL, NULL, badVerbV); - out = orion::requestServe(&ci); - - EXPECT_EQ(expected, out); - EXPECT_EQ("Allow", ci.httpHeader[0]); - EXPECT_EQ("GET, POST, DELETE", ci.httpHeaderValue[0]); -} diff --git a/test/unittests/serviceRoutines/badVerbGetPostOnly_test.cpp b/test/unittests/serviceRoutines/badVerbGetPostOnly_test.cpp index c4f1421047..9de0c4ac6b 100644 --- a/test/unittests/serviceRoutines/badVerbGetPostOnly_test.cpp +++ b/test/unittests/serviceRoutines/badVerbGetPostOnly_test.cpp @@ -38,8 +38,8 @@ */ static RestService badVerbV[] = { - { ContextEntitiesByEntityId, 3, { "ngsi9", "contextEntities", "*" }, badVerbGetPostOnly }, - { InvalidRequest, 0, { }, NULL } + { EntitiesRequest, 2, { "v2", "entities" }, badVerbGetPostOnly }, + { InvalidRequest, 0, { }, NULL } }; @@ -50,12 +50,11 @@ static RestService badVerbV[] = */ TEST(badVerbGetPostOnly, ok) { - ConnectionInfo ci("/ngsi9/contextEntities/aaa", "PUT", "1.1"); - std::string expected = ""; // no payload for bad verb, only http headers to indicate the error + ConnectionInfo ci("/v2/entities", "PUT", "1.1"); + std::string expected = "{\"error\":\"MethodNotAllowed\",\"description\":\"method not allowed\"}"; std::string out; - RestService restService = { VersionRequest, 3, { "ngsi9", "contextEntities", "aaa" }, NULL }; + RestService restService = { VersionRequest, 3, { "foo", "bar", "aaa" }, NULL }; - ci.apiVersion = V1; ci.restServiceP = &restService; serviceVectorsSet(NULL, NULL, NULL, NULL, NULL, NULL, badVerbV); diff --git a/test/unittests/serviceRoutines/badVerbGetPutDeleteOnly_test.cpp b/test/unittests/serviceRoutines/badVerbGetPutDeleteOnly_test.cpp index ff28198780..befa178a11 100644 --- a/test/unittests/serviceRoutines/badVerbGetPutDeleteOnly_test.cpp +++ b/test/unittests/serviceRoutines/badVerbGetPutDeleteOnly_test.cpp @@ -38,8 +38,8 @@ */ static RestService badVerbV[] = { - { AttributeValueInstance, 6, { "ngsi10", "contextEntities", "*", "attributes", "*", "*" }, badVerbGetPutDeleteOnly }, - { InvalidRequest, 0, { }, NULL } + { EntityAttributeRequest, 5, { "v2", "entities", "*", "attrs", "*" }, badVerbGetPutDeleteOnly }, + { InvalidRequest, 0, { }, NULL } }; @@ -50,17 +50,16 @@ static RestService badVerbV[] = */ TEST(badVerbGetPutDeleteOnly, ok) { - ConnectionInfo ci("/ngsi10/contextEntities/entityId01/attributes/temperature/14", "POST", "1.1"); - std::string expected = ""; // Bad verb gives no payload, only HTTP headers + ConnectionInfo ci("/v2/entities/entityId01/attrs/temperature", "POST", "1.1"); + std::string expected = "{\"error\":\"MethodNotAllowed\",\"description\":\"method not allowed\"}"; std::string out; RestService restService = { - VersionRequest, - 6, { "ngsi10", "contextEntities", "entityId01", "attributes", "temperature", "14" }, + EntityAttributeRequest, + 5, { "v2", "entities", "entityId01", "attrs", "temperature" }, NULL }; - ci.apiVersion = V1; ci.restServiceP = &restService; serviceVectorsSet(NULL, NULL, NULL, NULL, NULL, NULL, badVerbV); diff --git a/test/unittests/serviceRoutines/badVerbPostOnly_test.cpp b/test/unittests/serviceRoutines/badVerbPostOnly_test.cpp index 33e486e114..256a5b6bfb 100644 --- a/test/unittests/serviceRoutines/badVerbPostOnly_test.cpp +++ b/test/unittests/serviceRoutines/badVerbPostOnly_test.cpp @@ -38,8 +38,8 @@ */ static RestService badVerbV[] = { - { RegisterContext, 2, { "ngsi9", "registerContext" }, badVerbPostOnly }, - { InvalidRequest, 0, { }, NULL } + { BatchUpdateRequest, 3, { "v2", "op", "update" }, badVerbPostOnly }, + { InvalidRequest, 0, { }, NULL } }; @@ -50,10 +50,10 @@ static RestService badVerbV[] = */ TEST(badVerbPostOnly, ok) { - ConnectionInfo ci("/ngsi9/registerContext", "PUT", "1.1"); - std::string expected = ""; // Bad verb gives no payload, only HTTP headers + ConnectionInfo ci("/v2/op/update", "PUT", "1.1"); + std::string expected = "{\"error\":\"MethodNotAllowed\",\"description\":\"method not allowed\"}"; std::string out; - RestService restService = { RegisterContext, 2, { "ngsi9", "registerContext" }, NULL }; + RestService restService = { BatchUpdateRequest, 3, { "v2", "op", "update" }, NULL }; ci.restServiceP = &restService; diff --git a/test/unittests/serviceRoutines/exitTreat_test.cpp b/test/unittests/serviceRoutines/exitTreat_test.cpp index 298da7b890..46521608ab 100644 --- a/test/unittests/serviceRoutines/exitTreat_test.cpp +++ b/test/unittests/serviceRoutines/exitTreat_test.cpp @@ -66,7 +66,6 @@ TEST(exitTreat, error) utInit(); harakiri = true; - ci.apiVersion = V1; ci.restServiceP = &restService; serviceVectorsSet(getV, NULL, NULL, NULL, NULL, NULL, NULL); diff --git a/test/unittests/serviceRoutines/putIndividualContextEntityAttribute_test.cpp b/test/unittests/serviceRoutines/putIndividualContextEntityAttribute_test.cpp deleted file mode 100644 index acd6c56b9c..0000000000 --- a/test/unittests/serviceRoutines/putIndividualContextEntityAttribute_test.cpp +++ /dev/null @@ -1,99 +0,0 @@ -/* -* -* Copyright 2014 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: TID Developer -*/ -#include - -#include "logMsg/logMsg.h" - -#include "serviceRoutines/putIndividualContextEntityAttribute.h" -#include "serviceRoutines/badRequest.h" -#include "rest/RestService.h" -#include "rest/rest.h" - -#include "unittests/unittest.h" - - - -/* **************************************************************************** -* -* rs - -*/ -#define ICEA IndividualContextEntityAttribute -#define IR InvalidRequest - -static RestService putV[] = -{ - { ICEA, 5, { "ngsi10", "contextEntities", "*", "attributes", "*" }, putIndividualContextEntityAttribute }, - { IR, 0, { }, NULL } -}; - -static RestService badVerbV[] = -{ - { IR, 0, { "*", "*", "*", "*", "*", "*" }, badRequest }, - { IR, 0, { }, NULL } -}; - - - -/* **************************************************************************** -* -* json - -*/ -TEST(putIndividualContextEntityAttribute, json) -{ - ConnectionInfo ci("/ngsi10/contextEntities/entity11/attributes/temperature", "PUT", "1.1"); - - ci.servicePathV.push_back(""); - - const char* infile = "ngsi10.updateContextAttributeRequest.putAttribute.valid.json"; - const char* outfile = "ngsi10.updateContextAttributeResponse.notFound.valid.json"; - std::string out; - RestService restService = - { - VersionRequest, - 5, { "ngsi10", "contextEntities", "entity11", "attributes", "temperature" }, - NULL - }; - - EXPECT_EQ("OK", testDataFromFile(testBuf, - sizeof(testBuf), - infile)) << "Error getting test data from '" << infile << "'"; - - EXPECT_EQ("OK", testDataFromFile(expectedBuf, - sizeof(expectedBuf), - outfile)) << "Error getting test data from '" << outfile << "'"; - - ci.outMimeType = JSON; - ci.inMimeType = JSON; - ci.payload = testBuf; - ci.payloadSize = strlen(testBuf); - ci.restServiceP = &restService; - - serviceVectorsSet(NULL, putV, NULL, NULL, NULL, NULL, badVerbV); - out = orion::requestServe(&ci); - - EXPECT_STREQ(expectedBuf, out.c_str()); - - utExit(); -} diff --git a/test/unittests/serviceRoutines/putSubscriptionConvOp_test.cpp b/test/unittests/serviceRoutines/putSubscriptionConvOp_test.cpp deleted file mode 100644 index 1d28b815dc..0000000000 --- a/test/unittests/serviceRoutines/putSubscriptionConvOp_test.cpp +++ /dev/null @@ -1,84 +0,0 @@ -/* -* -* Copyright 2013 Telefonica Investigacion y Desarrollo, S.A.U -* -* This file is part of Orion Context Broker. -* -* Orion Context Broker is free software: you can redistribute it and/or -* modify it under the terms of the GNU Affero General Public License as -* published by the Free Software Foundation, either version 3 of the -* License, or (at your option) any later version. -* -* Orion Context Broker is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero -* General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with Orion Context Broker. If not, see http://www.gnu.org/licenses/. -* -* For those usages not covered by this license please contact with -* iot_support at tid dot es -* -* Author: Ken Zangelin -*/ -#include - -#include "logMsg/logMsg.h" - -#include "serviceRoutines/postSubscribeContext.h" -#include "serviceRoutines/putSubscriptionConvOp.h" -#include "serviceRoutines/deleteSubscriptionConvOp.h" -#include "serviceRoutines/badVerbPutDeleteOnly.h" -#include "serviceRoutines/badRequest.h" -#include "rest/RestService.h" -#include "rest/rest.h" - -#include "unittests/unittest.h" - - - -/* **************************************************************************** -* -* badVerbV - -*/ -static RestService badVerbV[] = -{ - { Ngsi10SubscriptionsConvOp, 3, { "ngsi10", "contextSubscriptions", "*" }, badVerbPutDeleteOnly }, - { InvalidRequest, 0, { "*", "*", "*", "*", "*", "*" }, badRequest }, -}; - - - -/* **************************************************************************** -* -* put - -*/ -TEST(putSubscriptionConvOp, put) -{ - ConnectionInfo ci1("/ngsi10/contextSubscriptions/012345678901234567890123", "XVERB", "1.1"); - std::string out; - RestService restService = - { - VersionRequest, - 3, { "ngsi10", "contextSubscriptions", "012345678901234567890123" }, - NULL - }; - - utInit(); - - ci1.outMimeType = JSON; - ci1.inMimeType = JSON; - ci1.payload = NULL; - ci1.payloadSize = 0; - ci1.restServiceP = &restService; - - serviceVectorsSet(NULL, NULL, NULL, NULL, NULL, NULL, badVerbV); - out = orion::requestServe(&ci1); - - EXPECT_EQ("Allow", ci1.httpHeader[0]); - EXPECT_EQ("PUT, DELETE", ci1.httpHeaderValue[0]); - EXPECT_EQ("", out); - - utExit(); -} diff --git a/test/unittests/serviceRoutines/statisticsTreat_test.cpp b/test/unittests/serviceRoutines/statisticsTreat_test.cpp index ef49618de2..1e557a5d21 100644 --- a/test/unittests/serviceRoutines/statisticsTreat_test.cpp +++ b/test/unittests/serviceRoutines/statisticsTreat_test.cpp @@ -168,6 +168,7 @@ TEST(statisticsTreat, badVerb) { ConnectionInfo ci("/statistics", "POLLUTE", "1.1"); std::string out; + std::string expected = "{\"error\":\"MethodNotAllowed\",\"description\":\"method not allowed\"}"; RestService restService = { StatisticsRequest, 1, { "statistics" }, NULL }; utInit(); @@ -178,7 +179,7 @@ TEST(statisticsTreat, badVerb) ci.restServiceP = &restService; out = orion::requestServe(&ci); - EXPECT_EQ("", out); + EXPECT_EQ(expected, out); EXPECT_EQ("Allow", ci.httpHeader[0]); EXPECT_EQ("GET, DELETE", ci.httpHeaderValue[0]); diff --git a/test/unittests/serviceRoutines/versionTreat_test.cpp b/test/unittests/serviceRoutines/versionTreat_test.cpp index 71eded8972..4a0b995302 100644 --- a/test/unittests/serviceRoutines/versionTreat_test.cpp +++ b/test/unittests/serviceRoutines/versionTreat_test.cpp @@ -54,7 +54,6 @@ TEST(versionTreat, ok) std::string out; RestService restService = { VersionRequest, 1, { "version" }, NULL }; - ci.apiVersion = V1; ci.restServiceP = &restService; serviceVectorsSet(getV, NULL, NULL, NULL, NULL, NULL, NULL); diff --git a/test/unittests/testData/ngsi.attributeList.ok.middle.json b/test/unittests/testData/ngsi.attributeList.ok.middle.json index dc01eac9b4..6d21c478e5 100644 --- a/test/unittests/testData/ngsi.attributeList.ok.middle.json +++ b/test/unittests/testData/ngsi.attributeList.ok.middle.json @@ -1 +1 @@ -"attributes":["a1","a2"] \ No newline at end of file +["a1","a2"] \ No newline at end of file diff --git a/test/unittests/testData/ngsi.conditionValueList.ok2.middle.json b/test/unittests/testData/ngsi.conditionValueList.ok2.middle.json deleted file mode 100644 index cb97ec02ba..0000000000 --- a/test/unittests/testData/ngsi.conditionValueList.ok2.middle.json +++ /dev/null @@ -1 +0,0 @@ -"condValueList":["cv1"] \ No newline at end of file diff --git a/test/unittests/testData/ngsi.conditionValueList.ok3.middle.json b/test/unittests/testData/ngsi.conditionValueList.ok3.middle.json deleted file mode 100644 index b791f84559..0000000000 --- a/test/unittests/testData/ngsi.conditionValueList.ok3.middle.json +++ /dev/null @@ -1 +0,0 @@ -"condValueList":["cv1","cv2"] \ No newline at end of file diff --git a/test/unittests/testData/ngsi.contextAttribute.render.middle.json b/test/unittests/testData/ngsi.contextAttribute.render.middle.json index bd313bb6cd..25a4ca9c5a 100644 --- a/test/unittests/testData/ngsi.contextAttribute.render.middle.json +++ b/test/unittests/testData/ngsi.contextAttribute.render.middle.json @@ -1 +1 @@ -{"name":"NAME","type":"TYPE","value":"VALUE"} \ No newline at end of file +{"type":"TYPE","value":"VALUE","metadata":{}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi.contextElementResponse.render.middle.json b/test/unittests/testData/ngsi.contextElementResponse.render.middle.json index 7f5d0af6bc..9c7d6ab711 100644 --- a/test/unittests/testData/ngsi.contextElementResponse.render.middle.json +++ b/test/unittests/testData/ngsi.contextElementResponse.render.middle.json @@ -1 +1 @@ -{"contextElement":{"type":"Type","isPattern":"false","id":"ID"},"statusCode":{"code":"200","reasonPhrase":"OK","details":"details"}} \ No newline at end of file +{"id":"ID","type":"Type"} \ No newline at end of file diff --git a/test/unittests/testData/ngsi.contextRegistrationAttribute.render.middle.json b/test/unittests/testData/ngsi.contextRegistrationAttribute.render.middle.json deleted file mode 100644 index 870f6ee9d3..0000000000 --- a/test/unittests/testData/ngsi.contextRegistrationAttribute.render.middle.json +++ /dev/null @@ -1 +0,0 @@ -{"name":"name","type":"type"} \ No newline at end of file diff --git a/test/unittests/testData/ngsi.contextRegistrationAttributeVector.render1.middle.json b/test/unittests/testData/ngsi.contextRegistrationAttributeVector.render1.middle.json deleted file mode 100644 index 4b766b76a0..0000000000 --- a/test/unittests/testData/ngsi.contextRegistrationAttributeVector.render1.middle.json +++ /dev/null @@ -1 +0,0 @@ -"attributes":[{"name":"name","type":"type"}] \ No newline at end of file diff --git a/test/unittests/testData/ngsi.contextRegistrationAttributeVector.render2.middle.json b/test/unittests/testData/ngsi.contextRegistrationAttributeVector.render2.middle.json deleted file mode 100644 index 0a59fb29da..0000000000 --- a/test/unittests/testData/ngsi.contextRegistrationAttributeVector.render2.middle.json +++ /dev/null @@ -1 +0,0 @@ -"attributes":[{"name":"name","type":"type"},{"name":"name2","type":"type2"}] \ No newline at end of file diff --git a/test/unittests/testData/ngsi.contextRegistrationResponse.renderError.middle.json b/test/unittests/testData/ngsi.contextRegistrationResponse.renderError.middle.json deleted file mode 100644 index a2c459d295..0000000000 --- a/test/unittests/testData/ngsi.contextRegistrationResponse.renderError.middle.json +++ /dev/null @@ -1 +0,0 @@ -{"contextRegistration":{},"errorCode":{"code":"400","reasonPhrase":"Bad Request"}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi.contextRegistrationResponse.renderOk.middle.json b/test/unittests/testData/ngsi.contextRegistrationResponse.renderOk.middle.json deleted file mode 100644 index 419cebfe3e..0000000000 --- a/test/unittests/testData/ngsi.contextRegistrationResponse.renderOk.middle.json +++ /dev/null @@ -1 +0,0 @@ -{"contextRegistration":{}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi.contextelement.check.middle.json b/test/unittests/testData/ngsi.contextelement.check.middle.json index 1f00f16ef2..46aeb8f02e 100644 --- a/test/unittests/testData/ngsi.contextelement.check.middle.json +++ b/test/unittests/testData/ngsi.contextelement.check.middle.json @@ -1 +1 @@ -"contextElement":{"type":"","isPattern":"false","id":"id"} \ No newline at end of file +{"id":"id","type":"Thing"} \ No newline at end of file diff --git a/test/unittests/testData/ngsi.entityId.render.middle.json b/test/unittests/testData/ngsi.entityId.render.middle.json index 06db597e57..9e26dfeeb6 100644 --- a/test/unittests/testData/ngsi.entityId.render.middle.json +++ b/test/unittests/testData/ngsi.entityId.render.middle.json @@ -1 +1 @@ -"type":"","isPattern":"","id":"" \ No newline at end of file +{} \ No newline at end of file diff --git a/test/unittests/testData/ngsi.metadataVector.render1.middle.json b/test/unittests/testData/ngsi.metadataVector.render1.middle.json index c6dbd50cc5..0a027b641a 100644 --- a/test/unittests/testData/ngsi.metadataVector.render1.middle.json +++ b/test/unittests/testData/ngsi.metadataVector.render1.middle.json @@ -1 +1 @@ -"metadatas":[{"name":"Name","type":"Type","value":"Value"}] \ No newline at end of file +{"Name":{"type":"Type","value":"Value"}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi.metadataVector.render3.middle.json b/test/unittests/testData/ngsi.metadataVector.render3.middle.json index 6ce4746f93..a4d49ea53d 100644 --- a/test/unittests/testData/ngsi.metadataVector.render3.middle.json +++ b/test/unittests/testData/ngsi.metadataVector.render3.middle.json @@ -1 +1 @@ -"metadatas":[{"name":"Name","type":"Type","value":"Value"},{"name":"Name2","type":"Type2","value":"Value2"}] \ No newline at end of file +{"Name":{"type":"Type","value":"Value"},"Name2":{"type":"Type2","value":"Value2"}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi.metdata.render1.middle.json b/test/unittests/testData/ngsi.metdata.render1.middle.json index 908c63cea5..93ff70bc96 100644 --- a/test/unittests/testData/ngsi.metdata.render1.middle.json +++ b/test/unittests/testData/ngsi.metdata.render1.middle.json @@ -1 +1 @@ -{"name":"","type":"","value":"not given"} \ No newline at end of file +{"type":"NotGiven"} \ No newline at end of file diff --git a/test/unittests/testData/ngsi.metdata.render2.middle.json b/test/unittests/testData/ngsi.metdata.render2.middle.json index ec5c315a7a..4ffd60ad72 100644 --- a/test/unittests/testData/ngsi.metdata.render2.middle.json +++ b/test/unittests/testData/ngsi.metdata.render2.middle.json @@ -1 +1 @@ -{"name":"Name","type":"Integer","value":"19"} \ No newline at end of file +{"type":"Integer","value":"19"} \ No newline at end of file diff --git a/test/unittests/testData/ngsi.notifyCondition.render.middle.json b/test/unittests/testData/ngsi.notifyCondition.render.middle.json deleted file mode 100644 index 0128e68b85..0000000000 --- a/test/unittests/testData/ngsi.notifyCondition.render.middle.json +++ /dev/null @@ -1 +0,0 @@ -{"type":""} \ No newline at end of file diff --git a/test/unittests/testData/ngsi.notifyConditionVector.render.middle.json b/test/unittests/testData/ngsi.notifyConditionVector.render.middle.json deleted file mode 100644 index 2b079083e3..0000000000 --- a/test/unittests/testData/ngsi.notifyConditionVector.render.middle.json +++ /dev/null @@ -1 +0,0 @@ -"notifyConditions":[{"type":"Type"}] \ No newline at end of file diff --git a/test/unittests/testData/ngsi.originator.render.middle.json b/test/unittests/testData/ngsi.originator.render.middle.json deleted file mode 100644 index bf146a1ed5..0000000000 --- a/test/unittests/testData/ngsi.originator.render.middle.json +++ /dev/null @@ -1 +0,0 @@ -"originator":"String" \ No newline at end of file diff --git a/test/unittests/testData/ngsi.providingApplication.render.middle.json b/test/unittests/testData/ngsi.providingApplication.render.middle.json deleted file mode 100644 index 696b94a868..0000000000 --- a/test/unittests/testData/ngsi.providingApplication.render.middle.json +++ /dev/null @@ -1 +0,0 @@ -"providingApplication":"PA" \ No newline at end of file diff --git a/test/unittests/testData/ngsi.reference.render.middle.json b/test/unittests/testData/ngsi.reference.render.middle.json deleted file mode 100644 index 9867e4c63d..0000000000 --- a/test/unittests/testData/ngsi.reference.render.middle.json +++ /dev/null @@ -1 +0,0 @@ -"reference":"REF" \ No newline at end of file diff --git a/test/unittests/testData/ngsi.restrictionString.render.middle.json b/test/unittests/testData/ngsi.restrictionString.render.middle.json deleted file mode 100644 index 9921e155a9..0000000000 --- a/test/unittests/testData/ngsi.restrictionString.render.middle.json +++ /dev/null @@ -1 +0,0 @@ -"restriction":"String" \ No newline at end of file diff --git a/test/unittests/testData/ngsi.scope.render.middle.json b/test/unittests/testData/ngsi.scope.render.middle.json deleted file mode 100644 index 87986d33f6..0000000000 --- a/test/unittests/testData/ngsi.scope.render.middle.json +++ /dev/null @@ -1 +0,0 @@ -{"type":"Type","value":"Value"} \ No newline at end of file diff --git a/test/unittests/testData/ngsi.statusCode.render4.middle.json b/test/unittests/testData/ngsi.statusCode.render4.middle.json index af3641a5b7..a00b7dd8b9 100644 --- a/test/unittests/testData/ngsi.statusCode.render4.middle.json +++ b/test/unittests/testData/ngsi.statusCode.render4.middle.json @@ -1 +1 @@ -"statusCode":{"code":"200","reasonPhrase":"OK","details":"DETAILS"} \ No newline at end of file +{"error":"OK","description":"DETAILS"} \ No newline at end of file diff --git a/test/unittests/testData/ngsi.subscribeError.render1.middle.json b/test/unittests/testData/ngsi.subscribeError.render1.middle.json deleted file mode 100644 index 93f896dbd0..0000000000 --- a/test/unittests/testData/ngsi.subscribeError.render1.middle.json +++ /dev/null @@ -1 +0,0 @@ -"subscribeError":{"errorCode":{"code":"400","reasonPhrase":"Bad Request","details":"detail"}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi.subscribeError.render2.middle.json b/test/unittests/testData/ngsi.subscribeError.render2.middle.json deleted file mode 100644 index 49cae7f563..0000000000 --- a/test/unittests/testData/ngsi.subscribeError.render2.middle.json +++ /dev/null @@ -1 +0,0 @@ -"subscribeError":{"subscriptionId":"SUB_123","errorCode":{"code":"400","reasonPhrase":"Bad Request","details":"detail"}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi.subscriptionId.render2.middle.json b/test/unittests/testData/ngsi.subscriptionId.render2.middle.json deleted file mode 100644 index 6785a19eb6..0000000000 --- a/test/unittests/testData/ngsi.subscriptionId.render2.middle.json +++ /dev/null @@ -1 +0,0 @@ -"subscriptionId":"012345012345012345012345" \ No newline at end of file diff --git a/test/unittests/testData/ngsi.throttling.render.middle.json b/test/unittests/testData/ngsi.throttling.render.middle.json deleted file mode 100644 index bcd2c38ada..0000000000 --- a/test/unittests/testData/ngsi.throttling.render.middle.json +++ /dev/null @@ -1 +0,0 @@ -"throttling":"PT1S" \ No newline at end of file diff --git a/test/unittests/testData/ngsi.unrecognizedRequest.json b/test/unittests/testData/ngsi.unrecognizedRequest.json deleted file mode 100644 index ed253552a8..0000000000 --- a/test/unittests/testData/ngsi.unrecognizedRequest.json +++ /dev/null @@ -1 +0,0 @@ -{"orionError":{"code":"400","reasonPhrase":"Bad Request","details":"Service not found. Check your URL as probably it is wrong."}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.appendContextElementRequest.adn.valid.json b/test/unittests/testData/ngsi10.appendContextElementRequest.adn.valid.json deleted file mode 100644 index 1e8dde1170..0000000000 --- a/test/unittests/testData/ngsi10.appendContextElementRequest.adn.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"attributes":[{"name":"caName","type":"caType","value":"121"}]} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.appendContextElementRequest.check1.postponed.json b/test/unittests/testData/ngsi10.appendContextElementRequest.check1.postponed.json deleted file mode 100644 index ec95dfb1cc..0000000000 --- a/test/unittests/testData/ngsi10.appendContextElementRequest.check1.postponed.json +++ /dev/null @@ -1 +0,0 @@ -{"errorCode":{"code":"400","reasonPhrase":"Bad Request","details":"PRE ERR"}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.appendContextElementRequest.check2.postponed.json b/test/unittests/testData/ngsi10.appendContextElementRequest.check2.postponed.json deleted file mode 100644 index 3e77dcc013..0000000000 --- a/test/unittests/testData/ngsi10.appendContextElementRequest.check2.postponed.json +++ /dev/null @@ -1 +0,0 @@ -{"errorCode":{"code":"400","reasonPhrase":"Bad Request","details":"missing attribute name"}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.appendContextElementResponse.badRequest.valid.json b/test/unittests/testData/ngsi10.appendContextElementResponse.badRequest.valid.json deleted file mode 100644 index 101d498c40..0000000000 --- a/test/unittests/testData/ngsi10.appendContextElementResponse.badRequest.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"errorCode":{"code":"400","reasonPhrase":"Bad Request","details":"very bad request"}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.appendContextElementResponse.empty.valid.json b/test/unittests/testData/ngsi10.appendContextElementResponse.empty.valid.json deleted file mode 100644 index 9e26dfeeb6..0000000000 --- a/test/unittests/testData/ngsi10.appendContextElementResponse.empty.valid.json +++ /dev/null @@ -1 +0,0 @@ -{} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.appendContextElementResponse.missingAttributeName.valid.json b/test/unittests/testData/ngsi10.appendContextElementResponse.missingAttributeName.valid.json deleted file mode 100644 index 3e77dcc013..0000000000 --- a/test/unittests/testData/ngsi10.appendContextElementResponse.missingAttributeName.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"errorCode":{"code":"400","reasonPhrase":"Bad Request","details":"missing attribute name"}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.appendContextElementResponse.predetectedError.valid.json b/test/unittests/testData/ngsi10.appendContextElementResponse.predetectedError.valid.json deleted file mode 100644 index fc97279a56..0000000000 --- a/test/unittests/testData/ngsi10.appendContextElementResponse.predetectedError.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"errorCode":{"code":"400","reasonPhrase":"Bad Request","details":"Error is predetected"}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.attributeExpression.ok.middle.json b/test/unittests/testData/ngsi10.attributeExpression.ok.middle.json deleted file mode 100644 index 131b982b26..0000000000 --- a/test/unittests/testData/ngsi10.attributeExpression.ok.middle.json +++ /dev/null @@ -1 +0,0 @@ -"attributeExpression":"AE" \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.contextAttributeResponse.check1.valid.json b/test/unittests/testData/ngsi10.contextAttributeResponse.check1.valid.json deleted file mode 100644 index 329075a034..0000000000 --- a/test/unittests/testData/ngsi10.contextAttributeResponse.check1.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"attributes":[{"name":"caName","type":"caType","value":"caValue"}],"statusCode":{"code":"400","reasonPhrase":"Bad Request","details":"PRE ERROR"}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.contextAttributeResponse.check2.valid.json b/test/unittests/testData/ngsi10.contextAttributeResponse.check2.valid.json deleted file mode 100644 index 9b6e277321..0000000000 --- a/test/unittests/testData/ngsi10.contextAttributeResponse.check2.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"attributes":[{"name":"caName","type":"caType","value":"caValue"},{"name":"","type":"caType","value":"caValue"}],"statusCode":{"code":"400","reasonPhrase":"Bad Request","details":"missing attribute name"}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.contextAttributeResponse.check3.valid.json b/test/unittests/testData/ngsi10.contextAttributeResponse.check3.valid.json deleted file mode 100644 index 89e713afb1..0000000000 --- a/test/unittests/testData/ngsi10.contextAttributeResponse.check3.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"attributes":[{"name":"caName","type":"caType","value":"caValue"}],"statusCode":{"code":"400","reasonPhrase":"Bad Request","details":"PRE Error"}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.contextAttributeResponse.check4.valid.json b/test/unittests/testData/ngsi10.contextAttributeResponse.check4.valid.json deleted file mode 100644 index 9b6e277321..0000000000 --- a/test/unittests/testData/ngsi10.contextAttributeResponse.check4.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"attributes":[{"name":"caName","type":"caType","value":"caValue"},{"name":"","type":"caType","value":"caValue"}],"statusCode":{"code":"400","reasonPhrase":"Bad Request","details":"missing attribute name"}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.contextResponseList.render.invalid.json b/test/unittests/testData/ngsi10.contextResponseList.render.invalid.json deleted file mode 100644 index 0c70d682b9..0000000000 --- a/test/unittests/testData/ngsi10.contextResponseList.render.invalid.json +++ /dev/null @@ -1 +0,0 @@ -"contextResponses":[{"attributes":[{"name":"caName","type":"caType","value":"caValue"}],"statusCode":{"code":"400","reasonPhrase":"Bad Request","details":"Empty Vector"}}] \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.notifyContextRequest.badIsPattern.invalid.json b/test/unittests/testData/ngsi10.notifyContextRequest.badIsPattern.invalid.json deleted file mode 100644 index 93b24d170d..0000000000 --- a/test/unittests/testData/ngsi10.notifyContextRequest.badIsPattern.invalid.json +++ /dev/null @@ -1,54 +0,0 @@ -{ - "subscriptionId": "012345678901234567890123", - "originator": "http://localhost/test", - "contextResponses": [ - { - "contextElement": { - "type": "Room", - "isPattern": "phalse", - "id": "ConferenceRoom", - "attributes": [ - { - "name": "temperature", - "type": "Room", - "value": "10", - "metadatas": [ - { - "name": "ID", - "type": "string", - "value": "1110" - }, - { - "name": "id", - "type": "integer", - "value": "12" - } - ] - }, - { - "name": "temperature", - "type": "Room", - "value": "10", - "metadatas": [ - { - "name": "ID", - "type": "string", - "value": "1110" - }, - { - "name": "id", - "type": "integer", - "value": "55" - } - ] - } - ] - }, - "statusCode": { - "code": "200", - "reasonPhrase": "Ok", - "details": "a" - } - } - ] -} diff --git a/test/unittests/testData/ngsi10.notifyContextRequest.jsonRender1.valid.json b/test/unittests/testData/ngsi10.notifyContextRequest.jsonRender1.valid.json index 55c1a1fd25..4899c62129 100644 --- a/test/unittests/testData/ngsi10.notifyContextRequest.jsonRender1.valid.json +++ b/test/unittests/testData/ngsi10.notifyContextRequest.jsonRender1.valid.json @@ -1 +1 @@ -{"subscriptionId":"012345678901234567890123","originator":"http://www.tid.es/NotifyContextRequestUnitTest"} \ No newline at end of file +{"subscriptionId":"012345678901234567890123","data":[]} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.notifyContextRequest.jsonRender2.valid.json b/test/unittests/testData/ngsi10.notifyContextRequest.jsonRender2.valid.json index 7f774e15a9..144333c0c3 100644 --- a/test/unittests/testData/ngsi10.notifyContextRequest.jsonRender2.valid.json +++ b/test/unittests/testData/ngsi10.notifyContextRequest.jsonRender2.valid.json @@ -1 +1 @@ -{"subscriptionId":"012345678901234567890123","originator":"http://www.tid.es/NotifyContextRequestUnitTest","contextResponses":[{"contextElement":{"type":"EType","isPattern":"false","id":"E01"},"statusCode":{"code":"200","reasonPhrase":"OK"}}]} \ No newline at end of file +{"subscriptionId":"012345678901234567890123","data":[{"id":"E01","type":"EType"}]} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.notifyContextRequest.jsonRender3.valid.json b/test/unittests/testData/ngsi10.notifyContextRequest.jsonRender3.valid.json index 032e92a242..bab4f4e3d6 100644 --- a/test/unittests/testData/ngsi10.notifyContextRequest.jsonRender3.valid.json +++ b/test/unittests/testData/ngsi10.notifyContextRequest.jsonRender3.valid.json @@ -1 +1 @@ -{"subscriptionId":"012345678901234567890123","originator":"http://www.tid.es/NotifyContextRequestUnitTest","contextResponses":[{"contextElement":{"type":"EType","isPattern":"false","id":"E01"},"statusCode":{"code":"200","reasonPhrase":"OK"}},{"contextElement":{"type":"EType","isPattern":"false","id":"E02"},"statusCode":{"code":"200","reasonPhrase":"OK"}}]} \ No newline at end of file +{"subscriptionId":"012345678901234567890123","data":[{"id":"E01","type":"EType"},{"id":"E02","type":"EType"}]} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.notifyContextRequest_ok.expected1.valid.json b/test/unittests/testData/ngsi10.notifyContextRequest_ok.expected1.valid.json deleted file mode 100644 index 8ac1f75a56..0000000000 --- a/test/unittests/testData/ngsi10.notifyContextRequest_ok.expected1.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"subscriptionId":"012345678901234567890123","originator":"http://localhost/test","contextResponses":[{"contextElement":{"type":"Room","isPattern":"false","id":"ConferenceRoom","attributes":[{"name":"temperature","type":"Room","value":"10","metadatas":[{"name":"ID","type":"string","value":"1110"},{"name":"id","type":"integer","value":"12"}]},{"name":"temperature","type":"Room","value":"10","metadatas":[{"name":"ID","type":"string","value":"1110"},{"name":"id","type":"integer","value":"55"}]}]},"statusCode":{"code":"200","reasonPhrase":"Ok","details":"a"}}]} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.notifyContextResponse.badIsPattern.valid.json b/test/unittests/testData/ngsi10.notifyContextResponse.badIsPattern.valid.json deleted file mode 100644 index 201bba8b00..0000000000 --- a/test/unittests/testData/ngsi10.notifyContextResponse.badIsPattern.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"responseCode":{"code":"400","reasonPhrase":"Bad Request","details":"invalid isPattern value for entity: /phalse/"}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.queryContextRequest.badIsPattern.invalid.json b/test/unittests/testData/ngsi10.queryContextRequest.badIsPattern.invalid.json deleted file mode 100644 index 6ddbfd06f2..0000000000 --- a/test/unittests/testData/ngsi10.queryContextRequest.badIsPattern.invalid.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "entities": [ - { - "type": "Room", - "isPattern": "fralse", - "id": "ConferenceRoom" - }, - { - "type": "Room", - "isPattern": "false", - "id": "OfficeRoom" - } - ], - "attributes": [ - "temperature", - "occupancy", - "lightstatus" - ], - "restriction": { - "attributeExpression" : "Attribute Expression", - "scopes": [ - { - "type" : "st1", - "value" : "sv1" - }, - { - "type" : "st2", - "value" : "sv2" - } - ] - } -} diff --git a/test/unittests/testData/ngsi10.queryContextRequest.emptyAttribute.valid.json b/test/unittests/testData/ngsi10.queryContextRequest.emptyAttribute.valid.json deleted file mode 100644 index 020387d6e0..0000000000 --- a/test/unittests/testData/ngsi10.queryContextRequest.emptyAttribute.valid.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "entities": [ - { - "type": "Room", - "isPattern": "false", - "id": "ConferenceRoom" - }, - { - "type": "Room", - "isPattern": "false", - "id": "OfficeRoom" - } - ], - "attributes": [ - "temperature", - "", - "lightstatus" - ], - "restriction": { - "attributeExpression" : "Attribute Expression", - "scopes": [ - { - "type" : "st1", - "value" : "sv1" - }, - { - "type" : "st2", - "value" : "sv2" - } - ] - } -} diff --git a/test/unittests/testData/ngsi10.queryContextRequest.emptyAttributeExpression.invalid.json b/test/unittests/testData/ngsi10.queryContextRequest.emptyAttributeExpression.invalid.json deleted file mode 100644 index 282b7faf71..0000000000 --- a/test/unittests/testData/ngsi10.queryContextRequest.emptyAttributeExpression.invalid.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "entities": [ - { - "type": "Room", - "isPattern": "false", - "id": "ConferenceRoom" - }, - { - "type": "Room", - "isPattern": "false", - "id": "OfficeRoom" - } - ], - "attributes": [ - "temperature", - "occupancy", - "lightstatus" - ], - "restriction": { - "attributeExpression" : "", - "scopes": [ - { - "type" : "st1", - "value" : "sv1" - }, - { - "type" : "st2", - "value" : "sv2" - } - ] - } -} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.queryContextRequest_ok.expected.valid.json b/test/unittests/testData/ngsi10.queryContextRequest_ok.expected.valid.json deleted file mode 100644 index 4a331f4e9c..0000000000 --- a/test/unittests/testData/ngsi10.queryContextRequest_ok.expected.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"entities":[{"type":"Room","isPattern":"false","id":"ConferenceRoom"},{"type":"Room","isPattern":"false","id":"OfficeRoom"}],"attributes":["temperature","occupancy","lightstatus"],"restriction":{"attributeExpression":"Attribute Expression","scope":[{"type":"st1","value":"sv1"},{"type":"st2","value":"sv2"}]}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.queryContextRequest_ok.valid.json b/test/unittests/testData/ngsi10.queryContextRequest_ok.valid.json deleted file mode 100644 index 9d53921c0b..0000000000 --- a/test/unittests/testData/ngsi10.queryContextRequest_ok.valid.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "entities": [ - { - "type": "Room", - "isPattern": "false", - "id": "ConferenceRoom" - }, - { - "type": "Room", - "isPattern": "false", - "id": "OfficeRoom" - } - ], - "attributes": [ - "temperature", - "occupancy", - "lightstatus" - ], - "restriction": { - "attributeExpression" : "Attribute Expression", - "scopes": [ - { - "type" : "st1", - "value" : "sv1" - }, - { - "type" : "st2", - "value" : "sv2" - } - ] - } -} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.queryContextResponse.badIsPattern.valid.json b/test/unittests/testData/ngsi10.queryContextResponse.badIsPattern.valid.json deleted file mode 100644 index 746cf3f560..0000000000 --- a/test/unittests/testData/ngsi10.queryContextResponse.badIsPattern.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"errorCode":{"code":"400","reasonPhrase":"Bad Request","details":"invalid isPattern value for entity: /fralse/"}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.queryContextResponse.emptyAttribute.valid.json b/test/unittests/testData/ngsi10.queryContextResponse.emptyAttribute.valid.json deleted file mode 100644 index 2a12c9c063..0000000000 --- a/test/unittests/testData/ngsi10.queryContextResponse.emptyAttribute.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"errorCode":{"code":"400","reasonPhrase":"Bad Request","details":"Empty attribute name"}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.queryContextResponse.emptyAttributeExpression.valid.json b/test/unittests/testData/ngsi10.queryContextResponse.emptyAttributeExpression.valid.json deleted file mode 100644 index 4bdc828f76..0000000000 --- a/test/unittests/testData/ngsi10.queryContextResponse.emptyAttributeExpression.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"errorCode":{"code":"400","reasonPhrase":"Bad Request","details":"Empty attribute expression"}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.queryContextResponse.jsonRender1.valid.json b/test/unittests/testData/ngsi10.queryContextResponse.jsonRender1.valid.json deleted file mode 100644 index 0a3cb88107..0000000000 --- a/test/unittests/testData/ngsi10.queryContextResponse.jsonRender1.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"contextResponses":[{"contextElement":{"type":"EType","isPattern":"false","id":"E01"},"statusCode":{"code":"200","reasonPhrase":"OK"}}]} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.queryContextResponse.jsonRender11.valid.json b/test/unittests/testData/ngsi10.queryContextResponse.jsonRender11.valid.json deleted file mode 100644 index 4566598072..0000000000 --- a/test/unittests/testData/ngsi10.queryContextResponse.jsonRender11.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"contextResponses":[{"contextElement":{"type":"EType","isPattern":"false","id":"E01","attributes":[{"name":"ca7","type":"string","value":"context attribute 7"},{"name":"ca9","type":"string","value":"context attribute 9"}]},"statusCode":{"code":"200","reasonPhrase":"OK"}},{"contextElement":{"type":"EType","isPattern":"false","id":"E02"},"statusCode":{"code":"200","reasonPhrase":"OK"}}]} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.queryContextResponse.jsonRender12.valid.json b/test/unittests/testData/ngsi10.queryContextResponse.jsonRender12.valid.json deleted file mode 100644 index 4566598072..0000000000 --- a/test/unittests/testData/ngsi10.queryContextResponse.jsonRender12.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"contextResponses":[{"contextElement":{"type":"EType","isPattern":"false","id":"E01","attributes":[{"name":"ca7","type":"string","value":"context attribute 7"},{"name":"ca9","type":"string","value":"context attribute 9"}]},"statusCode":{"code":"200","reasonPhrase":"OK"}},{"contextElement":{"type":"EType","isPattern":"false","id":"E02"},"statusCode":{"code":"200","reasonPhrase":"OK"}}]} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.queryContextResponse.jsonRender13.valid.json b/test/unittests/testData/ngsi10.queryContextResponse.jsonRender13.valid.json deleted file mode 100644 index ec655cde25..0000000000 --- a/test/unittests/testData/ngsi10.queryContextResponse.jsonRender13.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"contextResponses":[{"contextElement":{"type":"EType","isPattern":"false","id":"E01","attributes":[{"name":"ca7","type":"string","value":"context attribute 7"},{"name":"ca9","type":"string","value":"context attribute 9"}]},"statusCode":{"code":"200","reasonPhrase":"OK"}},{"contextElement":{"type":"EType","isPattern":"false","id":"E02"},"statusCode":{"code":"200","reasonPhrase":"OK"}}],"errorCode":{"code":"400","reasonPhrase":"Bad Request","details":"no details"}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.queryContextResponse.jsonRender14.valid.json b/test/unittests/testData/ngsi10.queryContextResponse.jsonRender14.valid.json deleted file mode 100644 index 727f3ea1f3..0000000000 --- a/test/unittests/testData/ngsi10.queryContextResponse.jsonRender14.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"errorCode":{"code":"400","reasonPhrase":"Bad Request","details":"no details"}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.queryContextResponse.jsonRender2.valid.json b/test/unittests/testData/ngsi10.queryContextResponse.jsonRender2.valid.json deleted file mode 100644 index 0a3cb88107..0000000000 --- a/test/unittests/testData/ngsi10.queryContextResponse.jsonRender2.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"contextResponses":[{"contextElement":{"type":"EType","isPattern":"false","id":"E01"},"statusCode":{"code":"200","reasonPhrase":"OK"}}]} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.queryContextResponse.jsonRender3.valid.json b/test/unittests/testData/ngsi10.queryContextResponse.jsonRender3.valid.json deleted file mode 100644 index e9a0effa29..0000000000 --- a/test/unittests/testData/ngsi10.queryContextResponse.jsonRender3.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"contextResponses":[{"contextElement":{"type":"EType","isPattern":"false","id":"E01","attributes":[{"name":"ca","type":"string","value":"a context attribute"}]},"statusCode":{"code":"200","reasonPhrase":"OK"}}]} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.queryContextResponse.jsonRender4.valid.json b/test/unittests/testData/ngsi10.queryContextResponse.jsonRender4.valid.json deleted file mode 100644 index e9a0effa29..0000000000 --- a/test/unittests/testData/ngsi10.queryContextResponse.jsonRender4.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"contextResponses":[{"contextElement":{"type":"EType","isPattern":"false","id":"E01","attributes":[{"name":"ca","type":"string","value":"a context attribute"}]},"statusCode":{"code":"200","reasonPhrase":"OK"}}]} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.queryContextResponse.jsonRender5.valid.json b/test/unittests/testData/ngsi10.queryContextResponse.jsonRender5.valid.json deleted file mode 100644 index 0a3cb88107..0000000000 --- a/test/unittests/testData/ngsi10.queryContextResponse.jsonRender5.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"contextResponses":[{"contextElement":{"type":"EType","isPattern":"false","id":"E01"},"statusCode":{"code":"200","reasonPhrase":"OK"}}]} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.queryContextResponse.jsonRender6.valid.json b/test/unittests/testData/ngsi10.queryContextResponse.jsonRender6.valid.json deleted file mode 100644 index 0a3cb88107..0000000000 --- a/test/unittests/testData/ngsi10.queryContextResponse.jsonRender6.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"contextResponses":[{"contextElement":{"type":"EType","isPattern":"false","id":"E01"},"statusCode":{"code":"200","reasonPhrase":"OK"}}]} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.queryContextResponse.jsonRender7.valid.json b/test/unittests/testData/ngsi10.queryContextResponse.jsonRender7.valid.json deleted file mode 100644 index 36683f98fc..0000000000 --- a/test/unittests/testData/ngsi10.queryContextResponse.jsonRender7.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"contextResponses":[{"contextElement":{"type":"EType","isPattern":"false","id":"E01","attributes":[{"name":"ca7","type":"string","value":"context attribute 7"}]},"statusCode":{"code":"200","reasonPhrase":"OK"}}]} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.queryContextResponse.jsonRender8.valid.json b/test/unittests/testData/ngsi10.queryContextResponse.jsonRender8.valid.json deleted file mode 100644 index 36683f98fc..0000000000 --- a/test/unittests/testData/ngsi10.queryContextResponse.jsonRender8.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"contextResponses":[{"contextElement":{"type":"EType","isPattern":"false","id":"E01","attributes":[{"name":"ca7","type":"string","value":"context attribute 7"}]},"statusCode":{"code":"200","reasonPhrase":"OK"}}]} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.queryContextResponse.jsonRender9.valid.json b/test/unittests/testData/ngsi10.queryContextResponse.jsonRender9.valid.json deleted file mode 100644 index 5d9ac456fd..0000000000 --- a/test/unittests/testData/ngsi10.queryContextResponse.jsonRender9.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"contextResponses":[{"contextElement":{"type":"EType","isPattern":"false","id":"E01","attributes":[{"name":"ca7","type":"string","value":"context attribute 7"},{"name":"ca9","type":"string","value":"context attribute 9"}]},"statusCode":{"code":"200","reasonPhrase":"OK"}}]} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.queryContextResponse.polygonInvertedBadValue.valid.json b/test/unittests/testData/ngsi10.queryContextResponse.polygonInvertedBadValue.valid.json deleted file mode 100644 index 058b1cd27c..0000000000 --- a/test/unittests/testData/ngsi10.queryContextResponse.polygonInvertedBadValue.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"errorCode":{"code":"400","reasonPhrase":"Bad Request","details":"bad string for polygon/inverted: /zero/"}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.queryContextResponse.polygonNoVertices.valid.json b/test/unittests/testData/ngsi10.queryContextResponse.polygonNoVertices.valid.json deleted file mode 100644 index 64bbea2088..0000000000 --- a/test/unittests/testData/ngsi10.queryContextResponse.polygonNoVertices.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"errorCode":{"code":"400","reasonPhrase":"Bad Request","details":"too few vertices for a polygon"}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.queryContextResponse.polygonOneVertex.valid.json b/test/unittests/testData/ngsi10.queryContextResponse.polygonOneVertex.valid.json deleted file mode 100644 index 64bbea2088..0000000000 --- a/test/unittests/testData/ngsi10.queryContextResponse.polygonOneVertex.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"errorCode":{"code":"400","reasonPhrase":"Bad Request","details":"too few vertices for a polygon"}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.queryContextResponse.polygonTwoVertices.valid.json b/test/unittests/testData/ngsi10.queryContextResponse.polygonTwoVertices.valid.json deleted file mode 100644 index 64bbea2088..0000000000 --- a/test/unittests/testData/ngsi10.queryContextResponse.polygonTwoVertices.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"errorCode":{"code":"400","reasonPhrase":"Bad Request","details":"too few vertices for a polygon"}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.subscribeContextRequest.badIsPattern.invalid.json b/test/unittests/testData/ngsi10.subscribeContextRequest.badIsPattern.invalid.json deleted file mode 100644 index 0dbf0b3d15..0000000000 --- a/test/unittests/testData/ngsi10.subscribeContextRequest.badIsPattern.invalid.json +++ /dev/null @@ -1,46 +0,0 @@ -{ - "entities": [ - { - "type": "Room", - "isPattern": "false0", - "id": "ConferenceRoom" - }, - { - "type": "Room", - "isPattern": "false1", - "id": "OfficeRoom" - } - ], - "attributes": [ - "temperature", - "occupancy", - "lightstatus" - ], - "reference": "http://127.0.0.1", - "duration": "PT1S", - "restriction": { - "attributeExpression": "testRestriction", - "scopes" : [ - { - "type" : "t1", - "value" : "v1" - }, - { - "type" : "t2", - "value" : "v2" - } - ] - }, - "notifyConditions": [ - { - "type": "ONCHANGE", - "condValues": [ - "temperature", - "lightstatus" - ] - , - "restriction": "restriction" - } - ], - "throttling": "P5Y" -} diff --git a/test/unittests/testData/ngsi10.subscribeContextRequest.duration.invalid.json b/test/unittests/testData/ngsi10.subscribeContextRequest.duration.invalid.json deleted file mode 100644 index 8263134d31..0000000000 --- a/test/unittests/testData/ngsi10.subscribeContextRequest.duration.invalid.json +++ /dev/null @@ -1,46 +0,0 @@ -{ - "entities": [ - { - "type": "Room", - "isPattern": "false", - "id": "ConferenceRoom" - }, - { - "type": "Room", - "isPattern": "false", - "id": "OfficeRoom" - } - ], - "attributes": [ - "temperature", - "occupancy", - "lightstatus" - ], - "reference": "http://127.0.0.1", - "duration": "ssss", - "restriction": { - "attributeExpression": "testRestriction", - "scopes" : [ - { - "type" : "t1", - "value" : "v1" - }, - { - "type" : "t2", - "value" : "v2" - } - ] - }, - "notifyConditions": [ - { - "type": "ONCHANGE", - "condValues": [ - "temperature", - "lightstatus" - ] - , - "restriction": "restriction" - } - ], - "throttling": "P5Y" -} diff --git a/test/unittests/testData/ngsi10.subscribeContextRequest.ok.valid.json b/test/unittests/testData/ngsi10.subscribeContextRequest.ok.valid.json deleted file mode 100644 index 315b506dc7..0000000000 --- a/test/unittests/testData/ngsi10.subscribeContextRequest.ok.valid.json +++ /dev/null @@ -1,46 +0,0 @@ -{ - "entities": [ - { - "type": "Room", - "isPattern": "false", - "id": "ConferenceRoom" - }, - { - "type": "Room", - "isPattern": "false", - "id": "OfficeRoom" - } - ], - "attributes": [ - "temperature", - "occupancy", - "lightstatus" - ], - "reference": "http://127.0.0.1", - "duration": "P5Y", - "restriction": { - "attributeExpression": "testRestriction", - "scopes" : [ - { - "type" : "t1", - "value" : "v1" - }, - { - "type" : "t2", - "value" : "v2" - } - ] - }, - "notifyConditions": [ - { - "type": "ONCHANGE", - "condValues": [ - "temperature", - "lightstatus" - ] - , - "restriction": "restriction" - } - ], - "throttling": "P5Y" -} diff --git a/test/unittests/testData/ngsi10.subscribeContextResponse.badIsPattern.valid.json b/test/unittests/testData/ngsi10.subscribeContextResponse.badIsPattern.valid.json deleted file mode 100644 index 11dddb4809..0000000000 --- a/test/unittests/testData/ngsi10.subscribeContextResponse.badIsPattern.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"subscribeError":{"errorCode":{"code":"400","reasonPhrase":"Bad Request","details":"invalid payload: invalid isPattern value for entity: /false0/"}}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.subscribeContextResponse.durationInvalid.valid.json b/test/unittests/testData/ngsi10.subscribeContextResponse.durationInvalid.valid.json deleted file mode 100644 index f78c9ff144..0000000000 --- a/test/unittests/testData/ngsi10.subscribeContextResponse.durationInvalid.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"subscribeError":{"errorCode":{"code":"400","reasonPhrase":"Bad Request","details":"invalid payload: syntax error in duration string"}}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.subscribeContextResponse.jsonRender1.valid.json b/test/unittests/testData/ngsi10.subscribeContextResponse.jsonRender1.valid.json deleted file mode 100644 index 78a1183e8c..0000000000 --- a/test/unittests/testData/ngsi10.subscribeContextResponse.jsonRender1.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"subscribeError":{"errorCode":{"code":"400","reasonPhrase":"Bad Request","details":"details"}}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.subscribeContextResponse.jsonRender2.valid.json b/test/unittests/testData/ngsi10.subscribeContextResponse.jsonRender2.valid.json deleted file mode 100644 index 29765878bb..0000000000 --- a/test/unittests/testData/ngsi10.subscribeContextResponse.jsonRender2.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"subscribeError":{"subscriptionId":"012345678901234567890123","errorCode":{"code":"400","reasonPhrase":"Bad Request"}}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.subscribeContextResponse.jsonRender3.valid.json b/test/unittests/testData/ngsi10.subscribeContextResponse.jsonRender3.valid.json deleted file mode 100644 index 5a3f83fad4..0000000000 --- a/test/unittests/testData/ngsi10.subscribeContextResponse.jsonRender3.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"subscribeResponse":{"subscriptionId":"012345678901234567890123"}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.subscribeContextResponse.jsonRender4.valid.json b/test/unittests/testData/ngsi10.subscribeContextResponse.jsonRender4.valid.json deleted file mode 100644 index e6c43c5e32..0000000000 --- a/test/unittests/testData/ngsi10.subscribeContextResponse.jsonRender4.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"subscribeResponse":{"subscriptionId":"012345678901234567890123","throttling":"PT1M"}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.subscribeContextResponse.jsonRender5.valid.json b/test/unittests/testData/ngsi10.subscribeContextResponse.jsonRender5.valid.json deleted file mode 100644 index 7e67cd0071..0000000000 --- a/test/unittests/testData/ngsi10.subscribeContextResponse.jsonRender5.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"subscribeResponse":{"subscriptionId":"012345678901234567890123","duration":"PT1H"}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.subscribeContextResponse.jsonRender6.valid.json b/test/unittests/testData/ngsi10.subscribeContextResponse.jsonRender6.valid.json deleted file mode 100644 index 6b13b4e5b9..0000000000 --- a/test/unittests/testData/ngsi10.subscribeContextResponse.jsonRender6.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"subscribeResponse":{"subscriptionId":"012345678901234567890123","duration":"PT1H","throttling":"PT1M"}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.unsubscribeContextRequest.badSubscriptionId.invalid.json b/test/unittests/testData/ngsi10.unsubscribeContextRequest.badSubscriptionId.invalid.json deleted file mode 100644 index ebd32dab19..0000000000 --- a/test/unittests/testData/ngsi10.unsubscribeContextRequest.badSubscriptionId.invalid.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "subscriptionId": "012345678901234567890123" -} diff --git a/test/unittests/testData/ngsi10.unsubscribeContextResponse.badSubscriptionId2.valid.json b/test/unittests/testData/ngsi10.unsubscribeContextResponse.badSubscriptionId2.valid.json deleted file mode 100644 index fd8bd16958..0000000000 --- a/test/unittests/testData/ngsi10.unsubscribeContextResponse.badSubscriptionId2.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"subscriptionId":"012345678901234567890123"} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.unsubscribeContextResponse.jsonRender1.valid.json b/test/unittests/testData/ngsi10.unsubscribeContextResponse.jsonRender1.valid.json deleted file mode 100644 index 7d6c786376..0000000000 --- a/test/unittests/testData/ngsi10.unsubscribeContextResponse.jsonRender1.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"subscriptionId":"012345678901234567890123","statusCode":{"code":"400","reasonPhrase":"Bad Request","details":"details"}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.unsubscribeContextResponse.jsonRender2.valid.json b/test/unittests/testData/ngsi10.unsubscribeContextResponse.jsonRender2.valid.json deleted file mode 100644 index bbb32e18e0..0000000000 --- a/test/unittests/testData/ngsi10.unsubscribeContextResponse.jsonRender2.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"subscriptionId":"012345678901234567890123","statusCode":{"code":"200","reasonPhrase":"OK"}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.updateContext.ok.valid.json b/test/unittests/testData/ngsi10.updateContext.ok.valid.json deleted file mode 100644 index 4c0cda0708..0000000000 --- a/test/unittests/testData/ngsi10.updateContext.ok.valid.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "contextElements": [ - { - "type": "Room", - "isPattern": "false", - "id": "ConferenceRoom", - "attributes": [ - { - "name": "temperature", - "type": "degree", - "value": "20", - "metadatas": [ - { - "name": "attributeValueIdentifier", - "type": "long", - "value": "1" - }, - { - "name": "attributeValueIdentifier", - "type": "long", - "value": "2" - }, - { - "name": "attributeValueIdentifier", - "type": "long", - "value": "3" - } - ] - } - ] - } - ], - "updateAction": "UPDATE" -} diff --git a/test/unittests/testData/ngsi10.updateContextAttributeRequest.check1.valid.json b/test/unittests/testData/ngsi10.updateContextAttributeRequest.check1.valid.json deleted file mode 100644 index 77269d69b4..0000000000 --- a/test/unittests/testData/ngsi10.updateContextAttributeRequest.check1.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"statusCode":{"code":"400","reasonPhrase":"Bad Request","details":"PRE Error"}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.updateContextAttributeRequest.check3.valid.json b/test/unittests/testData/ngsi10.updateContextAttributeRequest.check3.valid.json deleted file mode 100644 index c69acf6bbd..0000000000 --- a/test/unittests/testData/ngsi10.updateContextAttributeRequest.check3.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"statusCode":{"code":"400","reasonPhrase":"Bad Request","details":"missing metadata name"}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.updateContextAttributeRequest.putAttribute.valid.json b/test/unittests/testData/ngsi10.updateContextAttributeRequest.putAttribute.valid.json deleted file mode 100644 index bf48aa7cdb..0000000000 --- a/test/unittests/testData/ngsi10.updateContextAttributeRequest.putAttribute.valid.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "value": "40" -} diff --git a/test/unittests/testData/ngsi10.updateContextAttributeRequest.render.valid.json b/test/unittests/testData/ngsi10.updateContextAttributeRequest.render.valid.json deleted file mode 100644 index fa301bf45f..0000000000 --- a/test/unittests/testData/ngsi10.updateContextAttributeRequest.render.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"type":"TYPE","contextValue":"Context Value","metadatas":[{"name":"name","type":"type","value":"value"}]} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.updateContextAttributeResponse.notFound.valid.json b/test/unittests/testData/ngsi10.updateContextAttributeResponse.notFound.valid.json deleted file mode 100644 index 240ef9fb42..0000000000 --- a/test/unittests/testData/ngsi10.updateContextAttributeResponse.notFound.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"code":"404","reasonPhrase":"No context element found","details":"entity11"} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.updateContextElementRequest.check1.valid.json b/test/unittests/testData/ngsi10.updateContextElementRequest.check1.valid.json deleted file mode 100644 index 37a816c72e..0000000000 --- a/test/unittests/testData/ngsi10.updateContextElementRequest.check1.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"errorCode":{"code":"400","reasonPhrase":"Bad Request","details":"PRE Error"}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.updateContextElementRequest.check2.valid.json b/test/unittests/testData/ngsi10.updateContextElementRequest.check2.valid.json deleted file mode 100644 index 3e77dcc013..0000000000 --- a/test/unittests/testData/ngsi10.updateContextElementRequest.check2.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"errorCode":{"code":"400","reasonPhrase":"Bad Request","details":"missing attribute name"}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.updateContextElementRequest.render.valid.json b/test/unittests/testData/ngsi10.updateContextElementRequest.render.valid.json deleted file mode 100644 index c9b34ea4dd..0000000000 --- a/test/unittests/testData/ngsi10.updateContextElementRequest.render.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"attributes":[{"name":"caName","type":"caType","value":"caValue"}]} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.updateContextElementResponse.check1.valid.json b/test/unittests/testData/ngsi10.updateContextElementResponse.check1.valid.json deleted file mode 100644 index ec95dfb1cc..0000000000 --- a/test/unittests/testData/ngsi10.updateContextElementResponse.check1.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"errorCode":{"code":"400","reasonPhrase":"Bad Request","details":"PRE ERR"}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.updateContextElementResponse.check2.valid.json b/test/unittests/testData/ngsi10.updateContextElementResponse.check2.valid.json deleted file mode 100644 index 3e77dcc013..0000000000 --- a/test/unittests/testData/ngsi10.updateContextElementResponse.check2.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"errorCode":{"code":"400","reasonPhrase":"Bad Request","details":"missing attribute name"}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.updateContextElementResponse.ok.valid.json b/test/unittests/testData/ngsi10.updateContextElementResponse.ok.valid.json deleted file mode 100644 index a152712364..0000000000 --- a/test/unittests/testData/ngsi10.updateContextElementResponse.ok.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"contextResponses":[{"attributes":[{"name":"caName","type":"caType","value":"caValue"}],"statusCode":{"code":"200","reasonPhrase":"OK","details":"details"}}]} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.updateContextRequest.badIsPattern.invalid.json b/test/unittests/testData/ngsi10.updateContextRequest.badIsPattern.invalid.json deleted file mode 100644 index 30ab82ea08..0000000000 --- a/test/unittests/testData/ngsi10.updateContextRequest.badIsPattern.invalid.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "contextElements": [ - { - "type": "Room", - "isPattern": "fahlse", - "id": "ConferenceRoom", - "attributes": [ - { - "name": "temperature", - "type": "degree", - "value": "20", - "metadatas": [ - { - "name": "attributeValueIdentifier", - "type": "long", - "value": "1" - }, - { - "name": "attributeValueIdentifier", - "type": "long", - "value": "2" - }, - { - "name": "attributeValueIdentifier", - "type": "long", - "value": "3" - } - ] - } - ] - } - ], - "updateAction": "UPDATE" -} diff --git a/test/unittests/testData/ngsi10.updateContextResponse.badIsPattern.invalid.json b/test/unittests/testData/ngsi10.updateContextResponse.badIsPattern.invalid.json deleted file mode 100644 index f47ae4608a..0000000000 --- a/test/unittests/testData/ngsi10.updateContextResponse.badIsPattern.invalid.json +++ /dev/null @@ -1 +0,0 @@ -{"errorCode":{"code":"400","reasonPhrase":"Bad Request","details":"invalid isPattern value for entity: /fahlse/"}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.updateContextResponse.jsonRender1.valid.json b/test/unittests/testData/ngsi10.updateContextResponse.jsonRender1.valid.json deleted file mode 100644 index 7eb2000224..0000000000 --- a/test/unittests/testData/ngsi10.updateContextResponse.jsonRender1.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"errorCode":{"code":"404","reasonPhrase":"No context element found"}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.updateContextResponse.jsonRender11.valid.json b/test/unittests/testData/ngsi10.updateContextResponse.jsonRender11.valid.json deleted file mode 100644 index 32d08fed54..0000000000 --- a/test/unittests/testData/ngsi10.updateContextResponse.jsonRender11.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"contextResponses":[{"contextElement":{"type":"EType","isPattern":"false","id":"E01","attributes":[{"name":"ca5","type":"string","value":""},{"name":"ca11","type":"string","value":""}]},"statusCode":{"code":"200","reasonPhrase":"OK"}}]} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.updateContextResponse.jsonRender13.valid.json b/test/unittests/testData/ngsi10.updateContextResponse.jsonRender13.valid.json deleted file mode 100644 index e5a8a74694..0000000000 --- a/test/unittests/testData/ngsi10.updateContextResponse.jsonRender13.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"contextResponses":[{"contextElement":{"type":"EType","isPattern":"false","id":"E01","attributes":[{"name":"ca5","type":"string","value":""},{"name":"ca11","type":"string","value":""}]},"statusCode":{"code":"200","reasonPhrase":"OK"}},{"contextElement":{"type":"EType","isPattern":"false","id":"E02"},"statusCode":{"code":"200","reasonPhrase":"OK"}}]} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.updateContextResponse.jsonRender2.valid.json b/test/unittests/testData/ngsi10.updateContextResponse.jsonRender2.valid.json deleted file mode 100644 index 727f3ea1f3..0000000000 --- a/test/unittests/testData/ngsi10.updateContextResponse.jsonRender2.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"errorCode":{"code":"400","reasonPhrase":"Bad Request","details":"no details"}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.updateContextResponse.jsonRender3.valid.json b/test/unittests/testData/ngsi10.updateContextResponse.jsonRender3.valid.json deleted file mode 100644 index 0a3cb88107..0000000000 --- a/test/unittests/testData/ngsi10.updateContextResponse.jsonRender3.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"contextResponses":[{"contextElement":{"type":"EType","isPattern":"false","id":"E01"},"statusCode":{"code":"200","reasonPhrase":"OK"}}]} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.updateContextResponse.jsonRender5.valid.json b/test/unittests/testData/ngsi10.updateContextResponse.jsonRender5.valid.json deleted file mode 100644 index 206e88b073..0000000000 --- a/test/unittests/testData/ngsi10.updateContextResponse.jsonRender5.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"contextResponses":[{"contextElement":{"type":"EType","isPattern":"false","id":"E01","attributes":[{"name":"ca5","type":"string","value":""}]},"statusCode":{"code":"200","reasonPhrase":"OK"}}]} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.updateContextSubscriptionRequest.badLength.expected1.valid.json b/test/unittests/testData/ngsi10.updateContextSubscriptionRequest.badLength.expected1.valid.json deleted file mode 100644 index fbd49b98c8..0000000000 --- a/test/unittests/testData/ngsi10.updateContextSubscriptionRequest.badLength.expected1.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"subscribeError":{"subscriptionId":"9212ce4b0c214479be429e2","errorCode":{"code":"400","reasonPhrase":"Bad Request","details":"bad length - 24 chars expected"}}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.updateContextSubscriptionRequest.badLength.expected3.valid.json b/test/unittests/testData/ngsi10.updateContextSubscriptionRequest.badLength.expected3.valid.json deleted file mode 100644 index 8823171591..0000000000 --- a/test/unittests/testData/ngsi10.updateContextSubscriptionRequest.badLength.expected3.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"subscribeError":{"subscriptionId":"9212ce4b0c214479be429e2","errorCode":{"code":"400","reasonPhrase":"Bad Request","details":"FORCED ERROR"}}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.updateContextSubscriptionRequest.badLength.expected4.valid.json b/test/unittests/testData/ngsi10.updateContextSubscriptionRequest.badLength.expected4.valid.json deleted file mode 100644 index 9266544e7b..0000000000 --- a/test/unittests/testData/ngsi10.updateContextSubscriptionRequest.badLength.expected4.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"subscribeError":{"subscriptionId":"9212ce4b0c214479be429e2","errorCode":{"code":"400","reasonPhrase":"Bad Request","details":"syntax error in duration string"}}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.updateContextSubscriptionRequest.badLength.invalid.json b/test/unittests/testData/ngsi10.updateContextSubscriptionRequest.badLength.invalid.json deleted file mode 100644 index 5293507fa0..0000000000 --- a/test/unittests/testData/ngsi10.updateContextSubscriptionRequest.badLength.invalid.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "duration": "P5Y", - "restriction": { - "attributeExpression" : "AE", - "scopes": [ - { - "type" : "t1", - "value" : "1" - }, - { - "type" : "t2", - "value" : "2" - } - ] - }, - "subscriptionId": "9212ce4b0c214479be429e2", - "notifyConditions": [ - { - "type": "ONCHANGE", - "condValues": [ - "CondValue1", - "CondValue2" - ], - "restriction": "restriction" - } - ], - "throttling": "P5Y" -} diff --git a/test/unittests/testData/ngsi10.updateContextSubscriptionRequest.duration.invalid.json b/test/unittests/testData/ngsi10.updateContextSubscriptionRequest.duration.invalid.json deleted file mode 100644 index 74aa838910..0000000000 --- a/test/unittests/testData/ngsi10.updateContextSubscriptionRequest.duration.invalid.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "duration": "ddd", - "restriction": { - "attributeExpression" : "AE", - "scopes": [ - { - "type" : "t1", - "value" : "1" - }, - { - "type" : "t2", - "value" : "2" - } - ] - }, - "subscriptionId": "9212ce4b0c214479be429e2b", - "notifyConditions": [ - { - "type": "ONCHANGE", - "condValues": [ - "CondValue1", - "CondValue2" - ], - "restriction": "restriction" - } - ], - "throttling": "P5Y" -} diff --git a/test/unittests/testData/ngsi10.updateContextSubscriptionResponse.circleInvertedBadValue.valid.json b/test/unittests/testData/ngsi10.updateContextSubscriptionResponse.circleInvertedBadValue.valid.json deleted file mode 100644 index ee1a2bc651..0000000000 --- a/test/unittests/testData/ngsi10.updateContextSubscriptionResponse.circleInvertedBadValue.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"subscribeError":{"subscriptionId":"9212ce4b0c214479be429e21","errorCode":{"code":"400","reasonPhrase":"Bad Request","details":"bad string for circle/inverted: /zero/"}}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.updateContextSubscriptionResponse.circleZeroRadius.valid.json b/test/unittests/testData/ngsi10.updateContextSubscriptionResponse.circleZeroRadius.valid.json deleted file mode 100644 index 61f874edb7..0000000000 --- a/test/unittests/testData/ngsi10.updateContextSubscriptionResponse.circleZeroRadius.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"subscribeError":{"subscriptionId":"9212ce4b0c214479be429e21","errorCode":{"code":"400","reasonPhrase":"Bad Request","details":"Radius zero for a circle area"}}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.updateContextSubscriptionResponse.invalidDuration.valid.json b/test/unittests/testData/ngsi10.updateContextSubscriptionResponse.invalidDuration.valid.json deleted file mode 100644 index bfc55e5b72..0000000000 --- a/test/unittests/testData/ngsi10.updateContextSubscriptionResponse.invalidDuration.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"subscribeError":{"subscriptionId":"9212ce4b0c214479be429e2b","errorCode":{"code":"400","reasonPhrase":"Bad Request","details":"syntax error in duration string"}}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.updateContextSubscriptionResponse.jsonRender1.valid.json b/test/unittests/testData/ngsi10.updateContextSubscriptionResponse.jsonRender1.valid.json deleted file mode 100644 index dad063a159..0000000000 --- a/test/unittests/testData/ngsi10.updateContextSubscriptionResponse.jsonRender1.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"subscribeError":{"subscriptionId":"000000000000000000000000","errorCode":{"code":"400","reasonPhrase":"Bad Request","details":"details"}}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.updateContextSubscriptionResponse.jsonRender2.valid.json b/test/unittests/testData/ngsi10.updateContextSubscriptionResponse.jsonRender2.valid.json deleted file mode 100644 index 29765878bb..0000000000 --- a/test/unittests/testData/ngsi10.updateContextSubscriptionResponse.jsonRender2.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"subscribeError":{"subscriptionId":"012345678901234567890123","errorCode":{"code":"400","reasonPhrase":"Bad Request"}}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.updateContextSubscriptionResponse.jsonRender3.valid.json b/test/unittests/testData/ngsi10.updateContextSubscriptionResponse.jsonRender3.valid.json deleted file mode 100644 index 5a3f83fad4..0000000000 --- a/test/unittests/testData/ngsi10.updateContextSubscriptionResponse.jsonRender3.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"subscribeResponse":{"subscriptionId":"012345678901234567890123"}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.updateContextSubscriptionResponse.jsonRender4.valid.json b/test/unittests/testData/ngsi10.updateContextSubscriptionResponse.jsonRender4.valid.json deleted file mode 100644 index e6c43c5e32..0000000000 --- a/test/unittests/testData/ngsi10.updateContextSubscriptionResponse.jsonRender4.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"subscribeResponse":{"subscriptionId":"012345678901234567890123","throttling":"PT1M"}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.updateContextSubscriptionResponse.jsonRender5.valid.json b/test/unittests/testData/ngsi10.updateContextSubscriptionResponse.jsonRender5.valid.json deleted file mode 100644 index 7e67cd0071..0000000000 --- a/test/unittests/testData/ngsi10.updateContextSubscriptionResponse.jsonRender5.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"subscribeResponse":{"subscriptionId":"012345678901234567890123","duration":"PT1H"}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.updateContextSubscriptionResponse.jsonRender6.valid.json b/test/unittests/testData/ngsi10.updateContextSubscriptionResponse.jsonRender6.valid.json deleted file mode 100644 index 6b13b4e5b9..0000000000 --- a/test/unittests/testData/ngsi10.updateContextSubscriptionResponse.jsonRender6.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"subscribeResponse":{"subscriptionId":"012345678901234567890123","duration":"PT1H","throttling":"PT1M"}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.updateContextSubscriptionResponse.polygonInvertedBadValue.valid.json b/test/unittests/testData/ngsi10.updateContextSubscriptionResponse.polygonInvertedBadValue.valid.json deleted file mode 100644 index 20fdf7be93..0000000000 --- a/test/unittests/testData/ngsi10.updateContextSubscriptionResponse.polygonInvertedBadValue.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"subscribeError":{"subscriptionId":"9212ce4b0c214479be429e21","errorCode":{"code":"400","reasonPhrase":"Bad Request","details":"bad string for polygon/inverted: /zero/"}}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.updateContextSubscriptionResponse.polygonNoVertices.valid.json b/test/unittests/testData/ngsi10.updateContextSubscriptionResponse.polygonNoVertices.valid.json deleted file mode 100644 index 7a9264bcd7..0000000000 --- a/test/unittests/testData/ngsi10.updateContextSubscriptionResponse.polygonNoVertices.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"subscribeError":{"subscriptionId":"9212ce4b0c214479be429e21","errorCode":{"code":"400","reasonPhrase":"Bad Request","details":"too few vertices for a polygon"}}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.updateContextSubscriptionResponse.polygonOneVertex.valid.json b/test/unittests/testData/ngsi10.updateContextSubscriptionResponse.polygonOneVertex.valid.json deleted file mode 100644 index 7a9264bcd7..0000000000 --- a/test/unittests/testData/ngsi10.updateContextSubscriptionResponse.polygonOneVertex.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"subscribeError":{"subscriptionId":"9212ce4b0c214479be429e21","errorCode":{"code":"400","reasonPhrase":"Bad Request","details":"too few vertices for a polygon"}}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.updateContextSubscriptionResponse.polygonTwoVertices.valid.json b/test/unittests/testData/ngsi10.updateContextSubscriptionResponse.polygonTwoVertices.valid.json deleted file mode 100644 index 7a9264bcd7..0000000000 --- a/test/unittests/testData/ngsi10.updateContextSubscriptionResponse.polygonTwoVertices.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"subscribeError":{"subscriptionId":"9212ce4b0c214479be429e21","errorCode":{"code":"400","reasonPhrase":"Bad Request","details":"too few vertices for a polygon"}}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi9.discoverContextAvailabilityRequest.ok.valid.json b/test/unittests/testData/ngsi9.discoverContextAvailabilityRequest.ok.valid.json deleted file mode 100644 index 79a77f5046..0000000000 --- a/test/unittests/testData/ngsi9.discoverContextAvailabilityRequest.ok.valid.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "entities": [ - { - "type": "Room", - "isPattern": "false", - "id": "ConferenceRoom" - }, - { - "type": "Room", - "isPattern": "false", - "id": "OfficeRoom" - } - ], - "attributes": [ - "temperature", - "pressure" - ], - "restriction": { - "attributeExpression" : "Attribute Expression", - "scopes": [ - { - "type" : "st1", - "value" : "sv1" - }, - { - "type" : "st2", - "value" : "sv2" - } - ] - } -} diff --git a/test/unittests/testData/ngsi9.discoverContextAvailabilityResponse.jsonRender1.valid.json b/test/unittests/testData/ngsi9.discoverContextAvailabilityResponse.jsonRender1.valid.json deleted file mode 100644 index bff330857f..0000000000 --- a/test/unittests/testData/ngsi9.discoverContextAvailabilityResponse.jsonRender1.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"contextRegistrationResponses":[{"contextRegistration":{"entities":[{"type":"EType","isPattern":"false","id":"E01"}],"providingApplication":"http://tid.test.com/unitTest"}}]} \ No newline at end of file diff --git a/test/unittests/testData/ngsi9.discoverContextAvailabilityResponse.jsonRender10.valid.json b/test/unittests/testData/ngsi9.discoverContextAvailabilityResponse.jsonRender10.valid.json deleted file mode 100644 index 90b0dacdb8..0000000000 --- a/test/unittests/testData/ngsi9.discoverContextAvailabilityResponse.jsonRender10.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"contextRegistrationResponses":[{"contextRegistration":{"providingApplication":"http://tid.test.com/unitTest10"}}]} \ No newline at end of file diff --git a/test/unittests/testData/ngsi9.discoverContextAvailabilityResponse.jsonRender14.valid.json b/test/unittests/testData/ngsi9.discoverContextAvailabilityResponse.jsonRender14.valid.json deleted file mode 100644 index 8237d1a6b8..0000000000 --- a/test/unittests/testData/ngsi9.discoverContextAvailabilityResponse.jsonRender14.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"contextRegistrationResponses":[{"contextRegistration":{"entities":[{"type":"EType","isPattern":"false","id":"E14"}],"providingApplication":"http://tid.test.com/unitTest14"}}]} \ No newline at end of file diff --git a/test/unittests/testData/ngsi9.discoverContextAvailabilityResponse.jsonRender16.valid.json b/test/unittests/testData/ngsi9.discoverContextAvailabilityResponse.jsonRender16.valid.json deleted file mode 100644 index c67e6d12fe..0000000000 --- a/test/unittests/testData/ngsi9.discoverContextAvailabilityResponse.jsonRender16.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"contextRegistrationResponses":[{"contextRegistration":{"entities":[{"type":"EType","isPattern":"false","id":"E16"}],"attributes":[{"name":"Attr16","type":"AType"}],"providingApplication":"http://tid.test.com/unitTest16"}}]} \ No newline at end of file diff --git a/test/unittests/testData/ngsi9.discoverContextAvailabilityResponse.jsonRender18.valid.json b/test/unittests/testData/ngsi9.discoverContextAvailabilityResponse.jsonRender18.valid.json deleted file mode 100644 index 0f994ed3a0..0000000000 --- a/test/unittests/testData/ngsi9.discoverContextAvailabilityResponse.jsonRender18.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"errorCode":{"code":"400","reasonPhrase":"Bad Request","details":"DiscoverContextAvailabilityResponse Unit Test 18"}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi9.discoverContextAvailabilityResponse.jsonRender19.valid.json b/test/unittests/testData/ngsi9.discoverContextAvailabilityResponse.jsonRender19.valid.json deleted file mode 100644 index d782c0b7f4..0000000000 --- a/test/unittests/testData/ngsi9.discoverContextAvailabilityResponse.jsonRender19.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"errorCode":{"code":"400","reasonPhrase":"Bad Request"}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi9.discoverContextAvailabilityResponse.jsonRender2.valid.json b/test/unittests/testData/ngsi9.discoverContextAvailabilityResponse.jsonRender2.valid.json deleted file mode 100644 index 8569ab7720..0000000000 --- a/test/unittests/testData/ngsi9.discoverContextAvailabilityResponse.jsonRender2.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"contextRegistrationResponses":[{"contextRegistration":{"providingApplication":"http://tid.test.com/unitTest2"},"errorCode":{"code":"400","reasonPhrase":"Bad Request","details":"errorCode inside ContextRegistrationResponse"}}]} \ No newline at end of file diff --git a/test/unittests/testData/ngsi9.discoverContextAvailabilityResponse.jsonRender20.valid.json b/test/unittests/testData/ngsi9.discoverContextAvailabilityResponse.jsonRender20.valid.json deleted file mode 100644 index db64d9d9dd..0000000000 --- a/test/unittests/testData/ngsi9.discoverContextAvailabilityResponse.jsonRender20.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"contextRegistrationResponses":[{"contextRegistration":{"entities":[{"type":"EType","isPattern":"false","id":"E01"}],"providingApplication":"http://tid.test.com/unitTest"}},{"contextRegistration":{"entities":[{"type":"EType","isPattern":"false","id":"E02"}],"providingApplication":"http://tid.test.com/unitTest2"}}]} \ No newline at end of file diff --git a/test/unittests/testData/ngsi9.discoverContextAvailabilityResponse.jsonRender3.valid.json b/test/unittests/testData/ngsi9.discoverContextAvailabilityResponse.jsonRender3.valid.json deleted file mode 100644 index 90749c0159..0000000000 --- a/test/unittests/testData/ngsi9.discoverContextAvailabilityResponse.jsonRender3.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"contextRegistrationResponses":[{"contextRegistration":{"providingApplication":"http://tid.test.com/unitTest2"},"errorCode":{"code":"400","reasonPhrase":"Bad Request","details":"errorCode inside ContextRegistrationResponse"}},{"contextRegistration":{"providingApplication":"http://tid.test.com/unitTest3"}}]} \ No newline at end of file diff --git a/test/unittests/testData/ngsi9.discoverContextAvailabilityResponse.jsonRender4.valid.json b/test/unittests/testData/ngsi9.discoverContextAvailabilityResponse.jsonRender4.valid.json deleted file mode 100644 index 6b26e4dda0..0000000000 --- a/test/unittests/testData/ngsi9.discoverContextAvailabilityResponse.jsonRender4.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"contextRegistrationResponses":[{"contextRegistration":{"entities":[{"type":"EType","isPattern":"false","id":"E04"}],"providingApplication":"http://tid.test.com/unitTest4"}}]} \ No newline at end of file diff --git a/test/unittests/testData/ngsi9.discoverContextAvailabilityResponse.jsonRender5.valid.json b/test/unittests/testData/ngsi9.discoverContextAvailabilityResponse.jsonRender5.valid.json deleted file mode 100644 index c2bf472289..0000000000 --- a/test/unittests/testData/ngsi9.discoverContextAvailabilityResponse.jsonRender5.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"contextRegistrationResponses":[{"contextRegistration":{"entities":[{"type":"EType","isPattern":"false","id":"E04"},{"type":"EType","isPattern":"false","id":"E05"}],"providingApplication":"http://tid.test.com/unitTest5"}}]} \ No newline at end of file diff --git a/test/unittests/testData/ngsi9.discoverContextAvailabilityResponse.jsonRender6.valid.json b/test/unittests/testData/ngsi9.discoverContextAvailabilityResponse.jsonRender6.valid.json deleted file mode 100644 index b78b57c7fd..0000000000 --- a/test/unittests/testData/ngsi9.discoverContextAvailabilityResponse.jsonRender6.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"contextRegistrationResponses":[{"contextRegistration":{"attributes":[{"name":"Attr1","type":"AType"}],"providingApplication":"http://tid.test.com/unitTest6"}}]} \ No newline at end of file diff --git a/test/unittests/testData/ngsi9.discoverContextAvailabilityResponse.jsonRender7.valid.json b/test/unittests/testData/ngsi9.discoverContextAvailabilityResponse.jsonRender7.valid.json deleted file mode 100644 index b52567441e..0000000000 --- a/test/unittests/testData/ngsi9.discoverContextAvailabilityResponse.jsonRender7.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"contextRegistrationResponses":[{"contextRegistration":{"attributes":[{"name":"Attr1","type":"AType"},{"name":"Attr2","type":"AType"}],"providingApplication":"http://tid.test.com/unitTest7"}}]} \ No newline at end of file diff --git a/test/unittests/testData/ngsi9.discoverContextAvailabilityRsponse.notFound.valid.json b/test/unittests/testData/ngsi9.discoverContextAvailabilityRsponse.notFound.valid.json deleted file mode 100644 index 7eb2000224..0000000000 --- a/test/unittests/testData/ngsi9.discoverContextAvailabilityRsponse.notFound.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"errorCode":{"code":"404","reasonPhrase":"No context element found"}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi9.discoverContextAvailabilityRsponse.serviceNotRecognized.valid.json b/test/unittests/testData/ngsi9.discoverContextAvailabilityRsponse.serviceNotRecognized.valid.json deleted file mode 100644 index d57e25ddad..0000000000 --- a/test/unittests/testData/ngsi9.discoverContextAvailabilityRsponse.serviceNotRecognized.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"errorCode":{"code":"400","reasonPhrase":"Bad Request","details":"Service not found. Check your URL as probably it is wrong."}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi9.registerContext.ok.valid.json b/test/unittests/testData/ngsi9.registerContext.ok.valid.json deleted file mode 100644 index 02b14e294d..0000000000 --- a/test/unittests/testData/ngsi9.registerContext.ok.valid.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "contextRegistrations": [ - { - "entities": [ - { - "type": "Room", - "isPattern": "false", - "id": "ConferenceRoom" - }, - { - "type": "Room", - "isPattern": "false", - "id": "OfficeRoom" - } - ], - "attributes": [ - { - "name": "temperature", - "type": "degree" - } - ], - "providingApplication": "http://192.168.100.1:70/application" - } - ], - "duration": "PT1M" -} diff --git a/test/unittests/testData/ngsi9.registerContextResponse.registrationIdAndDuration.valid.json b/test/unittests/testData/ngsi9.registerContextResponse.registrationIdAndDuration.valid.json deleted file mode 100644 index f753c91dbc..0000000000 --- a/test/unittests/testData/ngsi9.registerContextResponse.registrationIdAndDuration.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"duration":"PT1S","registrationId":"012345678901234567890123"} \ No newline at end of file diff --git a/test/unittests/testData/ngsi9.registerContextResponse.registrationIdAndDurationAndErrorCode.valid.json b/test/unittests/testData/ngsi9.registerContextResponse.registrationIdAndDurationAndErrorCode.valid.json deleted file mode 100644 index 1c66e4ac77..0000000000 --- a/test/unittests/testData/ngsi9.registerContextResponse.registrationIdAndDurationAndErrorCode.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"registrationId":"012345678901234567890123","errorCode":{"code":"400","reasonPhrase":"Bad Request","details":"no details"}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi9.registerContextResponse.registrationIdAndErrorCode.valid.json b/test/unittests/testData/ngsi9.registerContextResponse.registrationIdAndErrorCode.valid.json deleted file mode 100644 index 1c66e4ac77..0000000000 --- a/test/unittests/testData/ngsi9.registerContextResponse.registrationIdAndErrorCode.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"registrationId":"012345678901234567890123","errorCode":{"code":"400","reasonPhrase":"Bad Request","details":"no details"}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi9.registerContextResponse.registrationIdOnly.valid.json b/test/unittests/testData/ngsi9.registerContextResponse.registrationIdOnly.valid.json deleted file mode 100644 index 53c6cdad62..0000000000 --- a/test/unittests/testData/ngsi9.registerContextResponse.registrationIdOnly.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"registrationId":"012345678901234567890123"} \ No newline at end of file diff --git a/test/unittests/testData/notifyContextRequest_ok.json b/test/unittests/testData/notifyContextRequest_ok.json deleted file mode 100644 index 98974c9979..0000000000 --- a/test/unittests/testData/notifyContextRequest_ok.json +++ /dev/null @@ -1,54 +0,0 @@ -{ - "subscriptionId": "012345678901234567890123", - "originator": "http://localhost/test", - "contextResponses": [ - { - "contextElement": { - "type": "Room", - "isPattern": "false", - "id": "ConferenceRoom", - "attributes": [ - { - "name": "temperature", - "type": "Room", - "value": "10", - "metadatas": [ - { - "name": "ID", - "type": "string", - "value": "1110" - }, - { - "name": "id", - "type": "integer", - "value": "12" - } - ] - }, - { - "name": "temperature", - "type": "Room", - "value": "10", - "metadatas": [ - { - "name": "ID", - "type": "string", - "value": "1110" - }, - { - "name": "id", - "type": "integer", - "value": "55" - } - ] - } - ] - }, - "statusCode": { - "code": "200", - "reasonPhrase": "Ok", - "details": "a" - } - } - ] -} diff --git a/test/unittests/testData/orion.jsonRequest.jsonTreat.valid.json b/test/unittests/testData/orion.jsonRequest.jsonTreat.valid.json deleted file mode 100644 index d6ee602de7..0000000000 --- a/test/unittests/testData/orion.jsonRequest.jsonTreat.valid.json +++ /dev/null @@ -1 +0,0 @@ -{"orionError":{"code":"400","reasonPhrase":"Bad Request","details":"Sorry, no request treating object found for RequestType /InvalidRequest/"}} \ No newline at end of file diff --git a/test/unittests/testData/orion.orionError.all1.valid.json b/test/unittests/testData/orion.orionError.all1.valid.json index 38c903a59e..bbacc4986c 100644 --- a/test/unittests/testData/orion.orionError.all1.valid.json +++ b/test/unittests/testData/orion.orionError.all1.valid.json @@ -1 +1 @@ -{"orionError":{"code":"200","reasonPhrase":"OK","details":"no details 3"}} \ No newline at end of file +{"error":"OK","description":"no details 3"} \ No newline at end of file diff --git a/test/unittests/testData/orion.orionError.all2.valid.json b/test/unittests/testData/orion.orionError.all2.valid.json deleted file mode 100644 index 23d5521ed9..0000000000 --- a/test/unittests/testData/orion.orionError.all2.valid.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "orionError" : { - "code" : "400", - "reasonPhrase" : "Bad Request", - "details" : "no details" - } -} diff --git a/test/unittests/testData/orion.orionError.all3.valid.json b/test/unittests/testData/orion.orionError.all3.valid.json index 454436b4d6..d3f9d843a7 100644 --- a/test/unittests/testData/orion.orionError.all3.valid.json +++ b/test/unittests/testData/orion.orionError.all3.valid.json @@ -1 +1 @@ -{"orionError":{"code":"400","reasonPhrase":"Bad Request","details":"no details 2"}} \ No newline at end of file +{"error":"BadRequest","description":"no details 2"} \ No newline at end of file diff --git a/test/unittests/testData/orion.orionError.all4.valid.json b/test/unittests/testData/orion.orionError.all4.valid.json index d9976a35ee..5427ffdec6 100644 --- a/test/unittests/testData/orion.orionError.all4.valid.json +++ b/test/unittests/testData/orion.orionError.all4.valid.json @@ -1 +1 @@ -{"orionError":{"code":"200","reasonPhrase":"OK","details":"Good Request"}} \ No newline at end of file +{"error":"OK","description":"Good Request"} \ No newline at end of file diff --git a/test/unittests/testInit.cpp b/test/unittests/testInit.cpp index ba7cb27ada..1b3c6cfb02 100644 --- a/test/unittests/testInit.cpp +++ b/test/unittests/testInit.cpp @@ -85,24 +85,7 @@ void setupDatabase(void) */ static bool equalEntity(EntityId enExpected, EntityId enArg) { - LM_M(("enArg '%s', '%s', '%s'", - enArg.id.c_str(), - enArg.type.c_str(), - enArg.isPattern.c_str())); - - LM_M(("enExpected '%s', '%s', '%s'", - enExpected.id.c_str(), - enExpected.type.c_str(), - enExpected.isPattern.c_str())); - - if (enExpected.id == enArg.id && enExpected.type == enArg.type && enExpected.isPattern == enArg.isPattern) - { - return true; - } - else - { - return false; - } + return (enExpected == enArg); } @@ -226,8 +209,8 @@ static bool equalContextElementResponseVector ContextElementResponse* cerArg = cerArgV[ix]; ContextElementResponse* cerExpected = cerExpectedV[jx]; - EntityId enExpected(cerExpected->entity.id, cerExpected->entity.type); - EntityId enArg(cerArg->entity.id, cerArg->entity.type); + EntityId enExpected(cerExpected->entity.entityId.id, cerExpected->entity.entityId.idPattern, cerExpected->entity.entityId.type, cerExpected->entity.entityId.typePattern); + EntityId enArg(cerArg->entity.entityId.id, cerArg->entity.entityId.idPattern, cerArg->entity.entityId.type, cerArg->entity.entityId.typePattern); if (!equalEntity(enExpected, enArg)) { @@ -278,12 +261,7 @@ bool matchNotifyContextRequest(NotifyContextRequest* expected, NotifyContextRequ /* The isEmpty() check is needed because, in some occasion, we don't have any expectations on * subscriptionId and, in these cases, we don't check its value */ - if (!expected->subscriptionId.isEmpty() && (expected->subscriptionId.get() != arg->subscriptionId.get())) - { - return false; - } - - if (expected->originator.get() != arg->originator.get()) + if (!expected->subscriptionId.empty() && (expected->subscriptionId != arg->subscriptionId)) { return false; } diff --git a/test/unittests/unittest.cpp b/test/unittests/unittest.cpp index 06ec5b23f7..028a595102 100644 --- a/test/unittests/unittest.cpp +++ b/test/unittests/unittest.cpp @@ -144,7 +144,6 @@ void utInit(bool notifierMocked, bool timerMocked) // uriParams[URI_PARAM_PAGINATION_OFFSET] = DEFAULT_PAGINATION_OFFSET; uriParams[URI_PARAM_PAGINATION_LIMIT] = DEFAULT_PAGINATION_LIMIT; - uriParams[URI_PARAM_PAGINATION_DETAILS] = DEFAULT_PAGINATION_DETAILS; uriParams[URI_PARAM_NOT_EXIST] = ""; // FIXME P7: we need this to implement "restriction-based" filters //