Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DMP 2024] Migration script #140 #152

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 63 additions & 1 deletion .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ KAFKA_GROUP_ID = "survey"
IMPROVEMENT_PROJECT_SUBMISSION_TOPIC = "dev.sl.improvement.project.submission" // Kafka topic name for pushing project submission related data
OBSERVATION_SUBMISSION_TOPIC = "dev.sl.observation.raw" // Kafka topic name for pushing observation submission

# redis Configuration
REDIS_URL = redis://localhost:6379 // Redis connection url
jayesh9747 marked this conversation as resolved.
Show resolved Hide resolved
REDIS_USERNAME = "redis" // Redis username
REDIS_PWD = "1234" // Redis password
REDIS_DB = 1 // Redis db index
REDIS_TTL = 86400 // Redis ttl ( for how many seconds a given key value will continue to be part of the dataset )


# ML Core Service
ML_CORE_SERVICE_URL = "http://ml-core-service:3000" // ML Core Service URL
Expand All @@ -40,4 +47,59 @@ TELEMETRY_ON_OFF = ON/OFF

TELEMETRY_TOPIC = {{env_name}}.telemetry.raw
VALIDATE_ENTITIES = "ON/OFF" // validate entities enable and disable
PROGRAM_JOIN_ON_OFF = "ON/OFF" // Program Join Feature enable and disable
PROGRAM_JOIN_ON_OFF = "ON/OFF" // Program Join Feature enable and disable


# creation portal migration Script

MASTER_USER_EMAIL = "[email protected]" // master user name of the sunbird enviornment to generate token
MASTER_USER_PWD = "password" // master user pwd of the sunbird enviornment to generate token
TOKEN_GEN_GRANT_TYPE = "password-grant" // grant type to generate token for the sunbird enviornment
TOKEN_GEN_CLIENT = "client-id" // client to generate token for the sunbird enviornment
TOKEN_GEN_CLIENT_SECRET = "client-secret-key" // client secret to generate token for the sunbird enviornment

ED_BASE_URL = "https://dev.sunbirded.org/" // base host url of the sunbird enviornment
ED_AUTHORIZATION = "Bearer + 'token'" // base bearer token with all the permissions to run the script of the sunbird enviornment

CREATION_PORTAL_BASE_URL = "https://dock.sunbirded.org/" // creation portal Url

CREATION_PORTAL_AUTHORIZATION = "Bearer + 'token'" // creation portal bearer token with all the permissions for below urls,


# Migration

# API'S required for migration

GEN_TOKEN: "auth/realms/sunbird/protocol/openid-connect/token" // To generate token
jayesh9747 marked this conversation as resolved.
Show resolved Hide resolved
READ_USER: "api/user/v5/read/" // To read user data Authorization: ED_AUTHORIZATION
SEARCH_USER: "api/user/v3/search" // To search user data, Authorization: ED_AUTHORIZATION
CREATE_QUESTION_SET: "api/questionset/v1/create" // To create questionset, Authorization: CREATION_PORTAL_AUTHORIZATION
UPDATE_QUESTION_SET_HIERARCHY: "api/questionset/v1/hierarchy/update" // To update questionset hierarchy, Authorization: CREATION_PORTAL_AUTHORIZATION
PUBLISH_QUESTION_SET: "api/questionset/v1/publish" // To publish questionset, Authorization: CREATION_PORTAL_AUTHORIZATION
READ_QUESTION_SET: "api/questionset/v1/hierarchy/read" // To read questionset, Authorization: CREATION_PORTAL_AUTHORIZATION
CREATE_QUESTION: "api/question/v1/create" // To create question, Authorization: CREATION_PORTAL_AUTHORIZATION
PUBLISH_QUESTION: "api/question/v1/publish" // To publish question, Authorization: CREATION_PORTAL_AUTHORIZATION
CREATE_PROGRAM: "api/program/v1/create" // To create program, Authorization: CREATION_PORTAL_AUTHORIZATION
UPDATE_PROGRAM: "api/program/v1/update" // To update program, Authorization: CREATION_PORTAL_AUTHORIZATION
ADD_PROGRAM_NOMINATION: "api/program/v1/nomination/add" // To add nomination to program, Authorization: CREATION_PORTAL_AUTHORIZATION
UPDATE_PROGRAM_NOMINATION: "api/program/v1/nomination/update" // To update program nomination, Authorization: CREATION_PORTAL_AUTHORIZATION
PUBLISH_PROGRAM: "api/program/v1/publish" // To publish program, Authorization: CREATION_PORTAL_AUTHORIZATION

# Default users to create program and question

DEFAULT_SLUG = 'sunbird' // default slug

