akvo / akvo-flow

A data collection and monitoring tool that works anywhere.
http://akvo.org/products/akvoflow/
GNU Affero General Public License v3.0
65 stars 31 forks source link

New backend service for form publishing #3835

Closed valllllll2000 closed 3 years ago

valllllll2000 commented 3 years ago

Context

Publishing will be made to work under 1 min with a new service see #3795

Problem or idea

Currently publishing takes too long

Solution or next step

Frontend will send all the data to publish

valllllll2000 commented 3 years ago

We have agreed to send one single json object to the backend which contains a form with a list of groups and each has a list of questions. Right now here is what the backend expects: https://github.com/akvo/akvo-flow/pull/3836/files#diff-7ac7de80b71f48472a26bf0618124c5c15744fa715d803a34a68aa2f8a75c166R57 The problem is Survey object has a map of questiongroups and this will not work with JSON, we need a new object for example:

{
      "keyId": 352160049,
      "name": "New form",
      "code": "New form",
      "version": "2.0",
      "description": null,
      "status": "NOT_PUBLISHED",
      "questionGroupList": null,
      "path": "/Valeria Test/New survey/New form",
      "surveyGroupId": 363200048,
      "defaultLanguageCode": "en",
      "requireApproval": false,
      "createdDateTime": 1613141078594,
      "lastUpdateDateTime": 1613553020694,
      "sourceId": null,
      "ancestorIds": [
        0,
        2000001,
        363200048
      ],
      "alias": null,
      "translationMap": null
    }

questionGroupList should be a json array:

[
    {
      "keyId": 363340042,
      "questionList": null,
      "code": "New group - please change name",
      "surveyId": 352160049,
      "order": 1,
      "path": "test translation tip/New form",
      "name": "New group - please change name",
      "sourceId": null,
      "repeatable": false,
      "status": "READY",
      "immutable": false,
      "translationMap": null,
      "displayName": "New group - please change name"
    },
    {
      "keyId": 363200049,
      "questionList": null,
      "code": "New group - please change name",
      "surveyId": 352160049,
      "order": 2,
      "path": "test translation tip/New form",
      "name": "New group - please change name",
      "sourceId": null,
      "repeatable": false,
      "status": "READY",
      "immutable": false,
      "translationMap": null,
      "displayName": "New group - please change name"
    }
  ]

questionList should also be a json array:

[
    {
      "keyId": 379030042,
      "type": "FREE_TEXT",
      "tip": "Texts that are freely shown",
      "text": "Free text question",
      "translationMap": null,
      "dependentFlag": false,
      "allowMultipleFlag": false,
      "allowOtherFlag": false,
      "collapseable": false,
      "geoLocked": false,
      "requireDoubleEntry": false,
      "immutable": true,
      "dependentQuestionId": null,
      "dependentQuestionAnswer": null,
      "cascadeResourceId": null,
      "caddisflyResourceUuid": null,
      "metricId": null,
      "optionContainerDto": null,
      "questionHelpList": null,
      "questionGroupId": 379010042,
      "surveyId": 352660040,
      "variableName": "free_text",
      "order": 1,
      "mandatoryFlag": true,
      "path": "All Questions - Template/All Questions Form/First 4 quesitons",
      "allowDecimal": false,
      "allowSign": false,
      "minVal": null,
      "maxVal": null,
      "allowExternalSources": false,
      "localeNameFlag": true,
      "localeLocationFlag": false,
      "personalData": false,
      "allowPoints": false,
      "allowLine": false,
      "allowPolygon": false,
      "optionList": null,
      "questionOptions": null,
      "questionDependency": null,
      "sourceId": null,
      "levelNames": null,
      "name": null
    },
    {
      "keyId": 379030043,
      "type": "OPTION",
      "tip": "Along with a tooltip",
      "text": "An option question that should be copied correctly!",
      "translationMap": null,
      "dependentFlag": false,
      "allowMultipleFlag": false,
      "allowOtherFlag": false,
      "collapseable": false,
      "geoLocked": false,
      "requireDoubleEntry": false,
      "immutable": true,
      "dependentQuestionId": null,
      "dependentQuestionAnswer": null,
      "cascadeResourceId": null,
      "caddisflyResourceUuid": null,
      "metricId": null,
      "optionContainerDto": null,
      "questionHelpList": null,
      "questionGroupId": 379010042,
      "surveyId": 352660040,
      "variableName": null,
      "order": 2,
      "mandatoryFlag": true,
      "path": "All Questions - Template/All Questions Form/First 4 quesitons",
      "allowDecimal": false,
      "allowSign": false,
      "minVal": null,
      "maxVal": null,
      "allowExternalSources": false,
      "localeNameFlag": false,
      "localeLocationFlag": false,
      "personalData": false,
      "allowPoints": false,
      "allowLine": false,
      "allowPolygon": false,
      "optionList": null,
      "questionOptions": [
        365560004,
        365560005,
        365560006
      ],
      "questionDependency": null,
      "sourceId": null,
      "levelNames": null,
      "name": null
    }
]

optionList should also be a json array and contain options:

[
{
      "keyId": 371670047,
      "text": "Tomato",
      "code": null,
      "order": 1,
      "questionId": 352670040,
      "translationMap": null
    },
    {
      "keyId": 371670048,
      "text": "Pepper",
      "code": null,
      "order": 2,
      "questionId": 352670040,
      "translationMap": null
    }
]

Some fields may be unnecessary but I copied responses that already exist in the client.

As for the backend this implies I need to create new objects for Form, Group, Question since the onces we have wont work as they expect maps instead of lists.