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;
45 public ComponentDependenciesImpl() {
46 this.componentDependencyModelManager =
47 ComponentDependencyModelManagerFactory.getInstance().createInterface();
50 public ComponentDependenciesImpl(ComponentDependencyModelManager componentDependencyModelManager) {
51 this.componentDependencyModelManager = componentDependencyModelManager;
55 public Response create(ComponentDependencyModel request, String vspId, String versionId,
57 final Version version = new Version(versionId);
59 ComponentDependencyModelEntity modelEntity =
60 new MapComponentDependencyModelRequestToEntity().applyMapping(request,
61 ComponentDependencyModelEntity.class);
63 modelEntity.setVspId(vspId);
64 modelEntity.setVersion(version);
66 ComponentDependencyModelEntity componentDependency =
67 componentDependencyModelManager.createComponentDependency(modelEntity, vspId, version);
69 MapComponentDependencyEntityToCreationDto mapping =
70 new MapComponentDependencyEntityToCreationDto();
71 ComponentDependencyCreationDto createdComponentDependencyDto = mapping.applyMapping(
72 componentDependency, ComponentDependencyCreationDto.class);
73 return Response.ok(componentDependency != null ? createdComponentDependencyDto : null)
78 public Response list(String vspId, String versionId, String user) {
80 Version vspVersion = new Version(versionId);
82 Collection<ComponentDependencyModelEntity> componentDependencies =
83 componentDependencyModelManager.list(vspId, vspVersion);
85 MapComponentDependencyEntityToDto mapper = new MapComponentDependencyEntityToDto();
86 GenericCollectionWrapper<ComponentDependencyResponseDto> results = new GenericCollectionWrapper
88 for (ComponentDependencyModelEntity entity : componentDependencies) {
89 results.add(mapper.applyMapping(entity, ComponentDependencyResponseDto.class));
92 return Response.ok(results).build();
96 public Response delete(String vspId, String versionId, String dependencyId, String user) {
98 Version vspVersion = new Version(versionId);
99 componentDependencyModelManager.delete(vspId, vspVersion, dependencyId);
100 return Response.ok().build();
104 public Response update(ComponentDependencyModel request, String vspId, String versionId, String
105 dependencyId, String user) {
107 final Version version = new Version(versionId);
108 ComponentDependencyModelEntity modelEntity =
109 new MapComponentDependencyModelRequestToEntity().applyMapping(request,
110 ComponentDependencyModelEntity.class);
112 modelEntity.setId(dependencyId);
113 modelEntity.setVspId(vspId);
114 modelEntity.setVersion(version);
115 componentDependencyModelManager.update(modelEntity);
116 return Response.ok().build();
120 public Response get(String vspId, String version, String dependencyId, String user) {
122 ComponentDependencyModelEntity componentDependencyModelEntity = componentDependencyModelManager
123 .get(vspId, new Version(version), dependencyId);
125 MapComponentDependencyEntityToDto mapper = new MapComponentDependencyEntityToDto();
126 ComponentDependencyResponseDto componentDependencyResponseDto =
127 mapper.applyMapping(componentDependencyModelEntity, ComponentDependencyResponseDto.class);
129 return Response.ok(componentDependencyModelEntity != null ? componentDependencyResponseDto :