Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
076cc02
latest examples in JSON-LD and XML
odungern Jan 18, 2026
fe79117
- included the JSON-LD schema files and reorganized the src folder st…
odungern Jan 18, 2026
021d741
index.html files for new server product-information-graph.org
odungern Jan 19, 2026
eba02c9
JSON-LD schemata are now loaded from schema files found in the same d…
odungern Jan 19, 2026
45b8525
Added new JSON-LD test file /11/Alice.pig.jsonld
odungern Jan 20, 2026
b8e74bb
all tests positive - including xml import. Need still to collect the …
odungern Jan 27, 2026
cb0b7e7
now the namespaces = context are extracted from XML, as well. All tra…
odungern Jan 27, 2026
030ca8a
Completed import of .pig.xml. No checks with XML schema or schematron…
odungern Jan 28, 2026
ffe5759
Merge branch 'dev' into 54-XML-import-export
odungern Jan 28, 2026
4d44961
Update src/utils/schemas/pig/index.html
odungern Jan 28, 2026
57dca73
Update src/utils/lib/messages.ts
odungern Jan 28, 2026
1affaca
Update src/utils/import/ReqIF/reqif2pig.ts
odungern Jan 28, 2026
ebdc40f
Update src/utils/lib/mvf.ts
odungern Jan 28, 2026
4a45611
changes following suggestions of Copilot merge review.
odungern Jan 28, 2026
cd871e9
Merge branch '54-XML-import-export' of https://github.com/GfSE/CASCaD…
odungern Jan 28, 2026
8d3e681
add a getHTML stub with 'not implenmented yet' to class aPackage.
odungern Jan 29, 2026
42be8c5
Merge pull request #58 from GfSE/54-XML-import-export
odungern Jan 30, 2026
615c3ef
getHTML() for anEntity and aPackage implemented. With all probability…
odungern Jan 30, 2026
50ff424
now with test-suite for aPackage.getHTML.
odungern Jan 30, 2026
e79a6d7
Update src/utils/schemas/pig/ts/pig-metaclasses.ts
odungern Jan 30, 2026
274e036
Update tests/unit/pig-package-gethtml.spec.ts
odungern Jan 30, 2026
7c06780
Reworked getHTML following Review suggestions.
odungern Jan 30, 2026
dfffea8
minor change in comment
odungern Jan 30, 2026
1b170c8
- Added constraint checks on anEntity and aRelationship hasClass refe…
odungern Feb 2, 2026
686e3f8
all constraint checks applied on JSONLD and XML import.
odungern Feb 2, 2026
a1b34f0
editorial changes in comments
odungern Feb 2, 2026
5db5e19
removed debug logging and redundant check in aPackage.validate().
odungern Feb 2, 2026
2c57a2c
Changes as suggested by Chrie' review.
odungern Feb 3, 2026
99f1380
another change as suggested by Copilot.
odungern Feb 3, 2026
3b69469
fixed merge conflicts
csaenz-psg Feb 3, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/utils/import/ReqIF/reqif2pig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
*/

import { IRsp } from '../../lib/messages';
import { IEntity, IRelationship, IProperty, IAnEntity, IARelationship } from '../../schemas/pig/pig-metaclasses';

export class reqif2pig {
private validate(xml: Document): boolean {
Expand Down
142 changes: 0 additions & 142 deletions src/utils/import/jsonld/import-jsonld.ts.goodButReplaced

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@

import { IRsp, rspOK, Msg } from "../../lib/messages";
import { LIB, logger } from "../../lib/helpers";
import { APackage, TPigItem } from '../../schemas/pig/pig-metaclasses';
import { SCH_LD } from '../../schemas/pig/pig-schemata-jsonld';
import { APackage, TPigItem } from '../../schemas/pig/ts/pig-metaclasses';
import { SCH_LD } from '../../schemas/pig/jsonld/pig-schemata-jsonld';
// import { ConstraintCheckType } from '../../schemas/pig/ts/pig-package-constraints';

/**
* Import JSON-LD document and instantiate PIG items
Expand All @@ -35,28 +36,47 @@ export async function importJSONLD(source: string | File | Blob): Promise<IRsp>
return rsp;

const text = rsp.response as string;
logger.info('importJSONLD: loaded text length ' + text.length);
// logger.info('importJSONLD: loaded text length ' + text.length);

let doc: any;
try {
doc = JSON.parse(text);
} catch (err: any) {
return Msg.create(690, err?.message ?? err);
return Msg.create(690, 'JSON-LD', err?.message ?? err);
}

// ✅ Validate entire JSON-LD document structure
const isValidPackage = SCH_LD.validatePackageLD(doc);
const isValidPackage = await SCH_LD.validatePackageLD(doc);
if (!isValidPackage) {
const errors = SCH_LD.getValidatePackageLDErrors();
const errors = await SCH_LD.getValidatePackageLDErrors();
logger.error('JSON-LD package validation failed:', errors);
return Msg.create(697, errors);
return Msg.create(697, 'JSON-LD', errors);
}

// Instantiate APackage and load the document
const aPackage = new APackage();
const allItems = aPackage.setJSONLD(doc);
const aPackage = new APackage().setJSONLD(doc); // apply all constraint checks by default
/* keeping it because it will be needed when implementing further consistency checks:
const aPackage = new APackage().setJSONLD(
doc,
// some examples are incomplete, so we skip the tests for specializes:
[
ConstraintCheckType.UniqueIds,
ConstraintCheckType.aPropertyHasClass,
ConstraintCheckType.aLinkHasClass,
ConstraintCheckType.anEntityHasClass,
ConstraintCheckType.aRelationshipHasClass,
]
);
*/
// Check if package was successfully created
if (!aPackage.status().ok) {
return aPackage.status();
}

const allItems = aPackage.getAllItems();

// allItems[0] is the package itself, rest are graph items
// const graphItems = allItems.slice(1);
const expectedCount = doc['@graph']?.length || 0;
const actualCount = allItems.length -1;

Expand All @@ -65,16 +85,14 @@ export async function importJSONLD(source: string | File | Blob): Promise<IRsp>
result = rspOK;
logger.info(`importJSONLD: successfully instantiated package with all ${actualCount} items`);
} else {
result = Msg.create(691, actualCount, expectedCount);
result = Msg.create(691, 'JSON-LD', actualCount, expectedCount);
logger.warn(`importJSONLD: instantiated ${actualCount} of ${expectedCount} items`);
}

// Return all items (package + graph items)
result.response = allItems;
result.responseType = 'json';

result = result as IRsp<TPigItem[]>;

return result
return result as IRsp<TPigItem[]>;
}

