@ui5/task-adaptation
Version:
Custom task for ui5-builder which allows building UI5 Flexibility Adaptation Projects for SAP BTP, Cloud Foundry environment
61 lines • 2.28 kB
JavaScript
import XmlUtil from "../../util/xmlUtil.js";
export default class DataSource {
name;
uri;
jsonTransformers = new Array();
constructor(name, uri) {
this.name = name;
this.uri = uri;
}
/**
* Update the json of the dataSources in manifest.json
*/
updateManifest(_) {
// to be overriden in children
}
/**
* Get the filename under which it should be stored in dist folder
*/
getFilename() {
return `annotations/annotation_${this.name}.xml`;
}
async createAnnotationFile(languages, i18nManager, serviceRequestor) {
const annotationJsons = this.getPromisesPerLanguage(languages, serviceRequestor);
const annotationJson = await i18nManager.populateTranslations(annotationJsons);
const xml = XmlUtil.jsonToXml(await annotationJson.json);
return {
filename: this.getFilename(),
xml
};
}
/**
* Download the annotation for all configured languages
* @param languages from configuration
* @param serviceRequestor will download the annotation for all languages
*/
getPromisesPerLanguage(languages, serviceRequestor) {
const promises = new Map();
for (const language of languages) {
promises.set(language, this.downloadAnnotation(language, serviceRequestor));
}
return promises;
}
/**
* Download annotations and process xml string after it
*/
async downloadAnnotation(language, serviceRequestor) {
const languageXmlContent = await serviceRequestor.downloadAnnotation(this.uri, this.name, language);
if (!languageXmlContent) {
throw new Error(`Xml is undefined for '${this.uri}', name '${this.name}' and language '${language.sap}'`);
}
return this.afterXmlDownload({ xml: languageXmlContent, language, serviceRequestor, uri: this.uri });
}
async afterXmlDownload({ xml, language, serviceRequestor, uri }) {
let json = XmlUtil.xmlToJson(xml);
for (const transformer of this.jsonTransformers) {
json = await transformer.transform({ xml, json, language, serviceRequestor, uri });
}
return json;
}
}
//# sourceMappingURL=dataSource.js.map