2 * Copyright © 2016-2017 European Support Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.openecomp.sdcrests.vsp.rest.services;
19 import org.openecomp.sdc.vendorsoftwareproduct.ComponentDependencyModelManager;
20 import org.openecomp.sdc.vendorsoftwareproduct.ComponentDependencyModelManagerFactory;
21 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentDependencyModelEntity;
22 import org.openecomp.sdc.versioning.dao.types.Version;
23 import org.openecomp.sdcrests.vendorsoftwareproducts.types.ComponentDependencyCreationDto;
24 import org.openecomp.sdcrests.vendorsoftwareproducts.types.ComponentDependencyModel;
25 import org.openecomp.sdcrests.vendorsoftwareproducts.types.ComponentDependencyResponseDto;
26 import org.openecomp.sdcrests.vsp.rest.ComponentDependencies;
27 import org.openecomp.sdcrests.vsp.rest.mapping.MapComponentDependencyEntityToCreationDto;
28 import org.openecomp.sdcrests.vsp.rest.mapping.MapComponentDependencyEntityToDto;
29 import org.openecomp.sdcrests.vsp.rest.mapping.MapComponentDependencyModelRequestToEntity;
30 import org.openecomp.sdcrests.wrappers.GenericCollectionWrapper;
31 import org.springframework.context.annotation.Scope;
32 import org.springframework.stereotype.Service;
34 import javax.inject.Named;
35 import javax.ws.rs.core.Response;
36 import java.util.Collection;
39 @Service("componentDependencies")
40 @Scope(value = "prototype")
41 public class ComponentDependenciesImpl implements ComponentDependencies {
43 private final ComponentDependencyModelManager componentDependencyModelManager =
44 ComponentDependencyModelManagerFactory.getInstance().createInterface();
47 public Response create(ComponentDependencyModel request, String vspId, String versionId,
49 final Version version = new Version(versionId);
51 ComponentDependencyModelEntity modelEntity =
52 new MapComponentDependencyModelRequestToEntity().applyMapping(request,
53 ComponentDependencyModelEntity.class);
55 modelEntity.setVspId(vspId);
56 modelEntity.setVersion(version);
58 ComponentDependencyModelEntity componentDependency =
59 componentDependencyModelManager.createComponentDependency(modelEntity, vspId, version);
61 MapComponentDependencyEntityToCreationDto mapping =
62 new MapComponentDependencyEntityToCreationDto();
63 ComponentDependencyCreationDto createdComponentDependencyDto = mapping.applyMapping(
64 componentDependency, ComponentDependencyCreationDto.class);
65 return Response.ok(componentDependency != null ? createdComponentDependencyDto : null)
70 public Response list(String vspId, String versionId, String user) {
72 Version vspVersion = new Version(versionId);
74 Collection<ComponentDependencyModelEntity> componentDependencies =
75 componentDependencyModelManager.list(vspId, vspVersion);
77 MapComponentDependencyEntityToDto mapper = new MapComponentDependencyEntityToDto();
78 GenericCollectionWrapper<ComponentDependencyResponseDto> results = new GenericCollectionWrapper
80 for (ComponentDependencyModelEntity entity : componentDependencies) {
81 results.add(mapper.applyMapping(entity, ComponentDependencyResponseDto.class));
84 return Response.ok(results).build();
88 public Response delete(String vspId, String versionId, String dependencyId, String user) {
90 Version vspVersion = new Version(versionId);
91 componentDependencyModelManager.delete(vspId, vspVersion, dependencyId);
92 return Response.ok().build();
96 public Response update(ComponentDependencyModel request, String vspId, String versionId, String
97 dependencyId, String user) {
99 final Version version = new Version(versionId);
100 ComponentDependencyModelEntity modelEntity =
101 new MapComponentDependencyModelRequestToEntity().applyMapping(request,
102 ComponentDependencyModelEntity.class);
104 modelEntity.setId(dependencyId);
105 modelEntity.setVspId(vspId);
106 modelEntity.setVersion(version);
107 componentDependencyModelManager.update(modelEntity);
108 return Response.ok().build();
112 public Response get(String vspId, String version, String dependencyId, String user) {
114 ComponentDependencyModelEntity componentDependencyModelEntity = componentDependencyModelManager
115 .get(vspId, new Version(version), dependencyId);
117 MapComponentDependencyEntityToDto mapper = new MapComponentDependencyEntityToDto();
118 ComponentDependencyResponseDto componentDependencyResponseDto =
119 mapper.applyMapping(componentDependencyModelEntity, ComponentDependencyResponseDto.class);
121 return Response.ok(componentDependencyModelEntity != null ? componentDependencyResponseDto :