From 6dc58fd625279f8ffe1060170418686034db0af4 Mon Sep 17 00:00:00 2001 From: vasraz Date: Wed, 2 Oct 2019 12:08:49 +0100 Subject: Fix name convention issue Rename modules: workflow-designer-init to sdc-workflow-designer-init workflow-designer-be to sdc-workflow-designer-be workflow-designer-ui to sdc-workflow-designer-ui Rename docker images: onap/workflow-init to onap/sdc-workflow-init onap/workflow-backend to onap/sdc-workflow-backend onap/workflow-frontend to onap/sdc-workflow-frontend List of changed files: modified: README.md modified: docker-compose/debug.yml modified: docker-compose/docker-compose.yml modified: pom.xml modified: sdc-workflow-bdd/pom.xml modified: sdc-workflow-designer-be/pom.xml modified: sdc-workflow-designer-init/pom.xml modified: sdc-workflow-designer-ui/pom.xml modified: sdc-workflow-designer-ui/src/main/frontend/yarn.lock modified: version.properties All others changes are relaited to rename/move. Change-Id: Ic989b6347b815f85e77e23fc8d7884c05b650a27 Issue-ID: SDC-2334 Issue-ID: SDC-2335 Signed-off-by: Vasyl Razinkov --- .../sdc/workflow/SpringBootWebApplication.java | 39 +++ .../sdc/workflow/api/ActivitySpecController.java | 124 +++++++++ .../workflow/api/ArtifactAssociationService.java | 235 ++++++++++++++++ .../sdc/workflow/api/DisableSwaggerController.java | 33 +++ .../onap/sdc/workflow/api/ExceptionsHandler.java | 119 ++++++++ .../java/org/onap/sdc/workflow/api/RestParams.java | 28 ++ .../onap/sdc/workflow/api/WorkflowController.java | 138 +++++++++ .../workflow/api/WorkflowVersionController.java | 161 +++++++++++ .../api/mappers/ActivitySpecDtoMapper.java | 34 +++ .../api/mappers/WorkflowVersionDtoMapper.java | 31 +++ .../sdc/workflow/api/swagger/UserIdReader.java | 61 ++++ .../sdc/workflow/api/types/CollectionResponse.java | 32 +++ .../onap/sdc/workflow/api/types/ErrorResponse.java | 27 ++ .../org/onap/sdc/workflow/api/types/Paging.java | 50 ++++ .../org/onap/sdc/workflow/api/types/Parameter.java | 34 +++ .../org/onap/sdc/workflow/api/types/Sorting.java | 66 +++++ .../api/types/UnexpectedErrorResponse.java | 34 +++ .../sdc/workflow/api/types/VersionStateDto.java | 35 +++ .../workflow/api/types/VersionStatesFormatter.java | 53 ++++ .../sdc/workflow/api/types/WorkflowStatusDto.java | 26 ++ .../workflow/api/types/WorkflowVersionRequest.java | 36 +++ .../api/types/WorkflowVersionResponse.java | 34 +++ .../api/types/activityspec/ActivitySpecAction.java | 21 ++ .../activityspec/ActivitySpecActionRequest.java | 26 ++ .../api/types/activityspec/ActivitySpecBase.java | 31 +++ .../activityspec/ActivitySpecCreateResponse.java | 29 ++ .../activityspec/ActivitySpecDataResponse.java | 27 ++ .../types/activityspec/ActivitySpecRequest.java | 37 +++ .../types/activityspec/ActivitySpecResponse.java | 27 ++ .../types/dto/ArtifactDeliveriesRequestDto.java | 41 +++ .../ActivitySpecParameterNameValidator.java | 65 +++++ .../api/validation/ArchivingStatusValidator.java | 38 +++ .../sdc/workflow/api/validation/NoDuplicates.java | 38 +++ .../api/validation/NoDuplicatesValidator.java | 37 +++ .../sdc/workflow/api/validation/ValidName.java | 38 +++ .../sdc/workflow/api/validation/ValidStatus.java | 38 +++ .../persistence/ActivitySpecRepository.java | 28 ++ .../workflow/persistence/ArtifactRepository.java | 36 +++ .../workflow/persistence/ParameterRepository.java | 39 +++ .../persistence/UniqueValueRepository.java | 26 ++ .../impl/ActivitySpecRepositoryImpl.java | 141 ++++++++++ .../persistence/impl/ArtifactRepositoryImpl.java | 136 +++++++++ .../persistence/impl/ParameterRepositoryImpl.java | 171 ++++++++++++ .../persistence/impl/types/ActivitySpecData.java | 31 +++ .../impl/types/ActivitySpecElementType.java | 21 ++ .../impl/types/ParameterPropertyName.java | 21 ++ .../impl/types/WorkflowElementType.java | 26 ++ .../persistence/types/ActivitySpecEntity.java | 44 +++ .../persistence/types/ActivitySpecParameter.java | 33 +++ .../workflow/persistence/types/ArtifactEntity.java | 29 ++ .../persistence/types/ParameterEntity.java | 34 +++ .../workflow/persistence/types/ParameterRole.java | 24 ++ .../workflow/persistence/types/ParameterType.java | 25 ++ .../persistence/types/UniqueValueEntity.java | 36 +++ .../server/config/ApplicationConfigurer.java | 50 ++++ .../server/config/LoggingInterceptorConfig.java | 39 +++ .../sdc/workflow/server/config/SwaggerConfig.java | 39 +++ .../workflow/server/config/WebServerConfig.java | 44 +++ .../config/WorkflowZusammenConfigProvider.java | 48 ++++ .../server/filters/SessionContextFilter.java | 73 +++++ .../workflow/server/resolvers/UserIdResolver.java | 71 +++++ .../workflow/services/ActivitySpecConstant.java | 28 ++ .../sdc/workflow/services/ActivitySpecManager.java | 34 +++ .../sdc/workflow/services/UniqueValueService.java | 122 ++++++++ .../sdc/workflow/services/WorkflowManager.java | 37 +++ .../workflow/services/WorkflowVersionManager.java | 46 +++ .../sdc/workflow/services/annotations/UserId.java | 28 ++ .../exceptions/EntityNotFoundException.java | 24 ++ .../exceptions/InvalidArtifactException.java | 24 ++ .../exceptions/UniqueValueViolationException.java | 27 ++ .../exceptions/VersionCreationException.java | 31 +++ .../exceptions/VersionModificationException.java | 26 ++ .../VersionStateModificationException.java | 33 +++ ...nStateModificationMissingArtifactException.java | 32 +++ .../VersionStatusModificationException.java | 28 ++ .../exceptions/VersionValidationException.java | 26 ++ .../exceptions/WorkflowModificationException.java | 25 ++ .../services/impl/ActivitySpecManagerImpl.java | 231 ++++++++++++++++ .../onap/sdc/workflow/services/impl/ItemType.java | 21 ++ .../services/impl/WorkflowManagerImpl.java | 217 +++++++++++++++ .../services/impl/WorkflowVersionManagerImpl.java | 308 +++++++++++++++++++++ .../services/impl/mappers/ActivitySpecMapper.java | 61 ++++ .../impl/mappers/ArchivingStatusMapper.java | 36 +++ .../services/impl/mappers/VersionMapper.java | 45 +++ .../services/impl/mappers/VersionStateMapper.java | 46 +++ .../services/impl/mappers/WorkflowMapper.java | 49 ++++ .../workflow/services/types/ArchivingStatus.java | 22 ++ .../org/onap/sdc/workflow/services/types/Page.java | 34 +++ .../onap/sdc/workflow/services/types/Paging.java | 41 +++ .../workflow/services/types/PagingConstants.java | 28 ++ .../sdc/workflow/services/types/PagingRequest.java | 39 +++ .../sdc/workflow/services/types/RequestSpec.java | 28 ++ .../org/onap/sdc/workflow/services/types/Sort.java | 30 ++ .../workflow/services/types/SortingRequest.java | 30 ++ .../onap/sdc/workflow/services/types/Workflow.java | 45 +++ .../types/WorkflowValidationConstants.java | 23 ++ .../workflow/services/types/WorkflowVersion.java | 46 +++ .../services/types/WorkflowVersionState.java | 36 +++ .../sdc/workflow/services/utilities/JsonUtil.java | 96 +++++++ 99 files changed, 5271 insertions(+) create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/SpringBootWebApplication.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/ActivitySpecController.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/ArtifactAssociationService.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/DisableSwaggerController.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/ExceptionsHandler.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/RestParams.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/WorkflowController.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/WorkflowVersionController.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/mappers/ActivitySpecDtoMapper.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/mappers/WorkflowVersionDtoMapper.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/swagger/UserIdReader.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/CollectionResponse.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/ErrorResponse.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/Paging.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/Parameter.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/Sorting.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/UnexpectedErrorResponse.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/VersionStateDto.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/VersionStatesFormatter.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/WorkflowStatusDto.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/WorkflowVersionRequest.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/WorkflowVersionResponse.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/activityspec/ActivitySpecAction.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/activityspec/ActivitySpecActionRequest.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/activityspec/ActivitySpecBase.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/activityspec/ActivitySpecCreateResponse.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/activityspec/ActivitySpecDataResponse.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/activityspec/ActivitySpecRequest.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/activityspec/ActivitySpecResponse.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/dto/ArtifactDeliveriesRequestDto.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/validation/ActivitySpecParameterNameValidator.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/validation/ArchivingStatusValidator.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/validation/NoDuplicates.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/validation/NoDuplicatesValidator.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/validation/ValidName.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/validation/ValidStatus.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/ActivitySpecRepository.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/ArtifactRepository.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/ParameterRepository.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/UniqueValueRepository.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/ActivitySpecRepositoryImpl.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/ArtifactRepositoryImpl.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/ParameterRepositoryImpl.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/types/ActivitySpecData.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/types/ActivitySpecElementType.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/types/ParameterPropertyName.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/types/WorkflowElementType.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ActivitySpecEntity.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ActivitySpecParameter.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ArtifactEntity.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ParameterEntity.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ParameterRole.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ParameterType.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/UniqueValueEntity.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/config/ApplicationConfigurer.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/config/LoggingInterceptorConfig.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/config/SwaggerConfig.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/config/WebServerConfig.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/config/WorkflowZusammenConfigProvider.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/filters/SessionContextFilter.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/resolvers/UserIdResolver.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/ActivitySpecConstant.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/ActivitySpecManager.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/UniqueValueService.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/WorkflowManager.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/WorkflowVersionManager.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/annotations/UserId.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/EntityNotFoundException.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/InvalidArtifactException.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/UniqueValueViolationException.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionCreationException.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionModificationException.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionStateModificationException.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionStateModificationMissingArtifactException.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionStatusModificationException.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionValidationException.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/WorkflowModificationException.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/ActivitySpecManagerImpl.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/ItemType.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/WorkflowManagerImpl.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImpl.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/ActivitySpecMapper.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/ArchivingStatusMapper.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/VersionMapper.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/VersionStateMapper.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/WorkflowMapper.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/ArchivingStatus.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/Page.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/Paging.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/PagingConstants.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/PagingRequest.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/RequestSpec.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/Sort.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/SortingRequest.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/Workflow.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/WorkflowValidationConstants.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/WorkflowVersion.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/WorkflowVersionState.java create mode 100644 sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/utilities/JsonUtil.java (limited to 'sdc-workflow-designer-be/src/main/java') diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/SpringBootWebApplication.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/SpringBootWebApplication.java new file mode 100644 index 00000000..87de212e --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/SpringBootWebApplication.java @@ -0,0 +1,39 @@ +/* + * 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; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory; +import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; + +@SpringBootApplication +@ComponentScan( {"org.onap.sdc.common", "org.onap.sdc.workflow"}) +public class SpringBootWebApplication { + + public static void main(String[] args) { + SpringApplication.run(SpringBootWebApplication.class, args); + } + + @Bean + public ConfigurableServletWebServerFactory webServerFactory() { + return new JettyServletWebServerFactory(); + } + +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/ActivitySpecController.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/ActivitySpecController.java new file mode 100644 index 00000000..ac72d46e --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/ActivitySpecController.java @@ -0,0 +1,124 @@ +/* + * Copyright © 2016-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; + +import static org.onap.sdc.workflow.api.RestParams.USER_ID_HEADER; +import static org.onap.sdc.workflow.services.ActivitySpecConstant.VERSION_ID_DEFAULT_VALUE; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import java.util.stream.Collectors; +import javax.validation.Valid; +import org.onap.sdc.workflow.api.mappers.ActivitySpecDtoMapper; +import org.onap.sdc.workflow.api.types.CollectionResponse; +import org.onap.sdc.workflow.api.types.activityspec.ActivitySpecActionRequest; +import org.onap.sdc.workflow.api.types.activityspec.ActivitySpecCreateResponse; +import org.onap.sdc.workflow.api.types.activityspec.ActivitySpecDataResponse; +import org.onap.sdc.workflow.api.types.activityspec.ActivitySpecRequest; +import org.onap.sdc.workflow.api.types.activityspec.ActivitySpecResponse; +import org.onap.sdc.workflow.persistence.types.ActivitySpecEntity; +import org.onap.sdc.workflow.services.ActivitySpecManager; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RequestMapping(value = "/v1.0/activity-spec") +@Api("Activity Specs") +@RestController("activitySpecController") +@Validated +public class ActivitySpecController { + + private final ActivitySpecManager activitySpecManager; + private final ActivitySpecDtoMapper activitySpecDtoMapper; + + @Autowired + public ActivitySpecController(@Qualifier("activitySpecManager") ActivitySpecManager activitySpecManager, + ActivitySpecDtoMapper activitySpecDtoMapper) { + this.activitySpecManager = activitySpecManager; + this.activitySpecDtoMapper = activitySpecDtoMapper; + } + + @GetMapping + @ApiOperation(value = "List activity specs", responseContainer = "List") + @ApiImplicitParam(name = USER_ID_HEADER, required = true, dataType = "string", paramType = "header") + public CollectionResponse list(@ApiParam(value = "List activity specs based on status filter", + allowableValues = "Draft,Certified,Deprecated,Deleted") @RequestParam(name = "status", required = false) + String versionStatus) { + return new CollectionResponse<>( + activitySpecManager.list(versionStatus).stream().map(activitySpecDtoMapper::toActivitySpecResponse) + .collect(Collectors.toList())); + } + + @PostMapping + @ApiOperation(value = "Create Activity Spec") + @ApiImplicitParam(name = USER_ID_HEADER, required = true, dataType = "string", paramType = "header") + public ResponseEntity create(@Valid @RequestBody ActivitySpecRequest request) { + ActivitySpecEntity activitySpec = + activitySpecManager.createActivitySpec(activitySpecDtoMapper.fromActivitySpecRequest(request)); + return new ResponseEntity<>(new ActivitySpecCreateResponse(activitySpec.getId(),activitySpec.getVersionId()), + HttpStatus.CREATED); + } + + @GetMapping("/{id}/versions/{versionId}") + @ApiOperation(value = "Get Activity Spec") + @ApiImplicitParam(name = USER_ID_HEADER, required = true, dataType = "string", paramType = "header") + public ActivitySpecDataResponse get(@ApiParam(value = "Activity Spec Id") @PathVariable("id") String activitySpecId, + @ApiParam(value = "Version Id", defaultValue = VERSION_ID_DEFAULT_VALUE) @PathVariable("versionId") + String versionId) { + return activitySpecDtoMapper.toActivitySpecDataResponse( + activitySpecManager.get(new ActivitySpecEntity(activitySpecId, versionId))); + } + + @PutMapping("/{id}/versions/{versionId}") + @ApiOperation(value = "Update Activity Spec") + @ApiImplicitParam(name = USER_ID_HEADER, required = true, dataType = "string", paramType = "header") + public void update(@Valid @RequestBody ActivitySpecRequest request, + @ApiParam(value = "Activity Spec Id") @PathVariable("id") String activitySpecId, + @ApiParam(value = "Version Id", defaultValue = VERSION_ID_DEFAULT_VALUE) @PathVariable("versionId") + String versionId) { + ActivitySpecEntity activitySpec = activitySpecDtoMapper.fromActivitySpecRequest(request); + activitySpec.setId(activitySpecId); + activitySpec.setVersionId(versionId); + + activitySpecManager.update(activitySpec); + } + + @PutMapping("/{id}/versions/{versionId}/actions") + @ApiOperation(value = "Actions on a activity spec", + notes = "Performs one of the following actions on a activity spec: |" + "CERTIFY: Certifies activity spec.|" + + "DEPRECATE: Deprecates activity spec.|" + "DELETE: Deletes activity spec.") + @ApiImplicitParam(name = USER_ID_HEADER, required = true, dataType = "string", paramType = "header") + public void actOn(@Valid @RequestBody ActivitySpecActionRequest request, + @ApiParam(value = "Activity Spec Id") @PathVariable("id") String activitySpecId, + @ApiParam(value = "Version Id", defaultValue = VERSION_ID_DEFAULT_VALUE) @PathVariable("versionId") + String versionId) { + activitySpecManager + .actOnAction(new ActivitySpecEntity(activitySpecId, versionId), request.getAction()); + } +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/ArtifactAssociationService.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/ArtifactAssociationService.java new file mode 100644 index 00000000..2b24577a --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/ArtifactAssociationService.java @@ -0,0 +1,235 @@ +/* + * 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; + +import static org.apache.commons.codec.digest.DigestUtils.md5Hex; + +import com.fasterxml.jackson.databind.ObjectMapper; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.nio.charset.Charset; +import java.security.GeneralSecurityException; +import java.security.KeyStore; +import java.security.cert.CertificateException; +import java.security.cert.X509Certificate; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; + +import org.apache.http.conn.ssl.TrustStrategy; +import org.openecomp.sdc.logging.api.Logger; +import org.openecomp.sdc.logging.api.LoggerFactory; + +import java.util.Base64; + +import org.apache.commons.io.IOUtils; +import org.apache.http.HttpHost; +import org.apache.http.conn.ssl.NoopHostnameVerifier; +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; +import org.apache.http.conn.ssl.TrustSelfSignedStrategy; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.ssl.SSLContexts; +import org.onap.sdc.workflow.api.types.dto.ArtifactDeliveriesRequestDto; +import org.onap.sdc.workflow.persistence.types.ArtifactEntity; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.web.client.RestTemplateBuilder; +import org.springframework.http.*; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; +import org.springframework.stereotype.Component; +import org.springframework.web.client.RestTemplate; + +import javax.net.ssl.SSLContext; + + +@Component("ArtifactAssociationHandler") +public class ArtifactAssociationService { + + private static final String WORKFLOW_ARTIFACT_TYPE = "WORKFLOW"; + private static final String WORKFLOW_ARTIFACT_DESCRIPTION = "Workflow Artifact Description"; + private static final String USER_ID_HEADER = "USER_ID"; + private static final String MD5_HEADER = "Content-MD5"; + private static final String X_ECOMP_INSTANCE_ID_HEADER = "X-ECOMP-InstanceID"; + private static final String INIT_ERROR_MSG = + "Failed while attaching workflow artifact to Operation in SDC. Parameters were not initialized: %s"; + private static final String INIT_CLIENT_MSG = + "Failed while creating the HTTP client to SDC. Following exception: %s"; + private static final Logger LOGGER = LoggerFactory.getLogger(ArtifactAssociationService.class); + @Value("${sdc.be.endpoint}") + private String sdcBeEndpoint; + @Value("${sdc.be.protocol}") + private String sdcBeProtocol; + @Value("${sdc.be.external.user}") + private String sdcUser; + @Value("${sdc.be.external.password}") + private String sdcPassword; + + private RestTemplate restClient; + + private KeyStore getKeyStore(String file, String password, String keyStoreType) throws IOException, GeneralSecurityException { + KeyStore keyStore = KeyStore.getInstance(keyStoreType); + File keyFile = new File(file); + try (FileInputStream inStr = new FileInputStream(keyFile)) { + keyStore.load(inStr, password.toCharArray()); + } + return keyStore; + + } + + + @Autowired + public ArtifactAssociationService(RestTemplateBuilder builder, + @Value("${server.ssl.trust-store}") + String truststorePath, + @Value("${server.ssl.trust-store-password}") + String truststorePassword, + @Value("${server.ssl.trust-store-type}") + String truststoreType, + @Value("${server.ssl.key-store}") + String keystorePath, + @Value("${server.ssl.key-password}") + String keystorePassword, + @Value("${server.ssl.key-store-type}") + String keystoreType, + @Value("${sdc.be.protocol}") + String protocol) { + if (protocol != null && + !protocol.equalsIgnoreCase(HttpHost.DEFAULT_SCHEME_NAME)) { + try { + KeyStore trustStore = getKeyStore(truststorePath, truststorePassword, truststoreType); + KeyStore keyStore = getKeyStore(keystorePath, keystorePassword, keystoreType); + + SSLContext sslcontext = SSLContexts.custom() + .loadKeyMaterial(keyStore, keystorePassword.toCharArray()) + .loadTrustMaterial(trustStore, new TrustSelfSignedStrategy()) + .build(); + SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory( + sslcontext, + new NoopHostnameVerifier() + ); + CloseableHttpClient httpClient = + HttpClients.custom() + .setSSLSocketFactory(sslsf) + .setSSLHostnameVerifier(new NoopHostnameVerifier()) + .build(); + HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory(httpClient); + this.restClient = new RestTemplate(factory); + } catch (Exception e) { + LOGGER.error(String.format(INIT_CLIENT_MSG, e.getMessage()), e); + } + } else { + this.restClient = builder.build(); + } + } + + void setRestClient(RestTemplate restClient) { + this.restClient = restClient; + } + + void setSdcBeEndpoint(String value) { + this.sdcBeEndpoint = value; + } + + ResponseEntity execute(String userId, ArtifactDeliveriesRequestDto deliveriesRequestDto, + ArtifactEntity artifactEntity) { + + Optional initializationState = parametersInitializationState(); + if (initializationState.isPresent()) { + LOGGER.error(String.format(INIT_ERROR_MSG, initializationState.get())); + return ResponseEntity.status(HttpStatus.EXPECTATION_FAILED).body(String.format(INIT_ERROR_MSG, initializationState.get())); + } + + String formattedArtifact; + try { + formattedArtifact = getFormattedWorkflowArtifact(artifactEntity); + } catch (IOException e) { + LOGGER.error("Failed while attaching workflow artifact to Operation in SDC", e); + return ResponseEntity.status(HttpStatus.EXPECTATION_FAILED).body(e.getMessage()); + } + + HttpEntity request = new HttpEntity<>(formattedArtifact, createHeaders(userId, formattedArtifact)); + + return restClient.exchange(sdcBeProtocol + "://" + sdcBeEndpoint + "/" + deliveriesRequestDto.getEndpoint(), + HttpMethod.valueOf(deliveriesRequestDto.getMethod()), request, String.class); + } + + Optional parametersInitializationState() { + ArrayList result = new ArrayList<>(); + if (sdcBeEndpoint == null || sdcBeEndpoint.equals("")) { + result.add("SDC_ENDPOINT"); + } + if (sdcBeProtocol == null || sdcBeProtocol.equals("")) { + result.add("SDC_PROTOCOL"); + } + if (sdcUser == null || sdcUser.equals("")) { + result.add("SDC_USER"); + } + if (sdcPassword == null || sdcPassword.equals("")) { + result.add("SDC_PASSWORD"); + } + + if (result.isEmpty() || this.restClient == null) { + return Optional.empty(); + } else { + return Optional.of(result.toString()); + } + } + + + private String getFormattedWorkflowArtifact(ArtifactEntity artifactEntity) throws IOException { + + byte[] encodeBase64 = Base64.getEncoder().encode(IOUtils.toByteArray(artifactEntity.getArtifactData())); + String encodedPayloadData = new String(encodeBase64); + + Map artifactInfo = new HashMap<>(); + artifactInfo.put("artifactName", artifactEntity.getFileName()); + artifactInfo.put("payloadData", encodedPayloadData); + artifactInfo.put("artifactType", WORKFLOW_ARTIFACT_TYPE); + artifactInfo.put("description", WORKFLOW_ARTIFACT_DESCRIPTION); + + ObjectMapper mapper = new ObjectMapper(); + return mapper.writeValueAsString(artifactInfo); + } + + private HttpHeaders createHeaders(String userId, String formattedArtifact) { + HttpHeaders headers = new HttpHeaders(); + headers.add(USER_ID_HEADER, userId); + headers.add(HttpHeaders.AUTHORIZATION, createAuthorizationsHeaderValue(sdcUser, sdcPassword)); + headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE); + headers.add(MD5_HEADER, calculateMD5Base64EncodedByString(formattedArtifact)); + headers.add(X_ECOMP_INSTANCE_ID_HEADER, "InstanceId"); + return headers; + } + + private String calculateMD5Base64EncodedByString(String data) { + String calculatedMd5 = md5Hex(data); + // encode base-64 result + byte[] encodeBase64 = Base64.getEncoder().encode(calculatedMd5.getBytes()); + return new String(encodeBase64); + } + + private String createAuthorizationsHeaderValue(String username, String password) { + String auth = username + ":" + password; + byte[] encodedAuth = Base64.getEncoder().encode(auth.getBytes(Charset.forName("US-ASCII"))); + return "Basic " + new String(encodedAuth); + } +} \ No newline at end of file diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/DisableSwaggerController.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/DisableSwaggerController.java new file mode 100644 index 00000000..12d4b06c --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/DisableSwaggerController.java @@ -0,0 +1,33 @@ +/* + * Copyright © 2019 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; + +import javax.servlet.http.HttpServletResponse; + +import org.springframework.context.annotation.Profile; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@Profile("!swagger") +@RestController +public class DisableSwaggerController { + @RequestMapping("swagger-ui.html") + public void swagger(HttpServletResponse response) { + response.setStatus(HttpStatus.NOT_FOUND.value()); + } +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/ExceptionsHandler.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/ExceptionsHandler.java new file mode 100644 index 00000000..70633d41 --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/ExceptionsHandler.java @@ -0,0 +1,119 @@ +/* + * 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; + +import static org.springframework.http.HttpStatus.BAD_REQUEST; +import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR; +import static org.springframework.http.HttpStatus.NOT_FOUND; +import static org.springframework.http.HttpStatus.UNPROCESSABLE_ENTITY; + +import java.util.function.Function; +import org.apache.commons.lang3.exception.ExceptionUtils; +import org.apache.commons.text.RandomStringGenerator; +import org.onap.sdc.workflow.api.types.ErrorResponse; +import org.onap.sdc.workflow.api.types.UnexpectedErrorResponse; +import org.onap.sdc.workflow.services.exceptions.EntityNotFoundException; +import org.onap.sdc.workflow.services.exceptions.InvalidArtifactException; +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.openecomp.sdc.logging.api.Logger; +import org.openecomp.sdc.logging.api.LoggerFactory; +import org.springframework.context.support.DefaultMessageSourceResolvable; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.MethodArgumentNotValidException; +import org.springframework.web.bind.ServletRequestBindingException; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.context.request.WebRequest; +import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; + +@ControllerAdvice +@RestController +public class ExceptionsHandler extends ResponseEntityExceptionHandler { + + private static final Logger LOG = LoggerFactory.getLogger(ExceptionsHandler.class); + + private static final String LOG_MSG = "Exception was mapped to {} response"; + private static final String UNEXPECTED_ERROR_MSG = "Something bad happened. Please contact support with code %s"; + private static final RandomStringGenerator CODE_GENERATOR = + new RandomStringGenerator.Builder().withinRange('A', 'Z').build(); + private static final int CODE_LENGTH = 8; + + private static final Function UNEXPECTED_EXCEPTION_MAPPER = + isDevInfoDisabled() + ? e -> new UnexpectedErrorResponse(getUnexpectedErrorMessage()) + : e -> new UnexpectedErrorResponse(getUnexpectedErrorMessage(), ExceptionUtils.getStackTrace(e)); + + @Override + public ResponseEntity handleServletRequestBindingException(ServletRequestBindingException ex, + HttpHeaders headers, HttpStatus status, WebRequest request) { + LOG.debug(LOG_MSG, BAD_REQUEST, ex); + // Convert Spring-generated binding exceptions into the format of an application message + return new ResponseEntity<>(new ErrorResponse(ex.getMessage()), BAD_REQUEST); + } + + @Override + protected final ResponseEntity handleMethodArgumentNotValid(final MethodArgumentNotValidException exception, + final HttpHeaders headers, final HttpStatus status, final WebRequest request) { + LOG.debug(LOG_MSG, BAD_REQUEST, exception); + String errorMsg = exception.getBindingResult().getFieldErrors().stream() + .map(DefaultMessageSourceResolvable::getDefaultMessage).findFirst() + .orElse(exception.getMessage()); + return new ResponseEntity<>(new ErrorResponse(errorMsg), BAD_REQUEST); + } + + @ExceptionHandler(EntityNotFoundException.class) + public final ResponseEntity handleNotFoundException(Exception exception) { + LOG.debug(LOG_MSG, NOT_FOUND, exception); + return new ResponseEntity<>(new ErrorResponse(exception.getMessage()), NOT_FOUND); + } + + @ExceptionHandler( + {InvalidArtifactException.class, VersionCreationException.class, VersionModificationException.class, + VersionStateModificationException.class, + VersionStateModificationMissingArtifactException.class, + VersionStatusModificationException.class, + UniqueValueViolationException.class, + WorkflowModificationException.class}) + public final ResponseEntity handleUnprocessableEntityException(Exception exception) { + LOG.debug(LOG_MSG, UNPROCESSABLE_ENTITY, exception); + return new ResponseEntity<>(new ErrorResponse(exception.getMessage()), UNPROCESSABLE_ENTITY); + } + + @ExceptionHandler(Exception.class) + public final ResponseEntity handleUnexpectedException(Exception exception) { + UnexpectedErrorResponse response = UNEXPECTED_EXCEPTION_MAPPER.apply(exception); + LOG.error(response.getMessage(), exception); + return new ResponseEntity<>(response, INTERNAL_SERVER_ERROR); + } + + private static boolean isDevInfoDisabled() { + return Boolean.FALSE.toString().equalsIgnoreCase(System.getProperty("errors.includeDevInfo")); + } + + private static String getUnexpectedErrorMessage() { + return String.format(UNEXPECTED_ERROR_MSG, CODE_GENERATOR.generate(CODE_LENGTH)); + } +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/RestParams.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/RestParams.java new file mode 100644 index 00000000..c22a0c20 --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/RestParams.java @@ -0,0 +1,28 @@ +/* + * 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; + +public class RestParams { + + private RestParams() { + } + + public static final String USER_ID_HEADER = "USER_ID"; + public static final String OFFSET = "offset"; + public static final String LIMIT = "limit"; + public static final String SORT = "sort"; +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/WorkflowController.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/WorkflowController.java new file mode 100644 index 00000000..ff06f828 --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/WorkflowController.java @@ -0,0 +1,138 @@ +/* + * 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; + +import static org.onap.sdc.workflow.api.RestParams.LIMIT; +import static org.onap.sdc.workflow.api.RestParams.OFFSET; +import static org.onap.sdc.workflow.api.RestParams.SORT; +import static org.onap.sdc.workflow.services.types.PagingConstants.DEFAULT_LIMIT; +import static org.onap.sdc.workflow.services.types.PagingConstants.DEFAULT_OFFSET; + +import io.swagger.annotations.Api; +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; +import org.onap.sdc.workflow.services.types.ArchivingStatus; +import org.onap.sdc.workflow.services.types.Page; +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.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import springfox.documentation.annotations.ApiIgnore; + +@RequestMapping("/wf/workflows") +@Api("Workflows") +@RestController("workflowController") +public class WorkflowController { + + private final WorkflowManager workflowManager; + private final WorkflowVersionManager workflowVersionManager; + + @Autowired + public WorkflowController(@Qualifier("workflowManager") WorkflowManager workflowManager, + @Qualifier("workflowVersionManager") WorkflowVersionManager workflowVersionManager) { + this.workflowManager = workflowManager; + this.workflowVersionManager = workflowVersionManager; + } + + @GetMapping(produces = MediaType.APPLICATION_JSON_VALUE) + @ApiOperation("List workflows") + @ApiImplicitParams({@ApiImplicitParam(name = "versionState", dataType = "string", paramType = "query", + allowableValues = "DRAFT,CERTIFIED", value = "Filter by version state"), + @ApiImplicitParam(name = OFFSET, dataType = "string", paramType = "query", defaultValue = "0", + value = "Index of the starting item"), + @ApiImplicitParam(name = LIMIT, dataType = "string", paramType = "query", defaultValue = "200", + value = "Number of returned items"), + @ApiImplicitParam(name = SORT, dataType = "string", paramType = "query", defaultValue = "name:asc", + 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"), + @ApiImplicitParam(name = "archiving", dataType = "string", paramType = "query", + allowableValues = "ACTIVE,ARCHIVED", value = "Filter by workflow status")}) + public Page list(@ApiIgnore String archiving, @ApiIgnore String searchNameFilter, + @ApiIgnore VersionStatesFormatter versionStateFilter, @ApiIgnore Paging paging, + @ApiIgnore Sorting sorting, @UserId String user) { + return workflowManager.list(archiving, searchNameFilter, versionStateFilter.getVersionStates(), initRequestSpec(paging, sorting)); + } + + @PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE) + @ApiOperation("Create workflow") + public ResponseEntity create(@Validated @RequestBody Workflow workflow, @UserId String user) { + return new ResponseEntity<>(workflowManager.create(workflow), HttpStatus.CREATED); + } + + @GetMapping(path = "/{workflowId}") + @ApiOperation("Get workflow") + public Workflow get(@PathVariable("workflowId") String workflowId, + @ApiParam(value = "Expand workflow data", allowableValues = "versions") + @RequestParam(value = "expand", required = false) String expand, @UserId String user) { + Workflow workflow = new Workflow(); + workflow.setId(workflowId); + Workflow retrievedWorkflow = workflowManager.get(workflow); + if ("versions".equals(expand)) { + retrievedWorkflow.setVersions(workflowVersionManager.list(workflowId, null)); + } + return retrievedWorkflow; + } + + @PutMapping(path = "/{workflowId}", consumes = MediaType.APPLICATION_JSON_VALUE) + @ApiOperation("Update workflow") + public Workflow update(@RequestBody Workflow workflow, @PathVariable("workflowId") String workflowId, + @UserId String user) { + workflow.setId(workflowId); + workflowManager.update(workflow); + 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, ArchivingStatus.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()), + SortingRequest.builder().sorts(sorting.getSorts()).build()); + } +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/WorkflowVersionController.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/WorkflowVersionController.java new file mode 100644 index 00000000..213cd713 --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/WorkflowVersionController.java @@ -0,0 +1,161 @@ +/* + * 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; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiOperation; +import java.util.stream.Collectors; +import javax.validation.Valid; +import org.onap.sdc.workflow.api.mappers.WorkflowVersionDtoMapper; +import org.onap.sdc.workflow.api.types.CollectionResponse; +import org.onap.sdc.workflow.api.types.VersionStateDto; +import org.onap.sdc.workflow.api.types.VersionStatesFormatter; +import org.onap.sdc.workflow.api.types.WorkflowVersionRequest; +import org.onap.sdc.workflow.api.types.WorkflowVersionResponse; +import org.onap.sdc.workflow.api.types.dto.ArtifactDeliveriesRequestDto; +import org.onap.sdc.workflow.persistence.types.ArtifactEntity; +import org.onap.sdc.workflow.services.WorkflowVersionManager; +import org.onap.sdc.workflow.services.annotations.UserId; +import org.onap.sdc.workflow.services.types.WorkflowVersion; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.core.io.InputStreamResource; +import org.springframework.core.io.Resource; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; +import springfox.documentation.annotations.ApiIgnore; + +@RequestMapping("/wf/workflows/{workflowId}/versions") +@Api("Workflow versions") +@RestController("workflowsVersionController") +public class WorkflowVersionController { + + private final WorkflowVersionManager versionManager; + private final WorkflowVersionDtoMapper versionDtoMapper; + private final ArtifactAssociationService associationHandler; + + @Autowired + public WorkflowVersionController(@Qualifier("workflowVersionManager") WorkflowVersionManager versionManager, + WorkflowVersionDtoMapper versionDtoMapper, + @Qualifier("ArtifactAssociationHandler") ArtifactAssociationService artifactAssociationHandler) { + this.versionManager = versionManager; + this.versionDtoMapper = versionDtoMapper; + this.associationHandler = artifactAssociationHandler; + } + + @GetMapping + @ApiOperation("List workflow versions") + @ApiImplicitParam(name = "state", dataType = "string", paramType = "query", allowableValues = "DRAFT,CERTIFIED", + value = "Filter by state") + public CollectionResponse list(@PathVariable("workflowId") String workflowId, + @ApiIgnore VersionStatesFormatter stateFilter, @UserId String user) { + return new CollectionResponse<>(versionManager.list(workflowId, stateFilter.getVersionStates()).stream() + .map(versionDtoMapper::workflowVersionToResponse) + .collect(Collectors.toList())); + } + + @PostMapping + @ApiOperation("Create workflow version") + public ResponseEntity create(@RequestBody @Valid WorkflowVersionRequest request, + @PathVariable("workflowId") String workflowId, + @RequestParam(value = "baseVersionId", required = false) String baseVersionId, @UserId String user) { + WorkflowVersionResponse createdVersion = versionDtoMapper.workflowVersionToResponse( + versionManager.create(workflowId, baseVersionId, versionDtoMapper.requestToWorkflowVersion(request))); + return new ResponseEntity<>(createdVersion, HttpStatus.CREATED); + } + + @GetMapping("/{versionId}") + @ApiOperation("Get workflow version") + public WorkflowVersionResponse get(@PathVariable("workflowId") String workflowId, + @PathVariable("versionId") String versionId, @UserId String user) { + return versionDtoMapper.workflowVersionToResponse(versionManager.get(workflowId, versionId)); + } + + @PutMapping("/{versionId}") + @ApiOperation("Update workflow version") + public void update(@RequestBody @Valid WorkflowVersionRequest request, + @PathVariable("workflowId") String workflowId, @PathVariable("versionId") String versionId, + @UserId String user) { + WorkflowVersion version = versionDtoMapper.requestToWorkflowVersion(request); + version.setId(versionId); + versionManager.update(workflowId, version); + } + + @GetMapping("/{versionId}/state") + @ApiOperation("Get workflow version state") + public VersionStateDto getState(@PathVariable("workflowId") String workflowId, + @PathVariable("versionId") String versionId, @UserId String user) { + return new VersionStateDto(versionManager.getState(workflowId, versionId)); + } + + @PostMapping("/{versionId}/state") + @ApiOperation("Update workflow version state") + public VersionStateDto updateState(@RequestBody VersionStateDto state, + @PathVariable("workflowId") String workflowId, @PathVariable("versionId") String versionId, + @UserId String user) { + versionManager.updateState(workflowId, versionId, state.getName()); + return new VersionStateDto(state.getName()); + } + + @PostMapping("/{versionId}/artifact-deliveries") + @ApiOperation("upload of artifact to VF operation workflow") + public ResponseEntity artifactDeliveries(@RequestBody ArtifactDeliveriesRequestDto deliveriesRequestDto, + @PathVariable("workflowId") String workflowId, @PathVariable("versionId") String versionId, + @UserId String user) { + return associationHandler + .execute(user, deliveriesRequestDto, versionManager.getArtifact(workflowId, versionId)); + } + + @PutMapping("/{versionId}/artifact") + @ApiOperation("Create/update artifact of a version") + public void uploadArtifact(@RequestBody MultipartFile fileToUpload, @PathVariable("workflowId") String workflowId, + @PathVariable("versionId") String versionId, @UserId String user) { + versionManager.uploadArtifact(workflowId, versionId, fileToUpload); + } + + @GetMapping("/{versionId}/artifact") + @ApiOperation("Download workflow version artifact") + public ResponseEntity getArtifact(@PathVariable("workflowId") String workflowId, + @PathVariable("versionId") String versionId, @UserId String user) { + ArtifactEntity artifact = versionManager.getArtifact(workflowId, versionId); + + return ResponseEntity.ok() + .header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + artifact.getFileName()) + .contentType(MediaType.APPLICATION_OCTET_STREAM) + .body(new InputStreamResource(artifact.getArtifactData())); + } + + @DeleteMapping("/{versionId}/artifact") + @ApiOperation("Delete workflow version artifact") + public void deleteArtifact(@PathVariable("workflowId") String workflowId, + @PathVariable("versionId") String versionId, @UserId String user) { + versionManager.deleteArtifact(workflowId, versionId); + } +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/mappers/ActivitySpecDtoMapper.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/mappers/ActivitySpecDtoMapper.java new file mode 100644 index 00000000..cea7c878 --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/mappers/ActivitySpecDtoMapper.java @@ -0,0 +1,34 @@ +/* + * 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.mappers; + +import org.mapstruct.Mapper; +import org.onap.sdc.workflow.api.types.activityspec.ActivitySpecDataResponse; +import org.onap.sdc.workflow.api.types.activityspec.ActivitySpecRequest; +import org.onap.sdc.workflow.api.types.activityspec.ActivitySpecResponse; +import org.onap.sdc.workflow.persistence.types.ActivitySpecEntity; + +@Mapper(componentModel = "spring") +public interface ActivitySpecDtoMapper { + + ActivitySpecResponse toActivitySpecResponse(ActivitySpecEntity activitySpec); + + ActivitySpecDataResponse toActivitySpecDataResponse(ActivitySpecEntity activitySpec); + + ActivitySpecEntity fromActivitySpecRequest(ActivitySpecRequest request); + +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/mappers/WorkflowVersionDtoMapper.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/mappers/WorkflowVersionDtoMapper.java new file mode 100644 index 00000000..120b0d23 --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/mappers/WorkflowVersionDtoMapper.java @@ -0,0 +1,31 @@ +/* + * Copyright © 2016-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.mappers; + +import org.mapstruct.Mapper; +import org.onap.sdc.workflow.api.types.WorkflowVersionRequest; +import org.onap.sdc.workflow.api.types.WorkflowVersionResponse; +import org.onap.sdc.workflow.services.types.WorkflowVersion; + +@Mapper(componentModel = "spring") +public interface WorkflowVersionDtoMapper { + + WorkflowVersion requestToWorkflowVersion(WorkflowVersionRequest request); + + WorkflowVersionResponse workflowVersionToResponse(WorkflowVersion workflowVersion); + +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/swagger/UserIdReader.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/swagger/UserIdReader.java new file mode 100644 index 00000000..d16c9407 --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/swagger/UserIdReader.java @@ -0,0 +1,61 @@ +/* + * 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.swagger; + +import static org.onap.sdc.workflow.api.RestParams.USER_ID_HEADER; + +import com.fasterxml.classmate.TypeResolver; +import com.google.common.base.Optional; +import org.onap.sdc.workflow.services.annotations.UserId; +import org.springframework.core.annotation.Order; +import org.springframework.stereotype.Component; +import springfox.documentation.service.ResolvedMethodParameter; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spi.service.ParameterBuilderPlugin; +import springfox.documentation.spi.service.contexts.ParameterContext; +import springfox.documentation.swagger.common.SwaggerPluginSupport; + +/** + * This component is neccesary because swagger cannot find a custom annotations in API. + * This is needed to find specifically the {@link UserId} annotation + */ +@Component +@Order(SwaggerPluginSupport.SWAGGER_PLUGIN_ORDER + 1000) +public class UserIdReader implements ParameterBuilderPlugin { + + private static final String HEADER = "header"; + private final TypeResolver resolver; + + public UserIdReader(TypeResolver resolver) { + this.resolver = resolver; + } + + @Override + public void apply(ParameterContext parameterContext) { + ResolvedMethodParameter methodParameter = parameterContext.resolvedMethodParameter(); + Optional requestParam = methodParameter.findAnnotation(UserId.class); + if (requestParam.isPresent()) { + parameterContext.parameterBuilder().parameterType(HEADER).name(USER_ID_HEADER) + .type(resolver.resolve(String.class)); + } + } + + @Override + public boolean supports(DocumentationType documentationType) { + return true; + } +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/CollectionResponse.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/CollectionResponse.java new file mode 100644 index 00000000..1734dd6c --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/CollectionResponse.java @@ -0,0 +1,32 @@ +/* + * 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 java.util.Collection; +import lombok.Data; + +@Data +public class CollectionResponse { + + private int total; + private Collection items; + + public CollectionResponse(Collection items) { + this.items = items; + this.total = items.size(); + } +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/ErrorResponse.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/ErrorResponse.java new file mode 100644 index 00000000..45f54341 --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/ErrorResponse.java @@ -0,0 +1,27 @@ +/* + * 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.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public class ErrorResponse { + + private String message; +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/Paging.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/Paging.java new file mode 100644 index 00000000..7e47f6d6 --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/Paging.java @@ -0,0 +1,50 @@ +/* + * 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 static org.onap.sdc.workflow.services.types.PagingConstants.MAX_LIMIT; + +import java.util.Optional; +import lombok.Getter; + +@Getter +public class Paging { + + private Integer offset; + private Integer limit; + + public void setOffset(String offset) { + getIntValue(offset).ifPresent(integer -> this.offset = integer); + } + + public void setLimit(String limit) { + getIntValue(limit).map(integer -> integer > MAX_LIMIT ? MAX_LIMIT : integer).ifPresent(integer -> { + if (integer != 0) { + this.limit = integer; + } + }); + } + + private static Optional getIntValue(String value) { + try { + int intValue = Integer.parseInt(value); + return intValue < 0 ? Optional.empty() : Optional.of(intValue); + } catch (NumberFormatException e) { + return Optional.empty(); + } + } +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/Parameter.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/Parameter.java new file mode 100644 index 00000000..f5bbecec --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/Parameter.java @@ -0,0 +1,34 @@ +/* + * Copyright © 2016-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 javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Pattern; +import lombok.Data; +import org.onap.sdc.workflow.persistence.types.ParameterType; + +@Data +public class Parameter { + @NotBlank(message = "Parameter Name may not be blank") + @Pattern(regexp = "[A-Za-z0-9_ ]+", message = "Parameter name must contain only letters, digits and underscores") + private String name; + @NotNull + private ParameterType type; + @NotNull + private boolean mandatory; +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/Sorting.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/Sorting.java new file mode 100644 index 00000000..38b579b2 --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/Sorting.java @@ -0,0 +1,66 @@ +/* + * 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 java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; +import lombok.Getter; +import org.onap.sdc.workflow.services.types.Sort; +import org.openecomp.sdc.logging.api.Logger; +import org.openecomp.sdc.logging.api.LoggerFactory; + +@Getter +public class Sorting { + + private static final String SORTS_DELIMITER = ","; + private static final String DIRECTION_DELIMITER = ":"; + private static final String ASC = "asc"; + private static final String DESC = "desc"; + private static final Logger LOGGER = LoggerFactory.getLogger(Sorting.class); + + private List sorts = Collections.emptyList(); + + public void setSort(String sortString) { + this.sorts = Arrays.stream(sortString.split(SORTS_DELIMITER)) + .map(Sorting::formatSort) + .filter(Objects::nonNull) + .collect(Collectors.toList()); + } + + private static Sort formatSort(String sort) { + String[] tokens = sort.split(DIRECTION_DELIMITER, 2); + + return tokens.length == 2 + ? formatSingleSort(tokens[0], tokens[1]) + : new Sort(tokens[0], true); + } + + private static Sort formatSingleSort(String property, String direction) { + if (ASC.equalsIgnoreCase(direction)) { + return new Sort(property, true); + } + if (DESC.equalsIgnoreCase(direction)) { + return new Sort(property, false); + } + LOGGER.warn("Sorting direction {} of property {} is invalid. Allowed direction values: asc, desc.", direction, + property); + return null; + } +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/UnexpectedErrorResponse.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/UnexpectedErrorResponse.java new file mode 100644 index 00000000..8cf513a2 --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/UnexpectedErrorResponse.java @@ -0,0 +1,34 @@ +/* + * 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.Getter; + +@Getter +public class UnexpectedErrorResponse extends ErrorResponse { + + private String devInfo; + + public UnexpectedErrorResponse(String message) { + super(message); + } + + public UnexpectedErrorResponse(String message, String devInfo) { + super(message); + this.devInfo = devInfo; + } +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/VersionStateDto.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/VersionStateDto.java new file mode 100644 index 00000000..8e6dd09f --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/VersionStateDto.java @@ -0,0 +1,35 @@ +/* + * 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 java.util.List; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.onap.sdc.workflow.services.types.WorkflowVersionState; + +@Data +@NoArgsConstructor +public class VersionStateDto { + + private WorkflowVersionState name; + private List nextStates; + + public VersionStateDto(WorkflowVersionState state) { + name = state; + nextStates = state.getNextStates(); + } +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/VersionStatesFormatter.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/VersionStatesFormatter.java new file mode 100644 index 00000000..cc17f928 --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/VersionStatesFormatter.java @@ -0,0 +1,53 @@ +/* + * 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 java.util.Arrays; +import java.util.Collections; +import java.util.Set; +import java.util.stream.Collectors; +import lombok.Getter; +import org.onap.sdc.workflow.services.types.WorkflowVersionState; +import org.openecomp.sdc.logging.api.Logger; +import org.openecomp.sdc.logging.api.LoggerFactory; + +@Getter +public class VersionStatesFormatter { + + private static final Logger LOGGER = LoggerFactory.getLogger(VersionStatesFormatter.class); + + private Set versionStates = null; + + public void setVersionState(String value) { + this.versionStates = formatString(value); + } + + public void setState(String value) { + setVersionState(value); + } + + private static Set formatString(String value) { + try { + return value == null ? null : Arrays.stream(value.split(",")).map(WorkflowVersionState::valueOf) + .collect(Collectors.toSet()); + } catch (IllegalArgumentException ex) { + LOGGER.warn("value {} is invalid and cannot be formatted to a set of version states, " + + "therefore it set to empty set", value, ex); + return Collections.emptySet(); + } + } +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/WorkflowStatusDto.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/WorkflowStatusDto.java new file mode 100644 index 00000000..6e5ab1cf --- /dev/null +++ b/sdc-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/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/WorkflowVersionRequest.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/WorkflowVersionRequest.java new file mode 100644 index 00000000..090f129a --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/WorkflowVersionRequest.java @@ -0,0 +1,36 @@ +/* + * Copyright © 2016-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 java.util.Collection; +import java.util.Collections; +import javax.validation.Valid; +import lombok.Data; +import org.onap.sdc.workflow.api.validation.NoDuplicates; + +@Data +public class WorkflowVersionRequest { + + private String name; + private String description; + @Valid + @NoDuplicates(message = "Inputs names must be unique") + private Collection inputs = Collections.emptyList(); + @Valid + @NoDuplicates(message = "Outputs names must be unique") + private Collection outputs = Collections.emptyList(); +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/WorkflowVersionResponse.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/WorkflowVersionResponse.java new file mode 100644 index 00000000..460d3d63 --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/WorkflowVersionResponse.java @@ -0,0 +1,34 @@ +/* + * Copyright © 2016-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 java.util.Date; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.onap.sdc.workflow.services.types.WorkflowVersionState; + +@EqualsAndHashCode(callSuper = true) +@Data +public class WorkflowVersionResponse extends WorkflowVersionRequest { + + private String id; + private String baseId; + private WorkflowVersionState state; + private boolean hasArtifact; + private Date creationTime; + private Date modificationTime; +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/activityspec/ActivitySpecAction.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/activityspec/ActivitySpecAction.java new file mode 100644 index 00000000..87a97fff --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/activityspec/ActivitySpecAction.java @@ -0,0 +1,21 @@ +/* + * Copyright © 2016-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.activityspec; + +public enum ActivitySpecAction { + CERTIFY, DEPRECATE, DELETE +} \ No newline at end of file diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/activityspec/ActivitySpecActionRequest.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/activityspec/ActivitySpecActionRequest.java new file mode 100644 index 00000000..8b469da4 --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/activityspec/ActivitySpecActionRequest.java @@ -0,0 +1,26 @@ +/* + * Copyright © 2016-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.activityspec; + +import javax.validation.constraints.NotNull; + +@lombok.Data +public class ActivitySpecActionRequest { + + @NotNull + private ActivitySpecAction action; +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/activityspec/ActivitySpecBase.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/activityspec/ActivitySpecBase.java new file mode 100644 index 00000000..cf494c20 --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/activityspec/ActivitySpecBase.java @@ -0,0 +1,31 @@ +/* + * Copyright © 2016-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.activityspec; + +import java.util.List; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.Pattern; +import lombok.Data; + +@Data +abstract class ActivitySpecBase { + + @NotBlank(message = "Mandatory name field is missing") + @Pattern(regexp = "^[a-zA-Z0-9-]*$", message = "name should match with \"^[a-zA-Z0-9-]*$\" pattern") + private String name; + private List categoryList; +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/activityspec/ActivitySpecCreateResponse.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/activityspec/ActivitySpecCreateResponse.java new file mode 100644 index 00000000..895c74e8 --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/activityspec/ActivitySpecCreateResponse.java @@ -0,0 +1,29 @@ +/* + * Copyright © 2016-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.activityspec; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public class ActivitySpecCreateResponse { + + private String id; + private String versionId; +} + diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/activityspec/ActivitySpecDataResponse.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/activityspec/ActivitySpecDataResponse.java new file mode 100644 index 00000000..d4b1003f --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/activityspec/ActivitySpecDataResponse.java @@ -0,0 +1,27 @@ +/* + * Copyright © 2016-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.activityspec; + +import lombok.EqualsAndHashCode; + +@lombok.Data +@EqualsAndHashCode(callSuper = true) +public class ActivitySpecDataResponse extends ActivitySpecRequest { + + private String id; + private String status; +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/activityspec/ActivitySpecRequest.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/activityspec/ActivitySpecRequest.java new file mode 100644 index 00000000..972e99cc --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/activityspec/ActivitySpecRequest.java @@ -0,0 +1,37 @@ +/* + * Copyright © 2016-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.activityspec; + +import io.swagger.annotations.ApiModel; +import java.util.List; +import javax.validation.Valid; +import lombok.EqualsAndHashCode; +import org.onap.sdc.workflow.persistence.types.ActivitySpecParameter; + +@ApiModel(value = "ActivitySpecRequest") +@lombok.Data +@EqualsAndHashCode(callSuper = true) +public class ActivitySpecRequest extends ActivitySpecBase { + + private String description; + @Valid + private List inputs; + @Valid + private List outputs; + private String type; + private String content; +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/activityspec/ActivitySpecResponse.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/activityspec/ActivitySpecResponse.java new file mode 100644 index 00000000..a061b3fd --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/activityspec/ActivitySpecResponse.java @@ -0,0 +1,27 @@ +/* + * Copyright © 2016-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.activityspec; + +import lombok.EqualsAndHashCode; + +@lombok.Data +@EqualsAndHashCode(callSuper = true) +public class ActivitySpecResponse extends ActivitySpecBase { + + private String id; + private String status; +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/dto/ArtifactDeliveriesRequestDto.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/dto/ArtifactDeliveriesRequestDto.java new file mode 100644 index 00000000..5ec54ffb --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/types/dto/ArtifactDeliveriesRequestDto.java @@ -0,0 +1,41 @@ +/* + * 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.dto; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * This class is a simple data object for the Artifact-Deliveries API. + * It will be used to build a HTTP request to be sent to SDC external API. + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class ArtifactDeliveriesRequestDto { + + /** + * The HTTP method (PUT, POST etc) that will be executed. + */ + private String method; + + /** + * The server to which the request will be sent. Correct format is <IP>:<PORT>. + */ + private String endpoint; +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/validation/ActivitySpecParameterNameValidator.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/validation/ActivitySpecParameterNameValidator.java new file mode 100644 index 00000000..06818c9d --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/validation/ActivitySpecParameterNameValidator.java @@ -0,0 +1,65 @@ +/* + * 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.util.Objects; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; +import org.onap.sdc.workflow.persistence.types.ActivitySpecParameter; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +@Component("ActivitySpecParameterNameValidator") +public class ActivitySpecParameterNameValidator implements ConstraintValidator { + + private String validationRegex; + private static final String defaultValidationRegex = "^\\S*$"; + private String validationMessage; + private static final String defaultValidationMessage = "Input and Output names must not contain any spaces"; + + @Override + public boolean isValid(ActivitySpecParameter parameter, ConstraintValidatorContext context) { + Pattern pattern = Pattern.compile(validationRegex); + Matcher matcher = pattern.matcher(parameter.getName()); + boolean isValid = matcher.find(); + if (!isValid) { + context.disableDefaultConstraintViolation(); + context.buildConstraintViolationWithTemplate(validationMessage).addConstraintViolation(); + } + return isValid; + } + + @Value("${activitySpec.parameterName.validation:" + defaultValidationRegex + "}") + void setValidationRegex(String regex) { + if (Objects.isNull(regex) || regex.equals("")) { + Objects.requireNonNull(regex); + } else { + validationRegex = regex; + } + } + + @Value("${activitySpec.parameterName.validationMessage:" + defaultValidationMessage + "}") + void setValidationMessage(String message) { + if (Objects.isNull(message) || message.equals("")) { + Objects.requireNonNull(message); + } else { + validationMessage = message; + } + } +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/validation/ArchivingStatusValidator.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/validation/ArchivingStatusValidator.java new file mode 100644 index 00000000..bfbf7580 --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/validation/ArchivingStatusValidator.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.ArchivingStatus; + +public class ArchivingStatusValidator implements ConstraintValidator { + + @Override + public boolean isValid(String value, ConstraintValidatorContext context) { + if (value == null) { + return false; + } else { + try { + Enum.valueOf(ArchivingStatus.class, value); + return true; + } catch (IllegalArgumentException var3) { + return false; + } + } + } +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/validation/NoDuplicates.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/validation/NoDuplicates.java new file mode 100644 index 00000000..296e4387 --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/validation/NoDuplicates.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 = {NoDuplicatesValidator.class}) +public @interface NoDuplicates { + + String message(); + + Class[] groups() default {}; + + Class[] payload() default {}; +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/validation/NoDuplicatesValidator.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/validation/NoDuplicatesValidator.java new file mode 100644 index 00000000..7ade1ab0 --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/validation/NoDuplicatesValidator.java @@ -0,0 +1,37 @@ +/* + * 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.util.Collection; +import java.util.HashSet; +import java.util.Objects; +import java.util.Set; +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; +import org.onap.sdc.workflow.api.types.Parameter; + +public class NoDuplicatesValidator implements ConstraintValidator> { + + @Override + public boolean isValid(Collection parameters, ConstraintValidatorContext context) { + if (Objects.isNull(parameters) || parameters.size() < 2) { + return true; + } + Set testSet = new HashSet<>(); + return parameters.stream().allMatch(parameter -> testSet.add(parameter.getName())); + } +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/validation/ValidName.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/validation/ValidName.java new file mode 100644 index 00000000..2d90aeba --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/validation/ValidName.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 = {ActivitySpecParameterNameValidator.class}) +public @interface ValidName { + + String message() default ""; + + Class[] groups() default {}; + + Class[] payload() default {}; +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/validation/ValidStatus.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/validation/ValidStatus.java new file mode 100644 index 00000000..15778b1d --- /dev/null +++ b/sdc-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 = {ArchivingStatusValidator.class}) +public @interface ValidStatus { + + String message(); + + Class[] groups() default {}; + + Class[] payload() default {}; +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/ActivitySpecRepository.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/ActivitySpecRepository.java new file mode 100644 index 00000000..f8f1d9a9 --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/ActivitySpecRepository.java @@ -0,0 +1,28 @@ +/* + * Copyright © 2016-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.persistence; + +import org.onap.sdc.workflow.persistence.types.ActivitySpecEntity; + +public interface ActivitySpecRepository { + + void create(ActivitySpecEntity activitySpec); + + ActivitySpecEntity get(ActivitySpecEntity activitySpec); + + void update(ActivitySpecEntity activitySpec); +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/ArtifactRepository.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/ArtifactRepository.java new file mode 100644 index 00000000..e10279fe --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/ArtifactRepository.java @@ -0,0 +1,36 @@ +/* + * 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.persistence; + + +import java.util.Optional; +import org.onap.sdc.workflow.persistence.types.ArtifactEntity; + + +public interface ArtifactRepository { + + void update(String workflowId, String versionId,ArtifactEntity artifactEntity); + + Optional get(String workflowId, String versionId); + + boolean isExist(String workflowId, String versionId); + + void createStructure(String workflowId, String versionId); + + void delete(String workflowId, String versionId); + +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/ParameterRepository.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/ParameterRepository.java new file mode 100644 index 00000000..9f7fb1ad --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/ParameterRepository.java @@ -0,0 +1,39 @@ +/* + * 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.persistence; + +import java.util.Collection; +import org.onap.sdc.workflow.persistence.types.ParameterEntity; +import org.onap.sdc.workflow.persistence.types.ParameterRole; + + +public interface ParameterRepository { + + void createStructure(String id, String versionId); + + Collection list(String id, String versionId, ParameterRole role); + + void deleteAll(String id, String versionId, ParameterRole role); + + ParameterEntity get(String id, String versionId, String parameterId); + + void delete(String id, String versionId, String parameterId); + + ParameterEntity create(String id, String versionId , ParameterRole role, ParameterEntity parameter); + + void update(String id, String versionId, ParameterRole role, ParameterEntity parameter); +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/UniqueValueRepository.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/UniqueValueRepository.java new file mode 100644 index 00000000..cf7b0633 --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/UniqueValueRepository.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.persistence; + +import org.onap.sdc.workflow.persistence.types.UniqueValueEntity; +import org.springframework.data.cassandra.repository.CassandraRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface UniqueValueRepository extends CassandraRepository { + +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/ActivitySpecRepositoryImpl.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/ActivitySpecRepositoryImpl.java new file mode 100644 index 00000000..b304f900 --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/ActivitySpecRepositoryImpl.java @@ -0,0 +1,141 @@ +/* + * Copyright © 2016-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.persistence.impl; + +import static org.onap.sdc.common.zusammen.services.ZusammenElementUtil.buildStructuralElement; + +import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element; +import com.amdocs.zusammen.adaptor.inbound.api.types.item.ZusammenElement; +import com.amdocs.zusammen.datatypes.item.Action; +import com.amdocs.zusammen.datatypes.item.ElementContext; +import com.amdocs.zusammen.datatypes.item.Info; +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.util.Objects; +import java.util.Optional; +import org.onap.sdc.common.versioning.persistence.zusammen.ZusammenSessionContextCreator; +import org.onap.sdc.common.zusammen.services.ZusammenAdaptor; +import org.onap.sdc.workflow.persistence.ActivitySpecRepository; +import org.onap.sdc.workflow.persistence.impl.types.ActivitySpecData; +import org.onap.sdc.workflow.persistence.impl.types.ActivitySpecElementType; +import org.onap.sdc.workflow.persistence.types.ActivitySpecEntity; +import org.onap.sdc.workflow.services.ActivitySpecConstant; +import org.onap.sdc.workflow.services.utilities.JsonUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; + +@Repository +public class ActivitySpecRepositoryImpl implements ActivitySpecRepository { + + private final ZusammenAdaptor zusammenAdaptor; + private final ZusammenSessionContextCreator contextCreator; + + @Autowired + public ActivitySpecRepositoryImpl(ZusammenAdaptor zusammenAdaptor, ZusammenSessionContextCreator contextCreator) { + this.zusammenAdaptor = zusammenAdaptor; + this.contextCreator = contextCreator; + } + + @Override + public void create(ActivitySpecEntity activitySpec) { + ZusammenElement generalElement = mapActivityDetailsToZusammenElement(activitySpec, Action.CREATE); + + ElementContext elementContext = new ElementContext(activitySpec.getId(), activitySpec.getVersionId()); + zusammenAdaptor + .saveElement(contextCreator.create(), elementContext, generalElement, "Create Activity Spec General Info Element"); + } + + @Override + public ActivitySpecEntity get(ActivitySpecEntity entity) { + ElementContext elementContext = new ElementContext(entity.getId(), entity.getVersionId()); + Optional element = + zusammenAdaptor.getElementByName(contextCreator.create(), elementContext, null, ActivitySpecElementType.ACTIVITYSPEC.name()); + return element.map(this::mapZusammenElementToActivityDetails).orElse(null); + } + + @Override + public void update(ActivitySpecEntity entity) { + + ZusammenElement generalElement = mapActivityDetailsToZusammenElement(entity, Action.UPDATE); + + ElementContext elementContext = new ElementContext(entity.getId(), entity.getVersionId()); + zusammenAdaptor + .saveElement(contextCreator.create(), elementContext, generalElement, "Update Activity Spec General Info Element"); + } + + private ZusammenElement mapActivityDetailsToZusammenElement(ActivitySpecEntity entity, Action action) { + ZusammenElement generalElement = buildStructuralElement(ActivitySpecElementType.ACTIVITYSPEC.name(), action); + + enrichElementInfoFromEntity(generalElement, entity); + enrichElementDataFromEntity(generalElement, entity); + return generalElement; + } + + private void enrichElementInfoFromEntity(ZusammenElement element, ActivitySpecEntity entity) { + element.getInfo().addProperty(InfoPropertyName.DESCRIPTION.getValue(), entity.getDescription()); + element.getInfo().addProperty(InfoPropertyName.NAME.getValue(), entity.getName()); + element.getInfo().addProperty(InfoPropertyName.CATEGORY.getValue(), entity.getCategoryList()); + } + + private void enrichElementDataFromEntity(ZusammenElement element, ActivitySpecEntity entity) { + ActivitySpecData activitySpecData = new ActivitySpecData(); + activitySpecData.setInputs(entity.getInputs()); + activitySpecData.setOutputs(entity.getOutputs()); + activitySpecData.setType(entity.getType()); + activitySpecData.setContent(entity.getContent()); + element.setData(new ByteArrayInputStream(JsonUtil.object2Json(activitySpecData).getBytes())); + } + + private ActivitySpecEntity mapZusammenElementToActivityDetails(Element element) { + ActivitySpecEntity entity = new ActivitySpecEntity(); + entity.setId(element.getElementId().getValue()); + enrichEntityFromElementData(entity, element.getData()); + enrichEntityFromElementInfo(entity, element.getInfo()); + return entity; + } + + private void enrichEntityFromElementData(ActivitySpecEntity entity, InputStream data) { + ActivitySpecData activitySpecData = JsonUtil.json2Object(data, ActivitySpecData.class); + if (Objects.nonNull(activitySpecData)) { + entity.setInputs(activitySpecData.getInputs()); + entity.setOutputs(activitySpecData.getOutputs()); + entity.setType(activitySpecData.getType()); + entity.setContent(activitySpecData.getContent()); + } + } + + private void enrichEntityFromElementInfo(ActivitySpecEntity entity, Info info) { + entity.setName(info.getProperty(InfoPropertyName.NAME.getValue())); + entity.setDescription(info.getProperty(InfoPropertyName.DESCRIPTION.getValue())); + entity.setCategoryList(info.getProperty(InfoPropertyName.CATEGORY.getValue())); + } + + public enum InfoPropertyName { + DESCRIPTION("description"), NAME("name"), CATEGORY(ActivitySpecConstant.CATEGORY_ATTRIBUTE_NAME); + + private final String value; + + InfoPropertyName(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + } + +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/ArtifactRepositoryImpl.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/ArtifactRepositoryImpl.java new file mode 100644 index 00000000..4ad54614 --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/ArtifactRepositoryImpl.java @@ -0,0 +1,136 @@ +/* + * 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.persistence.impl; + +import static org.onap.sdc.common.zusammen.services.ZusammenElementUtil.buildStructuralElement; + +import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element; +import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementInfo; +import com.amdocs.zusammen.adaptor.inbound.api.types.item.ZusammenElement; +import com.amdocs.zusammen.datatypes.item.Action; +import com.amdocs.zusammen.datatypes.item.ElementContext; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Arrays; +import java.util.Optional; +import org.apache.commons.io.IOUtils; +import org.onap.sdc.common.versioning.persistence.zusammen.ZusammenSessionContextCreator; +import org.onap.sdc.common.zusammen.services.ZusammenAdaptor; +import org.onap.sdc.workflow.persistence.ArtifactRepository; +import org.onap.sdc.workflow.persistence.impl.types.WorkflowElementType; +import org.onap.sdc.workflow.persistence.types.ArtifactEntity; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; + +@Repository +public class ArtifactRepositoryImpl implements ArtifactRepository { + + private static final String FILE_NAME_PROPERTY = "fileName"; + private static final String EMPTY_DATA = "{}"; + + private final ZusammenAdaptor zusammenAdaptor; + private final ZusammenSessionContextCreator contextCreator; + + @Autowired + public ArtifactRepositoryImpl(ZusammenAdaptor zusammenAdaptor, ZusammenSessionContextCreator contextCreator) { + this.zusammenAdaptor = zusammenAdaptor; + this.contextCreator = contextCreator; + } + + @Override + public void update(String workflowId, String versionId, ArtifactEntity artifactEntity) { + + ZusammenElement artifactElement = buildStructuralElement(WorkflowElementType.ARTIFACT.name(), Action.UPDATE); + artifactElement.setData(artifactEntity.getArtifactData()); + artifactElement.getInfo().addProperty(FILE_NAME_PROPERTY, artifactEntity.getFileName()); + + + ElementContext elementContext = new ElementContext(workflowId, versionId); + + zusammenAdaptor + .saveElement(contextCreator.create(), elementContext, artifactElement, "Update WorkflowVersion Artifact Element"); + } + + @Override + public Optional get(String workflowId, String versionId) { + + ElementContext elementContext = new ElementContext(workflowId, versionId); + + Optional elementOptional = + zusammenAdaptor.getElementByName(contextCreator.create(), elementContext, null, WorkflowElementType.ARTIFACT.name()); + + if (!elementOptional.isPresent() || hasEmptyData(elementOptional.get().getData())) { + return Optional.empty(); + } + + Element artifactElement = elementOptional.get(); + + ArtifactEntity artifact = new ArtifactEntity(artifactElement.getInfo().getProperty(FILE_NAME_PROPERTY), + artifactElement.getData()); + + return Optional.of(artifact); + } + + @Override + public boolean isExist(String workflowId, String versionId) { + + ElementContext elementContext = new ElementContext(workflowId, versionId); + + Optional optionalElementInfo = zusammenAdaptor.getElementInfoByName(contextCreator.create(), elementContext, null, + WorkflowElementType.ARTIFACT.name()); + return optionalElementInfo.isPresent() && optionalElementInfo.get().getInfo().getProperties() + .containsKey(FILE_NAME_PROPERTY); + } + + @Override + public void createStructure(String workflowId, String versionId) { + + ElementContext elementContext = new ElementContext(workflowId, versionId); + + ZusammenElement artifactElement = buildStructuralElement(WorkflowElementType.ARTIFACT.name(), Action.CREATE); + artifactElement.setData(new ByteArrayInputStream(EMPTY_DATA.getBytes())); + + zusammenAdaptor + .saveElement(contextCreator.create(), elementContext, artifactElement, "Create WorkflowVersion Artifact Element"); + + } + + @Override + public void delete(String workflowId, String versionId) { + + ElementContext elementContext = new ElementContext(workflowId, versionId); + + ZusammenElement artifactElement = buildStructuralElement(WorkflowElementType.ARTIFACT.name(), Action.UPDATE); + artifactElement.setData(new ByteArrayInputStream(EMPTY_DATA.getBytes())); + artifactElement.getInfo().getProperties().remove(FILE_NAME_PROPERTY); + + zusammenAdaptor.saveElement(contextCreator.create(), elementContext, artifactElement, "Delete WorkflowVersion Artifact Data"); + + } + + private boolean hasEmptyData(InputStream elementData) { + + byte[] byteElementData; + try { + byteElementData = IOUtils.toByteArray(elementData); + } catch (IOException ex) { + return false; + } + return Arrays.equals(EMPTY_DATA.getBytes(), byteElementData); + } +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/ParameterRepositoryImpl.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/ParameterRepositoryImpl.java new file mode 100644 index 00000000..eeef2477 --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/ParameterRepositoryImpl.java @@ -0,0 +1,171 @@ +/* + * 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.persistence.impl; + +import static org.onap.sdc.common.zusammen.services.ZusammenElementUtil.ELEMENT_TYPE_PROPERTY; +import static org.onap.sdc.common.zusammen.services.ZusammenElementUtil.buildElement; +import static org.onap.sdc.common.zusammen.services.ZusammenElementUtil.buildStructuralElement; + +import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element; +import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementInfo; +import com.amdocs.zusammen.adaptor.inbound.api.types.item.ZusammenElement; +import com.amdocs.zusammen.datatypes.Id; +import com.amdocs.zusammen.datatypes.item.Action; +import com.amdocs.zusammen.datatypes.item.ElementContext; +import com.amdocs.zusammen.datatypes.item.Info; +import java.util.Collection; +import java.util.Optional; +import java.util.stream.Collectors; +import org.onap.sdc.common.versioning.persistence.zusammen.ZusammenSessionContextCreator; +import org.onap.sdc.common.zusammen.services.ZusammenAdaptor; +import org.onap.sdc.workflow.persistence.ParameterRepository; +import org.onap.sdc.workflow.persistence.impl.types.ParameterPropertyName; +import org.onap.sdc.workflow.persistence.impl.types.WorkflowElementType; +import org.onap.sdc.workflow.persistence.types.ParameterEntity; +import org.onap.sdc.workflow.persistence.types.ParameterRole; +import org.onap.sdc.workflow.persistence.types.ParameterType; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; + +@Repository +public class ParameterRepositoryImpl implements ParameterRepository { + + private final ZusammenAdaptor zusammenAdaptor; + private final ZusammenSessionContextCreator contextCreator; + + @Autowired + public ParameterRepositoryImpl(ZusammenAdaptor zusammenAdaptor, ZusammenSessionContextCreator contextCreator) { + this.zusammenAdaptor = zusammenAdaptor; + this.contextCreator = contextCreator; + } + + @Override + public void createStructure(String id, String versionId) { + ElementContext elementContext = new ElementContext(id, versionId); + + ZusammenElement inputsElement = buildStructuralElement(WorkflowElementType.INPUTS.name(), Action.CREATE); + ZusammenElement outputsElement = buildStructuralElement(WorkflowElementType.OUTPUTS.name(), Action.CREATE); + + zusammenAdaptor.saveElement(contextCreator.create(), elementContext, inputsElement, "Create WorkflowVersion INPUTS Element"); + zusammenAdaptor.saveElement(contextCreator.create(), elementContext, outputsElement, "Create WorkflowVersion OUTPUTS Element"); + } + + @Override + public Collection list(String id, String versionId, ParameterRole role) { + ElementContext elementContext = new ElementContext(id, versionId); + + return zusammenAdaptor.listElementsByName(contextCreator.create(), elementContext, null, getParentElementType(role)).stream() + .map(this::mapElementInfoToParameter).collect(Collectors.toList()); + } + + @Override + public void deleteAll(String id, String versionId, ParameterRole role) { + ElementContext elementContext = new ElementContext(id, versionId); + + Optional optionalParentElement = + zusammenAdaptor.getElementInfoByName(contextCreator.create(), elementContext, null, getParentElementType(role)); + + if (!optionalParentElement.isPresent()) { + throw new IllegalStateException( + String.format("Missing data for workflow id %s version id %s", id, versionId)); + } + ZusammenElement parentElement = buildElement(optionalParentElement.get().getId(), Action.IGNORE); + parentElement.setSubElements(optionalParentElement.get().getSubElements().stream() + .map(parameter -> buildElement(parameter.getId(), Action.DELETE)) + .collect(Collectors.toList())); + + zusammenAdaptor.saveElement(contextCreator.create(), elementContext, parentElement, "Delete all " + role); + } + + @Override + public ParameterEntity get(String id, String versionId, String parameterId) { + ElementContext elementContext = new ElementContext(id, versionId); + + Optional element = zusammenAdaptor.getElementInfo(contextCreator.create(), elementContext, new Id(parameterId)); + + return element.map(this::mapElementInfoToParameter).orElse(null); + } + + @Override + public void delete(String id, String versionId, String parameterId) { + ElementContext elementContext = new ElementContext(id, versionId); + + ZusammenElement parameterElement = buildElement(new Id(parameterId), Action.DELETE); + + zusammenAdaptor.saveElement(contextCreator.create(), elementContext, parameterElement, + String.format("Delete Parameter with id %s", parameterId)); + } + + @Override + public ParameterEntity create(String id, String versionId, ParameterRole role, ParameterEntity parameter) { + ZusammenElement parameterElement = parameterToZusammenElement(parameter, role, Action.CREATE); + ZusammenElement parentElement = buildStructuralElement(getParentElementType(role), Action.IGNORE); + parentElement.addSubElement(parameterElement); + + ElementContext elementContext = new ElementContext(id, versionId); + + Element savedElement = zusammenAdaptor.saveElement(contextCreator.create(), elementContext, parentElement, + "Create WorkflowVersion Parameter Element"); + + parameter.setId(savedElement.getSubElements().iterator().next().getElementId().getValue()); + return parameter; + } + + @Override + public void update(String id, String versionId, ParameterRole role, ParameterEntity parameter) { + ElementContext elementContext = new ElementContext(id, versionId); + + ZusammenElement parameterElement = parameterToZusammenElement(parameter, role, Action.UPDATE); + + zusammenAdaptor.saveElement(contextCreator.create(), elementContext, parameterElement, "Update WorkflowVersion Parameter"); + } + + private ZusammenElement parameterToZusammenElement(ParameterEntity parameter, ParameterRole role, Action action) { + ZusammenElement parameterElement = + buildElement(parameter.getId() == null ? null : new Id(parameter.getId()), action); + Info info = new Info(); + info.setName(parameter.getName()); + info.addProperty(ELEMENT_TYPE_PROPERTY, WorkflowElementType.valueOf(role.name())); + info.addProperty(ParameterPropertyName.TYPE.name(), parameter.getType()); + info.addProperty(ParameterPropertyName.MANDATORY.name(), parameter.isMandatory()); + parameterElement.setInfo(info); + + return parameterElement; + } + + private ParameterEntity mapElementInfoToParameter(ElementInfo elementInfo) { + ParameterEntity parameterEntity = new ParameterEntity(); + parameterEntity.setId(elementInfo.getId().getValue()); + parameterEntity.setName(elementInfo.getInfo().getName()); + parameterEntity + .setType(ParameterType.valueOf(elementInfo.getInfo().getProperty(ParameterPropertyName.TYPE.name()))); + parameterEntity.setMandatory(elementInfo.getInfo().getProperty(ParameterPropertyName.MANDATORY.name())); + return parameterEntity; + } + + private static String getParentElementType(ParameterRole role) { + switch (role) { + case INPUT: + return WorkflowElementType.INPUTS.name(); + case OUTPUT: + return WorkflowElementType.OUTPUTS.name(); + default: + throw new IllegalArgumentException("Wrong Element Type"); + } + } + +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/types/ActivitySpecData.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/types/ActivitySpecData.java new file mode 100644 index 00000000..5daba8d6 --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/types/ActivitySpecData.java @@ -0,0 +1,31 @@ +/* + * Copyright © 2016-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.persistence.impl.types; + +import java.util.Collections; +import java.util.List; +import org.onap.sdc.workflow.persistence.types.ActivitySpecParameter; + +@lombok.Data +public class ActivitySpecData { + + private List inputs = Collections.emptyList(); + private List outputs = Collections.emptyList(); + private String type; + private String content; +} + diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/types/ActivitySpecElementType.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/types/ActivitySpecElementType.java new file mode 100644 index 00000000..e26b8088 --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/types/ActivitySpecElementType.java @@ -0,0 +1,21 @@ +/* + * Copyright © 2016-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.persistence.impl.types; + +public enum ActivitySpecElementType { + ACTIVITYSPEC +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/types/ParameterPropertyName.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/types/ParameterPropertyName.java new file mode 100644 index 00000000..300ddc49 --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/types/ParameterPropertyName.java @@ -0,0 +1,21 @@ +/* + * 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.persistence.impl.types; + +public enum ParameterPropertyName { + TYPE, MANDATORY +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/types/WorkflowElementType.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/types/WorkflowElementType.java new file mode 100644 index 00000000..109ce97c --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/impl/types/WorkflowElementType.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.persistence.impl.types; + +public enum WorkflowElementType { + + ARTIFACT, + INPUTS, + OUTPUTS, + INPUT, + OUTPUT +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ActivitySpecEntity.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ActivitySpecEntity.java new file mode 100644 index 00000000..cf3be394 --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ActivitySpecEntity.java @@ -0,0 +1,44 @@ +/* + * Copyright © 2016-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.persistence.types; + +import java.util.List; +import lombok.NoArgsConstructor; + +@lombok.Data +@NoArgsConstructor +public class ActivitySpecEntity { + + private String id; + private String versionId; + private String name; + private String description; + + private List categoryList; + private List inputs; + private List outputs; + private String type; + private String content; + + //Not to be maintained in activityspec element + private String status; + + public ActivitySpecEntity(String id, String versionId) { + this.id = id; + this.versionId = versionId; + } +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ActivitySpecParameter.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ActivitySpecParameter.java new file mode 100644 index 00000000..ec1c2681 --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ActivitySpecParameter.java @@ -0,0 +1,33 @@ +/* + * Copyright © 2016-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.persistence.types; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.onap.sdc.workflow.api.validation.ValidName; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@ValidName +public class ActivitySpecParameter { + + private String name; + private String type; + private String value; +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ArtifactEntity.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ArtifactEntity.java new file mode 100644 index 00000000..62819754 --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ArtifactEntity.java @@ -0,0 +1,29 @@ +/* + * 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.persistence.types; + +import java.io.InputStream; +import lombok.AllArgsConstructor; +import lombok.Data; + +@Data +@AllArgsConstructor +public class ArtifactEntity { + + private String fileName; + private InputStream artifactData; +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ParameterEntity.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ParameterEntity.java new file mode 100644 index 00000000..4dfd1e4f --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ParameterEntity.java @@ -0,0 +1,34 @@ +/* + * 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.persistence.types; + +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +public class ParameterEntity { + + private String id; + private String name; + private ParameterType type; + private boolean mandatory; + + public ParameterEntity(String name) { + this.name = name; + } +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ParameterRole.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ParameterRole.java new file mode 100644 index 00000000..9f5aacfe --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ParameterRole.java @@ -0,0 +1,24 @@ +/* + * 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.persistence.types; + +public enum ParameterRole { + + INPUT, + OUTPUT + +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ParameterType.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ParameterType.java new file mode 100644 index 00000000..04d09c01 --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/ParameterType.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.persistence.types; + +public enum ParameterType { + STRING, + INTEGER, + FLOAT, + BOOLEAN, + TIMESTAMP +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/UniqueValueEntity.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/UniqueValueEntity.java new file mode 100644 index 00000000..faf515b7 --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/persistence/types/UniqueValueEntity.java @@ -0,0 +1,36 @@ +/* + * 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.persistence.types; + +import static org.springframework.data.cassandra.core.cql.PrimaryKeyType.PARTITIONED; + +import lombok.AllArgsConstructor; +import lombok.Data; +import org.springframework.data.cassandra.core.mapping.PrimaryKeyColumn; +import org.springframework.data.cassandra.core.mapping.Table; + +@Table("unique_value") +@Data +@AllArgsConstructor +public class UniqueValueEntity { + + @PrimaryKeyColumn(ordinal = 0, type = PARTITIONED) + private String type; + + @PrimaryKeyColumn(ordinal = 1, type = PARTITIONED) + private String value; +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/config/ApplicationConfigurer.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/config/ApplicationConfigurer.java new file mode 100644 index 00000000..a5cce460 --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/config/ApplicationConfigurer.java @@ -0,0 +1,50 @@ +/* + * 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. + * ============LICENSE_END========================================================= + * Modifications copyright (c) 2019 Nokia + * ================================================================================ + */ + +package org.onap.sdc.workflow.server.config; + +import java.util.List; +import org.onap.sdc.workflow.server.resolvers.UserIdResolver; +import org.openecomp.sdc.logging.servlet.spring.LoggingInterceptor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.method.support.HandlerMethodArgumentResolver; +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +@Configuration +public class ApplicationConfigurer implements WebMvcConfigurer { + + private final LoggingInterceptor loggingInterceptor; + + @Autowired + public ApplicationConfigurer(LoggingInterceptor loggingInterceptor) { + this.loggingInterceptor = loggingInterceptor; + } + + @Override + public void addInterceptors(InterceptorRegistry registry) { + registry.addInterceptor(loggingInterceptor); + } + + @Override + public void addArgumentResolvers(List argumentResolvers) { + argumentResolvers.add(new UserIdResolver()); + } +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/config/LoggingInterceptorConfig.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/config/LoggingInterceptorConfig.java new file mode 100644 index 00000000..53dbda59 --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/config/LoggingInterceptorConfig.java @@ -0,0 +1,39 @@ +/* + * 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.server.config; + +import org.openecomp.sdc.logging.servlet.HttpHeader; +import org.openecomp.sdc.logging.servlet.spring.LoggingInterceptor; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class LoggingInterceptorConfig { + + @Value("${onap.logging.requestIdHeader}") + private String[] loggingRequestIdHeaders; + + @Value("${onap.logging.partnerNameHeader}") + private String[] loggingPartnerNameHeader; + + @Bean + public LoggingInterceptor createLoggingInterceptor() { + return new LoggingInterceptor(new HttpHeader(loggingRequestIdHeaders), + new HttpHeader(loggingPartnerNameHeader)); + } +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/config/SwaggerConfig.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/config/SwaggerConfig.java new file mode 100644 index 00000000..a2eca63a --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/config/SwaggerConfig.java @@ -0,0 +1,39 @@ +/* + * 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.server.config; + +import static springfox.documentation.builders.PathSelectors.regex; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2; + +@Configuration +@EnableSwagger2 +public class SwaggerConfig { + + @Bean + public Docket api() { + return new Docket(DocumentationType.SWAGGER_2) + .select().apis(RequestHandlerSelectors.basePackage("org.onap.sdc.workflow.api")) + .paths(regex("/(wf/workflows|v1.0/activity-spec).*")) + .build(); + } +} \ No newline at end of file diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/config/WebServerConfig.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/config/WebServerConfig.java new file mode 100644 index 00000000..e760ecd1 --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/config/WebServerConfig.java @@ -0,0 +1,44 @@ +/* + * Copyright © 2016-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.server.config; + +import org.eclipse.jetty.server.ServerConnector; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.web.embedded.jetty.JettyServerCustomizer; +import org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory; +import org.springframework.boot.web.server.WebServerFactoryCustomizer; +import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class WebServerConfig implements WebServerFactoryCustomizer { + + @Value("${http.port}") + private int httpPort; + + @Override + public void customize(ConfigurableServletWebServerFactory container) { + if (container instanceof JettyServletWebServerFactory) { + JettyServletWebServerFactory containerFactory = (JettyServletWebServerFactory) container; + containerFactory.addServerCustomizers((JettyServerCustomizer) server -> { + ServerConnector connector = new ServerConnector(server); + connector.setPort(httpPort); + server.addConnector(connector); + }); + } + } +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/config/WorkflowZusammenConfigProvider.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/config/WorkflowZusammenConfigProvider.java new file mode 100644 index 00000000..dbd2d6de --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/config/WorkflowZusammenConfigProvider.java @@ -0,0 +1,48 @@ +/* + * 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.server.config; + +import lombok.Getter; +import org.onap.sdc.common.zusammen.config.ZusammenConfigProvider; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Configuration; + +@Configuration +@Getter +public class WorkflowZusammenConfigProvider implements ZusammenConfigProvider { + + @Value("${spring.data.cassandra.keyspace-name}") + private String tenant; + @Value("${spring.data.cassandra.contact-points}") + private String cassandraAddresses; + @Value("${spring.data.cassandra.port}") + private String cassandraPort; + + @Value("${spring.data.cassandra.username}") + private String cassandraUser; + @Value("${spring.data.cassandra.password}") + private String cassandraPassword; + @Value("${zusammen.cassandra.isAuthenticate}") + private String cassandraAuth; + @Value("${spring.data.cassandra.ssl}") + + private String cassandraSSL; + @Value("${zusammen.cassandra.trustStorePath}") + private String cassandraTrustStorePath; + @Value("${zusammen.cassandra.trustStorePassword}") + private String cassandraTrustStorePassword; +} \ No newline at end of file diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/filters/SessionContextFilter.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/filters/SessionContextFilter.java new file mode 100644 index 00000000..57cda856 --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/filters/SessionContextFilter.java @@ -0,0 +1,73 @@ +/* + * 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.server.filters; + +import java.io.IOException; +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.http.HttpServletRequest; +import org.onap.sdc.common.session.SessionContextProvider; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +@Component +public class SessionContextFilter implements Filter { + + private final SessionContextProvider sessionContextProvider; + @Value("${spring.data.cassandra.keyspace-name}") + private String tenant; + + @Autowired + public SessionContextFilter(SessionContextProvider sessionContextProvider) { + this.sessionContextProvider = sessionContextProvider; + } + + @Override + public void init(FilterConfig filterConfig) { + // not implemented + } + + @Override + public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) + throws IOException, ServletException { + try { + if (servletRequest instanceof HttpServletRequest) { + sessionContextProvider.create(getUser(servletRequest), tenant); + } + + filterChain.doFilter(servletRequest, servletResponse); + } finally { + sessionContextProvider.close(); + } + } + + @Override + public void destroy() { + // not implemented + } + + private String getUser(ServletRequest servletRequest) { + return "GLOBAL_USER"; + // TODO: 7/11/2018 get user from header when collaboration will be supported + //((HttpServletRequest) servletRequest).getHeader(USER_ID_HEADER_PARAM); + } +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/resolvers/UserIdResolver.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/resolvers/UserIdResolver.java new file mode 100644 index 00000000..80cb07a8 --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/resolvers/UserIdResolver.java @@ -0,0 +1,71 @@ +/* + * 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.server.resolvers; + +import static org.onap.sdc.workflow.api.RestParams.USER_ID_HEADER; + +import java.util.Objects; +import javax.servlet.http.HttpServletRequest; +import org.onap.sdc.workflow.services.annotations.UserId; +import org.springframework.core.MethodParameter; +import org.springframework.web.bind.ServletRequestBindingException; +import org.springframework.web.bind.support.WebDataBinderFactory; +import org.springframework.web.context.request.NativeWebRequest; +import org.springframework.web.method.support.HandlerMethodArgumentResolver; +import org.springframework.web.method.support.ModelAndViewContainer; + +/** + * Resolves a user ID from an HTTP header and injects it into a parameter of type {@link String} annotated with {@link + * UserId}. The header is considered mandatory, therefore an error is returned to the client if no user ID was sent. + * + * @author evitaliy + * @since 21 Aug 2018 + */ +public class UserIdResolver implements HandlerMethodArgumentResolver { + + private static final String ERROR_MESSAGE = "Missing mandatory request header '" + USER_ID_HEADER + "'"; + + @Override + public boolean supportsParameter(MethodParameter methodParameter) { + + if (!methodParameter.hasParameterAnnotation(UserId.class)) { + return false; + } + + Class parameterType = methodParameter.getParameterType(); + if (!parameterType.equals(String.class)) { + throw new IllegalStateException("Cannot inject user ID into a parameter of type " + + parameterType.getTypeName()); + } + + return true; + } + + @Override + public Object resolveArgument(MethodParameter methodParameter, ModelAndViewContainer modelAndViewContainer, + NativeWebRequest nativeWebRequest, WebDataBinderFactory webDataBinderFactory) + throws ServletRequestBindingException { + + HttpServletRequest httpServletRequest = nativeWebRequest.getNativeRequest(HttpServletRequest.class); + String userHeader = Objects.requireNonNull(httpServletRequest).getHeader(USER_ID_HEADER); + if (userHeader == null) { + throw new ServletRequestBindingException(ERROR_MESSAGE); + } + + return userHeader; + } +} \ No newline at end of file diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/ActivitySpecConstant.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/ActivitySpecConstant.java new file mode 100644 index 00000000..bee916aa --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/ActivitySpecConstant.java @@ -0,0 +1,28 @@ +/* + * Copyright © 2016-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; + +public class ActivitySpecConstant { + + public static final String CATEGORY_ATTRIBUTE_NAME = "category"; + public static final String VERSION_ID_DEFAULT_VALUE = "latest"; + public static final String ACTIVITY_SPEC_NOT_FOUND = "No Activity Spec found for the given identifiers"; + + private ActivitySpecConstant() { + //Utility Class declaring constants does not require instantiation. + } +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/ActivitySpecManager.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/ActivitySpecManager.java new file mode 100644 index 00000000..b93a8dc8 --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/ActivitySpecManager.java @@ -0,0 +1,34 @@ +/* + * Copyright © 2016-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; + +import java.util.Collection; +import org.onap.sdc.workflow.api.types.activityspec.ActivitySpecAction; +import org.onap.sdc.workflow.persistence.types.ActivitySpecEntity; + +public interface ActivitySpecManager { + + ActivitySpecEntity createActivitySpec(ActivitySpecEntity activitySpec); + + ActivitySpecEntity get(ActivitySpecEntity activitySpec); + + void update(ActivitySpecEntity activitySpec); + + void actOnAction(ActivitySpecEntity activitySpec, ActivitySpecAction action); + + Collection list(String versionStatus); +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/UniqueValueService.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/UniqueValueService.java new file mode 100644 index 00000000..0a789829 --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/UniqueValueService.java @@ -0,0 +1,122 @@ +/* + * 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; + +import java.util.Optional; +import org.apache.commons.lang3.ArrayUtils; +import org.onap.sdc.workflow.persistence.UniqueValueRepository; +import org.onap.sdc.workflow.persistence.types.UniqueValueEntity; +import org.onap.sdc.workflow.services.exceptions.UniqueValueViolationException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service("uniqueValueService") +public class UniqueValueService { + + private static final String FORMATTED_UNIQUE_VALUE_SEPARATOR = "_"; + + private final UniqueValueRepository uniqueValueRepository; + + @Autowired + public UniqueValueService(UniqueValueRepository uniqueValueRepository) { + this.uniqueValueRepository = uniqueValueRepository; + } + + /** + * Create unique value. + * + * @param type the type + * @param uniqueCombination the unique combination + */ + public void createUniqueValue(String type, String... uniqueCombination) { + formatValue(uniqueCombination).ifPresent(formattedValue -> { + validateUniqueValue(type, formattedValue, uniqueCombination); + uniqueValueRepository.insert(new UniqueValueEntity(type, formattedValue)); + }); + } + + /** + * Delete unique value. + * + * @param type the type + * @param uniqueCombination the unique combination + */ + public void deleteUniqueValue(String type, String... uniqueCombination) { + formatValue(uniqueCombination) + .ifPresent(formattedValue -> uniqueValueRepository.delete(new UniqueValueEntity(type, formattedValue))); + + } + + /** + * Update unique value. + * + * @param type the type + * @param oldValue the old value + * @param newValue the new value + * @param uniqueContext the unique context + */ + public void updateUniqueValue(String type, String oldValue, String newValue, String... uniqueContext) { + if (newValue == null || !newValue.equalsIgnoreCase(oldValue)) { + createUniqueValue(type, ArrayUtils.addAll(uniqueContext, newValue)); + deleteUniqueValue(type, ArrayUtils.addAll(uniqueContext, oldValue)); + } + } + + /** + * Validate unique value. + * + * @param type the type + * @param uniqueCombination the unique combination + */ + public void validateUniqueValue(String type, String... uniqueCombination) { + formatValue(uniqueCombination) + .ifPresent(formattedValue -> validateUniqueValue(type, formattedValue, uniqueCombination)); + } + + private Optional formatValue(String[] uniqueCombination) { + if (ArrayUtils.isEmpty(uniqueCombination) || getValueWithoutContext(uniqueCombination) == null) { + return Optional.empty(); + } + + uniqueCombination[uniqueCombination.length - 1] = getValueWithoutContext(uniqueCombination).toLowerCase(); + return Optional.of(String.join(FORMATTED_UNIQUE_VALUE_SEPARATOR, uniqueCombination)); + } + + private void validateUniqueValue(String type, String formattedValue, String[] uniqueCombination) { + if (isUniqueValueOccupied(type, formattedValue)) { + throw new UniqueValueViolationException(type, getValueWithoutContext(uniqueCombination)); + } + } + + private boolean isUniqueValueOccupied(String type, String formattedValue) { + return uniqueValueRepository.findById(new UniqueValueEntity(type, formattedValue)).isPresent(); + } + + /** + * Checks if a unique value is taken. + * + * @return true if the unique value is occupied, false otherwise + */ + public boolean isUniqueValueOccupied(String type, String... uniqueCombination) { + return formatValue(uniqueCombination).map(formattedValue -> isUniqueValueOccupied(type, formattedValue)) + .orElse(false); + } + + private String getValueWithoutContext(String[] uniqueCombination) { + return uniqueCombination[uniqueCombination.length - 1]; + } +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/WorkflowManager.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/WorkflowManager.java new file mode 100644 index 00000000..2c7a7c24 --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/WorkflowManager.java @@ -0,0 +1,37 @@ +/* + * 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; + +import java.util.Set; +import org.onap.sdc.workflow.services.types.ArchivingStatus; +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.WorkflowVersionState; + +public interface WorkflowManager { + + Page list(String statusFilter, String searchNameFilter, Set versionStatesFilter, RequestSpec requestSpec); + + Workflow get(Workflow workflow); + + Workflow create(Workflow workflow); + + void update(Workflow workflow); + + void updateStatus(String workflowId, ArchivingStatus status); +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/WorkflowVersionManager.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/WorkflowVersionManager.java new file mode 100644 index 00000000..a7f5c421 --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/WorkflowVersionManager.java @@ -0,0 +1,46 @@ +/* + * 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; + +import java.util.Collection; +import java.util.Set; +import org.onap.sdc.workflow.persistence.types.ArtifactEntity; +import org.onap.sdc.workflow.services.types.WorkflowVersion; +import org.onap.sdc.workflow.services.types.WorkflowVersionState; +import org.springframework.web.multipart.MultipartFile; + + +public interface WorkflowVersionManager { + + Collection list(String workflowId, Set stateFilter); + + WorkflowVersion create(String workflowId, String baseVersionId, WorkflowVersion version); + + void update(String workflowId, WorkflowVersion version); + + WorkflowVersion get(String workflowId, String versionId); + + WorkflowVersionState getState(String workflowId, String versionId); + + void updateState(String workflowId, String versionId, WorkflowVersionState state); + + ArtifactEntity getArtifact(String workflowId, String versionId); + + void deleteArtifact(String workflowId, String versionId); + + void uploadArtifact(String workflowId, String versionId, MultipartFile artifact); +} \ No newline at end of file diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/annotations/UserId.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/annotations/UserId.java new file mode 100644 index 00000000..90a1a763 --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/annotations/UserId.java @@ -0,0 +1,28 @@ +/* + * 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.annotations; + +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; + +@Target({ElementType.PARAMETER}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface UserId { } diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/EntityNotFoundException.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/EntityNotFoundException.java new file mode 100644 index 00000000..7fc3e81c --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/EntityNotFoundException.java @@ -0,0 +1,24 @@ +/* + * 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 EntityNotFoundException extends RuntimeException { + + public EntityNotFoundException(String message) { + super(message); + } +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/InvalidArtifactException.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/InvalidArtifactException.java new file mode 100644 index 00000000..c4584179 --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/InvalidArtifactException.java @@ -0,0 +1,24 @@ +/* + * 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 InvalidArtifactException extends RuntimeException { + + public InvalidArtifactException(String message) { + super("Invalid artifact file can not be processed. Error: " + message); + } +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/UniqueValueViolationException.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/UniqueValueViolationException.java new file mode 100644 index 00000000..a3046a77 --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/UniqueValueViolationException.java @@ -0,0 +1,27 @@ +/* + * 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 UniqueValueViolationException extends RuntimeException { + + private static final String UNIQUE_VALUE_VIOLATION_MSG = "%s with the value '%s' already exists."; + + public UniqueValueViolationException(String uniqueType, String value) { + super(String.format(UNIQUE_VALUE_VIOLATION_MSG, uniqueType, value)); + } +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionCreationException.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionCreationException.java new file mode 100644 index 00000000..31c88923 --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionCreationException.java @@ -0,0 +1,31 @@ +/* + * 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 VersionCreationException extends RuntimeException { + + private static final String MSG = "Error creating a new version for workflow with id %s"; + private static final String MSG_WITH_BASE_ID = MSG + " based on version %s: %s"; + + public VersionCreationException(String workflowId, String baseVersionId, String detailedMessage) { + super(String.format(MSG_WITH_BASE_ID, workflowId, baseVersionId, detailedMessage)); + } + + public VersionCreationException(String workflowId) { + super(String.format(MSG, workflowId)); + } +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionModificationException.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionModificationException.java new file mode 100644 index 00000000..752d6bce --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionModificationException.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; + +public class VersionModificationException extends RuntimeException { + + public VersionModificationException(String workflowId, String versionId) { + super(String.format( + "Error while trying to modify version %s of workflow %s: Version is CERTIFIED and can not be edited", + versionId, workflowId)); + } +} \ No newline at end of file diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionStateModificationException.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionStateModificationException.java new file mode 100644 index 00000000..43360bd6 --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionStateModificationException.java @@ -0,0 +1,33 @@ +/* + * 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.onap.sdc.workflow.services.types.WorkflowVersionState; + +public class VersionStateModificationException extends RuntimeException { + + public VersionStateModificationException(String workflowId, String versionId, WorkflowVersionState sourceState, + WorkflowVersionState targetState) { + this(workflowId, versionId, sourceState, targetState, null); + } + + public VersionStateModificationException(String workflowId, String versionId, WorkflowVersionState sourceState, + 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/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionStateModificationMissingArtifactException.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionStateModificationMissingArtifactException.java new file mode 100644 index 00000000..abda1caf --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionStateModificationMissingArtifactException.java @@ -0,0 +1,32 @@ +/* + * Copyright © 2016-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.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/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionStatusModificationException.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionStatusModificationException.java new file mode 100644 index 00000000..917a8384 --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionStatusModificationException.java @@ -0,0 +1,28 @@ +/* + * 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.onap.sdc.common.versioning.services.types.VersionStatus; + +public class VersionStatusModificationException extends RuntimeException { + + public VersionStatusModificationException(String activitySpecId, String versionId, VersionStatus sourceState, + VersionStatus targetState) { + super(String.format("Activity spec %s, version %s: status can not be changed from %s to %s", activitySpecId, + versionId, sourceState.name(), targetState.name())); + } +} \ No newline at end of file diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionValidationException.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionValidationException.java new file mode 100644 index 00000000..815bc0b2 --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/VersionValidationException.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; + +public class VersionValidationException extends RuntimeException { + + private static final String MSG = "Error creating or modifying version for workflow with id %s: %s"; + + public VersionValidationException(String workflowId, String detailedMessage) { + super(String.format(MSG, workflowId, detailedMessage)); + } +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/WorkflowModificationException.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/exceptions/WorkflowModificationException.java new file mode 100644 index 00000000..7aa5ac0b --- /dev/null +++ b/sdc-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/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/ActivitySpecManagerImpl.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/ActivitySpecManagerImpl.java new file mode 100644 index 00000000..e1849b9f --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/ActivitySpecManagerImpl.java @@ -0,0 +1,231 @@ +/* + * Copyright © 2016-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.impl; + +import static org.onap.sdc.common.versioning.services.types.VersionStatus.Certified; +import static org.onap.sdc.common.versioning.services.types.VersionStatus.Deleted; +import static org.onap.sdc.common.versioning.services.types.VersionStatus.Deprecated; +import static org.onap.sdc.common.versioning.services.types.VersionStatus.Draft; +import static org.onap.sdc.workflow.services.ActivitySpecConstant.ACTIVITY_SPEC_NOT_FOUND; +import static org.onap.sdc.workflow.services.ActivitySpecConstant.VERSION_ID_DEFAULT_VALUE; + +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.EnumMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.function.Predicate; +import java.util.stream.Collectors; +import org.onap.sdc.common.versioning.services.ItemManager; +import org.onap.sdc.common.versioning.services.VersioningManager; +import org.onap.sdc.common.versioning.services.types.Item; +import org.onap.sdc.common.versioning.services.types.Version; +import org.onap.sdc.common.versioning.services.types.VersionCreationMethod; +import org.onap.sdc.common.versioning.services.types.VersionStatus; +import org.onap.sdc.workflow.api.types.activityspec.ActivitySpecAction; +import org.onap.sdc.workflow.persistence.ActivitySpecRepository; +import org.onap.sdc.workflow.persistence.types.ActivitySpecEntity; +import org.onap.sdc.workflow.services.ActivitySpecManager; +import org.onap.sdc.workflow.services.UniqueValueService; +import org.onap.sdc.workflow.services.exceptions.EntityNotFoundException; +import org.onap.sdc.workflow.services.exceptions.VersionStatusModificationException; +import org.onap.sdc.workflow.services.impl.mappers.ActivitySpecMapper; +import org.openecomp.sdc.logging.api.Logger; +import org.openecomp.sdc.logging.api.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Service; + +@Service("activitySpecManager") +public class ActivitySpecManagerImpl implements ActivitySpecManager { + + private static final String ACTIVITY_SPEC_NAME = "ActivitySpec.Name"; + private static final Logger LOGGER = LoggerFactory.getLogger(ActivitySpecManagerImpl.class); + private static final Map EXPECTED_PREV_STATUS; + + static { + EXPECTED_PREV_STATUS = new EnumMap<>(VersionStatus.class); + EXPECTED_PREV_STATUS.put(Certified, Draft); + EXPECTED_PREV_STATUS.put(Deprecated, Certified); + EXPECTED_PREV_STATUS.put(Deleted, Deprecated); + } + + private final ItemManager itemManager; + private final VersioningManager versioningManager; + private final ActivitySpecRepository activitySpecDao; + private final UniqueValueService uniqueValueService; + private final ActivitySpecMapper activitySpecMapper; + + + @Autowired + public ActivitySpecManagerImpl(ItemManager itemManager, VersioningManager versioningManager, + ActivitySpecRepository activitySpecDao, + @Qualifier("uniqueValueService") UniqueValueService uniqueValueService, + ActivitySpecMapper activitySpecMapper) { + this.itemManager = itemManager; + this.versioningManager = versioningManager; + this.activitySpecDao = activitySpecDao; + this.uniqueValueService = uniqueValueService; + this.activitySpecMapper = activitySpecMapper; + } + + @Override + public ActivitySpecEntity createActivitySpec(ActivitySpecEntity activitySpec) { + + uniqueValueService.validateUniqueValue(ACTIVITY_SPEC_NAME, activitySpec.getName()); + + Item item = new Item(); + activitySpecMapper.toItem(activitySpec, item); + Item createdItem = itemManager.create(item); + + Version createdVersion = + versioningManager.create(createdItem.getId(), null, new Version(), VersionCreationMethod.major); + + activitySpec.setId(createdItem.getId()); + activitySpec.setVersionId(createdVersion.getId()); + activitySpecDao.create(activitySpec); + + uniqueValueService.createUniqueValue(ACTIVITY_SPEC_NAME, activitySpec.getName()); + return activitySpec; + } + + @Override + public ActivitySpecEntity get(ActivitySpecEntity activitySpec) { + activitySpec.setVersionId(calculateLatestVersion(activitySpec)); + ActivitySpecEntity retrieved; + try { + + retrieved = activitySpecDao.get(activitySpec); + } catch (RuntimeException e) { + LOGGER.error("Failed to retrieve activity spec for activitySpecId: {} and version: {}", + activitySpec.getId(), activitySpec.getVersionId(), e); + throw new EntityNotFoundException(ACTIVITY_SPEC_NOT_FOUND); + } + if (retrieved != null) { + final Version retrievedVersion = versioningManager.get(activitySpec.getId(), activitySpec.getVersionId()); + retrieved.setStatus(Objects.nonNull(retrievedVersion) ? retrievedVersion.getStatus().name() : null); + } + return retrieved; + } + + @Override + public void update(ActivitySpecEntity activitySpec) { + Item item = itemManager.get(activitySpec.getId()); + if (item == null) { + LOGGER.error("Activity Spec with id {} was not found", activitySpec.getId()); + throw new EntityNotFoundException(ACTIVITY_SPEC_NOT_FOUND); + } + uniqueValueService.updateUniqueValue(ACTIVITY_SPEC_NAME, item.getName(), activitySpec.getName()); + + activitySpecMapper.toItem(activitySpec, item); + itemManager.update(activitySpec.getId(), item); + + activitySpec.setVersionId(calculateLatestVersion(activitySpec)); + activitySpecDao.update(activitySpec); + } + + @Override + public void actOnAction(ActivitySpecEntity activitySpec, ActivitySpecAction action) { + VersionStatus newStatus = getVersionStatusByAction(action); + + String versionId = calculateLatestVersion(activitySpec); + Version retrievedVersion; + try { + retrievedVersion = versioningManager.get(activitySpec.getId(), versionId); + } catch (RuntimeException e) { + LOGGER.error("failed to get activity {}, version {}", activitySpec.getId(), versionId, e); + throw new EntityNotFoundException(ACTIVITY_SPEC_NOT_FOUND); + } + if (retrievedVersion == null) { + throw new EntityNotFoundException(ACTIVITY_SPEC_NOT_FOUND); + } + + VersionStatus retrievedStatus = retrievedVersion.getStatus(); + VersionStatus expectedPrevStatus = EXPECTED_PREV_STATUS.get(newStatus); + if (expectedPrevStatus != null && retrievedStatus != expectedPrevStatus) { + LOGGER.debug("Failed to {} since activity spec is in status {}", action.name(), retrievedStatus); + throw new VersionStatusModificationException(activitySpec.getId(), versionId, retrievedStatus, + newStatus); + } + + versioningManager.updateStatus(activitySpec.getId(), retrievedVersion.getId(), newStatus, + "actionOnActivitySpec :" + action.name()); + + if (action == ActivitySpecAction.DELETE) { + final String activitySpecName = get(new ActivitySpecEntity(activitySpec.getId(), versionId)).getName(); + uniqueValueService.deleteUniqueValue(ACTIVITY_SPEC_NAME, activitySpecName); + } + } + + private VersionStatus getVersionStatusByAction(ActivitySpecAction action) { + switch (action) { + case DELETE: + return Deleted; + case DEPRECATE: + return Deprecated; + case CERTIFY: + return Certified; + default: + throw new UnsupportedOperationException( + String.format("Activity Spec action %s is not supported", action.name())); + } + + } + + @Override + public Collection list(String versionStatus) { + Predicate itemPredicate; + if (Objects.nonNull(versionStatus)) { + VersionStatus statusEnumValue; + + try { + statusEnumValue = VersionStatus.valueOf(versionStatus); + } catch (IllegalArgumentException e) { + LOGGER.debug("Unexpected value of VersionStatus {}", versionStatus); + return Collections.emptyList(); + } + itemPredicate = + item -> ItemType.ACTIVITYSPEC.name().equals(item.getType()) && item.getVersionStatusCounters() + .containsKey( + statusEnumValue); + } else { + itemPredicate = item -> ItemType.ACTIVITYSPEC.name().equals(item.getType()); + } + + return itemManager.list(itemPredicate).stream() + .sorted(Comparator.comparing(Item::getModificationTime).reversed()) + .map(activitySpecMapper::itemToActivitySpec).collect(Collectors.toList()); + } + + private String calculateLatestVersion(ActivitySpecEntity activitySpec) { + if (VERSION_ID_DEFAULT_VALUE.equalsIgnoreCase(activitySpec.getVersionId())) { + List versions; + try { + versions = versioningManager.list(activitySpec.getId()); + } catch (RuntimeException e) { + LOGGER.error("Failed to list versions for activitySpecId {}", activitySpec.getId(), e); + throw new EntityNotFoundException(ACTIVITY_SPEC_NOT_FOUND); + } + if (Objects.nonNull(versions) && !versions.isEmpty()) { + return versions.get(0).getId(); + } + } + return activitySpec.getVersionId(); + } +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/ItemType.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/ItemType.java new file mode 100644 index 00000000..8a05d88d --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/ItemType.java @@ -0,0 +1,21 @@ +/* + * Copyright © 2016-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.impl; + +public enum ItemType { + WORKFLOW, ACTIVITYSPEC +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/WorkflowManagerImpl.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/WorkflowManagerImpl.java new file mode 100644 index 00000000..fc135621 --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/WorkflowManagerImpl.java @@ -0,0 +1,217 @@ +/* + * 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.impl; + +import static org.onap.sdc.workflow.services.impl.ItemType.WORKFLOW; +import static org.onap.sdc.workflow.services.types.PagingConstants.DEFAULT_LIMIT; +import static org.onap.sdc.workflow.services.types.PagingConstants.DEFAULT_OFFSET; +import static org.onap.sdc.workflow.services.types.PagingConstants.MAX_LIMIT; + +import java.util.Collection; +import java.util.Comparator; +import java.util.List; +import java.util.Set; +import java.util.function.Predicate; +import java.util.stream.Collectors; +import org.onap.sdc.common.versioning.services.ItemManager; +import org.onap.sdc.common.versioning.services.types.Item; +import org.onap.sdc.common.versioning.services.types.ItemStatus; +import org.onap.sdc.common.versioning.services.types.VersionStatus; +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.impl.mappers.ArchivingStatusMapper; +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.ArchivingStatus; +import org.onap.sdc.workflow.services.types.Page; +import org.onap.sdc.workflow.services.types.PagingRequest; +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.WorkflowVersionState; +import org.openecomp.sdc.logging.api.Logger; +import org.openecomp.sdc.logging.api.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Service; + +@Service("workflowManager") +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 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), + SortingRequest.builder().sort(new Sort(WORKSPACES_SORT_PROPERTY, true)).build()); + + private static final Logger LOGGER = LoggerFactory.getLogger(WorkflowManagerImpl.class); + + private final ItemManager itemManager; + private final UniqueValueService uniqueValueService; + private final WorkflowMapper workflowMapper; + private final ArchivingStatusMapper archivingStatusMapper; + private final VersionStateMapper versionStateMapper; + + @Autowired + public WorkflowManagerImpl(ItemManager itemManager, + @Qualifier("uniqueValueService") UniqueValueService uniqueValueService, WorkflowMapper workflowMapper, + ArchivingStatusMapper archivingStatusMapper, VersionStateMapper versionStateMapper) { + this.itemManager = itemManager; + this.uniqueValueService = uniqueValueService; + this.workflowMapper = workflowMapper; + this.archivingStatusMapper = archivingStatusMapper; + this.versionStateMapper = versionStateMapper; + } + + @Override + public Page list(String statusFilter, String searchNameFilter, + Set versionStatesFilter, RequestSpec requestSpec) { + requestSpec = getRequestSpec(requestSpec); + + Collection workflowItems = + itemManager.list(createFilter(statusFilter, searchNameFilter, versionStatesFilter)); + + List workflowsSlice = workflowItems.stream().map(workflowMapper::fromItem) + .sorted(getWorkflowComparator(requestSpec.getSorting())) + .skip(requestSpec.getPaging().getOffset()) + .limit(requestSpec.getPaging().getLimit()).collect(Collectors.toList()); + + return new Page<>(workflowsSlice, requestSpec.getPaging(), workflowItems.size()); + } + + @Override + public Workflow get(Workflow workflow) { + Item retrievedItem = itemManager.get(workflow.getId()); + if (retrievedItem == null) { + throw new EntityNotFoundException(String.format(WORKFLOW_NOT_FOUND_ERROR_MSG, workflow.getId())); + } + return this.workflowMapper.fromItem(retrievedItem); + } + + @Override + public Workflow create(Workflow workflow) { + Item item = new Item(); + workflowMapper.toItem(workflow, item); + + uniqueValueService.validateUniqueValue(WORKFLOW_NAME_UNIQUE_TYPE, workflow.getName()); + Item createdItem = itemManager.create(item); + uniqueValueService.createUniqueValue(WORKFLOW_NAME_UNIQUE_TYPE, workflow.getName()); + + return workflowMapper.fromItem(createdItem); + } + + @Override + public void update(Workflow workflow) { + Item item = itemManager.get(workflow.getId()); + if (item == null) { + throw new EntityNotFoundException(String.format(WORKFLOW_NOT_FOUND_ERROR_MSG, workflow.getId())); + } + + if (ItemStatus.ARCHIVED.equals(item.getStatus())) { + throw new WorkflowModificationException(workflow.getId()); + } + + uniqueValueService.updateUniqueValue(WORKFLOW_NAME_UNIQUE_TYPE, item.getName(), workflow.getName()); + + workflowMapper.toItem(workflow, item); + itemManager.update(workflow.getId(), item); + } + + @Override + public void updateStatus(String workflowId, ArchivingStatus status) { + itemManager.updateStatus(workflowId, archivingStatusMapper.toItemStatus(status)); + } + + private static RequestSpec getRequestSpec(RequestSpec requestSpec) { + if (requestSpec == null) { + return WORKSPACES_DEFAULT_REQUEST_SPEC; + } + if (requestSpec.getPaging() == null) { + requestSpec.setPaging(WORKSPACES_DEFAULT_REQUEST_SPEC.getPaging()); + } else { + handlePagingRequestValues(requestSpec.getPaging()); + } + if (requestSpec.getSorting() == null) { + requestSpec.setSorting(WORKSPACES_DEFAULT_REQUEST_SPEC.getSorting()); + } + return requestSpec; + } + + private static void handlePagingRequestValues(PagingRequest paging) { + if (paging.getOffset() == null) { + paging.setOffset(DEFAULT_OFFSET); + } + if (paging.getLimit() == null) { + paging.setLimit(DEFAULT_LIMIT); + } else if (paging.getLimit() > MAX_LIMIT) { + paging.setLimit(MAX_LIMIT); + } + } + + private static Comparator getWorkflowComparator(SortingRequest sorting) { + Boolean byNameAscending = sorting.getSorts().stream() + .filter(sort -> WORKSPACES_SORT_PROPERTY.equalsIgnoreCase(sort.getProperty())) + .findFirst().map(Sort::isAscendingOrder).orElse(true); + Comparator byName = Comparator.comparing(Workflow::getName); + + return byNameAscending ? byName : byName.reversed(); + } + + private Predicate createFilter(String itemStatusFilter, String searchNameFilter, + Set versionStatesFilter) { + + Set versionStatusesFilter = versionStatesFilter == null ? null : + versionStatesFilter.stream() + .map(versionStateMapper::workflowVersionStateToVersionStatus) + .collect(Collectors.toSet()); + + Predicate filter = addSearchNameFilter(WORKFLOW_ITEM_TYPE_FILTER, searchNameFilter); + + filter = addVersionStatusFilter(filter, versionStatusesFilter); + + return addItemStatusFilter(filter, itemStatusFilter); + + } + + private static Predicate addSearchNameFilter(Predicate filter, String searchNameFilter) { + return filter.and(item -> searchNameFilter == null || item.getName().toLowerCase() + .contains(searchNameFilter.toLowerCase())); + } + + private static Predicate addVersionStatusFilter(Predicate filter, Set versionStatuses) { + return filter.and(item -> versionStatuses == null || item.getVersionStatusCounters().keySet().stream() + .anyMatch(versionStatuses::contains)); + } + + private static Predicate addItemStatusFilter(Predicate filter, String itemStatusFilter) { + if (itemStatusFilter != null) { + try { + ItemStatus.valueOf(itemStatusFilter.toUpperCase()); + } catch (IllegalArgumentException e) { + LOGGER.debug("Illegal Workflow status filter: {}. Ignoring filter", itemStatusFilter, e); + return filter; + } + return filter.and(item -> item.getStatus().equals(ItemStatus.valueOf(itemStatusFilter.toUpperCase()))); + } + return filter; + } +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImpl.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImpl.java new file mode 100644 index 00000000..f95e6a1f --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/WorkflowVersionManagerImpl.java @@ -0,0 +1,308 @@ +/* + * 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.impl; + +import static org.onap.sdc.workflow.services.types.WorkflowVersionState.CERTIFIED; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Collection; +import java.util.Comparator; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.function.Function; +import java.util.stream.Collectors; +import org.onap.sdc.common.versioning.services.ItemManager; +import org.onap.sdc.common.versioning.services.VersioningManager; +import org.onap.sdc.common.versioning.services.types.Item; +import org.onap.sdc.common.versioning.services.types.ItemStatus; +import org.onap.sdc.common.versioning.services.types.Version; +import org.onap.sdc.common.versioning.services.types.VersionCreationMethod; +import org.onap.sdc.common.versioning.services.types.VersionStatus; +import org.onap.sdc.workflow.persistence.ArtifactRepository; +import org.onap.sdc.workflow.persistence.ParameterRepository; +import org.onap.sdc.workflow.persistence.types.ArtifactEntity; +import org.onap.sdc.workflow.persistence.types.ParameterEntity; +import org.onap.sdc.workflow.persistence.types.ParameterRole; +import org.onap.sdc.workflow.services.WorkflowVersionManager; +import org.onap.sdc.workflow.services.exceptions.EntityNotFoundException; +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.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; +import org.springframework.web.multipart.MultipartFile; + +@Service("workflowVersionManager") +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; + private final VersionStateMapper versionStateMapper; + private static final Logger LOGGER = LoggerFactory.getLogger(WorkflowVersionManagerImpl.class); + + @Autowired + public WorkflowVersionManagerImpl(VersioningManager versioningManager, ArtifactRepository artifactRepository, + VersionMapper versionMapper, VersionStateMapper versionStateMapper, ItemManager itemManager, + ParameterRepository parameterRepository) { + this.itemManager = itemManager; + this.versioningManager = versioningManager; + this.artifactRepository = artifactRepository; + this.parameterRepository = parameterRepository; + this.versionMapper = versionMapper; + this.versionStateMapper = versionStateMapper; + } + + @Override + public Collection list(String workflowId, Set stateFilter) { + Set versionStatusFilter = + stateFilter == null ? null : + stateFilter.stream().map(versionStateMapper::workflowVersionStateToVersionStatus) + .collect(Collectors.toSet()); + + return versioningManager.list(workflowId).stream() + .filter(version -> versionStatusFilter == null || versionStatusFilter.contains( + version.getStatus())) + .map(versionMapper::fromVersion) + .sorted(Comparator.comparing(WorkflowVersion::getName).reversed()) + .peek(workflowVersion -> loadAndAddParameters(workflowId, workflowVersion)) + .collect(Collectors.toList()); + } + + @Override + public WorkflowVersion get(String workflowId, String versionId) { + WorkflowVersion workflowVersion = versionMapper.fromVersion(getVersion(workflowId, versionId)); + loadAndAddParameters(workflowId, workflowVersion); + workflowVersion.setHasArtifact(artifactRepository.isExist(workflowId,versionId)); + return workflowVersion; + } + + @Override + public WorkflowVersion create(String workflowId, String baseVersionId, WorkflowVersion workflowVersion) { + validateWorkflowStatus(workflowId); + List versions = versioningManager.list(workflowId); + + if (baseVersionId != null) { + if (!workflowVersion.getInputs().isEmpty() || !workflowVersion.getOutputs().isEmpty()) { + throw new VersionCreationException(workflowId, baseVersionId, "Inputs/Outputs should not be supplied"); + } + validateVersionExistAndCertified(workflowId, versions, baseVersionId); + } else if (!versions.isEmpty()) { + throw new VersionCreationException(workflowId); + } + + Version version = new Version(); + version.setDescription(workflowVersion.getDescription()); + Version createdVersion = versioningManager.create(workflowId, baseVersionId, version, VersionCreationMethod.major); + + if (versions.isEmpty()) { // only for first versionId + artifactRepository.createStructure(workflowId, createdVersion.getId()); + parameterRepository.createStructure(workflowId, createdVersion.getId()); + updateParameters(workflowId, createdVersion.getId(), workflowVersion.getInputs(), workflowVersion.getOutputs()); + versioningManager.publish(workflowId, createdVersion.getId(), "Add initial data"); + } + + return get(workflowId, createdVersion.getId()); + } + + @Override + public void update(String workflowId, WorkflowVersion workflowVersion) { + validateWorkflowStatus(workflowId); + Version version = getVersion(workflowId, workflowVersion.getId()); + if (CERTIFIED.equals(versionStateMapper.versionStatusToWorkflowVersionState(version.getStatus()))) { + throw new VersionModificationException(workflowId, workflowVersion.getId()); + } + + versionMapper.toVersion(workflowVersion, version); + + updateParameters(workflowId, version.getId(), workflowVersion.getInputs(), workflowVersion.getOutputs()); + + versioningManager.update(workflowId, version.getId(), version); + + Version updatedVersion = versioningManager.get(workflowId, version.getId()); + if (updatedVersion.getState().isDirty()) { + versioningManager.publish(workflowId, version.getId(), "Update version"); + } + } + + + @Override + public WorkflowVersionState getState(String workflowId, String versionId) { + return versionStateMapper.versionStatusToWorkflowVersionState(getVersion(workflowId, versionId).getStatus()); + } + + @Override + 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.updateStatus(workflowId, versionId, VersionStatus.Certified, + String.format("Update version state to %s", newState.name())); + } catch (Exception submitException) { + throw new VersionStateModificationException(workflowId, versionId, currentState, newState, + submitException); + } + } else { + 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); + } + + try (InputStream artifactData = artifact.getInputStream()) { + ArtifactEntity artifactEntity = + new ArtifactEntity(StringUtils.cleanPath(artifact.getOriginalFilename()), artifactData); + artifactRepository.update(workflowId, versionId, artifactEntity); + Version updatedVersion = versioningManager.get(workflowId, versionId); + if(updatedVersion.getState().isDirty()) { + versioningManager.publish(workflowId, updatedVersion.getId(), "Update artifact"); + } + + } catch (IOException e) { + LOGGER.error(String.format("Upload Artifact failed for workflow id %s and version id %s", + workflowId, versionId),e); + throw new InvalidArtifactException(e.getMessage()); + } + } + + @Override + public ArtifactEntity getArtifact(String workflowId, String versionId) { + getVersion(workflowId, versionId); + Optional artifactOptional = artifactRepository.get(workflowId, versionId); + if (!artifactOptional.isPresent()) { + LOGGER.error("Workflow Version Artifact was not found for workflow id {} and version id {}", + workflowId, versionId); + throw new EntityNotFoundException( + String.format("Artifact for workflow id %s version id %s was not found", workflowId, versionId)); + } + return artifactOptional.get(); + } + + @Override + public void deleteArtifact(String workflowId, String versionId) { + validateWorkflowStatus(workflowId); + WorkflowVersion retrievedVersion = get(workflowId, versionId); + if (CERTIFIED.equals(retrievedVersion.getState())) { + LOGGER.error("Workflow Version is certified and can not be edited.Workflow id {} and version id {}", + workflowId, versionId); + throw new VersionModificationException(workflowId, versionId); + } + if(retrievedVersion.isHasArtifact()) { + artifactRepository.delete(workflowId, versionId); + versioningManager.publish(workflowId, versionId, "Delete Artifact"); + } + } + + private void validateVersionExistAndCertified(String workflowId, List versions, String versionId) { + Version baseVersion = findVersion(versions, versionId).orElseThrow( + () -> new EntityNotFoundException(String.format(VERSION_NOT_EXIST_MSG, versionId, workflowId))); + + if (CERTIFIED != versionStateMapper.versionStatusToWorkflowVersionState(baseVersion.getStatus())) { + throw new VersionCreationException(workflowId, versionId, "base version must be CERTIFIED"); + } + } + + private Version getVersion(String workflowId, String versionId) { + try { + Version version = versioningManager.get(workflowId, versionId); + if (version == null) { + throw new EntityNotFoundException(String.format(VERSION_NOT_EXIST_MSG, versionId, workflowId)); + } + return version; + } catch (Exception e) { + LOGGER.error(String.format( + "Workflow Version was not found.Workflow id %s and version id %s", workflowId, + versionId),e); + throw new EntityNotFoundException(String.format(VERSION_NOT_EXIST_MSG, versionId, workflowId)); + } + } + + private void updateParameters(String workflowId, String versionId, Collection inputs, + Collection outputs) { + updateVersionParameters(workflowId, versionId, ParameterRole.INPUT, inputs); + updateVersionParameters(workflowId, versionId, ParameterRole.OUTPUT, outputs); + } + + private void updateVersionParameters(String workflowId, String versionId, ParameterRole role, + Collection parameters) { + + Collection retrievedParams = parameterRepository.list(workflowId, versionId, role); + Map retrievedParamsByName = + retrievedParams.stream().collect(Collectors.toMap(ParameterEntity::getName, Function.identity())); + + Set namesOfParamsToKeep = new HashSet<>(); + for (ParameterEntity parameter : parameters) { + + ParameterEntity retrievedParam = retrievedParamsByName.get(parameter.getName()); + if (retrievedParam == null) { + parameterRepository.create(workflowId, versionId, role, parameter); + } else { + parameter.setId(retrievedParam.getId()); + parameterRepository.update(workflowId, versionId, role, parameter); + namesOfParamsToKeep.add(parameter.getName()); + } + } + + retrievedParams.stream().filter(retrievedParam -> !namesOfParamsToKeep.contains(retrievedParam.getName())) + .forEach(retrievedParam -> parameterRepository + .delete(workflowId, versionId, retrievedParam.getId())); + } + + private void loadAndAddParameters(String workflowId, WorkflowVersion workflowVersion) { + workflowVersion.setInputs(parameterRepository.list(workflowId, workflowVersion.getId(), ParameterRole.INPUT)); + workflowVersion.setOutputs(parameterRepository.list(workflowId, workflowVersion.getId(), ParameterRole.OUTPUT)); + } + + private static Optional findVersion(List versions, String versionId) { + return versions.stream().filter(version -> versionId.equals(version.getId())).findFirst(); + } + + 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/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/ActivitySpecMapper.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/ActivitySpecMapper.java new file mode 100644 index 00000000..09e96c3e --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/ActivitySpecMapper.java @@ -0,0 +1,61 @@ +/* + * 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.impl.mappers; + +import static org.onap.sdc.workflow.services.ActivitySpecConstant.CATEGORY_ATTRIBUTE_NAME; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.mapstruct.InheritInverseConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.MappingTarget; +import org.onap.sdc.common.versioning.services.types.Item; +import org.onap.sdc.common.versioning.services.types.VersionStatus; +import org.onap.sdc.workflow.persistence.types.ActivitySpecEntity; +import org.onap.sdc.workflow.services.ActivitySpecConstant; +import org.onap.sdc.workflow.services.impl.ItemType; + +@Mapper(componentModel = "spring", imports = {ItemType.class, ActivitySpecConstant.class}) +public interface ActivitySpecMapper { + + @Mapping(source = "versionStatusCounters", target = "status") + @Mapping(source = "properties", target = "categoryList") + ActivitySpecEntity itemToActivitySpec(Item item); + + @InheritInverseConfiguration + @Mapping(expression = "java(ItemType.ACTIVITYSPEC.name())", target = "type") + @Mapping(target = "versionStatusCounters", ignore = true) + @Mapping(target = "status", ignore = true) + @Mapping(source = "categoryList", target = "properties") + void toItem(ActivitySpecEntity activitySpec, @MappingTarget Item retrievedItem); + + default String versionStatusCountersToStatus(Map versionStatusCounters) { + return versionStatusCounters.keySet().stream().findFirst().map(Enum::name).orElse(null); + } + + default Map categoriesToProperties(List categories) { + Map properties = new HashMap<>(); + properties.put(CATEGORY_ATTRIBUTE_NAME, categories); + return properties; + } + + default List propertiesToCategories(Map properties) { + return (List) properties.get(CATEGORY_ATTRIBUTE_NAME); + } +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/ArchivingStatusMapper.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/ArchivingStatusMapper.java new file mode 100644 index 00000000..702815f6 --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/ArchivingStatusMapper.java @@ -0,0 +1,36 @@ +/* + * 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.impl.mappers; + +import org.mapstruct.InheritInverseConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.ValueMapping; +import org.onap.sdc.common.versioning.services.types.ItemStatus; +import org.onap.sdc.workflow.services.types.ArchivingStatus; + +@Mapper(componentModel = "spring") +public interface ArchivingStatusMapper { + + @ValueMapping(source = "ACTIVE", target = "ACTIVE") + @ValueMapping(source = "ARCHIVED", target = "ARCHIVED") + @ValueMapping(source = "", target = "ACTIVE") + ArchivingStatus fromItemStatus(ItemStatus status); + + @InheritInverseConfiguration + ItemStatus toItemStatus(ArchivingStatus status); + +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/VersionMapper.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/VersionMapper.java new file mode 100644 index 00000000..145c79fe --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/VersionMapper.java @@ -0,0 +1,45 @@ +/* + * 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.impl.mappers; + +import org.mapstruct.InheritInverseConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.MappingTarget; +import org.onap.sdc.common.versioning.services.convertors.VersionConvertor; +import org.onap.sdc.common.versioning.services.types.Version; +import org.onap.sdc.workflow.services.impl.ItemType; +import org.onap.sdc.workflow.services.types.WorkflowVersion; + +@Mapper(componentModel = "spring", uses = VersionStateMapper.class) +public interface VersionMapper extends VersionConvertor { + + @Override + default String getItemType(){ + return ItemType.WORKFLOW.name(); + } + + @Override + @Mapping(source = "status", target = "state") + WorkflowVersion fromVersion(Version version); + + @Override + @InheritInverseConfiguration + @Mapping(target = "status", ignore = true) + void toVersion(WorkflowVersion workflowVersion, @MappingTarget Version retrievedVersion); + +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/VersionStateMapper.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/VersionStateMapper.java new file mode 100644 index 00000000..05772f4f --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/VersionStateMapper.java @@ -0,0 +1,46 @@ +/* + * 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.impl.mappers; + +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; +import org.mapstruct.InheritInverseConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.ValueMapping; +import org.onap.sdc.common.versioning.services.types.VersionStatus; +import org.onap.sdc.workflow.services.types.WorkflowVersionState; + +@Mapper(componentModel = "spring") +public interface VersionStateMapper { + + @ValueMapping(source = "Certified", target = "CERTIFIED") + @ValueMapping(source = "Draft", target = "DRAFT") + @ValueMapping(source = "", target = "DRAFT") + WorkflowVersionState versionStatusToWorkflowVersionState(VersionStatus status); + + @InheritInverseConfiguration + VersionStatus workflowVersionStateToVersionStatus(WorkflowVersionState status); + + default Set versionStatusCountersToWorkflowVersionStates( + Map versionStatusCounters) { + return versionStatusCounters.keySet().stream().map(this::versionStatusToWorkflowVersionState) + .collect(Collectors.toSet()); + } + + +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/WorkflowMapper.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/WorkflowMapper.java new file mode 100644 index 00000000..214d2ac6 --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/impl/mappers/WorkflowMapper.java @@ -0,0 +1,49 @@ +/* + * 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.impl.mappers; + +import org.mapstruct.InheritInverseConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.MappingTarget; +import org.onap.sdc.common.versioning.services.convertors.ItemConvertor; +import org.onap.sdc.common.versioning.services.types.Item; +import org.onap.sdc.workflow.services.impl.ItemType; +import org.onap.sdc.workflow.services.types.Workflow; + +@Mapper(componentModel = "spring", imports = ItemType.class, + uses = {VersionStateMapper.class, ArchivingStatusMapper.class}) +public interface WorkflowMapper extends ItemConvertor { + + @Override + default String getItemType() { + return ItemType.WORKFLOW.name(); + } + + @Override + @Mapping(source = "versionStatusCounters", target = "versionStates") + @Mapping(source = "status", target = "archiving") + Workflow fromItem(Item item); + + @Override + @InheritInverseConfiguration + @Mapping(target = "status", ignore = true) + @Mapping(target = "versionStatusCounters", ignore = true) + @Mapping(expression = "java(ItemType.WORKFLOW.name())", target = "type") + void toItem(Workflow workflow, @MappingTarget Item item); + +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/ArchivingStatus.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/ArchivingStatus.java new file mode 100644 index 00000000..2e7eb22b --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/ArchivingStatus.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 ArchivingStatus { + ARCHIVED, + ACTIVE +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/Page.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/Page.java new file mode 100644 index 00000000..3fc9d0ba --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/Page.java @@ -0,0 +1,34 @@ +/* + * 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; + +import java.util.List; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor +public class Page { + + private Paging paging; + private List items; + + public Page(List items, PagingRequest pagingRequest, int total) { + this.items = items; + this.paging = new Paging(pagingRequest, items.size(), total); + } +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/Paging.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/Paging.java new file mode 100644 index 00000000..2c4124fa --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/Paging.java @@ -0,0 +1,41 @@ +/* + * Copyright © 2016-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; + +import lombok.Getter; + +@Getter +public class Paging { + + private int offset; + private int limit; + private int count; + private boolean hasMore; + private int total; + + public Paging(PagingRequest pagingRequest, int count, int total) { + this.offset = pagingRequest.getOffset(); + this.limit = pagingRequest.getLimit(); + this.count = count; + setTotal(total); + } + + private void setTotal(int total) { + this.total = total; + this.hasMore = total > offset + limit; + } +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/PagingConstants.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/PagingConstants.java new file mode 100644 index 00000000..214e7ea2 --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/PagingConstants.java @@ -0,0 +1,28 @@ +/* + * Copyright © 2016-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 class PagingConstants { + + public static final int DEFAULT_OFFSET = 0; + public static final int DEFAULT_LIMIT = 200; + public static final int MAX_LIMIT = 2000; + + private PagingConstants() { + throw new IllegalStateException("Constants class"); + } +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/PagingRequest.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/PagingRequest.java new file mode 100644 index 00000000..6408ee69 --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/PagingRequest.java @@ -0,0 +1,39 @@ +/* + * 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; + +import lombok.Getter; + +@Getter +public class PagingRequest { + + private Integer offset; + private Integer limit; + + public PagingRequest(int offset, int limit) { + setOffset(offset); + setLimit(limit); + } + + public void setOffset(int offset) { + this.offset = offset < 0 ? null : offset; + } + + public void setLimit(int limit) { + this.limit = limit <= 0 ? null : limit; + } +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/RequestSpec.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/RequestSpec.java new file mode 100644 index 00000000..06ebdf1c --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/RequestSpec.java @@ -0,0 +1,28 @@ +/* + * 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; + +import lombok.AllArgsConstructor; +import lombok.Data; + +@Data +@AllArgsConstructor +public class RequestSpec { + + private PagingRequest paging; + private SortingRequest sorting; +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/Sort.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/Sort.java new file mode 100644 index 00000000..b26ef1cb --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/Sort.java @@ -0,0 +1,30 @@ +/* + * 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; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; + +@Getter +@EqualsAndHashCode +@AllArgsConstructor +public class Sort { + + private String property; + private boolean ascendingOrder; +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/SortingRequest.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/SortingRequest.java new file mode 100644 index 00000000..cd8b2c27 --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/SortingRequest.java @@ -0,0 +1,30 @@ +/* + * 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; + +import java.util.List; +import lombok.Builder; +import lombok.Getter; +import lombok.Singular; + +@Builder +@Getter +public class SortingRequest { + + @Singular + private List sorts; +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/Workflow.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/Workflow.java new file mode 100644 index 00000000..fcac779f --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/Workflow.java @@ -0,0 +1,45 @@ +/* + * 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; + + +import static org.onap.sdc.workflow.services.types.WorkflowValidationConstants.MAX_LENGTH; +import static org.onap.sdc.workflow.services.types.WorkflowValidationConstants.MIN_LENGTH; + +import java.util.Collection; +import java.util.Set; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.Pattern; +import javax.validation.constraints.Size; +import lombok.Data; + + +@Data +public class Workflow { + + private String id; + @NotBlank(message = "Workflow name may not be blank.") + @Size(min = MIN_LENGTH, max = MAX_LENGTH, + message = "Workflow name must be at least " + MIN_LENGTH + " characters, and no more than " + MAX_LENGTH + + " characters.") + @Pattern(regexp = "[A-Za-z0-9_. -]+", message = "Workflow name must contain only letters, digits and underscores.") + private String name; + private String description; + private Set versionStates; + private Collection versions; + private ArchivingStatus archiving; +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/WorkflowValidationConstants.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/WorkflowValidationConstants.java new file mode 100644 index 00000000..2d54c7b8 --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/WorkflowValidationConstants.java @@ -0,0 +1,23 @@ +/* + * Copyright © 2016-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 class WorkflowValidationConstants { + + public static final int MAX_LENGTH = 80; + public static final int MIN_LENGTH = 6; +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/WorkflowVersion.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/WorkflowVersion.java new file mode 100644 index 00000000..0699157f --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/WorkflowVersion.java @@ -0,0 +1,46 @@ +/* + * 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; + +import java.util.Collection; +import java.util.Collections; +import java.util.Date; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.onap.sdc.workflow.persistence.types.ParameterEntity; + + +@Data +@NoArgsConstructor +public class WorkflowVersion { + + private String id; + private String name; + private String description; + private String baseId; + private WorkflowVersionState state; + private Collection inputs = Collections.emptyList(); + private Collection outputs = Collections.emptyList(); + private boolean hasArtifact; + private Date creationTime; + private Date modificationTime; + + public WorkflowVersion(String id) { + this.id = id; + this.state = WorkflowVersionState.DRAFT; + } +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/WorkflowVersionState.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/WorkflowVersionState.java new file mode 100644 index 00000000..cccdd5c7 --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/types/WorkflowVersionState.java @@ -0,0 +1,36 @@ +/* + * 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; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +public enum WorkflowVersionState { + + CERTIFIED, DRAFT(CERTIFIED); + + private final List nextStates; + + WorkflowVersionState(WorkflowVersionState... nextStates) { + this.nextStates = Collections.unmodifiableList(Arrays.asList(nextStates)); + } + + public List getNextStates() { + return nextStates; + } +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/utilities/JsonUtil.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/utilities/JsonUtil.java new file mode 100644 index 00000000..3e197a9f --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/services/utilities/JsonUtil.java @@ -0,0 +1,96 @@ +/* + * 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.utilities; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonIOException; +import com.google.gson.JsonSyntaxException; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.io.StringReader; + +public class JsonUtil { + + private static final Gson gson = new Gson(); + + private JsonUtil() { + } + + /** + * Object 2 json string. + * + * @param obj the obj + * @return the string + */ + public static String object2Json(Object obj) { + return sbObject2Json(obj).toString(); + + } + + /** + * Sb object 2 json string builder. + * + * @param obj the obj + * @return the string builder + */ + public static StringBuilder sbObject2Json(Object obj) { + return new StringBuilder(new GsonBuilder().setPrettyPrinting().create().toJson(obj)); + } + + /** + * Json 2 object t. + * + * @param the type parameter + * @param json the json + * @param classOfT the class of t + * @return the t + */ + public static T json2Object(String json, Class classOfT) { + T typ; + try { + try (Reader br = new StringReader(json)) { + typ = gson.fromJson(br, classOfT); + } + } catch (JsonIOException | JsonSyntaxException | IOException exception) { + throw new RuntimeException(exception); + } + return typ; + } + + /** + * Json 2 object t. + * + * @param the type parameter + * @param is the is + * @param classOfT the class of t + * @return the t + */ + public static T json2Object(InputStream is, Class classOfT) { + T type; + try (Reader br = new BufferedReader(new InputStreamReader(is))) { + type = new Gson().fromJson(br, classOfT); + } catch (JsonIOException | JsonSyntaxException | IOException exception) { + throw new RuntimeException(exception); + } + return type; + } + +} -- cgit 1.2.3-korg