DEFAULT_USER_ID_TO_CREATE_PROGRAM = '5a587cc1-e018-4859-a0a8-e842650b9d64' // default user id to create program if solution author is not present
DEFAULT_USER_CHANNEL_ID_TO_CREATE_PROGRAM = '01285019302823526477' // default user channel id to create program if solution author is not present
DEFAULT_USER_SOURCING_ORG_NAME_TO_CREATE_PROGRAM = 'NIT' // default user sourcing org name
DEFAULT_PROGRAM_CREATOR_ORGANISATION_ID = '937dd865-b256-4c1a-9830-a9b5b89f0913'// default user org id to create program if solution author is not present


DEFAULT_FRAMEWORK_ID = 'nit_tpd' // default framework id to create program
DEFAULT_FRAMEWORK_TYPE = 'TPD' // default framework type to create program

DEFAULT_USER_ID_TO_ADD_CONTRIBUTOR = 'bb551fff-121e-4a18-b969-984ac62bd572' // default user id to nominate and add contributor to program

DEFAULT_CONTRIBUTOR_USER_ID = '4e397c42-495e-4fdb-8558-f98176230916' // default user id to contribute content to the program
DEFAULT_CONTRIBUTOR_USER_NAME = '[email protected]' // default user name to contribute content to the program
DEFAULT_CONTRIBUTOR_USER_CHANNEL_ID = '01309282781705830427' // default user user channel to contribute content to the program
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Logs
logs
logTemplates
*.log
npm-debug.log*
csvs

# Runtime data
pids
Expand Down Expand Up @@ -66,3 +68,4 @@ generics/helpers/credentials/*

keycloak-public-keys/

draft.csv
8 changes: 8 additions & 0 deletions config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,16 @@ const configuration = {
}
};

let redis_connect = function () {
const redis = require("./redisConfig");
redis.connect;
global.redisCache = redis.client;
global.cacheTtl = redis.expiry;
};

db_connect();
kafka_connect();
// elasticsearch_connect();
redis_connect();

module.exports = configuration;
26 changes: 26 additions & 0 deletions config/redisConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const redis = require("redis");


var Connect = function () {
var client = redis.createClient({
host: process.env.REDIS_URL,
database: process.env.REDIS_DB,
jayesh9747 marked this conversation as resolved.
Show resolved Hide resolved
socket: {
connectTimeout: 30000
jayesh9747 marked this conversation as resolved.
Show resolved Hide resolved
}
});

client.on("connect", function () {
console.log("redis connected");
});

client.on("error", console.error.bind(console, "redis connection error:"));

return {
connect: client.connect(),
client: client,
expiry: process.env.REDIS_TTL,
};
};

module.exports = Connect();
107 changes: 106 additions & 1 deletion controllers/v1/programsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ module.exports = class Programs extends Abstract {
return new Promise(async (resolve, reject) => {
try {

let programData =
let programData =
await programsHelper.removeSolutions(req.params._id,req.body.solutionIds);

programData.result = programData.data;
Expand All @@ -762,4 +762,109 @@ module.exports = class Programs extends Abstract {
})
}


/**
* @api {post} program/questionset/create
jayesh9747 marked this conversation as resolved.
Show resolved Hide resolved

* @apiVersion 1.0.0
* @apiName mapObservation
* @apiGroup Program
* @apiSampleRequest program/questionset/create
*{
"programId": "5f34e44681871d939950bca5",
"questionsetId": "do_1135353079207444481964",
"createdFor": [
"ShikshaLokam"
],
"name": "ShikshaLokam-QS"
}
* @apiParamExample {json} Response:
{
"message": "mapped observation to program successfully",
"status": 200,
"result": {
"do_1135353079207444481964": "do_11357345389617152011677",
"do_11357345389617152011677": "62c287307d70ae36aaf96cd3"
}
}

/**
* Map Observation to program.
* @method
* @name mapObservation
* @param {Object} req - requested data.
* @returns {JSON} -
*/

async mapObservation(req) {
priyanka-TL marked this conversation as resolved.
Show resolved Hide resolved
return new Promise(async (resolve, reject) => {
try {

let programUpdated = await programsHelper.mapObservation(
req.body.programId,
req.body.questionsetId,
{
createdFor: req.body.createdFor,
createdBy: req.userDetails.userId,
name: req.body.name
}
);

return resolve(programUpdated);

} catch (error) {
return reject({
status: error.status || httpStatusCode.internal_server_error.status,
message: error.message || httpStatusCode.internal_server_error.message,
errorObject: error
});
}
});
}


