navidev-abap-gw-api
Version:
API para la extracción de datos de servicios SAP GW
97 lines (96 loc) • 3.94 kB
JavaScript
;
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 adtExceptionController_1 = __importDefault(require("navidev-adt-api/dist/shared/exceptions/adtExceptionController"));
const Result_1 = require("navidev-adt-api/dist/shared/core/Result");
const odataUtils_1 = __importDefault(require("../shared/utilities/general/odataUtils"));
class MetadataApp {
constructor(connectionController, serviceBindingInfo, options) {
this.adtExceptionController = new adtExceptionController_1.default();
this.connectionController = connectionController;
this.serviceBindingInfo = serviceBindingInfo;
this.oDataUtils = new odataUtils_1.default();
this.options = options !== null && options !== void 0 ? options : {
ignoreAnnotVocab: false,
ignoreFields: false,
ignoreValueHelp: false,
};
this.metadataContent = {
namespace: "",
alias: "",
entities: [],
serviceUrl: this.serviceBindingInfo.serviceUrl,
};
this.entityTypes = [];
}
getMetadataCommon() {
return __awaiter(this, void 0, void 0, function* () {
return Result_1.Result.fail(this.adtExceptionController.fromText(`method not implemented`, 400));
});
}
getMetadataInfo() {
return __awaiter(this, void 0, void 0, function* () {
return Result_1.Result.fail(this.adtExceptionController.fromText(`method not implemented`, 400));
});
}
/**
* Construye la URL para obtener el metadata
* @param serviceName
* @param version
* @returns
*/
buildUrlMetadata(url) {
if (url.includes("$metadata"))
return url;
return `${url}${url.endsWith("/") ? "" : "/"}$metadata`;
}
/**
* Lectura del metadata de SAP
*/
loadMetadata(url) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.connectionController.request(this.buildUrlMetadata(url), {
method: "GET",
});
if (response.isSuccess) {
let httpResponse = response.getValue();
return Result_1.Result.ok(httpResponse.body);
}
else {
return Result_1.Result.fail(response.getErrorValue());
}
});
}
/**
* Obtiene el namespace del metadata necesario
* @param bodyParsed
* @returns
*/
extractNamespace(bodyParsed) {
return bodyParsed["edmx:Edmx"]["edmx:DataServices"].Schema["@_Namespace"];
}
/**
* Extrae el nombre de la entityType para buscar en el nodo de entityType que es donde están los campos
* @param namespace
* @param entityName
* @returns
*/
extractEntityName(namespace, entityName) {
const prefijo = `${namespace}.`;
const regex = new RegExp(`${prefijo}(.*)`);
let namespaceMatch = entityName.match(regex);
return namespaceMatch ? namespaceMatch[1] : entityName;
}
}
exports.default = MetadataApp;