UNPKG

navidev-adt-api

Version:

API de conexión al Abap Developer Tools

137 lines (136 loc) 8.77 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 Result_1 = require("../shared/core/Result"); const xmlParser_1 = __importDefault(require("../shared/utilities/parser/xmlParser")); const businessServiceConstants_1 = require("./businessServiceConstants"); class AdtBusinessServicesApp { constructor(connectionController) { this.connectionController = connectionController; } /** * Obtiene la información del binding de un servicio * @param service * @returns */ getServiceBinding(service) { return __awaiter(this, void 0, void 0, function* () { const response = yield this.connectionController.request(`${businessServiceConstants_1.BUSINESS_SERVICES_URL.BINDING}${encodeURIComponent(service)}`, { method: "GET", }); if (response.isSuccess) { let httpResponse = response.getValue(); let bodyParsed = xmlParser_1.default.fullParse(httpResponse.body); let bindingInfo = { name: bodyParsed["srvb:serviceBinding"]["@_adtcore:name"], createdAt: new Date(bodyParsed["srvb:serviceBinding"]["@_adtcore:createdAt"]), createdBy: bodyParsed["srvb:serviceBinding"]["@_adtcore:createdBy"], changedAt: new Date(bodyParsed["srvb:serviceBinding"]["@_adtcore:changedAt"]), changedBy: bodyParsed["srvb:serviceBinding"]["@_adtcore:changedBy"], description: bodyParsed["srvb:serviceBinding"]["@_adtcore:description"], language: bodyParsed["srvb:serviceBinding"]["@_adtcore:language"], type: bodyParsed["srvb:serviceBinding"]["@_adtcore:type"], version: bodyParsed["srvb:serviceBinding"]["@_adtcore:version"], bindingCreated: bodyParsed["srvb:serviceBinding"]["@_srvb:bindingCreated"], published: bodyParsed["srvb:serviceBinding"]["@_srvb:published"], packageRef: { name: bodyParsed["srvb:serviceBinding"]["adtcore:packageRef"]["@_adtcore:name"], description: bodyParsed["srvb:serviceBinding"]["adtcore:packageRef"]["@_adtcore:description"], type: bodyParsed["srvb:serviceBinding"]["adtcore:packageRef"]["@_adtcore:type"], }, versionOdata: bodyParsed["srvb:serviceBinding"]["srvb:binding"]["@_srvb:version"], serviceName: bodyParsed["srvb:serviceBinding"]["srvb:services"]["@_srvb:name"], serviceVersion: bodyParsed["srvb:serviceBinding"]["srvb:services"]["srvb:content"]["@_srvb:version"], serviceDefinitionName: bodyParsed["srvb:serviceBinding"]["srvb:services"]["srvb:content"]["srvb:serviceDefinition"]["@_adtcore:name"], annotationUrl: "", serviceUrl: "", }; // Sacamos la URL para obtener las URL de como llamar al servicio. let links = xmlParser_1.default.xmlArray(bodyParsed["srvb:serviceBinding"]["atom:link"]); let link = links.find((row) => row["@_title"] == `ODATA${bindingInfo.versionOdata}`); if (link) { const responseLink = yield this.connectionController.request(`${link["@_href"]}?servicename=${bindingInfo.serviceName}&serviceversion=${bindingInfo.serviceVersion}&srvdname=${bindingInfo.serviceDefinitionName}`, { method: "GET", }); if (responseLink.isSuccess) { let httpResponse = responseLink.getValue(); let bodyParsed = xmlParser_1.default.fullParse(httpResponse.body); if (bindingInfo.versionOdata == "V2") { bindingInfo.annotationUrl = bodyParsed["odatav2:serviceList"]["odatav2:services"]["@_odatav2:annotationUrl"]; // La URL de anotaciones o vocabulary no funciona tal cual. Hay que hacer un reemplazo en la URL para que funcioe bien. // Supongo que sap a nivel interno sabrá como hacerlo bien pero yo tengo que hacer este reemplazo. bindingInfo.annotationUrl = bindingInfo.annotationUrl.replace("/sap/opu/odata/sap/IWFND/CATALOGSERVICE", "/sap/opu/odata/IWFND/CATALOGSERVICE" + ";v=2"); bindingInfo.serviceUrl = bodyParsed["odatav2:serviceList"]["odatav2:services"]["@_odatav2:serviceUrl"]; } else { bindingInfo.annotationUrl = bodyParsed["odatav4:serviceGroup"]["odatav4:services"]["@_odatav4:annotationUrl"]; bindingInfo.serviceUrl = bodyParsed["odatav4:serviceGroup"]["odatav4:services"]["@_odatav4:serviceUrl"]; ("/sap/opu/odata4/sap/zui_booking_o4/srvd/sap/zui_booking/0001/"); const regex = new RegExp("srvd/sap/" + bindingInfo.serviceDefinitionName.toLowerCase(), "g"); // El servicio common es el que devuelve las entidades asociadas al servicio principal, solo en el caso de los V4 bindingInfo.serviceUrlCommon = bindingInfo.serviceUrl.replace(regex, businessServiceConstants_1.SERVICE_DEFINITION_COMMON); } } else { return Result_1.Result.fail(response.getErrorValue()); } } return Result_1.Result.ok(bindingInfo); } else { return Result_1.Result.fail(response.getErrorValue()); } }); } /** * Obtiene la información de la definición de un servicio * @param service * @returns */ getServiceDefinition(service) { return __awaiter(this, void 0, void 0, function* () { const response = yield this.connectionController.request(`${businessServiceConstants_1.BUSINESS_SERVICES_URL.DEFINITION}${encodeURIComponent(service)}`, { method: "GET", }); if (response.isSuccess) { let httpResponse = response.getValue(); let bodyParsed = xmlParser_1.default.fullParse(httpResponse.body); return Result_1.Result.ok({ name: bodyParsed["srvd:srvdSource"]["@_adtcore:name"], createdAt: new Date(bodyParsed["srvd:srvdSource"]["@_adtcore:createdAt"]), createdBy: bodyParsed["srvd:srvdSource"]["@_adtcore:createdBy"], changedAt: new Date(bodyParsed["srvd:srvdSource"]["@_adtcore:createdAt"]), changedBy: bodyParsed["srvd:srvdSource"]["@_adtcore:changedBy"], description: bodyParsed["srvd:srvdSource"]["@_adtcore:description"], language: bodyParsed["srvd:srvdSource"]["@_adtcore:language"], type: bodyParsed["srvd:srvdSource"]["@_adtcore:type"], version: bodyParsed["srvd:srvdSource"]["@_adtcore:version"], packageRef: { name: bodyParsed["srvd:srvdSource"]["adtcore:packageRef"]["@_adtcore:name"], description: bodyParsed["srvd:srvdSource"]["adtcore:packageRef"]["@_adtcore:description"], type: bodyParsed["srvd:srvdSource"]["adtcore:packageRef"]["@_adtcore:type"], }, }); } else { return Result_1.Result.fail(response.getErrorValue()); } }); } } exports.default = AdtBusinessServicesApp;