diff --git a/Insomnia_2019-10-10.yaml b/Insomnia_2019-10-10.yaml new file mode 100644 index 0000000..09fdea4 --- /dev/null +++ b/Insomnia_2019-10-10.yaml @@ -0,0 +1,692 @@ +_type: export +__export_format: 4 +__export_date: 2019-10-10T08:51:17.923Z +__export_source: insomnia.desktop.app:v7.0.0 +resources: + - _id: req_f0797b6411b144f0bf0a40d9300ee92f + authentication: + disabled: false + password: E7FEA07DBC82FB9BA34B2E453E2EFE89F0583E7187543507EF11E84726071FE428445372F2E46B455EB0C79747C51E362F403CE39473A2A8C2DFA0CE5C9826C0 + type: basic + username: spaceti + body: + mimeType: application/json + text: >- + { + "username": "spaceti", + "password": "E7FEA07DBC82FB9BA34B2E453E2EFE89F0583E7187543507EF11E84726071FE428445372F2E46B455EB0C79747C51E362F403CE39473A2A8C2DFA0CE5C9826C0" + } + created: 1569905755136 + description: "" + headers: + - id: pair_061d15d1294e412caca8300559541695 + name: content-type + value: application/json + isPrivate: false + metaSortKey: -1569905755136 + method: POST + modified: 1570026752164 + name: Login user + parameters: [] + parentId: fld_9ef1d96e0e6d40ef9094250114269496 + settingDisableRenderRequestBody: false + settingEncodeUrl: true + settingRebuildPath: true + settingSendCookies: true + settingStoreCookies: true + url: "{{ base_url }}/AaaManager/authSession" + _type: request + - _id: fld_9ef1d96e0e6d40ef9094250114269496 + created: 1569905755142 + description: Login information ( token ) + environment: {} + environmentPropertyOrder: null + metaSortKey: -1569905755142 + modified: 1569905755142 + name: login + parentId: wrk_43652e59afaf4825a8bbbf31e346f616 + _type: request_group + - _id: wrk_43652e59afaf4825a8bbbf31e346f616 + created: 1569905755149 + description: "Colnod system: [Product information](http://produkty.colsys.cz/colnod) + Jira issues: [Communicaiton with + Colnod](https://spaceti.atlassian.net/secure/RapidBoard.jspa?rapidView=78\ + &projectKey=INT&modal=detail&selectedIssue=INT-3563)" + modified: 1569905755149 + name: Colnod server 1.0.0 + parentId: null + _type: workspace + - _id: req_00f9f99d933c4638900385ffbbd4f8f7 + authentication: + disabled: false + token: "{% response 'body', 'req_f0797b6411b144f0bf0a40d9300ee92f', + 'b64::JC5pZA==::46b', 'no-history' %}" + type: bearer + body: + mimeType: application/json + text: "" + created: 1569905755134 + description: "" + headers: + - id: pair_a2a3c43a20f64efbb8a4752c7e983c8e + name: Content-Type + value: application/json + isPrivate: false + metaSortKey: -1569905755134 + method: POST + modified: 1570696568628 + name: Get Subjects Bearer + parameters: [] + parentId: fld_2fb4c2cef1f44cff83d6b00fe0886384 + settingDisableRenderRequestBody: false + settingEncodeUrl: true + settingRebuildPath: true + settingSendCookies: true + settingStoreCookies: true + url: "{{ base_url }}/SubjectManager/getSubjects" + _type: request + - _id: fld_2fb4c2cef1f44cff83d6b00fe0886384 + created: 1569905755140 + description: Operations about user + environment: {} + environmentPropertyOrder: null + metaSortKey: -1569905755140 + modified: 1570632691970 + name: Subjects + parentId: wrk_43652e59afaf4825a8bbbf31e346f616 + _type: request_group + - _id: req_1c6b6e7783ac4eec95802f655899b9ea + authentication: + disabled: false + password: "" + type: basic + username: "{% response 'body', 'req_f0797b6411b144f0bf0a40d9300ee92f', + 'b64::JC5pZA==::46b', 'never' %}" + body: + mimeType: application/json + text: "" + created: 1570444564217 + description: "" + headers: + - id: pair_a2a3c43a20f64efbb8a4752c7e983c8e + name: Content-Type + value: application/json + isPrivate: false + metaSortKey: -1569905755132.5 + method: POST + modified: 1570696575241 + name: Get Subjects + parameters: [] + parentId: fld_2fb4c2cef1f44cff83d6b00fe0886384 + settingDisableRenderRequestBody: false + settingEncodeUrl: true + settingRebuildPath: true + settingSendCookies: true + settingStoreCookies: true + url: "{{ base_url }}/SubjectManager/getSubjects" + _type: request + - _id: req_7380fab5ef444b1382692bb0474a996c + authentication: + disabled: false + password: "" + type: basic + username: "{% response 'body', 'req_f0797b6411b144f0bf0a40d9300ee92f', + 'b64::JC5pZA==::46b', 'never' %}" + body: + mimeType: application/json + text: |- + { + "timestamp": 1568646217767 + } + created: 1570632390552 + description: "" + headers: + - id: pair_a2a3c43a20f64efbb8a4752c7e983c8e + name: Content-Type + value: application/json + isPrivate: false + metaSortKey: -1569905755131.75 + method: POST + modified: 1570696583252 + name: Get Subjects Updated + parameters: [] + parentId: fld_2fb4c2cef1f44cff83d6b00fe0886384 + settingDisableRenderRequestBody: false + settingEncodeUrl: true + settingRebuildPath: true + settingSendCookies: true + settingStoreCookies: true + url: "{{ base_url }}/SubjectManager/getSubjectsUpdated" + _type: request + - _id: req_3ecc5702954a41e7b80a58130d38c6cf + authentication: + disabled: false + password: "" + type: basic + username: "{% response 'body', 'req_f0797b6411b144f0bf0a40d9300ee92f', + 'b64::JC5pZA==::46b', 'never' %}" + body: + mimeType: application/json + text: |- + { + "timestamp": 0 + } + created: 1570632515576 + description: "" + headers: + - id: pair_a2a3c43a20f64efbb8a4752c7e983c8e + name: Content-Type + value: application/json + isPrivate: false + metaSortKey: -1569905755131.375 + method: POST + modified: 1570696594665 + name: Get Subjects Deleted + parameters: [] + parentId: fld_2fb4c2cef1f44cff83d6b00fe0886384 + settingDisableRenderRequestBody: false + settingEncodeUrl: true + settingRebuildPath: true + settingSendCookies: true + settingStoreCookies: true + url: "{{ base_url }}/SubjectManager/getSubjectsDeleted" + _type: request + - _id: req_9e42a5023f9d4235a5de099cd7573d2b + authentication: + disabled: false + password: "" + type: basic + username: "{% response 'body', 'req_f0797b6411b144f0bf0a40d9300ee92f', + 'b64::JC5pZA==::46b', 'never' %}" + body: + mimeType: application/json + text: "" + created: 1569905755131 + description: "" + headers: + - disabled: false + id: pair_e888b6c679d74b0988f0dd2d77690383 + name: Content-Type + value: application/json + isPrivate: false + metaSortKey: -1569905755131 + method: POST + modified: 1570530410208 + name: Get Tokens + parameters: [] + parentId: fld_36a4be72380440a0ace83ad508a0458d + settingDisableRenderRequestBody: false + settingEncodeUrl: true + settingRebuildPath: true + settingSendCookies: true + settingStoreCookies: true + url: "{{ base_url }}TokenManager/getTokens/" + _type: request + - _id: fld_36a4be72380440a0ace83ad508a0458d + created: 1569905755138 + description: Working with tokens ( keys ) + environment: {} + environmentPropertyOrder: null + metaSortKey: -1569905755138 + modified: 1569934361048 + name: Token Manager + parentId: wrk_43652e59afaf4825a8bbbf31e346f616 + _type: request_group + - _id: req_3d5c333b21d9472f8d8628d2c45a5f0d + authentication: + disabled: false + password: "" + type: basic + username: "{% response 'body', 'req_f0797b6411b144f0bf0a40d9300ee92f', + 'b64::JC5pZA==::46b', 'never' %}" + body: + mimeType: application/json + text: |- + { + "timestamp": 1570696743171 + } + created: 1570696427073 + description: "" + headers: + - id: pair_ae0b3209dd2c4e2699ac3c6125082d88 + name: Content-Type + value: application/json + isPrivate: false + metaSortKey: -1569905755129.75 + method: POST + modified: 1570696752630 + name: Get Tokens Updated + parameters: [] + parentId: fld_36a4be72380440a0ace83ad508a0458d + settingDisableRenderRequestBody: false + settingEncodeUrl: true + settingRebuildPath: true + settingSendCookies: true + settingStoreCookies: true + url: "{{ base_url }}/TokenManager/getTokensUpdated" + _type: request + - _id: req_b6667f303a8a4d5a9d7cc4245cc598eb + authentication: + disabled: false + password: "" + type: basic + username: "{% response 'body', 'req_f0797b6411b144f0bf0a40d9300ee92f', + 'b64::JC5pZA==::46b', 'never' %}" + body: + mimeType: application/json + text: |- + { + "timestamp": 1568646217767 + } + created: 1570696638651 + description: "" + headers: + - id: pair_67395eea470e491ab6b14f6fc6ed26ae + name: Content-Type + value: application/json + isPrivate: false + metaSortKey: -1569905755129.375 + method: POST + modified: 1570696694533 + name: Get Token Deleted + parameters: [] + parentId: fld_36a4be72380440a0ace83ad508a0458d + settingDisableRenderRequestBody: false + settingEncodeUrl: true + settingRebuildPath: true + settingSendCookies: true + settingStoreCookies: true + url: "{{ base_url }}/TokenManager/getTokensDeleted" + _type: request + - _id: req_4f99d61a83c14da29882cc80c07ddf54 + authentication: + disabled: false + password: "" + type: basic + username: "{% response 'body', 'req_f0797b6411b144f0bf0a40d9300ee92f', + 'b64::JC5pZA==::46b', 'never' %}" + body: + mimeType: application/json + text: | + { + "id": "cf5cb80e-e6dd-45db-8edd-c9655447821c", + "name": "Anonym", + "description": "", + "lastUpdate": 1543494713260, + "tokenType": "Token", + "tokenBits": 32, + "tokenData": "AB1EA4D4", + "timeToLive": 255, + "authErrors": 255, + "flags": [ + "Enabled", + "NoValidity" + ], + "subjectId": "69c6e3b3-3f23-456f-a6c2-73ef08e589a4" + } + created: 1569905755127 + description: "" + headers: + - id: pair_3808311d7abc4f37898beff39a7016eb + name: Content-Type + value: application/json + isPrivate: false + metaSortKey: -1569905755129 + method: POST + modified: 1570697398859 + name: Set Tokens (in progress) + parameters: [] + parentId: fld_36a4be72380440a0ace83ad508a0458d + settingDisableRenderRequestBody: false + settingEncodeUrl: true + settingRebuildPath: true + settingSendCookies: true + settingStoreCookies: true + url: "{{ base_url }}/TokenManager/setTokens" + _type: request + - _id: req_fd2e096f45554b46b31755564a0932bf + authentication: + disabled: false + password: "" + type: basic + username: "{% response 'body', 'req_f0797b6411b144f0bf0a40d9300ee92f', + 'b64::JC5pZA==::46b', 'never' %}" + body: {} + created: 1569934364782 + description: "" + headers: [] + isPrivate: false + metaSortKey: -1569905755130.5 + method: POST + modified: 1570445314172 + name: Get Token Subject + parameters: [] + parentId: fld_8d34eca167ef426c8aa998c98bbe74e2 + settingDisableRenderRequestBody: false + settingEncodeUrl: true + settingRebuildPath: true + settingSendCookies: true + settingStoreCookies: true + url: "{{ base_url }}/OpenManager/getTokenSubject" + _type: request + - _id: fld_8d34eca167ef426c8aa998c98bbe74e2 + created: 1569934364777 + description: Working with tokens ( keys ) + environment: {} + environmentPropertyOrder: null + metaSortKey: -1569905755088 + modified: 1570632707161 + name: Open Manager ( wont use ) + parentId: wrk_43652e59afaf4825a8bbbf31e346f616 + _type: request_group + - _id: req_7007bb1f6a0243a7b0568741f691f6d1 + authentication: + disabled: false + password: E7FEA07DBC82FB9BA34B2E453E2EFE89F0583E7187543507EF11E84726071FE428445372F2E46B455EB0C79747C51E362F403CE39473A2A8C2DFA0CE5C9826C0 + type: basic + username: spaceti + body: + mimeType: application/json + text: >- + { + "username": "spaceti", + "password": "E7FEA07DBC82FB9BA34B2E453E2EFE89F0583E7187543507EF11E84726071FE428445372F2E46B455EB0C79747C51E362F403CE39473A2A8C2DFA0CE5C9826C0" + } + created: 1570025458784 + description: "" + headers: + - id: pair_74b4df5d54d1446a90e6a668d373fb79 + name: Content-Type + value: application/json + isPrivate: false + metaSortKey: -1569905755129.75 + method: POST + modified: 1570030518745 + name: Get Token Subject Full authorization + parameters: [] + parentId: fld_8d34eca167ef426c8aa998c98bbe74e2 + settingDisableRenderRequestBody: false + settingEncodeUrl: true + settingRebuildPath: true + settingSendCookies: true + settingStoreCookies: true + url: "{{ base_url }}/OpenManager/getTokenSubject" + _type: request + - _id: req_9e5b797601a740488876ea20cc9fd183 + authentication: + disabled: false + password: E7FEA07DBC82FB9BA34B2E453E2EFE89F0583E7187543507EF11E84726071FE428445372F2E46B455EB0C79747C51E362F403CE39473A2A8C2DFA0CE5C9826C0 + type: basic + username: spaceti + body: + mimeType: application/json + text: >- + { + "username": "spaceti", + "password": "E7FEA07DBC82FB9BA34B2E453E2EFE89F0583E7187543507EF11E84726071FE428445372F2E46B455EB0C79747C51E362F403CE39473A2A8C2DFA0CE5C9826C0" + } + created: 1570110543873 + description: "" + headers: + - id: pair_74b4df5d54d1446a90e6a668d373fb79 + name: Content-Type + value: application/json + isPrivate: false + metaSortKey: -1569905755129.375 + method: POST + modified: 1570429074494 + name: Get Token Subject test with nc + parameters: [] + parentId: fld_8d34eca167ef426c8aa998c98bbe74e2 + settingDisableRenderRequestBody: false + settingEncodeUrl: true + settingRebuildPath: true + settingSendCookies: true + settingStoreCookies: true + url: "{{ base_url }}/OpenManager/getTokenSubject" + _type: request + - _id: req_9fe84e48068847aba97ff920376dc768 + authentication: + disabled: false + password: "" + type: basic + username: "{% response 'body', 'req_f0797b6411b144f0bf0a40d9300ee92f', + 'b64::JC5pZA==::46b', 'never' %}" + body: {} + created: 1570695910222 + description: "" + headers: [] + isPrivate: false + metaSortKey: -1570695910222 + method: POST + modified: 1570696316380 + name: Get Access Groups + parameters: [] + parentId: fld_2cd1b870d3304ee2a49c4a09c24e2eb0 + settingDisableRenderRequestBody: false + settingEncodeUrl: true + settingRebuildPath: true + settingSendCookies: true + settingStoreCookies: true + url: "{{ base_url }}/AccessManager/getAccessGroups" + _type: request + - _id: fld_2cd1b870d3304ee2a49c4a09c24e2eb0 + created: 1570695902620 + description: "" + environment: {} + environmentPropertyOrder: null + metaSortKey: -1569905755029.375 + modified: 1570696079131 + name: AccessManager + parentId: wrk_43652e59afaf4825a8bbbf31e346f616 + _type: request_group + - _id: req_c5666cec2d3d4a81bc653d57b0dbb09a + authentication: + disabled: false + password: "" + type: basic + username: "{% response 'body', 'req_f0797b6411b144f0bf0a40d9300ee92f', + 'b64::JC5pZA==::46b', 'never' %}" + body: + mimeType: application/json + text: |- + { + "timestamp": 1568646217767 + } + created: 1570696789456 + description: "" + headers: + - id: pair_5341cecb8a0d47e5ba7e1c0c52c12b47 + name: Content-Type + value: application/json + isPrivate: false + metaSortKey: -1570695910172 + method: POST + modified: 1570696957577 + name: Get Access Groups Updated + parameters: [] + parentId: fld_2cd1b870d3304ee2a49c4a09c24e2eb0 + settingDisableRenderRequestBody: false + settingEncodeUrl: true + settingRebuildPath: true + settingSendCookies: true + settingStoreCookies: true + url: "{{ base_url }}/AccessManager/getAccessGroupsUpdated" + _type: request + - _id: req_126a165eaa60410fae62c3baa11036ea + authentication: + disabled: false + password: "" + type: basic + username: "{% response 'body', 'req_f0797b6411b144f0bf0a40d9300ee92f', + 'b64::JC5pZA==::46b', 'never' %}" + body: + mimeType: application/json + text: |- + { + "timestamp": 0 + } + created: 1570696820132 + description: "" + headers: + - id: pair_73e13582518d46c5b1e67ca9783e319c + name: Content-Type + value: application/json + isPrivate: false + metaSortKey: -1570695910122 + method: POST + modified: 1570697027201 + name: Get Access Groups Deleted + parameters: [] + parentId: fld_2cd1b870d3304ee2a49c4a09c24e2eb0 + settingDisableRenderRequestBody: false + settingEncodeUrl: true + settingRebuildPath: true + settingSendCookies: true + settingStoreCookies: true + url: "{{ base_url }}/AccessManager/getAccessGroupsDeleted" + _type: request + - _id: req_6d950dec8f414bf195261428e394b468 + authentication: + disabled: false + password: "" + type: basic + username: "{% response 'body', 'req_f0797b6411b144f0bf0a40d9300ee92f', + 'b64::JC5pZA==::46b', 'never' %}" + body: + mimeType: application/json + text: |- + { + "timestamp": 1568646217767 + } + created: 1570696857201 + description: "" + headers: + - id: pair_053943120aed4194bc23bb7e07ef5485 + name: Content-Type + value: application/json + isPrivate: false + metaSortKey: -1570695910072 + method: POST + modified: 1570697040108 + name: Get Access Group Membership + parameters: [] + parentId: fld_2cd1b870d3304ee2a49c4a09c24e2eb0 + settingDisableRenderRequestBody: false + settingEncodeUrl: true + settingRebuildPath: true + settingSendCookies: true + settingStoreCookies: true + url: "{{ base_url }}/AccessManager/getAccessGroupMembership" + _type: request + - _id: req_1af11b4de244498c9940fd90862bf8a1 + authentication: + disabled: false + password: "" + type: basic + username: "{% response 'body', 'req_f0797b6411b144f0bf0a40d9300ee92f', + 'b64::JC5pZA==::46b', 'never' %}" + body: + mimeType: application/json + text: |- + { + "timestamp": 1568646217767 + } + created: 1570696880249 + description: "" + headers: + - id: pair_cae12a041df14bd995719d6162b48bab + name: Content-Type + value: application/json + isPrivate: false + metaSortKey: -1570695910022 + method: POST + modified: 1570697063733 + name: Get Access Group Membership Updated + parameters: [] + parentId: fld_2cd1b870d3304ee2a49c4a09c24e2eb0 + settingDisableRenderRequestBody: false + settingEncodeUrl: true + settingRebuildPath: true + settingSendCookies: true + settingStoreCookies: true + url: "{{ base_url }}/AccessManager/getAccessGroupMembershipUpdated" + _type: request + - _id: req_0ae1522c390943bbaba12ca4fb24f27f + authentication: + disabled: false + password: "" + type: basic + username: "{% response 'body', 'req_f0797b6411b144f0bf0a40d9300ee92f', + 'b64::JC5pZA==::46b', 'never' %}" + body: + mimeType: application/json + text: |- + { + "timestamp": 0 + } + created: 1570696897934 + description: "" + headers: + - id: pair_1bbc15031afb4303836d2d62a5769191 + name: Content-Type + value: application/json + isPrivate: false + metaSortKey: -1570695909972 + method: POST + modified: 1570697068425 + name: Get Access Group Membership Deleted + parameters: [] + parentId: fld_2cd1b870d3304ee2a49c4a09c24e2eb0 + settingDisableRenderRequestBody: false + settingEncodeUrl: true + settingRebuildPath: true + settingSendCookies: true + settingStoreCookies: true + url: "{{ base_url }}/AccessManager/getAccessGroupMembershipDeleted" + _type: request + - _id: env_7bc4918f1ec5467393a2ab36a460e4d0 + color: null + created: 1569905755147 + data: + base_url: "{{ scheme }}://{{ host }}{{ base_path }}" + dataPropertyOrder: + "&": + - base_url + isPrivate: false + metaSortKey: 1569905755147 + modified: 1569905805832 + name: Base environment + parentId: wrk_43652e59afaf4825a8bbbf31e346f616 + _type: environment + - _id: jar_61bbb3fdc5ee80a49ee817b3e5341053a6022960 + cookies: + - creation: 2019-10-01T04:57:46.521Z + domain: 192.168.1.3 + hostOnly: true + httpOnly: true + id: "2614746010416731" + key: JSESSIONID + lastAccessed: 2019-10-10T08:32:49.572Z + path: / + secure: true + value: C5BB91A79F1DC2EFBB1C6D938CC0BC4A + created: 1569905764431 + modified: 1570696369572 + name: Default Jar + parentId: wrk_43652e59afaf4825a8bbbf31e346f616 + _type: cookie_jar + - _id: env_92b9543a27e847689c951d1b1eeff229 + color: "#cb5dc2" + created: 1569905755144 + data: + base_path: / + host: 192.168.1.3:8443 + scheme: https + dataPropertyOrder: null + isPrivate: false + metaSortKey: 1569905755144 + modified: 1569935791597 + name: colnod-test + parentId: env_7bc4918f1ec5467393a2ab36a460e4d0 + _type: environment diff --git a/Insomnia_2019-10-15.yaml b/Insomnia_2019-10-15.yaml new file mode 100644 index 0000000..e979a00 --- /dev/null +++ b/Insomnia_2019-10-15.yaml @@ -0,0 +1,738 @@ +_type: export +__export_format: 4 +__export_date: 2019-10-15T06:06:27.272Z +__export_source: insomnia.desktop.app:v7.0.1 +resources: + - _id: req_f0797b6411b144f0bf0a40d9300ee92f + authentication: + disabled: false + password: E7FEA07DBC82FB9BA34B2E453E2EFE89F0583E7187543507EF11E84726071FE428445372F2E46B455EB0C79747C51E362F403CE39473A2A8C2DFA0CE5C9826C0 + type: basic + username: spaceti + body: + mimeType: application/json + text: >- + { + "username": "spaceti", + "password": "E7FEA07DBC82FB9BA34B2E453E2EFE89F0583E7187543507EF11E84726071FE428445372F2E46B455EB0C79747C51E362F403CE39473A2A8C2DFA0CE5C9826C0" + } + created: 1569905755136 + description: "" + headers: + - id: pair_061d15d1294e412caca8300559541695 + name: content-type + value: application/json + isPrivate: false + metaSortKey: -1569905755136 + method: POST + modified: 1570796289148 + name: Login user + parameters: [] + parentId: fld_9ef1d96e0e6d40ef9094250114269496 + settingDisableRenderRequestBody: false + settingEncodeUrl: true + settingRebuildPath: true + settingSendCookies: true + settingStoreCookies: true + url: "{{ base_url }}/AaaManager/authSession" + _type: request + - _id: fld_9ef1d96e0e6d40ef9094250114269496 + created: 1569905755142 + description: Login information ( token ) + environment: {} + environmentPropertyOrder: null + metaSortKey: -1569905755142 + modified: 1569905755142 + name: login + parentId: wrk_43652e59afaf4825a8bbbf31e346f616 + _type: request_group + - _id: wrk_43652e59afaf4825a8bbbf31e346f616 + created: 1569905755149 + description: "Colnod system: [Product information](http://produkty.colsys.cz/colnod) + Jira issues: [Communicaiton with + Colnod](https://spaceti.atlassian.net/secure/RapidBoard.jspa?rapidView=78\ + &projectKey=INT&modal=detail&selectedIssue=INT-3563)" + modified: 1569905755149 + name: Colnod server 1.0.0 + parentId: null + _type: workspace + - _id: req_00f9f99d933c4638900385ffbbd4f8f7 + authentication: + disabled: false + token: "{% response 'body', 'req_f0797b6411b144f0bf0a40d9300ee92f', + 'b64::JC5pZA==::46b', 'no-history' %}" + type: bearer + body: + mimeType: application/json + text: "" + created: 1569905755134 + description: "" + headers: + - id: pair_a2a3c43a20f64efbb8a4752c7e983c8e + name: Content-Type + value: application/json + isPrivate: false + metaSortKey: -1569905755134 + method: POST + modified: 1570696568628 + name: Get Subjects Bearer + parameters: [] + parentId: fld_2fb4c2cef1f44cff83d6b00fe0886384 + settingDisableRenderRequestBody: false + settingEncodeUrl: true + settingRebuildPath: true + settingSendCookies: true + settingStoreCookies: true + url: "{{ base_url }}/SubjectManager/getSubjects" + _type: request + - _id: fld_2fb4c2cef1f44cff83d6b00fe0886384 + created: 1569905755140 + description: Operations about user + environment: {} + environmentPropertyOrder: null + metaSortKey: -1569905755140 + modified: 1570632691970 + name: Subjects + parentId: wrk_43652e59afaf4825a8bbbf31e346f616 + _type: request_group + - _id: req_1c6b6e7783ac4eec95802f655899b9ea + authentication: + disabled: false + password: "" + type: basic + username: "{% response 'body', 'req_f0797b6411b144f0bf0a40d9300ee92f', + 'b64::JC5pZA==::46b', 'never' %}" + body: + mimeType: application/json + text: "" + created: 1570444564217 + description: "" + headers: + - id: pair_a2a3c43a20f64efbb8a4752c7e983c8e + name: Content-Type + value: application/json + isPrivate: false + metaSortKey: -1569905755132.5 + method: POST + modified: 1570696575241 + name: Get Subjects + parameters: [] + parentId: fld_2fb4c2cef1f44cff83d6b00fe0886384 + settingDisableRenderRequestBody: false + settingEncodeUrl: true + settingRebuildPath: true + settingSendCookies: true + settingStoreCookies: true + url: "{{ base_url }}/SubjectManager/getSubjects" + _type: request + - _id: req_7380fab5ef444b1382692bb0474a996c + authentication: + disabled: false + password: "" + type: basic + username: "{% response 'body', 'req_f0797b6411b144f0bf0a40d9300ee92f', + 'b64::JC5pZA==::46b', 'never' %}" + body: + mimeType: application/json + text: |- + { + "timestamp": 1568646217767 + } + created: 1570632390552 + description: "" + headers: + - id: pair_a2a3c43a20f64efbb8a4752c7e983c8e + name: Content-Type + value: application/json + isPrivate: false + metaSortKey: -1569905755131.75 + method: POST + modified: 1570696583252 + name: Get Subjects Updated + parameters: [] + parentId: fld_2fb4c2cef1f44cff83d6b00fe0886384 + settingDisableRenderRequestBody: false + settingEncodeUrl: true + settingRebuildPath: true + settingSendCookies: true + settingStoreCookies: true + url: "{{ base_url }}/SubjectManager/getSubjectsUpdated" + _type: request + - _id: req_3ecc5702954a41e7b80a58130d38c6cf + authentication: + disabled: false + password: "" + type: basic + username: "{% response 'body', 'req_f0797b6411b144f0bf0a40d9300ee92f', + 'b64::JC5pZA==::46b', 'never' %}" + body: + mimeType: application/json + text: |- + { + "timestamp": 0 + } + created: 1570632515576 + description: "" + headers: + - id: pair_a2a3c43a20f64efbb8a4752c7e983c8e + name: Content-Type + value: application/json + isPrivate: false + metaSortKey: -1569905755131.375 + method: POST + modified: 1570696594665 + name: Get Subjects Deleted + parameters: [] + parentId: fld_2fb4c2cef1f44cff83d6b00fe0886384 + settingDisableRenderRequestBody: false + settingEncodeUrl: true + settingRebuildPath: true + settingSendCookies: true + settingStoreCookies: true + url: "{{ base_url }}/SubjectManager/getSubjectsDeleted" + _type: request + - _id: req_9e42a5023f9d4235a5de099cd7573d2b + authentication: + disabled: false + password: "" + type: basic + username: "{% response 'body', 'req_f0797b6411b144f0bf0a40d9300ee92f', + 'b64::JC5pZA==::46b', 'never' %}" + body: + mimeType: application/json + text: "" + created: 1569905755131 + description: "" + headers: + - disabled: false + id: pair_e888b6c679d74b0988f0dd2d77690383 + name: Content-Type + value: application/json + isPrivate: false + metaSortKey: -1569905755131 + method: POST + modified: 1571065188860 + name: Get Tokens + parameters: [] + parentId: fld_36a4be72380440a0ace83ad508a0458d + settingDisableRenderRequestBody: false + settingEncodeUrl: true + settingRebuildPath: true + settingSendCookies: true + settingStoreCookies: true + url: "{{ base_url }}TokenManager/getTokens/" + _type: request + - _id: fld_36a4be72380440a0ace83ad508a0458d + created: 1569905755138 + description: Working with tokens ( keys ) + environment: {} + environmentPropertyOrder: null + metaSortKey: -1569905755138 + modified: 1569934361048 + name: Token Manager + parentId: wrk_43652e59afaf4825a8bbbf31e346f616 + _type: request_group + - _id: req_3d5c333b21d9472f8d8628d2c45a5f0d + authentication: + disabled: false + password: "" + type: basic + username: "{% response 'body', 'req_f0797b6411b144f0bf0a40d9300ee92f', + 'b64::JC5pZA==::46b', 'never' %}" + body: + mimeType: application/json + text: |- + { + "timestamp": 1570109859681 + } + created: 1570696427073 + description: "" + headers: + - id: pair_ae0b3209dd2c4e2699ac3c6125082d88 + name: Content-Type + value: application/json + isPrivate: false + metaSortKey: -1569905755129.75 + method: POST + modified: 1570704882144 + name: Get Tokens Updated + parameters: [] + parentId: fld_36a4be72380440a0ace83ad508a0458d + settingDisableRenderRequestBody: false + settingEncodeUrl: true + settingRebuildPath: true + settingSendCookies: true + settingStoreCookies: true + url: "{{ base_url }}/TokenManager/getTokensUpdated" + _type: request + - _id: req_b6667f303a8a4d5a9d7cc4245cc598eb + authentication: + disabled: false + password: "" + type: basic + username: "{% response 'body', 'req_f0797b6411b144f0bf0a40d9300ee92f', + 'b64::JC5pZA==::46b', 'never' %}" + body: + mimeType: application/json + text: |- + { + "timestamp": 1571065593049 + } + created: 1570696638651 + description: "" + headers: + - id: pair_67395eea470e491ab6b14f6fc6ed26ae + name: Content-Type + value: application/json + isPrivate: false + metaSortKey: -1569905755129.375 + method: POST + modified: 1571065616213 + name: Get Tokens Deleted + parameters: [] + parentId: fld_36a4be72380440a0ace83ad508a0458d + settingDisableRenderRequestBody: false + settingEncodeUrl: true + settingRebuildPath: true + settingSendCookies: true + settingStoreCookies: true + url: "{{ base_url }}/TokenManager/getTokensDeleted" + _type: request + - _id: req_4f99d61a83c14da29882cc80c07ddf54 + authentication: + disabled: false + password: "" + type: basic + username: "{% response 'body', 'req_f0797b6411b144f0bf0a40d9300ee92f', + 'b64::JC5pZA==::46b', 'never' %}" + body: + mimeType: application/json + text: |- + { + "items": [ + { + "id": "582c982d-6fd7-4856-8548-7ce542791c7a", + "name": "test", + "description": "mobile", + "tokenType": "Token", + "tokenBits": 32, + "tokenData": "7B9D32", + "timeToLive": 255, + "authErrors": 255, + "flags": [ + "Enabled", + "NoValidity" + ], + "subjectId": "72b37f7e-5761-4e6c-8e87-20c0bed0d904" + }, + { + "id": "3ff23b41-3da3-4b33-82ce-d8e2d8c9a546", + "name": "test1", + "description": "mobile", + "tokenType": "Token", + "tokenBits": 32, + "tokenData": "7B9D12", + "timeToLive": 255, + "authErrors": 255, + "flags": [ + "Enabled", + "NoValidity" + ], + "subjectId": "72b37f7e-5761-4e6c-8e87-20c0bed0d904" + } + ] + } + created: 1569905755127 + description: "" + headers: + - id: pair_3808311d7abc4f37898beff39a7016eb + name: Content-Type + value: application/json + isPrivate: false + metaSortKey: -1569905755129 + method: POST + modified: 1571119569057 + name: Set Tokens + parameters: [] + parentId: fld_36a4be72380440a0ace83ad508a0458d + settingDisableRenderRequestBody: false + settingEncodeUrl: true + settingRebuildPath: true + settingSendCookies: true + settingStoreCookies: true + url: "{{ base_url }}/TokenManager/setTokens" + _type: request + - _id: req_c2e7f6beac484134bd1a48126d301904 + authentication: + disabled: false + password: "" + type: basic + username: "{% response 'body', 'req_f0797b6411b144f0bf0a40d9300ee92f', + 'b64::JC5pZA==::46b', 'never' %}" + body: + mimeType: application/json + text: |- + { + "items": [ + "582c982d-6fd7-4856-8548-7ce542791c7a", + "3ff23b41-3da3-4b33-82ce-d8e2d8c9a546" + ] + } + created: 1570699082101 + description: "" + headers: + - id: pair_a33dbf5e2b144c12a600d776a5c0084a + name: Content-Type + value: application/json + isPrivate: false + metaSortKey: -1569905755079 + method: POST + modified: 1571040029666 + name: Delete Tokens + parameters: [] + parentId: fld_36a4be72380440a0ace83ad508a0458d + settingDisableRenderRequestBody: false + settingEncodeUrl: true + settingRebuildPath: true + settingSendCookies: true + settingStoreCookies: true + url: "{{ base_url }}/TokenManager/deleteTokens" + _type: request + - _id: req_fd2e096f45554b46b31755564a0932bf + authentication: + disabled: false + password: "" + type: basic + username: "{% response 'body', 'req_f0797b6411b144f0bf0a40d9300ee92f', + 'b64::JC5pZA==::46b', 'never' %}" + body: {} + created: 1569934364782 + description: "" + headers: [] + isPrivate: false + metaSortKey: -1569905755130.5 + method: POST + modified: 1570445314172 + name: Get Token Subject + parameters: [] + parentId: fld_8d34eca167ef426c8aa998c98bbe74e2 + settingDisableRenderRequestBody: false + settingEncodeUrl: true + settingRebuildPath: true + settingSendCookies: true + settingStoreCookies: true + url: "{{ base_url }}/OpenManager/getTokenSubject" + _type: request + - _id: fld_8d34eca167ef426c8aa998c98bbe74e2 + created: 1569934364777 + description: Working with tokens ( keys ) + environment: {} + environmentPropertyOrder: null + metaSortKey: -1569905755088 + modified: 1570632707161 + name: Open Manager ( wont use ) + parentId: wrk_43652e59afaf4825a8bbbf31e346f616 + _type: request_group + - _id: req_7007bb1f6a0243a7b0568741f691f6d1 + authentication: + disabled: false + password: E7FEA07DBC82FB9BA34B2E453E2EFE89F0583E7187543507EF11E84726071FE428445372F2E46B455EB0C79747C51E362F403CE39473A2A8C2DFA0CE5C9826C0 + type: basic + username: spaceti + body: + mimeType: application/json + text: >- + { + "username": "spaceti", + "password": "E7FEA07DBC82FB9BA34B2E453E2EFE89F0583E7187543507EF11E84726071FE428445372F2E46B455EB0C79747C51E362F403CE39473A2A8C2DFA0CE5C9826C0" + } + created: 1570025458784 + description: "" + headers: + - id: pair_74b4df5d54d1446a90e6a668d373fb79 + name: Content-Type + value: application/json + isPrivate: false + metaSortKey: -1569905755129.75 + method: POST + modified: 1570030518745 + name: Get Token Subject Full authorization + parameters: [] + parentId: fld_8d34eca167ef426c8aa998c98bbe74e2 + settingDisableRenderRequestBody: false + settingEncodeUrl: true + settingRebuildPath: true + settingSendCookies: true + settingStoreCookies: true + url: "{{ base_url }}/OpenManager/getTokenSubject" + _type: request + - _id: req_9e5b797601a740488876ea20cc9fd183 + authentication: + disabled: false + password: E7FEA07DBC82FB9BA34B2E453E2EFE89F0583E7187543507EF11E84726071FE428445372F2E46B455EB0C79747C51E362F403CE39473A2A8C2DFA0CE5C9826C0 + type: basic + username: spaceti + body: + mimeType: application/json + text: >- + { + "username": "spaceti", + "password": "E7FEA07DBC82FB9BA34B2E453E2EFE89F0583E7187543507EF11E84726071FE428445372F2E46B455EB0C79747C51E362F403CE39473A2A8C2DFA0CE5C9826C0" + } + created: 1570110543873 + description: "" + headers: + - id: pair_74b4df5d54d1446a90e6a668d373fb79 + name: Content-Type + value: application/json + isPrivate: false + metaSortKey: -1569905755129.375 + method: POST + modified: 1570429074494 + name: Get Token Subject test with nc + parameters: [] + parentId: fld_8d34eca167ef426c8aa998c98bbe74e2 + settingDisableRenderRequestBody: false + settingEncodeUrl: true + settingRebuildPath: true + settingSendCookies: true + settingStoreCookies: true + url: "{{ base_url }}/OpenManager/getTokenSubject" + _type: request + - _id: req_9fe84e48068847aba97ff920376dc768 + authentication: + disabled: false + password: "" + type: basic + username: "{% response 'body', 'req_f0797b6411b144f0bf0a40d9300ee92f', + 'b64::JC5pZA==::46b', 'never' %}" + body: {} + created: 1570695910222 + description: "" + headers: [] + isPrivate: false + metaSortKey: -1570695910222 + method: POST + modified: 1570696316380 + name: Get Access Groups + parameters: [] + parentId: fld_2cd1b870d3304ee2a49c4a09c24e2eb0 + settingDisableRenderRequestBody: false + settingEncodeUrl: true + settingRebuildPath: true + settingSendCookies: true + settingStoreCookies: true + url: "{{ base_url }}/AccessManager/getAccessGroups" + _type: request + - _id: fld_2cd1b870d3304ee2a49c4a09c24e2eb0 + created: 1570695902620 + description: "" + environment: {} + environmentPropertyOrder: null + metaSortKey: -1569905755029.375 + modified: 1570696079131 + name: AccessManager + parentId: wrk_43652e59afaf4825a8bbbf31e346f616 + _type: request_group + - _id: req_c5666cec2d3d4a81bc653d57b0dbb09a + authentication: + disabled: false + password: "" + type: basic + username: "{% response 'body', 'req_f0797b6411b144f0bf0a40d9300ee92f', + 'b64::JC5pZA==::46b', 'never' %}" + body: + mimeType: application/json + text: |- + { + "timestamp": 1568646217767 + } + created: 1570696789456 + description: "" + headers: + - id: pair_5341cecb8a0d47e5ba7e1c0c52c12b47 + name: Content-Type + value: application/json + isPrivate: false + metaSortKey: -1570695910172 + method: POST + modified: 1570696957577 + name: Get Access Groups Updated + parameters: [] + parentId: fld_2cd1b870d3304ee2a49c4a09c24e2eb0 + settingDisableRenderRequestBody: false + settingEncodeUrl: true + settingRebuildPath: true + settingSendCookies: true + settingStoreCookies: true + url: "{{ base_url }}/AccessManager/getAccessGroupsUpdated" + _type: request + - _id: req_126a165eaa60410fae62c3baa11036ea + authentication: + disabled: false + password: "" + type: basic + username: "{% response 'body', 'req_f0797b6411b144f0bf0a40d9300ee92f', + 'b64::JC5pZA==::46b', 'never' %}" + body: + mimeType: application/json + text: |- + { + "timestamp": 0 + } + created: 1570696820132 + description: "" + headers: + - id: pair_73e13582518d46c5b1e67ca9783e319c + name: Content-Type + value: application/json + isPrivate: false + metaSortKey: -1570695910122 + method: POST + modified: 1570697027201 + name: Get Access Groups Deleted + parameters: [] + parentId: fld_2cd1b870d3304ee2a49c4a09c24e2eb0 + settingDisableRenderRequestBody: false + settingEncodeUrl: true + settingRebuildPath: true + settingSendCookies: true + settingStoreCookies: true + url: "{{ base_url }}/AccessManager/getAccessGroupsDeleted" + _type: request + - _id: req_6d950dec8f414bf195261428e394b468 + authentication: + disabled: false + password: "" + type: basic + username: "{% response 'body', 'req_f0797b6411b144f0bf0a40d9300ee92f', + 'b64::JC5pZA==::46b', 'never' %}" + body: {} + created: 1570696857201 + description: "" + headers: [] + isPrivate: false + metaSortKey: -1570695910072 + method: POST + modified: 1570698188682 + name: Get Access Group Membership + parameters: [] + parentId: fld_2cd1b870d3304ee2a49c4a09c24e2eb0 + settingDisableRenderRequestBody: false + settingEncodeUrl: true + settingRebuildPath: true + settingSendCookies: true + settingStoreCookies: true + url: "{{ base_url }}/AccessManager/getAccessGroupMembership" + _type: request + - _id: req_1af11b4de244498c9940fd90862bf8a1 + authentication: + disabled: false + password: "" + type: basic + username: "{% response 'body', 'req_f0797b6411b144f0bf0a40d9300ee92f', + 'b64::JC5pZA==::46b', 'never' %}" + body: + mimeType: application/json + text: |- + { + "timestamp": 1568646217767 + } + created: 1570696880249 + description: "" + headers: + - id: pair_cae12a041df14bd995719d6162b48bab + name: Content-Type + value: application/json + isPrivate: false + metaSortKey: -1570695910022 + method: POST + modified: 1570697063733 + name: Get Access Group Membership Updated + parameters: [] + parentId: fld_2cd1b870d3304ee2a49c4a09c24e2eb0 + settingDisableRenderRequestBody: false + settingEncodeUrl: true + settingRebuildPath: true + settingSendCookies: true + settingStoreCookies: true + url: "{{ base_url }}/AccessManager/getAccessGroupMembershipUpdated" + _type: request + - _id: req_0ae1522c390943bbaba12ca4fb24f27f + authentication: + disabled: false + password: "" + type: basic + username: "{% response 'body', 'req_f0797b6411b144f0bf0a40d9300ee92f', + 'b64::JC5pZA==::46b', 'never' %}" + body: + mimeType: application/json + text: |- + { + "timestamp": 0 + } + created: 1570696897934 + description: "" + headers: + - id: pair_1bbc15031afb4303836d2d62a5769191 + name: Content-Type + value: application/json + isPrivate: false + metaSortKey: -1570695909972 + method: POST + modified: 1570698604781 + name: Get Access Group Membership Deleted + parameters: [] + parentId: fld_2cd1b870d3304ee2a49c4a09c24e2eb0 + settingDisableRenderRequestBody: false + settingEncodeUrl: true + settingRebuildPath: true + settingSendCookies: true + settingStoreCookies: true + url: "{{ base_url }}/AccessManager/getAccessGroupMembershipDeleted" + _type: request + - _id: env_7bc4918f1ec5467393a2ab36a460e4d0 + color: null + created: 1569905755147 + data: + base_url: "{{ scheme }}://{{ host }}{{ base_path }}" + dataPropertyOrder: + "&": + - base_url + isPrivate: false + metaSortKey: 1569905755147 + modified: 1569905805832 + name: Base environment + parentId: wrk_43652e59afaf4825a8bbbf31e346f616 + _type: environment + - _id: jar_61bbb3fdc5ee80a49ee817b3e5341053a6022960 + cookies: + - creation: 2019-10-01T04:57:46.521Z + domain: 192.168.1.3 + hostOnly: true + httpOnly: true + id: "40085635127327857" + key: JSESSIONID + lastAccessed: 2019-10-15T06:03:40.821Z + path: / + secure: true + value: 3914922FC8B0D8449FA0FFD1654D9815 + created: 1569905764431 + modified: 1571119420822 + name: Default Jar + parentId: wrk_43652e59afaf4825a8bbbf31e346f616 + _type: cookie_jar + - _id: env_92b9543a27e847689c951d1b1eeff229 + color: "#cb5dc2" + created: 1569905755144 + data: + base_path: / + host: 192.168.1.3:8443 + scheme: https + dataPropertyOrder: null + isPrivate: false + metaSortKey: 1569905755144 + modified: 1569935791597 + name: colnod-test + parentId: env_7bc4918f1ec5467393a2ab36a460e4d0 + _type: environment diff --git a/README.md b/README.md index b83a56e..d8f034d 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,22 @@ Acces Management System of Colsys: [Product info](http://produkty.colsys.cz/colnod/) +## Requirements + +- QPSQL driver must be installed (PostgreSQL) +- running on Qt 5.9 + +### Qt 5 + ``` + sudo apt-get install -y build-essential + sudo apt-get install -y qt5-default + ``` +### PostgreSQL ( devel libs ) + ``` + sudo apt-get install -y libpq-dev + sudo apt install libqt5sql5-psql # psql driver for Qt + ``` + ## Endpoints - POST `/AaaManager/authSession` diff --git a/src/app/main.cpp b/src/app/main.cpp index 7759942..70c5e9e 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -1,6 +1,5 @@ #include -#include "data.h" #include "datamanager.h" #include "colnodapi.h" @@ -12,7 +11,7 @@ int main(int argc, char *argv[]) api->downloadData(); // this will start downloading data QObject::connect(api, &ColnodAPI::dataDownloaded, [=](){ qDebug() << "now I have all data"; - api->syncData(); + api->syncDataToColnod(); QCoreApplication::quit(); }); diff --git a/src/colnod/colnod.pri b/src/colnod/colnod.pri index 2b038d4..51c711d 100644 --- a/src/colnod/colnod.pri +++ b/src/colnod/colnod.pri @@ -3,7 +3,6 @@ INCLUDEPATH += $$PWD message($$PWD) SOURCES += \ $$PWD/colnodapi.cpp \ - $$PWD/data.cpp \ $$PWD/databasemanager.cpp \ $$PWD/datamanager.cpp \ $$PWD/entity.cpp \ @@ -14,7 +13,6 @@ SOURCES += \ HEADERS += \ $$PWD/colnodapi.h \ - $$PWD/data.h \ $$PWD/databasemanager.h \ $$PWD/datamanager.h \ $$PWD/entity.h \ diff --git a/src/colnod/colnodapi.cpp b/src/colnod/colnodapi.cpp index 7452c39..7584be2 100644 --- a/src/colnod/colnodapi.cpp +++ b/src/colnod/colnodapi.cpp @@ -3,26 +3,25 @@ ColnodAPI::ColnodAPI() { reqMan = new RequestManager(); - //data = new Data(); dataMan = new DataManager(); - connect(this, &ColnodAPI::partReady, this, &ColnodAPI::checkPartOfData); - connect(this, &ColnodAPI::partReady, this, &ColnodAPI::areDataReady); - } +} // PUBLIC FUNCTIONS void ColnodAPI::downloadData() { Response* resp0 = reqMan->getSubjects(); - connect(resp0, &Response::finished, [=](){ - dataMan->localSaveSubjects(resp0->reply->readAll()); - emit partReady(); + connect(resp0, &Response::ready, [=](){ + dataMan->localSaveSubjects(resp0->getJson()); + areDataReady(); + resp0->deleteLater(); }); Response* resp1 = reqMan->getTokens(); - connect(resp1, &Response::finished, [=](){ - dataMan->localSaveTokens(resp1->reply->readAll()); - emit partReady(); + connect(resp1, &Response::ready, [=](){ + dataMan->localSaveTokens(resp1->getJson()); + areDataReady(); + resp1->deleteLater(); }); /* @@ -33,22 +32,144 @@ void ColnodAPI::downloadData() */ } -void ColnodAPI::syncData() +void ColnodAPI::downloadChangedDataFromColnod() { - dataMan->pushDataToDB(); + downloadUpdatedData(); + downloadDeletedData(); +} + +void ColnodAPI::downloadUpdatedData() +{ + uint64_t lastUpdate = dataMan->getLastUpdate(); + qDebug() << lastUpdate; + Response* resp0 = reqMan->getSubjectsUpdated(lastUpdate); + connect(resp0, &Response::ready, [=](){ + dataMan->localSaveSubjects(resp0->getJson()); + areChangedDataReady(); + resp0->deleteLater(); + }); + + Response* resp1 = reqMan->getTokensUpdated(lastUpdate); + connect(resp1, &Response::ready, [=](){ + dataMan->localSaveTokens(resp1->getJson()); + areChangedDataReady(); + resp1->deleteLater(); + }); +} + +void ColnodAPI::downloadDeletedData() +{ + uint64_t lastUpdate = dataMan->getLastUpdate(); + Response* resp2 = reqMan->getSubjectsDeleted(lastUpdate); + connect(resp2, &Response::ready, [=](){ + dataMan->localSaveSubjectsToDelete(resp2->getJson()); + areChangedDataReady(); + resp2->deleteLater(); + }); + + Response* resp3 = reqMan->getTokensDeleted(lastUpdate); + connect(resp3, &Response::ready, [=](){ + dataMan->localSaveTokensToDelete(resp3->getJson()); + areChangedDataReady(); + resp3->deleteLater(); + }); + +} + +void ColnodAPI::syncDataFromColnod() +{ + dataMan->pushTokensToDB(); + dataMan->pushSubjectsToDB(); + dataMan->updateLastSync(); + dataMan->clear(); +} + +void ColnodAPI::syncChangedDataFromColnod() +{ + syncUpdatedDataFromColnod(); + syncDeletedDataFromColnod(); + dataMan->updateLastSync(); + dataMan->clear(); +} + +void ColnodAPI::syncUpdatedDataFromColnod() +{ + dataMan->pushSubjectsToDB(); + dataMan->pushTokensToDB(); +} + + +void ColnodAPI::syncDeletedDataFromColnod() +{ + dataMan->deleteSubjectsFromDB(); + dataMan->deleteTokensFromDB(); +} + + + + +void ColnodAPI::syncDataToColnod() +{ + // TODO +} + + +void ColnodAPI::syncChangedDataToColnod() +{ + // TODO + dataMan->loadTokensToAdd(); + dataMan->loadTokensToDelete(); + processDataToColnod(); + dataMan->clear(); + +} + +void ColnodAPI::processDataToColnod() +{ + QList* tokensToDelete = dataMan->getTokensToDelete(); + if ((*tokensToDelete)[0] != "empty") + { + Response* resp0 = reqMan->deleteTokens(dataMan->getTokensToDelete()); + connect(resp0, &Response::ready, [=](){ + areProcessDataReady(); + resp0->deleteLater(); + }); + } + QList>* tokens = dataMan->getTokens(); + if ((*tokens)[0]->getName() != "empty") + { + Response* resp1 = reqMan->setTokens(dataMan->getTokens()); + connect(resp1, &Response::ready, [=](){ + areProcessDataReady(); + resp1->deleteLater(); + }); + } + connect(this, &ColnodAPI::dataLoaded, this, &ColnodAPI::syncChangedDataFromColnod); +} + +void ColnodAPI::prepareDatabase() +{ + dataMan->emptyDatabase(); } // PRIVATE FUNCTIONS void ColnodAPI::areDataReady() { - if (index >= numOfMembers) - { + if (dataMan->haveData()) emit dataDownloaded(); +} + +void ColnodAPI::areChangedDataReady() +{ + if (dataMan->haveChangedData()) + emit dataDownloaded(); +} + + +void ColnodAPI::areProcessDataReady() +{ + if (dataMan->haveProcessData()) + { + emit dataLoaded(); } } - -void ColnodAPI::checkPartOfData() -{ - index++; -} - diff --git a/src/colnod/colnodapi.h b/src/colnod/colnodapi.h index e19d760..31bbb2f 100644 --- a/src/colnod/colnodapi.h +++ b/src/colnod/colnodapi.h @@ -2,7 +2,6 @@ #define COLNODAPI_H #include "requestmanager.h" -#include "data.h" #include "datamanager.h" @@ -16,18 +15,42 @@ public: ColnodAPI(); void downloadData(); - void syncData(); + void syncDataFromColnod(); + void syncDataToColnod(); + + + + void syncChangedDataFromColnod(); + void syncChangedDataToColnod(); + + + + + void prepareDatabase(); + +public slots: + void downloadChangedDataFromColnod(); + signals: void dataDownloaded(); - void partReady(); + void dataLoaded(); private slots: - void areDataReady(); - void checkPartOfData(); private: + void downloadUpdatedData(); + void downloadDeletedData(); + void syncUpdatedDataFromColnod(); + void syncDeletedDataFromColnod(); + void areDataReady(); + void areChangedDataReady(); + void areProcessDataReady(); + void processDataToColnod(); + + + RequestManager* reqMan = nullptr; // Data* data = nullptr; DataManager* dataMan = nullptr; diff --git a/src/colnod/data.cpp b/src/colnod/data.cpp deleted file mode 100644 index 0ee6f2c..0000000 --- a/src/colnod/data.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "data.h" - -Data::Data() -{ - -} - diff --git a/src/colnod/data.h b/src/colnod/data.h deleted file mode 100644 index fc25e4e..0000000 --- a/src/colnod/data.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef DATA_H -#define DATA_H -#include - -#include "subject.h" -#include "token.h" -#include -#include - -class Data : public QObject -{ - Q_OBJECT - -public: - Data(); - - - -private: - - -}; - -#endif // DATA_H diff --git a/src/colnod/databasemanager.cpp b/src/colnod/databasemanager.cpp index 85c2654..f45ca8a 100644 --- a/src/colnod/databasemanager.cpp +++ b/src/colnod/databasemanager.cpp @@ -8,6 +8,9 @@ DatabaseManager::DatabaseManager(QString host, QString dbName, QString user, QSt db.setDatabaseName(dbName); db.setHostName(host); db.setUserName(user); + // home-office stuff + //db.setPort(80); + // db.setPassword(password); opened = db.open(); if (!opened) @@ -19,21 +22,84 @@ DatabaseManager::DatabaseManager(QString host, QString dbName, QString user, QSt void DatabaseManager::saveSubject(Subject* subject, QString table) { - query.prepare("INSERT INTO subject (id, name) VALUES (:id, :name)"); - query.bindValue(":table", table); - query.bindValue(":id",subject->getId().toString()); - qDebug() << subject->getId().toString() << subject->getName(); - query.bindValue(":name", subject->getName()); - query.exec(); + QString id = subject->idToStringWithoutBraces(); + if (checkIfExists(id, table)) + { + query.prepare(QString("UPDATE %1 SET name = :name, last_update = :last_update " + "WHERE id = :id)").arg(table)); + query.bindValue(":id", id); + query.bindValue(":name", subject->getName()); + query.bindValue(":last_update", QDateTime::fromMSecsSinceEpoch(subject->getLastUpdate()).toString("yyyy-MM-dd hh:mm:ss.zzz")); + query.exec(); + } + else + { + query.prepare(QString("INSERT INTO %1 (id, name, last_update) " + "VALUES (:id, :name, :last_update)").arg(table)); + query.bindValue(":id", id); + query.bindValue(":name", subject->getName()); + query.bindValue(":last_update", QDateTime::fromMSecsSinceEpoch(subject->getLastUpdate()).toString("yyyy-MM-dd hh:mm:ss.zzz")); + query.exec(); + } } void DatabaseManager::saveToken(Token* token, QString table) { - query.prepare("INSERT INTO :table (id, name) VALUES (:id, :data, :subject_id)"); - query.bindValue(":table", table); - query.bindValue(":id",token->getId()); - query.bindValue(":data", token->getTokenData()); - query.bindValue(":subject_id", token->getSubjectId()); + QString id = token->idToStringWithoutBraces(); + if (checkIfExists(id, table)) + { + query.prepare(QString("UPDATE %1 SET last_update = :last_update, token_data = :data, subject_id = :subject_id) " + "WHERE id = :id").arg(table)); + query.bindValue(":id", id); + query.bindValue(":last_update", QDateTime::fromMSecsSinceEpoch(token->getLastUpdate()).toString("yyyy-MM-dd hh:mm:ss.zzz")); + query.bindValue(":data", token->getTokenData()); + query.bindValue(":subject_id", token->subjectIdToStringWithoutBraces()); + query.exec(); + } + else + { + query.prepare(QString("INSERT INTO %1 (id, last_update, token_data, subject_id) " + "VALUES (:id, :last_update, :data, :subject_id)").arg(table)); + query.bindValue(":id", id); + query.bindValue(":last_update", QDateTime::fromMSecsSinceEpoch(token->getLastUpdate()).toString("yyyy-MM-dd hh:mm:ss.zzz")); + query.bindValue(":data", token->getTokenData()); + query.bindValue(":subject_id", token->subjectIdToStringWithoutBraces()); + query.exec(); + } +} + +void DatabaseManager::saveSubjectAttribute(Subject *subject, QString table) +{ + auto attributes = subject->getAtr(); + for (auto attribute : attributes){ + QString id = subject->idToStringWithoutBraces() + " " + attribute.first; + if (checkIfExists(id, table)) + { + query.prepare(QString("UPDATE %1 SET id = :id, attribute_key = :key, attribute_value = :value, subject_id = :subject_id) " + "WHERE id = :id").arg(table)); + query.bindValue(":id", id); + query.bindValue(":key", attribute.first); + query.bindValue(":value", attribute.second); + query.bindValue(":subject_id", subject->idToStringWithoutBraces()); + query.exec(); + } + else + { + query.prepare(QString("INSERT INTO %1 (id, attribute_key, attribute_value, subject_id)" + "VALUES (:id, :key, :value, :subject_id)").arg(table)); + query.bindValue(":id", id); + query.bindValue(":key", attribute.first); + query.bindValue(":value", attribute.second); + query.bindValue(":subject_id", subject->idToStringWithoutBraces()); + query.exec(); + } + } +} + +void DatabaseManager::deleteItem(QString id, QString table) +{ + query.prepare(QString("DELETE FROM %1 WHERE id = :id").arg(table)); + query.bindValue(":id", id); query.exec(); } @@ -43,23 +109,104 @@ QString DatabaseManager::getTestMessage(int id) query.bindValue(":id", id); query.exec(); query.next(); - //qDebug() << query.value(0); return query.value(0).toString(); } -void DatabaseManager::createTestRecord(QString msg) +int DatabaseManager::createTestRecord(QString msg) { query.exec("SELECT MAX(id) FROM test"); query.next(); int id = query.value(0).toInt() + 1; - //QString statement = QString("INSERT INTO test (id, message) VALUES (%1, '%2')").arg(id).arg(msg); - //query.exec(statement); - query.prepare("INSERT INTO test (id, message) VALUES (:id, :msg)"); query.bindValue(":id", id); query.bindValue(":msg", msg); query.exec(); - query.next(); qDebug() << "U inserted new row, id: " << id << "msg: " << getTestMessage(id); - + return id; +} + + +bool DatabaseManager::checkIfExists(QString id, QString table) +{ + query.prepare(QString("SELECT EXISTS(SELECT 1 FROM %1 WHERE id = :id)").arg(table)); + query.bindValue(":id", id); + query.exec(); + query.first(); + return query.value(0).toBool(); +} + +void DatabaseManager::dropTables() +{ + query.exec("DROP TABLE IF EXISTS colnod_token, colnod_subject, colnod_subject_attribute"); +} + +void DatabaseManager::createTables() +{ + query.exec("CREATE TABLE colnod_subject (" + "id CHAR(36) primary key," + "name VARCHAR(255)," + "last_update timestamp)"); + + query.exec("CREATE TABLE colnod_token (" + "id CHAR(36) primary key," + "token_data VARCHAR(255)," + "subject_id CHAR(36)," + "last_update timestamp)"); + query.exec("CREATE TABLE colnod_subject_attribute (" + "id VARCHAR(255) primary key," + "attribute_key VARCHAR(255)," + "attribute_value VARCHAR(255)," + "subject_id CHAR(36))"); + query.exec("CREATE TABLE users (" + "id VARCHAR(255) primary key," + "email VARCHAR(255)," + "token_data VARCHAR(255)," + "last_update timestamp)"); +} + +uint64_t DatabaseManager::getLastUpdate() +{ + query.exec("SELECT EXTRACT(EPOCH FROM (SELECT MIN(last_sync) FROM changes))*1000"); //MAX for using, MIN for testing + query.next(); + return query.value(0).toULongLong(); +} + +void DatabaseManager::makeTestingLast_sync() +{ + query.prepare("INSERT INTO last_changes (last_sync) " + "VALUES (:time)"); + query.bindValue(":time", QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz")); + query.exec(); +} + +void DatabaseManager::updateLastSync() +{ + query.prepare("INSERT INTO changes (last_sync) " + "VALUES (:time)"); + query.bindValue(":time", QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz")); + query.exec(); +} + + +QSqlQuery* DatabaseManager::getTokensToAdd() +{ + QSqlQuery* qry = new QSqlQuery; + qry->exec("SELECT name, token_data FROM changes WHERE status = 'toBeAdd'"); + return qry; +} + +QSqlQuery* DatabaseManager::getTokensToDelete() +{ + QSqlQuery* qry = new QSqlQuery; + qry->exec("SELECT id FROM changes WHERE status = 'toBeDeleted'"); + return qry; +} + +QUuid DatabaseManager::getId(QString name) +{ + query.prepare("SELECT id FROM colnod_subject WHERE name = :name"); + query.bindValue(":name", name); + query.exec(); + query.next(); + return query.value(0).toUuid(); } diff --git a/src/colnod/databasemanager.h b/src/colnod/databasemanager.h index 42a2eae..0425ae5 100644 --- a/src/colnod/databasemanager.h +++ b/src/colnod/databasemanager.h @@ -9,6 +9,7 @@ #include #include "subject.h" #include "token.h" +#include class DatabaseManager : public QObject @@ -19,12 +20,31 @@ public: void saveSubject(Subject* subject, QString table); void saveToken(Token* token, QString table); + void saveSubjectAttribute(Subject* subject, QString table); + void deleteItem(QString id, QString table); QString getTestMessage(int id); - void createTestRecord(QString msg); + int createTestRecord(QString msg); + // + void makeTestingLast_sync(); + // + void dropTables(); + void createTables(); bool getOpened() {return opened;} + uint64_t getLastUpdate(); + void updateLastSync(); + + QSqlQuery* getTokensToAdd(); + QSqlQuery* getTokensToDelete(); + + QUuid getId(QString name); + + +private: + bool checkIfExists(QString id, QString table); + private: QSqlDatabase db; diff --git a/src/colnod/datamanager.cpp b/src/colnod/datamanager.cpp index 857b765..f4d195d 100644 --- a/src/colnod/datamanager.cpp +++ b/src/colnod/datamanager.cpp @@ -3,16 +3,26 @@ DataManager::DataManager() { db = new DatabaseManager("192.168.1.94", "deloitte", "postgres", "34rjkciea12"); + //db = new DatabaseManager("localhost", "deloitte", "postgres", "34rjkciea12"); } void DataManager::localSaveSubjects(QString response) { QJsonDocument doc = QJsonDocument::fromJson(response.toUtf8()); QJsonArray items = doc.object()["items"].toArray(); - for (QJsonValueRef item : items) + if (items.size() > 0) { - auto subject = new Subject(); - subject->fromJSON(item.toObject()); + for (QJsonValueRef item : items) + { + auto subject = new Subject(); + subject->fromJSON(item.toObject()); + subjects.append(subject); + } + } + else + { + Subject* subject = new Subject; + subject->setName("empty"); subjects.append(subject); } } @@ -21,24 +31,195 @@ void DataManager::localSaveTokens(QString response) { QJsonDocument doc = QJsonDocument::fromJson(response.toUtf8()); QJsonArray items = doc.object()["items"].toArray(); - for (QJsonValueRef item : items) + if (items.size() > 0) { - auto token = new Token(); - token->fromJSON(item.toObject()); + for (QJsonValueRef item : items) + { + auto token = new Token(); + token->fromJSON(item.toObject()); + tokens.append(token); + } + } + else + { + Token* token = new Token; + token->setName("empty"); tokens.append(token); - } } -void DataManager::pushDataToDB() +void DataManager::localSaveSubjectsToDelete(QString json) { + QJsonDocument doc = QJsonDocument::fromJson(json.toUtf8()); + QJsonArray items = doc.object()["items"].toArray(); + if (items.size() > 0) + { + for (QJsonValueRef item : items) + { + subjectsToDelete.append(item.toString()); + } + } + else + { + subjectsToDelete.append("empty"); + } +} + +void DataManager::localSaveTokensToDelete(QString json) +{ + QJsonDocument doc = QJsonDocument::fromJson(json.toUtf8()); + QJsonArray items = doc.object()["items"].toArray(); + if (items.size() > 0) + { + for (QJsonValueRef item : items) + { + tokensToDelete.append(item.toString()); + } + } + else + { + tokensToDelete.append("empty"); + } +} + +void DataManager::pushSubjectsToDB() +{ + if (subjects.size() == 1 && subjects[0]->getName() == "empty") + { + qDebug() << "All subjects are up to date"; + return; + } + //QSqlDatabase::database().transaction(); + qDebug() << "Subjects in progress..."; for (auto subject : subjects) { - db->saveSubject(subject, "subject"); + db->saveSubject(subject, "colnod_subject"); + db->saveSubjectAttribute(subject, "colnod_subject_attribute"); } + //QSqlDatabase::database().commit(); + qDebug() << subjects.size() << " subjects has been updated"; +} + +void DataManager::pushTokensToDB() +{ + if (tokens.size() == 1 && tokens[0]->getName() == "empty") + { + qDebug() << "All tokens are up to date"; + return; + } + //QSqlDatabase::database().transaction(); + qDebug() << "Tokens in progress..."; for (auto token : tokens) { - db->saveToken(token, "Subjects"); + db->saveToken(token, "colnod_token"); } + //QSqlDatabase::database().commit(); + qDebug() << tokens.size() << " tokens has been updated"; } + +void DataManager::deleteSubjectsFromDB() +{ + if (subjectsToDelete.size() == 1 && subjectsToDelete[0] == "empty") + { + qDebug() << "No subjects to be deleted"; + return; + } + qDebug() << "Deleted subjects in progress..."; + //QSqlDatabase::database().transaction(); + for (auto subjectId : subjectsToDelete) + { + db->deleteItem(subjectId, "colnod_subject"); + } + //QSqlDatabase::database().commit(); + qDebug() << subjectsToDelete.size() << "subject has beed deleted"; +} + +void DataManager::deleteTokensFromDB() +{ + if (tokensToDelete.size() == 1 && tokensToDelete[0] == "empty") + { + qDebug() << "No tokens to be deleted"; + return; + } + // QSqlDatabase::database().transaction(); + qDebug() << "Deleted tokens in progress..."; + for (auto tokenId : tokensToDelete) + { + db->deleteItem(tokenId, "colnod_token"); + } + //QSqlDatabase::database().commit(); + qDebug() << tokensToDelete.size() << "tokens has beed deleted"; +} + +bool DataManager::haveData() +{ + if ( !subjects.isEmpty() && !tokens.isEmpty() ) + return true; + return false; +} + +bool DataManager::haveChangedData() +{ + if ( !subjects.isEmpty() && !tokens.isEmpty() && !subjectsToDelete.isEmpty() && !tokensToDelete.isEmpty() ) + return true; + return false; +} + +bool DataManager::haveProcessData() +{ + if ( !tokens.isEmpty() && !tokensToDelete.isEmpty()) + return true; + return false; +} + +uint64_t DataManager::getLastUpdate() +{ + return db->getLastUpdate(); +} + +void DataManager::emptyDatabase() +{ + db->dropTables(); + db->createTables(); +} + +void DataManager::clear() +{ + subjects.clear(); + subjectsToDelete.clear(); + tokens.clear(); + tokensToDelete.clear(); +} + +void DataManager::updateLastSync() +{ + db->updateLastSync(); +} + +void DataManager::loadTokensToAdd() +{ + QSqlQuery* query = db->getTokensToAdd(); + while (query->next()) + { + Token* token = new Token(query->value(0).toString(), query->value(1).toString()); + token->setSubjectId(db->getId(token->getName())); + tokens.append(token); + } + if (tokens.isEmpty()) + tokens.append(new Token("empty")); +} + +void DataManager::loadTokensToDelete() +{ + QSqlQuery* query = db->getTokensToDelete(); + while (query->next()) + { + tokensToDelete.append(query->value(0).toString()); + } + if (tokensToDelete.isEmpty()) + tokensToDelete.append("empty"); +} + + + diff --git a/src/colnod/datamanager.h b/src/colnod/datamanager.h index af741e6..1f51db0 100644 --- a/src/colnod/datamanager.h +++ b/src/colnod/datamanager.h @@ -7,7 +7,6 @@ #include "databasemanager.h" #include #include -#include "data.h" class DataManager : public QObject @@ -20,16 +19,37 @@ public: void localSaveSubjects(QString jsonResponse); void localSaveTokens(QString jsonResponse); - void pushDataToDB(); + void localSaveSubjectsToDelete(QString jsonResponse); + void localSaveTokensToDelete(QString jsonResponse); + + void pushSubjectsToDB(); + void pushTokensToDB(); + void deleteSubjectsFromDB(); + void deleteTokensFromDB(); + + void updateLastSync(); + uint64_t getLastUpdate(); + + bool haveData(); + bool haveChangedData(); + bool haveProcessData(); + + void emptyDatabase(); + void clear(); + + void loadTokensToAdd(); + void loadTokensToDelete(); + + QList>* getTokens() {return &tokens;} + QList* getTokensToDelete() {return &tokensToDelete;} private: DatabaseManager *db = nullptr; QList> subjects; QList> tokens; - //Data *dataToProcess = nullptr; - - + QList subjectsToDelete; + QList tokensToDelete; }; #endif // DATAMANAGER_H diff --git a/src/colnod/entity.cpp b/src/colnod/entity.cpp index 96eb597..da6f98f 100644 --- a/src/colnod/entity.cpp +++ b/src/colnod/entity.cpp @@ -33,6 +33,11 @@ void Entity::setLastUpdate(uint64_t lastUpdate) { this->lastUpdate = lastUpdate; } +QString Entity::idToStringWithoutBraces() +{ + return id.toString().mid(1,36); +} + void Entity::fromJSON(const QJsonObject &json) { id = json.value("id").toString(); name = json.value("name").toString(); diff --git a/src/colnod/entity.h b/src/colnod/entity.h index e416b51..d1b2aa6 100644 --- a/src/colnod/entity.h +++ b/src/colnod/entity.h @@ -1,37 +1,39 @@ -#ifndef COLNOD_CONNECTOR_ENTITY_H -#define COLNOD_CONNECTOR_ENTITY_H - -#include -#include -#include - - -class Entity : public QObject { -Q_OBJECT -public: - using QObject::QObject; - - const QUuid &getId() const; - void setId(const QUuid &id); - - const QString &getName() const; - void setName(const QString &name); - - const QString &getDescription() const; - void setDescription(const QString &description); - - uint64_t getLastUpdate() const; - void setLastUpdate(uint64_t lastUpdate); - - virtual void fromJSON(const QJsonObject &json); - virtual QJsonObject toJSON() const; -protected: - QUuid id; - QString name; - QString description; - qint64 lastUpdate; -}; - - - -#endif //COLNOD_CONNECTOR_ENTITY_H +#ifndef COLNOD_CONNECTOR_ENTITY_H +#define COLNOD_CONNECTOR_ENTITY_H + +#include +#include +#include + + +class Entity : public QObject { +Q_OBJECT +public: + using QObject::QObject; + + const QUuid &getId() const; + void setId(const QUuid &id); + + const QString &getName() const; + void setName(const QString &name); + + const QString &getDescription() const; + void setDescription(const QString &description); + + uint64_t getLastUpdate() const; + void setLastUpdate(uint64_t lastUpdate); + + QString idToStringWithoutBraces(); + + virtual void fromJSON(const QJsonObject &json); + virtual QJsonObject toJSON() const; +protected: + QUuid id; + QString name; + QString description; + qint64 lastUpdate; +}; + + + +#endif //COLNOD_CONNECTOR_ENTITY_H diff --git a/src/colnod/requestmanager.cpp b/src/colnod/requestmanager.cpp index 8f05830..3847358 100644 --- a/src/colnod/requestmanager.cpp +++ b/src/colnod/requestmanager.cpp @@ -16,9 +16,9 @@ RequestManager::RequestManager() QObject::connect(manager, &QNetworkAccessManager::sslErrors, this, &RequestManager::onSSLError); } -void RequestManager::login(QString host, QString username, QString password) +Response* RequestManager::login() { - + loginResponse = new Response; QNetworkRequest request; QString hash = encryptedPassword(this->password); authHeader = getLoginHeader(this->user, hash); @@ -26,8 +26,6 @@ void RequestManager::login(QString host, QString username, QString password) {"password", hash}, {"username", this->user} }; - //this->host = host; - request.setUrl(this->host + "/AaaManager/authSession"); request.setRawHeader("Authorization", authHeader.toLocal8Bit()); request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json; charset=UTF-8"); @@ -35,42 +33,78 @@ void RequestManager::login(QString host, QString username, QString password) QJsonDocument jsonDocument; jsonDocument.setObject(reqBody); QNetworkReply* reply = manager->post(request, jsonDocument.toJson()); + loginResponse->setReply(reply); QObject::connect(reply, &QNetworkReply::finished, [=]() { if (reply->error()) { - qDebug() << reply->errorString(); + qDebug() << "Login failed: "<< reply->errorString(); loginStatus = false; + reply->deleteLater(); return; } - if (loginStatus) - return; - jsonResponse = reply->readAll(); - prepareAuthHeader(); + qDebug() << "Logged in successfully."; loginStatus = true; emit successLogin(); reply->deleteLater(); }); + connect(this, &RequestManager::successLogin, loginResponse, &Response::ready); + connect(this, &RequestManager::successLogin, this, &RequestManager::prepareAuthHeader); + return loginResponse; } -QNetworkReply* RequestManager::getRequest(QString endpoint) +QNetworkReply* RequestManager::postRequest(QString endpoint, QByteArray json) { QNetworkRequest request; request.setUrl(host + endpoint); - qDebug() << "Auth: " << authHeader; request.setRawHeader("Authorization", authHeader.toLocal8Bit()); - QNetworkReply* reply = manager->post(request, QByteArray()); + request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json; charset=UTF-8"); + QNetworkReply* reply = manager->post(request, json); QObject::connect(reply, &QNetworkReply::finished, [=]() { if (reply->error()) { - qDebug() << reply->errorString(); + qDebug() << "Authorization failed: " << reply->errorString(); loginStatus = false; - //getRequest(endpoint); + reply->deleteLater(); return; } + qDebug() << "Authorized successfully, response ready."; emit responseReady(); + reply->deleteLater(); }); return reply; +} + +Response* RequestManager::getLoginResponse() { + if (!loginResponse){ + loginResponse = login(); + + + } + return loginResponse; +} + +Response* RequestManager::postRequestReturnLogic(QString endpoint, QByteArray data) +{ + auto loginResponse = getLoginResponse(); + // This will ensure login is called only once + + Q_ASSERT(loginResponse); + Response* response = new Response; + + if (!loginStatus){ + + connect(this, &RequestManager::successLogin, [=](){ + response->setReply(postRequest(endpoint, data)); + connect(response->getReply(), &QNetworkReply::finished, response, &Response::ready); + }); + } + else + { + response->setReply(postRequest(endpoint, data)); + connect(response->getReply(), &QNetworkReply::finished, response, &Response::ready); + } + return response; } QString RequestManager::getFromJson(QString json, const QString &member) @@ -97,6 +131,7 @@ QString RequestManager::getLoginHeader(QString username, QString hash) void RequestManager::prepareAuthHeader() { + jsonResponse = loginResponse->getJson(); token = getFromJson(jsonResponse, "id"); QString authValue = token + ":"; authHeader = "Basic " + authValue.toLocal8Bit().toBase64(); @@ -104,74 +139,138 @@ void RequestManager::prepareAuthHeader() void RequestManager::onSSLError(QNetworkReply *reply, const QList &errors) { - qDebug() << "Network SSL errors"; + //qDebug() << "Network SSL errors"; for (const auto &error : errors) { if (error.error() == QSslError::SelfSignedCertificate) reply->ignoreSslErrors(errors); - if (error.error() == QSslError::HostNameMismatch) - reply->ignoreSslErrors(errors); - qDebug() << error.errorString(); + //qDebug() << error.errorString(); } } +QByteArray RequestManager::makeTimeStampJson(uint64_t time) +{ + QJsonObject reqBody = {{"timestamp",QJsonValue(static_cast(time)) }}; + QJsonDocument doc; + doc.setObject(reqBody); + return doc.toJson(); +} + +QByteArray RequestManager::makeTokensJson(QList>* tokens) +{ + QJsonObject items; + QJsonArray jsonTokens; + for (auto token : *tokens) + { + QJsonObject jsonToken; + jsonToken.insert("id",token->idToStringWithoutBraces()); + jsonToken.insert("name",token->getName()); + jsonToken.insert("description", token->getDescription()); + jsonToken.insert("tokenType", token->getTokenType()); + jsonToken.insert("tokenBits", token->getTokenBits()); + jsonToken.insert("tokenData", token->getTokenData()); + jsonToken.insert("timeToLive", token->getTimeToLive()); + jsonToken.insert("authErrors", token->getAuthErrors()); + QJsonArray flags; + auto flagStructure = token->getFlags(); + for (auto flag : flagStructure) + flags.push_back(flag); + jsonToken.insert("flags", flags); + jsonToken.insert("subjectId", token->subjectIdToStringWithoutBraces()); + jsonTokens.push_back(jsonToken); + } + items.insert("items", jsonTokens); + QJsonDocument doc; + doc.setObject(items); + return doc.toJson(); +} + +QByteArray RequestManager::makeIdsJson(QList* ids) +{ + QJsonArray jsonIds; + for (auto id : *ids) + { + jsonIds.push_back(id); + } + QJsonObject items; + items.insert("items", jsonIds); + QJsonDocument doc; + doc.setObject(items); + return doc.toJson(); +} + Response* RequestManager::getSubjects() { - auto response = new Response; - if (!loginStatus){ - login(host, user, password); - connect(this, &RequestManager::successLogin, [=](){ - auto subjectReply = getRequest("/SubjectManager/getSubjects"); - response->reply = subjectReply; - connect(subjectReply, &QNetworkReply::finished, response, &Response::finished); - }); - } - else - { - QNetworkReply* reply = getRequest("/SubjectManager/getSubjects"); - connect(reply, &QNetworkReply::finished, response, &Response::finished); - } - - return response; + return postRequestReturnLogic("/SubjectManager/getSubjects"); } Response* RequestManager::getTokens() { - auto response = new Response; - if (!loginStatus){ - login(host, user, password); - connect(this, &RequestManager::successLogin, [=](){ - auto subjectReply = getRequest("/TokenManager/getTokens"); - response->reply = subjectReply; - connect(subjectReply, &QNetworkReply::finished, response, &Response::finished); - }); - } - else - { - QNetworkReply* reply = getRequest("/TokenManager/getTokens"); - connect(reply, &QNetworkReply::finished, response, &Response::finished); - } - - return response; + return postRequestReturnLogic("/TokenManager/getTokens"); } Response* RequestManager::getTokenSubject() { - auto response = new Response; - if (!loginStatus){ - login(host, user, password); - connect(this, &RequestManager::successLogin, [=](){ - auto subjectReply = getRequest("/OpenManager/getTokenSubject"); - response->reply = subjectReply; - connect(subjectReply, &QNetworkReply::finished, response, &Response::finished); - }); - } - else - { - QNetworkReply* reply = getRequest("/OpenManager/getTokenSubject"); - connect(reply, &QNetworkReply::finished, response, &Response::finished); - } - - return response; + return postRequestReturnLogic("/OpenManager/getTokenSubject"); +} + +Response* RequestManager::getSubjectsUpdated(uint64_t time) +{ + return postRequestReturnLogic("/SubjectManager/getSubjectsUpdated", makeTimeStampJson(time)); +} + +Response* RequestManager::getSubjectsDeleted(uint64_t time) +{ + return postRequestReturnLogic("/SubjectManager/getSubjectsDeleted", makeTimeStampJson(time)); +} + +Response* RequestManager::getTokensUpdated(uint64_t time) +{ + return postRequestReturnLogic("/TokenManager/getTokensUpdated", makeTimeStampJson(time)); +} + +Response* RequestManager::getTokensDeleted(uint64_t time) +{ + return postRequestReturnLogic("/TokenManager/getTokensDeleted", makeTimeStampJson(time)); +} + +Response* RequestManager::getAccessGroups() +{ + return postRequestReturnLogic("/AccessManager/getAccessGroups"); +} + +Response* RequestManager::getAccessGroupsUpdated(uint64_t time) +{ + return postRequestReturnLogic("/AccessManager/getAccessGroupsUpdated", makeTimeStampJson(time)); +} + +Response* RequestManager::getAccessGroupsDeleted(uint64_t time) +{ + return postRequestReturnLogic("/AccessManager/getAccessGroupsDeleted", makeTimeStampJson(time)); +} + +Response* RequestManager::getAccessGroupMembership() +{ + return postRequestReturnLogic("/AccessManager/getAccessGroupMembership"); +} + +Response* RequestManager::getAccessGroupMembershipUpdated(uint64_t time) +{ + return postRequestReturnLogic("/AccessManager/getAccessGroupMembershipUpdated", makeTimeStampJson(time)); +} + +Response* RequestManager::getAccessGroupMembershipDeleted(uint64_t time) +{ + return postRequestReturnLogic("/AccessManager/getAccessGroupMembershipDeleted", makeTimeStampJson(time)); +} + +Response* RequestManager::setTokens(QList>* tokens) +{ + return postRequestReturnLogic("/TokenManager/setTokens", makeTokensJson(tokens)); +} + +Response* RequestManager::deleteTokens(QList* ids) +{ + return postRequestReturnLogic("/TokenManager/deleteTokens", makeIdsJson(ids)); } diff --git a/src/colnod/requestmanager.h b/src/colnod/requestmanager.h index 42b1a62..b784535 100644 --- a/src/colnod/requestmanager.h +++ b/src/colnod/requestmanager.h @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -19,8 +20,10 @@ #include #include #include +#include +#include "token.h" #include "response.h" class RequestManager : public QObject @@ -32,21 +35,43 @@ public: Response* getSubjects(); Response* getTokens(); Response* getTokenSubject(); - void login(QString endpoint, QString username, QString password); //I want it private, but unittest??? + + Response* getSubjectsUpdated(uint64_t time); + Response* getSubjectsDeleted(uint64_t time); + + Response* getTokensUpdated(uint64_t time); + Response* getTokensDeleted(uint64_t time); + + Response* getAccessGroups(); + Response* getAccessGroupsUpdated(uint64_t time); + Response* getAccessGroupsDeleted(uint64_t time); + Response* getAccessGroupMembership(); + Response* getAccessGroupMembershipUpdated(uint64_t time); + Response* getAccessGroupMembershipDeleted(uint64_t time); + + Response* setTokens(QList>* tokens); + Response* deleteTokens(QList* ids); + + Response* login(); //I want it private, but unittest??? const QJsonDocument &getConfig() const {return config;} const QString &getResponse() const {return jsonResponse;} private: - QNetworkReply* getRequest(QString endpoint); + QNetworkReply* postRequest(QString endpoint, QByteArray json = QByteArray()); + Response* postRequestReturnLogic(QString endpoint, QByteArray data = QByteArray()); QString getFromJson(QString json, const QString &member); QString encryptedPassword(QString password); QString getLoginHeader(QString username, QString hash); - void prepareAuthHeader(); + + QByteArray makeTimeStampJson(uint64_t time); + QByteArray makeTokensJson(QList>* tokens); + QByteArray makeIdsJson(QList* ids); + Response* getLoginResponse(); private slots: void onSSLError(QNetworkReply *reply, const QList &errors); - + void prepareAuthHeader(); signals: void successLogin(); @@ -55,10 +80,11 @@ signals: private: QNetworkAccessManager* manager = nullptr; + Response* loginResponse = nullptr; QJsonDocument config; QString authHeader; QString host = "https://192.168.1.3:8443"; - //QString host = "http://localhost:8080"; + // QString host = "https://localhost:8080"; QString password = "spaceti1"; QString user = "spaceti"; diff --git a/src/colnod/response.cpp b/src/colnod/response.cpp index a3cb839..39d6482 100644 --- a/src/colnod/response.cpp +++ b/src/colnod/response.cpp @@ -2,5 +2,10 @@ Response::Response() { - + connect(this, &Response::ready, this, &Response::setJson); +} + +int Response::getStatusCode() +{ + return reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); } diff --git a/src/colnod/response.h b/src/colnod/response.h index aa5ef96..4416f88 100644 --- a/src/colnod/response.h +++ b/src/colnod/response.h @@ -8,18 +8,28 @@ class Response : public QObject { Q_OBJECT public: + Response(); + int getStatusCode(); + QString getJson() {return json;} + void setReply(QNetworkReply* rpl) {reply = rpl;} + QNetworkReply* getReply() {return reply;} public: - QNetworkReply *reply = nullptr; + signals: - void finished(); -public slots: + void ready(); + + +private slots: + void setJson() {json = reply->readAll();} + private: - + QString json; + QNetworkReply *reply = nullptr; }; #endif // RESPONSE_H diff --git a/src/colnod/subject.cpp b/src/colnod/subject.cpp index 6ddff51..c2ae710 100644 --- a/src/colnod/subject.cpp +++ b/src/colnod/subject.cpp @@ -11,10 +11,13 @@ QString Subject::getEmail() const { void Subject::fromJSON(const QJsonObject &json) { Entity::fromJSON(json); - //attributes = json["attributes"]["items"].toObject(); - attributes = json.value("attributes").toObject().value("items").toObject(); - + for (int i = 0; i < attributeTypes->length(); i++) + { + if (!attributes[attributeTypes[i]].toString().isEmpty()){ + atr.append(qMakePair(attributeTypes[i], attributes[attributeTypes[i]].toString())); + } + } const auto &tokenFlagsArray = json.value("tokenFlags").toArray(); for(const auto &flag : tokenFlagsArray){ tokenFlags.insert(flag.toString()); @@ -72,3 +75,11 @@ const QSet &Subject::getPinFlags() const { void Subject::setPinFlags(const QSet &pinFlags) { Subject::pinFlags = pinFlags; } + +const QList> &Subject::getAtr() const { + return atr; +} + +void Subject::setAtr(const QList> &atr) { + this->atr = atr; +} diff --git a/src/colnod/subject.h b/src/colnod/subject.h index 8659c11..955f623 100644 --- a/src/colnod/subject.h +++ b/src/colnod/subject.h @@ -1,35 +1,46 @@ -#ifndef COLNOD_CONNECTOR_SUBJECT_H -#define COLNOD_CONNECTOR_SUBJECT_H - -#include - -#include "entity.h" - - -class Subject : public Entity { - -public: - using Entity::Entity; - - QString getEmail() const; - - const QJsonObject &getAttributes() const; - void setAttributes(const QJsonObject &attributes); - const QSet &getTokenFlags() const; - void setTokenFlags(const QSet &tokenFlags); - const QString &getPin() const; - void setPin(const QString &pin); - const QSet &getPinFlags() const; - void setPinFlags(const QSet &pinFlags); - - void fromJSON(const QJsonObject &json) override; - QJsonObject toJSON() const override; -protected: - QJsonObject attributes; - QSet tokenFlags; - QString pin; - QSet pinFlags; -}; - - -#endif //COLNOD_CONNECTOR_SUBJECT_H +#ifndef COLNOD_CONNECTOR_SUBJECT_H +#define COLNOD_CONNECTOR_SUBJECT_H + +#include + +#include "entity.h" +#include +#include +#include + +class Subject : public Entity { + +public: + using Entity::Entity; + + QString getEmail() const; + + const QJsonObject &getAttributes() const; + void setAttributes(const QJsonObject &attributes); + const QSet &getTokenFlags() const; + void setTokenFlags(const QSet &tokenFlags); + const QString &getPin() const; + void setPin(const QString &pin); + const QSet &getPinFlags() const; + void setPinFlags(const QSet &pinFlags); + // const QList> &getAtr() const; + // void setAtr(const QList> &atr); + + const QList> &getAtr() const; + void setAtr(const QList> &atr); + + void fromJSON(const QJsonObject &json) override; + QJsonObject toJSON() const override; +protected: + QJsonObject attributes; + QSet tokenFlags; + QString pin; + QSet pinFlags; + //QList> atr; + QList> atr; + const QString attributeTypes[6] = {"Jmeno", "Prijmeni", "ProfilParking", "Spolecnost", "Profil", "spz"}; + +}; + + +#endif //COLNOD_CONNECTOR_SUBJECT_H diff --git a/src/colnod/token.cpp b/src/colnod/token.cpp index bf306bf..941f1fc 100644 --- a/src/colnod/token.cpp +++ b/src/colnod/token.cpp @@ -2,6 +2,25 @@ #include +Token::Token(QString namee, QString tokenData, QString decription) +{ + this->name = namee; + this->tokenData = tokenData; + this->description = decription; + this->id = QUuid::createUuid(); + this->tokenType = "Token"; + this->tokenBits = 32; + this->timeToLive = 255; + this->authErrors = 255; + this->flags = {"Enabled", "NoValidity"}; + +} + +Token::Token(QString namee) +{ + this->name = namee; +} + void Token::fromJSON(const QJsonObject &json) { Entity::fromJSON(json); @@ -106,3 +125,7 @@ const QUuid &Token::getSubjectId() const { void Token::setSubjectId(const QUuid &subjectId) { Token::subjectId = subjectId; } + +QString Token::subjectIdToStringWithoutBraces(){ + return subjectId.toString().mid(1,36); +} diff --git a/src/colnod/token.h b/src/colnod/token.h index fe06222..1ffc80f 100644 --- a/src/colnod/token.h +++ b/src/colnod/token.h @@ -1,48 +1,53 @@ -#ifndef COLNOD_CONNECTOR_TOKEN_H -#define COLNOD_CONNECTOR_TOKEN_H - -#include "entity.h" - -#include - - -class Token : public Entity { -public: - // using Entity::Entity; - - const QString &getTokenType() const; - void setTokenType(const QString &tokenType); - int getTokenBits() const; - void setTokenBits(int tokenBits); - const QString &getTokenData() const; - void setTokenData(const QString &tokenData); - qint64 getValidFrom() const; - void setValidFrom(qint64 validFrom); - qint64 getValidTo() const; - void setValidTo(qint64 validTo); - int getTimeToLive() const; - void setTimeToLive(int timeToLive); - int getAuthErrors() const; - void setAuthErrors(int authErrors); - const QSet &getFlags() const; - void setFlags(const QSet &flags); - const QUuid &getSubjectId() const; - void setSubjectId(const QUuid &subjectId); - - - void fromJSON(const QJsonObject &json) override; - QJsonObject toJSON() const override; -protected: - QString tokenType; - int tokenBits; - QString tokenData; - qint64 validFrom; - qint64 validTo; - int timeToLive; - int authErrors; - QSet flags; - QUuid subjectId; -}; - - -#endif //COLNOD_CONNECTOR_TOKEN_H +#ifndef COLNOD_CONNECTOR_TOKEN_H +#define COLNOD_CONNECTOR_TOKEN_H + +#include "entity.h" + +#include + + +class Token : public Entity { +public: + // using Entity::Entity; + + Token() = default; + Token(QString name, QString tokenData, QString decription = "mobile"); + Token(QString name); + const QString &getTokenType() const; + void setTokenType(const QString &tokenType); + int getTokenBits() const; + void setTokenBits(int tokenBits); + const QString &getTokenData() const; + void setTokenData(const QString &tokenData); + qint64 getValidFrom() const; + void setValidFrom(qint64 validFrom); + qint64 getValidTo() const; + void setValidTo(qint64 validTo); + int getTimeToLive() const; + void setTimeToLive(int timeToLive); + int getAuthErrors() const; + void setAuthErrors(int authErrors); + const QSet &getFlags() const; + void setFlags(const QSet &flags); + const QUuid &getSubjectId() const; + void setSubjectId(const QUuid &subjectId); + + QString subjectIdToStringWithoutBraces(); + + + void fromJSON(const QJsonObject &json) override; + QJsonObject toJSON() const override; +protected: + QString tokenType; + int tokenBits; + QString tokenData; + qint64 validFrom; + qint64 validTo; + int timeToLive; + int authErrors; + QSet flags; + QUuid subjectId; +}; + + +#endif //COLNOD_CONNECTOR_TOKEN_H diff --git a/src/colnod/tokens.json b/src/colnod/tokens.json new file mode 100644 index 0000000..d3e882f --- /dev/null +++ b/src/colnod/tokens.json @@ -0,0 +1,34 @@ +{ + "items": [ + { + "id": "582c982d-6fd7-4856-8548-7ce542791c7a", + "name": "test", + "description": "mobile", + "tokenType": "Token", + "tokenBits": 32, + "tokenData": "7B9D32", + "timeToLive": 255, + "authErrors": 255, + "flags": [ + "Enabled", + "NoValidity" + ], + "subjectId": "72b37f7e-5761-4e6c-8e87-20c0bed0d904" + }, + { + "id": "3ff23b41-3da3-4b33-82ce-d8e2d8c9a546", + "name": "test1", + "description": "mobile", + "tokenType": "Token", + "tokenBits": 32, + "tokenData": "7B9D12", + "timeToLive": 255, + "authErrors": 255, + "flags": [ + "Enabled", + "NoValidity" + ], + "subjectId": "72b37f7e-5761-4e6c-8e87-20c0bed0d904" + } + ] +} \ No newline at end of file diff --git a/test/unitTests/UnitTest.cpp b/test/unitTests/UnitTest.cpp index a25c365..af27504 100644 --- a/test/unitTests/UnitTest.cpp +++ b/test/unitTests/UnitTest.cpp @@ -1,13 +1,19 @@ #include "unittest.h" +void UnitTest::initTestCase() +{ + +} + void UnitTest::loginSuccessfully() { RequestManager* testAccess = new RequestManager(); QJsonDocument config = testAccess->getConfig(); QSignalSpy spy(testAccess, SIGNAL(successLogin())); - testAccess->login(host, email, password); - spy.wait(); QVERIFY(spy.isValid()); + testAccess->login(); + spy.wait(15000); + QCOMPARE(spy.count(), 1); QString json = testAccess->getResponse(); qDebug() << json; @@ -20,11 +26,15 @@ void UnitTest::getSubjects() { RequestManager* testAccess = new RequestManager(); QSignalSpy spy(testAccess, SIGNAL(responseReady())); - testAccess->getSubjects(); - spy.wait(); QVERIFY(spy.isValid()); + Response* response = testAccess->getSubjects(); + QSignalSpy spy1(response, &Response::ready); + + spy.wait(15000); + QCOMPARE(spy.count(), 1); - QString json = testAccess->getResponse(); + QCOMPARE(spy1.count(), 1); + QString json = response->getJson(); QJsonDocument doc = QJsonDocument::fromJson(json.toUtf8()); QVERIFY(doc.isObject()); QVERIFY2(doc.object().value("items").isArray(), "No parameter 'id' in response"); @@ -36,13 +46,13 @@ void UnitTest::getSubjects() void UnitTest::getTokens() { RequestManager* testAccess = new RequestManager(); - QSignalSpy spy(testAccess, SIGNAL(responseReady())); - testAccess->getTokens(); + Response* response = testAccess->getTokens(); + QSignalSpy spy(response, &Response::ready); QCOMPARE(spy.count(), 0); - spy.wait(); + spy.wait(15000); QVERIFY(spy.isValid()); QCOMPARE(spy.count(), 1); - QString json = testAccess->getResponse(); + QString json = response->getJson(); QJsonDocument doc = QJsonDocument::fromJson(json.toUtf8()); QVERIFY(doc.isObject()); QVERIFY2(doc.object().value("items").isArray(), "No parameter 'id' in response"); @@ -54,14 +64,187 @@ void UnitTest::getTokenSubject() { RequestManager* testAccess = new RequestManager(); QSignalSpy spy(testAccess, SIGNAL(responseReady())); - testAccess->getTokenSubject(); + Response* response = testAccess->getTokenSubject(); QCOMPARE(spy.count(), 0); - spy.wait(); + spy.wait(15000); QVERIFY(spy.isValid()); QCOMPARE(spy.count(), 1); - QString response = testAccess->getResponse(); - qDebug() << response; - QVERIFY(!response.isEmpty()); + QString json = response->getJson(); + QVERIFY(!json.isEmpty()); +} + +void UnitTest::getSubjectsUpdated() +{ + RequestManager* testAccess = new RequestManager(); + QSignalSpy spy(testAccess, SIGNAL(responseReady())); + Response* response = testAccess->getSubjectsUpdated(1568646217767); + QCOMPARE(spy.count(), 0); + spy.wait(15000); + QVERIFY(spy.isValid()); + QCOMPARE(spy.count(), 1); + QString json = response->getJson(); + QVERIFY(!json.isEmpty()); +} + +void UnitTest::getSubjectsDeleted() +{ + RequestManager* testAccess = new RequestManager(); + QSignalSpy spy(testAccess, SIGNAL(responseReady())); + Response* response = testAccess->getSubjectsDeleted(1568646217767); + QCOMPARE(spy.count(), 0); + spy.wait(15000); + QVERIFY(spy.isValid()); + QCOMPARE(spy.count(), 1); + QString json = response->getJson(); + QVERIFY(!json.isEmpty()); +} + +void UnitTest::getTokensUpdated() +{ + RequestManager* testAccess = new RequestManager(); + QSignalSpy spy(testAccess, SIGNAL(responseReady())); + Response* response = testAccess->getTokensUpdated(1570109859681); + QCOMPARE(spy.count(), 0); + spy.wait(15000); + QVERIFY(spy.isValid()); + QCOMPARE(spy.count(), 1); + QString json = response->getJson(); + QVERIFY(!json.isEmpty()); +} + +void UnitTest::getTokensDeleted() +{ + RequestManager* testAccess = new RequestManager(); + QSignalSpy spy(testAccess, SIGNAL(responseReady())); + Response* response = testAccess->getTokensDeleted(1570109859681); + QCOMPARE(spy.count(), 0); + spy.wait(15000); + QVERIFY(spy.isValid()); + QCOMPARE(spy.count(), 1); + QString json = response->getJson(); + QVERIFY(!json.isEmpty()); +} + +void UnitTest::getAccessGroups() +{ + RequestManager* testAccess = new RequestManager(); + QSignalSpy spy(testAccess, SIGNAL(responseReady())); + Response* response = testAccess->getAccessGroups(); + QCOMPARE(spy.count(), 0); + spy.wait(15000); + QVERIFY(spy.isValid()); + QCOMPARE(spy.count(), 1); + QString json = response->getJson(); + QVERIFY(!json.isEmpty()); +} + +void UnitTest::getAccessGroupsUpdated() +{ + RequestManager* testAccess = new RequestManager(); + QSignalSpy spy(testAccess, SIGNAL(responseReady())); + Response* response = testAccess->getAccessGroupsUpdated(1568646217767); + QCOMPARE(spy.count(), 0); + spy.wait(15000); + QVERIFY(spy.isValid()); + QCOMPARE(spy.count(), 1); + QString json = response->getJson(); + QVERIFY(!json.isEmpty()); +} + +void UnitTest::getAccessGroupsDeleted() +{ + RequestManager* testAccess = new RequestManager(); + QSignalSpy spy(testAccess, SIGNAL(responseReady())); + Response* response = testAccess->getAccessGroupsDeleted(1568646217767); + QCOMPARE(spy.count(), 0); + spy.wait(15000); + QVERIFY(spy.isValid()); + QCOMPARE(spy.count(), 1); + QString json = response->getJson(); + QVERIFY(!json.isEmpty()); +} + +void UnitTest::getAccessGroupMembership() +{ + RequestManager* testAccess = new RequestManager(); + QSignalSpy spy(testAccess, SIGNAL(responseReady())); + Response* response = testAccess->getAccessGroupMembership(); + QCOMPARE(spy.count(), 0); + spy.wait(15000); + QVERIFY(spy.isValid()); + QCOMPARE(spy.count(), 1); + QString json = response->getJson(); + QVERIFY(!json.isEmpty()); +} + +void UnitTest::getAccessGroupMembershipUpdated() +{ + RequestManager* testAccess = new RequestManager(); + QSignalSpy spy(testAccess, SIGNAL(responseReady())); + Response* response = testAccess->getAccessGroupMembershipUpdated(1568646217767); + QCOMPARE(spy.count(), 0); + spy.wait(15000); + QVERIFY(spy.isValid()); + QCOMPARE(spy.count(), 1); + QString json = response->getJson(); + QVERIFY(!json.isEmpty()); +} + +void UnitTest::getAccessGroupMembershipDeleted() +{ + RequestManager* testAccess = new RequestManager(); + QSignalSpy spy(testAccess, SIGNAL(responseReady())); + Response* response = testAccess->getAccessGroupMembershipDeleted(1568646217767); + QCOMPARE(spy.count(), 0); + spy.wait(15000); + QVERIFY(spy.isValid()); + QCOMPARE(spy.count(), 1); + QString json = response->getJson(); + QVERIFY(!json.isEmpty()); +} + +void UnitTest::setTokens() +{ + QFile jsonData(QDir::current().filePath("tokens.json")); + + QVERIFY2(jsonData.open(QIODevice::ReadOnly), "Couldn't open config file tokens.json"); + QJsonDocument doc = QJsonDocument::fromJson(jsonData.readAll()); + QJsonObject obj = doc.object(); + QJsonArray arr = obj["items"].toArray(); + qDebug() << arr; + QList> tokens; + for (auto object : arr) + { + auto token = new Token; + token->fromJSON(object.toObject()); + qDebug() << token; + tokens.append(token); + } + RequestManager* testAccess = new RequestManager(); + QSignalSpy spy(testAccess, SIGNAL(responseReady())); + Response* response = testAccess->setTokens(&tokens); + QCOMPARE(spy.count(), 0); + spy.wait(15000); + QVERIFY(spy.isValid()); + QCOMPARE(spy.count(), 1); + QString json = response->getJson(); + QVERIFY(!json.isEmpty()); +} + +void UnitTest::deleteTokens() +{ + RequestManager* testAccess = new RequestManager(); + QSignalSpy spy(testAccess, SIGNAL(responseReady())); + QList ids; + ids.append("582c982d-6fd7-4856-8548-7ce542791c7a"); + ids.append("3ff23b41-3da3-4b33-82ce-d8e2d8c9a546"); + Response* response = testAccess->deleteTokens(&ids); + QCOMPARE(spy.count(), 0); + spy.wait(15000); + QVERIFY(spy.isValid()); + QCOMPARE(spy.count(), 1); + QString json = response->getJson(); + QVERIFY(!json.isEmpty()); } void UnitTest::subjectJSONParser() @@ -79,13 +262,12 @@ void UnitTest::subjectJSONParser() QJsonObject obj = doc.object(); QJsonArray arr = obj["items"].toArray(); */ - RequestManager* testAccess = new RequestManager(); QSignalSpy spy(testAccess, SIGNAL(responseReady())); - testAccess->getSubjects(); - spy.wait(); - QString response = testAccess->getResponse(); - QJsonDocument doc = QJsonDocument::fromJson(response.toUtf8()); + Response* response = testAccess->getSubjects(); + spy.wait(15000); + QString json = response->getJson(); + QJsonDocument doc = QJsonDocument::fromJson(json.toUtf8()); QJsonArray arr = doc.object()["items"].toArray(); auto testSubject = new Subject(); testSubject->fromJSON(arr[1].toObject()); @@ -97,10 +279,10 @@ void UnitTest::tokenJSONParser() { RequestManager* testAccess = new RequestManager(); QSignalSpy spy(testAccess, SIGNAL(responseReady())); - testAccess->getTokens(); - spy.wait(); - QString response = testAccess->getResponse(); - QJsonDocument doc = QJsonDocument::fromJson(response.toUtf8()); + Response* response = testAccess->getTokens(); + spy.wait(15000); + QString json = response->getJson(); + QJsonDocument doc = QJsonDocument::fromJson(json.toUtf8()); QJsonArray arr = doc.object()["items"].toArray(); auto testToken = new Token(); testToken->fromJSON(arr[5].toObject()); @@ -115,10 +297,10 @@ void UnitTest::connectToDB() qDebug() << db->getTestMessage(1); QVERIFY(true); QCOMPARE(db->getTestMessage(1), QStringLiteral("Hello world")); - db->createTestRecord("Now it's diffrent"); - QCOMPARE(db->getTestMessage(2), QStringLiteral("Does it work?")); + QCOMPARE(db->getTestMessage(db->createTestRecord("Now it's diffrent")), QStringLiteral("Now it's diffrent")); } +/* void UnitTest::debugConnection() { QSslSocket ssl;// = new QSslSocket(); @@ -128,7 +310,7 @@ void UnitTest::debugConnection() { qDebug() << ssl.errorString(); } - QString tmp = "POST /AaaManager/authSession HTTP/1.1\r\nHost: 192.168.1.3:8443\r\nAuthorization: Basic c3BhY2V0aTpFN0ZFQTA3REJDODJGQjlCQTM0QjJFNDUzRTJFRkU4OUYwNTgzRTcxODc1NDM1MDdFRjExRTg0NzI2MDcxRkU0Mjg0NDUzNzJGMkU0NkI0NTVFQjBDNzk3NDdDNTFFMzYyRjQwM0NFMzk0NzNBMkE4QzJERkEwQ0U1Qzk4MjZDMA==\r\nUser-Agent: curl/7.65.3\r\nAccept: */*\r\nContent-Type: application/json\r\nContent-Length: 164\r\n\r\n{\"password\":\"E7FEA07DBC82FB9BA34B2E453E2EFE89F0583E7187543507EF11E84726071FE428445372F2E46B455EB0C79747C51E362F403CE39473A2A8C2DFA0CE5C9826C0\",\"username\":\"spaceti\"}"; + QString tmp = "POST /AaaManager/authSession HTTP/1.1\r\nHost: 192.168.1.3:8443\r\nAuthorization: Basic c3BhY2V0aTpFN0ZFQTA3REJDODJGQjlCQTM0QjJFNDUzRTJFRkU4OUYwNTgzRTcxODc1NDM1MDdFRjExRTg0NzI2MDcxRkU0Mjg0NDUzNzJGMkU0NkI0NTVFQjBDNzk3NDdDNTFFMzYyRjQwM0NFMzk0NzNBMkE4QzJERkEwQ0U1Qzk4MjZDMA==\r\nUser-Agent: curl/7.65.3\r\nAccept: **\r\nContent-Type: application/json\r\nContent-Length: 164\r\n\r\n{\"password\":\"E7FEA07DBC82FB9BA34B2E453E2EFE89F0583E7187543507EF11E84726071FE428445372F2E46B455EB0C79747C51E362F403CE39473A2A8C2DFA0CE5C9826C0\",\"username\":\"spaceti\"}"; qDebug().noquote() << tmp.toUtf8(); ssl.write(tmp.toUtf8()); QString data; @@ -141,7 +323,7 @@ void UnitTest::debugConnection() QString tkn = data.mid( index + 5, 36); tkn = tkn + ":"; qDebug() << "parsed token : " <localSaveTokens(); QVERIFY(true); } +void UnitTest::getUuid() +{ + qDebug() << QUuid::createUuid().toString().mid(1,36); + QCOMPARE(1,1); +} -QTEST_MAIN(UnitTest) + + +//QTEST_MAIN(UnitTest) diff --git a/test/unitTests/complextest.cpp b/test/unitTests/complextest.cpp new file mode 100644 index 0000000..7fc87e7 --- /dev/null +++ b/test/unitTests/complextest.cpp @@ -0,0 +1,175 @@ +#include "complextest.h" + +void ComplexTest::initTestCase() +{ + reqMan = new RequestManager; + start = QDateTime::currentMSecsSinceEpoch()-2000; + api = new ColnodAPI; + qDebug() << start; +} + +void ComplexTest::cleanupTestCase() +{ + QList ids; + ids.append("582c982d-6fd7-4856-8548-7ce542791c7a"); + Response* deleteTokensResp = reqMan->deleteTokens(&ids); + QSignalSpy deleteTokensRespSpy(deleteTokensResp, &Response::ready); + QCOMPARE(deleteTokensRespSpy.count(), 0); + deleteTokensRespSpy.wait(10000); +} + +void ComplexTest::complexTest() +{ + // LOGIN_BEGIN + QSignalSpy loginSpy(reqMan, &RequestManager::successLogin); + Response* loginResp = reqMan->login(); + QSignalSpy loginRespSpy(loginResp, &Response::ready); + QCOMPARE(loginSpy.count(), 0); + QCOMPARE(loginRespSpy.count(), 0); + loginSpy.wait(10000); + QCOMPARE(loginResp->getStatusCode(), 200); // HTTP status code check + QCOMPARE(loginSpy.count(), 1); // Checking multiple calls + QCOMPARE(loginRespSpy.count(), 1); + auto doc0 = getJsonDoc(loginResp->getJson()); + QVERIFY(doc0.object()["id"].isString()); + // LOGIN_END + + // NUMBER_OF_SUBJECTS_AND_TOKENS_BEGIN + int numOfSubjects = getNumOfSubjects(); + QCOMPARE(numOfSubjects, 2893); // should be still the same, if false db has been changed + int numOfTokens = getNumOfTokens(); + QCOMPARE(numOfTokens, 2881); // should be still the same, if false db has been changed, or deleteTokens didnt work in previous test + // NUMBER_OF_SUBJECTS_AND_TOKENS_END + + + // ADD_TOKENS_CHECK_BEGIN + QList> tokens; + tokens.append(getTestToken()); + Response* setTokensResp = reqMan->setTokens(&tokens); + QSignalSpy setTokensRespSpy(setTokensResp, &Response::ready); + QCOMPARE(setTokensRespSpy.count(), 0); + setTokensRespSpy.wait(10000); + QCOMPARE(setTokensRespSpy.count(), 1); + QCOMPARE(setTokensResp->getStatusCode(), 200); + QCOMPARE(getNumOfTokens(), numOfTokens + 1); + // ADD_TOKENS_CHEK_END + + // CHECK_UPDATED_TOKENS_BEGIN + Response* getTokensUpdatedResp = reqMan->getTokensUpdated(start); + //start = QDateTime::currentMSecsSinceEpoch(); + QSignalSpy getTokensUpdatedRespSpy(getTokensUpdatedResp, &Response::ready); + QCOMPARE(getTokensUpdatedRespSpy.count(), 0); + getTokensUpdatedRespSpy.wait(10000); + QCOMPARE(getTokensUpdatedResp->getStatusCode(), 200); + QCOMPARE(getTokensUpdatedRespSpy.count(), 1); + auto doc1 = getJsonDoc(getTokensUpdatedResp->getJson()); + QCOMPARE(doc1.object()["items"].toArray().size(), 1); + // CHECK_UPDATED_TOKENS_END + + // DELETE_TOKENS_CHECK_BEGIN + QList ids; + ids.append("582c982d-6fd7-4856-8548-7ce542791c7a"); + Response* deleteTokensResp = reqMan->deleteTokens(&ids); + QSignalSpy deleteTokensRespSpy(deleteTokensResp, &Response::ready); + QCOMPARE(deleteTokensRespSpy.count(), 0); + deleteTokensRespSpy.wait(10000); + QCOMPARE(deleteTokensRespSpy.count(), 1); + QCOMPARE(deleteTokensResp->getStatusCode(), 200); + // DELETE_TOKENS_CHECK_END + + // CHECK_DELETED_TOKENS_BEGIN + Response* getTokensDeletedResp = reqMan->getTokensDeleted(start); + start = QDateTime::currentMSecsSinceEpoch(); + QSignalSpy getTokensDeletedRespSpy(getTokensDeletedResp, &Response::ready); + QCOMPARE(getTokensDeletedRespSpy.count(), 0); + getTokensDeletedRespSpy.wait(10000); + QCOMPARE(getTokensDeletedResp->getStatusCode(), 200); + QCOMPARE(getTokensDeletedRespSpy.count(), 1); + auto doc2 = getJsonDoc(getTokensDeletedResp->getJson()); + QCOMPARE(doc2.object()["items"].toArray().size(), 1); + QVERIFY(doc2.object()["items"].toArray().contains("582c982d-6fd7-4856-8548-7ce542791c7a")); + // CHECK_DELETED_TOKENS_END + + + + // LAST_TESTS (for sure) + QCOMPARE(loginSpy.count(), 1); // Checking multiple calls + QCOMPARE(loginRespSpy.count(), 1); + QCOMPARE(getNumOfSubjects(), numOfSubjects); + QCOMPARE(getNumOfTokens(), numOfTokens); +} + + +void ComplexTest::fullSync() +{ + api->prepareDatabase(); + api->downloadData(); + QSignalSpy spy(api, &ColnodAPI::dataDownloaded); + spy.wait(10000); + api->syncDataFromColnod(); + // api->syncDataToColnod(); +} + +void ComplexTest::syncLastUpdated() +{ + api->downloadChangedDataFromColnod(); + QSignalSpy spy(api, &ColnodAPI::dataDownloaded); + spy.wait(10000); + api->syncChangedDataFromColnod(); + // api->syncChangedDataToColnod(); + +} + +void ComplexTest::testingStuff() +{ + //DatabaseManager* db = new DatabaseManager("192.168.1.94", "deloitte", "postgres", "34rjkciea12"); + //DatabaseManager* db = new DatabaseManager("localhost", "deloitte", "postgres", "34rjkciea12"); + //db->makeTestingLast_sync(); +} + +// HELPFUL_FUNCTIONS +int ComplexTest::getNumOfSubjects() +{ + Response* subjectsResp = reqMan->getSubjects(); + QSignalSpy subjectsRespSpy(subjectsResp, &Response::ready); + subjectsRespSpy.wait(10000); + auto doc = getJsonDoc(subjectsResp->getJson()); + return doc.object()["items"].toArray().size(); +} + +int ComplexTest::getNumOfTokens() +{ + Response* tokensResp = reqMan->getTokens(); + QSignalSpy tokensRespSpy(tokensResp, &Response::ready); + tokensRespSpy.wait(10000); + auto doc = getJsonDoc(tokensResp->getJson()); + return doc.object()["items"].toArray().size(); +} + +QJsonDocument ComplexTest::getJsonDoc(QString json) +{ + return QJsonDocument::fromJson(json.toUtf8()); +} + +Token* ComplexTest::getTestToken() +{ + QJsonObject jsonToken; + jsonToken.insert("id", "582c982d-6fd7-4856-8548-7ce542791c7a"); + jsonToken.insert("name", "test"); + jsonToken.insert("description", "mobile"); + jsonToken.insert("tokenType", "Token"); + jsonToken.insert("tokenBits", 32); + jsonToken.insert("tokenData", "7B9D32"); + jsonToken.insert("timeToLive", 255); + jsonToken.insert("authErrors", 255); + QJsonArray flags; + flags.push_back("Enabled"); + flags.push_back("NoValidity"); + jsonToken.insert("flags", flags); + jsonToken.insert("subjectId", "72b37f7e-5761-4e6c-8e87-20c0bed0d904"); + Token* token = new Token; + token->fromJSON(jsonToken); + return token; +} + +QTEST_MAIN(ComplexTest) diff --git a/test/unitTests/complextest.h b/test/unitTests/complextest.h new file mode 100644 index 0000000..ed34fe5 --- /dev/null +++ b/test/unitTests/complextest.h @@ -0,0 +1,38 @@ + +#pragma once + +#include +#include +#include "response.h" +#include "requestmanager.h" +#include "colnodapi.h" + +class ComplexTest : public QObject +{ + Q_OBJECT + +private slots: + void initTestCase(); + void complexTest(); + void fullSync(); + void syncLastUpdated(); + void testingStuff(); + void cleanupTestCase(); + +private: + // FUNCTIONS + int getNumOfSubjects(); + int getNumOfTokens(); + QJsonDocument getJsonDoc(QString json); + Token* getTestToken(); + + + // VARIABLES + QString host = "https://192.168.1.3"; + QString user = "spaceti"; + QString password = "spaceti1"; + RequestManager* reqMan = nullptr; + uint64_t start = 0; + ColnodAPI* api = nullptr; +}; + diff --git a/test/unitTests/unitTests.pro b/test/unitTests/unitTests.pro index c735084..a0b7551 100644 --- a/test/unitTests/unitTests.pro +++ b/test/unitTests/unitTests.pro @@ -1,15 +1,17 @@ -QT -= gui -QT += core sql network testlib -CONFIG += testcase # neccesary to have posibility to run: make check UnitTest - -HEADERS += \ - unittest.h -SOURCES += \ - unittest.cpp - -include(../../src/colnod/colnod.pri) - -# Default rules for deployment. -qnx: target.path = /tmp/$${TARGET}/bin -else: unix:!android: target.path = /opt/$${TARGET}/bin -!isEmpty(target.path): INSTALLS += target +QT -= gui +QT += core sql network testlib +CONFIG += testcase # neccesary to have posibility to run: make check UnitTest + +HEADERS += \ + complextest.h \ + unittest.h +SOURCES += \ + complextest.cpp \ + unittest.cpp + +include(../../src/colnod/colnod.pri) + +# Default rules for deployment. +qnx: target.path = /tmp/$${TARGET}/bin +else: unix:!android: target.path = /opt/$${TARGET}/bin +!isEmpty(target.path): INSTALLS += target diff --git a/test/unitTests/unittest.h b/test/unitTests/unittest.h index 0765fa6..2fabad0 100644 --- a/test/unitTests/unittest.h +++ b/test/unitTests/unittest.h @@ -8,6 +8,7 @@ #include "databasemanager.h" #include #include "datamanager.h" +#include "response.h" class UnitTest : public QObject @@ -16,15 +17,31 @@ class UnitTest : public QObject private slots: + void initTestCase(); + void loginSuccessfully(); // /AaaManager/authSession void getSubjects(); // /SubjectManager/getSubjects void getTokens(); // /TokenManager/getTokens - void getTokenSubject(); // /OpenManager/getTokenSubject + void getTokenSubject(); // /OpenManager/getTokenSubject + void getSubjectsUpdated(); + void getSubjectsDeleted(); + void getTokensUpdated(); + void getTokensDeleted(); + void getAccessGroups(); + void getAccessGroupsUpdated(); + void getAccessGroupsDeleted(); + void getAccessGroupMembership(); + void getAccessGroupMembershipUpdated(); + void getAccessGroupMembershipDeleted(); + void setTokens(); + void deleteTokens(); void subjectJSONParser(); void tokenJSONParser(); void connectToDB(); - void debugConnection(); + //void debugConnection(); void saveDataToDB(); + void getUuid(); + private: //QString host = "http://localhost:8080"; //colnod server (ssh -L 8080:192.168.254.11:8443 penta-master)