Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce new status standardized #104

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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