Skip to content

Commit

Permalink
Merge pull request #308 from ELEVATE-Project/develop
Browse files Browse the repository at this point in the history
Develop To Staging
  • Loading branch information
adithyadinesh0412 authored Dec 31, 2024
2 parents 831dede + 36a6f0a commit 7d47c7e
Show file tree
Hide file tree
Showing 15 changed files with 943 additions and 91 deletions.
40 changes: 22 additions & 18 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -147,23 +147,23 @@ jobs:
- run:
name: Running test cases
command: |
cd src/ && npm run test:integration || true
- run:
name: Get User container ID and print logs
command: |
echo "Getting SCP container ID..."
USER_CONTAINER_ID=$(docker ps -q --filter "name=user")
echo "SCP container ID: $USER_CONTAINER_ID"
# Check if the SCP container is running
if [ -z "$USER_CONTAINER_ID" ]; then
echo "SCP container is not running. Cannot fetch logs."
exit 1 # Exit with an error if SCP container is not running
fi
# Print logs of the SCP container
echo "Printing SCP container logs..."
docker logs $USER_CONTAINER_ID --tail=10000
cd src/ && npm run test:integration
# - run:
# name: Get User container ID and print logs
# command: |
# echo "Getting User container ID..."
# USER_CONTAINER_ID=$(docker ps -q --filter "name=user")
# echo "User container ID: $USER_CONTAINER_ID"

# # Check if the User container is running
# if [ -z "$USER_CONTAINER_ID" ]; then
# echo "User container is not running. Cannot fetch logs."
# exit 1 # Exit with an error if User container is not running
# fi

# # Print logs of the SCP container
# echo "Printing SCP container logs..."
# docker logs $USER_CONTAINER_ID --tail=20000
# - run:
# name: Get SCP container ID and print logs
# command: |
Expand All @@ -179,10 +179,14 @@ jobs:

# # Print logs of the SCP container
# echo "Printing SCP container logs..."
# docker logs $SCP_CONTAINER_ID --tail=10000
# docker logs $SCP_CONTAINER_ID --tail=20000

- store_test_results:
path: ./dev-ops/report
# path: test-results
- store_artifacts:
path: ./dev-ops/report
destination: test-results/
- run:
name: Stop the docker containers - Unmap volumes
command: |-
Expand Down
4 changes: 2 additions & 2 deletions dev-ops/integration_test.self_creation_portal.env
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ KAFKA_GROUP_ID=scp
NOTIFICATION_KAFKA_TOPIC=dev.notifications
PROJECT_PUBLISH_KAFKA_TOPIC=projectpublishtopic
KAFKA_COMMUNICATIONS_ON_OFF=OFF
RESOURCE_KAFKA_PUSH_ON_OFF=ON
RESOURCE_KAFKA_PUSH_ON_OFF=OFF

# Cloud Storage Configuration
CLOUD_STORAGE_PROVIDER=aws
Expand Down Expand Up @@ -55,7 +55,7 @@ MIN_APPROVAL=1
REVIEW_TYPE=SEQUENTIAL
MAX_PROJECT_TASK_COUNT=10
RESOURCE_TYPES="project,observation,observation_with_rubric,survey,program"
CONSUMPTION_SERVICE=elevate-project
CONSUMPTION_SERVICE=self
MAX_BODY_LENGTH_FOR_UPLOAD=5242880
RESOURCE_AUTO_SAVE_TIMER=1000
MAX_RESOURCE_NOTE_LENGTH=2000
Expand Down
2 changes: 1 addition & 1 deletion src/.env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ DEFAULT_DATA_MANAGERS="program_manager,program_designer"
DEFAULT_ROLLOUT_ROLES='rollout_manager'

#kafka topic for publishing rollout
ROLLOUT_PUBLISH_KAFKA_TOPIC='dev.rolloutpublishtopic'
ROLLOUT_PUBLISH_KAFKA_TOPIC='dev.rolloutpublish'

