From 0a83625bd932391d0e00e89d2a5b5074ac8b03a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20R=C3=B6mer?= Date: Tue, 25 Apr 2023 17:10:14 +0200 Subject: [PATCH] Introduce new status standardized This adds a new status standardized. Already released models can be transitioned into the standardized status. It is not possible to delete a standardized model. --- .../hub/domain/ModelPackageStatus.java | 3 +- .../triplestore/TripleStorePersistence.java | 17 +++++++++-- .../static/semantic-hub-openapi.yaml | 1 + .../tractusx/semantics/hub/ModelsApiTest.java | 29 ++++++++++++++++--- 4 files changed, 43 insertions(+), 7 deletions(-) diff --git a/backend/src/main/java/org/eclipse/tractusx/semantics/hub/domain/ModelPackageStatus.java b/backend/src/main/java/org/eclipse/tractusx/semantics/hub/domain/ModelPackageStatus.java index f45ed3f3..6d238d87 100644 --- a/backend/src/main/java/org/eclipse/tractusx/semantics/hub/domain/ModelPackageStatus.java +++ b/backend/src/main/java/org/eclipse/tractusx/semantics/hub/domain/ModelPackageStatus.java @@ -22,5 +22,6 @@ public enum ModelPackageStatus { RELEASED, DRAFT, - DEPRECATED + DEPRECATED, + STANDARDIZED } diff --git a/backend/src/main/java/org/eclipse/tractusx/semantics/hub/persistence/triplestore/TripleStorePersistence.java b/backend/src/main/java/org/eclipse/tractusx/semantics/hub/persistence/triplestore/TripleStorePersistence.java index 1d60bc22..ce0617e1 100644 --- a/backend/src/main/java/org/eclipse/tractusx/semantics/hub/persistence/triplestore/TripleStorePersistence.java +++ b/backend/src/main/java/org/eclipse/tractusx/semantics/hub/persistence/triplestore/TripleStorePersistence.java @@ -119,11 +119,24 @@ public SemanticModel save( SemanticModelType type, String newModel, SemanticMode case DRAFT: if ( desiredModelStatus.equals( ModelPackageStatus.RELEASED ) && !hasReferenceToDraftPackage( modelUrn, rdfModel ) ) { throw new InvalidStateTransitionException( "It is not allowed to release an aspect that has dependencies in DRAFT state." ); + } else if ( desiredModelStatus.equals( ModelPackageStatus.STANDARDIZED ) ) { + throw new IllegalArgumentException( + String.format( "The package %s is in status %s. Only a transition to RELEASED or DEPRECATED is possible.", + ModelPackageUrn.fromUrn( modelUrn ).getUrn(), persistedModelStatus.name() ) ); } deleteByUrn( ModelPackageUrn.fromUrn( modelUrn ) ); break; case RELEASED: - // released models can only be updated when the new state is deprecated + // released models can only be updated when the new state is deprecated or standardized + if ( desiredModelStatus.equals( ModelPackageStatus.DEPRECATED ) || desiredModelStatus.equals( ModelPackageStatus.STANDARDIZED ) ) { + deleteByUrn( ModelPackageUrn.fromUrn( modelUrn ) ); + } else { + throw new IllegalArgumentException( + String.format( "The package %s is already in status %s and cannot be modified. Only a transition to STANDARDIZED or DEPRECATED is possible.", + ModelPackageUrn.fromUrn( modelUrn ).getUrn(), persistedModelStatus.name() ) ); + } + break; + case STANDARDIZED: if ( desiredModelStatus.equals( ModelPackageStatus.DEPRECATED ) ) { deleteByUrn( ModelPackageUrn.fromUrn( modelUrn ) ); } else { @@ -168,7 +181,7 @@ public void deleteModelsPackage( final ModelPackageUrn urn ) { .orElseThrow( () -> new ModelPackageNotFoundException( urn ) ); ModelPackageStatus status = modelsPackage.getStatus(); - if ( ModelPackageStatus.RELEASED.equals( status ) ) { + if ( ModelPackageStatus.RELEASED.equals( status ) || ModelPackageStatus.STANDARDIZED.equals( status ) ) { throw new IllegalArgumentException( String.format( "The package %s is already in status %s and cannot be deleted.", urn.getUrn(), status.name() ) ); diff --git a/backend/src/main/resources/static/semantic-hub-openapi.yaml b/backend/src/main/resources/static/semantic-hub-openapi.yaml index 46310e16..a38c23d4 100644 --- a/backend/src/main/resources/static/semantic-hub-openapi.yaml +++ b/backend/src/main/resources/static/semantic-hub-openapi.yaml @@ -406,6 +406,7 @@ components: enum: - DRAFT - RELEASED + - STANDARDIZED - DEPRECATED SemanticModelType: type: string diff --git a/backend/src/test/java/org/eclipse/tractusx/semantics/hub/ModelsApiTest.java b/backend/src/test/java/org/eclipse/tractusx/semantics/hub/ModelsApiTest.java index e3194ad9..f85fbd46 100644 --- a/backend/src/test/java/org/eclipse/tractusx/semantics/hub/ModelsApiTest.java +++ b/backend/src/test/java/org/eclipse/tractusx/semantics/hub/ModelsApiTest.java @@ -313,6 +313,11 @@ public void testModelStatusTransitionForPost() throws Exception { mvc.perform(post( TestUtils.createValidModelRequest(urnPrefix),"DRAFT") ) .andDo( MockMvcResultHandlers.print() ) .andExpect(status().isOk()); + + // Transition from draft to standardized is not allowed + mvc.perform(post( TestUtils.createValidModelRequest(urnPrefix),"STANDARDIZED") ) + .andDo( MockMvcResultHandlers.print() ) + .andExpect(status().isBadRequest()); // transition from draft to release is allowed, delete is not allowed mvc.perform(post( TestUtils.createValidModelRequest(urnPrefix),"RELEASED") ) @@ -328,10 +333,21 @@ public void testModelStatusTransitionForPost() throws Exception { // transition from released to draft is not allowed mvc.perform(post( TestUtils.createValidModelRequest(urnPrefix),"DRAFT") ) .andExpect( jsonPath( "$.error.message", is( - "The package urn:bamm:org.eclipse.tractusx.model.status.transition.post:2.0.0# is already in status RELEASED and cannot be modified. Only a transition to DEPRECATED is possible." ) ) ) + "The package urn:bamm:org.eclipse.tractusx.model.status.transition.post:2.0.0# is already in status RELEASED and cannot be modified. Only a transition to STANDARDIZED or DEPRECATED is possible." ) ) ) .andExpect( status().isBadRequest() ); - // transition from released to deprecated is allowed + // transition from released to standardized is allowed + mvc.perform(post( TestUtils.createValidModelRequest(urnPrefix),"STANDARDIZED") ) + .andDo( MockMvcResultHandlers.print() ) + .andExpect(status().isOk()); + + // transition from standardized to draft is not allowed + mvc.perform(post( TestUtils.createValidModelRequest(urnPrefix),"DRAFT") ) + .andExpect( jsonPath( "$.error.message", is( + "The package urn:bamm:org.eclipse.tractusx.model.status.transition.post:2.0.0# is already in status STANDARDIZED and cannot be modified. Only a transition to DEPRECATED is possible." ) ) ) + .andExpect( status().isBadRequest() ); + + // transition from standardized to deprecated is allowed mvc.perform( post( TestUtils.createValidModelRequest(urnPrefix),"DEPRECATED") ) @@ -376,10 +392,15 @@ public void testModelStatusTransitionForPut() throws Exception { // transition from released to draft is not allowed mvc.perform(put( TestUtils.createValidModelRequest(urnPrefix), "DRAFT") ) .andExpect( jsonPath( "$.error.message", is( - "The package urn:bamm:org.eclipse.tractusx.model.status.transition.put:2.0.0# is already in status RELEASED and cannot be modified. Only a transition to DEPRECATED is possible." ) ) ) + "The package urn:bamm:org.eclipse.tractusx.model.status.transition.put:2.0.0# is already in status RELEASED and cannot be modified. Only a transition to STANDARDIZED or DEPRECATED is possible." ) ) ) .andExpect( status().isBadRequest() ); - // transition from released to deprecated is allowed + // transition from released to standardized is allowed + mvc.perform(put( TestUtils.createValidModelRequest(urnPrefix),"STANDARDIZED") ) + .andDo( MockMvcResultHandlers.print() ) + .andExpect(status().isOk()); + + // transition from standardized to deprecated is allowed mvc.perform(put( TestUtils.createValidModelRequest(urnPrefix),"DEPRECATED") ) .andDo( MockMvcResultHandlers.print() ) .andExpect(status().isOk());