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

Single file upload #174

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
0f094b4
list assets type using orgId
praveenKDass Jan 22, 2024
f8e6cdc
fetch both assets when type undefined
praveenKDass Jan 23, 2024
c2cc254
projection added
praveenKDass Jan 23, 2024
29aada4
kafka event for owner transfer
praveenKDass Jan 24, 2024
11aa228
worked on PR changes and fixed bugs on ownerassetsTransfer
praveenKDass Jan 29, 2024
78b6de7
handled ownership assets transfer PR changes
praveenKDass Jan 30, 2024
45a65c9
Worked PR comments forowner asstes transfer
praveenKDass Jan 31, 2024
98858c9
checking from and touser role identical
praveenKDass Feb 1, 2024
1c1f9e7
bug fixes in assets for solution type
praveenKDass Feb 1, 2024
6293706
fetch assets using list function for program and solution
praveenKDass Feb 1, 2024
ba509c2
made changes on Feb1 PR comments
praveenKDass Feb 2, 2024
c0a81d2
return key added for promises in user extension and roles helper func…
praveenKDass Feb 2, 2024
39db1b6
renaming functions from query to list
praveenKDass Feb 2, 2024
125f9d0
file upload to the azure cloud
praveenKDass Feb 5, 2024
b19e257
wrote the conditon for assetinformation identifier'
praveenKDass Feb 7, 2024
df5d903
bug fixes on owner asstes tranfser
praveenKDass Feb 7, 2024
5440320
bug fixes for owner asstes transfer
praveenKDass Feb 7, 2024
df8f287
removed upload from PR
praveenKDass Feb 7, 2024
0f6ab28
bug fixes on ownerAssetTransfer one to one flow
praveenKDass Feb 8, 2024
133ecf8
program collection query added
praveenKDass Feb 8, 2024
f898c1b
telementry event conditions added
praveenKDass Feb 8, 2024
1d38a43
working on file upload api
praveenKDass Feb 15, 2024
d229f35
removing logs
praveenKDass Feb 15, 2024
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
84 changes: 46 additions & 38 deletions config/kafka.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,53 +3,55 @@
* author : vishnu
* created-date : 10-Jan-2023
* Description : Kafka Configurations related information.
*/

*/

//dependencies
const kafka = require('kafka-node');
const kafka = require("kafka-node");
const USER_DELETE_TOPIC = process.env.USER_DELETE_TOPIC;
const USER_DELETE_ON_OFF = process.env.USER_DELETE_ON_OFF
const USER_DELETE_ON_OFF = process.env.USER_DELETE_ON_OFF;
const OWNERSHIP_TRANSFER_TOPIC = process.env.OWNERSHIP_TRANSFER_TOPIC;
const OWNERSHIP_TRANSFER_ON_OFF = process.env.OWNERSHIP_TRANSFER_ON_OFF;

/**
* Kafka configurations.
* @function
* @name connect
*/

const connect = function() {

const Producer = kafka.Producer
KeyedMessage = kafka.KeyedMessage

const client = new kafka.KafkaClient({
kafkaHost : process.env.KAFKA_URL
});
* Kafka configurations.
* @function
* @name connect
*/

client.on('error', function(error) {
console.log("kafka connection error!")
});
const connect = function () {
const Producer = kafka.Producer;
KeyedMessage = kafka.KeyedMessage;

const producer = new Producer(client)
const client = new kafka.KafkaClient({
kafkaHost: process.env.KAFKA_URL,
});

producer.on('ready', function () {
console.log("Connected to Kafka");
});

producer.on('error', function (err) {
console.log("kafka producer creation error!")
})
client.on("error", function (error) {
console.log("kafka connection error!");
});

if(USER_DELETE_ON_OFF !== "OFF") {
_sendToKafkaConsumers(USER_DELETE_TOPIC, process.env.KAFKA_URL);
}
const producer = new Producer(client);

return {
kafkaProducer: producer,
kafkaClient: client
};
producer.on("ready", function () {
console.log("Connected to Kafka");
});

};
producer.on("error", function (err) {
console.log("kafka producer creation error!");
});

if (USER_DELETE_ON_OFF !== "OFF") {
_sendToKafkaConsumers(USER_DELETE_TOPIC, process.env.KAFKA_URL);
}
if (OWNERSHIP_TRANSFER_ON_OFF !== "OFF") {
_sendToKafkaConsumers(OWNERSHIP_TRANSFER_TOPIC, process.env.KAFKA_URL);
}

return {
kafkaProducer: producer,
kafkaClient: client,
};
};

