1 package org.openecomp.sdcrests.vsp.rest.services;
3 import org.openecomp.sdc.logging.context.MdcUtil;
4 import org.openecomp.sdc.logging.types.LoggerServiceName;
5 import org.openecomp.sdc.vendorsoftwareproduct.ComponentDependencyModelManager;
6 import org.openecomp.sdc.vendorsoftwareproduct.ComponentDependencyModelManagerFactory;
7 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentDependencyModelEntity;
8 import org.openecomp.sdc.versioning.dao.types.Version;
9 import org.openecomp.sdc.versioning.types.VersionableEntityAction;
10 import org.openecomp.sdcrests.vendorsoftwareproducts.types.ComponentDependencyModel;
11 import org.openecomp.sdcrests.vendorsoftwareproducts.types.ComponentDependencyModelRequestDto;
12 import org.openecomp.sdcrests.vsp.rest.ComponentDependencyModels;
13 import org.openecomp.sdcrests.vsp.rest.mapping.MapComponentDependencyModelEntityToDto;
14 import org.openecomp.sdcrests.vsp.rest.mapping.MapComponentDependencyModelRequestToEntity;
16 import org.openecomp.sdcrests.wrappers.GenericCollectionWrapper;
17 import org.springframework.context.annotation.Scope;
18 import org.springframework.stereotype.Service;
20 import java.util.ArrayList;
21 import java.util.Collection;
22 import java.util.List;
23 import javax.inject.Named;
24 import javax.ws.rs.core.Response;
27 @Service("componentDependencyModel")
28 @Scope(value = "prototype")
29 public class ComponentDependencyModelsImpl implements ComponentDependencyModels {
31 private ComponentDependencyModelManager componentDependencyModelManager =
32 ComponentDependencyModelManagerFactory.getInstance().createInterface();
35 public Response create(ComponentDependencyModelRequestDto request, String vspId,
36 String versionId, String user) {
37 MdcUtil.initMdc(LoggerServiceName.CREATE_COMPONENT_DEPENDENCY_MODEL.toString());
38 List<ComponentDependencyModelEntity> modelEntities = new
39 ArrayList<ComponentDependencyModelEntity>();
41 final Version version = resolveVspVersion(vspId, null, user, VersionableEntityAction.Write);
43 if (request.getComponentDependencyModels() != null) {
44 for(ComponentDependencyModel model : request.getComponentDependencyModels()) {
45 ComponentDependencyModelEntity modelEntity =
46 new MapComponentDependencyModelRequestToEntity().applyMapping(model,
47 ComponentDependencyModelEntity.class);
49 modelEntity.setVspId(vspId);
50 modelEntity.setVersion(version);
51 modelEntities.add(modelEntity);
55 componentDependencyModelManager
56 .createComponentDependencyModel(modelEntities, vspId, version, user);
58 return Response.ok().build();
62 public Response list(String vspId, String versionId, String user) {
63 MdcUtil.initMdc(LoggerServiceName.GET_COMPONENT_DEPENDENCY_MODEL.toString());
64 Version vspVersion = resolveVspVersion(vspId, versionId, user, VersionableEntityAction.Read);
66 Collection<ComponentDependencyModelEntity> componentDependencies =
67 componentDependencyModelManager.list(vspId, vspVersion, user);
69 MapComponentDependencyModelEntityToDto mapper = new MapComponentDependencyModelEntityToDto();
70 GenericCollectionWrapper<ComponentDependencyModel> results = new GenericCollectionWrapper
71 <ComponentDependencyModel>();
72 for (ComponentDependencyModelEntity entity : componentDependencies) {
73 results.add(mapper.applyMapping(entity, ComponentDependencyModel.class));
76 return Response.ok(results).build();