diff --git a/basyx.aasrepository/basyx.aasrepository-core/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/AasRepositorySuite.java b/basyx.aasrepository/basyx.aasrepository-core/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/AasRepositorySuite.java index e6af8282e..0020d6ba3 100644 --- a/basyx.aasrepository/basyx.aasrepository-core/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/AasRepositorySuite.java +++ b/basyx.aasrepository/basyx.aasrepository-core/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/AasRepositorySuite.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (C) 2023 the Eclipse BaSyx Authors + * Copyright (C) 2024 the Eclipse BaSyx Authors * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -39,10 +39,7 @@ import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultAssetAdministrationShell; import org.eclipse.digitaltwin.basyx.aasservice.AasService; import org.eclipse.digitaltwin.basyx.aasservice.AasServiceSuite; -import org.eclipse.digitaltwin.basyx.core.exceptions.CollidingIdentifierException; -import org.eclipse.digitaltwin.basyx.core.exceptions.ElementDoesNotExistException; -import org.eclipse.digitaltwin.basyx.core.exceptions.IdentificationMismatchException; -import org.eclipse.digitaltwin.basyx.core.exceptions.MissingIdentifierException; +import org.eclipse.digitaltwin.basyx.core.exceptions.*; import org.eclipse.digitaltwin.basyx.core.pagination.CursorResult; import org.eclipse.digitaltwin.basyx.core.pagination.PaginationInfo; import org.junit.Test; @@ -145,6 +142,14 @@ public void addSubmodelReferenceToNonExistingAas() { aasRepo.addSubmodelReference("doesNotMatter", reference); } + @Test(expected = CollidingSubmodelReferenceException.class) + public void duplicateSubmodelReference() { + AssetAdministrationShell aas = DummyAasFactory.createAasWithSubmodelReference(); + AasRepository aasRepo = getAasRepository(Collections.singleton(aas)); + Reference reference = DummyAasFactory.createDummyReference(DummyAasFactory.DUMMY_SUBMODEL_ID); + aasRepo.addSubmodelReference(aas.getId(), reference); + } + @Test(expected = ElementDoesNotExistException.class) public void removeSubmodelReferenceOfNonExistingAas() { AasRepository aasRepo = getAasRepository(); diff --git a/basyx.aasrepository/basyx.aasrepository-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/authorization/TestAuthorizedAasRepository.java b/basyx.aasrepository/basyx.aasrepository-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/authorization/TestAuthorizedAasRepository.java index afad4e93a..4533bd801 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/authorization/TestAuthorizedAasRepository.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/authorization/TestAuthorizedAasRepository.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (C) 2023 the Eclipse BaSyx Authors + * Copyright (C) 2024 the Eclipse BaSyx Authors * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -355,7 +355,7 @@ public void getSubmodelReferencesWithNoAuthorization() throws IOException { public void addSubmodelReferenceWithCorrectRoleAndPermission() throws IOException { String accessToken = getAccessToken(DummyCredentialStore.BASYX_UPDATER_CREDENTIAL); - CloseableHttpResponse retrievalResponse = updateElementWithAuthorizationPostRequest(getSpecificAasSubmodelRefAccessURL(SPECIFIC_SHELL_ID), getAasJSONString("SingleSubmodelReference.json"), accessToken); + CloseableHttpResponse retrievalResponse = updateElementWithAuthorizationPostRequest(getSpecificAasSubmodelRefAccessURL(SPECIFIC_SHELL_ID), getAasJSONString("SingleSubmodelReference_1.json"), accessToken); assertEquals(HttpStatus.CREATED.value(), retrievalResponse.getCode()); } @@ -363,7 +363,7 @@ public void addSubmodelReferenceWithCorrectRoleAndPermission() throws IOExceptio public void addSubmodelReferenceWithCorrectRoleAndSpecificAasPermission() throws IOException { String accessToken = getAccessToken(DummyCredentialStore.BASYX_UPDATER_TWO_CREDENTIAL); - CloseableHttpResponse retrievalResponse = updateElementWithAuthorizationPostRequest(getSpecificAasSubmodelRefAccessURL(SPECIFIC_SHELL_ID), getAasJSONString("SingleSubmodelReference.json"), accessToken); + CloseableHttpResponse retrievalResponse = updateElementWithAuthorizationPostRequest(getSpecificAasSubmodelRefAccessURL(SPECIFIC_SHELL_ID), getAasJSONString("SingleSubmodelReference_2.json"), accessToken); assertEquals(HttpStatus.CREATED.value(), retrievalResponse.getCode()); } @@ -371,7 +371,7 @@ public void addSubmodelReferenceWithCorrectRoleAndSpecificAasPermission() throws public void addSubmodelReferenceWithCorrectRoleAndUnauthorizedSpecificAas() throws IOException { String accessToken = getAccessToken(DummyCredentialStore.BASYX_UPDATER_TWO_CREDENTIAL); - CloseableHttpResponse retrievalResponse = updateElementWithAuthorizationPostRequest(getSpecificAasSubmodelRefAccessURL(SPECIFIC_SHELL_ID_2), getAasJSONString("SingleSubmodelReference.json"), accessToken); + CloseableHttpResponse retrievalResponse = updateElementWithAuthorizationPostRequest(getSpecificAasSubmodelRefAccessURL(SPECIFIC_SHELL_ID_2), getAasJSONString("SingleSubmodelReference_1.json"), accessToken); assertEquals(HttpStatus.FORBIDDEN.value(), retrievalResponse.getCode()); } @@ -379,13 +379,13 @@ public void addSubmodelReferenceWithCorrectRoleAndUnauthorizedSpecificAas() thro public void addSubmodelReferenceWithInsufficientPermissionRole() throws IOException { String accessToken = getAccessToken(DummyCredentialStore.BASYX_READER_CREDENTIAL); - CloseableHttpResponse retrievalResponse = updateElementWithAuthorizationPostRequest(getSpecificAasSubmodelRefAccessURL(SPECIFIC_SHELL_ID), getAasJSONString("SingleSubmodelReference.json"), accessToken); + CloseableHttpResponse retrievalResponse = updateElementWithAuthorizationPostRequest(getSpecificAasSubmodelRefAccessURL(SPECIFIC_SHELL_ID), getAasJSONString("SingleSubmodelReference_1.json"), accessToken); assertEquals(HttpStatus.FORBIDDEN.value(), retrievalResponse.getCode()); } @Test public void addSubmodelReferenceWithNoAuthorization() throws IOException { - CloseableHttpResponse retrievalResponse = updateElementWithNoAuthorizationPostRequest(getSpecificAasSubmodelRefAccessURL(SPECIFIC_SHELL_ID), getAasJSONString("SingleSubmodelReference.json")); + CloseableHttpResponse retrievalResponse = updateElementWithNoAuthorizationPostRequest(getSpecificAasSubmodelRefAccessURL(SPECIFIC_SHELL_ID), getAasJSONString("SingleSubmodelReference_1.json")); assertEquals(HttpStatus.UNAUTHORIZED.value(), retrievalResponse.getCode()); } diff --git a/basyx.aasrepository/basyx.aasrepository-http/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/http/AasRepositoryApiHTTPController.java b/basyx.aasrepository/basyx.aasrepository-http/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/http/AasRepositoryApiHTTPController.java index 6c0be88c3..53f79cdc5 100644 --- a/basyx.aasrepository/basyx.aasrepository-http/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/http/AasRepositoryApiHTTPController.java +++ b/basyx.aasrepository/basyx.aasrepository-http/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/http/AasRepositoryApiHTTPController.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (C) 2023 the Eclipse BaSyx Authors + * Copyright (C) 2024 the Eclipse BaSyx Authors * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -38,6 +38,7 @@ import org.eclipse.digitaltwin.basyx.aasrepository.AasRepository; import org.eclipse.digitaltwin.basyx.aasrepository.http.pagination.GetAssetAdministrationShellsResult; import org.eclipse.digitaltwin.basyx.aasrepository.http.pagination.GetReferencesResult; +import org.eclipse.digitaltwin.basyx.core.exceptions.CollidingSubmodelReferenceException; import org.eclipse.digitaltwin.basyx.core.pagination.CursorResult; import org.eclipse.digitaltwin.basyx.core.pagination.PaginationInfo; import org.eclipse.digitaltwin.basyx.http.Base64UrlEncodedIdentifier; @@ -156,7 +157,11 @@ public ResponseEntity getAllSubmodelReferencesAasRepository(Base64U @Override public ResponseEntity postSubmodelReferenceAasRepository(Base64UrlEncodedIdentifier aasIdentifier, @Valid Reference body) { - aasRepository.addSubmodelReference(aasIdentifier.getIdentifier(), body); + try { + aasRepository.addSubmodelReference(aasIdentifier.getIdentifier(), body); + }catch(CollidingSubmodelReferenceException e){ + return new ResponseEntity(HttpStatus.CONFLICT); + } return new ResponseEntity(body, HttpStatus.CREATED); } diff --git a/basyx.aasrepository/basyx.aasrepository-http/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/http/AasRepositoryHTTPSuite.java b/basyx.aasrepository/basyx.aasrepository-http/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/http/AasRepositoryHTTPSuite.java index ec24bec5e..4e8bb589b 100644 --- a/basyx.aasrepository/basyx.aasrepository-http/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/http/AasRepositoryHTTPSuite.java +++ b/basyx.aasrepository/basyx.aasrepository-http/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/http/AasRepositoryHTTPSuite.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (C) 2023 the Eclipse BaSyx Authors + * Copyright (C) 2024 the Eclipse BaSyx Authors * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -206,6 +206,17 @@ public void createSubmodelReference() throws FileNotFoundException, IOException, BaSyxHttpTestUtils.assertSameJSONContent(getPaginatedSingleSMReferenceJson(), BaSyxHttpTestUtils.getResponseAsString(getResponse)); } + @Test + public void duplicateSubmodelReference() throws FileNotFoundException, IOException, ParseException { + createDummyAasOnServer(getAas1JSONString()); + + String json = getSingleSubmodelReference(); + + addSubmodelReferenceToDummyAas(json); + CloseableHttpResponse response = addSubmodelReferenceToDummyAas(json); + assertEquals(response.getCode(), HttpStatus.CONFLICT.value()); + } + @Test public void removeSubmodelReference() throws FileNotFoundException, IOException, ParseException { createDummyAasOnServer(getAas1JSONString()); @@ -408,7 +419,7 @@ private String requestSpecificAasJSON(String aasId) throws IOException, ParseExc } private String getSpecificSubmodelReferenceUrl() { - Base64UrlEncodedIdentifier identifier = new Base64UrlEncodedIdentifier("http://i40.customer.com/type/1/1/testSubmodel"); + Base64UrlEncodedIdentifier identifier = new Base64UrlEncodedIdentifier("http://i40.customer.com/type/1/1/testSubmodelNew"); return getSpecificAasSubmodelRefAccessURL(dummyAasId) + "/" + identifier.getEncodedIdentifier(); } @@ -420,8 +431,8 @@ private String getSpecificAssetInformationAccessURL(String aasID) { return getSpecificAasAccessURL(aasID) + "/asset-information"; } - private void addSubmodelReferenceToDummyAas(String json) throws FileNotFoundException, IOException { - BaSyxHttpTestUtils.executePostOnURL(getSpecificAasSubmodelRefAccessURL(dummyAasId), json); + private CloseableHttpResponse addSubmodelReferenceToDummyAas(String json) throws FileNotFoundException, IOException { + return BaSyxHttpTestUtils.executePostOnURL(getSpecificAasSubmodelRefAccessURL(dummyAasId), json); } protected String getSpecificAasAccessURL(String aasId) { @@ -473,7 +484,7 @@ private String getAas2JSONString() throws FileNotFoundException, IOException { } private String getSingleSubmodelReference() throws FileNotFoundException, IOException { - return BaSyxHttpTestUtils.readJSONStringFromClasspath("SingleSubmodelReference.json"); + return BaSyxHttpTestUtils.readJSONStringFromClasspath("SingleSubmodelReference_1.json"); } private String getSMReferenceRemovalJson() throws FileNotFoundException, IOException { diff --git a/basyx.aasrepository/basyx.aasrepository-http/src/test/resources/PaginatedSingleSMReference.json b/basyx.aasrepository/basyx.aasrepository-http/src/test/resources/PaginatedSingleSMReference.json index 386db3288..acff22e79 100644 --- a/basyx.aasrepository/basyx.aasrepository-http/src/test/resources/PaginatedSingleSMReference.json +++ b/basyx.aasrepository/basyx.aasrepository-http/src/test/resources/PaginatedSingleSMReference.json @@ -6,7 +6,7 @@ "keys": [ { "type": "Submodel", - "value": "http://i40.customer.com/type/1/1/testSubmodel" + "value": "http://i40.customer.com/type/1/1/testSubmodelNew" } ], "type": "ExternalReference" diff --git a/basyx.aasrepository/basyx.aasrepository-feature-authorization/src/test/resources/authorization/SingleSubmodelReference.json b/basyx.aasrepository/basyx.aasrepository-http/src/test/resources/SingleSubmodelReference_1.json similarity index 55% rename from basyx.aasrepository/basyx.aasrepository-feature-authorization/src/test/resources/authorization/SingleSubmodelReference.json rename to basyx.aasrepository/basyx.aasrepository-http/src/test/resources/SingleSubmodelReference_1.json index 0758b3be1..25657efe7 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-authorization/src/test/resources/authorization/SingleSubmodelReference.json +++ b/basyx.aasrepository/basyx.aasrepository-http/src/test/resources/SingleSubmodelReference_1.json @@ -2,7 +2,7 @@ "keys": [ { "type": "Submodel", - "value": "http://i40.customer.com/type/1/1/testSubmodel256" + "value": "http://i40.customer.com/type/1/1/testSubmodelNew" } ], "type": "ExternalReference" diff --git a/basyx.aasrepository/basyx.aasrepository-http/src/test/resources/SingleSubmodelReference.json b/basyx.aasrepository/basyx.aasrepository-http/src/test/resources/SingleSubmodelReference_2.json similarity index 55% rename from basyx.aasrepository/basyx.aasrepository-http/src/test/resources/SingleSubmodelReference.json rename to basyx.aasrepository/basyx.aasrepository-http/src/test/resources/SingleSubmodelReference_2.json index a4dc8f9b7..31198293f 100644 --- a/basyx.aasrepository/basyx.aasrepository-http/src/test/resources/SingleSubmodelReference.json +++ b/basyx.aasrepository/basyx.aasrepository-http/src/test/resources/SingleSubmodelReference_2.json @@ -2,7 +2,7 @@ "keys": [ { "type": "Submodel", - "value": "http://i40.customer.com/type/1/1/testSubmodel" + "value": "http://i40.customer.com/type/1/1/testSubmodelNew_2" } ], "type": "ExternalReference" diff --git a/basyx.aasservice/basyx.aasservice-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasservice/backend/InMemoryAasService.java b/basyx.aasservice/basyx.aasservice-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasservice/backend/InMemoryAasService.java index 56ade886c..ff913f73f 100644 --- a/basyx.aasservice/basyx.aasservice-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasservice/backend/InMemoryAasService.java +++ b/basyx.aasservice/basyx.aasservice-backend-inmemory/src/main/java/org/eclipse/digitaltwin/basyx/aasservice/backend/InMemoryAasService.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (C) 2023 the Eclipse BaSyx Authors + * Copyright (C) 2024 the Eclipse BaSyx Authors * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -30,6 +30,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.util.List; +import java.util.Optional; import java.util.TreeMap; import java.util.function.Function; import java.util.stream.Collectors; @@ -42,9 +43,7 @@ import org.eclipse.digitaltwin.aas4j.v3.model.Resource; import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultResource; import org.eclipse.digitaltwin.basyx.aasservice.AasService; -import org.eclipse.digitaltwin.basyx.core.exceptions.ElementDoesNotExistException; -import org.eclipse.digitaltwin.basyx.core.exceptions.FileDoesNotExistException; -import org.eclipse.digitaltwin.basyx.core.exceptions.FileHandlingException; +import org.eclipse.digitaltwin.basyx.core.exceptions.*; import org.eclipse.digitaltwin.basyx.core.filerepository.FileMetadata; import org.eclipse.digitaltwin.basyx.core.filerepository.FileRepository; import org.eclipse.digitaltwin.basyx.core.pagination.CursorResult; @@ -94,6 +93,8 @@ public CursorResult> getSubmodelReferences(PaginationInfo pInfo) @Override public void addSubmodelReference(Reference submodelReference) { + throwExceptionIfReferenceIsAlreadyPresent(submodelReference); + aas.getSubmodels().add(submodelReference); } @@ -207,4 +208,28 @@ private File getResourceContent(Resource resource) throws IOException { return new java.io.File(filePath); } + private void throwExceptionIfReferenceIsAlreadyPresent(Reference submodelReference) { + Optional submodelIdKey = getSubmodelTypeKey(submodelReference); + if(submodelIdKey.isEmpty()) + return; + String submodelId = submodelIdKey.get().getValue(); + if (isSubmodelIdAlreadyReferenced(submodelId)) { + throw new CollidingSubmodelReferenceException(submodelId); + } + } + + private boolean isSubmodelIdAlreadyReferenced(String submodelId) { + return aas.getSubmodels().stream().anyMatch(ref -> ref.getKeys().stream().anyMatch(key -> key.getValue().equals(submodelId))); + } + + private static Optional getSubmodelTypeKey(Reference submodelReference) { + Optional submodelIdKey = submodelReference.getKeys().stream().filter(key -> { + KeyTypes type = key.getType(); + if(type == null) + throw new MissingKeyTypeException(); + return type.equals(KeyTypes.SUBMODEL); + }).findFirst(); + return submodelIdKey; + } + } diff --git a/basyx.aasservice/basyx.aasservice-client/src/main/java/org/eclipse/digitaltwin/basyx/aasservice/client/ConnectedAasService.java b/basyx.aasservice/basyx.aasservice-client/src/main/java/org/eclipse/digitaltwin/basyx/aasservice/client/ConnectedAasService.java index b2ad3aa4a..df9095b15 100644 --- a/basyx.aasservice/basyx.aasservice-client/src/main/java/org/eclipse/digitaltwin/basyx/aasservice/client/ConnectedAasService.java +++ b/basyx.aasservice/basyx.aasservice-client/src/main/java/org/eclipse/digitaltwin/basyx/aasservice/client/ConnectedAasService.java @@ -36,6 +36,7 @@ import org.eclipse.digitaltwin.basyx.aasservice.AasService; import org.eclipse.digitaltwin.basyx.aasservice.client.internal.AssetAdministrationShellServiceApi; import org.eclipse.digitaltwin.basyx.client.internal.ApiException; +import org.eclipse.digitaltwin.basyx.core.exceptions.CollidingSubmodelReferenceException; import org.eclipse.digitaltwin.basyx.core.exceptions.ElementDoesNotExistException; import org.eclipse.digitaltwin.basyx.core.exceptions.ElementNotAFileException; import org.eclipse.digitaltwin.basyx.core.exceptions.FileDoesNotExistException; @@ -168,6 +169,10 @@ private RuntimeException mapAasAccess(ApiException e) { return new ElementDoesNotExistException(); } + if(e.getCode() == HttpStatus.CONFLICT.value()) { + return new CollidingSubmodelReferenceException(); + } + return e; } diff --git a/basyx.aasservice/basyx.aasservice-core/src/test/java/org/eclipse/digitaltwin/basyx/aasservice/AasServiceSuite.java b/basyx.aasservice/basyx.aasservice-core/src/test/java/org/eclipse/digitaltwin/basyx/aasservice/AasServiceSuite.java index 291fa47df..0c7e4cbf0 100644 --- a/basyx.aasservice/basyx.aasservice-core/src/test/java/org/eclipse/digitaltwin/basyx/aasservice/AasServiceSuite.java +++ b/basyx.aasservice/basyx.aasservice-core/src/test/java/org/eclipse/digitaltwin/basyx/aasservice/AasServiceSuite.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (C) 2023 the Eclipse BaSyx Authors + * Copyright (C) 2024 the Eclipse BaSyx Authors * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -38,18 +38,13 @@ import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import javax.imageio.ImageIO; import org.apache.commons.io.IOUtils; -import org.eclipse.digitaltwin.aas4j.v3.model.AssetAdministrationShell; -import org.eclipse.digitaltwin.aas4j.v3.model.AssetInformation; -import org.eclipse.digitaltwin.aas4j.v3.model.AssetKind; -import org.eclipse.digitaltwin.aas4j.v3.model.KeyTypes; -import org.eclipse.digitaltwin.aas4j.v3.model.Reference; -import org.eclipse.digitaltwin.aas4j.v3.model.ReferenceTypes; -import org.eclipse.digitaltwin.aas4j.v3.model.Submodel; +import org.eclipse.digitaltwin.aas4j.v3.model.*; import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultAssetAdministrationShell; import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultAssetInformation; import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultKey; @@ -99,14 +94,17 @@ public void addSubmodelReference() { Submodel submodel = createDummySubmodel(); - aasService.addSubmodelReference(submodel.getSemanticId()); + Reference ref = new DefaultReference(); + Key submodelKey = new DefaultKey.Builder().value(submodel.getId()).type(KeyTypes.SUBMODEL).build(); + ref.setKeys(Arrays.asList(submodelKey)); + + aasService.addSubmodelReference(ref); List submodelReferences = aasService.getSubmodelReferences(NO_LIMIT_PAGINATION_INFO).getResult(); Reference submodelReference = getFirstSubmodelReference(submodelReferences); - assertTrue( - submodelReference.getKeys().stream().filter(ref -> ref.getValue().equals("testKey")).findAny().isPresent()); + assertTrue(submodelReference.getKeys().contains(submodelKey)); } @Test @@ -233,6 +231,7 @@ private Reference getFirstSubmodelReference(List submodelReferences) private DefaultSubmodel createDummySubmodel() { return new DefaultSubmodel.Builder() + .id("testId") .semanticId( new DefaultReference.Builder().keys(new DefaultKey.Builder().value("testKey").build()).build()) .build(); diff --git a/basyx.common/basyx.core/src/main/java/org/eclipse/digitaltwin/basyx/core/exceptions/CollidingSubmodelReferenceException.java b/basyx.common/basyx.core/src/main/java/org/eclipse/digitaltwin/basyx/core/exceptions/CollidingSubmodelReferenceException.java new file mode 100644 index 000000000..55e40555f --- /dev/null +++ b/basyx.common/basyx.core/src/main/java/org/eclipse/digitaltwin/basyx/core/exceptions/CollidingSubmodelReferenceException.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (C) 2024 the Eclipse BaSyx Authors + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT + ******************************************************************************/ + +package org.eclipse.digitaltwin.basyx.core.exceptions; + +public class CollidingSubmodelReferenceException extends RuntimeException { + public CollidingSubmodelReferenceException() { + } + + public CollidingSubmodelReferenceException(String submodelIdentifier) { + super(getMessage(submodelIdentifier)); + } + + private static String getMessage(String submodelIdentifier) { + return "Submodel Reference with id " + submodelIdentifier + " already exists"; + } + +} diff --git a/basyx.common/basyx.core/src/main/java/org/eclipse/digitaltwin/basyx/core/exceptions/MissingKeyTypeException.java b/basyx.common/basyx.core/src/main/java/org/eclipse/digitaltwin/basyx/core/exceptions/MissingKeyTypeException.java new file mode 100644 index 000000000..8fc53b7ce --- /dev/null +++ b/basyx.common/basyx.core/src/main/java/org/eclipse/digitaltwin/basyx/core/exceptions/MissingKeyTypeException.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (C) 2024 the Eclipse BaSyx Authors + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT + ******************************************************************************/ + +package org.eclipse.digitaltwin.basyx.core.exceptions; + +public class MissingKeyTypeException extends RuntimeException { + public MissingKeyTypeException() { + } + + public MissingKeyTypeException(String msg) { + super(msg); + } +}