Upgrade sonar plugin
[vid.git] / vid-app-common / src / main / java / org / openecomp / vid / services / VidServiceImpl.java
1 package org.openecomp.vid.services;
2
3 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
4 import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException;
5 import org.openecomp.vid.asdc.AsdcCatalogException;
6 import org.openecomp.vid.asdc.AsdcClient;
7 import org.openecomp.vid.asdc.beans.Service;
8 import org.openecomp.vid.asdc.parser.ToscaParser;
9 import org.openecomp.vid.asdc.parser.ToscaParserImpl;
10 import org.openecomp.vid.asdc.parser.ToscaParserImpl2;
11 import org.openecomp.vid.model.ServiceModel;
12 import org.springframework.beans.factory.annotation.Autowired;
13
14 import java.nio.file.Path;
15 import java.text.DateFormat;
16 import java.text.SimpleDateFormat;
17 import java.util.*;
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     private final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");
32     protected final AsdcClient asdcClient;
33     @Autowired
34     private ToscaParserImpl2 toscaParser;
35
36     public VidServiceImpl(AsdcClient asdcClient) {
37         this.asdcClient = asdcClient;
38     }
39
40     /*
41      * (non-Javadoc)
42      *
43      * @see org.openecomp.vid.controller.VidService#getServices(java.util.Map)
44      */
45     @Override
46     public Collection<Service> getServices(Map<String, String[]> requestParams)
47             throws AsdcCatalogException {
48         return asdcClient.getServices(requestParams);
49     }
50
51     /*
52      * (non-Javadoc)
53      *
54      * @see org.openecomp.vid.controller.VidService#getService(java.lang.String)
55      */
56     @Override
57     public ServiceModel getService(String uuid) throws AsdcCatalogException {
58         final Path serviceCsar = asdcClient.getServiceToscaModel(UUID.fromString(uuid));
59         ToscaParser tosca = new ToscaParserImpl();
60         serviceCsar.toFile().getAbsolutePath();
61         ServiceModel serviceModel = null;
62         try {
63             final Service asdcServiceMetadata = asdcClient.getService(UUID.fromString(uuid));
64             try {
65                 serviceModel = toscaParser.makeServiceModel(serviceCsar, asdcServiceMetadata);
66             }
67             catch (SdcToscaParserException e){
68                 serviceModel = tosca.makeServiceModel(uuid, serviceCsar, asdcServiceMetadata);
69             }
70         } catch (Exception e) {
71             e.printStackTrace();
72         }
73         return serviceModel;
74     }
75
76
77 }