1 package org.onap.vid.services;
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;
14 import java.nio.file.Path;
15 import java.util.Collection;
17 import java.util.UUID;
20 * The Class VidController.
23 public class VidServiceImpl implements VidService {
27 private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(VidServiceImpl.class);
29 * The Constant dateFormat.
31 protected final AsdcClient asdcClient;
33 private ToscaParserImpl2 toscaParser;
35 public VidServiceImpl(AsdcClient asdcClient) {
36 this.asdcClient = asdcClient;
42 * @see org.onap.vid.controller.VidService#getServices(java.util.Map)
45 public Collection<Service> getServices(Map<String, String[]> requestParams)
46 throws AsdcCatalogException {
47 return asdcClient.getServices(requestParams);
53 * @see org.onap.vid.controller.VidService#getService(java.lang.String)
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;
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);
70 private ServiceModel getServiceModel(String uuid, Path serviceCsar, ToscaParser tosca, Service asdcServiceMetadata) throws Exception {
72 return toscaParser.makeServiceModel(serviceCsar, asdcServiceMetadata);
73 } catch (SdcToscaParserException e) {
74 return tosca.makeServiceModel(uuid, serviceCsar, asdcServiceMetadata);