navidev-adt-api
Version:
API de conexión al Abap Developer Tools
90 lines (89 loc) • 4.91 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 Result_1 = require("../shared/core/Result");
const xmlParser_1 = __importDefault(require("../shared/utilities/parser/xmlParser"));
const abapObjectConstants_1 = require("./abapObjectConstants");
const extractData_1 = __importDefault(require("./extractData"));
class AbapObjectCheckRunApp {
constructor(connectionController) {
this.connectionController = connectionController;
}
/**
* Valida la sintaxis de un objeto
* @param objectUri URL del objeto
* @param artifacts Objetos/Contenido a validar su sintaxis
* @returns Resultado de la validación
*/
checkObject(objectUri, artifacts) {
return __awaiter(this, void 0, void 0, function* () {
let body = this.buildBody(objectUri, artifacts);
const response = yield this.connectionController.request(abapObjectConstants_1.OBJECT_URL.CHECK_RUN, {
method: "POST",
body: body,
});
if (response.isSuccess) {
let httpResponse = response.getValue();
const bodyParse = xmlParser_1.default.fullParse(httpResponse.body);
let objectCheck = {
messagesList: [],
status: bodyParse["chkrun:checkRunReports"]["chkrun:checkReport"]["@_chkrun:status"],
statusText: bodyParse["chkrun:checkRunReports"]["chkrun:checkReport"]["@_chkrun:statusText"],
triggeringUri: bodyParse["chkrun:checkRunReports"]["chkrun:checkReport"]["@_chkrun:triggeringUri"],
};
let messagesList = xmlParser_1.default.nodeArray(bodyParse["chkrun:checkRunReports"]["chkrun:checkReport"]["chkrun:checkMessageList"]);
messagesList.forEach((rowMessage) => {
let checkMessages = xmlParser_1.default.nodeArray(rowMessage["chkrun:checkMessage"]);
checkMessages.forEach((rowCheckMessage) => {
let sourceUriPosition = extractData_1.default.extractSourcePositionBlockElement(rowCheckMessage["@_chkrun:uri"].replace(objectUri, ""));
let message = {
shortText: rowCheckMessage["@_chkrun:shortText"],
type: rowCheckMessage["@_chkrun:type"],
sourceUri: sourceUriPosition.source,
pos: sourceUriPosition.start,
quickFix: false,
};
if (xmlParser_1.default.nodeArray(rowCheckMessage["atom:link"]).findIndex((link) => link["@_rel"].includes("quickfixes")) != -1)
message.quickFix = true;
objectCheck.messagesList.push(message);
});
});
return Result_1.Result.ok(objectCheck);
}
else {
return Result_1.Result.fail(response.getErrorValue());
}
});
}
/**
* Construye el body del servicio
* @param object2Validate
*/
buildBody(objectUri, artifacts) {
let body = `<?xml version="1.0" encoding="UTF-8"?><chkrun:checkObjectList xmlns:chkrun="http://www.sap.com/adt/checkrun" xmlns:adtcore="http://www.sap.com/adt/core">`;
if (artifacts == undefined) {
body += `<chkrun:checkObject adtcore:uri="${objectUri}" chkrun:version="active"/>`;
}
else {
body += `<chkrun:checkObject adtcore:uri="${objectUri}" chkrun:version="active"><chkrun:artifacts>`;
artifacts.forEach((row) => {
body += `<chkrun:artifact chkrun:contentType="text/plain; charset=utf-8" chkrun:uri="${objectUri}/${row.sourceUri}"><chkrun:content>${row.artifactContent}</chkrun:content></chkrun:artifact>`;
});
body += `</chkrun:artifacts></chkrun:checkObject>`;
}
body += `</chkrun:checkObjectList>`;
return body;
}
}
exports.default = AbapObjectCheckRunApp;