From 201fa264cdf57b8831a32bffac60936c704b145b Mon Sep 17 00:00:00 2001 From: Tino Bischoff Date: Wed, 25 Oct 2023 18:29:34 +0200 Subject: [PATCH 01/57] Memory: separate AAS und Submodel Registry --- .../faaast/registry/core/AbstractAasRepositoryTest.java | 7 ++++--- .../ilt/faaast/registry/memory/AasRepositoryMemory.java | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/core/src/test/java/de/fraunhofer/iosb/ilt/faaast/registry/core/AbstractAasRepositoryTest.java b/core/src/test/java/de/fraunhofer/iosb/ilt/faaast/registry/core/AbstractAasRepositoryTest.java index d1f3a473..8fc6cd59 100644 --- a/core/src/test/java/de/fraunhofer/iosb/ilt/faaast/registry/core/AbstractAasRepositoryTest.java +++ b/core/src/test/java/de/fraunhofer/iosb/ilt/faaast/registry/core/AbstractAasRepositoryTest.java @@ -227,7 +227,7 @@ public void listAllSubmodels() throws Exception { repository.create(getAASWithSubmodel()); repository.addSubmodel(getSubmodel()); List submodels = repository.getSubmodels(); - Assert.assertEquals(2, submodels.size()); + Assert.assertEquals(1, submodels.size()); } @@ -238,8 +238,9 @@ public void findStandAloneSubmodelById() throws Exception { repository.create(getAASWithSubmodel()); repository.addSubmodel(submodel); - SubmodelDescriptor findSubmodel = repository.getSubmodel(aas.getSubmodels().get(0).getIdentification().getIdentifier()); - Assert.assertNotNull(findSubmodel); + SubmodelDescriptor findSubmodel; + // Ensure, submodel of the AAS is not registered + Assert.assertThrows(ResourceNotFoundException.class, () -> repository.getSubmodel(aas.getSubmodels().get(0).getIdentification().getIdentifier())); findSubmodel = repository.getSubmodel(submodel.getIdentification().getIdentifier()); Assert.assertNotNull(findSubmodel); } diff --git a/persistence/memory/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/memory/AasRepositoryMemory.java b/persistence/memory/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/memory/AasRepositoryMemory.java index 0c5be843..4b11088d 100644 --- a/persistence/memory/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/memory/AasRepositoryMemory.java +++ b/persistence/memory/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/memory/AasRepositoryMemory.java @@ -72,7 +72,7 @@ public AssetAdministrationShellDescriptor create(AssetAdministrationShellDescrip AssetAdministrationShellDescriptor aas = fetchAAS(descriptor.getIdentification().getIdentifier()); Ensure.require(Objects.isNull(aas), buildAASAlreadyExistsException(descriptor.getIdentification().getIdentifier())); shellDescriptors.put(descriptor.getIdentification().getIdentifier(), descriptor); - descriptor.getSubmodels().forEach(s -> submodelDescriptors.putIfAbsent(s.getIdentification().getIdentifier(), s)); + //descriptor.getSubmodels().forEach(s -> submodelDescriptors.putIfAbsent(s.getIdentification().getIdentifier(), s)); return descriptor; } @@ -83,7 +83,7 @@ public void deleteAAS(String aasId) throws ResourceNotFoundException { AssetAdministrationShellDescriptor aas = fetchAAS(aasId); Ensure.requireNonNull(aas, buildAASNotFoundException(aasId)); shellDescriptors.remove(aasId); - aas.getSubmodels().forEach(s -> submodelDescriptors.remove(s.getIdentification().getIdentifier())); + //aas.getSubmodels().forEach(s -> submodelDescriptors.remove(s.getIdentification().getIdentifier())); } From ce5c4be2c218432c1fc0c5d5cf93a772aaedc109 Mon Sep 17 00:00:00 2001 From: Tino Bischoff Date: Thu, 26 Oct 2023 18:09:24 +0200 Subject: [PATCH 02/57] first version: separate storage for standalone submodels --- .../faaast/registry/jpa/AasRepositoryJpa.java | 14 ++++++++--- .../jpa/model/JpaSubmodelDescriptor.java | 24 +++++++++++++++++-- service/src/main/resources/META-INF/orm.xml | 1 + .../src/main/resources/application.properties | 21 ++++++++-------- 4 files changed, 45 insertions(+), 15 deletions(-) diff --git a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/AasRepositoryJpa.java b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/AasRepositoryJpa.java index 1916328a..95a0c23e 100644 --- a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/AasRepositoryJpa.java +++ b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/AasRepositoryJpa.java @@ -26,6 +26,7 @@ import de.fraunhofer.iosb.ilt.faaast.service.util.Ensure; import jakarta.persistence.EntityManager; import jakarta.persistence.PersistenceContext; +import jakarta.persistence.TypedQuery; import jakarta.transaction.Transactional; import java.util.List; import java.util.Objects; @@ -40,6 +41,8 @@ @Transactional public class AasRepositoryJpa extends AbstractAasRepository { + private static final String FIND_SUBMODEL_STANDALONE = "SELECT s FROM JpaSubmodelDescriptor s where s.standalone=true"; + @PersistenceContext(name = "AASRepositoryJPA") private final EntityManager entityManager; @@ -107,7 +110,11 @@ public List getSubmodels(String aasId) throws ResourceNotFou @Override public List getSubmodels() { - return EntityManagerHelper.getAll(entityManager, JpaSubmodelDescriptor.class, SubmodelDescriptor.class); + TypedQuery query = entityManager.createQuery(FIND_SUBMODEL_STANDALONE, SubmodelDescriptor.class); + //entityManager.createQuery + return query.getResultList(); + + //return EntityManagerHelper.getAll(entityManager, JpaSubmodelDescriptor.class, SubmodelDescriptor.class); } @@ -159,8 +166,9 @@ public SubmodelDescriptor addSubmodel(SubmodelDescriptor descriptor) throws Reso ensureDescriptorId(descriptor); SubmodelDescriptor submodel = fetchSubmodel(descriptor.getIdentification().getIdentifier()); Ensure.require(Objects.isNull(submodel), buildSubmodelAlreadyExistsException(descriptor.getIdentification().getIdentifier())); - submodel = ModelTransformationHelper.convertSubmodel(descriptor); - entityManager.persist(submodel); + JpaSubmodelDescriptor jpaSubmodel = ModelTransformationHelper.convertSubmodel(descriptor); + jpaSubmodel.setStandalone(true); + entityManager.persist(jpaSubmodel); return submodel; } diff --git a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaSubmodelDescriptor.java b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaSubmodelDescriptor.java index 443dc285..f175f69c 100644 --- a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaSubmodelDescriptor.java +++ b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaSubmodelDescriptor.java @@ -28,9 +28,12 @@ public class JpaSubmodelDescriptor extends DefaultSubmodelDescriptor { @JsonIgnore private String id; + @JsonIgnore + private boolean standalone; public JpaSubmodelDescriptor() { id = null; + standalone = false; } @@ -44,9 +47,19 @@ public void setId(String id) { } + public boolean getStandalone() { + return standalone; + } + + + public void setStandalone(boolean value) { + standalone = value; + } + + @Override public int hashCode() { - return Objects.hash(super.hashCode(), id); + return Objects.hash(super.hashCode(), id, standalone); } @@ -64,7 +77,8 @@ else if (this.getClass() != obj.getClass()) { else { JpaSubmodelDescriptor other = (JpaSubmodelDescriptor) obj; return super.equals(obj) - && Objects.equals(this.id, other.id); + && Objects.equals(this.id, other.id) + && Objects.equals(this.standalone, other.standalone); } } @@ -77,6 +91,12 @@ public B id(String value) { } + public B standalone(boolean value) { + getBuildingInstance().setStandalone(value); + return getSelf(); + } + + @Override public B from(SubmodelDescriptor other) { if (other != null) { diff --git a/service/src/main/resources/META-INF/orm.xml b/service/src/main/resources/META-INF/orm.xml index 2767b8b2..6b43febc 100644 --- a/service/src/main/resources/META-INF/orm.xml +++ b/service/src/main/resources/META-INF/orm.xml @@ -82,6 +82,7 @@ + diff --git a/service/src/main/resources/application.properties b/service/src/main/resources/application.properties index ea6c73a1..78209a57 100644 --- a/service/src/main/resources/application.properties +++ b/service/src/main/resources/application.properties @@ -8,17 +8,18 @@ server.port=8090 ######################### ##### RDBS via JPA (in-memory H2) ##### -spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect -spring.datasource.driver=org.h2.Driver -spring.datasource.url=jdbc:h2:mem:testdb -spring.datasource.username=sa -spring.datasource.password= +#spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect +#spring.datasource.driver=org.h2.Driver +#spring.datasource.url=jdbc:h2:mem:testdb +#spring.datasource.username=sa +#spring.datasource.password= ####################################### ###### RDBS via JPA (external PostgresDB) ##### -#spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect -#spring.datasource.driver=org.postgresql.Driver -#spring.datasource.url=jdbc:postgresql://localhost:5432/Fa3stRegistry -#spring.datasource.username=postgres -#spring.datasource.password=admin +spring.profiles.active=external +spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect +spring.datasource.driver=org.postgresql.Driver +spring.datasource.url=jdbc:postgresql://localhost:5432/Fa3stRegistry +spring.datasource.username=postgres +spring.datasource.password=admin ############################################### \ No newline at end of file From 3a4a4864dd977c82707867275f98d931e1258ea1 Mon Sep 17 00:00:00 2001 From: Tino Bischoff Date: Fri, 27 Oct 2023 13:16:02 +0200 Subject: [PATCH 03/57] second version: separate storage for standalone submodels --- .../faaast/registry/jpa/AasRepositoryJpa.java | 32 ++--- .../jpa/model/JpaSubmodelDescriptor.java | 34 +++--- .../JpaSubmodelDescriptorStandalone.java | 109 ++++++++++++++++++ .../jpa/util/ModelTransformationHelper.java | 12 ++ .../jpa/src/test/resources/META-INF/orm.xml | 43 ++++++- .../registry/service/RegistryService.java | 12 ++ service/src/main/resources/META-INF/orm.xml | 45 +++++++- 7 files changed, 243 insertions(+), 44 deletions(-) create mode 100644 persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaSubmodelDescriptorStandalone.java diff --git a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/AasRepositoryJpa.java b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/AasRepositoryJpa.java index 95a0c23e..53d1738b 100644 --- a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/AasRepositoryJpa.java +++ b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/AasRepositoryJpa.java @@ -19,6 +19,7 @@ import de.fraunhofer.iosb.ilt.faaast.registry.core.exception.ResourceNotFoundException; import de.fraunhofer.iosb.ilt.faaast.registry.jpa.model.JpaAssetAdministrationShellDescriptor; import de.fraunhofer.iosb.ilt.faaast.registry.jpa.model.JpaSubmodelDescriptor; +import de.fraunhofer.iosb.ilt.faaast.registry.jpa.model.JpaSubmodelDescriptorStandalone; import de.fraunhofer.iosb.ilt.faaast.registry.jpa.util.EntityManagerHelper; import de.fraunhofer.iosb.ilt.faaast.registry.jpa.util.ModelTransformationHelper; import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.AssetAdministrationShellDescriptor; @@ -26,7 +27,6 @@ import de.fraunhofer.iosb.ilt.faaast.service.util.Ensure; import jakarta.persistence.EntityManager; import jakarta.persistence.PersistenceContext; -import jakarta.persistence.TypedQuery; import jakarta.transaction.Transactional; import java.util.List; import java.util.Objects; @@ -41,8 +41,6 @@ @Transactional public class AasRepositoryJpa extends AbstractAasRepository { - private static final String FIND_SUBMODEL_STANDALONE = "SELECT s FROM JpaSubmodelDescriptor s where s.standalone=true"; - @PersistenceContext(name = "AASRepositoryJPA") private final EntityManager entityManager; @@ -110,11 +108,9 @@ public List getSubmodels(String aasId) throws ResourceNotFou @Override public List getSubmodels() { - TypedQuery query = entityManager.createQuery(FIND_SUBMODEL_STANDALONE, SubmodelDescriptor.class); - //entityManager.createQuery - return query.getResultList(); - - //return EntityManagerHelper.getAll(entityManager, JpaSubmodelDescriptor.class, SubmodelDescriptor.class); + //TypedQuery query = entityManager.createQuery(FIND_SUBMODEL_STANDALONE, SubmodelDescriptor.class); + //return query.getResultList(); + return EntityManagerHelper.getAll(entityManager, JpaSubmodelDescriptorStandalone.class, SubmodelDescriptor.class); } @@ -139,7 +135,7 @@ public SubmodelDescriptor getSubmodel(String aasId, String submodelId) throws Re @Override public SubmodelDescriptor getSubmodel(String submodelId) throws ResourceNotFoundException { ensureSubmodelId(submodelId); - SubmodelDescriptor submodel = fetchSubmodel(submodelId); + SubmodelDescriptor submodel = fetchSubmodelStandalone(submodelId); Ensure.requireNonNull(submodel, buildSubmodelNotFoundException(submodelId)); return submodel; } @@ -164,11 +160,11 @@ public SubmodelDescriptor addSubmodel(String aasId, SubmodelDescriptor descripto @Override public SubmodelDescriptor addSubmodel(SubmodelDescriptor descriptor) throws ResourceAlreadyExistsException { ensureDescriptorId(descriptor); - SubmodelDescriptor submodel = fetchSubmodel(descriptor.getIdentification().getIdentifier()); + SubmodelDescriptor submodel = fetchSubmodelStandalone(descriptor.getIdentification().getIdentifier()); Ensure.require(Objects.isNull(submodel), buildSubmodelAlreadyExistsException(descriptor.getIdentification().getIdentifier())); - JpaSubmodelDescriptor jpaSubmodel = ModelTransformationHelper.convertSubmodel(descriptor); - jpaSubmodel.setStandalone(true); - entityManager.persist(jpaSubmodel); + submodel = ModelTransformationHelper.convertSubmodelStandalone(descriptor); + //jpaSubmodel.setStandalone(true); + entityManager.persist(submodel); return submodel; } @@ -194,7 +190,7 @@ public void deleteSubmodel(String aasId, String submodelId) throws ResourceNotFo @Override public void deleteSubmodel(String submodelId) throws ResourceNotFoundException { ensureSubmodelId(submodelId); - SubmodelDescriptor submodel = fetchSubmodel(submodelId); + SubmodelDescriptor submodel = fetchSubmodelStandalone(submodelId); Ensure.requireNonNull(submodel, buildSubmodelNotFoundException(submodelId)); entityManager.remove(submodel); } @@ -209,8 +205,12 @@ private JpaAssetAdministrationShellDescriptor fetchAAS(String aasId) { } } + //private JpaSubmodelDescriptor fetchSubmodel(String submodelId) { + // return entityManager.find(JpaSubmodelDescriptor.class, submodelId); + //} + - private JpaSubmodelDescriptor fetchSubmodel(String submodelId) { - return entityManager.find(JpaSubmodelDescriptor.class, submodelId); + private JpaSubmodelDescriptorStandalone fetchSubmodelStandalone(String submodelId) { + return entityManager.find(JpaSubmodelDescriptorStandalone.class, submodelId); } } diff --git a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaSubmodelDescriptor.java b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaSubmodelDescriptor.java index f175f69c..895eeb26 100644 --- a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaSubmodelDescriptor.java +++ b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaSubmodelDescriptor.java @@ -28,12 +28,12 @@ public class JpaSubmodelDescriptor extends DefaultSubmodelDescriptor { @JsonIgnore private String id; - @JsonIgnore - private boolean standalone; + //@JsonIgnore + //private boolean standalone; public JpaSubmodelDescriptor() { id = null; - standalone = false; + //standalone = false; } @@ -46,20 +46,18 @@ public void setId(String id) { this.id = id; } + //public boolean getStandalone() { + // return standalone; + //} - public boolean getStandalone() { - return standalone; - } - - - public void setStandalone(boolean value) { - standalone = value; - } + //public void setStandalone(boolean value) { + // standalone = value; + //} @Override public int hashCode() { - return Objects.hash(super.hashCode(), id, standalone); + return Objects.hash(super.hashCode(), id); } @@ -77,8 +75,7 @@ else if (this.getClass() != obj.getClass()) { else { JpaSubmodelDescriptor other = (JpaSubmodelDescriptor) obj; return super.equals(obj) - && Objects.equals(this.id, other.id) - && Objects.equals(this.standalone, other.standalone); + && Objects.equals(this.id, other.id); } } @@ -90,11 +87,10 @@ public B id(String value) { return getSelf(); } - - public B standalone(boolean value) { - getBuildingInstance().setStandalone(value); - return getSelf(); - } + //public B standalone(boolean value) { + // getBuildingInstance().setStandalone(value); + // return getSelf(); + //} @Override diff --git a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaSubmodelDescriptorStandalone.java b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaSubmodelDescriptorStandalone.java new file mode 100644 index 00000000..9d7a300b --- /dev/null +++ b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaSubmodelDescriptorStandalone.java @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2021 Fraunhofer IOSB, eine rechtlich nicht selbstaendige + * Einrichtung der Fraunhofer-Gesellschaft zur Foerderung der angewandten + * Forschung e.V. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package de.fraunhofer.iosb.ilt.faaast.registry.jpa.model; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import de.fraunhofer.iosb.ilt.faaast.registry.jpa.util.ModelTransformationHelper; +import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.SubmodelDescriptor; +import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.impl.DefaultSubmodelDescriptor; +import java.util.Objects; + + +/** + * Registry Descriptor JPA implementation for standalone Submodel. + */ +public class JpaSubmodelDescriptorStandalone extends DefaultSubmodelDescriptor { + + @JsonIgnore + private String id; + + public JpaSubmodelDescriptorStandalone() { + id = null; + } + + + public String getId() { + return id; + } + + + public void setId(String id) { + this.id = id; + } + + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), id); + } + + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + else if (obj == null) { + return false; + } + else if (this.getClass() != obj.getClass()) { + return false; + } + else { + JpaSubmodelDescriptorStandalone other = (JpaSubmodelDescriptorStandalone) obj; + return super.equals(obj) + && Objects.equals(this.id, other.id); + } + } + + public abstract static class AbstractBuilder> + extends DefaultSubmodelDescriptor.AbstractBuilder { + + public B id(String value) { + getBuildingInstance().setId(value); + return getSelf(); + } + + + @Override + public B from(SubmodelDescriptor other) { + if (other != null) { + id(other.getIdentification().getIdentifier()); + idShort(other.getIdShort()); + endpoints(ModelTransformationHelper.convertEndpoints(other.getEndpoints())); + administration(ModelTransformationHelper.convertAdministrativeInformation(other.getAdministration())); + descriptions(ModelTransformationHelper.convertDescriptions(other.getDescriptions())); + displayNames(ModelTransformationHelper.convertDescriptions(other.getDisplayNames())); + identification(ModelTransformationHelper.convertIdentifier(other.getIdentification())); + semanticId(ModelTransformationHelper.convertReference(other.getSemanticId())); + } + return getSelf(); + } + } + + public static class Builder extends AbstractBuilder { + + @Override + protected Builder getSelf() { + return this; + } + + + @Override + protected JpaSubmodelDescriptorStandalone newBuildingInstance() { + return new JpaSubmodelDescriptorStandalone(); + } + } +} diff --git a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/util/ModelTransformationHelper.java b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/util/ModelTransformationHelper.java index b34403ba..f5dc80dc 100644 --- a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/util/ModelTransformationHelper.java +++ b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/util/ModelTransformationHelper.java @@ -24,6 +24,7 @@ import de.fraunhofer.iosb.ilt.faaast.registry.jpa.model.JpaProtocolInformation; import de.fraunhofer.iosb.ilt.faaast.registry.jpa.model.JpaReference; import de.fraunhofer.iosb.ilt.faaast.registry.jpa.model.JpaSubmodelDescriptor; +import de.fraunhofer.iosb.ilt.faaast.registry.jpa.model.JpaSubmodelDescriptorStandalone; import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.AssetAdministrationShellDescriptor; import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.Endpoint; import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.ProtocolInformation; @@ -180,6 +181,17 @@ public static JpaSubmodelDescriptor convertSubmodel(SubmodelDescriptor submodel) } + /** + * Converts SubmodelDescriptor to JPASubmodelDescriptorStandalone. + * + * @param submodel The SubmodelDescriptor. + * @return The converted JPASubmodelDescriptor. + */ + public static JpaSubmodelDescriptorStandalone convertSubmodelStandalone(SubmodelDescriptor submodel) { + return new JpaSubmodelDescriptorStandalone.Builder().from(submodel).build(); + } + + /** * Converts a list of SubmodelDescriptor to a list of JPASubmodelDescriptor. * diff --git a/persistence/jpa/src/test/resources/META-INF/orm.xml b/persistence/jpa/src/test/resources/META-INF/orm.xml index 2767b8b2..8b61c1e6 100644 --- a/persistence/jpa/src/test/resources/META-INF/orm.xml +++ b/persistence/jpa/src/test/resources/META-INF/orm.xml @@ -97,16 +97,16 @@ - + - + - + - + @@ -175,4 +175,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/RegistryService.java b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/RegistryService.java index a505bcf0..6a3f8197 100644 --- a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/RegistryService.java +++ b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/RegistryService.java @@ -23,6 +23,8 @@ import de.fraunhofer.iosb.ilt.faaast.service.util.Ensure; import java.util.Base64; import java.util.List; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -33,6 +35,7 @@ @Service public class RegistryService { + private static final Logger LOGGER = LoggerFactory.getLogger(RegistryService.class); private static final String AAS_NOT_NULL_TXT = "aas must be non-null"; private static final String SUBMODEL_NOT_NULL_TXT = "submodel must be non-null"; @@ -71,6 +74,7 @@ public AssetAdministrationShellDescriptor getAAS(String id) throws ResourceNotFo public AssetAdministrationShellDescriptor createAAS(AssetAdministrationShellDescriptor aas) throws ResourceAlreadyExistsException { Ensure.requireNonNull(aas, AAS_NOT_NULL_TXT); checkShellIdentifiers(aas); + LOGGER.debug("createAAS: {}", aas.getIdentification().getIdentifier()); if (aas.getSubmodels() != null) { aas.getSubmodels().stream().forEach(this::checkSubmodelIdentifiers); } @@ -86,6 +90,7 @@ public AssetAdministrationShellDescriptor createAAS(AssetAdministrationShellDesc */ public void deleteAAS(String id) throws ResourceNotFoundException { String idDecoded = decode(id); + LOGGER.debug("deleteAAS: AAS {}", idDecoded); aasRepository.deleteAAS(idDecoded); } @@ -101,6 +106,7 @@ public void deleteAAS(String id) throws ResourceNotFoundException { public AssetAdministrationShellDescriptor updateAAS(String id, AssetAdministrationShellDescriptor aas) throws ResourceNotFoundException { Ensure.requireNonNull(aas, AAS_NOT_NULL_TXT); String idDecoded = decode(id); + LOGGER.debug("updateAAS: {}", idDecoded); checkShellIdentifiers(aas); aas.getSubmodels().stream().forEach(this::checkSubmodelIdentifiers); return aasRepository.update(idDecoded, aas); @@ -194,10 +200,12 @@ public SubmodelDescriptor createSubmodel(String aasId, SubmodelDescriptor submod Ensure.requireNonNull(submodel, SUBMODEL_NOT_NULL_TXT); checkSubmodelIdentifiers(submodel); if (aasId == null) { + LOGGER.debug("createSubmodel: Submodel {}", submodel.getIdentification().getIdentifier()); return aasRepository.addSubmodel(submodel); } else { String aasIdDecoded = decode(aasId); + LOGGER.debug("createSubmodel: AAS '{}'; Submodel {}", aasIdDecoded, submodel.getIdentification().getIdentifier()); return aasRepository.addSubmodel(aasIdDecoded, submodel); } } @@ -224,10 +232,12 @@ public void deleteSubmodel(String submodelId) throws ResourceNotFoundException { public void deleteSubmodel(String aasId, String submodelId) throws ResourceNotFoundException { String submodelIdDecoded = decode(submodelId); if (aasId == null) { + LOGGER.debug("deleteSubmodel: Submodel {}", submodelIdDecoded); aasRepository.deleteSubmodel(submodelIdDecoded); } else { String aasIdDecoded = decode(aasId); + LOGGER.debug("deleteSubmodel: AAS '{}'; Submodel {}", aasIdDecoded, submodelIdDecoded); aasRepository.deleteSubmodel(aasIdDecoded, submodelIdDecoded); } } @@ -246,6 +256,7 @@ public SubmodelDescriptor updateSubmodel(String submodelId, SubmodelDescriptor s Ensure.requireNonNull(submodel, SUBMODEL_NOT_NULL_TXT); String submodelIdDecoded = decode(submodelId); checkSubmodelIdentifiers(submodel); + LOGGER.debug("updateSubmodel: Submodel {}", submodelIdDecoded); aasRepository.deleteSubmodel(submodelIdDecoded); return aasRepository.addSubmodel(submodel); } @@ -266,6 +277,7 @@ public SubmodelDescriptor updateSubmodel(String aasId, String submodelId, Submod String aasIdDecoded = decode(aasId); String submodelIdDecoded = decode(submodelId); checkSubmodelIdentifiers(submodel); + LOGGER.debug("updateSubmodel: AAS '{}'; Submodel {}", aasIdDecoded, submodelIdDecoded); aasRepository.deleteSubmodel(aasIdDecoded, submodelIdDecoded); return aasRepository.addSubmodel(aasIdDecoded, submodel); } diff --git a/service/src/main/resources/META-INF/orm.xml b/service/src/main/resources/META-INF/orm.xml index 6b43febc..67ebbede 100644 --- a/service/src/main/resources/META-INF/orm.xml +++ b/service/src/main/resources/META-INF/orm.xml @@ -82,7 +82,7 @@ - + @@ -98,16 +98,16 @@ - + - + - + - + @@ -176,4 +176,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 9e77c3f29ed74553bc8d9557365fc05ab93afdac Mon Sep 17 00:00:00 2001 From: Tino Bischoff Date: Fri, 27 Oct 2023 15:46:12 +0200 Subject: [PATCH 04/57] cleanup --- .../faaast/registry/jpa/AasRepositoryJpa.java | 7 ------- .../jpa/model/JpaSubmodelDescriptor.java | 16 ---------------- .../jpa/src/test/resources/META-INF/orm.xml | 6 ------ service/src/main/resources/META-INF/orm.xml | 7 ------- 4 files changed, 36 deletions(-) diff --git a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/AasRepositoryJpa.java b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/AasRepositoryJpa.java index 53d1738b..05e27029 100644 --- a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/AasRepositoryJpa.java +++ b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/AasRepositoryJpa.java @@ -108,8 +108,6 @@ public List getSubmodels(String aasId) throws ResourceNotFou @Override public List getSubmodels() { - //TypedQuery query = entityManager.createQuery(FIND_SUBMODEL_STANDALONE, SubmodelDescriptor.class); - //return query.getResultList(); return EntityManagerHelper.getAll(entityManager, JpaSubmodelDescriptorStandalone.class, SubmodelDescriptor.class); } @@ -163,7 +161,6 @@ public SubmodelDescriptor addSubmodel(SubmodelDescriptor descriptor) throws Reso SubmodelDescriptor submodel = fetchSubmodelStandalone(descriptor.getIdentification().getIdentifier()); Ensure.require(Objects.isNull(submodel), buildSubmodelAlreadyExistsException(descriptor.getIdentification().getIdentifier())); submodel = ModelTransformationHelper.convertSubmodelStandalone(descriptor); - //jpaSubmodel.setStandalone(true); entityManager.persist(submodel); return submodel; } @@ -205,10 +202,6 @@ private JpaAssetAdministrationShellDescriptor fetchAAS(String aasId) { } } - //private JpaSubmodelDescriptor fetchSubmodel(String submodelId) { - // return entityManager.find(JpaSubmodelDescriptor.class, submodelId); - //} - private JpaSubmodelDescriptorStandalone fetchSubmodelStandalone(String submodelId) { return entityManager.find(JpaSubmodelDescriptorStandalone.class, submodelId); diff --git a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaSubmodelDescriptor.java b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaSubmodelDescriptor.java index 895eeb26..443dc285 100644 --- a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaSubmodelDescriptor.java +++ b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaSubmodelDescriptor.java @@ -28,12 +28,9 @@ public class JpaSubmodelDescriptor extends DefaultSubmodelDescriptor { @JsonIgnore private String id; - //@JsonIgnore - //private boolean standalone; public JpaSubmodelDescriptor() { id = null; - //standalone = false; } @@ -46,14 +43,6 @@ public void setId(String id) { this.id = id; } - //public boolean getStandalone() { - // return standalone; - //} - - //public void setStandalone(boolean value) { - // standalone = value; - //} - @Override public int hashCode() { @@ -87,11 +76,6 @@ public B id(String value) { return getSelf(); } - //public B standalone(boolean value) { - // getBuildingInstance().setStandalone(value); - // return getSelf(); - //} - @Override public B from(SubmodelDescriptor other) { diff --git a/persistence/jpa/src/test/resources/META-INF/orm.xml b/persistence/jpa/src/test/resources/META-INF/orm.xml index 8b61c1e6..b965be7f 100644 --- a/persistence/jpa/src/test/resources/META-INF/orm.xml +++ b/persistence/jpa/src/test/resources/META-INF/orm.xml @@ -80,9 +80,7 @@ - - @@ -179,15 +177,11 @@ - - - - diff --git a/service/src/main/resources/META-INF/orm.xml b/service/src/main/resources/META-INF/orm.xml index 67ebbede..b965be7f 100644 --- a/service/src/main/resources/META-INF/orm.xml +++ b/service/src/main/resources/META-INF/orm.xml @@ -80,10 +80,7 @@ - - - @@ -180,15 +177,11 @@ - - - - From 3ce80d803bda6c5cf59af33489b5459280906384 Mon Sep 17 00:00:00 2001 From: Tino Bischoff Date: Fri, 27 Oct 2023 15:59:40 +0200 Subject: [PATCH 05/57] fix error in addSubmodel --- .../registry/memory/AasRepositoryMemory.java | 1 - .../src/main/resources/application.properties | 22 +++++++++---------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/persistence/memory/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/memory/AasRepositoryMemory.java b/persistence/memory/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/memory/AasRepositoryMemory.java index 4b11088d..f1b1a6e9 100644 --- a/persistence/memory/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/memory/AasRepositoryMemory.java +++ b/persistence/memory/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/memory/AasRepositoryMemory.java @@ -146,7 +146,6 @@ public SubmodelDescriptor addSubmodel(String aasId, SubmodelDescriptor descripto throw buildSubmodelAlreadyExistsException(descriptor.getIdentification().getIdentifier()); } aas.getSubmodels().add(descriptor); - submodelDescriptors.putIfAbsent(descriptor.getIdentification().getIdentifier(), descriptor); return descriptor; } diff --git a/service/src/main/resources/application.properties b/service/src/main/resources/application.properties index 78209a57..dc05d096 100644 --- a/service/src/main/resources/application.properties +++ b/service/src/main/resources/application.properties @@ -8,18 +8,18 @@ server.port=8090 ######################### ##### RDBS via JPA (in-memory H2) ##### -#spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect -#spring.datasource.driver=org.h2.Driver -#spring.datasource.url=jdbc:h2:mem:testdb -#spring.datasource.username=sa -#spring.datasource.password= +spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect +spring.datasource.driver=org.h2.Driver +spring.datasource.url=jdbc:h2:mem:testdb +spring.datasource.username=sa +spring.datasource.password= ####################################### ###### RDBS via JPA (external PostgresDB) ##### -spring.profiles.active=external -spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect -spring.datasource.driver=org.postgresql.Driver -spring.datasource.url=jdbc:postgresql://localhost:5432/Fa3stRegistry -spring.datasource.username=postgres -spring.datasource.password=admin +#spring.profiles.active=external +#spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect +#spring.datasource.driver=org.postgresql.Driver +#spring.datasource.url=jdbc:postgresql://localhost:5432/Fa3stRegistry +#spring.datasource.username=postgres +#spring.datasource.password=admin ############################################### \ No newline at end of file From 25d35b5a75addf01b7f6c0f228a13956cdd1942b Mon Sep 17 00:00:00 2001 From: Tino Bischoff Date: Mon, 30 Oct 2023 09:24:27 +0100 Subject: [PATCH 06/57] remove comments --- .../iosb/ilt/faaast/registry/memory/AasRepositoryMemory.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/persistence/memory/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/memory/AasRepositoryMemory.java b/persistence/memory/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/memory/AasRepositoryMemory.java index f1b1a6e9..e6a804ae 100644 --- a/persistence/memory/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/memory/AasRepositoryMemory.java +++ b/persistence/memory/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/memory/AasRepositoryMemory.java @@ -72,7 +72,6 @@ public AssetAdministrationShellDescriptor create(AssetAdministrationShellDescrip AssetAdministrationShellDescriptor aas = fetchAAS(descriptor.getIdentification().getIdentifier()); Ensure.require(Objects.isNull(aas), buildAASAlreadyExistsException(descriptor.getIdentification().getIdentifier())); shellDescriptors.put(descriptor.getIdentification().getIdentifier(), descriptor); - //descriptor.getSubmodels().forEach(s -> submodelDescriptors.putIfAbsent(s.getIdentification().getIdentifier(), s)); return descriptor; } @@ -83,7 +82,6 @@ public void deleteAAS(String aasId) throws ResourceNotFoundException { AssetAdministrationShellDescriptor aas = fetchAAS(aasId); Ensure.requireNonNull(aas, buildAASNotFoundException(aasId)); shellDescriptors.remove(aasId); - //aas.getSubmodels().forEach(s -> submodelDescriptors.remove(s.getIdentification().getIdentifier())); } From 35343642cf5c3ff799826081da1ef189cacf1867 Mon Sep 17 00:00:00 2001 From: Tino Bischoff Date: Mon, 30 Oct 2023 12:42:40 +0100 Subject: [PATCH 07/57] refactor JPA submodels --- .../jpa/model/JpaSubmodelDescriptor.java | 77 +-------------- .../jpa/model/JpaSubmodelDescriptorBase.java | 95 +++++++++++++++++++ .../JpaSubmodelDescriptorStandalone.java | 75 +-------------- 3 files changed, 100 insertions(+), 147 deletions(-) create mode 100644 persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaSubmodelDescriptorBase.java diff --git a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaSubmodelDescriptor.java b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaSubmodelDescriptor.java index 443dc285..b2e7173e 100644 --- a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaSubmodelDescriptor.java +++ b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaSubmodelDescriptor.java @@ -14,84 +14,13 @@ */ package de.fraunhofer.iosb.ilt.faaast.registry.jpa.model; -import com.fasterxml.jackson.annotation.JsonIgnore; -import de.fraunhofer.iosb.ilt.faaast.registry.jpa.util.ModelTransformationHelper; -import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.SubmodelDescriptor; -import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.impl.DefaultSubmodelDescriptor; -import java.util.Objects; - - /** - * Registry Descriptor JPA implementation for Submodel. + * Registry Descriptor JPA implementation for Submodel of an AAS. */ -public class JpaSubmodelDescriptor extends DefaultSubmodelDescriptor { - - @JsonIgnore - private String id; - - public JpaSubmodelDescriptor() { - id = null; - } - - - public String getId() { - return id; - } - - - public void setId(String id) { - this.id = id; - } - - - @Override - public int hashCode() { - return Objects.hash(super.hashCode(), id); - } - - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - else if (obj == null) { - return false; - } - else if (this.getClass() != obj.getClass()) { - return false; - } - else { - JpaSubmodelDescriptor other = (JpaSubmodelDescriptor) obj; - return super.equals(obj) - && Objects.equals(this.id, other.id); - } - } +public class JpaSubmodelDescriptor extends JpaSubmodelDescriptorBase { public abstract static class AbstractBuilder> - extends DefaultSubmodelDescriptor.AbstractBuilder { - - public B id(String value) { - getBuildingInstance().setId(value); - return getSelf(); - } - - - @Override - public B from(SubmodelDescriptor other) { - if (other != null) { - id(other.getIdentification().getIdentifier()); - idShort(other.getIdShort()); - endpoints(ModelTransformationHelper.convertEndpoints(other.getEndpoints())); - administration(ModelTransformationHelper.convertAdministrativeInformation(other.getAdministration())); - descriptions(ModelTransformationHelper.convertDescriptions(other.getDescriptions())); - displayNames(ModelTransformationHelper.convertDescriptions(other.getDisplayNames())); - identification(ModelTransformationHelper.convertIdentifier(other.getIdentification())); - semanticId(ModelTransformationHelper.convertReference(other.getSemanticId())); - } - return getSelf(); - } - } + extends JpaSubmodelDescriptorBase.AbstractBuilder {} public static class Builder extends AbstractBuilder { diff --git a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaSubmodelDescriptorBase.java b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaSubmodelDescriptorBase.java new file mode 100644 index 00000000..b6c6cb10 --- /dev/null +++ b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaSubmodelDescriptorBase.java @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2021 Fraunhofer IOSB, eine rechtlich nicht selbstaendige + * Einrichtung der Fraunhofer-Gesellschaft zur Foerderung der angewandten + * Forschung e.V. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package de.fraunhofer.iosb.ilt.faaast.registry.jpa.model; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import de.fraunhofer.iosb.ilt.faaast.registry.jpa.util.ModelTransformationHelper; +import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.SubmodelDescriptor; +import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.impl.DefaultSubmodelDescriptor; +import java.util.Objects; + + +/** + * Registry Descriptor JPA implementation Base class for Submodel. + */ +public abstract class JpaSubmodelDescriptorBase extends DefaultSubmodelDescriptor { + + @JsonIgnore + private String id; + + public JpaSubmodelDescriptorBase() { + id = null; + } + + + public String getId() { + return id; + } + + + public void setId(String id) { + this.id = id; + } + + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), id); + } + + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + else if (obj == null) { + return false; + } + else if (this.getClass() != obj.getClass()) { + return false; + } + else { + JpaSubmodelDescriptorBase other = (JpaSubmodelDescriptorBase) obj; + return super.equals(obj) + && Objects.equals(this.id, other.id); + } + } + + public abstract static class AbstractBuilder> + extends DefaultSubmodelDescriptor.AbstractBuilder { + + public B id(String value) { + getBuildingInstance().setId(value); + return getSelf(); + } + + + @Override + public B from(SubmodelDescriptor other) { + if (other != null) { + id(other.getIdentification().getIdentifier()); + idShort(other.getIdShort()); + endpoints(ModelTransformationHelper.convertEndpoints(other.getEndpoints())); + administration(ModelTransformationHelper.convertAdministrativeInformation(other.getAdministration())); + descriptions(ModelTransformationHelper.convertDescriptions(other.getDescriptions())); + displayNames(ModelTransformationHelper.convertDescriptions(other.getDisplayNames())); + identification(ModelTransformationHelper.convertIdentifier(other.getIdentification())); + semanticId(ModelTransformationHelper.convertReference(other.getSemanticId())); + } + return getSelf(); + } + } +} diff --git a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaSubmodelDescriptorStandalone.java b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaSubmodelDescriptorStandalone.java index 9d7a300b..19feb3a6 100644 --- a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaSubmodelDescriptorStandalone.java +++ b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaSubmodelDescriptorStandalone.java @@ -14,84 +14,13 @@ */ package de.fraunhofer.iosb.ilt.faaast.registry.jpa.model; -import com.fasterxml.jackson.annotation.JsonIgnore; -import de.fraunhofer.iosb.ilt.faaast.registry.jpa.util.ModelTransformationHelper; -import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.SubmodelDescriptor; -import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.impl.DefaultSubmodelDescriptor; -import java.util.Objects; - - /** * Registry Descriptor JPA implementation for standalone Submodel. */ -public class JpaSubmodelDescriptorStandalone extends DefaultSubmodelDescriptor { - - @JsonIgnore - private String id; - - public JpaSubmodelDescriptorStandalone() { - id = null; - } - - - public String getId() { - return id; - } - - - public void setId(String id) { - this.id = id; - } - - - @Override - public int hashCode() { - return Objects.hash(super.hashCode(), id); - } - - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - else if (obj == null) { - return false; - } - else if (this.getClass() != obj.getClass()) { - return false; - } - else { - JpaSubmodelDescriptorStandalone other = (JpaSubmodelDescriptorStandalone) obj; - return super.equals(obj) - && Objects.equals(this.id, other.id); - } - } +public class JpaSubmodelDescriptorStandalone extends JpaSubmodelDescriptorBase { public abstract static class AbstractBuilder> - extends DefaultSubmodelDescriptor.AbstractBuilder { - - public B id(String value) { - getBuildingInstance().setId(value); - return getSelf(); - } - - - @Override - public B from(SubmodelDescriptor other) { - if (other != null) { - id(other.getIdentification().getIdentifier()); - idShort(other.getIdShort()); - endpoints(ModelTransformationHelper.convertEndpoints(other.getEndpoints())); - administration(ModelTransformationHelper.convertAdministrativeInformation(other.getAdministration())); - descriptions(ModelTransformationHelper.convertDescriptions(other.getDescriptions())); - displayNames(ModelTransformationHelper.convertDescriptions(other.getDisplayNames())); - identification(ModelTransformationHelper.convertIdentifier(other.getIdentification())); - semanticId(ModelTransformationHelper.convertReference(other.getSemanticId())); - } - return getSelf(); - } - } + extends JpaSubmodelDescriptorBase.AbstractBuilder {} public static class Builder extends AbstractBuilder { From bc48161cb34a8b5df07ee3be5a0d6822221de419 Mon Sep 17 00:00:00 2001 From: Tino Bischoff Date: Mon, 30 Oct 2023 12:47:50 +0100 Subject: [PATCH 08/57] remove sonar warning --- .../faaast/registry/jpa/model/JpaSubmodelDescriptorBase.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaSubmodelDescriptorBase.java b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaSubmodelDescriptorBase.java index b6c6cb10..771694c7 100644 --- a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaSubmodelDescriptorBase.java +++ b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaSubmodelDescriptorBase.java @@ -29,7 +29,7 @@ public abstract class JpaSubmodelDescriptorBase extends DefaultSubmodelDescripto @JsonIgnore private String id; - public JpaSubmodelDescriptorBase() { + protected JpaSubmodelDescriptorBase() { id = null; } From 3016dcc17158a21d7de2e66dc57c47002cecb5e5 Mon Sep 17 00:00:00 2001 From: Tino Bischoff Date: Wed, 21 Feb 2024 18:16:30 +0100 Subject: [PATCH 09/57] adapt to v3.0 model --- .../registry/core/AbstractAasRepository.java | 12 +- .../core/AbstractAasRepositoryTest.java | 110 ++++++++---------- .../faaast/registry/jpa/AasRepositoryJpa.java | 27 +++-- .../model/JpaAdministrativeInformation.java | 6 +- ...JpaAssetAdministrationShellDescriptor.java | 91 +++++++-------- .../registry/jpa/model/JpaDescription.java | 35 +++--- ...JpaIdentifier.java => JpaDisplayName.java} | 31 +++-- .../ilt/faaast/registry/jpa/model/JpaKey.java | 7 +- .../registry/jpa/model/JpaReference.java | 6 +- ...ValuePair.java => JpaSpecificAssetId.java} | 29 ++--- .../jpa/model/JpaSubmodelDescriptorBase.java | 89 +++++++------- .../jpa/util/ModelTransformationHelper.java | 60 ++++++---- .../registry/memory/AasRepositoryMemory.java | 20 ++-- .../registry/service/RegistryService.java | 10 +- .../config/DescriptorMapperConfig.java | 28 +++-- service/src/main/resources/logback.xml | 27 +++++ 16 files changed, 300 insertions(+), 288 deletions(-) rename persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/{JpaIdentifier.java => JpaDisplayName.java} (67%) rename persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/{JpaIdentifierKeyValuePair.java => JpaSpecificAssetId.java} (69%) create mode 100644 service/src/main/resources/logback.xml diff --git a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/core/AbstractAasRepository.java b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/core/AbstractAasRepository.java index 53626d6a..ef143e74 100644 --- a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/core/AbstractAasRepository.java +++ b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/core/AbstractAasRepository.java @@ -96,8 +96,7 @@ protected static ResourceNotFoundException buildSubmodelNotFoundInAASException(S */ protected static void ensureDescriptorId(AssetAdministrationShellDescriptor descriptor) { Ensure.requireNonNull(descriptor, "descriptor must be non-null"); - Ensure.requireNonNull(descriptor.getIdentification(), "descriptor.identification must be non-null"); - Ensure.requireNonNull(descriptor.getIdentification().getIdentifier(), "descriptor id must be non-null"); + Ensure.requireNonNull(descriptor.getId(), "descriptor id must be non-null"); } @@ -109,8 +108,7 @@ protected static void ensureDescriptorId(AssetAdministrationShellDescriptor desc */ protected static void ensureDescriptorId(SubmodelDescriptor descriptor) { Ensure.requireNonNull(descriptor, "descriptor must be non-null"); - Ensure.requireNonNull(descriptor.getIdentification(), "descriptor.identification must be non-null"); - Ensure.requireNonNull(descriptor.getIdentification().getIdentifier(), "descriptor id must be non-null"); + Ensure.requireNonNull(descriptor.getId(), "descriptor id must be non-null"); } @@ -145,11 +143,9 @@ protected static void ensureSubmodelId(String submodelId) { */ protected static Optional getSubmodelInternal(List submodels, String submodelId) { return submodels.stream() - .filter(x -> Objects.nonNull(x.getIdentification()) - && Objects.nonNull(x.getIdentification().getIdentifier()) - && Objects.equals(x.getIdentification().getIdentifier(), submodelId)) + .filter(x -> Objects.nonNull(x.getId()) + && Objects.equals(x.getId(), submodelId)) .findAny(); - } } diff --git a/core/src/test/java/de/fraunhofer/iosb/ilt/faaast/registry/core/AbstractAasRepositoryTest.java b/core/src/test/java/de/fraunhofer/iosb/ilt/faaast/registry/core/AbstractAasRepositoryTest.java index 8fc6cd59..51179ba6 100644 --- a/core/src/test/java/de/fraunhofer/iosb/ilt/faaast/registry/core/AbstractAasRepositoryTest.java +++ b/core/src/test/java/de/fraunhofer/iosb/ilt/faaast/registry/core/AbstractAasRepositoryTest.java @@ -21,18 +21,17 @@ import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.impl.DefaultEndpoint; import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.impl.DefaultProtocolInformation; import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.impl.DefaultSubmodelDescriptor; -import io.adminshell.aas.v3.model.IdentifierType; -import io.adminshell.aas.v3.model.KeyElements; -import io.adminshell.aas.v3.model.KeyType; -import io.adminshell.aas.v3.model.LangString; -import io.adminshell.aas.v3.model.impl.DefaultAdministrativeInformation; -import io.adminshell.aas.v3.model.impl.DefaultIdentifier; -import io.adminshell.aas.v3.model.impl.DefaultIdentifierKeyValuePair; -import io.adminshell.aas.v3.model.impl.DefaultKey; -import io.adminshell.aas.v3.model.impl.DefaultReference; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import org.eclipse.digitaltwin.aas4j.v3.model.KeyTypes; +import org.eclipse.digitaltwin.aas4j.v3.model.ReferenceTypes; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultAdministrativeInformation; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultKey; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultLangStringNameType; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultLangStringTextType; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultReference; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultSpecificAssetId; import org.junit.After; import org.junit.Assert; import org.junit.Test; @@ -51,18 +50,15 @@ public void clearDatastore() {} protected DefaultSubmodelDescriptor getSubmodel() { return DefaultSubmodelDescriptor.builder() .idShort("Submodel2") - .identification(new DefaultIdentifier.Builder() - .idType(IdentifierType.CUSTOM) - .identifier("TestSubmodel2") - .build()) - .description(new LangString("some submodel", "en-US")) - .displayName(new LangString("Submodel 2 Name", "de-DE")) + .id("TestSubmodel2") + .description(new DefaultLangStringTextType.Builder().text("some submodel").language("en-US").build()) + .displayName(new DefaultLangStringNameType.Builder().text("Submodel 2 Name").language("de-DE").build()) .semanticId(new DefaultReference.Builder() - .key(new DefaultKey.Builder() - .idType(KeyType.IRI) - .type(KeyElements.SUBMODEL) + .keys(new DefaultKey.Builder() + .type(KeyTypes.SUBMODEL) .value("http://example.org/smTest2") .build()) + .type(ReferenceTypes.EXTERNAL_REFERENCE) .build()) .administration(new DefaultAdministrativeInformation.Builder() .revision("1") @@ -82,41 +78,32 @@ protected DefaultSubmodelDescriptor getSubmodel() { protected AssetAdministrationShellDescriptor getAASWithSubmodel() { AssetAdministrationShellDescriptor aas = DefaultAssetAdministrationShellDescriptor.builder() .idShort("Test1") - .identification(new DefaultIdentifier.Builder() - .idType(IdentifierType.CUSTOM) - .identifier("TestAAS1") - .build()) - .description(new LangString("some aas", "en-US")) - .displayName(new LangString("Test 1 AAS", "en-US")) + .id("TestAAS1") + .description(new DefaultLangStringTextType.Builder().text("some aas").language("en-US").build()) + .displayName(new DefaultLangStringNameType.Builder().text("Test 1 AAS").language("en-US").build()) .administration(new DefaultAdministrativeInformation.Builder() .revision("1") .version("1.1") .build()) - .specificAssetIds(new ArrayList<>(Arrays.asList(new DefaultIdentifierKeyValuePair.Builder() + .specificAssetIds(new ArrayList<>(Arrays.asList(new DefaultSpecificAssetId.Builder() + .name("TestKey") + .value("ValueTest") .externalSubjectId(new DefaultReference.Builder() - .key(new DefaultKey.Builder() - .idType(KeyType.IRI) - .type(KeyElements.ASSET) + .keys(new DefaultKey.Builder() + .type(KeyTypes.GLOBAL_REFERENCE) .value("http://example.org/aasTest1") .build()) + .type(ReferenceTypes.EXTERNAL_REFERENCE) .build()) .semanticId(new DefaultReference.Builder() - .key(new DefaultKey.Builder() - .idType(KeyType.IRI) - .type(KeyElements.ASSET) + .keys(new DefaultKey.Builder() + .type(KeyTypes.GLOBAL_REFERENCE) .value("http://example.org/aasTest1") .build()) + .type(ReferenceTypes.EXTERNAL_REFERENCE) .build()) - .key("TestKey") - .value("ValueTest") .build()))) - .globalAssetId(new DefaultReference.Builder() - .key(new DefaultKey.Builder() - .idType(KeyType.IRI) - .type(KeyElements.ASSET) - .value("http://example.org/aasTest1") - .build()) - .build()) + .globalAssetId("http://example.org/aasTest1") .endpoint(DefaultEndpoint.builder() .interfaceInformation("http") .protocolInformation(DefaultProtocolInformation.builder() @@ -128,18 +115,15 @@ protected AssetAdministrationShellDescriptor getAASWithSubmodel() { List submodels = new ArrayList<>(); submodels.add(DefaultSubmodelDescriptor.builder() .idShort("Submodel1") - .identification(new DefaultIdentifier.Builder() - .idType(IdentifierType.CUSTOM) - .identifier("TestSubmodel1") - .build()) - .description(new LangString("some submodel", "en-US")) - .displayName(new LangString("Submodel 1 Name", "en-US")) + .id("TestSubmodel1") + .description(new DefaultLangStringTextType.Builder().text("some submodel").language("en-US").build()) + .displayName(new DefaultLangStringNameType.Builder().text("Submodel 1 Name").language("en-US").build()) .semanticId(new DefaultReference.Builder() - .key(new DefaultKey.Builder() - .idType(KeyType.IRI) - .type(KeyElements.SUBMODEL) + .keys(new DefaultKey.Builder() + .type(KeyTypes.SUBMODEL) .value("http://example.org/smTest1") .build()) + .type(ReferenceTypes.EXTERNAL_REFERENCE) .build()) .administration(new DefaultAdministrativeInformation.Builder() .revision("1") @@ -189,7 +173,7 @@ public void updateAAS() throws Exception { aas.setIdShort("NewIdShort"); aas.getSubmodels().get(0).setIdShort("NewSubmodelIdShort"); repository.update(aasId, aas); - aas = repository.getAAS(aas.getIdentification().getIdentifier()); + aas = repository.getAAS(aas.getId()); Assert.assertEquals("NewIdShort", aas.getIdShort()); Assert.assertEquals("NewSubmodelIdShort", aas.getSubmodels().get(0).getIdShort()); } @@ -217,8 +201,8 @@ public void createSubmodelToAAS() throws Exception { SubmodelDescriptor submodel = getSubmodel(); AssetAdministrationShellDescriptor aas = getAASWithSubmodel(); repository.create(aas); - repository.addSubmodel(aas.getIdentification().getIdentifier(), submodel); - compareSubmodel(submodel, repository.getSubmodel(aas.getIdentification().getIdentifier(), submodel.getIdentification().getIdentifier())); + repository.addSubmodel(aas.getId(), submodel); + compareSubmodel(submodel, repository.getSubmodel(aas.getId(), submodel.getId())); } @@ -240,8 +224,8 @@ public void findStandAloneSubmodelById() throws Exception { SubmodelDescriptor findSubmodel; // Ensure, submodel of the AAS is not registered - Assert.assertThrows(ResourceNotFoundException.class, () -> repository.getSubmodel(aas.getSubmodels().get(0).getIdentification().getIdentifier())); - findSubmodel = repository.getSubmodel(submodel.getIdentification().getIdentifier()); + Assert.assertThrows(ResourceNotFoundException.class, () -> repository.getSubmodel(aas.getSubmodels().get(0).getId())); + findSubmodel = repository.getSubmodel(submodel.getId()); Assert.assertNotNull(findSubmodel); } @@ -251,9 +235,9 @@ public void findAASSubmodelById() throws Exception { AssetAdministrationShellDescriptor aas = getAASWithSubmodel(); SubmodelDescriptor submodel = getSubmodel(); repository.create(getAASWithSubmodel()); - repository.addSubmodel(aas.getIdentification().getIdentifier(), submodel); + repository.addSubmodel(aas.getId(), submodel); - SubmodelDescriptor findSubmodel = repository.getSubmodel(aas.getIdentification().getIdentifier(), submodel.getIdentification().getIdentifier()); + SubmodelDescriptor findSubmodel = repository.getSubmodel(aas.getId(), submodel.getId()); Assert.assertNotNull(findSubmodel); } @@ -262,10 +246,10 @@ public void findAASSubmodelById() throws Exception { public void deleteStandAloneSubmodel() throws Exception { SubmodelDescriptor submodel = getSubmodel(); repository.addSubmodel(submodel); - compareSubmodel(submodel, repository.getSubmodel(submodel.getIdentification().getIdentifier())); + compareSubmodel(submodel, repository.getSubmodel(submodel.getId())); - repository.deleteSubmodel(submodel.getIdentification().getIdentifier()); - Assert.assertThrows(ResourceNotFoundException.class, () -> repository.getSubmodel(submodel.getIdentification().getIdentifier())); + repository.deleteSubmodel(submodel.getId()); + Assert.assertThrows(ResourceNotFoundException.class, () -> repository.getSubmodel(submodel.getId())); } @@ -274,12 +258,12 @@ public void deleteAASSubmodel() throws Exception { SubmodelDescriptor submodel = getSubmodel(); AssetAdministrationShellDescriptor aas = getAASWithSubmodel(); repository.create(aas); - repository.addSubmodel(aas.getIdentification().getIdentifier(), submodel); - compareSubmodel(submodel, repository.getSubmodel(aas.getIdentification().getIdentifier(), submodel.getIdentification().getIdentifier())); + repository.addSubmodel(aas.getId(), submodel); + compareSubmodel(submodel, repository.getSubmodel(aas.getId(), submodel.getId())); - repository.deleteSubmodel(aas.getIdentification().getIdentifier(), submodel.getIdentification().getIdentifier()); + repository.deleteSubmodel(aas.getId(), submodel.getId()); - Assert.assertThrows(ResourceNotFoundException.class, () -> repository.getSubmodel(aas.getIdentification().getIdentifier(), submodel.getIdentification().getIdentifier())); + Assert.assertThrows(ResourceNotFoundException.class, () -> repository.getSubmodel(aas.getId(), submodel.getId())); } diff --git a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/AasRepositoryJpa.java b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/AasRepositoryJpa.java index 05e27029..31fdcc61 100644 --- a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/AasRepositoryJpa.java +++ b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/AasRepositoryJpa.java @@ -67,8 +67,8 @@ public AssetAdministrationShellDescriptor getAAS(String aasId) throws ResourceNo @Override public AssetAdministrationShellDescriptor create(AssetAdministrationShellDescriptor descriptor) throws ResourceAlreadyExistsException { ensureDescriptorId(descriptor); - AssetAdministrationShellDescriptor aas = fetchAAS(descriptor.getIdentification().getIdentifier()); - Ensure.require(Objects.isNull(aas), buildAASAlreadyExistsException(descriptor.getIdentification().getIdentifier())); + AssetAdministrationShellDescriptor aas = fetchAAS(descriptor.getId()); + Ensure.require(Objects.isNull(aas), buildAASAlreadyExistsException(descriptor.getId())); JpaAssetAdministrationShellDescriptor result = ModelTransformationHelper.convertAAS(descriptor); entityManager.persist(result); return result; @@ -88,7 +88,7 @@ public void deleteAAS(String aasId) throws ResourceNotFoundException { public AssetAdministrationShellDescriptor update(String aasId, AssetAdministrationShellDescriptor descriptor) throws ResourceNotFoundException { ensureAasId(aasId); ensureDescriptorId(descriptor); - JpaAssetAdministrationShellDescriptor aas = fetchAAS(descriptor.getIdentification().getIdentifier()); + JpaAssetAdministrationShellDescriptor aas = fetchAAS(descriptor.getId()); Ensure.requireNonNull(aas, buildAASNotFoundException(aasId)); return entityManager.merge(new JpaAssetAdministrationShellDescriptor.Builder() .id(aas.getId()) @@ -121,9 +121,8 @@ public SubmodelDescriptor getSubmodel(String aasId, String submodelId) throws Re List submodels = aas.getSubmodels(); Optional submodel = submodels.stream() - .filter(x -> Objects.nonNull(x.getIdentification()) - && Objects.nonNull(x.getIdentification().getIdentifier()) - && Objects.equals(x.getIdentification().getIdentifier(), submodelId)) + .filter(x -> Objects.nonNull(x.getId()) + && Objects.equals(x.getId(), submodelId)) .findAny(); Ensure.require(submodel.isPresent(), buildSubmodelNotFoundInAASException(aasId, submodelId)); return submodel.get(); @@ -145,8 +144,8 @@ public SubmodelDescriptor addSubmodel(String aasId, SubmodelDescriptor descripto ensureDescriptorId(descriptor); AssetAdministrationShellDescriptor aas = fetchAAS(aasId); Ensure.requireNonNull(aas, buildAASNotFoundException(aasId)); - if (getSubmodelInternal(aas.getSubmodels(), descriptor.getIdentification().getIdentifier()).isPresent()) { - throw buildSubmodelAlreadyExistsException(descriptor.getIdentification().getIdentifier()); + if (getSubmodelInternal(aas.getSubmodels(), descriptor.getId()).isPresent()) { + throw buildSubmodelAlreadyExistsException(descriptor.getId()); } JpaSubmodelDescriptor submodel = ModelTransformationHelper.convertSubmodel(descriptor); aas.getSubmodels().add(submodel); @@ -158,8 +157,8 @@ public SubmodelDescriptor addSubmodel(String aasId, SubmodelDescriptor descripto @Override public SubmodelDescriptor addSubmodel(SubmodelDescriptor descriptor) throws ResourceAlreadyExistsException { ensureDescriptorId(descriptor); - SubmodelDescriptor submodel = fetchSubmodelStandalone(descriptor.getIdentification().getIdentifier()); - Ensure.require(Objects.isNull(submodel), buildSubmodelAlreadyExistsException(descriptor.getIdentification().getIdentifier())); + SubmodelDescriptor submodel = fetchSubmodelStandalone(descriptor.getId()); + Ensure.require(Objects.isNull(submodel), buildSubmodelAlreadyExistsException(descriptor.getId())); submodel = ModelTransformationHelper.convertSubmodelStandalone(descriptor); entityManager.persist(submodel); return submodel; @@ -173,13 +172,13 @@ public void deleteSubmodel(String aasId, String submodelId) throws ResourceNotFo AssetAdministrationShellDescriptor aas = fetchAAS(aasId); Ensure.requireNonNull(aas, buildAASNotFoundException(aasId)); Optional submodel = aas.getSubmodels().stream() - .filter(x -> Objects.equals(x.getIdentification().getIdentifier(), submodelId) - || (Objects.nonNull(x.getIdentification().getIdentifier()) - && x.getIdentification().getIdentifier().equalsIgnoreCase(submodelId))) + .filter(x -> Objects.equals(x.getId(), submodelId) + || (Objects.nonNull(x.getId()) + && x.getId().equalsIgnoreCase(submodelId))) .findAny(); Ensure.require(submodel.isPresent(), buildSubmodelNotFoundInAASException(aasId, submodelId)); entityManager.remove(aas); - aas.getSubmodels().removeIf(x -> x.getIdentification().getIdentifier().equals(submodelId)); + aas.getSubmodels().removeIf(x -> x.getId().equals(submodelId)); entityManager.persist(aas); } diff --git a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaAdministrativeInformation.java b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaAdministrativeInformation.java index 6a711e34..907defcc 100644 --- a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaAdministrativeInformation.java +++ b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaAdministrativeInformation.java @@ -15,10 +15,10 @@ package de.fraunhofer.iosb.ilt.faaast.registry.jpa.model; import com.fasterxml.jackson.annotation.JsonIgnore; -import io.adminshell.aas.v3.model.AdministrativeInformation; -import io.adminshell.aas.v3.model.builder.AdministrativeInformationBuilder; -import io.adminshell.aas.v3.model.impl.DefaultAdministrativeInformation; import java.util.Objects; +import org.eclipse.digitaltwin.aas4j.v3.model.AdministrativeInformation; +import org.eclipse.digitaltwin.aas4j.v3.model.builder.AdministrativeInformationBuilder; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultAdministrativeInformation; /** diff --git a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaAssetAdministrationShellDescriptor.java b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaAssetAdministrationShellDescriptor.java index 11b604b2..4f5e6776 100644 --- a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaAssetAdministrationShellDescriptor.java +++ b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaAssetAdministrationShellDescriptor.java @@ -14,7 +14,6 @@ */ package de.fraunhofer.iosb.ilt.faaast.registry.jpa.model; -import com.fasterxml.jackson.annotation.JsonIgnore; import de.fraunhofer.iosb.ilt.faaast.registry.jpa.util.ModelTransformationHelper; import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.AssetAdministrationShellDescriptor; import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.impl.DefaultAssetAdministrationShellDescriptor; @@ -26,69 +25,65 @@ */ public class JpaAssetAdministrationShellDescriptor extends DefaultAssetAdministrationShellDescriptor { - @JsonIgnore - private String id; + //@JsonIgnore + //private String id; public JpaAssetAdministrationShellDescriptor() { - id = null; + //id = null; } - - public String getId() { - return id; - } - - - public void setId(String id) { - this.id = id; - } - - - @Override - public int hashCode() { - return Objects.hash(super.hashCode(), id); - } - - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - else if (obj == null) { - return false; - } - else if (this.getClass() != obj.getClass()) { - return false; - } - else { - JpaAssetAdministrationShellDescriptor other = (JpaAssetAdministrationShellDescriptor) obj; - return super.equals(obj) - && Objects.equals(this.id, other.id); - } - } + //public String getId() { + // return id; + //} + + //public void setId(String id) { + // this.id = id; + //} + + //@Override + //public int hashCode() { + // return Objects.hash(super.hashCode(), id); + //} + + //@Override + //public boolean equals(Object obj) { + // if (this == obj) { + // return true; + // } + // else if (obj == null) { + // return false; + // } + // else if (this.getClass() != obj.getClass()) { + // return false; + // } + // else { + // JpaAssetAdministrationShellDescriptor other = (JpaAssetAdministrationShellDescriptor) obj; + // return super.equals(obj) + // && Objects.equals(this.id, other.id); + // } + //} public abstract static class AbstractBuilder> extends DefaultAssetAdministrationShellDescriptor.AbstractBuilder { - public B id(String value) { - getBuildingInstance().setId(value); - return getSelf(); - } - + //public B id(String value) { + // getBuildingInstance().setId(value); + // return getSelf(); + //} @Override public B from(AssetAdministrationShellDescriptor other) { if (Objects.nonNull(other)) { - id(other.getIdentification().getIdentifier()); + //id(other.getIdentification().getIdentifier()); + id(other.getId()); idShort(other.getIdShort()); endpoints(ModelTransformationHelper.convertEndpoints(other.getEndpoints())); administration(ModelTransformationHelper.convertAdministrativeInformation(other.getAdministration())); descriptions(ModelTransformationHelper.convertDescriptions(other.getDescriptions())); - displayNames(ModelTransformationHelper.convertDescriptions(other.getDisplayNames())); - identification(ModelTransformationHelper.convertIdentifier(other.getIdentification())); - globalAssetId(ModelTransformationHelper.convertReference(other.getGlobalAssetId())); - specificAssetIds(ModelTransformationHelper.convertIdentifierKeyValuePairs(other.getSpecificAssetIds())); + displayNames(ModelTransformationHelper.convertDisplayNames(other.getDisplayNames())); + //identification(ModelTransformationHelper.convertIdentifier(other.getIdentification())); + globalAssetId(other.getGlobalAssetId()); + specificAssetIds(ModelTransformationHelper.convertSpecificAssetIds(other.getSpecificAssetIds())); submodels(ModelTransformationHelper.convertSubmodels(other.getSubmodels())); } return getSelf(); diff --git a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaDescription.java b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaDescription.java index 1a704704..37c7f7e9 100644 --- a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaDescription.java +++ b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaDescription.java @@ -15,15 +15,16 @@ package de.fraunhofer.iosb.ilt.faaast.registry.jpa.model; import com.fasterxml.jackson.annotation.JsonIgnore; -import io.adminshell.aas.v3.model.LangString; -import io.adminshell.aas.v3.model.builder.ExtendableBuilder; import java.util.Objects; +import org.eclipse.digitaltwin.aas4j.v3.model.LangStringTextType; +import org.eclipse.digitaltwin.aas4j.v3.model.builder.LangStringTextTypeBuilder; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultLangStringTextType; /** * Registry Descriptor JPA implementation for Description. */ -public class JpaDescription extends LangString { +public class JpaDescription extends DefaultLangStringTextType { @JsonIgnore private String id; @@ -68,29 +69,29 @@ else if (this.getClass() != obj.getClass()) { } public abstract static class AbstractBuilder> - extends ExtendableBuilder { + extends LangStringTextTypeBuilder { + //extends ExtendableBuilder { public B id(String value) { getBuildingInstance().setId(value); return getSelf(); } - - public B value(String value) { - getBuildingInstance().setValue(value); - return getSelf(); - } - - - public B language(String value) { - getBuildingInstance().setLanguage(value); - return getSelf(); - } + // public B value(String value) { + // getBuildingInstance().setValue(value); + // return getSelf(); + // } + // + // + // public B language(String value) { + // getBuildingInstance().setLanguage(value); + // return getSelf(); + // } - public B from(LangString other) { + public B from(LangStringTextType other) { if (Objects.nonNull(other)) { - value(other.getValue()); + text(other.getText()); language(other.getLanguage()); } return getSelf(); diff --git a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaIdentifier.java b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaDisplayName.java similarity index 67% rename from persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaIdentifier.java rename to persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaDisplayName.java index 00f5cd3e..a8b52f98 100644 --- a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaIdentifier.java +++ b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaDisplayName.java @@ -15,21 +15,20 @@ package de.fraunhofer.iosb.ilt.faaast.registry.jpa.model; import com.fasterxml.jackson.annotation.JsonIgnore; -import io.adminshell.aas.v3.model.Identifier; -import io.adminshell.aas.v3.model.builder.IdentifierBuilder; -import io.adminshell.aas.v3.model.impl.DefaultIdentifier; import java.util.Objects; +import org.eclipse.digitaltwin.aas4j.v3.model.LangStringNameType; +import org.eclipse.digitaltwin.aas4j.v3.model.builder.LangStringNameTypeBuilder; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultLangStringNameType; /** - * Registry Descriptor JPA implementation for Identifier. + * Registry Descriptor JPA implementation for Display Name. */ -public class JpaIdentifier extends DefaultIdentifier { - +public class JpaDisplayName extends DefaultLangStringNameType { @JsonIgnore private String id; - public JpaIdentifier() { + public JpaDisplayName() { id = null; } @@ -62,14 +61,14 @@ else if (this.getClass() != obj.getClass()) { return false; } else { - JpaIdentifier other = (JpaIdentifier) obj; + JpaDisplayName other = (JpaDisplayName) obj; return super.equals(obj) && Objects.equals(this.id, other.id); } } - public abstract static class AbstractBuilder> - extends IdentifierBuilder { + public abstract static class AbstractBuilder> + extends LangStringNameTypeBuilder { public B id(String value) { getBuildingInstance().setId(value); @@ -77,16 +76,16 @@ public B id(String value) { } - public B from(Identifier other) { + public B from(LangStringNameType other) { if (Objects.nonNull(other)) { - identifier(other.getIdentifier()); - idType(other.getIdType()); + text(other.getText()); + language(other.getLanguage()); } return getSelf(); } } - public static class Builder extends AbstractBuilder { + public static class Builder extends AbstractBuilder { @Override protected Builder getSelf() { @@ -95,8 +94,8 @@ protected Builder getSelf() { @Override - protected JpaIdentifier newBuildingInstance() { - return new JpaIdentifier(); + protected JpaDisplayName newBuildingInstance() { + return new JpaDisplayName(); } } } diff --git a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaKey.java b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaKey.java index ffa71964..076c53f5 100644 --- a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaKey.java +++ b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaKey.java @@ -15,10 +15,10 @@ package de.fraunhofer.iosb.ilt.faaast.registry.jpa.model; import com.fasterxml.jackson.annotation.JsonIgnore; -import io.adminshell.aas.v3.model.Key; -import io.adminshell.aas.v3.model.builder.KeyBuilder; -import io.adminshell.aas.v3.model.impl.DefaultKey; import java.util.Objects; +import org.eclipse.digitaltwin.aas4j.v3.model.Key; +import org.eclipse.digitaltwin.aas4j.v3.model.builder.KeyBuilder; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultKey; /** @@ -79,7 +79,6 @@ public B id(String value) { public B from(Key other) { if (Objects.nonNull(other)) { - idType(other.getIdType()); type(other.getType()); value(other.getValue()); } diff --git a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaReference.java b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaReference.java index 13e761b3..caa116c9 100644 --- a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaReference.java +++ b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaReference.java @@ -16,10 +16,10 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import de.fraunhofer.iosb.ilt.faaast.registry.jpa.util.ModelTransformationHelper; -import io.adminshell.aas.v3.model.Reference; -import io.adminshell.aas.v3.model.builder.ReferenceBuilder; -import io.adminshell.aas.v3.model.impl.DefaultReference; import java.util.Objects; +import org.eclipse.digitaltwin.aas4j.v3.model.Reference; +import org.eclipse.digitaltwin.aas4j.v3.model.builder.ReferenceBuilder; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultReference; /** diff --git a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaIdentifierKeyValuePair.java b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaSpecificAssetId.java similarity index 69% rename from persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaIdentifierKeyValuePair.java rename to persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaSpecificAssetId.java index 01409be6..14daf5cb 100644 --- a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaIdentifierKeyValuePair.java +++ b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaSpecificAssetId.java @@ -16,21 +16,21 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import de.fraunhofer.iosb.ilt.faaast.registry.jpa.util.ModelTransformationHelper; -import io.adminshell.aas.v3.model.IdentifierKeyValuePair; -import io.adminshell.aas.v3.model.builder.IdentifierKeyValuePairBuilder; -import io.adminshell.aas.v3.model.impl.DefaultIdentifierKeyValuePair; import java.util.Objects; +import org.eclipse.digitaltwin.aas4j.v3.model.SpecificAssetId; +import org.eclipse.digitaltwin.aas4j.v3.model.builder.SpecificAssetIdBuilder; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultSpecificAssetId; /** - * Registry Descriptor JPA implementation for IdentifierKeyValuePair. + * Registry Descriptor JPA implementation for SpecificAssetId. */ -public class JpaIdentifierKeyValuePair extends DefaultIdentifierKeyValuePair { +public class JpaSpecificAssetId extends DefaultSpecificAssetId { @JsonIgnore private String id; - public JpaIdentifierKeyValuePair() { + public JpaSpecificAssetId() { id = null; } @@ -63,14 +63,14 @@ else if (this.getClass() != obj.getClass()) { return false; } else { - JpaIdentifierKeyValuePair other = (JpaIdentifierKeyValuePair) obj; + JpaSpecificAssetId other = (JpaSpecificAssetId) obj; return super.equals(obj) && Objects.equals(this.id, other.id); } } - public abstract static class AbstractBuilder> - extends IdentifierKeyValuePairBuilder { + public abstract static class AbstractBuilder> + extends SpecificAssetIdBuilder { public B id(String value) { getBuildingInstance().setId(value); @@ -78,18 +78,19 @@ public B id(String value) { } - public B from(IdentifierKeyValuePair other) { + public B from(SpecificAssetId other) { if (Objects.nonNull(other)) { semanticId(ModelTransformationHelper.convertReference(other.getSemanticId())); externalSubjectId(ModelTransformationHelper.convertReference(other.getExternalSubjectId())); - key(other.getKey()); + name(other.getName()); value(other.getValue()); + // TODO: supplementalSemanticIds } return getSelf(); } } - public static class Builder extends AbstractBuilder { + public static class Builder extends AbstractBuilder { @Override protected Builder getSelf() { @@ -98,8 +99,8 @@ protected Builder getSelf() { @Override - protected JpaIdentifierKeyValuePair newBuildingInstance() { - return new JpaIdentifierKeyValuePair(); + protected JpaSpecificAssetId newBuildingInstance() { + return new JpaSpecificAssetId(); } } } diff --git a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaSubmodelDescriptorBase.java b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaSubmodelDescriptorBase.java index 771694c7..af037dc0 100644 --- a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaSubmodelDescriptorBase.java +++ b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaSubmodelDescriptorBase.java @@ -14,11 +14,9 @@ */ package de.fraunhofer.iosb.ilt.faaast.registry.jpa.model; -import com.fasterxml.jackson.annotation.JsonIgnore; import de.fraunhofer.iosb.ilt.faaast.registry.jpa.util.ModelTransformationHelper; import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.SubmodelDescriptor; import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.impl.DefaultSubmodelDescriptor; -import java.util.Objects; /** @@ -26,67 +24,64 @@ */ public abstract class JpaSubmodelDescriptorBase extends DefaultSubmodelDescriptor { - @JsonIgnore - private String id; + //@JsonIgnore + //private String id; protected JpaSubmodelDescriptorBase() { - id = null; + // id = null; } - - public String getId() { - return id; - } - - - public void setId(String id) { - this.id = id; - } - - - @Override - public int hashCode() { - return Objects.hash(super.hashCode(), id); - } - - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - else if (obj == null) { - return false; - } - else if (this.getClass() != obj.getClass()) { - return false; - } - else { - JpaSubmodelDescriptorBase other = (JpaSubmodelDescriptorBase) obj; - return super.equals(obj) - && Objects.equals(this.id, other.id); - } - } + //public String getId() { + // return id; + //} + + //public void setId(String id) { + // this.id = id; + //} + + // @Override + // public int hashCode() { + // return Objects.hash(super.hashCode(), id); + // } + // + // + // @Override + // public boolean equals(Object obj) { + // if (this == obj) { + // return true; + // } + // else if (obj == null) { + // return false; + // } + // else if (this.getClass() != obj.getClass()) { + // return false; + // } + // else { + // JpaSubmodelDescriptorBase other = (JpaSubmodelDescriptorBase) obj; + // return super.equals(obj) + // && Objects.equals(this.id, other.id); + // } + // } public abstract static class AbstractBuilder> extends DefaultSubmodelDescriptor.AbstractBuilder { - public B id(String value) { - getBuildingInstance().setId(value); - return getSelf(); - } - + //public B id(String value) { + // getBuildingInstance().setId(value); + // return getSelf(); + //} @Override public B from(SubmodelDescriptor other) { if (other != null) { - id(other.getIdentification().getIdentifier()); + //id(other.getIdentification().getIdentifier()); + id(other.getId()); idShort(other.getIdShort()); endpoints(ModelTransformationHelper.convertEndpoints(other.getEndpoints())); administration(ModelTransformationHelper.convertAdministrativeInformation(other.getAdministration())); descriptions(ModelTransformationHelper.convertDescriptions(other.getDescriptions())); - displayNames(ModelTransformationHelper.convertDescriptions(other.getDisplayNames())); - identification(ModelTransformationHelper.convertIdentifier(other.getIdentification())); + displayNames(ModelTransformationHelper.convertDisplayNames(other.getDisplayNames())); + //identification(ModelTransformationHelper.convertIdentifier(other.getIdentification())); semanticId(ModelTransformationHelper.convertReference(other.getSemanticId())); } return getSelf(); diff --git a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/util/ModelTransformationHelper.java b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/util/ModelTransformationHelper.java index f5dc80dc..99800515 100644 --- a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/util/ModelTransformationHelper.java +++ b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/util/ModelTransformationHelper.java @@ -17,27 +17,27 @@ import de.fraunhofer.iosb.ilt.faaast.registry.jpa.model.JpaAdministrativeInformation; import de.fraunhofer.iosb.ilt.faaast.registry.jpa.model.JpaAssetAdministrationShellDescriptor; import de.fraunhofer.iosb.ilt.faaast.registry.jpa.model.JpaDescription; +import de.fraunhofer.iosb.ilt.faaast.registry.jpa.model.JpaDisplayName; import de.fraunhofer.iosb.ilt.faaast.registry.jpa.model.JpaEndpoint; -import de.fraunhofer.iosb.ilt.faaast.registry.jpa.model.JpaIdentifier; -import de.fraunhofer.iosb.ilt.faaast.registry.jpa.model.JpaIdentifierKeyValuePair; import de.fraunhofer.iosb.ilt.faaast.registry.jpa.model.JpaKey; import de.fraunhofer.iosb.ilt.faaast.registry.jpa.model.JpaProtocolInformation; import de.fraunhofer.iosb.ilt.faaast.registry.jpa.model.JpaReference; +import de.fraunhofer.iosb.ilt.faaast.registry.jpa.model.JpaSpecificAssetId; import de.fraunhofer.iosb.ilt.faaast.registry.jpa.model.JpaSubmodelDescriptor; import de.fraunhofer.iosb.ilt.faaast.registry.jpa.model.JpaSubmodelDescriptorStandalone; import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.AssetAdministrationShellDescriptor; import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.Endpoint; import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.ProtocolInformation; import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.SubmodelDescriptor; -import io.adminshell.aas.v3.model.AdministrativeInformation; -import io.adminshell.aas.v3.model.Identifier; -import io.adminshell.aas.v3.model.IdentifierKeyValuePair; -import io.adminshell.aas.v3.model.Key; -import io.adminshell.aas.v3.model.LangString; -import io.adminshell.aas.v3.model.Reference; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; +import org.eclipse.digitaltwin.aas4j.v3.model.AdministrativeInformation; +import org.eclipse.digitaltwin.aas4j.v3.model.Key; +import org.eclipse.digitaltwin.aas4j.v3.model.LangStringNameType; +import org.eclipse.digitaltwin.aas4j.v3.model.LangStringTextType; +import org.eclipse.digitaltwin.aas4j.v3.model.Reference; +import org.eclipse.digitaltwin.aas4j.v3.model.SpecificAssetId; /** @@ -80,13 +80,26 @@ public static JpaAdministrativeInformation convertAdministrativeInformation(Admi * @param descriptions The list of LangString. * @return The converted list of JPADescription. */ - public static List convertDescriptions(List descriptions) { + public static List convertDescriptions(List descriptions) { return descriptions.stream() .map(x -> new JpaDescription.Builder().from(x).build()) .collect(Collectors.toList()); } + /** + * Converts a list of LangString to a list of JPADescription. + * + * @param names The list of DisplayNames. + * @return The converted list of JPADescription. + */ + public static List convertDisplayNames(List names) { + return names.stream() + .map(x -> new JpaDisplayName.Builder().from(x).build()) + .collect(Collectors.toList()); + } + + /** * Converts a list of Endpoint to a list of JPAEndpoint. * @@ -102,30 +115,29 @@ public static List convertEndpoints(List endpoints) { .collect(Collectors.toList()); } - - /** - * Converts Identifier to JPAIdentifier. - * - * @param identifier The Identifier. - * @return The converted JPAIdentifier. - */ - public static Identifier convertIdentifier(Identifier identifier) { - return new JpaIdentifier.Builder().from(identifier).build(); - } + // /** + // * Converts Identifier to JPAIdentifier. + // * + // * @param identifier The Identifier. + // * @return The converted JPAIdentifier. + // */ + // public static Identifier convertIdentifier(Identifier identifier) { + // return new JpaIdentifier.Builder().from(identifier).build(); + // } /** - * Converts a list of IdentifierKeyValuePair to a list of JPAIdentifierKeyValuePair. + * Converts a list of SpecificAssetIds to a list of JPASpecificAssetId. * - * @param pairs The list of IdentifierKeyValuePair. - * @return The converted list of JPAIdentifierKeyValuePair. + * @param pairs The list of SpecificAssetId. + * @return The converted list of JPASpecificAssetId. */ - public static List convertIdentifierKeyValuePairs(List pairs) { + public static List convertSpecificAssetIds(List pairs) { if (Objects.isNull(pairs)) { return null; } return pairs.stream() - .map(x -> new JpaIdentifierKeyValuePair.Builder().from(x).build()) + .map(x -> new JpaSpecificAssetId.Builder().from(x).build()) .collect(Collectors.toList()); } diff --git a/persistence/memory/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/memory/AasRepositoryMemory.java b/persistence/memory/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/memory/AasRepositoryMemory.java index e6a804ae..a6dfe7c7 100644 --- a/persistence/memory/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/memory/AasRepositoryMemory.java +++ b/persistence/memory/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/memory/AasRepositoryMemory.java @@ -69,9 +69,9 @@ public AssetAdministrationShellDescriptor getAAS(String id) throws ResourceNotFo @Override public AssetAdministrationShellDescriptor create(AssetAdministrationShellDescriptor descriptor) throws ResourceAlreadyExistsException { ensureDescriptorId(descriptor); - AssetAdministrationShellDescriptor aas = fetchAAS(descriptor.getIdentification().getIdentifier()); - Ensure.require(Objects.isNull(aas), buildAASAlreadyExistsException(descriptor.getIdentification().getIdentifier())); - shellDescriptors.put(descriptor.getIdentification().getIdentifier(), descriptor); + AssetAdministrationShellDescriptor aas = fetchAAS(descriptor.getId()); + Ensure.require(Objects.isNull(aas), buildAASAlreadyExistsException(descriptor.getId())); + shellDescriptors.put(descriptor.getId(), descriptor); return descriptor; } @@ -93,7 +93,7 @@ public AssetAdministrationShellDescriptor update(String aasId, AssetAdministrati if (Objects.nonNull(oldAAS)) { shellDescriptors.remove(aasId); } - shellDescriptors.put(descriptor.getIdentification().getIdentifier(), descriptor); + shellDescriptors.put(descriptor.getId(), descriptor); return descriptor; } @@ -140,8 +140,8 @@ public SubmodelDescriptor addSubmodel(String aasId, SubmodelDescriptor descripto ensureDescriptorId(descriptor); AssetAdministrationShellDescriptor aas = fetchAAS(aasId); Ensure.requireNonNull(aas, buildAASNotFoundException(aasId)); - if (getSubmodelInternal(aas.getSubmodels(), descriptor.getIdentification().getIdentifier()).isPresent()) { - throw buildSubmodelAlreadyExistsException(descriptor.getIdentification().getIdentifier()); + if (getSubmodelInternal(aas.getSubmodels(), descriptor.getId()).isPresent()) { + throw buildSubmodelAlreadyExistsException(descriptor.getId()); } aas.getSubmodels().add(descriptor); return descriptor; @@ -152,9 +152,9 @@ public SubmodelDescriptor addSubmodel(String aasId, SubmodelDescriptor descripto public SubmodelDescriptor addSubmodel(SubmodelDescriptor descriptor) throws ResourceAlreadyExistsException { ensureDescriptorId(descriptor); Ensure.require( - !submodelDescriptors.containsKey(descriptor.getIdentification().getIdentifier()), - buildSubmodelAlreadyExistsException(descriptor.getIdentification().getIdentifier())); - submodelDescriptors.put(descriptor.getIdentification().getIdentifier(), descriptor); + !submodelDescriptors.containsKey(descriptor.getId()), + buildSubmodelAlreadyExistsException(descriptor.getId())); + submodelDescriptors.put(descriptor.getId(), descriptor); return descriptor; } @@ -165,7 +165,7 @@ public void deleteSubmodel(String aasId, String submodelId) throws ResourceNotFo ensureSubmodelId(submodelId); AssetAdministrationShellDescriptor aas = fetchAAS(aasId); Ensure.requireNonNull(aas, buildAASNotFoundException(aasId)); - boolean found = aas.getSubmodels().removeIf(x -> Objects.equals(x.getIdentification().getIdentifier(), submodelId)); + boolean found = aas.getSubmodels().removeIf(x -> Objects.equals(x.getId(), submodelId)); Ensure.require(found, buildSubmodelNotFoundException(submodelId)); submodelDescriptors.remove(submodelId); } diff --git a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/RegistryService.java b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/RegistryService.java index 6a3f8197..eb09625b 100644 --- a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/RegistryService.java +++ b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/RegistryService.java @@ -74,7 +74,7 @@ public AssetAdministrationShellDescriptor getAAS(String id) throws ResourceNotFo public AssetAdministrationShellDescriptor createAAS(AssetAdministrationShellDescriptor aas) throws ResourceAlreadyExistsException { Ensure.requireNonNull(aas, AAS_NOT_NULL_TXT); checkShellIdentifiers(aas); - LOGGER.debug("createAAS: {}", aas.getIdentification().getIdentifier()); + LOGGER.debug("createAAS: {}", aas.getId()); if (aas.getSubmodels() != null) { aas.getSubmodels().stream().forEach(this::checkSubmodelIdentifiers); } @@ -200,12 +200,12 @@ public SubmodelDescriptor createSubmodel(String aasId, SubmodelDescriptor submod Ensure.requireNonNull(submodel, SUBMODEL_NOT_NULL_TXT); checkSubmodelIdentifiers(submodel); if (aasId == null) { - LOGGER.debug("createSubmodel: Submodel {}", submodel.getIdentification().getIdentifier()); + LOGGER.debug("createSubmodel: Submodel {}", submodel.getId()); return aasRepository.addSubmodel(submodel); } else { String aasIdDecoded = decode(aasId); - LOGGER.debug("createSubmodel: AAS '{}'; Submodel {}", aasIdDecoded, submodel.getIdentification().getIdentifier()); + LOGGER.debug("createSubmodel: AAS '{}'; Submodel {}", aasIdDecoded, submodel.getId()); return aasRepository.addSubmodel(aasIdDecoded, submodel); } } @@ -290,7 +290,7 @@ private static String decode(String encoded) { private void checkSubmodelIdentifiers(SubmodelDescriptor submodel) throws BadRequestException { Ensure.requireNonNull(submodel, SUBMODEL_NOT_NULL_TXT); - if ((submodel.getIdentification() == null) || (submodel.getIdentification().getIdentifier() == null) || (submodel.getIdentification().getIdentifier().length() == 0)) { + if ((submodel.getId() == null) || (submodel.getId().length() == 0)) { throw new BadRequestException("no Submodel identification provided"); } } @@ -298,7 +298,7 @@ private void checkSubmodelIdentifiers(SubmodelDescriptor submodel) throws BadReq private void checkShellIdentifiers(AssetAdministrationShellDescriptor aas) throws BadRequestException { Ensure.requireNonNull(aas, AAS_NOT_NULL_TXT); - if ((aas.getIdentification() == null) || (aas.getIdentification().getIdentifier() == null) || (aas.getIdentification().getIdentifier().length() == 0)) { + if ((aas.getId() == null) || (aas.getId().length() == 0)) { throw new BadRequestException("no AAS Identification provided"); } } diff --git a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/config/DescriptorMapperConfig.java b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/config/DescriptorMapperConfig.java index d1a8798d..b994da87 100644 --- a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/config/DescriptorMapperConfig.java +++ b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/config/DescriptorMapperConfig.java @@ -25,16 +25,18 @@ import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.impl.DefaultEndpoint; import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.impl.DefaultProtocolInformation; import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.impl.DefaultSubmodelDescriptor; -import io.adminshell.aas.v3.model.AdministrativeInformation; -import io.adminshell.aas.v3.model.Identifier; -import io.adminshell.aas.v3.model.IdentifierKeyValuePair; -import io.adminshell.aas.v3.model.Key; -import io.adminshell.aas.v3.model.Reference; -import io.adminshell.aas.v3.model.impl.DefaultAdministrativeInformation; -import io.adminshell.aas.v3.model.impl.DefaultIdentifier; -import io.adminshell.aas.v3.model.impl.DefaultIdentifierKeyValuePair; -import io.adminshell.aas.v3.model.impl.DefaultKey; -import io.adminshell.aas.v3.model.impl.DefaultReference; +import org.eclipse.digitaltwin.aas4j.v3.model.AdministrativeInformation; +import org.eclipse.digitaltwin.aas4j.v3.model.Key; +import org.eclipse.digitaltwin.aas4j.v3.model.LangStringNameType; +import org.eclipse.digitaltwin.aas4j.v3.model.LangStringTextType; +import org.eclipse.digitaltwin.aas4j.v3.model.Reference; +import org.eclipse.digitaltwin.aas4j.v3.model.SpecificAssetId; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultAdministrativeInformation; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultKey; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultLangStringNameType; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultLangStringTextType; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultReference; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultSpecificAssetId; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; @@ -62,11 +64,13 @@ public Jackson2ObjectMapperBuilder jackson2ObjectMapperBuilder() { resolver.addMapping(AdministrativeInformation.class, DefaultAdministrativeInformation.class); resolver.addMapping(Endpoint.class, DefaultEndpoint.class); resolver.addMapping(ProtocolInformation.class, DefaultProtocolInformation.class); - resolver.addMapping(Identifier.class, DefaultIdentifier.class); - resolver.addMapping(IdentifierKeyValuePair.class, DefaultIdentifierKeyValuePair.class); + //resolver.addMapping(Identifier.class, DefaultIdentifier.class); + resolver.addMapping(SpecificAssetId.class, DefaultSpecificAssetId.class); resolver.addMapping(Key.class, DefaultKey.class); resolver.addMapping(Reference.class, DefaultReference.class); resolver.addMapping(SubmodelDescriptor.class, DefaultSubmodelDescriptor.class); + resolver.addMapping(LangStringTextType.class, DefaultLangStringTextType.class); + resolver.addMapping(LangStringNameType.class, DefaultLangStringNameType.class); module.setAbstractTypes(resolver); return new Jackson2ObjectMapperBuilder() diff --git a/service/src/main/resources/logback.xml b/service/src/main/resources/logback.xml new file mode 100644 index 00000000..81c36342 --- /dev/null +++ b/service/src/main/resources/logback.xml @@ -0,0 +1,27 @@ + + + + + + INFO + + + ${PATTERN_STDOUT} + + + + logs/App.log + false + + INFO + + + %date{dd.MM.yyyy HH:mm:ss.SSS} %-5level %logger{55}: %msg%n + + + + + + + + From 126fc2b6b4d8d5d5fa0833d5b9a6de7c3b2647a9 Mon Sep 17 00:00:00 2001 From: Tino Bischoff Date: Mon, 26 Feb 2024 12:21:58 +0100 Subject: [PATCH 10/57] update libs --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index b361ed5f..b44de4b9 100644 --- a/pom.xml +++ b/pom.xml @@ -52,7 +52,7 @@ 1.16.1 2.15.1 3.14.0 - 0.6.0-SNAPSHOT + 1.0.0-SNAPSHOT 2.2.224 6.4.4.Final 2.16.1 @@ -89,7 +89,7 @@ jacoco java fraunhofer-iosb - 3.2.2 + 3.2.3 From 49c251347036aeb76967d6ace694f6ea122f7950 Mon Sep 17 00:00:00 2001 From: Tino Bischoff Date: Mon, 26 Feb 2024 16:39:22 +0100 Subject: [PATCH 11/57] adapt ORM to changed model --- .../jpa/src/test/resources/META-INF/orm.xml | 59 ++++++++++++------- .../config/DescriptorMapperConfig.java | 3 + service/src/main/resources/META-INF/orm.xml | 59 ++++++++++++------- 3 files changed, 77 insertions(+), 44 deletions(-) diff --git a/persistence/jpa/src/test/resources/META-INF/orm.xml b/persistence/jpa/src/test/resources/META-INF/orm.xml index b965be7f..6e81fda0 100644 --- a/persistence/jpa/src/test/resources/META-INF/orm.xml +++ b/persistence/jpa/src/test/resources/META-INF/orm.xml @@ -6,12 +6,12 @@ - - + + - + @@ -32,14 +32,14 @@ - + - + @@ -63,10 +63,18 @@ - + + + + + + + + + - + - - + + - + @@ -104,7 +112,7 @@ - + @@ -122,14 +130,15 @@ - + + - io.adminshell.aas.v3.model.KeyElements + org.eclipse.digitaltwin.aas4j.v3.model.KeyTypes @@ -141,6 +150,12 @@ + + + org.eclipse.digitaltwin.aas4j.v3.model.ReferenceTypes + + + @@ -161,7 +176,7 @@ - + - - + + - + @@ -200,7 +215,7 @@ - + diff --git a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/config/DescriptorMapperConfig.java b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/config/DescriptorMapperConfig.java index b994da87..abd1cf4e 100644 --- a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/config/DescriptorMapperConfig.java +++ b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/config/DescriptorMapperConfig.java @@ -26,12 +26,14 @@ import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.impl.DefaultProtocolInformation; import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.impl.DefaultSubmodelDescriptor; import org.eclipse.digitaltwin.aas4j.v3.model.AdministrativeInformation; +import org.eclipse.digitaltwin.aas4j.v3.model.Extension; import org.eclipse.digitaltwin.aas4j.v3.model.Key; import org.eclipse.digitaltwin.aas4j.v3.model.LangStringNameType; import org.eclipse.digitaltwin.aas4j.v3.model.LangStringTextType; import org.eclipse.digitaltwin.aas4j.v3.model.Reference; import org.eclipse.digitaltwin.aas4j.v3.model.SpecificAssetId; import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultAdministrativeInformation; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultExtension; import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultKey; import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultLangStringNameType; import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultLangStringTextType; @@ -71,6 +73,7 @@ public Jackson2ObjectMapperBuilder jackson2ObjectMapperBuilder() { resolver.addMapping(SubmodelDescriptor.class, DefaultSubmodelDescriptor.class); resolver.addMapping(LangStringTextType.class, DefaultLangStringTextType.class); resolver.addMapping(LangStringNameType.class, DefaultLangStringNameType.class); + resolver.addMapping(Extension.class, DefaultExtension.class); module.setAbstractTypes(resolver); return new Jackson2ObjectMapperBuilder() diff --git a/service/src/main/resources/META-INF/orm.xml b/service/src/main/resources/META-INF/orm.xml index b965be7f..6e81fda0 100644 --- a/service/src/main/resources/META-INF/orm.xml +++ b/service/src/main/resources/META-INF/orm.xml @@ -6,12 +6,12 @@ - - + + - + @@ -32,14 +32,14 @@ - + - + @@ -63,10 +63,18 @@ - + + + + + + + + + - + - - + + - + @@ -104,7 +112,7 @@ - + @@ -122,14 +130,15 @@ - + + - io.adminshell.aas.v3.model.KeyElements + org.eclipse.digitaltwin.aas4j.v3.model.KeyTypes @@ -141,6 +150,12 @@ + + + org.eclipse.digitaltwin.aas4j.v3.model.ReferenceTypes + + + @@ -161,7 +176,7 @@ - + - - + + - + @@ -200,7 +215,7 @@ - + From f1535ca32dd6dd1fdec4f5a372fbf4ebbffecc76 Mon Sep 17 00:00:00 2001 From: Tino Bischoff Date: Mon, 26 Feb 2024 16:40:07 +0100 Subject: [PATCH 12/57] fix version incompatibilities --- service/pom.xml | 5 +++++ .../registry/service/ShellRegistryController.java | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/service/pom.xml b/service/pom.xml index b22cc70d..5a13f982 100644 --- a/service/pom.xml +++ b/service/pom.xml @@ -45,6 +45,11 @@ jackson-annotations ${jackson.version} + + com.fasterxml.jackson.core + jackson-databind + ${jackson.version} + com.h2database h2 diff --git a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/ShellRegistryController.java b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/ShellRegistryController.java index 08070514..eb23e183 100644 --- a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/ShellRegistryController.java +++ b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/ShellRegistryController.java @@ -191,4 +191,16 @@ public void deleteSubmodelOfAAS(@PathVariable("aasIdentifier") String aasIdentif throws ResourceNotFoundException { service.deleteSubmodel(aasIdentifier, submodelIdentifier); } + + // /** + // * Exception Handler for no such method error. + // * + // * @param error The error that was thrown. + // * @return error string. + // */ + // @ExceptionHandler(NoSuchMethodError.class) + // public String noSuchMethodError(NoSuchMethodError error) { + // LOGGER.error("noSuchMethodError", error); + // return "no such method"; + // } } From 3be9a8f71bcda2726ebbf5562db4a90fbdd13034 Mon Sep 17 00:00:00 2001 From: Tino Bischoff Date: Mon, 26 Feb 2024 17:43:27 +0100 Subject: [PATCH 13/57] add more properties --- .../model/JpaEmbeddedDataSpecification.java | 103 ++++++++++++++++++ .../jpa/src/test/resources/META-INF/orm.xml | 29 ++++- service/src/main/resources/META-INF/orm.xml | 29 ++++- 3 files changed, 159 insertions(+), 2 deletions(-) create mode 100644 persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaEmbeddedDataSpecification.java diff --git a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaEmbeddedDataSpecification.java b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaEmbeddedDataSpecification.java new file mode 100644 index 00000000..6901b985 --- /dev/null +++ b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaEmbeddedDataSpecification.java @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2021 Fraunhofer IOSB, eine rechtlich nicht selbstaendige + * Einrichtung der Fraunhofer-Gesellschaft zur Foerderung der angewandten + * Forschung e.V. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package de.fraunhofer.iosb.ilt.faaast.registry.jpa.model; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import de.fraunhofer.iosb.ilt.faaast.registry.jpa.util.ModelTransformationHelper; +import java.util.Objects; +import org.eclipse.digitaltwin.aas4j.v3.model.EmbeddedDataSpecification; +import org.eclipse.digitaltwin.aas4j.v3.model.builder.EmbeddedDataSpecificationBuilder; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultEmbeddedDataSpecification; + + +/** + * Registry Descriptor JPA implementation for JpaEmbeddedDataSpecification. + */ +public class JpaEmbeddedDataSpecification extends DefaultEmbeddedDataSpecification { + + @JsonIgnore + private String id; + + public JpaEmbeddedDataSpecification() { + id = null; + } + + + public String getId() { + return id; + } + + + public void setId(String id) { + this.id = id; + } + + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), id); + } + + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + else if (obj == null) { + return false; + } + else if (this.getClass() != obj.getClass()) { + return false; + } + else { + JpaEmbeddedDataSpecification other = (JpaEmbeddedDataSpecification) obj; + return super.equals(obj) + && Objects.equals(this.id, other.id); + } + } + + public abstract static class AbstractBuilder> + extends EmbeddedDataSpecificationBuilder { + + public B id(String value) { + getBuildingInstance().setId(value); + return getSelf(); + } + + + public B from(EmbeddedDataSpecification other) { + if (Objects.nonNull(other)) { + dataSpecification(ModelTransformationHelper.convertReference(other.getDataSpecification())); + // TODO: dataSpecificationContent + } + return getSelf(); + } + } + + public static class Builder extends AbstractBuilder { + + @Override + protected Builder getSelf() { + return this; + } + + + @Override + protected JpaEmbeddedDataSpecification newBuildingInstance() { + return new JpaEmbeddedDataSpecification(); + } + } +} diff --git a/persistence/jpa/src/test/resources/META-INF/orm.xml b/persistence/jpa/src/test/resources/META-INF/orm.xml index 6e81fda0..f8753aa6 100644 --- a/persistence/jpa/src/test/resources/META-INF/orm.xml +++ b/persistence/jpa/src/test/resources/META-INF/orm.xml @@ -10,12 +10,20 @@ + + + + + org.eclipse.digitaltwin.aas4j.v3.model.AssetKind + + + - + @@ -123,6 +131,16 @@ + + + + + + + + + + @@ -219,4 +237,13 @@ + + + + + + + + + diff --git a/service/src/main/resources/META-INF/orm.xml b/service/src/main/resources/META-INF/orm.xml index 6e81fda0..f8753aa6 100644 --- a/service/src/main/resources/META-INF/orm.xml +++ b/service/src/main/resources/META-INF/orm.xml @@ -10,12 +10,20 @@ + + + + + org.eclipse.digitaltwin.aas4j.v3.model.AssetKind + + + - + @@ -123,6 +131,16 @@ + + + + + + + + + + @@ -219,4 +237,13 @@ + + + + + + + + + From ab79fe0cb6f4859c86fb54d63f607a6a91bce299 Mon Sep 17 00:00:00 2001 From: Tino Bischoff Date: Tue, 27 Feb 2024 11:19:47 +0100 Subject: [PATCH 14/57] add extensions --- .../registry/jpa/model/JpaExtension.java | 107 ++++++++++++++++++ .../jpa/util/ModelTransformationHelper.java | 16 +++ .../jpa/src/test/resources/META-INF/orm.xml | 48 ++++++++ service/src/main/resources/META-INF/orm.xml | 48 ++++++++ 4 files changed, 219 insertions(+) create mode 100644 persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaExtension.java diff --git a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaExtension.java b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaExtension.java new file mode 100644 index 00000000..eb36b045 --- /dev/null +++ b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaExtension.java @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2021 Fraunhofer IOSB, eine rechtlich nicht selbstaendige + * Einrichtung der Fraunhofer-Gesellschaft zur Foerderung der angewandten + * Forschung e.V. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package de.fraunhofer.iosb.ilt.faaast.registry.jpa.model; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import de.fraunhofer.iosb.ilt.faaast.registry.jpa.util.ModelTransformationHelper; +import java.util.Objects; +import org.eclipse.digitaltwin.aas4j.v3.model.Extension; +import org.eclipse.digitaltwin.aas4j.v3.model.builder.ExtensionBuilder; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultExtension; + + +/** + * Registry Descriptor JPA implementation for Extension. + */ +public class JpaExtension extends DefaultExtension { + + @JsonIgnore + private String id; + + public JpaExtension() { + id = null; + } + + + public String getId() { + return id; + } + + + public void setId(String id) { + this.id = id; + } + + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), id); + } + + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + else if (obj == null) { + return false; + } + else if (this.getClass() != obj.getClass()) { + return false; + } + else { + JpaExtension other = (JpaExtension) obj; + return super.equals(obj) + && Objects.equals(this.id, other.id); + } + } + + public abstract static class AbstractBuilder> + extends ExtensionBuilder { + + public B id(String value) { + getBuildingInstance().setId(value); + return getSelf(); + } + + + public B from(Extension other) { + if (Objects.nonNull(other)) { + semanticId(ModelTransformationHelper.convertReference(other.getSemanticId())); + supplementalSemanticIds(ModelTransformationHelper.convertReferences(other.getSupplementalSemanticIds())); + name(other.getName()); + valueType(other.getValueType()); + value(other.getValue()); + refersTo(ModelTransformationHelper.convertReferences(other.getRefersTo())); + } + return getSelf(); + } + } + + public static class Builder extends AbstractBuilder { + + @Override + protected Builder getSelf() { + return this; + } + + + @Override + protected JpaExtension newBuildingInstance() { + return new JpaExtension(); + } + } +} diff --git a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/util/ModelTransformationHelper.java b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/util/ModelTransformationHelper.java index 99800515..be90df05 100644 --- a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/util/ModelTransformationHelper.java +++ b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/util/ModelTransformationHelper.java @@ -182,6 +182,22 @@ public static JpaReference convertReference(Reference reference) { } + /** + * Converts Reference to JPAReference. + * + * @param references The list of References. + * @return The converted list of References. + */ + public static List convertReferences(List references) { + if (Objects.isNull(references)) { + return null; + } + return references.stream() + .map(x -> new JpaReference.Builder().from(x).build()) + .collect(Collectors.toList()); + } + + /** * Converts SubmodelDescriptor to JPASubmodelDescriptor. * diff --git a/persistence/jpa/src/test/resources/META-INF/orm.xml b/persistence/jpa/src/test/resources/META-INF/orm.xml index f8753aa6..ba48c3ca 100644 --- a/persistence/jpa/src/test/resources/META-INF/orm.xml +++ b/persistence/jpa/src/test/resources/META-INF/orm.xml @@ -55,6 +55,12 @@ + + + + + + @@ -122,6 +128,13 @@ + + + + + + + @@ -235,6 +248,12 @@ + + + + + + @@ -246,4 +265,33 @@ + + + + + + + + + + + + + + + + + org.eclipse.digitaltwin.aas4j.v3.model.DataTypeDefXsd + + + + + + + + + + + + diff --git a/service/src/main/resources/META-INF/orm.xml b/service/src/main/resources/META-INF/orm.xml index f8753aa6..ba48c3ca 100644 --- a/service/src/main/resources/META-INF/orm.xml +++ b/service/src/main/resources/META-INF/orm.xml @@ -55,6 +55,12 @@ + + + + + + @@ -122,6 +128,13 @@ + + + + + + + @@ -235,6 +248,12 @@ + + + + + + @@ -246,4 +265,33 @@ + + + + + + + + + + + + + + + + + org.eclipse.digitaltwin.aas4j.v3.model.DataTypeDefXsd + + + + + + + + + + + + From 8746e77b54fcb350113128b206c058e847315ac9 Mon Sep 17 00:00:00 2001 From: Tino Bischoff Date: Tue, 27 Feb 2024 12:15:06 +0100 Subject: [PATCH 15/57] Add SupplementalSemanticId to SubmodelDescriptor --- ...JpaAssetAdministrationShellDescriptor.java | 3 +- .../registry/jpa/model/JpaReference.java | 2 ++ .../jpa/model/JpaSpecificAssetId.java | 4 +-- .../jpa/model/JpaSubmodelDescriptorBase.java | 4 +-- .../jpa/util/ModelTransformationHelper.java | 31 +++++++++++++++++++ .../jpa/src/test/resources/META-INF/orm.xml | 17 +++++++++- service/src/main/resources/META-INF/orm.xml | 17 +++++++++- 7 files changed, 70 insertions(+), 8 deletions(-) diff --git a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaAssetAdministrationShellDescriptor.java b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaAssetAdministrationShellDescriptor.java index 4f5e6776..3a4c8c86 100644 --- a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaAssetAdministrationShellDescriptor.java +++ b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaAssetAdministrationShellDescriptor.java @@ -74,16 +74,15 @@ public abstract static class AbstractBuilder convertSubmodels(List .collect(Collectors.toList()); } + + /** + * Converts Extension to JPAExtension. + * + * @param extension The Extension. + * @return The converted JPAExtension. + */ + public static JpaExtension convertExtension(Extension extension) { + return new JpaExtension.Builder() + .from(extension) + .build(); + } + + + /** + * Converts Extension to JPAExtension. + * + * @param extensions The list of Extensions. + * @return The converted list of Extensions. + */ + public static List convertExtensions(List extensions) { + if (Objects.isNull(extensions)) { + return null; + } + return extensions.stream() + .map(x -> new JpaExtension.Builder().from(x).build()) + .collect(Collectors.toList()); + } + } diff --git a/persistence/jpa/src/test/resources/META-INF/orm.xml b/persistence/jpa/src/test/resources/META-INF/orm.xml index ba48c3ca..10f56714 100644 --- a/persistence/jpa/src/test/resources/META-INF/orm.xml +++ b/persistence/jpa/src/test/resources/META-INF/orm.xml @@ -134,7 +134,13 @@ - + + + + + + + @@ -192,6 +198,8 @@ + + @@ -254,6 +262,13 @@ + + + + + + + diff --git a/service/src/main/resources/META-INF/orm.xml b/service/src/main/resources/META-INF/orm.xml index ba48c3ca..10f56714 100644 --- a/service/src/main/resources/META-INF/orm.xml +++ b/service/src/main/resources/META-INF/orm.xml @@ -134,7 +134,13 @@ - + + + + + + + @@ -192,6 +198,8 @@ + + @@ -254,6 +262,13 @@ + + + + + + + From 65c661d9421c3f0380fe91f444e0116e672dfb4a Mon Sep 17 00:00:00 2001 From: Tino Bischoff Date: Tue, 27 Feb 2024 12:59:46 +0100 Subject: [PATCH 16/57] Extension: avoid reserved names --- persistence/jpa/src/test/resources/META-INF/orm.xml | 6 +++--- service/src/main/resources/META-INF/orm.xml | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/persistence/jpa/src/test/resources/META-INF/orm.xml b/persistence/jpa/src/test/resources/META-INF/orm.xml index 10f56714..a82c4756 100644 --- a/persistence/jpa/src/test/resources/META-INF/orm.xml +++ b/persistence/jpa/src/test/resources/META-INF/orm.xml @@ -280,7 +280,7 @@ - + @@ -293,13 +293,13 @@ - + org.eclipse.digitaltwin.aas4j.v3.model.DataTypeDefXsd - + diff --git a/service/src/main/resources/META-INF/orm.xml b/service/src/main/resources/META-INF/orm.xml index 10f56714..a82c4756 100644 --- a/service/src/main/resources/META-INF/orm.xml +++ b/service/src/main/resources/META-INF/orm.xml @@ -280,7 +280,7 @@ - + @@ -293,13 +293,13 @@ - + org.eclipse.digitaltwin.aas4j.v3.model.DataTypeDefXsd - + From 69ee8602e2ae89f8c62c4057e3ca5fa599be6e2c Mon Sep 17 00:00:00 2001 From: Tino Bischoff Date: Tue, 27 Feb 2024 13:54:10 +0100 Subject: [PATCH 17/57] change API URL --- .../ilt/faaast/registry/service/ShellRegistryController.java | 2 +- .../ilt/faaast/registry/service/SubmodelRegistryController.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/ShellRegistryController.java b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/ShellRegistryController.java index eb23e183..e5363641 100644 --- a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/ShellRegistryController.java +++ b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/ShellRegistryController.java @@ -36,7 +36,7 @@ * REST controller for the Asset Administration Shell registry. */ @RestController -@RequestMapping("/registry/shell-descriptors") +@RequestMapping("/api/v3.0/shell-descriptors") public class ShellRegistryController { @Autowired diff --git a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/SubmodelRegistryController.java b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/SubmodelRegistryController.java index f47e2b0d..8a2909d1 100644 --- a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/SubmodelRegistryController.java +++ b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/SubmodelRegistryController.java @@ -35,7 +35,7 @@ * REST controller for the Submodel registry. */ @RestController -@RequestMapping(value = "/registry/submodel-descriptors") +@RequestMapping(value = "/api/v3.0/submodel-descriptors") public class SubmodelRegistryController { @Autowired From 6fa941026faf46e367be4e6bfac9440c78c58b4e Mon Sep 17 00:00:00 2001 From: Tino Bischoff Date: Tue, 27 Feb 2024 15:44:14 +0100 Subject: [PATCH 18/57] add Location Header --- .../registry/service/RegistryService.java | 31 +++++------ .../service/ShellRegistryController.java | 26 +++++++--- .../service/SubmodelRegistryController.java | 14 +++-- .../src/main/java/helper/RegistryHelper.java | 51 +++++++++++++++++++ 4 files changed, 94 insertions(+), 28 deletions(-) create mode 100644 service/src/main/java/helper/RegistryHelper.java diff --git a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/RegistryService.java b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/RegistryService.java index eb09625b..93cb9626 100644 --- a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/RegistryService.java +++ b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/RegistryService.java @@ -21,7 +21,7 @@ import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.AssetAdministrationShellDescriptor; import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.SubmodelDescriptor; import de.fraunhofer.iosb.ilt.faaast.service.util.Ensure; -import java.util.Base64; +import helper.RegistryHelper; import java.util.List; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -60,7 +60,7 @@ public List getAASs() { * @throws ResourceNotFoundException When the AAS was not found. */ public AssetAdministrationShellDescriptor getAAS(String id) throws ResourceNotFoundException { - return aasRepository.getAAS(decode(id)); + return aasRepository.getAAS(RegistryHelper.decode(id)); } @@ -89,7 +89,7 @@ public AssetAdministrationShellDescriptor createAAS(AssetAdministrationShellDesc * @throws ResourceNotFoundException When the AAS was not found. */ public void deleteAAS(String id) throws ResourceNotFoundException { - String idDecoded = decode(id); + String idDecoded = RegistryHelper.decode(id); LOGGER.debug("deleteAAS: AAS {}", idDecoded); aasRepository.deleteAAS(idDecoded); } @@ -105,7 +105,7 @@ public void deleteAAS(String id) throws ResourceNotFoundException { */ public AssetAdministrationShellDescriptor updateAAS(String id, AssetAdministrationShellDescriptor aas) throws ResourceNotFoundException { Ensure.requireNonNull(aas, AAS_NOT_NULL_TXT); - String idDecoded = decode(id); + String idDecoded = RegistryHelper.decode(id); LOGGER.debug("updateAAS: {}", idDecoded); checkShellIdentifiers(aas); aas.getSubmodels().stream().forEach(this::checkSubmodelIdentifiers); @@ -136,7 +136,7 @@ public List getSubmodels(String aasId) throws ResourceNotFou return aasRepository.getSubmodels(); } else { - String aasIdDecoded = decode(aasId); + String aasIdDecoded = RegistryHelper.decode(aasId); return aasRepository.getSubmodels(aasIdDecoded); } } @@ -163,12 +163,12 @@ public SubmodelDescriptor getSubmodel(String submodelId) throws ResourceNotFound * @throws ResourceNotFoundException When the AAS or Submodel was not found. */ public SubmodelDescriptor getSubmodel(String aasId, String submodelId) throws ResourceNotFoundException { - String submodelIdDecoded = decode(submodelId); + String submodelIdDecoded = RegistryHelper.decode(submodelId); if (aasId == null) { return aasRepository.getSubmodel(submodelIdDecoded); } else { - String aasIdDecoded = decode(aasId); + String aasIdDecoded = RegistryHelper.decode(aasId); return aasRepository.getSubmodel(aasIdDecoded, submodelIdDecoded); } } @@ -204,7 +204,7 @@ public SubmodelDescriptor createSubmodel(String aasId, SubmodelDescriptor submod return aasRepository.addSubmodel(submodel); } else { - String aasIdDecoded = decode(aasId); + String aasIdDecoded = RegistryHelper.decode(aasId); LOGGER.debug("createSubmodel: AAS '{}'; Submodel {}", aasIdDecoded, submodel.getId()); return aasRepository.addSubmodel(aasIdDecoded, submodel); } @@ -230,13 +230,13 @@ public void deleteSubmodel(String submodelId) throws ResourceNotFoundException { * @throws ResourceNotFoundException When the Submodel was not found. */ public void deleteSubmodel(String aasId, String submodelId) throws ResourceNotFoundException { - String submodelIdDecoded = decode(submodelId); + String submodelIdDecoded = RegistryHelper.decode(submodelId); if (aasId == null) { LOGGER.debug("deleteSubmodel: Submodel {}", submodelIdDecoded); aasRepository.deleteSubmodel(submodelIdDecoded); } else { - String aasIdDecoded = decode(aasId); + String aasIdDecoded = RegistryHelper.decode(aasId); LOGGER.debug("deleteSubmodel: AAS '{}'; Submodel {}", aasIdDecoded, submodelIdDecoded); aasRepository.deleteSubmodel(aasIdDecoded, submodelIdDecoded); } @@ -254,7 +254,7 @@ public void deleteSubmodel(String aasId, String submodelId) throws ResourceNotFo */ public SubmodelDescriptor updateSubmodel(String submodelId, SubmodelDescriptor submodel) throws ResourceNotFoundException, ResourceAlreadyExistsException { Ensure.requireNonNull(submodel, SUBMODEL_NOT_NULL_TXT); - String submodelIdDecoded = decode(submodelId); + String submodelIdDecoded = RegistryHelper.decode(submodelId); checkSubmodelIdentifiers(submodel); LOGGER.debug("updateSubmodel: Submodel {}", submodelIdDecoded); aasRepository.deleteSubmodel(submodelIdDecoded); @@ -274,8 +274,8 @@ public SubmodelDescriptor updateSubmodel(String submodelId, SubmodelDescriptor s */ public SubmodelDescriptor updateSubmodel(String aasId, String submodelId, SubmodelDescriptor submodel) throws ResourceNotFoundException, ResourceAlreadyExistsException { Ensure.requireNonNull(submodel, SUBMODEL_NOT_NULL_TXT); - String aasIdDecoded = decode(aasId); - String submodelIdDecoded = decode(submodelId); + String aasIdDecoded = RegistryHelper.decode(aasId); + String submodelIdDecoded = RegistryHelper.decode(submodelId); checkSubmodelIdentifiers(submodel); LOGGER.debug("updateSubmodel: AAS '{}'; Submodel {}", aasIdDecoded, submodelIdDecoded); aasRepository.deleteSubmodel(aasIdDecoded, submodelIdDecoded); @@ -283,11 +283,6 @@ public SubmodelDescriptor updateSubmodel(String aasId, String submodelId, Submod } - private static String decode(String encoded) { - return new String(Base64.getUrlDecoder().decode(encoded)); - } - - private void checkSubmodelIdentifiers(SubmodelDescriptor submodel) throws BadRequestException { Ensure.requireNonNull(submodel, SUBMODEL_NOT_NULL_TXT); if ((submodel.getId() == null) || (submodel.getId().length() == 0)) { diff --git a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/ShellRegistryController.java b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/ShellRegistryController.java index e5363641..e6d11e3c 100644 --- a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/ShellRegistryController.java +++ b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/ShellRegistryController.java @@ -18,9 +18,12 @@ import de.fraunhofer.iosb.ilt.faaast.registry.core.exception.ResourceNotFoundException; import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.AssetAdministrationShellDescriptor; import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.SubmodelDescriptor; +import helper.RegistryHelper; +import java.net.URI; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -30,6 +33,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.servlet.support.ServletUriComponentsBuilder; /** @@ -74,9 +78,13 @@ public AssetAdministrationShellDescriptor getAAS(@PathVariable("aasIdentifier") * @throws ResourceAlreadyExistsException When the AAS already exists. */ @PostMapping() - @ResponseStatus(HttpStatus.CREATED) - public AssetAdministrationShellDescriptor create(@RequestBody AssetAdministrationShellDescriptor resource) throws ResourceAlreadyExistsException { - return service.createAAS(resource); + public ResponseEntity create(@RequestBody AssetAdministrationShellDescriptor resource) throws ResourceAlreadyExistsException { + AssetAdministrationShellDescriptor aas = service.createAAS(resource); + URI location = ServletUriComponentsBuilder + .fromCurrentRequest() + .path(String.format("/%s", RegistryHelper.encode(aas.getId()))) + .build().toUri(); + return ResponseEntity.created(location).body(aas); } @@ -149,11 +157,15 @@ public SubmodelDescriptor getSubmodelOfAAS(@PathVariable("aasIdentifier") String * @throws ResourceAlreadyExistsException When the Submodel already exists. */ @PostMapping(value = "/{aasIdentifier}/submodel-descriptors") - @ResponseStatus(HttpStatus.CREATED) - public SubmodelDescriptor create(@PathVariable("aasIdentifier") String aasIdentifier, - @RequestBody SubmodelDescriptor submodel) + public ResponseEntity create(@PathVariable("aasIdentifier") String aasIdentifier, + @RequestBody SubmodelDescriptor submodel) throws ResourceNotFoundException, ResourceAlreadyExistsException { - return service.createSubmodel(aasIdentifier, submodel); + SubmodelDescriptor descriptor = service.createSubmodel(aasIdentifier, submodel); + URI location = ServletUriComponentsBuilder + .fromCurrentRequest() + .path(String.format("/%s", RegistryHelper.encode(descriptor.getId()))) + .build().toUri(); + return ResponseEntity.created(location).body(descriptor); } diff --git a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/SubmodelRegistryController.java b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/SubmodelRegistryController.java index 8a2909d1..13289a51 100644 --- a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/SubmodelRegistryController.java +++ b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/SubmodelRegistryController.java @@ -17,9 +17,12 @@ import de.fraunhofer.iosb.ilt.faaast.registry.core.exception.ResourceAlreadyExistsException; import de.fraunhofer.iosb.ilt.faaast.registry.core.exception.ResourceNotFoundException; import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.SubmodelDescriptor; +import helper.RegistryHelper; +import java.net.URI; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -29,6 +32,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.servlet.support.ServletUriComponentsBuilder; /** @@ -75,9 +79,13 @@ public SubmodelDescriptor getSubmodel(@PathVariable("submodelIdentifier") String * @throws ResourceAlreadyExistsException When the Submodel already exists. */ @PostMapping - @ResponseStatus(HttpStatus.CREATED) - public SubmodelDescriptor createSubmodel(@RequestBody SubmodelDescriptor submodel) throws ResourceNotFoundException, ResourceAlreadyExistsException { - return service.createSubmodel(submodel); + public ResponseEntity createSubmodel(@RequestBody SubmodelDescriptor submodel) throws ResourceNotFoundException, ResourceAlreadyExistsException { + SubmodelDescriptor descriptor = service.createSubmodel(submodel); + URI location = ServletUriComponentsBuilder + .fromCurrentRequest() + .path(String.format("/%s", RegistryHelper.encode(descriptor.getId()))) + .build().toUri(); + return ResponseEntity.created(location).body(descriptor); } diff --git a/service/src/main/java/helper/RegistryHelper.java b/service/src/main/java/helper/RegistryHelper.java new file mode 100644 index 00000000..dc9ac831 --- /dev/null +++ b/service/src/main/java/helper/RegistryHelper.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2021 Fraunhofer IOSB, eine rechtlich nicht selbstaendige + * Einrichtung der Fraunhofer-Gesellschaft zur Foerderung der angewandten + * Forschung e.V. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package helper; + +import de.fraunhofer.iosb.ilt.faaast.service.util.Ensure; +import java.util.Base64; + + +/** + * Class with helper methods for the Registry. + */ +public class RegistryHelper { + + private RegistryHelper() {} + + + /** + * Decodes the given Base64 URL encoded value. + * + * @param encoded The Base64 URL encoded value. + * @return The decoded value. + */ + public static String decode(String encoded) { + return new String(Base64.getUrlDecoder().decode(encoded)); + } + + + /** + * Encodes the given value with a Base64 URL encoding. + * + * @param value The desired value. + * @return The Base64URL encoded value. + */ + public static String encode(String value) { + Ensure.requireNonNull(value); + return new String(Base64.getUrlEncoder().encode(value.getBytes())); + } + +} From 3160388293e8382d46141c5779e78f83bec83773 Mon Sep 17 00:00:00 2001 From: Tino Bischoff Date: Wed, 28 Feb 2024 12:19:22 +0100 Subject: [PATCH 19/57] change Enum handling --- .../registry/service/config/DescriptorMapperConfig.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/config/DescriptorMapperConfig.java b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/config/DescriptorMapperConfig.java index abd1cf4e..f4857b77 100644 --- a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/config/DescriptorMapperConfig.java +++ b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/config/DescriptorMapperConfig.java @@ -25,6 +25,9 @@ import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.impl.DefaultEndpoint; import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.impl.DefaultProtocolInformation; import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.impl.DefaultSubmodelDescriptor; +import org.eclipse.digitaltwin.aas4j.v3.dataformat.core.internal.deserialization.EnumDeserializer; +import org.eclipse.digitaltwin.aas4j.v3.dataformat.core.internal.serialization.EnumSerializer; +import org.eclipse.digitaltwin.aas4j.v3.dataformat.core.internal.util.ReflectionHelper; import org.eclipse.digitaltwin.aas4j.v3.model.AdministrativeInformation; import org.eclipse.digitaltwin.aas4j.v3.model.Extension; import org.eclipse.digitaltwin.aas4j.v3.model.Key; @@ -75,6 +78,9 @@ public Jackson2ObjectMapperBuilder jackson2ObjectMapperBuilder() { resolver.addMapping(LangStringNameType.class, DefaultLangStringNameType.class); resolver.addMapping(Extension.class, DefaultExtension.class); + ReflectionHelper.ENUMS.forEach(x -> module.addSerializer(x, new EnumSerializer())); + ReflectionHelper.ENUMS.forEach(x -> module.addDeserializer(x, new EnumDeserializer(x))); + module.setAbstractTypes(resolver); return new Jackson2ObjectMapperBuilder() .modules(module); From ac09dc603cf5f54356821ea15492915dbbac795b Mon Sep 17 00:00:00 2001 From: Tino Bischoff Date: Wed, 28 Feb 2024 15:58:41 +0100 Subject: [PATCH 20/57] start adding request parameter --- .../faaast/registry/core/AasRepository.java | 11 +++++++ .../registry/core/AbstractAasRepository.java | 6 ++++ .../faaast/registry/jpa/AasRepositoryJpa.java | 4 ++- .../registry/memory/AasRepositoryMemory.java | 31 +++++++++++++++-- .../registry/service/RegistryService.java | 7 ++-- .../service/ShellRegistryController.java | 15 +++++++-- .../service/config/ControllerConfig.java | 33 +++++++++++++++++++ .../main/java/helper/AssetKindConverter.java | 30 +++++++++++++++++ .../src/main/java/helper/RegistryHelper.java | 3 ++ service/src/main/resources/logback.xml | 2 +- 10 files changed, 134 insertions(+), 8 deletions(-) create mode 100644 service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/config/ControllerConfig.java create mode 100644 service/src/main/java/helper/AssetKindConverter.java diff --git a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/core/AasRepository.java b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/core/AasRepository.java index 417cb334..442b211c 100644 --- a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/core/AasRepository.java +++ b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/core/AasRepository.java @@ -19,6 +19,7 @@ import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.AssetAdministrationShellDescriptor; import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.SubmodelDescriptor; import java.util.List; +import org.eclipse.digitaltwin.aas4j.v3.model.AssetKind; /** @@ -34,6 +35,16 @@ public interface AasRepository { public List getAASs(); + /** + * Retrieves a list of all registered Asset Administration Shells which meet the given conditions. + * + * @param assetType The desired Asset Type. + * @param assetKind The desired Asset Kind. + * @return The list of all registered Asset Administration Shells. + */ + public List getAASs(String assetType, AssetKind assetKind); + + /** * Retrieves the Asset Administration Shell with the given ID. * diff --git a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/core/AbstractAasRepository.java b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/core/AbstractAasRepository.java index ef143e74..54d1c63b 100644 --- a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/core/AbstractAasRepository.java +++ b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/core/AbstractAasRepository.java @@ -32,6 +32,12 @@ public abstract class AbstractAasRepository implements AasRepository { protected AbstractAasRepository() {} + @Override + public List getAASs() { + return getAASs(null, null); + } + + /** * Creates a new {@link ResourceNotFoundException} for the AAS. * diff --git a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/AasRepositoryJpa.java b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/AasRepositoryJpa.java index 31fdcc61..a616d252 100644 --- a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/AasRepositoryJpa.java +++ b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/AasRepositoryJpa.java @@ -31,6 +31,7 @@ import java.util.List; import java.util.Objects; import java.util.Optional; +import org.eclipse.digitaltwin.aas4j.v3.model.AssetKind; import org.springframework.stereotype.Repository; @@ -50,7 +51,8 @@ public AasRepositoryJpa(EntityManager entityManager) { @Override - public List getAASs() { + public List getAASs(String assetType, AssetKind assetKind) { + // TODO filter results return EntityManagerHelper.getAll(entityManager, JpaAssetAdministrationShellDescriptor.class, AssetAdministrationShellDescriptor.class); } diff --git a/persistence/memory/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/memory/AasRepositoryMemory.java b/persistence/memory/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/memory/AasRepositoryMemory.java index a6dfe7c7..2e2bb073 100644 --- a/persistence/memory/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/memory/AasRepositoryMemory.java +++ b/persistence/memory/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/memory/AasRepositoryMemory.java @@ -26,6 +26,8 @@ import java.util.Map; import java.util.Objects; import java.util.Optional; +import java.util.stream.Collectors; +import org.eclipse.digitaltwin.aas4j.v3.model.AssetKind; /** @@ -52,8 +54,9 @@ public void clear() { @Override - public List getAASs() { - return new ArrayList<>(shellDescriptors.values()); + public List getAASs(String assetType, AssetKind assetKind) { + return new ArrayList<>( + shellDescriptors.values().stream().filter(a -> filterAssetType(a, assetType)).filter(b -> filterAssetKind(b, assetKind)).collect(Collectors.toList())); } @@ -183,4 +186,28 @@ private AssetAdministrationShellDescriptor fetchAAS(String aasId) { ensureAasId(aasId); return shellDescriptors.getOrDefault(aasId, null); } + + + private static boolean filterAssetType(AssetAdministrationShellDescriptor aas, String assetType) { + boolean retval; + if (assetType == null) { + retval = true; + } + else { + retval = aas.getAssetType().equals(assetType); + } + return retval; + } + + + private static boolean filterAssetKind(AssetAdministrationShellDescriptor aas, AssetKind assetKind) { + boolean retval; + if (assetKind == null) { + retval = true; + } + else { + retval = aas.getAssetKind() == assetKind; + } + return retval; + } } diff --git a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/RegistryService.java b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/RegistryService.java index 93cb9626..e2e34161 100644 --- a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/RegistryService.java +++ b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/RegistryService.java @@ -23,6 +23,7 @@ import de.fraunhofer.iosb.ilt.faaast.service.util.Ensure; import helper.RegistryHelper; import java.util.List; +import org.eclipse.digitaltwin.aas4j.v3.model.AssetKind; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -45,10 +46,12 @@ public class RegistryService { /** * Retrieves a list of all registered Asset Administration Shells. * + * @param assetType The desired Asset Type. + * @param assetKind The desired Asset Kind. * @return The list of all registered Asset Administration Shells. */ - public List getAASs() { - return aasRepository.getAASs(); + public List getAASs(String assetType, AssetKind assetKind) { + return aasRepository.getAASs(RegistryHelper.decode(assetType), assetKind); } diff --git a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/ShellRegistryController.java b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/ShellRegistryController.java index e6d11e3c..b3d9a5c9 100644 --- a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/ShellRegistryController.java +++ b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/ShellRegistryController.java @@ -21,6 +21,9 @@ import helper.RegistryHelper; import java.net.URI; import java.util.List; +import org.eclipse.digitaltwin.aas4j.v3.model.AssetKind; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -31,6 +34,7 @@ import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.servlet.support.ServletUriComponentsBuilder; @@ -43,17 +47,24 @@ @RequestMapping("/api/v3.0/shell-descriptors") public class ShellRegistryController { + private static final Logger LOGGER = LoggerFactory.getLogger(ShellRegistryController.class); + @Autowired RegistryService service; /** * Retrieves a list of all registered Asset Administration Shells. * + * @param assetType The desired Asset Type. + * @param assetKind The desired Asset Kind. * @return The list of all registered Asset Administration Shells. */ @GetMapping() - public List getAASs() { - return service.getAASs(); + public List getAASs(@RequestParam(name = "assetType", required = false) String assetType, + @RequestParam(name = "assetKind", required = false) AssetKind assetKind) { + // Asset type is Base64URL encoded + LOGGER.debug("getAASs: AssetType {}; AssetKind {}", assetType, assetKind); + return service.getAASs(assetType, assetKind); } diff --git a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/config/ControllerConfig.java b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/config/ControllerConfig.java new file mode 100644 index 00000000..5fe509df --- /dev/null +++ b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/config/ControllerConfig.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2021 Fraunhofer IOSB, eine rechtlich nicht selbstaendige + * Einrichtung der Fraunhofer-Gesellschaft zur Foerderung der angewandten + * Forschung e.V. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package de.fraunhofer.iosb.ilt.faaast.registry.service.config; + +import helper.AssetKindConverter; +import org.springframework.context.annotation.Configuration; +import org.springframework.format.FormatterRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + + +/** + * Class with configuration for enum converters. + * They are necessary for the request parameter. + */ +@Configuration +public class ControllerConfig implements WebMvcConfigurer { + @Override + public void addFormatters(FormatterRegistry registry) { + registry.addConverter(new AssetKindConverter()); + } +} diff --git a/service/src/main/java/helper/AssetKindConverter.java b/service/src/main/java/helper/AssetKindConverter.java new file mode 100644 index 00000000..7e3a8de2 --- /dev/null +++ b/service/src/main/java/helper/AssetKindConverter.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2021 Fraunhofer IOSB, eine rechtlich nicht selbstaendige + * Einrichtung der Fraunhofer-Gesellschaft zur Foerderung der angewandten + * Forschung e.V. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package helper; + +import org.eclipse.digitaltwin.aas4j.v3.model.AssetKind; +import org.springframework.core.convert.converter.Converter; + + +/** + * Test converter for AssetKind. + */ +public class AssetKindConverter implements Converter { + + @Override + public AssetKind convert(String source) { + return AssetKind.valueOf(org.eclipse.digitaltwin.aas4j.v3.dataformat.core.internal.deserialization.EnumDeserializer.deserializeEnumName(source)); + } +} diff --git a/service/src/main/java/helper/RegistryHelper.java b/service/src/main/java/helper/RegistryHelper.java index dc9ac831..3db8c34f 100644 --- a/service/src/main/java/helper/RegistryHelper.java +++ b/service/src/main/java/helper/RegistryHelper.java @@ -33,6 +33,9 @@ private RegistryHelper() {} * @return The decoded value. */ public static String decode(String encoded) { + if (encoded == null) { + return null; + } return new String(Base64.getUrlDecoder().decode(encoded)); } diff --git a/service/src/main/resources/logback.xml b/service/src/main/resources/logback.xml index 81c36342..81dfd0df 100644 --- a/service/src/main/resources/logback.xml +++ b/service/src/main/resources/logback.xml @@ -13,7 +13,7 @@ logs/App.log false - INFO + DEBUG %date{dd.MM.yyyy HH:mm:ss.SSS} %-5level %logger{55}: %msg%n From 7d56d4432b61609dd9ec4c9ba30de79323563f17 Mon Sep 17 00:00:00 2001 From: Tino Bischoff Date: Thu, 29 Feb 2024 10:19:55 +0100 Subject: [PATCH 21/57] code analysis --- .../iosb/ilt/faaast/registry/memory/AasRepositoryMemory.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/persistence/memory/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/memory/AasRepositoryMemory.java b/persistence/memory/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/memory/AasRepositoryMemory.java index 2e2bb073..63e6bd88 100644 --- a/persistence/memory/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/memory/AasRepositoryMemory.java +++ b/persistence/memory/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/memory/AasRepositoryMemory.java @@ -26,7 +26,6 @@ import java.util.Map; import java.util.Objects; import java.util.Optional; -import java.util.stream.Collectors; import org.eclipse.digitaltwin.aas4j.v3.model.AssetKind; @@ -56,7 +55,7 @@ public void clear() { @Override public List getAASs(String assetType, AssetKind assetKind) { return new ArrayList<>( - shellDescriptors.values().stream().filter(a -> filterAssetType(a, assetType)).filter(b -> filterAssetKind(b, assetKind)).collect(Collectors.toList())); + shellDescriptors.values().stream().filter(a -> filterAssetType(a, assetType)).filter(b -> filterAssetKind(b, assetKind)).toList()); } From 8f6e04fe921078afc2d34ede8ddbf71639dcd1e3 Mon Sep 17 00:00:00 2001 From: Tino Bischoff Date: Fri, 1 Mar 2024 16:58:19 +0100 Subject: [PATCH 22/57] start integrating constraints --- pom.xml | 1 + service/pom.xml | 5 + .../registry/service/RegistryService.java | 4 +- .../service/ShellRegistryController.java | 1 + .../main/java/helper/ConstraintHelper.java | 375 ++++++++++++++++++ 5 files changed, 385 insertions(+), 1 deletion(-) create mode 100644 service/src/main/java/helper/ConstraintHelper.java diff --git a/pom.xml b/pom.xml index c77766fa..8a237e1d 100644 --- a/pom.xml +++ b/pom.xml @@ -54,6 +54,7 @@ 3.14.0 1.0.0-SNAPSHOT 2.2.224 + 8.0.1.Final 6.4.4.Final 2.16.1 4.13.2 diff --git a/service/pom.xml b/service/pom.xml index 5a13f982..fc9b8a3c 100644 --- a/service/pom.xml +++ b/service/pom.xml @@ -65,6 +65,11 @@ picocli-spring-boot-starter ${picocli.version} + org.postgresql postgresql diff --git a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/RegistryService.java b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/RegistryService.java index e2e34161..43fa72cb 100644 --- a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/RegistryService.java +++ b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/RegistryService.java @@ -21,6 +21,7 @@ import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.AssetAdministrationShellDescriptor; import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.SubmodelDescriptor; import de.fraunhofer.iosb.ilt.faaast.service.util.Ensure; +import helper.ConstraintHelper; import helper.RegistryHelper; import java.util.List; import org.eclipse.digitaltwin.aas4j.v3.model.AssetKind; @@ -36,8 +37,8 @@ @Service public class RegistryService { + public static final String AAS_NOT_NULL_TXT = "aas must be non-null"; private static final Logger LOGGER = LoggerFactory.getLogger(RegistryService.class); - private static final String AAS_NOT_NULL_TXT = "aas must be non-null"; private static final String SUBMODEL_NOT_NULL_TXT = "submodel must be non-null"; @Autowired @@ -77,6 +78,7 @@ public AssetAdministrationShellDescriptor getAAS(String id) throws ResourceNotFo public AssetAdministrationShellDescriptor createAAS(AssetAdministrationShellDescriptor aas) throws ResourceAlreadyExistsException { Ensure.requireNonNull(aas, AAS_NOT_NULL_TXT); checkShellIdentifiers(aas); + ConstraintHelper.validate(aas); LOGGER.debug("createAAS: {}", aas.getId()); if (aas.getSubmodels() != null) { aas.getSubmodels().stream().forEach(this::checkSubmodelIdentifiers); diff --git a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/ShellRegistryController.java b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/ShellRegistryController.java index b3d9a5c9..b97c7bff 100644 --- a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/ShellRegistryController.java +++ b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/ShellRegistryController.java @@ -63,6 +63,7 @@ public class ShellRegistryController { public List getAASs(@RequestParam(name = "assetType", required = false) String assetType, @RequestParam(name = "assetKind", required = false) AssetKind assetKind) { // Asset type is Base64URL encoded + // perhaps constraint: @Size(min=1, max=2000) LOGGER.debug("getAASs: AssetType {}; AssetKind {}", assetType, assetKind); return service.getAASs(assetType, assetKind); } diff --git a/service/src/main/java/helper/ConstraintHelper.java b/service/src/main/java/helper/ConstraintHelper.java new file mode 100644 index 00000000..3a620c7c --- /dev/null +++ b/service/src/main/java/helper/ConstraintHelper.java @@ -0,0 +1,375 @@ +/* + * Copyright (c) 2021 Fraunhofer IOSB, eine rechtlich nicht selbstaendige + * Einrichtung der Fraunhofer-Gesellschaft zur Foerderung der angewandten + * Forschung e.V. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package helper; + +import de.fraunhofer.iosb.ilt.faaast.registry.core.exception.BadRequestException; +import de.fraunhofer.iosb.ilt.faaast.registry.service.RegistryService; +import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.AssetAdministrationShellDescriptor; +import de.fraunhofer.iosb.ilt.faaast.service.util.Ensure; +import java.util.List; +import java.util.regex.Pattern; +import org.eclipse.digitaltwin.aas4j.v3.model.AdministrativeInformation; +import org.eclipse.digitaltwin.aas4j.v3.model.DataSpecificationContent; +import org.eclipse.digitaltwin.aas4j.v3.model.DataSpecificationIec61360; +import org.eclipse.digitaltwin.aas4j.v3.model.EmbeddedDataSpecification; +import org.eclipse.digitaltwin.aas4j.v3.model.Extension; +import org.eclipse.digitaltwin.aas4j.v3.model.Key; +import org.eclipse.digitaltwin.aas4j.v3.model.LangStringDefinitionTypeIec61360; +import org.eclipse.digitaltwin.aas4j.v3.model.LangStringNameType; +import org.eclipse.digitaltwin.aas4j.v3.model.LangStringPreferredNameTypeIec61360; +import org.eclipse.digitaltwin.aas4j.v3.model.LangStringShortNameTypeIec61360; +import org.eclipse.digitaltwin.aas4j.v3.model.LangStringTextType; +import org.eclipse.digitaltwin.aas4j.v3.model.Reference; +import org.eclipse.digitaltwin.aas4j.v3.model.ValueList; +import org.eclipse.digitaltwin.aas4j.v3.model.ValueReferencePair; + + +/** + * Helper class for constraint validation. + */ +public class ConstraintHelper { + + //private static final Logger LOGGER = LoggerFactory.getLogger(ConstraintHelper.class); + private static final Pattern LANG_LANGUAGE_PATTERN = Pattern.compile( + "^(([a-zA-Z]{2,3}(-[a-zA-Z]{3}(-[a-zA-Z]{3}){2})?|[a-zA-Z]{4}|[a-zA-Z]{5,8})(-[a-zA-Z]{4})?(-([a-zA-Z]{2}|[0-9]{3}))?(-(([a-zA-Z0-9]){5,8}|[0-9]([a-zA-Z0-9]){3}))*(-[0-9A-WY-Za-wy-z](-([a-zA-Z0-9]){2,8})+)*(-[xX](-([a-zA-Z0-9]){1,8})+)?|[xX](-([a-zA-Z0-9]){1,8})+|((en-GB-oed|i-ami|i-bnn|i-default|i-enochian|i-hak|i-klingon|i-lux|i-mingo|i-navajo|i-pwn|i-tao|i-tay|i-tsu|sgn-BE-FR|sgn-BE-NL|sgn-CH-DE)|(art-lojban|cel-gaulish|no-bok|no-nyn|zh-guoyu|zh-hakka|zh-min|zh-min-nan|zh-xiang)))$"); + private static final Pattern TEXT_PATTERN = Pattern + .compile("^([\\t\\n\\r -퟿-�]|\\ud800[\\udc00-\\udfff]|[\\ud801-\\udbfe][\\udc00-\\udfff]|\\udbff[\\udc00-\\udfff])*$"); + private static final Pattern VERSION_PATTERN = Pattern.compile("^(0|[1-9][0-9]*)$"); + private static final int MAX_ID_LENGTH = 2000; + private static final int MAX_IDSHORT_LENGTH = 128; + private static final int MAX_DESCRIPTION_TEXT_LENGTH = 1023; + private static final int MAX_NAME_TEXT_LENGTH = 128; + private static final int MAX_IEC61360_NAME_TEXT_LENGTH = 255; + private static final int MAX_IEC61360_SHORT_NAME_TEXT_LENGTH = 18; + private static final int MAX_VALUE_LENGTH = 2000; + private static final int MAX_VERSION_LENGTH = 4; + + private ConstraintHelper() {} + + + /** + * Validate the given AAS Descriptor. + * + * @param aas The desired AAS Descriptor. + */ + public static void validate(AssetAdministrationShellDescriptor aas) { + Ensure.requireNonNull(aas, RegistryService.AAS_NOT_NULL_TXT); + checkId(aas.getId()); + checkIdShort(aas.getIdShort()); + checkDescriptions(aas.getDescriptions()); + checkDisplayNames(aas.getDisplayNames()); + checkExtensions(aas.getExtensions()); + checkAdministrativeInformation(aas.getAdministration()); + } + + + private static void checkId(String id) { + if ((id == null) || (id.length() == 0)) { + raiseConstraintViolatedException("no Id provided"); + } + else if (id.length() > MAX_ID_LENGTH) { + raiseConstraintViolatedException("ID too long."); + } + } + + + private static void checkIdShort(String idShort) { + if ((idShort != null) && (idShort.length() > MAX_IDSHORT_LENGTH)) { + raiseConstraintViolatedException("IdShort too long."); + } + } + + + private static void checkDescriptions(List descriptions) { + if (descriptions != null) { + for (var d: descriptions) { + checkDescription(d); + } + } + } + + + private static void checkDescription(LangStringTextType description) { + if (description != null) { + checkLanguage(description.getLanguage(), "description language"); + checkText(description.getText(), MAX_DESCRIPTION_TEXT_LENGTH, true, "description text"); + } + } + + + private static void checkDisplayNames(List names) { + if (names != null) { + for (var n: names) { + checkDisplayName(n); + } + } + } + + + private static void checkDisplayName(LangStringNameType name) { + if (name != null) { + checkLanguage(name.getLanguage(), "display name language"); + checkText(name.getText(), MAX_NAME_TEXT_LENGTH, true, "isplay name text"); + } + } + + + private static void checkExtensions(List extensions) { + if (extensions != null) { + for (var e: extensions) { + checkExtension(e); + } + } + } + + + private static void checkExtension(Extension extension) { + if (extension != null) { + checkText(extension.getName(), MAX_NAME_TEXT_LENGTH, true, "extension name"); + checkReference(extension.getSemanticId()); + checkReferences(extension.getSupplementalSemanticIds()); + checkReferences(extension.getRefersTo()); + } + } + + + private static void checkReferenceParent(Reference reference) { + if (reference != null) { + if (reference.getType() == null) { + raiseConstraintViolatedException("no reference type provided"); + } + if ((reference.getKeys() == null) || reference.getKeys().isEmpty()) { + raiseConstraintViolatedException("no keys provided"); + } + + for (var k: reference.getKeys()) { + checkKey(k); + } + } + } + + + private static void checkReferences(List references) { + if (references != null) { + for (var r: references) { + checkReference(r); + } + } + } + + + private static void checkReference(Reference reference) { + if (reference != null) { + checkReferenceParent(reference); + checkReferenceParent(reference.getReferredSemanticId()); + } + } + + + private static void checkKey(Key key) { + if (key.getType() == null) { + raiseConstraintViolatedException("no key type provided"); + } + checkText(key.getValue(), MAX_VALUE_LENGTH, true, "key value"); + } + + + private static void checkAdministrativeInformation(AdministrativeInformation adminInfo) { + if (adminInfo != null) { + checkEmbeddedDataSpecifications(adminInfo.getEmbeddedDataSpecifications()); + checkVersion(adminInfo.getVersion(), "Version"); + checkVersion(adminInfo.getRevision(), "Revision"); + checkReference(adminInfo.getCreator()); + checkText(adminInfo.getTemplateId(), MAX_VALUE_LENGTH, false, "templateId"); + } + } + + + private static void checkEmbeddedDataSpecifications(List specs) { + if (specs != null) { + for (var s: specs) { + checkEmbeddedDataSpecification(s); + } + } + } + + + private static void checkEmbeddedDataSpecification(EmbeddedDataSpecification data) { + if (data != null) { + if (data.getDataSpecification() == null) { + raiseConstraintViolatedException("no DataSpecification provided"); + } + checkReference(data.getDataSpecification()); + checkDataSpecificationContent(data.getDataSpecificationContent()); + } + } + + + private static void checkDataSpecificationContent(DataSpecificationContent content) { + if (content == null) { + raiseConstraintViolatedException("no DataSpecificationContent provided"); + } + else if (content instanceof DataSpecificationIec61360 dataSpecificationIec61360) { + checkDataSpecificationIec61360(dataSpecificationIec61360); + } + } + + + private static void checkDataSpecificationIec61360(DataSpecificationIec61360 dataSpec) { + // modelType missing in model + checkIec61360Names(dataSpec.getPreferredName()); + checkIec61360ShortNames(dataSpec.getShortName()); + checkText(dataSpec.getUnit(), 0, false, "IEC 61360: unit"); + checkReference(dataSpec.getUnitId()); + checkText(dataSpec.getSourceOfDefinition(), 0, false, "IEC 61360: source of definition"); + checkText(dataSpec.getSymbol(), 0, false, "IEC 61360: symbol"); + checkIec61360Definitions(dataSpec.getDefinition()); + checkText(dataSpec.getValueFormat(), 0, false, "IEC 61360: value format"); + checkValueList(dataSpec.getValueList()); + checkText(dataSpec.getValue(), MAX_VALUE_LENGTH, false, "IEC 61360: value"); + } + + + private static void checkIec61360Names(List names) { + if ((names == null) || names.isEmpty()) { + raiseConstraintViolatedException("no IEC 61360 Preferred Name provided"); + } + else { + for (var n: names) { + checkIec61360Name(n); + } + } + } + + + private static void checkIec61360Name(LangStringPreferredNameTypeIec61360 name) { + if (name != null) { + checkLanguage(name.getLanguage(), "IEC 61360 PreferredName language"); + checkText(name.getText(), MAX_IEC61360_NAME_TEXT_LENGTH, true, "IEC 61360 PreferredName text"); + } + else { + raiseConstraintViolatedException("IEC 61360 PreferredName not provided"); + } + } + + + private static void checkIec61360ShortNames(List names) { + if ((names == null) || names.isEmpty()) { + raiseConstraintViolatedException("no IEC 61360 Short Name provided"); + } + else { + for (var n: names) { + checkIec61360ShortName(n); + } + } + } + + + private static void checkIec61360ShortName(LangStringShortNameTypeIec61360 name) { + if (name != null) { + checkLanguage(name.getLanguage(), "IEC 61360 ShortName language"); + checkText(name.getText(), MAX_IEC61360_SHORT_NAME_TEXT_LENGTH, true, "IEC 61360 ShortName"); + } + } + + + private static void checkIec61360Definitions(List definitions) { + if (definitions != null) { + for (var d: definitions) { + checkIec61360Definition(d); + } + } + } + + + private static void checkIec61360Definition(LangStringDefinitionTypeIec61360 definition) { + if (definition != null) { + checkLanguage(definition.getLanguage(), "IEC 61360 definition language"); + checkText(definition.getText(), MAX_DESCRIPTION_TEXT_LENGTH, true, "IEC 61360 definition text"); + } + } + + + private static void checkText(String txt, int maxLength, boolean notNull, String msg) { + if (notNull && (txt == null)) { + raiseConstraintViolatedException(String.format("%s is null", msg)); + } + if (txt != null) { + if (txt.isEmpty()) { + raiseConstraintViolatedException(String.format("%s is empty", msg)); + } + else if ((maxLength > 0) && (txt.length() > maxLength)) { + raiseConstraintViolatedException(String.format("%s too long", msg)); + } + else if (!TEXT_PATTERN.matcher(txt).matches()) { + raiseConstraintViolatedException(String.format("%s doesn't match the pattern", msg)); + } + } + } + + + private static void checkLanguage(String language, String msg) { + if (language == null) { + raiseConstraintViolatedException(String.format("no %s provided", msg)); + } + else if (!LANG_LANGUAGE_PATTERN.matcher(language).matches()) { + raiseConstraintViolatedException(String.format("%s doesn't match the pattern", msg)); + } + } + + + private static void checkValueList(ValueList values) { + if (values != null) { + checkValueReferencePairs(values.getValueReferencePairs()); + } + } + + + private static void checkValueReferencePairs(List pairs) { + if (pairs != null) { + for (var p: pairs) { + checkValueReferencePair(p); + } + } + } + + + private static void checkValueReferencePair(ValueReferencePair pair) { + if (pair != null) { + checkText(pair.getValue(), MAX_VALUE_LENGTH, true, "ValueReferencePair value"); + checkReference(pair.getValueId()); + } + } + + + private static void checkVersion(String version, String msg) { + if (version != null) { + if (version.isEmpty()) { + raiseConstraintViolatedException(String.format("%s is empty", msg)); + } + else if (version.length() > MAX_VERSION_LENGTH) { + raiseConstraintViolatedException(String.format("%s too long", msg)); + } + else if (!VERSION_PATTERN.matcher(version).matches()) { + raiseConstraintViolatedException(String.format("%s doesn't match the pattern", msg)); + } + } + } + + + private static void raiseConstraintViolatedException(String txt) { + throw new BadRequestException(txt); + } +} From 9b94b54ac55a4cd483a0985f14bf2f5e4fbe1092 Mon Sep 17 00:00:00 2001 From: Tino Bischoff Date: Tue, 5 Mar 2024 16:28:54 +0100 Subject: [PATCH 23/57] implement endpoint constraints --- .../core/AbstractAasRepositoryTest.java | 6 +- .../jpa/model/JpaSecurityAttributeObject.java | 103 ++++++++++++++++++ .../jpa/src/test/resources/META-INF/orm.xml | 23 +++- .../main/java/helper/ConstraintHelper.java | 63 ++++++++++- service/src/main/resources/META-INF/orm.xml | 23 +++- 5 files changed, 209 insertions(+), 9 deletions(-) create mode 100644 persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaSecurityAttributeObject.java diff --git a/core/src/test/java/de/fraunhofer/iosb/ilt/faaast/registry/core/AbstractAasRepositoryTest.java b/core/src/test/java/de/fraunhofer/iosb/ilt/faaast/registry/core/AbstractAasRepositoryTest.java index 51179ba6..1bd0d405 100644 --- a/core/src/test/java/de/fraunhofer/iosb/ilt/faaast/registry/core/AbstractAasRepositoryTest.java +++ b/core/src/test/java/de/fraunhofer/iosb/ilt/faaast/registry/core/AbstractAasRepositoryTest.java @@ -67,7 +67,7 @@ protected DefaultSubmodelDescriptor getSubmodel() { .endpoint(DefaultEndpoint.builder() .interfaceInformation("http") .protocolInformation(DefaultProtocolInformation.builder() - .endpointAddress("localhost:8080/factory1/submodel2") + .href("localhost:8080/factory1/submodel2") .endpointProtocol("http") .build()) .build()) @@ -107,7 +107,7 @@ protected AssetAdministrationShellDescriptor getAASWithSubmodel() { .endpoint(DefaultEndpoint.builder() .interfaceInformation("http") .protocolInformation(DefaultProtocolInformation.builder() - .endpointAddress("localhost:8080/factory1") + .href("localhost:8080/factory1") .endpointProtocol("http") .build()) .build()) @@ -132,7 +132,7 @@ protected AssetAdministrationShellDescriptor getAASWithSubmodel() { .endpoint(DefaultEndpoint.builder() .interfaceInformation("http") .protocolInformation(DefaultProtocolInformation.builder() - .endpointAddress("localhost:8080/factory1/submodel") + .href("localhost:8080/factory1/submodel") .endpointProtocol("http") .build()) .build()) diff --git a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaSecurityAttributeObject.java b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaSecurityAttributeObject.java new file mode 100644 index 00000000..63f24a95 --- /dev/null +++ b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaSecurityAttributeObject.java @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2021 Fraunhofer IOSB, eine rechtlich nicht selbstaendige + * Einrichtung der Fraunhofer-Gesellschaft zur Foerderung der angewandten + * Forschung e.V. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package de.fraunhofer.iosb.ilt.faaast.registry.jpa.model; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import java.util.Objects; +import org.eclipse.digitaltwin.aas4j.v3.model.SecurityAttributeObject; +import org.eclipse.digitaltwin.aas4j.v3.model.builder.SecurityAttributeObjectBuilder; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultSecurityAttributeObject; + + +/** + * Registry Descriptor JPA implementation for SecurityAttributeObject. + */ +public class JpaSecurityAttributeObject extends DefaultSecurityAttributeObject { + + @JsonIgnore + private String id; + + public JpaSecurityAttributeObject() { + id = null; + } + + + public String getId() { + return id; + } + + + public void setId(String id) { + this.id = id; + } + + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), id); + } + + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + else if (obj == null) { + return false; + } + else if (this.getClass() != obj.getClass()) { + return false; + } + else { + JpaSecurityAttributeObject other = (JpaSecurityAttributeObject) obj; + return super.equals(obj) + && Objects.equals(this.id, other.id); + } + } + + public abstract static class AbstractBuilder> + extends SecurityAttributeObjectBuilder { + + public B id(String value) { + getBuildingInstance().setId(value); + return getSelf(); + } + + + public B from(SecurityAttributeObject other) { + if (Objects.nonNull(other)) { + type(other.getType()); + key(other.getKey()); + value(other.getValue()); + } + return getSelf(); + } + } + + public static class Builder extends AbstractBuilder { + + @Override + protected Builder getSelf() { + return this; + } + + + @Override + protected JpaSecurityAttributeObject newBuildingInstance() { + return new JpaSecurityAttributeObject(); + } + } +} diff --git a/persistence/jpa/src/test/resources/META-INF/orm.xml b/persistence/jpa/src/test/resources/META-INF/orm.xml index a82c4756..5230ab01 100644 --- a/persistence/jpa/src/test/resources/META-INF/orm.xml +++ b/persistence/jpa/src/test/resources/META-INF/orm.xml @@ -207,12 +207,18 @@ - + + + + + + + + + + + + + + + org.eclipse.digitaltwin.aas4j.v3.model.SecurityTypeEnum + + + + + + + diff --git a/service/src/main/java/helper/ConstraintHelper.java b/service/src/main/java/helper/ConstraintHelper.java index 3a620c7c..ed2abd64 100644 --- a/service/src/main/java/helper/ConstraintHelper.java +++ b/service/src/main/java/helper/ConstraintHelper.java @@ -17,6 +17,8 @@ import de.fraunhofer.iosb.ilt.faaast.registry.core.exception.BadRequestException; import de.fraunhofer.iosb.ilt.faaast.registry.service.RegistryService; import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.AssetAdministrationShellDescriptor; +import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.Endpoint; +import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.ProtocolInformation; import de.fraunhofer.iosb.ilt.faaast.service.util.Ensure; import java.util.List; import java.util.regex.Pattern; @@ -32,6 +34,7 @@ import org.eclipse.digitaltwin.aas4j.v3.model.LangStringShortNameTypeIec61360; import org.eclipse.digitaltwin.aas4j.v3.model.LangStringTextType; import org.eclipse.digitaltwin.aas4j.v3.model.Reference; +import org.eclipse.digitaltwin.aas4j.v3.model.SecurityAttributeObject; import org.eclipse.digitaltwin.aas4j.v3.model.ValueList; import org.eclipse.digitaltwin.aas4j.v3.model.ValueReferencePair; @@ -50,11 +53,11 @@ public class ConstraintHelper { private static final int MAX_ID_LENGTH = 2000; private static final int MAX_IDSHORT_LENGTH = 128; private static final int MAX_DESCRIPTION_TEXT_LENGTH = 1023; - private static final int MAX_NAME_TEXT_LENGTH = 128; private static final int MAX_IEC61360_NAME_TEXT_LENGTH = 255; private static final int MAX_IEC61360_SHORT_NAME_TEXT_LENGTH = 18; private static final int MAX_VALUE_LENGTH = 2000; private static final int MAX_VERSION_LENGTH = 4; + private static final int MAX_STRING_2048_LENGTH = 2048; private ConstraintHelper() {} @@ -72,6 +75,8 @@ public static void validate(AssetAdministrationShellDescriptor aas) { checkDisplayNames(aas.getDisplayNames()); checkExtensions(aas.getExtensions()); checkAdministrativeInformation(aas.getAdministration()); + checkText(aas.getAssetType(), MAX_ID_LENGTH, false, "Asset Type"); + checkEndpoints(aas.getEndpoints()); } @@ -121,7 +126,7 @@ private static void checkDisplayNames(List names) { private static void checkDisplayName(LangStringNameType name) { if (name != null) { checkLanguage(name.getLanguage(), "display name language"); - checkText(name.getText(), MAX_NAME_TEXT_LENGTH, true, "isplay name text"); + checkText(name.getText(), MAX_IDSHORT_LENGTH, true, "display name text"); } } @@ -137,7 +142,7 @@ private static void checkExtensions(List extensions) { private static void checkExtension(Extension extension) { if (extension != null) { - checkText(extension.getName(), MAX_NAME_TEXT_LENGTH, true, "extension name"); + checkText(extension.getName(), MAX_IDSHORT_LENGTH, true, "extension name"); checkReference(extension.getSemanticId()); checkReferences(extension.getSupplementalSemanticIds()); checkReferences(extension.getRefersTo()); @@ -228,7 +233,6 @@ else if (content instanceof DataSpecificationIec61360 dataSpecificationIec61360) private static void checkDataSpecificationIec61360(DataSpecificationIec61360 dataSpec) { - // modelType missing in model checkIec61360Names(dataSpec.getPreferredName()); checkIec61360ShortNames(dataSpec.getShortName()); checkText(dataSpec.getUnit(), 0, false, "IEC 61360: unit"); @@ -369,6 +373,57 @@ else if (!VERSION_PATTERN.matcher(version).matches()) { } + private static void checkEndpoints(List endpoints) { + if (endpoints != null) { + for (var e: endpoints) { + checkEndpoint(e); + } + } + } + + + private static void checkEndpoint(Endpoint endpoint) { + if (endpoint != null) { + checkText(endpoint.getInterfaceInformation(), MAX_IDSHORT_LENGTH, true, "Interface Information"); + checkProtocolInformation(endpoint.getProtocolInformation()); + } + } + + + private static void checkProtocolInformation(ProtocolInformation protocolInformation) { + if (protocolInformation != null) { + checkText(protocolInformation.getHref(), MAX_STRING_2048_LENGTH, true, "href"); + checkText(protocolInformation.getEndpointProtocol(), MAX_IDSHORT_LENGTH, false, "Endpoint Protocol"); + checkText(protocolInformation.getEndpointProtocolVersion(), MAX_IDSHORT_LENGTH, false, "Endpoint Protocol Version"); + checkText(protocolInformation.getSubprotocol(), MAX_IDSHORT_LENGTH, false, "Subprotocol"); + checkText(protocolInformation.getSubprotocolBody(), MAX_IDSHORT_LENGTH, false, "Subprotocol Body"); + checkText(protocolInformation.getSubprotocolBodyEncoding(), MAX_IDSHORT_LENGTH, false, "Subprotocol Body Encoding"); + checkSecurityAttributes(protocolInformation.getSecurityAttributes()); + } + } + + + private static void checkSecurityAttributes(List securityAttributes) { + if (securityAttributes != null) { + for (var s: securityAttributes) { + checkSecurityAttribute(s); + } + } + } + + + private static void checkSecurityAttribute(SecurityAttributeObject securityAttribute) { + if (securityAttribute != null) { + if (securityAttribute.getKey() == null) { + raiseConstraintViolatedException("Key is null"); + } + else if (securityAttribute.getValue() == null) { + raiseConstraintViolatedException("Value is null"); + } + } + } + + private static void raiseConstraintViolatedException(String txt) { throw new BadRequestException(txt); } diff --git a/service/src/main/resources/META-INF/orm.xml b/service/src/main/resources/META-INF/orm.xml index a82c4756..5230ab01 100644 --- a/service/src/main/resources/META-INF/orm.xml +++ b/service/src/main/resources/META-INF/orm.xml @@ -207,12 +207,18 @@ - + + + + + + + + + + + + + + + org.eclipse.digitaltwin.aas4j.v3.model.SecurityTypeEnum + + + + + + + From 4c7e45e84839e156ee8225ae73e741c6e80ae734 Mon Sep 17 00:00:00 2001 From: Tino Bischoff Date: Wed, 6 Mar 2024 11:13:53 +0100 Subject: [PATCH 24/57] add SpecificAssetId constraint --- .../main/java/helper/ConstraintHelper.java | 39 +++++++++++++++---- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/service/src/main/java/helper/ConstraintHelper.java b/service/src/main/java/helper/ConstraintHelper.java index ed2abd64..839dff50 100644 --- a/service/src/main/java/helper/ConstraintHelper.java +++ b/service/src/main/java/helper/ConstraintHelper.java @@ -35,6 +35,7 @@ import org.eclipse.digitaltwin.aas4j.v3.model.LangStringTextType; import org.eclipse.digitaltwin.aas4j.v3.model.Reference; import org.eclipse.digitaltwin.aas4j.v3.model.SecurityAttributeObject; +import org.eclipse.digitaltwin.aas4j.v3.model.SpecificAssetId; import org.eclipse.digitaltwin.aas4j.v3.model.ValueList; import org.eclipse.digitaltwin.aas4j.v3.model.ValueReferencePair; @@ -50,14 +51,14 @@ public class ConstraintHelper { private static final Pattern TEXT_PATTERN = Pattern .compile("^([\\t\\n\\r -퟿-�]|\\ud800[\\udc00-\\udfff]|[\\ud801-\\udbfe][\\udc00-\\udfff]|\\udbff[\\udc00-\\udfff])*$"); private static final Pattern VERSION_PATTERN = Pattern.compile("^(0|[1-9][0-9]*)$"); - private static final int MAX_ID_LENGTH = 2000; + private static final int MAX_IDENTIFIER_LENGTH = 2000; private static final int MAX_IDSHORT_LENGTH = 128; private static final int MAX_DESCRIPTION_TEXT_LENGTH = 1023; private static final int MAX_IEC61360_NAME_TEXT_LENGTH = 255; private static final int MAX_IEC61360_SHORT_NAME_TEXT_LENGTH = 18; - private static final int MAX_VALUE_LENGTH = 2000; private static final int MAX_VERSION_LENGTH = 4; private static final int MAX_STRING_2048_LENGTH = 2048; + private static final int MAX_LABEL_LENGTH = 64; private ConstraintHelper() {} @@ -75,8 +76,10 @@ public static void validate(AssetAdministrationShellDescriptor aas) { checkDisplayNames(aas.getDisplayNames()); checkExtensions(aas.getExtensions()); checkAdministrativeInformation(aas.getAdministration()); - checkText(aas.getAssetType(), MAX_ID_LENGTH, false, "Asset Type"); + checkText(aas.getAssetType(), MAX_IDENTIFIER_LENGTH, false, "Asset Type"); checkEndpoints(aas.getEndpoints()); + checkText(aas.getGlobalAssetId(), MAX_IDENTIFIER_LENGTH, false, "Global Asset ID"); + checkSpecificAssetIds(aas.getSpecificAssetIds()); } @@ -84,7 +87,7 @@ private static void checkId(String id) { if ((id == null) || (id.length() == 0)) { raiseConstraintViolatedException("no Id provided"); } - else if (id.length() > MAX_ID_LENGTH) { + else if (id.length() > MAX_IDENTIFIER_LENGTH) { raiseConstraintViolatedException("ID too long."); } } @@ -187,7 +190,7 @@ private static void checkKey(Key key) { if (key.getType() == null) { raiseConstraintViolatedException("no key type provided"); } - checkText(key.getValue(), MAX_VALUE_LENGTH, true, "key value"); + checkText(key.getValue(), MAX_IDENTIFIER_LENGTH, true, "key value"); } @@ -197,7 +200,7 @@ private static void checkAdministrativeInformation(AdministrativeInformation adm checkVersion(adminInfo.getVersion(), "Version"); checkVersion(adminInfo.getRevision(), "Revision"); checkReference(adminInfo.getCreator()); - checkText(adminInfo.getTemplateId(), MAX_VALUE_LENGTH, false, "templateId"); + checkText(adminInfo.getTemplateId(), MAX_IDENTIFIER_LENGTH, false, "templateId"); } } @@ -242,7 +245,7 @@ private static void checkDataSpecificationIec61360(DataSpecificationIec61360 dat checkIec61360Definitions(dataSpec.getDefinition()); checkText(dataSpec.getValueFormat(), 0, false, "IEC 61360: value format"); checkValueList(dataSpec.getValueList()); - checkText(dataSpec.getValue(), MAX_VALUE_LENGTH, false, "IEC 61360: value"); + checkText(dataSpec.getValue(), MAX_IDENTIFIER_LENGTH, false, "IEC 61360: value"); } @@ -352,7 +355,7 @@ private static void checkValueReferencePairs(List pairs) { private static void checkValueReferencePair(ValueReferencePair pair) { if (pair != null) { - checkText(pair.getValue(), MAX_VALUE_LENGTH, true, "ValueReferencePair value"); + checkText(pair.getValue(), MAX_IDENTIFIER_LENGTH, true, "ValueReferencePair value"); checkReference(pair.getValueId()); } } @@ -424,6 +427,26 @@ else if (securityAttribute.getValue() == null) { } + private static void checkSpecificAssetIds(List specificAssetIds) { + if (specificAssetIds != null) { + for (var s: specificAssetIds) { + checkSpecificAssetId(s); + } + } + } + + + private static void checkSpecificAssetId(SpecificAssetId specificAssetId) { + if (specificAssetId != null) { + checkReference(specificAssetId.getSemanticId()); + checkReferences(specificAssetId.getSupplementalSemanticIds()); + checkText(specificAssetId.getName(), MAX_LABEL_LENGTH, true, "Specific Asset ID Name"); + checkText(specificAssetId.getValue(), MAX_IDENTIFIER_LENGTH, true, "Specific Asset ID value"); + checkReference(specificAssetId.getExternalSubjectId()); + } + } + + private static void raiseConstraintViolatedException(String txt) { throw new BadRequestException(txt); } From 5f4fc1326b2be65b47279be85886ec12418298f6 Mon Sep 17 00:00:00 2001 From: Tino Bischoff Date: Wed, 6 Mar 2024 12:55:49 +0100 Subject: [PATCH 25/57] check submodel constraints --- .../registry/service/RegistryService.java | 7 +- .../main/java/helper/ConstraintHelper.java | 85 ++++++++++--------- 2 files changed, 48 insertions(+), 44 deletions(-) diff --git a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/RegistryService.java b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/RegistryService.java index 43fa72cb..2b4334d4 100644 --- a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/RegistryService.java +++ b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/RegistryService.java @@ -38,8 +38,8 @@ public class RegistryService { public static final String AAS_NOT_NULL_TXT = "aas must be non-null"; + public static final String SUBMODEL_NOT_NULL_TXT = "submodel must be non-null"; private static final Logger LOGGER = LoggerFactory.getLogger(RegistryService.class); - private static final String SUBMODEL_NOT_NULL_TXT = "submodel must be non-null"; @Autowired private AasRepository aasRepository; @@ -76,8 +76,6 @@ public AssetAdministrationShellDescriptor getAAS(String id) throws ResourceNotFo * @throws ResourceAlreadyExistsException When the AAS already exists. */ public AssetAdministrationShellDescriptor createAAS(AssetAdministrationShellDescriptor aas) throws ResourceAlreadyExistsException { - Ensure.requireNonNull(aas, AAS_NOT_NULL_TXT); - checkShellIdentifiers(aas); ConstraintHelper.validate(aas); LOGGER.debug("createAAS: {}", aas.getId()); if (aas.getSubmodels() != null) { @@ -202,8 +200,7 @@ public SubmodelDescriptor createSubmodel(SubmodelDescriptor submodel) throws Res * @throws ResourceAlreadyExistsException When the Submodel already exists. */ public SubmodelDescriptor createSubmodel(String aasId, SubmodelDescriptor submodel) throws ResourceNotFoundException, ResourceAlreadyExistsException { - Ensure.requireNonNull(submodel, SUBMODEL_NOT_NULL_TXT); - checkSubmodelIdentifiers(submodel); + ConstraintHelper.validate(submodel); if (aasId == null) { LOGGER.debug("createSubmodel: Submodel {}", submodel.getId()); return aasRepository.addSubmodel(submodel); diff --git a/service/src/main/java/helper/ConstraintHelper.java b/service/src/main/java/helper/ConstraintHelper.java index 839dff50..de02bf42 100644 --- a/service/src/main/java/helper/ConstraintHelper.java +++ b/service/src/main/java/helper/ConstraintHelper.java @@ -19,6 +19,7 @@ import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.AssetAdministrationShellDescriptor; import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.Endpoint; import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.ProtocolInformation; +import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.SubmodelDescriptor; import de.fraunhofer.iosb.ilt.faaast.service.util.Ensure; import java.util.List; import java.util.regex.Pattern; @@ -80,6 +81,38 @@ public static void validate(AssetAdministrationShellDescriptor aas) { checkEndpoints(aas.getEndpoints()); checkText(aas.getGlobalAssetId(), MAX_IDENTIFIER_LENGTH, false, "Global Asset ID"); checkSpecificAssetIds(aas.getSpecificAssetIds()); + checkSubmodels(aas.getSubmodels()); + } + + + /** + * Validate the given AAS Descriptor. + * + * @param submodel The desired Submodel Descriptor. + */ + public static void validate(SubmodelDescriptor submodel) { + checkSubmodel(submodel); + } + + + private static void checkSubmodels(List submodels) { + if (submodels != null) { + submodels.stream().forEach(ConstraintHelper::checkSubmodel); + } + } + + + private static void checkSubmodel(SubmodelDescriptor submodel) { + Ensure.requireNonNull(submodel, RegistryService.SUBMODEL_NOT_NULL_TXT); + checkId(submodel.getId()); + checkIdShort(submodel.getIdShort()); + checkDescriptions(submodel.getDescriptions()); + checkDisplayNames(submodel.getDisplayNames()); + checkExtensions(submodel.getExtensions()); + checkAdministrativeInformation(submodel.getAdministration()); + checkEndpoints(submodel.getEndpoints()); + checkReference(submodel.getSemanticId()); + checkReferences(submodel.getSupplementalSemanticIds()); } @@ -102,9 +135,7 @@ private static void checkIdShort(String idShort) { private static void checkDescriptions(List descriptions) { if (descriptions != null) { - for (var d: descriptions) { - checkDescription(d); - } + descriptions.stream().forEach(ConstraintHelper::checkDescription); } } @@ -119,9 +150,7 @@ private static void checkDescription(LangStringTextType description) { private static void checkDisplayNames(List names) { if (names != null) { - for (var n: names) { - checkDisplayName(n); - } + names.stream().forEach(ConstraintHelper::checkDisplayName); } } @@ -136,9 +165,7 @@ private static void checkDisplayName(LangStringNameType name) { private static void checkExtensions(List extensions) { if (extensions != null) { - for (var e: extensions) { - checkExtension(e); - } + extensions.stream().forEach(ConstraintHelper::checkExtension); } } @@ -162,18 +189,14 @@ private static void checkReferenceParent(Reference reference) { raiseConstraintViolatedException("no keys provided"); } - for (var k: reference.getKeys()) { - checkKey(k); - } + reference.getKeys().stream().forEach(ConstraintHelper::checkKey); } } private static void checkReferences(List references) { if (references != null) { - for (var r: references) { - checkReference(r); - } + references.stream().forEach(ConstraintHelper::checkReference); } } @@ -207,9 +230,7 @@ private static void checkAdministrativeInformation(AdministrativeInformation adm private static void checkEmbeddedDataSpecifications(List specs) { if (specs != null) { - for (var s: specs) { - checkEmbeddedDataSpecification(s); - } + specs.stream().forEach(ConstraintHelper::checkEmbeddedDataSpecification); } } @@ -254,9 +275,7 @@ private static void checkIec61360Names(List raiseConstraintViolatedException("no IEC 61360 Preferred Name provided"); } else { - for (var n: names) { - checkIec61360Name(n); - } + names.stream().forEach(ConstraintHelper::checkIec61360Name); } } @@ -277,9 +296,7 @@ private static void checkIec61360ShortNames(List definitions) { if (definitions != null) { - for (var d: definitions) { - checkIec61360Definition(d); - } + definitions.stream().forEach(ConstraintHelper::checkIec61360Definition); } } @@ -346,9 +361,7 @@ private static void checkValueList(ValueList values) { private static void checkValueReferencePairs(List pairs) { if (pairs != null) { - for (var p: pairs) { - checkValueReferencePair(p); - } + pairs.stream().forEach(ConstraintHelper::checkValueReferencePair); } } @@ -378,9 +391,7 @@ else if (!VERSION_PATTERN.matcher(version).matches()) { private static void checkEndpoints(List endpoints) { if (endpoints != null) { - for (var e: endpoints) { - checkEndpoint(e); - } + endpoints.stream().forEach(ConstraintHelper::checkEndpoint); } } @@ -408,9 +419,7 @@ private static void checkProtocolInformation(ProtocolInformation protocolInforma private static void checkSecurityAttributes(List securityAttributes) { if (securityAttributes != null) { - for (var s: securityAttributes) { - checkSecurityAttribute(s); - } + securityAttributes.stream().forEach(ConstraintHelper::checkSecurityAttribute); } } @@ -429,9 +438,7 @@ else if (securityAttribute.getValue() == null) { private static void checkSpecificAssetIds(List specificAssetIds) { if (specificAssetIds != null) { - for (var s: specificAssetIds) { - checkSpecificAssetId(s); - } + specificAssetIds.stream().forEach(ConstraintHelper::checkSpecificAssetId); } } From f0f151579872ec96abab55a2bb5f97f49ffd5770 Mon Sep 17 00:00:00 2001 From: Tino Bischoff Date: Wed, 6 Mar 2024 15:43:25 +0100 Subject: [PATCH 26/57] refactoring --- .../java/helper/CommonConstraintHelper.java | 156 ++++++++ .../main/java/helper/ConstraintHelper.java | 341 ++---------------- .../DataSpecificationConstraintHelper.java | 160 ++++++++ .../java/helper/EndpointConstraintHelper.java | 84 +++++ 4 files changed, 438 insertions(+), 303 deletions(-) create mode 100644 service/src/main/java/helper/CommonConstraintHelper.java create mode 100644 service/src/main/java/helper/DataSpecificationConstraintHelper.java create mode 100644 service/src/main/java/helper/EndpointConstraintHelper.java diff --git a/service/src/main/java/helper/CommonConstraintHelper.java b/service/src/main/java/helper/CommonConstraintHelper.java new file mode 100644 index 00000000..ce85a71a --- /dev/null +++ b/service/src/main/java/helper/CommonConstraintHelper.java @@ -0,0 +1,156 @@ +/* + * Copyright (c) 2021 Fraunhofer IOSB, eine rechtlich nicht selbstaendige + * Einrichtung der Fraunhofer-Gesellschaft zur Foerderung der angewandten + * Forschung e.V. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package helper; + +import de.fraunhofer.iosb.ilt.faaast.registry.core.exception.BadRequestException; +import java.util.List; +import org.eclipse.digitaltwin.aas4j.v3.model.Key; +import org.eclipse.digitaltwin.aas4j.v3.model.Reference; + + +/** + * Helper class for common data for the constraint validation. + */ +public class CommonConstraintHelper { + + private CommonConstraintHelper() {} + + + /** + * Checks the constraints of the given Id. + * + * @param id The desired id. + */ + public static void checkId(String id) { + if ((id == null) || (id.length() == 0)) { + raiseConstraintViolatedException("no Id provided"); + } + else if (id.length() > ConstraintHelper.MAX_IDENTIFIER_LENGTH) { + raiseConstraintViolatedException("ID too long."); + } + } + + + /** + * Checks the constraints of the given IdShort. + * + * @param idShort The desired idShort. + */ + public static void checkIdShort(String idShort) { + if ((idShort != null) && (idShort.length() > ConstraintHelper.MAX_IDSHORT_LENGTH)) { + raiseConstraintViolatedException("IdShort too long."); + } + } + + + /** + * Checks the constraints of the given text. + * + * @param txt The desired text. + * @param maxLength The maximum length of the text, 0 if unlimited. + * @param notNull true if the text must not be null, false if null is allowed. + * @param msg The message for the exception. + */ + public static void checkText(String txt, int maxLength, boolean notNull, String msg) { + if (notNull && (txt == null)) { + raiseConstraintViolatedException(String.format("%s is null", msg)); + } + if (txt != null) { + if (txt.isEmpty()) { + raiseConstraintViolatedException(String.format("%s is empty", msg)); + } + else if ((maxLength > 0) && (txt.length() > maxLength)) { + raiseConstraintViolatedException(String.format("%s too long", msg)); + } + else if (!ConstraintHelper.TEXT_PATTERN.matcher(txt).matches()) { + raiseConstraintViolatedException(String.format("%s doesn't match the pattern", msg)); + } + } + } + + + /** + * Checks the constraints of the given language text. + * + * @param language The deesired language text. + * @param msg + */ + public static void checkLanguage(String language, String msg) { + if (language == null) { + raiseConstraintViolatedException(String.format("no %s provided", msg)); + } + else if (!ConstraintHelper.LANG_LANGUAGE_PATTERN.matcher(language).matches()) { + raiseConstraintViolatedException(String.format("%s doesn't match the pattern", msg)); + } + } + + + /** + * Checks the constraints of the given list of references. + * + * @param references The desired list of references. + */ + public static void checkReferences(List references) { + if (references != null) { + references.stream().forEach(CommonConstraintHelper::checkReference); + } + } + + + /** + * Checks the constraints of the given reference. + * + * @param reference The desired reference. + */ + public static void checkReference(Reference reference) { + if (reference != null) { + checkReferenceParent(reference); + checkReferenceParent(reference.getReferredSemanticId()); + } + } + + + /** + * Raise an exception if a constraint is violated. + * + * @param txt The desired text for the exception. + */ + public static void raiseConstraintViolatedException(String txt) { + throw new BadRequestException(txt); + } + + + private static void checkKey(Key key) { + if (key.getType() == null) { + raiseConstraintViolatedException("no key type provided"); + } + checkText(key.getValue(), ConstraintHelper.MAX_IDENTIFIER_LENGTH, true, "key value"); + } + + + private static void checkReferenceParent(Reference reference) { + if (reference != null) { + if (reference.getType() == null) { + raiseConstraintViolatedException("no reference type provided"); + } + if ((reference.getKeys() == null) || reference.getKeys().isEmpty()) { + raiseConstraintViolatedException("no keys provided"); + } + + reference.getKeys().stream().forEach(CommonConstraintHelper::checkKey); + } + } + +} diff --git a/service/src/main/java/helper/ConstraintHelper.java b/service/src/main/java/helper/ConstraintHelper.java index de02bf42..0809309a 100644 --- a/service/src/main/java/helper/ConstraintHelper.java +++ b/service/src/main/java/helper/ConstraintHelper.java @@ -14,31 +14,17 @@ */ package helper; -import de.fraunhofer.iosb.ilt.faaast.registry.core.exception.BadRequestException; import de.fraunhofer.iosb.ilt.faaast.registry.service.RegistryService; import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.AssetAdministrationShellDescriptor; -import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.Endpoint; -import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.ProtocolInformation; import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.SubmodelDescriptor; import de.fraunhofer.iosb.ilt.faaast.service.util.Ensure; import java.util.List; import java.util.regex.Pattern; import org.eclipse.digitaltwin.aas4j.v3.model.AdministrativeInformation; -import org.eclipse.digitaltwin.aas4j.v3.model.DataSpecificationContent; -import org.eclipse.digitaltwin.aas4j.v3.model.DataSpecificationIec61360; -import org.eclipse.digitaltwin.aas4j.v3.model.EmbeddedDataSpecification; import org.eclipse.digitaltwin.aas4j.v3.model.Extension; -import org.eclipse.digitaltwin.aas4j.v3.model.Key; -import org.eclipse.digitaltwin.aas4j.v3.model.LangStringDefinitionTypeIec61360; import org.eclipse.digitaltwin.aas4j.v3.model.LangStringNameType; -import org.eclipse.digitaltwin.aas4j.v3.model.LangStringPreferredNameTypeIec61360; -import org.eclipse.digitaltwin.aas4j.v3.model.LangStringShortNameTypeIec61360; import org.eclipse.digitaltwin.aas4j.v3.model.LangStringTextType; -import org.eclipse.digitaltwin.aas4j.v3.model.Reference; -import org.eclipse.digitaltwin.aas4j.v3.model.SecurityAttributeObject; import org.eclipse.digitaltwin.aas4j.v3.model.SpecificAssetId; -import org.eclipse.digitaltwin.aas4j.v3.model.ValueList; -import org.eclipse.digitaltwin.aas4j.v3.model.ValueReferencePair; /** @@ -47,18 +33,18 @@ public class ConstraintHelper { //private static final Logger LOGGER = LoggerFactory.getLogger(ConstraintHelper.class); - private static final Pattern LANG_LANGUAGE_PATTERN = Pattern.compile( - "^(([a-zA-Z]{2,3}(-[a-zA-Z]{3}(-[a-zA-Z]{3}){2})?|[a-zA-Z]{4}|[a-zA-Z]{5,8})(-[a-zA-Z]{4})?(-([a-zA-Z]{2}|[0-9]{3}))?(-(([a-zA-Z0-9]){5,8}|[0-9]([a-zA-Z0-9]){3}))*(-[0-9A-WY-Za-wy-z](-([a-zA-Z0-9]){2,8})+)*(-[xX](-([a-zA-Z0-9]){1,8})+)?|[xX](-([a-zA-Z0-9]){1,8})+|((en-GB-oed|i-ami|i-bnn|i-default|i-enochian|i-hak|i-klingon|i-lux|i-mingo|i-navajo|i-pwn|i-tao|i-tay|i-tsu|sgn-BE-FR|sgn-BE-NL|sgn-CH-DE)|(art-lojban|cel-gaulish|no-bok|no-nyn|zh-guoyu|zh-hakka|zh-min|zh-min-nan|zh-xiang)))$"); - private static final Pattern TEXT_PATTERN = Pattern + public static final Pattern TEXT_PATTERN = Pattern .compile("^([\\t\\n\\r -퟿-�]|\\ud800[\\udc00-\\udfff]|[\\ud801-\\udbfe][\\udc00-\\udfff]|\\udbff[\\udc00-\\udfff])*$"); + public static final Pattern LANG_LANGUAGE_PATTERN = Pattern.compile( + "^(([a-zA-Z]{2,3}(-[a-zA-Z]{3}(-[a-zA-Z]{3}){2})?|[a-zA-Z]{4}|[a-zA-Z]{5,8})(-[a-zA-Z]{4})?(-([a-zA-Z]{2}|[0-9]{3}))?(-(([a-zA-Z0-9]){5,8}|[0-9]([a-zA-Z0-9]){3}))*(-[0-9A-WY-Za-wy-z](-([a-zA-Z0-9]){2,8})+)*(-[xX](-([a-zA-Z0-9]){1,8})+)?|[xX](-([a-zA-Z0-9]){1,8})+|((en-GB-oed|i-ami|i-bnn|i-default|i-enochian|i-hak|i-klingon|i-lux|i-mingo|i-navajo|i-pwn|i-tao|i-tay|i-tsu|sgn-BE-FR|sgn-BE-NL|sgn-CH-DE)|(art-lojban|cel-gaulish|no-bok|no-nyn|zh-guoyu|zh-hakka|zh-min|zh-min-nan|zh-xiang)))$"); private static final Pattern VERSION_PATTERN = Pattern.compile("^(0|[1-9][0-9]*)$"); - private static final int MAX_IDENTIFIER_LENGTH = 2000; - private static final int MAX_IDSHORT_LENGTH = 128; - private static final int MAX_DESCRIPTION_TEXT_LENGTH = 1023; - private static final int MAX_IEC61360_NAME_TEXT_LENGTH = 255; - private static final int MAX_IEC61360_SHORT_NAME_TEXT_LENGTH = 18; + public static final int MAX_IDENTIFIER_LENGTH = 2000; + public static final int MAX_IDSHORT_LENGTH = 128; + public static final int MAX_DESCRIPTION_TEXT_LENGTH = 1023; + public static final int MAX_IEC61360_NAME_TEXT_LENGTH = 255; + public static final int MAX_IEC61360_SHORT_NAME_TEXT_LENGTH = 18; private static final int MAX_VERSION_LENGTH = 4; - private static final int MAX_STRING_2048_LENGTH = 2048; + public static final int MAX_STRING_2048_LENGTH = 2048; private static final int MAX_LABEL_LENGTH = 64; private ConstraintHelper() {} @@ -71,15 +57,15 @@ private ConstraintHelper() {} */ public static void validate(AssetAdministrationShellDescriptor aas) { Ensure.requireNonNull(aas, RegistryService.AAS_NOT_NULL_TXT); - checkId(aas.getId()); - checkIdShort(aas.getIdShort()); + CommonConstraintHelper.checkId(aas.getId()); + CommonConstraintHelper.checkIdShort(aas.getIdShort()); checkDescriptions(aas.getDescriptions()); checkDisplayNames(aas.getDisplayNames()); checkExtensions(aas.getExtensions()); checkAdministrativeInformation(aas.getAdministration()); - checkText(aas.getAssetType(), MAX_IDENTIFIER_LENGTH, false, "Asset Type"); - checkEndpoints(aas.getEndpoints()); - checkText(aas.getGlobalAssetId(), MAX_IDENTIFIER_LENGTH, false, "Global Asset ID"); + CommonConstraintHelper.checkText(aas.getAssetType(), MAX_IDENTIFIER_LENGTH, false, "Asset Type"); + EndpointConstraintHelper.checkEndpoints(aas.getEndpoints()); + CommonConstraintHelper.checkText(aas.getGlobalAssetId(), MAX_IDENTIFIER_LENGTH, false, "Global Asset ID"); checkSpecificAssetIds(aas.getSpecificAssetIds()); checkSubmodels(aas.getSubmodels()); } @@ -104,32 +90,15 @@ private static void checkSubmodels(List submodels) { private static void checkSubmodel(SubmodelDescriptor submodel) { Ensure.requireNonNull(submodel, RegistryService.SUBMODEL_NOT_NULL_TXT); - checkId(submodel.getId()); - checkIdShort(submodel.getIdShort()); + CommonConstraintHelper.checkId(submodel.getId()); + CommonConstraintHelper.checkIdShort(submodel.getIdShort()); checkDescriptions(submodel.getDescriptions()); checkDisplayNames(submodel.getDisplayNames()); checkExtensions(submodel.getExtensions()); checkAdministrativeInformation(submodel.getAdministration()); - checkEndpoints(submodel.getEndpoints()); - checkReference(submodel.getSemanticId()); - checkReferences(submodel.getSupplementalSemanticIds()); - } - - - private static void checkId(String id) { - if ((id == null) || (id.length() == 0)) { - raiseConstraintViolatedException("no Id provided"); - } - else if (id.length() > MAX_IDENTIFIER_LENGTH) { - raiseConstraintViolatedException("ID too long."); - } - } - - - private static void checkIdShort(String idShort) { - if ((idShort != null) && (idShort.length() > MAX_IDSHORT_LENGTH)) { - raiseConstraintViolatedException("IdShort too long."); - } + EndpointConstraintHelper.checkEndpoints(submodel.getEndpoints()); + CommonConstraintHelper.checkReference(submodel.getSemanticId()); + CommonConstraintHelper.checkReferences(submodel.getSupplementalSemanticIds()); } @@ -142,8 +111,8 @@ private static void checkDescriptions(List descriptions) { private static void checkDescription(LangStringTextType description) { if (description != null) { - checkLanguage(description.getLanguage(), "description language"); - checkText(description.getText(), MAX_DESCRIPTION_TEXT_LENGTH, true, "description text"); + CommonConstraintHelper.checkLanguage(description.getLanguage(), "description language"); + CommonConstraintHelper.checkText(description.getText(), MAX_DESCRIPTION_TEXT_LENGTH, true, "description text"); } } @@ -157,8 +126,8 @@ private static void checkDisplayNames(List names) { private static void checkDisplayName(LangStringNameType name) { if (name != null) { - checkLanguage(name.getLanguage(), "display name language"); - checkText(name.getText(), MAX_IDSHORT_LENGTH, true, "display name text"); + CommonConstraintHelper.checkLanguage(name.getLanguage(), "display name language"); + CommonConstraintHelper.checkText(name.getText(), MAX_IDSHORT_LENGTH, true, "display name text"); } } @@ -172,204 +141,21 @@ private static void checkExtensions(List extensions) { private static void checkExtension(Extension extension) { if (extension != null) { - checkText(extension.getName(), MAX_IDSHORT_LENGTH, true, "extension name"); - checkReference(extension.getSemanticId()); - checkReferences(extension.getSupplementalSemanticIds()); - checkReferences(extension.getRefersTo()); - } - } - - - private static void checkReferenceParent(Reference reference) { - if (reference != null) { - if (reference.getType() == null) { - raiseConstraintViolatedException("no reference type provided"); - } - if ((reference.getKeys() == null) || reference.getKeys().isEmpty()) { - raiseConstraintViolatedException("no keys provided"); - } - - reference.getKeys().stream().forEach(ConstraintHelper::checkKey); - } - } - - - private static void checkReferences(List references) { - if (references != null) { - references.stream().forEach(ConstraintHelper::checkReference); - } - } - - - private static void checkReference(Reference reference) { - if (reference != null) { - checkReferenceParent(reference); - checkReferenceParent(reference.getReferredSemanticId()); - } - } - - - private static void checkKey(Key key) { - if (key.getType() == null) { - raiseConstraintViolatedException("no key type provided"); + CommonConstraintHelper.checkText(extension.getName(), MAX_IDSHORT_LENGTH, true, "extension name"); + CommonConstraintHelper.checkReference(extension.getSemanticId()); + CommonConstraintHelper.checkReferences(extension.getSupplementalSemanticIds()); + CommonConstraintHelper.checkReferences(extension.getRefersTo()); } - checkText(key.getValue(), MAX_IDENTIFIER_LENGTH, true, "key value"); } private static void checkAdministrativeInformation(AdministrativeInformation adminInfo) { if (adminInfo != null) { - checkEmbeddedDataSpecifications(adminInfo.getEmbeddedDataSpecifications()); + DataSpecificationConstraintHelper.checkEmbeddedDataSpecifications(adminInfo.getEmbeddedDataSpecifications()); checkVersion(adminInfo.getVersion(), "Version"); checkVersion(adminInfo.getRevision(), "Revision"); - checkReference(adminInfo.getCreator()); - checkText(adminInfo.getTemplateId(), MAX_IDENTIFIER_LENGTH, false, "templateId"); - } - } - - - private static void checkEmbeddedDataSpecifications(List specs) { - if (specs != null) { - specs.stream().forEach(ConstraintHelper::checkEmbeddedDataSpecification); - } - } - - - private static void checkEmbeddedDataSpecification(EmbeddedDataSpecification data) { - if (data != null) { - if (data.getDataSpecification() == null) { - raiseConstraintViolatedException("no DataSpecification provided"); - } - checkReference(data.getDataSpecification()); - checkDataSpecificationContent(data.getDataSpecificationContent()); - } - } - - - private static void checkDataSpecificationContent(DataSpecificationContent content) { - if (content == null) { - raiseConstraintViolatedException("no DataSpecificationContent provided"); - } - else if (content instanceof DataSpecificationIec61360 dataSpecificationIec61360) { - checkDataSpecificationIec61360(dataSpecificationIec61360); - } - } - - - private static void checkDataSpecificationIec61360(DataSpecificationIec61360 dataSpec) { - checkIec61360Names(dataSpec.getPreferredName()); - checkIec61360ShortNames(dataSpec.getShortName()); - checkText(dataSpec.getUnit(), 0, false, "IEC 61360: unit"); - checkReference(dataSpec.getUnitId()); - checkText(dataSpec.getSourceOfDefinition(), 0, false, "IEC 61360: source of definition"); - checkText(dataSpec.getSymbol(), 0, false, "IEC 61360: symbol"); - checkIec61360Definitions(dataSpec.getDefinition()); - checkText(dataSpec.getValueFormat(), 0, false, "IEC 61360: value format"); - checkValueList(dataSpec.getValueList()); - checkText(dataSpec.getValue(), MAX_IDENTIFIER_LENGTH, false, "IEC 61360: value"); - } - - - private static void checkIec61360Names(List names) { - if ((names == null) || names.isEmpty()) { - raiseConstraintViolatedException("no IEC 61360 Preferred Name provided"); - } - else { - names.stream().forEach(ConstraintHelper::checkIec61360Name); - } - } - - - private static void checkIec61360Name(LangStringPreferredNameTypeIec61360 name) { - if (name != null) { - checkLanguage(name.getLanguage(), "IEC 61360 PreferredName language"); - checkText(name.getText(), MAX_IEC61360_NAME_TEXT_LENGTH, true, "IEC 61360 PreferredName text"); - } - else { - raiseConstraintViolatedException("IEC 61360 PreferredName not provided"); - } - } - - - private static void checkIec61360ShortNames(List names) { - if ((names == null) || names.isEmpty()) { - raiseConstraintViolatedException("no IEC 61360 Short Name provided"); - } - else { - names.stream().forEach(ConstraintHelper::checkIec61360ShortName); - } - } - - - private static void checkIec61360ShortName(LangStringShortNameTypeIec61360 name) { - if (name != null) { - checkLanguage(name.getLanguage(), "IEC 61360 ShortName language"); - checkText(name.getText(), MAX_IEC61360_SHORT_NAME_TEXT_LENGTH, true, "IEC 61360 ShortName"); - } - } - - - private static void checkIec61360Definitions(List definitions) { - if (definitions != null) { - definitions.stream().forEach(ConstraintHelper::checkIec61360Definition); - } - } - - - private static void checkIec61360Definition(LangStringDefinitionTypeIec61360 definition) { - if (definition != null) { - checkLanguage(definition.getLanguage(), "IEC 61360 definition language"); - checkText(definition.getText(), MAX_DESCRIPTION_TEXT_LENGTH, true, "IEC 61360 definition text"); - } - } - - - private static void checkText(String txt, int maxLength, boolean notNull, String msg) { - if (notNull && (txt == null)) { - raiseConstraintViolatedException(String.format("%s is null", msg)); - } - if (txt != null) { - if (txt.isEmpty()) { - raiseConstraintViolatedException(String.format("%s is empty", msg)); - } - else if ((maxLength > 0) && (txt.length() > maxLength)) { - raiseConstraintViolatedException(String.format("%s too long", msg)); - } - else if (!TEXT_PATTERN.matcher(txt).matches()) { - raiseConstraintViolatedException(String.format("%s doesn't match the pattern", msg)); - } - } - } - - - private static void checkLanguage(String language, String msg) { - if (language == null) { - raiseConstraintViolatedException(String.format("no %s provided", msg)); - } - else if (!LANG_LANGUAGE_PATTERN.matcher(language).matches()) { - raiseConstraintViolatedException(String.format("%s doesn't match the pattern", msg)); - } - } - - - private static void checkValueList(ValueList values) { - if (values != null) { - checkValueReferencePairs(values.getValueReferencePairs()); - } - } - - - private static void checkValueReferencePairs(List pairs) { - if (pairs != null) { - pairs.stream().forEach(ConstraintHelper::checkValueReferencePair); - } - } - - - private static void checkValueReferencePair(ValueReferencePair pair) { - if (pair != null) { - checkText(pair.getValue(), MAX_IDENTIFIER_LENGTH, true, "ValueReferencePair value"); - checkReference(pair.getValueId()); + CommonConstraintHelper.checkReference(adminInfo.getCreator()); + CommonConstraintHelper.checkText(adminInfo.getTemplateId(), MAX_IDENTIFIER_LENGTH, false, "templateId"); } } @@ -377,60 +163,13 @@ private static void checkValueReferencePair(ValueReferencePair pair) { private static void checkVersion(String version, String msg) { if (version != null) { if (version.isEmpty()) { - raiseConstraintViolatedException(String.format("%s is empty", msg)); + CommonConstraintHelper.raiseConstraintViolatedException(String.format("%s is empty", msg)); } else if (version.length() > MAX_VERSION_LENGTH) { - raiseConstraintViolatedException(String.format("%s too long", msg)); + CommonConstraintHelper.raiseConstraintViolatedException(String.format("%s too long", msg)); } else if (!VERSION_PATTERN.matcher(version).matches()) { - raiseConstraintViolatedException(String.format("%s doesn't match the pattern", msg)); - } - } - } - - - private static void checkEndpoints(List endpoints) { - if (endpoints != null) { - endpoints.stream().forEach(ConstraintHelper::checkEndpoint); - } - } - - - private static void checkEndpoint(Endpoint endpoint) { - if (endpoint != null) { - checkText(endpoint.getInterfaceInformation(), MAX_IDSHORT_LENGTH, true, "Interface Information"); - checkProtocolInformation(endpoint.getProtocolInformation()); - } - } - - - private static void checkProtocolInformation(ProtocolInformation protocolInformation) { - if (protocolInformation != null) { - checkText(protocolInformation.getHref(), MAX_STRING_2048_LENGTH, true, "href"); - checkText(protocolInformation.getEndpointProtocol(), MAX_IDSHORT_LENGTH, false, "Endpoint Protocol"); - checkText(protocolInformation.getEndpointProtocolVersion(), MAX_IDSHORT_LENGTH, false, "Endpoint Protocol Version"); - checkText(protocolInformation.getSubprotocol(), MAX_IDSHORT_LENGTH, false, "Subprotocol"); - checkText(protocolInformation.getSubprotocolBody(), MAX_IDSHORT_LENGTH, false, "Subprotocol Body"); - checkText(protocolInformation.getSubprotocolBodyEncoding(), MAX_IDSHORT_LENGTH, false, "Subprotocol Body Encoding"); - checkSecurityAttributes(protocolInformation.getSecurityAttributes()); - } - } - - - private static void checkSecurityAttributes(List securityAttributes) { - if (securityAttributes != null) { - securityAttributes.stream().forEach(ConstraintHelper::checkSecurityAttribute); - } - } - - - private static void checkSecurityAttribute(SecurityAttributeObject securityAttribute) { - if (securityAttribute != null) { - if (securityAttribute.getKey() == null) { - raiseConstraintViolatedException("Key is null"); - } - else if (securityAttribute.getValue() == null) { - raiseConstraintViolatedException("Value is null"); + CommonConstraintHelper.raiseConstraintViolatedException(String.format("%s doesn't match the pattern", msg)); } } } @@ -445,16 +184,12 @@ private static void checkSpecificAssetIds(List specificAssetIds private static void checkSpecificAssetId(SpecificAssetId specificAssetId) { if (specificAssetId != null) { - checkReference(specificAssetId.getSemanticId()); - checkReferences(specificAssetId.getSupplementalSemanticIds()); - checkText(specificAssetId.getName(), MAX_LABEL_LENGTH, true, "Specific Asset ID Name"); - checkText(specificAssetId.getValue(), MAX_IDENTIFIER_LENGTH, true, "Specific Asset ID value"); - checkReference(specificAssetId.getExternalSubjectId()); + CommonConstraintHelper.checkReference(specificAssetId.getSemanticId()); + CommonConstraintHelper.checkReferences(specificAssetId.getSupplementalSemanticIds()); + CommonConstraintHelper.checkText(specificAssetId.getName(), MAX_LABEL_LENGTH, true, "Specific Asset ID Name"); + CommonConstraintHelper.checkText(specificAssetId.getValue(), MAX_IDENTIFIER_LENGTH, true, "Specific Asset ID value"); + CommonConstraintHelper.checkReference(specificAssetId.getExternalSubjectId()); } } - - private static void raiseConstraintViolatedException(String txt) { - throw new BadRequestException(txt); - } } diff --git a/service/src/main/java/helper/DataSpecificationConstraintHelper.java b/service/src/main/java/helper/DataSpecificationConstraintHelper.java new file mode 100644 index 00000000..73d37f95 --- /dev/null +++ b/service/src/main/java/helper/DataSpecificationConstraintHelper.java @@ -0,0 +1,160 @@ +/* + * Copyright (c) 2021 Fraunhofer IOSB, eine rechtlich nicht selbstaendige + * Einrichtung der Fraunhofer-Gesellschaft zur Foerderung der angewandten + * Forschung e.V. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package helper; + +import static helper.ConstraintHelper.MAX_IDENTIFIER_LENGTH; + +import java.util.List; +import org.eclipse.digitaltwin.aas4j.v3.model.DataSpecificationContent; +import org.eclipse.digitaltwin.aas4j.v3.model.DataSpecificationIec61360; +import org.eclipse.digitaltwin.aas4j.v3.model.EmbeddedDataSpecification; +import org.eclipse.digitaltwin.aas4j.v3.model.LangStringDefinitionTypeIec61360; +import org.eclipse.digitaltwin.aas4j.v3.model.LangStringPreferredNameTypeIec61360; +import org.eclipse.digitaltwin.aas4j.v3.model.LangStringShortNameTypeIec61360; +import org.eclipse.digitaltwin.aas4j.v3.model.ValueList; +import org.eclipse.digitaltwin.aas4j.v3.model.ValueReferencePair; + + +/** + * Helper class for validating DataSpecification constraints. + */ +public class DataSpecificationConstraintHelper { + + private DataSpecificationConstraintHelper() {} + + + /** + * Checks the constraints of the given Embedded Data Specification. + * + * @param specs The desired Embedded Data Specification. + */ + public static void checkEmbeddedDataSpecifications(List specs) { + if (specs != null) { + specs.stream().forEach(DataSpecificationConstraintHelper::checkEmbeddedDataSpecification); + } + } + + + private static void checkEmbeddedDataSpecification(EmbeddedDataSpecification data) { + if (data != null) { + if (data.getDataSpecification() == null) { + CommonConstraintHelper.raiseConstraintViolatedException("no DataSpecification provided"); + } + CommonConstraintHelper.checkReference(data.getDataSpecification()); + checkDataSpecificationContent(data.getDataSpecificationContent()); + } + } + + + private static void checkDataSpecificationContent(DataSpecificationContent content) { + if (content == null) { + CommonConstraintHelper.raiseConstraintViolatedException("no DataSpecificationContent provided"); + } + else if (content instanceof DataSpecificationIec61360 dataSpecificationIec61360) { + checkDataSpecificationIec61360(dataSpecificationIec61360); + } + } + + + private static void checkDataSpecificationIec61360(DataSpecificationIec61360 dataSpec) { + checkIec61360Names(dataSpec.getPreferredName()); + checkIec61360ShortNames(dataSpec.getShortName()); + CommonConstraintHelper.checkText(dataSpec.getUnit(), 0, false, "IEC 61360: unit"); + CommonConstraintHelper.checkReference(dataSpec.getUnitId()); + CommonConstraintHelper.checkText(dataSpec.getSourceOfDefinition(), 0, false, "IEC 61360: source of definition"); + CommonConstraintHelper.checkText(dataSpec.getSymbol(), 0, false, "IEC 61360: symbol"); + checkIec61360Definitions(dataSpec.getDefinition()); + CommonConstraintHelper.checkText(dataSpec.getValueFormat(), 0, false, "IEC 61360: value format"); + checkValueList(dataSpec.getValueList()); + CommonConstraintHelper.checkText(dataSpec.getValue(), ConstraintHelper.MAX_IDENTIFIER_LENGTH, false, "IEC 61360: value"); + } + + + private static void checkIec61360Names(List names) { + if ((names == null) || names.isEmpty()) { + CommonConstraintHelper.raiseConstraintViolatedException("no IEC 61360 Preferred Name provided"); + } + else { + names.stream().forEach(DataSpecificationConstraintHelper::checkIec61360Name); + } + } + + + private static void checkIec61360Name(LangStringPreferredNameTypeIec61360 name) { + if (name != null) { + CommonConstraintHelper.checkLanguage(name.getLanguage(), "IEC 61360 PreferredName language"); + CommonConstraintHelper.checkText(name.getText(), ConstraintHelper.MAX_IEC61360_NAME_TEXT_LENGTH, true, "IEC 61360 PreferredName text"); + } + else { + CommonConstraintHelper.raiseConstraintViolatedException("IEC 61360 PreferredName not provided"); + } + } + + + private static void checkIec61360ShortNames(List names) { + if ((names == null) || names.isEmpty()) { + CommonConstraintHelper.raiseConstraintViolatedException("no IEC 61360 Short Name provided"); + } + else { + names.stream().forEach(DataSpecificationConstraintHelper::checkIec61360ShortName); + } + } + + + private static void checkIec61360ShortName(LangStringShortNameTypeIec61360 name) { + if (name != null) { + CommonConstraintHelper.checkLanguage(name.getLanguage(), "IEC 61360 ShortName language"); + CommonConstraintHelper.checkText(name.getText(), ConstraintHelper.MAX_IEC61360_SHORT_NAME_TEXT_LENGTH, true, "IEC 61360 ShortName"); + } + } + + + private static void checkIec61360Definitions(List definitions) { + if (definitions != null) { + definitions.stream().forEach(DataSpecificationConstraintHelper::checkIec61360Definition); + } + } + + + private static void checkIec61360Definition(LangStringDefinitionTypeIec61360 definition) { + if (definition != null) { + CommonConstraintHelper.checkLanguage(definition.getLanguage(), "IEC 61360 definition language"); + CommonConstraintHelper.checkText(definition.getText(), ConstraintHelper.MAX_DESCRIPTION_TEXT_LENGTH, true, "IEC 61360 definition text"); + } + } + + + private static void checkValueList(ValueList values) { + if (values != null) { + checkValueReferencePairs(values.getValueReferencePairs()); + } + } + + + private static void checkValueReferencePairs(List pairs) { + if (pairs != null) { + pairs.stream().forEach(DataSpecificationConstraintHelper::checkValueReferencePair); + } + } + + + private static void checkValueReferencePair(ValueReferencePair pair) { + if (pair != null) { + CommonConstraintHelper.checkText(pair.getValue(), MAX_IDENTIFIER_LENGTH, true, "ValueReferencePair value"); + CommonConstraintHelper.checkReference(pair.getValueId()); + } + } + +} diff --git a/service/src/main/java/helper/EndpointConstraintHelper.java b/service/src/main/java/helper/EndpointConstraintHelper.java new file mode 100644 index 00000000..6748225f --- /dev/null +++ b/service/src/main/java/helper/EndpointConstraintHelper.java @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2021 Fraunhofer IOSB, eine rechtlich nicht selbstaendige + * Einrichtung der Fraunhofer-Gesellschaft zur Foerderung der angewandten + * Forschung e.V. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package helper; + +import static helper.ConstraintHelper.MAX_IDSHORT_LENGTH; + +import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.Endpoint; +import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.ProtocolInformation; +import java.util.List; +import org.eclipse.digitaltwin.aas4j.v3.model.SecurityAttributeObject; + + +/** + * Helper class for validating endpoint constraints. + */ +public class EndpointConstraintHelper { + + private EndpointConstraintHelper() {} + + + /** + * Checks the constraints of the given list of endpoints. + * + * @param endpoints + */ + public static void checkEndpoints(List endpoints) { + if (endpoints != null) { + endpoints.stream().forEach(EndpointConstraintHelper::checkEndpoint); + } + } + + + private static void checkEndpoint(Endpoint endpoint) { + if (endpoint != null) { + CommonConstraintHelper.checkText(endpoint.getInterfaceInformation(), MAX_IDSHORT_LENGTH, true, "Interface Information"); + checkProtocolInformation(endpoint.getProtocolInformation()); + } + } + + + private static void checkProtocolInformation(ProtocolInformation protocolInformation) { + if (protocolInformation != null) { + CommonConstraintHelper.checkText(protocolInformation.getHref(), ConstraintHelper.MAX_STRING_2048_LENGTH, true, "href"); + CommonConstraintHelper.checkText(protocolInformation.getEndpointProtocol(), MAX_IDSHORT_LENGTH, false, "Endpoint Protocol"); + CommonConstraintHelper.checkText(protocolInformation.getEndpointProtocolVersion(), MAX_IDSHORT_LENGTH, false, "Endpoint Protocol Version"); + CommonConstraintHelper.checkText(protocolInformation.getSubprotocol(), MAX_IDSHORT_LENGTH, false, "Subprotocol"); + CommonConstraintHelper.checkText(protocolInformation.getSubprotocolBody(), MAX_IDSHORT_LENGTH, false, "Subprotocol Body"); + CommonConstraintHelper.checkText(protocolInformation.getSubprotocolBodyEncoding(), MAX_IDSHORT_LENGTH, false, "Subprotocol Body Encoding"); + checkSecurityAttributes(protocolInformation.getSecurityAttributes()); + } + } + + + private static void checkSecurityAttributes(List securityAttributes) { + if (securityAttributes != null) { + securityAttributes.stream().forEach(EndpointConstraintHelper::checkSecurityAttribute); + } + } + + + private static void checkSecurityAttribute(SecurityAttributeObject securityAttribute) { + if (securityAttribute != null) { + if (securityAttribute.getKey() == null) { + CommonConstraintHelper.raiseConstraintViolatedException("Key is null"); + } + else if (securityAttribute.getValue() == null) { + CommonConstraintHelper.raiseConstraintViolatedException("Value is null"); + } + } + } + +} From 40e3ca6d0c01e2b9c8f74f6e4cc8361d557ea697 Mon Sep 17 00:00:00 2001 From: Tino Bischoff Date: Thu, 21 Mar 2024 16:48:49 +0100 Subject: [PATCH 27/57] add paging support --- service/pom.xml | 5 ++ .../registry/service/RegistryService.java | 79 +++++++++++++++++-- .../service/ShellRegistryController.java | 33 ++++++-- .../service/SubmodelRegistryController.java | 15 +++- .../config/DescriptorMapperConfig.java | 5 +- 5 files changed, 119 insertions(+), 18 deletions(-) diff --git a/service/pom.xml b/service/pom.xml index fc9b8a3c..e4cb5b90 100644 --- a/service/pom.xml +++ b/service/pom.xml @@ -55,6 +55,11 @@ h2 ${h2.version} + + de.fraunhofer.iosb.ilt.faaast.service + dataformat-json + ${faaast.service.version} + de.fraunhofer.iosb.ilt.faaast.service model diff --git a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/RegistryService.java b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/RegistryService.java index 2b4334d4..075a19d5 100644 --- a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/RegistryService.java +++ b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/RegistryService.java @@ -18,12 +18,18 @@ import de.fraunhofer.iosb.ilt.faaast.registry.core.exception.BadRequestException; import de.fraunhofer.iosb.ilt.faaast.registry.core.exception.ResourceAlreadyExistsException; import de.fraunhofer.iosb.ilt.faaast.registry.core.exception.ResourceNotFoundException; +import de.fraunhofer.iosb.ilt.faaast.service.model.api.paging.Page; +import de.fraunhofer.iosb.ilt.faaast.service.model.api.paging.PagingInfo; +import de.fraunhofer.iosb.ilt.faaast.service.model.api.paging.PagingMetadata; import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.AssetAdministrationShellDescriptor; import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.SubmodelDescriptor; import de.fraunhofer.iosb.ilt.faaast.service.util.Ensure; import helper.ConstraintHelper; import helper.RegistryHelper; import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; +import java.util.stream.Stream; import org.eclipse.digitaltwin.aas4j.v3.model.AssetKind; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -49,10 +55,16 @@ public class RegistryService { * * @param assetType The desired Asset Type. * @param assetKind The desired Asset Kind. + * @param paging The paging information. * @return The list of all registered Asset Administration Shells. */ - public List getAASs(String assetType, AssetKind assetKind) { - return aasRepository.getAASs(RegistryHelper.decode(assetType), assetKind); + public Page getAASs(String assetType, AssetKind assetKind, PagingInfo paging) { + List list = aasRepository.getAASs(RegistryHelper.decode(assetType), assetKind); + return preparePagedResult(list.stream(), paging); + //return Page. builder() + // .metadata(PagingMetadata.builder().build()) + // .result(list) + // .build(); } @@ -119,11 +131,12 @@ public AssetAdministrationShellDescriptor updateAAS(String id, AssetAdministrati /** * Retrieves a list of all registered Submodels. * + * @param paging The paging information. * @return The list of Submodels. * @throws ResourceNotFoundException When the AAS was not found. */ - public List getSubmodels() throws ResourceNotFoundException { - return getSubmodels(null); + public Page getSubmodels(PagingInfo paging) throws ResourceNotFoundException { + return getSubmodels(null, paging); } @@ -131,17 +144,20 @@ public List getSubmodels() throws ResourceNotFoundException * Retrieves a list of all Submodels of the given Asset Administration Shell. * * @param aasId The ID of the desired Asset Administration Shell. + * @param paging The paging information. * @return The list of Submodels. * @throws ResourceNotFoundException When the AAS was not found. */ - public List getSubmodels(String aasId) throws ResourceNotFoundException { + public Page getSubmodels(String aasId, PagingInfo paging) throws ResourceNotFoundException { + List list; if (aasId == null) { - return aasRepository.getSubmodels(); + list = aasRepository.getSubmodels(); } else { String aasIdDecoded = RegistryHelper.decode(aasId); - return aasRepository.getSubmodels(aasIdDecoded); + list = aasRepository.getSubmodels(aasIdDecoded); } + return preparePagedResult(list.stream(), paging); } @@ -299,4 +315,53 @@ private void checkShellIdentifiers(AssetAdministrationShellDescriptor aas) throw throw new BadRequestException("no AAS Identification provided"); } } + + + private static Page preparePagedResult(Stream input, PagingInfo paging) { + Stream result = input; + if (Objects.nonNull(paging.getCursor())) { + result = result.skip(readCursor(paging.getCursor())); + } + if (paging.hasLimit()) { + result = result.limit(paging.getLimit() + 1); + } + List temp = result.collect(Collectors.toList()); + return Page. builder() + .result(temp.stream() + .limit(paging.hasLimit() ? paging.getLimit() : temp.size()) + .collect(Collectors.toList())) + .metadata(PagingMetadata.builder() + .cursor(nextCursor(paging, temp.size())) + .build()) + .build(); + } + + + private static long readCursor(String cursor) { + return Long.parseLong(cursor); + } + + + private static String writeCursor(long index) { + return Long.toString(index); + } + + + private static String nextCursor(PagingInfo paging, int resultCount) { + return nextCursor(paging, paging.hasLimit() && resultCount > paging.getLimit()); + } + + + private static String nextCursor(PagingInfo paging, boolean hasMoreData) { + if (!hasMoreData) { + return null; + } + if (!paging.hasLimit()) { + throw new IllegalStateException("unable to generate next cursor for paging - there should not be more data available if previous request did not have a limit set"); + } + if (Objects.isNull(paging.getCursor())) { + return writeCursor(paging.getLimit()); + } + return writeCursor(readCursor(paging.getCursor()) + paging.getLimit()); + } } diff --git a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/ShellRegistryController.java b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/ShellRegistryController.java index b97c7bff..cdfa9286 100644 --- a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/ShellRegistryController.java +++ b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/ShellRegistryController.java @@ -16,11 +16,12 @@ import de.fraunhofer.iosb.ilt.faaast.registry.core.exception.ResourceAlreadyExistsException; import de.fraunhofer.iosb.ilt.faaast.registry.core.exception.ResourceNotFoundException; +import de.fraunhofer.iosb.ilt.faaast.service.model.api.paging.Page; +import de.fraunhofer.iosb.ilt.faaast.service.model.api.paging.PagingInfo; import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.AssetAdministrationShellDescriptor; import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.SubmodelDescriptor; import helper.RegistryHelper; import java.net.URI; -import java.util.List; import org.eclipse.digitaltwin.aas4j.v3.model.AssetKind; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -57,15 +58,24 @@ public class ShellRegistryController { * * @param assetType The desired Asset Type. * @param assetKind The desired Asset Kind. + * @param limit The limit value. + * @param cursor The cursor value. * @return The list of all registered Asset Administration Shells. */ @GetMapping() - public List getAASs(@RequestParam(name = "assetType", required = false) String assetType, - @RequestParam(name = "assetKind", required = false) AssetKind assetKind) { + //public List getAASs(@RequestParam(name = "assetType", required = false) String assetType, + public Page getAASs(@RequestParam(name = "assetType", required = false) String assetType, + @RequestParam(name = "assetKind", required = false) AssetKind assetKind, + @RequestParam(name = "limit", required = false) Long limit, + @RequestParam(name = "cursor", required = false) String cursor) { // Asset type is Base64URL encoded // perhaps constraint: @Size(min=1, max=2000) - LOGGER.debug("getAASs: AssetType {}; AssetKind {}", assetType, assetKind); - return service.getAASs(assetType, assetKind); + LOGGER.debug("getAASs: AssetType {}; AssetKind {}, Limit: {}, Cursor: {}", assetType, assetKind, limit, cursor); + PagingInfo.Builder pageBuilder = PagingInfo.builder().cursor(cursor); + if (limit != null) { + pageBuilder.limit(limit); + } + return service.getAASs(assetType, assetKind, pageBuilder.build()); } @@ -134,12 +144,21 @@ public AssetAdministrationShellDescriptor update(@PathVariable("aasIdentifier") * Retrieves a list of all Submodels of the given Asset Administration Shell. * * @param aasIdentifier The ID of the desired Asset Administration Shell. + * @param limit The limit value. + * @param cursor The cursor value. * @return The list of Submodels. * @throws ResourceNotFoundException When the AAS was not found. */ @GetMapping(value = "/{aasIdentifier}/submodel-descriptors") - public List getSubmodelsOfAAS(@PathVariable("aasIdentifier") String aasIdentifier) throws ResourceNotFoundException { - return service.getSubmodels(aasIdentifier); + public Page getSubmodelsOfAAS(@PathVariable("aasIdentifier") String aasIdentifier, + @RequestParam(name = "limit", required = false) Long limit, + @RequestParam(name = "cursor", required = false) String cursor) + throws ResourceNotFoundException { + PagingInfo.Builder pageBuilder = PagingInfo.builder().cursor(cursor); + if (limit != null) { + pageBuilder.limit(limit); + } + return service.getSubmodels(aasIdentifier, pageBuilder.build()); } diff --git a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/SubmodelRegistryController.java b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/SubmodelRegistryController.java index 13289a51..2ac2d959 100644 --- a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/SubmodelRegistryController.java +++ b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/SubmodelRegistryController.java @@ -16,10 +16,11 @@ import de.fraunhofer.iosb.ilt.faaast.registry.core.exception.ResourceAlreadyExistsException; import de.fraunhofer.iosb.ilt.faaast.registry.core.exception.ResourceNotFoundException; +import de.fraunhofer.iosb.ilt.faaast.service.model.api.paging.Page; +import de.fraunhofer.iosb.ilt.faaast.service.model.api.paging.PagingInfo; import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.SubmodelDescriptor; import helper.RegistryHelper; import java.net.URI; -import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -30,6 +31,7 @@ import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.servlet.support.ServletUriComponentsBuilder; @@ -48,12 +50,19 @@ public class SubmodelRegistryController { /** * Retrieves a list of all registered Submodels. * + * @param limit The limit value. + * @param cursor The cursor value. * @return The list of Submodels. * @throws ResourceNotFoundException When the Submodel was not found. */ @GetMapping() - public List getSubmodels() throws ResourceNotFoundException { - return service.getSubmodels(); + public Page getSubmodels(@RequestParam(name = "limit", required = false) Long limit, @RequestParam(name = "cursor", required = false) String cursor) + throws ResourceNotFoundException { + PagingInfo.Builder pageBuilder = PagingInfo.builder().cursor(cursor); + if (limit != null) { + pageBuilder.limit(limit); + } + return service.getSubmodels(pageBuilder.build()); } diff --git a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/config/DescriptorMapperConfig.java b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/config/DescriptorMapperConfig.java index f4857b77..37a0ff1f 100644 --- a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/config/DescriptorMapperConfig.java +++ b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/config/DescriptorMapperConfig.java @@ -17,6 +17,8 @@ import com.fasterxml.jackson.core.Version; import com.fasterxml.jackson.databind.module.SimpleAbstractTypeResolver; import com.fasterxml.jackson.databind.module.SimpleModule; +import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.mixins.PageMixin; +import de.fraunhofer.iosb.ilt.faaast.service.model.api.paging.Page; import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.AssetAdministrationShellDescriptor; import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.Endpoint; import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.ProtocolInformation; @@ -83,6 +85,7 @@ public Jackson2ObjectMapperBuilder jackson2ObjectMapperBuilder() { module.setAbstractTypes(resolver); return new Jackson2ObjectMapperBuilder() - .modules(module); + .modules(module) + .mixIn(Page.class, PageMixin.class); } } From c0fe1569d7fd3bd34e1598c87be7418f11076d6d Mon Sep 17 00:00:00 2001 From: Tino Bischoff Date: Thu, 21 Mar 2024 17:28:20 +0100 Subject: [PATCH 28/57] cleanup pom.xml --- pom.xml | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/pom.xml b/pom.xml index 315c994a..0ada1e44 100644 --- a/pom.xml +++ b/pom.xml @@ -49,9 +49,6 @@ 3.25.3 10.14.2 - 1.16.1 - 2.15.1 - 3.14.0 1.0.0-SNAPSHOT 2.2.224 8.0.1.Final @@ -70,11 +67,9 @@ 0.8.11 3.3.0 3.6.3 - 2.0.0 1.6.13 9.0.10 4.7.5 - 2.5.3 3.5.2 3.3.0 2.43.0 @@ -84,12 +79,6 @@ ${project.basedir} 2.0.12 2.2 - ${maven.multiModuleProjectDirectory}/test/target/site/jacoco-aggregate/jacoco.xml - reuseReports - https://sonarcloud.io - jacoco - java - fraunhofer-iosb 3.2.3 From ef9c42459e98e5494772b1be2d50ad2c642a3544 Mon Sep 17 00:00:00 2001 From: Tino Bischoff Date: Fri, 22 Mar 2024 16:34:21 +0100 Subject: [PATCH 29/57] check constraints --- .../ilt/faaast/registry/service/RegistryService.java | 11 ++++++----- .../registry/service/ShellRegistryController.java | 9 +++++++-- .../registry/service/SubmodelRegistryController.java | 4 ++++ 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/RegistryService.java b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/RegistryService.java index 075a19d5..6a333b56 100644 --- a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/RegistryService.java +++ b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/RegistryService.java @@ -59,12 +59,13 @@ public class RegistryService { * @return The list of all registered Asset Administration Shells. */ public Page getAASs(String assetType, AssetKind assetKind, PagingInfo paging) { - List list = aasRepository.getAASs(RegistryHelper.decode(assetType), assetKind); + // Asset type is Base64URL encoded + String assetTypeDecoded = RegistryHelper.decode(assetType); + if ((assetTypeDecoded != null) && (assetTypeDecoded.length() > ConstraintHelper.MAX_IDENTIFIER_LENGTH)) { + throw new BadRequestException("AssetType too long"); + } + List list = aasRepository.getAASs(assetTypeDecoded, assetKind); return preparePagedResult(list.stream(), paging); - //return Page. builder() - // .metadata(PagingMetadata.builder().build()) - // .result(list) - // .build(); } diff --git a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/ShellRegistryController.java b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/ShellRegistryController.java index cdfa9286..e33eaa67 100644 --- a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/ShellRegistryController.java +++ b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/ShellRegistryController.java @@ -14,6 +14,7 @@ */ package de.fraunhofer.iosb.ilt.faaast.registry.service; +import de.fraunhofer.iosb.ilt.faaast.registry.core.exception.BadRequestException; import de.fraunhofer.iosb.ilt.faaast.registry.core.exception.ResourceAlreadyExistsException; import de.fraunhofer.iosb.ilt.faaast.registry.core.exception.ResourceNotFoundException; import de.fraunhofer.iosb.ilt.faaast.service.model.api.paging.Page; @@ -68,11 +69,12 @@ public Page getAASs(@RequestParam(name = "as @RequestParam(name = "assetKind", required = false) AssetKind assetKind, @RequestParam(name = "limit", required = false) Long limit, @RequestParam(name = "cursor", required = false) String cursor) { - // Asset type is Base64URL encoded - // perhaps constraint: @Size(min=1, max=2000) LOGGER.debug("getAASs: AssetType {}; AssetKind {}, Limit: {}, Cursor: {}", assetType, assetKind, limit, cursor); PagingInfo.Builder pageBuilder = PagingInfo.builder().cursor(cursor); if (limit != null) { + if (limit == 0) { + throw new BadRequestException("Limit must be greater than 0"); + } pageBuilder.limit(limit); } return service.getAASs(assetType, assetKind, pageBuilder.build()); @@ -156,6 +158,9 @@ public Page getSubmodelsOfAAS(@PathVariable("aasIdentifier") throws ResourceNotFoundException { PagingInfo.Builder pageBuilder = PagingInfo.builder().cursor(cursor); if (limit != null) { + if (limit == 0) { + throw new BadRequestException("Limit must be greater than 0"); + } pageBuilder.limit(limit); } return service.getSubmodels(aasIdentifier, pageBuilder.build()); diff --git a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/SubmodelRegistryController.java b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/SubmodelRegistryController.java index 2ac2d959..cc9d207a 100644 --- a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/SubmodelRegistryController.java +++ b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/SubmodelRegistryController.java @@ -14,6 +14,7 @@ */ package de.fraunhofer.iosb.ilt.faaast.registry.service; +import de.fraunhofer.iosb.ilt.faaast.registry.core.exception.BadRequestException; import de.fraunhofer.iosb.ilt.faaast.registry.core.exception.ResourceAlreadyExistsException; import de.fraunhofer.iosb.ilt.faaast.registry.core.exception.ResourceNotFoundException; import de.fraunhofer.iosb.ilt.faaast.service.model.api.paging.Page; @@ -60,6 +61,9 @@ public Page getSubmodels(@RequestParam(name = "limit", requi throws ResourceNotFoundException { PagingInfo.Builder pageBuilder = PagingInfo.builder().cursor(cursor); if (limit != null) { + if (limit == 0) { + throw new BadRequestException("Limit must be greater than 0"); + } pageBuilder.limit(limit); } return service.getSubmodels(pageBuilder.build()); From d44c1f51e7f71a1c10532e578cd353d036a51466 Mon Sep 17 00:00:00 2001 From: Tino Bischoff Date: Mon, 25 Mar 2024 16:57:10 +0100 Subject: [PATCH 30/57] update libs --- persistence/jpa/pom.xml | 2 +- pom.xml | 5 ++--- service/pom.xml | 5 ----- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/persistence/jpa/pom.xml b/persistence/jpa/pom.xml index 77fa5bd4..45fbdc70 100644 --- a/persistence/jpa/pom.xml +++ b/persistence/jpa/pom.xml @@ -45,7 +45,7 @@ test - org.hibernate + org.hibernate.orm hibernate-core ${hibernate.version} diff --git a/pom.xml b/pom.xml index 0ada1e44..e42a8dc1 100644 --- a/pom.xml +++ b/pom.xml @@ -49,9 +49,8 @@ 3.25.3 10.14.2 - 1.0.0-SNAPSHOT + 1.1.0-SNAPSHOT 2.2.224 - 8.0.1.Final 6.4.4.Final 2.17.0 4.13.2 @@ -79,7 +78,7 @@ ${project.basedir} 2.0.12 2.2 - 3.2.3 + 3.2.4 diff --git a/service/pom.xml b/service/pom.xml index e4cb5b90..c84e47ed 100644 --- a/service/pom.xml +++ b/service/pom.xml @@ -70,11 +70,6 @@ picocli-spring-boot-starter ${picocli.version} - org.postgresql postgresql From 510ec15e3baa5da68eae4eb09d570040360ea709 Mon Sep 17 00:00:00 2001 From: Tino Bischoff Date: Tue, 26 Mar 2024 14:10:46 +0100 Subject: [PATCH 31/57] use HTTPS --- .../registry/service/config/SslConfig.java | 54 +++++++++++++++ .../main/java/helper/CertificateHelper.java | 67 +++++++++++++++++++ .../src/main/resources/application.properties | 9 +++ 3 files changed, 130 insertions(+) create mode 100644 service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/config/SslConfig.java create mode 100644 service/src/main/java/helper/CertificateHelper.java diff --git a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/config/SslConfig.java b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/config/SslConfig.java new file mode 100644 index 00000000..8cdad42b --- /dev/null +++ b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/config/SslConfig.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2021 Fraunhofer IOSB, eine rechtlich nicht selbstaendige + * Einrichtung der Fraunhofer-Gesellschaft zur Foerderung der angewandten + * Forschung e.V. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package de.fraunhofer.iosb.ilt.faaast.registry.service.config; + +import helper.CertificateHelper; +import java.security.KeyStore; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.ssl.DefaultSslBundleRegistry; +import org.springframework.boot.ssl.SslBundle; +import org.springframework.boot.ssl.SslStoreBundle; +import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; +import org.springframework.boot.web.server.WebServerFactoryCustomizer; +import org.springframework.stereotype.Component; + + +/** + * SSL configuration with dynmic keystore. + */ +@Component +public class SslConfig implements WebServerFactoryCustomizer { + + private static final Logger LOGGER = LoggerFactory.getLogger(SslConfig.class); + + @Override + public void customize(TomcatServletWebServerFactory factory) { + // if no SSL Bundle is provided, we generate a self-signed certificate + if (factory.getSsl().getBundle() == null) { + LOGGER.info("Generating self-signed certificate for HTTPS (reason: no SSL-Bundle provided)"); + KeyStore keyStore = CertificateHelper.generateSelfSignedCertificate(); + SslStoreBundle storeBundle = SslStoreBundle.of(keyStore, null, null); + SslBundle bundle = SslBundle.of(storeBundle); + + DefaultSslBundleRegistry defaultSslBundleRegistry = new DefaultSslBundleRegistry(); + String bundleName = "default-bundle"; + defaultSslBundleRegistry.registerBundle(bundleName, bundle); + factory.setSslBundles(defaultSslBundleRegistry); + factory.getSsl().setBundle(bundleName); + } + } + +} diff --git a/service/src/main/java/helper/CertificateHelper.java b/service/src/main/java/helper/CertificateHelper.java new file mode 100644 index 00000000..1850c7c1 --- /dev/null +++ b/service/src/main/java/helper/CertificateHelper.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2021 Fraunhofer IOSB, eine rechtlich nicht selbstaendige + * Einrichtung der Fraunhofer-Gesellschaft zur Foerderung der angewandten + * Forschung e.V. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package helper; + +import de.fraunhofer.iosb.ilt.faaast.service.certificate.CertificateData; +import de.fraunhofer.iosb.ilt.faaast.service.certificate.CertificateInformation; +import de.fraunhofer.iosb.ilt.faaast.service.certificate.util.KeyStoreHelper; +import java.io.IOException; +import java.security.KeyStore; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.cert.CertificateException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.http.HttpStatus; +import org.springframework.web.server.ResponseStatusException; + + +/** + * Helper class for certificate handling. + */ +public class CertificateHelper { + + private static final Logger LOGGER = LoggerFactory.getLogger(CertificateHelper.class); + + private static final CertificateInformation SELFSIGNED_CERTIFICATE_INFORMATION = CertificateInformation.builder() + .applicationUri("urn:de:fraunhofer:iosb:ilt:faaast:registry:service") + .commonName("FA³ST Registry Service") + .countryCode("DE") + .localityName("Karlsruhe") + .organization("Fraunhofer IOSB") + .organizationUnit("ILT") + .build(); + + /** + * Create a KeyStore with a self-signed certificate. + * + * @return The created KeyStore. + */ + public static KeyStore generateSelfSignedCertificate() { + try { + LOGGER.debug("Generating self-signed certificate for HTTP endpoint..."); + CertificateData certificateData = KeyStoreHelper.generateSelfSigned(SELFSIGNED_CERTIFICATE_INFORMATION); + KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); + keyStore.load(null, null); + keyStore.setCertificateEntry(KeyStoreHelper.DEFAULT_ALIAS, certificateData.getCertificate()); + keyStore.setKeyEntry(KeyStoreHelper.DEFAULT_ALIAS, certificateData.getKeyPair().getPrivate(), null, certificateData.getCertificateChain()); + LOGGER.debug("Self-signed certificate for Registry service successfully generated"); + return keyStore; + } + catch (IOException | CertificateException | KeyStoreException | NoSuchAlgorithmException e) { + throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "error generating self-signed certificate for service", e); + } + } +} diff --git a/service/src/main/resources/application.properties b/service/src/main/resources/application.properties index dc05d096..941af35e 100644 --- a/service/src/main/resources/application.properties +++ b/service/src/main/resources/application.properties @@ -5,6 +5,15 @@ spring.jpa.orm=orm.xml spring.jpa.properties.hibernate.format_sql=true spring.jpa.hibernate.ddl-auto=update server.port=8090 +server.ssl.enabled=true +######################### + +###### SSL Bundle ####### +#server.ssl.bundle=service +#spring.ssl.bundle.jks.service.key.alias=server +#spring.ssl.bundle.jks.service.keystore.location=classpath:keystore.p12 +#spring.ssl.bundle.jks.service.keystore.password=password +#spring.ssl.bundle.jks.service.keystore.type=PKCS12 ######################### ##### RDBS via JPA (in-memory H2) ##### From 900fe47441e7e6f2ba25550ef4a6ad86e4a6f278 Mon Sep 17 00:00:00 2001 From: Tino Bischoff Date: Tue, 2 Apr 2024 16:55:49 +0200 Subject: [PATCH 32/57] change date format --- .../registry/service/config/DescriptorMapperConfig.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/config/DescriptorMapperConfig.java b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/config/DescriptorMapperConfig.java index 37a0ff1f..eb49e0a2 100644 --- a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/config/DescriptorMapperConfig.java +++ b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/config/DescriptorMapperConfig.java @@ -15,8 +15,10 @@ package de.fraunhofer.iosb.ilt.faaast.registry.service.config; import com.fasterxml.jackson.core.Version; +import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.databind.module.SimpleAbstractTypeResolver; import com.fasterxml.jackson.databind.module.SimpleModule; +import com.fasterxml.jackson.databind.util.StdDateFormat; import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.mixins.PageMixin; import de.fraunhofer.iosb.ilt.faaast.service.model.api.paging.Page; import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.AssetAdministrationShellDescriptor; @@ -86,6 +88,9 @@ public Jackson2ObjectMapperBuilder jackson2ObjectMapperBuilder() { module.setAbstractTypes(resolver); return new Jackson2ObjectMapperBuilder() .modules(module) - .mixIn(Page.class, PageMixin.class); + .mixIn(Page.class, PageMixin.class) + .featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) + .featuresToEnable(SerializationFeature.WRITE_DATES_WITH_ZONE_ID) + .dateFormat(new StdDateFormat().withColonInTimeZone(true)); } } From 28e2f2df944d59de0db5fe15bfa7ffdc1bd3108e Mon Sep 17 00:00:00 2001 From: Tino Bischoff Date: Tue, 2 Apr 2024 16:56:26 +0200 Subject: [PATCH 33/57] generate correct exception message --- .../service/RegistryControllerAdvice.java | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/RegistryControllerAdvice.java diff --git a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/RegistryControllerAdvice.java b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/RegistryControllerAdvice.java new file mode 100644 index 00000000..d5136c4c --- /dev/null +++ b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/RegistryControllerAdvice.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2021 Fraunhofer IOSB, eine rechtlich nicht selbstaendige + * Einrichtung der Fraunhofer-Gesellschaft zur Foerderung der angewandten + * Forschung e.V. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package de.fraunhofer.iosb.ilt.faaast.registry.service; + +import de.fraunhofer.iosb.ilt.faaast.registry.core.exception.BadRequestException; +import de.fraunhofer.iosb.ilt.faaast.registry.core.exception.ResourceAlreadyExistsException; +import de.fraunhofer.iosb.ilt.faaast.registry.core.exception.ResourceNotFoundException; +import de.fraunhofer.iosb.ilt.faaast.service.model.api.Message; +import de.fraunhofer.iosb.ilt.faaast.service.model.api.MessageType; +import de.fraunhofer.iosb.ilt.faaast.service.model.api.Result; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; + + +/** + * Class with our error handling. + */ +@ControllerAdvice +public class RegistryControllerAdvice { + + /** + * Handles the ResourceNotFoundException. + * + * @param e The desired exception. + * @return The corresponding response. + */ + @ExceptionHandler(ResourceNotFoundException.class) + public ResponseEntity handleResourceNotFoundException(Exception e) { + Message msg = Message.builder().messageType(MessageType.ERROR).text(e.getMessage()).build(); + return new ResponseEntity<>(Result.builder().message(msg).build(), HttpStatus.NOT_FOUND); + } + + + /** + * Handles ResourceAlreadyExistsException and BadRequestException. + * + * @param e The desired exception. + * @return The corresponding response. + */ + @ExceptionHandler(value = { + ResourceAlreadyExistsException.class, + BadRequestException.class + }) + public ResponseEntity handleResourceAlreadyExistsException(Exception e) { + Message msg = Message.builder().messageType(MessageType.ERROR).text(e.getMessage()).build(); + return new ResponseEntity<>(Result.builder().message(msg).build(), HttpStatus.BAD_REQUEST); + } + + + /** + * Fallback method. Handles all other exceptions. + * + * @param e The desired exception. + * @return The corresponding response. + */ + public ResponseEntity handleExceptions(Exception e) { + Message msg = Message.builder().messageType(MessageType.ERROR).text(e.getMessage()).build(); + return new ResponseEntity<>(Result.builder().message(msg).build(), HttpStatus.INTERNAL_SERVER_ERROR); + } +} From a77e56bf951d2bbfb4684a39019fd64683ed7328 Mon Sep 17 00:00:00 2001 From: Tino Bischoff Date: Thu, 4 Apr 2024 11:00:56 +0200 Subject: [PATCH 34/57] use Fa3st Service Release 1.0.1 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 5f10c541..1bb6e17f 100644 --- a/pom.xml +++ b/pom.xml @@ -49,7 +49,7 @@ 3.25.3 10.15.0 - 1.1.0-SNAPSHOT + 1.0.1 2.2.224 6.4.4.Final 2.17.0 From 497ce2ec38297dadcc400566947a406c3ad926ff Mon Sep 17 00:00:00 2001 From: Tino Bischoff Date: Fri, 5 Apr 2024 17:00:13 +0200 Subject: [PATCH 35/57] add data specification --- ...JpaAssetAdministrationShellDescriptor.java | 43 +---- .../model/JpaDataSpecificationIec61360.java | 113 +++++++++++++ .../model/JpaEmbeddedDataSpecification.java | 38 ++++- .../JpaLangStringDefinitionTypeIec61360.java | 102 ++++++++++++ ...paLangStringPreferredNameTypeIec61360.java | 102 ++++++++++++ .../JpaLangStringShortNameTypeIec61360.java | 102 ++++++++++++ .../registry/jpa/model/JpaLevelType.java | 104 ++++++++++++ .../registry/jpa/model/JpaValueList.java | 102 ++++++++++++ .../jpa/model/JpaValueReferencePair.java | 103 ++++++++++++ .../jpa/util/ModelTransformationHelper.java | 114 ++++++++++++- .../jpa/src/test/resources/META-INF/orm.xml | 152 +++++++++++++----- service/src/main/resources/META-INF/orm.xml | 152 +++++++++++++----- 12 files changed, 1100 insertions(+), 127 deletions(-) create mode 100644 persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaDataSpecificationIec61360.java create mode 100644 persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaLangStringDefinitionTypeIec61360.java create mode 100644 persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaLangStringPreferredNameTypeIec61360.java create mode 100644 persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaLangStringShortNameTypeIec61360.java create mode 100644 persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaLevelType.java create mode 100644 persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaValueList.java create mode 100644 persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaValueReferencePair.java diff --git a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaAssetAdministrationShellDescriptor.java b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaAssetAdministrationShellDescriptor.java index 3a4c8c86..9e4b7f9a 100644 --- a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaAssetAdministrationShellDescriptor.java +++ b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaAssetAdministrationShellDescriptor.java @@ -25,52 +25,11 @@ */ public class JpaAssetAdministrationShellDescriptor extends DefaultAssetAdministrationShellDescriptor { - //@JsonIgnore - //private String id; - - public JpaAssetAdministrationShellDescriptor() { - //id = null; - } - - //public String getId() { - // return id; - //} - - //public void setId(String id) { - // this.id = id; - //} - - //@Override - //public int hashCode() { - // return Objects.hash(super.hashCode(), id); - //} - - //@Override - //public boolean equals(Object obj) { - // if (this == obj) { - // return true; - // } - // else if (obj == null) { - // return false; - // } - // else if (this.getClass() != obj.getClass()) { - // return false; - // } - // else { - // JpaAssetAdministrationShellDescriptor other = (JpaAssetAdministrationShellDescriptor) obj; - // return super.equals(obj) - // && Objects.equals(this.id, other.id); - // } - //} + public JpaAssetAdministrationShellDescriptor() {} public abstract static class AbstractBuilder> extends DefaultAssetAdministrationShellDescriptor.AbstractBuilder { - //public B id(String value) { - // getBuildingInstance().setId(value); - // return getSelf(); - //} - @Override public B from(AssetAdministrationShellDescriptor other) { if (Objects.nonNull(other)) { diff --git a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaDataSpecificationIec61360.java b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaDataSpecificationIec61360.java new file mode 100644 index 00000000..e3004155 --- /dev/null +++ b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaDataSpecificationIec61360.java @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2021 Fraunhofer IOSB, eine rechtlich nicht selbstaendige + * Einrichtung der Fraunhofer-Gesellschaft zur Foerderung der angewandten + * Forschung e.V. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package de.fraunhofer.iosb.ilt.faaast.registry.jpa.model; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import de.fraunhofer.iosb.ilt.faaast.registry.jpa.util.ModelTransformationHelper; +import java.util.Objects; +import org.eclipse.digitaltwin.aas4j.v3.model.DataSpecificationIec61360; +import org.eclipse.digitaltwin.aas4j.v3.model.builder.DataSpecificationIec61360Builder; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultDataSpecificationIec61360; + + +/** + * Registry Descriptor JPA implementation for DataSpecificationIec61360. + */ +public class JpaDataSpecificationIec61360 extends DefaultDataSpecificationIec61360 { + + @JsonIgnore + private String id; + + public JpaDataSpecificationIec61360() { + id = null; + } + + + public String getId() { + return id; + } + + + public void setId(String id) { + this.id = id; + } + + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), id); + } + + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + else if (obj == null) { + return false; + } + else if (this.getClass() != obj.getClass()) { + return false; + } + else { + JpaDataSpecificationIec61360 other = (JpaDataSpecificationIec61360) obj; + return super.equals(obj) + && Objects.equals(this.id, other.id); + } + } + + public abstract static class AbstractBuilder> + extends DataSpecificationIec61360Builder { + + public B id(String value) { + getBuildingInstance().setId(value); + return getSelf(); + } + + + public B from(DataSpecificationIec61360 other) { + if (Objects.nonNull(other)) { + preferredName(ModelTransformationHelper.convertPreferredNameIec61360(other.getPreferredName())); + shortName(ModelTransformationHelper.convertShortNameIec61360(other.getShortName())); + unit(other.getUnit()); + unitId(ModelTransformationHelper.convertReference(other.getUnitId())); + sourceOfDefinition(other.getSourceOfDefinition()); + symbol(other.getSymbol()); + dataType(other.getDataType()); + definition(ModelTransformationHelper.convertDefinitionIec61360(other.getDefinition())); + valueFormat(other.getValueFormat()); + valueList(ModelTransformationHelper.convertValueList(other.getValueList())); + value(other.getValue()); + levelType(ModelTransformationHelper.convertLevelType(other.getLevelType())); + } + return getSelf(); + } + } + + public static class Builder extends AbstractBuilder { + + @Override + protected Builder getSelf() { + return this; + } + + + @Override + protected JpaDataSpecificationIec61360 newBuildingInstance() { + return new JpaDataSpecificationIec61360(); + } + } +} diff --git a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaEmbeddedDataSpecification.java b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaEmbeddedDataSpecification.java index 6901b985..f10c2e8f 100644 --- a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaEmbeddedDataSpecification.java +++ b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaEmbeddedDataSpecification.java @@ -17,6 +17,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import de.fraunhofer.iosb.ilt.faaast.registry.jpa.util.ModelTransformationHelper; import java.util.Objects; +import org.eclipse.digitaltwin.aas4j.v3.model.DataSpecificationIec61360; import org.eclipse.digitaltwin.aas4j.v3.model.EmbeddedDataSpecification; import org.eclipse.digitaltwin.aas4j.v3.model.builder.EmbeddedDataSpecificationBuilder; import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultEmbeddedDataSpecification; @@ -30,8 +31,12 @@ public class JpaEmbeddedDataSpecification extends DefaultEmbeddedDataSpecificati @JsonIgnore private String id; + @JsonIgnore + private DataSpecificationIec61360 contentIec6360; + public JpaEmbeddedDataSpecification() { id = null; + contentIec6360 = null; } @@ -45,9 +50,25 @@ public void setId(String id) { } + public DataSpecificationIec61360 getDataSpecificationContentIec61360() { + return contentIec6360; + } + + + /** + * Set DataSpecificationContentIec61360. + * + * @param value The desired DataSpecificationContentIec61360. + */ + public void setDataSpecificationContentIec61360(DataSpecificationIec61360 value) { + contentIec6360 = value; + setDataSpecificationContent(value); + } + + @Override public int hashCode() { - return Objects.hash(super.hashCode(), id); + return Objects.hash(super.hashCode(), id, contentIec6360); } @@ -65,7 +86,8 @@ else if (this.getClass() != obj.getClass()) { else { JpaEmbeddedDataSpecification other = (JpaEmbeddedDataSpecification) obj; return super.equals(obj) - && Objects.equals(this.id, other.id); + && Objects.equals(this.id, other.id) + && Objects.equals(contentIec6360, other.contentIec6360); } } @@ -78,10 +100,20 @@ public B id(String value) { } + public B dataSpecificationContentIec61360(DataSpecificationIec61360 value) { + getBuildingInstance().setDataSpecificationContentIec61360(value); + return getSelf(); + } + + public B from(EmbeddedDataSpecification other) { if (Objects.nonNull(other)) { dataSpecification(ModelTransformationHelper.convertReference(other.getDataSpecification())); - // TODO: dataSpecificationContent + //dataSpecificationContent(ModelTransformationHelper.convertDataSpecificationContent(other.getDataSpecificationContent())); + + if (other.getDataSpecificationContent() instanceof DataSpecificationIec61360 iec61360) { + dataSpecificationContentIec61360(ModelTransformationHelper.convertDataSpecificationIec61360(iec61360)); + } } return getSelf(); } diff --git a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaLangStringDefinitionTypeIec61360.java b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaLangStringDefinitionTypeIec61360.java new file mode 100644 index 00000000..ac006fbe --- /dev/null +++ b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaLangStringDefinitionTypeIec61360.java @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2021 Fraunhofer IOSB, eine rechtlich nicht selbstaendige + * Einrichtung der Fraunhofer-Gesellschaft zur Foerderung der angewandten + * Forschung e.V. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package de.fraunhofer.iosb.ilt.faaast.registry.jpa.model; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import java.util.Objects; +import org.eclipse.digitaltwin.aas4j.v3.model.LangStringDefinitionTypeIec61360; +import org.eclipse.digitaltwin.aas4j.v3.model.builder.LangStringDefinitionTypeIec61360Builder; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultLangStringDefinitionTypeIec61360; + + +/** + * Registry Descriptor JPA implementation for LangStringDefinitionTypeIec61360. + */ +public class JpaLangStringDefinitionTypeIec61360 extends DefaultLangStringDefinitionTypeIec61360 { + + @JsonIgnore + private String id; + + public JpaLangStringDefinitionTypeIec61360() { + id = null; + } + + + public String getId() { + return id; + } + + + public void setId(String id) { + this.id = id; + } + + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), id); + } + + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + else if (obj == null) { + return false; + } + else if (this.getClass() != obj.getClass()) { + return false; + } + else { + JpaLangStringDefinitionTypeIec61360 other = (JpaLangStringDefinitionTypeIec61360) obj; + return super.equals(obj) + && Objects.equals(this.id, other.id); + } + } + + public abstract static class AbstractBuilder> + extends LangStringDefinitionTypeIec61360Builder { + + public B id(String value) { + getBuildingInstance().setId(value); + return getSelf(); + } + + + public B from(LangStringDefinitionTypeIec61360 other) { + if (Objects.nonNull(other)) { + text(other.getText()); + language(other.getLanguage()); + } + return getSelf(); + } + } + + public static class Builder extends AbstractBuilder { + + @Override + protected Builder getSelf() { + return this; + } + + + @Override + protected JpaLangStringDefinitionTypeIec61360 newBuildingInstance() { + return new JpaLangStringDefinitionTypeIec61360(); + } + } +} diff --git a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaLangStringPreferredNameTypeIec61360.java b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaLangStringPreferredNameTypeIec61360.java new file mode 100644 index 00000000..55d546ea --- /dev/null +++ b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaLangStringPreferredNameTypeIec61360.java @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2021 Fraunhofer IOSB, eine rechtlich nicht selbstaendige + * Einrichtung der Fraunhofer-Gesellschaft zur Foerderung der angewandten + * Forschung e.V. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package de.fraunhofer.iosb.ilt.faaast.registry.jpa.model; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import java.util.Objects; +import org.eclipse.digitaltwin.aas4j.v3.model.LangStringPreferredNameTypeIec61360; +import org.eclipse.digitaltwin.aas4j.v3.model.builder.LangStringPreferredNameTypeIec61360Builder; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultLangStringPreferredNameTypeIec61360; + + +/** + * Registry Descriptor JPA implementation for LangStringPreferredNameTypeIec61360. + */ +public class JpaLangStringPreferredNameTypeIec61360 extends DefaultLangStringPreferredNameTypeIec61360 { + + @JsonIgnore + private String id; + + public JpaLangStringPreferredNameTypeIec61360() { + id = null; + } + + + public String getId() { + return id; + } + + + public void setId(String id) { + this.id = id; + } + + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), id); + } + + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + else if (obj == null) { + return false; + } + else if (this.getClass() != obj.getClass()) { + return false; + } + else { + JpaLangStringPreferredNameTypeIec61360 other = (JpaLangStringPreferredNameTypeIec61360) obj; + return super.equals(obj) + && Objects.equals(this.id, other.id); + } + } + + public abstract static class AbstractBuilder> + extends LangStringPreferredNameTypeIec61360Builder { + + public B id(String value) { + getBuildingInstance().setId(value); + return getSelf(); + } + + + public B from(LangStringPreferredNameTypeIec61360 other) { + if (Objects.nonNull(other)) { + text(other.getText()); + language(other.getLanguage()); + } + return getSelf(); + } + } + + public static class Builder extends AbstractBuilder { + + @Override + protected Builder getSelf() { + return this; + } + + + @Override + protected JpaLangStringPreferredNameTypeIec61360 newBuildingInstance() { + return new JpaLangStringPreferredNameTypeIec61360(); + } + } +} diff --git a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaLangStringShortNameTypeIec61360.java b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaLangStringShortNameTypeIec61360.java new file mode 100644 index 00000000..f151ee5f --- /dev/null +++ b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaLangStringShortNameTypeIec61360.java @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2021 Fraunhofer IOSB, eine rechtlich nicht selbstaendige + * Einrichtung der Fraunhofer-Gesellschaft zur Foerderung der angewandten + * Forschung e.V. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package de.fraunhofer.iosb.ilt.faaast.registry.jpa.model; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import java.util.Objects; +import org.eclipse.digitaltwin.aas4j.v3.model.LangStringShortNameTypeIec61360; +import org.eclipse.digitaltwin.aas4j.v3.model.builder.LangStringShortNameTypeIec61360Builder; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultLangStringShortNameTypeIec61360; + + +/** + * Registry Descriptor JPA implementation for LangStringShortNameTypeIec61360. + */ +public class JpaLangStringShortNameTypeIec61360 extends DefaultLangStringShortNameTypeIec61360 { + + @JsonIgnore + private String id; + + public JpaLangStringShortNameTypeIec61360() { + id = null; + } + + + public String getId() { + return id; + } + + + public void setId(String id) { + this.id = id; + } + + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), id); + } + + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + else if (obj == null) { + return false; + } + else if (this.getClass() != obj.getClass()) { + return false; + } + else { + JpaLangStringShortNameTypeIec61360 other = (JpaLangStringShortNameTypeIec61360) obj; + return super.equals(obj) + && Objects.equals(this.id, other.id); + } + } + + public abstract static class AbstractBuilder> + extends LangStringShortNameTypeIec61360Builder { + + public B id(String value) { + getBuildingInstance().setId(value); + return getSelf(); + } + + + public B from(LangStringShortNameTypeIec61360 other) { + if (Objects.nonNull(other)) { + text(other.getText()); + language(other.getLanguage()); + } + return getSelf(); + } + } + + public static class Builder extends AbstractBuilder { + + @Override + protected Builder getSelf() { + return this; + } + + + @Override + protected JpaLangStringShortNameTypeIec61360 newBuildingInstance() { + return new JpaLangStringShortNameTypeIec61360(); + } + } +} diff --git a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaLevelType.java b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaLevelType.java new file mode 100644 index 00000000..5cbd47d6 --- /dev/null +++ b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaLevelType.java @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2021 Fraunhofer IOSB, eine rechtlich nicht selbstaendige + * Einrichtung der Fraunhofer-Gesellschaft zur Foerderung der angewandten + * Forschung e.V. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package de.fraunhofer.iosb.ilt.faaast.registry.jpa.model; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import java.util.Objects; +import org.eclipse.digitaltwin.aas4j.v3.model.LevelType; +import org.eclipse.digitaltwin.aas4j.v3.model.builder.LevelTypeBuilder; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultLevelType; + + +/** + * Registry Descriptor JPA implementation for LevelType. + */ +public class JpaLevelType extends DefaultLevelType { + + @JsonIgnore + private String id; + + public JpaLevelType() { + id = null; + } + + + public String getId() { + return id; + } + + + public void setId(String id) { + this.id = id; + } + + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), id); + } + + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + else if (obj == null) { + return false; + } + else if (this.getClass() != obj.getClass()) { + return false; + } + else { + JpaLevelType other = (JpaLevelType) obj; + return super.equals(obj) + && Objects.equals(this.id, other.id); + } + } + + public abstract static class AbstractBuilder> + extends LevelTypeBuilder { + + public B id(String value) { + getBuildingInstance().setId(value); + return getSelf(); + } + + + public B from(LevelType other) { + if (Objects.nonNull(other)) { + min(other.getMin()); + max(other.getMax()); + nom(other.getNom()); + typ(other.getTyp()); + } + return getSelf(); + } + } + + public static class Builder extends AbstractBuilder { + + @Override + protected Builder getSelf() { + return this; + } + + + @Override + protected JpaLevelType newBuildingInstance() { + return new JpaLevelType(); + } + } +} diff --git a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaValueList.java b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaValueList.java new file mode 100644 index 00000000..712a47d0 --- /dev/null +++ b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaValueList.java @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2021 Fraunhofer IOSB, eine rechtlich nicht selbstaendige + * Einrichtung der Fraunhofer-Gesellschaft zur Foerderung der angewandten + * Forschung e.V. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package de.fraunhofer.iosb.ilt.faaast.registry.jpa.model; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import de.fraunhofer.iosb.ilt.faaast.registry.jpa.util.ModelTransformationHelper; +import java.util.Objects; +import org.eclipse.digitaltwin.aas4j.v3.model.ValueList; +import org.eclipse.digitaltwin.aas4j.v3.model.builder.ValueListBuilder; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultValueList; + + +/** + * Registry Descriptor JPA implementation for ValueList. + */ +public class JpaValueList extends DefaultValueList { + + @JsonIgnore + private String id; + + public JpaValueList() { + id = null; + } + + + public String getId() { + return id; + } + + + public void setId(String id) { + this.id = id; + } + + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), id); + } + + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + else if (obj == null) { + return false; + } + else if (this.getClass() != obj.getClass()) { + return false; + } + else { + JpaValueList other = (JpaValueList) obj; + return super.equals(obj) + && Objects.equals(this.id, other.id); + } + } + + public abstract static class AbstractBuilder> + extends ValueListBuilder { + + public B id(String value) { + getBuildingInstance().setId(value); + return getSelf(); + } + + + public B from(ValueList other) { + if (Objects.nonNull(other)) { + valueReferencePairs(ModelTransformationHelper.convertValueReferencePairs(other.getValueReferencePairs())); + } + return getSelf(); + } + } + + public static class Builder extends AbstractBuilder { + + @Override + protected Builder getSelf() { + return this; + } + + + @Override + protected JpaValueList newBuildingInstance() { + return new JpaValueList(); + } + } +} diff --git a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaValueReferencePair.java b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaValueReferencePair.java new file mode 100644 index 00000000..0bcc4ed0 --- /dev/null +++ b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaValueReferencePair.java @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2021 Fraunhofer IOSB, eine rechtlich nicht selbstaendige + * Einrichtung der Fraunhofer-Gesellschaft zur Foerderung der angewandten + * Forschung e.V. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package de.fraunhofer.iosb.ilt.faaast.registry.jpa.model; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import de.fraunhofer.iosb.ilt.faaast.registry.jpa.util.ModelTransformationHelper; +import java.util.Objects; +import org.eclipse.digitaltwin.aas4j.v3.model.ValueReferencePair; +import org.eclipse.digitaltwin.aas4j.v3.model.builder.ValueReferencePairBuilder; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultValueReferencePair; + + +/** + * Registry Descriptor JPA implementation for ValueReferencePair. + */ +public class JpaValueReferencePair extends DefaultValueReferencePair { + + @JsonIgnore + private String id; + + public JpaValueReferencePair() { + id = null; + } + + + public String getId() { + return id; + } + + + public void setId(String id) { + this.id = id; + } + + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), id); + } + + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + else if (obj == null) { + return false; + } + else if (this.getClass() != obj.getClass()) { + return false; + } + else { + JpaValueReferencePair other = (JpaValueReferencePair) obj; + return super.equals(obj) + && Objects.equals(this.id, other.id); + } + } + + public abstract static class AbstractBuilder> + extends ValueReferencePairBuilder { + + public B id(String value) { + getBuildingInstance().setId(value); + return getSelf(); + } + + + public B from(ValueReferencePair other) { + if (Objects.nonNull(other)) { + value(other.getValue()); + valueId(ModelTransformationHelper.convertReference(other.getValueId())); + } + return getSelf(); + } + } + + public static class Builder extends AbstractBuilder { + + @Override + protected Builder getSelf() { + return this; + } + + + @Override + protected JpaValueReferencePair newBuildingInstance() { + return new JpaValueReferencePair(); + } + } +} diff --git a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/util/ModelTransformationHelper.java b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/util/ModelTransformationHelper.java index c0303955..669beecd 100644 --- a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/util/ModelTransformationHelper.java +++ b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/util/ModelTransformationHelper.java @@ -16,16 +16,23 @@ import de.fraunhofer.iosb.ilt.faaast.registry.jpa.model.JpaAdministrativeInformation; import de.fraunhofer.iosb.ilt.faaast.registry.jpa.model.JpaAssetAdministrationShellDescriptor; +import de.fraunhofer.iosb.ilt.faaast.registry.jpa.model.JpaDataSpecificationIec61360; import de.fraunhofer.iosb.ilt.faaast.registry.jpa.model.JpaDescription; import de.fraunhofer.iosb.ilt.faaast.registry.jpa.model.JpaDisplayName; import de.fraunhofer.iosb.ilt.faaast.registry.jpa.model.JpaEndpoint; import de.fraunhofer.iosb.ilt.faaast.registry.jpa.model.JpaExtension; import de.fraunhofer.iosb.ilt.faaast.registry.jpa.model.JpaKey; +import de.fraunhofer.iosb.ilt.faaast.registry.jpa.model.JpaLangStringDefinitionTypeIec61360; +import de.fraunhofer.iosb.ilt.faaast.registry.jpa.model.JpaLangStringPreferredNameTypeIec61360; +import de.fraunhofer.iosb.ilt.faaast.registry.jpa.model.JpaLangStringShortNameTypeIec61360; +import de.fraunhofer.iosb.ilt.faaast.registry.jpa.model.JpaLevelType; import de.fraunhofer.iosb.ilt.faaast.registry.jpa.model.JpaProtocolInformation; import de.fraunhofer.iosb.ilt.faaast.registry.jpa.model.JpaReference; import de.fraunhofer.iosb.ilt.faaast.registry.jpa.model.JpaSpecificAssetId; import de.fraunhofer.iosb.ilt.faaast.registry.jpa.model.JpaSubmodelDescriptor; import de.fraunhofer.iosb.ilt.faaast.registry.jpa.model.JpaSubmodelDescriptorStandalone; +import de.fraunhofer.iosb.ilt.faaast.registry.jpa.model.JpaValueList; +import de.fraunhofer.iosb.ilt.faaast.registry.jpa.model.JpaValueReferencePair; import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.AssetAdministrationShellDescriptor; import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.Endpoint; import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.ProtocolInformation; @@ -34,12 +41,19 @@ import java.util.Objects; import java.util.stream.Collectors; import org.eclipse.digitaltwin.aas4j.v3.model.AdministrativeInformation; +import org.eclipse.digitaltwin.aas4j.v3.model.DataSpecificationIec61360; import org.eclipse.digitaltwin.aas4j.v3.model.Extension; import org.eclipse.digitaltwin.aas4j.v3.model.Key; +import org.eclipse.digitaltwin.aas4j.v3.model.LangStringDefinitionTypeIec61360; import org.eclipse.digitaltwin.aas4j.v3.model.LangStringNameType; +import org.eclipse.digitaltwin.aas4j.v3.model.LangStringPreferredNameTypeIec61360; +import org.eclipse.digitaltwin.aas4j.v3.model.LangStringShortNameTypeIec61360; import org.eclipse.digitaltwin.aas4j.v3.model.LangStringTextType; +import org.eclipse.digitaltwin.aas4j.v3.model.LevelType; import org.eclipse.digitaltwin.aas4j.v3.model.Reference; import org.eclipse.digitaltwin.aas4j.v3.model.SpecificAssetId; +import org.eclipse.digitaltwin.aas4j.v3.model.ValueList; +import org.eclipse.digitaltwin.aas4j.v3.model.ValueReferencePair; /** @@ -77,10 +91,10 @@ public static JpaAdministrativeInformation convertAdministrativeInformation(Admi /** - * Converts a list of LangString to a list of JPADescription. + * Converts a list of LangStringTextType to a list of JPALangStringTextType. * - * @param descriptions The list of LangString. - * @return The converted list of JPADescription. + * @param descriptions The list of descriptions. + * @return The converted list of descriptions. */ public static List convertDescriptions(List descriptions) { return descriptions.stream() @@ -90,10 +104,10 @@ public static List convertDescriptions(List convertDisplayNames(List names) { return names.stream() @@ -266,4 +280,92 @@ public static List convertExtensions(List extensions) { .collect(Collectors.toList()); } + + /** + * Converts a list of LangStringPreferredNameTypeIec61360 to a list of JpaLangStringPreferredNameTypeIec61360. + * + * @param names The list of names. + * @return The converted list of names. + */ + public static List convertPreferredNameIec61360(List names) { + return names.stream() + .map(x -> new JpaLangStringPreferredNameTypeIec61360.Builder().from(x).build()) + .collect(Collectors.toList()); + } + + + /** + * Converts a list of LangStringShortNameTypeIec61360 to a list of JpaLangStringShortNameTypeIec61360. + * + * @param names The list of names. + * @return The converted list of names. + */ + public static List convertShortNameIec61360(List names) { + return names.stream() + .map(x -> new JpaLangStringShortNameTypeIec61360.Builder().from(x).build()) + .collect(Collectors.toList()); + } + + + /** + * Converts a list of LangStringDefinitionTypeIec61360 to a list of JpaLangStringDefinitionTypeIec61360. + * + * @param names The list of names. + * @return The converted list of names. + */ + public static List convertDefinitionIec61360(List names) { + return names.stream() + .map(x -> new JpaLangStringDefinitionTypeIec61360.Builder().from(x).build()) + .collect(Collectors.toList()); + } + + + /** + * Converts a list of ValueReferencePair to a list of JpaValueReferencePair. + * + * @param pairs The list of pairs. + * @return The converted list of pairs. + */ + public static List convertValueReferencePairs(List pairs) { + return pairs.stream() + .map(x -> new JpaValueReferencePair.Builder().from(x).build()) + .collect(Collectors.toList()); + } + + + /** + * Converts a ValueList to a JpaValueList. + * + * @param value the desired ValueList. + * @return The converted ValueList. + */ + public static ValueList convertValueList(ValueList value) { + return new JpaValueList.Builder() + .from(value) + .build(); + } + + + /** + * Converts a DataSpecificationIec61360 into JpaDataSpecificationIec61360. + * + * @param iec The desired DataSpecificationIec61360. + * @return The converted JPA DataSpecificationIec61360. + */ + public static DataSpecificationIec61360 convertDataSpecificationIec61360(DataSpecificationIec61360 iec) { + return new JpaDataSpecificationIec61360.Builder().from(iec).build(); + } + + + /** + * Converts LevelType to JpaLevelType. + * + * @param levelType The LevelType. + * @return The converted LevelType. + */ + public static JpaLevelType convertLevelType(LevelType levelType) { + return new JpaLevelType.Builder() + .from(levelType) + .build(); + } } diff --git a/persistence/jpa/src/test/resources/META-INF/orm.xml b/persistence/jpa/src/test/resources/META-INF/orm.xml index 5230ab01..4ff26bd2 100644 --- a/persistence/jpa/src/test/resources/META-INF/orm.xml +++ b/persistence/jpa/src/test/resources/META-INF/orm.xml @@ -6,7 +6,6 @@ - @@ -19,12 +18,8 @@ - - - - @@ -43,11 +38,11 @@ - + + @@ -88,26 +83,22 @@ - + - - - - @@ -167,12 +158,6 @@ - - org.eclipse.digitaltwin.aas4j.v3.model.KeyTypes @@ -221,19 +206,6 @@ - - @@ -250,12 +222,9 @@ - - - @@ -298,7 +267,8 @@ - + + @@ -330,4 +300,110 @@ + + + + + + + + + + + + + + org.eclipse.digitaltwin.aas4j.v3.model.DataTypeIec61360 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/service/src/main/resources/META-INF/orm.xml b/service/src/main/resources/META-INF/orm.xml index 5230ab01..4ff26bd2 100644 --- a/service/src/main/resources/META-INF/orm.xml +++ b/service/src/main/resources/META-INF/orm.xml @@ -6,7 +6,6 @@ - @@ -19,12 +18,8 @@ - - - - @@ -43,11 +38,11 @@ - + + @@ -88,26 +83,22 @@ - + - - - - @@ -167,12 +158,6 @@ - - org.eclipse.digitaltwin.aas4j.v3.model.KeyTypes @@ -221,19 +206,6 @@ - - @@ -250,12 +222,9 @@ - - - @@ -298,7 +267,8 @@ - + + @@ -330,4 +300,110 @@ + + + + + + + + + + + + + + org.eclipse.digitaltwin.aas4j.v3.model.DataTypeIec61360 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 9f285632d5ca11a8042cadd3212a13cc557246d5 Mon Sep 17 00:00:00 2001 From: Tino Bischoff Date: Fri, 12 Apr 2024 15:49:01 +0200 Subject: [PATCH 36/57] fix errors in JPA transformation --- .../model/JpaAdministrativeInformation.java | 3 +- .../model/JpaEmbeddedDataSpecification.java | 12 ++-- .../jpa/util/ModelTransformationHelper.java | 61 +++++++++++++++++++ .../jpa/src/test/resources/META-INF/orm.xml | 2 +- .../config/DescriptorMapperConfig.java | 26 ++++++++ service/src/main/resources/META-INF/orm.xml | 2 +- 6 files changed, 97 insertions(+), 9 deletions(-) diff --git a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaAdministrativeInformation.java b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaAdministrativeInformation.java index 907defcc..1d7bf0fa 100644 --- a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaAdministrativeInformation.java +++ b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaAdministrativeInformation.java @@ -15,6 +15,7 @@ package de.fraunhofer.iosb.ilt.faaast.registry.jpa.model; import com.fasterxml.jackson.annotation.JsonIgnore; +import de.fraunhofer.iosb.ilt.faaast.registry.jpa.util.ModelTransformationHelper; import java.util.Objects; import org.eclipse.digitaltwin.aas4j.v3.model.AdministrativeInformation; import org.eclipse.digitaltwin.aas4j.v3.model.builder.AdministrativeInformationBuilder; @@ -75,7 +76,7 @@ public B from(AdministrativeInformation other) { if (Objects.nonNull(other)) { version(other.getVersion()); revision(other.getRevision()); - embeddedDataSpecifications(other.getEmbeddedDataSpecifications()); + embeddedDataSpecifications(ModelTransformationHelper.convertEmbeddedDataSpecifications(other.getEmbeddedDataSpecifications())); } return getSelf(); } diff --git a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaEmbeddedDataSpecification.java b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaEmbeddedDataSpecification.java index f10c2e8f..f614df0c 100644 --- a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaEmbeddedDataSpecification.java +++ b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaEmbeddedDataSpecification.java @@ -32,11 +32,11 @@ public class JpaEmbeddedDataSpecification extends DefaultEmbeddedDataSpecificati private String id; @JsonIgnore - private DataSpecificationIec61360 contentIec6360; + private DataSpecificationIec61360 dataSpecificationContentIec61360; public JpaEmbeddedDataSpecification() { id = null; - contentIec6360 = null; + dataSpecificationContentIec61360 = null; } @@ -51,7 +51,7 @@ public void setId(String id) { public DataSpecificationIec61360 getDataSpecificationContentIec61360() { - return contentIec6360; + return dataSpecificationContentIec61360; } @@ -61,14 +61,14 @@ public DataSpecificationIec61360 getDataSpecificationContentIec61360() { * @param value The desired DataSpecificationContentIec61360. */ public void setDataSpecificationContentIec61360(DataSpecificationIec61360 value) { - contentIec6360 = value; + dataSpecificationContentIec61360 = value; setDataSpecificationContent(value); } @Override public int hashCode() { - return Objects.hash(super.hashCode(), id, contentIec6360); + return Objects.hash(super.hashCode(), id, dataSpecificationContentIec61360); } @@ -87,7 +87,7 @@ else if (this.getClass() != obj.getClass()) { JpaEmbeddedDataSpecification other = (JpaEmbeddedDataSpecification) obj; return super.equals(obj) && Objects.equals(this.id, other.id) - && Objects.equals(contentIec6360, other.contentIec6360); + && Objects.equals(dataSpecificationContentIec61360, other.dataSpecificationContentIec61360); } } diff --git a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/util/ModelTransformationHelper.java b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/util/ModelTransformationHelper.java index 669beecd..b60b6898 100644 --- a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/util/ModelTransformationHelper.java +++ b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/util/ModelTransformationHelper.java @@ -19,6 +19,7 @@ import de.fraunhofer.iosb.ilt.faaast.registry.jpa.model.JpaDataSpecificationIec61360; import de.fraunhofer.iosb.ilt.faaast.registry.jpa.model.JpaDescription; import de.fraunhofer.iosb.ilt.faaast.registry.jpa.model.JpaDisplayName; +import de.fraunhofer.iosb.ilt.faaast.registry.jpa.model.JpaEmbeddedDataSpecification; import de.fraunhofer.iosb.ilt.faaast.registry.jpa.model.JpaEndpoint; import de.fraunhofer.iosb.ilt.faaast.registry.jpa.model.JpaExtension; import de.fraunhofer.iosb.ilt.faaast.registry.jpa.model.JpaKey; @@ -42,6 +43,7 @@ import java.util.stream.Collectors; import org.eclipse.digitaltwin.aas4j.v3.model.AdministrativeInformation; import org.eclipse.digitaltwin.aas4j.v3.model.DataSpecificationIec61360; +import org.eclipse.digitaltwin.aas4j.v3.model.EmbeddedDataSpecification; import org.eclipse.digitaltwin.aas4j.v3.model.Extension; import org.eclipse.digitaltwin.aas4j.v3.model.Key; import org.eclipse.digitaltwin.aas4j.v3.model.LangStringDefinitionTypeIec61360; @@ -71,6 +73,9 @@ private ModelTransformationHelper() {} * @return The converted JPAAssetAdministrationShellDescriptor. */ public static JpaAssetAdministrationShellDescriptor convertAAS(AssetAdministrationShellDescriptor aas) { + if (aas == null) { + return null; + } return new JpaAssetAdministrationShellDescriptor.Builder() .from(aas) .build(); @@ -84,6 +89,9 @@ public static JpaAssetAdministrationShellDescriptor convertAAS(AssetAdministrati * @return The converted JPAAdministrativeInformation. */ public static JpaAdministrativeInformation convertAdministrativeInformation(AdministrativeInformation administrativeInformation) { + if (administrativeInformation == null) { + return null; + } return new JpaAdministrativeInformation.Builder() .from(administrativeInformation) .build(); @@ -181,6 +189,9 @@ public static List convertKeys(List keys) { * @return The converted JPAProtocolInformation. */ public static JpaProtocolInformation convertProtocolInformation(ProtocolInformation protocolInformation) { + if (protocolInformation == null) { + return null; + } return new JpaProtocolInformation.Builder().from(protocolInformation).build(); } @@ -192,6 +203,9 @@ public static JpaProtocolInformation convertProtocolInformation(ProtocolInformat * @return The converted JPAReference. */ public static JpaReference convertReference(Reference reference) { + if (reference == null) { + return null; + } return new JpaReference.Builder() .from(reference) .build(); @@ -221,6 +235,9 @@ public static List convertReferences(List references) { * @return The converted JPASubmodelDescriptor. */ public static JpaSubmodelDescriptor convertSubmodel(SubmodelDescriptor submodel) { + if (submodel == null) { + return null; + } return new JpaSubmodelDescriptor.Builder().from(submodel).build(); } @@ -232,6 +249,9 @@ public static JpaSubmodelDescriptor convertSubmodel(SubmodelDescriptor submodel) * @return The converted JPASubmodelDescriptor. */ public static JpaSubmodelDescriptorStandalone convertSubmodelStandalone(SubmodelDescriptor submodel) { + if (submodel == null) { + return null; + } return new JpaSubmodelDescriptorStandalone.Builder().from(submodel).build(); } @@ -259,6 +279,9 @@ public static List convertSubmodels(List * @return The converted JPAExtension. */ public static JpaExtension convertExtension(Extension extension) { + if (extension == null) { + return null; + } return new JpaExtension.Builder() .from(extension) .build(); @@ -340,6 +363,9 @@ public static List convertValueReferencePairs(List convertEmbeddedDataSpecifications(List embeddedDataSpecifications) { + return embeddedDataSpecifications.stream() + .map(x -> new JpaEmbeddedDataSpecification.Builder().from(x).build()) + .collect(Collectors.toList()); + } } diff --git a/persistence/jpa/src/test/resources/META-INF/orm.xml b/persistence/jpa/src/test/resources/META-INF/orm.xml index 4ff26bd2..9298c0f9 100644 --- a/persistence/jpa/src/test/resources/META-INF/orm.xml +++ b/persistence/jpa/src/test/resources/META-INF/orm.xml @@ -324,7 +324,7 @@ --> - + diff --git a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/config/DescriptorMapperConfig.java b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/config/DescriptorMapperConfig.java index eb49e0a2..23772f94 100644 --- a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/config/DescriptorMapperConfig.java +++ b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/config/DescriptorMapperConfig.java @@ -33,19 +33,36 @@ import org.eclipse.digitaltwin.aas4j.v3.dataformat.core.internal.serialization.EnumSerializer; import org.eclipse.digitaltwin.aas4j.v3.dataformat.core.internal.util.ReflectionHelper; import org.eclipse.digitaltwin.aas4j.v3.model.AdministrativeInformation; +import org.eclipse.digitaltwin.aas4j.v3.model.DataSpecificationContent; +import org.eclipse.digitaltwin.aas4j.v3.model.DataSpecificationIec61360; +import org.eclipse.digitaltwin.aas4j.v3.model.EmbeddedDataSpecification; import org.eclipse.digitaltwin.aas4j.v3.model.Extension; import org.eclipse.digitaltwin.aas4j.v3.model.Key; +import org.eclipse.digitaltwin.aas4j.v3.model.LangStringDefinitionTypeIec61360; import org.eclipse.digitaltwin.aas4j.v3.model.LangStringNameType; +import org.eclipse.digitaltwin.aas4j.v3.model.LangStringPreferredNameTypeIec61360; +import org.eclipse.digitaltwin.aas4j.v3.model.LangStringShortNameTypeIec61360; import org.eclipse.digitaltwin.aas4j.v3.model.LangStringTextType; +import org.eclipse.digitaltwin.aas4j.v3.model.LevelType; import org.eclipse.digitaltwin.aas4j.v3.model.Reference; import org.eclipse.digitaltwin.aas4j.v3.model.SpecificAssetId; +import org.eclipse.digitaltwin.aas4j.v3.model.ValueList; +import org.eclipse.digitaltwin.aas4j.v3.model.ValueReferencePair; import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultAdministrativeInformation; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultDataSpecificationIec61360; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultEmbeddedDataSpecification; import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultExtension; import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultKey; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultLangStringDefinitionTypeIec61360; import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultLangStringNameType; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultLangStringPreferredNameTypeIec61360; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultLangStringShortNameTypeIec61360; import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultLangStringTextType; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultLevelType; import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultReference; import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultSpecificAssetId; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultValueList; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultValueReferencePair; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; @@ -81,6 +98,15 @@ public Jackson2ObjectMapperBuilder jackson2ObjectMapperBuilder() { resolver.addMapping(LangStringTextType.class, DefaultLangStringTextType.class); resolver.addMapping(LangStringNameType.class, DefaultLangStringNameType.class); resolver.addMapping(Extension.class, DefaultExtension.class); + resolver.addMapping(EmbeddedDataSpecification.class, DefaultEmbeddedDataSpecification.class); + resolver.addMapping(DataSpecificationIec61360.class, DefaultDataSpecificationIec61360.class); + resolver.addMapping(LangStringPreferredNameTypeIec61360.class, DefaultLangStringPreferredNameTypeIec61360.class); + resolver.addMapping(LangStringShortNameTypeIec61360.class, DefaultLangStringShortNameTypeIec61360.class); + resolver.addMapping(LangStringDefinitionTypeIec61360.class, DefaultLangStringDefinitionTypeIec61360.class); + resolver.addMapping(ValueList.class, DefaultValueList.class); + resolver.addMapping(ValueReferencePair.class, DefaultValueReferencePair.class); + resolver.addMapping(LevelType.class, DefaultLevelType.class); + resolver.addMapping(DataSpecificationContent.class, DataSpecificationIec61360.class); ReflectionHelper.ENUMS.forEach(x -> module.addSerializer(x, new EnumSerializer())); ReflectionHelper.ENUMS.forEach(x -> module.addDeserializer(x, new EnumDeserializer(x))); diff --git a/service/src/main/resources/META-INF/orm.xml b/service/src/main/resources/META-INF/orm.xml index 4ff26bd2..9298c0f9 100644 --- a/service/src/main/resources/META-INF/orm.xml +++ b/service/src/main/resources/META-INF/orm.xml @@ -324,7 +324,7 @@ --> - + From 9fc218c455e84534ae7257c0f14a465c5c390a06 Mon Sep 17 00:00:00 2001 From: Tino Bischoff Date: Fri, 19 Apr 2024 18:01:13 +0200 Subject: [PATCH 37/57] add missing members --- .../faaast/registry/jpa/model/JpaAdministrativeInformation.java | 2 ++ .../jpa/model/JpaAssetAdministrationShellDescriptor.java | 2 ++ 2 files changed, 4 insertions(+) diff --git a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaAdministrativeInformation.java b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaAdministrativeInformation.java index 1d7bf0fa..d5d34d0f 100644 --- a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaAdministrativeInformation.java +++ b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaAdministrativeInformation.java @@ -76,6 +76,8 @@ public B from(AdministrativeInformation other) { if (Objects.nonNull(other)) { version(other.getVersion()); revision(other.getRevision()); + creator(ModelTransformationHelper.convertReference(other.getCreator())); + templateId(other.getTemplateId()); embeddedDataSpecifications(ModelTransformationHelper.convertEmbeddedDataSpecifications(other.getEmbeddedDataSpecifications())); } return getSelf(); diff --git a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaAssetAdministrationShellDescriptor.java b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaAssetAdministrationShellDescriptor.java index 9e4b7f9a..94b22e53 100644 --- a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaAssetAdministrationShellDescriptor.java +++ b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaAssetAdministrationShellDescriptor.java @@ -35,6 +35,8 @@ public B from(AssetAdministrationShellDescriptor other) { if (Objects.nonNull(other)) { id(other.getId()); idShort(other.getIdShort()); + assetkind(other.getAssetKind()); + assetType(other.getAssetType()); endpoints(ModelTransformationHelper.convertEndpoints(other.getEndpoints())); administration(ModelTransformationHelper.convertAdministrativeInformation(other.getAdministration())); descriptions(ModelTransformationHelper.convertDescriptions(other.getDescriptions())); From 0f1d7f88a67705273c47e3d8c8c9809af617f4ab Mon Sep 17 00:00:00 2001 From: Tino Bischoff Date: Fri, 19 Apr 2024 18:01:51 +0200 Subject: [PATCH 38/57] rename columns (prevent reserved keywords) --- persistence/jpa/src/test/resources/META-INF/orm.xml | 6 +++--- service/src/main/resources/META-INF/orm.xml | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/persistence/jpa/src/test/resources/META-INF/orm.xml b/persistence/jpa/src/test/resources/META-INF/orm.xml index 9298c0f9..43abe93b 100644 --- a/persistence/jpa/src/test/resources/META-INF/orm.xml +++ b/persistence/jpa/src/test/resources/META-INF/orm.xml @@ -309,9 +309,9 @@ - + - + org.eclipse.digitaltwin.aas4j.v3.model.DataTypeIec61360 @@ -389,7 +389,7 @@ - + diff --git a/service/src/main/resources/META-INF/orm.xml b/service/src/main/resources/META-INF/orm.xml index 9298c0f9..43abe93b 100644 --- a/service/src/main/resources/META-INF/orm.xml +++ b/service/src/main/resources/META-INF/orm.xml @@ -309,9 +309,9 @@ - + - + org.eclipse.digitaltwin.aas4j.v3.model.DataTypeIec61360 @@ -389,7 +389,7 @@ - + From 3576b0cae481f53fe744f0d4754dfea60daf5438 Mon Sep 17 00:00:00 2001 From: Tino Bischoff Date: Tue, 23 Apr 2024 13:44:20 +0200 Subject: [PATCH 39/57] JPA: filter getAllAas --- .../faaast/registry/jpa/AasRepositoryJpa.java | 3 +- .../jpa/util/EntityManagerHelper.java | 36 +++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/AasRepositoryJpa.java b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/AasRepositoryJpa.java index a616d252..2a5a4694 100644 --- a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/AasRepositoryJpa.java +++ b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/AasRepositoryJpa.java @@ -52,8 +52,7 @@ public AasRepositoryJpa(EntityManager entityManager) { @Override public List getAASs(String assetType, AssetKind assetKind) { - // TODO filter results - return EntityManagerHelper.getAll(entityManager, JpaAssetAdministrationShellDescriptor.class, AssetAdministrationShellDescriptor.class); + return EntityManagerHelper.getAllAas(entityManager, assetType, assetKind); } diff --git a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/util/EntityManagerHelper.java b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/util/EntityManagerHelper.java index 7587eb3e..545282ea 100644 --- a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/util/EntityManagerHelper.java +++ b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/util/EntityManagerHelper.java @@ -14,10 +14,15 @@ */ package de.fraunhofer.iosb.ilt.faaast.registry.jpa.util; +import de.fraunhofer.iosb.ilt.faaast.registry.jpa.model.JpaAssetAdministrationShellDescriptor; +import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.AssetAdministrationShellDescriptor; import jakarta.persistence.EntityManager; import jakarta.persistence.criteria.CriteriaBuilder; +import jakarta.persistence.criteria.Predicate; +import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; +import org.eclipse.digitaltwin.aas4j.v3.model.AssetKind; /** @@ -60,4 +65,35 @@ public static List getAll(EntityManager entityManager, Class .map(returnType::cast) .collect(Collectors.toList()); } + + + /** + * Fetches all instances of AssetAdministrationShellDescriptor, matching the given criteria. + * + * @param entityManager The entityManager to use. + * @param assetType The desired assetType. + * @param assetKind The desired assetKind. + * @return All instances matching the given criteria. + */ + public static List getAllAas(EntityManager entityManager, String assetType, AssetKind assetKind) { + if ((assetKind == null) && (assetType == null)) { + return getAll(entityManager, JpaAssetAdministrationShellDescriptor.class, AssetAdministrationShellDescriptor.class); + } + + CriteriaBuilder builder = entityManager.getCriteriaBuilder(); + var queryCriteria = builder.createQuery(JpaAssetAdministrationShellDescriptor.class); + var root = queryCriteria.from(JpaAssetAdministrationShellDescriptor.class); + List predicates = new ArrayList<>(); + if (assetType != null) { + predicates.add(builder.equal(root.get("assetType"), assetType)); + } + if (assetKind != null) { + predicates.add(builder.equal(root.get("assetKind"), assetKind)); + } + queryCriteria.select(root).where(predicates.toArray(Predicate[]::new)); + var query = entityManager.createQuery(queryCriteria); + return query.getResultList().stream() + .map(AssetAdministrationShellDescriptor.class::cast) + .collect(Collectors.toList()); + } } From c7d011a93bd7146f2306af030da737168c19ee23 Mon Sep 17 00:00:00 2001 From: Tino Bischoff Date: Wed, 24 Apr 2024 11:43:09 +0200 Subject: [PATCH 40/57] JPA fixes; cleanup --- .../model/JpaEmbeddedDataSpecification.java | 1 - .../jpa/model/JpaProtocolInformation.java | 9 +++- .../jpa/model/JpaSubmodelDescriptorBase.java | 44 +------------------ .../jpa/util/ModelTransformationHelper.java | 25 ++++++----- .../service/ShellRegistryController.java | 13 ------ .../config/DescriptorMapperConfig.java | 4 +- 6 files changed, 27 insertions(+), 69 deletions(-) diff --git a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaEmbeddedDataSpecification.java b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaEmbeddedDataSpecification.java index f614df0c..f0f50bf1 100644 --- a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaEmbeddedDataSpecification.java +++ b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaEmbeddedDataSpecification.java @@ -109,7 +109,6 @@ public B dataSpecificationContentIec61360(DataSpecificationIec61360 value) { public B from(EmbeddedDataSpecification other) { if (Objects.nonNull(other)) { dataSpecification(ModelTransformationHelper.convertReference(other.getDataSpecification())); - //dataSpecificationContent(ModelTransformationHelper.convertDataSpecificationContent(other.getDataSpecificationContent())); if (other.getDataSpecificationContent() instanceof DataSpecificationIec61360 iec61360) { dataSpecificationContentIec61360(ModelTransformationHelper.convertDataSpecificationIec61360(iec61360)); diff --git a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaProtocolInformation.java b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaProtocolInformation.java index 45858d4a..775d70b0 100644 --- a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaProtocolInformation.java +++ b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaProtocolInformation.java @@ -15,6 +15,7 @@ package de.fraunhofer.iosb.ilt.faaast.registry.jpa.model; import com.fasterxml.jackson.annotation.JsonIgnore; +import de.fraunhofer.iosb.ilt.faaast.registry.jpa.util.ModelTransformationHelper; import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.ProtocolInformation; import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.impl.DefaultProtocolInformation; import java.util.Objects; @@ -78,7 +79,13 @@ public B id(String value) { @Override public B from(ProtocolInformation other) { - super.from(other); + endpointProtocol(other.getEndpointProtocol()); + endpointProtocolVersion(other.getEndpointProtocolVersion()); + href(other.getHref()); + securityAttributes(ModelTransformationHelper.convertSecurityAttributes(other.getSecurityAttributes())); + subprotocol(other.getSubprotocol()); + subprotocolBody(other.getSubprotocolBody()); + subprotocolBodyEncoding(other.getSubprotocolBodyEncoding()); return getSelf(); } } diff --git a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaSubmodelDescriptorBase.java b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaSubmodelDescriptorBase.java index d7a14d58..181ba919 100644 --- a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaSubmodelDescriptorBase.java +++ b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaSubmodelDescriptorBase.java @@ -24,53 +24,11 @@ */ public abstract class JpaSubmodelDescriptorBase extends DefaultSubmodelDescriptor { - //@JsonIgnore - //private String id; - - protected JpaSubmodelDescriptorBase() { - // id = null; - } - - //public String getId() { - // return id; - //} - - //public void setId(String id) { - // this.id = id; - //} - - // @Override - // public int hashCode() { - // return Objects.hash(super.hashCode(), id); - // } - // - // - // @Override - // public boolean equals(Object obj) { - // if (this == obj) { - // return true; - // } - // else if (obj == null) { - // return false; - // } - // else if (this.getClass() != obj.getClass()) { - // return false; - // } - // else { - // JpaSubmodelDescriptorBase other = (JpaSubmodelDescriptorBase) obj; - // return super.equals(obj) - // && Objects.equals(this.id, other.id); - // } - // } + protected JpaSubmodelDescriptorBase() {} public abstract static class AbstractBuilder> extends DefaultSubmodelDescriptor.AbstractBuilder { - //public B id(String value) { - // getBuildingInstance().setId(value); - // return getSelf(); - //} - @Override public B from(SubmodelDescriptor other) { if (other != null) { diff --git a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/util/ModelTransformationHelper.java b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/util/ModelTransformationHelper.java index b60b6898..fe12dc91 100644 --- a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/util/ModelTransformationHelper.java +++ b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/util/ModelTransformationHelper.java @@ -29,6 +29,7 @@ import de.fraunhofer.iosb.ilt.faaast.registry.jpa.model.JpaLevelType; import de.fraunhofer.iosb.ilt.faaast.registry.jpa.model.JpaProtocolInformation; import de.fraunhofer.iosb.ilt.faaast.registry.jpa.model.JpaReference; +import de.fraunhofer.iosb.ilt.faaast.registry.jpa.model.JpaSecurityAttributeObject; import de.fraunhofer.iosb.ilt.faaast.registry.jpa.model.JpaSpecificAssetId; import de.fraunhofer.iosb.ilt.faaast.registry.jpa.model.JpaSubmodelDescriptor; import de.fraunhofer.iosb.ilt.faaast.registry.jpa.model.JpaSubmodelDescriptorStandalone; @@ -53,6 +54,7 @@ import org.eclipse.digitaltwin.aas4j.v3.model.LangStringTextType; import org.eclipse.digitaltwin.aas4j.v3.model.LevelType; import org.eclipse.digitaltwin.aas4j.v3.model.Reference; +import org.eclipse.digitaltwin.aas4j.v3.model.SecurityAttributeObject; import org.eclipse.digitaltwin.aas4j.v3.model.SpecificAssetId; import org.eclipse.digitaltwin.aas4j.v3.model.ValueList; import org.eclipse.digitaltwin.aas4j.v3.model.ValueReferencePair; @@ -139,16 +141,6 @@ public static List convertEndpoints(List endpoints) { .collect(Collectors.toList()); } - // /** - // * Converts Identifier to JPAIdentifier. - // * - // * @param identifier The Identifier. - // * @return The converted JPAIdentifier. - // */ - // public static Identifier convertIdentifier(Identifier identifier) { - // return new JpaIdentifier.Builder().from(identifier).build(); - // } - /** * Converts a list of SpecificAssetIds to a list of JPASpecificAssetId. @@ -429,4 +421,17 @@ public static List convertEmbeddedDataSpecifications( .map(x -> new JpaEmbeddedDataSpecification.Builder().from(x).build()) .collect(Collectors.toList()); } + + + /** + * Convert a list of SecurityAttributeObjects to a list of JpaSecurityAttributeObjects. + * + * @param securityAttributes The list of SecurityAttributeObject. + * @return The converted list of SecurityAttributeObjects. + */ + public static List convertSecurityAttributes(List securityAttributes) { + return securityAttributes.stream() + .map(x -> new JpaSecurityAttributeObject.Builder().from(x).build()) + .collect(Collectors.toList()); + } } diff --git a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/ShellRegistryController.java b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/ShellRegistryController.java index e33eaa67..0c797ab8 100644 --- a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/ShellRegistryController.java +++ b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/ShellRegistryController.java @@ -64,7 +64,6 @@ public class ShellRegistryController { * @return The list of all registered Asset Administration Shells. */ @GetMapping() - //public List getAASs(@RequestParam(name = "assetType", required = false) String assetType, public Page getAASs(@RequestParam(name = "assetType", required = false) String assetType, @RequestParam(name = "assetKind", required = false) AssetKind assetKind, @RequestParam(name = "limit", required = false) Long limit, @@ -239,16 +238,4 @@ public void deleteSubmodelOfAAS(@PathVariable("aasIdentifier") String aasIdentif throws ResourceNotFoundException { service.deleteSubmodel(aasIdentifier, submodelIdentifier); } - - // /** - // * Exception Handler for no such method error. - // * - // * @param error The error that was thrown. - // * @return error string. - // */ - // @ExceptionHandler(NoSuchMethodError.class) - // public String noSuchMethodError(NoSuchMethodError error) { - // LOGGER.error("noSuchMethodError", error); - // return "no such method"; - // } } diff --git a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/config/DescriptorMapperConfig.java b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/config/DescriptorMapperConfig.java index 23772f94..9b3e3fa4 100644 --- a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/config/DescriptorMapperConfig.java +++ b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/config/DescriptorMapperConfig.java @@ -45,6 +45,7 @@ import org.eclipse.digitaltwin.aas4j.v3.model.LangStringTextType; import org.eclipse.digitaltwin.aas4j.v3.model.LevelType; import org.eclipse.digitaltwin.aas4j.v3.model.Reference; +import org.eclipse.digitaltwin.aas4j.v3.model.SecurityAttributeObject; import org.eclipse.digitaltwin.aas4j.v3.model.SpecificAssetId; import org.eclipse.digitaltwin.aas4j.v3.model.ValueList; import org.eclipse.digitaltwin.aas4j.v3.model.ValueReferencePair; @@ -60,6 +61,7 @@ import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultLangStringTextType; import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultLevelType; import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultReference; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultSecurityAttributeObject; import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultSpecificAssetId; import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultValueList; import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultValueReferencePair; @@ -90,7 +92,6 @@ public Jackson2ObjectMapperBuilder jackson2ObjectMapperBuilder() { resolver.addMapping(AdministrativeInformation.class, DefaultAdministrativeInformation.class); resolver.addMapping(Endpoint.class, DefaultEndpoint.class); resolver.addMapping(ProtocolInformation.class, DefaultProtocolInformation.class); - //resolver.addMapping(Identifier.class, DefaultIdentifier.class); resolver.addMapping(SpecificAssetId.class, DefaultSpecificAssetId.class); resolver.addMapping(Key.class, DefaultKey.class); resolver.addMapping(Reference.class, DefaultReference.class); @@ -107,6 +108,7 @@ public Jackson2ObjectMapperBuilder jackson2ObjectMapperBuilder() { resolver.addMapping(ValueReferencePair.class, DefaultValueReferencePair.class); resolver.addMapping(LevelType.class, DefaultLevelType.class); resolver.addMapping(DataSpecificationContent.class, DataSpecificationIec61360.class); + resolver.addMapping(SecurityAttributeObject.class, DefaultSecurityAttributeObject.class); ReflectionHelper.ENUMS.forEach(x -> module.addSerializer(x, new EnumSerializer())); ReflectionHelper.ENUMS.forEach(x -> module.addDeserializer(x, new EnumDeserializer(x))); From 5e3353c528266cfa92051d1af6ef76f9a092899d Mon Sep 17 00:00:00 2001 From: Tino Bischoff Date: Wed, 24 Apr 2024 17:44:03 +0200 Subject: [PATCH 41/57] Submodel must have at least one endpoint --- service/src/main/java/helper/ConstraintHelper.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/service/src/main/java/helper/ConstraintHelper.java b/service/src/main/java/helper/ConstraintHelper.java index 0809309a..72b13c96 100644 --- a/service/src/main/java/helper/ConstraintHelper.java +++ b/service/src/main/java/helper/ConstraintHelper.java @@ -97,6 +97,10 @@ private static void checkSubmodel(SubmodelDescriptor submodel) { checkExtensions(submodel.getExtensions()); checkAdministrativeInformation(submodel.getAdministration()); EndpointConstraintHelper.checkEndpoints(submodel.getEndpoints()); + // Submodel must have at least one endpoint + if ((submodel.getEndpoints() == null) || (submodel.getEndpoints().isEmpty())) { + CommonConstraintHelper.raiseConstraintViolatedException("submodel doesn't have an endpoint"); + } CommonConstraintHelper.checkReference(submodel.getSemanticId()); CommonConstraintHelper.checkReferences(submodel.getSupplementalSemanticIds()); } From ceccf32d9ba65ea4732f7a6ddebc15954b0acc15 Mon Sep 17 00:00:00 2001 From: Tino Bischoff Date: Thu, 25 Apr 2024 12:39:13 +0200 Subject: [PATCH 42/57] switch to in-memory --- .../src/main/resources/application.properties | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/service/src/main/resources/application.properties b/service/src/main/resources/application.properties index 8ec842cd..941af35e 100644 --- a/service/src/main/resources/application.properties +++ b/service/src/main/resources/application.properties @@ -17,18 +17,18 @@ server.ssl.enabled=true ######################### ##### RDBS via JPA (in-memory H2) ##### -#spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect -#spring.datasource.driver=org.h2.Driver -#spring.datasource.url=jdbc:h2:mem:testdb -#spring.datasource.username=sa -#spring.datasource.password= +spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect +spring.datasource.driver=org.h2.Driver +spring.datasource.url=jdbc:h2:mem:testdb +spring.datasource.username=sa +spring.datasource.password= ####################################### ###### RDBS via JPA (external PostgresDB) ##### -spring.profiles.active=external -spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect -spring.datasource.driver=org.postgresql.Driver -spring.datasource.url=jdbc:postgresql://localhost:5432/Fa3stRegistry -spring.datasource.username=postgres -spring.datasource.password=admin +#spring.profiles.active=external +#spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect +#spring.datasource.driver=org.postgresql.Driver +#spring.datasource.url=jdbc:postgresql://localhost:5432/Fa3stRegistry +#spring.datasource.username=postgres +#spring.datasource.password=admin ############################################### \ No newline at end of file From af4a78c711e24e9215583ff3fa1a09604547bc2f Mon Sep 17 00:00:00 2001 From: Tino Bischoff Date: Fri, 26 Apr 2024 15:21:37 +0200 Subject: [PATCH 43/57] update documentation --- docs/source/index.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/index.md b/docs/source/index.md index 23db352c..5a7a2934 100644 --- a/docs/source/index.md +++ b/docs/source/index.md @@ -1,14 +1,14 @@ # FA³ST Registry ![FA³ST Logo Light](./images/Fa3st-Registry_positiv.png "FA³ST Registry Logo") -The **F**raunhofer **A**dvanced **A**sset **A**dministration **S**hell **T**ools (**FA³ST**) Registry implements the Registry for the [Asset Administration Shell (AAS) specification by Plattform Industrie 4.0](https://www.plattform-i40.de/SiteGlobals/IP/Forms/Listen/Downloads/EN/Downloads_Formular.html?cl2Categories_TechnologieAnwendungsbereich_name=Verwaltungsschale) and provides an easy-to-use Registry for AAS. +The **F**raunhofer **A**dvanced **A**sset **A**dministration **S**hell **T**ools (**FA³ST**) Registry implements the Registry for the [Asset Administration Shell (AAS) specification by IDTA](https://industrialdigitaltwin.org/content-hub/downloads) and provides an easy-to-use Registry for AAS. The FA³ST Registry contains two separate Registry instances: An AAS Registry for Asset Administration Shell (AAS) Descriptors, and a Submodel Registry for Submodel Descriptors. These Registry instances are strictly separated, i.e. when an AAS with Submodels is registered in the AAS Registry, the Submodels of this AAS won't be registered in the Submodel Registry. If you want these Submodels to be registered in the Submodel Registry, you must register them in the Submodel Registry separately. ## Implemented AAS Specification | Specification | Version | |:--| -- | -| Details of the Asset Administration Shell - Part 2
Interoperability at Runtime – Exchanging Information via Application Programming Interfaces | Version 1.0RC02
([specification](https://www.plattform-i40.de/IP/Redaktion/EN/Downloads/Publikation/Details_of_the_Asset_Administration_Shell_Part2_V1.pdf))
([swagger](https://app.swaggerhub.com/apis/Plattform_i40/Entire-API-Collection/V1.0RC02)) | +| Details of the Asset Administration Shell - Part 2
Application Programming Interfaces | Version 3.0
([specification](https://industrialdigitaltwin.org/wp-content/uploads/2023/06/IDTA-01002-3-0_SpecificationAssetAdministrationShell_Part2_API_.pdf))
([swagger](https://app.swaggerhub.com/apis/Plattform_i40/Entire-API-Collection/V3.0.1)) | ## Features From 8c65c8492c027f2e80444c4ba56fee1203437aba Mon Sep 17 00:00:00 2001 From: Tino Bischoff Date: Mon, 29 Apr 2024 10:36:13 +0200 Subject: [PATCH 44/57] remove unnecessary constructor --- .../jpa/model/JpaAssetAdministrationShellDescriptor.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaAssetAdministrationShellDescriptor.java b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaAssetAdministrationShellDescriptor.java index 94b22e53..db1863cc 100644 --- a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaAssetAdministrationShellDescriptor.java +++ b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaAssetAdministrationShellDescriptor.java @@ -25,8 +25,6 @@ */ public class JpaAssetAdministrationShellDescriptor extends DefaultAssetAdministrationShellDescriptor { - public JpaAssetAdministrationShellDescriptor() {} - public abstract static class AbstractBuilder> extends DefaultAssetAdministrationShellDescriptor.AbstractBuilder { From fcfd66b839dde840ad91137a82d230e9edb22061 Mon Sep 17 00:00:00 2001 From: Tino Bischoff Date: Mon, 29 Apr 2024 10:41:22 +0200 Subject: [PATCH 45/57] fix package name --- .../iosb/ilt/faaast/registry/service/RegistryService.java | 4 ++-- .../faaast/registry/service/ShellRegistryController.java | 2 +- .../faaast/registry/service/SubmodelRegistryController.java | 2 +- .../faaast/registry/service/config/ControllerConfig.java | 2 +- .../iosb/ilt/faaast/registry/service/config/SslConfig.java | 2 +- .../faaast/registry/service}/helper/AssetKindConverter.java | 2 +- .../faaast/registry/service}/helper/CertificateHelper.java | 2 +- .../registry/service}/helper/CommonConstraintHelper.java | 2 +- .../faaast/registry/service}/helper/ConstraintHelper.java | 2 +- .../service}/helper/DataSpecificationConstraintHelper.java | 6 ++---- .../registry/service}/helper/EndpointConstraintHelper.java | 4 ++-- .../ilt/faaast/registry/service}/helper/RegistryHelper.java | 2 +- 12 files changed, 15 insertions(+), 17 deletions(-) rename service/src/main/java/{ => de/fraunhofer/iosb/ilt/faaast/registry/service}/helper/AssetKindConverter.java (94%) rename service/src/main/java/{ => de/fraunhofer/iosb/ilt/faaast/registry/service}/helper/CertificateHelper.java (97%) rename service/src/main/java/{ => de/fraunhofer/iosb/ilt/faaast/registry/service}/helper/CommonConstraintHelper.java (98%) rename service/src/main/java/{ => de/fraunhofer/iosb/ilt/faaast/registry/service}/helper/ConstraintHelper.java (99%) rename service/src/main/java/{ => de/fraunhofer/iosb/ilt/faaast/registry/service}/helper/DataSpecificationConstraintHelper.java (97%) rename service/src/main/java/{ => de/fraunhofer/iosb/ilt/faaast/registry/service}/helper/EndpointConstraintHelper.java (95%) rename service/src/main/java/{ => de/fraunhofer/iosb/ilt/faaast/registry/service}/helper/RegistryHelper.java (96%) diff --git a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/RegistryService.java b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/RegistryService.java index 6a333b56..14a7f7ea 100644 --- a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/RegistryService.java +++ b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/RegistryService.java @@ -18,14 +18,14 @@ import de.fraunhofer.iosb.ilt.faaast.registry.core.exception.BadRequestException; import de.fraunhofer.iosb.ilt.faaast.registry.core.exception.ResourceAlreadyExistsException; import de.fraunhofer.iosb.ilt.faaast.registry.core.exception.ResourceNotFoundException; +import de.fraunhofer.iosb.ilt.faaast.registry.service.helper.ConstraintHelper; +import de.fraunhofer.iosb.ilt.faaast.registry.service.helper.RegistryHelper; import de.fraunhofer.iosb.ilt.faaast.service.model.api.paging.Page; import de.fraunhofer.iosb.ilt.faaast.service.model.api.paging.PagingInfo; import de.fraunhofer.iosb.ilt.faaast.service.model.api.paging.PagingMetadata; import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.AssetAdministrationShellDescriptor; import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.SubmodelDescriptor; import de.fraunhofer.iosb.ilt.faaast.service.util.Ensure; -import helper.ConstraintHelper; -import helper.RegistryHelper; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; diff --git a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/ShellRegistryController.java b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/ShellRegistryController.java index 0c797ab8..21935713 100644 --- a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/ShellRegistryController.java +++ b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/ShellRegistryController.java @@ -17,11 +17,11 @@ import de.fraunhofer.iosb.ilt.faaast.registry.core.exception.BadRequestException; import de.fraunhofer.iosb.ilt.faaast.registry.core.exception.ResourceAlreadyExistsException; import de.fraunhofer.iosb.ilt.faaast.registry.core.exception.ResourceNotFoundException; +import de.fraunhofer.iosb.ilt.faaast.registry.service.helper.RegistryHelper; import de.fraunhofer.iosb.ilt.faaast.service.model.api.paging.Page; import de.fraunhofer.iosb.ilt.faaast.service.model.api.paging.PagingInfo; import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.AssetAdministrationShellDescriptor; import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.SubmodelDescriptor; -import helper.RegistryHelper; import java.net.URI; import org.eclipse.digitaltwin.aas4j.v3.model.AssetKind; import org.slf4j.Logger; diff --git a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/SubmodelRegistryController.java b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/SubmodelRegistryController.java index cc9d207a..9203ae39 100644 --- a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/SubmodelRegistryController.java +++ b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/SubmodelRegistryController.java @@ -17,10 +17,10 @@ import de.fraunhofer.iosb.ilt.faaast.registry.core.exception.BadRequestException; import de.fraunhofer.iosb.ilt.faaast.registry.core.exception.ResourceAlreadyExistsException; import de.fraunhofer.iosb.ilt.faaast.registry.core.exception.ResourceNotFoundException; +import de.fraunhofer.iosb.ilt.faaast.registry.service.helper.RegistryHelper; import de.fraunhofer.iosb.ilt.faaast.service.model.api.paging.Page; import de.fraunhofer.iosb.ilt.faaast.service.model.api.paging.PagingInfo; import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.SubmodelDescriptor; -import helper.RegistryHelper; import java.net.URI; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; diff --git a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/config/ControllerConfig.java b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/config/ControllerConfig.java index 5fe509df..03e70bc3 100644 --- a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/config/ControllerConfig.java +++ b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/config/ControllerConfig.java @@ -14,7 +14,7 @@ */ package de.fraunhofer.iosb.ilt.faaast.registry.service.config; -import helper.AssetKindConverter; +import de.fraunhofer.iosb.ilt.faaast.registry.service.helper.AssetKindConverter; import org.springframework.context.annotation.Configuration; import org.springframework.format.FormatterRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; diff --git a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/config/SslConfig.java b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/config/SslConfig.java index 8cdad42b..29b0eee2 100644 --- a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/config/SslConfig.java +++ b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/config/SslConfig.java @@ -14,7 +14,7 @@ */ package de.fraunhofer.iosb.ilt.faaast.registry.service.config; -import helper.CertificateHelper; +import de.fraunhofer.iosb.ilt.faaast.registry.service.helper.CertificateHelper; import java.security.KeyStore; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/service/src/main/java/helper/AssetKindConverter.java b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/helper/AssetKindConverter.java similarity index 94% rename from service/src/main/java/helper/AssetKindConverter.java rename to service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/helper/AssetKindConverter.java index 7e3a8de2..342ec492 100644 --- a/service/src/main/java/helper/AssetKindConverter.java +++ b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/helper/AssetKindConverter.java @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package helper; +package de.fraunhofer.iosb.ilt.faaast.registry.service.helper; import org.eclipse.digitaltwin.aas4j.v3.model.AssetKind; import org.springframework.core.convert.converter.Converter; diff --git a/service/src/main/java/helper/CertificateHelper.java b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/helper/CertificateHelper.java similarity index 97% rename from service/src/main/java/helper/CertificateHelper.java rename to service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/helper/CertificateHelper.java index 1850c7c1..27f089df 100644 --- a/service/src/main/java/helper/CertificateHelper.java +++ b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/helper/CertificateHelper.java @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package helper; +package de.fraunhofer.iosb.ilt.faaast.registry.service.helper; import de.fraunhofer.iosb.ilt.faaast.service.certificate.CertificateData; import de.fraunhofer.iosb.ilt.faaast.service.certificate.CertificateInformation; diff --git a/service/src/main/java/helper/CommonConstraintHelper.java b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/helper/CommonConstraintHelper.java similarity index 98% rename from service/src/main/java/helper/CommonConstraintHelper.java rename to service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/helper/CommonConstraintHelper.java index ce85a71a..906c9890 100644 --- a/service/src/main/java/helper/CommonConstraintHelper.java +++ b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/helper/CommonConstraintHelper.java @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package helper; +package de.fraunhofer.iosb.ilt.faaast.registry.service.helper; import de.fraunhofer.iosb.ilt.faaast.registry.core.exception.BadRequestException; import java.util.List; diff --git a/service/src/main/java/helper/ConstraintHelper.java b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/helper/ConstraintHelper.java similarity index 99% rename from service/src/main/java/helper/ConstraintHelper.java rename to service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/helper/ConstraintHelper.java index 72b13c96..a6b3e71b 100644 --- a/service/src/main/java/helper/ConstraintHelper.java +++ b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/helper/ConstraintHelper.java @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package helper; +package de.fraunhofer.iosb.ilt.faaast.registry.service.helper; import de.fraunhofer.iosb.ilt.faaast.registry.service.RegistryService; import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.AssetAdministrationShellDescriptor; diff --git a/service/src/main/java/helper/DataSpecificationConstraintHelper.java b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/helper/DataSpecificationConstraintHelper.java similarity index 97% rename from service/src/main/java/helper/DataSpecificationConstraintHelper.java rename to service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/helper/DataSpecificationConstraintHelper.java index 73d37f95..2d90ab51 100644 --- a/service/src/main/java/helper/DataSpecificationConstraintHelper.java +++ b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/helper/DataSpecificationConstraintHelper.java @@ -12,9 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package helper; - -import static helper.ConstraintHelper.MAX_IDENTIFIER_LENGTH; +package de.fraunhofer.iosb.ilt.faaast.registry.service.helper; import java.util.List; import org.eclipse.digitaltwin.aas4j.v3.model.DataSpecificationContent; @@ -152,7 +150,7 @@ private static void checkValueReferencePairs(List pairs) { private static void checkValueReferencePair(ValueReferencePair pair) { if (pair != null) { - CommonConstraintHelper.checkText(pair.getValue(), MAX_IDENTIFIER_LENGTH, true, "ValueReferencePair value"); + CommonConstraintHelper.checkText(pair.getValue(), ConstraintHelper.MAX_IDENTIFIER_LENGTH, true, "ValueReferencePair value"); CommonConstraintHelper.checkReference(pair.getValueId()); } } diff --git a/service/src/main/java/helper/EndpointConstraintHelper.java b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/helper/EndpointConstraintHelper.java similarity index 95% rename from service/src/main/java/helper/EndpointConstraintHelper.java rename to service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/helper/EndpointConstraintHelper.java index 6748225f..765409cd 100644 --- a/service/src/main/java/helper/EndpointConstraintHelper.java +++ b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/helper/EndpointConstraintHelper.java @@ -12,9 +12,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package helper; +package de.fraunhofer.iosb.ilt.faaast.registry.service.helper; -import static helper.ConstraintHelper.MAX_IDSHORT_LENGTH; +import static de.fraunhofer.iosb.ilt.faaast.registry.service.helper.ConstraintHelper.MAX_IDSHORT_LENGTH; import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.Endpoint; import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.ProtocolInformation; diff --git a/service/src/main/java/helper/RegistryHelper.java b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/helper/RegistryHelper.java similarity index 96% rename from service/src/main/java/helper/RegistryHelper.java rename to service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/helper/RegistryHelper.java index 3db8c34f..26a795e8 100644 --- a/service/src/main/java/helper/RegistryHelper.java +++ b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/helper/RegistryHelper.java @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package helper; +package de.fraunhofer.iosb.ilt.faaast.registry.service.helper; import de.fraunhofer.iosb.ilt.faaast.service.util.Ensure; import java.util.Base64; From 456017783b0316fcd823be0ed10aa188dedd04b5 Mon Sep 17 00:00:00 2001 From: Tino Bischoff Date: Mon, 29 Apr 2024 11:19:06 +0200 Subject: [PATCH 46/57] pom.xml: add sonar properties --- pom.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pom.xml b/pom.xml index 9ac378d1..a08ea608 100644 --- a/pom.xml +++ b/pom.xml @@ -78,6 +78,12 @@ ${project.basedir} 2.0.13 2.2 + ${maven.multiModuleProjectDirectory}/test/target/site/jacoco-aggregate/jacoco.xml + reuseReports + https://sonarcloud.io + jacoco + java + fraunhofer-iosb 3.2.5 6.1.6 From c6462d9db70d96d10b183daa2191f125532edba1 Mon Sep 17 00:00:00 2001 From: Tino Bischoff Date: Mon, 29 Apr 2024 11:59:16 +0200 Subject: [PATCH 47/57] use Fa3st 1.1.0-SNAPSHOT; remove sonar warnings --- .../model/JpaAssetAdministrationShellDescriptor.java | 2 +- .../faaast/registry/jpa/model/JpaDescription.java | 12 ------------ .../registry/jpa/util/EntityManagerHelper.java | 2 +- .../registry/jpa/util/ModelTransformationHelper.java | 5 +++-- pom.xml | 2 +- .../ilt/faaast/registry/service/RegistryService.java | 6 +++--- .../registry/service/ShellRegistryController.java | 1 - 7 files changed, 9 insertions(+), 21 deletions(-) diff --git a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaAssetAdministrationShellDescriptor.java b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaAssetAdministrationShellDescriptor.java index db1863cc..df03e3e2 100644 --- a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaAssetAdministrationShellDescriptor.java +++ b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaAssetAdministrationShellDescriptor.java @@ -33,7 +33,7 @@ public B from(AssetAdministrationShellDescriptor other) { if (Objects.nonNull(other)) { id(other.getId()); idShort(other.getIdShort()); - assetkind(other.getAssetKind()); + assetKind(other.getAssetKind()); assetType(other.getAssetType()); endpoints(ModelTransformationHelper.convertEndpoints(other.getEndpoints())); administration(ModelTransformationHelper.convertAdministrativeInformation(other.getAdministration())); diff --git a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaDescription.java b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaDescription.java index 37c7f7e9..d0b51fae 100644 --- a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaDescription.java +++ b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/model/JpaDescription.java @@ -70,24 +70,12 @@ else if (this.getClass() != obj.getClass()) { public abstract static class AbstractBuilder> extends LangStringTextTypeBuilder { - //extends ExtendableBuilder { public B id(String value) { getBuildingInstance().setId(value); return getSelf(); } - // public B value(String value) { - // getBuildingInstance().setValue(value); - // return getSelf(); - // } - // - // - // public B language(String value) { - // getBuildingInstance().setLanguage(value); - // return getSelf(); - // } - public B from(LangStringTextType other) { if (Objects.nonNull(other)) { diff --git a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/util/EntityManagerHelper.java b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/util/EntityManagerHelper.java index 545282ea..e9a1cda8 100644 --- a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/util/EntityManagerHelper.java +++ b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/util/EntityManagerHelper.java @@ -94,6 +94,6 @@ public static List getAllAas(EntityManager e var query = entityManager.createQuery(queryCriteria); return query.getResultList().stream() .map(AssetAdministrationShellDescriptor.class::cast) - .collect(Collectors.toList()); + .toList(); } } diff --git a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/util/ModelTransformationHelper.java b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/util/ModelTransformationHelper.java index fe12dc91..0a69dc48 100644 --- a/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/util/ModelTransformationHelper.java +++ b/persistence/jpa/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/jpa/util/ModelTransformationHelper.java @@ -39,6 +39,7 @@ import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.Endpoint; import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.ProtocolInformation; import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.SubmodelDescriptor; +import java.util.ArrayList; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; @@ -212,7 +213,7 @@ public static JpaReference convertReference(Reference reference) { */ public static List convertReferences(List references) { if (Objects.isNull(references)) { - return null; + return new ArrayList<>(); } return references.stream() .map(x -> new JpaReference.Builder().from(x).build()) @@ -288,7 +289,7 @@ public static JpaExtension convertExtension(Extension extension) { */ public static List convertExtensions(List extensions) { if (Objects.isNull(extensions)) { - return null; + return new ArrayList<>(); } return extensions.stream() .map(x -> new JpaExtension.Builder().from(x).build()) diff --git a/pom.xml b/pom.xml index a08ea608..f0f11715 100644 --- a/pom.xml +++ b/pom.xml @@ -49,7 +49,7 @@ 3.25.3 10.16.0 - 1.0.1 + 1.1.0-SNAPSHOT 2.2.224 6.4.4.Final 2.17.0 diff --git a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/RegistryService.java b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/RegistryService.java index 14a7f7ea..1d44c1cc 100644 --- a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/RegistryService.java +++ b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/RegistryService.java @@ -28,7 +28,6 @@ import de.fraunhofer.iosb.ilt.faaast.service.util.Ensure; import java.util.List; import java.util.Objects; -import java.util.stream.Collectors; import java.util.stream.Stream; import org.eclipse.digitaltwin.aas4j.v3.model.AssetKind; import org.slf4j.Logger; @@ -64,6 +63,7 @@ public Page getAASs(String assetType, AssetK if ((assetTypeDecoded != null) && (assetTypeDecoded.length() > ConstraintHelper.MAX_IDENTIFIER_LENGTH)) { throw new BadRequestException("AssetType too long"); } + LOGGER.debug("getAASs: AssetType {}; AssetKind {}", assetTypeDecoded, assetKind); List list = aasRepository.getAASs(assetTypeDecoded, assetKind); return preparePagedResult(list.stream(), paging); } @@ -326,11 +326,11 @@ private static Page preparePagedResult(Stream input, PagingInfo paging if (paging.hasLimit()) { result = result.limit(paging.getLimit() + 1); } - List temp = result.collect(Collectors.toList()); + List temp = result.toList(); return Page. builder() .result(temp.stream() .limit(paging.hasLimit() ? paging.getLimit() : temp.size()) - .collect(Collectors.toList())) + .toList()) .metadata(PagingMetadata.builder() .cursor(nextCursor(paging, temp.size())) .build()) diff --git a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/ShellRegistryController.java b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/ShellRegistryController.java index 21935713..fe498230 100644 --- a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/ShellRegistryController.java +++ b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/ShellRegistryController.java @@ -68,7 +68,6 @@ public Page getAASs(@RequestParam(name = "as @RequestParam(name = "assetKind", required = false) AssetKind assetKind, @RequestParam(name = "limit", required = false) Long limit, @RequestParam(name = "cursor", required = false) String cursor) { - LOGGER.debug("getAASs: AssetType {}; AssetKind {}, Limit: {}, Cursor: {}", assetType, assetKind, limit, cursor); PagingInfo.Builder pageBuilder = PagingInfo.builder().cursor(cursor); if (limit != null) { if (limit == 0) { From ce272098e7ede905534283fc35bb9347c63049b4 Mon Sep 17 00:00:00 2001 From: Tino Bischoff Date: Mon, 29 Apr 2024 12:38:19 +0200 Subject: [PATCH 48/57] remove sonar warnings --- .../iosb/ilt/faaast/registry/service/RegistryService.java | 5 ++++- .../ilt/faaast/registry/service/ShellRegistryController.java | 4 ---- .../faaast/registry/service/helper/CertificateHelper.java | 3 +++ 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/RegistryService.java b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/RegistryService.java index 1d44c1cc..29d52436 100644 --- a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/RegistryService.java +++ b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/RegistryService.java @@ -63,7 +63,10 @@ public Page getAASs(String assetType, AssetK if ((assetTypeDecoded != null) && (assetTypeDecoded.length() > ConstraintHelper.MAX_IDENTIFIER_LENGTH)) { throw new BadRequestException("AssetType too long"); } - LOGGER.debug("getAASs: AssetType {}; AssetKind {}", assetTypeDecoded, assetKind); + if (assetType != null) { + assetType = assetType.replaceAll("[\n\r]", "_"); + } + LOGGER.debug("getAASs: AssetType {}; AssetKind {}", assetType, assetKind); List list = aasRepository.getAASs(assetTypeDecoded, assetKind); return preparePagedResult(list.stream(), paging); } diff --git a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/ShellRegistryController.java b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/ShellRegistryController.java index fe498230..215b343f 100644 --- a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/ShellRegistryController.java +++ b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/ShellRegistryController.java @@ -24,8 +24,6 @@ import de.fraunhofer.iosb.ilt.faaast.service.model.descriptor.SubmodelDescriptor; import java.net.URI; import org.eclipse.digitaltwin.aas4j.v3.model.AssetKind; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -49,8 +47,6 @@ @RequestMapping("/api/v3.0/shell-descriptors") public class ShellRegistryController { - private static final Logger LOGGER = LoggerFactory.getLogger(ShellRegistryController.class); - @Autowired RegistryService service; diff --git a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/helper/CertificateHelper.java b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/helper/CertificateHelper.java index 27f089df..7f2bcee6 100644 --- a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/helper/CertificateHelper.java +++ b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/helper/CertificateHelper.java @@ -44,6 +44,9 @@ public class CertificateHelper { .organizationUnit("ILT") .build(); + private CertificateHelper() {} + + /** * Create a KeyStore with a self-signed certificate. * From 196220abd5670f8e792667d8ea706bf4ea187526 Mon Sep 17 00:00:00 2001 From: Tino Bischoff Date: Mon, 29 Apr 2024 13:18:29 +0200 Subject: [PATCH 49/57] add owaspSuppressions --- owaspSuppressions.xml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/owaspSuppressions.xml b/owaspSuppressions.xml index ddc59214..853bbe85 100644 --- a/owaspSuppressions.xml +++ b/owaspSuppressions.xml @@ -21,4 +21,18 @@ ^pkg:maven/org\.apache\.tomcat\.embed/tomcat\-embed\-(core|websocket)@.*$ CVE-2023-41080 + + + ^pkg:maven/io\.admin\-shell\.aas/dataformat\-xml@.*$ + CVE-2016-4570 + CVE-2016-4571 + + + + CVE-2016-4570 + + + + CVE-2016-4571 + From 7df02d8778bc4ad0100a5673b7a22cd88574e5d3 Mon Sep 17 00:00:00 2001 From: Tino Bischoff Date: Mon, 29 Apr 2024 13:31:35 +0200 Subject: [PATCH 50/57] remove sonar warning --- .../iosb/ilt/faaast/registry/service/RegistryService.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/RegistryService.java b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/RegistryService.java index 29d52436..a942357d 100644 --- a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/RegistryService.java +++ b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/RegistryService.java @@ -65,8 +65,11 @@ public Page getAASs(String assetType, AssetK } if (assetType != null) { assetType = assetType.replaceAll("[\n\r]", "_"); + LOGGER.debug("getAASs: AssetType {}", assetType); + } + if (assetKind != null) { + LOGGER.debug("getAASs: AssetKind {}", assetKind); } - LOGGER.debug("getAASs: AssetType {}; AssetKind {}", assetType, assetKind); List list = aasRepository.getAASs(assetTypeDecoded, assetKind); return preparePagedResult(list.stream(), paging); } From f99ee1f77421b82e40d967c2b8b60fc7d4f863ee Mon Sep 17 00:00:00 2001 From: Tino Bischoff Date: Mon, 29 Apr 2024 17:56:57 +0200 Subject: [PATCH 51/57] update documentation --- docs/source/gettingstarted/gettingstarted.md | 6 ------ 1 file changed, 6 deletions(-) diff --git a/docs/source/gettingstarted/gettingstarted.md b/docs/source/gettingstarted/gettingstarted.md index d6bee8b7..4b8cdd9d 100644 --- a/docs/source/gettingstarted/gettingstarted.md +++ b/docs/source/gettingstarted/gettingstarted.md @@ -49,9 +49,3 @@ This example shows how to start a FA³ST Registry with in-memory persistence. ```sh java -jar service-0.1.0-SNAPSHOT.jar ``` - -or - -```sh -mvn spring-boot:run -``` From 3fee36279767bf05ace7803d9112218c70f6a273 Mon Sep 17 00:00:00 2001 From: Tino Bischoff Date: Mon, 6 May 2024 15:48:34 +0200 Subject: [PATCH 52/57] remove sonar warning --- .../iosb/ilt/faaast/registry/service/RegistryService.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/RegistryService.java b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/RegistryService.java index a942357d..bdffde4a 100644 --- a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/RegistryService.java +++ b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/RegistryService.java @@ -64,8 +64,7 @@ public Page getAASs(String assetType, AssetK throw new BadRequestException("AssetType too long"); } if (assetType != null) { - assetType = assetType.replaceAll("[\n\r]", "_"); - LOGGER.debug("getAASs: AssetType {}", assetType); + LOGGER.debug("getAASs: AssetType {}", assetType.replaceAll("[\n\r]", "_")); } if (assetKind != null) { LOGGER.debug("getAASs: AssetKind {}", assetKind); From f61c8709283dc3e858a5144840f5f9c904261846 Mon Sep 17 00:00:00 2001 From: Tino Bischoff Date: Mon, 6 May 2024 16:04:27 +0200 Subject: [PATCH 53/57] remove sonar warning --- .../iosb/ilt/faaast/registry/service/RegistryService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/RegistryService.java b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/RegistryService.java index bdffde4a..4a014614 100644 --- a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/RegistryService.java +++ b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/RegistryService.java @@ -64,7 +64,7 @@ public Page getAASs(String assetType, AssetK throw new BadRequestException("AssetType too long"); } if (assetType != null) { - LOGGER.debug("getAASs: AssetType {}", assetType.replaceAll("[\n\r]", "_")); + LOGGER.atDebug().log("getAASs: AssetType {}", assetType.replaceAll("[\n\r]", "_")); } if (assetKind != null) { LOGGER.debug("getAASs: AssetKind {}", assetKind); From a789a90dea444fc1d9a8e0955f936b1cfb3dadec Mon Sep 17 00:00:00 2001 From: Tino Bischoff Date: Tue, 7 May 2024 15:51:44 +0200 Subject: [PATCH 54/57] update documentation --- docs/source/about/about.md | 2 +- docs/source/about/recommended.md | 3 ++- docs/source/api/api.md | 12 ++++++------ docs/source/changelog/changelog.md | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/docs/source/about/about.md b/docs/source/about/about.md index 40fdbbef..9473df3a 100644 --- a/docs/source/about/about.md +++ b/docs/source/about/about.md @@ -1,6 +1,6 @@ # About the Project -This project provides an implemetation of the Registry for the [Asset Administration Shell (AAS)](https://www.plattform-i40.de/SiteGlobals/IP/Forms/Listen/Downloads/EN/Downloads_Formular.html?cl2Categories_TechnologieAnwendungsbereich_name=Verwaltungsschale). +This project provides an implemetation of the Registry for the [Asset Administration Shell (AAS)](https://industrialdigitaltwin.org/content-hub/downloads). The Registry provides information about registered AASs, including the endpoint of the AASs. ## Contact diff --git a/docs/source/about/recommended.md b/docs/source/about/recommended.md index deb86ae6..8543339f 100644 --- a/docs/source/about/recommended.md +++ b/docs/source/about/recommended.md @@ -2,5 +2,6 @@ - [Asset Administration Shell Specifications](https://industrialdigitaltwin.org/en/content-hub) Quicklinks To Different Versions & Reading Guide -- [Details of the Asset Administration Shell - Part 2](https://www.plattform-i40.de/IP/Redaktion/EN/Downloads/Publikation/Details_of_the_Asset_Administration_Shell_Part2_V1.html), Nov 2021 +- [Details of the Asset Administration Shell - Part 2](https://industrialdigitaltwin.org/wp-content/uploads/2023/06/IDTA-01002-3-0_SpecificationAssetAdministrationShell_Part2_API_.pdf), June 20237LTS#cjt#+ + This part of the AAS specification provides information about the Registry, the descriptors and the available APIs. diff --git a/docs/source/api/api.md b/docs/source/api/api.md index 591b8bd2..64d09f53 100644 --- a/docs/source/api/api.md +++ b/docs/source/api/api.md @@ -5,11 +5,11 @@ The Registry allows accessing the data via REST-API. ### Supported API calls - Asset Administration Shell Registry Interface - - /registry/shell-descriptors ![GET](https://img.shields.io/badge/GET-blue) ![POST](https://img.shields.io/badge/POST-brightgreen) - - /registry/shell-descriptors/{aasIdentifier} ![GET](https://img.shields.io/badge/GET-blue) ![PUT](https://img.shields.io/badge/PUT-orange) ![DELETE](https://img.shields.io/badge/DELETE-red) - - /registry/shell-descriptors/{aasIdentifier}/submodel-descriptors ![GET](https://img.shields.io/badge/GET-blue) ![POST](https://img.shields.io/badge/POST-brightgreen) - - /registry/shell-descriptors/{aasIdentifier}/submodel-descriptors/{submodelIdentifier} ![GET](https://img.shields.io/badge/GET-blue) ![PUT](https://img.shields.io/badge/PUT-orange) ![DELETE](https://img.shields.io/badge/DELETE-red) + - /api/v3.0/shell-descriptors ![GET](https://img.shields.io/badge/GET-blue) ![POST](https://img.shields.io/badge/POST-brightgreen) + - /api/v3.0/shell-descriptors/{aasIdentifier} ![GET](https://img.shields.io/badge/GET-blue) ![PUT](https://img.shields.io/badge/PUT-orange) ![DELETE](https://img.shields.io/badge/DELETE-red) + - /api/v3.0/shell-descriptors/{aasIdentifier}/submodel-descriptors ![GET](https://img.shields.io/badge/GET-blue) ![POST](https://img.shields.io/badge/POST-brightgreen) + - /api/v3.0/shell-descriptors/{aasIdentifier}/submodel-descriptors/{submodelIdentifier} ![GET](https://img.shields.io/badge/GET-blue) ![PUT](https://img.shields.io/badge/PUT-orange) ![DELETE](https://img.shields.io/badge/DELETE-red) - Submodel Registry Interface - - registry/submodel-descriptors ![GET](https://img.shields.io/badge/GET-blue) ![POST](https://img.shields.io/badge/POST-brightgreen) - - registry/submodel-descriptors/{submodelIdentifier} ![GET](https://img.shields.io/badge/GET-blue) ![PUT](https://img.shields.io/badge/PUT-orange) ![DELETE](https://img.shields.io/badge/DELETE-red) + - api/v3.0/submodel-descriptors ![GET](https://img.shields.io/badge/GET-blue) ![POST](https://img.shields.io/badge/POST-brightgreen) + - api/v3.0/submodel-descriptors/{submodelIdentifier} ![GET](https://img.shields.io/badge/GET-blue) ![PUT](https://img.shields.io/badge/PUT-orange) ![DELETE](https://img.shields.io/badge/DELETE-red) diff --git a/docs/source/changelog/changelog.md b/docs/source/changelog/changelog.md index b3642f5c..5502c739 100644 --- a/docs/source/changelog/changelog.md +++ b/docs/source/changelog/changelog.md @@ -1,4 +1,4 @@ -# Changelog +# Release Notes ## Current development version (0.1.0-SNAPSHOT) From ae71f073f29b930fcfc84b8c96ad516fcadbf4af Mon Sep 17 00:00:00 2001 From: Tino Bischoff Date: Wed, 8 May 2024 10:55:11 +0200 Subject: [PATCH 55/57] Docker configuration --- Dockerfile | 3 +++ misc/docker/docker-compose.yml | 7 ++++--- 2 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..adab3373 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,3 @@ +FROM eclipse-temurin:17-jdk-alpine +COPY service/target/service-0.1.0-SNAPSHOT.jar service-0.1.0-SNAPSHOT.jar +ENTRYPOINT ["java","-jar","/service-0.1.0-SNAPSHOT.jar"] diff --git a/misc/docker/docker-compose.yml b/misc/docker/docker-compose.yml index 9889af0d..3fe77a4e 100644 --- a/misc/docker/docker-compose.yml +++ b/misc/docker/docker-compose.yml @@ -1,7 +1,6 @@ version: '3.4' services: - FA3STRegistry: - image: fraunhoferiosb/faaast-registry + fa3stregistry: volumes: - ../examples/:/app/resources/ environment: @@ -12,6 +11,8 @@ services: - spring.datasource.username=postgres - spring.datasource.password=admin - service.port=8090 + build: + context: ../../ ports: - 8090:8090 depends_on: @@ -24,4 +25,4 @@ services: POSTGRES_USER: postgres POSTGRES_PASSWORD: admin ports: - - 5432:5432 \ No newline at end of file + - 8092:5432 \ No newline at end of file From 001f1c0f0ce1bee74a46f6cd67d43a8c2a8f47ec Mon Sep 17 00:00:00 2001 From: Tino Bischoff Date: Wed, 8 May 2024 12:01:41 +0200 Subject: [PATCH 56/57] docker-compose: remove version (deprecated) --- misc/docker/docker-compose.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/misc/docker/docker-compose.yml b/misc/docker/docker-compose.yml index 3fe77a4e..3a7a5710 100644 --- a/misc/docker/docker-compose.yml +++ b/misc/docker/docker-compose.yml @@ -1,4 +1,3 @@ -version: '3.4' services: fa3stregistry: volumes: From 47532e0c7cfdc62605cade317f36325b0217905d Mon Sep 17 00:00:00 2001 From: Tino Bischoff Date: Fri, 24 May 2024 12:31:12 +0200 Subject: [PATCH 57/57] change docker-compose.yml --- misc/docker/docker-compose.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/misc/docker/docker-compose.yml b/misc/docker/docker-compose.yml index 3a7a5710..9148e450 100644 --- a/misc/docker/docker-compose.yml +++ b/misc/docker/docker-compose.yml @@ -1,5 +1,6 @@ services: - fa3stregistry: + FA3STRegistry: + image: fraunhoferiosb/faaast-registry volumes: - ../examples/:/app/resources/ environment: @@ -10,8 +11,6 @@ services: - spring.datasource.username=postgres - spring.datasource.password=admin - service.port=8090 - build: - context: ../../ ports: - 8090:8090 depends_on: