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.NicEntity;
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.Nic;
30 import org.openecomp.sdc.versioning.dao.types.Version;
32 import org.openecomp.sdcrests.vendorsoftwareproducts.types.CompositionEntityResponseDto;
33 import org.openecomp.sdcrests.vendorsoftwareproducts.types.CompositionEntityValidationDataDto;
34 import org.openecomp.sdcrests.vendorsoftwareproducts.types.NicDto;
35 import org.openecomp.sdcrests.vendorsoftwareproducts.types.NicRequestDto;
36 import org.openecomp.sdcrests.vendorsoftwareproducts.types.QuestionnaireResponseDto;
37 import org.openecomp.sdcrests.vsp.rest.Nics;
38 import org.openecomp.sdcrests.vsp.rest.mapping.MapCompositionEntityResponseToDto;
39 import org.openecomp.sdcrests.vsp.rest.mapping.MapCompositionEntityValidationDataToDto;
40 import org.openecomp.sdcrests.vsp.rest.mapping.MapNicEntityToNicDto;
41 import org.openecomp.sdcrests.vsp.rest.mapping.MapNicRequestDtoToNicEntity;
42 import org.openecomp.sdcrests.vsp.rest.mapping.MapNicToNicDto;
43 import org.openecomp.sdcrests.vsp.rest.mapping.MapQuestionnaireResponseToQuestionnaireResponseDto;
44 import org.openecomp.sdcrests.wrappers.GenericCollectionWrapper;
45 import org.openecomp.sdcrests.wrappers.StringWrapperResponse;
47 import org.springframework.beans.factory.annotation.Autowired;
48 import org.springframework.context.annotation.Scope;
49 import org.springframework.stereotype.Service;
51 import java.util.Collection;
52 import javax.inject.Named;
53 import javax.ws.rs.core.Response;
58 @Scope(value = "prototype")
59 public class NicsImpl implements Nics {
61 private VendorSoftwareProductManager vendorSoftwareProductManager;
64 public Response list(String vspId, String componentId, String version, String user) {
65 Collection<NicEntity> nics =
66 vendorSoftwareProductManager.listNics(vspId, Version.valueOf(version), componentId, user);
68 MapNicEntityToNicDto mapper = new MapNicEntityToNicDto();
69 GenericCollectionWrapper<NicDto> results = new GenericCollectionWrapper<>();
70 for (NicEntity nic : nics) {
71 results.add(mapper.applyMapping(nic, NicDto.class));
74 return Response.ok(results).build();
78 public Response create(NicRequestDto request, String vspId, String componentId, String user) {
79 NicEntity nic = new MapNicRequestDtoToNicEntity().applyMapping(request, NicEntity.class);
81 nic.setComponentId(componentId);
83 NicEntity createdNic = vendorSoftwareProductManager.createNic(nic, user);
84 return Response.ok(createdNic != null ? new StringWrapperResponse(createdNic.getId()) : null)
89 public Response get(String vspId, String componentId, String nicId, String version, String user) {
90 CompositionEntityResponse<Nic> response = vendorSoftwareProductManager
91 .getNic(vspId, Version.valueOf(version), componentId, nicId, user);
93 CompositionEntityResponseDto<NicDto> responseDto = new CompositionEntityResponseDto<>();
94 new MapCompositionEntityResponseToDto<>(new MapNicToNicDto(), NicDto.class)
95 .doMapping(response, responseDto);
96 return Response.ok(responseDto).build();
100 public Response delete(String vspId, String componentId, String nicId, String user) {
101 vendorSoftwareProductManager.deleteNic(vspId, componentId, nicId, user);
102 return Response.ok().build();
106 public Response update(NicRequestDto request, String vspId, String componentId, String nicId,
108 NicEntity nicEntity = new MapNicRequestDtoToNicEntity().applyMapping(request, NicEntity.class);
109 nicEntity.setVspId(vspId);
110 nicEntity.setComponentId(componentId);
111 nicEntity.setId(nicId);
113 CompositionEntityValidationData validationData =
114 vendorSoftwareProductManager.updateNic(nicEntity, user);
115 return validationData != null && CollectionUtils.isNotEmpty(validationData.getErrors())
116 ? Response.status(Response.Status.EXPECTATION_FAILED).entity(
117 new MapCompositionEntityValidationDataToDto()
118 .applyMapping(validationData, CompositionEntityValidationDataDto.class)).build() :
119 Response.ok().build();
123 public Response getQuestionnaire(String vspId, String componentId, String nicId, String version,
125 QuestionnaireResponse questionnaireResponse = vendorSoftwareProductManager
126 .getNicQuestionnaire(vspId, Version.valueOf(version), componentId, nicId, user);
128 QuestionnaireResponseDto result = new MapQuestionnaireResponseToQuestionnaireResponseDto()
129 .applyMapping(questionnaireResponse, QuestionnaireResponseDto.class);
130 return Response.ok(result).build();
134 public Response updateQuestionnaire(String questionnaireData, String vspId, String componentId,
135 String nicId, String user) {
136 vendorSoftwareProductManager
137 .updateNicQuestionnaire(vspId, componentId, nicId, questionnaireData, user);
138 return Response.ok().build();