106 changes: 106 additions & 0 deletions src/utils/import/xml/import-package-xml.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*! Cross-environment XML importer.
* Copyright 2025 GfSE (https://gfse.org)
* License and terms of use: Apache 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
*/
/**
* Cross-environment XML importer.
* - Accepts a Node file path, an http(s) URL string or a browser File/Blob.
* - Parses XML document, converts XML structure to internal keys
* and instantiates matching PIG class instances where possible.
*
* Dependencies:
* Authors: oskar.dungern@gfse.org, ..
* License and terms of use: Apache 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
* We appreciate any correction, comment or contribution as Github issue (https://github.com/GfSE/CASCaDE-Reference-Implementation/issues)
*
* Usage:
* - Node: await importXML('C:/path/to/file.xml')
* - URL: await importXML('https://example/.../doc.xml')
* - Browser: await importXML(fileInput.files[0])
*/

import { IRsp, rspOK, Msg } from '../../lib/messages';
import { LIB, logger } from '../../lib/helpers';
import { APackage, TPigItem } from '../../schemas/pig/ts/pig-metaclasses';
//import { ConstraintCheckType } from '../../schemas/pig/ts/pig-package-constraints';

/**
* Import XML document and instantiate PIG items
* @param source - File path, URL, or File/Blob object
* @returns IRsp with array of TPigItem (first item is APackage, rest are graph items)
*/
export async function importXML(source: string | File | Blob): Promise<IRsp> {
const rsp = await LIB.readFileAsText(source);
if (!rsp.ok)
return rsp;

const xmlString = rsp.response as string;
// logger.info('importXML: loaded text length ' + xmlString.length);

// ✅ Optional: Pre-validate XML syntax
let doc: Document;
try {
const parser = new DOMParser();
doc = parser.parseFromString(xmlString, 'text/xml');

// Check for XML parsing errors
const parserError = doc.querySelector('parsererror');
if (parserError) {
const errorMessage = parserError.textContent || 'Unknown XML parsing error';
return Msg.create(690, 'XML', errorMessage);
}
} catch (err: any) {
return Msg.create(690, 'XML', err?.message ?? err);
}
/*
// ✅ Validate entire XML document structure
const isValidPackage = await SCH_XSD.validatePackageXML(doc);
if (!isValidPackage) {
const errors = await SCH_XSD.getValidatePackageXMLErrors();
logger.error('XML package validation failed:', errors);
return Msg.create(697, 'XML', errors);
}
*/

// Instantiate APackage directly from XML string
const aPackage = new APackage().setXML(xmlString); // apply all constraint checks by default
/* keeping it because it will be needed when implementing further consistency checks:
const aPackage = new APackage().setXML(
xmlString,
// some examples are incomplete, so we skip the tests for specializes:
[
ConstraintCheckType.UniqueIds,
ConstraintCheckType.aPropertyHasClass,
ConstraintCheckType.aLinkHasClass,
ConstraintCheckType.anEntityHasClass,
ConstraintCheckType.aRelationshipHasClass,
]
);
*/
// Check if package was successfully created
if (!aPackage.status().ok) {
return aPackage.status();
}

// allItems[0] is the package itself, rest are graph items:
const allItems = aPackage.getAllItems();

const graphElement = aPackage.graph;
const expectedCount = graphElement?.length || 0;
const actualCount = allItems.length - 1;

let result: IRsp;
if (actualCount === expectedCount) {
result = rspOK;
logger.info(`importXML: successfully instantiated package with all ${actualCount} items`);
} else {
result = Msg.create(691, 'XML', actualCount, expectedCount);
logger.warn(`importXML: instantiated ${actualCount} of ${expectedCount} items`);
}

// Return all items (package + graph items)
result.response = allItems;
result.responseType = 'json';

return result as IRsp<TPigItem[]>;
}
Loading
Loading