org.onap migration
[vid.git] / vid-app-common / src / main / java / org / onap / vid / services / VidServiceImpl.java
1 package org.onap.vid.services;
2
3 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
4 import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException;
5 import org.onap.vid.asdc.AsdcCatalogException;
6 import org.onap.vid.asdc.AsdcClient;
7 import org.onap.vid.asdc.beans.Service;
8 import org.onap.vid.asdc.parser.ToscaParser;
9 import org.onap.vid.asdc.parser.ToscaParserImpl;
10 import org.onap.vid.asdc.parser.ToscaParserImpl2;
11 import org.onap.vid.model.ServiceModel;
12 import org.springframework.beans.factory.annotation.Autowired;
13
14 import java.nio.file.Path;
15 import java.util.Collection;
16 import java.util.Map;
17 import java.util.UUID;
18
19 /**
20  * The Class VidController.
21  */
22
23 public class VidServiceImpl implements VidService {
24     /**
25      * The Constant LOG.
26      */
27     private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(VidServiceImpl.class);
28     /**
29      * The Constant dateFormat.
30      */
31     protected final AsdcClient asdcClient;
32     @Autowired
33     private ToscaParserImpl2 toscaParser;
34
35     public VidServiceImpl(AsdcClient asdcClient) {
36         this.asdcClient = asdcClient;
37     }
38
39     /*
40      * (non-Javadoc)
41      *
42      * @see org.openecomp.vid.controller.VidService#getServices(java.util.Map)
43      */
44     @Override
45     public Collection<Service> getServices(Map<String, String[]> requestParams)
46             throws AsdcCatalogException {
47         return asdcClient.getServices(requestParams);
48     }
49
50     /*
51      * (non-Javadoc)
52      *
53      * @see org.openecomp.vid.controller.VidService#getService(java.lang.String)
54      */
55     @Override
56     public ServiceModel getService(String uuid) throws AsdcCatalogException {
57         final Path serviceCsar = asdcClient.getServiceToscaModel(UUID.fromString(uuid));
58         ToscaParser tosca = new ToscaParserImpl();
59         serviceCsar.toFile().getAbsolutePath();
60         ServiceModel serviceModel = null;
61         try {
62             final Service asdcServiceMetadata = asdcClient.getService(UUID.fromString(uuid));
63             return getServiceModel(uuid, serviceCsar, tosca, asdcServiceMetadata);
64         } catch (Exception e) {
65             LOG.error("Failed to download and proccess service from ASDC", e);
66         }
67         return serviceModel;
68     }
69
70     private ServiceModel getServiceModel(String uuid, Path serviceCsar, ToscaParser tosca, Service asdcServiceMetadata) throws Exception {
71         try {
72             return toscaParser.makeServiceModel(serviceCsar, asdcServiceMetadata);
73         } catch (SdcToscaParserException e) {
74             return tosca.makeServiceModel(uuid, serviceCsar, asdcServiceMetadata);
75         }
76     }
77
78
79 }