#API for create the project template in consumption
PROJECT_PUBLISH_END_POINT=v1/scp/publishTemplateAndTasks
Expand Down
10 changes: 8 additions & 2 deletions src/configs/kafka.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,14 @@ module.exports = async () => {
const subscribeToConsumer = async () => {
try {
await consumer.subscribe({
topics: [process.env.CLEAR_INTERNAL_CACHE, process.env.PROJECT_PUBLISH_KAFKA_TOPIC],
topics: [
process.env.CLEAR_INTERNAL_CACHE,
process.env.PROJECT_PUBLISH_KAFKA_TOPIC,
process.env.ROLLOUT_PUBLISH_KAFKA_TOPIC,
],
})
logger.info(
`Subscribed to topics: ${process.env.CLEAR_INTERNAL_CACHE} and ${process.env.PROJECT_PUBLISH_KAFKA_TOPIC}`
`Subscribed to topics: ${process.env.CLEAR_INTERNAL_CACHE} , ${process.env.PROJECT_PUBLISH_KAFKA_TOPIC} and ${process.env.ROLLOUT_PUBLISH_KAFKA_TOPIC}`
)
await consumer.run({
eachMessage: async ({ topic, partition, message }) => {
Expand All @@ -75,6 +79,8 @@ module.exports = async () => {
utils.internalDel(streamingData)
} else if (topic == process.env.PROJECT_PUBLISH_KAFKA_TOPIC) {
await consumptionService.publishProjectTemplates(streamingData)
} else if (topic == process.env.ROLLOUT_PUBLISH_KAFKA_TOPIC) {
await consumptionService.publishProgram(streamingData)
}
} catch (error) {
logger.error('Error processing Kafka message:', { error })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ module.exports = {
// as per the discussion with products , all text field length is set to 256 and text-area tp 2000

const validations = {
title: { required: true, regex: "^[a-zA-Z0-9 <>_&-' ]+$" },
description: { required: true, regex: "^[a-zA-Z0-9 <>_&-' ]+$" },
objective: { required: true, regex: "^[a-zA-Z0-9 <>_&-' ]+$" },
name: { required: true, regex: "^[a-zA-Z0-9 <>_&-' ]+$" },
title: { required: true, regex: "^[a-zA-Z0-9 <>_&'\\-]+$" },
description: { required: true, regex: "^[a-zA-Z0-9 <>_&'\\-]+$" },
objective: { required: true, regex: "^[a-zA-Z0-9 <>_&'\\-]+$" },
name: { required: true, regex: "^[a-zA-Z0-9 <>_&'\\-]+$" },
keywords: { required: false, regex: '^[a-zA-Z0-9 <>_&-,]$+' },
learning_resources: {
required: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ module.exports = {
{
entityType: 'solution_details',
has_entities: false,
validation: { required: false, regex: "^[a-zA-Z0-9 <>_&-' ]+$" },
validation: { required: false, regex: "^[a-zA-Z0-9 <>_&'\\-]+$" },
model: ['tasks'],
},
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,18 +182,18 @@ function transformValidation(validation, entityType) {
function getNewMessage(entityType, validationType) {
const messages = {
title: {
regex: 'Project title can only include alphanumeric characters with spaces, -, _, &, <>',
regex: "Project title can only include alphanumeric characters with spaces, -, _, &, <>, '",
required: 'Enter valid project title',
max_length: 'Project title must not exceed 256 characters',
},
categories: { required: 'Add project category' },
objective: {
regex: 'Objective can only include alphanumeric characters with spaces, -, _, &, <>',
regex: "Objective can only include alphanumeric characters with spaces, -, _, &, <>, '",
required: 'Summarize the goal of the project',
max_length: 'Objective must not exceed 2000 characters',
},
keywords: {
regex: 'Keyword can only include alphanumeric characters with spaces, -, _, &, <>',
regex: "Keyword can only include alphanumeric characters with spaces, -, _, &, <>, '",
required: 'Add a tag',
max_length: 'Keyword must not exceed 256 characters',
},
Expand All @@ -204,7 +204,7 @@ function getNewMessage(entityType, validationType) {
required: 'Enter link to the resource',
},
name: {
regex: 'Description can only include alphanumeric characters with spaces, -, _, &, <>',
regex: "Description can only include alphanumeric characters with spaces, -, _, &, <>, '",
required: 'Enter description for task',
max_length: 'Description title must not exceed 2000 characters',
},
Expand All @@ -213,7 +213,7 @@ function getNewMessage(entityType, validationType) {
allow_evidences: { required: 'allow_evidences field is required' },
min_no_of_evidences: { required: 'min_no_of_evidences field is required' },
solution_details: {
regex: 'Description can only include alphanumeric characters with spaces, -, _, &, <>',
regex: "Description can only include alphanumeric characters with spaces, -, _, &, <>, '",
max_length: 'Name must not exceed 256 characters',
},
}
Expand Down
15 changes: 10 additions & 5 deletions src/envVariables.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,15 +207,20 @@ let environmentVariables = {
ROLLOUT_PUBLISH_KAFKA_TOPIC: {
message: 'Default Kafka topic for rollout publish required',
optional: true,
default: 'dev.rolloutpublishtopic',
},
default: 'dev.rolloutpublish',
requiredIf: {
key: 'CONSUMPTION_SERVICE_BASE_URL',
operator: 'NOT_EQUALS',
value: 'self',
},
},
CONSUMPTION_SERVICE_BASE_URL: {
message: 'Consumption service base name required',
optional: true,
requiredIf: {
key: 'RESOURCE_KAFKA_PUSH_ON_OFF',
operator: 'EQUALS',
value: 'OFF',
key: 'CONSUMPTION_SERVICE',
operator: 'NOT_EQUALS',
value: 'self',
},
},
PROJECT_PUBLISH_END_POINT: {
Expand Down
20 changes: 20 additions & 0 deletions src/generics/kafka-communication.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,28 @@ const pushResourceToKafka = async (message, resourceType) => {
throw error
}
}
const pushRolloutToKafka = async (message, resourceType) => {
try {
let topic = process.env.ROLLOUT_PUBLISH_KAFKA_TOPIC

if (!topic) {
console.log('Publishing rollout topic not fount.')
return
}

const payload = {
topic: topic,
messages: [{ value: JSON.stringify(message) }],
}

return await pushPayloadToKafka(payload)
} catch (error) {
throw error
}
}

module.exports = {
clearInternalCache,
pushResourceToKafka,
pushRolloutToKafka,
}
48 changes: 19 additions & 29 deletions src/generics/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,36 +419,21 @@ const checkRegexPattern = (entityType, entityData) => {
}
// Proceed if a regex validation object is found
if (entityType && entityType.type === common.REGEX_VALIDATION) {
const isTextEnglish = isEnglish(entityData)

// Normalize the entityData
let normalizedValue = typeof entityData === 'number' ? entityData.toString() : entityData

// If the language is not English, translate
if (!isTextEnglish) {
normalizedValue = tr(entityData) // Assuming translateText function exists
}

const modifyPattern = (pattern) => {
// If the text is English, remove the apostrophe from the regex pattern
if (isTextEnglish) {
return pattern.replace(/'/g, '')
}
return pattern
}
let normalizedValue = typeof entityData === 'number' ? entityData.toString() : tr(entityData)

// Handle array of regex patterns
if (Array.isArray(entityType.regex)) {
for (let pattern of entityType.regex) {
let regex = new RegExp(modifyPattern(pattern))
let regex = new RegExp(pattern)
if (regex.test(normalizedValue)) {
return true
}
}
return false
} else {
// Handle the case where regex is a single pattern
let regex = new RegExp(modifyPattern(entityType.value))
let regex = new RegExp(entityType.value)
return regex.test(normalizedValue)
}
}
Expand Down Expand Up @@ -620,16 +605,6 @@ const isEmpty = (obj) => {
return true
}

function isEnglish(text) {
// Regex to match only English letters and numbers
var englishRegex = new RegExp('^[\x20-\x7E]*$')
if (englishRegex.test(text)) {
return true
} else {
return false
}
}

/**
* Format Name to title case
* @name formatToTitleCase
Expand Down Expand Up @@ -743,6 +718,21 @@ function convertDuration(durationObj) {
}
}

/**
* Converts charachters which can cause issues in xml file to accepted values
* name escapeXml
* @param {String} inputElement - The input duration object.
* @returns {String} - Converted xml with accepted charecters.
*/
const escapeXml = (inputElement) => {
return inputElement
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&apos;')
}

module.exports = {
composeEmailBody,
internalSet,
Expand Down Expand Up @@ -779,12 +769,12 @@ module.exports = {
sort,
isEmpty,
checkLength,
isEnglish,
checkEndDate,
formatToTitleCase,
generateExternalId,
convertResources,
formatKeywords,
formatProjectMetaInformation,
convertDuration,
escapeXml,
}
2 changes: 1 addition & 1 deletion src/integration-tests/commonTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const verifyUserRole = async () => {

// Create a new user
let email = 'orgadmin' + crypto.randomBytes(5).toString('hex') + '@shikshalokam.com'
let password = 'Welcome@123'
let password = 'Welco@Me#123!'

try {
let res = await request.post('/user/v1/account/create').send({
Expand Down
39 changes: 33 additions & 6 deletions src/integration-tests/rollouts/responseSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ const getDataManagersEmptyResponseSchema = {
},
required: ['responseCode', 'message', 'result', 'meta'],
}
const getRolloutsListSchema = {
const listSchema = {
type: 'object',
properties: {
responseCode: {
Expand Down Expand Up @@ -360,7 +360,7 @@ const getRolloutsListSchema = {
},
required: ['responseCode', 'message', 'result', 'meta'],
}
const getRolloutsListEmptyResponseSchema = {
const listEmptyResponseSchema = {
type: 'object',
properties: {
responseCode: {
Expand Down Expand Up @@ -398,7 +398,33 @@ const getRolloutsListEmptyResponseSchema = {
},
required: ['responseCode', 'message', 'result', 'meta'],
}
const rolloutDetailResponseSchema = {
const detailResponseSchema = {
type: 'object',
properties: {
responseCode: {
type: 'string',
},
error: {
type: 'array',
items: {},
},
meta: {
type: 'object',
properties: {
correlation: {
type: 'string',
},
},
required: [],
},
message: {
type: 'string',
},
},
required: ['responseCode', 'error', 'meta', 'message'],
}

const createSchema = {
type: 'object',
properties: {
responseCode: {
Expand Down Expand Up @@ -426,7 +452,8 @@ const rolloutDetailResponseSchema = {
module.exports = {
getDataManagersSchema,
getDataManagersEmptyResponseSchema,
getRolloutsListSchema,
getRolloutsListEmptyResponseSchema,
rolloutDetailResponseSchema,
listSchema,
listEmptyResponseSchema,
detailResponseSchema,
createSchema,
}
Loading

0 comments on commit 7d47c7e

Please sign in to comment.