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

Implement service /v1/provide-list-of-network-element-interfaces-on-path-in-generic-representation #175

Merged
merged 1 commit into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions server/controllers/IndividualServices.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module.exports.provideListOfNetworkElementInterfacesOnPath = async function prov
let startTime = process.hrtime();
let responseCode = responseCodeEnum.code.OK;
let responseBodyToDocument = {};
await IndividualServices.provideListOfNetworkElementInterfacesOnPath(body, user, originator, xCorrelator, traceIndicator, customerJourney, req.url)
await IndividualServices.provideListOfNetworkElementInterfacesOnPath(body, req.url)
.then(async function (responseBody) {
responseBodyToDocument = responseBody;
let responseHeader = await ResponseHeader.createResponseHeader(xCorrelator, startTime, req.url);
Expand All @@ -50,9 +50,9 @@ module.exports.provideListOfNetworkElementInterfacesOnPath = async function prov

module.exports.provideListOfNetworkElementInterfacesOnPathInGenericRepresentation = async function provideListOfNetworkElementInterfacesOnPathInGenericRepresentation(req, res, next, body, user, originator, xCorrelator, traceIndicator, customerJourney) {
let startTime = process.hrtime();
let responseCode = responseCodeEnum.code.NO_CONTENT;
let responseCode = responseCodeEnum.code.OK;
let responseBodyToDocument = {};
await IndividualServices.provideListOfNetworkElementInterfacesOnPathInGenericRepresentation(body, user, originator, xCorrelator, traceIndicator, customerJourney, req.url)
await IndividualServices.provideListOfNetworkElementInterfacesOnPathInGenericRepresentation(body, req.url)
.then(async function (responseBody) {
responseBodyToDocument = responseBody;
let responseHeader = await ResponseHeader.createResponseHeader(xCorrelator, startTime, req.url);
Expand Down
135 changes: 87 additions & 48 deletions server/service/IndividualServicesService.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const RequestHeader = require('onf-core-model-ap/applicationPattern/rest/client/
const RestRequestBuilder = require('onf-core-model-ap/applicationPattern/rest/client/RequestBuilder');
var responseCodeEnum = require('onf-core-model-ap/applicationPattern/rest/server/ResponseCode');
const TcpClient = require('../service/TcpClientService');
const genericRepresentation = require('onf-core-model-ap-bs/basicServices/GenericRepresentation');
const createHttpError = require("http-errors");
const axios = require('axios');

Expand Down Expand Up @@ -186,7 +187,6 @@ function transformData(inputData) {
"vlan-id": inputData["vlan-id"],
"time-stamp-of-data": new Date(inputData["time-stamp-of-data"]).toISOString()
};

return outputData;
}

Expand Down Expand Up @@ -415,12 +415,11 @@ exports.updateCurrentConnectedEquipment = async function (user, originator, xCor
try {
if (Array.isArray(listDisconnectedEq)) {
for (const elementToRemove of listDisconnectedEq) {
try{
try {
RequestForDeleteEquipmentIntoElasticSearch(elementToRemove);
}
catch(error)
{
console.error('Error during deleting operation of old mac address data into db (' + elementToRemove +')');
catch (error) {
console.error('Error during deleting operation of old mac address data into db (' + elementToRemove + ')');
}
}
}
Expand Down Expand Up @@ -674,8 +673,10 @@ const RequestForListOfNetworkElementInterfacesOnPathCausesReadingFromElasticSear
* customerJourney String Holds information supporting customer’s journey to which the execution applies
* returns List
**/
exports.provideListOfNetworkElementInterfacesOnPath = async function (body, user, originator, xCorrelator, traceIndicator, customerJourney) {
exports.provideListOfNetworkElementInterfacesOnPath = async function (body, url) {
return new Promise(function (resolve, reject) {


RequestForListOfNetworkElementInterfacesOnPathCausesReadingFromElasticSearch(body)
.then(function (response) {
resolve(response);
Expand Down Expand Up @@ -706,51 +707,89 @@ exports.provideListOfNetworkElementInterfacesOnPath = async function (body, user
* customerJourney String Holds information supporting customer’s journey to which the execution applies
* returns genericRepresentation
**/
exports.provideListOfNetworkElementInterfacesOnPathInGenericRepresentation = function (body, user, originator, xCorrelator, traceIndicator, customerJourney) {
return new Promise(function (resolve, reject) {
var examples = {};
examples['application/json'] = {
"consequent-action-list": [{
"request": "request",
"input-value-list": [{
"field-name": "field-name",
"unit": "unit"
}, {
"field-name": "field-name",
"unit": "unit"
}],
"display-in-new-browser-window": true,
"label": "label"
}, {
"request": "request",
"input-value-list": [{
"field-name": "field-name",
"unit": "unit"
}, {
"field-name": "field-name",
"unit": "unit"
}],
"display-in-new-browser-window": true,
"label": "label"
}],
"response-value-list": [{
"field-name": "field-name",
"datatype": "datatype",
"value": "value"
}, {
"field-name": "field-name",
"datatype": "datatype",
"value": "value"
}]
};
if (Object.keys(examples).length > 0) {
resolve(examples[Object.keys(examples)[0]]);
} else {
resolve();
exports.provideListOfNetworkElementInterfacesOnPathInGenericRepresentation = async function (body, req) {
return new Promise(async function (resolve, reject) {

const inputValueList = body["input-value-list"];
let fieldValues;
let fieldValueFinal = [];
let result = [];
let responseValueVist;

let operationServerName = req;

if (inputValueList && inputValueList.length > 0) {
// Crea un vettore per memorizzare i valori "field-value"
fieldValues = inputValueList.map(item => item["field-value"]);
}

for (const inputValue of body["input-value-list"]) {
// Estrarre il campo "field-value" dall'input
const fieldValue = inputValue["field-value"];

// Creare un nuovo oggetto nel formato desiderato e aggiungerlo all'array risultante
fieldValueFinal.push({
"target-mac-address": fieldValue
});
}

// Loop attraverso ogni elemento di fieldValues e esegui la richiesta per ciascuno
const promises = fieldValueFinal.map(fieldValue => {
return RequestForListOfNetworkElementInterfacesOnPathCausesReadingFromElasticSearch(fieldValue)
.then(
response => response
)
.catch(error => {
if (error.name == 'TimeoutError') {
const requestTimeout = createHttpError.RequestTimeout('Elastic Search error: ' + error.message);
throw requestTimeout;
} else {
const notFoundError = createHttpError.InternalServerError('Elastic Search error: ' + error.message);
throw notFoundError;
}
});
});
}



let existingItem = false;
Promise.all(promises)
.then(response => {
// Tutte le richieste sono state completate con successo
let pippo = 0;

response.at(0).forEach(element => {
// Puoi accedere alle proprietà di ciascun elemento qui
console.log("Target MAC Address:", element["target-mac-address"]);

existingItem = result.find(item => item["value"].includes(element["mount-name"]));

if (existingItem!=undefined) {
existingItem["value"] = existingItem["value"] + ";" + element["target-mac-address"];
} else {
result.push({
"value": `${element["mount-name"]}:${element["target-mac-address"]}`,
"datatype": "string",
"field-name": "listOfNetworkElementInterfacesOnPath"
});
}

});


let fullResponse =
{
"consequent-action-list": [],
"response-value-list": result
}

resolve(fullResponse);
})
.catch(error => {
console.error(error);
});
});
}


function orderData(input) {
Expand Down
Loading