navidev-adt-api
Version:
API de conexión al Abap Developer Tools
145 lines (144 loc) • 6.7 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");
class AbapObjectElementInfo {
constructor(connectionController) {
this.connectionController = connectionController;
}
/**
* Lectura del elemento info
* @param objectUri url para obtener la información del elemento
* @param line Línea del codigo fuente donde esta el objeto
* @param pos Posición de la línea donde se obtendrá la info del elemento.
* @param content Contenido del codigo
* @returns
*/
readElementInfo(objectUri, line, pos, content) {
return __awaiter(this, void 0, void 0, function* () {
let contentDecode = atob(content);
const response = yield this.connectionController.request(`${abapObjectConstants_1.OBJECT_URL.ELEMENT_INFO}`, {
method: "POST",
qs: { uri: `${objectUri}#start=${line},${pos}` },
body: contentDecode,
});
if (response.isSuccess) {
let httpResponse = response.getValue();
const bodyParse = xmlParser_1.default.fullParse(httpResponse.body);
let objectInfo = {
name: bodyParse["abapsource:elementInfo"]["@_adtcore:name"],
type: bodyParse["abapsource:elementInfo"]["@_adtcore:type"],
documentation: [],
};
objectInfo.properties = this.fillProperties(bodyParse["abapsource:elementInfo"]);
objectInfo.documentation = this.fillDocumentation(bodyParse["abapsource:elementInfo"]);
objectInfo.elementInfoDetail = this.fillDetailElementInfo(bodyParse);
return Result_1.Result.ok(objectInfo);
}
else {
return Result_1.Result.fail(response.getErrorValue());
}
});
}
/**
* Rellena el detalle del element info seleccionado
* @param bodyParse Body del servicio parseado
* @returns
*/
fillDetailElementInfo(bodyParse) {
let elementInfoDetails = [];
let subElementInfo = xmlParser_1.default.nodeArray(bodyParse["abapsource:elementInfo"]["abapsource:elementInfo"]);
subElementInfo.forEach((row) => {
let elementInfoDetail = {
name: row["@_adtcore:name"],
type: row["@_adtcore:type"] ? row["@_adtcore:type"] : "",
documentation: [],
};
elementInfoDetail.properties = this.fillProperties(row);
elementInfoDetails.push(elementInfoDetail);
elementInfoDetail.documentation = this.fillDocumentation(row);
});
return elementInfoDetails;
}
/**
* Rellena la documentación
* @param bodyParse Respuesta del servicio ya parseado
*/
fillDocumentation(bodyParse) {
let elementDocs = [];
if (bodyParse["abapsource:documentation"]) {
let docs = xmlParser_1.default.nodeArray(bodyParse["abapsource:documentation"]);
docs.forEach((row) => {
elementDocs.push({
text: row["#text"],
type: row["@_abapsource:type"],
rel: row["@_abapsource:rel"],
});
});
}
/*documentation: row["abapsource:documentation"]["#text"]
? row["abapsource:documentation"]["#text"]
: "",
documentation_type: row["abapsource:documentation"]
? row["abapsource:documentation"]["@_abapsource:type"]
: "",*/
return elementDocs;
}
/**
* Rellena las propiedades del objeto de la info del elemento
* @param bodyParse Respuesta del servicio ya parseado
* @returns Propiedades
*/
fillProperties(bodyParse) {
let responseProperties = {
kind: "",
visibility: "",
instantation: "",
paramType: "",
byValue: false,
optional: false,
preferrred: false,
level: "",
};
if (bodyParse["abapsource:properties"]) {
let propertiesArray = xmlParser_1.default.nodeArray(bodyParse["abapsource:properties"]["abapsource:entry"]);
propertiesArray.forEach((row) => {
if (row["#text"]) {
if (row["@_abapsource:key"] == "visibility")
responseProperties.visibility = row["#text"];
if (row["@_abapsource:key"] == "level")
responseProperties.level = row["#text"];
if (row["@_abapsource:key"] == "kind")
responseProperties.kind = row["#text"];
if (row["@_abapsource:key"] == "abapType")
responseProperties.kind = row["#text"];
if (row["@_abapsource:key"] == "instantation")
responseProperties.instantation = row["#text"];
if (row["@_abapsource:key"] == "paramType")
responseProperties.paramType = row["#text"];
if (row["@_abapsource:key"] == "optional")
responseProperties.optional = row["#text"];
if (row["@_abapsource:key"] == "byValue")
responseProperties.byValue = row["#text"];
if (row["@_abapsource:key"] == "preferred")
responseProperties.preferrred = row["#text"];
}
});
}
return responseProperties;
}
}
exports.default = AbapObjectElementInfo;