2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdcrests.vsp.rest.services;
23 import org.apache.commons.collections4.CollectionUtils;
24 import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductManager;
25 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity;
26 import org.openecomp.sdc.vendorsoftwareproduct.types.CompositionEntityResponse;
27 import org.openecomp.sdc.vendorsoftwareproduct.types.CompositionEntityValidationData;
28 import org.openecomp.sdc.vendorsoftwareproduct.types.QuestionnaireResponse;
29 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComponentData;
30 import org.openecomp.sdc.versioning.dao.types.Version;
31 import org.openecomp.sdcrests.vendorsoftwareproducts.types.ComponentDto;
32 import org.openecomp.sdcrests.vendorsoftwareproducts.types.ComponentRequestDto;
33 import org.openecomp.sdcrests.vendorsoftwareproducts.types.CompositionEntityResponseDto;
34 import org.openecomp.sdcrests.vendorsoftwareproducts.types.CompositionEntityValidationDataDto;
35 import org.openecomp.sdcrests.vendorsoftwareproducts.types.QuestionnaireResponseDto;
36 import org.openecomp.sdcrests.vsp.rest.Components;
37 import org.openecomp.sdcrests.vsp.rest.mapping.MapComponentDataToComponentDto;
38 import org.openecomp.sdcrests.vsp.rest.mapping.MapComponentEntityToComponentDto;
39 import org.openecomp.sdcrests.vsp.rest.mapping.MapComponentRequestDtoToComponentEntity;
40 import org.openecomp.sdcrests.vsp.rest.mapping.MapCompositionEntityResponseToDto;
41 import org.openecomp.sdcrests.vsp.rest.mapping.MapCompositionEntityValidationDataToDto;
42 import org.openecomp.sdcrests.vsp.rest.mapping.MapQuestionnaireResponseToQuestionnaireResponseDto;
43 import org.openecomp.sdcrests.wrappers.GenericCollectionWrapper;
44 import org.openecomp.sdcrests.wrappers.StringWrapperResponse;
46 import org.springframework.beans.factory.annotation.Autowired;
47 import org.springframework.context.annotation.Scope;
48 import org.springframework.stereotype.Service;
50 import java.util.Collection;
51 import javax.inject.Named;
52 import javax.ws.rs.core.Response;
56 @Service("components")
57 @Scope(value = "prototype")
58 public class ComponentsImpl implements Components {
60 private VendorSoftwareProductManager vendorSoftwareProductManager;
63 public Response list(String vspId, String version, String user) {
64 Collection<ComponentEntity> components =
65 vendorSoftwareProductManager.listComponents(vspId, Version.valueOf(version), user);
67 MapComponentEntityToComponentDto mapper = new MapComponentEntityToComponentDto();
68 GenericCollectionWrapper<ComponentDto> results = new GenericCollectionWrapper<>();
69 for (ComponentEntity component : components) {
70 results.add(mapper.applyMapping(component, ComponentDto.class));
73 return Response.ok(results).build();
77 public Response deleteList(String vspId, String user) {
78 vendorSoftwareProductManager.deleteComponents(vspId, user);
79 return Response.ok().build();
83 public Response create(ComponentRequestDto request, String vspId, String user) {
84 ComponentEntity component =
85 new MapComponentRequestDtoToComponentEntity().applyMapping(request, ComponentEntity.class);
86 component.setVspId(vspId);
87 ComponentEntity createdComponent =
88 vendorSoftwareProductManager.createComponent(component, user);
90 .ok(createdComponent != null ? new StringWrapperResponse(createdComponent.getId()) : null)
95 public Response get(String vspId, String componentId, String version, String user) {
96 CompositionEntityResponse<ComponentData> response = vendorSoftwareProductManager
97 .getComponent(vspId, Version.valueOf(version), componentId, user);
99 CompositionEntityResponseDto<ComponentDto> responseDto = new CompositionEntityResponseDto<>();
100 new MapCompositionEntityResponseToDto<>(new MapComponentDataToComponentDto(),
101 ComponentDto.class).doMapping(response, responseDto);
102 return Response.ok(responseDto).build();
106 public Response delete(String vspId, String componentId, String user) {
107 vendorSoftwareProductManager.deleteComponent(vspId, componentId, user);
108 return Response.ok().build();
112 public Response update(ComponentRequestDto request, String vspId, String componentId,
114 ComponentEntity componentEntity =
115 new MapComponentRequestDtoToComponentEntity().applyMapping(request, ComponentEntity.class);
116 componentEntity.setVspId(vspId);
117 componentEntity.setId(componentId);
119 CompositionEntityValidationData validationData =
120 vendorSoftwareProductManager.updateComponent(componentEntity, user);
121 return validationData != null && CollectionUtils.isNotEmpty(validationData.getErrors())
122 ? Response.status(Response.Status.EXPECTATION_FAILED).entity(
123 new MapCompositionEntityValidationDataToDto()
124 .applyMapping(validationData, CompositionEntityValidationDataDto.class)).build() :
125 Response.ok().build();
129 public Response getQuestionnaire(String vspId, String componentId, String version, String user) {
130 QuestionnaireResponse questionnaireResponse = vendorSoftwareProductManager
131 .getComponentQuestionnaire(vspId, Version.valueOf(version), componentId, user);
133 QuestionnaireResponseDto result = new MapQuestionnaireResponseToQuestionnaireResponseDto()
134 .applyMapping(questionnaireResponse, QuestionnaireResponseDto.class);
135 return Response.ok(result).build();
139 public Response updateQuestionnaire(String questionnaireData, String vspId, String componentId,
141 vendorSoftwareProductManager
142 .updateComponentQuestionnaire(vspId, componentId, questionnaireData, user);
143 return Response.ok().build();