From 894285bfa9ccacde35b1e94e07856b53971e2559 Mon Sep 17 00:00:00 2001 From: sheetalm Date: Thu, 12 Apr 2018 13:20:36 +0530 Subject: Activity Spec - change in package and group names 1 Package structure will now be org.onap.sdc.activityspec instead of org.openecomp.activityspec 2 Same applies for group names 3 This is done to fix issue with pushing docker images to nexus repository 4 In ONAP in order for you to push to nexus you need to match the package and artifact name to the repository Change-Id: I1266c66fa0d0a85acd9ca1164647b996433eb960 Issue-ID: SDC-1048 Signed-off-by: sheetalm --- services/activity-spec/activity-spec-init/pom.xml | 2 +- .../activity-spec-api-docs/pom.xml | 2 +- .../activity-spec-service/pom.xml | 2 +- .../sdc/activityspec/api/rest/ActivitySpecs.java | 77 ++++ .../rest/mapping/MapActivityParameterToDto.java | 31 ++ ...ActivitySpecRequestDtoToActivitySpecEntity.java | 54 +++ ...apActivitySpecToActivitySpecCreateResponse.java | 33 ++ .../MapActivitySpecToActivitySpecGetResponse.java | 52 +++ .../rest/mapping/MapDtoToActivityParameter.java | 31 ++ .../api/rest/mapping/MapItemToListResponseDto.java | 45 +++ .../api/rest/services/ActivitySpecsImpl.java | 114 ++++++ .../api/rest/types/ActivitySpecAction.java | 21 ++ .../rest/types/ActivitySpecActionRequestDto.java | 23 ++ .../api/rest/types/ActivitySpecCreateResponse.java | 25 ++ .../api/rest/types/ActivitySpecGetResponse.java | 32 ++ .../rest/types/ActivitySpecListResponseDto.java | 29 ++ .../api/rest/types/ActivitySpecParameterDto.java | 25 ++ .../api/rest/types/ActivitySpecRequestDto.java | 39 ++ .../api/rest/types/InternalEmptyObject.java | 27 ++ .../filters/ActivitySpecSessionContextFilter.java | 82 +++++ .../listeners/ActivitySpecAppStartupListener.java | 43 +++ .../sdc/activityspec/be/ActivitySpecManager.java | 36 ++ .../sdc/activityspec/be/dao/ActivitySpecDao.java | 28 ++ .../be/dao/impl/ActivitySpecDaoZusammenImpl.java | 148 ++++++++ .../be/dao/types/ActivitySpecEntity.java | 40 +++ .../be/datatypes/ActivitySpecData.java | 30 ++ .../be/datatypes/ActivitySpecParameter.java | 35 ++ .../sdc/activityspec/be/datatypes/ElementType.java | 21 ++ .../sdc/activityspec/be/datatypes/ItemType.java | 21 ++ .../be/impl/ActivitySpecManagerImpl.java | 265 ++++++++++++++ .../errors/ActivitySpecErrorResponse.java | 31 ++ .../errors/ActivitySpecNotFoundException.java | 24 ++ .../errors/DefaultExceptionMapper.java | 96 +++++ .../activityspec/utils/ActivitySpecConstant.java | 32 ++ .../activityspec/api/rest/ActivitySpecs.java | 84 ----- .../rest/mapping/MapActivityParameterToDto.java | 31 -- ...ActivitySpecRequestDtoToActivitySpecEntity.java | 53 --- ...apActivitySpecToActivitySpecCreateResponse.java | 32 -- .../MapActivitySpecToActivitySpecGetResponse.java | 51 --- .../rest/mapping/MapDtoToActivityParameter.java | 31 -- .../api/rest/mapping/MapItemToListResponseDto.java | 45 --- .../api/rest/services/ActivitySpecsImpl.java | 117 ------ .../api/rest/types/ActivitySpecAction.java | 23 -- .../rest/types/ActivitySpecActionRequestDto.java | 22 -- .../api/rest/types/ActivitySpecCreateResponse.java | 24 -- .../api/rest/types/ActivitySpecGetResponse.java | 31 -- .../rest/types/ActivitySpecListResponseDto.java | 28 -- .../api/rest/types/ActivitySpecParameterDto.java | 24 -- .../api/rest/types/ActivitySpecRequestDto.java | 39 -- .../api/rest/types/InternalEmptyObject.java | 27 -- .../filters/ActivitySpecSessionContextFilter.java | 83 ----- .../listeners/ActivitySpecAppStartupListener.java | 44 --- .../activityspec/be/ActivitySpecManager.java | 36 -- .../activityspec/be/dao/ActivitySpecDao.java | 27 -- .../be/dao/impl/ActivitySpecDaoZusammenImpl.java | 155 -------- .../be/dao/types/ActivitySpecEntity.java | 39 -- .../be/datatypes/ActivitySpecData.java | 29 -- .../be/datatypes/ActivitySpecParameter.java | 34 -- .../activityspec/be/datatypes/ElementType.java | 21 -- .../activityspec/be/datatypes/ItemType.java | 21 -- .../be/impl/ActivitySpecManagerImpl.java | 291 --------------- .../errors/ActivitySpecErrorResponse.java | 30 -- .../errors/ActivitySpecNotFoundException.java | 24 -- .../errors/DefaultExceptionMapper.java | 99 ----- .../activityspec/utils/ActivitySpecConstant.java | 32 -- .../dao/impl/ActivitySpecZusammenDaoImplTest.java | 368 +++++++++++++++++++ .../be/impl/ActivitySpecManagerImplTest.java | 302 ++++++++++++++++ .../dao/impl/ActivitySpecZusammenDaoImplTest.java | 400 --------------------- .../be/impl/ActivitySpecManagerImplTest.java | 318 ---------------- .../activity-spec-web/activity-spec-war/pom.xml | 6 +- .../src/main/webapp/WEB-INF/beans-services.xml | 8 +- .../src/main/webapp/WEB-INF/web.xml | 4 +- services/activity-spec/activity-spec-web/pom.xml | 2 +- services/activity-spec/pom.xml | 2 +- 74 files changed, 2273 insertions(+), 2360 deletions(-) create mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/ActivitySpecs.java create mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/mapping/MapActivityParameterToDto.java create mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/mapping/MapActivitySpecRequestDtoToActivitySpecEntity.java create mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/mapping/MapActivitySpecToActivitySpecCreateResponse.java create mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/mapping/MapActivitySpecToActivitySpecGetResponse.java create mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/mapping/MapDtoToActivityParameter.java create mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/mapping/MapItemToListResponseDto.java create mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/services/ActivitySpecsImpl.java create mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/types/ActivitySpecAction.java create mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/types/ActivitySpecActionRequestDto.java create mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/types/ActivitySpecCreateResponse.java create mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/types/ActivitySpecGetResponse.java create mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/types/ActivitySpecListResponseDto.java create mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/types/ActivitySpecParameterDto.java create mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/types/ActivitySpecRequestDto.java create mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/types/InternalEmptyObject.java create mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/server/filters/ActivitySpecSessionContextFilter.java create mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/server/listeners/ActivitySpecAppStartupListener.java create mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/be/ActivitySpecManager.java create mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/be/dao/ActivitySpecDao.java create mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/be/dao/impl/ActivitySpecDaoZusammenImpl.java create mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/be/dao/types/ActivitySpecEntity.java create mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/be/datatypes/ActivitySpecData.java create mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/be/datatypes/ActivitySpecParameter.java create mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/be/datatypes/ElementType.java create mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/be/datatypes/ItemType.java create mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/be/impl/ActivitySpecManagerImpl.java create mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/errors/ActivitySpecErrorResponse.java create mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/errors/ActivitySpecNotFoundException.java create mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/errors/DefaultExceptionMapper.java create mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/utils/ActivitySpecConstant.java delete mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/ActivitySpecs.java delete mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/mapping/MapActivityParameterToDto.java delete mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/mapping/MapActivitySpecRequestDtoToActivitySpecEntity.java delete mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/mapping/MapActivitySpecToActivitySpecCreateResponse.java delete mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/mapping/MapActivitySpecToActivitySpecGetResponse.java delete mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/mapping/MapDtoToActivityParameter.java delete mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/mapping/MapItemToListResponseDto.java delete mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/services/ActivitySpecsImpl.java delete mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/types/ActivitySpecAction.java delete mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/types/ActivitySpecActionRequestDto.java delete mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/types/ActivitySpecCreateResponse.java delete mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/types/ActivitySpecGetResponse.java delete mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/types/ActivitySpecListResponseDto.java delete mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/types/ActivitySpecParameterDto.java delete mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/types/ActivitySpecRequestDto.java delete mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/types/InternalEmptyObject.java delete mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/server/filters/ActivitySpecSessionContextFilter.java delete mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/server/listeners/ActivitySpecAppStartupListener.java delete mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/ActivitySpecManager.java delete mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/dao/ActivitySpecDao.java delete mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/dao/impl/ActivitySpecDaoZusammenImpl.java delete mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/dao/types/ActivitySpecEntity.java delete mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/datatypes/ActivitySpecData.java delete mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/datatypes/ActivitySpecParameter.java delete mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/datatypes/ElementType.java delete mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/datatypes/ItemType.java delete mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/impl/ActivitySpecManagerImpl.java delete mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/errors/ActivitySpecErrorResponse.java delete mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/errors/ActivitySpecNotFoundException.java delete mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/errors/DefaultExceptionMapper.java delete mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/utils/ActivitySpecConstant.java create mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/test/java/org/onap/sdc/activityspec/be/dao/impl/ActivitySpecZusammenDaoImplTest.java create mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/test/java/org/onap/sdc/activityspec/be/impl/ActivitySpecManagerImplTest.java delete mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/test/java/org/openecomp/activityspec/be/dao/impl/ActivitySpecZusammenDaoImplTest.java delete mode 100644 services/activity-spec/activity-spec-web/activity-spec-service/src/test/java/org/openecomp/activityspec/be/impl/ActivitySpecManagerImplTest.java (limited to 'services/activity-spec') diff --git a/services/activity-spec/activity-spec-init/pom.xml b/services/activity-spec/activity-spec-init/pom.xml index 7873876846..2d41c9e310 100644 --- a/services/activity-spec/activity-spec-init/pom.xml +++ b/services/activity-spec/activity-spec-init/pom.xml @@ -8,7 +8,7 @@ pom - org.openecomp.activityspec + org.onap.sdc.activityspec activity-spec 1.2.0-SNAPSHOT diff --git a/services/activity-spec/activity-spec-web/activity-spec-api-docs/pom.xml b/services/activity-spec/activity-spec-web/activity-spec-api-docs/pom.xml index b920b91860..392704781b 100644 --- a/services/activity-spec/activity-spec-web/activity-spec-api-docs/pom.xml +++ b/services/activity-spec/activity-spec-web/activity-spec-api-docs/pom.xml @@ -8,7 +8,7 @@ pom - org.openecomp.activityspec + org.onap.sdc.activityspec activity-spec 1.2.0-SNAPSHOT ../.. diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/pom.xml b/services/activity-spec/activity-spec-web/activity-spec-service/pom.xml index 12bb3ca99d..49cb3f4ee7 100644 --- a/services/activity-spec/activity-spec-web/activity-spec-service/pom.xml +++ b/services/activity-spec/activity-spec-web/activity-spec-service/pom.xml @@ -7,7 +7,7 @@ activity-spec-service - org.openecomp.activityspec + org.onap.sdc.activityspec activity-spec 1.2.0-SNAPSHOT ../.. diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/ActivitySpecs.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/ActivitySpecs.java new file mode 100644 index 0000000000..06b85246af --- /dev/null +++ b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/ActivitySpecs.java @@ -0,0 +1,77 @@ +/* + * 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.activityspec.api.rest; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import org.onap.sdc.activityspec.api.rest.types.ActivitySpecActionRequestDto; +import org.onap.sdc.activityspec.api.rest.types.ActivitySpecRequestDto; +import org.springframework.validation.annotation.Validated; + +import javax.validation.Valid; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +@Path("/v1.0/activity-spec/") +@Produces(MediaType.APPLICATION_JSON) +@Consumes(MediaType.APPLICATION_JSON) +@Api(value = "Activity Specs") +@Validated +public interface ActivitySpecs { + + @POST + @Path("/") + @ApiOperation(value = "Create Activity Spec") + Response createActivitySpec(@Valid ActivitySpecRequestDto request); + + @GET + @Path("/{id}/versions/{versionId}") + @ApiOperation(value = "Get Activity Spec") + Response getActivitySpec(@ApiParam(value = "Activity Spec Id") @PathParam("id") String id, + @ApiParam(value = "Version Id") @PathParam("versionId") String versionId); + + @PUT + @Path("/{id}/versions/{versionId}") + @ApiOperation(value = "Update Activity Spec") + Response updateActivitySpec(@Valid ActivitySpecRequestDto request, + @ApiParam(value = "Activity Spec Id") @PathParam("id") String id, + @ApiParam(value = "Version Id") @PathParam("versionId") String versionId); + + @PUT + @Path("/{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.") + Response actOnActivitySpec(ActivitySpecActionRequestDto request, + @ApiParam(value = "Activity Spec Id") @PathParam("id") String id, + @ApiParam(value = "Version Id") @PathParam("versionId") String versionId); + + @GET + @Path("/") + @ApiOperation(value = "Get list of activity specs ", responseContainer = "List") + Response list(@ApiParam(value = "List activity specs based on status filter") @QueryParam("status") + String versionStatus); +} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/mapping/MapActivityParameterToDto.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/mapping/MapActivityParameterToDto.java new file mode 100644 index 0000000000..acf3ef4727 --- /dev/null +++ b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/mapping/MapActivityParameterToDto.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.activityspec.api.rest.mapping; + +import org.onap.sdc.activityspec.api.rest.types.ActivitySpecParameterDto; +import org.onap.sdc.activityspec.be.datatypes.ActivitySpecParameter; +import org.openecomp.sdcrests.mapping.MappingBase; + +public class MapActivityParameterToDto extends MappingBase { + + @Override + public void doMapping(ActivitySpecParameter source, ActivitySpecParameterDto target) { + target.setName(source.getName()); + target.setType(source.getType()); + target.setValue(source.getValue()); + } +} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/mapping/MapActivitySpecRequestDtoToActivitySpecEntity.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/mapping/MapActivitySpecRequestDtoToActivitySpecEntity.java new file mode 100644 index 0000000000..aedb4edb5a --- /dev/null +++ b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/mapping/MapActivitySpecRequestDtoToActivitySpecEntity.java @@ -0,0 +1,54 @@ +/* + * 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.activityspec.api.rest.mapping; + +import java.util.ArrayList; + +import org.onap.sdc.activityspec.api.rest.types.ActivitySpecRequestDto; +import org.onap.sdc.activityspec.be.dao.types.ActivitySpecEntity; +import org.onap.sdc.activityspec.be.datatypes.ActivitySpecParameter; +import org.openecomp.sdcrests.mapping.MappingBase; + +import java.util.Objects; +import java.util.stream.Collectors; + +public class MapActivitySpecRequestDtoToActivitySpecEntity + extends MappingBase { + + @Override + public void doMapping(ActivitySpecRequestDto source, ActivitySpecEntity target) { + target.setName(source.getName()); + target.setDescription(source.getDescription()); + target.setCategoryList(source.getCategoryList() == null ? new ArrayList<>() : source.getCategoryList()); + if (Objects.nonNull(source.getInputs())) { + target.setInputs(source.getInputs().stream().map(activitySpecParameterDto -> new MapDtoToActivityParameter() + .applyMapping( + activitySpecParameterDto, + ActivitySpecParameter.class)) + .collect(Collectors.toList())); + } + if (Objects.nonNull(source.getOutputs())) { + target.setOutputs(source.getOutputs().stream() + .map(activitySpecParameterDto -> new MapDtoToActivityParameter() + .applyMapping(activitySpecParameterDto, + ActivitySpecParameter.class)) + .collect(Collectors.toList())); + } + target.setType(source.getType()); + target.setContent(source.getContent()); + } +} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/mapping/MapActivitySpecToActivitySpecCreateResponse.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/mapping/MapActivitySpecToActivitySpecCreateResponse.java new file mode 100644 index 0000000000..0568ef1192 --- /dev/null +++ b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/mapping/MapActivitySpecToActivitySpecCreateResponse.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.activityspec.api.rest.mapping; + +import java.util.Objects; + +import org.onap.sdc.activityspec.be.dao.types.ActivitySpecEntity; +import org.onap.sdc.activityspec.api.rest.types.ActivitySpecCreateResponse; +import org.openecomp.sdcrests.mapping.MappingBase; + +public class MapActivitySpecToActivitySpecCreateResponse + extends MappingBase { + + @Override + public void doMapping(ActivitySpecEntity source, ActivitySpecCreateResponse target) { + target.setId(source.getId()); + target.setVersionId(Objects.nonNull(source.getVersion()) ? source.getVersion().getId() : null); + } +} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/mapping/MapActivitySpecToActivitySpecGetResponse.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/mapping/MapActivitySpecToActivitySpecGetResponse.java new file mode 100644 index 0000000000..fb4fb18d38 --- /dev/null +++ b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/mapping/MapActivitySpecToActivitySpecGetResponse.java @@ -0,0 +1,52 @@ +/* + * 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.activityspec.api.rest.mapping; + +import org.onap.sdc.activityspec.api.rest.types.ActivitySpecParameterDto; +import org.onap.sdc.activityspec.be.dao.types.ActivitySpecEntity; +import org.onap.sdc.activityspec.api.rest.types.ActivitySpecGetResponse; +import org.openecomp.sdcrests.mapping.MappingBase; + +import java.util.Objects; +import java.util.stream.Collectors; + +public class MapActivitySpecToActivitySpecGetResponse extends MappingBase { + + @Override + public void doMapping(ActivitySpecEntity source, ActivitySpecGetResponse target) { + target.setName(source.getName()); + target.setDescription(source.getDescription()); + target.setCategoryList(source.getCategoryList()); + if (Objects.nonNull(source.getInputs())) { + target.setInputs(source.getInputs().stream().map(activitySpecParameter -> new MapActivityParameterToDto() + .applyMapping( + activitySpecParameter, + ActivitySpecParameterDto.class)) + .collect(Collectors.toList())); + } + if (Objects.nonNull(source.getOutputs())) { + target.setOutputs(source.getOutputs().stream().map(activitySpecParameter -> new MapActivityParameterToDto() + .applyMapping( + activitySpecParameter, + ActivitySpecParameterDto.class)) + .collect(Collectors.toList())); + } + target.setStatus(source.getStatus()); + target.setType(source.getType()); + target.setContent(source.getContent()); + } +} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/mapping/MapDtoToActivityParameter.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/mapping/MapDtoToActivityParameter.java new file mode 100644 index 0000000000..051cbbd92d --- /dev/null +++ b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/mapping/MapDtoToActivityParameter.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.activityspec.api.rest.mapping; + +import org.onap.sdc.activityspec.be.datatypes.ActivitySpecParameter; +import org.onap.sdc.activityspec.api.rest.types.ActivitySpecParameterDto; +import org.openecomp.sdcrests.mapping.MappingBase; + +public class MapDtoToActivityParameter extends MappingBase { + + @Override + public void doMapping(ActivitySpecParameterDto source, ActivitySpecParameter target) { + target.setName(source.getName()); + target.setType(source.getType()); + target.setValue(source.getValue()); + } +} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/mapping/MapItemToListResponseDto.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/mapping/MapItemToListResponseDto.java new file mode 100644 index 0000000000..2671c9771e --- /dev/null +++ b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/mapping/MapItemToListResponseDto.java @@ -0,0 +1,45 @@ +/* + * 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.activityspec.api.rest.mapping; + +import org.onap.sdc.activityspec.api.rest.types.ActivitySpecListResponseDto; +import org.openecomp.sdc.versioning.dao.types.VersionStatus; +import org.openecomp.sdc.versioning.types.Item; +import org.openecomp.sdcrests.mapping.MappingBase; + +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; + +import static org.onap.sdc.activityspec.utils.ActivitySpecConstant.CATEGORY_ATTRIBUTE_NAME; + +public class MapItemToListResponseDto extends MappingBase { + + @Override + public void doMapping(Item source, ActivitySpecListResponseDto target) { + target.setId(source.getId()); + target.setName(source.getName()); + target.setCategoryList((List) source.getProperties().get(CATEGORY_ATTRIBUTE_NAME)); + final Map versionStatusCounters = source.getVersionStatusCounters(); + if (Objects.nonNull(versionStatusCounters) && !versionStatusCounters.isEmpty()) { + final Set versionStatuses = versionStatusCounters.keySet(); + target.setStatus(versionStatuses.stream().findFirst().isPresent() + ? versionStatuses.stream().findFirst().get().name() : null); + } + } +} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/services/ActivitySpecsImpl.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/services/ActivitySpecsImpl.java new file mode 100644 index 0000000000..e0eec80fcb --- /dev/null +++ b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/services/ActivitySpecsImpl.java @@ -0,0 +1,114 @@ +/* + * 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.activityspec.api.rest.services; + +import org.onap.sdc.activityspec.api.rest.ActivitySpecs; +import org.onap.sdc.activityspec.api.rest.mapping.MapActivitySpecRequestDtoToActivitySpecEntity; +import org.onap.sdc.activityspec.api.rest.mapping.MapActivitySpecToActivitySpecCreateResponse; +import org.onap.sdc.activityspec.api.rest.mapping.MapActivitySpecToActivitySpecGetResponse; +import org.onap.sdc.activityspec.api.rest.mapping.MapItemToListResponseDto; +import org.onap.sdc.activityspec.api.rest.types.ActivitySpecActionRequestDto; +import org.onap.sdc.activityspec.api.rest.types.ActivitySpecGetResponse; +import org.onap.sdc.activityspec.api.rest.types.ActivitySpecListResponseDto; +import org.onap.sdc.activityspec.api.rest.types.ActivitySpecRequestDto; +import org.onap.sdc.activityspec.api.rest.types.InternalEmptyObject; +import org.onap.sdc.activityspec.be.ActivitySpecManager; +import org.onap.sdc.activityspec.be.dao.types.ActivitySpecEntity; +import org.onap.sdc.activityspec.be.impl.ActivitySpecManagerImpl; +import org.onap.sdc.activityspec.api.rest.types.ActivitySpecCreateResponse; +import org.onap.sdc.activityspec.be.dao.impl.ActivitySpecDaoZusammenImpl; +import org.openecomp.core.dao.UniqueValueDaoFactory; +import org.openecomp.core.zusammen.api.ZusammenAdaptorFactory; +import org.openecomp.sdc.versioning.ItemManagerFactory; +import org.openecomp.sdc.versioning.VersioningManagerFactory; +import org.openecomp.sdc.versioning.dao.types.Version; + +import org.openecomp.sdcrests.wrappers.GenericCollectionWrapper; +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; + +import javax.ws.rs.core.Response; + +@Service("activitySpecs") +@Validated +public class ActivitySpecsImpl implements ActivitySpecs { + + + private final ActivitySpecManager activitySpecManager = + new ActivitySpecManagerImpl(ItemManagerFactory.getInstance().createInterface(), + VersioningManagerFactory.getInstance().createInterface(), + new ActivitySpecDaoZusammenImpl(ZusammenAdaptorFactory.getInstance() + .createInterface()), + UniqueValueDaoFactory.getInstance().createInterface()); + + @Override + public Response createActivitySpec(ActivitySpecRequestDto request) { + ActivitySpecEntity activitySpec = + new MapActivitySpecRequestDtoToActivitySpecEntity().applyMapping(request, ActivitySpecEntity.class); + + activitySpec = activitySpecManager.createActivitySpec(activitySpec); + ActivitySpecCreateResponse createActivitySpecResponse = new MapActivitySpecToActivitySpecCreateResponse() + .applyMapping(activitySpec, + ActivitySpecCreateResponse.class); + + return Response.ok(createActivitySpecResponse).build(); + } + + @Override + public Response getActivitySpec(String activitySpecId, String versionId) { + ActivitySpecEntity activitySpec = new ActivitySpecEntity(); + activitySpec.setId(activitySpecId); + activitySpec.setVersion(new Version(versionId)); + final ActivitySpecEntity retrieved = activitySpecManager.get(activitySpec); + ActivitySpecGetResponse getResponse = + new MapActivitySpecToActivitySpecGetResponse().applyMapping(retrieved, ActivitySpecGetResponse.class); + return Response.ok(getResponse).build(); + } + + @Override + public Response updateActivitySpec(ActivitySpecRequestDto request, String activitySpecId, String versionId) { + ActivitySpecEntity activitySpec = + new MapActivitySpecRequestDtoToActivitySpecEntity().applyMapping(request, ActivitySpecEntity.class); + + activitySpec.setId(activitySpecId); + activitySpec.setVersion(new Version(versionId)); + + activitySpecManager.update(activitySpec); + + return Response.ok(new InternalEmptyObject()).build(); + } + + @Override + public Response actOnActivitySpec(ActivitySpecActionRequestDto request, String activitySpecId, String versionId) { + activitySpecManager.actOnAction(activitySpecId, versionId, request.getAction()); + return Response.ok(new InternalEmptyObject()).build(); + } + + @Override + public Response list(String versionStatus) { + + GenericCollectionWrapper results = new GenericCollectionWrapper<>(); + MapItemToListResponseDto mapper = new MapItemToListResponseDto(); + activitySpecManager.list(versionStatus).stream() + .sorted((o1, o2) -> o2.getModificationTime().compareTo(o1.getModificationTime())).forEach( + activitySpecItem -> results.add( + mapper.applyMapping(activitySpecItem, ActivitySpecListResponseDto.class))); + + return Response.ok(results).build(); + } + +} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/types/ActivitySpecAction.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/types/ActivitySpecAction.java new file mode 100644 index 0000000000..c3e6904f82 --- /dev/null +++ b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/types/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.activityspec.api.rest.types; + +public enum ActivitySpecAction { + CERTIFY, DEPRECATE, DELETE +} \ No newline at end of file diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/types/ActivitySpecActionRequestDto.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/types/ActivitySpecActionRequestDto.java new file mode 100644 index 0000000000..a420e1f0fd --- /dev/null +++ b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/types/ActivitySpecActionRequestDto.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.activityspec.api.rest.types; + +@lombok.Data +public class ActivitySpecActionRequestDto { + + private ActivitySpecAction action; +} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/types/ActivitySpecCreateResponse.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/types/ActivitySpecCreateResponse.java new file mode 100644 index 0000000000..d21dab19ee --- /dev/null +++ b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/types/ActivitySpecCreateResponse.java @@ -0,0 +1,25 @@ +/* + * 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.activityspec.api.rest.types; + +@lombok.Data +public class ActivitySpecCreateResponse { + + private String id; + private String versionId; +} + diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/types/ActivitySpecGetResponse.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/types/ActivitySpecGetResponse.java new file mode 100644 index 0000000000..04cdc4efc4 --- /dev/null +++ b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/types/ActivitySpecGetResponse.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.activityspec.api.rest.types; + +import java.util.List; + +@lombok.Data +public class ActivitySpecGetResponse { + + private String name; + private String description; + private List categoryList; + private List inputs; + private List outputs; + private String status; + private String type; + private String content; +} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/types/ActivitySpecListResponseDto.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/types/ActivitySpecListResponseDto.java new file mode 100644 index 0000000000..4c6128fab5 --- /dev/null +++ b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/types/ActivitySpecListResponseDto.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.activityspec.api.rest.types; + +import java.util.List; + +@lombok.Data +public class ActivitySpecListResponseDto { + + private String id; + private String version; + String name; + List categoryList; + private String status; +} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/types/ActivitySpecParameterDto.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/types/ActivitySpecParameterDto.java new file mode 100644 index 0000000000..69a66cec32 --- /dev/null +++ b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/types/ActivitySpecParameterDto.java @@ -0,0 +1,25 @@ +/* + * 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.activityspec.api.rest.types; + +@lombok.Data +public class ActivitySpecParameterDto { + + private String name; + private String type; + private String value; +} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/types/ActivitySpecRequestDto.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/types/ActivitySpecRequestDto.java new file mode 100644 index 0000000000..86148ac315 --- /dev/null +++ b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/types/ActivitySpecRequestDto.java @@ -0,0 +1,39 @@ +/* + * 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.activityspec.api.rest.types; + +import io.swagger.annotations.ApiModel; +import org.hibernate.validator.constraints.NotBlank; + +import javax.validation.constraints.Pattern; +import java.util.List; + +@ApiModel(value = "ActivitySpecRequest") +@lombok.Data +public class ActivitySpecRequestDto { + + @NotBlank(message = "Mandatory %s field is missing/null") + @Pattern(regexp = "^[a-zA-Z0-9-]*$", message = "%s should match with \"^[a-zA-Z0-9-]*$\" pattern") + private String name; + private String description; + + private List categoryList; + private List inputs; + private List outputs; + private String type; + private String content; +} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/types/InternalEmptyObject.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/types/InternalEmptyObject.java new file mode 100644 index 0000000000..9d9538ebf4 --- /dev/null +++ b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/rest/types/InternalEmptyObject.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.activityspec.api.rest.types; + +import org.codehaus.jackson.annotate.JsonAutoDetect; + +/** + * Object of this class can be used to create empty Response body like "{}". + */ +@JsonAutoDetect +public class InternalEmptyObject { + +} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/server/filters/ActivitySpecSessionContextFilter.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/server/filters/ActivitySpecSessionContextFilter.java new file mode 100644 index 0000000000..9269eacbfd --- /dev/null +++ b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/server/filters/ActivitySpecSessionContextFilter.java @@ -0,0 +1,82 @@ +/* + * 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.activityspec.api.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 javax.servlet.http.HttpServletResponse; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response.Status; + +import org.apache.commons.lang.StringUtils; +import org.onap.sdc.activityspec.utils.ActivitySpecConstant; +import org.openecomp.sdc.common.session.SessionContextProvider; +import org.openecomp.sdc.common.session.SessionContextProviderFactory; + +public class ActivitySpecSessionContextFilter implements Filter { + + private static final String MESSAGE_USER_MAY_NOT_BE_NULL = "{\"message\": \"User ID can not be null\"}"; + + @Override + public void init(FilterConfig filterConfig) { + //No ActivitySpec specific initialization required + } + + @Override + public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) + throws IOException, ServletException { + + final String userHeader = + ((HttpServletRequest) servletRequest).getHeader(ActivitySpecConstant.USER_ID_HEADER_PARAM); + + // Not a real security, just make sure the request + // has passed some authentication gateway + if (StringUtils.isEmpty(userHeader)) { + sendErrorResponse(servletResponse); + return; + } + + SessionContextProvider contextProvider = SessionContextProviderFactory.getInstance().createInterface(); + + try { + // use the system-wide user and tenant + contextProvider.create(ActivitySpecConstant.USER, ActivitySpecConstant.TENANT); + filterChain.doFilter(servletRequest, servletResponse); + } finally { + contextProvider.close(); + } + } + + private void sendErrorResponse(ServletResponse servletResponse) throws IOException { + HttpServletResponse httpServletResponse = (HttpServletResponse) servletResponse; + httpServletResponse.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON); + httpServletResponse.setStatus(Status.UNAUTHORIZED.getStatusCode()); + servletResponse.getOutputStream().write(MESSAGE_USER_MAY_NOT_BE_NULL.getBytes()); + } + + @Override + public void destroy() { + //No ActivitySpec specific destroy required + } +} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/server/listeners/ActivitySpecAppStartupListener.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/server/listeners/ActivitySpecAppStartupListener.java new file mode 100644 index 0000000000..cb1cc65d2c --- /dev/null +++ b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/api/server/listeners/ActivitySpecAppStartupListener.java @@ -0,0 +1,43 @@ +/* + * 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.activityspec.api.server.listeners; + +import org.openecomp.sdc.common.session.SessionContextProviderFactory; +import org.springframework.web.context.ContextLoaderListener; + +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; + +import static org.onap.sdc.activityspec.utils.ActivitySpecConstant.TENANT; +import static org.onap.sdc.activityspec.utils.ActivitySpecConstant.USER; + +public class ActivitySpecAppStartupListener implements ServletContextListener { + + private ContextLoaderListener springListener; + + @Override + public void contextInitialized(ServletContextEvent servletContextEvent) { + SessionContextProviderFactory.getInstance().createInterface().create(USER, TENANT); + springListener = new ContextLoaderListener(); + springListener.initWebApplicationContext(servletContextEvent.getServletContext()); + } + + @Override + public void contextDestroyed(ServletContextEvent servletContextEvent) { + springListener.closeWebApplicationContext(servletContextEvent.getServletContext()); + } +} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/be/ActivitySpecManager.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/be/ActivitySpecManager.java new file mode 100644 index 0000000000..6c1a4d0526 --- /dev/null +++ b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/be/ActivitySpecManager.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.activityspec.be; + +import java.util.Collection; + +import org.onap.sdc.activityspec.api.rest.types.ActivitySpecAction; +import org.onap.sdc.activityspec.be.dao.types.ActivitySpecEntity; +import org.openecomp.sdc.versioning.types.Item; + +public interface ActivitySpecManager { + + ActivitySpecEntity createActivitySpec(ActivitySpecEntity activitySpecEntity); + + ActivitySpecEntity get(ActivitySpecEntity activitySpec); + + void update(ActivitySpecEntity activitySpec); + + void actOnAction(String activitySpecId, String versionId, ActivitySpecAction action); + + Collection list(String versionStatus); +} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/be/dao/ActivitySpecDao.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/be/dao/ActivitySpecDao.java new file mode 100644 index 0000000000..c71f296f1a --- /dev/null +++ b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/be/dao/ActivitySpecDao.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.activityspec.be.dao; + +import org.onap.sdc.activityspec.be.dao.types.ActivitySpecEntity; + +public interface ActivitySpecDao { + + void create(ActivitySpecEntity activitySpecEntity); + + ActivitySpecEntity get(ActivitySpecEntity activitySpec); + + void update(ActivitySpecEntity activitySpec); +} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/be/dao/impl/ActivitySpecDaoZusammenImpl.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/be/dao/impl/ActivitySpecDaoZusammenImpl.java new file mode 100644 index 0000000000..9da4cd4835 --- /dev/null +++ b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/be/dao/impl/ActivitySpecDaoZusammenImpl.java @@ -0,0 +1,148 @@ +/* + * 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.activityspec.be.dao.impl; + +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.SessionContext; +import com.amdocs.zusammen.datatypes.item.Action; +import com.amdocs.zusammen.datatypes.item.ElementContext; +import com.amdocs.zusammen.datatypes.item.Info; + +import org.onap.sdc.activityspec.be.dao.ActivitySpecDao; +import org.onap.sdc.activityspec.be.dao.types.ActivitySpecEntity; +import org.onap.sdc.activityspec.be.datatypes.ActivitySpecData; +import org.onap.sdc.activityspec.be.datatypes.ElementType; +import org.onap.sdc.activityspec.utils.ActivitySpecConstant; +import org.openecomp.core.utilities.json.JsonUtil; +import org.openecomp.core.zusammen.api.ZusammenAdaptor; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.util.Objects; +import java.util.Optional; + +import static org.openecomp.core.zusammen.api.ZusammenUtil.buildStructuralElement; +import static org.openecomp.core.zusammen.api.ZusammenUtil.createSessionContext; + +public class ActivitySpecDaoZusammenImpl implements ActivitySpecDao { + + private final ZusammenAdaptor zusammenAdaptor; + + public ActivitySpecDaoZusammenImpl(ZusammenAdaptor zusammenAdaptor) { + this.zusammenAdaptor = zusammenAdaptor; + } + + @Override + public void create(ActivitySpecEntity entity) { + SessionContext context = createSessionContext(); + ZusammenElement generalElement = mapActivityDetailsToZusammenElement(entity, Action.CREATE); + + ElementContext elementContext = new ElementContext(entity.getId(), entity.getVersion().getId()); + zusammenAdaptor + .saveElement(context, elementContext, generalElement, "Create Activity Spec General Info Element"); + } + + @Override + public ActivitySpecEntity get(ActivitySpecEntity entity) { + SessionContext context = createSessionContext(); + + ElementContext elementContext = new ElementContext(entity.getId(), entity.getVersion().getId()); + Optional element = + zusammenAdaptor.getElementByName(context, elementContext, null, ElementType.ACTIVITYSPEC.name()); + if (element.isPresent()) { + return mapZusammenElementToActivityDetails(element.get()); + } else { + return null; + } + } + + @Override + public void update(ActivitySpecEntity entity) { + SessionContext context = createSessionContext(); + ZusammenElement generalElement = mapActivityDetailsToZusammenElement(entity, Action.UPDATE); + + ElementContext elementContext = new ElementContext(entity.getId(), entity.getVersion().getId()); + zusammenAdaptor + .saveElement(context, elementContext, generalElement, "Update Activity Spec General Info Element"); + } + + + 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 ZusammenElement mapActivityDetailsToZusammenElement(ActivitySpecEntity entity, Action action) { + ZusammenElement generalElement = buildStructuralElement(ElementType.ACTIVITYSPEC.name(), action); + + enrichElementInfoFromEntity(generalElement, entity); + enrichElementDataFromEntity(generalElement, entity); + return generalElement; + } + + + 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())); + } + + 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 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())); + } + + 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/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/be/dao/types/ActivitySpecEntity.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/be/dao/types/ActivitySpecEntity.java new file mode 100644 index 0000000000..7dc66123f9 --- /dev/null +++ b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/be/dao/types/ActivitySpecEntity.java @@ -0,0 +1,40 @@ +/* + * 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.activityspec.be.dao.types; + +import org.onap.sdc.activityspec.be.datatypes.ActivitySpecParameter; +import org.openecomp.sdc.versioning.dao.types.Version; + +import java.util.List; + +@lombok.Data +public class ActivitySpecEntity { + + private String id; + private Version version; + 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; +} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/be/datatypes/ActivitySpecData.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/be/datatypes/ActivitySpecData.java new file mode 100644 index 0000000000..2c76ed86d3 --- /dev/null +++ b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/be/datatypes/ActivitySpecData.java @@ -0,0 +1,30 @@ +/* + * 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.activityspec.be.datatypes; + +import java.util.Collections; +import java.util.List; + +@lombok.Data +public class ActivitySpecData { + + private List inputs = Collections.emptyList(); + private List outputs = Collections.emptyList(); + private String type; + private String content; +} + diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/be/datatypes/ActivitySpecParameter.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/be/datatypes/ActivitySpecParameter.java new file mode 100644 index 0000000000..72273dd649 --- /dev/null +++ b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/be/datatypes/ActivitySpecParameter.java @@ -0,0 +1,35 @@ +/* + * 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.activityspec.be.datatypes; + +@lombok.Data +public class ActivitySpecParameter { + + private String name; + private String type; + private String value; + + @SuppressWarnings("unused") + public ActivitySpecParameter() { + // default constructor for automatic tools that use reflection + } + + public ActivitySpecParameter(String name, String type) { + this.name = name; + this.type = type; + } +} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/be/datatypes/ElementType.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/be/datatypes/ElementType.java new file mode 100644 index 0000000000..d063530145 --- /dev/null +++ b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/be/datatypes/ElementType.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.activityspec.be.datatypes; + +public enum ElementType { + ACTIVITYSPEC +} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/be/datatypes/ItemType.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/be/datatypes/ItemType.java new file mode 100644 index 0000000000..f9d8fa33f3 --- /dev/null +++ b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/be/datatypes/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.activityspec.be.datatypes; + +public enum ItemType { + ACTIVITYSPEC +} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/be/impl/ActivitySpecManagerImpl.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/be/impl/ActivitySpecManagerImpl.java new file mode 100644 index 0000000000..6853b855d2 --- /dev/null +++ b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/be/impl/ActivitySpecManagerImpl.java @@ -0,0 +1,265 @@ +/* + * 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.activityspec.be.impl; + +import static org.openecomp.sdc.versioning.dao.types.VersionStatus.Certified; +import static org.openecomp.sdc.versioning.dao.types.VersionStatus.Deleted; +import static org.openecomp.sdc.versioning.dao.types.VersionStatus.Deprecated; +import static org.openecomp.sdc.versioning.dao.types.VersionStatus.Draft; + +import java.util.Collection; +import java.util.Collections; +import java.util.EnumMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.function.Predicate; + +import org.onap.sdc.activityspec.api.rest.types.ActivitySpecAction; +import org.onap.sdc.activityspec.be.dao.ActivitySpecDao; +import org.onap.sdc.activityspec.utils.ActivitySpecConstant; +import org.onap.sdc.activityspec.be.ActivitySpecManager; +import org.onap.sdc.activityspec.be.dao.types.ActivitySpecEntity; +import org.onap.sdc.activityspec.be.datatypes.ItemType; +import org.onap.sdc.activityspec.errors.ActivitySpecNotFoundException; +import org.openecomp.core.dao.UniqueValueDao; +import org.openecomp.core.util.UniqueValueUtil; +import org.openecomp.sdc.common.errors.CoreException; +import org.openecomp.sdc.common.errors.ErrorCategory; +import org.openecomp.sdc.common.errors.ErrorCode; +import org.openecomp.sdc.common.errors.SdcRuntimeException; +import org.openecomp.sdc.logging.api.Logger; +import org.openecomp.sdc.logging.api.LoggerFactory; +import org.openecomp.sdc.versioning.ItemManager; +import org.openecomp.sdc.versioning.VersioningManager; +import org.openecomp.sdc.versioning.dao.types.Version; +import org.openecomp.sdc.versioning.dao.types.VersionStatus; +import org.openecomp.sdc.versioning.types.Item; +import org.openecomp.sdc.versioning.types.VersionCreationMethod; + +public class ActivitySpecManagerImpl implements ActivitySpecManager { + + 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 ActivitySpecDao activitySpecDao; + private final UniqueValueUtil uniqueValueUtil; + private static final String ACTIVITY_SPEC_NAME = "ActivitySpec.Name"; + private static final Logger LOGGER = LoggerFactory.getLogger(ActivitySpecManagerImpl.class); + + public ActivitySpecManagerImpl(ItemManager itemManager, VersioningManager versioningManager, + ActivitySpecDao activitySpecDao, UniqueValueDao uniqueValueDao) { + this.itemManager = itemManager; + this.versioningManager = versioningManager; + this.activitySpecDao = activitySpecDao; + this.uniqueValueUtil = new UniqueValueUtil(uniqueValueDao); + } + + @Override + public ActivitySpecEntity createActivitySpec(ActivitySpecEntity activitySpecEntity) { + + validateUniqueValue(activitySpecEntity); + + Item item = getActivitySpecItem(activitySpecEntity); + item = itemManager.create(item); + + Version version = getActivitySpecVersion(activitySpecEntity); + versioningManager.create(item.getId(), version, VersionCreationMethod.major); + + enrichActivitySpec(item, version, activitySpecEntity); + activitySpecDao.create(activitySpecEntity); + + uniqueValueUtil.createUniqueValue(ACTIVITY_SPEC_NAME, activitySpecEntity.getName()); + return activitySpecEntity; + } + + private void validateUniqueValue(ActivitySpecEntity activitySpecEntity) { + try { + uniqueValueUtil.validateUniqueValue(ACTIVITY_SPEC_NAME, activitySpecEntity.getName()); + } catch (CoreException exception) { + LOGGER.debug("Unique value error for activity spec name :" + activitySpecEntity.getName(), exception); + throw new CoreException(new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION) + .withId(exception.code().id()) + .withMessage("name already in use").build()); + } + } + + private Version getActivitySpecVersion(ActivitySpecEntity activitySpecEntity) { + return activitySpecEntity.getVersion() == null ? new Version() : activitySpecEntity.getVersion(); + + } + + @Override + public ActivitySpecEntity get(ActivitySpecEntity activitySpec) { + activitySpec.setVersion(calculateLatestVersion(activitySpec.getId(), activitySpec.getVersion())); + ActivitySpecEntity retrieved; + try { + retrieved = activitySpecDao.get(activitySpec); + } catch (SdcRuntimeException runtimeException) { + LOGGER.debug( + "Failed to retrieve activity spec for activitySpecId: " + activitySpec.getId() + " and version: " + + activitySpec.getVersion().getId(), runtimeException); + throw new ActivitySpecNotFoundException(ActivitySpecConstant.ACTIVITY_SPEC_NOT_FOUND, runtimeException); + } + if (retrieved != null) { + final Version retrievedVersion = versioningManager.get(activitySpec.getId(), activitySpec.getVersion()); + retrieved.setStatus(Objects.nonNull(retrievedVersion) ? retrievedVersion.getStatus().name() : null); + } + return retrieved; + } + + @Override + public void update(ActivitySpecEntity activitySpec) { + + ActivitySpecEntity previousActivitySpec = get(activitySpec); + + if (!activitySpec.getName().equals(previousActivitySpec.getName())) { + validateUniqueValue(activitySpec); + } + + activitySpecDao.update(activitySpec); + + if (!activitySpec.getName().equals(previousActivitySpec.getName())) { + uniqueValueUtil.createUniqueValue(ACTIVITY_SPEC_NAME, activitySpec.getName()); + itemManager.updateName(activitySpec.getId(), activitySpec.getName()); + uniqueValueUtil.deleteUniqueValue(ACTIVITY_SPEC_NAME, previousActivitySpec.getName()); + } + } + + @Override + public void actOnAction(String activitySpecId, String versionId, ActivitySpecAction action) { + Version version = new Version(versionId); + version = calculateLatestVersion(activitySpecId, version); + if (action == ActivitySpecAction.CERTIFY) { + version.setStatus(Certified); + } + if (action == ActivitySpecAction.DEPRECATE) { + version.setStatus(Deprecated); + } + if (action == ActivitySpecAction.DELETE) { + version.setStatus(Deleted); + } + + updateVersionStatus(activitySpecId, action, version); + if (action == ActivitySpecAction.DELETE) { + ActivitySpecEntity entity = new ActivitySpecEntity(); + entity.setId(activitySpecId); + entity.setVersion(version); + final ActivitySpecEntity activitySpecEntity = get(entity); + uniqueValueUtil.deleteUniqueValue(ACTIVITY_SPEC_NAME, activitySpecEntity.getName()); + } + } + + private void updateVersionStatus(String activitySpecId, ActivitySpecAction action, Version version) { + VersionStatus prevVersionStatus = null; + Version retrievedVersion; + try { + retrievedVersion = versioningManager.get(activitySpecId, version); + } catch (SdcRuntimeException exception) { + LOGGER.debug( + "Failed to get version for activitySpecId: " + activitySpecId + " and version: " + version.getId(), + exception); + throw new ActivitySpecNotFoundException(ActivitySpecConstant.ACTIVITY_SPEC_NOT_FOUND, exception); + + } + + VersionStatus status = version.getStatus(); + VersionStatus expectedPrevStatus = EXPECTED_PREV_STATUS.get(status); + if (expectedPrevStatus != null) { + + VersionStatus retrievedStatus = Objects.nonNull(retrievedVersion) ? retrievedVersion.getStatus() : null; + if (retrievedStatus != expectedPrevStatus) { + LOGGER.debug("Failed to " + version.getStatus() + " since activity spec is in " + retrievedStatus); + throw new CoreException(new ErrorCode.ErrorCodeBuilder().withMessage(ActivitySpecConstant.INVALID_STATE) + .build()); + } + prevVersionStatus = expectedPrevStatus; + } + + if (Objects.nonNull(retrievedVersion)) { + retrievedVersion.setStatus(status); + versioningManager.updateVersion(activitySpecId, retrievedVersion); + itemManager.updateVersionStatus(activitySpecId, status, prevVersionStatus); + versioningManager.publish(activitySpecId, retrievedVersion, "actionOnActivitySpec :" + action.name()); + } + } + + private Version calculateLatestVersion(String activitySpecId, Version version) { + if (ActivitySpecConstant.VERSION_ID_DEFAULT_VALUE.equalsIgnoreCase(version.getId())) { + List list; + try { + list = versioningManager.list(activitySpecId); + } catch (SdcRuntimeException runtimeException) { + LOGGER.debug("Failed to list versions for activitySpecId " + activitySpecId, runtimeException); + throw new ActivitySpecNotFoundException(ActivitySpecConstant.ACTIVITY_SPEC_NOT_FOUND, runtimeException); + } + if (Objects.nonNull(list) && !list.isEmpty()) { + return list.get(0); + } + } + return version; + } + + @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); + } + + private void enrichActivitySpec(Item item, Version version, ActivitySpecEntity activitySpecEntity) { + activitySpecEntity.setId(item.getId()); + activitySpecEntity.setVersion(version); + } + + private Item getActivitySpecItem(ActivitySpecEntity activitySpecEntity) { + Item item = new Item(); + item.setType(ItemType.ACTIVITYSPEC.name()); + item.setName(activitySpecEntity.getName()); + if (activitySpecEntity.getId() != null) { + item.setId(activitySpecEntity.getId()); + } + item.addProperty(ActivitySpecConstant.CATEGORY_ATTRIBUTE_NAME, activitySpecEntity.getCategoryList()); + return item; + } +} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/errors/ActivitySpecErrorResponse.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/errors/ActivitySpecErrorResponse.java new file mode 100644 index 0000000000..8d9117daa6 --- /dev/null +++ b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/errors/ActivitySpecErrorResponse.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.activityspec.errors; + +@lombok.Data +public class ActivitySpecErrorResponse { + + private String message; + + public ActivitySpecErrorResponse() { + //default constructor + } + + public ActivitySpecErrorResponse(String message) { + this.message = message; + } +} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/errors/ActivitySpecNotFoundException.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/errors/ActivitySpecNotFoundException.java new file mode 100644 index 0000000000..415aa68093 --- /dev/null +++ b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/errors/ActivitySpecNotFoundException.java @@ -0,0 +1,24 @@ +/* + * 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.activityspec.errors; + +public class ActivitySpecNotFoundException extends RuntimeException { + + public ActivitySpecNotFoundException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/errors/DefaultExceptionMapper.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/errors/DefaultExceptionMapper.java new file mode 100644 index 0000000000..d09d1740eb --- /dev/null +++ b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/errors/DefaultExceptionMapper.java @@ -0,0 +1,96 @@ +/* + * 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.activityspec.errors; + +import java.util.Set; +import javax.validation.ConstraintViolation; +import javax.validation.ConstraintViolationException; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; +import javax.ws.rs.ext.ExceptionMapper; + +import org.codehaus.jackson.map.JsonMappingException; +import org.hibernate.validator.internal.engine.path.PathImpl; +import org.openecomp.sdc.common.errors.CoreException; +import org.openecomp.sdc.logging.api.Logger; +import org.openecomp.sdc.logging.api.LoggerFactory; + +public class DefaultExceptionMapper implements ExceptionMapper { + + private static final Logger LOGGER = LoggerFactory.getLogger(DefaultExceptionMapper.class); + + @Override + public Response toResponse(Exception exception) { + Response response; + if (exception instanceof CoreException) { + response = transform(CoreException.class.cast(exception)); + } else if (exception instanceof ActivitySpecNotFoundException) { + response = transform(ActivitySpecNotFoundException.class.cast(exception)); + } else if (exception instanceof ConstraintViolationException) { + response = transform(ConstraintViolationException.class.cast(exception)); + } else if (exception instanceof JsonMappingException) { + response = transform(JsonMappingException.class.cast(exception)); + } else { + response = transform(exception); + } + + return response; + } + + private Response transform(ActivitySpecNotFoundException notFoundException) { + LOGGER.error("Transforming ActivitySpecNotFoundException to Error Response :", notFoundException); + return generateResponse(Status.NOT_FOUND, new ActivitySpecErrorResponse(notFoundException.getMessage())); + } + + private Response transform(CoreException coreException) { + LOGGER.error("Transforming CoreException to Error Response :", coreException); + return generateResponse(Status.BAD_REQUEST, new ActivitySpecErrorResponse(coreException.getMessage())); + } + + private Response transform(ConstraintViolationException validationException) { + LOGGER.error("Transforming ConstraintViolationException to Error Response :", validationException); + Set> constraintViolationSet = validationException.getConstraintViolations(); + String message; + + String fieldName = null; + if (constraintViolationSet != null) { + // getting the first violation message for the output response. + ConstraintViolation constraintViolation = constraintViolationSet.iterator().next(); + message = constraintViolation.getMessage(); + fieldName = ((PathImpl) constraintViolation.getPropertyPath()).getLeafNode().toString(); + + } else { + message = validationException.getMessage(); + } + return generateResponse(Status.BAD_REQUEST, new ActivitySpecErrorResponse(String.format(message, fieldName))); + } + + private Response transform(Exception exception) { + LOGGER.error("Transforming Exception to Error Response " + exception); + return generateResponse(Status.INTERNAL_SERVER_ERROR, new ActivitySpecErrorResponse(exception.getMessage())); + } + + private Response transform(JsonMappingException jsonMappingException) { + LOGGER.error("Transforming JsonMappingException to Error Response " + jsonMappingException); + return generateResponse(Status.BAD_REQUEST, new ActivitySpecErrorResponse("Invalid Json Input")); + } + + private Response generateResponse(Response.Status status, ActivitySpecErrorResponse activitySpecErrorResponse) { + return Response.status(status).entity(activitySpecErrorResponse).type(MediaType.APPLICATION_JSON).build(); + } +} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/utils/ActivitySpecConstant.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/utils/ActivitySpecConstant.java new file mode 100644 index 0000000000..a0da1c977f --- /dev/null +++ b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/onap/sdc/activityspec/utils/ActivitySpecConstant.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.activityspec.utils; + +public class ActivitySpecConstant { + + public static final String CATEGORY_ATTRIBUTE_NAME = "category"; + public static final String VERSION_ID_DEFAULT_VALUE = "latest"; + public static final String TENANT = "activity_spec"; + public static final String USER = "activity_spec_USER"; + public static final String USER_ID_HEADER_PARAM = "USER_ID"; + public static final String ACTIVITY_SPEC_NOT_FOUND = "No Activity Spec found for the given identifiers"; + public static final String INVALID_STATE = "Activity Spec is in an invalid state"; + + private ActivitySpecConstant() { + //Utility Class declaring constants does not require instantiation. + } +} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/ActivitySpecs.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/ActivitySpecs.java deleted file mode 100644 index ae9e1583fd..0000000000 --- a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/ActivitySpecs.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * 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.openecomp.activityspec.api.rest; - -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiParam; -import org.openecomp.activityspec.api.rest.types.ActivitySpecActionRequestDto; -import org.openecomp.activityspec.api.rest.types.ActivitySpecRequestDto; -import org.springframework.validation.annotation.Validated; - -import javax.validation.Valid; -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - -@Path("/v1.0/activity-spec/") -@Produces(MediaType.APPLICATION_JSON) -@Consumes(MediaType.APPLICATION_JSON) -@Api(value = "Activity Specs") -@Validated -public interface ActivitySpecs { - @POST - @Path("/") - @ApiOperation(value = "Create Activity Spec") - Response createActivitySpec(@Valid ActivitySpecRequestDto request); - - @GET - @Path("/{id}/versions/{versionId}") - @ApiOperation(value = "Get Activity Spec") - Response getActivitySpec(@ApiParam(value = "Activity Spec Id") @PathParam("id") - String id, - @ApiParam(value = "Version Id") @PathParam("versionId") - String versionId); - - @PUT - @Path("/{id}/versions/{versionId}") - @ApiOperation(value = "Update Activity Spec") - Response updateActivitySpec(@Valid ActivitySpecRequestDto request, - @ApiParam(value = "Activity Spec Id") @PathParam("id") - String id, - @ApiParam(value = "Version Id") @PathParam("versionId") - String versionId); - - @PUT - @Path("/{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.") - Response actOnActivitySpec(ActivitySpecActionRequestDto request, - @ApiParam(value = "Activity Spec Id") @PathParam("id") String id, - @ApiParam(value = "Version Id") @PathParam("versionId") String versionId); - - @GET - @Path("/") - @ApiOperation(value = "Get list of activity specs ", - responseContainer = "List") - Response list(@ApiParam( - value = "List activity specs based on status filter") - @QueryParam("status") String versionStatus); -} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/mapping/MapActivityParameterToDto.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/mapping/MapActivityParameterToDto.java deleted file mode 100644 index bd644ff4d6..0000000000 --- a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/mapping/MapActivityParameterToDto.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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.openecomp.activityspec.api.rest.mapping; - -import org.openecomp.activityspec.be.datatypes.ActivitySpecParameter; -import org.openecomp.activityspec.api.rest.types.ActivitySpecParameterDto; -import org.openecomp.sdcrests.mapping.MappingBase; - -public class MapActivityParameterToDto extends MappingBase { - @Override - public void doMapping(ActivitySpecParameter source, ActivitySpecParameterDto target) { - target.setName(source.getName()); - target.setType(source.getType()); - target.setValue(source.getValue()); - } -} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/mapping/MapActivitySpecRequestDtoToActivitySpecEntity.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/mapping/MapActivitySpecRequestDtoToActivitySpecEntity.java deleted file mode 100644 index 2364d59629..0000000000 --- a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/mapping/MapActivitySpecRequestDtoToActivitySpecEntity.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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.openecomp.activityspec.api.rest.mapping; - -import java.util.ArrayList; -import org.openecomp.activityspec.be.dao.types.ActivitySpecEntity; -import org.openecomp.activityspec.be.datatypes.ActivitySpecParameter; -import org.openecomp.activityspec.api.rest.types.ActivitySpecRequestDto; -import org.openecomp.sdcrests.mapping.MappingBase; - -import java.util.Objects; -import java.util.stream.Collectors; - -public class MapActivitySpecRequestDtoToActivitySpecEntity - extends MappingBase { - - @Override - public void doMapping(ActivitySpecRequestDto source, ActivitySpecEntity target) { - target.setName(source.getName()); - target.setDescription(source.getDescription()); - target.setCategoryList(source.getCategoryList() == null ? new ArrayList() - : source.getCategoryList()); - if (Objects.nonNull(source.getInputs())) { - target.setInputs(source.getInputs().stream() - .map(activitySpecParameterDto -> new MapDtoToActivityParameter() - .applyMapping(activitySpecParameterDto, ActivitySpecParameter.class)) - .collect(Collectors.toList())); - } - if (Objects.nonNull(source.getOutputs())) { - target.setOutputs(source.getOutputs().stream() - .map(activitySpecParameterDto -> new MapDtoToActivityParameter() - .applyMapping(activitySpecParameterDto, ActivitySpecParameter.class)) - .collect(Collectors.toList())); - } - target.setType(source.getType()); - target.setContent(source.getContent()); - } -} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/mapping/MapActivitySpecToActivitySpecCreateResponse.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/mapping/MapActivitySpecToActivitySpecCreateResponse.java deleted file mode 100644 index 13c881404f..0000000000 --- a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/mapping/MapActivitySpecToActivitySpecCreateResponse.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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.openecomp.activityspec.api.rest.mapping; - -import java.util.Objects; -import org.openecomp.activityspec.be.dao.types.ActivitySpecEntity; -import org.openecomp.activityspec.api.rest.types.ActivitySpecCreateResponse; -import org.openecomp.sdcrests.mapping.MappingBase; - -public class MapActivitySpecToActivitySpecCreateResponse extends MappingBase { - - @Override - public void doMapping(ActivitySpecEntity source, ActivitySpecCreateResponse target) { - target.setId(source.getId()); - target.setVersionId(Objects.nonNull(source.getVersion()) ? source.getVersion().getId() : null); - } -} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/mapping/MapActivitySpecToActivitySpecGetResponse.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/mapping/MapActivitySpecToActivitySpecGetResponse.java deleted file mode 100644 index 697e1bd667..0000000000 --- a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/mapping/MapActivitySpecToActivitySpecGetResponse.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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.openecomp.activityspec.api.rest.mapping; - -import org.openecomp.activityspec.be.dao.types.ActivitySpecEntity; -import org.openecomp.activityspec.api.rest.types.ActivitySpecGetResponse; -import org.openecomp.activityspec.api.rest.types.ActivitySpecParameterDto; -import org.openecomp.sdcrests.mapping.MappingBase; - -import java.util.Objects; -import java.util.stream.Collectors; - -public class MapActivitySpecToActivitySpecGetResponse extends MappingBase { - - @Override - public void doMapping(ActivitySpecEntity source, ActivitySpecGetResponse target) { - target.setName(source.getName()); - target.setDescription(source.getDescription()); - target.setCategoryList(source.getCategoryList()); - if (Objects.nonNull(source.getInputs())) { - target.setInputs(source.getInputs().stream().map( - activitySpecParameter -> new MapActivityParameterToDto() - .applyMapping(activitySpecParameter, ActivitySpecParameterDto - .class)).collect(Collectors.toList())); - } - if (Objects.nonNull(source.getOutputs())) { - target.setOutputs(source.getOutputs().stream().map( - activitySpecParameter -> new MapActivityParameterToDto() - .applyMapping(activitySpecParameter, ActivitySpecParameterDto - .class)).collect(Collectors.toList())); - } - target.setStatus(source.getStatus()); - target.setType(source.getType()); - target.setContent(source.getContent()); - } -} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/mapping/MapDtoToActivityParameter.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/mapping/MapDtoToActivityParameter.java deleted file mode 100644 index ccffaead76..0000000000 --- a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/mapping/MapDtoToActivityParameter.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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.openecomp.activityspec.api.rest.mapping; - -import org.openecomp.activityspec.be.datatypes.ActivitySpecParameter; -import org.openecomp.activityspec.api.rest.types.ActivitySpecParameterDto; -import org.openecomp.sdcrests.mapping.MappingBase; - -public class MapDtoToActivityParameter extends MappingBase { - @Override - public void doMapping(ActivitySpecParameterDto source, ActivitySpecParameter target) { - target.setName(source.getName()); - target.setType(source.getType()); - target.setValue(source.getValue()); - } -} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/mapping/MapItemToListResponseDto.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/mapping/MapItemToListResponseDto.java deleted file mode 100644 index c85d5af427..0000000000 --- a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/mapping/MapItemToListResponseDto.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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.openecomp.activityspec.api.rest.mapping; - -import org.openecomp.activityspec.api.rest.types.ActivitySpecListResponseDto; -import org.openecomp.sdc.versioning.dao.types.VersionStatus; -import org.openecomp.sdc.versioning.types.Item; -import org.openecomp.sdcrests.mapping.MappingBase; - -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Set; - -import static org.openecomp.activityspec.utils.ActivitySpecConstant.CATEGORY_ATTRIBUTE_NAME; - -public class MapItemToListResponseDto extends MappingBase { - @Override - public void doMapping(Item source, ActivitySpecListResponseDto target) { - target.setId(source.getId()); - target.setName(source.getName()); - target.setCategoryList((List) source.getProperties().get( - CATEGORY_ATTRIBUTE_NAME)); - final Map versionStatusCounters = source.getVersionStatusCounters(); - if (Objects.nonNull(versionStatusCounters) && !versionStatusCounters.isEmpty()) { - final Set versionStatuses = versionStatusCounters.keySet(); - target.setStatus(versionStatuses.stream().findFirst().isPresent() - ? versionStatuses.stream().findFirst().get().name() : null); - } - } -} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/services/ActivitySpecsImpl.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/services/ActivitySpecsImpl.java deleted file mode 100644 index db2db40f6e..0000000000 --- a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/services/ActivitySpecsImpl.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * 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.openecomp.activityspec.api.rest.services; - -import org.openecomp.activityspec.api.rest.ActivitySpecs; -import org.openecomp.activityspec.api.rest.mapping.MapActivitySpecRequestDtoToActivitySpecEntity; -import org.openecomp.activityspec.api.rest.mapping.MapActivitySpecToActivitySpecCreateResponse; -import org.openecomp.activityspec.api.rest.mapping.MapActivitySpecToActivitySpecGetResponse; -import org.openecomp.activityspec.api.rest.mapping.MapItemToListResponseDto; -import org.openecomp.activityspec.api.rest.types.ActivitySpecActionRequestDto; -import org.openecomp.activityspec.api.rest.types.ActivitySpecCreateResponse; -import org.openecomp.activityspec.api.rest.types.ActivitySpecGetResponse; -import org.openecomp.activityspec.api.rest.types.ActivitySpecListResponseDto; -import org.openecomp.activityspec.api.rest.types.ActivitySpecRequestDto; -import org.openecomp.activityspec.api.rest.types.InternalEmptyObject; -import org.openecomp.activityspec.be.ActivitySpecManager; -import org.openecomp.activityspec.be.dao.impl.ActivitySpecDaoZusammenImpl; -import org.openecomp.activityspec.be.dao.types.ActivitySpecEntity; -import org.openecomp.activityspec.be.impl.ActivitySpecManagerImpl; -import org.openecomp.core.dao.UniqueValueDaoFactory; -import org.openecomp.core.zusammen.api.ZusammenAdaptorFactory; -import org.openecomp.sdc.versioning.ItemManagerFactory; -import org.openecomp.sdc.versioning.VersioningManagerFactory; -import org.openecomp.sdc.versioning.dao.types.Version; - -import org.openecomp.sdcrests.wrappers.GenericCollectionWrapper; -import org.springframework.context.annotation.Scope; -import org.springframework.stereotype.Service; -import org.springframework.validation.annotation.Validated; - -import javax.ws.rs.core.Response; - -@Service("activitySpecs") -@Scope(value = "singleton") -@Validated -public class ActivitySpecsImpl implements ActivitySpecs { - - - private final ActivitySpecManager activitySpecManager = - new ActivitySpecManagerImpl(ItemManagerFactory.getInstance().createInterface(), - VersioningManagerFactory.getInstance().createInterface(), - new ActivitySpecDaoZusammenImpl(ZusammenAdaptorFactory.getInstance().createInterface()), - UniqueValueDaoFactory.getInstance().createInterface()); - - @Override - public Response createActivitySpec(ActivitySpecRequestDto request) { - ActivitySpecEntity activitySpec = new MapActivitySpecRequestDtoToActivitySpecEntity() - .applyMapping(request, ActivitySpecEntity.class); - - activitySpec = activitySpecManager.createActivitySpec(activitySpec); - ActivitySpecCreateResponse createActivitySpecResponse = - new MapActivitySpecToActivitySpecCreateResponse().applyMapping(activitySpec, - ActivitySpecCreateResponse.class); - - return Response.ok(createActivitySpecResponse).build(); - } - - @Override - public Response getActivitySpec(String activitySpecId, String versionId) { - ActivitySpecEntity activitySpec = new ActivitySpecEntity(); - activitySpec.setId(activitySpecId); - activitySpec.setVersion(new Version(versionId)); - final ActivitySpecEntity retrieved = activitySpecManager.get(activitySpec); - ActivitySpecGetResponse getResponse = new MapActivitySpecToActivitySpecGetResponse() - .applyMapping(retrieved, ActivitySpecGetResponse.class); - return Response.ok(getResponse).build(); - } - - @Override - public Response updateActivitySpec(ActivitySpecRequestDto request, String activitySpecId, - String versionId) { - ActivitySpecEntity activitySpec = new MapActivitySpecRequestDtoToActivitySpecEntity() - .applyMapping(request, ActivitySpecEntity.class); - - activitySpec.setId(activitySpecId); - activitySpec.setVersion(new Version(versionId)); - - activitySpecManager.update(activitySpec); - - return Response.ok(new InternalEmptyObject()).build(); - } - - @Override - public Response actOnActivitySpec(ActivitySpecActionRequestDto request, String activitySpecId, - String versionId) { - activitySpecManager.actOnAction(activitySpecId, versionId, request.getAction()); - return Response.ok(new InternalEmptyObject()).build(); - } - - @Override - public Response list(String versionStatus) { - - GenericCollectionWrapper results = new GenericCollectionWrapper<>(); - MapItemToListResponseDto mapper = new MapItemToListResponseDto(); - activitySpecManager.list(versionStatus).stream() - .sorted((o1, o2) -> o2.getModificationTime().compareTo(o1.getModificationTime())) - .forEach(activitySpecItem -> results.add(mapper.applyMapping(activitySpecItem, - ActivitySpecListResponseDto.class))); - - return Response.ok(results).build(); - } - -} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/types/ActivitySpecAction.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/types/ActivitySpecAction.java deleted file mode 100644 index bedcfcb2da..0000000000 --- a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/types/ActivitySpecAction.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * 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.openecomp.activityspec.api.rest.types; - -public enum ActivitySpecAction { - CERTIFY, - DEPRECATE, - DELETE -} \ No newline at end of file diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/types/ActivitySpecActionRequestDto.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/types/ActivitySpecActionRequestDto.java deleted file mode 100644 index c9012120f1..0000000000 --- a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/types/ActivitySpecActionRequestDto.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * 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.openecomp.activityspec.api.rest.types; - -@lombok.Data -public class ActivitySpecActionRequestDto { - private ActivitySpecAction action; -} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/types/ActivitySpecCreateResponse.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/types/ActivitySpecCreateResponse.java deleted file mode 100644 index 9a654f780c..0000000000 --- a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/types/ActivitySpecCreateResponse.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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.openecomp.activityspec.api.rest.types; - -@lombok.Data -public class ActivitySpecCreateResponse { - private String id; - private String versionId; -} - diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/types/ActivitySpecGetResponse.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/types/ActivitySpecGetResponse.java deleted file mode 100644 index 9453935559..0000000000 --- a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/types/ActivitySpecGetResponse.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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.openecomp.activityspec.api.rest.types; - -import java.util.List; - -@lombok.Data -public class ActivitySpecGetResponse { - private String name; - private String description; - private List categoryList; - private List inputs; - private List outputs; - private String status; - private String type; - private String content; -} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/types/ActivitySpecListResponseDto.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/types/ActivitySpecListResponseDto.java deleted file mode 100644 index 782143f620..0000000000 --- a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/types/ActivitySpecListResponseDto.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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.openecomp.activityspec.api.rest.types; - -import java.util.List; - -@lombok.Data -public class ActivitySpecListResponseDto { - private String id; - private String version; - String name; - List categoryList; - private String status; -} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/types/ActivitySpecParameterDto.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/types/ActivitySpecParameterDto.java deleted file mode 100644 index 76e8262984..0000000000 --- a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/types/ActivitySpecParameterDto.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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.openecomp.activityspec.api.rest.types; - -@lombok.Data -public class ActivitySpecParameterDto { - private String name; - private String type; - private String value; -} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/types/ActivitySpecRequestDto.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/types/ActivitySpecRequestDto.java deleted file mode 100644 index 08b07b8031..0000000000 --- a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/types/ActivitySpecRequestDto.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright © 2016-2017 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.openecomp.activityspec.api.rest.types; - -import io.swagger.annotations.ApiModel; -import org.hibernate.validator.constraints.NotBlank; - -import javax.validation.constraints.Pattern; -import java.util.List; - -@ApiModel(value = "ActivitySpecRequest") -@lombok.Data -public class ActivitySpecRequestDto { - - @NotBlank(message = "Mandatory %s field is missing/null") - @Pattern(regexp = "^[a-zA-Z0-9-]*$", message = "%s should match with \"^[a-zA-Z0-9-]*$\" pattern") - private String name; - private String description; - - private List categoryList; - private List inputs; - private List outputs; - private String type; - private String content; -} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/types/InternalEmptyObject.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/types/InternalEmptyObject.java deleted file mode 100644 index 2faf7bcafa..0000000000 --- a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/rest/types/InternalEmptyObject.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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.openecomp.activityspec.api.rest.types; - -import org.codehaus.jackson.annotate.JsonAutoDetect; - -/** - * Object of this class can be used to create empty Response body like "{}" - */ -@JsonAutoDetect -public class InternalEmptyObject { - -} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/server/filters/ActivitySpecSessionContextFilter.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/server/filters/ActivitySpecSessionContextFilter.java deleted file mode 100644 index 715d0961e6..0000000000 --- a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/server/filters/ActivitySpecSessionContextFilter.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * 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.openecomp.activityspec.api.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 javax.servlet.http.HttpServletResponse; -import javax.ws.rs.core.HttpHeaders; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response.Status; -import org.apache.commons.lang.StringUtils; -import org.openecomp.sdc.common.session.SessionContextProvider; -import org.openecomp.sdc.common.session.SessionContextProviderFactory; - -import static org.openecomp.activityspec.utils.ActivitySpecConstant.TENANT; -import static org.openecomp.activityspec.utils.ActivitySpecConstant.USER; -import static org.openecomp.activityspec.utils.ActivitySpecConstant.USER_ID_HEADER_PARAM; - -public class ActivitySpecSessionContextFilter implements Filter { - - private static final String MESSAGE_USER_MAY_NOT_BE_NULL = "{\"message\": \"User ID can not be null\"}"; - - @Override - public void init(FilterConfig filterConfig) { - //No ActivitySpec specific initialization required - } - - @Override - public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, - FilterChain filterChain) throws IOException, ServletException { - - final String userHeader = ((HttpServletRequest) servletRequest).getHeader(USER_ID_HEADER_PARAM); - - // Not a real security, just make sure the request - // has passed some authentication gateway - if (StringUtils.isEmpty(userHeader)) { - sendErrorResponse(servletResponse); - return; - } - - SessionContextProvider contextProvider = SessionContextProviderFactory.getInstance().createInterface(); - - try { - // use the system-wide user and tenant - contextProvider.create(USER, TENANT); - filterChain.doFilter(servletRequest, servletResponse); - } finally { - contextProvider.close(); - } - } - - private void sendErrorResponse(ServletResponse servletResponse) throws IOException { - HttpServletResponse httpServletResponse = (HttpServletResponse) servletResponse; - httpServletResponse.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON); - httpServletResponse.setStatus(Status.UNAUTHORIZED.getStatusCode()); - servletResponse.getOutputStream().write(MESSAGE_USER_MAY_NOT_BE_NULL.getBytes()); - } - - @Override - public void destroy() { - //No ActivitySpec specific destroy required - } -} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/server/listeners/ActivitySpecAppStartupListener.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/server/listeners/ActivitySpecAppStartupListener.java deleted file mode 100644 index 8ddb7f3493..0000000000 --- a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/api/server/listeners/ActivitySpecAppStartupListener.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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.openecomp.activityspec.api.server.listeners; - -import org.openecomp.sdc.common.session.SessionContextProviderFactory; -import org.springframework.web.context.ContextLoaderListener; - -import javax.servlet.ServletContextEvent; -import javax.servlet.ServletContextListener; - -import static org.openecomp.activityspec.utils.ActivitySpecConstant.TENANT; -import static org.openecomp.activityspec.utils.ActivitySpecConstant.USER; - -public class ActivitySpecAppStartupListener implements ServletContextListener { - - ContextLoaderListener springListener; - - @Override - public void contextInitialized(ServletContextEvent servletContextEvent) { - SessionContextProviderFactory.getInstance().createInterface().create(USER, - TENANT); - springListener = new ContextLoaderListener(); - springListener.initWebApplicationContext(servletContextEvent.getServletContext()); - } - - @Override - public void contextDestroyed(ServletContextEvent servletContextEvent) { - springListener.closeWebApplicationContext(servletContextEvent.getServletContext()); - } -} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/ActivitySpecManager.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/ActivitySpecManager.java deleted file mode 100644 index 4fa41d029a..0000000000 --- a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/ActivitySpecManager.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright © 2016-2017 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.openecomp.activityspec.be; - -import java.util.Collection; - -import org.openecomp.activityspec.api.rest.types.ActivitySpecAction; -import org.openecomp.activityspec.be.dao.types.ActivitySpecEntity; -import org.openecomp.sdc.versioning.types.Item; - -public interface ActivitySpecManager { - - ActivitySpecEntity createActivitySpec(ActivitySpecEntity activitySpecEntity); - - ActivitySpecEntity get(ActivitySpecEntity activitySpec); - - void update(ActivitySpecEntity activitySpec); - - void actOnAction(String activitySpecId, String versionId, ActivitySpecAction action); - - Collection list(String versionStatus); -} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/dao/ActivitySpecDao.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/dao/ActivitySpecDao.java deleted file mode 100644 index 375adac876..0000000000 --- a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/dao/ActivitySpecDao.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright © 2016-2017 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.openecomp.activityspec.be.dao; - -import org.openecomp.activityspec.be.dao.types.ActivitySpecEntity; - -public interface ActivitySpecDao { - void create(ActivitySpecEntity activitySpecEntity); - - ActivitySpecEntity get(ActivitySpecEntity activitySpec); - - void update(ActivitySpecEntity activitySpec); -} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/dao/impl/ActivitySpecDaoZusammenImpl.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/dao/impl/ActivitySpecDaoZusammenImpl.java deleted file mode 100644 index 0dabcca984..0000000000 --- a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/dao/impl/ActivitySpecDaoZusammenImpl.java +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Copyright © 2016-2017 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.openecomp.activityspec.be.dao.impl; - -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.SessionContext; -import com.amdocs.zusammen.datatypes.item.Action; -import com.amdocs.zusammen.datatypes.item.ElementContext; -import com.amdocs.zusammen.datatypes.item.Info; - -import org.openecomp.activityspec.be.dao.ActivitySpecDao; -import org.openecomp.activityspec.be.dao.types.ActivitySpecEntity; -import org.openecomp.activityspec.utils.ActivitySpecConstant; -import org.openecomp.activityspec.be.datatypes.ActivitySpecData; -import org.openecomp.activityspec.be.datatypes.ElementType; -import org.openecomp.core.utilities.json.JsonUtil; -import org.openecomp.core.zusammen.api.ZusammenAdaptor; - -import java.io.ByteArrayInputStream; -import java.io.InputStream; -import java.util.Objects; -import java.util.Optional; - -import static org.openecomp.core.zusammen.api.ZusammenUtil.buildStructuralElement; -import static org.openecomp.core.zusammen.api.ZusammenUtil.createSessionContext; - -public class ActivitySpecDaoZusammenImpl implements ActivitySpecDao { - - private final ZusammenAdaptor zusammenAdaptor; - - public ActivitySpecDaoZusammenImpl(ZusammenAdaptor zusammenAdaptor) { - this.zusammenAdaptor = zusammenAdaptor; - } - - @Override - public void create(ActivitySpecEntity entity) { - SessionContext context = createSessionContext(); - ZusammenElement generalElement = mapActivityDetailsToZusammenElement(entity, Action.CREATE); - - ElementContext elementContext = - new ElementContext(entity.getId(), entity.getVersion().getId()); - zusammenAdaptor.saveElement(context, elementContext, generalElement, - "Create Activity Spec General Info Element"); - } - - @Override - public ActivitySpecEntity get(ActivitySpecEntity entity) { - SessionContext context = createSessionContext(); - - ElementContext elementContext = new ElementContext(entity.getId(), entity.getVersion().getId()); - Optional element = zusammenAdaptor.getElementByName(context, elementContext, - null, ElementType.ACTIVITYSPEC.name()); - if (element.isPresent()) { - return mapZusammenElementToActivityDetails(element.get()); - } else { - return null; - } - } - - @Override - public void update(ActivitySpecEntity entity) { - SessionContext context = createSessionContext(); - ZusammenElement generalElement = mapActivityDetailsToZusammenElement(entity, Action.UPDATE); - - ElementContext elementContext = - new ElementContext(entity.getId(), entity.getVersion().getId()); - zusammenAdaptor.saveElement(context, elementContext, generalElement, - "Update Activity Spec General Info Element"); - } - - - 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 ZusammenElement mapActivityDetailsToZusammenElement(ActivitySpecEntity entity, - Action action) { - ZusammenElement generalElement = - buildStructuralElement(ElementType.ACTIVITYSPEC.name(), action); - - enrichElementInfoFromEntity(generalElement, entity); - enrichElementDataFromEntity(generalElement, entity); - return generalElement; - } - - - 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())); - } - - 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 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())); - } - - 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/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/dao/types/ActivitySpecEntity.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/dao/types/ActivitySpecEntity.java deleted file mode 100644 index 2f261f8fa9..0000000000 --- a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/dao/types/ActivitySpecEntity.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright © 2016-2017 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.openecomp.activityspec.be.dao.types; - -import org.openecomp.activityspec.be.datatypes.ActivitySpecParameter; -import org.openecomp.sdc.versioning.dao.types.Version; - -import java.util.List; - -@lombok.Data -public class ActivitySpecEntity { - private String id; - private Version version; - 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; -} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/datatypes/ActivitySpecData.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/datatypes/ActivitySpecData.java deleted file mode 100644 index ad70376aa2..0000000000 --- a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/datatypes/ActivitySpecData.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * 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.openecomp.activityspec.be.datatypes; - -import java.util.Collections; -import java.util.List; - -@lombok.Data -public class ActivitySpecData { - private List inputs = Collections.emptyList(); - private List outputs = Collections.emptyList(); - private String type; - private String content; -} - diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/datatypes/ActivitySpecParameter.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/datatypes/ActivitySpecParameter.java deleted file mode 100644 index b9153fa5d9..0000000000 --- a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/datatypes/ActivitySpecParameter.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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.openecomp.activityspec.be.datatypes; - -@lombok.Data -public class ActivitySpecParameter { - private String name; - private String type; - private String value; - - @SuppressWarnings("unused") - public ActivitySpecParameter() { - // default constructor for automatic tools that use reflection - } - - public ActivitySpecParameter(String name, String type) { - this.name = name; - this.type = type; - } -} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/datatypes/ElementType.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/datatypes/ElementType.java deleted file mode 100644 index be7e61ca8c..0000000000 --- a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/datatypes/ElementType.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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.openecomp.activityspec.be.datatypes; - -public enum ElementType { - ACTIVITYSPEC; -} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/datatypes/ItemType.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/datatypes/ItemType.java deleted file mode 100644 index 5091412d08..0000000000 --- a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/datatypes/ItemType.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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.openecomp.activityspec.be.datatypes; - -public enum ItemType { - ACTIVITYSPEC -} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/impl/ActivitySpecManagerImpl.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/impl/ActivitySpecManagerImpl.java deleted file mode 100644 index 44383734e8..0000000000 --- a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/impl/ActivitySpecManagerImpl.java +++ /dev/null @@ -1,291 +0,0 @@ -/* - * Copyright © 2016-2017 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.openecomp.activityspec.be.impl; - -import static org.openecomp.activityspec.api.rest.types.ActivitySpecAction.CERTIFY; -import static org.openecomp.activityspec.api.rest.types.ActivitySpecAction.DELETE; -import static org.openecomp.activityspec.api.rest.types.ActivitySpecAction.DEPRECATE; -import static org.openecomp.activityspec.utils.ActivitySpecConstant.ACTIVITY_SPEC_NOT_FOUND; -import static org.openecomp.activityspec.utils.ActivitySpecConstant.INVALID_STATE; -import static org.openecomp.sdc.versioning.dao.types.VersionStatus.Certified; -import static org.openecomp.sdc.versioning.dao.types.VersionStatus.Deleted; -import static org.openecomp.sdc.versioning.dao.types.VersionStatus.Deprecated; -import static org.openecomp.sdc.versioning.dao.types.VersionStatus.Draft; - -import java.util.Collection; -import java.util.Collections; -import java.util.EnumMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.function.Predicate; -import org.openecomp.activityspec.api.rest.types.ActivitySpecAction; -import org.openecomp.activityspec.be.ActivitySpecManager; -import org.openecomp.activityspec.be.dao.ActivitySpecDao; -import org.openecomp.activityspec.be.dao.types.ActivitySpecEntity; -import org.openecomp.activityspec.be.datatypes.ItemType; -import org.openecomp.activityspec.errors.ActivitySpecNotFoundException; -import org.openecomp.activityspec.utils.ActivitySpecConstant; -import org.openecomp.core.dao.UniqueValueDao; -import org.openecomp.core.util.UniqueValueUtil; -import org.openecomp.sdc.common.errors.CoreException; -import org.openecomp.sdc.common.errors.ErrorCategory; -import org.openecomp.sdc.common.errors.ErrorCode; -import org.openecomp.sdc.common.errors.SdcRuntimeException; -import org.openecomp.sdc.logging.api.Logger; -import org.openecomp.sdc.logging.api.LoggerFactory; -import org.openecomp.sdc.versioning.ItemManager; -import org.openecomp.sdc.versioning.VersioningManager; -import org.openecomp.sdc.versioning.dao.types.Version; -import org.openecomp.sdc.versioning.dao.types.VersionStatus; -import org.openecomp.sdc.versioning.types.Item; -import org.openecomp.sdc.versioning.types.VersionCreationMethod; - -public class ActivitySpecManagerImpl implements ActivitySpecManager { - - private static final Map TRANSITIONS; - - static { - TRANSITIONS = new EnumMap<>(VersionStatus.class); - TRANSITIONS.put(Certified, new Transition("Certify", Draft)); - TRANSITIONS.put(Deprecated, new Transition("Deprecate", Certified)); - TRANSITIONS.put(Deleted, new Transition("Delete", Deprecated)); - } - - private final ItemManager itemManager; - private final VersioningManager versioningManager; - private final ActivitySpecDao activitySpecDao; - private final UniqueValueUtil uniqueValueUtil; - private static final String ACTIVITY_SPEC_NAME = "ActivitySpec.Name"; - private static final Logger LOGGER = - LoggerFactory.getLogger(ActivitySpecManagerImpl.class); - - public ActivitySpecManagerImpl(ItemManager itemManager, - VersioningManager versioningManager, - ActivitySpecDao activitySpecDao, - UniqueValueDao uniqueValueDao) { - this.itemManager = itemManager; - this.versioningManager = versioningManager; - this.activitySpecDao = activitySpecDao; - this.uniqueValueUtil = new UniqueValueUtil(uniqueValueDao); - } - - @Override - public ActivitySpecEntity createActivitySpec(ActivitySpecEntity activitySpecEntity) { - - validateUniqueValue(activitySpecEntity); - - Item item = getActivitySpecItem(activitySpecEntity); - item = itemManager.create(item); - - Version version = getActivitySpecVersion(activitySpecEntity); - versioningManager.create(item.getId(), version, VersionCreationMethod.major); - - enrichActivitySpec(item, version, activitySpecEntity); - activitySpecDao.create(activitySpecEntity); - - uniqueValueUtil.createUniqueValue(ACTIVITY_SPEC_NAME, activitySpecEntity.getName()); - return activitySpecEntity; - } - - private void validateUniqueValue(ActivitySpecEntity activitySpecEntity) { - try { - uniqueValueUtil.validateUniqueValue(ACTIVITY_SPEC_NAME, activitySpecEntity.getName()); - } catch (CoreException exception) { - LOGGER.debug("Unique value error for activity spec name :" + activitySpecEntity.getName(), exception); - throw new CoreException(new ErrorCode.ErrorCodeBuilder() - .withCategory(ErrorCategory.APPLICATION) - .withId(exception.code().id()) - .withMessage("name already in use").build()); - } - } - - private Version getActivitySpecVersion(ActivitySpecEntity activitySpecEntity) { - return activitySpecEntity.getVersion() == null ? new Version() - : activitySpecEntity.getVersion(); - - } - - @Override - public ActivitySpecEntity get(ActivitySpecEntity activitySpec) { - activitySpec.setVersion(calculateLatestVersion(activitySpec.getId(),activitySpec.getVersion())); - ActivitySpecEntity retrieved; - try { - retrieved = activitySpecDao.get(activitySpec); - } catch (SdcRuntimeException runtimeException) { - LOGGER.debug("Failed to retrieve activity spec for activitySpecId: " + activitySpec.getId() - + " and version: " + activitySpec.getVersion().getId(), runtimeException); - throw new ActivitySpecNotFoundException(ACTIVITY_SPEC_NOT_FOUND, runtimeException); - } - if (retrieved != null) { - final Version retrievedVersion = versioningManager.get(activitySpec.getId(), - activitySpec.getVersion()); - retrieved.setStatus(Objects.nonNull(retrievedVersion) ? retrievedVersion.getStatus().name() - : null); - } - return retrieved; - } - - @Override - public void update(ActivitySpecEntity activitySpec) { - - ActivitySpecEntity previousActivitySpec = get(activitySpec); - - if (!activitySpec.getName().equals(previousActivitySpec.getName())) { - validateUniqueValue(activitySpec); - } - - activitySpecDao.update(activitySpec); - - if (!activitySpec.getName().equals(previousActivitySpec.getName())) { - uniqueValueUtil.createUniqueValue(ACTIVITY_SPEC_NAME, activitySpec.getName()); - itemManager.updateName(activitySpec.getId(), activitySpec.getName()); - uniqueValueUtil.deleteUniqueValue(ACTIVITY_SPEC_NAME, previousActivitySpec.getName()); - } - } - - @Override - public void actOnAction(String activitySpecId, String versionId, ActivitySpecAction action) { - Version version = new Version(versionId); - version = calculateLatestVersion(activitySpecId, version); - if (action == CERTIFY) { - version.setStatus(Certified); - } - if (action == DEPRECATE) { - version.setStatus(Deprecated); - } - if (action == DELETE) { - version.setStatus(Deleted); - } - - updateVersionStatus(activitySpecId, action, version); - if (action == DELETE) { - ActivitySpecEntity entity = new ActivitySpecEntity(); - entity.setId(activitySpecId); - entity.setVersion(version); - final ActivitySpecEntity activitySpecEntity = get(entity); - uniqueValueUtil.deleteUniqueValue(ACTIVITY_SPEC_NAME, activitySpecEntity.getName()); - } - } - - private void updateVersionStatus(String activitySpecId, ActivitySpecAction action, - Version version) { - VersionStatus prevVersionStatus = null; - Version retrievedVersion; - try { - retrievedVersion = versioningManager.get(activitySpecId, version); - } catch (SdcRuntimeException exception) { - LOGGER.debug("Failed to get version for activitySpecId: " + activitySpecId - + " and version: " + version.getId(), exception); - throw new ActivitySpecNotFoundException(ACTIVITY_SPEC_NOT_FOUND, exception); - - } - - VersionStatus status = version.getStatus(); - Transition transition = TRANSITIONS.get(status); - if (transition != null) { - - VersionStatus retrievedStatus = Objects.nonNull(retrievedVersion) ? retrievedVersion.getStatus() : null; - if (retrievedStatus != transition.prevStatus) { - LOGGER.debug("Failed to " + version.getStatus() + " since activity spec is in " - + retrievedStatus); - throw new CoreException(new ErrorCode.ErrorCodeBuilder() - .withMessage(INVALID_STATE).build()); - } - prevVersionStatus = transition.prevStatus; - } - - if (Objects.nonNull(retrievedVersion)) { - retrievedVersion.setStatus(status); - versioningManager.updateVersion(activitySpecId, retrievedVersion); - itemManager.updateVersionStatus(activitySpecId, status, prevVersionStatus); - versioningManager.publish(activitySpecId, retrievedVersion, "actionOnActivitySpec :" - + action.name()); - } - } - - private Version calculateLatestVersion(String activitySpecId, Version version) { - if (ActivitySpecConstant.VERSION_ID_DEFAULT_VALUE.equalsIgnoreCase(version.getId())) { - List list; - try { - list = versioningManager.list(activitySpecId); - } catch (SdcRuntimeException runtimeException) { - LOGGER.debug("Failed to list versions for activitySpecId " - + activitySpecId, runtimeException); - throw new ActivitySpecNotFoundException(ACTIVITY_SPEC_NOT_FOUND, runtimeException); - } - if (Objects.nonNull(list) && !list.isEmpty()) { - return list.get(0); - } - } - return version; - } - - @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); - } - - private void enrichActivitySpec(Item item, Version version, - ActivitySpecEntity activitySpecEntity) { - activitySpecEntity.setId(item.getId()); - activitySpecEntity.setVersion(version); - } - - private Item getActivitySpecItem(ActivitySpecEntity activitySpecEntity) { - Item item = new Item(); - item.setType(ItemType.ACTIVITYSPEC.name()); - item.setName(activitySpecEntity.getName()); - if (activitySpecEntity.getId() != null) { - item.setId(activitySpecEntity.getId()); - } - item.addProperty(ActivitySpecConstant.CATEGORY_ATTRIBUTE_NAME, - activitySpecEntity.getCategoryList()); - return item; - } - - private static class Transition { - - private final String action; - private final VersionStatus prevStatus; - - private Transition(String action, VersionStatus prevStatus) { - this.action = action; - this.prevStatus = prevStatus; - } - } - -} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/errors/ActivitySpecErrorResponse.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/errors/ActivitySpecErrorResponse.java deleted file mode 100644 index 18ae886d87..0000000000 --- a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/errors/ActivitySpecErrorResponse.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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.openecomp.activityspec.errors; - -@lombok.Data -public class ActivitySpecErrorResponse { - private String message; - - public ActivitySpecErrorResponse() { - //default constructor - } - - public ActivitySpecErrorResponse(String message) { - this.message = message; - } -} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/errors/ActivitySpecNotFoundException.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/errors/ActivitySpecNotFoundException.java deleted file mode 100644 index 8c775f935c..0000000000 --- a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/errors/ActivitySpecNotFoundException.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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.openecomp.activityspec.errors; - -public class ActivitySpecNotFoundException extends RuntimeException { - - public ActivitySpecNotFoundException(String message, Throwable cause) { - super(message, cause); - } -} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/errors/DefaultExceptionMapper.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/errors/DefaultExceptionMapper.java deleted file mode 100644 index 950988a4b1..0000000000 --- a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/errors/DefaultExceptionMapper.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * 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.openecomp.activityspec.errors; - -import java.util.Set; -import javax.validation.ConstraintViolation; -import javax.validation.ConstraintViolationException; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.Response.Status; -import javax.ws.rs.ext.ExceptionMapper; -import org.codehaus.jackson.map.JsonMappingException; -import org.hibernate.validator.internal.engine.path.PathImpl; -import org.openecomp.sdc.common.errors.CoreException; -import org.openecomp.sdc.logging.api.Logger; -import org.openecomp.sdc.logging.api.LoggerFactory; - -public class DefaultExceptionMapper implements ExceptionMapper { - - private static final Logger LOGGER = LoggerFactory.getLogger(DefaultExceptionMapper.class); - - @Override - public Response toResponse(Exception exception) { - Response response; - if (exception instanceof CoreException) { - response = transform(CoreException.class.cast(exception)); - } else if (exception instanceof ActivitySpecNotFoundException) { - response = transform(ActivitySpecNotFoundException.class.cast(exception)); - } else if (exception instanceof ConstraintViolationException) { - response = transform(ConstraintViolationException.class.cast(exception)); - } else if (exception instanceof JsonMappingException) { - response = transform(JsonMappingException.class.cast(exception)); - } else { - response = transform(exception); - } - - return response; - } - - private Response transform(ActivitySpecNotFoundException notFoundException) { - LOGGER.error("Transforming ActivitySpecNotFoundException to Error Response :", notFoundException); - return generateResponse(Status.NOT_FOUND, new ActivitySpecErrorResponse(notFoundException.getMessage())); - } - - private Response transform(CoreException coreException) { - LOGGER.error("Transforming CoreException to Error Response :", coreException); - return generateResponse(Status.BAD_REQUEST, new ActivitySpecErrorResponse(coreException.getMessage())); - } - - private Response transform(ConstraintViolationException validationException) { - LOGGER.error("Transforming ConstraintViolationException to Error Response :", - validationException); - Set> constraintViolationSet = validationException - .getConstraintViolations(); - String message; - - String fieldName = null; - if (constraintViolationSet != null) { - // getting the first violation message for the output response. - ConstraintViolation constraintViolation = constraintViolationSet.iterator().next(); - message = constraintViolation.getMessage(); - fieldName = ((PathImpl) constraintViolation.getPropertyPath()).getLeafNode().toString(); - - } else { - message = validationException.getMessage(); - } - return generateResponse(Status.BAD_REQUEST, new ActivitySpecErrorResponse(String.format(message,fieldName))); - } - - private Response transform(Exception exception) { - LOGGER.error("Transforming Exception to Error Response " + exception); - return generateResponse(Status.INTERNAL_SERVER_ERROR, new ActivitySpecErrorResponse(exception.getMessage())); - } - - private Response transform(JsonMappingException jsonMappingException) { - LOGGER.error("Transforming JsonMappingException to Error Response " + jsonMappingException); - return generateResponse(Status.BAD_REQUEST, new ActivitySpecErrorResponse("Invalid Json Input")); - } - - private Response generateResponse(Response.Status status, ActivitySpecErrorResponse - activitySpecErrorResponse) { - return Response.status(status).entity(activitySpecErrorResponse).type(MediaType - .APPLICATION_JSON).build(); - } -} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/utils/ActivitySpecConstant.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/utils/ActivitySpecConstant.java deleted file mode 100644 index f63810d884..0000000000 --- a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/utils/ActivitySpecConstant.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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.openecomp.activityspec.utils; - -public class ActivitySpecConstant { - - public static final String CATEGORY_ATTRIBUTE_NAME = "category"; - public static final String VERSION_ID_DEFAULT_VALUE = "latest"; - public static final String TENANT = "activity_spec"; - public static final String USER = "activity_spec_USER"; - public static final String USER_ID_HEADER_PARAM = "USER_ID"; - public static final String ACTIVITY_SPEC_NOT_FOUND = "No Activity Spec found for the given identifiers"; - public static final String INVALID_STATE = "Activity Spec is in an invalid state"; - - private ActivitySpecConstant(){ - //Utility Class declaring constants does not require instantiation. - } -} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/test/java/org/onap/sdc/activityspec/be/dao/impl/ActivitySpecZusammenDaoImplTest.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/test/java/org/onap/sdc/activityspec/be/dao/impl/ActivitySpecZusammenDaoImplTest.java new file mode 100644 index 0000000000..26b9adb89c --- /dev/null +++ b/services/activity-spec/activity-spec-web/activity-spec-service/src/test/java/org/onap/sdc/activityspec/be/dao/impl/ActivitySpecZusammenDaoImplTest.java @@ -0,0 +1,368 @@ +/* + * 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.activityspec.be.dao.impl; + +import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element; +import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementConflict; +import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementInfo; +import com.amdocs.zusammen.adaptor.inbound.api.types.item.ItemVersionConflict; +import com.amdocs.zusammen.adaptor.inbound.api.types.item.ZusammenElement; +import com.amdocs.zusammen.commons.health.data.HealthInfo; +import com.amdocs.zusammen.datatypes.Id; +import com.amdocs.zusammen.datatypes.SessionContext; +import com.amdocs.zusammen.datatypes.item.Action; +import com.amdocs.zusammen.datatypes.item.ElementContext; +import com.amdocs.zusammen.datatypes.item.Info; +import com.amdocs.zusammen.datatypes.item.Item; +import com.amdocs.zusammen.datatypes.item.ItemVersion; +import com.amdocs.zusammen.datatypes.item.ItemVersionData; +import com.amdocs.zusammen.datatypes.item.ItemVersionStatus; +import com.amdocs.zusammen.datatypes.item.Resolution; +import com.amdocs.zusammen.datatypes.itemversion.ItemVersionRevisions; +import com.amdocs.zusammen.datatypes.itemversion.Tag; + +import java.io.InputStream; + +import org.onap.sdc.activityspec.be.dao.impl.ActivitySpecDaoZusammenImpl.InfoPropertyName; +import org.onap.sdc.activityspec.be.dao.types.ActivitySpecEntity; +import org.onap.sdc.activityspec.be.datatypes.ActivitySpecData; +import org.onap.sdc.activityspec.be.datatypes.ActivitySpecParameter; +import org.onap.sdc.activityspec.be.datatypes.ElementType; +import org.openecomp.core.utilities.json.JsonUtil; +import org.openecomp.core.zusammen.api.ZusammenAdaptor; +import org.openecomp.sdc.common.session.SessionContextProviderFactory; +import org.openecomp.sdc.versioning.dao.types.Version; +import org.openecomp.types.ElementPropertyName; +import org.testng.Assert; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.UUID; +import java.util.stream.Collectors; + +import static org.openecomp.core.zusammen.api.ZusammenUtil.createSessionContext; + +public class ActivitySpecZusammenDaoImplTest { + + private static final Version version = new Version(); + private static final String versionId = "1234"; + private static final String itemId = "5678"; + private static final String tenant = "dox"; + + private ZusammenAdaptorMock zusammenAdaptor; + private ActivitySpecDaoZusammenImpl daoImpl; + private ActivitySpecEntity entity; + + + @BeforeMethod + public void setUp() { + SessionContextProviderFactory.getInstance().createInterface().create("test", tenant); + zusammenAdaptor = new ZusammenAdaptorMock(); + daoImpl = new ActivitySpecDaoZusammenImpl(zusammenAdaptor); + entity = new ActivitySpecEntity(); + entity = new ActivitySpecEntity(); + + entity.setId(itemId); + version.setId(versionId); + entity.setVersion(version); + entity.setName("activitySpec"); + List categoryList = new ArrayList<>(); + categoryList.add("category1"); + entity.setCategoryList(categoryList); + ActivitySpecParameter inputParams = new ActivitySpecParameter("dbhost", "String"); + inputParams.setValue("localhost"); + List inputs = new ArrayList<>(); + inputs.add(inputParams); + entity.setInputs(inputs); + } + + @AfterMethod + public void tearDown() { + SessionContextProviderFactory.getInstance().createInterface().close(); + } + + @Test + public void testCreate() { + ItemVersion itemVersionmock = new ItemVersion(); + itemVersionmock.setId(new Id()); + + daoImpl.create(entity); + SessionContext context = createSessionContext(); + ElementContext elementContext = new ElementContext(entity.getId(), entity.getVersion().getId()); + Optional testElementInfo = + zusammenAdaptor.getElementInfoByName(context, elementContext, Id.ZERO, ElementType.ACTIVITYSPEC.name()); + Assert.assertTrue(testElementInfo.isPresent()); + Assert.assertEquals(testElementInfo.get().getInfo().getName(), ElementType.ACTIVITYSPEC.name()); + Assert.assertEquals(testElementInfo.get().getInfo().getProperty( + ActivitySpecDaoZusammenImpl.InfoPropertyName.DESCRIPTION.getValue()), entity.getDescription()); + Assert.assertEquals(testElementInfo.get().getInfo().getProperty(InfoPropertyName.CATEGORY.getValue()), + entity.getCategoryList()); + Assert.assertEquals(testElementInfo.get().getInfo() + .getProperty(ActivitySpecDaoZusammenImpl.InfoPropertyName.NAME.getValue()), + entity.getName()); + + final Optional testElement = + zusammenAdaptor.getElement(context, elementContext, zusammenAdaptor.elementId); + final InputStream data = testElement.get().getData(); + final ActivitySpecData activitySpecData = JsonUtil.json2Object(data, ActivitySpecData.class); + Assert.assertEquals(activitySpecData.getInputs().get(0).getName(), entity.getInputs().get(0).getName()); + } + + @Test + public void testGet() { + final ActivitySpecEntity retrieved = daoImpl.get(entity); + Assert.assertEquals(retrieved.getName(), entity.getName()); + Assert.assertEquals(retrieved.getDescription(), entity.getDescription()); + Assert.assertEquals(retrieved.getCategoryList(), entity.getCategoryList()); + } + + @Test + public void testUpdate() { + entity.setDescription("Update AS version1"); + daoImpl.update(entity); + final ActivitySpecEntity retrieved = daoImpl.get(entity); + Assert.assertEquals(retrieved.getName(), entity.getName()); + Assert.assertEquals(retrieved.getDescription(), entity.getDescription()); + Assert.assertEquals(retrieved.getCategoryList(), entity.getCategoryList()); + } + + private class ZusammenAdaptorMock implements ZusammenAdaptor { + + private ItemVersion itemVersion; + private final Map elementMap = new HashMap<>(); + String elementId; + + @Override + public Optional getFirstVersion(SessionContext context, Id itemId) { + + return Optional.ofNullable(itemVersion); + } + + @Override + public Collection listPublicVersions(SessionContext context, Id itemId) { + return null; + } + + @Override + public ItemVersion getPublicVersion(SessionContext context, Id itemId, Id versionId) { + return null; + } + + @Override + public Optional getElement(SessionContext context, ElementContext elementContext, String elementId) { + return Optional.of(elementMap.get(elementId)); + } + + @Override + public Optional getElementByName(SessionContext context, ElementContext elementContext, + Id parentElementId, String elementName) { + //return Optional.empty(); + ZusammenElement element = new ZusammenElement(); + Info info = new Info(); + element.setElementId(Id.ZERO); + info.addProperty("name", entity.getName()); + info.addProperty("description", entity.getDescription()); + info.addProperty("category", entity.getCategoryList()); + element.setInfo(info); + return Optional.ofNullable(element); + } + + @Override + public Collection listElements(SessionContext context, ElementContext elementContext, + Id parentElementId) { + return null; + } + + @Override + public Collection listElementData(SessionContext context, ElementContext elementContext, + Id parentElementId) { + return elementMap.values(); + } + + @Override + public Collection listElementsByName(SessionContext context, ElementContext elementContext, + Id parentElementId, String elementName) { + + return elementMap.values().stream() + .filter(element -> elementName.equals(element.getInfo() + .getProperty( + ElementPropertyName.elementType + .name()))) + .map(element -> { + ElementInfo elementInfo = new ElementInfo(); + elementInfo.setId(element.getElementId()); + elementInfo.setInfo(element.getInfo()); + return elementInfo; + }).collect(Collectors.toList()); + + } + + @Override + public Optional getElementInfoByName(SessionContext context, ElementContext elementContext, + Id parentElementId, String elementName) { + + + return elementMap.values().stream() + .filter(element -> elementName.equals(element.getInfo() + .getProperty( + ElementPropertyName.elementType + .name()))) + .map(element -> { + ElementInfo elementInfo = new ElementInfo(); + elementInfo.setId(element.getElementId()); + elementInfo.setInfo(element.getInfo()); + return elementInfo; + }).findAny(); + + + } + + @Override + public Element saveElement(SessionContext context, ElementContext elementContext, ZusammenElement element, + String message) { + if (element.getAction().equals(Action.CREATE) || element.getAction().equals(Action.UPDATE)) { + element.setElementId(new Id(UUID.randomUUID().toString())); + } + elementMap.put(element.getElementId().getValue(), element); + elementId = element.getElementId().getValue(); + return element; + } + + @Override + public void resolveElementConflict(SessionContext context, ElementContext elementContext, + ZusammenElement element, Resolution resolution) { + + } + + @Override + public Collection checkHealth(SessionContext context) { + return null; + } + + @Override + public Id createItem(SessionContext context, Info info) { + return null; + } + + @Override + public void updateItem(SessionContext context, Id itemId, Info info) { + + } + + @Override + public Id createVersion(SessionContext context, Id itemId, Id baseVersionId, ItemVersionData itemVersionData) { + return null; + } + + @Override + public void updateVersion(SessionContext context, Id itemId, Id versionId, ItemVersionData itemVersionData) { + + } + + @Override + public ItemVersion getVersion(SessionContext context, Id itemId, Id versionId) { + return null; + } + + @Override + public String getVersion(SessionContext sessionContext) { + return null; + } + + @Override + public ItemVersionStatus getVersionStatus(SessionContext context, Id itemId, Id versionId) { + return null; + } + + @Override + public ItemVersionConflict getVersionConflict(SessionContext context, Id itemId, Id versionId) { + return null; + } + + @Override + public void tagVersion(SessionContext context, Id itemId, Id versionId, Tag tag) { + + } + + @Override + public void resetVersionHistory(SessionContext context, Id itemId, Id versionId, String changeRef) { + + } + + + @Override + public void publishVersion(SessionContext context, Id itemId, Id versionId, String message) { + + } + + @Override + public void syncVersion(SessionContext sessionContext, Id itemId, Id versionId) { + + } + + @Override + public void forceSyncVersion(SessionContext context, Id itemId, Id versionId) { + + } + + @Override + public Optional getElementInfo(SessionContext context, ElementContext elementContext, + Id elementId) { + return Optional.empty(); + } + + @Override + public void revert(SessionContext sessionContext, Id itemId, Id versionId, Id revisionId) { + + } + + @Override + public ItemVersionRevisions listRevisions(SessionContext sessionContext, Id itemId, Id versionId) { + return null; + } + + @Override + public Optional getElementConflict(SessionContext context, ElementContext elementContext, + Id id) { + return Optional.empty(); + } + + @Override + public Collection listItems(SessionContext context) { + return null; + } + + @Override + public Item getItem(SessionContext context, Id itemId) { + return null; + } + + @Override + public void deleteItem(SessionContext context, Id itemId) { + + } + + } + +} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/test/java/org/onap/sdc/activityspec/be/impl/ActivitySpecManagerImplTest.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/test/java/org/onap/sdc/activityspec/be/impl/ActivitySpecManagerImplTest.java new file mode 100644 index 0000000000..21d1709537 --- /dev/null +++ b/services/activity-spec/activity-spec-web/activity-spec-service/src/test/java/org/onap/sdc/activityspec/be/impl/ActivitySpecManagerImplTest.java @@ -0,0 +1,302 @@ +/* + * 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.activityspec.be.impl; + +import java.util.Arrays; +import java.util.Collection; + +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.mockito.Spy; +import org.onap.sdc.activityspec.be.dao.ActivitySpecDao; +import org.onap.sdc.activityspec.api.rest.types.ActivitySpecAction; +import org.onap.sdc.activityspec.be.dao.types.ActivitySpecEntity; +import org.onap.sdc.activityspec.be.datatypes.ActivitySpecParameter; +import org.onap.sdc.activityspec.errors.ActivitySpecNotFoundException; +import org.openecomp.core.dao.UniqueValueDao; +import org.openecomp.sdc.common.errors.CoreException; +import org.openecomp.sdc.common.errors.SdcRuntimeException; +import org.openecomp.sdc.common.session.SessionContextProviderFactory; +import org.openecomp.sdc.versioning.ItemManager; +import org.openecomp.sdc.versioning.VersioningManager; +import org.openecomp.sdc.versioning.dao.types.Version; +import org.openecomp.sdc.versioning.dao.types.VersionStatus; +import org.openecomp.sdc.versioning.types.Item; +import org.testng.Assert; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import java.util.ArrayList; +import java.util.List; + +import static org.mockito.Matchers.anyObject; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.verify; +import static org.onap.sdc.activityspec.utils.ActivitySpecConstant.ACTIVITY_SPEC_NOT_FOUND; +import static org.onap.sdc.activityspec.utils.ActivitySpecConstant.INVALID_STATE; +import static org.onap.sdc.activityspec.utils.ActivitySpecConstant.VERSION_ID_DEFAULT_VALUE; + +public class ActivitySpecManagerImplTest { + + private static final String STRING_TYPE = "String"; + private static final String TEST_ERROR_MSG = "Test Error"; + private ActivitySpecEntity input; + private static final Version VERSION01 = new Version("12345"); + private static final String ID = "ID1"; + + @Spy + @InjectMocks + private ActivitySpecManagerImpl activitySpecManager; + + @Mock + private ItemManager itemManagerMock; + + @Mock + private VersioningManager versionManagerMock; + + @Mock + private ActivitySpecDao activitySpecDaoMock; + + //This is used to mock UniqueValueUtil. This should not be removed. + @Mock + private UniqueValueDao uniqueValueDaoMock; + + @BeforeMethod + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + } + + @AfterMethod + public void tearDown() { + activitySpecManager = null; + } + + @Test + public void testCreate() { + + SessionContextProviderFactory.getInstance().createInterface().create("testUser", "testTenant"); + + ActivitySpecEntity activitySpecToCreate = new ActivitySpecEntity(); + activitySpecToCreate.setName("startserver"); + activitySpecToCreate.setDescription("start the server"); + activitySpecToCreate.setVersion(VERSION01); + + List categoryList = new ArrayList<>(); + categoryList.add("category1"); + categoryList.add("category2"); + activitySpecToCreate.setCategoryList(categoryList); + + ActivitySpecParameter inputParams = new ActivitySpecParameter("dbhost", STRING_TYPE); + inputParams.setValue("localhost"); + ActivitySpecParameter inputParams1 = new ActivitySpecParameter("dbname", STRING_TYPE); + inputParams.setValue("prod"); + List inputs = new ArrayList<>(); + inputs.add(inputParams); + inputs.add(inputParams1); + activitySpecToCreate.setInputs(inputs); + + ActivitySpecParameter outputParams = new ActivitySpecParameter("status", STRING_TYPE); + outputParams.setValue("started"); + List outputs = new ArrayList<>(); + outputs.add(outputParams); + activitySpecToCreate.setOutputs(outputs); + + activitySpecToCreate.setId("ID1"); + activitySpecToCreate.setVersion(VERSION01); + + Item item = new Item(); + doReturn(item).when(itemManagerMock).create(anyObject()); + + ActivitySpecEntity activitySpec = activitySpecManager.createActivitySpec(activitySpecToCreate); + + Assert.assertNotNull(activitySpec); + activitySpec.setId("ID1"); + activitySpec.setStatus(VersionStatus.Draft.name()); + assertActivitySpecEquals(activitySpec, activitySpecToCreate); + } + + + @Test + public void testList() { + ActivitySpecEntity activitySpec = new ActivitySpecEntity(); + activitySpec.setName("stopServer"); + doReturn(Arrays.asList(activitySpec)).when(itemManagerMock).list(anyObject()); + final Collection activitySpecs = activitySpecManager.list("Certified"); + Assert.assertEquals(activitySpecs.size(), 1); + } + + @Test + public void testListInvalidFilter() { + final Collection activitySpecs = activitySpecManager.list("invalid_status"); + Assert.assertEquals(activitySpecs.size(), 0); + } + + @Test + public void testListNoFilter() { + final Collection activitySpecs = activitySpecManager.list(null); + Assert.assertEquals(activitySpecs.size(), 0); + } + + @Test + public void testGet() { + input = new ActivitySpecEntity(); + input.setId(ID); + input.setVersion(VERSION01); + + doReturn(Arrays.asList(VERSION01)).when(versionManagerMock).list(anyObject()); + doReturn(input).when(activitySpecDaoMock).get(anyObject()); + VERSION01.setStatus(VersionStatus.Draft); + doReturn(VERSION01).when(versionManagerMock).get(anyObject(), anyObject()); + ActivitySpecEntity retrieved = activitySpecManager.get(input); + assertActivitySpecEquals(retrieved, input); + Assert.assertEquals(retrieved.getStatus(), VersionStatus.Draft.name()); + + + input.setVersion(new Version(VERSION_ID_DEFAULT_VALUE)); + retrieved = activitySpecManager.get(input); + assertActivitySpecEquals(retrieved, input); + Assert.assertEquals(retrieved.getStatus(), VersionStatus.Draft.name()); + } + + @Test + public void testGetActivitySpecDaoFail() { + input = new ActivitySpecEntity(); + input.setId(ID); + input.setVersion(VERSION01); + doReturn(Arrays.asList(VERSION01)).when(versionManagerMock).list(anyObject()); + doReturn(input).when(activitySpecDaoMock).get(anyObject()); + doThrow(new SdcRuntimeException(TEST_ERROR_MSG)).when(activitySpecDaoMock).get(anyObject()); + try { + activitySpecManager.get(input); + Assert.fail(); + } catch (ActivitySpecNotFoundException exception) { + Assert.assertEquals(exception.getMessage(), ACTIVITY_SPEC_NOT_FOUND); + } + } + + @Test + public void testListVersionFail() { + input = new ActivitySpecEntity(); + input.setId(ID); + input.setVersion(VERSION01); + input.getVersion().setId(VERSION_ID_DEFAULT_VALUE); + doThrow(new SdcRuntimeException(TEST_ERROR_MSG)).when(versionManagerMock).list(anyObject()); + try { + activitySpecManager.get(input); + Assert.fail(); + } catch (ActivitySpecNotFoundException exception) { + Assert.assertEquals(exception.getMessage(), ACTIVITY_SPEC_NOT_FOUND); + } + } + + @Test + public void testInvalidDeprecate() { + try { + activitySpecManager.actOnAction(ID, VERSION01.getId(), ActivitySpecAction.DEPRECATE); + } catch (CoreException exception) { + Assert.assertEquals(exception.getMessage(), INVALID_STATE); + } + } + + @Test + public void testInvalidDelete() { + try { + activitySpecManager.actOnAction(ID, VERSION01.getId(), ActivitySpecAction.DELETE); + } catch (CoreException exception) { + Assert.assertEquals(exception.getMessage(), INVALID_STATE); + } + } + + @Test + public void testCertify() { + doReturn(Arrays.asList(VERSION01)).when(versionManagerMock).list(anyObject()); + doReturn(VERSION01).when(versionManagerMock).get(anyObject(), anyObject()); + activitySpecManager.actOnAction(ID, VERSION01.getId(), ActivitySpecAction.CERTIFY); + + verify(versionManagerMock).updateVersion(ID, VERSION01); + verify(itemManagerMock).updateVersionStatus(ID, VersionStatus.Certified, VersionStatus.Draft); + verify(versionManagerMock).publish(anyObject(), anyObject(), anyObject()); + } + + @Test + public void testInvalidCertify() { + try { + activitySpecManager.actOnAction(ID, VERSION01.getId(), ActivitySpecAction.CERTIFY); + } catch (CoreException exception) { + Assert.assertEquals(exception.getMessage(), INVALID_STATE); + } + } + + @Test + public void testGetVersionFailOnStatusChangeAction() { + doReturn(Arrays.asList(VERSION01)).when(versionManagerMock).list(anyObject()); + doThrow(new SdcRuntimeException(TEST_ERROR_MSG)).when(versionManagerMock).get(anyObject(), anyObject()); + try { + activitySpecManager.actOnAction(ID, VERSION01.getId(), ActivitySpecAction.CERTIFY); + Assert.fail(); + } catch (ActivitySpecNotFoundException exception) { + Assert.assertEquals(exception.getMessage(), ACTIVITY_SPEC_NOT_FOUND); + } + } + + @Test + public void testDeprecate() { + VERSION01.setStatus(VersionStatus.Certified); + Version retrivedVersion = new Version("12"); + retrivedVersion.setStatus(VersionStatus.Certified); + doReturn(Arrays.asList(VERSION01)).when(versionManagerMock).list(anyObject()); + doReturn(retrivedVersion).when(versionManagerMock).get(anyObject(), anyObject()); + activitySpecManager.actOnAction(ID, VERSION_ID_DEFAULT_VALUE, ActivitySpecAction.DEPRECATE); + + verify(versionManagerMock).updateVersion(ID, retrivedVersion); + verify(itemManagerMock).updateVersionStatus(ID, VersionStatus.Deprecated, VersionStatus.Certified); + verify(versionManagerMock).publish(anyObject(), anyObject(), anyObject()); + } + + @Test + public void testDelete() { + ActivitySpecEntity activitySpec = new ActivitySpecEntity(); + VERSION01.setStatus(VersionStatus.Deprecated); + activitySpec.setName("stopServer"); + activitySpec.setVersion(VERSION01); + + Version retrivedVersion = new Version("12"); + retrivedVersion.setStatus(VersionStatus.Deprecated); + + doReturn(Arrays.asList(VERSION01)).when(versionManagerMock).list(anyObject()); + doReturn(retrivedVersion).when(versionManagerMock).get(anyObject(), anyObject()); + doReturn(activitySpec).when(activitySpecDaoMock).get(anyObject()); + activitySpecManager.actOnAction(ID, VERSION_ID_DEFAULT_VALUE, ActivitySpecAction.DELETE); + + verify(versionManagerMock).updateVersion(ID, VERSION01); + verify(itemManagerMock).updateVersionStatus(ID, VersionStatus.Deleted, VersionStatus.Deprecated); + verify(versionManagerMock).publish(anyObject(), anyObject(), anyObject()); + } + + private void assertActivitySpecEquals(ActivitySpecEntity actual, ActivitySpecEntity expected) { + Assert.assertEquals(actual.getId(), expected.getId()); + Assert.assertEquals(actual.getName(), expected.getName()); + Assert.assertEquals(actual.getDescription(), expected.getDescription()); + Assert.assertEquals(actual.getCategoryList(), expected.getCategoryList()); + Assert.assertEquals(actual.getInputs(), expected.getInputs()); + Assert.assertEquals(actual.getOutputs(), expected.getOutputs()); + } + +} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/test/java/org/openecomp/activityspec/be/dao/impl/ActivitySpecZusammenDaoImplTest.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/test/java/org/openecomp/activityspec/be/dao/impl/ActivitySpecZusammenDaoImplTest.java deleted file mode 100644 index b03f4544d2..0000000000 --- a/services/activity-spec/activity-spec-web/activity-spec-service/src/test/java/org/openecomp/activityspec/be/dao/impl/ActivitySpecZusammenDaoImplTest.java +++ /dev/null @@ -1,400 +0,0 @@ -/* - * 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.openecomp.activityspec.be.dao.impl; - -import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element; -import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementConflict; -import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementInfo; -import com.amdocs.zusammen.adaptor.inbound.api.types.item.ItemVersionConflict; -import com.amdocs.zusammen.adaptor.inbound.api.types.item.ZusammenElement; -import com.amdocs.zusammen.commons.health.data.HealthInfo; -import com.amdocs.zusammen.datatypes.Id; -import com.amdocs.zusammen.datatypes.SessionContext; -import com.amdocs.zusammen.datatypes.item.Action; -import com.amdocs.zusammen.datatypes.item.ElementContext; -import com.amdocs.zusammen.datatypes.item.Info; -import com.amdocs.zusammen.datatypes.item.Item; -import com.amdocs.zusammen.datatypes.item.ItemVersion; -import com.amdocs.zusammen.datatypes.item.ItemVersionData; -import com.amdocs.zusammen.datatypes.item.ItemVersionStatus; -import com.amdocs.zusammen.datatypes.item.Resolution; -import com.amdocs.zusammen.datatypes.itemversion.ItemVersionRevisions; -import com.amdocs.zusammen.datatypes.itemversion.Tag; -import java.io.InputStream; -import org.openecomp.activityspec.be.dao.impl.ActivitySpecDaoZusammenImpl.InfoPropertyName; -import org.openecomp.activityspec.be.datatypes.ActivitySpecData; -import org.openecomp.activityspec.be.datatypes.ActivitySpecParameter; -import org.openecomp.core.utilities.json.JsonUtil; -import org.openecomp.core.zusammen.api.ZusammenAdaptor; -import org.openecomp.activityspec.be.dao.types.ActivitySpecEntity; -import org.openecomp.activityspec.be.datatypes.ElementType; -import org.openecomp.sdc.common.session.SessionContextProviderFactory; -import org.openecomp.sdc.versioning.dao.types.Version; -import org.openecomp.types.ElementPropertyName; -import org.testng.Assert; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.UUID; -import java.util.stream.Collectors; - -import static org.mockito.Mockito.verify; -import static org.openecomp.core.zusammen.api.ZusammenUtil.createSessionContext; - -public class ActivitySpecZusammenDaoImplTest { - - private static final Version version = new Version(); - private static final String versionId = "1234"; - private static final String itemId = "5678"; - private static final String tenant = "dox"; - - ZusammenAdaptorMock zusammenAdaptor; - ActivitySpecDaoZusammenImpl daoImpl; - ActivitySpecEntity entity; - - - @BeforeMethod - public void setUp(){ - SessionContextProviderFactory.getInstance().createInterface().create("test", - tenant); - zusammenAdaptor = new ZusammenAdaptorMock(); - daoImpl = new ActivitySpecDaoZusammenImpl(zusammenAdaptor); - entity = new ActivitySpecEntity(); - entity = new ActivitySpecEntity(); - - entity.setId(itemId); - version.setId(versionId); - entity.setVersion(version); - entity.setName("activitySpec"); - List categoryList = new ArrayList(); - categoryList.add("category1"); - entity.setCategoryList(categoryList); - ActivitySpecParameter inputParams = new ActivitySpecParameter("dbhost", "String"); - inputParams.setValue("localhost"); - List inputs = new ArrayList<>(); - inputs.add(inputParams); - entity.setInputs(inputs); - } - - @AfterMethod - public void tearDown(){ - SessionContextProviderFactory.getInstance().createInterface().close(); - } - - @Test - public void testCreate() { - ItemVersion itemVersionmock = new ItemVersion(); - itemVersionmock.setId(new Id()); - - daoImpl.create(entity); - SessionContext context = createSessionContext(); - ElementContext elementContext = - new ElementContext(entity.getId(), entity.getVersion().getId()); - Optional testElementInfo = - zusammenAdaptor.getElementInfoByName(context, elementContext,Id.ZERO, - ElementType.ACTIVITYSPEC.name() ); - Assert.assertTrue(testElementInfo.isPresent()); - Assert.assertEquals(testElementInfo.get().getInfo().getName(), ElementType.ACTIVITYSPEC.name()); - Assert.assertEquals(testElementInfo.get().getInfo().getProperty( - ActivitySpecDaoZusammenImpl.InfoPropertyName.DESCRIPTION.getValue()), - entity.getDescription()); - Assert.assertEquals(testElementInfo.get().getInfo().getProperty( - InfoPropertyName.CATEGORY.getValue()), - entity.getCategoryList()); - Assert.assertEquals(testElementInfo.get().getInfo().getProperty( - ActivitySpecDaoZusammenImpl.InfoPropertyName.NAME.getValue()), - entity.getName()); - - final Optional testElement = zusammenAdaptor - .getElement(context, elementContext, zusammenAdaptor.elementId); - final InputStream data = testElement.get().getData(); - final ActivitySpecData activitySpecData = JsonUtil.json2Object(data, ActivitySpecData.class); - Assert.assertEquals(activitySpecData.getInputs().get(0).getName(), - entity.getInputs().get(0).getName()); - } - - @Test - public void testGet () { - SessionContext context = createSessionContext(); - ElementContext elementContext = - new ElementContext(entity.getId(), entity.getVersion().getId()); - final ActivitySpecEntity retrieved = daoImpl.get(entity); - Assert.assertEquals(retrieved.getName(), entity.getName()); - Assert.assertEquals(retrieved.getDescription(), entity.getDescription()); - Assert.assertEquals(retrieved.getCategoryList(), entity.getCategoryList()); - } - - @Test - public void testUpdate () { - SessionContext context = createSessionContext(); - ElementContext elementContext = - new ElementContext(entity.getId(), entity.getVersion().getId()); - entity.setDescription("Update AS version1"); - daoImpl.update(entity); - final ActivitySpecEntity retrieved = daoImpl.get(entity); - Assert.assertEquals(retrieved.getName(), entity.getName()); - Assert.assertEquals(retrieved.getDescription(), entity.getDescription()); - Assert.assertEquals(retrieved.getCategoryList(), entity.getCategoryList()); - } - - private class ZusammenAdaptorMock implements ZusammenAdaptor { - - private ItemVersion itemVersion; - private Map elementMap = new HashMap<>(); - String elementId; - - /* private void setItemVersion(ItemVersion itemVersion) { - this.itemVersion = itemVersion; - } - - private void addElementInfo(String key, ElementInfo elementInfo) { - elementInfoMap.put(key, elementInfo); - } - - private void addElement(Element element) { - elements.add(element); - }*/ - - @Override - public Optional getFirstVersion(SessionContext context, Id itemId) { - - return Optional.ofNullable(itemVersion); - } - - @Override - public Collection listPublicVersions(SessionContext context, Id itemId) { - return null; - } - - @Override - public ItemVersion getPublicVersion(SessionContext context, Id itemId, Id versionId) { - return null; - } - - @Override - public Optional getElement(SessionContext context, ElementContext elementContext, - String elementId) { - return Optional.of(elementMap.get(elementId)); - } - - @Override - public Optional getElementByName(SessionContext context, - ElementContext elementContext, - Id parentElementId, String elementName) { - //return Optional.empty(); - ZusammenElement element = new ZusammenElement(); - Info info = new Info(); - element.setElementId(Id.ZERO); - info.addProperty("name", entity.getName()); - info.addProperty("description", entity.getDescription()); - info.addProperty("category", entity.getCategoryList()); - element.setInfo(info); - return Optional.ofNullable(element); - } - - @Override - public Collection listElements(SessionContext context, - ElementContext elementContext, - Id parentElementId) { - return null; - } - - @Override - public Collection listElementData(SessionContext context, - ElementContext elementContext, - Id parentElementId) { - return elementMap.values(); - } - - @Override - public Collection listElementsByName(SessionContext context, - ElementContext elementContext, - Id parentElementId, String elementName) { - - return elementMap.values().stream(). - filter(element->elementName.equals(element.getInfo().getProperty - (ElementPropertyName.elementType.name()))).map(element->{ - ElementInfo elementInfo = new ElementInfo(); - elementInfo.setId(element.getElementId()); - elementInfo.setInfo(element.getInfo()); - return elementInfo; - }).collect(Collectors.toList()); - - } - - @Override - public Optional getElementInfoByName(SessionContext context, - ElementContext elementContext, - Id parentElementId, String elementName) { - - - return elementMap.values().stream(). - filter(element -> elementName.equals(element.getInfo().getProperty - (ElementPropertyName.elementType.name()))).map(element -> { - ElementInfo elementInfo = new ElementInfo(); - elementInfo.setId(element.getElementId()); - elementInfo.setInfo(element.getInfo()); - return elementInfo; - }).findAny(); - - - - } - - @Override - public Element saveElement(SessionContext context, ElementContext elementContext, - ZusammenElement element, String message) { - if(element.getAction().equals(Action.CREATE) || - element.getAction().equals(Action.UPDATE)){ - element.setElementId(new Id(UUID.randomUUID().toString())); - } - elementMap.put(element.getElementId().getValue(),element); - elementId = element.getElementId().getValue(); - return element; - } - - @Override - public void resolveElementConflict(SessionContext context, ElementContext elementContext, - ZusammenElement element, Resolution resolution) { - - } - - @Override - public Collection checkHealth(SessionContext context) { - return null; - } - - @Override - public Id createItem(SessionContext context, Info info) { - return null; - } - - @Override - public void updateItem(SessionContext context, Id itemId, Info info) { - - } - - @Override - public Id createVersion(SessionContext context, Id itemId, Id baseVersionId, - ItemVersionData itemVersionData) { - return null; - } - - @Override - public void updateVersion(SessionContext context, Id itemId, Id versionId, - ItemVersionData itemVersionData) { - - } - - @Override - public ItemVersion getVersion(SessionContext context, Id itemId, Id versionId) { - return null; - } - - @Override - public ItemVersionStatus getVersionStatus(SessionContext context, Id itemId, Id versionId) { - return null; - } - - @Override - public ItemVersionConflict getVersionConflict(SessionContext context, Id itemId, Id versionId) { - return null; - } - - @Override - public void tagVersion(SessionContext context, Id itemId, Id versionId, Tag tag) { - - } - - @Override - public void resetVersionHistory(SessionContext context, Id itemId, Id versionId, - String changeRef) { - - } - - - @Override - public void publishVersion(SessionContext context, Id itemId, Id versionId, String message) { - - } - - @Override - public void syncVersion(SessionContext sessionContext, Id itemId, Id versionId) { - - } - - @Override - public void forceSyncVersion(SessionContext context, Id itemId, Id versionId) { - - } - - @Override - public Optional getElementInfo(SessionContext context, - ElementContext elementContext, - Id elementId) { - return Optional.empty(); - } - - @Override - public String getVersion(SessionContext sessionContext) { - return null; - } - - @Override - public void revert(SessionContext sessionContext, Id itemId, Id versionId, - Id revisionId) { - - } - - @Override - public ItemVersionRevisions listRevisions(SessionContext sessionContext, Id itemId, - Id versionId) { - return null; - } - - @Override - public Optional getElementConflict(SessionContext context, - ElementContext elementContext, - Id id) { - return Optional.empty(); - } - - @Override - public Collection listItems(SessionContext context) { - return null; - } - - @Override - public Item getItem(SessionContext context, Id itemId) { - return null; - } - - @Override - public void deleteItem(SessionContext context, Id itemId) { - - } - - } - -} diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/test/java/org/openecomp/activityspec/be/impl/ActivitySpecManagerImplTest.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/test/java/org/openecomp/activityspec/be/impl/ActivitySpecManagerImplTest.java deleted file mode 100644 index e930dd9454..0000000000 --- a/services/activity-spec/activity-spec-web/activity-spec-service/src/test/java/org/openecomp/activityspec/be/impl/ActivitySpecManagerImplTest.java +++ /dev/null @@ -1,318 +0,0 @@ -/* - * 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.openecomp.activityspec.be.impl; - -import java.util.Arrays; -import java.util.Collection; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.mockito.Spy; -import org.openecomp.activityspec.api.rest.types.ActivitySpecAction; -import org.openecomp.activityspec.be.dao.ActivitySpecDao; -import org.openecomp.activityspec.be.dao.types.ActivitySpecEntity; -import org.openecomp.activityspec.be.datatypes.ActivitySpecParameter; -import org.openecomp.activityspec.errors.ActivitySpecNotFoundException; -import org.openecomp.core.dao.UniqueValueDao; -import org.openecomp.sdc.common.errors.CoreException; -import org.openecomp.sdc.common.errors.SdcRuntimeException; -import org.openecomp.sdc.common.session.SessionContextProviderFactory; -import org.openecomp.sdc.versioning.ItemManager; -import org.openecomp.sdc.versioning.VersioningManager; -import org.openecomp.sdc.versioning.dao.types.Version; -import org.openecomp.sdc.versioning.dao.types.VersionStatus; -import org.openecomp.sdc.versioning.types.Item; -import org.testng.Assert; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import java.util.ArrayList; -import java.util.List; - -import static org.mockito.Matchers.anyObject; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.verify; -import static org.openecomp.activityspec.utils.ActivitySpecConstant.ACTIVITY_SPEC_NOT_FOUND; -import static org.openecomp.activityspec.utils.ActivitySpecConstant.INVALID_STATE; -import static org.openecomp.activityspec.utils.ActivitySpecConstant.VERSION_ID_DEFAULT_VALUE; - -public class ActivitySpecManagerImplTest { - - private static final String STRING_TYPE = "String"; - private static final String TEST_ERROR_MSG = "Test Error"; - private ActivitySpecEntity input; - private static final Version VERSION01 = new Version("12345"); - private static final String ID = "ID1"; - - @Spy - @InjectMocks - private ActivitySpecManagerImpl activitySpecManager; - - @Mock - private ItemManager itemManagerMock; - - @Mock - private VersioningManager versionManagerMock; - - @Mock - private ActivitySpecDao activitySpecDaoMock; - - //This is used to mock UniqueValueUtil. This should not be removed. - @Mock - private UniqueValueDao uniqueValueDaoMock; - - @BeforeMethod - public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); - } - - @AfterMethod - public void tearDown() { - activitySpecManager = null; - } - - @Test - public void testCreate() { - - SessionContextProviderFactory.getInstance().createInterface().create("testUser", "testTenant"); - - ActivitySpecEntity activitySpecToCreate = new ActivitySpecEntity(); - activitySpecToCreate.setName("startserver"); - activitySpecToCreate.setDescription("start the server"); - activitySpecToCreate.setVersion(VERSION01); - - List categoryList = new ArrayList<>(); - categoryList.add("category1"); - categoryList.add("category2"); - activitySpecToCreate.setCategoryList(categoryList); - - ActivitySpecParameter inputParams = new ActivitySpecParameter("dbhost", STRING_TYPE); - inputParams.setValue("localhost"); - ActivitySpecParameter inputParams1 = new ActivitySpecParameter("dbname", STRING_TYPE); - inputParams.setValue("prod"); - List inputs = new ArrayList<>(); - inputs.add(inputParams); - inputs.add(inputParams1); - activitySpecToCreate.setInputs(inputs); - - ActivitySpecParameter outputParams = new ActivitySpecParameter("status", STRING_TYPE); - outputParams.setValue("started"); - List outputs = new ArrayList<>(); - outputs.add(outputParams); - activitySpecToCreate.setOutputs(outputs); - - activitySpecToCreate.setId("ID1"); - activitySpecToCreate.setVersion(VERSION01); - - Item item = new Item(); - doReturn(item).when(itemManagerMock).create(anyObject()); - - ActivitySpecEntity activitySpec = activitySpecManager.createActivitySpec - (activitySpecToCreate); - - Assert.assertNotNull(activitySpec); - activitySpec.setId("ID1"); - activitySpec.setStatus(VersionStatus.Draft.name()); - assertActivitySpecEquals(activitySpec, activitySpecToCreate); - } - - - - @Test - public void testList () { - ActivitySpecEntity activitySpec = new ActivitySpecEntity(); - activitySpec.setName("stopServer"); - doReturn(Arrays.asList( - activitySpec)) - .when(itemManagerMock).list(anyObject()); - final Collection activitySpecs = activitySpecManager.list("Certified"); - Assert.assertEquals(activitySpecs.size(), 1); - } - - @Test - public void testListInvalidFilter () { - final Collection activitySpecs = activitySpecManager.list("invalid_status"); - Assert.assertEquals(activitySpecs.size(), 0); - } - - @Test - public void testListNoFilter () { - final Collection activitySpecs = activitySpecManager.list(null); - Assert.assertEquals(activitySpecs.size(), 0); - } - - @Test - public void testGet () { - input = new ActivitySpecEntity(); - input.setId(ID); - input.setVersion(VERSION01); - - doReturn(Arrays.asList(VERSION01)).when(versionManagerMock).list(anyObject()); - doReturn(input).when(activitySpecDaoMock).get(anyObject()); - VERSION01.setStatus(VersionStatus.Draft); - doReturn(VERSION01).when(versionManagerMock).get(anyObject(), anyObject()); - ActivitySpecEntity retrieved = activitySpecManager.get(input); - assertActivitySpecEquals(retrieved, input); - Assert.assertEquals(retrieved.getStatus(), VersionStatus.Draft.name()); - - - input.setVersion(new Version(VERSION_ID_DEFAULT_VALUE)); - retrieved = activitySpecManager.get(input); - assertActivitySpecEquals(retrieved, input); - Assert.assertEquals(retrieved.getStatus(), VersionStatus.Draft.name()); - } - - @Test - public void testGetActivitySpecDaoFail () { - input = new ActivitySpecEntity(); - input.setId(ID); - input.setVersion(VERSION01); - doReturn(Arrays.asList(VERSION01)).when(versionManagerMock).list(anyObject()); - doReturn(input).when(activitySpecDaoMock).get(anyObject()); - doThrow(new SdcRuntimeException(TEST_ERROR_MSG)).when(activitySpecDaoMock).get(anyObject()); - try { - activitySpecManager.get(input); - Assert.fail(); - } catch (ActivitySpecNotFoundException exception) { - Assert.assertEquals(exception.getMessage(), ACTIVITY_SPEC_NOT_FOUND); - } - } - - @Test - public void testListVersionFail () { - input = new ActivitySpecEntity(); - input.setId(ID); - input.setVersion(VERSION01); - input.getVersion().setId(VERSION_ID_DEFAULT_VALUE); - doThrow(new SdcRuntimeException(TEST_ERROR_MSG)).when(versionManagerMock).list(anyObject()); - try { - activitySpecManager.get(input); - Assert.fail(); - } catch (ActivitySpecNotFoundException exception) { - Assert.assertEquals(exception.getMessage(), ACTIVITY_SPEC_NOT_FOUND); - } - } - - @Test - public void testInvalidDeprecate () { - try { - activitySpecManager.actOnAction(ID, - VERSION01.getId(), ActivitySpecAction.DEPRECATE); - } - catch (CoreException exception) { - Assert.assertEquals(exception.getMessage(), INVALID_STATE); - } - } - - @Test - public void testInvalidDelete () { - try { - activitySpecManager.actOnAction(ID, - VERSION01.getId(), ActivitySpecAction.DELETE); - } - catch (CoreException exception) { - Assert.assertEquals(exception.getMessage(), INVALID_STATE); - } - } - - @Test - public void testCertify () { - doReturn(Arrays.asList(VERSION01)).when(versionManagerMock).list(anyObject()); - doReturn(VERSION01).when(versionManagerMock).get(anyObject(), anyObject()); - activitySpecManager.actOnAction(ID, - VERSION01.getId(), ActivitySpecAction.CERTIFY); - - verify(versionManagerMock).updateVersion(ID, VERSION01); - verify(itemManagerMock).updateVersionStatus(ID, VersionStatus.Certified, - VersionStatus.Draft); - verify(versionManagerMock).publish(anyObject(), anyObject(), anyObject()); - } - - @Test - public void testInvalidCertify () { - try { - activitySpecManager.actOnAction(ID, - VERSION01.getId(), ActivitySpecAction.CERTIFY); - } - catch (CoreException exception) { - Assert.assertEquals(exception.getMessage(), INVALID_STATE); - } - } - - @Test - public void testGetVersionFailOnStatusChangeAction () { - doReturn(Arrays.asList(VERSION01)).when(versionManagerMock).list(anyObject()); - doThrow(new SdcRuntimeException(TEST_ERROR_MSG)).when(versionManagerMock).get(anyObject(), anyObject()); - try { - activitySpecManager.actOnAction(ID, - VERSION01.getId(), ActivitySpecAction.CERTIFY); - Assert.fail(); - } catch (ActivitySpecNotFoundException exception) { - Assert.assertEquals(exception.getMessage(), ACTIVITY_SPEC_NOT_FOUND); - } - } - - @Test - public void testDeprecate () { - VERSION01.setStatus(VersionStatus.Certified); - Version retrivedVersion = new Version("12"); - retrivedVersion.setStatus(VersionStatus.Certified); - doReturn(Arrays.asList(VERSION01)).when(versionManagerMock).list(anyObject()); - doReturn(retrivedVersion).when(versionManagerMock).get(anyObject(), anyObject()); - activitySpecManager.actOnAction(ID, - VERSION_ID_DEFAULT_VALUE, ActivitySpecAction.DEPRECATE); - - verify(versionManagerMock).updateVersion(ID, retrivedVersion); - verify(itemManagerMock).updateVersionStatus(ID, VersionStatus.Deprecated, - VersionStatus.Certified); - verify(versionManagerMock).publish(anyObject(), anyObject(), anyObject()); - } - - @Test - public void testDelete () { - ActivitySpecEntity activitySpec = new ActivitySpecEntity(); - VERSION01.setStatus(VersionStatus.Deprecated); - activitySpec.setName("stopServer"); - activitySpec.setVersion(VERSION01); - - Version retrivedVersion = new Version("12"); - retrivedVersion.setStatus(VersionStatus.Deprecated); - - doReturn(Arrays.asList(VERSION01)).when(versionManagerMock).list(anyObject()); - doReturn(retrivedVersion).when(versionManagerMock).get(anyObject(), anyObject()); - doReturn(activitySpec).when(activitySpecDaoMock).get(anyObject()); - activitySpecManager.actOnAction(ID, - VERSION_ID_DEFAULT_VALUE, ActivitySpecAction.DELETE); - - verify(versionManagerMock).updateVersion(ID, VERSION01); - verify(itemManagerMock).updateVersionStatus(ID, VersionStatus.Deleted, - VersionStatus.Deprecated); - verify(versionManagerMock).publish(anyObject(), anyObject(), anyObject()); - } - - private void assertActivitySpecEquals(ActivitySpecEntity actual, ActivitySpecEntity expected) { - Assert.assertEquals(actual.getId(), expected.getId()); - Assert.assertEquals(actual.getName(), expected.getName()); - Assert.assertEquals(actual.getDescription(), expected.getDescription()); - Assert.assertEquals(actual.getCategoryList(), expected.getCategoryList()); - Assert.assertEquals(actual.getInputs(), expected.getInputs()); - Assert.assertEquals(actual.getOutputs(), expected.getOutputs()); - } - -} diff --git a/services/activity-spec/activity-spec-web/activity-spec-war/pom.xml b/services/activity-spec/activity-spec-web/activity-spec-war/pom.xml index 7d9c2c7f0b..fa2092a8c3 100644 --- a/services/activity-spec/activity-spec-web/activity-spec-war/pom.xml +++ b/services/activity-spec/activity-spec-web/activity-spec-war/pom.xml @@ -8,7 +8,7 @@ war - org.openecomp.activityspec + org.onap.sdc.activityspec activity-spec 1.2.0-SNAPSHOT ../.. @@ -16,7 +16,7 @@ - org.openecomp.activityspec + org.onap.sdc.activityspec activity-spec-service ${project.version} @@ -53,7 +53,7 @@ false - org.openecomp.activityspec + org.onap.sdc.activityspec http /activity-spec-api diff --git a/services/activity-spec/activity-spec-web/activity-spec-war/src/main/webapp/WEB-INF/beans-services.xml b/services/activity-spec/activity-spec-web/activity-spec-war/src/main/webapp/WEB-INF/beans-services.xml index 11bf98477c..245f3b8fdd 100644 --- a/services/activity-spec/activity-spec-web/activity-spec-war/src/main/webapp/WEB-INF/beans-services.xml +++ b/services/activity-spec/activity-spec-web/activity-spec-war/src/main/webapp/WEB-INF/beans-services.xml @@ -2,11 +2,9 @@ + http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd"> @@ -27,7 +25,7 @@ + class="org.onap.sdc.activityspec.api.rest.services.ActivitySpecsImpl"/> @@ -38,7 +36,7 @@ - + diff --git a/services/activity-spec/activity-spec-web/activity-spec-war/src/main/webapp/WEB-INF/web.xml b/services/activity-spec/activity-spec-web/activity-spec-war/src/main/webapp/WEB-INF/web.xml index 0a78e8e61e..229ef9fd4a 100644 --- a/services/activity-spec/activity-spec-web/activity-spec-war/src/main/webapp/WEB-INF/web.xml +++ b/services/activity-spec/activity-spec-web/activity-spec-war/src/main/webapp/WEB-INF/web.xml @@ -12,12 +12,12 @@ - org.openecomp.activityspec.api.server.listeners.ActivitySpecAppStartupListener + org.onap.sdc.activityspec.api.server.listeners.ActivitySpecAppStartupListener SessionContextFilter - org.openecomp.activityspec.api.server.filters.ActivitySpecSessionContextFilter + org.onap.sdc.activityspec.api.server.filters.ActivitySpecSessionContextFilter SessionContextFilter diff --git a/services/activity-spec/activity-spec-web/pom.xml b/services/activity-spec/activity-spec-web/pom.xml index 799c9d2b9e..a1df9771fd 100644 --- a/services/activity-spec/activity-spec-web/pom.xml +++ b/services/activity-spec/activity-spec-web/pom.xml @@ -7,7 +7,7 @@ pom - org.openecomp.activityspec + org.onap.sdc.activityspec activity-spec 1.2.0-SNAPSHOT diff --git a/services/activity-spec/pom.xml b/services/activity-spec/pom.xml index 72b3bf5c62..fddf2302d7 100644 --- a/services/activity-spec/pom.xml +++ b/services/activity-spec/pom.xml @@ -4,7 +4,7 @@ 4.0.0 - org.openecomp.activityspec + org.onap.sdc.activityspec activity-spec 1.2.0-SNAPSHOT pom -- cgit 1.2.3-korg