diff options
Diffstat (limited to 'workflow-designer-be/src/main')
14 files changed, 318 insertions, 33 deletions
diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/ExceptionsHandler.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/ExceptionsHandler.java index 642c3438..083206c8 100644 --- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/ExceptionsHandler.java +++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/ExceptionsHandler.java @@ -32,7 +32,10 @@ import org.onap.sdc.workflow.services.exceptions.UniqueValueViolationException; import org.onap.sdc.workflow.services.exceptions.VersionCreationException; import org.onap.sdc.workflow.services.exceptions.VersionModificationException; import org.onap.sdc.workflow.services.exceptions.VersionStateModificationException; +import org.onap.sdc.workflow.services.exceptions.VersionStateModificationMissingArtifactException; import org.onap.sdc.workflow.services.exceptions.VersionStatusModificationException; +import org.onap.sdc.workflow.services.exceptions.WorkflowModificationException; +import org.onap.sdc.workflow.services.exceptions.WorkflowStatusModificationException; import org.openecomp.sdc.logging.api.Logger; import org.openecomp.sdc.logging.api.LoggerFactory; import org.springframework.context.support.DefaultMessageSourceResolvable; @@ -90,8 +93,11 @@ public class ExceptionsHandler extends ResponseEntityExceptionHandler { @ExceptionHandler( {InvalidArtifactException.class, VersionCreationException.class, VersionModificationException.class, - VersionStateModificationException.class, VersionStatusModificationException.class, - UniqueValueViolationException.class}) + VersionStateModificationException.class, + VersionStateModificationMissingArtifactException.class, + VersionStatusModificationException.class, + UniqueValueViolationException.class, WorkflowStatusModificationException.class, + WorkflowModificationException.class}) public final ResponseEntity<ErrorResponse> handleUnprocessableEntityException(Exception exception) { LOG.debug(LOG_MSG, UNPROCESSABLE_ENTITY, exception); return new ResponseEntity<>(new ErrorResponse(exception.getMessage()), UNPROCESSABLE_ENTITY); diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/WorkflowController.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/WorkflowController.java index 9010fea4..8eb22390 100644 --- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/WorkflowController.java +++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/WorkflowController.java @@ -27,9 +27,11 @@ import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; +import javax.validation.Valid; import org.onap.sdc.workflow.api.types.Paging; import org.onap.sdc.workflow.api.types.Sorting; import org.onap.sdc.workflow.api.types.VersionStatesFormatter; +import org.onap.sdc.workflow.api.types.WorkflowStatusDto; import org.onap.sdc.workflow.services.WorkflowManager; import org.onap.sdc.workflow.services.WorkflowVersionManager; import org.onap.sdc.workflow.services.annotations.UserId; @@ -38,6 +40,7 @@ import org.onap.sdc.workflow.services.types.PagingRequest; import org.onap.sdc.workflow.services.types.RequestSpec; import org.onap.sdc.workflow.services.types.SortingRequest; import org.onap.sdc.workflow.services.types.Workflow; +import org.onap.sdc.workflow.services.types.WorkflowStatus; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.http.HttpStatus; @@ -81,11 +84,13 @@ public class WorkflowController { value = "Sorting criteria in the format: property:(asc|desc). Default sort order is ascending.", allowableValues = "name:asc,name:desc"), @ApiImplicitParam(name = "searchNameFilter", dataType = "string", paramType = "query", - value = "Filter by workflow name")}) - public Page<Workflow> list(@ApiIgnore String searchNameFilter, + value = "Filter by workflow name"), + @ApiImplicitParam(name = "archiving", dataType = "string", paramType = "query", + allowableValues = "ACTIVE,ARCHIVED", value = "Filter by workflow status")}) + public Page<Workflow> list(@ApiIgnore String archiving, @ApiIgnore String searchNameFilter, @ApiIgnore VersionStatesFormatter versionStateFilter, @ApiIgnore Paging paging, @ApiIgnore Sorting sorting, @UserId String user) { - return workflowManager.list(searchNameFilter, versionStateFilter.getVersionStates(), initRequestSpec(paging, sorting)); + return workflowManager.list(archiving, searchNameFilter, versionStateFilter.getVersionStates(), initRequestSpec(paging, sorting)); } @PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE) @@ -117,6 +122,14 @@ public class WorkflowController { return workflow; } + @PostMapping(path = "/{workflowId}/archiving", consumes = MediaType.APPLICATION_JSON_VALUE) + @ApiOperation("Update workflow status") + public ResponseEntity updateStatus(@RequestBody @Valid WorkflowStatusDto request, @PathVariable("workflowId") String workflowId, + @UserId String user) { + workflowManager.updateStatus(workflowId,WorkflowStatus.valueOf(request.getStatus())); + return new ResponseEntity(HttpStatus.OK); + } + private RequestSpec initRequestSpec(Paging paging, Sorting sorting) { return new RequestSpec(new PagingRequest(paging.getOffset() == null ? DEFAULT_OFFSET : paging.getOffset(), paging.getLimit() == null ? DEFAULT_LIMIT : paging.getLimit()), diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/WorkflowStatusDto.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/WorkflowStatusDto.java new file mode 100644 index 00000000..6e5ab1cf --- /dev/null +++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/WorkflowStatusDto.java @@ -0,0 +1,26 @@ +/* + * Copyright © 2018 European Support Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.sdc.workflow.api.types; + +import lombok.Data; +import org.onap.sdc.workflow.api.validation.ValidStatus; + +@Data +public class WorkflowStatusDto { + @ValidStatus(message = "Invalid status. Allowable values are: ARCHIVED,ACTIVE.") + private String status; +} diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/validation/ValidStatus.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/validation/ValidStatus.java new file mode 100644 index 00000000..96325919 --- /dev/null +++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/validation/ValidStatus.java @@ -0,0 +1,38 @@ +/* + * Copyright © 2018 European Support Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.sdc.workflow.api.validation; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import javax.validation.Constraint; +import javax.validation.Payload; + +@Target({ElementType.TYPE, ElementType.FIELD}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Constraint(validatedBy = {WorkflowStatusValidator.class}) +public @interface ValidStatus { + + String message(); + + Class<?>[] groups() default {}; + + Class<? extends Payload>[] payload() default {}; +} diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/validation/WorkflowStatusValidator.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/validation/WorkflowStatusValidator.java new file mode 100644 index 00000000..b99b424a --- /dev/null +++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/validation/WorkflowStatusValidator.java @@ -0,0 +1,38 @@ +/* + * Copyright © 2018 European Support Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.sdc.workflow.api.validation; + +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; +import org.onap.sdc.workflow.services.types.WorkflowStatus; + +public class WorkflowStatusValidator implements ConstraintValidator<ValidStatus, String> { + + @Override + public boolean isValid(String value, ConstraintValidatorContext context) { + if (value == null) { + return false; + } else { + try { + Enum.valueOf(WorkflowStatus.class, value); + return true; + } catch (IllegalArgumentException var3) { + return false; + } + } + } +} diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/WorkflowManager.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/WorkflowManager.java index 5190da14..0f8f27e2 100644 --- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/WorkflowManager.java +++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/WorkflowManager.java @@ -20,15 +20,18 @@ import java.util.Set; import org.onap.sdc.workflow.services.types.Page; import org.onap.sdc.workflow.services.types.RequestSpec; import org.onap.sdc.workflow.services.types.Workflow; +import org.onap.sdc.workflow.services.types.WorkflowStatus; import org.onap.sdc.workflow.services.types.WorkflowVersionState; public interface WorkflowManager { - Page<Workflow> list(String searchNameFilter, Set<WorkflowVersionState> versionStatesFilter, RequestSpec requestSpec); + Page<Workflow> list(String statusFilter, String searchNameFilter, Set<WorkflowVersionState> versionStatesFilter, RequestSpec requestSpec); Workflow get(Workflow workflow); Workflow create(Workflow workflow); void update(Workflow workflow); + + void updateStatus(String workflowId, WorkflowStatus status); } diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionStateModificationException.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionStateModificationException.java index 379d8e2e..43360bd6 100644 --- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionStateModificationException.java +++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionStateModificationException.java @@ -21,12 +21,12 @@ import org.onap.sdc.workflow.services.types.WorkflowVersionState; public class VersionStateModificationException extends RuntimeException { public VersionStateModificationException(String workflowId, String versionId, WorkflowVersionState sourceState, - WorkflowVersionState targetState) { + WorkflowVersionState targetState) { this(workflowId, versionId, sourceState, targetState, null); } public VersionStateModificationException(String workflowId, String versionId, WorkflowVersionState sourceState, - WorkflowVersionState targetState, Exception submitException) { + WorkflowVersionState targetState, Exception submitException) { super(String.format("Workflow %s, version %s: state can not be changed from %s to %s", workflowId, versionId, sourceState.name(), targetState.name()), submitException); } diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionStateModificationMissingArtifactException.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionStateModificationMissingArtifactException.java new file mode 100644 index 00000000..48aaa5c7 --- /dev/null +++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionStateModificationMissingArtifactException.java @@ -0,0 +1,16 @@ +package org.onap.sdc.workflow.services.exceptions; + +import org.onap.sdc.workflow.services.types.WorkflowVersionState; + +public class VersionStateModificationMissingArtifactException extends RuntimeException { + + public static final String WORKFLOW_MODIFICATION_STATE_MISSING_ARTIFACT_TEMPLATE = + "Workflow %s, version %s: state can not be changed from %s to %s. Missing artifact"; + + public VersionStateModificationMissingArtifactException(String workflowId, String versionId, + WorkflowVersionState sourceState, + WorkflowVersionState targetState) { + super(String.format(WORKFLOW_MODIFICATION_STATE_MISSING_ARTIFACT_TEMPLATE, workflowId, versionId, + sourceState.name(), targetState.name())); + } +} diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/WorkflowModificationException.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/WorkflowModificationException.java new file mode 100644 index 00000000..7aa5ac0b --- /dev/null +++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/WorkflowModificationException.java @@ -0,0 +1,25 @@ +/* + * Copyright © 2018 European Support Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.sdc.workflow.services.exceptions; + +public class WorkflowModificationException extends RuntimeException { + + public WorkflowModificationException(String workflowId) { + super(String.format( + "Error while trying to modify workflow %s: Workflow is ARCHIVED and can not be edited", workflowId)); + } +} diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/WorkflowStatusModificationException.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/WorkflowStatusModificationException.java new file mode 100644 index 00000000..380b1405 --- /dev/null +++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/WorkflowStatusModificationException.java @@ -0,0 +1,26 @@ +/* + * Copyright © 2018 European Support Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.sdc.workflow.services.exceptions; + +import org.openecomp.sdc.common.errors.CoreException; + +public class WorkflowStatusModificationException extends RuntimeException { + + public WorkflowStatusModificationException(CoreException ex) { + super(ex.getMessage()); + } +} diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/WorkflowManagerImpl.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/WorkflowManagerImpl.java index 9dd33132..27257b49 100644 --- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/WorkflowManagerImpl.java +++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/WorkflowManagerImpl.java @@ -30,6 +30,8 @@ import java.util.stream.Collectors; import org.onap.sdc.workflow.services.UniqueValueService; import org.onap.sdc.workflow.services.WorkflowManager; import org.onap.sdc.workflow.services.exceptions.EntityNotFoundException; +import org.onap.sdc.workflow.services.exceptions.WorkflowModificationException; +import org.onap.sdc.workflow.services.exceptions.WorkflowStatusModificationException; import org.onap.sdc.workflow.services.impl.mappers.VersionStateMapper; import org.onap.sdc.workflow.services.impl.mappers.WorkflowMapper; import org.onap.sdc.workflow.services.types.Page; @@ -38,7 +40,9 @@ import org.onap.sdc.workflow.services.types.RequestSpec; import org.onap.sdc.workflow.services.types.Sort; import org.onap.sdc.workflow.services.types.SortingRequest; import org.onap.sdc.workflow.services.types.Workflow; +import org.onap.sdc.workflow.services.types.WorkflowStatus; import org.onap.sdc.workflow.services.types.WorkflowVersionState; +import org.openecomp.sdc.common.errors.CoreException; import org.openecomp.sdc.logging.api.Logger; import org.openecomp.sdc.logging.api.LoggerFactory; import org.openecomp.sdc.versioning.ItemManager; @@ -54,7 +58,7 @@ public class WorkflowManagerImpl implements WorkflowManager { private static final String WORKFLOW_NOT_FOUND_ERROR_MSG = "Workflow with id '%s' does not exist"; private static final String WORKFLOW_NAME_UNIQUE_TYPE = "WORKFLOW_NAME"; - private static final Predicate<Item> WORKFLOW_ITEM_FILTER = item -> WORKFLOW.name().equals(item.getType()); + private static final Predicate<Item> WORKFLOW_ITEM_TYPE_FILTER = item -> WORKFLOW.name().equals(item.getType()); private static final String WORKSPACES_SORT_PROPERTY = "name"; private static final RequestSpec WORKSPACES_DEFAULT_REQUEST_SPEC = new RequestSpec(new PagingRequest(DEFAULT_OFFSET, DEFAULT_LIMIT), @@ -78,17 +82,12 @@ public class WorkflowManagerImpl implements WorkflowManager { } @Override - public Page<Workflow> list(String searchNameFilter, Set<WorkflowVersionState> versionStatesFilter, - RequestSpec requestSpec) { + public Page<Workflow> list(String statusFilter, String searchNameFilter, + Set<WorkflowVersionState> versionStatesFilter, RequestSpec requestSpec) { requestSpec = getRequestSpec(requestSpec); - Set<VersionStatus> versionStatusesFilter = - versionStatesFilter == null ? null : - versionStatesFilter.stream().map(versionStateMapper::workflowVersionStateToVersionStatus) - .collect(Collectors.toSet()); - - Predicate<Item> filter = addSearchNameFilter(WORKFLOW_ITEM_FILTER, searchNameFilter); - Collection<Item> workflowItems = itemManager.list(addVersionStatusFilter(filter, versionStatusesFilter)); + Collection<Item> workflowItems = + itemManager.list(createFilter(statusFilter, searchNameFilter, versionStatesFilter)); List<Workflow> workflowsSlice = workflowItems.stream().map(workflowMapper::itemToWorkflow) .sorted(getWorkflowComparator(requestSpec.getSorting())) @@ -128,6 +127,10 @@ public class WorkflowManagerImpl implements WorkflowManager { throw new EntityNotFoundException(String.format(WORKFLOW_NOT_FOUND_ERROR_MSG, workflow.getId())); } + if (ItemStatus.ARCHIVED.equals(retrievedItem.getStatus())) { + throw new WorkflowModificationException(workflow.getId()); + } + uniqueValueService.updateUniqueValue(WORKFLOW_NAME_UNIQUE_TYPE, retrievedItem.getName(), workflow.getName()); Item item = workflowMapper.workflowToItem(workflow); @@ -137,7 +140,25 @@ public class WorkflowManagerImpl implements WorkflowManager { itemManager.update(item); } - private static RequestSpec getRequestSpec(RequestSpec requestSpec) { + @Override + public void updateStatus(String workflowId, WorkflowStatus status) { + Item item = itemManager.get(workflowId); + if (item == null) { + LOGGER.error(String.format("Workflow with id %s was not found",workflowId)); + throw new EntityNotFoundException(String.format(WORKFLOW_NOT_FOUND_ERROR_MSG, workflowId)); + } + try { + if (WorkflowStatus.ARCHIVED.equals(status)) { + itemManager.archive(item); + } else if (WorkflowStatus.ACTIVE.equals(status)) { + itemManager.restore(item); + } + } catch (CoreException ex) { + throw new WorkflowStatusModificationException(ex); + } + } + + private static RequestSpec getRequestSpec(RequestSpec requestSpec) { if (requestSpec == null) { return WORKSPACES_DEFAULT_REQUEST_SPEC; } @@ -172,15 +193,42 @@ public class WorkflowManagerImpl implements WorkflowManager { return byNameAscending ? byName : byName.reversed(); } + private Predicate<Item> createFilter(String itemStatusFilter, String searchNameFilter, + Set<WorkflowVersionState> versionStatesFilter) { + + Set<VersionStatus> versionStatusesFilter = + versionStatesFilter == null ? null : + versionStatesFilter.stream().map(versionStateMapper::workflowVersionStateToVersionStatus) + .collect(Collectors.toSet()); + + Predicate<Item> filter = addSearchNameFilter(WORKFLOW_ITEM_TYPE_FILTER, searchNameFilter); + + filter = addVersionStatusFilter(filter, versionStatusesFilter); + + return addItemStatusFilter(filter, itemStatusFilter); + + } + private static Predicate<Item> addSearchNameFilter(Predicate<Item> filter, String searchNameFilter) { - return filter - .and(item -> searchNameFilter == null || - item.getName().toLowerCase().contains(searchNameFilter.toLowerCase())); + return filter.and(item -> searchNameFilter == null + || item.getName().toLowerCase().contains(searchNameFilter.toLowerCase())); } private static Predicate<Item> addVersionStatusFilter(Predicate<Item> filter, Set<VersionStatus> versionStatuses) { - return filter - .and(item -> versionStatuses == null || item.getVersionStatusCounters().keySet().stream() - .anyMatch(versionStatuses::contains)); + return filter.and(item -> versionStatuses == null + || item.getVersionStatusCounters().keySet().stream().anyMatch(versionStatuses::contains)); + } + + private static Predicate<Item> addItemStatusFilter(Predicate<Item> filter, String itemStatusFilter) { + if (itemStatusFilter != null) { + try { + ItemStatus.valueOf(itemStatusFilter.toUpperCase()); + } catch (IllegalArgumentException e) { + LOGGER.debug(String.format("Illegal Workflow status filter: %s. Ignoring filter", itemStatusFilter)); + return filter; + } + return filter.and(item -> item.getStatus().equals(ItemStatus.valueOf(itemStatusFilter.toUpperCase()))); + } + return filter; } } diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImpl.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImpl.java index f2f8c276..5eba8d4a 100644 --- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImpl.java +++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImpl.java @@ -29,6 +29,7 @@ import java.util.Optional; import java.util.Set; import java.util.function.Function; import java.util.stream.Collectors; + import org.onap.sdc.workflow.persistence.ArtifactRepository; import org.onap.sdc.workflow.persistence.ParameterRepository; import org.onap.sdc.workflow.persistence.types.ArtifactEntity; @@ -40,15 +41,20 @@ import org.onap.sdc.workflow.services.exceptions.InvalidArtifactException; import org.onap.sdc.workflow.services.exceptions.VersionCreationException; import org.onap.sdc.workflow.services.exceptions.VersionModificationException; import org.onap.sdc.workflow.services.exceptions.VersionStateModificationException; +import org.onap.sdc.workflow.services.exceptions.VersionStateModificationMissingArtifactException; +import org.onap.sdc.workflow.services.exceptions.WorkflowModificationException; import org.onap.sdc.workflow.services.impl.mappers.VersionMapper; import org.onap.sdc.workflow.services.impl.mappers.VersionStateMapper; import org.onap.sdc.workflow.services.types.WorkflowVersion; import org.onap.sdc.workflow.services.types.WorkflowVersionState; import org.openecomp.sdc.logging.api.Logger; import org.openecomp.sdc.logging.api.LoggerFactory; +import org.openecomp.sdc.versioning.ItemManager; import org.openecomp.sdc.versioning.VersioningManager; import org.openecomp.sdc.versioning.dao.types.Version; import org.openecomp.sdc.versioning.dao.types.VersionStatus; +import org.openecomp.sdc.versioning.types.Item; +import org.openecomp.sdc.versioning.types.ItemStatus; import org.openecomp.sdc.versioning.types.VersionCreationMethod; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -60,6 +66,7 @@ public class WorkflowVersionManagerImpl implements WorkflowVersionManager { private static final String VERSION_NOT_EXIST_MSG = "version with id '%s' does not exist for workflow with id '%s'"; private final VersioningManager versioningManager; + private final ItemManager itemManager; private final ArtifactRepository artifactRepository; private final ParameterRepository parameterRepository; private final VersionMapper versionMapper; @@ -68,8 +75,9 @@ public class WorkflowVersionManagerImpl implements WorkflowVersionManager { @Autowired public WorkflowVersionManagerImpl(VersioningManager versioningManager, ArtifactRepository artifactRepository, - VersionMapper versionMapper, VersionStateMapper versionStateMapper, + VersionMapper versionMapper, VersionStateMapper versionStateMapper, ItemManager itemManager, ParameterRepository parameterRepository) { + this.itemManager = itemManager; this.versioningManager = versioningManager; this.artifactRepository = artifactRepository; this.parameterRepository = parameterRepository; @@ -103,6 +111,7 @@ public class WorkflowVersionManagerImpl implements WorkflowVersionManager { @Override public WorkflowVersion create(String workflowId, String baseVersionId, WorkflowVersion workflowVersion) { + validateWorkflowStatus(workflowId); List<Version> versions = versioningManager.list(workflowId); if (baseVersionId != null) { @@ -131,6 +140,7 @@ public class WorkflowVersionManagerImpl implements WorkflowVersionManager { @Override public void update(String workflowId, WorkflowVersion workflowVersion) { + validateWorkflowStatus(workflowId); Version retrievedVersion = getVersion(workflowId, workflowVersion.getId()); if (CERTIFIED.equals(versionStateMapper.versionStatusToWorkflowVersionState(retrievedVersion.getStatus()))) { throw new VersionModificationException(workflowId, workflowVersion.getId()); @@ -157,23 +167,28 @@ public class WorkflowVersionManagerImpl implements WorkflowVersionManager { } @Override - public void updateState(String workflowId, String versionId, WorkflowVersionState state) { - WorkflowVersionState retrievedState = getState(workflowId, versionId); - if (state == CERTIFIED) { + public void updateState(String workflowId, String versionId, WorkflowVersionState newState) { + WorkflowVersionState currentState = getState(workflowId, versionId); + if (newState == CERTIFIED) { + if(!artifactRepository.isExist(workflowId,versionId)){ + throw new VersionStateModificationMissingArtifactException(workflowId, versionId, currentState, + newState); + } try { versioningManager.submit(workflowId, new Version(versionId), - String.format("Update version state to %s", state.name())); + String.format("Update version state to %s", newState.name())); } catch (Exception submitException) { - throw new VersionStateModificationException(workflowId, versionId, retrievedState, - state, submitException); + throw new VersionStateModificationException(workflowId, versionId, currentState, newState, + submitException); } } else { - throw new VersionStateModificationException(workflowId, versionId, retrievedState, state); + throw new VersionStateModificationException(workflowId, versionId, currentState, newState); } } @Override public void uploadArtifact(String workflowId, String versionId, MultipartFile artifact) { + validateWorkflowStatus(workflowId); Version retrievedVersion = getVersion(workflowId, versionId); if (CERTIFIED.equals(versionStateMapper.versionStatusToWorkflowVersionState(retrievedVersion.getStatus()))) { throw new VersionModificationException(workflowId, versionId); @@ -210,6 +225,7 @@ public class WorkflowVersionManagerImpl implements WorkflowVersionManager { @Override public void deleteArtifact(String workflowId, String versionId) { + validateWorkflowStatus(workflowId); WorkflowVersion retrievedVersion = get(workflowId, versionId); if (CERTIFIED.equals(retrievedVersion.getState())) { LOGGER.error(String.format( @@ -286,4 +302,11 @@ public class WorkflowVersionManagerImpl implements WorkflowVersionManager { return versions.stream().filter(version -> versionId.equals(version.getId())).findFirst(); } + protected void validateWorkflowStatus(String workflowId) { + Item workflowItem = itemManager.get(workflowId); + if (ItemStatus.ARCHIVED.equals(workflowItem.getStatus())) { + throw new WorkflowModificationException(workflowId); + } + } + }
\ No newline at end of file diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/Workflow.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/Workflow.java index 3d8e4c77..0c0179e2 100644 --- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/Workflow.java +++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/Workflow.java @@ -39,4 +39,5 @@ public class Workflow { private String description; private Set<WorkflowVersionState> versionStates; private Collection<WorkflowVersion> versions; + private WorkflowStatus status; } diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/WorkflowStatus.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/WorkflowStatus.java new file mode 100644 index 00000000..6df7ff30 --- /dev/null +++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/WorkflowStatus.java @@ -0,0 +1,22 @@ +/* + * Copyright © 2018 European Support Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.sdc.workflow.services.types; + +public enum WorkflowStatus { + ARCHIVED, + ACTIVE +} |