UNPKG

navidev-adt-api

Version:

API de conexión al Abap Developer Tools

77 lines (76 loc) 4.06 kB
"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 atcApp_1 = __importDefault(require("../adtAtc/atcApp")); const Result_1 = require("../shared/core/Result"); const adtExceptionController_1 = __importDefault(require("../shared/exceptions/adtExceptionController")); const xmlParser_1 = __importDefault(require("../shared/utilities/parser/xmlParser")); const transportConstants_1 = require("./transportConstants"); class TransportReleaseApp { constructor(connectionController) { this.connectionController = connectionController; this.atcController = new atcApp_1.default(this.connectionController); this.exceptionController = new adtExceptionController_1.default(); } /** * Liberación de una orden o tarea * @param order */ releaseOrder(order) { return __awaiter(this, void 0, void 0, function* () { let responseWorkList = yield this.atcController.getWorklist(); if (responseWorkList.isFailure) return Result_1.Result.fail(responseWorkList.getErrorValue()); const response = yield this.connectionController.request(`${transportConstants_1.TRANSPORT_URL.RELEASE_NEW.replace("{ORDER}", order)}`, { method: "POST", qs: { worklistId: responseWorkList.getValue() }, }); if (response.isSuccess) { let httpResponse = response.getValue(); let bodyParsed = xmlParser_1.default.fullParse(httpResponse.body); if (bodyParsed["tm:root"]["tm:releasereports"]["chkrun:checkReport"]["@_chkrun:status"] == "abortrelapifail") { let messages = this.extractMessageList(bodyParsed); return Result_1.Result.fail(this.exceptionController.fromText(messages.length > 0 ? messages[0].shortText : `Error to liberate the order/task ${order}`, 400)); } else { return Result_1.Result.ok({ number: bodyParsed["tm:root"]["@_tm:number"], status: bodyParsed["tm:root"]["tm:releasereports"]["chkrun:checkReport"]["@_chkrun:status"], statusText: bodyParsed["tm:root"]["tm:releasereports"]["chkrun:checkReport"]["@_chkrun:statusText"], //messages: this.extractMessageList(bodyParsed), }); } } else { return Result_1.Result.fail(responseWorkList.getErrorValue()); } }); } extractMessageList(bodyParsed) { if (bodyParsed["tm:root"]["tm:releasereports"]["chkrun:checkReport"]["chkrun:checkMessageList"]) { return xmlParser_1.default.xmlArray(bodyParsed["tm:root"]["tm:releasereports"]["chkrun:checkReport"]["chkrun:checkMessageList"]).map((row) => { return { shortText: row["chkrun:checkMessage"]["@_chkrun:shortText"], type: row["chkrun:checkMessage"]["@_chkrun:type"], }; }); } else { return []; } } } exports.default = TransportReleaseApp;