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.NetworkEntity;
26 import org.openecomp.sdc.vendorsoftwareproduct.types.CompositionEntityResponse;
27 import org.openecomp.sdc.vendorsoftwareproduct.types.CompositionEntityValidationData;
28 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Network;
29 import org.openecomp.sdc.versioning.dao.types.Version;
30 import org.openecomp.sdcrests.vendorsoftwareproducts.types.CompositionEntityResponseDto;
31 import org.openecomp.sdcrests.vendorsoftwareproducts.types.CompositionEntityValidationDataDto;
32 import org.openecomp.sdcrests.vendorsoftwareproducts.types.NetworkDto;
33 import org.openecomp.sdcrests.vendorsoftwareproducts.types.NetworkRequestDto;
34 import org.openecomp.sdcrests.vsp.rest.Networks;
35 import org.openecomp.sdcrests.vsp.rest.mapping.MapCompositionEntityResponseToDto;
36 import org.openecomp.sdcrests.vsp.rest.mapping.MapCompositionEntityValidationDataToDto;
37 import org.openecomp.sdcrests.vsp.rest.mapping.MapNetworkEntityToNetworkDto;
38 import org.openecomp.sdcrests.vsp.rest.mapping.MapNetworkRequestDtoToNetworkEntity;
39 import org.openecomp.sdcrests.vsp.rest.mapping.MapNetworkToNetworkDto;
40 import org.openecomp.sdcrests.wrappers.GenericCollectionWrapper;
41 import org.openecomp.sdcrests.wrappers.StringWrapperResponse;
42 import org.springframework.beans.factory.annotation.Autowired;
43 import org.springframework.context.annotation.Scope;
44 import org.springframework.stereotype.Service;
46 import java.util.Collection;
47 import javax.inject.Named;
48 import javax.ws.rs.core.Response;
53 @Scope(value = "prototype")
54 public class NetworksImpl implements Networks {
56 private VendorSoftwareProductManager vendorSoftwareProductManager;
59 public Response list(String vspId, String version, String user) {
60 Collection<NetworkEntity> networks =
61 vendorSoftwareProductManager.listNetworks(vspId, Version.valueOf(version), user);
63 MapNetworkEntityToNetworkDto mapper = new MapNetworkEntityToNetworkDto();
64 GenericCollectionWrapper<NetworkDto> results = new GenericCollectionWrapper<>();
65 for (NetworkEntity network : networks) {
66 results.add(mapper.applyMapping(network, NetworkDto.class));
69 return Response.ok(results).build();
73 public Response create(NetworkRequestDto request, String vspId, String user) {
74 NetworkEntity network =
75 new MapNetworkRequestDtoToNetworkEntity().applyMapping(request, NetworkEntity.class);
76 network.setVspId(vspId);
77 NetworkEntity createdNetwork = vendorSoftwareProductManager.createNetwork(network, user);
79 .ok(createdNetwork != null ? new StringWrapperResponse(createdNetwork.getId()) : null)
84 public Response get(String vspId, String networkId, String version, String user) {
85 CompositionEntityResponse<Network> response =
86 vendorSoftwareProductManager.getNetwork(vspId, Version.valueOf(version), networkId, user);
88 CompositionEntityResponseDto<NetworkDto> responseDto = new CompositionEntityResponseDto<>();
89 new MapCompositionEntityResponseToDto<>(new MapNetworkToNetworkDto(), NetworkDto.class)
90 .doMapping(response, responseDto);
91 return Response.ok(responseDto).build();
95 public Response delete(String vspId, String networkId, String user) {
96 vendorSoftwareProductManager.deleteNetwork(vspId, networkId, user);
97 return Response.ok().build();
101 public Response update(NetworkRequestDto request, String vspId, String networkId, String user) {
102 NetworkEntity networkEntity =
103 new MapNetworkRequestDtoToNetworkEntity().applyMapping(request, NetworkEntity.class);
104 networkEntity.setVspId(vspId);
105 networkEntity.setId(networkId);
107 CompositionEntityValidationData validationData =
108 vendorSoftwareProductManager.updateNetwork(networkEntity, user);
109 return validationData != null && CollectionUtils.isNotEmpty(validationData.getErrors())
110 ? Response.status(Response.Status.EXPECTATION_FAILED).entity(
111 new MapCompositionEntityValidationDataToDto()
112 .applyMapping(validationData, CompositionEntityValidationDataDto.class)).build() :
113 Response.ok().build();