dynamicsmobile
Version:
Allows development of off-line mobile and web business apps over the Dynamics Mobile platform. More info on https://www.dynamicsmobile.com
414 lines • 21.5 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LegacyLiveLinkQueryDmsAgent = void 0;
const tslib_1 = require("tslib");
const dms_root_container_1 = require("../../ioc/dms-root-container");
const configuration_service_1 = require("../configuration-service");
const userinterface_service_1 = require("../userinterface-service");
const js_base64_1 = require("js-base64");
const livelink_query_apparea_1 = require("./livelink-query-apparea");
const dms_api_wrapper_1 = require("../../platform-web/dms-api-wrapper");
class LegacyLiveLinkQueryDmsAgent extends livelink_query_apparea_1.LiveLinkQueryAppArea {
executeCommand(parameters) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const cfg = dms_root_container_1.RootDIContainer.inject(configuration_service_1.ConfigurationService);
let liveLinkUrl = yield cfg.getSetting('liveLinkUrl');
const dmsApiKey = yield cfg.getSetting('dmsApiKey');
if (liveLinkUrl) {
const user = yield (dms_root_container_1.RootDIContainer.inject(userinterface_service_1.UserInterfaceService)).getUsername();
//direct livelink is enabled , e.g. skipping the cloud and directly hitting DMS Agent
const appCode = js_base64_1.Base64.encode(this._appCode ? this._appCode : '');
const company = js_base64_1.Base64.encode(this._company ? this._company : '');
if (liveLinkUrl[liveLinkUrl.length - 1] == '/')
liveLinkUrl = liveLinkUrl.substr(0, liveLinkUrl.length - 1);
let url = `${liveLinkUrl}/m/m3.ashx`;
const data = {
cmd: 'llexeccmd',
cmdid: parameters.commandId,
mod: appCode,
cmp: company
};
const props = Object.getOwnPropertyNames(data);
const queryStringParams = [];
props.forEach(pName => {
if (data[pName] != null && data[pName] != undefined && data[pName] != '')
queryStringParams.push(`${pName}=${data[pName]}`);
});
if (queryStringParams.length > 0) {
url += '?' + queryStringParams.join('&');
}
// let attrXml = '';
// const attributeNames = Object.getOwnPropertyNames(attributes);
// attributeNames.forEach(a=>{
// attrXml+=`<${a}>${attributes[a]}</${a}>`;
// });
let attrXml = '';
const attributeNames = Object.getOwnPropertyNames(parameters.commandArguments);
attributeNames.forEach(a => {
if (Array.isArray(parameters.commandArguments[a])) {
attrXml += `<${a}>`;
parameters.commandArguments[a].forEach(attrI => {
if (typeof attrI === 'object') {
const attributeNamesObj = Object.getOwnPropertyNames(attrI);
attrXml += `<r>`;
attributeNamesObj.forEach(aObj => {
attrXml += `<${aObj}>${attrI[aObj]}</${aObj}>`;
});
attrXml += `</r>`;
}
else {
const attributeNamesNotObj = Object.getOwnPropertyNames(attrI);
attributeNamesNotObj.forEach(aNotObj => {
attrXml += `<${aNotObj}>${attrI[aNotObj]}</${aNotObj}>`;
});
}
});
attrXml += `</${a}>`;
}
else {
attrXml += `<${a}>${parameters.commandArguments[a]}</${a}>`;
}
});
const options = {
contentType: 'application/xml',
headers: {
'nm-username': user,
'nm-security': dmsApiKey,
'nm-agentid': 'idr.' + user
},
method: "POST",
dataType: 'json',
data: attrXml,
url: url,
timeout: dms_api_wrapper_1.DmsAPIWrapper.globalAjaxTimeoutMiliseconds
};
try {
//console.log(`dms-sdk::ll-agnt-cmd ${options.url} ${options.method} ${options.timeout} ${user} ${dmsApiKey}`);
var response = yield this.dms.app.request.promise(options);
//console.log(`dms-sdk::ll-agnt-cmd completed`);
if (response) {
const d = response.data ? response.data : response;
let v;
if (typeof d === "string")
v = JSON.parse(d);
else
v = d;
v = v.response ? v.response : v.value;
return v;
}
else {
throw new Error(`External LiveLink Service ${this._serviceName} did not return correct response`);
}
}
catch (err) {
this.processApiError(err, true);
}
}
});
}
executeSelect() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
yield this.checkNetworkStatus();
const cfg = dms_root_container_1.RootDIContainer.inject(configuration_service_1.ConfigurationService);
let liveLinkUrl = yield cfg.getSetting('liveLinkUrl');
const dmsApiKey = yield cfg.getSetting('dmsApiKey');
if (liveLinkUrl) {
const user = yield (dms_root_container_1.RootDIContainer.inject(userinterface_service_1.UserInterfaceService)).getUsername();
//direct livelink is enabled , e.g. skipping the cloud and directly hitting DMS Agent
const filter = js_base64_1.Base64.encode(this._filter ? this._filter : '');
const sort = js_base64_1.Base64.encode(this._sort ? this._sort : '');
const appCode = js_base64_1.Base64.encode(this._appCode ? this._appCode : '');
const company = js_base64_1.Base64.encode(this._company ? this._company : '');
const entityName = js_base64_1.Base64.encode(this._entityName);
const maxRecords = this._max ? js_base64_1.Base64.encode(this._max) : js_base64_1.Base64.encode('100');
if (liveLinkUrl[liveLinkUrl.length - 1] == '/')
liveLinkUrl = liveLinkUrl.substr(0, liveLinkUrl.length - 1);
let url = `${liveLinkUrl}/m/m3.ashx`;
const data = {
cmd: 'llfetchent',
wh: filter,
mod: appCode,
cmp: company,
sort: sort,
params: entityName,
top: maxRecords
};
const props = Object.getOwnPropertyNames(data);
const queryStringParams = [];
props.forEach(pName => {
if (data[pName] != null && data[pName] != undefined && data[pName] != '')
queryStringParams.push(`${pName}=${data[pName]}`);
});
if (queryStringParams.length > 0) {
url += '?' + queryStringParams.join('&');
}
const options = {
contentType: 'application/json',
headers: {
'nm-username': user,
'nm-security': dmsApiKey,
'nm-agentid': 'idr.' + user
},
method: "GET",
dataType: 'json',
url: url,
timeout: dms_api_wrapper_1.DmsAPIWrapper.globalAjaxTimeoutMiliseconds
};
//console.log(`dms-sdk::ll-agnt-sel ${options.url} ${options.method} ${options.timeout} ${user} ${dmsApiKey}`);
try {
var response = yield this.dms.app.request.promise(options);
//console.log(`dms-sdk::ll-agnt-sel completed`);
if (response) {
const d = response.data ? response.data : response;
let v;
if (typeof d === "string")
v = JSON.parse(d);
else
v = d;
v = v.response ? v.response : (v.value ? v.value : v);
v.forEach(element => {
element.members = this._members;
element.boName = this._entityName;
element.boTableName = this._entityTable;
element.appCode = this._appCode;
});
return v;
}
else {
throw new Error(`External LiveLink Service ${this._serviceName} did not return correct response`);
}
}
catch (err) {
this.processApiError(err, true);
}
}
});
}
executeCount() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
yield this.checkNetworkStatus();
const cfg = dms_root_container_1.RootDIContainer.inject(configuration_service_1.ConfigurationService);
let liveLinkUrl = yield cfg.getSetting('liveLinkUrl');
const dmsApiKey = yield cfg.getSetting('dmsApiKey');
if (liveLinkUrl) {
const user = yield (dms_root_container_1.RootDIContainer.inject(userinterface_service_1.UserInterfaceService)).getUsername();
//direct livelink is enabled , e.g. skipping the cloud and directly hitting DMS Agent
const filter = js_base64_1.Base64.encode(this._filter ? this._filter : '');
const sort = js_base64_1.Base64.encode(this._sort ? this._sort : '');
const appCode = js_base64_1.Base64.encode(this._appCode ? this._appCode : '');
const company = js_base64_1.Base64.encode(this._company ? this._company : '');
const entityName = js_base64_1.Base64.encode(this._entityName);
if (liveLinkUrl[liveLinkUrl.length - 1] == '/')
liveLinkUrl = liveLinkUrl.substr(0, liveLinkUrl.length - 1);
let url = `${liveLinkUrl}/m/m3.ashx`;
const data = {
cmd: 'llfetchent',
wh: filter,
mod: appCode,
cmp: company,
sort: sort,
params: entityName
};
const props = Object.getOwnPropertyNames(data);
const queryStringParams = [];
props.forEach(pName => {
if (data[pName] != null && data[pName] != undefined && data[pName] != '')
queryStringParams.push(`${pName}=${data[pName]}`);
});
if (queryStringParams.length > 0) {
url += '?' + queryStringParams.join('&');
}
const options = {
contentType: 'application/json',
headers: {
'nm-username': user,
'nm-security': dmsApiKey,
'nm-agentid': 'idr.' + user
},
method: "GET",
dataType: 'json',
url: url,
timeout: dms_api_wrapper_1.DmsAPIWrapper.globalAjaxTimeoutMiliseconds
};
try {
//console.log(`dms-sdk::ll-agnt-cnt ${options.url} ${options.method} ${options.timeout} ${user} ${dmsApiKey}`);
var response = yield this.dms.app.request.promise(options);
//console.log(`dms-sdk::ll-agnt-cnt completed`);
if (response) {
const d = response.data ? response.data : response;
let v;
if (typeof d === "string")
v = JSON.parse(d);
else
v = d;
v = v.response ? v.response : v.value;
return Array.isArray(v) ? v.length : 0;
}
else {
throw new Error(`External LiveLink Service ${this._serviceName} did not return correct response`);
}
}
catch (err) {
this.processApiError(err, true);
}
}
});
}
executeCreate(entity) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
yield this.checkNetworkStatus();
const cfg = dms_root_container_1.RootDIContainer.inject(configuration_service_1.ConfigurationService);
let liveLinkUrl = yield cfg.getSetting('liveLinkUrl');
const dmsApiKey = yield cfg.getSetting('dmsApiKey');
const user = yield (dms_root_container_1.RootDIContainer.inject(userinterface_service_1.UserInterfaceService)).getUsername();
if (liveLinkUrl) {
//direct livelink is enabled , e.g. skipping the cloud and directly hitting DMS Agent
const appCode = js_base64_1.Base64.encode(this._appCode ? this._appCode : '');
const company = js_base64_1.Base64.encode(this._company ? this._company : '');
const entityName = js_base64_1.Base64.encode(this._entityName);
if (liveLinkUrl[liveLinkUrl.length - 1] == '/')
liveLinkUrl = liveLinkUrl.substr(0, liveLinkUrl.length - 1);
let url = `${liveLinkUrl}/m/m3.ashx`;
const data = {
cmd: 'llcreateent',
mod: appCode,
cmp: company,
params: entityName
};
const props = Object.getOwnPropertyNames(data);
const queryStringParams = [];
props.forEach(pName => {
if (data[pName] != null && data[pName] != undefined && data[pName] != '')
queryStringParams.push(`${pName}=${data[pName]}`);
});
var _ent = this.prepareBusinessObjectForTransmission(entity);
if (queryStringParams.length > 0) {
url += '?' + queryStringParams.join('&');
}
const options = {
contentType: 'application/json',
headers: {
'nm-username': user,
'nm-security': dmsApiKey,
'nm-agentid': 'idr.' + user
},
method: "POST",
url: url,
data: JSON.stringify(_ent),
timeout: dms_api_wrapper_1.DmsAPIWrapper.globalAjaxTimeoutMiliseconds
};
try {
//console.log(`dms-sdk::ll-agnt-cr ${options.url} ${options.method} ${options.timeout} ${user} ${dmsApiKey}`);
var response = yield this.dms.app.request.promise(options);
//console.log(`dms-sdk::ll-agnt-cr completed`);
if (response) {
const d = response.data ? response.data : response;
let v;
if (typeof d === "string")
v = JSON.parse(d);
else
v = d;
v = v.response ? v.response : v.value;
v.forEach(element => {
element.members = this._members;
element.boName = this._entityName;
element.boTableName = this._entityTable;
element.appCode = this._appCode;
});
return v;
}
else {
throw new Error(`External LiveLink Service ${this._serviceName} did not return correct response`);
}
}
catch (err) {
this.processApiError(err, true);
}
}
});
}
executeUpdate(entity, pkValues, pkFields) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
yield this.checkNetworkStatus();
const cfg = dms_root_container_1.RootDIContainer.inject(configuration_service_1.ConfigurationService);
let liveLinkUrl = yield cfg.getSetting('liveLinkUrl');
const dmsApiKey = yield cfg.getSetting('dmsApiKey');
const user = yield (dms_root_container_1.RootDIContainer.inject(userinterface_service_1.UserInterfaceService)).getUsername();
if (liveLinkUrl) {
//direct livelink is enabled , e.g. skipping the cloud and directly hitting DMS Agent
const appCode = js_base64_1.Base64.encode(this._appCode ? this._appCode : '');
const company = js_base64_1.Base64.encode(this._company ? this._company : '');
const entityName = js_base64_1.Base64.encode(this._entityName);
if (liveLinkUrl[liveLinkUrl.length - 1] == '/')
liveLinkUrl = liveLinkUrl.substr(0, liveLinkUrl.length - 1);
let url = `${liveLinkUrl}/m/m3.ashx`;
const data = {
cmd: 'llupdateen',
mod: appCode,
cmp: company,
params: entityName
};
const props = Object.getOwnPropertyNames(data);
const queryStringParams = [];
props.forEach(pName => {
if (data[pName] != null && data[pName] != undefined && data[pName] != '')
queryStringParams.push(`${pName}=${data[pName]}`);
});
var _ent = this.prepareBusinessObjectForTransmission(entity);
if (pkValues) {
_ent[0]['$pk'] = Array.isArray(pkValues) ? pkValues.join(',') : pkValues.toString();
}
if (queryStringParams.length > 0) {
url += '?' + queryStringParams.join('&');
}
const options = {
contentType: 'application/json',
headers: {
'nm-username': user,
'nm-security': dmsApiKey,
'nm-agentid': 'idr.' + user
},
method: "POST",
url: url,
data: JSON.stringify(_ent),
timeout: dms_api_wrapper_1.DmsAPIWrapper.globalAjaxTimeoutMiliseconds
};
try {
//console.log(`dms-sdk::ll-agnt-upd ${options.url} ${options.method} ${options.timeout} ${user} ${dmsApiKey}`);
var response = yield this.dms.app.request.promise(options);
//console.log(`dms-sdk::ll-agnt-upd completed`);
if (response) {
const d = response.data ? response.data : response;
let v;
if (typeof d === "string")
v = JSON.parse(d);
else
v = d;
v = v.response ? v.response : v.value;
v.forEach(element => {
element.members = this._members;
element.boName = this._entityName;
element.boTableName = this._entityTable;
element.appCode = this._appCode;
});
return v;
}
else {
throw new Error(`External LiveLink Service ${this._serviceName} did not return correct response`);
}
}
catch (err) {
this.processApiError(err, true);
}
}
});
}
executeDelete(entity, pkValues, pkFields) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
console.log(`dms-sdk::ll-agnt ERROR delete is not supported`);
throw new Error('LiveLinkQuery.executeDelete for dmsagent is not supported');
});
}
}
exports.LegacyLiveLinkQueryDmsAgent = LegacyLiveLinkQueryDmsAgent;
//# sourceMappingURL=livelink-query-legacy-dmsagent.js.map