/**
* @api {post} program/questionset/update/:solutionId
jayesh9747 marked this conversation as resolved.
Show resolved Hide resolved
* @apiVersion 1.0.0
* @apiName mapObservation
* @apiGroup Program
* @apiParam {String} SolutionId Solution ID.
* @apiSampleRequest {json} request:
*{
"name": "ShikshaLokam",
"desciption": "",
"startDate": "2021-02-01",
"endDate": "2021-02-05",
"status": "published"
}
* @apiParamExample {json} Response:
{
"message": "Observation successfully updated.",
"status": 200
}
/**
* updateMapObservation.
* @method
* @name updateMapObservation
* @param {Object} req - requested data.
* @returns {JSON} -
*/
async updateMapObservation(req) {
jayesh9747 marked this conversation as resolved.
Show resolved Hide resolved
return new Promise(async (resolve, reject) => {
try {

let programUpdated = await programsHelper.mapUpdateObservation(
req.params.solutionId, req.body

);

return resolve(programUpdated);
} catch (error) {
return reject({
status: error.status || httpStatusCode.internal_server_error.status,
message: error.message || httpStatusCode.internal_server_error.message
});
}
});
}
};
102 changes: 50 additions & 52 deletions controllers/v1/surveysController.js
Original file line number Diff line number Diff line change
Expand Up @@ -614,59 +614,57 @@ module.exports = class Surveys extends Abstract {

async details(req) {
return new Promise(async (resolve, reject) => {
try {
let appVersion = req.headers["x-app-ver"]
? req.headers["x-app-ver"]
: req.headers.appversion
? req.headers.appversion
: "";
let appName = req.headers["x-app-id"]
? req.headers["x-app-id"]
: req.headers.appname
? req.headers.appname
: "";
let validateSurveyId = gen.utils.isValidMongoId(req.params._id);

let surveyDetails = {};

if (validateSurveyId || req.query.solutionId) {
let surveyId = req.params._id ? req.params._id : "";

surveyDetails = await surveysHelper.detailsV3(
req.body,
surveyId,
req.query.solutionId,
req.userDetails.userId,
req.userDetails.userToken,
appVersion,
appName
);
} else {
let bodyData = req.body ? req.body : {};

surveyDetails = await surveysHelper.getDetailsByLink(
req.params._id,
req.userDetails.userId,
req.userDetails.userToken,
bodyData,
"",
appVersion,
appName
);
}
try {
let appVersion = req.headers["x-app-ver"] ? req.headers["x-app-ver"] : req.headers.appversion ? req.headers.appversion : "";
let appName = req.headers["x-app-id"] ? req.headers["x-app-id"] : req.headers.appname ? req.headers.appname : "";
let validateSurveyId = gen.utils.isValidMongoId(req.params._id);

let surveyDetails = {};

if( validateSurveyId || req.query.solutionId ) {

let surveyId = req.params._id ? req.params._id : "";

surveyDetails = await surveysHelper.detailsV3
(
req.body,
surveyId,
req.query.solutionId,
req.userDetails.userId,
req.userDetails.userToken,
appVersion,
appName,
true
);

} else {

let bodyData = req.body ? req.body : {};

surveyDetails = await surveysHelper.getDetailsByLink(
jayesh9747 marked this conversation as resolved.
Show resolved Hide resolved
req.params._id,
req.userDetails.userId,
req.userDetails.userToken,
bodyData,
"",
appVersion,
appName,
true
);
}

return resolve({
message: surveyDetails.message,
result: surveyDetails.data,
});
} catch (error) {
return reject({
status: error.status || httpStatusCode.internal_server_error.status,
message:
error.message || httpStatusCode.internal_server_error.message,
errorObject: error,
});
}
return resolve({
message: surveyDetails.message,
result: surveyDetails.data
});

} catch (error) {
return reject({
status: error.status || httpStatusCode.internal_server_error.status,
message: error.message || httpStatusCode.internal_server_error.message,
errorObject: error
});
}
});
}

Expand Down
15 changes: 14 additions & 1 deletion envVariables.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,20 @@ let enviromentVariables = {
"message" : "Program Join on/off",
"optional" : false,
"default" : "ON"
}
},
"REDIS_URL": {
"message" : "Required redis url",
"optional" : false
},
"REDIS_DB": {
jayesh9747 marked this conversation as resolved.
Show resolved Hide resolved
"message" : "Required redis dbname",
"optional" : false
},
"REDIS_TTL": {
"message" : "Required redis ttl",
"optional" : true,
"default": 86400
},
}

let success = true;
Expand Down
2 changes: 2 additions & 0 deletions generics/messageConstants/apiResponses.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,5 +376,7 @@ module.exports = {
"KEYS_INDEXED_SUCCESSFULLY": 'Keys indexed successfully',
"KEYS_ALREADY_INDEXED": 'Keys already indexed',
"FAILED_TO_START_RESOURCE": "There was an error in starting/joining. Please try again after some time.",
"SOLUTION_IS_NOT_MIGRATED": "Required solution referenceQuestionSetId",
"QUESTIONSET_NOT_FOUND": "Question set not found",
"OBSERVATION_OVERVIEW_INFORMATION_FETCHED":'Observation overview information fetched successfully'
}
Loading