Rendering format filters dynamically from ontologies and schacl shapes.
The http://www.w3.org/ns/shacl#in parameters were added to the Shape model when the shape object was created from the fetched data, which was necessary because it contains the resouce formats.
/**
* Returns all resource formats. Resource formats are listed in a node of a resource called Format. The possible
* values are contained inside the http://www.w3.org/ns/shacl#in property.
*
* @param ontologies serving as the source of information
* @return a list of resource formats
*/
export const getResourceFormats = (ontologies: Ontology[]): string[] => {
const dataResourceOntologies = ontologies
.filter(ontology => ontology.relatedShapes
.some(relatedShape => isSubclassOfDataResource(ontology, relatedShape))
)
const formatShapes = dataResourceOntologies
.map(ontology => ontology.relatedShapes
.filter(relatedShape => relatedShape.targetClasses
.some(targetClass => targetClass.endsWith('/Format')))
)
.flat()
const formatShapeProperties = formatShapes
.map(shape => shape.properties
.filter(property => property.propertyId.endsWith('/formatType'))
)
.flat()
const inPropertyParameters = formatShapeProperties
.map(property => property.propertyValues
.filter(propertyParameter => propertyParameter.type === 'http://www.w3.org/ns/shacl#in')
)
.flat()
return Array.from(new Set<string>(
inPropertyParameters.map(parameter => parameter.value).flat()
));
}
Other thing solved
Changing what kind of resources are fetched
the node labels should contain at least one of the selected filters
the node labels should contain the DataResource label too
only main nodes (uri which does not start with pnode://) are returned as result.
fetching resource formats too
/**
* Returns all resources of type included in the type asset list passed in as parameter.
*
* @param authContext authorization token for server calls
* @param typeFilters the list of requested resource types
*/
async getAllResources(authContext: AuthContextType, typeFilters: Asset[]): Promise<ResourceInput> {
const whereDataResource = typeFilters.length ? `
WHERE ANY (label IN labels(n) WHERE label IN [ '${typeFilters.map(asset => asset.label).join('\', \'')}'])
AND 'DataResource' IN labels(n)
AND NOT n.uri STARTS WITH 'bnode://'`
: ''
const matchFormatNode = `
OPTIONAL MATCH(m)
WHERE n.uri IN m.claimsGraphUri
AND ANY(label IN labels(m) WHERE label CONTAINS 'Format')`
return cypherQuery(authContext, {
statement: `
MATCH (n)
${whereDataResource}
${matchFormatNode}
RETURN
properties(n) AS properties,
labels(n) AS labels,
properties(m).type AS format`,
})
}
Model Shape changed
Code cleanup: Resource, ResourceInput, ServiceOffering, ServiceOfferingInput were simplified and moved to the correct files.
Changing the way existing resource types are calculated see the comment
Applying format filter fixed: Filters the already fetched resources correctly and does not fetch data again.
Refactored createShapeObjects:
Code was restructred some concerns were separated in order to simplify.
The http://www.w3.org/ns/shacl#in parameters were added to the Shape model. which by the way contain the resouce formats.
Configure Jest
Test coverage for createShapeObjects and createOntologyObject methods assuring refactoring without error
Tasks:
Description
Required
Shape
model when the shape object was created from the fetched data, which was necessary because it contains the resouce formats.Other thing solved
DataResource
label toopnode://
) are returned as result.Model
Shape
changedCode cleanup: Resource, ResourceInput, ServiceOffering, ServiceOfferingInput were simplified and moved to the correct files.
Changing the way existing resource types are calculated see the comment
Applying format filter fixed: Filters the already fetched resources correctly and does not fetch data again.
Refactored
createShapeObjects
:Shape
model. which by the way contain the resouce formats.Configure Jest
Test coverage for
createShapeObjects
andcreateOntologyObject
methods assuring refactoring without error