Skip to content
This repository was archived by the owner on Feb 15, 2024. It is now read-only.

Commit b6ff0ca

Browse files
committed
Adds constraints validation
- AASd-005, AASd-014, AASd-051, AASd-052a, AASd-053, AASd-054, AASd-055, AASd-056, AASd-057, AASd-058, AASd-059, AASd-060, AASd-061, AASd-062, AASd-063, AASd-064, AASd-069, AASd-070, AASd-071, AASd-072, AASd-073, AASd-074, AASd-075, AASd-076, AASd-080, AASd-081, AASd-090, AASd-092, AASd-093, AASd-100 Signed-off-by: Frank Schnicke <frank.schnicke@iese.fraunhofer.de>
1 parent 606880b commit b6ff0ca

26 files changed

Lines changed: 2910 additions & 758 deletions

validator/src/main/java/io/adminshell/aas/v3/model/validator/ShaclValidator.java

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@
1515
*/
1616
package io.adminshell.aas.v3.model.validator;
1717

18-
import io.adminshell.aas.v3.dataformat.rdf.Serializer;
18+
import java.io.ByteArrayInputStream;
19+
import java.io.IOException;
20+
import java.io.InputStream;
21+
import java.nio.charset.StandardCharsets;
22+
import java.util.HashMap;
23+
import java.util.stream.Collectors;
24+
1925
import org.apache.jena.graph.compose.Union;
2026
import org.apache.jena.rdf.model.Model;
2127
import org.apache.jena.rdf.model.ModelFactory;
@@ -27,10 +33,7 @@
2733
import org.apache.jena.util.FileUtils;
2834
import org.slf4j.LoggerFactory;
2935

30-
import java.io.*;
31-
import java.nio.charset.StandardCharsets;
32-
import java.util.HashMap;
33-
import java.util.stream.Collectors;
36+
import io.adminshell.aas.v3.dataformat.rdf.Serializer;
3437

3538

3639
public class ShaclValidator implements Validator{
@@ -124,29 +127,6 @@ private ShaclValidator() {
124127
//Initialize an empty model into which we will be loading the shapes
125128
Model shapesModel = ModelFactory.createDefaultModel();
126129

127-
/*
128-
//Use resources from zip file
129-
//TODO: Will they be compressed?
130-
InputStream inputStream = getClass().getClassLoader().getResourceAsStream("validation.zip");
131-
132-
//Stream this to some temporary file which will be deleted after program exit
133-
if (inputStream == null)
134-
throw new IOException("Failed to retrieve validation.zip from resources.");
135-
136-
File inputStreamToFile = File.createTempFile("validation_zip_file", null);
137-
inputStreamToFile.deleteOnExit();
138-
139-
Files.copy(inputStream, inputStreamToFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
140-
ZipFile zipFile = new ZipFile(inputStreamToFile);
141-
Enumeration<? extends ZipEntry> entries = zipFile.entries();
142-
143-
while (entries.hasMoreElements()) {
144-
shapesModel.read(zipFile.getInputStream(entries.nextElement()), null, FileUtils.langTurtle);
145-
}
146-
*/
147-
//shapesModel.read(Files.readString(Path.of("src/main/resources/shapes.ttl")));
148-
149-
150130
//All loaded, let's parse!
151131
//shapes = Shapes.parse(shapesModel);
152132
InputStream shapesInputStream = getClass().getClassLoader().getResourceAsStream("shapes.ttl");

validator/src/main/resources/constraint_shapes.ttl

Lines changed: 556 additions & 250 deletions
Large diffs are not rendered by default.
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*******************************************************************************
2+
* Copyright (C) 2021 the Eclipse BaSyx Authors
3+
*
4+
* This program and the accompanying materials are made
5+
* available under the terms of the Eclipse Public License 2.0
6+
* which is available at https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
******************************************************************************/
10+
11+
12+
package io.adminshell.aas.v3.model.validator;
13+
14+
import java.util.List;
15+
16+
import io.adminshell.aas.v3.model.AssetAdministrationShell;
17+
import io.adminshell.aas.v3.model.AssetAdministrationShellEnvironment;
18+
import io.adminshell.aas.v3.model.AssetKind;
19+
import io.adminshell.aas.v3.model.ConceptDescription;
20+
import io.adminshell.aas.v3.model.IdentifierType;
21+
import io.adminshell.aas.v3.model.KeyElements;
22+
import io.adminshell.aas.v3.model.KeyType;
23+
import io.adminshell.aas.v3.model.LangString;
24+
import io.adminshell.aas.v3.model.Reference;
25+
import io.adminshell.aas.v3.model.Submodel;
26+
import io.adminshell.aas.v3.model.SubmodelElement;
27+
import io.adminshell.aas.v3.model.impl.DefaultAssetAdministrationShell;
28+
import io.adminshell.aas.v3.model.impl.DefaultAssetAdministrationShellEnvironment;
29+
import io.adminshell.aas.v3.model.impl.DefaultAssetInformation;
30+
import io.adminshell.aas.v3.model.impl.DefaultConceptDescription;
31+
import io.adminshell.aas.v3.model.impl.DefaultIdentifier;
32+
import io.adminshell.aas.v3.model.impl.DefaultKey;
33+
import io.adminshell.aas.v3.model.impl.DefaultReference;
34+
import io.adminshell.aas.v3.model.impl.DefaultSubmodel;
35+
36+
public class ConstraintTestHelper {
37+
38+
public static ConceptDescription createConceptDescription(String idShort, String identifier, String category) {
39+
return new DefaultConceptDescription.Builder()
40+
.description(new LangString("TestDescription"))
41+
.identification(new DefaultIdentifier.Builder().identifier(identifier)
42+
.idType(IdentifierType.CUSTOM).build())
43+
.category(category).idShort(idShort).build();
44+
}
45+
46+
public static Submodel createSubmodel(List<SubmodelElement> elements) {
47+
return new DefaultSubmodel.Builder()
48+
.identification(
49+
new DefaultIdentifier.Builder().identifier("submodel").idType(IdentifierType.CUSTOM).build())
50+
.idShort("smIdShort")
51+
.submodelElements(elements)
52+
.build();
53+
}
54+
55+
public static ConceptDescription getIrrelevantConceptDescription() {
56+
return ConstraintTestHelper.createConceptDescription("irrelevantIdShort", "irrelevant", "COLLECTION");
57+
}
58+
59+
public static AssetAdministrationShell getDummyAAS() {
60+
return new DefaultAssetAdministrationShell.Builder()
61+
.identification(new DefaultIdentifier.Builder()
62+
.identifier("dummyAAS")
63+
.idType(IdentifierType.CUSTOM)
64+
.build())
65+
.idShort("dummyAASIdShort")
66+
.assetInformation(new DefaultAssetInformation.Builder()
67+
.assetKind(AssetKind.INSTANCE)
68+
.build())
69+
.build();
70+
}
71+
72+
public static AssetAdministrationShellEnvironment createEnvironment(Submodel sm, List<ConceptDescription> conceptDescriptions) {
73+
return new DefaultAssetAdministrationShellEnvironment.Builder()
74+
.assetAdministrationShells(getDummyAAS())
75+
.submodels(sm)
76+
.conceptDescriptions(conceptDescriptions)
77+
.build();
78+
}
79+
80+
public static Reference createDummyReference() {
81+
return new DefaultReference.Builder()
82+
.key(new DefaultKey.Builder()
83+
.idType(KeyType.CUSTOM)
84+
.value("reference")
85+
.type(KeyElements.GLOBAL_REFERENCE)
86+
.build())
87+
.build();
88+
}
89+
}

0 commit comments

Comments
 (0)