From 8825ba1606e82bcf4ef9161cf08cf0153da1ca6b Mon Sep 17 00:00:00 2001 From: Reshmi V Nair <54312456+reshmi-nair@users.noreply.github.com> Date: Tue, 20 Jun 2023 18:13:44 +0530 Subject: [PATCH] LR-583 Merging Release 5.3.0 to master (#572) --- .circleci/config.yml | 2 +- README.md | 257 +++ ...Proxy Exhaust APIs.postman_collection.json | 124 ++ course-mw/course-actors-common/pom.xml | 5 + .../actor/exhaustjob/ExhaustJobActor.java | 86 + .../learner/actors/health/HealthActor.java | 27 +- .../learner/util/ContentSearchMock.java | 62 + .../org/sunbird/learner/util/ContentUtil.java | 2 +- .../java/org/sunbird/util/ExhaustAPIUtil.java | 143 ++ .../actor/exhaustjob/ExhaustJobActorTest.java | 177 ++ .../FrameworkForTextbookTocActorTest.json | 1 - ...MandatoryValueForTextbookTocActorTest.json | 1 - course-mw/pom.xml | 1 - course-mw/sunbird-util/cache-utils/pom.xml | 1 - .../sunbird-util/sunbird-cache-utils/pom.xml | 2 +- .../sunbird-util/sunbird-es-utils/pom.xml | 2 +- .../src/main/resources/reindexing/README.md | 166 +- .../dependency-reduced-pom.xml | 2 +- .../sunbird-util/sunbird-notification/pom.xml | 4 +- .../sunbird-platform-core/actor-util/pom.xml | 2 +- .../sunbird-platform-core/common-util/pom.xml | 8 +- .../common/models/response/Response.java | 5 +- .../models/response/ResponseParams.java | 4 + .../common/models/util/ActorOperations.java | 5 +- .../sunbird/common/models/util/JsonKey.java | 463 +---- .../common/responsecode/ResponseCode.java | 110 +- .../common/responsecode/ResponseMessage.java | 115 +- .../resources/externalresource.properties | 39 +- .../sunbird-commons/pom.xml | 5 + course-mw/sunbird-utils | 1 - course-mw/textbook-actors/.gitignore | 6 - course-mw/textbook-actors/pom.xml | 90 - .../content/textbook/FileExtension.java | 61 - .../textbook/TextBookTocFileConfig.java | 138 -- .../content/textbook/TextBookTocUploader.java | 435 ----- .../content/util/ContentCloudStore.java | 44 - .../sunbird/content/util/TextBookTocUtil.java | 173 -- .../textbook/TextbookActorOperation.java | 21 - .../actors/textbook/TextbookTocActor.java | 1627 ----------------- .../content/util/TextBookTocUtilTest.java | 99 - .../actors/textbook/TextbookTocActorTest.java | 411 ----- scripts/lms-config.sh | 77 + .../exhaustjob/ExhaustJobController.java | 55 + .../validator/ExhaustJobRequestValidator.java | 27 + .../textbook/TextbookController.java | 132 -- service/app/modules/ApplicationStart.java | 15 +- service/app/util/ACTOR_NAMES.java | 8 +- service/conf/application.conf | 12 +- service/conf/routes | 11 +- service/dependency-reduced-pom.xml | 2 +- service/pom.xml | 9 +- .../controllers/ApplicationStartTest.java | 32 + .../exhaustjob/ExhaustJobControllerTest.java | 86 + .../textbook/TextbookControllerTest.java | 54 - service/test/mapper/RequestMapperTest.java | 6 +- setup.md | 2 - 56 files changed, 1372 insertions(+), 4083 deletions(-) create mode 100644 api-tests/Collection/Proxy Exhaust APIs.postman_collection.json create mode 100644 course-mw/course-actors-common/src/main/java/org/sunbird/actor/exhaustjob/ExhaustJobActor.java create mode 100644 course-mw/course-actors-common/src/main/java/org/sunbird/learner/util/ContentSearchMock.java create mode 100644 course-mw/course-actors-common/src/main/java/org/sunbird/util/ExhaustAPIUtil.java create mode 100644 course-mw/course-actors-common/src/test/java/org/sunbird/actor/exhaustjob/ExhaustJobActorTest.java delete mode 100644 course-mw/course-actors-common/src/test/resources/FrameworkForTextbookTocActorTest.json delete mode 100644 course-mw/course-actors-common/src/test/resources/MandatoryValueForTextbookTocActorTest.json delete mode 160000 course-mw/sunbird-utils delete mode 100644 course-mw/textbook-actors/.gitignore delete mode 100644 course-mw/textbook-actors/pom.xml delete mode 100644 course-mw/textbook-actors/src/main/java/org/sunbird/content/textbook/FileExtension.java delete mode 100644 course-mw/textbook-actors/src/main/java/org/sunbird/content/textbook/TextBookTocFileConfig.java delete mode 100644 course-mw/textbook-actors/src/main/java/org/sunbird/content/textbook/TextBookTocUploader.java delete mode 100644 course-mw/textbook-actors/src/main/java/org/sunbird/content/util/ContentCloudStore.java delete mode 100644 course-mw/textbook-actors/src/main/java/org/sunbird/content/util/TextBookTocUtil.java delete mode 100644 course-mw/textbook-actors/src/main/java/org/sunbird/learner/actors/textbook/TextbookActorOperation.java delete mode 100644 course-mw/textbook-actors/src/main/java/org/sunbird/learner/actors/textbook/TextbookTocActor.java delete mode 100644 course-mw/textbook-actors/src/test/java/org/sunbird/content/util/TextBookTocUtilTest.java delete mode 100644 course-mw/textbook-actors/src/test/java/org/sunbird/learner/actors/textbook/TextbookTocActorTest.java create mode 100644 scripts/lms-config.sh create mode 100644 service/app/controllers/exhaustjob/ExhaustJobController.java create mode 100644 service/app/controllers/exhaustjob/validator/ExhaustJobRequestValidator.java delete mode 100644 service/app/controllers/textbook/TextbookController.java create mode 100644 service/test/controllers/ApplicationStartTest.java create mode 100644 service/test/controllers/exhaustjob/ExhaustJobControllerTest.java delete mode 100644 service/test/controllers/textbook/TextbookControllerTest.java diff --git a/.circleci/config.yml b/.circleci/config.yml index 3528e7112..33849763f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -25,7 +25,7 @@ jobs: name: sonar command: | JAVA_REPORT_PATHS=`find /home/circleci/project -iname jacoco.xml | awk 'BEGIN { RS = "" ; FS = "\n"; OFS = ","}{$1=$1; print $0}'` - mvn verify -DskipTests=true sonar:sonar -Dsonar.projectKey=project-sunbird_sunbird-course-service -Dsonar.organization=project-sunbird -Dsonar.host.url=https://sonarcloud.io -Dsonar.pullrequest.branch=$srcbranch -Dsonar.pullrequest.key=$CIRCLE_PR_NUMBER -Dsonar.pullrequest.base=$tarbranch -Dsonar.coverage.exclusions=**/sunbird-util/sunbird-platform-core/**,**/course-actors-common/**,**/textbook-actors/** -Dsonar.scala.coverage.reportPaths=/home/circleci/project/course-mw/enrolment-actor/target/scoverage.xml,/home/circleci/project/course-mw/sunbird-util/cache-utils/target/scoverage.xml -Dsonar.coverage.jacoco.xmlReportPaths=${JAVA_REPORT_PATHS} + mvn verify -DskipTests=true sonar:sonar -Dsonar.projectKey=project-sunbird_sunbird-course-service -Dsonar.organization=project-sunbird -Dsonar.host.url=https://sonarcloud.io -Dsonar.pullrequest.branch=$srcbranch -Dsonar.pullrequest.key=$CIRCLE_PR_NUMBER -Dsonar.pullrequest.base=$tarbranch -Dsonar.coverage.exclusions=**/sunbird-util/sunbird-platform-core/**,**/course-actors-common/** -Dsonar.scala.coverage.reportPaths=/home/circleci/project/course-mw/enrolment-actor/target/scoverage.xml,/home/circleci/project/course-mw/sunbird-util/cache-utils/target/scoverage.xml -Dsonar.coverage.jacoco.xmlReportPaths=${JAVA_REPORT_PATHS} workflows: version: 2.1 diff --git a/README.md b/README.md index 219030e97..612460f62 100644 --- a/README.md +++ b/README.md @@ -5,3 +5,260 @@ This is the repository for Sunbird learning management system (lms) micro-service. It provides the APIs for lms functionality of Sunbird. The code in this repository is licensed under MIT License unless otherwise noted. Please see the [LICENSE](https://github.com/project-sunbird/sunbird-lms-service/blob/master/LICENSE) file for details. +This readme file describes how to install and start course-service in your developement environment. +## Sunbird-course-service developement environment setup: +This readme file contains the instruction to set up and run the sunbird-course-service in local machine. + +### System Requirements + +### Prerequisites + +- Java 11 +- Latest Docker +- Latest Maven + (Only for Mac M1 use 3.8.8 Maven version) + +### Prepare folders for database data and logs + +To prepare folders for database data and logs, run the following command: + +```shell +mkdir -p ~/sunbird-dbs/cassandra ~/sunbird-dbs/es +export sunbird_dbs_path=~/sunbird-dbs +``` + +To verify the creation of folders, run: + +```shell +echo $sunbird_dbs_path +``` + +### Cassandra database setup in Docker + +1. To get the Cassandra image, use the following command: + +```shell +docker pull cassandra:3.11.6 +``` +For Mac M1 users follow the bellow command: +```shell +docker pull --platform=linux/amd64 cassandra:3.11.6 +``` + +For the network, you can either use an existing network or create a new one by executing the following command: +```shell +docker network create sunbird_db_network +``` + +2. To create the Cassandra instance, run the following command: +```shell +docker run -p 9042:9042 --name sunbird_cassandra \ + -v $sunbird_dbs_path/cassandra/data:/var/lib/cassandra \ + -v $sunbird_dbs_path/cassandra/logs:/opt/cassandra/logs \ + -v $sunbird_dbs_path/cassandra/backups:/mnt/backups \ + --network sunbird_db_network -d cassandra:3.11.6 +``` + + +For Mac M1 users follow the below command: +```shell +docker run --platform=linux/amd64 -p 9042:9042 --name sunbird_cassandra \ + -v $sunbird_dbs_path/cassandra/data:/var/lib/cassandra \ + -v $sunbird_dbs_path/cassandra/logs:/opt/cassandra/logs \ + -v $sunbird_dbs_path/cassandra/backups:/mnt/backups \ + --network sunbird_db_network -d cassandra:3.11.6 +``` + +3. To verify the setup, run the following command, which will show the status of Cassandra as up and running: + +```shell +docker ps -a | grep cassandra +``` + +## To create/load keyspaces and tables to Cassandra + +Click the link [sunbird-utils-cassandra-setup](https://github.com/Sunbird-Lern/sunbird-utils/tree/release-5.3.0#readme) +and follow the steps for creating/loading the Cassandra keyspaces and tables to your development environment. + +Note: It is mandatory to follow the instructions provided in the link. + +4. To verify the creation of keyspaces and tables, connect to the Cassandra Docker container using SSH and run the following command: + +```shell +docker exec -it sunbird_cassandra /bin/bash +``` + +## Setting up Elastic Search in Docker + +To set up Elastic Search in Docker, follow the below steps: + +1. Obtain the Elastic Search image by executing the following command: + +```shell +docker pull elasticsearch:6.8.11 +``` + +For Mac M1 users follow the bellow command: +```shell +docker pull --platform=linux/amd64 elasticsearch:6.8.11 +``` + +2. Create an Elastic Search instance by executing the following command to run it in a container: +```shell +docker run -p 9200:9200 --name sunbird_es -v +$sunbird_dbs_path/es/data:/usr/share/elasticsearch/data -v +$sunbird_dbs_path/es/logs://usr/share/elasticsearch/logs -v +$sunbird_dbs_path/es/backups:/opt/elasticsearch/backup +-e "discovery.type=single-node" --network sunbird_db_network +-d docker.elastic.co/elasticsearch/elasticsearch:6.8.11 +``` +For Mac M1 users follow the bellow command:: +```shell +docker run --platform=linux/amd64 -p 9200:9200 --name sunbird_es -v +$sunbird_dbs_path/es/data:/usr/share/elasticsearch/data -v +$sunbird_dbs_path/es/logs://usr/share/elasticsearch/logs -v +$sunbird_dbs_path/es/backups:/opt/elasticsearch/backup +-e "discovery.type=single-node" --network sunbird_db_network +-d docker.elastic.co/elasticsearch/elasticsearch:6.8.11 +``` + +The above command performs the following actions: +- "-p 9200:9200" maps the host's port 9200 to the container's port 9200, allowing access to the Elasticsearch API. +- "--name " assigns a name to the container, which can be used to reference it in other Docker commands. +- "-v /es/data:/usr/share/elasticsearch/data" mounts the host's directory "/es/data" as the Elasticsearch data directory inside the container. +- "-v /es/logs://usr/share/elasticsearch/logs" mounts the host's directory "/es/logs" as the Elasticsearch logs directory inside the container. +- "-v /es/backups:/opt/elasticsearch/backup" mounts the host's directory "/es/backups" as the Elasticsearch backups directory inside the container. +- "-e "discovery.type=single-node"" sets an environment variable "discovery.type" with the value "single-node", which tells Elasticsearch to start as a single-node cluster. +- "--network " assigns the container to a Docker network, which is used to connect the container to other containers in the same network. +- "-d" runs the container in detached mode, which allows it to run in the background. + +To verify the setup, execute the following command. It will display the elastic search status as up and running. +```shell +docker ps -a | grep es +``` + +If you are using an Ubuntu system, perform the following step to ensure that the necessary permissions are created for the folder: +```shell +chmod -R 777 sunbird-dbs/es +``` +### elastic search Indices and mappings setup + +Create indices for, +To create indices, follow these steps: + +1. Copy the JSON content of the index from the provided link below for each index. +2. Replace `` with the name of the index for which you want to create the mapping. +3. Replace `` with the JSON content you copied in step 1. + +Use the following api to create each index: + +``` +PUT {{es_host}}/ +Body : +``` + +Here's an example curl command for creating the `course-batch` index: + +``` +curl --location --request PUT 'localhost:9200/course-batch' \ +--header 'Content-Type: application/json' \ +--data '' +``` + +Make sure to replace `course-batch_json_content` with the name of the index JSON file for the corresponding index. + +Here's the list of indices to create and their corresponding links: +- [Course-batch](https://github.com/project-sunbird/sunbird-devops/blob/release-5.3.0-lern/ansible/roles/es-mapping/files/indices/course-batch.json) + +To create mappings for the listed indices, follow these steps: + +1. Copy the JSON content of the mapping from the provided link for each index. +2. Replace `` with the name of the index for which you want to create the mapping. +3. Replace `` with the JSON content you copied in step 1. + +Use the following api to create each mapping: + +``` +PUT {{es_host}}//_mapping/_doc +Body: +``` + +Here's an example curl command for creating the mapping for the `course-batch` index: + +``` +curl --location --request PUT 'localhost:9200/course-batch/_mapping/_doc' \ +--header 'Content-Type: application/json' \ +--data '' +``` + +Make sure to replace `` with the name of the mapping JSON file for the corresponding index. + +Here's the list of mappings to create and their corresponding links: + +- [Course-batch](https://github.com/project-sunbird/sunbird-devops/blob/release-5.3.0-lern/ansible/roles/es-mapping/files/mappings/course-batch-mapping.json) + +## Setting up Redis in Docker: + +To set up Redis database in Docker, please follow the below steps: + +1. Pull the Redis image from Docker Hub using the following command: +```shell +docker pull redis:4.0.0 +``` +2. Create a Redis instance by running it in a container with the following command: +```shell +docker run --name sunbird_redis -d -p 6379:6379 redis:4.0.0 +``` +3. To verify the Redis setup, run the following command to SSH into the Redis Docker container: +```shell +docker exec -it sunbird_redis bash +``` + +To set up Redis database in Docker for Mac M1, please follow the below steps: + +1. Pull the Redis image from Docker Hub using the following command: +```shell +docker pull --platform=linux/amd64 redis:5.0.7 +``` +2. Create a Redis instance by running it in a container with the following command: +```shell +docker run --platform=linux/amd64 --name sunbird_redis -d -p 6379:6379 redis:5.0.7 +``` +3. To verify the Redis setup, run the following command to SSH into the Redis Docker container: +```shell +docker exec -it sunbird_redis bash +``` +## Sunbird-course-service Setup + +To set up the batch service, follow the steps below: + +1. Clone the latest branch of the course service using the following command: +```shell +git clone https://github.com/Sunbird-Lern/sunbird-course-service.git +``` + +2. Set up the necessary environment variables by running the following script in the path `/sunbird-course-service`: +```shell +./scripts/lms-config.sh +``` + +3. Build the application using the following maven command in the path `/sunbird-course-service`: +```shell +mvn clean install -DskipTests +``` +Make sure the build is successful before proceeding to the next step. If the build is not successful, +fix any configuration issues and rebuild the application. + +4. Run the netty server using the following maven command in the path `/sunbird-course-service/service`: +```shell +mvn play2:run +``` + +5. Verify the database connections by running the following command: +```shell +curl --location --request GET 'http://localhost:9000/health’ +``` +If all connections are established successfully, the health status will be shown as 'true', otherwise it will be 'false'. + +Currently, the lms service is dependent on content read API for batch creation and User org service for getting user and organisation information. +We are planning to implement a mock service soon for these dependencies. diff --git a/api-tests/Collection/Proxy Exhaust APIs.postman_collection.json b/api-tests/Collection/Proxy Exhaust APIs.postman_collection.json new file mode 100644 index 000000000..4046a08e0 --- /dev/null +++ b/api-tests/Collection/Proxy Exhaust APIs.postman_collection.json @@ -0,0 +1,124 @@ +{ + "info": { + "_postman_id": "d0f28683-d050-49da-b7f4-07800b6fc11a", + "name": "Proxy Exhaust APIs", + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", + "_exporter_id": "9863223" + }, + "item": [ + { + "name": "{host}/v1/jobrequest/submit", + "request": { + "method": "POST", + "header": [ + { + "key": "x-authenticated-user-token", + "value": "{{auth_token}}", + "type": "text", + "description": "User token" + }, + { + "key": "Authorization", + "value": "{{kong_api_key}}", + "type": "text", + "description": "API key" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "x-channel-id", + "value": "{{organisation_id}}", + "type": "text", + "description": "Organisation id of the requestor" + }, + { + "key": "x-authenticated-userid", + "value": "{{requested_user_id}}", + "type": "text", + "description": "UserId of the requester - ORG_ADMIN, COURSE_MENTOR" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"request\": {\n \"tag\": \"do_2137002173427875841205_01370023185341644821\",\n \"requestedBy\": \"fca2925f-1eee-4654-9177-fece3fd6afc9\",\n \"dataset\": \"response-exhaust\",\n \"datasetConfig\": {\n \"batchId\": \"01370023185341644821\"\n },\n \"output_format\": \"csv\",\n \"encryptionKey\": \"encryption-keyencryption-keyencryption-keyencryption-keyencryption-key\"\n }\n}\n", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{host}}/api/course/v1/jobrequest/submit", + "host": [ + "{{host}}" + ], + "path": [ + "api", + "course", + "v1", + "jobrequest", + "submit" + ] + }, + "description": "This API will internally call ‘/dataset/v1/request/submit’ API in SB-Obsrv ‘On Demand Data Exhaust API’, to submit the on demand exhaust job request. The job status will be in the submitted state. \n\n- This API should encrypt the password using auto generated encryption key and pass it in the exhaust API request if the security level is L2 or L3. \n- L1 and L4 do not need encryption keys. \n- Fetch the security level using tenant preference APIs to check this.\n- Configure the exhaust api base url and endpoints." + }, + "response": [] + }, + { + "name": "{host}/v1/jobrequest/list", + "request": { + "method": "GET", + "header": [ + { + "key": "x-authenticated-user-token", + "value": "{{auth_token}}", + "type": "text", + "description": "User token" + }, + { + "key": "Authorization", + "value": "{{kong_api_key}}", + "type": "text", + "description": "API Key" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "x-channel-id", + "value": "{{organisation_id}}", + "type": "text", + "description": "Organisation id of the requestor" + }, + { + "key": "x-authenticated-userid", + "value": "{{requested_user_id}}", + "type": "text", + "description": "UserId of the requester - ORG_ADMIN, COURSE_MENTOR" + } + ], + "url": { + "raw": "{{host}}/api/course/v1/jobrequest/list/{{tag}}", + "host": [ + "{{host}}" + ], + "path": [ + "api", + "course", + "v1", + "jobrequest", + "list", + "{{tag}}" + ] + }, + "description": "This API will internally call ‘/dataset/v1/request/list API in Obsrv ‘On Demand Data Exhaust API’, to list all the requests that are specific to a tag" + }, + "response": [] + } + ] +} \ No newline at end of file diff --git a/course-mw/course-actors-common/pom.xml b/course-mw/course-actors-common/pom.xml index 4b6a904a2..454c99884 100644 --- a/course-mw/course-actors-common/pom.xml +++ b/course-mw/course-actors-common/pom.xml @@ -150,6 +150,11 @@ googleauth 1.1.2 + + com.squareup.okhttp3 + mockwebserver + 4.10.0 + ${basedir}/src/main/java diff --git a/course-mw/course-actors-common/src/main/java/org/sunbird/actor/exhaustjob/ExhaustJobActor.java b/course-mw/course-actors-common/src/main/java/org/sunbird/actor/exhaustjob/ExhaustJobActor.java new file mode 100644 index 000000000..b26f6b14d --- /dev/null +++ b/course-mw/course-actors-common/src/main/java/org/sunbird/actor/exhaustjob/ExhaustJobActor.java @@ -0,0 +1,86 @@ +package org.sunbird.actor.exhaustjob; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.sunbird.actor.base.BaseActor; +import org.sunbird.common.exception.ProjectCommonException; +import org.sunbird.common.models.response.Response; +import org.sunbird.common.models.util.ActorOperations; +import org.sunbird.common.models.util.JsonKey; +import org.sunbird.common.models.util.datasecurity.EncryptionService; +import org.sunbird.common.request.Request; +import org.sunbird.common.responsecode.ResponseCode; +import org.sunbird.util.ExhaustAPIUtil; + +import java.util.HashMap; +import java.util.Map; + +public class ExhaustJobActor extends BaseActor { + private ObjectMapper mapper = new ObjectMapper(); + private EncryptionService encryptionService = + org.sunbird.common.models.util.datasecurity.impl.ServiceFactory.getEncryptionServiceInstance( + null); + @Override + public void onReceive(Request request) throws Throwable { + if (request.getOperation().equalsIgnoreCase(ActorOperations.SUBMIT_JOB_REQUEST.getValue())) { + submitJobRequest(request); + } else if (request.getOperation().equalsIgnoreCase(ActorOperations.LIST_JOB_REQUEST.getValue())) { + listJobRequest(request); + } else { + onReceiveUnsupportedOperation(request.getOperation()); + } + } + + private void submitJobRequest(Request request) { + Response res = new Response(); + try{ + logger.info(request.getRequestContext(), "ExhaustJobActor:submitJobRequest: called "); + Map requestMap = request.getRequest(); + String passwordStr = (String) requestMap.get("encryptionKey"); + try { + passwordStr = encryptionService.encryptData(passwordStr); + requestMap.put("encryptionKey", passwordStr); + } catch (Exception e) { + ProjectCommonException.throwClientErrorException( + ResponseCode.internalError, null); + } + Map requestMapNew = new HashMap<>(); + requestMapNew.put(JsonKey.REQUEST, requestMap); + String queryRequestBody = mapper.writeValueAsString(requestMapNew); + + res = ExhaustAPIUtil.submitJobRequest(request.getRequestContext(), queryRequestBody, getExhaustAPIHeaders(request.getContext()), context().dispatcher()); + } catch (Exception e) { + logger.error(request.getRequestContext(), "ExhaustJobActor:submitJobRequest: Error occurred = " + e.getMessage(), e); + ProjectCommonException exception = + new ProjectCommonException( + ResponseCode.SERVER_ERROR.getErrorCode(), + ResponseCode.SERVER_ERROR.getErrorMessage(), + ResponseCode.SERVER_ERROR.getResponseCode()); + throw exception; + } + sender().tell(res, self()); + } + + private Map getExhaustAPIHeaders(Map requestHeader){ + Map headerNew = new HashMap(); + headerNew.put(JsonKey.X_CHANNEL_ID, requestHeader.get(JsonKey.CHANNEL)); + headerNew.put(JsonKey.X_AUTHENTICATED_USERID, requestHeader.get(JsonKey.REQUESTED_BY)); + headerNew.put(JsonKey.X_AUTHENTICATED_USER_TOKEN, requestHeader.get(JsonKey.X_AUTH_TOKEN)); + return headerNew; + } + private void listJobRequest(Request request) { + Response res = new Response(); + try{ + logger.info(request.getRequestContext(), "ExhaustJobActor:listJobRequest: called "); + res = ExhaustAPIUtil.listJobRequest(request.getRequestContext(), (String)request.getRequest().get(JsonKey.TAG), getExhaustAPIHeaders(request.getContext()), context().dispatcher()); + } catch (Exception e) { + logger.error(request.getRequestContext(), "ExhaustJobActor:listJobRequest: Error occurred = " + e.getMessage(), e); + ProjectCommonException exception = + new ProjectCommonException( + ResponseCode.SERVER_ERROR.getErrorCode(), + ResponseCode.SERVER_ERROR.getErrorMessage(), + ResponseCode.SERVER_ERROR.getResponseCode()); + throw exception; + } + sender().tell(res, self()); + } +} diff --git a/course-mw/course-actors-common/src/main/java/org/sunbird/learner/actors/health/HealthActor.java b/course-mw/course-actors-common/src/main/java/org/sunbird/learner/actors/health/HealthActor.java index f2c8c7055..74e837b6e 100644 --- a/course-mw/course-actors-common/src/main/java/org/sunbird/learner/actors/health/HealthActor.java +++ b/course-mw/course-actors-common/src/main/java/org/sunbird/learner/actors/health/HealthActor.java @@ -2,6 +2,7 @@ package org.sunbird.learner.actors.health; import org.apache.commons.lang3.StringUtils; +import org.apache.http.HttpHeaders; import org.sunbird.actor.base.BaseActor; import org.sunbird.cassandra.CassandraOperation; import org.sunbird.common.ElasticSearchHelper; @@ -22,6 +23,7 @@ import org.sunbird.learner.util.Util; import scala.concurrent.Future; +import javax.ws.rs.core.MediaType; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -155,7 +157,7 @@ private void checkAllComponentHealth() { responseList.add(ProjectUtil.createCheckResponse(LMS_SERVICE, false, null)); responseList.add(ProjectUtil.createCheckResponse(JsonKey.ACTOR_SERVICE, false, null)); try { - cassandraOperation.getAllRecords(null, pagesDbInfo.getKeySpace(), pagesDbInfo.getTableName()); +// cassandraOperation.getAllRecords(null, pagesDbInfo.getKeySpace(), pagesDbInfo.getTableName()); responseList.add(ProjectUtil.createCheckResponse(JsonKey.CASSANDRA_SERVICE, false, null)); } catch (Exception e) { responseList.add(ProjectUtil.createCheckResponse(JsonKey.CASSANDRA_SERVICE, true, e)); @@ -176,24 +178,27 @@ private void checkAllComponentHealth() { String body = "{\"request\":{\"filters\":{\"identifier\":\"test\"}}}"; Map headers = new HashMap<>(); headers.put( - JsonKey.AUTHORIZATION, JsonKey.BEARER + System.getenv(JsonKey.EKSTEP_AUTHORIZATION)); + JsonKey.AUTHORIZATION, JsonKey.BEARER + System.getenv(JsonKey.EKSTEP_AUTHORIZATION)); + headers.put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON); + headers.remove(HttpHeaders.ACCEPT_ENCODING.toLowerCase()); + headers.put(HttpHeaders.ACCEPT_ENCODING.toLowerCase(), "UTF-8"); if (StringUtils.isBlank(headers.get(JsonKey.AUTHORIZATION))) { headers.put( - JsonKey.AUTHORIZATION, - PropertiesCache.getInstance().getProperty(JsonKey.EKSTEP_AUTHORIZATION)); - headers.put("Content_Type", "application/json; charset=utf-8"); + JsonKey.AUTHORIZATION, + PropertiesCache.getInstance().getProperty(JsonKey.EKSTEP_AUTHORIZATION)); } String searchBaseUrl = ProjectUtil.getConfigValue(JsonKey.SEARCH_SERVICE_API_BASE_URL); String response = - HttpUtil.sendPostRequest( - searchBaseUrl - + PropertiesCache.getInstance().getProperty(JsonKey.EKSTEP_CONTENT_SEARCH_URL), - body, - headers); + HttpUtil.sendPostRequest( + searchBaseUrl + + PropertiesCache.getInstance().getProperty(JsonKey.EKSTEP_CONTENT_SEARCH_URL), + body, + headers); if (response.contains("OK")) { responseList.add(ProjectUtil.createCheckResponse(JsonKey.EKSTEP_SERVICE, false, null)); } else { responseList.add(ProjectUtil.createCheckResponse(JsonKey.EKSTEP_SERVICE, true, null)); + isallHealthy = false; } } catch (Exception e) { responseList.add(ProjectUtil.createCheckResponse(JsonKey.EKSTEP_SERVICE, true, null)); @@ -211,4 +216,4 @@ private void checkAllComponentHealth() { response.getResult().put(JsonKey.RESPONSE, finalResponseMap); sender().tell(response, self()); } -} +} \ No newline at end of file diff --git a/course-mw/course-actors-common/src/main/java/org/sunbird/learner/util/ContentSearchMock.java b/course-mw/course-actors-common/src/main/java/org/sunbird/learner/util/ContentSearchMock.java new file mode 100644 index 000000000..349570111 --- /dev/null +++ b/course-mw/course-actors-common/src/main/java/org/sunbird/learner/util/ContentSearchMock.java @@ -0,0 +1,62 @@ +package org.sunbird.learner.util; + +import okhttp3.mockwebserver.Dispatcher; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; +import okhttp3.mockwebserver.RecordedRequest; +import org.sunbird.common.models.util.LoggerUtil; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +public class ContentSearchMock { + + private static final Map RESPONSES = new HashMap<>(); + private static LoggerUtil logger = new LoggerUtil(ContentSearchMock.class); + private static final String CONTENT_TYPE = "Content-Type"; + private static final String HEADER = "application/json"; + private static final Dispatcher DISPATCHER = new Dispatcher() { + @Override + public MockResponse dispatch(RecordedRequest request) { + String path = request.getPath(); + return RESPONSES.getOrDefault(path, new MockResponse().setResponseCode(404)); + } + }; + private static MockWebServer server; + + private ContentSearchMock() { + } + + public static void setup() throws IOException { + server = new MockWebServer(); + server.setDispatcher(DISPATCHER); + server.start(9080); + + RESPONSES.put("/content/v3/read/" + "do_2137525270494330881314?fields=status,batches,leafNodesCount", + new MockResponse() + .setHeader(CONTENT_TYPE, HEADER) + .setResponseCode(200) + .setBody("{\"id\":\"api.content.read\",\"ver\":\"1.0\",\"ts\":\"2023-04-28T11:13:36.611Z\",\"params\":{\"resmsgid\":\"b887eb30-e5b5-11ed-9d5b-d30bfb2743aa\",\"msgid\":\"b8852c10-e5b5-11ed-b223-294888a1bb2f\",\"status\":\"successful\",\"err\":null,\"errmsg\":null},\"responseCode\":\"OK\",\"result\":{\"content\":{\"ownershipType\":[\"createdBy\"],\"copyright\":\"tn\",\"se_gradeLevelIds\":[\"tn_k-12_5_gradelevel_class10\",\"tn_k-12_5_gradelevel_class11\",\"tn_k-12_5_gradelevel_class12\",\"tn_k-12_5_gradelevel_class1\",\"tn_k-12_5_gradelevel_class2\",\"tn_k-12_5_gradelevel_class3\",\"tn_k-12_5_gradelevel_class4\",\"tn_k-12_5_gradelevel_class5\",\"tn_k-12_5_gradelevel_class6\",\"tn_k-12_5_gradelevel_class7\",\"tn_k-12_5_gradelevel_class8\",\"tn_k-12_5_gradelevel_class9\"],\"keywords\":[\"test\"],\"subject\":[\"Basic Civil Engineering - Practical\"],\"targetMediumIds\":[\"tn_k-12_5_medium_english\",\"tn_k-12_5_medium_tamil\"],\"channel\":\"01269878797503692810\",\"downloadUrl\":\"https://sunbirddevbbpublic.blob.core.windows.net/sunbird-content-dev/content/do_213754130660818944126/l1-course_1678971250268_do_213754130660818944126_1_SPINE.ecar\",\"organisation\":[\"Tamil Nadu\"],\"language\":[\"English\"],\"mimeType\":\"application/vnd.ekstep.content-collection\",\"variants\":{\"spine\":{\"ecarUrl\":\"https://sunbirddevbbpublic.blob.core.windows.net/sunbird-content-dev/content/do_213754130660818944126/l1-course_1678971250268_do_213754130660818944126_1_SPINE.ecar\",\"size\":\"19243\"},\"online\":{\"ecarUrl\":\"https://sunbirddevbbpublic.blob.core.windows.net/sunbird-content-dev/content/do_213754130660818944126/l1-course_1678971250557_do_213754130660818944126_1_ONLINE.ecar\",\"size\":\"7427\"}},\"leafNodes\":[\"do_2135323699826606081233\",\"do_21337188080177971211\"],\"targetGradeLevelIds\":[\"tn_k-12_5_gradelevel_class10\",\"tn_k-12_5_gradelevel_class11\",\"tn_k-12_5_gradelevel_class12\",\"tn_k-12_5_gradelevel_class1\",\"tn_k-12_5_gradelevel_class2\",\"tn_k-12_5_gradelevel_class3\",\"tn_k-12_5_gradelevel_class4\",\"tn_k-12_5_gradelevel_class5\",\"tn_k-12_5_gradelevel_class6\",\"tn_k-12_5_gradelevel_class7\",\"tn_k-12_5_gradelevel_class8\",\"tn_k-12_5_gradelevel_class9\"],\"objectType\":\"Content\",\"se_mediums\":[\"English\",\"Tamil\"],\"primaryCategory\":\"Course\",\"appId\":\"staging.sunbird.portal\",\"contentEncoding\":\"gzip\",\"lockKey\":\"5f98d8fe-872d-4708-a55a-92e05190c8c8\",\"generateDIALCodes\":\"No\",\"totalCompressedSize\":1498116,\"mimeTypesCount\":\"{\\\"application/pdf\\\":1,\\\"application/vnd.ekstep.ecml-archive\\\":1,\\\"application/vnd.ekstep.content-collection\\\":1}\",\"sYS_INTERNAL_LAST_UPDATED_ON\":\"2023-03-16T12:54:10.266+0000\",\"contentType\":\"Course\",\"se_gradeLevels\":[\"Class 10\",\"Class 11\",\"Class 12\",\"Class 1\",\"Class 2\",\"Class 3\",\"Class 4\",\"Class 5\",\"Class 6\",\"Class 7\",\"Class 8\",\"Class 9\"],\"trackable\":{\"enabled\":\"Yes\",\"autoBatch\":\"No\"},\"identifier\":\"do_213754130660818944126\",\"audience\":[\"Student\"],\"se_boardIds\":[\"tn_k-12_5_board_statetamilnadu\"],\"subjectIds\":[\"tn_k-12_5_subject_basiccivilengineeringpractical\"],\"toc_url\":\"https://sunbirddevbbpublic.blob.core.windows.net/sunbird-content-dev/content/do_213754130660818944126/artifact/do_213754130660818944126_toc.json\",\"visibility\":\"Default\",\"contentTypesCount\":\"{\\\"SelfAssess\\\":1,\\\"Resource\\\":1,\\\"CourseUnit\\\":1}\",\"author\":\"newtncc\",\"consumerId\":\"c24a9706-93e0-47e8-a39e-862e71b9b026\",\"childNodes\":[\"do_2135323699826606081233\",\"do_213754131124731904131\",\"do_21337188080177971211\"],\"discussionForum\":{\"enabled\":\"Yes\"},\"mediaType\":\"content\",\"osId\":\"org.ekstep.quiz.app\",\"languageCode\":[\"en\"],\"lastPublishedBy\":\"91a81041-bbbd-4bd7-947f-09f9e469213c\",\"version\":2,\"se_subjects\":[\"Basic Civil Engineering - Practical\"],\"license\":\"CC BY 4.0\",\"prevState\":\"Review\",\"size\":19243,\"lastPublishedOn\":\"2023-03-16T12:54:10.194+0000\",\"name\":\"L1 course\",\"targetBoardIds\":[\"tn_k-12_5_board_statetamilnadu\"],\"status\":\"Live\",\"code\":\"org.sunbird.lFrel6\",\"credentials\":{\"enabled\":\"Yes\"},\"prevStatus\":\"Processing\",\"description\":\"Enter description for Course\",\"idealScreenSize\":\"normal\",\"createdOn\":\"2023-03-16T12:50:27.939+0000\",\"reservedDialcodes\":{\"F5D3D2\":0},\"batches\":[{\"createdFor\":[\"01269878797503692810\"],\"endDate\":null,\"name\":\"123\",\"batchId\":\"0137541355703173128\",\"enrollmentType\":\"open\",\"enrollmentEndDate\":null,\"startDate\":\"2023-03-16\",\"status\":1}],\"se_boards\":[\"State (Tamil Nadu)\"],\"targetSubjectIds\":[\"tn_k-12_5_subject_accountancy\"],\"se_mediumIds\":[\"tn_k-12_5_medium_english\",\"tn_k-12_5_medium_tamil\"],\"copyrightYear\":2023,\"contentDisposition\":\"inline\",\"additionalCategories\":[\"Lesson Plan\",\"Textbook\"],\"lastUpdatedOn\":\"2023-03-16T12:54:10.666+0000\",\"dialcodeRequired\":\"No\",\"lastStatusChangedOn\":\"2023-03-16T12:54:10.666+0000\",\"createdFor\":[\"01269878797503692810\"],\"creator\":\"newtncc\",\"os\":[\"All\"],\"se_subjectIds\":[\"tn_k-12_5_subject_basiccivilengineeringpractical\",\"tn_k-12_5_subject_accountancy\"],\"se_FWIds\":[\"tn_k-12_5\"],\"targetFWIds\":[\"tn_k-12_5\"],\"pkgVersion\":1,\"versionKey\":\"1678971216414\",\"idealScreenDensity\":\"hdpi\",\"framework\":\"tn_k-12_5\",\"dialcodes\":[\"F5D3D2\"],\"depth\":0,\"s3Key\":\"content/do_213754130660818944126/artifact/do_213754130660818944126_toc.json\",\"lastSubmittedOn\":\"2023-03-16T12:53:35.402+0000\",\"createdBy\":\"deec6352-0f62-4306-9818-aba349a0e0f8\",\"compatibilityLevel\":4,\"leafNodesCount\":2,\"userConsent\":\"Yes\",\"resourceType\":\"Course\"}}}")); + RESPONSES.put("/content/v3/search", + new MockResponse() + .setHeader(CONTENT_TYPE, HEADER) + .setResponseCode(200) + .setBody("{\"id\":\"api.content.search\",\"ver\":\"1.0\",\"ts\":\"2023-02-16T07:19:30.405Z\",\"params\":{\"resmsgid\":\"4102b950-adca-11ed-90b2-b7bf811d5c69\",\"msgid\":\"40fbdb80-adca-11ed-a723-4b0cc0e91be5\",\"status\":\"successful\",\"err\":null,\"errmsg\":null},\"responseCode\":\"OK\",\"result\":{\"count\":712392,\"content\":[{\"ownershipType\":[\"createdBy\"],\"publish_type\":\"public\",\"unitIdentifiers\":[\"do_21337599437489766414999\"],\"copyright\":\"Test axis,2126\",\"se_gradeLevelIds\":[\"ekstep_ncert_k-12_gradelevel_class10\"],\"previewUrl\":\"https://obj.stage.sunbirded.org/sunbird-content-staging/content/do_21337600715072307215013/artifact/do_21337600715072307215013_1632814051137_do_21337600715072307215013_1632813407308_pdf_229.pdf\",\"organisationId\":\"c5b2b2b9-fafa-4909-8d5d-f9458d1a3881\",\"keywords\":[\"All_Contents\"],\"subject\":[\"Hindi\"],\"downloadUrl\":\"https://obj.stage.sunbirded.org/sunbird-content-staging/content/do_21337600715072307215013/learning-resource_1671091450835_do_21337600715072307215013_2.ecar\",\"channel\":\"b00bc992ef25f1a9a8d63291e20efc8d\",\"language\":[\"English\"],\"variants\":{\"full\":{\"ecarUrl\":\"https://obj.stage.sunbirded.org/sunbird-content-staging/content/do_21337600715072307215013/learning-resource_1671091450835_do_21337600715072307215013_2.ecar\",\"size\":\"262229\"},\"spine\":{\"ecarUrl\":\"https://obj.stage.sunbirded.org/sunbird-content-staging/content/do_21337600715072307215013/learning-resource_1671091451013_do_21337600715072307215013_2_SPINE.ecar\",\"size\":\"7647\"}},\"source\":\"https://dockstaging.sunbirded.org/api/content/v1/read/do_21337600715072307215013\",\"mimeType\":\"application/pdf\",\"objectType\":\"Content\",\"se_mediums\":[\"English\"],\"appIcon\":\"https://stagingdock.blob.core.windows.net/sunbird-content-dock/content/do_21337600715072307215013/artifact/apple-fruit.thumb.jpg\",\"gradeLevel\":[\"Class 10\"],\"primaryCategory\":\"Learning Resource\",\"appId\":\"staging.dock.portal\",\"artifactUrl\":\"https://obj.stage.sunbirded.org/sunbird-content-staging/content/do_21337600715072307215013/artifact/do_21337600715072307215013_1632814051137_do_21337600715072307215013_1632813407308_pdf_229.pdf\",\"contentEncoding\":\"identity\",\"contentType\":\"PreviousBoardExamPapers\",\"se_gradeLevels\":[\"Class 10\"],\"trackable\":{\"enabled\":\"No\",\"autoBatch\":\"No\"},\"identifier\":\"do_213754130660818944126\",\"se_boardIds\":[\"ekstep_ncert_k-12_board_cbse\"],\"subjectIds\":[\"ekstep_ncert_k-12_subject_hindi\"],\"audience\":[\"Student\"],\"visibility\":\"Default\",\"consumerId\":\"cb069f8d-e4e1-46c5-831f-d4a83b323ada\",\"author\":\"paul1\",\"discussionForum\":{\"enabled\":\"No\"},\"mediaType\":\"content\",\"osId\":\"org.ekstep.quiz.app\",\"lastPublishedBy\":\"9c9b3259-f137-491a-bae5-fe2ad1763647\",\"languageCode\":[\"en\"],\"graph_id\":\"domain\",\"nodeType\":\"DATA_NODE\",\"version\":2,\"pragma\":[\"external\"],\"se_subjects\":[\"Hindi\"],\"prevState\":\"Review\",\"license\":\"CC BY 4.0\",\"lastPublishedOn\":\"2019-11-15 05:41:50:382+0000\",\"size\":270173,\"name\":\"24 aug course\",\"topic\":[\"कर चले हम फ़िदा\"],\"mediumIds\":[\"ekstep_ncert_k-12_medium_english\"],\"attributions\":[]}]}}")); + RESPONSES.put("/system/v3/content/update/", + new MockResponse() + .setHeader(CONTENT_TYPE, HEADER) + .setResponseCode(200) + .setBody("{\"id\":\"api.content.update\",\"ver\":\"4.0\",\"ts\":\"2020-12-10T20:26:07ZZ\",\"params\":{\"resmsgid\":\"80aa9310-b749-411c-a13b-8d9f25af389f\",\"msgid\":null,\"err\":null,\"status\":\"successful\",\"errmsg\":null},\"responseCode\":\"OK\",\"result\":{\"identifier\":\"do_213754130660818944126\",\"node_id\":\"do_213754130660818944126\",\"versionKey\":\"1607631967842\"}}")); + + // Register shutdown hook + Runtime.getRuntime().addShutdownHook(new Thread(() -> { + try { + server.shutdown(); + } catch (IOException e) { + logger.info(null,"Error setting up ContentSearchMock:"+e); + } + })); + } + +} \ No newline at end of file diff --git a/course-mw/course-actors-common/src/main/java/org/sunbird/learner/util/ContentUtil.java b/course-mw/course-actors-common/src/main/java/org/sunbird/learner/util/ContentUtil.java index 8576d4ef2..f4be11786 100644 --- a/course-mw/course-actors-common/src/main/java/org/sunbird/learner/util/ContentUtil.java +++ b/course-mw/course-actors-common/src/main/java/org/sunbird/learner/util/ContentUtil.java @@ -129,7 +129,7 @@ public static Map getContent(String courseId, List field Map headers = new HashMap<>(); try { String fieldsStr = StringUtils.join(fields, ","); - String baseContentreadUrl = ProjectUtil.getConfigValue(JsonKey.EKSTEP_BASE_URL) + "/content/v3/read/" + courseId + "?fields=" + fieldsStr; + String baseContentreadUrl = ProjectUtil.getConfigValue(JsonKey.EKSTEP_BASE_URL) + PropertiesCache.getInstance().getProperty(JsonKey.CONTENT_READ_URL) + courseId + "?fields=" + fieldsStr; headers.put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON); headers.put(JsonKey.AUTHORIZATION, PropertiesCache.getInstance().getProperty(JsonKey.EKSTEP_AUTHORIZATION)); diff --git a/course-mw/course-actors-common/src/main/java/org/sunbird/util/ExhaustAPIUtil.java b/course-mw/course-actors-common/src/main/java/org/sunbird/util/ExhaustAPIUtil.java new file mode 100644 index 000000000..fa9112dff --- /dev/null +++ b/course-mw/course-actors-common/src/main/java/org/sunbird/util/ExhaustAPIUtil.java @@ -0,0 +1,143 @@ +package org.sunbird.util; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.mashape.unirest.http.HttpResponse; +import com.mashape.unirest.http.Unirest; +import com.mashape.unirest.http.exceptions.UnirestException; +import org.apache.commons.lang3.StringUtils; +import org.apache.http.HttpHeaders; +import org.sunbird.common.exception.ProjectCommonException; +import org.sunbird.common.models.response.Response; +import org.sunbird.common.models.util.JsonKey; +import org.sunbird.common.models.util.LoggerUtil; +import org.sunbird.common.models.util.PropertiesCache; +import org.sunbird.common.request.RequestContext; +import org.sunbird.common.responsecode.ResponseCode; +import scala.concurrent.ExecutionContextExecutor; + +import javax.ws.rs.core.MediaType; +import java.util.HashMap; +import java.util.Map; + +public class ExhaustAPIUtil { + + private static LoggerUtil logger = new LoggerUtil(ExhaustAPIUtil.class); + private static ObjectMapper mapper = new ObjectMapper(); + private static String exhaustAPISubmitURL = null; + private static String exhaustAPIListURL = null; + static { + String baseUrl = System.getenv(JsonKey.EXHAUST_API_BASE_URL); + String submitPath = System.getenv(JsonKey.EXHAUST_API_SUBMIT_ENDPOINT); + String listPath = System.getenv(JsonKey.EXHAUST_API_LIST_ENDPOINT); + if (StringUtils.isBlank(baseUrl)) + baseUrl = PropertiesCache.getInstance().getProperty(JsonKey.EXHAUST_API_BASE_URL); + if (StringUtils.isBlank(submitPath)) + submitPath = PropertiesCache.getInstance().getProperty(JsonKey.EXHAUST_API_SUBMIT_ENDPOINT); + if (StringUtils.isBlank(listPath)) + listPath = PropertiesCache.getInstance().getProperty(JsonKey.EXHAUST_API_LIST_ENDPOINT); + exhaustAPISubmitURL = baseUrl + submitPath; + exhaustAPIListURL = baseUrl + listPath; + } + + private static Map getUpdatedHeaders(Map headers) { + if (headers == null) { + headers = new HashMap<>(); + } + headers.put( + HttpHeaders.AUTHORIZATION, JsonKey.BEARER + System.getenv(JsonKey.SUNBIRD_AUTHORIZATION)); + headers.put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON); + headers.put("Connection", "Keep-Alive"); + return headers; + } + + public static Response submitJobRequest( RequestContext requestContext, + String queryRequestBody, Map header, + ExecutionContextExecutor ec) { + Unirest.clearDefaultHeaders(); + Response responseObj = null; + + try { + mapper = mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,false); + + logger.info(requestContext, "ExhaustJobActor:submitJobRequest: url :"+exhaustAPISubmitURL + +", header : "+ header + +", request : " + queryRequestBody); + HttpResponse apiResponse = + Unirest.post(exhaustAPISubmitURL).headers(getUpdatedHeaders(header)).body(queryRequestBody).asString(); + logger.info(requestContext, "Exhaust API submit report apiResponse1 : " + apiResponse == null?"null" : ""+apiResponse.getStatus()); + if (null != apiResponse && apiResponse.getStatus()== ResponseCode.OK.getResponseCode()) { + logger.info(requestContext, "Exhaust API submit report call success"); + responseObj = mapper.readValue(apiResponse.getBody(), Response.class); + } else { + logger.info(requestContext, "Exhaust API submit report call failed : "+apiResponse.getStatusText() + +" : "+apiResponse.getBody()); + ProjectCommonException.throwServerErrorException( + ResponseCode.customServerError, "Exhaust API submit report apiResponse2 : " + apiResponse ); + } + } catch (JsonMappingException e) { + logger.error(requestContext, "Exhaust API submit report call failed : JsonMappingException : " + e.getMessage(), e); + ProjectCommonException.throwServerErrorException( + ResponseCode.customServerError, e.getMessage()); + } catch (UnirestException e) { + logger.error(requestContext, "Exhaust API submit report call failed : UnirestException : " + e.getMessage(), e); + ProjectCommonException.throwServerErrorException( + ResponseCode.customServerError, e.getMessage()); + } catch (JsonProcessingException e) { + logger.error(requestContext, "Exhaust API submit report call failed : JsonProcessingException : " + e.getMessage(), e); + ProjectCommonException.throwServerErrorException( + ResponseCode.customServerError, e.getMessage()); + } catch ( ProjectCommonException e) { + throw e; + }catch (Exception e) { + logger.error(requestContext, "Exhaust API submit report call failed : " + e.getMessage(), e); + ProjectCommonException.throwServerErrorException( + ResponseCode.customServerError, e.getMessage()); + } + return responseObj; + } + public static Response listJobRequest( RequestContext requestContext, + String queryParam, Map header, + ExecutionContextExecutor ec) { + Unirest.clearDefaultHeaders(); + Response responseObj = null; + try { + logger.info(requestContext, "ExhaustJobActor:listJobRequest: url :"+exhaustAPIListURL + +", header : "+ header + +", request : " + queryParam); + HttpResponse apiResponse = + Unirest.get(exhaustAPIListURL+queryParam).headers(getUpdatedHeaders(header)).asString(); + logger.info(requestContext, "Exhaust API submit report apiResponse1 : " + apiResponse == null?"null" : ""+apiResponse.getStatus()); + if (null != apiResponse && apiResponse.getStatus()== ResponseCode.OK.getResponseCode()) { + logger.info(requestContext, "Exhaust API submit report call success"); + responseObj = mapper.readValue(apiResponse.getBody(), Response.class); + } else { + logger.info(requestContext, "Exhaust API submit report call failed : "+apiResponse.getStatusText() + +" : "+apiResponse.getBody()); + ProjectCommonException.throwServerErrorException( + ResponseCode.customServerError, "Exhaust API submit report apiResponse2 : " + apiResponse ); + } + } catch (JsonMappingException e) { + logger.error(requestContext, "Exhaust API report list call failed : JsonMappingException : " + e.getMessage(), e); + ProjectCommonException.throwServerErrorException( + ResponseCode.customServerError, e.getMessage()); + } catch (UnirestException e) { + logger.error(requestContext, "Exhaust API report list call failed : UnirestException : " + e.getMessage(), e); + ProjectCommonException.throwServerErrorException( + ResponseCode.customServerError, e.getMessage()); + } catch (JsonProcessingException e) { + logger.error(requestContext, "Exhaust API report list call failed : JsonProcessingException : " + e.getMessage(), e); + ProjectCommonException.throwServerErrorException( + ResponseCode.customServerError, e.getMessage()); + } catch ( ProjectCommonException e) { + throw e; + } catch (Exception e) { + logger.error(requestContext, "Exhaust API report list call failed : " + e.getMessage(), e); + ProjectCommonException.throwServerErrorException( + ResponseCode.customServerError, e.getMessage()); + } + return responseObj; + } +} diff --git a/course-mw/course-actors-common/src/test/java/org/sunbird/actor/exhaustjob/ExhaustJobActorTest.java b/course-mw/course-actors-common/src/test/java/org/sunbird/actor/exhaustjob/ExhaustJobActorTest.java new file mode 100644 index 000000000..e42724416 --- /dev/null +++ b/course-mw/course-actors-common/src/test/java/org/sunbird/actor/exhaustjob/ExhaustJobActorTest.java @@ -0,0 +1,177 @@ +package org.sunbird.actor.exhaustjob; + +import com.mashape.unirest.http.HttpResponse; +import com.mashape.unirest.http.Unirest; +import com.mashape.unirest.http.exceptions.UnirestException; +import com.mashape.unirest.request.GetRequest; +import com.mashape.unirest.request.HttpRequestWithBody; +import com.mashape.unirest.request.body.RequestBodyEntity; +import org.junit.Assert; +import org.junit.Before; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.MethodSorters; +import org.mockito.Mockito; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PowerMockIgnore; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.sunbird.application.test.SunbirdApplicationActorTest; +import org.sunbird.common.exception.ProjectCommonException; +import org.sunbird.common.models.response.Response; +import org.sunbird.common.models.util.ActorOperations; +import org.sunbird.common.models.util.JsonKey; +import org.sunbird.common.request.Request; + +import java.util.HashMap; +import java.util.Map; + +import static org.powermock.api.mockito.PowerMockito.when; + +@RunWith(PowerMockRunner.class) +@PowerMockIgnore({ + "javax.management.*", + "javax.net.ssl.*", + "javax.security.*","javax.crypto.*", + "jdk.internal.reflect.*", + "jdk.internal.util.*" +}) +@PrepareForTest({ + Unirest.class +}) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class ExhaustJobActorTest extends SunbirdApplicationActorTest { + @Before + public void setUp() { + init(ExhaustJobActor.class); + PowerMockito.mockStatic(Unirest.class); + } + + @Test + public void testSubmitJobRequestSuccess() throws Exception{ + mockJobSubmitResponse(); + Response response = executeInTenSeconds(createJobSubmitRequest(), Response.class); + Assert.assertNotNull(response); + } + @Test + public void testListJobRequestSuccess() throws Exception{ + mockListJobResponse(); + Response response = executeInTenSeconds(createListJobRequest(), Response.class); + Assert.assertNotNull(response); + } + + private Request createJobSubmitRequest() { + Request req = new Request(); + req.setOperation(ActorOperations.SUBMIT_JOB_REQUEST.getValue()); + Map requestMap = new HashMap<>(); + requestMap.put(JsonKey.TAG, "do_2137002173427875841205_01370023185341644822"); + requestMap.put(JsonKey.REQUESTED_BY, "fca2925f-1eee-4654-9177-fece3fd6afc9"); + requestMap.put(JsonKey.DATASET, "progress-exhaust"); + requestMap.put(JsonKey.CONTENT_TYPE, "Course"); + requestMap.put(JsonKey.OUTPUT_FORMAT, "csv"); + requestMap.put(JsonKey.ENCRYPTIONKEY, "test"); + requestMap.put(JsonKey.DATASETCONFIG, new HashMap<>().put(JsonKey.BATCH_ID,"01370023185341644822")); + req.setRequest(requestMap); + return req; + } + private void mockJobSubmitResponse() throws UnirestException { + HttpRequestWithBody http = Mockito.mock(HttpRequestWithBody.class); + RequestBodyEntity entity = Mockito.mock(RequestBodyEntity.class); + HttpResponse response = Mockito.mock(HttpResponse.class); + when(Unirest.post(Mockito.anyString())).thenReturn(http); + when(http.headers(Mockito.anyMap())).thenReturn(http); + when(http.body(Mockito.anyString())).thenReturn(entity); + when(entity.asString()).thenReturn(response); + when(response.getStatus()).thenReturn(200); + when(response.getBody()).thenReturn("{\n" + + " \"id\": \"ekstep.analytics.dataset.request.submit\",\n" + + " \"ver\": \"1.0\",\n" + + " \"ts\": \"2020-06-29T08:31:03ZZ\",\n" + + " \"params\": {\n" + + " \"resmsgid\": \"7f88375d-4c59-4f3a-9626-be0fd3b3ad72\",\n" + + " \"msgid\": null,\n" + + " \"err\": null,\n" + + " \"status\": \"successful\",\n" + + " \"errmsg\": null,\n" + + " \"client_key\": null\n" + + " },\n" + + " \"responseCode\": \"OK\",\n" + + " \"result\": {\n" + + " \"attempts\": 0,\n" + + " \"lastUpdated\": 1683113415084,\n" + + " \"tag\": \"do_2137002173427875841205_01370023185341644822:01269878797503692810\",\n" + + " \"expiresAt\": 1683115215120,\n" + + " \"datasetConfig\": {\n" + + " \"batchId\": \"01370023185341644822\"\n" + + " },\n" + + " \"downloadUrls\": [],\n" + + " \"requestedBy\": \"fca2925f-1eee-4654-9177-fece3fd6afc9\",\n" + + " \"jobStats\": {\n" + + " \"dtJobSubmitted\": 1683113415084,\n" + + " \"dtJobCompleted\": null,\n" + + " \"executionTime\": null\n" + + " },\n" + + " \"status\": \"SUBMITTED\",\n" + + " \"dataset\": \"progress-exhaust\",\n" + + " \"requestId\": \"768A4C249657E994FC3F8FB2D86281FA\",\n" + + " \"requestedChannel\": \"01269878797503692810\"\n" + + " }\n" + + "}").thenThrow(ProjectCommonException.class); + } + private Request createListJobRequest() { + Request req = new Request(); + req.setOperation(ActorOperations.LIST_JOB_REQUEST.getValue()); + Map requestMap = new HashMap<>(); + requestMap.put(JsonKey.TAG, "do_2137002173427875841205_01370023185341644822"); + req.setRequest(requestMap); + return req; + } + private void mockListJobResponse() throws UnirestException { + GetRequest http = Mockito.mock(GetRequest.class); + HttpResponse response = Mockito.mock(HttpResponse.class); + when(Unirest.get(Mockito.anyString())).thenReturn(http); + when(http.headers(Mockito.anyMap())).thenReturn(http); + when(http.asString()).thenReturn(response); + when(response.getStatus()).thenReturn(200); + when(response.getBody()).thenReturn("{\n" + + " \"id\": \"eekstep.analytics.dataset.request.list\",\n" + + " \"ver\": \"1.0\",\n" + + " \"ts\": \"2020-06-29T08:31:03ZZ\",\n" + + " \"params\": {\n" + + " \"resmsgid\": \"7f88375d-4c59-4f3a-9626-be0fd3b3ad72\",\n" + + " \"msgid\": null,\n" + + " \"err\": null,\n" + + " \"status\": \"successful\",\n" + + " \"errmsg\": null,\n" + + " \"client_key\": null\n" + + " },\n" + + " \"responseCode\": \"OK\",\n" + + " \"result\": {\n" + + " \"count\": 3,\n" + + " \"jobs\": [\n" + + " {\n"+ + " \"attempts\": 0,\n" + + " \"lastUpdated\": 1683113415084,\n" + + " \"tag\": \"do_2137002173427875841205_01370023185341644822:01269878797503692810\",\n" + + " \"expiresAt\": 1683115215120,\n" + + " \"datasetConfig\": {\n" + + " \"batchId\": \"01370023185341644822\"\n" + + " },\n" + + " \"downloadUrls\": [],\n" + + " \"requestedBy\": \"fca2925f-1eee-4654-9177-fece3fd6afc9\",\n" + + " \"jobStats\": {\n" + + " \"dtJobSubmitted\": 1683113415084,\n" + + " \"dtJobCompleted\": null,\n" + + " \"executionTime\": null\n" + + " },\n" + + " \"status\": \"SUBMITTED\",\n" + + " \"dataset\": \"progress-exhaust\",\n" + + " \"requestId\": \"768A4C249657E994FC3F8FB2D86281FA\",\n" + + " \"requestedChannel\": \"01269878797503692810\"\n" + + " }\n"+ + " ]\n"+ + " }\n" + + "}").thenThrow(ProjectCommonException.class); + } +} diff --git a/course-mw/course-actors-common/src/test/resources/FrameworkForTextbookTocActorTest.json b/course-mw/course-actors-common/src/test/resources/FrameworkForTextbookTocActorTest.json deleted file mode 100644 index ce216c1eb..000000000 --- a/course-mw/course-actors-common/src/test/resources/FrameworkForTextbookTocActorTest.json +++ /dev/null @@ -1 +0,0 @@ -{ "identifier":"Identifier","frameworkCategories":{"medium":"Medium","gradeLevel":"Grade","subject":"Subject"},"hierarchy":{"Textbook":"Textbook Name","L:1":"Level 1 Textbook Unit","L:2":"Level 2 Textbook Unit","L:3":"Level 3 Textbook Unit","L:4":"Level 4 Textbook Unit"},"metadata":{"description":"Description","dialcodeRequired":"QR Code Required?","dialcodes":"QR Code","purpose":"Purpose of Content to be linked","topic":"Mapped Topics","keywords":"Keywords"}} \ No newline at end of file diff --git a/course-mw/course-actors-common/src/test/resources/MandatoryValueForTextbookTocActorTest.json b/course-mw/course-actors-common/src/test/resources/MandatoryValueForTextbookTocActorTest.json deleted file mode 100644 index bd644ecf0..000000000 --- a/course-mw/course-actors-common/src/test/resources/MandatoryValueForTextbookTocActorTest.json +++ /dev/null @@ -1 +0,0 @@ -{"Textbook":"Textbook Name","L:1":"Level 1 Textbook Unit"} \ No newline at end of file diff --git a/course-mw/pom.xml b/course-mw/pom.xml index e823c7c80..38568dd8b 100644 --- a/course-mw/pom.xml +++ b/course-mw/pom.xml @@ -17,7 +17,6 @@ sunbird-util course-actors-common course-actors - textbook-actors enrolment-actor diff --git a/course-mw/sunbird-util/cache-utils/pom.xml b/course-mw/sunbird-util/cache-utils/pom.xml index be59f7c57..5723ac2f6 100644 --- a/course-mw/sunbird-util/cache-utils/pom.xml +++ b/course-mw/sunbird-util/cache-utils/pom.xml @@ -7,7 +7,6 @@ org.sunbird 1.0-SNAPSHOT - org.sunbird cache-utils 0.0.1-SNAPSHOT jar diff --git a/course-mw/sunbird-util/sunbird-cache-utils/pom.xml b/course-mw/sunbird-util/sunbird-cache-utils/pom.xml index 75e6990d2..a2e59fabf 100644 --- a/course-mw/sunbird-util/sunbird-cache-utils/pom.xml +++ b/course-mw/sunbird-util/sunbird-cache-utils/pom.xml @@ -56,7 +56,7 @@ junit junit - 4.12 + 4.13.1 test diff --git a/course-mw/sunbird-util/sunbird-es-utils/pom.xml b/course-mw/sunbird-util/sunbird-es-utils/pom.xml index a5f477d85..068b378ee 100644 --- a/course-mw/sunbird-util/sunbird-es-utils/pom.xml +++ b/course-mw/sunbird-util/sunbird-es-utils/pom.xml @@ -63,7 +63,7 @@ junit junit - 4.12 + 4.13.1 test diff --git a/course-mw/sunbird-util/sunbird-es-utils/src/main/resources/reindexing/README.md b/course-mw/sunbird-util/sunbird-es-utils/src/main/resources/reindexing/README.md index d1b3d5260..b53f38f30 100644 --- a/course-mw/sunbird-util/sunbird-es-utils/src/main/resources/reindexing/README.md +++ b/course-mw/sunbird-util/sunbird-es-utils/src/main/resources/reindexing/README.md @@ -1,35 +1,131 @@ -This is the script which will perform reindexing on Elasticsearch Index... - -## How to run - - give permission to the script chmod +x reindex.sh - - bash reindex.sh {{es_ip}} {{old_index}} {{new_index}} {{alias_name}} {{index_req_filePath}} {{mappings_req_filePath}} - - - -## CLI ARGS DESCRIPTION - - es_ip: Ip of ElasticSearch and port is assumed to be 9200 - - old_index: Source Index from which reindexing to be done - - new_index: Destination Index, to which reindexing to be done - - alias_name: Name of Alias to which new_index to be mapped and old index need to be removed. - - index_req_filepath: .json file path which will have a request body for creating new_index. - - mapping_req_filepath: .json file path which will have a request body for creating mappings of new_index. - - - **NOTE**: old_index will be deleted by the script.
- - - ## Following Steps will be done by Script: - - 1: Validating Input params - a) File paths - b) ElasticSearch health
- 2: *Creating Backup file.
- 3: mapping alias_name with `old_index`.
- 4: creating indices and mapping of `new_index`.
- 5: Reindexing from `old_index` index to `new_index` index.
- 6: deleting alias with `old_index` and mapping alias with `new_index`.
- 7: deleting `old_index`.
- - -*BackUp file may not contain all the ES records(due to size limit in ES).
-SOURCE : https://engineering.carsguide.com.au/elasticsearch-zero-downtime-reindexing-e3a53000f0ac +# sunbird-course-service + +Repository for Batch Service + +## sunbird-course-Service local setup +This readme file contains the instruction to set up and run the sunbird-course-service in local machine. + +### Prerequisites: +Java 11, +Maven - Latest, +Cassandra 3.11.6, +ES 6.8.11, +Redis 4.0.0, +GIT, +Docker - Latest + +### Create folders for database data and logs + +```shell +mkdir -p ~/sunbird-dbs/cassandra ~/sunbird-dbs/es +export sunbird_dbs_path=~/sunbird-dbs +``` + +### Cassandra database setup in docker: + + + +i. Get the cassandra image using below command +```shell +docker pull cassandra:3.11.6 +``` +ii. For the network, we can use the existing network or create a new network using the following command and use it. +```shell +docker network create sunbird_db_network +``` +iii. Run Cassandra +```shell +docker run -p 9042:9042 --name sunbird_cassandra -v $sunbird_dbs_path/cassandra/data:/var/lib/cassandra -v $sunbird_dbs_path/cassandra/logs:/opt/cassandra/logs -v $sunbird_dbs_path/cassandra/backups:/mnt/backups --network sunbird_db_network -d cassandra:3.11.6 +``` +Fork the below projects and clone it from git, +```shell +git clone https://github.com/Sunbird-Lern/sunbird-utils/ +``` +Open a new Terminal In the path, +#### (Project base path)/sunbird-utils +Run the below command, +```shell +mvn clean install -DskipTests +``` +Make sure the build is success and then, +open a new Terminal In the path, +#### (Project base path)/sunbird-utils/sunbird-cassandra-migration/cassandra-migration, +Run below command, +```shell +mvn clean install -DskipTests +``` +## One should execute only one of the commands listed below. +### Command 1: +```shell +java -jar \ +-Dcassandra.migration.scripts.locations=filesystem:/db/migration/cassandra \ +-Dcassandra.migration.cluster.contactpoints=localhost \ +-Dcassandra.migration.cluster.port=9042 \ +-Dcassandra.migration.cluster.username=username \ +-Dcassandra.migration.cluster.password=password \ +-Dcassandra.migration.keyspace.name=keyspace_name \ +target/*-jar-with-dependencies.jar migrate +``` +### replace keyspace_name as sunbird_courses and sunbird +### Command 2: +```shell +java -cp "cassandra-migration-0.0.1-SNAPSHOT-jar-with-dependencies.jar" com.contrastsecurity.cassandra.migration.utils.MigrationScriptEntryPoint +``` +The system environment listed below is required for command 2. +### System Env +```shell +sunbird_cassandra_keyspace= +sunbird_cassandra_migration_location="filesystem:/db/migration/cassandra" +``` + +### Elasticsearch database setup in docker: +i. Get the ES image using below command: +```shell +docker pull elasticsearch:6.8.11 +``` +ii. Run ES +```shell +docker run -p 9200:9200 --name sunbird_es -v $sunbird_dbs_path/es/data:/usr/share/elasticsearch/data -v $sunbird_dbs_path/es/logs://usr/share/elasticsearch/logs -v $sunbird_dbs_path/es/backups:/opt/elasticsearch/backup -e "discovery.type=single-node" --network sunbird_db_network -d docker.elastic.co/elasticsearch/elasticsearch:6.8.11 + +chmod -R 777 sunbird-dbs/es +``` +iii. ES Indices and Mappings +Get the index and mapping from these folders and create them using postman. +https://github.com/project-sunbird/sunbird-devops/tree/master/ansible/roles/es-mapping +PUT http://localhost:9200/ Body : +PUT http://localhost:9200//_mapping/_doc Body : + +### Redis setup in docker: +i. Get the Redis image using below command: +```shell +docker pull redis:4.0.0 +``` +ii. Run Redis +```shell +docker run --name sunbird_redis -d -p 6379:6379 redis:4.0.0 +``` +​ +### Batch Service Repo setup: +Repository url : git clone https://github.com//sunbird-course-service.git +Branch : + +i. Checkout the branch code from github after forking the repository. + +ii. Update the lms-service.sh file in the scripts folder with configuration values to setup environment variables and run it to export the values or add the variables to bashrc or bashprofile. +```shell +./scripts/lms-service.sh +``` +iii. Build using maven from sunbird-course-service folder +```shell +mvn clean install -DskipTests +``` +iii. Run the service from sunbird-course-service/service folder +```shell +mvn play2:run +``` +iv. Use the below curl to check the service health +```shell +curl --location --request GET 'http://localhost:9000/health' +``` + +The code in this repository is licensed under MIT License unless otherwise noted. Please see the [LICENSE](https://github.com/project-sunbird/sunbird-lms-service/blob/master/LICENSE) file for details. \ No newline at end of file diff --git a/course-mw/sunbird-util/sunbird-notification/dependency-reduced-pom.xml b/course-mw/sunbird-util/sunbird-notification/dependency-reduced-pom.xml index 7257c8d4a..98c1d9579 100644 --- a/course-mw/sunbird-util/sunbird-notification/dependency-reduced-pom.xml +++ b/course-mw/sunbird-util/sunbird-notification/dependency-reduced-pom.xml @@ -73,7 +73,7 @@ junit junit - 4.12 + 4.13.1 test diff --git a/course-mw/sunbird-util/sunbird-notification/pom.xml b/course-mw/sunbird-util/sunbird-notification/pom.xml index ac60abfa1..c6c867a3c 100644 --- a/course-mw/sunbird-util/sunbird-notification/pom.xml +++ b/course-mw/sunbird-util/sunbird-notification/pom.xml @@ -88,12 +88,12 @@ org.apache.httpcomponents httpclient - 4.5.2 + 4.5.13 junit junit - 4.12 + 4.13.1 test diff --git a/course-mw/sunbird-util/sunbird-platform-core/actor-util/pom.xml b/course-mw/sunbird-util/sunbird-platform-core/actor-util/pom.xml index d9fd56c04..a1f684343 100644 --- a/course-mw/sunbird-util/sunbird-platform-core/actor-util/pom.xml +++ b/course-mw/sunbird-util/sunbird-platform-core/actor-util/pom.xml @@ -56,7 +56,7 @@ junit junit - 3.8.1 + 4.13.1 test diff --git a/course-mw/sunbird-util/sunbird-platform-core/common-util/pom.xml b/course-mw/sunbird-util/sunbird-platform-core/common-util/pom.xml index d4a6ddc3f..d3a23b85f 100644 --- a/course-mw/sunbird-util/sunbird-platform-core/common-util/pom.xml +++ b/course-mw/sunbird-util/sunbird-platform-core/common-util/pom.xml @@ -22,7 +22,7 @@ junit junit - 4.12 + 4.13.1 test @@ -65,7 +65,7 @@ org.jboss.resteasy resteasy-client - 3.1.0.Final + 3.11.3.Final @@ -165,7 +165,7 @@ org.apache.httpcomponents httpclient - 4.5 + 4.5.13 @@ -262,7 +262,7 @@ org.apache.kafka kafka-clients - 0.10.0.1 + 0.10.2.2 diff --git a/course-mw/sunbird-util/sunbird-platform-core/common-util/src/main/java/org/sunbird/common/models/response/Response.java b/course-mw/sunbird-util/sunbird-platform-core/common-util/src/main/java/org/sunbird/common/models/response/Response.java index adbaed174..24e3d9ef3 100644 --- a/course-mw/sunbird-util/sunbird-platform-core/common-util/src/main/java/org/sunbird/common/models/response/Response.java +++ b/course-mw/sunbird-util/sunbird-platform-core/common-util/src/main/java/org/sunbird/common/models/response/Response.java @@ -1,15 +1,18 @@ package org.sunbird.common.models.response; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import org.sunbird.common.responsecode.ResponseCode; + import java.io.Serializable; import java.util.HashMap; import java.util.Map; -import org.sunbird.common.responsecode.ResponseCode; /** * This is a common response class for all the layer. All layer will send same response object. * * @author Manzarul */ +@JsonIgnoreProperties(ignoreUnknown = true) public class Response implements Serializable, Cloneable { private static final long serialVersionUID = -3773253896160786443L; diff --git a/course-mw/sunbird-util/sunbird-platform-core/common-util/src/main/java/org/sunbird/common/models/response/ResponseParams.java b/course-mw/sunbird-util/sunbird-platform-core/common-util/src/main/java/org/sunbird/common/models/response/ResponseParams.java index e46355168..d214aa666 100644 --- a/course-mw/sunbird-util/sunbird-platform-core/common-util/src/main/java/org/sunbird/common/models/response/ResponseParams.java +++ b/course-mw/sunbird-util/sunbird-platform-core/common-util/src/main/java/org/sunbird/common/models/response/ResponseParams.java @@ -1,5 +1,8 @@ package org.sunbird.common.models.response; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; + import java.io.Serializable; /** @@ -7,6 +10,7 @@ * * @author Manzarul */ +@JsonIgnoreProperties(ignoreUnknown = true) public class ResponseParams implements Serializable { private static final long serialVersionUID = 6772142067149203497L; diff --git a/course-mw/sunbird-util/sunbird-platform-core/common-util/src/main/java/org/sunbird/common/models/util/ActorOperations.java b/course-mw/sunbird-util/sunbird-platform-core/common-util/src/main/java/org/sunbird/common/models/util/ActorOperations.java index fb79c71bd..5dd589867 100644 --- a/course-mw/sunbird-util/sunbird-platform-core/common-util/src/main/java/org/sunbird/common/models/util/ActorOperations.java +++ b/course-mw/sunbird-util/sunbird-platform-core/common-util/src/main/java/org/sunbird/common/models/util/ActorOperations.java @@ -172,7 +172,10 @@ public enum ActorOperations { GET_USER_FEED_BY_ID("getUserFeedById"), CREATE_USER_V3("createUserV3"), ONDEMAND_START_SCHEDULER("onDemandStartScheduler"), - GROUP_ACTIVITY_AGGREGATES("groupActivityAggregates"); + GROUP_ACTIVITY_AGGREGATES("groupActivityAggregates"), + SUBMIT_JOB_REQUEST("submitJobRequest"), + LIST_JOB_REQUEST("listJobRequest"); + private String value; /** diff --git a/course-mw/sunbird-util/sunbird-platform-core/common-util/src/main/java/org/sunbird/common/models/util/JsonKey.java b/course-mw/sunbird-util/sunbird-platform-core/common-util/src/main/java/org/sunbird/common/models/util/JsonKey.java index c86654567..c711660f4 100644 --- a/course-mw/sunbird-util/sunbird-platform-core/common-util/src/main/java/org/sunbird/common/models/util/JsonKey.java +++ b/course-mw/sunbird-util/sunbird-platform-core/common-util/src/main/java/org/sunbird/common/models/util/JsonKey.java @@ -13,43 +13,23 @@ public final class JsonKey { public static final String UNAUTHORIZED = "Unauthorized"; public static final String MW_SYSTEM_HOST = "sunbird_mw_system_host"; public static final String MW_SYSTEM_PORT = "sunbird_mw_system_port"; - public static final String MW_SYSTEM_CLIENT_PORT = "sunbird_mw_system_client_port"; - public static final String ACCESS_TOKEN = "access_token"; - public static final String ACCESSTOKEN = "accessToken"; public static final String ACCOUNT_KEY = "sunbird_account_key"; public static final String ACCOUNT_NAME = "sunbird_account_name"; public static final String DOWNLOAD_LINK_EXPIRY_TIMEOUT = "download_link_expiry_timeout"; public static final String SIGNED_URL = "signedUrl"; - public static final String REPORTS = "reports"; - public static final String PROGRESS_REPORT_SIGNED_URL = "courseProgressReportUrl"; - public static final String ASSESSMENT_REPORT_BLOB_URL = "reportUrl"; - public static final String ASSESSMENT_REPORT_SIGNED_URL = "assessmentReportUrl"; - public static final String BULK_UPLOAD_STATUS = "Status"; - public static final String BULK_UPLOAD_ERROR = "Remarks"; - public static final String ACTION_GROUP = "action_group"; - public static final String ACTION_GROUPS = "actionGroups"; public static final String ACTION_NAME = "actionName"; public static final String ACTION_URL = "actionUrl"; - public static final String ACTIONS = "actions"; public static final String ACTIVE = "active"; public static final String ACTOR_ID = "actorId"; public static final String ACTOR_SERVICE = "Actor service"; public static final String ACTOR_TYPE = "actorType"; public static final String ADD_TYPE = "addType"; - public static final String ADDED_AT = "addedAt"; public static final String ADDED_BY = "addedBy"; - public static final String ADDED_BY_NAME = "addedByName"; public static final String ADDITIONAL_INFO = "ADDITIONAL_INFO"; public static final String ADDRESS = "address"; - public static final String ADDRESS_DB = "address"; - public static final String ADDRESS_ID = "addressId"; public static final String ADDRESS_LINE1 = "addressLine1"; - public static final String ADDRESS_LINE2 = "addressLine2"; - public static final String ADDRESS_TYPE = "address type"; - public static final String AGGREGATIONS = "aggregations"; public static final String ALL = "all"; public static final String ALLOWED_LOGIN = "allowedLogin"; - public static final String ANNOUNCEMENT = "announcement"; public static final String API_ACCESS = "api_access"; public static final String API_ACTOR_PROVIDER = "api_actor_provider"; public static final String API_CALL = "API_CALL"; @@ -57,103 +37,58 @@ public final class JsonKey { public static final String APP_ICON = "appIcon"; public static final String APP_MAP = "appMap"; public static final String APP_SECTIONS = "appSections"; - public static final String APP_URL = "appUrl"; - public static final String APPICON = "appIcon"; - public static final String APPLICABLE_FOR = "applicableFor"; - public static final String APPROOVE_DATE = "approvalDate"; - public static final String APPROVED_BY = "approvedBy"; - public static final String APPROVED_BY_NAME = "approvedByName"; - public static final String APPROVED_DATE = "approvedDate"; public static final String ASSESSMENT = "assessment"; public static final String ASSESSMENT_EVENTS = "assessments"; public static final String ASSESSMENT_TS = "assessmentTs"; - public static final String ASSESSMENT_ANSWERS = "answers"; - public static final String ASSESSMENT_ATTEMPT_DATE = "attemptedDate"; public static final String ASSESSMENT_EVAL_DB = "assessment_eval_db"; - public static final String ASSESSMENT_GRADE = "grade"; public static final String ASSESSMENT_ITEM_DB = "assessment_item_db"; - public static final String ASSESSMENT_ITEM_ID = "assessmentItemId"; - public static final String ASSESSMENT_MAX_SCORE = "maxScore"; public static final String ASSESSMENT_SCORE = "score"; - public static final String ASSESSMENT_STATUS = "assessmentStatus"; - public static final String ASSESSMENT_TYPE = "assessmentType"; public static final String ATTEMPT_ID = "attemptId"; public static final String ASSESSMENT_EVENTS_KEY = "events"; public static final String ASSESSMENT_ACTOR = "actor"; - public static final String ATTEMPTED_COUNT = "attemptedCount"; - public static final String AUTH_TOKEN = "authToken"; - public static final String AUTH_USER_HEADER = "X-Authenticated-Userid"; public static final String AUTH_WITH_MASTER_KEY = "authWithMasterKey"; public static final String AUTHORIZATION = "Authorization"; public static final String BACKGROUND_ACTOR_PROVIDER = "background_actor_provider"; - public static final String BAD_REQUEST = "badRequest"; public static final String BATCH = "batch"; public static final String BATCH_ID = "batchId"; public static final String BEARER = "Bearer "; - public static final String BLOCKED = "blocked"; public static final String BODY = "body"; public static final String BULK_OP_DB = "BulkOpDb"; public static final String BULK_UPLOAD_BATCH_DATA_SIZE = "bulk_upload_batch_data_size"; public static final String BULK_USER_UPLOAD = "bulkUserUpload"; - public static final String CASSANDRA_IN_EMBEDDED_MODE = "cassandraInEmbeddedMode"; public static final String CASSANDRA_SERVICE = "Cassandra service"; - public static final String CATEGORIES = "categories"; public static final String CHANNEL = "channel"; - public static final String CHANNEL_REG_STATUS = "channelRegStatus"; - public static final String CHANNEL_REG_STATUS_ID = "003"; - public static final String CHANNELS = "channels"; public static final String CHECKS = "checks"; - public static final String CHILD_OF = "childOf"; - public static final String CHILDREN = "children"; public static final String CITY = "city"; public static final String CLASS = "class"; - public static final String CLIENT_ID = "clientId"; public static final String CLIENT_INFO_DB = "clientInfo_db"; public static final String CLIENT_NAME = "clientName"; - public static final String CLIENT_NAMES = "client.names"; - public static final String CODE = "code"; - public static final String COMPLETED_COUNT = "completedCount"; public static final String COMPLETENESS = "completeness"; public static final String CONSUMER = "consumer"; public static final String CONTACT_DETAILS = "contactDetail"; public static final String CONTAINER = "container"; public static final String CONTENT = "content"; - public static final String CONTENT_CREATOR = "CONTENT_CREATOR"; public static final String CONTENT_ID = "contentId"; public static final String CONTENT_IDS = "contentIds"; public static final String CONTENT_LIST = "contentList"; - public static final String CONTENT_NAME = "contentName"; - public static final String CONTENT_PROGRESS = "progress"; public static final String CONTENT_TYPE = "contentType"; - public static final String CONTENT_VERSION = "contentVersion"; public static final String CONTENTS = "contents"; public static final String CONTEXT = "context"; public static final String CORRELATED_OBJECTS = "correlatedObjects"; public static final String COUNT = "count"; - public static final String COUNT_DECREMENT_DATE = "countDecrementDate"; - public static final String COUNT_INCREMENT_DATE = "countIncrementDate"; - public static final String COUNTER_DECREMENT_STATUS = "countDecrementStatus"; - public static final String COUNTER_INCREMENT_STATUS = "countIncrementStatus"; public static final String COUNTRY = "country"; public static final String COUNTRY_CODE = "countryCode"; public static final String COURSE = "course"; public static final String COURSE_ADDITIONAL_INFO = "courseAdditionalInfo"; public static final String COURSE_BATCH_DB = "courseBatchDB"; public static final String COURSE_CREATED_FOR = "createdFor"; - public static final String COURSE_CREATOR = "courseCreator"; - public static final String COURSE_DURATION = "courseDuration"; public static final String COURSE_ENROLL_DATE = "enrolledDate"; public static final String COURSE_ID = "courseId"; public static final String COURSE_IDS = "courseIds"; - public static final String COURSE_LIST = "courseList"; public static final String COURSE_LOGO_URL = "courseLogoUrl"; public static final String COURSE_MANAGEMENT_DB = "courseManagement_db"; public static final String COURSE_NAME = "courseName"; public static final String COURSE_PROGRESS = "progress"; - public static final String COURSE_PUBLISHED_STATUS = "course_publish_status"; - public static final String COURSE_VERSION = "courseVersion"; - public static final String CourseConsumption = "courseConsumption"; - public static final String CourseProgress = "courseProgress"; public static final String COURSES = "courses"; public static final String CREATE = "create"; public static final String CREATED_BY = "createdBy"; @@ -163,9 +98,6 @@ public final class JsonKey { public static final String CURRENT_STATE = "CURRENT_STATE"; public static final String DASHBOARD = "dashboard"; public static final String DATA = "data"; - public static final String KEY = "key"; - public static final String KEYS = "keys"; - public static final String DATE = "date"; public static final String DATE_HISTOGRAM = "DATE_HISTOGRAM"; public static final String DATE_TIME = "dateTime"; public static final String DB_IP = "db.ip"; @@ -173,27 +105,20 @@ public final class JsonKey { public static final String DB_PASSWORD = "db.password"; public static final String DB_PORT = "db.port"; public static final String DB_USERNAME = "db.username"; - public static final String DEFAULT_ACTION_NAME = "Download Reports"; public static final String DEFAULT_CONSUMER_ID = "internal"; public static final String DEFAULT_ROOT_ORG_ID = "ORG_001"; public static final String DEGREE = "degree"; - public static final String DELETE = "delete"; - public static final String DELTA = "delta"; public static final String DESCRIPTION = "description"; public static final String DOB = "dob"; - public static final String DOWNLOAD_URL = "downloadUrl"; - public static final String DUPLICATE = "duplicate"; public static final String EDUCATION = "education"; - public static final String EDUCATION_DB = "user_education"; public static final String EKS = "eks"; public static final String SEARCH_SERVICE_API_BASE_URL = "sunbird_search_service_api_base_url"; public static final String ANALYTICS_API_BASE_URL = "sunbird_analytics_api_base_url"; public static final String EKSTEP_AUTHORIZATION = "ekstep_authorization"; public static final String EKSTEP_BASE_URL = "ekstep_api_base_url"; - public static final String EKSTEP_CONTENT_SEARCH_BASE_URL = "ekstep_content_search_base_url"; public static final String EKSTEP_CONTENT_SEARCH_URL = "ekstep_content_search_url"; public static final String EKSTEP_CONTENT_UPDATE_URL = "ekstep.content.update.url"; - public static final String EKSTEP_SERVICE = "EkStep service"; + public static final String EKSTEP_SERVICE = "Content service"; public static final String EKSTEP_TAG_API_URL = "ekstep.tag.api.url"; public static final String EMAIL = "email"; public static final String EMAIL_REQUEST = "emailReq"; @@ -212,14 +137,7 @@ public final class JsonKey { public static final String ENC_PHONE = "encPhone"; public static final String ENCRYPTION_KEY = "sunbird_encryption_key"; public static final String END_DATE = "endDate"; - public static final String END_TIME = "endTime"; - public static final String ENDORSE_DATE = "endorseDate"; - public static final String ENDORSED_USER_ID = "endorsedUserId"; - public static final String ENDORSEMENT_COUNT = "endorsementCount"; - public static final String ENDORSERS = "endorsers"; - public static final String ENDORSERS_LIST = "endorsersList"; public static final String ENROLLMENT_END_DATE = "enrollmentEndDate"; - public static final String ENROLLMENT_START_DATE = "enrollementStartDate"; public static final String ENROLLMENT_TYPE = "enrollmentType"; public static final String ENROLMENTTYPE = "enrolmentType"; public static final String ENV = "env"; @@ -234,9 +152,7 @@ public final class JsonKey { public static final String EVENTS = "events"; public static final String EXISTS = "exists"; public static final String EXTERNAL_ID = "externalId"; - public static final String EXTERNAL_ID_VALUE = "externalIdValue"; public static final String FACETS = "facets"; - public static final String FAILED = "FAILED"; public static final String FAILURE = "failure"; public static final String FAILURE_RESULT = "failureResult"; public static final String FCM = "fcm"; @@ -244,47 +160,30 @@ public final class JsonKey { public static final String FIELD = "field"; public static final String FIELDS = "fields"; public static final String FILE = "file"; - public static final String FILE_NAME = "fileName"; - public static final String FILE_PARAMS = "fileParams"; - public static final String FILE_URL = "fileUrl"; public static final String FILTER = "filter"; public static final String FILTERS = "filters"; public static final String FIRST_NAME = "firstName"; - public static final String FORM_PARAMS = "formParams"; - public static final String FORMAT = "format"; public static final String FRAMEWORK = "framework"; public static final String FROM_EMAIL = "fromEmail"; public static final String GENDER = "gender"; - public static final String GEO_LOCATION_DB = "geoLocationDb"; public static final String GRADE = "grade"; - public static final String GRADE_LEVEL = "gradeLevel"; public static final String GROUP = "group"; public static final String GROUPID = "groupId"; public static final String GROUP_QUERY = "groupQuery"; public static final String HASH_TAG_ID = "hashtagid"; - public static final String HASHTAGID = "hashTagId"; public static final String HEADER = "header"; public static final String Healthy = "healthy"; - public static final String HOME_URL = "homeUrl"; public static final String ID = "id"; public static final String IDENTIFIER = "identifier"; - public static final String IMAGE = "image"; - public static final String INACTIVE = "inactive"; public static final String INDEX = "index"; public static final String INFO = "info"; - public static final String INSERT = "insert"; public static final String INVITE_ONLY = "invite-only"; - public static final String IS_APPROVED = "isApproved"; public static final String IS_AUTH_REQ = "isAuthReq"; - public static final String IS_DEFAULT = "isDefault"; public static final String IS_DELETED = "isDeleted"; - public static final String IS_REJECTED = "isRejected"; public static final String IS_ROOT_ORG = "isRootOrg"; public static final String IS_SSO_ENABLED = "sso.enabled"; - public static final String IS_VERIFIED = "isVerified"; public static final String JOB_NAME = "jobName"; public static final String JOB_PROFILE = "jobProfile"; - public static final String JOB_PROFILE_DB = "user_job_profile"; public static final String JOINING_DATE = "joiningDate"; public static final String LANGUAGE = "language"; public static final String LAST_ACCESS_TIME = "lastAccessTime"; @@ -303,84 +202,42 @@ public final class JsonKey { public static final String LEVEL = "level"; public static final String LIMIT = "limit"; public static final String LIST = "List"; - public static final String LOC_ID = "locationId"; public static final String LOCATION = "location"; - public static final String LOCATION_NAME = "locationName"; - public static final String LOCATION_ID = "locationId"; public static final String LOCATION_IDS = "locationIds"; - public static final String LOCATIONS = "locations"; public static final String LOG_LEVEL = "logLevel"; - public static final String LOG_RECORD = "logRecord"; public static final String LOG_TYPE = "logType"; - public static final String LOGIN_GENERAL = "general"; public static final String LOGIN_ID = "loginId"; - public static final String LOGIN_ID_DELIMETER = "@"; - public static final String LOGIN_TYPE = "type"; - public static final String MAIL_NOTE = "mail_note"; - public static final String MANDATORY_FIELDS = "mandatoryFields"; public static final String MAP = "map"; - public static final String MAPPED_FORM_PARAMS = "mappedFormParams"; - public static final String MASKED_EMAIL = "maskedEmail"; public static final String MASKED_PHONE = "maskedPhone"; - public static final String MASTER_ACTION = "master_action"; public static final String MASTER_KEY = "masterKey"; - public static final String MEDIA_TYPE_DB = "mediaTypeDB"; public static final String MENTORS = "mentors"; public static final String MESSAGE = "message"; public static final String MESSAGE_Id = "message_id"; public static final String MESSAGE_ID = "X-msgId"; public static final String METHOD = "method"; - public static final String METHOD_NAME = "methodName"; - public static final String METRICS = "metrics"; public static final String MISSING_FIELDS = "missingFields"; public static final String MOBILE = "mobile"; public static final String NAME = "name"; public static final String NEW_PASSWORD = "newPassword"; - public static final String NO_OF_LECTURES = "noOfLectures"; - public static final String NO_OF_MEMBERS = "noOfMembers"; - public static final String NOT_AVAILABLE = "NA"; public static final String NOT_EXISTS = "not_exists"; public static final String NOTE = "note"; - public static final String NOTE_ID = "noteId"; - public static final String NOTIFICATION = "notification"; public static final String NULL = "null"; - public static final String OBJECT_ID = "objectId"; public static final String OBJECT_IDS = "objectIds"; public static final String OBJECT_TYPE = "objectType"; public static final String OFFSET = "offset"; public static final String ON = "ON"; - public static final String ONBOARDING_WELCOME_MAIL_BODY = "onboarding_welcome_mail_body"; public static final String OPEN = "open"; public static final String OPERATION = "operation"; public static final String OPERATION_FOR = "operationFor"; public static final String OPERATION_TYPE = "operationType"; public static final String ORDER = "order"; public static final String ORG_CODE = "orgCode"; - public static final String ORG_CODE_HEADER = "X-Org-code"; - public static final String ORG_EXT_ID_DB = "org_external_identity"; - public static final String ORG_DB = "org_db"; - public static final String ORG_ID = "orgId"; - public static final String ORG_ID_ONE = "orgIdOne"; - public static final String ORG_ID_TWO = "orgIdTwo"; public static final String ORG_IMAGE_URL = "orgImageUrl"; - public static final String ORG_JOIN_DATE = "orgJoinDate"; - public static final String ORG_LEFT_DATE = "orgLeftDate"; - public static final String ORG_MAP_DB = "org_mapping"; public static final String ORG_NAME = "orgName"; - public static final String ORG_SERVER_FROM_NAME = "orgServerFromName"; - public static final String ORG_TYPE = "orgType"; - public static final String ORG_TYPE_DB = "org_type"; - public static final String ORG_TYPE_ID = "orgTypeId"; public static final String ORGANISATION = "organisation"; public static final String ORGANISATION_ID = "organisationId"; public static final String ORGANISATION_NAME = "orgName"; public static final String ORGANISATIONS = "organisations"; - public static final String OrgConsumption = "orgConsumption"; - public static final String OrgCreation = "orgCreation"; - public static final String OTP = "otp"; - public static final String OTP_EMAIL_RESET_PASSWORD_TEMPLATE = "otpEmailResetPasswordTemplate"; - public static final String OTP_PHONE_RESET_PASSWORD_TEMPLATE = "otpPhoneResetPasswordTemplate"; - public static final String VERIFY_PHONE_OTP_TEMPLATE = "verifyPhoneOtpTemplate"; public static final String PAGE = "page"; public static final String PAGE_ID = "pageId"; public static final String PAGE_MGMT_DB = "page_mgmt_db"; @@ -388,77 +245,49 @@ public final class JsonKey { public static final String PAGE_SECTION = "page_section"; public static final String PAGE_SECTION_DB = "page_section_db"; public static final String PARAMS = "params"; - public static final String PARENT_OF = "parentOf"; - public static final String PARENT_ORG_ID = "parentOrgId"; public static final String PARTICIPANT = "participant"; public static final String PARTICIPANTS = "participants"; public static final String PASSWORD = "password"; public static final String PDATA = "pdata"; public static final String PERCENTAGE = "percentage"; - public static final String PERIOD = "period"; public static final String PHONE = "phone"; - public static final String PHONE_NUMBER_VERIFIED = "phoneNumberVerified"; - public static final String PHONE_UNIQUE = "phoneUnique"; public static final String PHONE_VERIFIED = "phoneVerified"; public static final String PORTAL_MAP = "portalMap"; public static final String PORTAL_SECTIONS = "portalSections"; - public static final String POSITION = "position"; - public static final String PREFERRED_LANGUAGE = "preferredLanguage"; public static final String PREV_STATE = "PREV_STATE"; public static final String PRIMARY_KEY_DELIMETER = "##"; public static final String PRIVATE = "private"; public static final String PROCESS_END_TIME = "processEndTime"; public static final String PROCESS_ID = "processId"; public static final String PROCESS_START_TIME = "processStartTime"; - public static final String PROCESSING_STATUS = "processingStatus"; public static final String PDATA_ID = "telemetry_pdata_id"; - public static final String PDATA_PID = "telemetry_pdata_pid"; - public static final String PDATA_VERSION = "telemetry_pdata_ver"; public static final String PROFILE_SUMMARY = "profileSummary"; public static final String PROFILE_VISIBILITY = "profileVisibility"; public static final String PROGRESS = "progress"; - public static final String PROPERTIES = "properties"; public static final String PROPS = "props"; public static final String PROVIDER = "provider"; public static final String PUBLIC = "public"; - public static final String PUBLISH_COURSE = "publishCourse"; public static final String QUERY = "query"; public static final String QUERY_FIELDS = "queryFields"; public static final String RECEIVER_ID = "receiverId"; - public static final String RECIPIENT_COUNT = "recipientCount"; public static final String RECIPIENT_EMAILS = "recipientEmails"; public static final String RECIPIENT_USERIDS = "recipientUserIds"; - public static final String RECOMMEND_TYPE = "recommendType"; public static final String REGISTERED_ORG = "registeredOrg"; public static final String REGISTERED_ORG_ID = "regOrgId"; public static final String RELATION = "relation"; - public static final String RELATIONS = "relations"; - public static final String REMOTE = "remote"; public static final String REPLACE_WITH_ASTERISK = "*"; - public static final String REPLACE_WITH_X = "X"; - public static final String REPORT_TRACKING_DB = "reportTrackingDb"; - public static final String REQ_ID = "reqId"; public static final String REQUEST = "request"; public static final String REQUEST_ID = "requestId"; - public static final String REQUEST_MESSAGE_ID = "msgId"; public static final String REQUEST_TYPE = "requestType"; public static final String REQUESTED_BY = "requestedBy"; public static final String RES_MSG_ID = "resmsgId"; - public static final String RESOURCE_ID = "resourceId"; public static final String RESPONSE = "response"; public static final String RESULT = "result"; - public static final String RETIRED = "retired"; - public static final String RETRY_COUNT = "retryCount"; public static final String ROLE = "role"; - public static final String ROLE_GROUP = "role_group"; - public static final String ROLE_GROUP_ID = "rolegroupid"; public static final String ROLES = "roles"; public static final String ROLLUP = "rollup"; - public static final String ROOT_ORG = "rootOrg"; public static final String ROOT_ORG_ID = "rootOrgId"; - public static final String SCHEDULER_JOB = "scheduler"; - public static final String SEARCH = "search"; public static final String SEARCH_QUERY = "searchQuery"; public static final String SEARCH_TOP_N = "searchTopN"; public static final String SECTION = "section"; @@ -468,20 +297,11 @@ public final class JsonKey { public static final String SECTION_MGMT_DB = "section_mgmt_db"; public static final String SECTION_NAME = "name"; public static final String SECTIONS = "sections"; - public static final String SERIES = "series"; public static final String SIZE = "size"; - public static final String SKILL_ENDORSEMENT_DB = "skillEndorsementDb"; - public static final String SKILL_NAME = "skillName"; - public static final String SKILL_NAME_TO_LOWERCASE = "skillnametolowercase"; - public static final String SKILLS = "skills"; - public static final String SKILLS_LIST_DB = "skillsListDb"; - public static final String SLUG = "slug"; public static final String SNAPSHOT = "snapshot"; public static final String SORT = "sort"; public static final String SORT_BY = "sort_by"; public static final String SOURCE = "source"; - public static final String SOURCE_HEADER = "X-Source"; - public static final String SPLIT = "split"; public static final String SSO_CLIENT_ID = "sso.client.id"; public static final String SSO_CLIENT_SECRET = "sso.client.secret"; public static final String SSO_PASSWORD = "sso.password"; @@ -491,24 +311,15 @@ public final class JsonKey { public static final String SSO_URL = "sso.url"; public static final String SSO_USERNAME = "sso.username"; public static final String STACKTRACE = "stacktrace"; - public static final String STANDALONE_MODE = "standalone"; public static final String START_DATE = "startDate"; public static final String START_TIME = "startTime"; public static final String STATE = "state"; public static final String STATUS = "status"; - public static final String STATUS_CODE = "statusCode"; - public static final String SUB_SECTIONS = "subSections"; public static final String SUBJECT = "subject"; - public static final String SUBMIT_DATE = "submitDate"; - public static final String SUBTYPE = "subtype"; public static final String SUCCESS = "SUCCESS"; public static final String SUCCESS_RESULT = "successResult"; - public static final String SUMMARY = "summary"; - public static final String SUNBIRD = "sunbird"; public static final String SUNBIRD_ALLOWED_LOGIN = "sunbird_allowed_login"; - public static final String SUNBIRD_API_BASE_URL = "sunbird_api_base_url"; public static final String SUNBIRD_CASSANDRA_IP = "sunbird_cassandra_host"; - public static final String SUNBIRD_CASSANDRA_KEYSPACE = "sunbird_cassandra_keyspace"; public static final String SUNBIRD_CASSANDRA_MODE = "sunbird_cassandra_mode"; public static final String SUNBIRD_CASSANDRA_PASSWORD = "sunbird_cassandra_password"; public static final String SUNBIRD_CASSANDRA_PORT = "sunbird_cassandra_port"; @@ -521,15 +332,6 @@ public final class JsonKey { public static final String SUNBIRD_ES_PORT = "sunbird_es_port"; public static final String SUNBIRD_FCM_ACCOUNT_KEY = "sunbird_fcm_account_key"; public static final String SUNBIRD_INSTALLATION = "sunbird_installation"; - public static final String SUNBIRD_NETTY_HOST = "sunbird_netty_host"; - public static final String SUNBIRD_NETTY_PORT = "sunbird_netty_port"; - public static final String SUNBIRD_PG_DB = "sunbird_pg_db"; - public static final String SUNBIRD_PG_HOST = "sunbird_pg_host"; - public static final String SUNBIRD_PG_PASSWORD = "sunbird_pg_password"; - public static final String SUNBIRD_PG_PORT = "sunbird_pg_port"; - public static final String SUNBIRD_PG_USER = "sunbird_pg_user"; - public static final String SUNBIRD_PLUGIN = "sunbirdplugin"; - public static final String SUNBIRD_QUARTZ_MODE = "sunbird_quartz_mode"; public static final String SUNBIRD_SSO_CLIENT_ID = "sunbird_sso_client_id"; public static final String SUNBIRD_SSO_CLIENT_SECRET = "sunbird_sso_client_secret"; public static final String SUNBIRD_SSO_PASSWORD = "sunbird_sso_password"; @@ -540,48 +342,25 @@ public final class JsonKey { public static final String SUNBIRD_GET_ORGANISATION_API = "sunbird_search_organisation_api"; public static final String SUNBIRD_GET_SINGLE_USER_API = "sunbird_read_user_api"; public static final String SUNBIRD_GET_MULTIPLE_USER_API = "sunbird_search_user_api"; - public static final String SUNBIRD_CONTENT_GET_HIERARCHY_API = "sunbird_get_hierarchy_api"; - public static final String SUNBIRD_CONTENT_READ_API = "sunbird_content_read_api"; - public static final String SYSTEM = "system"; - public static final String SYSTEM_SETTINGS_DB = "system_settings"; - public static final String TAG = "tag"; public static final String TAGS = "tags"; public static final String TARGET_OBJECT = "targetObject"; - public static final String TC_UPDATED_DATE = "tcUpdatedAt"; public static final String TELEMETRY_CONTEXT = "TELEMETRY_CONTEXT"; public static final String TELEMETRY_EVENT_TYPE = "telemetryEventType"; public static final String TEMPORARY_PASSWORD = "tempPassword"; - public static final String TENANT_PREFERENCE = "tenantPreference"; - public static final String TENANT_PREFERENCE_DB = "tenantPreferenceDb"; - public static final String TERM_AND_CONDITION_STATUS = "tcStatus"; - public static final String TERMS = "terms"; - public static final String THEME = "theme"; - public static final String THUMBNAIL = "thumbnail"; - public static final String TIME_TAKEN = "timeTaken"; - public static final String TIME_UNIT = "time_unit"; public static final String TITLE = "title"; public static final String TO = "to"; - public static final String TOC_URL = "tocUrl"; - public static final String TOKEN = "token"; - public static final String TOPIC = "topic"; - public static final String TOPIC_NAME = "topicName"; - public static final String TOPICS = "topics"; public static final String TOPN = "topn"; - public static final String TRY_COUNT = "tryCount"; public static final String TYPE = "type"; public static final String UNDEFINED_IDENTIFIER = "Undefined column name "; - public static final String UNIQUE = "unique"; public static final String UNKNOWN_IDENTIFIER = "Unknown identifier "; public static final String UPDATE = "update"; public static final String UPDATED_BY = "updatedBy"; - public static final String UPDATED_BY_NAME = "updatedByName"; public static final String UPDATED_DATE = "updatedDate"; public static final String UPLOADED_BY = "uploadedBy"; public static final String UPLOADED_DATE = "uploadedDate"; public static final String URL = "url"; public static final String URL_ACTION = "url_action"; public static final String URL_ACTION_ID = "url_action_ids"; - public static final String URLS = "urls"; public static final String USER = "user"; public static final String USER_ACTION_ROLE = "user_action_role"; public static final String USER_AUTH_DB = "userAuth_db"; @@ -593,64 +372,29 @@ public final class JsonKey { public static final String USER_FOUND = "user exist with this login Id."; public static final String USER_ID = "userId"; public static final String USER_IDs = "userIds"; - public static final String USER_LIST = "userList"; public static final String USER_LIST_REQ = "userListReq"; public static final String USER_NAME = "username"; - public static final String USER_NOT_FOUND = "user does not exist with this login Id."; - public static final String USER_NOTES_DB = "userNotes_db"; - public static final String USER_ORG = "user_org"; - public static final String USER_ORG_DB = "user_org_db"; - public static final String USER_SKILL_DB = "userSkillDb"; - public static final String USERIDS = "userIds"; public static final String USERNAME = "userName"; - public static final String USR_EXT_ID_DB = "user_external_identity"; - public static final String USR_ORG_DB = "user_org"; - public static final String VALUE = "value"; public static final String VER = "ver"; public static final String VERSION = "version"; - public static final String VIEW_COUNT = "viewCount"; - public static final String VIEW_POSITION = "viewPosition"; public static final String WEB_PAGES = "webPages"; - public static final String WEB_URL = "webUrl"; - public static final String WELCOME_MESSAGE = "welcomeMessage"; - public static final String YEAR_OF_PASSING = "yearOfPassing"; - public static final String ZIPCODE = "zipcode"; - public static final String SUNBIRD_CONTENT_SERVICE_BASE_URL = "sunbird_content_service_base_url"; - public static final String SUNBIRD_CONTENT_SERVICE_AUTHORIZATION = - "sunbird_content_service_authorization"; public static final String SUNBIRD_HEALTH_CHECK_ENABLE = "sunbird_health_check_enable"; public static final String HEALTH = "health"; - public static final String SERVICE = "service"; public static final String SOFT_CONSTRAINTS = "softConstraints"; public static final String SUNBIRD_USER_ORG_API_BASE_URL = "sunbird_user_org_api_base_url"; public static final String SUNBIRD_API_MGR_BASE_URL = "sunbird_api_mgr_base_url"; public static final String SUNBIRD_AUTHORIZATION = "sunbird_authorization"; - public static final String SUNBIRD_CS_BASE_URL = "sunbird_cs_base_url"; public static final String SUNBIRD_CS_SEARCH_PATH = "sunbird_cs_search_path"; - public static final String SUNBIRD_LMS_TELEMETRY = "Sunbird_LMS_Telemetry"; - public static final String SUNBIRD_LMS_AUTHORIZATION = "sunbird_authorization"; - public static final String ETS = "ets"; - public static final String CONTENT_ENCODING = "Content-Encoding"; - public static final String EK_STEP = "EK-STEP"; - public static final String RESOURCE_NAME = "resourceName"; public static final String DURATION = "duration"; - public static final String OBJECT_STORE = "object-store"; - public static final String IMAGE_URL = "imgUrl"; - public static final String COMMUNITY_ID = "communityId"; public static final String LOCATION_CODE = "locationCode"; - public static final String LATITUDE = "latitude"; - public static final String LONGITUDE = "longitude"; public static final String UPLOAD_FILE_MAX_SIZE = "file_upload_max_size"; public static final String PRIMARY_KEY = "PK"; public static final String NON_PRIMARY_KEY = "NonPK"; public static final String PARENT_ID = "parentId"; public static final String CREATED_ON = "createdOn"; - public static final String UPDATED_ON = "updatedOn"; public static final String LAST_UPDATED_ON = "lastUpdatedOn"; - public static final String LAST_UPDATED_BY = "lastUpdatedBy"; public static final String SUNBIRD_DEFAULT_CHANNEL = "sunbird_default_channel"; public static final String CASSANDRA_WRITE_BATCH_SIZE = "cassandra_write_batch_size"; - public static final String CASSANDRA_UPDATE_BATCH_SIZE = "cassandra_update_batch_size"; public static final String ORG_EXTERNAL_ID = "orgExternalId"; public static final String ORG_PROVIDER = "orgProvider"; public static final String EXTERNAL_IDS = "externalIds"; @@ -661,35 +405,13 @@ public final class JsonKey { public static final String EDIT = "edit"; public static final String DEFAULT_FRAMEWORK = "defaultFramework"; public static final String EXTERNAL_ID_PROVIDER = "externalIdProvider"; - public static final String USR_EXT_IDNT_TABLE = "usr_external_identity"; - public static final String END_TIME_IN_HOUR_MINUTE_SECOND = " 23:59:59"; - public static final String REGISTRY_ID = "registryId"; - public static final String RESPONSE_CODE = "responseCode"; public static final String OK = "ok"; - public static final String SUNBIRD_DEFAULT_COUNTRY_CODE = "sunbird_default_country_code"; - public static final String ONBOARDING_MAIL_SUBJECT = "onboarding_mail_subject"; - public static final String ONBOARDING_MAIL_MESSAGE = "onboarding_welcome_message"; - public static final String ES_TYPES = "types"; public static final String RECIPIENT_SEARCH_QUERY = "recipientSearchQuery"; - public static final String ORIGINAL_EXTERNAL_ID = "originalExternalId"; - public static final String ORIGINAL_ID_TYPE = "originalIdType"; - public static final String ORIGINAL_PROVIDER = "originalProvider"; public static final String SUNBIRD_CASSANDRA_CONSISTENCY_LEVEL = "sunbird_cassandra_consistency_level"; public static final String VERSION_2 = "v2"; - public static final String CUSTODIAN_ORG_CHANNEL = "custodianOrgChannel"; - public static final String CUSTODIAN_ORG_ID = "custodianOrgId"; public static final String APP_ID = "appId"; - public static final String REDIRECT_URI = "redirectUri"; - public static final String SET_PASSWORD_LINK = "set_password_link"; - public static final String VERIFY_EMAIL_LINK = "verify_email_link"; - public static final String LINK = "link"; - public static final String SET_PW_LINK = "setPasswordLink"; public static final String SUNBIRD_URL_SHORTNER_ENABLE = "sunbird_url_shortner_enable"; - public static final String USER_PROFILE_CONFIG = "userProfileConfig"; - public static final String PUBLIC_FIELDS = "publicFields"; - public static final String PRIVATE_FIELDS = "privateFields"; - public static final String DEFAULT_PROFILE_FIELD_VISIBILITY = "defaultProfileFieldVisibility"; public static final String SUNBIRD_COURSE_BATCH_NOTIFICATIONS_ENABLED = "sunbird_course_batch_notification_enabled"; @@ -705,9 +427,6 @@ public final class JsonKey { public static final String UNENROLL_FROM_COURSE_BATCH = "Unenrolled from Training"; public static final String OPEN_BATCH_LEARNER_UNENROL = "openBatchLearnerUnenrol"; - public static final String MENTOR = "mentor"; - public static final String OLD = "old"; - public static final String NEW = "new"; public static final String COURSE_BATCH = "courseBatch"; public static final String ADDED_MENTORS = "addedMentors"; public static final String REMOVED_MENTORS = "removedMentors"; @@ -716,10 +435,6 @@ public final class JsonKey { public static final String URL_QUERY_STRING = "urlQueryString"; public static final String SUNBIRD_API_REQUEST_LOWER_CASE_FIELDS = "sunbird_api_request_lower_case_fields"; - public static final String ATTRIBUTE = "attribute"; - public static final String ERRORS = "errors"; - public static final String ROLE_LIST = "roleList"; - public static final String SUNBIRD_USER_PROFILE_READ_EXCLUDED_FIELDS = "read.excludedFields"; public static final String COMPLETED_ON = "completedOn"; public static final String CALLER_ID = "callerId"; public static final String USER_TYPE = "userType"; @@ -729,17 +444,6 @@ public final class JsonKey { "sunbird_course_batch_notification_signature"; public static final String SIGNATURE = "signature"; public static final String OPEN_BATCH_LEARNER_ENROL = "openBatchLearnerEnrol"; - public static final String CONTENT_PROPERTY_MEDIUM = "medium"; - public static final String CONTENT_PROPERTY_GRADE_LEVEL = "gradeLevel"; - public static final String CONTENT_PROPERTY_SUBJECT = "subject"; - public static final String CONTENT_PROPERTY_NAME = "name"; - public static final String CONTENT_PROPERTY_VISIBILITY = "visibility"; - public static final String CONTENT_PROPERTY_VISIBILITY_PARENT = "Parent"; - public static final String CONTENT_PROPERTY_MIME_TYPE = "mimeType"; - public static final String CONTENT_MIME_TYPE_COLLECTION = - "application/vnd.ekstep.content-collection"; - public static final String VERSION_KEY = "versionKey"; - public static final String CSV_SEPERATOR = ","; public static final String CONTENT_CLOUD_STORAGE_TYPE = "sunbird_cloud_service_provider"; public static final String CONTENT_CLOUD_STORAGE_CONTAINER = "sunbird_content_cloud_storage_container"; @@ -750,153 +454,51 @@ public final class JsonKey { public static final String CLOUD_FOLDER_CONTENT = "sunbird_cloud_content_folder"; public static final String CLOUD_STORE_BASE_PATH = "cloud_storage_base_url"; public static final String CLOUD_STORAGE_CNAME_URL= "cloud_storage_cname_url"; - public static final String CLOUD_STORAGE_DIAL_BUCKET_NAME = "cloud_storage_dial_bucketname"; - public static final String DIAL_STORAGE_BASE_PATH_PLACEHOLDER="cloud_storage_path_prefix_dial"; public static final String CLOUD_STORE_BASE_PATH_PLACEHOLDER = "cloud_store_base_path_placeholder"; - public static final String TO_URL = "toUrl"; public static final String TTL = "ttl"; - public static final String TEXTBOOK_TOC_CSV_TTL = "sunbird_texbook_toc_csv_ttl"; - public static final String FILE_TYPE_CSV = "csv"; - // Texbook TOC - public static final String TEXTBOOK = "textbook"; - public static final String TEXTBOOK_ID = "textbookId"; - public static final String MODE = "mode"; public static final String MIME_TYPE = "mimeType"; - public static final String METADATA = "metadata"; - public static final String HIERARCHY = "hierarchy"; - public static final String FILE_DATA = "fileData"; - public static final String FRAMEWORK_METADATA = "frameworkCategories"; - public static final String TEXTBOOK_TOC_ALLOWED_MIMETYPE = - "application/vnd.ekstep.content-collection"; - public static final String TEXTBOOK_TOC_ALLOWED_CONTNET_TYPES = - "textbook_toc_allowed_content_types"; - public static final String TEXTBOOK_TOC_MAX_CSV_ROWS = "textbook_toc_max_csv_rows"; - public static final String TEXTBOOK_TOC_INPUT_MAPPING = "textbook_toc_input_mapping"; - public static final String NODES_MODIFIED = "nodesModified"; - public static final String TEXT_TOC_FILE_SUPPRESS_COLUMN_NAMES = - "textbook_toc_file_suppress_column_names"; - public static final String TEXTBOOK_TOC_MANDATORY_FIELDS = "textbook_toc_mandatory_fields"; - public static final String DOWNLOAD = "download"; public static final String COLLECTION_MIME_TYPE = "application/vnd.ekstep.content-collection"; - public static final String TB_ROOT = "root"; - public static final String TB_IS_NEW = "isNew"; - public static final String KEYWORDS = "keywords"; - public static final String UNIT = "Unit"; - public static final String UPDATE_HIERARCHY_API = "sunbird_update_hierarchy_api"; - public static final String TB_MESSAGES = "messages"; - public static final String TNC_ACCEPTED_ON = "tncAcceptedOn"; - public static final String TNC_ACCEPTED_VERSION = "tncAcceptedVersion"; - public static final String TNC_LATEST_VERSION_URL = "tncLatestVersionUrl"; - public static final String PROMPT_TNC = "promptTnC"; - public static final String TNC_LATEST_VERSION = "tncLatestVersion"; public static final String BULK_ORG_UPLOAD = "bulkOrgUpload"; - public static final String FRAMEWORKS = "frameworks"; - public static final String LATEST_VERSION = "latestVersion"; - public static final String TNC_CONFIG = "tncConfig"; - public static final String TNC = "tnc"; - public static final String ACCEPT = "accept"; - public static final String ROOT_ORG_NAME = "rootOrgName"; - public static final String OTP_EXPIRATION_IN_MINUTES = "otpExpiryInMinutes"; - public static final String SUNBIRD_USER_MAX_PHONE_LENGTH = "sunbird_user_max_phone_length"; - public static final String RATE_LIMIT = "rate_limit"; - public static final String RATE_LIMIT_UNIT = "unit"; - public static final String RATE = "rate"; - public static final String INSTALLATION_NAME = "installationName"; public static final String LOCATION_CODES = "locationCodes"; public static final String BATCH_DETAILS = "batchDetails"; - public static final String USER_LOCATIONS = "userLocations"; public static final String DIAL_CODES = "dialcodes"; - public static final String DIAL_CODE_REQUIRED = "dialcodeRequired"; public static final String NO = "No"; public static final String YES = "Yes"; - public static final String QR_CODE_REQUIRED = "QR Code Required?"; - public static final String QR_CODE = "QR Code"; - public static final String RESERVED_DIAL_CODES = "reservedDialcodes"; - public static final String FRAMEWORK_READ_API_URL = "framework_read_api_url"; - public static final String DIAL_CODE_IDENTIFIER_MAP = "dialCodeIdentifierMap"; - public static final String LINK_DIAL_CODE_API = "sunbird_link_dial_code_api"; - public static final String LINKED_CONTENT = "linkedContent"; - public static final String MAX_ALLOWED_CONTENT_SIZE = "max_allowed_content_size"; - public static final String LINKED_CONTENT_COLUMN_KEY = "Linked Content"; public static final String BATCHES = "batches"; public static final String ENROLLED_ON = "enrolledOn"; - public static final String LAST_ACCESSED_ON = "lastAccessedOn"; public static final String OTHER = "OTHER"; public static final String TEACHER = "TEACHER"; public static final String USER_EXTERNAL_ID = "userExternalId"; public static final String USER_ID_TYPE = "userIdType"; public static final String USER_PROVIDER = "userProvider"; - public static final String SORTBY = "sortBy"; - public static final String SORT_ORDER = "sortOrder"; - public static final String NUMERIC = "NUMERIC"; - public static final String ASC = "asc"; public static final String TERM = "term"; public static final String DESC = "desc"; - public static final String SUNBIRD_TOC_LINKED_CONTENT_COLUMN_NAME = - "sunbird_toc_linked_content_column_name"; - public static final String SUNBIRD_TOC_MAX_FIRST_LEVEL_UNITS = - "sunbird_toc_max_first_level_units"; - public static final String TEXTBOOK_TOC_OUTPUT_MAPPING = "textbook_toc_output_mapping"; - public static final String TEXTBOOK_UNIT = "TextBookUnit"; - public static final String USER_NAME_HEADER = "User Name"; - public static final String ORG_NAME_HEADER = "Org Name"; - public static final String SCHOOL_NAME_HEADER = "School Name"; - public static final String COURSE_ENROLL_DATE_HEADER = "Enrollment Date"; - public static final String PROGRESS_HEADER = "Progress"; - public static final String SUNBIRD_CONTENT_SEARCH_URL = "sunbird_content_search_url"; - public static final String DATE_TIME_HEADER = "Date time stamp"; - public static final String PHONE_HEADER = "Mobile Number"; - public static final String EMAIL_HEADER = "Email Id"; - public static final String COURSE_PROGRESS_MAIL_TEMPLATE = "courseProgressMailTemplate"; public static final String SUNBIRD_TIMEZONE = "sunbird_time_zone"; - public static final String COURSE_STAT_MAIL_DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss"; public static final String DATA_SOURCE = "dataSource"; - public static final String SUNBIRD_DIALCODE_SEARCH_API = "sunbird_dialcode_search_api"; - public static final String FROM_BEGINING = "fromBegining"; public static final String SUNBIRD_KEYCLOAK_USER_FEDERATION_PROVIDER_ID = "sunbird_keycloak_user_federation_provider_id"; public static final String DEVICE_ID = "did"; - public static final String SUNBIRD_GZIP_FILTER_ENABLED = "sunbird_gzip_filter_enabled"; public static final String COMPLETED_PERCENT = "completedPercent"; - public static final String PARTICIPANT_COUNT = "participantCount"; - public static final String BOARD = "board"; - public static final String MEDIUM = "medium"; public static final String SUNBIRD_GZIP_ENABLE = "sunbird_gzip_enable"; - public static final String SHOW_DOWNLOAD_LINK = "showDownloadLink"; public static final String SUNBIRD_SYNC_READ_WAIT_TIME = "sunbird_sync_read_wait_time"; - public static final String REPORT_UPDATED_ON = "reportUpdatedOn"; public static final String SUNBIRD_GZIP_SIZE_THRESHOLD = "sunbird_gzip_size_threshold"; public static final String PAGE_MANAGEMENT = "page_management"; public static final String MAP_NAME = "mapName"; - public static final String PAGE_ASSEMBLE = "pageAssemble"; public static final String SIGNUP_TYPE = "signupType"; public static final String REQUEST_SOURCE = "source"; public static final String SUNBIRD_REDIS_CONN_POOL_SIZE = "sunbird_redis_connection_pool_size"; public static final String RECIPIENT_PHONES = "recipientPhones"; - public static final String TCP = "tcp"; public static final String REST = "rest"; public static final String ES_OR_OPERATION = "$or"; - public static final String PREV_USED_EMAIL = "prevUsedEmail"; - public static final String PREV_USED_PHONE = "prevUsedPhone"; - public static final String MERGE_USER = "Mergeuser"; public static final String FROM_ACCOUNT_ID = "fromAccountId"; public static final String TO_ACCOUNT_ID = "toAccountId"; - public static final String MERGEE_ID = "mergeeId"; - public static final String USER_MERGEE_ACCOUNT = "userMergeeAccount"; - public static final String SEARCH_FUZZY = "fuzzy"; public static final String CERT_ID = "certId"; public static final String ACCESS_CODE = "accessCode"; - public static final String USER_CERT = "user_cert"; - public static final String STORE = "store"; - public static final String JSON = "json"; - public static final String PDF = "pdf"; public static final String JSON_DATA = "jsonData"; public static final String PDF_URL = "pdfURL"; - public static final String CREATED_AT = "createdAt"; - public static final String UPDATED_AT = "updatedAt"; public static final String SIGN_KEYS = "signKeys"; public static final String ENC_KEYS = "encKeys"; public static final String SUNBIRD_STATE_IMG_URL = "sunbird_state_img_url"; @@ -907,61 +509,19 @@ public final class JsonKey { public static final String certificateImgUrl = "certificateImgUrl"; public static final String X_AUTHENTICATED_USER_TOKEN = "x-authenticated-user-token"; public static final String X_SOURCE_USER_TOKEN = "x-source-user-token"; - public static final String SUNBIRD_SUBDOMAIN_KEYCLOAK_BASE_URL = - "sunbird_subdomain_keycloak_base_url"; - public static final String ACTION = "action"; - public static final String ITERATION = "iteration"; - public static final String TELEMETRY_TARGET_USER_MERGE_TYPE = "MergeUserCoursesAndCert"; - public static final String TELEMETRY_PRODUCER_USER_MERGE_ID = "org.sunbird.platform"; - public static final String TELEMETRY_EDATA_USER_MERGE_ACTION = "merge-user-courses-and-cert"; - public static final String BE_JOB_REQUEST = "BE_JOB_REQUEST"; - public static final String TELEMETRY_ACTOR_USER_MERGE_ID = "Merge User Courses and Cert"; + public static final String X_CHANNEL_ID = "x-channel-id"; + public static final String X_AUTHENTICATED_USERID = "x-authenticated-userid"; public static final String SUNBIRD_COURSE_DIALCODES_DB = "sunbird_course_dialcodes_db"; - public static final String CERTIFICATE = "Certificate"; - public static final String OLD_CERTIFICATE = "oldCertificate"; - public static final String MERGE_CERT = "Mergecert"; public static final String RECOVERY_EMAIL = "recoveryEmail"; public static final String RECOVERY_PHONE = "recoveryPhone"; - public static final String SUPPORTED_COlUMNS = "supportedColumns"; - public static final String INPUT_STATUS = "input status"; - public static final String EXTERNAL_USER_ID = "ext user id"; - public static final String EXTERNAL_ORG_ID = "ext org id"; - public static final String MIGRATION_USER_OBJECT = "MigrationUser"; - public static final String TASK_COUNT = "taskCount";; public static final String NESTED_KEY_FILTER = "nestedFilters"; - public static final String SHADOW_USER = "shadow_user"; - public static final String USER_EXT_ID = "userExtId"; - public static final String ORG_EXT_ID = "orgExtId"; - public static final String STATE_VALIDATED = "stateValidated"; - public static final String FLAGS_VALUE = "flagsValue"; - public static final String USER_STATUS = "userStatus"; - public static final String CLAIM_STATUS = "claimStatus"; - public static final String CLAIMED_ON = "claimedOn"; - public static final String SMS = "sms"; - public static final String CONTEXT_TELEMETRY = "telemetryContext"; - public static final String OLD_ID = "oldId"; - public static final String MAX_ATTEMPT = "maxAttempt"; - public static final String REMAINING_ATTEMPT = "remainingAttempt"; - public static final String IS_SSO_ROOTORG_ENABLED = "isSSOEnabled"; - public static final String USER_FEED_DB = "user_feed"; - public static final String USER_FEED = "userFeed"; - public static final String FEED_DATA = "data"; - public static final String REJECT = "reject"; - public static final String FEED_ID = "feedId"; public static final String LICENSE = "license"; public static final String DEFAULT_LICENSE = "defaultLicense"; public static final String SUNBIRD_PASS_REGEX = "sunbird_pass_regex"; public static final String NESTED_EXISTS = "nested_exists"; public static final String NESTED_NOT_EXISTS = "nested_not_exists"; - public static final String PROSPECT_CHANNELS = "prospectChannels"; - public static final String PROSPECT_CHANNELS_IDS = "prospectChannelsIds"; - public static final String CATEGORY = "category"; - public static final String TEMPLATE_ID = "templateId"; - public static final String TEMPLATE_ID_VALUE = "resetPasswordWithOtp"; - public static final String VERSION_3 = "v3"; public static final String LEARNING_SERVICE_BASE_URL = "learning_service_base_url"; public static final String CREATOR_DETAILS_FIELDS = "sunbird_user_search_cretordetails_fields"; - public static final String USER_SEARCH_BASE_URL = "sunbird_user_service_api_base_url"; public static final String SUNBIRD_QRCODE_COURSES_LIMIT ="sunbird_user_qrcode_courses_limit"; public static final String ACCESS_TOKEN_PUBLICKEY_BASEPATH = "accesstoken.publickey.basepath"; public static final String ACCESS_TOKEN_PUBLICKEY_KEYPREFIX = "accesstoken.publickey.keyprefix"; @@ -974,10 +534,7 @@ public final class JsonKey { public static final String GROUP_ACTIVITY_DB = "groupActivityDB"; public static final String ACTIVITYID = "activityId"; public static final String ACTIVITYTYPE = "activityType"; - public static final String ACTIVITY_ID = "activity_id"; - public static final String ACTIVITY_TYPE = "activity_type"; public static final String GROUP_SERVICE_API_BASE_URL ="sunbird_group_service_api_base_url"; - public static final String GROUP_MEMBERS_METADATA ="group.members.metadata"; public static final String COLLECTION_ID = "collectionId"; public static final String TRACKABLE_ENABLED = "trackable.enabled"; public static final String GROUPBY = "groupBy"; @@ -990,7 +547,6 @@ public final class JsonKey { public static final String P_VERSION = "1.0"; public static final String X_DEVICE_ID = "x-device-id"; public static final String X_SESSION_ID = "x-session-id"; - public static final String X_TRACE_ID = "x-trace-id"; public static final String USER_ENROLMENTS_DB = "user_enrolments"; public static final List CHANGE_IN_SIMPLE_DATE_FORMAT = Arrays.asList("startDate", "endDate", "enrollmentEndDate"); public static final List CHANGE_IN_DATE_FORMAT = Arrays.asList("createdDate", "updatedDate"); @@ -1011,10 +567,21 @@ public final class JsonKey { public static final String X_LOGGING_HEADERS = "X_LOGGING_HEADERS"; public static final String LAST_CONTENT_ACCESS_TIME = "lastcontentaccesstime"; public static final String GCP="gcloud"; - public static final String TEMPLATE_URL = "templateUrl"; public static final String SUNBIRD_DIAL_SERVICE_BASE_URL = "sunbird_dial_service_base_url"; public static final String SUNBIRD_DIAL_SERVICE_SEARCH_URL = "sunbird_dial_service_search_url"; + public static final String CONTENT_SERVICE_MOCK_ENABLED = "content_service_mock_enabled"; public static final String AUTH_ENABLED = "AuthenticationEnabled"; + public static final String CONTENT_READ_URL = "content_read_url"; + public static final String TAG = "tag"; + public static final String EXHAUST_API_BASE_URL = "exhaust_api_base_url"; + public static final String EXHAUST_API_SUBMIT_ENDPOINT = "exhaust_api_submit_endpoint"; + public static final String EXHAUST_API_LIST_ENDPOINT = "exhaust_api_list_endpoint"; + public static final String ENCRYPTIONKEY = "encryptionKey"; + public static final String DATASET = "dataset"; + public static final String DATASETCONFIG = "datasetConfig"; + public static final String OUTPUT_FORMAT = "output_format"; + + public static final String CONTENT_LENGTH = "Content-Length"; private JsonKey() {} } diff --git a/course-mw/sunbird-util/sunbird-platform-core/common-util/src/main/java/org/sunbird/common/responsecode/ResponseCode.java b/course-mw/sunbird-util/sunbird-platform-core/common-util/src/main/java/org/sunbird/common/responsecode/ResponseCode.java index 37063db23..db082b419 100644 --- a/course-mw/sunbird-util/sunbird-platform-core/common-util/src/main/java/org/sunbird/common/responsecode/ResponseCode.java +++ b/course-mw/sunbird-util/sunbird-platform-core/common-util/src/main/java/org/sunbird/common/responsecode/ResponseCode.java @@ -15,17 +15,6 @@ public enum ResponseCode { ResponseMessage.Key.INVALID_OPERATION_NAME, ResponseMessage.Message.INVALID_OPERATION_NAME), invalidRequestData( ResponseMessage.Key.INVALID_REQUESTED_DATA, ResponseMessage.Message.INVALID_REQUESTED_DATA), - invalidCustomerId( - ResponseMessage.Key.CONSUMER_ID_MISSING_ERROR, - ResponseMessage.Message.CONSUMER_ID_MISSING_ERROR), - customerIdRequired( - ResponseMessage.Key.CONSUMER_ID_INVALID_ERROR, - ResponseMessage.Message.CONSUMER_ID_INVALID_ERROR), - deviceIdRequired( - ResponseMessage.Key.DEVICE_ID_MISSING_ERROR, ResponseMessage.Message.DEVICE_ID_MISSING_ERROR), - invalidContentId( - ResponseMessage.Key.CONTENT_ID_INVALID_ERROR, - ResponseMessage.Message.CONTENT_ID_INVALID_ERROR), courseIdRequired( ResponseMessage.Key.COURSE_ID_MISSING_ERROR, ResponseMessage.Message.COURSE_ID_MISSING_ERROR), contentIdRequired( @@ -480,23 +469,8 @@ public enum ResponseCode { ResponseMessage.Message.REVOCATION_REASON_REQUIRED), invalidRecipientType( ResponseMessage.Key.INVALID_RECIPIENT_TYPE, ResponseMessage.Message.INVALID_RECIPIENT_TYPE), - customClientError( - ResponseMessage.Key.CUSTOM_CLIENT_ERROR, ResponseMessage.Message.CUSTOM_CLIENT_ERROR), - customResourceNotFound( - ResponseMessage.Key.CUSTOM_RESOURCE_NOT_FOUND_ERROR, - ResponseMessage.Message.CUSTOM_RESOURCE_NOT_FOUND_ERROR), customServerError( ResponseMessage.Key.CUSTOM_SERVER_ERROR, ResponseMessage.Message.CUSTOM_SERVER_ERROR), - inactiveUser(ResponseMessage.Key.INACTIVE_USER, ResponseMessage.Message.INACTIVE_USER), - userInactiveForThisOrg( - ResponseMessage.Key.USER_INACTIVE_FOR_THIS_ORG, - ResponseMessage.Message.USER_INACTIVE_FOR_THIS_ORG), - userUpdateToOrgFailed( - ResponseMessage.Key.USER_UPDATE_FAILED_FOR_THIS_ORG, - ResponseMessage.Message.USER_UPDATE_FAILED_FOR_THIS_ORG), - preferenceKeyMissing( - ResponseMessage.Key.USER_UPDATE_FAILED_FOR_THIS_ORG, - ResponseMessage.Message.USER_UPDATE_FAILED_FOR_THIS_ORG), pageDoesNotExist(ResponseMessage.Key.PAGE_NOT_EXIST, ResponseMessage.Message.PAGE_NOT_EXIST), sectionDoesNotExist( ResponseMessage.Key.SECTION_NOT_EXIST, ResponseMessage.Message.SECTION_NOT_EXIST), @@ -683,12 +657,6 @@ public enum ResponseCode { ResponseMessage.Key.ERROR_INACTIVE_ORG, ResponseMessage.Message.ERROR_INACTIVE_ORG), errorDuplicateEntries( ResponseMessage.Key.ERROR_DUPLICATE_ENTRIES, ResponseMessage.Message.ERROR_DUPLICATE_ENTRIES), - errorConflictingValues( - ResponseMessage.Key.ERROR_CONFLICTING_VALUES, - ResponseMessage.Message.ERROR_CONFLICTING_VALUES), - errorConflictingRootOrgId( - ResponseMessage.Key.ERROR_CONFLICTING_ROOT_ORG_ID, - ResponseMessage.Message.ERROR_CONFLICTING_ROOT_ORG_ID), errorUpdateSettingNotAllowed( ResponseMessage.Key.ERROR_UPDATE_SETTING_NOT_ALLOWED, ResponseMessage.Message.ERROR_UPDATE_SETTING_NOT_ALLOWED), @@ -697,35 +665,10 @@ public enum ResponseCode { errorProcessingRequest( ResponseMessage.Key.ERROR_PROCESSING_REQUEST, ResponseMessage.Message.ERROR_PROCESSING_REQUEST), - errorUnavailableCertificate( - ResponseMessage.Key.ERROR_UNAVAILABLE_CERTIFICATE, - ResponseMessage.Message.ERROR_UNAVAILABLE_CERTIFICATE), - invalidTextbook(ResponseMessage.Key.INVALID_TEXTBOOK, ResponseMessage.Message.INVALID_TEXTBOOK), - csvRowsExceeds(ResponseMessage.Key.CSV_ROWS_EXCEEDS, ResponseMessage.Message.CSV_ROWS_EXCEEDS), - invalidTextbookName( - ResponseMessage.Key.INVALID_TEXTBOOK_NAME, ResponseMessage.Message.INVALID_TEXTBOOK_NAME), - duplicateRows(ResponseMessage.Key.DUPLICATE_ROWS, ResponseMessage.Message.DUPLICATE_ROWS), requiredHeaderMissing( ResponseMessage.Key.REQUIRED_HEADER_MISSING, ResponseMessage.Message.REQUIRED_HEADER_MISSING), - requiredFieldMissing( - ResponseMessage.Key.REQUIRED_FIELD_MISSING, ResponseMessage.Message.REQUIRED_FIELD_MISSING), - blankCsvData(ResponseMessage.Key.BLANK_CSV_DATA, ResponseMessage.Message.BLANK_CSV_DATA), - exceedMaxChildren( - ResponseMessage.Key.EXCEEDS_MAX_CHILDREN, ResponseMessage.Message.EXCEEDS_MAX_CHILDREN), - textbookChildrenExist( - ResponseMessage.Key.TEXTBOOK_CHILDREN_EXISTS, - ResponseMessage.Message.TEXTBOOK_CHILDREN_EXISTS), - textbookUpdateFailure( - ResponseMessage.Key.TEXTBOOK_UPDATE_FAILURE, ResponseMessage.Message.TEXTBOOK_UPDATE_FAILURE), - noChildrenExists( - ResponseMessage.Key.TEXTBOOK_CHILDREN_NOT_EXISTS, - ResponseMessage.Message.TEXTBOOK_CHILDREN_NOT_EXISTS), - textBookNotFound( - ResponseMessage.Key.TEXTBOOK_NOT_FOUND, ResponseMessage.Message.TEXTBOOK_NOT_FOUND), errorProcessingFile( ResponseMessage.Key.ERROR_PROCESSING_FILE, ResponseMessage.Message.ERROR_PROCESSING_FILE), - fileNotFound(ResponseMessage.Key.ERR_FILE_NOT_FOUND, ResponseMessage.Message.ERR_FILE_NOT_FOUND), - errorTbUpdate(ResponseMessage.Key.ERROR_TB_UPDATE, ResponseMessage.Message.ERROR_TB_UPDATE), errorInvalidParameterSize( ResponseMessage.Key.ERROR_INVALID_PARAMETER_SIZE, ResponseMessage.Message.ERROR_INVALID_PARAMETER_SIZE), @@ -734,44 +677,8 @@ public enum ResponseCode { errorRateLimitExceeded( ResponseMessage.Key.ERROR_RATE_LIMIT_EXCEEDED, ResponseMessage.Message.ERROR_RATE_LIMIT_EXCEEDED), - errorInvalidDialCode( - ResponseMessage.Key.ERROR_INVALID_DIAL_CODE, ResponseMessage.Message.ERROR_INVALID_DIAL_CODE), - errorInvalidTopic( - ResponseMessage.Key.ERROR_INVALID_TOPIC, ResponseMessage.Message.ERROR_INVALID_TOPIC), - errorDialCodeDuplicateEntry( - ResponseMessage.Key.ERROR_DIAL_CODE_DUPLICATE_ENTRY, - ResponseMessage.Message.ERROR_DIAL_CODE_DUPLICATE_ENTRY), - errorDialCodeAlreadyAssociated( - ResponseMessage.Key.ERROR_DIAL_CODE_ALREADY_ASSOCIATED, - ResponseMessage.Message.ERROR_DIAL_CODE_ALREADY_ASSOCIATED), - errorDialCodeLinkingFail( - ResponseMessage.Key.DIAL_CODE_LINKING_FAILED, - ResponseMessage.Message.DIAL_CODE_LINKING_FAILED), - errorDialCodeLinkingClientError( - ResponseMessage.Key.ERROR_TEXTBOOK_UPDATE, ResponseMessage.Message.ERROR_TEXTBOOK_UPDATE), - errorInvalidLinkedContentId( - ResponseMessage.Key.ERROR_INVALID_LINKED_CONTENT_ID, - ResponseMessage.Message.ERROR_INVALID_LINKED_CONTENT_ID), - errorDuplicateLinkedContentId( - ResponseMessage.Key.ERROR_DUPLICATE_LINKED_CONTENT, - ResponseMessage.Message.ERROR_DUPLICATE_LINKED_CONTENT), - - errorTeacherCannotBelongToCustodianOrg( - ResponseMessage.Key.TEACHER_CANNOT_BELONG_TO_CUSTODIAN_ORG, - ResponseMessage.Message.TEACHER_CANNOT_BELONG_TO_CUSTODIAN_ORG), - errorDduplicateDialCodeEntry( - ResponseMessage.Key.ERROR_DUPLICATE_QR_CODE_ENTRY, - ResponseMessage.Message.ERROR_DUPLICATE_QR_CODE_ENTRY), - errorInvalidTextbookUnitId( - ResponseMessage.Key.ERROR_INVALID_TEXTBOOK_UNIT_ID, - ResponseMessage.Message.ERROR_INVALID_TEXTBOOK_UNIT_ID), invalidRequestTimeout( ResponseMessage.Key.INVALID_REQUEST_TIMEOUT, ResponseMessage.Message.INVALID_REQUEST_TIMEOUT), - errorBGMSMismatch( - ResponseMessage.Key.ERROR_BGMS_MISMATCH, ResponseMessage.Message.ERROR_BGMS_MISMATCH), - errorUserMigrationFailed( - ResponseMessage.Key.ERROR_USER_MIGRATION_FAILED, - ResponseMessage.Message.ERROR_USER_MIGRATION_FAILED), invalidIdentifier( ResponseMessage.Key.VALID_IDENTIFIER_ABSENSE, ResponseMessage.Message.IDENTIFIER_VALIDATION_FAILED), @@ -785,13 +692,6 @@ public enum ResponseCode { mandatoryHeaderParamsMissing( ResponseMessage.Key.MANDATORY_HEADER_PARAMETER_MISSING, ResponseMessage.Message.MANDATORY_HEADER_PARAMETER_MISSING), - recoveryParamsMatchException( - ResponseMessage.Key.RECOVERY_PARAM_MATCH_EXCEPTION, - ResponseMessage.Message.RECOVERY_PARAM_MATCH_EXCEPTION), - PARAM_NOT_MATCH(ResponseMessage.Key.PARAM_NOT_MATCH, ResponseMessage.Message.PARAM_NOT_MATCH), - emptyContentsForUpdateBatchStatus( - ResponseMessage.Key.EMPTY_CONTENTS_FOR_UPDATE_BATCH_STATUS, - ResponseMessage.Message.EMPTY_CONTENTS_FOR_UPDATE_BATCH_STATUS), errorUserHasNotCreatedAnyCourse( ResponseMessage.Key.ERROR_USER_HAS_NOT_CREATED_ANY_COURSE, ResponseMessage.Message.ERROR_USER_HAS_NOT_CREATED_ANY_COURSE), @@ -830,6 +730,7 @@ public enum ResponseCode { OK(200), CLIENT_ERROR(400), SERVER_ERROR(500), + ERROR(ResponseMessage.Key.ERR_CALLING_EXHAUST_API, ResponseMessage.Message.ERR_CALLING_EXHAUST_API), RESOURCE_NOT_FOUND(404), UNAUTHORIZED(401), FORBIDDEN(403), @@ -896,7 +797,7 @@ public static String getResponseMessage(String code) { if (StringUtils.isBlank(code)) { return ""; } - ResponseCode responseCodes[] = ResponseCode.values(); + ResponseCode[] responseCodes = ResponseCode.values(); for (ResponseCode actionState : responseCodes) { if (actionState.getErrorCode().equals(code)) { return actionState.getErrorMessage(); @@ -905,7 +806,7 @@ public static String getResponseMessage(String code) { return ""; } - private ResponseCode(int responseCode) { + ResponseCode(int responseCode) { this.responseCode = responseCode; } @@ -952,14 +853,13 @@ public static ResponseCode getResponse(String errorCode) { } else if (JsonKey.UNAUTHORIZED.equals(errorCode)) { return ResponseCode.unAuthorized; } else { - ResponseCode value = null; - ResponseCode responseCodes[] = ResponseCode.values(); + ResponseCode[] responseCodes = ResponseCode.values(); for (ResponseCode response : responseCodes) { if (response.getErrorCode().equals(errorCode)) { return response; } } - return value; + return null; } } } diff --git a/course-mw/sunbird-util/sunbird-platform-core/common-util/src/main/java/org/sunbird/common/responsecode/ResponseMessage.java b/course-mw/sunbird-util/sunbird-platform-core/common-util/src/main/java/org/sunbird/common/responsecode/ResponseMessage.java index ff31f5f44..b17248105 100644 --- a/course-mw/sunbird-util/sunbird-platform-core/common-util/src/main/java/org/sunbird/common/responsecode/ResponseMessage.java +++ b/course-mw/sunbird-util/sunbird-platform-core/common-util/src/main/java/org/sunbird/common/responsecode/ResponseMessage.java @@ -15,10 +15,6 @@ interface Message { String INVALID_OPERATION_NAME = "Operation name is invalid. Please provide a valid operation name"; String INVALID_REQUESTED_DATA = "Requested data for this operation is not valid."; - String CONSUMER_ID_MISSING_ERROR = "Consumer id is mandatory."; - String CONSUMER_ID_INVALID_ERROR = "Consumer id is invalid."; - String DEVICE_ID_MISSING_ERROR = "Device id is mandatory."; - String CONTENT_ID_INVALID_ERROR = "Please provide a valid content id."; String CONTENT_ID_MISSING_ERROR = "Please provide content id."; String COURSE_ID_MISSING_ERROR = "Please provide course id."; String API_KEY_MISSING_ERROR = "APi key is mandatory."; @@ -95,9 +91,6 @@ interface Message { String STATUS_CANNOT_BE_UPDATED = "status cann't be updated."; String ATTEMPT_ID_MISSING_ERROR = "Please provide attempt id."; String LOGIN_TYPE_ERROR = "provide login type as null."; - String INVALID_ORG_ID = "Org id does not exist ."; - String INVALID_ORG_STATUS = "Invalid org status for approve ."; - String INVALID_ORG_STATUS_TRANSITION = "Can not change state of Org to requeted state ."; String ADDRESS_REQUIRED_ERROR = "Please provide address."; String EDUCATION_REQUIRED_ERROR = "Please provide education details."; String JOBDETAILS_REQUIRED_ERROR = "Please provide job details."; @@ -142,7 +135,6 @@ interface Message { String USER_ALREADY_COMPLETED_COURSE = "User already completed given course batch."; String COURSE_BATCH_ALREADY_COMPLETED = "Course batch is already completed."; String COURSE_BATCH_ENROLLMENT_DATE_ENDED = "Course batch enrollment date has ended."; - String EXISTING_ORG_MEMBER = "You already have a membership of this organization."; String CONTENT_TYPE_ERROR = "Please add Content-Type header with value application/json"; String INVALID_PROPERTY_ERROR = "Invalid property {0}."; String USER_NAME_OR_ID_ERROR = "Please provide either username or userId."; @@ -233,7 +225,6 @@ interface Message { String USER_PHONE_UPDATE_FAILED = "user phone update is failed."; String ES_UPDATE_FAILED = "Data insertion to ES failed."; String UPDATE_FAILED = "Data updation failed due to invalid Request"; - String INVALID_TYPE_VALUE = "Type value should be organisation OR location ."; String INVALID_LOCATION_ID = "Please provide valid location id."; String INVALID_HASHTAG_ID = "Please provide different hashTagId.This HashTagId is associated with some other organization."; @@ -251,7 +242,6 @@ interface Message { String NOT_SUPPORTED = "Not Supported."; String USERNAME_USERID_MISSING = "Please provide either userName or userId."; String ISSUER_ID_REQUIRED = "Please provide issuer ID."; - String ISSUER_LIST_REQUIRED = "Please provide issuer list."; String ROOT_ORG_ID_REQUIRED = "Please provide root organisation ID."; String RECIPIENT_EMAIL_REQUIRED = "Please provide recipient email."; String ASSERTION_EVIDENCE_REQUIRED = "Please provide valid assertion url as an evidence."; @@ -263,15 +253,8 @@ interface Message { String SLUG_REQUIRED = "Slug is required ."; String INVALID_ISSUER_ID = "Invalid issuer ID."; String REVOCATION_REASON_REQUIRED = "Please provide revocation reason."; - String ALREADY_REVOKED = "Assertion is already revoked."; String INVALID_RECIPIENT_TYPE = "Please provide a valid recipient type."; - String CUSTOM_CLIENT_ERROR = "Request failed. {0}"; - String CUSTOM_RESOURCE_NOT_FOUND_ERROR = "{0}"; String CUSTOM_SERVER_ERROR = "{0}"; - String INACTIVE_USER = "User is Inactive. Please make it active to proceed."; - String USER_INACTIVE_FOR_THIS_ORG = - "User is Inactive for this org. Please make it active to proceed."; - String USER_UPDATE_FAILED_FOR_THIS_ORG = "user updation failed for this org."; String PAGE_NOT_EXIST = "Requested page does not exist."; String SECTION_NOT_EXIST = "Requested section does not exist."; String ORG_NOT_EXIST = "Requested organisation does not exist."; @@ -282,14 +265,12 @@ interface Message { String INVALID_VALUE = "Invalid {0}: {1}. Valid values are: {2}."; String PARENT_CODE_AND_PARENT_ID_MISSING = "Please provide either parentCode or parentId."; String INVALID_PARAMETER = "Please provide valid {0}."; - String INVALID_PARENT_ID = "Please provide valid parentId."; String INVALID_LOCATION_DELETE_REQUEST = "One or more locations have a parent reference to given location and hence cannot be deleted."; String LOCATION_TYPE_CONFLICTS = "Location type conflicts with its parent location type."; String MANDATORY_PARAMETER_MISSING = "Mandatory parameter {0} is missing."; String ERROR_MANDATORY_PARAMETER_EMPTY = "Mandatory parameter {0} is empty."; String ERROR_NO_FRAMEWORK_FOUND = "No framework found."; - String INVALID_LOCN_ID = "Please provide valid locationId."; String UPDATE_NOT_ALLOWED = "Update of {0} is not allowed."; String MANDATORY_HEADER_MISSING = "Mandatory header {0} is missing."; String INVALID_PARAMETER_VALUE = @@ -308,13 +289,10 @@ interface Message { "No root organisation found which is associated with given {0}."; String OR_FORMAT = "{0} or {1}"; String AND_FORMAT = "{0} and {1}"; - String DOT_FORMAT = "{0}.{1}"; String DEPENDENT_PARAMETER_MISSING = "Missing parameter {0} which is dependent on {1}."; String DEPENDENT_PARAMS_MISSING = "Missing parameter value in {0}."; String EXTERNALID_NOT_FOUND = "External ID (id: {0}, idType: {1}, provider: {2}) not found for given user."; - String PARSING_FAILED = "Failed to parse {0}."; - String EXTERNAL_ID_FORMAT = "externalId (id: {0}, idType: {1}, provider: {2})"; String EXTERNALID_ASSIGNED_TO_OTHER_USER = "External ID (id: {0}, idType: {1}, provider: {2}) already assigned to another user."; String MANDATORY_CONFIG_PARAMETER_MISSING = @@ -374,68 +352,24 @@ interface Message { String ERROR_SAVING_STORAGE_DETAILS = "Error saving storage details for download link."; String ERROR_CSV_NO_DATA_ROWS = "No data rows in CSV."; String ERROR_INACTIVE_ORG = "Organisation corresponding to given {0} ({1}) is inactive."; - String ERROR_CONFLICTING_VALUES = "Conflicting values for {0} ({1}) and {2} ({3})."; - String ERROR_CONFLICTING_ROOT_ORG_ID = - "Root organisation ID of API user is conflicting with that of specified organisation ID."; String ERROR_UPDATE_SETTING_NOT_ALLOWED = "Update of system setting {0} is not allowed."; String ERROR_CREATING_FILE = "Error Reading File"; String ERROR_PROCESSING_REQUEST = "Something went wrong while Processing Request"; - String ERROR_UNAVAILABLE_CERTIFICATE = "Certificate is unavailable"; - String INVALID_TEXTBOOK = "Invalid Textbook. Please Provide Valid Textbook Identifier."; - String CSV_ROWS_EXCEEDS = "Number of rows in csv file is more than "; - String INVALID_TEXTBOOK_NAME = - "Textbook Name given in the file doesn’t match current Textbook name. Please check and upload again."; - String DUPLICATE_ROWS = - "Duplicate Textbook node found. Please check and upload again. Row number "; String REQUIRED_HEADER_MISSING = "Required set of header missing: "; - String REQUIRED_FIELD_MISSING = - "Required columns missing. Please check and upload again. Mandatory fields are: "; - String BLANK_CSV_DATA = - "Did not find any Table of Contents data. Please check and upload again."; - String EXCEEDS_MAX_CHILDREN = "Number of first level units is more than allowed."; - String TEXTBOOK_CHILDREN_EXISTS = "Textbook is already having children."; - String TEXTBOOK_UPDATE_FAILURE = "Textbook could not be updated."; - String TEXTBOOK_CHILDREN_NOT_EXISTS = "No Children Exists for given TextBook."; - String TEXTBOOK_NOT_FOUND = "Textbook not found."; String ERROR_PROCESSING_FILE = "Something Went Wrong While Reading File. Please Check The File."; - String ERR_FILE_NOT_FOUND = "File not found. Please select valid file and upload."; - String ERROR_TB_UPDATE = "Error while updating the textbook"; String ERROR_INVALID_PARAMETER_SIZE = "Parameter {0} is of invalid size (expected: {1}, actual: {2})."; String INVALID_PAGE_SECTION = "Page section associated with the page is invalid."; String ERROR_RATE_LIMIT_EXCEEDED = "Your per {0} rate limit has exceeded. You can retry after some time."; - String ERROR_INVALID_DIAL_CODE = "The given QR code {0} is not valid."; - String ERROR_INVALID_TOPIC = "Topic {0} not found in the framework. Please check and correct."; - String ERROR_DIAL_CODE_DUPLICATE_ENTRY = - "QR code {0} is associated with more than one section {1}."; - String ERROR_DIAL_CODE_ALREADY_ASSOCIATED = - "QR code {0} is already associated with a section {1} in the textbook"; - String DIAL_CODE_LINKING_FAILED = "QR code linking failed."; - String ERROR_TEXTBOOK_UPDATE = "{0}"; - - String ERROR_INVALID_LINKED_CONTENT_ID = "Linked Content {0} is not valid at row {1}."; - String ERROR_DUPLICATE_LINKED_CONTENT = "Duplicate content {0} at row {1}."; - String TEACHER_CANNOT_BELONG_TO_CUSTODIAN_ORG = - "User type teacher is not supported for custodian organisation users"; - String ERROR_DUPLICATE_QR_CODE_ENTRY = - "CSV file contains more than one entry for {0}. Correct the duplicate entry and try again."; - String ERROR_INVALID_TEXTBOOK_UNIT_ID = "Invalid textbook unit id {0} for texbook."; String INVALID_REQUEST_TIMEOUT = "Invalid request timeout value {0}."; - String ERROR_USER_UPDATE_PASSWORD = "User is created but password couldn't be updated."; - String ERROR_BGMS_MISMATCH = "Mismatch in {0} at row - {1}"; - String ERROR_USER_MIGRATION_FAILED = "User migration failed."; - String EMPTY_CONTENTS_FOR_UPDATE_BATCH_STATUS = - "Contents should not be empty for batch status update."; String IDENTIFIER_VALIDATION_FAILED = "Valid identifier is not present in List, Valid supported identifiers are "; String FROM_ACCOUNT_ID_MISSING = "From Account id is mandatory."; String TO_ACCOUNT_ID_MISSING = "To Account id is mandatory."; String FROM_ACCOUNT_ID_NOT_EXISTS = "From Account id not exists"; - String PARAM_NOT_MATCH = "%s-NOT-MATCH"; String MANDATORY_HEADER_PARAMETER_MISSING = "Mandatory header parameter {0} is missing."; - String RECOVERY_PARAM_MATCH_EXCEPTION = "{0} could not be same as {1}"; String ERROR_USER_HAS_NOT_CREATED_ANY_COURSE = "User hasn't created any course, or may not have a creator role"; String ERROR_UPLOAD_QRCODE_CSV_FAILED = "Uploading the html file to cloud storage has failed."; @@ -457,6 +391,7 @@ interface Message { String ACTIVITY_ID_MISSING = "ActivityId is mandatory."; String ACTIVITY_TYPE_MISSING = "ActivityType is mandatory."; String ERR_CALLING_GROUP_API = "Error while calling group api."; + String ERR_CALLING_EXHAUST_API = "Error while calling exhaust api"; } interface Key { @@ -465,10 +400,6 @@ interface Key { String OPERATION_TIMEOUT = "PROCESS_EXE_TIMEOUT"; String INVALID_OPERATION_NAME = "INVALID_OPERATION_NAME"; String INVALID_REQUESTED_DATA = "INVALID_REQUESTED_DATA"; - String CONSUMER_ID_MISSING_ERROR = "CONSUMER_ID_REQUIRED_ERROR"; - String CONSUMER_ID_INVALID_ERROR = "CONSUMER_ID_INVALID_ERROR"; - String DEVICE_ID_MISSING_ERROR = "DEVICE_ID_REQUIRED_ERROR"; - String CONTENT_ID_INVALID_ERROR = "CONTENT_ID_INVALID_ERROR"; String CONTENT_ID_MISSING_ERROR = "CONTENT_ID_REQUIRED_ERROR"; String COURSE_ID_MISSING_ERROR = "COURSE_ID_REQUIRED_ERROR"; String API_KEY_MISSING_ERROR = "API_KEY_REQUIRED_ERROR"; @@ -619,7 +550,6 @@ interface Key { String EMAIL_BODY_ERROR = "EMAIL_BODY_ERROR"; String RECIPIENT_ADDRESS_ERROR = "RECIPIENT_ADDRESS_ERROR"; String ISSUER_ID_REQUIRED = "ISSUER_ID_REQUIRED"; - String ISSUER_LIST_REQUIRED = "ISSUER_LIST_REQUIRED"; String ROOT_ORG_ID_REQUIRED = "BADGE_ROOT_ORG_ID_REQUIRED"; String RECIPIENT_EMAIL_REQUIRED = "RECIPIENT_EMAIL_REQUIRED"; String ASSERTION_EVIDENCE_REQUIRED = "ASSERTION_EVIDENCE_REQUIRED"; @@ -689,15 +619,8 @@ interface Key { String SLUG_REQUIRED = "SLUG_REQUIRED"; String INVALID_ISSUER_ID = "INVALID_ISSUER_ID"; String REVOCATION_REASON_REQUIRED = "REVOCATION_REASON_REQUIRED"; - String ALREADY_REVOKED = "ALREADY_REVOKED"; String INVALID_RECIPIENT_TYPE = "INVALID_RECIPIENT_TYPE"; - String CUSTOM_CLIENT_ERROR = "CLIENT_ERROR"; - String CUSTOM_RESOURCE_NOT_FOUND_ERROR = "RESOURCE_NOT_FOUND"; String CUSTOM_SERVER_ERROR = "SERVER_ERROR"; - String INACTIVE_USER = "INACTIVE_USER"; - String USER_INACTIVE_FOR_THIS_ORG = "USER_INACTIVE_FOR_THIS_ORG"; - String USER_UPDATE_FAILED_FOR_THIS_ORG = "USER_UPDATE_FAILED_FOR_THIS_ORG"; - String PREFERENCE_KEY_MISSING = "PREFERENCE_KEY_MISSING"; String PAGE_NOT_EXIST = "PAGE_NOT_EXIST"; String SECTION_NOT_EXIST = "SECTION_NOT_EXIST"; String ORG_NOT_EXIST = "ORG_NOT_EXIST"; @@ -708,13 +631,11 @@ interface Key { String INVALID_VALUE = "INVALID_VALUE"; String PARENT_CODE_AND_PARENT_ID_MISSING = "PARENT_CODE_AND_PARENT_ID_MISSING"; String INVALID_PARAMETER = "INVALID_PARAMETER"; - String INVALID_PARENT_ID = "INVALID_PARENT_ID"; String INVALID_LOCATION_DELETE_REQUEST = "INVALID_LOCATION_DELETE_REQUEST"; String LOCATION_TYPE_CONFLICTS = "LOCATION_TYPE_CONFLICTS"; String MANDATORY_PARAMETER_MISSING = "MANDATORY_PARAMETER_MISSING"; String ERROR_MANDATORY_PARAMETER_EMPTY = "ERROR_MANDATORY_PARAMETER_EMPTY"; String ERROR_NO_FRAMEWORK_FOUND = "ERROR_NO_FRAMEWORK_FOUND"; - String INVALID_LOCN_ID = "INVALID_LOCATION_ID"; String UPDATE_NOT_ALLOWED = "UPDATE_NOT_ALLOWED"; String MANDATORY_HEADER_MISSING = "MANDATORY_HEADER_MISSING"; String INVALID_PARAMETER_VALUE = "INVALID_PARAMETER_VALUE"; @@ -723,7 +644,6 @@ interface Key { String FILE_ATTACHMENT_SIZE_NOT_CONFIGURED = "ATTACHMENT_SIZE_NOT_CONFIGURED"; String EMPTY_FILE = "EMPTY_FILE"; String INVALID_COLUMNS = "INVALID_COLUMNS"; - String INVALID_COLUMN = "INVALID_COLUMN"; String CONFLICTING_ORG_LOCATIONS = "CONFLICTING_ORG_LOCATIONS"; String UNABLE_TO_COMMUNICATE_WITH_ACTOR = "UNABLE_TO_COMMUNICATE_WITH_ACTOR"; String EMPTY_HEADER_LINE = "EMPTY_HEADER_LINE"; @@ -775,55 +695,23 @@ interface Key { String ERROR_CSV_NO_DATA_ROWS = "ERROR_CSV_NO_DATA_ROWS"; String ERROR_INACTIVE_ORG = "ERROR_INACTIVE_ORG"; String ERROR_DUPLICATE_ENTRIES = "ERROR_DUPLICATE_ENTRIES"; - String ERROR_CONFLICTING_VALUES = "ERROR_CONFLICTING_VALUES"; - String ERROR_CONFLICTING_ROOT_ORG_ID = "ERROR_CONFLICTING_ROOT_ORG_ID"; String ERROR_UPDATE_SETTING_NOT_ALLOWED = "ERROR_UPDATE_SETTING_NOT_ALLOWED"; String ERROR_CREATING_FILE = "ERROR_CREATING_FILE"; String ERROR_PROCESSING_REQUEST = "ERROR_PROCESSING_REQUEST"; - String ERROR_UNAVAILABLE_CERTIFICATE = "ERROR_UNAVAILABLE_CERTIFICATE"; - String INVALID_TEXTBOOK = "INVALID_TEXTBOOK"; - String CSV_ROWS_EXCEEDS = "CSV_ROWS_EXCEEDS"; - String INVALID_TEXTBOOK_NAME = "INVALID_TEXTBOOK_NAME"; - String DUPLICATE_ROWS = "DUPLICATE_ROWS"; String ERROR_INVALID_OTP = "ERROR_INVALID_OTP"; String REQUIRED_HEADER_MISSING = "REQUIRED_HEADER_MISSING"; - String REQUIRED_FIELD_MISSING = "REQUIRED_FIELD_MISSING"; - String BLANK_CSV_DATA = "BLANK_CSV_DATA"; - String EXCEEDS_MAX_CHILDREN = "EXCEEDS_MAX_CHILDREN"; - String TEXTBOOK_CHILDREN_EXISTS = "TEXTBOOK_CHILDREN_EXISTS"; - String TEXTBOOK_UPDATE_FAILURE = "TEXTBOOK_UPDATE_FAILURE"; - String TEXTBOOK_CHILDREN_NOT_EXISTS = "TEXTBOOK_CHILDREN_NOT_EXISTS"; - String TEXTBOOK_NOT_FOUND = "TEXTBOOK_NOT_FOUND"; String ERROR_PROCESSING_FILE = "ERROR_PROCESSING_FILE"; - String ERR_FILE_NOT_FOUND = "ERR_FILE_NOT_FOUND"; - String ERROR_TB_UPDATE = "ERROR_TB_UPDATE"; String ERROR_INVALID_PARAMETER_SIZE = "ERROR_INVALID_PARAMETER_SIZE"; String INVALID_PAGE_SECTION = "INVALID_PAGE_SECTION"; String ERROR_RATE_LIMIT_EXCEEDED = "ERROR_RATE_LIMIT_EXCEEDED"; String ERROR_INVALID_CONFIG_PARAM_VALUE = "ERROR_INVALID_CONFIG_PARAM_VALUE"; String ERROR_MAX_SIZE_EXCEEDED = "ERROR_MAX_SIZE_EXCEEDED"; - String ERROR_INVALID_DIAL_CODE = "ERROR_INVALID_DIAL_CODE"; - String ERROR_INVALID_TOPIC = "ERROR_INVALID_TOPIC"; - String ERROR_DIAL_CODE_DUPLICATE_ENTRY = "ERROR_DIAL_CODE_DUPLICATE_ENTRY"; - String ERROR_DIAL_CODE_ALREADY_ASSOCIATED = "ERROR_DIAL_CODE_ALREADY_ASSOCIATED"; - String DIAL_CODE_LINKING_FAILED = "DIAL_CODE_LINKING_FAILED"; - String ERROR_TEXTBOOK_UPDATE = "ERROR_TEXTBOOK_UPDATE"; - String ERROR_INVALID_LINKED_CONTENT_ID = "ERROR_INVALID_LINKED_CONTENT_ID"; - String ERROR_DUPLICATE_LINKED_CONTENT = "DUPLICATE_LINKED_CONTENT"; - String TEACHER_CANNOT_BELONG_TO_CUSTODIAN_ORG = "TEACHER_CANNOT_BELONG_TO_CUSTODIAN_ORG"; - String ERROR_DUPLICATE_QR_CODE_ENTRY = "ERROR_DUPLICATE_QR_CODE_ENTRY"; - String ERROR_INVALID_TEXTBOOK_UNIT_ID = "ERROR_INVALID_TEXTBOOK_UNIT_ID"; String INVALID_REQUEST_TIMEOUT = "INVALID_REQUEST_TIMEOUT"; - String ERROR_BGMS_MISMATCH = "ERROR_BGMS_MISMATCH"; - String ERROR_USER_MIGRATION_FAILED = "ERROR_USER_MIGRATION_FAILED"; String VALID_IDENTIFIER_ABSENSE = "IDENTIFIER IN LIST IS NOT SUPPORTED OR INCORRECT"; String FROM_ACCOUNT_ID_MISSING = "FROM_ACCOUNT_ID_MISSING"; String TO_ACCOUNT_ID_MISSING = "TO_ACCOUNT_ID_MISSING"; String FROM_ACCOUNT_ID_NOT_EXISTS = "FROM_ACCOUNT_ID_NOT_EXISTS"; - String PARAM_NOT_MATCH = "%s-NOT-MATCH"; String MANDATORY_HEADER_PARAMETER_MISSING = "MANDATORY_HEADER_PARAMETER_MISSING"; - String RECOVERY_PARAM_MATCH_EXCEPTION = "RECOVERY_PARAM_MATCH_EXCEPTION"; - String EMPTY_CONTENTS_FOR_UPDATE_BATCH_STATUS = "EMPTY_CONTENTS_FOR_UPDATE_BATCH_STATUS"; String ERROR_USER_HAS_NOT_CREATED_ANY_COURSE = "USER_HAS_NOT_CREATED_ANY_COURSE"; String ERROR_UPLOAD_QRCODE_CSV_FAILED = "ERROR_UPLOAD_QRCODE_CSV_FAILED"; String ERROR_NO_DIALCODES_LINKED = "ERROR_NO_DIALCODES_LINKED"; @@ -842,5 +730,6 @@ interface Key { String ACTIVITY_ID_MISSING = "ACTIVITY_ID_MISSING"; String ACTIVITY_TYPE_MISSING = "ACTIVITY_TYPE_MISSING"; String ERR_CALLING_GROUP_API = "ERR_CALLING_GROUOP_API"; + String ERR_CALLING_EXHAUST_API = "ERR_CALLING_EXHAUST_API"; } } diff --git a/course-mw/sunbird-util/sunbird-platform-core/common-util/src/main/resources/externalresource.properties b/course-mw/sunbird-util/sunbird-platform-core/common-util/src/main/resources/externalresource.properties index 56ff113e3..73a1cbd13 100644 --- a/course-mw/sunbird-util/sunbird-platform-core/common-util/src/main/resources/externalresource.properties +++ b/course-mw/sunbird-util/sunbird-platform-core/common-util/src/main/resources/externalresource.properties @@ -45,7 +45,7 @@ sunbird_url_shortner_access_token= #Telemetry producer related info telemetry_pdata_id=local.sunbird.learning.service telemetry_pdata_pid=learning-service -telemetry_pdata_ver=5.2.0 +telemetry_pdata_ver=5.3.0 #elastic search top n result count for telemetry searchTopN=5 # Sunbird lms telemetry url @@ -66,35 +66,11 @@ sunbird_keycloak_user_federation_provider_id= sunbird_keycloak_required_action_link_expiration_seconds=155520000 sunbird_url_shortner_enable=false sunbird_api_request_lower_case_fields=source,externalId,userName,provider,loginId,email,prevUsedEmail -# Textbook TOC Api -sunbird_content_read_api=/content/v3/read -textbook_toc_allowed_content_types=TextBook,Collection,LessonPlan -sunbird_get_hierarchy_api=/content/v3/hierarchy -sunbird_update_hierarchy_api=/content/v3/hierarchy/update -textbook_toc_max_csv_rows=6500 -textbook_toc_input_mapping={\"identifier\":\"Identifier\",\"frameworkCategories\":{\"board\":\"Board\",\"medium\":\"Medium\",\"gradeLevel\":\"Grade\",\"subject\":\"Subject\"},\"hierarchy\":{\"Textbook\":\"Textbook Name\",\"L:1\":\"Level 1 Textbook Unit\",\"L:2\":\"Level 2 Textbook Unit\",\"L:3\":\"Level 3 Textbook Unit\",\"L:4\":\"Level 4 Textbook Unit\"},\"metadata\":{\"description\":\"Description\",\"topic\":\"Mapped Topics\",\"keywords\":\"Keywords\",\"purpose\":\"Purpose of Content to be linked\",\"dialcodeRequired\":\"QR Code Required?\",\"dialcodes\":\"QR Code\"}} -textbook_toc_file_suppress_column_names=true -sunbird_texbook_toc_csv_ttl=86400 -textbook_toc_mandatory_fields={\"Textbook\":\"Textbook Name\",\"L:1\":\"Level 1 Textbook Unit\"} -sunbird_toc_linked_content_column_name=Linked Content {0} -sunbird_toc_max_first_level_units=30 # Add proper cloud service provider (azure,aws,gcloud) # Provide corresponding service provider container(azure,aws,gcloud) sunbird_content_cloud_storage_container=sunbird-content-dev sunbird_cloud_content_folder=content -framework_read_api_url=/framework/v3/read -sunbird_link_dial_code_api=/collection/v3/dialcode/link -textbook_toc_output_mapping={\"identifier\":\"Identifier\",\"frameworkCategories\":{\"board\":\"Board\",\"medium\":\"Medium\",\"gradeLevel\":\"Grade\",\"subject\":\"Subject\"},\"hierarchy\":{\"Textbook\":\"Textbook Name\",\"L:1\":\"Level 1 Textbook Unit\",\"L:2\":\"Level 2 Textbook Unit\",\"L:3\":\"Level 3 Textbook Unit\",\"L:4\":\"Level 4 Textbook Unit\"},\"metadata\":{\"description\":\"Description\",\"topic\":\"Mapped Topics\",\"keywords\":\"Keywords\",\"purpose\":\"Purpose of Content to be linked\",\"dialcodeRequired\":\"QR Code Required?\",\"dialcodes\":\"QR Code\"},\"linkedContent\":{\"Linked Content 1\":\"Linked Content 1\",\"Linked Content 2\":\"Linked Content 2\",\"Linked Content 3\":\"Linked Content 3\",\"Linked Content 4\":\"Linked Content 4\",\"Linked Content 5\":\"Linked Content 5\",\"Linked Content 6\":\"Linked Content 6\",\"Linked Content 7\":\"Linked Content 7\",\"Linked Content 8\":\"Linked Content 8\",\"Linked Content 9\":\"Linked Content 9\",\"Linked Content 10\":\"Linked Content 10\",\"Linked Content 11\":\"Linked Content 11\",\"Linked Content 12\":\"Linked Content 12\",\"Linked Content 13\":\"Linked Content 13\",\"Linked Content 14\":\"Linked Content 14\",\"Linked Content 15\":\"Linked Content 15\",\"Linked Content 16\":\"Linked Content 16\",\"Linked Content 17\":\"Linked Content 17\",\"Linked Content 18\":\"Linked Content 18\",\"Linked Content 19\":\"Linked Content 19\",\"Linked Content 20\":\"Linked Content 20\",\"Linked Content 21\":\"Linked Content 21\",\"Linked Content 22\":\"Linked Content 22\",\"Linked Content 23\":\"Linked Content 23\",\"Linked Content 24\":\"Linked Content 24\",\"Linked Content 25\":\"Linked Content 25\"},\"Linked Content 26\":\"Linked Content 26\",\"Linked Content 27\":\"Linked Content 27\",\"Linked Content 28\":\"Linked Content 28\",\"Linked Content 29\":\"Linked Content 29\",\"Linked Content 30\":\"Linked Content 30\"} -# For other environments -sunbird_content_search_url=/v1/content/search -# For Local -# sunbird_content_search_url=/content/v1/search sunbird_time_zone=Asia/Kolkata -# For other environments -sunbird_dialcode_search_api=/v1/dialcode/list -# For Local -# sunbird_dialcode_search_api=/dialcode/v1/list -sunbird_cs_base_url=https://dev.sunbirded.org/api sunbird_health_check_enable=true sunbird_sync_read_wait_time=1500 sunbird_gzip_size_threshold=262144 @@ -127,9 +103,14 @@ sunbird_api_mgr_base_url=https://dev.sunbirded.org/api enrollment_list_size=1000 cloud_storage_base_url=https://sunbirddev.blob.core.windows.net cloud_store_base_path_placeholder=CLOUD_BASE_PATH -cloud_storage_dial_bucketname=dial -cloud_storage_path_prefix_dial=DIAL_STORAGE_BASE_PATH +#Release-5.3.0 - LR-556 +content_service_mock_enabled=false #Release-5.2.0 - LR-325 -sunbird_dial_service_base_url = https://dev.lern.sunbird.org -sunbird_dial_service_search_url = /api/dialcode/v1/search \ No newline at end of file +sunbird_dial_service_base_url=https://dev.lern.sunbird.org +sunbird_dial_service_search_url=/api/dialcode/v1/search + +#Release-5.3.0 - LR-539 +exhaust_api_base_url=https://dev.lern.sunbird.org +exhaust_api_submit_endpoint=/api/dataset/v1/request/submit +exhaust_api_list_endpoint=/api/dataset/v1/request/list \ No newline at end of file diff --git a/course-mw/sunbird-util/sunbird-platform-core/sunbird-commons/pom.xml b/course-mw/sunbird-util/sunbird-platform-core/sunbird-commons/pom.xml index 74b57116d..9b1349255 100644 --- a/course-mw/sunbird-util/sunbird-platform-core/sunbird-commons/pom.xml +++ b/course-mw/sunbird-util/sunbird-platform-core/sunbird-commons/pom.xml @@ -30,6 +30,11 @@ auth-verifier 1.0-SNAPSHOT + + com.squareup.okhttp3 + mockwebserver + 4.10.0 + diff --git a/course-mw/sunbird-utils b/course-mw/sunbird-utils deleted file mode 160000 index 6412bddf2..000000000 --- a/course-mw/sunbird-utils +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 6412bddf2b42682178f806e9a691d79e887a14f5 diff --git a/course-mw/textbook-actors/.gitignore b/course-mw/textbook-actors/.gitignore deleted file mode 100644 index 918338544..000000000 --- a/course-mw/textbook-actors/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/target/ -/.classpath -/.project -/.settings -/logs -/bin/ diff --git a/course-mw/textbook-actors/pom.xml b/course-mw/textbook-actors/pom.xml deleted file mode 100644 index 32a1071d9..000000000 --- a/course-mw/textbook-actors/pom.xml +++ /dev/null @@ -1,90 +0,0 @@ - - - 4.0.0 - - org.sunbird - course-mw - 1.0-SNAPSHOT - ../pom.xml - - textbook-actors - Textbook - - UTF-8 - - - - ch.qos.logback - logback-classic - 1.2.3 - - - net.logstash.logback - logstash-logback-encoder - 6.3 - - - org.sunbird - course-actors-common - 1.0-SNAPSHOT - - - com.typesafe.akka - akka-testkit_2.11 - 2.5.22 - test - - - - org.mockito - mockito-core - ${mockito.core.version} - test - - - org.powermock - powermock-api-mockito2 - ${powermock.api.mockito2.version} - test - - - org.powermock - powermock-module-junit4 - ${powermock.module.junit4.version} - test - - - - ${basedir}/src/main/java - ${basedir}/src/test/java - - - org.jacoco - jacoco-maven-plugin - 0.8.5 - - - org.apache.maven.plugins - maven-compiler-plugin - 3.8.1 - - 11 - - - - org.apache.maven.plugins - maven-surefire-plugin - 3.0.0-M4 - - - - **/*Spec.java - **/*Test.java - - - - - - diff --git a/course-mw/textbook-actors/src/main/java/org/sunbird/content/textbook/FileExtension.java b/course-mw/textbook-actors/src/main/java/org/sunbird/content/textbook/FileExtension.java deleted file mode 100644 index e6d342782..000000000 --- a/course-mw/textbook-actors/src/main/java/org/sunbird/content/textbook/FileExtension.java +++ /dev/null @@ -1,61 +0,0 @@ -package org.sunbird.content.textbook; - -import static java.util.Arrays.asList; - -import java.util.ArrayList; -import java.util.List; - -public class FileExtension { - - private String type; - private List seperators; - - public FileExtension(String extension, List seperators) { - this.type = extension; - this.seperators = seperators; - } - - public String getExtension() { - return type; - } - - public String getDotExtension() { - return "." + type; - } - - public String getSeperator() { - return getSeperator(0); - } - - public String getSeperator(int i) { - return seperators.get(i); - } - - public enum Extension { - CSV("csv", new String[] {","}); - - private String extension; - private String[] seperators; - - Extension(String extension, String[] seperators) { - this.extension = extension; - this.seperators = seperators; - } - - public String getDotExtension() { - return "." + extension; - } - - public String getSeperator() { - return getSeperator(0); - } - - public String getSeperator(int i) { - return seperators[i]; - } - - public FileExtension getFileExtension() { - return new FileExtension(extension, new ArrayList<>(asList(seperators))); - } - } -} diff --git a/course-mw/textbook-actors/src/main/java/org/sunbird/content/textbook/TextBookTocFileConfig.java b/course-mw/textbook-actors/src/main/java/org/sunbird/content/textbook/TextBookTocFileConfig.java deleted file mode 100644 index 80890e6a2..000000000 --- a/course-mw/textbook-actors/src/main/java/org/sunbird/content/textbook/TextBookTocFileConfig.java +++ /dev/null @@ -1,138 +0,0 @@ -package org.sunbird.content.textbook; - -import static java.util.Optional.ofNullable; -import static org.sunbird.common.models.util.JsonKey.NAME; -import static org.sunbird.common.models.util.JsonKey.TEXT_TOC_FILE_SUPPRESS_COLUMN_NAMES; -import static org.sunbird.common.models.util.ProjectUtil.getConfigValue; -import static org.sunbird.content.util.TextBookTocUtil.getObjectFrom; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Optional; -import java.util.Set; -import org.apache.commons.lang3.StringUtils; -import org.sunbird.common.models.util.JsonKey; - -public class TextBookTocFileConfig { - - private static Map outputMapping = - getObjectFrom(getConfigValue(JsonKey.TEXTBOOK_TOC_OUTPUT_MAPPING), Map.class); - - protected static Optional> METADATA = - ofNullable(outputMapping.get("metadata")).map(e -> (Map) e); - - protected static Optional> HIERARCHY = - ofNullable(outputMapping.get("hierarchy")).map(e -> (Map) e); - - protected static boolean SUPPRESS_EMPTY_COLUMNS = - ofNullable(getConfigValue(TEXT_TOC_FILE_SUPPRESS_COLUMN_NAMES)) - .map(Boolean::parseBoolean) - .orElse(false); - - protected static int LEVELS = HIERARCHY.map(Map::size).orElse(0); - protected static String HIERARCHY_PROPERTY = NAME; - - protected static int metadataStartPos; - protected static int hierarchyStartPos; - - protected static List KEY_NAMES; - protected static List COLUMN_NAMES; - protected static String[] COLUMN_NAMES_ARRAY; - protected static List COMPULSORY_COLUMNS_KEYS; - protected static List HIERARCHY_KEYS = - HIERARCHY.map(h -> new ArrayList(h.keySet())).orElseGet(ArrayList::new); - protected static List ROW_METADATA; - - static { - int currPos = 0; - for (Entry e : outputMapping.entrySet()) { - if (e.getValue() instanceof String) { - currPos += 1; - } - if (e.getValue() instanceof Map) { - if ("metadata".equals(e.getKey())) { - metadataStartPos = currPos; - } - if ("hierarchy".equals(e.getKey())) { - hierarchyStartPos = currPos; - } - currPos += ((Map) e.getValue()).size(); - } - KEY_NAMES = keyNames(); - COLUMN_NAMES = columnNames(); - COLUMN_NAMES_ARRAY = COLUMN_NAMES.stream().toArray(String[]::new); - COMPULSORY_COLUMNS_KEYS = compulsoryColumnsKeys(); - ROW_METADATA = rowMetadata(); - } - } - - private static List keyNames() { - List keys = new ArrayList<>(); - for (Entry e : outputMapping.entrySet()) { - if (e.getValue() instanceof String) { - keys.add(e.getKey()); - } - if (e.getValue() instanceof Map) { - for (String s : ((Map) e.getValue()).keySet()) { - keys.add(s); - } - } - } - return keys; - } - - private static List columnNames() { - List columns = new ArrayList<>(); - for (Entry e : outputMapping.entrySet()) { - if (e.getValue() instanceof String) { - columns.add((String) e.getValue()); - } - if (e.getValue() instanceof Map) { - for (Entry entry : ((Map) e.getValue()).entrySet()) { - columns.add(entry.getValue()); - } - } - } - return columns; - } - - private static List compulsoryColumnsKeys() { - List keys = new ArrayList<>(); - for (Entry e : outputMapping.entrySet()) { - if (StringUtils.equalsIgnoreCase("hierarchy", e.getKey())) { - continue; - } - if (e.getValue() instanceof String) { - keys.add(e.getKey()); - } - if (e.getValue() instanceof Map) { - for (Entry entry : ((Map) e.getValue()).entrySet()) { - keys.add((String) entry.getKey()); - } - } - } - return keys; - } - - private static List rowMetadata() { - Set props = new HashSet<>(); - for (Entry e : outputMapping.entrySet()) { - if (StringUtils.equalsIgnoreCase("hierarchy", e.getKey())) { - continue; - } - if (e.getValue() instanceof String) { - props.add(e.getKey()); - } - if (e.getValue() instanceof Map) { - for (Entry entry : ((Map) e.getValue()).entrySet()) { - props.add(entry.getKey()); - } - } - } - props.addAll(COMPULSORY_COLUMNS_KEYS); - return new ArrayList(props); - } -} diff --git a/course-mw/textbook-actors/src/main/java/org/sunbird/content/textbook/TextBookTocUploader.java b/course-mw/textbook-actors/src/main/java/org/sunbird/content/textbook/TextBookTocUploader.java deleted file mode 100644 index b38f8f0a1..000000000 --- a/course-mw/textbook-actors/src/main/java/org/sunbird/content/textbook/TextBookTocUploader.java +++ /dev/null @@ -1,435 +0,0 @@ -package org.sunbird.content.textbook; - -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.csv.CSVPrinter; -import org.apache.commons.io.ByteOrderMark; -import org.apache.commons.lang3.StringUtils; -import org.sunbird.common.exception.ProjectCommonException; -import org.sunbird.common.models.util.JsonKey; -import org.sunbird.common.models.util.LoggerUtil; -import org.sunbird.common.models.util.ProjectUtil; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStreamWriter; -import java.nio.charset.StandardCharsets; -import java.text.MessageFormat; -import java.time.Instant; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.stream.IntStream; - -import static java.io.File.separator; -import static java.util.Objects.nonNull; -import static org.apache.commons.csv.CSVFormat.DEFAULT; -import static org.apache.commons.io.FileUtils.deleteQuietly; -import static org.apache.commons.io.FileUtils.touch; -import static org.apache.commons.lang3.StringUtils.equalsIgnoreCase; -import static org.sunbird.common.models.util.JsonKey.CHILDREN; -import static org.sunbird.common.models.util.JsonKey.CONTENT_MIME_TYPE_COLLECTION; -import static org.sunbird.common.models.util.JsonKey.CONTENT_PROPERTY_MIME_TYPE; -import static org.sunbird.common.models.util.JsonKey.CONTENT_PROPERTY_VISIBILITY; -import static org.sunbird.common.models.util.JsonKey.CONTENT_PROPERTY_VISIBILITY_PARENT; -import static org.sunbird.common.models.util.JsonKey.IDENTIFIER; -import static org.sunbird.common.models.util.JsonKey.VERSION_KEY; -import static org.sunbird.common.models.util.ProjectUtil.getConfigValue; -import static org.sunbird.common.responsecode.ResponseCode.SERVER_ERROR; -import static org.sunbird.common.responsecode.ResponseCode.errorProcessingRequest; -import static org.sunbird.content.textbook.FileExtension.Extension.CSV; -import static org.sunbird.content.textbook.TextBookTocFileConfig.COLUMN_NAMES; -import static org.sunbird.content.textbook.TextBookTocFileConfig.COLUMN_NAMES_ARRAY; -import static org.sunbird.content.textbook.TextBookTocFileConfig.COMPULSORY_COLUMNS_KEYS; -import static org.sunbird.content.textbook.TextBookTocFileConfig.HIERARCHY; -import static org.sunbird.content.textbook.TextBookTocFileConfig.HIERARCHY_KEYS; -import static org.sunbird.content.textbook.TextBookTocFileConfig.HIERARCHY_PROPERTY; -import static org.sunbird.content.textbook.TextBookTocFileConfig.KEY_NAMES; -import static org.sunbird.content.textbook.TextBookTocFileConfig.LEVELS; -import static org.sunbird.content.textbook.TextBookTocFileConfig.ROW_METADATA; -import static org.sunbird.content.textbook.TextBookTocFileConfig.SUPPRESS_EMPTY_COLUMNS; -import static org.sunbird.content.util.ContentCloudStore.upload; -import static org.sunbird.content.util.TextBookTocUtil.getObjectFrom; -import static org.sunbird.content.util.TextBookTocUtil.stringify; - -public class TextBookTocUploader { - public static final String TEXTBOOK_TOC_FOLDER = separator + "textbook" + separator + "toc"; - private Set viewableColumns; - - private String textBookTocFileName; - private FileExtension fileExtension; - - private Map row; - - private List> rows = new ArrayList<>(); - private List> parentChildHierarchyMapList = new ArrayList<>(); - private LoggerUtil logger = new LoggerUtil(TextBookTocUploader.class); - - public TextBookTocUploader(String textBookTocFileName, FileExtension fileExtension) { - this.textBookTocFileName = textBookTocFileName; - this.fileExtension = null == fileExtension ? CSV.getFileExtension() : fileExtension; - if (SUPPRESS_EMPTY_COLUMNS) { - viewableColumns = new HashSet<>(); - viewableColumns.addAll(COMPULSORY_COLUMNS_KEYS); - } - } - - public String execute(Map content, String textbookId, String versionKey) { - - if (!HIERARCHY.filter(h -> 0 != h.size()).isPresent()) return ""; - parentChildHierarchyMapList = - getParentChildHierarchy( - textbookId, (List>) content.get(JsonKey.CHILDREN)); - logger.info(null, - "Creating CSV for TextBookToC | Id: " + textbookId + "Version Key: " + versionKey); - File file = null; - try { - file = new File(this.textBookTocFileName + fileExtension.getDotExtension()); - deleteQuietly(file); - logger.info(null, "Creating file for CSV at Location: " + file.getAbsolutePath()); - touch(file); - Instant startTime = Instant.now(); - populateDataIntoFile(content, file); - logger.info(null, - "Timed:TextBookTocUploader:execute time taken in processing " - + (Instant.now().getEpochSecond() - startTime.getEpochSecond())); - logger.info(null, - "Uploading " - + fileExtension.getExtension() - + " to Cloud Storage for TextBookToC | Id: " - + textbookId - + ", Version Key: " - + versionKey); - return upload(TEXTBOOK_TOC_FOLDER, file); - } catch (IOException e) { - logger.error(null, - "Error creating " - + fileExtension.getExtension() - + " File at File Path | " - + file.getAbsolutePath(), - e); - throw new ProjectCommonException( - errorProcessingRequest.getErrorCode(), - errorProcessingRequest.getErrorMessage(), - SERVER_ERROR.getResponseCode()); - } finally { - logger.info(null, - "Deleting " - + fileExtension.getExtension() - + " for TextBookToC | Id: " - + textbookId - + ", " - + "Version Key: " - + versionKey); - try { - if (null != file && file.exists()) file.delete(); - } catch (SecurityException e) { - logger.error(null, "Error! While deleting the local csv file: " + file.getAbsolutePath(), e); - } catch (Exception e) { - logger.error(null, - "Error! Something Went wrong while deleting csv file: " + file.getAbsolutePath(), - e); - } - } - } - - private void populateDataIntoFile(Map content, File file) { - OutputStreamWriter out = null; - CSVPrinter printer = null; - try { - if (SUPPRESS_EMPTY_COLUMNS) { - logger.info(null, "Processing Hierarchy for TextBook | Id: " + content.get(IDENTIFIER)); - processHierarchySuppressColumns(content); - - String[] columns = - IntStream.range(0, KEY_NAMES.size()) - .mapToObj( - i -> { - if (viewableColumns.contains(KEY_NAMES.get(i))) return COLUMN_NAMES.get(i); - else return null; - }) - .filter(Objects::nonNull) - .toArray(String[]::new); - out = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8); - out.write(ByteOrderMark.UTF_BOM); - logger.info(null, - "Writing Headers to Output Stream for Textbook | Id " + content.get(IDENTIFIER)); - printer = new CSVPrinter(out, DEFAULT.withHeader(columns)); - - logger.info(null, - "Writing Data to Output Stream for Textbook | Id " + content.get(IDENTIFIER)); - for (Map row : rows) { - updateBGMSData(row, content); - Object[] tempRow = - IntStream.range(0, KEY_NAMES.size()) - .mapToObj( - i -> { - if (viewableColumns.contains(KEY_NAMES.get(i))) { - Object o = row.get(KEY_NAMES.get(i)); - return null == o ? "" : o; - } - return null; - }) - .filter(Objects::nonNull) - .toArray(Object[]::new); - printer.printRecord(tempRow); - } - - logger.info(null, - "Flushing Data to File | Location:" - + file.getAbsolutePath() - + " | for TextBook | Id: " - + content.get(IDENTIFIER)); - } else { - logger.info(null, "Processing Hierarchy for TextBook | Id: " + content.get(IDENTIFIER)); - processHierarchy(content); - - out = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8); - out.write(ByteOrderMark.UTF_BOM); - - logger.info(null, - "Writing Headers to Output Stream for Textbook | Id " + content.get(IDENTIFIER)); - printer = new CSVPrinter(out, DEFAULT.withHeader(COLUMN_NAMES_ARRAY)); - - logger.info(null, - "Writing Data to Output Stream for Textbook | Id " + content.get(IDENTIFIER)); - for (Map row : rows) { - updateBGMSData(row, content); - Object[] tempRow = - IntStream.range(0, KEY_NAMES.size()) - .mapToObj(i -> row.get(KEY_NAMES.get(i))) - .toArray(Object[]::new); - - printer.printRecord(tempRow); - } - } - } catch (IOException e) { - logger.error(null, - "Error writing data to file | TextBook Id:" - + content.get(IDENTIFIER) - + "Version Key: " - + content.get(VERSION_KEY), - e); - throw new ProjectCommonException( - errorProcessingRequest.getErrorCode(), - errorProcessingRequest.getErrorMessage(), - SERVER_ERROR.getResponseCode()); - } finally { - logger.info(null, - "Flushing Data to File | Location:" - + file.getAbsolutePath() - + " | for TextBook | Id: " - + content.get(IDENTIFIER)); - try { - if (nonNull(printer)) { - printer.close(); - } - if (nonNull(out)) { - out.close(); - } - } catch (IOException e) { - logger.error(null, - "Error writing data to file | TextBook Id:" - + content.get(IDENTIFIER) - + "Version Key: " - + content.get(VERSION_KEY), - e); - } - } - } - - public void initializeRow() { - row = new HashMap<>(); - } - - private String updateRowWithData(Map content, String key, int hierarchyLevel) { - String k = (-1 == hierarchyLevel) ? key : HIERARCHY_KEYS.get(hierarchyLevel); - if (null == content || null == content.get(key)) { - row.remove(k); - } else { - row.put(k, stringify(content.get(key))); - } - return k; - } - - private void processHierarchy(Map contentHierarchy) { - initializeRow(); - int level = 0; - updateRowWithData(contentHierarchy, HIERARCHY_PROPERTY, level); - processHierarchyRecursive(contentHierarchy, level); - } - - private void processHierarchyRecursive(Map contentHierarchy, int level) { - List> children = (List>) contentHierarchy.get(CHILDREN); - if (null != children && !children.isEmpty()) { - if (LEVELS - 1 == level) return; - for (Map child : children) { - if (equalsIgnoreCase( - CONTENT_PROPERTY_VISIBILITY_PARENT, (String) child.get(CONTENT_PROPERTY_VISIBILITY)) - && StringUtils.equals( - CONTENT_MIME_TYPE_COLLECTION, - (String) contentHierarchy.get(CONTENT_PROPERTY_MIME_TYPE))) { - updateMetadata(child, ++level); - appendRow(); - processHierarchyRecursive(child, level); - updateMetadata(null, level--); - } - } - } - } - - private void updateMetadata(Map content, int level) { - updateRowWithData(content, HIERARCHY_PROPERTY, level); - for (String e : ROW_METADATA) { - updateRowWithData(content, e, -1); - } - updateRowWithLinkedContent(); - } - - @SuppressWarnings("unchecked") - private void updateRowWithLinkedContent() { - String identifier = (String) row.get(JsonKey.IDENTIFIER); - if (StringUtils.isNotBlank(identifier)) { - Optional> contentMap = - parentChildHierarchyMapList - .stream() - .filter( - s -> { - for (Entry entry : s.entrySet()) { - if (identifier.equalsIgnoreCase(entry.getKey())) { - return true; - } - } - return false; - }) - .findFirst(); - if (contentMap.isPresent()) { - Map childrenMap = contentMap.get(); - List> children = - (List>) - ((Map) childrenMap.get(identifier)).get(JsonKey.CHILDREN); - AtomicInteger linkedContent = new AtomicInteger(1); - children - .stream() - .filter( - s -> - !(JsonKey.TEXTBOOK.equalsIgnoreCase((String) s.get(JsonKey.CONTENT_TYPE)) - || JsonKey.TEXTBOOK_UNIT.equalsIgnoreCase( - (String) s.get(JsonKey.CONTENT_TYPE)))) - .sorted( - (s, p) -> { - return (int) s.get(JsonKey.INDEX) - (int) p.get(JsonKey.INDEX); - }) - .forEach( - s -> { - String key = - MessageFormat.format( - ProjectUtil.getConfigValue( - JsonKey.SUNBIRD_TOC_LINKED_CONTENT_COLUMN_NAME), - linkedContent.getAndAdd(1)); - if (ROW_METADATA.contains(key)) { - row.put(key, (String) s.get(JsonKey.IDENTIFIER)); - } - }); - } - } - } - - @SuppressWarnings("unchecked") - private List> getParentChildHierarchy( - String parentId, List> children) { - List> hierarchyList = new ArrayList<>(); - Map hierarchy = new HashMap<>(); - Map node = new HashMap<>(); - List> contentIdList = new ArrayList<>(); - node.put(JsonKey.CHILDREN, contentIdList); - hierarchy.put(parentId, node); - hierarchyList.add(hierarchy); - for (Map child : children) { - Map contentIds = new HashMap<>(); - contentIds.put(JsonKey.IDENTIFIER, child.get(JsonKey.IDENTIFIER)); - contentIds.put(JsonKey.INDEX, child.get(JsonKey.INDEX)); - contentIds.put(JsonKey.CONTENT_TYPE, child.get(JsonKey.CONTENT_TYPE)); - contentIdList.add(contentIds); - if (CollectionUtils.isNotEmpty((List>) child.get(JsonKey.CHILDREN))) { - hierarchyList.addAll( - getParentChildHierarchy( - (String) child.get(JsonKey.IDENTIFIER), - (List>) child.get(JsonKey.CHILDREN))); - } - } - return hierarchyList; - } - - private void appendRow() { - Map tempRow = new HashMap<>(); - tempRow.putAll(row); - rows.add(tempRow); - } - - private void processHierarchySuppressColumns(Map contentHierarchy) { - initializeRow(); - int level = 0; - updateRowWithDataSuppressColumns(contentHierarchy, HIERARCHY_PROPERTY, level); - processHierarchyRecursiveSuppressColumns(contentHierarchy, level); - } - - private void processHierarchyRecursiveSuppressColumns( - Map contentHierarchy, int level) { - List> children = (List>) contentHierarchy.get(CHILDREN); - if (null != children && !children.isEmpty()) { - if (LEVELS - 1 == level) return; - for (Map child : children) { - if (equalsIgnoreCase( - CONTENT_PROPERTY_VISIBILITY_PARENT, (String) child.get(CONTENT_PROPERTY_VISIBILITY)) - && StringUtils.equals( - CONTENT_MIME_TYPE_COLLECTION, - (String) contentHierarchy.get(CONTENT_PROPERTY_MIME_TYPE))) { - updateMetadataSuppressColumns(child, ++level); - appendRow(); - processHierarchyRecursiveSuppressColumns(child, level); - updateMetadataSuppressColumns(null, level--); - } - } - } - } - - @SuppressWarnings("unchecked") - private void updateBGMSData(Map row, Map contentHierarchy) { - Map outputMapping = - getObjectFrom(getConfigValue(JsonKey.TEXTBOOK_TOC_OUTPUT_MAPPING), Map.class); - Map frameworkCategories = - (Map) outputMapping.get("frameworkCategories"); - for (Entry entry : frameworkCategories.entrySet()) { - String key = entry.getKey(); - if (null == contentHierarchy.get(key)) { - row.put(key, ""); - } else { - row.put(key, stringify(contentHierarchy.get(key))); - } - } - } - - private void updateRowWithDataSuppressColumns( - Map content, String key, int hierarchyLevel) { - String k = updateRowWithData(content, key, hierarchyLevel); - if (row.containsKey(k)) { - viewableColumns.add(k); - } - } - - private void updateMetadataSuppressColumns(Map content, int level) { - updateRowWithDataSuppressColumns(content, HIERARCHY_PROPERTY, level); - for (String e : ROW_METADATA) { - updateRowWithDataSuppressColumns(content, e, -1); - } - updateRowWithLinkedContent(); - } -} diff --git a/course-mw/textbook-actors/src/main/java/org/sunbird/content/util/ContentCloudStore.java b/course-mw/textbook-actors/src/main/java/org/sunbird/content/util/ContentCloudStore.java deleted file mode 100644 index 42ac3c676..000000000 --- a/course-mw/textbook-actors/src/main/java/org/sunbird/content/util/ContentCloudStore.java +++ /dev/null @@ -1,44 +0,0 @@ -package org.sunbird.content.util; - -import static java.io.File.separator; -import static org.sunbird.common.models.util.JsonKey.*; -import static org.sunbird.common.models.util.ProjectUtil.getConfigValue; -import java.io.File; -import org.sunbird.common.util.CloudStorageUtil; - -public class ContentCloudStore { - - public static String FOLDER = getConfigValue(CLOUD_FOLDER_CONTENT); - public static String storageType = getConfigValue(CONTENT_CLOUD_STORAGE_TYPE); - - public static String getUri(String prefix, boolean isDirectory) { - prefix = FOLDER + prefix; - try { - return CloudStorageUtil.getUri(storageType, getConfigValue(CONTENT_CLOUD_STORAGE_CONTAINER), prefix, isDirectory); - } catch (Exception e) { - return null; - } - } - - public static String upload(String objectKey, File file) { - objectKey = FOLDER + objectKey + separator; - if (file.isFile()) { - objectKey += file.getName(); - return CloudStorageUtil.upload( - storageType, getConfigValue(CONTENT_CLOUD_STORAGE_CONTAINER), objectKey, file.getAbsolutePath()); - } else { - return null; - } - } - - public static String upload(String storageType, String objectKey, File file) { - objectKey = FOLDER + objectKey + separator; - if (file.isFile()) { - objectKey += file.getName(); - return CloudStorageUtil.upload( - storageType, getConfigValue(CONTENT_CLOUD_STORAGE_CONTAINER), objectKey, file.getAbsolutePath()); - } else { - return null; - } - } -} diff --git a/course-mw/textbook-actors/src/main/java/org/sunbird/content/util/TextBookTocUtil.java b/course-mw/textbook-actors/src/main/java/org/sunbird/content/util/TextBookTocUtil.java deleted file mode 100644 index 98a6bb390..000000000 --- a/course-mw/textbook-actors/src/main/java/org/sunbird/content/util/TextBookTocUtil.java +++ /dev/null @@ -1,173 +0,0 @@ -package org.sunbird.content.util; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.mashape.unirest.http.HttpResponse; -import com.mashape.unirest.http.Unirest; -import com.mashape.unirest.http.exceptions.UnirestException; -import org.apache.commons.lang3.StringUtils; -import org.sunbird.common.exception.ProjectCommonException; -import org.sunbird.common.models.response.Response; -import org.sunbird.common.models.util.JsonKey; -import org.sunbird.common.models.util.LoggerUtil; -import org.sunbird.common.responsecode.ResponseCode; - -import java.io.IOException; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -import static java.util.Objects.isNull; -import static org.apache.http.HttpHeaders.AUTHORIZATION; -import static org.sunbird.common.exception.ProjectCommonException.throwServerErrorException; -import static org.sunbird.common.models.util.JsonKey.BEARER; -import static org.sunbird.common.models.util.JsonKey.EKSTEP_BASE_URL; -import static org.sunbird.common.models.util.JsonKey.SUNBIRD_AUTHORIZATION; -import static org.sunbird.common.models.util.ProjectUtil.getConfigValue; -import static org.sunbird.common.responsecode.ResponseCode.SERVER_ERROR; -import static org.sunbird.common.responsecode.ResponseCode.errorProcessingRequest; - -public class TextBookTocUtil { - - private static ObjectMapper mapper = new ObjectMapper(); - private static LoggerUtil logger= new LoggerUtil(TextBookTocUtil.class); - - private static Map getHeaders() { - Map headers = new HashMap<>(); - headers.put(AUTHORIZATION, BEARER + getConfigValue(SUNBIRD_AUTHORIZATION)); - headers.put("Content-Type", "application/json"); - return headers; - } - - public static Response getRelatedFrameworkById(String frameworkId) { - logger.info(null, "TextBookTocUtil::getRelatedFrameworkById: frameworkId = " + frameworkId); - Map requestParams = new HashMap<>(); - requestParams.put("categories", "topic"); - return handleReadRequest(frameworkId, JsonKey.LEARNING_SERVICE_BASE_URL, JsonKey.FRAMEWORK_READ_API_URL, requestParams); - } - - private static String requestParams(Map params) { - if (null != params) { - StringBuilder sb = new StringBuilder(); - sb.append("?"); - int i = 0; - for (Entry param : params.entrySet()) { - if (i++ > 1) { - sb.append("&"); - } - sb.append(param.getKey()).append("=").append(param.getValue()); - } - return sb.toString(); - } else { - return ""; - } - } - - public static Response readContent(String contentId, String url) { - logger.info(null, "TextBookTocUtil::readContent: contentId = " + contentId); - Map requestParams = new HashMap<>(); - requestParams.put("mode", "edit"); - return handleReadRequest(contentId, url, requestParams); - } - - private static Response handleReadRequest( - String id, String basePath, String urlPath, Map requestParams) { - Map headers = getHeaders(); - ObjectMapper mapper = new ObjectMapper(); - if (StringUtils.isBlank(basePath)) - basePath = getConfigValue(EKSTEP_BASE_URL); - else - basePath = getConfigValue(basePath); - - Response response = null; - try { - String requestUrl = basePath + getConfigValue(urlPath) + "/" + id + requestParams(requestParams); - logger.info(null, "TextBookTocUtil:handleReadRequest: Sending GET Request | TextBook Id: " + id + ", Request URL: " + requestUrl); - HttpResponse httpResponse = Unirest.get(requestUrl).headers(headers).asString(); - - if (StringUtils.isBlank(httpResponse.getBody())) { - logger.error(null, "TextBookTocUtil:handleReadRequest: Received Empty Response | TextBook Id: " + id + ", Request URL: " + requestUrl, null); - throwServerErrorException( - ResponseCode.SERVER_ERROR, errorProcessingRequest.getErrorMessage()); - } - logger.info(null, "Sized :TextBookTocUtil:handleReadRequest: " + " TextBook Id: " + id + " | Request URL: " + requestUrl + " | size of response " + httpResponse.getBody().getBytes().length); - - response = mapper.readValue(httpResponse.getBody(), Response.class); - if (!ResponseCode.OK.equals(response.getResponseCode())) { - logger.error(null, "TextBookTocUtil:handleReadRequest: Response code is not ok | TextBook Id: " + id + "| Request URL: " + requestUrl, null); - throw new ProjectCommonException( - response.getResponseCode().name(), - response.getParams().getErrmsg(), - response.getResponseCode().getResponseCode()); - } - } catch (IOException e) { - logger.error(null, "TextBookTocUtil:handleReadRequest: Exception occurred with error message = " + e.getMessage(), e); - throwServerErrorException(ResponseCode.SERVER_ERROR); - } catch (UnirestException e) { - logger.error(null, "TextBookTocUtil:handleReadRequest: Exception occurred with error message = " + e.getMessage(), e); - throwServerErrorException(ResponseCode.SERVER_ERROR); - } - return response; - } - - private static Response handleReadRequest( - String id, String urlPath, Map requestParams) { - return handleReadRequest(id, null, urlPath, requestParams); - } - - public static T getObjectFrom(String s, Class clazz) { - if (StringUtils.isBlank(s)) { - logger.error(null, "Invalid String cannot be converted to Map.", null); - throw new ProjectCommonException( - errorProcessingRequest.getErrorCode(), - errorProcessingRequest.getErrorMessage(), - SERVER_ERROR.getResponseCode()); - } - - try { - return mapper.readValue(s, clazz); - } catch (IOException e) { - logger.error(null, "Error Mapping File input Mapping Properties.", e); - throw new ProjectCommonException( - errorProcessingRequest.getErrorCode(), - errorProcessingRequest.getErrorMessage(), - SERVER_ERROR.getResponseCode()); - } - } - - public static String serialize(T o) { - try { - return mapper.writeValueAsString(o); - } catch (JsonProcessingException e) { - logger.error(null, "Error Serializing Object To String", e); - throw new ProjectCommonException( - errorProcessingRequest.getErrorCode(), - errorProcessingRequest.getErrorMessage(), - SERVER_ERROR.getResponseCode()); - } - } - - public static Object stringify(Object o) { - if (isNull(o)) return ""; - if (o instanceof List) { - List l = (List) o; - if (!l.isEmpty() && l.get(0) instanceof String) { - return String.join(",", l); - } - else if (l.isEmpty()) { - return ""; - } - } - if (o instanceof String[]) { - String[] l = (String[]) o; - if (l.length > 0) { - return String.join(",", l); - } - else { - return ""; - } - } - return o; - } -} diff --git a/course-mw/textbook-actors/src/main/java/org/sunbird/learner/actors/textbook/TextbookActorOperation.java b/course-mw/textbook-actors/src/main/java/org/sunbird/learner/actors/textbook/TextbookActorOperation.java deleted file mode 100644 index 4eeb768e0..000000000 --- a/course-mw/textbook-actors/src/main/java/org/sunbird/learner/actors/textbook/TextbookActorOperation.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.sunbird.learner.actors.textbook; - -/** - * This enum holds actor operations for Textbook TOC API. - * - * @author gauraw - */ -public enum TextbookActorOperation { - TEXTBOOK_TOC_UPLOAD("textbookTocUpload"), - TEXTBOOK_TOC_URL("textbookTocUrl"); - - private String value; - - TextbookActorOperation(String value) { - this.value = value; - } - - public String getValue() { - return this.value; - } -} diff --git a/course-mw/textbook-actors/src/main/java/org/sunbird/learner/actors/textbook/TextbookTocActor.java b/course-mw/textbook-actors/src/main/java/org/sunbird/learner/actors/textbook/TextbookTocActor.java deleted file mode 100644 index 900331e7d..000000000 --- a/course-mw/textbook-actors/src/main/java/org/sunbird/learner/actors/textbook/TextbookTocActor.java +++ /dev/null @@ -1,1627 +0,0 @@ -package org.sunbird.learner.actors.textbook; - -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.mashape.unirest.http.HttpResponse; -import com.mashape.unirest.http.Unirest; -import org.apache.commons.codec.digest.DigestUtils; -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.collections.MapUtils; -import org.apache.commons.csv.CSVFormat; -import org.apache.commons.csv.CSVParser; -import org.apache.commons.csv.CSVRecord; -import org.apache.commons.io.ByteOrderMark; -import org.apache.commons.io.input.BOMInputStream; -import org.apache.commons.lang3.BooleanUtils; -import org.apache.commons.lang3.SerializationUtils; -import org.apache.commons.lang3.StringUtils; -import org.sunbird.actor.base.BaseActor; -import org.sunbird.common.exception.ProjectCommonException; -import org.sunbird.common.models.response.Response; -import org.sunbird.common.models.util.JsonKey; -import org.sunbird.common.models.util.LoggerEnum; -import org.sunbird.common.models.util.ProjectUtil; -import org.sunbird.common.request.Request; -import org.sunbird.common.responsecode.ResponseCode; -import org.sunbird.common.util.KeycloakRequiredActionLinkUtil; -import org.sunbird.content.textbook.FileExtension; -import org.sunbird.content.textbook.TextBookTocUploader; -import org.sunbird.content.util.TextBookTocUtil; -import org.sunbird.services.sso.SSOManager; -import org.sunbird.services.sso.SSOServiceFactory; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.nio.charset.StandardCharsets; -import java.text.MessageFormat; -import java.time.Instant; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Optional; -import java.util.Set; -import java.util.stream.Collectors; - -import static java.io.File.separator; -import static java.util.Arrays.asList; -import static org.apache.commons.lang3.StringUtils.isBlank; -import static org.sunbird.common.exception.ProjectCommonException.throwClientErrorException; -import static org.sunbird.common.exception.ProjectCommonException.throwServerErrorException; -import static org.sunbird.common.models.util.JsonKey.CHILDREN; -import static org.sunbird.common.models.util.JsonKey.CONTENT; -import static org.sunbird.common.models.util.JsonKey.CONTENT_TYPE; -import static org.sunbird.common.models.util.JsonKey.DOWNLOAD; -import static org.sunbird.common.models.util.JsonKey.HIERARCHY; -import static org.sunbird.common.models.util.JsonKey.MIME_TYPE; -import static org.sunbird.common.models.util.JsonKey.NAME; -import static org.sunbird.common.models.util.JsonKey.SUNBIRD_CONTENT_GET_HIERARCHY_API; -import static org.sunbird.common.models.util.JsonKey.TEXTBOOK; -import static org.sunbird.common.models.util.JsonKey.TEXTBOOK_ID; -import static org.sunbird.common.models.util.JsonKey.TEXTBOOK_TOC_ALLOWED_CONTNET_TYPES; -import static org.sunbird.common.models.util.JsonKey.TEXTBOOK_TOC_ALLOWED_MIMETYPE; -import static org.sunbird.common.models.util.JsonKey.TEXTBOOK_TOC_CSV_TTL; -import static org.sunbird.common.models.util.JsonKey.TOC_URL; -import static org.sunbird.common.models.util.JsonKey.TTL; -import static org.sunbird.common.models.util.JsonKey.VERSION_KEY; -import static org.sunbird.common.models.util.ProjectLogger.log; -import static org.sunbird.common.models.util.ProjectUtil.getConfigValue; -import static org.sunbird.common.models.util.Slug.makeSlug; -import static org.sunbird.common.responsecode.ResponseCode.SERVER_ERROR; -import static org.sunbird.common.responsecode.ResponseCode.invalidTextbook; -import static org.sunbird.common.responsecode.ResponseCode.noChildrenExists; -import static org.sunbird.common.responsecode.ResponseCode.textbookChildrenExist; -import static org.sunbird.content.textbook.FileExtension.Extension.CSV; -import static org.sunbird.content.textbook.TextBookTocUploader.TEXTBOOK_TOC_FOLDER; -import static org.sunbird.content.util.ContentCloudStore.getUri; -import static org.sunbird.content.util.TextBookTocUtil.getObjectFrom; -import static org.sunbird.content.util.TextBookTocUtil.readContent; -import static org.sunbird.content.util.TextBookTocUtil.serialize; - -public class TextbookTocActor extends BaseActor { - - private SSOManager ssoManager = SSOServiceFactory.getInstance(); - private Instant startTime = null; - private Map frameCategories = null; - private ObjectMapper mapper = new ObjectMapper(); - - @Override - public void onReceive(Request request) throws Throwable { - startTime = Instant.now(); - Map outputMapping = - getObjectFrom(getConfigValue(JsonKey.TEXTBOOK_TOC_OUTPUT_MAPPING), Map.class); - frameCategories = (Map) outputMapping.get("frameworkCategories"); - if (request - .getOperation() - .equalsIgnoreCase(TextbookActorOperation.TEXTBOOK_TOC_UPLOAD.getValue())) { - upload(request); - } else if (request - .getOperation() - .equalsIgnoreCase(TextbookActorOperation.TEXTBOOK_TOC_URL.getValue())) { - getTocUrl(request); - } else { - onReceiveUnsupportedOperation(request.getOperation()); - } - } - - @SuppressWarnings("unchecked") - private void upload(Request request) throws Exception { - byte[] byteArray = (byte[]) request.getRequest().get(JsonKey.DATA); - logger.info(null, "Sized:TextbookTocActor:upload size of request " + byteArray.length); - InputStream inputStream = new ByteArrayInputStream(byteArray); - Map resultMap = readAndValidateCSV(inputStream); - logger.info(null, - "Timed:TextbookTocActor:upload duration for read and validate csv: " - + (Instant.now().toEpochMilli() - startTime.toEpochMilli())); - Set dialCodes = (Set) resultMap.get(JsonKey.DIAL_CODES); - resultMap.remove(JsonKey.DIAL_CODES); - Map> reqDialCodeIdentifierMap = - (Map>) resultMap.get(JsonKey.DIAL_CODE_IDENTIFIER_MAP); - resultMap.remove(JsonKey.DIAL_CODE_IDENTIFIER_MAP); - Set topics = (Set) resultMap.get(JsonKey.TOPICS); - resultMap.remove(JsonKey.TOPICS); - Map> rowNumVsContentIdsMap = - (Map>) resultMap.get(JsonKey.LINKED_CONTENT); - resultMap.remove(JsonKey.LINKED_CONTENT); - validateLinkedContents(rowNumVsContentIdsMap); - logger.info(null, - "Timed:TextbookTocActor:upload duration for validate linked content: " - + (Instant.now().toEpochMilli() - startTime.toEpochMilli())); - resultMap.put(JsonKey.LINKED_CONTENT, false); - for (Entry> entry : rowNumVsContentIdsMap.entrySet()) { - if (CollectionUtils.isNotEmpty(entry.getValue())) { - resultMap.put(JsonKey.LINKED_CONTENT, true); - break; - } - } - String tbId = (String) request.get(TEXTBOOK_ID); - - Map hierarchy = getHierarchy(tbId); - logger.info(null, - "Timed:TextbookTocActor:upload duration for get hirearchy data: " - + (Instant.now().toEpochMilli() - startTime.toEpochMilli())); - validateTopics(topics, (String) hierarchy.get(JsonKey.FRAMEWORK)); - validateDialCodesWithReservedDialCodes(dialCodes, hierarchy, (String) request.getContext().getOrDefault(JsonKey.X_AUTH_TOKEN, "")); - checkDialCodeUniquenessInTextBookHierarchy(reqDialCodeIdentifierMap, hierarchy); - request.getRequest().put(JsonKey.DATA, resultMap); - String mode = ((Map) request.get(JsonKey.DATA)).get(JsonKey.MODE).toString(); - logger.info(null, - "Timed:TextbookTocActor:upload duration for validate topic and dial codes: " - + (Instant.now().toEpochMilli() - startTime.toEpochMilli())); - validateRequest(request, mode, hierarchy); - logger.info(null, - "Timed:TextbookTocActor:upload duration for validate request: " - + (Instant.now().toEpochMilli() - startTime.toEpochMilli())); - Response response = new Response(); - if (StringUtils.equalsIgnoreCase(mode, JsonKey.CREATE)) { - response = createTextbook(request, hierarchy); - } else if (StringUtils.equalsIgnoreCase(mode, JsonKey.UPDATE)) { - response = updateTextbook(request, hierarchy); - } else { - unSupportedMessage(); - } - logger.info(null, - "Timed:TextbookTocActor:upload duration for textbook " - + mode - + " :" - + (Instant.now().toEpochMilli() - startTime.toEpochMilli())); - sender().tell(response, sender()); - } - - private void validateLinkedContents(Map> rowNumVsContentIdsMap) - throws Exception { - // rowNumVsContentIdsMap convert to contentIdVsrowListMap - if (MapUtils.isNotEmpty(rowNumVsContentIdsMap)) { - Map> contentIdVsRowNumMap = new HashMap<>(); - rowNumVsContentIdsMap.forEach( - (k, v) -> { - v.forEach( - contentId -> { - if (contentIdVsRowNumMap.containsKey(contentId)) { - contentIdVsRowNumMap.get(contentId).add(k); - } else { - List rowNumList = new ArrayList<>(); - rowNumList.add(k); - contentIdVsRowNumMap.put(contentId, rowNumList); - } - }); - }); - callSearchApiForContentIdsValidation(contentIdVsRowNumMap); - } - } - - @SuppressWarnings("unchecked") - private void callSearchApiForContentIdsValidation(Map> contentIdVsRowNumMap) - throws Exception { - if (MapUtils.isEmpty(contentIdVsRowNumMap)) { - logger.info(null, - "TextbookTocActor:callSearchApiForContentIdsValidation : Content id map is Empty."); - return; - } - List contentIds = new ArrayList<>(); - contentIds.addAll(contentIdVsRowNumMap.keySet()); - Map requestMap = new HashMap<>(); - Map request = new HashMap<>(); - Map filters = new HashMap<>(); - filters.put(JsonKey.STATUS, "Live"); - filters.put(JsonKey.IDENTIFIER, contentIds); - request.put(JsonKey.FILTERS, filters); - requestMap.put(JsonKey.REQUEST, request); - List fields = new ArrayList<>(); - fields.add(JsonKey.IDENTIFIER); - request.put(JsonKey.FIELDS, fields); - request.put(JsonKey.LIMIT, contentIds.size()); - String requestUrl = - getConfigValue(JsonKey.SUNBIRD_CS_BASE_URL) - + getConfigValue(JsonKey.SUNBIRD_CONTENT_SEARCH_URL); - HttpResponse updateResponse = null; - logger.info(null, - "TextbookTocActor:callSearchApiForContentIdsValidation : requestUrl=" + requestUrl); - try { - updateResponse = - Unirest.post(requestUrl) - .headers(getDefaultHeaders()) - .body(mapper.writeValueAsString(requestMap)) - .asString(); - if (null != updateResponse) { - Response response = mapper.readValue(updateResponse.getBody(), Response.class); - logger.info(null, - "TextbookTocActor:callSearchApiForContentIdsValidation : response.getResponseCode().getResponseCode() : " - + response.getResponseCode().getResponseCode()); - if (response.getResponseCode().getResponseCode() == ResponseCode.OK.getResponseCode()) { - Map result = response.getResult(); - Set searchedContentIds = new HashSet<>(); - if (MapUtils.isNotEmpty(result)) { - int count = (int) result.get(JsonKey.COUNT); - if (0 == count) { - logger.info(null, - "TextbookTocActor:callSearchApiForContentIdsValidation : Content id count in response is zero."); - String errorMsg = prepareErrorMsg(contentIdVsRowNumMap, searchedContentIds); - ProjectCommonException.throwClientErrorException( - ResponseCode.errorInvalidLinkedContentId, errorMsg); - } - List> content = - (List>) result.get(JsonKey.CONTENT); - if (CollectionUtils.isNotEmpty(content)) { - content.forEach( - contentMap -> { - searchedContentIds.add((String) contentMap.get(JsonKey.IDENTIFIER)); - }); - if (searchedContentIds.size() != contentIds.size()) { - String errorMsg = prepareErrorMsg(contentIdVsRowNumMap, searchedContentIds); - ProjectCommonException.throwClientErrorException( - ResponseCode.errorInvalidLinkedContentId, errorMsg); - } - } else { - logger.info(null, - "TextbookTocActor:callSearchApiForContentIdsValidation : Content is Empty."); - throwCompositeSearchFailureError(); - } - } - } else { - logger.info(null, - "TextbookTocActor:callSearchApiForContentIdsValidation : response.getResponseCode().getResponseCode() is not 200"); - throwCompositeSearchFailureError(); - } - } else { - logger.info(null, - "TextbookTocActor:callSearchApiForContentIdsValidation : update response is null."); - throwCompositeSearchFailureError(); - } - } catch (Exception e) { - logger.error(null, - "TextbookTocActor:validateLinkedContents : Error occurred with message " + e.getMessage(), - e); - if (e instanceof ProjectCommonException) { - throw e; - } - throwCompositeSearchFailureError(); - } - } - - private String prepareErrorMsg( - Map> contentIdVsRowNumMap, Set searchedContentIds) { - StringBuilder errorMsg = new StringBuilder(); - contentIdVsRowNumMap - .keySet() - .forEach( - contentId -> { - if (!searchedContentIds.contains(contentId)) { - String message = - MessageFormat.format( - ResponseCode.errorInvalidLinkedContentId.getErrorMessage(), - contentId, - contentIdVsRowNumMap.get(contentId)); - errorMsg.append(message); - errorMsg.append(" "); - } - }); - return errorMsg.toString(); - } - - private void throwCompositeSearchFailureError() { - ProjectCommonException.throwServerErrorException( - ResponseCode.customServerError, "Exception occurred while validating linked content."); - } - - @SuppressWarnings("unchecked") - private void checkDialCodeUniquenessInTextBookHierarchy( - Map> reqDialCodesIdentifierMap, Map contentHierarchy) { - if (MapUtils.isNotEmpty(reqDialCodesIdentifierMap)) { - Map> hierarchyDialCodeIdentifierMap = new HashMap<>(); - List contentDialCodes = (List) contentHierarchy.get(JsonKey.DIAL_CODES); - if (CollectionUtils.isNotEmpty(contentDialCodes)) { - hierarchyDialCodeIdentifierMap.put( - (String) contentHierarchy.get(JsonKey.IDENTIFIER), contentDialCodes); - } - - List> children = - (List>) contentHierarchy.get(JsonKey.CHILDREN); - hierarchyDialCodeIdentifierMap.putAll(getDialCodeIdentifierMap(children)); - - Map reqDialCodeMap = - convertDialcodeToIdentifierMap(reqDialCodesIdentifierMap); - if (MapUtils.isNotEmpty(hierarchyDialCodeIdentifierMap)) { - Map hierarchyDialCodeMap = - convertDialcodeToIdentifierMap(hierarchyDialCodeIdentifierMap); - validateReqDialCode(reqDialCodeMap, hierarchyDialCodeMap); - } - } - } - - private void validateReqDialCode( - Map reqDialCodeMap, Map hierarchyDialCodeMap) { - reqDialCodeMap.forEach( - (k, v) -> { - if (StringUtils.isNotBlank(hierarchyDialCodeMap.get(k)) - && !v.equalsIgnoreCase(hierarchyDialCodeMap.get(k))) { - throwClientErrorException( - ResponseCode.errorDialCodeAlreadyAssociated, - MessageFormat.format( - ResponseCode.errorDialCodeAlreadyAssociated.getErrorMessage(), - k, - hierarchyDialCodeMap.get(k))); - } - }); - } - - private Map convertDialcodeToIdentifierMap( - Map> identifierDialCodeMap) { - Map dialCodeIdentifierMap = new HashMap<>(); - if (MapUtils.isNotEmpty(identifierDialCodeMap)) { - identifierDialCodeMap.forEach( - (k, v) -> { - v.forEach( - dialcode -> { - if (dialCodeIdentifierMap.containsKey(dialcode)) { - throwClientErrorException( - ResponseCode.errorDialCodeDuplicateEntry, - MessageFormat.format( - ResponseCode.errorDialCodeDuplicateEntry.getErrorMessage(), k, v)); - } else { - dialCodeIdentifierMap.put(dialcode, k); - } - }); - }); - } - return dialCodeIdentifierMap; - } - - @SuppressWarnings("unchecked") - public Map> getDialCodeIdentifierMap(List> children) { - Map> hierarchyDialCodeIdentifierMap = new HashMap<>(); - for (Map child : children) { - if (CollectionUtils.isNotEmpty((List) child.get(JsonKey.DIAL_CODES))) { - hierarchyDialCodeIdentifierMap.put( - (String) child.get(JsonKey.IDENTIFIER), (List) child.get(JsonKey.DIAL_CODES)); - } - if (CollectionUtils.isNotEmpty((List>) child.get(JsonKey.CHILDREN))) { - hierarchyDialCodeIdentifierMap.putAll( - getDialCodeIdentifierMap((List>) child.get(JsonKey.CHILDREN))); - } - } - return hierarchyDialCodeIdentifierMap; - } - - private void validateTopics(Set topics, String frameworkId) { - if (CollectionUtils.isNotEmpty(topics)) { - List frameworkTopics = getRelatedFrameworkTopics(frameworkId); - Set invalidTopics = new HashSet<>(); - topics.forEach( - name -> { - if (!frameworkTopics.contains(name)) { - invalidTopics.add(name); - } - }); - if (CollectionUtils.isNotEmpty(invalidTopics)) { - throwClientErrorException( - ResponseCode.errorInvalidTopic, - MessageFormat.format( - ResponseCode.errorInvalidTopic.getErrorMessage(), - StringUtils.join(invalidTopics, ','))); - } - } - } - - @SuppressWarnings("unchecked") - private List getRelatedFrameworkTopics(String frameworkId) { - Response response = TextBookTocUtil.getRelatedFrameworkById(frameworkId); - Map result = response.getResult(); - List> terms = new ArrayList<>(); - if (MapUtils.isNotEmpty(result)) { - Map framework = (Map) result.get(JsonKey.FRAMEWORK); - if (MapUtils.isNotEmpty(framework)) { - List> categories = - (List>) framework.get(JsonKey.CATEGORIES); - if (CollectionUtils.isNotEmpty(categories)) - categories.forEach( - s -> { - if (JsonKey.TOPIC.equalsIgnoreCase((String) s.get(JsonKey.CODE))) { - terms.addAll((List>) s.get(JsonKey.TERMS)); - } - }); - } - } - return getTopic(terms); - } - - @SuppressWarnings("unchecked") - public List getTopic(List> children) { - List topics = new ArrayList<>(); - for (Map child : children) { - topics.add((String) child.get(JsonKey.NAME)); - if (null != child.get(JsonKey.CHILDREN)) { - topics.addAll(getTopic((List>) child.get(JsonKey.CHILDREN))); - } - } - return topics; - } - - private void validateDialCodesWithReservedDialCodes( - Set dialCodes, Map textbookData, String authToken) { - String channel = (String) textbookData.get(JsonKey.CHANNEL); - if (CollectionUtils.isNotEmpty(dialCodes)) { - Set invalidDialCodes = new HashSet<>(); - List searchedDialcodes = callDialcodeSearchApi(dialCodes, channel, authToken); - if (CollectionUtils.isNotEmpty(searchedDialcodes)) { - dialCodes.forEach( - dialCode -> { - if (!searchedDialcodes.contains(dialCode)) { - invalidDialCodes.add(dialCode); - } - }); - if (CollectionUtils.isNotEmpty(invalidDialCodes)) { - throwInvalidDialCodeError(invalidDialCodes); - } - } else if (CollectionUtils.isNotEmpty(dialCodes)) { - throwInvalidDialCodeError(dialCodes); - } - } - } - - private List callDialcodeSearchApi(Set dialCodes, String channel, String authToken) { - Map requestMap = new HashMap<>(); - Map request = new HashMap<>(); - requestMap.put(JsonKey.REQUEST, request); - Map search = new HashMap<>(); - request.put(JsonKey.SEARCH, search); - List identifier = new ArrayList<>(); - identifier.addAll(dialCodes); - search.put(JsonKey.IDENTIFIER, identifier); - - String requestUrl = - getConfigValue(JsonKey.SUNBIRD_CS_BASE_URL) - + getConfigValue(JsonKey.SUNBIRD_DIALCODE_SEARCH_API); - HttpResponse updateResponse = null; - List resDialcodes = new ArrayList<>(); - try { - Map headers = new HashMap<>(); - headers.putAll(getDefaultHeaders()); - headers.put("X-Channel-Id", channel); - headers.put( - "x-authenticated-user-token", authToken); - String reqBody = mapper.writeValueAsString(requestMap); - logger.info(null, - "Sized :TextBookTocUtil:callDialcodeSearchApi: size of request " - + reqBody.getBytes().length); - - updateResponse = Unirest.post(requestUrl).headers(headers).body(reqBody).asString(); - if (null != updateResponse) { - logger.info(null, - "Sized :TextBookTocUtil:callDialcodeSearchApi: size of response " - + updateResponse.getBody().getBytes().length); - Response response = mapper.readValue(updateResponse.getBody(), Response.class); - logger.info(null, - "TextbookTocActor:callDialcodeSearchApi : response.getResponseCode().getResponseCode() : " - + response.getResponseCode().getResponseCode()); - if (response.getResponseCode().getResponseCode() == ResponseCode.OK.getResponseCode()) { - Map result = response.getResult(); - if (MapUtils.isNotEmpty(result)) { - List> dialcodes = - (List>) result.get(JsonKey.DIAL_CODES); - if (CollectionUtils.isNotEmpty(dialcodes)) { - dialcodes - .stream() - .forEach( - map -> { - resDialcodes.add((String) map.get(JsonKey.IDENTIFIER)); - }); - return resDialcodes; - } - } - } - } - } catch (Exception ex) { - logger.error(null, - "TextbookTocActor:callDialcodeSearchApi : Exception occurred with message:" - + ex.getMessage(), - ex); - ProjectCommonException.throwServerErrorException(ResponseCode.SERVER_ERROR); - } - return resDialcodes; - } - - private void throwInvalidDialCodeError(Set invalidDialCodes) { - throwClientErrorException( - ResponseCode.errorInvalidDialCode, - MessageFormat.format( - ResponseCode.errorInvalidDialCode.getErrorMessage(), - StringUtils.join(invalidDialCodes, ','))); - } - - @SuppressWarnings("unchecked") - private Map readAndValidateCSV(InputStream inputStream) throws IOException { - ObjectMapper mapper = new ObjectMapper(); - Map result = new HashMap<>(); - Map> rowNumVsContentIdsMap = new HashMap<>(); - List> rows = new ArrayList<>(); - String tocMapping = ProjectUtil.getConfigValue(JsonKey.TEXTBOOK_TOC_INPUT_MAPPING); - Map configMap = - mapper.readValue(tocMapping, new TypeReference>() {}); - - Map metadata = (Map) configMap.get(JsonKey.METADATA); - Map hierarchy = (Map) configMap.get(JsonKey.HIERARCHY); - int max_allowed_content_size = - Integer.parseInt(ProjectUtil.getConfigValue(JsonKey.SUNBIRD_TOC_MAX_FIRST_LEVEL_UNITS)); - String linkedContentKey = - ProjectUtil.getConfigValue(JsonKey.SUNBIRD_TOC_LINKED_CONTENT_COLUMN_NAME); - - Map fwMetadata = - (Map) configMap.get(JsonKey.FRAMEWORK_METADATA); - String id = - configMap - .getOrDefault(JsonKey.IDENTIFIER, StringUtils.capitalize(JsonKey.IDENTIFIER)) - .toString(); - metadata.putAll(fwMetadata); - CSVParser csvFileParser = null; - CSVFormat csvFileFormat = CSVFormat.DEFAULT.withHeader(); - BOMInputStream bomInputStream = - new BOMInputStream( - inputStream, - ByteOrderMark.UTF_16BE, - ByteOrderMark.UTF_8, - ByteOrderMark.UTF_16LE, - ByteOrderMark.UTF_32BE, - ByteOrderMark.UTF_32LE); - String character = StandardCharsets.UTF_8.name(); - if (bomInputStream.hasBOM()) { - character = bomInputStream.getBOMCharsetName(); - logger.info(null, "TextbookTocActor:readAndValidateCSV : BOM charset"); - } - try (InputStreamReader reader = new InputStreamReader(bomInputStream, character); ) { - csvFileParser = csvFileFormat.parse(reader); - HashMap csvHeaders = new HashMap<>(); - if (MapUtils.isNotEmpty(csvFileParser.getHeaderMap())) { - csvFileParser - .getHeaderMap() - .entrySet() - .forEach(entry -> csvHeaders.put(entry.getKey().trim(), entry.getValue())); - } - String mode = csvHeaders.containsKey(id) ? JsonKey.UPDATE : JsonKey.CREATE; - result.put(JsonKey.MODE, mode); - - if (null != csvHeaders && !csvHeaders.isEmpty()) { - metadata.values().removeIf(key -> !csvHeaders.keySet().contains(key)); - hierarchy.values().removeIf(key -> !csvHeaders.keySet().contains(key)); - } else { - throwClientErrorException(ResponseCode.blankCsvData); - } - - String mandatoryFields = getConfigValue(JsonKey.TEXTBOOK_TOC_MANDATORY_FIELDS); - Map mandatoryFieldsMap = - mapper.readValue(mandatoryFields, new TypeReference>() {}); - List missingColumns = - mandatoryFieldsMap - .values() - .stream() - .filter(field -> !csvHeaders.keySet().contains(field)) - .collect(Collectors.toList()); - if (CollectionUtils.isNotEmpty(missingColumns)) { - throwClientErrorException( - ResponseCode.mandatoryHeadersMissing, - MessageFormat.format( - "Mandatory column(s) {0} are missing", - String.join(", ", new ArrayList<>(missingColumns)))); - } - - List csvRecords = csvFileParser.getRecords(); - validateCSV(csvRecords); - Set dialCodes = new HashSet<>(); - Set duplicateDialCodes = new LinkedHashSet<>(); - Map> dialCodeIdentifierMap = new HashMap<>(); - Set topics = new HashSet<>(); - Map bgms = new HashMap<>(); - StringBuilder exceptionMsgs = new StringBuilder(); - for (int i = 0; i < csvRecords.size(); i++) { - CSVRecord record = csvRecords.get(i); - Map trimMappingRecord = new HashMap<>(); - record - .toMap() - .entrySet() - .forEach( - entry -> - trimMappingRecord.put( - entry.getKey().trim(), - entry.getValue() != null ? entry.getValue().trim() : entry.getValue())); - HashMap recordMap = new HashMap<>(); - HashMap hierarchyMap = new HashMap<>(); - for (Map.Entry entry : metadata.entrySet()) { - if (StringUtils.isNotBlank(trimMappingRecord.get(entry.getValue()))) - recordMap.put(entry.getKey(), trimMappingRecord.get(entry.getValue())); - } - for (Map.Entry entry : hierarchy.entrySet()) { - if (StringUtils.isNotBlank(trimMappingRecord.get(entry.getValue()))) - hierarchyMap.put(entry.getKey(), trimMappingRecord.get(entry.getValue())); - } - validateBGMS(i, bgms, recordMap, metadata); - - if (!(MapUtils.isEmpty(recordMap) && MapUtils.isEmpty(hierarchyMap))) { - validateQrCodeRequiredAndQrCode(recordMap); - String dialCode = (String) recordMap.get(JsonKey.DIAL_CODES); - List dialCodeList = null; - if (StringUtils.isNotBlank(dialCode)) { - dialCodeList = new ArrayList(Arrays.asList(dialCode.split(","))); - for (String dCode : dialCodeList) { - if (!dialCodes.add(dCode.trim())) { - duplicateDialCodes.add(dCode.trim()); - } - } - } - - String reqTopics = (String) recordMap.get(JsonKey.TOPIC); - if (StringUtils.isNotBlank(reqTopics)) { - List topicList = new ArrayList(Arrays.asList(reqTopics.split(","))); - topicList.forEach( - s -> { - topics.add(s.trim()); - }); - } - Map map = new HashMap<>(); - if (JsonKey.UPDATE.equalsIgnoreCase(mode) - && StringUtils.isNotBlank(trimMappingRecord.get(id))) { - String identifier = trimMappingRecord.get(id); - map.put(JsonKey.IDENTIFIER, identifier); - if (CollectionUtils.isNotEmpty(dialCodeList)) { - dialCodeIdentifierMap.put(identifier, dialCodeList); - } - } - List contentIds = Collections.EMPTY_LIST; - try { - contentIds = - validateLinkedContentAndGetContentIds( - max_allowed_content_size, linkedContentKey, record, i + 1); - rowNumVsContentIdsMap.put(i + 1, contentIds); - } catch (Exception ex) { - exceptionMsgs.append(ex.getMessage()); - exceptionMsgs.append(" "); - } - map.put(JsonKey.METADATA, recordMap); - map.put(JsonKey.HIERARCHY, hierarchyMap); - map.put(JsonKey.CHILDREN, contentIds); - rows.add(map); - } - } - if (CollectionUtils.isNotEmpty(duplicateDialCodes)) { - throwClientErrorException( - ResponseCode.errorDduplicateDialCodeEntry, - MessageFormat.format( - ResponseCode.errorDduplicateDialCodeEntry.getErrorMessage(), - StringUtils.join(duplicateDialCodes, ","))); - } - if (StringUtils.isNotBlank(exceptionMsgs.toString())) { - ProjectCommonException.throwClientErrorException( - ResponseCode.customClientError, exceptionMsgs.toString()); - } - result.put(JsonKey.FILE_DATA, rows); - result.put(JsonKey.DIAL_CODES, dialCodes); - result.put(JsonKey.TOPICS, topics); - result.put(JsonKey.DIAL_CODE_IDENTIFIER_MAP, dialCodeIdentifierMap); - result.put(JsonKey.LINKED_CONTENT, rowNumVsContentIdsMap); - } catch (IllegalArgumentException e) { - ProjectCommonException.throwClientErrorException( - ResponseCode.customClientError, e.getMessage()); - } catch (ProjectCommonException e) { - throw e; - } catch (Exception e) { - throwServerErrorException(ResponseCode.errorProcessingFile); - } finally { - try { - if (null != csvFileParser) csvFileParser.close(); - } catch (IOException e) { - logger.error(null, - "TextbookTocActor:readAndValidateCSV : Exception occurred while closing stream", e); - } - } - return result; - } - - private void validateBGMS( - int recordNum, - Map bgms, - HashMap recordMap, - Map metadata) { - if (recordNum == 0) { - getBgmsData(recordMap, bgms); - } else { - handleBGMSMismatchValidation(recordNum, metadata, bgms, recordMap); - } - // Removing fields from updating further - recordMap.remove(JsonKey.BOARD); - recordMap.remove(JsonKey.MEDIUM); - recordMap.remove(JsonKey.GRADE_LEVEL); - recordMap.remove(JsonKey.SUBJECT); - } - - private void getBgmsData(HashMap recordMap, Map bgms) { - for (Entry entry : frameCategories.entrySet()) { - String key = entry.getKey(); - bgms.put(key, recordMap.get(key)); - } - } - - private void handleBGMSMismatchValidation( - int recordNum, - Map metadata, - Map bgms, - HashMap recordMap) { - for (Entry entry : frameCategories.entrySet()) { - String key = entry.getKey(); - if (null != bgms.get(key) && null != recordMap.get(key)) { - String bgmsKey = ((String) bgms.get(key)).toLowerCase(); - String recordMapKey = ((String) recordMap.get(key)).toLowerCase(); - List bgmsKeyList = - (Arrays.stream(bgmsKey.split(",")).map(s -> s.trim()).collect(Collectors.toList())); - - Arrays.stream(recordMapKey.split(",")) - .forEach( - s -> { - if (!bgmsKeyList.contains(s.trim())) { - throwClientErrorException( - ResponseCode.errorBGMSMismatch, - MessageFormat.format( - ResponseCode.errorBGMSMismatch.getErrorMessage(), - metadata.get(key), - recordNum + 1)); - } - }); - } else if ((null != bgms.get(key) && null == recordMap.get(key)) - || (null == bgms.get(key) && null != recordMap.get(key))) { - throwClientErrorException( - ResponseCode.errorBGMSMismatch, - MessageFormat.format( - ResponseCode.errorBGMSMismatch.getErrorMessage(), - metadata.get(key), - recordNum + 1)); - } - } - } - - private List validateLinkedContentAndGetContentIds( - int max_allowed_content_size, String linkedContentKey, CSVRecord record, int rowNumber) { - List contentIds = new ArrayList<>(); - for (int i = 1; i <= max_allowed_content_size; i++) { - String key = MessageFormat.format(linkedContentKey, i).trim(); - if (record.isMapped(key)) { - String contentId = record.get(key); - if (StringUtils.isNotBlank(contentId)) { - if (contentIds.contains(contentId)) { - String message = - MessageFormat.format( - ResponseCode.errorDuplicateLinkedContentId.getErrorMessage(), - record.get(key), - rowNumber); - ProjectCommonException.throwClientErrorException( - ResponseCode.errorDuplicateLinkedContentId, message); - } - contentIds.add(contentId); - } else { - break; - } - } - } - return contentIds; - } - - private void validateQrCodeRequiredAndQrCode(Map recordMap) { - if (JsonKey.NO.equalsIgnoreCase((String) recordMap.get(JsonKey.DIAL_CODE_REQUIRED)) - && StringUtils.isNotBlank((String) recordMap.get(JsonKey.DIAL_CODES))) { - String errorMessage = - MessageFormat.format( - ResponseCode.errorConflictingValues.getErrorMessage(), - JsonKey.QR_CODE_REQUIRED, - JsonKey.NO, - JsonKey.QR_CODE, - recordMap.get(JsonKey.DIAL_CODES)); - throwClientErrorException(ResponseCode.errorConflictingValues, errorMessage); - } - } - - private void validateCSV(List records) { - if (CollectionUtils.isEmpty(records)) { - throwClientErrorException( - ResponseCode.blankCsvData, ResponseCode.blankCsvData.getErrorMessage()); - } - Integer allowedNumberOfRecord = - Integer.valueOf(ProjectUtil.getConfigValue(JsonKey.TEXTBOOK_TOC_MAX_CSV_ROWS)); - if (CollectionUtils.isNotEmpty(records) && records.size() > allowedNumberOfRecord) { - throwClientErrorException( - ResponseCode.csvRowsExceeds, - ResponseCode.csvRowsExceeds.getErrorMessage() + allowedNumberOfRecord); - } - } - - private void getTocUrl(Request request) { - String textbookId = (String) request.get(TEXTBOOK_ID); - if (isBlank(textbookId)) { - logger.error(null, "Invalid TextBook Provided", null); - throwClientErrorException(invalidTextbook, invalidTextbook.getErrorMessage()); - } - logger.debug(null, "Reading Content for TextBook | Id: " + textbookId); - Map contentHierarchy = getHierarchy(textbookId); - logger.info(null, - "Timed:TextbookTocActor:getTocUrl duration for get textbook: " - + (Instant.now().toEpochMilli() - startTime.toEpochMilli())); - validateTextBook(contentHierarchy, DOWNLOAD); - FileExtension fileExtension = CSV.getFileExtension(); - String contentVersionKey = (String) contentHierarchy.get(VERSION_KEY); - String textBookNameSlug = makeSlug((String) contentHierarchy.get(NAME), true); - String textBookTocFileName = textbookId + "_" + textBookNameSlug + "_" + contentVersionKey; - String prefix = - TEXTBOOK_TOC_FOLDER + separator + textBookTocFileName + fileExtension.getDotExtension(); - //No need to make any changes here as the uri is being generated based on the cloud service providers - String cloudPath = getUri(prefix, false); - logger.info(null, - "Timed:TextbookTocActor:getTocUrl duration for get cloud path url: " - + (Instant.now().toEpochMilli() - startTime.toEpochMilli())); - if (isBlank(cloudPath)) { - logger.info(null, "Reading Hierarchy for TextBook | Id: " + textbookId); - logger.info(null, - "Timed:TextbookTocActor:getTocUrl duration for get hirearchy: " - + (Instant.now().toEpochMilli() - startTime.toEpochMilli())); - String hierarchyVersionKey = (String) contentHierarchy.get(VERSION_KEY); - cloudPath = - new TextBookTocUploader(textBookTocFileName, fileExtension) - .execute(contentHierarchy, textbookId, hierarchyVersionKey); - logger.info(null, - "Timed:TextbookTocActor:getTocUrl duration for processing preparing and uploading: " - + (Instant.now().toEpochMilli() - startTime.toEpochMilli())); - } - - logger.info(null, "Sending Response for Toc Download API for TextBook | Id: " + textbookId); - Map textbook = new HashMap<>(); - textbook.put(TOC_URL, cloudPath); - textbook.put(TTL, getConfigValue(TEXTBOOK_TOC_CSV_TTL)); - Response response = new Response(); - response.put(TEXTBOOK, textbook); - - sender().tell(response, sender()); - } - - @SuppressWarnings("unchecked") - private void validateTextBook(Map textbook, String mode) { - List allowedContentTypes = - asList(getConfigValue(TEXTBOOK_TOC_ALLOWED_CONTNET_TYPES).split(",")); - if (!TEXTBOOK_TOC_ALLOWED_MIMETYPE.equalsIgnoreCase(textbook.get(MIME_TYPE).toString()) - || !allowedContentTypes.contains(textbook.get(CONTENT_TYPE).toString())) { - throwClientErrorException(invalidTextbook, invalidTextbook.getErrorMessage()); - } - List children = (List) textbook.get(CHILDREN); - if (JsonKey.CREATE.equalsIgnoreCase(mode)) { - if (null != children && !children.isEmpty()) { - throwClientErrorException(textbookChildrenExist, textbookChildrenExist.getErrorMessage()); - } - } else if (DOWNLOAD.equalsIgnoreCase(mode)) { - if (null == children || children.isEmpty()) - throwClientErrorException(noChildrenExists, noChildrenExists.getErrorMessage()); - } - } - - @SuppressWarnings("unchecked") - private void validateRequest(Request request, String mode, Map textbook) - throws IOException { - Set rowsHash = new HashSet<>(); - String mandatoryFields = getConfigValue(JsonKey.TEXTBOOK_TOC_MANDATORY_FIELDS); - Map mandatoryFieldsMap = - mapper.readValue(mandatoryFields, new TypeReference>() {}); - String textbookName = - textbook.get(JsonKey.NAME) != null - ? ((String) textbook.get(JsonKey.NAME)).trim() - : (String) textbook.get(JsonKey.NAME); - - validateTextBook(textbook, mode); - - List> fileData = - (List>) - ((Map) request.get(JsonKey.DATA)).get(JsonKey.FILE_DATA); - - for (int i = 0; i < fileData.size(); i++) { - Map row = fileData.get(i); - Boolean isAdded = - rowsHash.add( - DigestUtils.md5Hex(SerializationUtils.serialize(row.get(HIERARCHY).toString()))); - if (!isAdded) { - throwClientErrorException( - ResponseCode.duplicateRows, ResponseCode.duplicateRows.getErrorMessage() + (i + 1)); - } - Map hierarchy = (Map) row.get(JsonKey.HIERARCHY); - - String name = - ((String) hierarchy.getOrDefault(StringUtils.capitalize(JsonKey.TEXTBOOK), "")).trim(); - if (isBlank(name) || !StringUtils.equalsIgnoreCase(name, textbookName)) { - logger.error(null, - "Name mismatch. Content has: " + name + " but, file has: " + textbookName, - null); - throwClientErrorException( - ResponseCode.invalidTextbookName, ResponseCode.invalidTextbookName.getErrorMessage()); - } - for (String field : mandatoryFieldsMap.keySet()) { - if (!hierarchy.containsKey(field) - || isBlank(hierarchy.getOrDefault(field, "").toString())) { - throwClientErrorException( - ResponseCode.requiredFieldMissing, - ResponseCode.requiredFieldMissing.getErrorMessage() + mandatoryFieldsMap.values()); - } - } - } - } - - @SuppressWarnings("unchecked") - private Response createTextbook(Request request, Map textBookHierarchy) - throws Exception { - Map file = (Map) request.get(JsonKey.DATA); - List> data = (List>) file.get(JsonKey.FILE_DATA); - if (CollectionUtils.isEmpty(data)) { - throw new ProjectCommonException( - ResponseCode.invalidRequestData.getErrorCode(), - ResponseCode.invalidRequestData.getErrorMessage(), - ResponseCode.CLIENT_ERROR.getResponseCode()); - } else { - logger.info(null, - "Create Textbook - UpdateHierarchy input data : " + mapper.writeValueAsString(data)); - String tbId = (String) request.get(TEXTBOOK_ID); - Map nodesModified = new HashMap<>(); - Map hierarchyData = new HashMap<>(); - nodesModified.put( - tbId, - new HashMap() { - { - put(JsonKey.TB_IS_NEW, false); - put(JsonKey.TB_ROOT, true); - put(JsonKey.METADATA, new HashMap()); - } - }); - - hierarchyData.put( - tbId, - new HashMap() { - { - put(JsonKey.NAME, textBookHierarchy.get(JsonKey.NAME)); - put(CONTENT_TYPE, textBookHierarchy.get(CONTENT_TYPE)); - put(CHILDREN, new ArrayList<>()); - put(JsonKey.TB_ROOT, true); - } - }); - for (Map row : data) { - populateNodes(row, tbId, textBookHierarchy, nodesModified, hierarchyData); - } - - Map updateRequest = new HashMap(); - Map requestMap = new HashMap(); - Map dataMap = new HashMap(); - Map hierarchy = new HashMap(); - if (MapUtils.isNotEmpty(hierarchyData)) { - hierarchy.putAll(hierarchyData); - } - dataMap.put(JsonKey.NODES_MODIFIED, nodesModified); - dataMap.put(JsonKey.HIERARCHY, hierarchy); - requestMap.put(JsonKey.DATA, dataMap); - updateRequest.put(JsonKey.REQUEST, requestMap); - - logger.info(null, - "Timed:TextbookTocActor:createTextbook duration for processing create textbook: " - + (Instant.now().toEpochMilli() - startTime.toEpochMilli())); - logger.info(null, - "Create Textbook - UpdateHierarchy Request : " + mapper.writeValueAsString(updateRequest)); - return callUpdateHierarchyAndLinkDialCodeApi( - tbId, updateRequest, nodesModified, (String) textBookHierarchy.get(JsonKey.CHANNEL)); - } - } - - private Response callUpdateHierarchyAndLinkDialCodeApi( - String tbId, - Map updateRequest, - Map nodesModified, - String channel) - throws Exception { - Response response = new Response(); - updateHierarchy(tbId, updateRequest); - logger.info(null, - "Timed:TextbookTocActor:callUpdateHierarchyAndLinkDialCodeApi duration for update hirearchy data: " - + (Instant.now().toEpochMilli() - startTime.toEpochMilli())); - try { - linkDialCode(nodesModified, channel, tbId); - logger.info(null, - "Timed:TextbookTocActor:callUpdateHierarchyAndLinkDialCodeApi duration for link dial code: " - + (Instant.now().toEpochMilli() - startTime.toEpochMilli())); - } catch (Exception ex) { - logger.error(null, - "TextbookTocActor:callUpdateHierarchyAndLinkDialCodeApi : Exception occurred while linking dial code : ", - ex); - response - .getResult() - .put( - JsonKey.ERROR_MSG, - "Textbook hierarchy metadata got updated but, " - + ResponseCode.errorDialCodeLinkingFail.getErrorMessage()); - } - response.getResult().put(JsonKey.RESPONSE, JsonKey.SUCCESS); - return response; - } - - private void populateNodes( - Map row, - String tbId, - Map tbMetadata, - Map nodesModified, - Map hierarchyData) { - Map hierarchy = (Map) row.get(JsonKey.HIERARCHY); - hierarchy.remove(StringUtils.capitalize(JsonKey.TEXTBOOK)); - hierarchy.remove(JsonKey.IDENTIFIER); - String unitType = (String) tbMetadata.get(JsonKey.CONTENT_TYPE) + JsonKey.UNIT; - String framework = (String) tbMetadata.get(JsonKey.FRAMEWORK); - int levelCount = 0; - String code = tbId; - String parentCode = tbId; - for (int i = 1; i <= hierarchy.size(); i++) { - if (StringUtils.isNotBlank((String) hierarchy.get("L:" + i))) { - String name = (String) hierarchy.get("L:" + i); - code += name; - levelCount += 1; - if (i - 1 > 0) parentCode += (String) hierarchy.get("L:" + (i - 1)); - if (isBlank((String) hierarchy.get("L:" + (i + 1)))) - populateNodeModified( - name, - getCode(code), - (Map) row.get(JsonKey.METADATA), - unitType, - framework, - nodesModified, - true); - else - populateNodeModified(name, getCode(code), null, unitType, framework, nodesModified, true); - populateHierarchyData( - tbId, name, getCode(code), getCode(parentCode), levelCount, hierarchyData); - } else { - break; - } - } - } - - private String getCode(String code) { - return DigestUtils.md5Hex(code); - } - - private Map getTextbook(String tbId) { - Response response = null; - Map textbook; - try { - response = readContent(tbId, JsonKey.SUNBIRD_CONTENT_READ_API); - textbook = (Map) response.get(CONTENT); - if (null == textbook) { - log("Empty Content fetched | TextBook Id: " + tbId); - throwServerErrorException(SERVER_ERROR, "Empty Content fetched for TextBook Id: " + tbId); - } - } catch (Exception e) { - logger.error(null, - "Error while fetching textbook : " + tbId + " with response " + serialize(response), e); - throw e; - } - return textbook; - } - - private Map getHierarchy(String tbId) { - Response response = null; - Map hierarchy; - try { - response = readContent(tbId, SUNBIRD_CONTENT_GET_HIERARCHY_API); - hierarchy = (Map) response.get(CONTENT); - if (null == hierarchy) { - log("Empty Hierarchy fetched | TextBook Id: " + tbId); - throwServerErrorException(SERVER_ERROR, "Empty Hierarchy fetched for TextBook Id: " + tbId); - } - } catch (Exception e) { - logger.error(null, - "Error while fetching textbook : " + tbId + " with response " + serialize(response), e); - throw e; - } - return hierarchy; - } - - @SuppressWarnings("unchecked") - private Response updateTextbook(Request request, Map textbookHierarchy) - throws Exception { - Boolean linkContent = - (boolean) ((Map) request.get(JsonKey.DATA)).get(JsonKey.LINKED_CONTENT); - String channel = (String) textbookHierarchy.get(JsonKey.CHANNEL); - List> data = - (List>) - ((Map) request.get(JsonKey.DATA)).get(JsonKey.FILE_DATA); - String tbId = (String) request.get(TEXTBOOK_ID); - Set identifierList = new HashSet<>(); - identifierList.add(tbId); - data.forEach( - s -> { - identifierList.add((String) s.get(JsonKey.IDENTIFIER)); - }); - if (CollectionUtils.isEmpty(data)) { - throw new ProjectCommonException( - ResponseCode.invalidRequestData.getErrorCode(), - ResponseCode.invalidRequestData.getErrorMessage(), - ResponseCode.CLIENT_ERROR.getResponseCode()); - } else { - logger.info(null, - "Update Textbook - UpdateHierarchy input data : " + mapper.writeValueAsString(data)); - Map nodesModified = new HashMap<>(); - nodesModified.put( - tbId, - new HashMap() { - { - put(JsonKey.TB_IS_NEW, false); - put(JsonKey.TB_ROOT, true); - put(JsonKey.METADATA, new HashMap()); - } - }); - Map hierarchyData = new HashMap<>(); - - for (Map row : data) { - Map metadata = (Map) row.get(JsonKey.METADATA); - Map hierarchy = (Map) row.get(JsonKey.HIERARCHY); - String id = (String) row.get(JsonKey.IDENTIFIER); - metadata.remove(JsonKey.IDENTIFIER); - - populateNodeModified( - (String) hierarchy.get("L:" + (hierarchy.size() - 1)), - id, - metadata, - null, - null, - nodesModified, - false); - } - List> hierarchyList = null; - if (CollectionUtils.isNotEmpty( - (List>) textbookHierarchy.get(JsonKey.CHILDREN))) { - hierarchyList = - getParentChildHierarchy( - tbId, - (String) textbookHierarchy.get(JsonKey.NAME), - (List>) textbookHierarchy.get(JsonKey.CHILDREN)); - } - logger.info(null, - "TextbookTocActor:updateTextbook : ParentChildHierarchy structure : " - + mapper.writeValueAsString(hierarchyList) - ); - if (CollectionUtils.isNotEmpty(hierarchyList)) { - validateTextbookUnitIds(identifierList, hierarchyList); - } - if (BooleanUtils.isTrue(linkContent) && CollectionUtils.isNotEmpty(hierarchyList)) { - Map hierarchy = populateHierarchyDataForUpdate(hierarchyList, tbId); - data.forEach( - s -> { - Map nodeData = - (Map) hierarchy.get(s.get(JsonKey.IDENTIFIER)); - if (MapUtils.isNotEmpty(nodeData) - && CollectionUtils.isNotEmpty((List) s.get(JsonKey.CHILDREN))) { - for (String contentId : (List) s.get(JsonKey.CHILDREN)) { - if (!((List) nodeData.get(JsonKey.CHILDREN)).contains(contentId)) { - ((List) nodeData.get(JsonKey.CHILDREN)).add(contentId); - } - } - } - }); - hierarchyData.putAll(hierarchy); - hierarchyData - .entrySet() - .removeIf( - entry -> { - if (!identifierList.contains(entry.getKey())) { - return true; - } - return false; - }); - - logger.info(null, - "TextbookTocActor:updateTextbook : hierarchyData structure : " - + mapper.writeValueAsString(hierarchyData)); - } - - Map updateRequest = new HashMap(); - Map requestMap = new HashMap(); - Map dataMap = new HashMap(); - - dataMap.put(JsonKey.NODES_MODIFIED, nodesModified); - dataMap.put(JsonKey.HIERARCHY, hierarchyData); - requestMap.put(JsonKey.DATA, dataMap); - updateRequest.put(JsonKey.REQUEST, requestMap); - logger.info(null, - "Timed:TextbookTocActor:updateTextbook duration for processing update: " - + (Instant.now().toEpochMilli() - startTime.toEpochMilli())); - logger.info(null, - "Update Textbook - UpdateHierarchy Request : " + mapper.writeValueAsString(updateRequest)); - return callUpdateHierarchyAndLinkDialCodeApi( - (String) request.get(TEXTBOOK_ID), updateRequest, nodesModified, channel); - } - } - - private void validateTextbookUnitIds( - Set identifierList, List> hierarchyList) { - Set textbookUnitIds = new HashSet<>(); - hierarchyList - .stream() - .forEach( - s -> { - textbookUnitIds.addAll(s.keySet()); - }); - identifierList.forEach( - textbookUnitId -> { - if (!textbookUnitIds.contains(textbookUnitId)) { - ProjectCommonException.throwClientErrorException( - ResponseCode.errorInvalidTextbookUnitId, - MessageFormat.format( - ResponseCode.errorInvalidTextbookUnitId.getErrorMessage(), textbookUnitId)); - } - }); - } - - private List> getParentChildHierarchy( - String parentId, String name, List> children) { - List> hierarchyList = new ArrayList<>(); - Map hierarchy = new HashMap<>(); - Map node = new HashMap<>(); - node.put(JsonKey.NAME, name); - List contentIdList = new ArrayList<>(); - node.put(JsonKey.CHILDREN, contentIdList); - hierarchy.put(parentId, node); - hierarchyList.add(hierarchy); - for (Map child : children) { - contentIdList.add((String) child.get(JsonKey.IDENTIFIER)); - if (null != child.get(JsonKey.CHILDREN)) { - hierarchyList.addAll( - getParentChildHierarchy( - (String) child.get(JsonKey.IDENTIFIER), - (String) child.get(JsonKey.NAME), - (List>) child.get(JsonKey.CHILDREN))); - } else { - List> newChildren = new ArrayList<>(); - hierarchyList.addAll( - getParentChildHierarchy( - (String) child.get(JsonKey.IDENTIFIER), - (String) child.get(JsonKey.NAME), - newChildren)); - } - } - return hierarchyList; - } - - @SuppressWarnings("unchecked") - private Map populateHierarchyDataForUpdate( - List> hierarchy, String textbookId) { - Map hierarchyData = new HashMap<>(); - hierarchy.forEach( - s -> { - for (Entry entry : s.entrySet()) { - if (textbookId.equalsIgnoreCase(entry.getKey())) { - ((Map) entry.getValue()).put(JsonKey.CONTENT_TYPE, "TextBook"); - ((Map) entry.getValue()).put(JsonKey.TB_ROOT, true); - } else { - ((Map) entry.getValue()).put(JsonKey.CONTENT_TYPE, "TextBookUnit"); - ((Map) entry.getValue()).put(JsonKey.TB_ROOT, false); - } - hierarchyData.put(entry.getKey(), entry.getValue()); - } - }); - return hierarchyData; - } - - @SuppressWarnings("unchecked") - private void linkDialCode(Map modifiedNodes, String channel, String tbId) - throws Exception { - List> content = new ArrayList<>(); - modifiedNodes.forEach( - (k, v) -> { - Map value = (Map) v; - Map metadata = (Map) value.get(JsonKey.METADATA); - if (MapUtils.isNotEmpty(metadata)) { - String dialCodeRequired = (String) metadata.get(JsonKey.DIAL_CODE_REQUIRED); - if (JsonKey.YES.equalsIgnoreCase(dialCodeRequired)) { - Map linkDialCode = new HashMap<>(); - linkDialCode.put(JsonKey.IDENTIFIER, k); - if (null != metadata.get(JsonKey.DIAL_CODES)) { - linkDialCode.put("dialcode", metadata.get(JsonKey.DIAL_CODES)); - } else { - List dialcodes = new ArrayList<>(); - linkDialCode.put("dialcode", dialcodes); - } - content.add(linkDialCode); - } - } - }); - Map request = new HashMap<>(); - request.put(JsonKey.CONTENT, content); - Map linkDialCoderequest = new HashMap<>(); - linkDialCoderequest.put(JsonKey.REQUEST, request); - if (CollectionUtils.isNotEmpty(content)) { - linkDialCodeApiCall(linkDialCoderequest, channel, tbId); - } - } - - private Response linkDialCodeApiCall( - Map updateRequest, String channel, String tbId) throws Exception { - String requestUrl = - getConfigValue(JsonKey.LEARNING_SERVICE_BASE_URL) - + getConfigValue(JsonKey.LINK_DIAL_CODE_API) - + "/" - + tbId; - HttpResponse updateResponse = null; - try { - Map headers = getDefaultHeaders(); - headers.put("X-Channel-Id", channel); - updateResponse = - Unirest.post(requestUrl) - .headers(headers) - .body(mapper.writeValueAsString(updateRequest)) - .asString(); - logger.info(null, - "TextbookTocActor:linkDialCodeApiCall : Request for link dial code api : " - + mapper.writeValueAsString(updateRequest)); - - logger.info(null, - "Sized: TextbookTocActor:linkDialCodeApiCall : size of request : " - + mapper.writeValueAsString(updateRequest).getBytes().length); - if (null != updateResponse) { - Response response = mapper.readValue(updateResponse.getBody(), Response.class); - logger.info(null, - "Sized: TextbookTocActor:linkDialCodeApiCall : size of response : " - + updateResponse.getBody().getBytes().length); - if (response.getResponseCode().getResponseCode() == ResponseCode.OK.getResponseCode()) { - return response; - } else { - Map resultMap = - Optional.ofNullable(response.getResult()).orElse(new HashMap<>()); - String message = "Linking of dial code failed "; - if (MapUtils.isNotEmpty(resultMap)) { - Object obj = Optional.ofNullable(resultMap.get(JsonKey.TB_MESSAGES)).orElse(""); - if (obj instanceof List) { - message += ((List) obj).stream().collect(Collectors.joining(";")); - } else { - message += String.valueOf(obj); - } - } - ProjectCommonException.throwClientErrorException( - ResponseCode.errorDialCodeLinkingClientError, - MessageFormat.format( - ResponseCode.errorDialCodeLinkingClientError.getErrorMessage(), message)); - } - } else { - ProjectCommonException.throwClientErrorException(ResponseCode.errorDialCodeLinkingFail); - } - } catch (Exception ex) { - logger.error(null, "TextbookTocActor:updateHierarchy : link dial code error ", ex); - if (ex instanceof ProjectCommonException) { - throw ex; - } else { - throw new ProjectCommonException( - ResponseCode.errorTbUpdate.getErrorCode(), - ResponseCode.errorTbUpdate.getErrorMessage(), - SERVER_ERROR.getResponseCode()); - } - } - return null; - } - - private Response updateHierarchy(String tbId, Map updateRequest) - throws Exception { - - String requestUrl = - getConfigValue(JsonKey.EKSTEP_BASE_URL) + getConfigValue(JsonKey.UPDATE_HIERARCHY_API); - Map headers = getDefaultHeaders(); - HttpResponse updateResponse = null; - try { - logger.info(null, - "Sized:updateHierarchy:upload size of request " - + mapper.writeValueAsString(updateRequest).getBytes().length); - updateResponse = - Unirest.patch(requestUrl) - .headers(headers) - .body(mapper.writeValueAsString(updateRequest)) - .asString(); - } catch (Exception ex) { - logger.error(null, "TextbookTocActor:updateHierarchy : Update response call ", ex); - } - logger.info(null, - "TextbookTocActor:updateHierarchy : access token : " + mapper.writeValueAsString(headers)); - logger.info(null, - "TextbookTocActor:updateHierarchy : Request for update hierarchy : " - + mapper.writeValueAsString(updateRequest)); - if (null != updateResponse) { - try { - logger.info(null, - "TextbookTocActor:updateHierarchy : status response code : " - + updateResponse.getStatus() - + "status message " - + updateResponse.getStatusText()); - logger.info(null, - "Sized:updateHierarchy:upload size of response " - + updateResponse.getBody().getBytes().length); - Response response = mapper.readValue(updateResponse.getBody(), Response.class); - if (response.getResponseCode().getResponseCode() == ResponseCode.OK.getResponseCode()) { - return response; - } else { - Map resultMap = - Optional.ofNullable(response.getResult()).orElse(new HashMap<>()); - String message = "Textbook hierarchy could not be created or updated. "; - if (MapUtils.isNotEmpty(resultMap)) { - Object obj = Optional.ofNullable(resultMap.get(JsonKey.TB_MESSAGES)).orElse(""); - if (obj instanceof List) { - message += ((List) obj).stream().collect(Collectors.joining(";")); - } else { - message += String.valueOf(obj); - } - } - throw new ProjectCommonException( - ResponseCode.errorDialCodeLinkingClientError.getErrorCode(), - MessageFormat.format( - ResponseCode.errorDialCodeLinkingClientError.getErrorMessage(), message), - ResponseCode.CLIENT_ERROR.getResponseCode()); - } - } catch (Exception ex) { - logger.error(null, - "TextbookTocActor:updateHierarchy : Update response body " + updateResponse.getBody(), - ex); - if (ex instanceof ProjectCommonException) { - throw ex; - } else { - throw new ProjectCommonException( - ResponseCode.errorTbUpdate.getErrorCode(), - ResponseCode.errorTbUpdate.getErrorMessage(), - SERVER_ERROR.getResponseCode()); - } - } - } else { - logger.info(null, "TextbookTocActor:updateHierarchy : null response "); - throw new ProjectCommonException( - ResponseCode.errorTbUpdate.getErrorCode(), - ResponseCode.errorTbUpdate.getErrorMessage(), - SERVER_ERROR.getResponseCode()); - } - } - - private Map getDefaultHeaders() { - Map headers = new HashMap<>(); - headers.put("Content-Type", "application/json"); - headers.put( - JsonKey.AUTHORIZATION, JsonKey.BEARER + getConfigValue(JsonKey.SUNBIRD_AUTHORIZATION)); - return headers; - } - - @SuppressWarnings("unchecked") - private void populateNodeModified( - String name, - String code, - Map metadata, - String unitType, - String framework, - Map nodesModified, - boolean isNew) { - Map node = null; - if (nodesModified.containsKey(code)) { - node = (Map) nodesModified.get(code); - if (MapUtils.isNotEmpty(metadata)) { - Map newMeta = initializeMetaDataForModifiedNode(metadata); - ((Map) node.get(JsonKey.METADATA)).putAll(newMeta); - } - } else { - Map newMeta = initializeMetaDataForModifiedNode(metadata); - node = new HashMap(); - node.put(JsonKey.TB_IS_NEW, isNew); - node.put(JsonKey.TB_ROOT, false); - if (StringUtils.isNotBlank(name)) newMeta.put(JsonKey.NAME, name); - newMeta.put(JsonKey.MIME_TYPE, JsonKey.COLLECTION_MIME_TYPE); - if (StringUtils.isNotBlank(unitType)) newMeta.put(JsonKey.CONTENT_TYPE, unitType); - if (StringUtils.isNotBlank(framework)) newMeta.put(JsonKey.FRAMEWORK, framework); - node.put(JsonKey.METADATA, newMeta); - } - if (StringUtils.isNotBlank(code)) { - nodesModified.put(code, node); - } - } - - private Map initializeMetaDataForModifiedNode(Map metadata) { - Map newMeta = new HashMap(); - if (MapUtils.isNotEmpty(metadata)) { - List keywords = - (StringUtils.isNotBlank((String) metadata.get(JsonKey.KEYWORDS))) - ? asList(((String) metadata.get(JsonKey.KEYWORDS)).split(",")) - : null; - List gradeLevel = - (StringUtils.isNotBlank((String) metadata.get(JsonKey.GRADE_LEVEL))) - ? asList(((String) metadata.get(JsonKey.GRADE_LEVEL)).split(",")) - : null; - List dialCodes = - (StringUtils.isNotBlank((String) metadata.get(JsonKey.DIAL_CODES))) - ? asList(((String) metadata.get(JsonKey.DIAL_CODES)).split(",")) - : null; - - List topics = - (StringUtils.isNotBlank((String) metadata.get(JsonKey.TOPIC))) - ? asList(((String) metadata.get(JsonKey.TOPIC)).split(",")) - : null; - newMeta.putAll(metadata); - newMeta.remove(JsonKey.KEYWORDS); - newMeta.remove(JsonKey.GRADE_LEVEL); - newMeta.remove(JsonKey.DIAL_CODES); - newMeta.remove(JsonKey.TOPIC); - if (JsonKey.NO.equalsIgnoreCase((String) newMeta.get(JsonKey.DIAL_CODE_REQUIRED))) { - newMeta.put(JsonKey.DIAL_CODE_REQUIRED, JsonKey.NO); - } else if (JsonKey.YES.equalsIgnoreCase((String) newMeta.get(JsonKey.DIAL_CODE_REQUIRED))) { - newMeta.put(JsonKey.DIAL_CODE_REQUIRED, JsonKey.YES); - } - if (CollectionUtils.isNotEmpty(keywords)) newMeta.put(JsonKey.KEYWORDS, keywords); - if (CollectionUtils.isNotEmpty(gradeLevel)) newMeta.put(JsonKey.GRADE_LEVEL, gradeLevel); - if (CollectionUtils.isNotEmpty(dialCodes)) { - List dCodes = new ArrayList<>(); - dialCodes.forEach( - s -> { - dCodes.add(s.trim()); - }); - newMeta.put(JsonKey.DIAL_CODES, dCodes); - } - if (CollectionUtils.isNotEmpty(topics)) { - List topicList = new ArrayList<>(); - topics.forEach( - s -> { - topicList.add(s.trim()); - }); - newMeta.put(JsonKey.TOPIC, topicList); - } - } - return newMeta; - } - - private void populateHierarchyData( - String tbId, - String name, - String code, - String parentCode, - int levelCount, - Map hierarchyData) { - if (levelCount == 1) { - parentCode = tbId; - } - if (null != hierarchyData.get(code)) { - ((Map) hierarchyData.get(code)).put(JsonKey.NAME, name); - } else { - hierarchyData.put( - code, - new HashMap() { - { - put(JsonKey.NAME, name); - put(CHILDREN, new ArrayList<>()); - put(JsonKey.TB_ROOT, false); - } - }); - } - - if (null != hierarchyData.get(parentCode)) { - List children = - ((List) ((Map) hierarchyData.get(parentCode)).get(CHILDREN)); - if (!children.contains(code)) { - children.add(code); - } - } else { - String finalCode = code; - hierarchyData.put( - parentCode, - new HashMap() { - { - put(JsonKey.NAME, ""); - put( - CHILDREN, - new ArrayList() { - { - add(finalCode); - } - }); - put(JsonKey.TB_ROOT, false); - } - }); - } - } -} diff --git a/course-mw/textbook-actors/src/test/java/org/sunbird/content/util/TextBookTocUtilTest.java b/course-mw/textbook-actors/src/test/java/org/sunbird/content/util/TextBookTocUtilTest.java deleted file mode 100644 index 560d95c5d..000000000 --- a/course-mw/textbook-actors/src/test/java/org/sunbird/content/util/TextBookTocUtilTest.java +++ /dev/null @@ -1,99 +0,0 @@ -package org.sunbird.content.util; - -import org.junit.Assert; -import org.junit.Ignore; -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.powermock.api.mockito.PowerMockito; -import org.sunbird.common.exception.ProjectCommonException; -import org.sunbird.common.models.util.JsonKey; -import org.sunbird.learner.util.Util; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class TextBookTocUtilTest { - - private Map testMap = new HashMap() { - { - put("userId", "test"); - } - }; - @Test - public void testSerializeMap() { - String output = TextBookTocUtil.serialize(testMap); - Assert.assertEquals("{\"userId\":\"test\"}",output); - } - - @Test - public void testSerializeString() { - String output = TextBookTocUtil.serialize(new String("TextBook")); - Assert.assertEquals("\"TextBook\"",output); - } - - @Test - public void testStringifyNull() { - Object output = TextBookTocUtil.stringify(null); - Assert.assertEquals("",output); - } - - @Test - public void testStringifyEmptyList() { - Object output = TextBookTocUtil.stringify(new ArrayList<>()); - Assert.assertEquals("",output); - } - - @Test - public void testStringifyList() { - Object output = TextBookTocUtil.stringify(new ArrayList<>(){ - { - add("Book1"); - add("Book2"); - } - }); - Assert.assertEquals("Book1,Book2",output); - } - - @Test - public void testStringifyEmptyArray() { - Object output = TextBookTocUtil.stringify(new String[0]); - Assert.assertEquals("",output); - } - - @Test - public void testStringifyArray() { - Object output = TextBookTocUtil.stringify(new String[]{"Book1","Book2"}); - Assert.assertEquals("Book1,Book2",output); - } - - @Test(expected = ProjectCommonException.class) - public void testGetObject() { - TextBookTocUtil.getObjectFrom(Mockito.anyString(),Mockito.any()); - } - - @Test - public void testGetObjectMap() { - HashMap outputMap = TextBookTocUtil.getObjectFrom("{\"userId\":\"test\"}",HashMap.class); - Assert.assertEquals(testMap,outputMap); - } - - @Test(expected = ProjectCommonException.class) - public void testGetObjectList() { - TextBookTocUtil.getObjectFrom("{\"userId\":\"test\"}",List.class); - } - - @Test(expected = ProjectCommonException.class) - @Ignore - public void testReadContent() { - TextBookTocUtil.readContent(Mockito.anyString(), Mockito.anyString()); - } - - @Test(expected = ProjectCommonException.class) - @Ignore - public void testGetRelatedFrameworkById() { - TextBookTocUtil.getRelatedFrameworkById(Mockito.anyString()); - } -} diff --git a/course-mw/textbook-actors/src/test/java/org/sunbird/learner/actors/textbook/TextbookTocActorTest.java b/course-mw/textbook-actors/src/test/java/org/sunbird/learner/actors/textbook/TextbookTocActorTest.java deleted file mode 100644 index cb29b832a..000000000 --- a/course-mw/textbook-actors/src/test/java/org/sunbird/learner/actors/textbook/TextbookTocActorTest.java +++ /dev/null @@ -1,411 +0,0 @@ -package org.sunbird.learner.actors.textbook; - -import static akka.testkit.JavaTestKit.duration; -import static org.powermock.api.mockito.PowerMockito.when; -import static org.sunbird.common.models.util.JsonKey.CONTENT_PROPERTY_VISIBILITY_PARENT; - -import akka.actor.ActorRef; -import akka.actor.ActorSystem; -import akka.actor.Props; -import akka.testkit.javadsl.TestKit; -import com.google.common.base.Joiner; -import com.mashape.unirest.http.HttpResponse; -import com.mashape.unirest.http.Unirest; -import com.mashape.unirest.http.exceptions.UnirestException; -import com.mashape.unirest.request.HttpRequestWithBody; -import com.mashape.unirest.request.body.RequestBodyEntity; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.time.Duration; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.apache.commons.io.IOUtils; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mockito; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PowerMockIgnore; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.sunbird.common.exception.ProjectCommonException; -import org.sunbird.common.models.response.Response; -import org.sunbird.common.models.util.JsonKey; -import org.sunbird.common.models.util.ProjectUtil; -import org.sunbird.common.request.Request; -import org.sunbird.common.responsecode.ResponseCode; -import org.sunbird.common.util.CloudStorageUtil; -import org.sunbird.common.util.KeycloakRequiredActionLinkUtil; -import org.sunbird.content.util.TextBookTocUtil; -import org.sunbird.services.sso.SSOServiceFactory; -import org.sunbird.services.sso.impl.KeyCloakServiceImpl; - -@RunWith(PowerMockRunner.class) -@PrepareForTest({ - TextBookTocUtil.class, - ProjectUtil.class, - Unirest.class, - SSOServiceFactory.class, - CloudStorageUtil.class, KeycloakRequiredActionLinkUtil.class -}) -@PowerMockIgnore({"javax.management.*", "javax.net.ssl.*", "jdk.internal.reflect.*", "sun.security.ssl.*", "javax.net.ssl.*" , "javax.crypto.*"}) -public class TextbookTocActorTest { - - private static ActorSystem system; - private static final Props props = - Props.create(org.sunbird.learner.actors.textbook.TextbookTocActor.class); - - String VALID_HEADER = - "Identifier,Board,Medium,Grade,Subject,Textbook Name,Level 1 Textbook Unit,Description,QR Code Required?,QR Code,Purpose of Content to be linked,Mapped Topics,Keywords\n"; - String TEXTBOOK_TOC_INPUT_MAPPING = - "{ \"identifier\":\"Identifier\",\"frameworkCategories\":{\"medium\":\"Medium\",\"gradeLevel\":\"Grade\",\"subject\":\"Subject\"},\"hierarchy\":{\"Textbook\":\"Textbook Name\",\"L:1\":\"Level 1 Textbook Unit\",\"L:2\":\"Level 2 Textbook Unit\",\"L:3\":\"Level 3 Textbook Unit\",\"L:4\":\"Level 4 Textbook Unit\"},\"metadata\":{\"description\":\"Description\",\"dialcodeRequired\":\"QR Code Required?\",\"dialcodes\":\"QR Code\",\"purpose\":\"Purpose of Content to be linked\",\"topic\":\"Mapped Topics\",\"keywords\":\"Keywords\"}}"; // getFileAsString("FrameworkForTextbookTocActorTest.json"); - String MANDATORY_VALUES = - "{\"Textbook\":\"Textbook Name\",\"L:1\":\"Level 1 Textbook Unit\"}"; - String CONTENT_TYPE = "any"; - String IDENTIFIER = "do_1126788813057638401122"; - String TEXTBOOK_NAME = "test"; - String UNIT_NAME = "unit1"; - - @Before - public void setUp() throws Exception { - PowerMockito.mockStatic(TextBookTocUtil.class); - PowerMockito.mockStatic(ProjectUtil.class); - PowerMockito.mockStatic(Unirest.class); - PowerMockito.mockStatic(SSOServiceFactory.class); - PowerMockito.mockStatic(CloudStorageUtil.class); - PowerMockito.mockStatic(KeycloakRequiredActionLinkUtil.class); - KeyCloakServiceImpl ssoManager = PowerMockito.mock(KeyCloakServiceImpl.class); - when(SSOServiceFactory.getInstance()).thenReturn(ssoManager); - system = ActorSystem.create("system"); - when(ProjectUtil.getConfigValue(JsonKey.TEXTBOOK_TOC_MAX_CSV_ROWS)).thenReturn("5"); - when(ProjectUtil.getConfigValue(JsonKey.TEXTBOOK_TOC_MANDATORY_FIELDS)) - .thenReturn(MANDATORY_VALUES); - when(ProjectUtil.getConfigValue(JsonKey.TEXTBOOK_TOC_ALLOWED_CONTNET_TYPES)) - .thenReturn(CONTENT_TYPE); - when(ProjectUtil.getConfigValue(JsonKey.EKSTEP_BASE_URL)).thenReturn("http://www.abc.com/"); - when(ProjectUtil.getConfigValue(JsonKey.UPDATE_HIERARCHY_API)).thenReturn(""); - when(ProjectUtil.getConfigValue(JsonKey.CASSANDRA_WRITE_BATCH_SIZE)).thenReturn("10"); - when(ProjectUtil.getConfigValue(JsonKey.TEXTBOOK_TOC_INPUT_MAPPING)) - .thenReturn(TEXTBOOK_TOC_INPUT_MAPPING); - when(ProjectUtil.getConfigValue(JsonKey.SUNBIRD_TOC_MAX_FIRST_LEVEL_UNITS)).thenReturn("30"); - when(ProjectUtil.getConfigValue(JsonKey.SUNBIRD_TOC_LINKED_CONTENT_COLUMN_NAME)) - .thenReturn("Linked Content {0}"); - when(ProjectUtil.getConfigValue(JsonKey.CONTENT_CLOUD_STORAGE_TYPE)).thenReturn("azure"); - when(ProjectUtil.getConfigValue(JsonKey.CONTENT_CLOUD_STORAGE_CONTAINER)) - .thenReturn("randomContainer"); - when(ProjectUtil.getConfigValue(JsonKey.TEXTBOOK_TOC_OUTPUT_MAPPING)) - .thenReturn( - "{\"identifier\":\"Identifier\",\"frameworkCategories\":{\"board\":\"Board\",\"medium\":\"Medium\",\"gradeLevel\":\"Grade\",\"subject\":\"Subject\"},\"hierarchy\":{\"Textbook\":\"Textbook Name\",\"L:1\":\"Level 1 Textbook Unit\",\"L:2\":\"Level 2 Textbook Unit\",\"L:3\":\"Level 3 Textbook Unit\",\"L:4\":\"Level 4 Textbook Unit\"},\"metadata\":{\"description\":\"Description\",\"topic\":\"Mapped Topics\",\"keywords\":\"Keywords\",\"purpose\":\"Purpose of Content to be linked\",\"dialcodeRequired\":\"QR Code Required?\",\"dialcodes\":\"QR Code\"}}"); - } - - @Ignore - @Test - public void testUpdateFailureWithIncorrectTocData() throws IOException, UnirestException { - mockRequiredMethods(false, false); - StringBuffer tocData = new StringBuffer(VALID_HEADER); - tocData = addTocDataRow(tocData, JsonKey.YES, "2019", "", "", false); - tocData = addTocDataRow(tocData, JsonKey.YES, "2096", "", "", true); - mockResponseFromDialCodeSearch(); - ProjectCommonException res = (ProjectCommonException) doRequest(true, tocData.toString()); - Assert.assertEquals(ResponseCode.errorInvalidDialCode.getErrorCode(), res.getCode()); - } - - @Test - public void testUpdateFailureWithDailcodeNotReq() throws IOException { - mockRequiredMethods(false, false); - StringBuffer tocData = new StringBuffer(VALID_HEADER); - tocData = addTocDataRow(tocData, JsonKey.NO, "2019", "", "", true); - ProjectCommonException res = (ProjectCommonException) doRequest(true, tocData.toString()); - Assert.assertEquals(ResponseCode.errorConflictingValues.getErrorCode(), res.getCode()); - } - - @Test - public void testUpdateFailureWithDuplicateEntry() throws IOException { - mockRequiredMethods(false, false); - StringBuffer tocData = new StringBuffer(VALID_HEADER); - tocData = addTocDataRow(tocData, JsonKey.YES, "2019", "", "", false); - tocData = addTocDataRow(tocData, JsonKey.YES, "2019", "", "", true); - ProjectCommonException res = (ProjectCommonException) doRequest(true, tocData.toString()); - Assert.assertEquals(ResponseCode.errorDduplicateDialCodeEntry.getErrorCode(), res.getCode()); - } - - @Test - public void testUpdateFailureWithBlankCsv() throws IOException { - mockRequiredMethods(false, false); - ProjectCommonException res = (ProjectCommonException) doRequest(true, VALID_HEADER); - Assert.assertEquals(ResponseCode.blankCsvData.getErrorCode(), res.getCode()); - } - - @Test - public void testUpdateFailureWithInvalidTopic() throws IOException { - mockRequiredMethods(false, false); - StringBuffer tocData = new StringBuffer(VALID_HEADER); - tocData = addTocDataRow(tocData, JsonKey.YES, "2019", "topi", "abc", true); - ProjectCommonException res = (ProjectCommonException) doRequest(true, tocData.toString()); - Assert.assertEquals(ResponseCode.errorInvalidTopic.getErrorCode(), res.getCode()); - } - - @Test - public void testUpdateFailureWithInvalidDailcode() throws IOException, UnirestException { - mockRequiredMethods(false, false); - mockResponseFromDialCodeSearch(); - StringBuffer tocData = new StringBuffer(VALID_HEADER); - tocData = addTocDataRow(tocData, JsonKey.YES, "2089", "", "", true); - ProjectCommonException res = (ProjectCommonException) doRequest(true, tocData.toString()); - Assert.assertEquals(ResponseCode.errorInvalidDialCode.getErrorCode(), res.getCode()); - } - - @Test - public void testUpdateFailureWithTocDataNotUnique() throws IOException, UnirestException { - mockRequiredMethods(true, false); - mockResponseFromDialCodeSearch(); - StringBuffer tocData = new StringBuffer(VALID_HEADER); - tocData = addTocDataRow(tocData, JsonKey.NO, "", "", "", false); - tocData = addTocDataRow(tocData, JsonKey.NO, "", "", "", true); - System.out.println(tocData.toString()); - ProjectCommonException res = (ProjectCommonException) doRequest(true, tocData.toString()); - Assert.assertEquals(ResponseCode.duplicateRows.getErrorCode(), res.getCode()); - } - - @Test - public void testUpdateSuccess() throws UnirestException, IOException { - mockRequiredMethods(false, false); - mockResponseFromDialCodeSearch(); - StringBuffer tocData = new StringBuffer(VALID_HEADER); - tocData = addTocDataRow(tocData, JsonKey.NO, "", "", "", true); - mockResponseFromUpdateHierarchy(); - Response response = (Response) doRequest(false, tocData.toString()); - Assert.assertNotNull(response); - } - - @Test - public void testUpdateChildrenSuccess() throws UnirestException, IOException { - mockRequiredMethods(false, true); - mockResponseFromDialCodeSearch(); - StringBuffer tocData = new StringBuffer(VALID_HEADER); - tocData = addTocDataRow(tocData, JsonKey.NO, "", "", "", true); - mockResponseFromUpdateHierarchy(); - Response response = (Response) doRequest(false, tocData.toString()); - Assert.assertNotNull(response); - } - - @Test - public void testCreateSuccess() throws UnirestException, IOException { - mockRequiredMethods(false, false); - mockResponseFromDialCodeSearch(); - StringBuffer tocData = - new StringBuffer( - VALID_HEADER.substring( - VALID_HEADER.indexOf(",") + 1)); // removing the identifier column in create call - tocData = addTocCreateDataRow(tocData, JsonKey.NO, "", "", "", true); - mockResponseFromUpdateHierarchy(); - Response response = (Response) doRequest(false, tocData.toString()); - Assert.assertNotNull(response); - } - - @Test - public void testNoChildrenDownloadFailure() throws UnirestException, IOException { - mockRequiredMethods(false, false); - ProjectCommonException res = (ProjectCommonException) doDownloadRequest(true); - Assert.assertEquals(ResponseCode.noChildrenExists.getErrorCode(), res.getCode()); - } - - @Test - public void testDownloadSuccess() throws UnirestException, IOException { - mockRequiredMethods(false, true); - mockCloudStorage(); - Response response = (Response) doDownloadRequest(false); - Assert.assertNotNull(response); - } - - private void mockResponseFromUpdateHierarchy() throws UnirestException { - HttpRequestWithBody http = Mockito.mock(HttpRequestWithBody.class); - RequestBodyEntity entity = Mockito.mock(RequestBodyEntity.class); - HttpResponse response = Mockito.mock(HttpResponse.class); - when(Unirest.patch(Mockito.anyString())).thenReturn(http); - when(http.headers(Mockito.anyMap())).thenReturn(http); - when(http.body(Mockito.anyString())).thenReturn(entity); - when(entity.asString()).thenReturn(response); - when(response.getBody()).thenReturn("{\"responseCode\" :\"OK\" }"); - } - - private void mockResponseFromDialCodeSearch() throws UnirestException { - HttpRequestWithBody http = Mockito.mock(HttpRequestWithBody.class); - RequestBodyEntity entity = Mockito.mock(RequestBodyEntity.class); - HttpResponse response = Mockito.mock(HttpResponse.class); - when(Unirest.post(Mockito.anyString())).thenReturn(http); - when(http.headers(Mockito.anyMap())).thenReturn(http); - when(http.body(Mockito.anyString())).thenReturn(entity); - when(entity.asString()).thenReturn(response); - when(response.getBody()).thenReturn("{\"responseCode\" :\"OK\" }"); - } - - private Object doRequest(boolean error, String data) throws IOException { - TestKit probe = new TestKit(system); - ActorRef toc = system.actorOf(props); - Request request = new Request(); - request.setContext( - new HashMap() { - { - put("userId", "test"); - } - }); - request.put(JsonKey.TEXTBOOK_ID, "do_1126788813057638401122"); - InputStream stream = new ByteArrayInputStream(data.getBytes()); - byte[] byteArray = IOUtils.toByteArray(stream); - request.getRequest().put(JsonKey.DATA, byteArray); - request.put(JsonKey.DATA, byteArray); - request.setOperation(TextbookActorOperation.TEXTBOOK_TOC_UPLOAD.getValue()); - toc.tell(request, probe.getRef()); - if (error) { - ProjectCommonException res = - probe.expectMsgClass(Duration.ofSeconds(10), ProjectCommonException.class); - return res; - } - Response response = probe.expectMsgClass(Duration.ofSeconds(10), Response.class); - return response; - } - - private Object doDownloadRequest(boolean error) throws IOException { - TestKit probe = new TestKit(system); - ActorRef toc = system.actorOf(props); - Request request = new Request(); - request.setContext( - new HashMap() { - { - put("userId", "test"); - } - }); - request.put(JsonKey.TEXTBOOK_ID, "do_1126788813057638401122"); - request.setOperation(TextbookActorOperation.TEXTBOOK_TOC_URL.getValue()); - toc.tell(request, probe.getRef()); - if (error) { - ProjectCommonException res = - probe.expectMsgClass(duration("10 second"), ProjectCommonException.class); - return res; - } - Response response = probe.expectMsgClass(duration("10 second"), Response.class); - return response; - } - - private void mockRequiredMethods(boolean error, boolean withChildren) { - when(TextBookTocUtil.getRelatedFrameworkById(Mockito.any())).thenReturn(new Response()); - when(TextBookTocUtil.readContent(Mockito.anyString(), Mockito.anyString())) - .thenReturn(getReadContentTextbookData(withChildren)); - when(TextBookTocUtil.getObjectFrom(Mockito.anyString(), Mockito.any())).thenCallRealMethod(); - } - - private void mockCloudStorage() { - when(CloudStorageUtil.upload( - Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) - .thenReturn("randomCloudStorageUrl"); - } - - private Response getReadHierarchy(boolean error) { - Response response = new Response(); - List tocData = new ArrayList<>(); - Map content = new HashMap<>(); - if (error) { - content.put(JsonKey.IDENTIFIER, "do_112678881305763840115"); - } else { - content.put(JsonKey.IDENTIFIER, "do_1126788813057638401122"); - } - tocData.add("2019"); - content.put(JsonKey.DIAL_CODES, tocData); - content.put(JsonKey.CHILDREN, new ArrayList<>()); - response.put(JsonKey.CONTENT, content); - return response; - } - - private Response getReadContentTextbookData(boolean withChildren) { - Response response = new Response(); - Map textBookdata = new HashMap<>(); - Map reserveDialCodes = new HashMap<>(); - reserveDialCodes.put("2019", 1); - textBookdata.put(JsonKey.RESERVED_DIAL_CODES, reserveDialCodes); - textBookdata.put(JsonKey.CONTENT_TYPE, CONTENT_TYPE); - textBookdata.put(JsonKey.MIME_TYPE, "application/vnd.ekstep.content-collection"); - textBookdata.put(JsonKey.NAME, TEXTBOOK_NAME); - textBookdata.put(JsonKey.IDENTIFIER, "id1"); - response.put(JsonKey.CONTENT, textBookdata); - if (withChildren) { - List> children = new ArrayList<>(); - textBookdata.put(JsonKey.CHILDREN, children); - Map childData = new HashMap<>(); - childData.put(JsonKey.NAME, "randomContentName"); - childData.put(JsonKey.IDENTIFIER, "idC1"); - childData.put(JsonKey.CONTENT_PROPERTY_VISIBILITY, CONTENT_PROPERTY_VISIBILITY_PARENT); - childData.put(JsonKey.CONTENT_PROPERTY_MIME_TYPE, JsonKey.CONTENT_MIME_TYPE_COLLECTION); - children.add(childData); - List> nestedChildren = new ArrayList<>(); - childData.put(JsonKey.CHILDREN, nestedChildren); - Map nestedChildData = new HashMap<>(); - nestedChildData.put(JsonKey.NAME, "randomNestedContentName"); - nestedChildData.put(JsonKey.IDENTIFIER, "idC11"); - nestedChildData.put(JsonKey.CONTENT_PROPERTY_VISIBILITY, CONTENT_PROPERTY_VISIBILITY_PARENT); - nestedChildData.put(JsonKey.CONTENT_PROPERTY_MIME_TYPE, JsonKey.CONTENT_MIME_TYPE_COLLECTION); - nestedChildren.add(nestedChildData); - } - return response; - } - - private StringBuffer addTocDataRow( - StringBuffer tocData, - String isQrCodeReq, - String qrCode, - String mappedTopic, - String keywords, - boolean isLastEntry) { - - tocData.append( - Joiner.on(',') - .join( - IDENTIFIER, - "", - "", - "", - "", - TEXTBOOK_NAME, - UNIT_NAME, - "", - isQrCodeReq, - qrCode, - "", - mappedTopic, - (isLastEntry ? keywords : keywords + "\n"))); - - return tocData; - } - - private StringBuffer addTocCreateDataRow( - StringBuffer tocData, - String isQrCodeReq, - String qrCode, - String mappedTopic, - String keywords, - boolean isLastEntry) { - - tocData.append( - Joiner.on(',') - .join( - "", - "", - "", - "", - TEXTBOOK_NAME, - UNIT_NAME, - "", - isQrCodeReq, - qrCode, - "", - mappedTopic, - (isLastEntry ? keywords : keywords + "\n"))); - - return tocData; - } -} diff --git a/scripts/lms-config.sh b/scripts/lms-config.sh new file mode 100644 index 000000000..0364a0fa1 --- /dev/null +++ b/scripts/lms-config.sh @@ -0,0 +1,77 @@ +#!/bin/bash + +export actor_hostname=actor-service +export api_actor_provider=local +export export background_actor_provider=local +export bind_hostname=0.0.0.0 +export export ekstep_api_base_url="https://dev.lern.sunbird.org" +export content_read_url="/api/content/v1/read/" +export learning_content_props_to_add=mimeType,contentType,name,code,description,keywords,framework,copyright,topic +export learning_service_base_url="https://dev.lern.sunbird.org" +export redis_connection_idle_max=32 +export redis_connection_idle_min=1 +export redis_connection_max=64 +export redis_connection_minEvictableIdleTimeSeconds=120 +export redis_connection_timeBetweenEvictionRunsSeconds=300 +export redis_dbIndex=2 +export redis_experimentIndex=10 +export sunbird_account_key= +export sunbird_account_name=sunbirddev +export sunbird_api_mgr_base_url="https://dev.lern.sunbird.org" +export sunbird_app_name=Sunbird +export sunbird_authorization= +export sunbird_cache_enable=True +export sunbird_cassandra_consistency_level=quorum +export sunbird_cassandra_host=localhost +export sunbird_cassandra_password=password +export sunbird_cassandra_port=9042 +export sunbird_cassandra_username=cassandra +export sunbird_cert_service_base_url=http://cert-service:9000 +export sunbird_content_azure_storage_container=sunbird-content-dev +export sunbird_course_batch_notification_enabled=false +export sunbird_course_batch_notification_signature=sunbird +export sunbird_cs_base_url="https://dev.lern.sunbird.org" +export sunbird_cs_search_path="/api/composite/v1/search" +export sunbird_default_channel=sunbird +export sunbird_encryption_key= +export sunbird_encryption_mode=local +export sunbird_env_logo_url= +export sunbird_env_name=sunbirddev +export sunbird_environment=dev +export sunbird_es_host=localhost +export sunbird_es_port=9200 +export sunbird_gzip_enable=True +export sunbird_gzip_size_threshold=262144 +export sunbird_health_check_enable=false +export sunbird_installation=Sunbird_Dev +export sunbird_instance=sunbird +export sunbird_keycloak_required_action_link_expiration_seconds=2592000 +export sunbird_keycloak_user_federation_provider_id=5a8a3f2b-3409-42e0-9001-f913bc0fde31 +export sunbird_mw_system_host=lms-service +export sunbird_mw_system_port=8088 +export sunbird_remote_bg_req_router_path=akka.tcp://SunbirdMWSystem@actor-service:8088/user/BackgroundRequestRouter +export sunbird_remote_req_router_path=akka.tcp://SunbirdMWSystem@actor-service:8088/user/RequestRouter +export sunbird_search_service_api_base_url="https://dev.lern.sunbird.org" +export ekstep_content_search_url="/api/content/v1/search" +export sunbird_sso_client_id=lms +export sunbird_sso_client_secret=9403f086 +export sunbird_sso_password=test +export sunbird_sso_publickey= +export sunbird_sso_realm=sunbird +export sunbird_sso_url=https://dev.lern.sunbird.org/auth/ +export sunbird_sso_username=admin +export sunbird_time_zone=Asia/Kolkata +export sunbird_url_shortner_access_token=ea7d5efa674 +export sunbird_url_shortner_enable=false +export sunbird_user_org_api_base_url="https://dev.lern.sunbird.org" +export sunbird_user_profile_field_default_visibility=private +export sunbird_user_qrcode_courses_limit=5000 +export sunbird_user_search_cretordetails_fields=id,firstName,lastName +export sunbird_user_service_api_base_url="https://dev.lern.sunbird.org" +export sunbird_search_organisation_api="/api/org/v1/search" +export sunbird_web_url=https://dev.lern.sunbird.org +export telemetry_pdata_id=dev.sunbird.learning.service +export telemetry_pdata_pid=lms-service +export telemetry_queue_threshold_value=100 +export user_enrolments_response_cache_enable=True +export user_enrolments_response_cache_ttl=10 \ No newline at end of file diff --git a/service/app/controllers/exhaustjob/ExhaustJobController.java b/service/app/controllers/exhaustjob/ExhaustJobController.java new file mode 100644 index 000000000..227696405 --- /dev/null +++ b/service/app/controllers/exhaustjob/ExhaustJobController.java @@ -0,0 +1,55 @@ +/** */ +package controllers.exhaustjob; + +import akka.actor.ActorRef; +import com.fasterxml.jackson.databind.JsonNode; +import controllers.BaseController; +import controllers.exhaustjob.validator.ExhaustJobRequestValidator; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CompletionStage; +import javax.inject.Inject; +import javax.inject.Named; +import org.sunbird.common.models.util.ActorOperations; +import org.sunbird.common.models.util.JsonKey; +import org.sunbird.common.models.util.LoggerEnum; +import org.sunbird.common.models.util.ProjectLogger; +import org.sunbird.common.models.util.ProjectUtil.EsType; +import org.sunbird.common.request.Request; +import play.mvc.Http; +import play.mvc.Result; +import util.Attrs; + +public class ExhaustJobController extends BaseController { + + @Inject + @Named("exhaust-job-actor") + private ActorRef exhaustJobActorRef; + + public CompletionStage submitJobRequest(Http.Request httpRequest) { + return handleRequest( + exhaustJobActorRef, + ActorOperations.SUBMIT_JOB_REQUEST.getValue(), + httpRequest.body().asJson(), + (request) -> { + Request req = (Request) request; + new ExhaustJobRequestValidator().validateCreateExhaustJobRequest(req); + return null; + }, + getAllRequestHeaders(httpRequest), + httpRequest); + } + + public CompletionStage listJobRequest(String tag, Http.Request httpRequest) { + return handleRequest( + exhaustJobActorRef, + ActorOperations.LIST_JOB_REQUEST.getValue(), + tag, + JsonKey.TAG, + false, + httpRequest); + } +} diff --git a/service/app/controllers/exhaustjob/validator/ExhaustJobRequestValidator.java b/service/app/controllers/exhaustjob/validator/ExhaustJobRequestValidator.java new file mode 100644 index 000000000..abbd3fbea --- /dev/null +++ b/service/app/controllers/exhaustjob/validator/ExhaustJobRequestValidator.java @@ -0,0 +1,27 @@ +package controllers.exhaustjob.validator; + + +import org.apache.commons.lang3.StringUtils; +import org.sunbird.common.models.util.JsonKey; +import org.sunbird.common.request.BaseRequestValidator; +import org.sunbird.common.request.Request; +import org.sunbird.common.responsecode.ResponseCode; + +public class ExhaustJobRequestValidator extends BaseRequestValidator { + private static final int ERROR_CODE = ResponseCode.CLIENT_ERROR.getResponseCode(); + + public void validateCreateExhaustJobRequest(Request request) { + + validateParam( + (String) request.getRequest().get(JsonKey.TAG), + ResponseCode.mandatoryParamsMissing, JsonKey.TAG); + validateParam( + (String) request.getRequest().get(JsonKey.DATASET), + ResponseCode.mandatoryParamsMissing, JsonKey.DATASET); + if(StringUtils.isBlank((String)request.getRequest().get(JsonKey.REQUESTED_BY))){ + request.getRequest().put(JsonKey.REQUESTED_BY,request.getContext().get(JsonKey.REQUESTED_BY)); + } + + } + +} diff --git a/service/app/controllers/textbook/TextbookController.java b/service/app/controllers/textbook/TextbookController.java deleted file mode 100644 index 9b5892865..000000000 --- a/service/app/controllers/textbook/TextbookController.java +++ /dev/null @@ -1,132 +0,0 @@ -package controllers.textbook; - -import static org.sunbird.common.exception.ProjectCommonException.throwClientErrorException; - -import akka.actor.ActorRef; -import akka.util.Timeout; -import controllers.BaseController; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.CompletionStage; -import java.util.concurrent.TimeUnit; -import javax.inject.Inject; -import javax.inject.Named; -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.collections.MapUtils; -import org.apache.commons.io.IOUtils; -import org.apache.commons.lang3.StringUtils; -import org.sunbird.common.models.util.JsonKey; -import org.sunbird.common.models.util.LoggerEnum; -import org.sunbird.common.models.util.ProjectLogger; -import org.sunbird.common.request.Request; -import org.sunbird.common.responsecode.ResponseCode; -import org.sunbird.learner.actors.textbook.TextbookActorOperation; -import play.libs.Files; -import play.mvc.Http; -import play.mvc.Result; -import util.Attrs; - -/** - * Handles Textbook TOC APIs. - * - * @author gauraw - */ -public class TextbookController extends BaseController { - - @Inject - @Named("textbook-toc-actor") - private ActorRef textbookTocActorRef; - - private static final int UPLOAD_TOC_TIMEOUT = 30; - - public CompletionStage uploadTOC(String textbookId, Http.Request httpRequest) { - try { - Request request = - createAndInitUploadRequest( - TextbookActorOperation.TEXTBOOK_TOC_UPLOAD.getValue(), JsonKey.TEXTBOOK, httpRequest); - request.put(JsonKey.TEXTBOOK_ID, textbookId); - request.setTimeout(UPLOAD_TOC_TIMEOUT); - Timeout uploadTimeout = new Timeout(UPLOAD_TOC_TIMEOUT, TimeUnit.SECONDS); - return actorResponseHandler(textbookTocActorRef, request, uploadTimeout, null, httpRequest); - } catch (Exception e) { - return CompletableFuture.completedFuture(createCommonExceptionResponse(e, httpRequest)); - } - } - - public CompletionStage getTocUrl(String textbookId, Http.Request httpRequest) { - try { - return handleRequest( - textbookTocActorRef, - TextbookActorOperation.TEXTBOOK_TOC_URL.getValue(), - textbookId, - JsonKey.TEXTBOOK_ID, - httpRequest); - } catch (Exception e) { - return CompletableFuture.completedFuture(createCommonExceptionResponse(e, httpRequest)); - } - } - - // @Override - public Request createAndInitUploadRequest( - String operation, String objectType, Http.Request httpRequest) throws IOException { - logger.info(null, "API call for operation : " + operation); - Request reqObj = new Request(); - Map map = new HashMap<>(); - InputStream inputStream = null; - - String fileUrl = httpRequest.getQueryString(JsonKey.FILE_URL); - if (StringUtils.isNotBlank(fileUrl)) { - logger.info(null, "Got fileUrl from path parameter: " + fileUrl); - URL url = new URL(fileUrl.trim()); - inputStream = url.openStream(); - } else { - Http.MultipartFormData body = httpRequest.body().asMultipartFormData(); - if (body != null) { - Map data = body.asFormUrlEncoded(); - if (MapUtils.isNotEmpty(data) && data.containsKey(JsonKey.FILE_URL)) { - fileUrl = data.getOrDefault(JsonKey.FILE_URL, new String[] {""})[0]; - if (StringUtils.isBlank(fileUrl) || !StringUtils.endsWith(fileUrl, ".csv")) { - throwClientErrorException( - ResponseCode.csvError, ResponseCode.csvError.getErrorMessage()); - } - URL url = new URL(fileUrl.trim()); - inputStream = url.openStream(); - } else { - List> filePart = body.getFiles(); - if (CollectionUtils.isEmpty(filePart)) { - throwClientErrorException( - ResponseCode.fileNotFound, ResponseCode.fileNotFound.getErrorMessage()); - } - inputStream = new FileInputStream(filePart.get(0).getRef().path().toFile()); - } - } else { - logger.info(null, "Textbook toc upload request body is empty"); - throwClientErrorException( - ResponseCode.invalidData, ResponseCode.invalidData.getErrorMessage()); - } - } - - byte[] byteArray = IOUtils.toByteArray(inputStream); - try { - if (null != inputStream) { - inputStream.close(); - } - } catch (Exception e) { - logger.error(null, "TextbookController:createAndInitUploadRequest : Exception occurred while closing stream", e); - } - reqObj.setOperation(operation); - reqObj.setRequestId(httpRequest.attrs().getOptional(Attrs.REQUEST_ID).orElse(null)); - reqObj.setEnv(getEnvironment()); - map.put(JsonKey.OBJECT_TYPE, objectType); - map.put(JsonKey.CREATED_BY, httpRequest.attrs().getOptional(Attrs.USER_ID).orElse(null)); - map.put(JsonKey.DATA, byteArray); - reqObj.setRequest(map); - return reqObj; - } -} diff --git a/service/app/modules/ApplicationStart.java b/service/app/modules/ApplicationStart.java index b55d1082f..73e4ab242 100644 --- a/service/app/modules/ApplicationStart.java +++ b/service/app/modules/ApplicationStart.java @@ -6,10 +6,9 @@ import org.sunbird.auth.verifier.KeyManager; import org.sunbird.common.models.util.JsonKey; -import org.sunbird.common.models.util.LoggerEnum; -import org.sunbird.common.models.util.ProjectLogger; import org.sunbird.common.models.util.ProjectUtil; import org.sunbird.common.models.util.LoggerUtil; +import org.sunbird.learner.util.ContentSearchMock; import org.sunbird.learner.util.SchedulerManager; import org.sunbird.learner.util.Util; import play.api.Environment; @@ -40,6 +39,9 @@ public ApplicationStart(ApplicationLifecycle lifecycle, Environment environment) setEnvironment(environment); ssoPublicKey = System.getenv(JsonKey.SSO_PUBLIC_KEY); logger.info(null, "Server started.. with environment: " + env.name()); + if (Boolean.parseBoolean(ProjectUtil.getConfigValue(JsonKey.CONTENT_SERVICE_MOCK_ENABLED))) { + mockServiceSetup(); + } checkCassandraConnections(); SchedulerManager.schedule(); lifecycle.addStopHook( @@ -51,6 +53,15 @@ public ApplicationStart(ApplicationLifecycle lifecycle, Environment environment) System.out.println("ApplicationStart:ApplicationStart: End"); } + public static void mockServiceSetup() { + LoggerUtil logger = new LoggerUtil(ApplicationStart.class); + try { + ContentSearchMock.setup(); + } catch (Exception e) { + logger.info(null,"Error setting up ContentSearchMock:"+e); + } + } + private void checkCassandraConnections() { Util.checkCassandraDbConnections(); } diff --git a/service/app/util/ACTOR_NAMES.java b/service/app/util/ACTOR_NAMES.java index 41aa6b42f..e7baf5571 100644 --- a/service/app/util/ACTOR_NAMES.java +++ b/service/app/util/ACTOR_NAMES.java @@ -3,7 +3,6 @@ import org.sunbird.aggregate.CollectionSummaryAggregate; import org.sunbird.enrolments.CourseEnrolmentActor; import org.sunbird.enrolments.ContentConsumptionActor; -import org.sunbird.enrolments.CourseEnrolmentActor; import org.sunbird.group.GroupAggregatesActor; import org.sunbird.learner.actors.BackgroundJobManager; import org.sunbird.learner.actors.PageManagementActor; @@ -19,7 +18,7 @@ import org.sunbird.learner.actors.qrcodedownload.QRCodeDownloadManagementActor; import org.sunbird.learner.actors.search.SearchHandlerActor; import org.sunbird.learner.actors.syncjobmanager.EsSyncActor; -import org.sunbird.learner.actors.textbook.TextbookTocActor; +import org.sunbird.actor.exhaustjob.ExhaustJobActor; public enum ACTOR_NAMES { COURSE_BATCH_MANAGEMENT_ACTOR(CourseBatchManagementActor.class, "course-batch-management-actor"), @@ -27,7 +26,6 @@ public enum ACTOR_NAMES { CACHE_MANAGEMENT_ACTOR(CacheManagementActor.class, "cache-management-actor"), PAGE_MANAGEMENT_ACTOR(PageManagementActor.class, "page-management-actor"), SEARCH_HANDLER_ACTOR(SearchHandlerActor.class, "search-handler-actor"), - TEXTBOOK_TOC_ACTOR(TextbookTocActor.class, "textbook-toc-actor"), HEALTH_ACTOR(HealthActor.class, "health-actor"), COURSEBATCH_CERTIFICATE_ACTOR( CourseBatchCertificateActor.class, "course-batch-certificate-actor"), @@ -44,8 +42,8 @@ public enum ACTOR_NAMES { //Scala Actors COURSE_ENROLMENT_ACTOR(CourseEnrolmentActor.class, "course-enrolment-actor"), CONTENT_CONSUMPTION_ACTOR(ContentConsumptionActor.class, "content-consumption-actor"), - GROUP_AGGREGATES_ACTORS(GroupAggregatesActor.class, "group-aggregates-actor"); - + GROUP_AGGREGATES_ACTORS(GroupAggregatesActor.class, "group-aggregates-actor"), + EXHAUST_JOB_ACTOR(ExhaustJobActor.class, "exhaust-job-actor"); private ACTOR_NAMES(Class clazz, String name) { actorClass = clazz; actorName = name; diff --git a/service/conf/application.conf b/service/conf/application.conf index 320b7cd29..e24fd8805 100644 --- a/service/conf/application.conf +++ b/service/conf/application.conf @@ -127,12 +127,6 @@ akka { nr-of-instances = 4 dispatcher = rr-dispatcher } - /textbook-toc-actor - { - router = smallest-mailbox-pool - nr-of-instances = 4 - dispatcher = rr-dispatcher - } /health-actor { router = smallest-mailbox-pool @@ -205,6 +199,12 @@ akka { nr-of-instances = 4 dispatcher = rr-dispatcher } + /exhaust-job-actor + { + router = smallest-mailbox-pool + nr-of-instances = 4 + dispatcher = rr-dispatcher + } } } } diff --git a/service/conf/routes b/service/conf/routes index cc1ec6098..65c04f8f9 100644 --- a/service/conf/routes +++ b/service/conf/routes @@ -55,11 +55,6 @@ GET /v1/course/batch/read/:batchId @controllers.coursemanagement.CourseBatch POST /v1/course/batch/search @controllers.coursemanagement.CourseBatchController.search(request: play.mvc.Http.Request) POST /v1/batch/participants/list @controllers.coursemanagement.CourseBatchController.getParticipants(request: play.mvc.Http.Request) -# Textbook APIs -POST /v1/textbook/toc/upload/:textbookId @controllers.textbook.TextbookController.uploadTOC(textbookId:String, request: play.mvc.Http.Request) -GET /v1/textbook/toc/download/:textbookId @controllers.textbook.TextbookController.getTocUrl(textbookId:String, request: play.mvc.Http.Request) - - # Certificate APIs POST /v1/course/batch/cert/issue @controllers.certificate.CertificateController.issueCertificate(request: play.mvc.Http.Request) PATCH /v1/course/batch/cert/template/add @controllers.certificate.CertificateController.addCertificate(request: play.mvc.Http.Request) @@ -75,4 +70,8 @@ POST /v1/course/create @controllers.coursemanagement.CourseControll POST /v1/group/activity/agg @controllers.group.GroupAggController.getGroupActivityAggregates(request: play.mvc.Http.Request) #Summary Aggregate -POST /v1/collection/summary @controllers.collectionsummaryaggregate.CollectionSummaryAggregateController.getCollectionSummaryAggregate(request: play.mvc.Http.Request) \ No newline at end of file +POST /v1/collection/summary @controllers.collectionsummaryaggregate.CollectionSummaryAggregateController.getCollectionSummaryAggregate(request: play.mvc.Http.Request) + +#Exhaust Proxy APIs +POST /v1/jobrequest/submit @controllers.exhaustjob.ExhaustJobController.submitJobRequest(request: play.mvc.Http.Request) +GET /v1/jobrequest/list/:tag @controllers.exhaustjob.ExhaustJobController.listJobRequest(tag:String, request: play.mvc.Http.Request) \ No newline at end of file diff --git a/service/dependency-reduced-pom.xml b/service/dependency-reduced-pom.xml index ac4819fd5..c0f9ffb95 100644 --- a/service/dependency-reduced-pom.xml +++ b/service/dependency-reduced-pom.xml @@ -220,7 +220,7 @@ junit junit - 4.12 + 4.13.1 test diff --git a/service/pom.xml b/service/pom.xml index bfc4f619e..da9f1bd2f 100644 --- a/service/pom.xml +++ b/service/pom.xml @@ -95,11 +95,6 @@ org.sunbird course-actors 1.0-SNAPSHOT - - - org.sunbird - textbook-actors - 1.0-SNAPSHOT org.sunbird @@ -182,7 +177,7 @@ org.apache.httpcomponents httpclient - 4.5.1 + 4.5.13 @@ -212,7 +207,7 @@ junit junit - 4.12 + 4.13.1 test diff --git a/service/test/controllers/ApplicationStartTest.java b/service/test/controllers/ApplicationStartTest.java new file mode 100644 index 000000000..ebba25b9c --- /dev/null +++ b/service/test/controllers/ApplicationStartTest.java @@ -0,0 +1,32 @@ +package controllers; + +import org.junit.Test; +import org.sunbird.common.models.util.JsonKey; +import org.sunbird.common.models.util.LoggerUtil; +import org.sunbird.common.request.RequestContext; +import org.mockito.Mockito; + +import static modules.ApplicationStart.mockServiceSetup; + +public class ApplicationStartTest { + + @Test + public void testMockServiceSetupWithMockEnabledTrue() { + System.setProperty(JsonKey.CONTENT_SERVICE_MOCK_ENABLED, "true"); + LoggerUtil logger = Mockito.mock(LoggerUtil.class); + RequestContext mockRequestContext = Mockito.mock(RequestContext.class); + mockServiceSetup(); + Mockito.verify(logger, Mockito.never()) + .info(Mockito.eq(mockRequestContext), Mockito.anyString()); + } + + @Test + public void testMockServiceSetupWithMockEnabledFalse() { + System.setProperty(JsonKey.CONTENT_SERVICE_MOCK_ENABLED, "false"); + LoggerUtil logger = Mockito.mock(LoggerUtil.class); + RequestContext mockRequestContext = Mockito.mock(RequestContext.class); + mockServiceSetup(); + Mockito.verify(logger, Mockito.never()) + .info(Mockito.eq(mockRequestContext), Mockito.anyString()); + } +} diff --git a/service/test/controllers/exhaustjob/ExhaustJobControllerTest.java b/service/test/controllers/exhaustjob/ExhaustJobControllerTest.java new file mode 100644 index 000000000..5df94e9e7 --- /dev/null +++ b/service/test/controllers/exhaustjob/ExhaustJobControllerTest.java @@ -0,0 +1,86 @@ +package controllers.exhaustjob; + +import actors.DummyActor; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import controllers.BaseApplicationTest; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.powermock.core.classloader.annotations.PowerMockIgnore; +import org.powermock.modules.junit4.PowerMockRunner; +import org.sunbird.common.models.util.JsonKey; +import org.sunbird.common.models.util.ProjectLogger; +import play.libs.Json; +import play.mvc.Http; +import play.mvc.Result; +import play.test.Helpers; +import util.ACTOR_NAMES; + +import java.io.IOException; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; + + +@RunWith(PowerMockRunner.class) +@PowerMockIgnore({"javax.management.*", "javax.net.ssl.*", "javax.security.*", "jdk.internal.reflect.*", + "sun.security.ssl.*", "javax.net.ssl.*", "javax.crypto.*", + "com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*"}) +public class ExhaustJobControllerTest extends BaseApplicationTest { + + @Before + public void before() { + setup(Arrays.asList(ACTOR_NAMES.EXHAUST_JOB_ACTOR), DummyActor.class); + } + + @Test + public void testJobSubmitRequestSuccess() { + Http.RequestBuilder req = + new Http.RequestBuilder() + .uri("/v1/jobrequest/submit") + .bodyJson(createJobSubmitRequest()) + .method("POST"); + Result result = Helpers.route(application, req); + Assert.assertEquals( 200, result.status()); + } + + @Test + public void testListJobRequestSuccess() { + Http.RequestBuilder req = + new Http.RequestBuilder() + .uri("/v1/jobrequest/list/do_2137002173427875841205_01370023185341644822") + .method("GET"); + Result result = Helpers.route(application, req); + Assert.assertEquals( 200, result.status()); + } + private JsonNode createJobSubmitRequest() { + Map req = new HashMap<>(); + Map requestMap = new HashMap<>(); + requestMap.put(JsonKey.TAG, "do_2137002173427875841205_01370023185341644822"); + requestMap.put(JsonKey.REQUESTED_BY, "fca2925f-1eee-4654-9177-fece3fd6afc9"); + requestMap.put(JsonKey.DATASET, "progress-exhaust"); + requestMap.put(JsonKey.CONTENT_TYPE, "Course"); + requestMap.put(JsonKey.OUTPUT_FORMAT, "csv"); + requestMap.put(JsonKey.DATASETCONFIG, new HashMap<>().put(JsonKey.BATCH_ID,"01370023185341644822")); + req.put(JsonKey.REQUEST,requestMap); + String data = mapToJson(req); + return Json.parse(data); + } + + public String mapToJson(Map map) { + ObjectMapper mapperObj = new ObjectMapper(); + String jsonResp = ""; + + if (map != null) { + try { + jsonResp = mapperObj.writeValueAsString(map); + } catch (IOException e) { + ProjectLogger.log(e.getMessage(), e); + } + } + return jsonResp; + } + +} diff --git a/service/test/controllers/textbook/TextbookControllerTest.java b/service/test/controllers/textbook/TextbookControllerTest.java deleted file mode 100644 index a215bbd0a..000000000 --- a/service/test/controllers/textbook/TextbookControllerTest.java +++ /dev/null @@ -1,54 +0,0 @@ -package controllers.textbook; - -import com.fasterxml.jackson.databind.ObjectMapper; -import controllers.BaseApplicationTest; -import actors.DummyActor; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.core.classloader.annotations.PowerMockIgnore; -import org.powermock.modules.junit4.PowerMockRunner; -import play.mvc.Http; -import play.mvc.Result; -import play.test.Helpers; -import util.ACTOR_NAMES; - -@RunWith(PowerMockRunner.class) -@PowerMockIgnore({"javax.management.*", "javax.net.ssl.*", "javax.security.*", "jdk.internal.reflect.*", - "sun.security.ssl.*", "javax.net.ssl.*", "javax.crypto.*", - "com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*"}) -public class TextbookControllerTest extends BaseApplicationTest { - - ObjectMapper mapper = new ObjectMapper(); - String TEXTBOOK_ID = "textbookId"; - - @Before - public void before() { - setup(ACTOR_NAMES.TEXTBOOK_TOC_ACTOR,DummyActor.class); - } - - @Ignore - @Test - public void testUploadTocWithUrl() { - Http.RequestBuilder req = - new Http.RequestBuilder() - .uri( - "/v1/textbook/toc/upload/?fileUrl=https://sunbirddev.blob.core.windows.net/sunbird-content-dev/content/toc/do_1126526588628582401237/download.csv") - .method("POST"); - Result result = Helpers.route(application, req); - Assert.assertEquals( 200, result.status()); - } - - @Test - public void testGetTocUrl() { - Http.RequestBuilder req = - new Http.RequestBuilder() - .uri( - "/v1/textbook/toc/download/"+TEXTBOOK_ID) - .method("GET"); - Result result = Helpers.route(application, req); - Assert.assertEquals( 200, result.status()); - } -} diff --git a/service/test/mapper/RequestMapperTest.java b/service/test/mapper/RequestMapperTest.java index b1cd2e778..41b37523a 100644 --- a/service/test/mapper/RequestMapperTest.java +++ b/service/test/mapper/RequestMapperTest.java @@ -2,9 +2,10 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; + import java.util.HashMap; import java.util.Map; -import mapper.RequestMapper; + import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -16,7 +17,6 @@ import org.sunbird.common.models.util.JsonKey; import org.sunbird.common.request.Request; import org.sunbird.common.responsecode.ResponseCode; -import org.sunbird.helper.ServiceFactory; import play.libs.Json; @RunWith(PowerMockRunner.class) @@ -67,7 +67,7 @@ public void testMapRequestFailureWithInvalidKey() { JsonNode node = new ObjectMapper().convertValue(createRequestMap("invalidKey"), JsonNode.class); request = (Request) RequestMapper.mapRequest(node, Request.class); Assert.assertNotNull(request); - Assert.assertEquals(null, request.getRequest().get(JsonKey.FIRST_NAME)); + Assert.assertNull(request.getRequest().get(JsonKey.FIRST_NAME)); } private Map createRequestMap(String requestKey) { diff --git a/setup.md b/setup.md index ce8401b54..d3b9e0c6c 100644 --- a/setup.md +++ b/setup.md @@ -25,7 +25,6 @@ 7. sunbird_es_cluster (optional): name of the elasticsearch cluster 8. sunbird_learner_actor_host: host running for learner actor 9. sunbird_learner_actor_port: port on which learner actor is running. - 10. ekstep_content_search_base_url : provide base url for EkStep content search 11. ekstep_authorization : provide authorization for value for content search 12. sunbird_pg_host: postgres host name or ip 13. sunbird_pg_port: postgres port number @@ -62,7 +61,6 @@ 44.sunbird_badger_baseurl=http://badger-service:8000 45.sunbird_remote_req_router_path= 46.sunbird_remote_bg_req_router_path= - 47.sunbird_api_base_url=http://content-service: 48.sunbird_authorization={} 49.telemetry_pdata_id={{env}}.sunbird.learning.service 50.telemetry_pdata_pid=actor-service