From 26ebc04f64e91d007dc5f8d6e8b61e854c010220 Mon Sep 17 00:00:00 2001 From: RHJ5FE Date: Wed, 10 Jan 2024 11:42:37 +0100 Subject: [PATCH 1/4] fixed idshort null pointer exception --- .../tractusx/semantics/registry/service/ShellService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/main/java/org/eclipse/tractusx/semantics/registry/service/ShellService.java b/backend/src/main/java/org/eclipse/tractusx/semantics/registry/service/ShellService.java index 466aced7..039a162f 100644 --- a/backend/src/main/java/org/eclipse/tractusx/semantics/registry/service/ShellService.java +++ b/backend/src/main/java/org/eclipse/tractusx/semantics/registry/service/ShellService.java @@ -109,7 +109,7 @@ public Shell save(Shell shell) { */ private void validateIdShort( Shell shell ) { //Check uniqueness of IdShort in shell level - Optional.of( shell.getIdShort() ).map( shellRepository::existsByIdShort ).filter( BooleanUtils::isFalse ) + Optional.ofNullable( shell.getIdShort() ).map( shellRepository::existsByIdShort ).filter( BooleanUtils::isFalse ) .orElseThrow( () -> new DuplicateKeyException( "An AssetAdministrationShell for the given IdShort already exists." ) ); checkForDuplicateIdShortWithInSubModels( shell ); From 235a6d8aef9b255169ef38099f6605a3574e1b1f Mon Sep 17 00:00:00 2001 From: RHJ5FE Date: Wed, 10 Jan 2024 15:51:11 +0100 Subject: [PATCH 2/4] prepare-release-0.3.30 --- charts/registry/Chart.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/charts/registry/Chart.yaml b/charts/registry/Chart.yaml index f5018a95..0510dd39 100644 --- a/charts/registry/Chart.yaml +++ b/charts/registry/Chart.yaml @@ -26,8 +26,8 @@ sources: - https://github.com/eclipse-tractusx/sldt-digital-twin-registry type: application -version: 0.3.29 -appVersion: 0.3.21 +version: 0.3.30 +appVersion: 0.3.22 dependencies: - repository: https://charts.bitnami.com/bitnami From 90638dbdb3cc478c7d06187e321f1147ec1fd91c Mon Sep 17 00:00:00 2001 From: RHJ5FE Date: Thu, 11 Jan 2024 12:17:40 +0100 Subject: [PATCH 3/4] Fixed idShort null pointer exception --- CHANGELOG.md | 2 +- .../registry/service/ShellService.java | 8 ++- .../static/aas-registry-openapi.yaml | 1 - .../AssetAdministrationShellApiTest.java | 67 +++++++++++++++++++ 4 files changed, 74 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f706993..24b2f117 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - default value for registry authentication has been corrected to 'true' in the documentation - Refactored DuplicateKey Exception handling - Removed deprecated /query-Endpoint -- Mark idShort in openApi mandatory +- Fixed idShort null pointer exception ## 0.3.21 ### Added diff --git a/backend/src/main/java/org/eclipse/tractusx/semantics/registry/service/ShellService.java b/backend/src/main/java/org/eclipse/tractusx/semantics/registry/service/ShellService.java index 039a162f..0c575451 100644 --- a/backend/src/main/java/org/eclipse/tractusx/semantics/registry/service/ShellService.java +++ b/backend/src/main/java/org/eclipse/tractusx/semantics/registry/service/ShellService.java @@ -32,6 +32,7 @@ import java.util.stream.Stream; import org.apache.commons.lang3.BooleanUtils; +import org.apache.commons.lang3.StringUtils; import org.eclipse.tractusx.semantics.RegistryProperties; import org.eclipse.tractusx.semantics.aas.registry.model.GetAllAssetAdministrationShellIdsByAssetLink200Response; import org.eclipse.tractusx.semantics.aas.registry.model.PagedResultPagingMetadata; @@ -109,8 +110,10 @@ public Shell save(Shell shell) { */ private void validateIdShort( Shell shell ) { //Check uniqueness of IdShort in shell level - Optional.ofNullable( shell.getIdShort() ).map( shellRepository::existsByIdShort ).filter( BooleanUtils::isFalse ) - .orElseThrow( () -> new DuplicateKeyException( "An AssetAdministrationShell for the given IdShort already exists." ) ); + Optional.ofNullable( shell.getIdShort() ).map( shellRepository::existsByIdShort ).filter( BooleanUtils::isTrue ) + .ifPresent( aBoolean -> { + throw new DuplicateKeyException( "An AssetAdministrationShell for the given IdShort already exists." ); + } ); checkForDuplicateIdShortWithInSubModels( shell ); } @@ -121,6 +124,7 @@ private void checkForDuplicateIdShortWithInSubModels( Shell shell ) { .map( Collection::stream ) .orElseGet( Stream::empty ) .map( Submodel::getIdShort ) + .filter( StringUtils::isNotBlank ) .map( String::toLowerCase ) .toList(); diff --git a/backend/src/main/resources/static/aas-registry-openapi.yaml b/backend/src/main/resources/static/aas-registry-openapi.yaml index 547ffd03..c56f0ab1 100644 --- a/backend/src/main/resources/static/aas-registry-openapi.yaml +++ b/backend/src/main/resources/static/aas-registry-openapi.yaml @@ -914,7 +914,6 @@ components: AssetAdministrationShellDescriptor: required: - id - - idShort type: object example: {"description":[{"language":"de","text":"hello text"},{"language":"en","text":"hello s"}],"displayName":[{"language":"de","text":"this is an example description1"}],"endpoints":[{"interface":"interfaceNameExample","protocolInformation":{"href":"endpointAddressExample","endpointProtocol":"endpointProtocolExample","endpointProtocolVersion":["e"],"subprotocol":"subprotocolExample","subprotocolBody":"subprotocolBodyExample","subprotocolBodyEncoding":"subprotocolBodyExample","securityAttributes":[{"type":"NONE","key": "Security Attribute key","value": "Security Attribute value"}]}}],"idShort":"idShortExample","id":"e1eba3d7-91f0-4dac-a730-eaa1d35e035c","specificAssetIds":[{"supplementalSemanticIds":[{"type":"ExternalReference","keys":[{"type":"Submodel","value":"semanticIdExample"}]}],"name":"identifier1KeyExample","value":"identifier1ValueExample"},{"supplementalSemanticIds":[{"type":"ExternalReference","keys":[{"type":"Submodel","value":"semanticIdExample"}]}],"name":"identifier2KeyExample","value":"identifier2ValueExample"}],"submodelDescriptors":[{"endpoints":[{"interface":"interfaceNameExample","protocolInformation":{"href":"endpointAddressExample","endpointProtocol":"endpointProtocolExample","endpointProtocolVersion":["e"],"subprotocol":"subprotocolExample","subprotocolBody":"subprotocolBodyExample","subprotocolBodyEncoding":"subprotocolBodyExample","securityAttributes":[{"type":"NONE","key": "Security Attribute key","value": "Security Attribute value"}]}}],"idShort":"idShortExample","id":"cd47615b-daf3-4036-8670-d2f89349d388","semanticId":{"type":"ExternalReference","keys":[{"type":"Submodel","value":"semanticIdExample"}]},"description":[{"language":"de","text":"hello text"},{"language":"en","text":"hello s"}]}]} allOf: diff --git a/backend/src/test/java/org/eclipse/tractusx/semantics/registry/AssetAdministrationShellApiTest.java b/backend/src/test/java/org/eclipse/tractusx/semantics/registry/AssetAdministrationShellApiTest.java index f6ea46dc..90fed33d 100644 --- a/backend/src/test/java/org/eclipse/tractusx/semantics/registry/AssetAdministrationShellApiTest.java +++ b/backend/src/test/java/org/eclipse/tractusx/semantics/registry/AssetAdministrationShellApiTest.java @@ -933,6 +933,7 @@ public void testFetchShellsByMultipleIdentificationsExpectSuccessExpectSuccess() @DisplayName( "Test creating a new Asset Administration Shell Descriptor with unique IdShort in shell and submodelDescriptor level" ) public void test_Creating_a_new_Asset_Administration_Shell_Descriptor_with_unique_IdShort_in_shell_and_submodelDescriptor_level() throws Exception { //Given + removedAllShells(); AssetAdministrationShellDescriptor shellPayload = TestUtil.createCompleteAasDescriptor(); //When & Then mvc.perform( @@ -947,10 +948,71 @@ public void test_Creating_a_new_Asset_Administration_Shell_Descriptor_with_uniqu .andExpect( status().isCreated()); } + @Test + @DisplayName( "Test creating a new Asset Administration Shell Descriptor with empty IdShort in shell and submodelDescriptor level" ) + public void test_Creating_a_new_Asset_Administration_Shell_Descriptor_with_empty_IdShort_in_shell_and_submodelDescriptor_level() throws Exception { + //Given + removedAllShells(); + AssetAdministrationShellDescriptor shellPayload = TestUtil.createCompleteAasDescriptor(); + shellPayload.setIdShort( null ); + shellPayload.getSubmodelDescriptors().get( 0 ).setIdShort( null ); + //When & Then + mvc.perform( + MockMvcRequestBuilders + .post( SHELL_BASE_PATH ) + .accept( MediaType.APPLICATION_JSON ) + .contentType( MediaType.APPLICATION_JSON ) + .content( mapper.writeValueAsString( shellPayload ) ) + .with( jwtTokenFactory.allRoles() ) + ) + .andDo( MockMvcResultHandlers.print() ) + .andExpect( status().isCreated()); + } + + @Test + @DisplayName( "Test creating a new Asset Administration Shell Descriptor with empty IdShort in shell and valid IdShort in submodelDescriptor level" ) + public void test_Creating_a_new_Asset_Administration_Shell_Descriptor_with_empty_IdShort_in_shell_and_valid_IdShort_in_submodelDescriptor_level() throws Exception { + //Given + removedAllShells(); + AssetAdministrationShellDescriptor shellPayload = TestUtil.createCompleteAasDescriptor(); + shellPayload.setIdShort( null ); + //When & Then + mvc.perform( + MockMvcRequestBuilders + .post( SHELL_BASE_PATH ) + .accept( MediaType.APPLICATION_JSON ) + .contentType( MediaType.APPLICATION_JSON ) + .content( mapper.writeValueAsString( shellPayload ) ) + .with( jwtTokenFactory.allRoles() ) + ) + .andDo( MockMvcResultHandlers.print() ) + .andExpect( status().isCreated()); + } + + @Test + @DisplayName( "Test creating a new Asset Administration Shell Descriptor with valid IdShort in shell and empty IdShort in submodelDescriptor level" ) + public void test_Creating_a_new_Asset_Administration_Shell_Descriptor_with_valid_IdShort_in_shell_and_empty_IdShort_in_submodelDescriptor_level() throws Exception { + //Given + AssetAdministrationShellDescriptor shellPayload = TestUtil.createCompleteAasDescriptor(); + shellPayload.getSubmodelDescriptors().get( 0 ).setIdShort( null ); + //When & Then + mvc.perform( + MockMvcRequestBuilders + .post( SHELL_BASE_PATH ) + .accept( MediaType.APPLICATION_JSON ) + .contentType( MediaType.APPLICATION_JSON ) + .content( mapper.writeValueAsString( shellPayload ) ) + .with( jwtTokenFactory.allRoles() ) + ) + .andDo( MockMvcResultHandlers.print() ) + .andExpect( status().isCreated()); + } + @Test @DisplayName( "Test creating a new Asset Administration Shell Descriptor with dupilcate IdShort in shell level" ) public void test_Creating_a_new_Asset_Administration_Shell_Descriptor_with_Dupilcate_IdShort_in_shell_level() throws Exception { //Given + removedAllShells(); //Creates a shell using test data AssetAdministrationShellDescriptor shellPayload = TestUtil.createCompleteAasDescriptor(); shellPayload.setId( UUID.randomUUID().toString() ); @@ -976,10 +1038,15 @@ public void test_Creating_a_new_Asset_Administration_Shell_Descriptor_with_Dupil .andExpect( jsonPath( "$.messages[0].text", is( "An AssetAdministrationShell for the given IdShort already exists." ) ) ); } + private void removedAllShells() { + shellRepository.deleteAll(); + } + @Test @DisplayName( "Test Creating a new Asset Administration Shell Descriptor with unique IdShort in shell level and duplicate IdShort in submodelDescriptor level" ) public void test_Creating_a_new_Asset_Administration_Shell_Descriptor_with_unique_IdShort_in_shell_level_and_duplicate_submodelDescriptor_level() throws Exception { //Given + removedAllShells(); AssetAdministrationShellDescriptor shellPayload = TestUtil.createCompleteAasDescriptor(); SubmodelDescriptor submodelDescriptor = new SubmodelDescriptor(); From 69cf31d4ced1cac53065797869e3167f65c04ee0 Mon Sep 17 00:00:00 2001 From: RHJ5FE Date: Thu, 11 Jan 2024 12:30:14 +0100 Subject: [PATCH 4/4] updated CHANGELOG.md --- CHANGELOG.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 24b2f117..45c3c1cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## 0.3.23 +### Added + +## fixed +- Fixed idShort null pointer exception. + ## 0.3.22 ### Added @@ -11,7 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - default value for registry authentication has been corrected to 'true' in the documentation - Refactored DuplicateKey Exception handling - Removed deprecated /query-Endpoint -- Fixed idShort null pointer exception +- Mark idShort in openApi mandatory ## 0.3.21 ### Added