Skip to content

Commit

Permalink
Merge pull request #104 from bci-oss/feature/status-standardized
Browse files Browse the repository at this point in the history
Introduce new status standardized
  • Loading branch information
tunacicek authored Jun 13, 2023
2 parents 4fa8274 + 0a83625 commit f1cebbe
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@
public enum ModelPackageStatus {
RELEASED,
DRAFT,
DEPRECATED
DEPRECATED,
STANDARDIZED
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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() ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ components:
enum:
- DRAFT
- RELEASED
- STANDARDIZED
- DEPRECATED
SemanticModelType:
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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") )
Expand All @@ -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")
)
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit f1cebbe

Please sign in to comment.