Skip to content

Commit

Permalink
Merge branch 'main' into SDTT-343-Add-an-extra-flag-the-ea-converter-…
Browse files Browse the repository at this point in the history
…that-allows-to-export-all-tags-from-the-UML-diagram-instead-of-a-controlled-selection
  • Loading branch information
KristofVDB1 committed Dec 4, 2024
2 parents d4f26b0 + 0a0021c commit 1763a95
Show file tree
Hide file tree
Showing 21 changed files with 515 additions and 192 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ export class StakeholdersConversionService implements IService {
editors: Stakeholder[];
}> {
const parser = parse({ delimiter: ';', columns: true });
parser.on('error', (error: any) => {
this.logger.error(
`[CsvConverterHandler] Unable to convert the provided csv into a stakeholders-file. ${error} for record ${error?.record}`,
);
});
const transformer = new ToJsonTransformer(this.configuration.outputFormat);

const contributors: Stakeholder[] = [];
Expand Down
2 changes: 1 addition & 1 deletion packages/oslo-converter-stakeholders/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@oslo-flanders/stakeholders-converter",
"version": "0.0.17-alpha.0",
"version": "0.0.19-alpha.0",
"description": "Converts an OSLO stakeholders csv file to a different format",
"author": "Digitaal Vlaanderen <https://data.vlaanderen.be/id/organisatie/OVO002949>",
"homepage": "https://github.com/informatievlaanderen/OSLO-UML-Transformer/tree/main/packages/oslo-converter-stakeholders-oslo#readme",
Expand Down
1 change: 1 addition & 0 deletions packages/oslo-converter-uml-ea/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ The service is executed from the CLI and expects the following parameters:
| `--outputFile` | The name of the RDF output file | No, but if omitted, output is written to process.stdout ||
| `--outputFormat` | RDF content-type specifiying the output format | :heavy_check_mark: | `application/ld+json` |
| `--allTags` | Add all tags from EA to the generated output | No, default `false` | `true` or `false` |
| `--debug` | A flag to enable debug mode which is more resilient to errors | | `false` |

## Usage

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ export class EaUmlConversionServiceRunner extends AppRunner<
default: false,
boolean: true,
})
.option('debug', {
describe:
'A flag to enable debug mode which is more resilient to errors',
default: false,
boolean: true,
})
.demandOption(
['umlFile', 'diagramName', 'versionId', 'publicationEnvironment'],
'Please provide the necessary arguments to work with this tool.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ export class EaUmlConverterConfiguration implements IConfiguration {
* The base URI of the environment where the document will be published
*/
private _publicationEnvironment: string | undefined;
/**
* A boolean to enable debug mode which is more resilient to errors
*/
private _debug: boolean | undefined;

/**
* A boolean that decided whether or not all tags will be added to the generated output
Expand All @@ -46,6 +50,7 @@ export class EaUmlConverterConfiguration implements IConfiguration {
this._outputFormat = <string>params.outputFormat;
this._publicationEnvironment = <string>params.publicationEnvironment;
this._allTags = <boolean>params.allTags;
this._debug = <boolean>params.debug;
}

public get umlFile(): string {
Expand Down Expand Up @@ -103,4 +108,8 @@ export class EaUmlConverterConfiguration implements IConfiguration {
public get allTags(): boolean {
return !!this._allTags;
}

public get debug(): boolean {
return !!this._debug;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ export class AttributeConverterHandler extends ConverterHandler<EaAttribute> {
model.targetDiagram.elementIds.includes(x.classId) &&
!enumerationClasses.some((y) => y.id === x.classId),
)
.forEach((object) => {
store.addQuads(this.createQuads(object, uriRegistry, model));
});
.forEach((object) =>
store.addQuads(this.createQuads(object, uriRegistry, model)),
);

return store;
}
Expand Down Expand Up @@ -88,7 +88,13 @@ export class AttributeConverterHandler extends ConverterHandler<EaAttribute> {
null,
);
if (externalUri) {
uriRegistry.attributeIdUriMap.set(attribute.id, new URL(externalUri));
try {
uriRegistry.attributeIdUriMap.set(attribute.id, new URL(externalUri));
} catch (error: unknown) {
throw new Error(
`[AttributeConverterHandler]: Invalid URL (${externalUri}) for attribute (${attribute.path})`,
);
}
return;
}

Expand Down Expand Up @@ -157,8 +163,14 @@ export class AttributeConverterHandler extends ConverterHandler<EaAttribute> {
localName = toCamelCase(localName);
}

const attributeURI: URL = new URL(`${attributeBaseURI}${localName}`);
uriRegistry.attributeIdUriMap.set(attribute.id, attributeURI);
try {
const attributeURI: URL = new URL(`${attributeBaseURI}${localName}`);
uriRegistry.attributeIdUriMap.set(attribute.id, attributeURI);
} catch (error: unknown) {
throw new Error(
`[AttributeConverterHandler]: Invalid URL (${attributeBaseURI}${localName}) for attribute (${attribute.path})`,
);
}
});

return uriRegistry;
Expand Down Expand Up @@ -298,10 +310,17 @@ export class AttributeConverterHandler extends ConverterHandler<EaAttribute> {
}
}

<<<<<<< HEAD

Check failure on line 313 in packages/oslo-converter-uml-ea/lib/converter-handlers/AttributeConverterHandler.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18.x)

Merge conflict marker encountered.

Check failure on line 313 in packages/oslo-converter-uml-ea/lib/converter-handlers/AttributeConverterHandler.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 20.x)

Merge conflict marker encountered.

Check failure on line 313 in packages/oslo-converter-uml-ea/lib/converter-handlers/AttributeConverterHandler.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18.x)

Merge conflict marker encountered.

Check failure on line 313 in packages/oslo-converter-uml-ea/lib/converter-handlers/AttributeConverterHandler.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 20.x)

Merge conflict marker encountered.
if (!rangeURI) {
throw new Error(
`[AttributeConverterHandler]: Unable to get the URI for the range of attribute (${object.path}).`,
);
=======

Check failure on line 318 in packages/oslo-converter-uml-ea/lib/converter-handlers/AttributeConverterHandler.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18.x)

Merge conflict marker encountered.

Check failure on line 318 in packages/oslo-converter-uml-ea/lib/converter-handlers/AttributeConverterHandler.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 20.x)

Merge conflict marker encountered.

Check failure on line 318 in packages/oslo-converter-uml-ea/lib/converter-handlers/AttributeConverterHandler.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18.x)

Merge conflict marker encountered.

Check failure on line 318 in packages/oslo-converter-uml-ea/lib/converter-handlers/AttributeConverterHandler.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 20.x)

Merge conflict marker encountered.
// https://vlaamseoverheid.atlassian.net/browse/SDTT-344
// Needed a way to log errors without throwing them so that the conversion process can continue
if (this.handleRangeError(object, rangeURI)) {
return [];
>>>>>>> main

Check failure on line 323 in packages/oslo-converter-uml-ea/lib/converter-handlers/AttributeConverterHandler.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18.x)

Merge conflict marker encountered.

Check failure on line 323 in packages/oslo-converter-uml-ea/lib/converter-handlers/AttributeConverterHandler.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 20.x)

Merge conflict marker encountered.

Check failure on line 323 in packages/oslo-converter-uml-ea/lib/converter-handlers/AttributeConverterHandler.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18.x)

Merge conflict marker encountered.

Check failure on line 323 in packages/oslo-converter-uml-ea/lib/converter-handlers/AttributeConverterHandler.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 20.x)

Merge conflict marker encountered.
}

quads.push(
Expand Down Expand Up @@ -362,6 +381,22 @@ export class AttributeConverterHandler extends ConverterHandler<EaAttribute> {
return quads;
}

private handleRangeError(
object: EaAttribute,
rangeURI: string | null,
): boolean {
if (!rangeURI) {
const error: string = `[AttributeConverterHandler]: Unable to determine the range for attribute (${object.path}).`;
if (this.config.debug) {
this.logger.error(error);
return true;
} else {
throw new Error(error);
}
}
return false;
}

private getDatatypeQuads(
rangeInternalId: RDF.NamedNode,
rangeAssignedURI: RDF.NamedNode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import type {
EaPackage,
NormalizedConnector,
} from '@oslo-flanders/ea-uml-extractor';
import {
ConnectorType,
} from '@oslo-flanders/ea-uml-extractor';
import { ConnectorType } from '@oslo-flanders/ea-uml-extractor';
import type * as RDF from '@rdfjs/types';
import { inject, injectable } from 'inversify';
import { EaUmlConverterServiceIdentifier } from '../config/EaUmlConverterServiceIdentifier';
Expand All @@ -27,7 +25,7 @@ export class ConnectorConverterHandler extends ConverterHandler<NormalizedConnec
public async filterIgnoredObjects(
model: DataRegistry,
): Promise<DataRegistry> {
model.connectors = model.connectors.filter(x => !ignore(x));
model.connectors = model.connectors.filter((x) => !ignore(x));

return model;
}
Expand All @@ -38,19 +36,22 @@ export class ConnectorConverterHandler extends ConverterHandler<NormalizedConnec
store: QuadStore,
): Promise<QuadStore> {
model.normalizedConnectors
.filter(x => model.targetDiagram.connectorsIds.includes(x.originalId))
.forEach(object =>
store.addQuads(this.createQuads(object, uriRegistry, model)));
.filter((x) => model.targetDiagram.connectorsIds.includes(x.originalId))
.forEach((object) =>
store.addQuads(this.createQuads(object, uriRegistry, model)),
);

return store;
}

public async normalize(model: DataRegistry): Promise<DataRegistry> {
const tasks: Promise<NormalizedConnector[]>[] = model.connectors
.filter(x => model.targetDiagram.connectorsIds.includes(x.id))
.map(connector => this.connectorNormalisationService.normalise(connector, model));
.filter((x) => model.targetDiagram.connectorsIds.includes(x.id))
.map((connector) =>
this.connectorNormalisationService.normalise(connector, model),
);

model.normalizedConnectors = await Promise.all(tasks).then(x => x.flat());
model.normalizedConnectors = await Promise.all(tasks).then((x) => x.flat());

return model;
}
Expand All @@ -62,26 +63,36 @@ export class ConnectorConverterHandler extends ConverterHandler<NormalizedConnec
uriRegistry.connectorOsloIdUriMap = new Map<number, URL>();
const diagramConnectors: NormalizedConnector[] = [];

model.targetDiagram.connectorsIds.forEach(connectorId => {
model.targetDiagram.connectorsIds.forEach((connectorId) => {
const filteredConnectors =
model.normalizedConnectors.filter(
x => x.originalId === connectorId,
(x) => x.originalId === connectorId,
) || [];
diagramConnectors.push(...filteredConnectors);
});

diagramConnectors.forEach(connector => {
diagramConnectors.forEach((connector) => {
// Inheritance related connectors do not get an URI.
if (connector.originalType === ConnectorType.Generalization) {
return;
}

const externalUri: string | null = getTagValue(connector, TagNames.ExternalUri, null);
const externalUri: string | null = getTagValue(
connector,
TagNames.ExternalUri,
null,
);
if (externalUri) {
uriRegistry.connectorOsloIdUriMap.set(
connector.id,
new URL(externalUri),
);
try {
uriRegistry.connectorOsloIdUriMap.set(
connector.id,
new URL(externalUri),
);
} catch (error: unknown) {
throw new Error(
`[ConnectorConverterHandler]: Invalid external URI (${externalUri}) for connector (${connector.path})`,
);
}
return;
}

Expand All @@ -93,7 +104,7 @@ export class ConnectorConverterHandler extends ConverterHandler<NormalizedConnec
let baseUri: string | undefined;
if (packageTagValue) {
const packageObject: EaPackage | undefined = model.packages.find(
x => x.name === packageTagValue,
(x) => x.name === packageTagValue,
);

if (!packageObject) {
Expand All @@ -114,10 +125,10 @@ export class ConnectorConverterHandler extends ConverterHandler<NormalizedConnec
baseUri = packageUri.toString();
} else {
const sourcePackage: EaElement | undefined = model.elements.find(
x => x.id === connector.sourceObjectId,
(x) => x.id === connector.sourceObjectId,
);
const destinationPackage: EaElement | undefined = model.elements.find(
x => x.id === connector.destinationObjectId,
(x) => x.id === connector.destinationObjectId,
);

if (
Expand All @@ -142,19 +153,27 @@ export class ConnectorConverterHandler extends ConverterHandler<NormalizedConnec
connector.name,
);

if(!localName){
throw new Error(`[ConnectorConverterHandler]: Unable to find local name for connector (${connector.path}).`);
if (!localName) {
throw new Error(
`[ConnectorConverterHandler]: Unable to find local name for connector (${connector.path}).`,
);
}

// Names on the diagram are not prefixed, so if this value contains
// a prefix (by checking for a dot), we assume this value was added by the editor through
// a name tag. We assume the spelling is correctly done and we do not camel case it.
if(!localName.includes('.')){
if (!localName.includes('.')) {
localName = toCamelCase(localName);
}

const connectorUri = new URL(`${baseUri}${localName}`);
uriRegistry.connectorOsloIdUriMap.set(connector.id, connectorUri);
try {
const connectorUri = new URL(`${baseUri}${localName}`);
uriRegistry.connectorOsloIdUriMap.set(connector.id, connectorUri);
} catch (error: unknown) {
throw new Error(
`[ConnectorConverterHandler]: Invalid URL (${baseUri}${localName}) for connector (${connector.path})`,
);
}
});

return uriRegistry;
Expand All @@ -170,15 +189,19 @@ export class ConnectorConverterHandler extends ConverterHandler<NormalizedConnec
const connectorInternalId: RDF.NamedNode = this.df.namedNode(
`${this.baseUrnScheme}:${object.osloGuid}`,
);
const connectorUri: URL | undefined = uriRegistry.connectorOsloIdUriMap.get(object.id);
const connectorUri: URL | undefined = uriRegistry.connectorOsloIdUriMap.get(
object.id,
);

if (!connectorUri) {
throw new Error(
`[ConnectorConverterHandler]: Unable to find URI for connector (${object.path})`,
);
}

const connectorUriNamedNode: RDF.NamedNode = this.df.namedNode(connectorUri.toString());
const connectorUriNamedNode: RDF.NamedNode = this.df.namedNode(
connectorUri.toString(),
);

quads.push(
this.df.quad(
Expand All @@ -197,7 +220,7 @@ export class ConnectorConverterHandler extends ConverterHandler<NormalizedConnec
this.addEntityInformation(object, connectorInternalId, quads);

const domainObject: EaElement | undefined = model.elements.find(
x => x.id === object.sourceObjectId,
(x) => x.id === object.sourceObjectId,
);

if (domainObject) {
Expand All @@ -210,7 +233,7 @@ export class ConnectorConverterHandler extends ConverterHandler<NormalizedConnec
}

const rangeObject: EaElement | undefined = model.elements.find(
x => x.id === object.destinationObjectId,
(x) => x.id === object.destinationObjectId,
);

if (rangeObject) {
Expand Down Expand Up @@ -270,7 +293,11 @@ export class ConnectorConverterHandler extends ConverterHandler<NormalizedConnec
);
}

const parentUri: string | null = getTagValue(object, TagNames.ParentUri, null);
const parentUri: string | null = getTagValue(
object,
TagNames.ParentUri,
null,
);
if (parentUri) {
quads.push(
this.df.quad(
Expand Down
Loading

0 comments on commit 1763a95

Please sign in to comment.