Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 14 additions & 2 deletions src/utils/import/jsonld/import-package-jsonld.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { IRsp, rspOK, Msg } from "../../lib/messages";
import { LIB, logger } from "../../lib/helpers";
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 Down Expand Up @@ -53,8 +54,19 @@ export async function importJSONLD(source: string | File | Blob): Promise<IRsp>
}

// Instantiate APackage and load the document
const aPackage = new APackage().setJSONLD(doc);

const aPackage = new APackage().setJSONLD(doc); // apply all constraint checks by default
/* 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();
Expand Down
17 changes: 15 additions & 2 deletions src/utils/import/xml/import-package-xml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
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
Expand Down Expand Up @@ -60,9 +61,21 @@ export async function importXML(source: string | File | Blob): Promise<IRsp> {
return Msg.create(697, 'XML', errors);
}
*/
// ✅ Instantiate APackage directly from XML string
const aPackage = new APackage().setXML(xmlString);

// Instantiate APackage directly from XML string
const aPackage = new APackage().setXML(xmlString); // apply all constraint checks by default
/* 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();
Expand Down
10 changes: 1 addition & 9 deletions src/utils/lib/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,6 @@ export const XML_NAMESPACES = Object.entries(NAMESPACE_MAP)

// LIB object with helper methods
export const LIB = {
/* createRsp<T = unknown>(status: number, statusText?: string, response?: T, responseType?: XMLHttpRequestResponseType): IRsp<T> {
return {
status: status,
statusText: statusText,
response: response,
responseType: responseType,
ok: status > 199 && status < 300 || status === 0
};
}, */

isLeaf(node: JsonValue): boolean {
return (typeof node === 'string' || typeof node === 'number' || typeof node === 'boolean');
Expand Down Expand Up @@ -243,6 +234,7 @@ export const LIB = {
}
return value;
},

