@ui5/task-adaptation
Version:
Custom task for ui5-builder which allows building UI5 Flexibility Adaptation Projects for SAP BTP, Cloud Foundry environment
45 lines • 2.08 kB
JavaScript
import DataSourceOData from "./dataSourceOData.js";
import DataSourceODataAnnotation from "./dataSourceODataAnnotation.js";
import path from "path/posix";
export default class DataSourceManager {
dataSources = new Array();
/**
* Parses dataSources from manifest.json.
* @param dataSourcesJson manifest.json/sap.app/dataSources node
*/
addDataSources(dataSourcesJson) {
if (!dataSourcesJson) {
return;
}
const odataAnnotationMap = new Map();
// Loop over OData first to collect linked annotation names
for (const [name, dataSource] of Object.entries(dataSourcesJson)) {
if (dataSource.uri?.startsWith("/") && dataSource.type === "OData") {
const uri = path.normalize(dataSource.uri + "/$metadata");
const odata = new DataSourceOData(name, uri, dataSource);
odata.getAnnotations().forEach(annotation => odataAnnotationMap.set(annotation, uri));
this.dataSources.push(odata);
}
}
// If ODataAnnotation is in OData annotations, pass metadata url to it
for (const [name, dataSource] of Object.entries(dataSourcesJson)) {
const uri = dataSource.uri;
const metadataUrl = odataAnnotationMap.get(name);
if (uri?.startsWith("/") && dataSource.type === "ODataAnnotation") {
this.dataSources.push(new DataSourceODataAnnotation(name, uri, dataSource, metadataUrl));
}
}
for (const dataSource of this.dataSources) {
dataSource.updateManifest(dataSourcesJson);
}
}
async createAnnotationFiles(languages, i18nManager, serviceRequestor) {
const annotationFiles = new Map();
for (const dataSource of this.dataSources) {
const { filename, xml } = await dataSource.createAnnotationFile(languages, i18nManager, serviceRequestor);
annotationFiles.set(filename, xml);
}
return annotationFiles;
}
}
//# sourceMappingURL=dataSourceManager.js.map