Correct export of Delivery Unit EON_EMOBILITY_PROVIDER (37 files, replaces incomplete initial export)

This commit is contained in:
Thorsten Schmitz
2026-07-09 01:59:09 +02:00
parent 1baef99314
commit dce458f6c1
38 changed files with 6669 additions and 75 deletions
@@ -0,0 +1,308 @@
var datetimeLib = $.import("uniorg.libs", "datetime");
//var logginglib = $.import("uniorg.libs", "uologging");
//var billingEngine = $.import("uniorg.eon.emobility.billing.engine.v1", "BillingEngine");
var destLib = $.import("uniorg.destinations", "uodestlib");
var slLib = $.import("uniorg.ServiceLayer", "B1SLLogic");
var serviceName = "eon.emobility.provider.backend.addNextPeriodData.xsjs";
var serviceVersion = '1.3';
var output = {};
var outMessages = [];
var outMsg = {};
var outStatus = "success";
var myDebug = {};
var companyid = 0;
var UserName = '';
var UserPass = '';
var UserComp = '';
var SESSIONID = "";
var NODEID = "";
var slLoggedIn = false;
var schemaName = "A19753_EON_P01";
var debugLevel = 0;
switch ($.request.parameters.get("debug")) {
case "true":
case "yes":
case "1":
debugLevel = 1;
break;
case "full":
case "2":
debugLevel = 2;
break;
}
if (debugLevel > 0) {
output.requestParams = $.request.parameters;
}
function setOutputMessage() {
output.status = outStatus;
if (debugLevel > 0) {
output.debugInfos = myDebug;
}
output.messages = outMessages;
$.response.contentType = "application/json";
$.response.setBody(JSON.stringify(output));
//$.response.status = $.net.http.OK;
}
function exceptionHandler(ex) {
if (outMsg.method && outMessages.indexOf(outMsg) === -1) {
outMsg.status = "canceled";
outMessages.push(outMsg);
}
outMsg = {};
outMsg.method = "exceptionHandler";
outMsg.status = "error";
outMsg.message = ex.toString();
if (debugLevel > 0) {
outMsg.exceptionInfo = {};
outMsg.exceptionInfo.name = ex.name;
outMsg.exceptionInfo.message = ex.message;
outMsg.exceptionInfo.fileName = ex.fileName;
outMsg.exceptionInfo.lineNumber = ex.lineNumber;
outMsg.exceptionInfo.columnNumber = ex.columnNumber;
outMsg.exceptionInfo.stack = ex.stack;
//outMsg.exceptionInfo.source = ex.toSource();
}
outMessages.push(outMsg);
outStatus = "error";
output.status = outStatus;
if (debugLevel > 0) {
output.debugInfos = myDebug;
}
output.messages = outMessages;
var errbody = JSON.stringify(output);
$.response.contentType = 'application/json';
$.response.setBody(errbody);
$.response.status = $.net.http.INTERNAL_SERVER_ERROR;
try {
if (slLoggedIn) {
slLib.SLLogout(SESSIONID, NODEID);
}
} catch (e) {
}
}
function checkAuthorization() {
var isAuthorized = true;
try {
$.session.assertAppPrivilege("uniorg.eon.emobility.provider::MaintainProviderData");
} catch (ex) {
isAuthorized = false;
outMsg = {};
outMsg.method = "checkAuthorization";
outMsg.status = "error";
outStatus = "error";
outMsg.message = "Privilege '" + ex.privilege + "' is missing";
outMessages.push(outMsg);
$.response.status = $.net.http.FORBIDDEN;
}
return isAuthorized;
}
function checkPayload(inObj) {
var isValid = true;
var errorList = [];
try {
var provider = JSON.parse(inObj);
if (!provider.hasOwnProperty('Code')) {
isValid = false;
}
if (Array.isArray(provider.NextPeriod)) {
provider.NextPeriod.forEach(function(npl) {
if (!npl.hasOwnProperty('U_CODE') || !npl.hasOwnProperty('U_FROM') || !npl.hasOwnProperty('U_TO') || !npl.hasOwnProperty('U_TYP') || !npl.hasOwnProperty('U_OPERATOR') || !npl.hasOwnProperty('U_SUBOPERATOR')) {
isValid = false;
} else {
var errorDetails = {
U_CODE: npl.U_CODE,
U_FROM: npl.U_FROM,
U_TO: npl.U_TO,
U_TYP: npl.U_TYP,
U_OPERATOR: npl.U_OPERATOR,
U_SUBOPERATOR: npl.U_SUBOPERATOR,
Status: 'error'
};
if (errorDetails.StatusText) {
errorList.push(errorDetails);
isValid = false;
} else if (debugLevel > 0) {
errorDetails.Status = "success";
errorList.push(errorDetails);
}
}
});
} else {
isValid = false;
}
} catch (e) {
exceptionHandler(e);
isValid = false;
}
if (!isValid) {
outMsg = {};
outMsg.method = "checkPayload";
outMsg.status = "error";
outStatus = "error";
if (errorList.length > 0) {
outMsg.message = "invalid payload content";
output.results = errorList;
} else {
outMsg.message = "invalid payload structure";
}
outMessages.push(outMsg);
$.response.status = $.net.http.BAD_REQUEST;
}
return isValid;
}
function setConnectionParams() {
var idValue = schemaName;
var idFieldname = 'SYS_NAME';
var CompanyConfig = destLib.getCompanyCfg(idValue, idFieldname);
UserComp = CompanyConfig.COMPANYNAME;
UserName = CompanyConfig.USERNAME;
UserPass = destLib.readSecureStore(CompanyConfig.ID);
if (debugLevel > 1) {
myDebug.connectionParams = CompanyConfig;
}
myDebug.idValue = idValue;
myDebug.idFieldname = idFieldname;
if (CompanyConfig.COMPANYNAME === undefined) {
outMsg = {};
outMsg.method = "getCompany";
outStatus = "error";
outMsg.status = "error";
outMsg.message = "System " + idValue + " is invalid for this endpoint";
outMessages.push(outMsg);
}
myDebug.CompanyName = UserComp;
}
function slLogin() {
var loginResult = false;
var loginInfo = {};
loginInfo.UserName = UserName;
loginInfo.Password = UserPass;
loginInfo.CompanyDB = UserComp;
// SL LOGIN
var response = slLib.SLLogin(JSON.stringify(loginInfo), null, null);
// B1SESSION and ROUTEID cookies returned by Login
for (var j in response.cookies) {
if (response.cookies[j].name == "B1SESSION") {
SESSIONID = response.cookies[j].value;
//output.SessionID = SESSIONID;
} else if (response.cookies[j].name == "ROUTEID") {
NODEID = response.cookies[j].value;
//output.NodeID = NODEID;
}
}
var loginResponse;
try {
loginResponse = JSON.parse(response.body.asString());
} catch (e) {
loginResponse = response.body.asString();
}
if (debugLevel > 1) {
myDebug.loginInfo = loginInfo;
}
myDebug.loginResponse = loginResponse;
if (response.status === 200) {
loginResult = true;
} else {
outMsg = {};
outMsg.method = "login";
outMsg.status = "error";
var slError = myDebug.loginResponse.error;
if (slError && slError.hasOwnProperty("code") && slError.message && slError.message.value) {
outMsg.message = slError.message.value + " (Code: " + slError.code.toString() + ")";
} else {
outMsg.message = JSON.stringify(myDebug.loginResponse);
}
outMsg.response = myDebug.loginResponse;
//outMsg.message = loginResponse;
outMessages.push(outMsg);
outStatus = "error";
}
return loginResult;
}
function updateUDO(provider) {
outMsg = {};
outMsg.method = "updateUDO";
outMsg.status = "failure";
try {
var slProviderObj = {
EON_PROVIDER_LINESCollection: provider.NextPeriod.map(function(npl) {return {
Code: npl.Code,
U_CODE: npl.U_CODE,
U_FROM: datetimeLib.convertToISODate(npl.U_FROM),
U_TO: datetimeLib.convertToISODate(npl.U_TO),
U_OPERATOR: npl.U_OPERATOR,
U_SUBOPERATOR: npl.U_SUBOPERATOR,
U_TYP: npl.U_TYP,
U_CURRENCY: npl.U_CURRENCY,
U_VALUE: npl.NewValue,
U_BLOCK_FROM: npl.U_BLOCK_FROM,
U_BLOCK_TO: npl.U_BLOCK_TO,
U_BLOCKMAX: npl.U_BLOCKMAX,
U_RELEASED: 'Y',
U_RELEASE_DATE: datetimeLib.convertToISODate(new Date()),
U_RELEASE_USER: $.session.getUsername(),
U_CHANGE_DATE: datetimeLib.convertToISODate(new Date()),
U_CHANGE_USER: $.session.getUsername()
};})
};
myDebug.slProviderObj = slProviderObj;
var responseProvider = slLib.patchDynamicEntity('EON_PROVIDER', provider.Code, JSON.stringify(slProviderObj), SESSIONID, NODEID, false);
if (responseProvider.status >= 200 && responseProvider.status < 300) {
outMsg.status = "success";
} else {
if (responseProvider.body) {
var responseBodyParsed = JSON.parse(responseProvider.body.asString());
var slError = responseBodyParsed.error;
if (slError && slError.hasOwnProperty("code") && slError.message && slError.message.value) {
outMsg.message = slError.message.value + " (Code: " + slError.code.toString() + ")";
} else {
outMsg.message = responseProvider.body.asString();
}
outMsg.response = responseBodyParsed;
} else {
outMsg.message = JSON.stringify(responseProvider);
}
outStatus = "error";
}
outMessages.push(outMsg);
} catch (ex) {
exceptionHandler(ex);
}
}
// main
var content = "";
if ($.request.body) {
content = $.request.body.asString();
}
if (checkPayload(content) && checkAuthorization()) {
setConnectionParams();
slLoggedIn = slLogin();
if (slLoggedIn) {
updateUDO(JSON.parse(content));
slLib.SLLogout(SESSIONID, NODEID);
}
}
$.trace.debug("DEBUG: " + JSON.stringify(myDebug));
setOutputMessage();