/**
* Send data based on topic to kafka consumers
Expand All @@ -59,8 +61,7 @@ const connect = function() {
* @param {String} host - kafka host
*/

var _sendToKafkaConsumers = function (topic, host) {

var _sendToKafkaConsumers = function (topic, host) {
if (topic && topic != "") {
let consumer = new kafka.ConsumerGroup(
{
Expand All @@ -81,12 +82,19 @@ const connect = function() {
if (message && message.topic === USER_DELETE_TOPIC) {
userDeleteConsumer.messageReceived(message);
}
// call assets or ownership Transfer consumer
if (message && message.topic === OWNERSHIP_TRANSFER_TOPIC) {
assetsTransferConsumer.messageReceived(message);
}
});

consumer.on("error", async function (error) {
if (error.topics && error.topics[0] === USER_DELETE_TOPIC) {
userDeleteConsumer.errorTriggered(error);
}
if (error.topics && error.topics[0] === OWNERSHIP_TRANSFER_TOPIC) {
assetsTransferConsumer.errorTriggered(error);
}
});
}
};
Expand Down
52 changes: 52 additions & 0 deletions controllers/v1/assets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
const assetsHelper = require(MODULES_BASE_PATH + "/assets/helper.js");

module.exports = class Assets {

/**
* Get organisation program and solution.
* @name list
* @api {get} /kendra/api/v1/assets/list?type=program or solution.
* @apiHeader {String} X-authenticated-user-token Authenticity token
* @apiSampleRequest v1/assets/list?type=program
* @apiParamExample {Object:} Request-Body:
{
"filters": {
"orgId": "01269934121990553633",
"userId":["5d7255bb-1216-460e-9228-59b60230b1c1","5d7255bb-1216-460e-9228-59b60230b1c2"]
},
"fields": [
"_id",
"name",
"status",
"owner",
"orgId",
"objectType"
],
"limit": 1000
}
* @apiUse successBody
* @apiUse errorBody
* @returns {JSON} - Details of the program or solution .
*/

list(req) {
return new Promise(async (resolve, reject) => {
try {
let assestsData = await assetsHelper.fetchAssets(
req.query.type,
req.body
);

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

};
70 changes: 68 additions & 2 deletions controllers/v1/cloud-services/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,14 @@ module.exports = class Files {
return new Promise(async (resolve, reject) => {

try {

let signedUrl =
let signedUrl =
await filesHelpers.preSignedUrls(
req.body.request,
req.body.ref,
req.userDetails ? req.userDetails.userId : ""
);


signedUrl["result"] = signedUrl["data"];
return resolve(signedUrl);

Expand Down Expand Up @@ -183,6 +183,72 @@ module.exports = class Files {
})

}

/**
* Get upload the file and Downloadable URL from cloud service.
* @method
* @name upload
* @param {Request} req request body.
* @returns {JSON} Response with status and message.
* @apiParamExample {json} Response:
* {
"message": "File uploaded successfully",
"status": 200,
"result": {
"url": {
"path": "uploadedFiles/industry.csv",
"downloadUrl": "https://sunbirddev.blob.core.windows.net/manage-learn-evidences/uploadedFiles/industry.csv?sv=2023-01-03&st=2024-02-15T11%3A54%3A41Z&se=2024-02-17T23%3A54%3A41Z&sr=b&sp=r&sig=LXLT8S4T2i2QUFPNLMbVMbp1fqhSznOSom4A3mh3KCk%3D"
},
"payload": {
"sourcePath": "uploadedFiles/industry.csv"
},
"cloudStorage": "AZURE"
}
}
*/

async upload(req) {
return new Promise(async (resolve, reject) => {

try {

if (req.files) {

let uploadResponse =
await filesHelpers.upload(
req.files.file,
);

return resolve({
message: constants.apiResponses.FILE_UPLOADED,
result: uploadResponse.result
})

} else {
return reject({
status: httpStatusCode["bad_request"].status,
message: httpStatusCode["bad_request"].message

});
}

} catch (error) {

return reject({
status:
error.status ||
httpStatusCode["internal_server_error"].status,

message:
error.message
|| httpStatusCode["internal_server_error"].message,

errorObject: error
})

}
})
}

};

1 change: 1 addition & 0 deletions generics/constants/api-responses.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,5 @@ module.exports = {
"FAILED_TO_CREATE_DOWNLOADABLEURL" : "Failed to generate downloadableUrl",
"KEYS_INDEXED_SUCCESSFULLY": 'Keys indexed successfully',
"KEYS_ALREADY_INDEXED": 'Keys already indexed',
"ASSETS_FETCHED_SUCCESSFULLY": "Assets fetched successfully "
};
10 changes: 9 additions & 1 deletion generics/constants/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,18 @@
TELEMTRY_EVENT_LOGGER: "TelemetryEventLogger",
INFO_LEVEL: "INFO",
DELETE_STATE: "Delete",
TRANSFER_STATE:"Transfer",
USER_DELETE_TYPE: "DeleteUserStatus",
AUDIT: "AUDIT",
DELETE_USER: "delete-user",
OWNERSHIP_TRANSFER_TOPIC:"ownership-transfer",
OWNERSHIP_TRANSFER_TYPE:"OwnerTransferStatus",
OWNERSHIP_TRANSFER_MODULE:"ownerTransfer",
USER: "User",
USER_DELETE_MODULE: "userDelete",
OFF: "OFF"
OFF: "OFF",
PROGRAM_DESIGNER:"PROGRAM_DESIGNER",
PROGRAM_MANAGER:"PROGRAM_MANAGER",
CONTENT_CREATOR:"CONTENT_CREATOR",
SOULTION:"solution",
};
90 changes: 90 additions & 0 deletions generics/kafka/consumers/assetsTransfer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@




const assetsHelper = require(MODULES_BASE_PATH + "/assets/helper.js");

/**
* Ownership transfer message received.
* @function
* @name messageReceived
* @param {Object} message - consumer data
* {
"highWaterOffset": 63,
"key": "",
"offset": 62,
"partition": 0,
"topic": "ownershiptransfer",
"edata": {
"action": "ownership-transfer",
"organisationId": "01269934121990553633",
"context": "Ownership Transfer",
"actionBy": {
"userId": "5d7255bb-1216-460e-9228-59b60230b1c1",
"userName": ""
},
"fromUserProfile": {
"userId": "fca2925f-1eee-4654-9177-fece3fd6afc9",
"userName": "",
"channel": "",
"organisationId": "",
"roles": [
"PROGRAM_MANAGER"
]
},
"toUserProfile": {
"userId": "289bc48c-0a74-4650-ac99-187575a3a8a9",
"userName": "",
"firstName": "",
"lastName": "",
"roles": [
"PROGRAM_MANAGER"
]
},
"assetInformation": {
"objectType": "PROGRAM_MANAGER",
"identifier": "{{resource_identifier}}"
},
"iteration": 1
}
}
}
* @returns {Promise} return a Promise.
*/



var messageReceived = function (message) {
return new Promise(async function (resolve, reject) {
try {
let parsedMessage = JSON.parse(message.value);
if (parsedMessage.edata.action === constants.common.OWNERSHIP_TRANSFER_TOPIC) {
let ownershipTransferResponse = await assetsHelper.ownershipTransfer(parsedMessage);

if (ownershipTransferResponse.success == true) {
return resolve("Message Processed.");
} else {
return resolve("Message Processed.");
}
}
} catch (error) {
return reject(error);
}
});
};

var errorTriggered = function (error) {
return new Promise(function (resolve, reject) {
try {
return resolve(error);
} catch (error) {
return reject(error);
}
});
};

module.exports = {
messageReceived: messageReceived,
errorTriggered: errorTriggered,
};

Loading