navidev-adt-api
Version:
API de conexión al Abap Developer Tools
300 lines (299 loc) • 14.9 kB
JavaScript
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const Result_1 = require("../shared/core/Result");
const xmlParser_1 = __importDefault(require("../shared/utilities/parser/xmlParser"));
const transportConstants_1 = require("./transportConstants");
const transportUtils_1 = __importDefault(require("./transportUtils"));
class TransportOrderApp {
constructor(connectionController, configurationApp, operationsApp) {
this.connectionController = connectionController;
this.configurationApp = configurationApp;
this.operationsApp = operationsApp;
}
/**
* Devuelve las ordenes en versiones S4 donde se busca a partir de una configuración(como los
* paramétros de la SE09/SE10) establecida(una por defecto o puede ser modificada))
* @param target
* @param urlConfiguration
* @returns
*/
getUserOrders() {
return __awaiter(this, arguments, void 0, function* (target = true, urlConfiguration) {
// Si no hay URL de configuración recupera la última
if (!urlConfiguration) {
let resultSearchConfiguration = yield this.configurationApp.searchConfigurations();
if (resultSearchConfiguration.isSuccess) {
urlConfiguration = resultSearchConfiguration.getValue().urlGetConfiguration;
}
else {
return Result_1.Result.fail(resultSearchConfiguration.getErrorValue());
}
}
const response = yield this.connectionController.request(transportConstants_1.TRANSPORT_URL.ORDER, {
method: "GET",
qs: { targets: target, configUri: urlConfiguration },
});
if (response.isSuccess) {
let orders = [];
let httpResponse = response.getValue();
let bodyParsed = xmlParser_1.default.fullParse(httpResponse.body);
if (bodyParsed["tm:root"]["tm:customizing"])
orders = orders.concat(this.processOrderType(bodyParsed["tm:root"]["tm:customizing"], bodyParsed["tm:root"]["tm:customizing"]["@_tm:category"]));
if (bodyParsed["tm:root"]["tm:workbench"])
orders = orders.concat(this.processOrderType(bodyParsed["tm:root"]["tm:workbench"], bodyParsed["tm:root"]["tm:workbench"]["@_tm:category"]));
if (bodyParsed["tm:root"]["tm:transportofcopies"])
orders = orders.concat(this.processOrderType(bodyParsed["tm:root"]["tm:transportofcopies"], bodyParsed["tm:root"]["tm:transportofcopies"]["@_tm:category"]));
return Result_1.Result.ok(orders);
}
else {
return Result_1.Result.fail(response.getErrorValue());
}
});
}
/**
* Devuelve las ordenes de un usuario en sistemas previos a S/4 HANA
* @param user
* @returns
*/
getUserOrdersWOConf(user_1) {
return __awaiter(this, arguments, void 0, function* (user, target = true) {
const response = yield this.connectionController.request(transportConstants_1.TRANSPORT_URL.ORDER, {
method: "GET",
qs: { targets: target, user: user },
});
if (response.isSuccess) {
let orders = [];
let httpResponse = response.getValue();
let bodyParsed = xmlParser_1.default.fullParse(httpResponse.body);
if (bodyParsed["tm:root"]["tm:customizing"])
orders = orders.concat(this.processOrderType(bodyParsed["tm:root"]["tm:customizing"], bodyParsed["tm:root"]["tm:customizing"]["@_tm:category"]));
if (bodyParsed["tm:root"]["tm:workbench"])
orders = orders.concat(this.processOrderType(bodyParsed["tm:root"]["tm:workbench"], bodyParsed["tm:root"]["tm:workbench"]["@_tm:category"]));
if (bodyParsed["tm:root"]["tm:transportofcopies"])
orders = orders.concat(this.processOrderType(bodyParsed["tm:root"]["tm:transportofcopies"], bodyParsed["tm:root"]["tm:transportofcopies"]["@_tm:category"]));
return Result_1.Result.ok(orders);
}
else {
return Result_1.Result.fail(response.getErrorValue());
}
});
}
/**
* Detalle de una orden/tarea. La info devuelta es la misma que la que se recupera al leer las ordenes
* de un usuario pero a nivel de orden/tarea.
* @param orderTask
* @param version
* @returns
*/
detailOrderTask(orderTask_1) {
return __awaiter(this, arguments, void 0, function* (orderTask, version = "workingArea") {
const response = yield this.readDetailOrderTask(orderTask, version);
if (response.isSuccess) {
let httpResponse = response.getValue();
let bodyParsed = xmlParser_1.default.fullParse(httpResponse.body);
let order = this.processRequest(bodyParsed["tm:root"]["tm:request"]["@_tm:target"], bodyParsed["tm:root"]["tm:request"]["@_tm:target_desc"], bodyParsed["tm:root"]["tm:request"], bodyParsed["tm:root"]["tm:request"]["@_tm:status_text"]);
// Si se pasa una tarea la info de la tarea y la orden son estructuras separadas.
// Si se informa una orden la info de la tarea esta dentro de la orden.
if (bodyParsed["tm:root"]["tm:task"])
order.tasks = this.processTask(xmlParser_1.default.xmlArray(bodyParsed["tm:root"]["tm:task"]));
return Result_1.Result.ok(order);
}
else {
return Result_1.Result.fail(response.getErrorValue());
}
});
}
/**
* Edición de una orden
* @param order
* @returns
*/
editOrder(order, values) {
return __awaiter(this, void 0, void 0, function* () {
const responseLock = yield this.operationsApp.lockOrder(order);
if (responseLock.isSuccess) {
let valuesLock = responseLock.getValue();
const responseDetail = yield this.readDetailOrderTask(order, "inactive");
if (responseDetail.isSuccess) {
let httpResponse = responseDetail.getValue();
let bodyParsed = xmlParser_1.default.fullParse(httpResponse.body, {
numberParseOptions: {
leadingZeros: false,
hex: false,
},
});
//bodyParsed["tm:root"]["tm:request"]["@_tm:desc"] = values.description;
let xml = xmlParser_1.default.buildXML(bodyParsed);
const responseEdit = yield this.connectionController.request(`${transportConstants_1.TRANSPORT_URL.ORDER}/${order}`, {
method: "PUT",
body: xml.toString(),
qs: { lockHandle: valuesLock.lockHandle },
});
if (responseEdit.isSuccess) {
yield this.operationsApp.unlockOrder(order, valuesLock.lockHandle);
return Result_1.Result.ok();
}
else {
yield this.operationsApp.unlockOrder(order, valuesLock.lockHandle);
return Result_1.Result.fail(responseEdit.getErrorValue());
}
}
else {
yield this.operationsApp.unlockOrder(order, valuesLock.lockHandle);
return Result_1.Result.fail(responseDetail.getErrorValue());
}
this.operationsApp.unlockOrder(order, valuesLock.lockHandle);
}
else {
return Result_1.Result.fail(responseLock.getErrorValue());
}
});
}
/**
* Proceso de los registros englobados en un tipo de orden: workbench,
* customizing.
* @param ordersType
* @param category
*/
processOrderType(ordersType, category) {
let tmpOrders = [];
xmlParser_1.default.xmlArray(ordersType["tm:target"]).forEach((row) => {
if (row["tm:modifiable"])
tmpOrders = tmpOrders.concat(this.processOrderStatus(row["@_tm:name"], row["@_tm:desc"], row["tm:modifiable"], category));
if (row["tm:released"])
tmpOrders = tmpOrders.concat(this.processOrderStatus(row["@_tm:name"], row["@_tm:desc"], row["tm:released"], category));
});
return tmpOrders;
}
/**
* Procesa las ordenes según su estado: modificable, liberado, etc.
* @param target Sistema destino o capa de transporte de la orden
* @param targetName
* @param ordersStatus
* @param category
*/
processOrderStatus(target, targetName, ordersStatus, category) {
return xmlParser_1.default.xmlArray(ordersStatus["tm:request"]).map((request) => {
return this.processRequest(target, targetName, request, ordersStatus["@_tm:status"], category);
});
}
/**
* Procesa la fila de una orden o tarea
* @param target
* @param targetName
* @param request
* @param categoryName
* @param statusName
* @returns
*/
processRequest(target, targetName, request, statusName, categoryName) {
var _a, _b, _c, _d;
return {
tasks: request["tm:task"]
? this.processTask(xmlParser_1.default.xmlArray(request["tm:task"]))
: [],
parent: "",
target: target,
targetName: targetName,
number: request["@_tm:number"],
owner: request["@_tm:owner"],
description: request["@_tm:desc"],
status: request["@_tm:status"],
statusName: statusName !== null && statusName !== void 0 ? statusName : request["@_tm:status_text"],
categoryTypeName: categoryName !== null && categoryName !== void 0 ? categoryName : transportConstants_1.REQUEST_FUNCTION_DESC[request["@_tm:type"]],
categoryType: (_a = request["@_tm:type"]) !== null && _a !== void 0 ? _a : "",
links: request["atom:link"]
? transportUtils_1.default.processOrderLinks(request["atom:link"])
: [],
objects: request["tm:abap_object"]
? this.processObjects(request["tm:abap_object"])
: [],
// Campos que aparecen en version S4
ctsProject: (_b = request["@_tm:cts_project"]) !== null && _b !== void 0 ? _b : "",
ctsProjectDesc: (_c = request["@_tm:cts_project_desc"]) !== null && _c !== void 0 ? _c : "",
lastChangedTimestamp: (_d = request["@_tm:lastchanged_timestamp"]) !== null && _d !== void 0 ? _d : "",
};
}
/**
* Procesa las tareas de una orden
* @param tasks
* @param category
* @returns
*/
processTask(requestTasks) {
return requestTasks.map((request) => {
var _a, _b, _c, _d;
return {
target: "",
targetName: "",
number: request["@_tm:number"],
owner: request["@_tm:owner"],
description: request["@_tm:desc"],
status: request["@_tm:status"],
parent: request["@_tm:parent"],
statusName: transportConstants_1.REQUEST_STATUS_DESC[request["@_tm:status"]],
categoryTypeName: (_a = request["@_tm:type"]) !== null && _a !== void 0 ? _a : "",
categoryType: "",
links: request["atom:link"]
? transportUtils_1.default.processOrderLinks(request["atom:link"])
: [],
objects: request["tm:abap_object"]
? this.processObjects(request["tm:abap_object"])
: [],
// Campos que aparecen en version S4
ctsProject: (_b = request["@_tm:cts_project"]) !== null && _b !== void 0 ? _b : "",
ctsProjectDesc: (_c = request["@_tm:cts_project_desc"]) !== null && _c !== void 0 ? _c : "",
lastChangedTimestamp: (_d = request["@_tm:lastchanged_timestamp"]) !== null && _d !== void 0 ? _d : "",
};
});
}
/**
* Proceso de los enlaces asociados a la orden/tarea
* @param ordersLinks
* @returns
*/
processOrderLinks(ordersLinks) {
return xmlParser_1.default.xmlArray(ordersLinks).map((row) => {
return { title: row["@_href"], href: row["@_title"] };
});
}
processObjects(objects) {
return xmlParser_1.default.xmlArray(objects).map((row) => {
var _a, _b, _c, _d;
return {
name: row["@_tm:name"],
type: row["@_tm:type"],
objInfo: row["@_tm:obj_info"],
dummyUri: row["@_tm:dummy_uri"],
wbtype: row["@_tm:wbtype"],
pgmid: row["@_tm:pgmid"],
// Campos que aparecen en version S4
imgActivity: (_a = row["@_tm:img_activity"]) !== null && _a !== void 0 ? _a : "",
lockStatus: (_b = row["@_tm:lock_status"]) !== null && _b !== void 0 ? _b : "",
objDesc: (_c = row["@_tm:obj_desc"]) !== null && _c !== void 0 ? _c : "",
position: (_d = row["@_tm:position"]) !== null && _d !== void 0 ? _d : 0,
};
});
}
readDetailOrderTask(orderTask_1) {
return __awaiter(this, arguments, void 0, function* (orderTask, version = "workingArea") {
return this.connectionController.request(`${transportConstants_1.TRANSPORT_URL.ORDER}/${orderTask}`, {
method: "GET",
qs: { version: version },
});
});
}
}
exports.default = TransportOrderApp;