/**
* Wrap XML fragment with root element and namespace declarations
* @param xml - XML fragment (without root wrapper)
Expand Down
32 changes: 16 additions & 16 deletions src/utils/lib/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,24 +365,24 @@ const messages: Record<number, Record<LanguageCode, (...args: any[]) => string>>
`Error en la validación del paquete: elemento '${parentId}' hasProperty[${propIndex}].hasClass='${hasClass}' - ${msg}`
},
674: {
en: (parentId: string, linkIndex: number, linkArrayName: string, msg: string) =>
`Package validation failed: item '${parentId}' ${linkArrayName}[${linkIndex}] has ${msg}`,
de: (parentId: string, linkIndex: number, linkArrayName: string, msg: string) =>
`Paket-Validierung fehlgeschlagen: Element '${parentId}' ${linkArrayName}[${linkIndex}] hat ${msg}`,
fr: (parentId: string, linkIndex: number, linkArrayName: string, msg: string) =>
`Échec de la validation du package: élément '${parentId}' ${linkArrayName}[${linkIndex}] a ${msg}`,
es: (parentId: string, linkIndex: number, linkArrayName: string, msg: string) =>
`Error en la validación del paquete: elemento '${parentId}' ${linkArrayName}[${linkIndex}] tiene ${msg}`
en: (parentId: string, index: number, prpName: string, msg: string) =>
`Package validation failed: item '${parentId}' graph[${index}] ${prpName} - ${msg}`,
de: (parentId: string, index: number, prpName: string, msg: string) =>
`Paket-Validierung fehlgeschlagen: Element '${parentId}' graph[${index}] ${prpName} - ${msg}`,
fr: (parentId: string, index: number, prpName: string, msg: string) =>
`Échec de la validation du package: élément '${parentId}' graph[${index}] ${prpName} - ${msg}`,
es: (parentId: string, index: number, prpName: string, msg: string) =>
`Error en la validación del paquete: elemento '${parentId}' graph[${index}] ${prpName} - ${msg}`
},
675: {
en: (parentId: string, linkIndex: number, linkArrayName: string, hasClass: string, msg: string) =>
`Package validation failed: item '${parentId}' ${linkArrayName}[${linkIndex}].hasClass='${hasClass}' - ${msg}`,
de: (parentId: string, linkIndex: number, linkArrayName: string, hasClass: string, msg: string) =>
`Paket-Validierung fehlgeschlagen: Element '${parentId}' ${linkArrayName}[${linkIndex}].hasClass='${hasClass}' - ${msg}`,
fr: (parentId: string, linkIndex: number, linkArrayName: string, hasClass: string, msg: string) =>
`Échec de la validation du package: élément '${parentId}' ${linkArrayName}[${linkIndex}].hasClass='${hasClass}' - ${msg}`,
es: (parentId: string, linkIndex: number, linkArrayName: string, hasClass: string, msg: string) =>
`Error en la validación del paquete: elemento '${parentId}' ${linkArrayName}[${linkIndex}].hasClass='${hasClass}' - ${msg}`
en: (parentId: string, index: number, prpName: string, prpVal: string, msg: string) =>
`Package validation failed: item '${parentId}' graph[${index}] ${prpName}: ${prpVal} - ${msg}`,
de: (parentId: string, index: number, prpName: string, prpVal: string, msg: string) =>
`Paket-Validierung fehlgeschlagen: Element '${parentId}' graph[${index}] ${prpName}: ${prpVal} - ${msg}`,
fr: (parentId: string, index: number, prpName: string, prpVal: string, msg: string) =>
`Échec de la validation du package: élément '${parentId}' graph[${index}] ${prpName}: ${prpVal} - ${msg}`,
es: (parentId: string, index: number, prpName: string, prpVal: string, msg: string) =>
`Error en la validación del paquete: elemento '${parentId}' graph[${index}] ${prpName}: ${prpVal} - ${msg}`
},
679: {
en: (op: string, act: number, exp: number) =>
Expand Down
76 changes: 76 additions & 0 deletions src/utils/schemas/pig/json/pig-schemata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,77 @@ const ARELATIONSHIP_SCHEMA = {
};
const validateARelationshipSchema = ajv.compile(ARELATIONSHIP_SCHEMA);

/* APACKAGE_SCHEMA: describes IAPackage (pig:aPackage) */
const APACKAGE_SCHEMA = {
$schema: 'http://json-schema.org/draft-07/schema#',
$id: 'https://gfse.org/schemas/pig/IAPackage',
type: 'object',
properties: {
context: {
type: 'array',
// minItems: 1,
items: {
type: 'object',
description: 'Namespace definitions with tag and URI mappings',
properties: {
tag: { type: 'string' },
uri: { type: 'string', format: 'uri' }
},
additionalProperties: false
}
},
id: { $ref: '#/$defs/idString' },
itemType: {
type: 'string',
enum: ['pig:aPackage'],
description: 'The PigItemType for pig:aPackage'
},
title: {
type: 'array',
minItems: 1,
items: { $ref: '#/$defs/LanguageText' }
},
description: {
type: 'array',
minItems: 1,
items: { $ref: '#/$defs/LanguageText' }
},
modified: {
type: 'string',
format: 'date-time'
},
creator: { type: 'string' },
graph: {
type: 'array',
items: {
type: 'object',
description: 'Any PIG item in the package graph; items are checked individually before instantiation'
}
}
},
additionalProperties: false,
required: ['id', 'itemType', 'modified', 'graph'],
$defs: {
idString: {
type: 'string',
description: 'TPigId — term with namespace (prefix:local) or an URI',
pattern: ID_NAME_PATTERN
},
LanguageText: {
type: 'object',
required: ['value'],
additionalProperties: false,
properties: {
value: { type: 'string' },
lang: { type: 'string' }
}
}
}
};
const validateAPackageSchema = ajv.compile(APACKAGE_SCHEMA);

/** SCH: Exported schemata and validation functions for PIG items:
*/
export const SCH = {
PROPERTY_SCHEMA,
validatePropertySchema,
Expand Down Expand Up @@ -580,5 +651,10 @@ export const SCH = {
validateARelationshipSchema,
getValidateARelationshipErrors() {
return ajv.errorsText(validateARelationshipSchema.errors, { separator: '; ' })
},
APACKAGE_SCHEMA,
validateAPackageSchema,
getValidateAPackageErrors() {
return ajv.errorsText(validateAPackageSchema.errors, { separator: '; ' })
}
};
Loading
Loading