aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/ComponentDependencyModelsImpl.java
blob: 4a23140c8818cab9582dac947c358e9840964188 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package org.openecomp.sdcrests.vsp.rest.services;

import org.openecomp.sdc.logging.context.MdcUtil;
import org.openecomp.sdc.logging.types.LoggerServiceName;
import org.openecomp.sdc.vendorsoftwareproduct.ComponentDependencyModelManager;
import org.openecomp.sdc.vendorsoftwareproduct.ComponentDependencyModelManagerFactory;
import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentDependencyModelEntity;
import org.openecomp.sdc.versioning.dao.types.Version;
import org.openecomp.sdc.versioning.types.VersionableEntityAction;
import org.openecomp.sdcrests.vendorsoftwareproducts.types.ComponentDependencyModel;
import org.openecomp.sdcrests.vendorsoftwareproducts.types.ComponentDependencyModelRequestDto;
import org.openecomp.sdcrests.vsp.rest.ComponentDependencyModels;
import org.openecomp.sdcrests.vsp.rest.mapping.MapComponentDependencyModelEntityToDto;
import org.openecomp.sdcrests.vsp.rest.mapping.MapComponentDependencyModelRequestToEntity;

import org.openecomp.sdcrests.wrappers.GenericCollectionWrapper;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.inject.Named;
import javax.ws.rs.core.Response;

@Named
@Service("componentDependencyModel")
@Scope(value = "prototype")
public class ComponentDependencyModelsImpl implements ComponentDependencyModels {

  private ComponentDependencyModelManager componentDependencyModelManager =
      ComponentDependencyModelManagerFactory.getInstance().createInterface();

  @Override
  public Response create(ComponentDependencyModelRequestDto request, String vspId,
                         String versionId, String user) {
    MdcUtil.initMdc(LoggerServiceName.CREATE_COMPONENT_DEPENDENCY_MODEL.toString());
    List<ComponentDependencyModelEntity> modelEntities = new
        ArrayList<ComponentDependencyModelEntity>();

    final Version version = resolveVspVersion(vspId, null, user, VersionableEntityAction.Write);

    if (request.getComponentDependencyModels() != null) {
      for(ComponentDependencyModel model : request.getComponentDependencyModels()) {
        ComponentDependencyModelEntity modelEntity =
            new MapComponentDependencyModelRequestToEntity().applyMapping(model,
                ComponentDependencyModelEntity.class);

        modelEntity.setVspId(vspId);
        modelEntity.setVersion(version);
        modelEntities.add(modelEntity);
      }
    }

    componentDependencyModelManager
        .createComponentDependencyModel(modelEntities, vspId, version, user);

    return Response.ok().build();
  }

  @Override
  public Response list(String vspId, String versionId, String user) {
    MdcUtil.initMdc(LoggerServiceName.GET_COMPONENT_DEPENDENCY_MODEL.toString());
    Version vspVersion = resolveVspVersion(vspId, versionId, user, VersionableEntityAction.Read);

    Collection<ComponentDependencyModelEntity> componentDependencies =
        componentDependencyModelManager.list(vspId, vspVersion, user);

    MapComponentDependencyModelEntityToDto mapper = new MapComponentDependencyModelEntityToDto();
    GenericCollectionWrapper<ComponentDependencyModel> results = new GenericCollectionWrapper
        <ComponentDependencyModel>();
    for (ComponentDependencyModelEntity entity : componentDependencies) {
      results.add(mapper.applyMapping(entity, ComponentDependencyModel.class));
    }

    return Response.ok(results).build();
  }
}