aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/main/java/org/onap/vid/services/VidServiceImpl.java
blob: 44cfb28be62ab194a83476411286cce66c76722b (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
79
package org.onap.vid.services;

import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException;
import org.onap.vid.asdc.AsdcCatalogException;
import org.onap.vid.asdc.AsdcClient;
import org.onap.vid.asdc.beans.Service;
import org.onap.vid.asdc.parser.ToscaParser;
import org.onap.vid.asdc.parser.ToscaParserImpl;
import org.onap.vid.asdc.parser.ToscaParserImpl2;
import org.onap.vid.model.ServiceModel;
import org.springframework.beans.factory.annotation.Autowired;

import java.nio.file.Path;
import java.util.Collection;
import java.util.Map;
import java.util.UUID;

/**
 * The Class VidController.
 */

public class VidServiceImpl implements VidService {
    /**
     * The Constant LOG.
     */
    private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(VidServiceImpl.class);
    /**
     * The Constant dateFormat.
     */
    protected final AsdcClient asdcClient;
    @Autowired
    private ToscaParserImpl2 toscaParser;

    public VidServiceImpl(AsdcClient asdcClient) {
        this.asdcClient = asdcClient;
    }

    /*
     * (non-Javadoc)
     *
     * @see org.onap.vid.controller.VidService#getServices(java.util.Map)
     */
    @Override
    public Collection<Service> getServices(Map<String, String[]> requestParams)
            throws AsdcCatalogException {
        return asdcClient.getServices(requestParams);
    }

    /*
     * (non-Javadoc)
     *
     * @see org.onap.vid.controller.VidService#getService(java.lang.String)
     */
    @Override
    public ServiceModel getService(String uuid) throws AsdcCatalogException {
        final Path serviceCsar = asdcClient.getServiceToscaModel(UUID.fromString(uuid));
        ToscaParser tosca = new ToscaParserImpl();
        serviceCsar.toFile().getAbsolutePath();
        ServiceModel serviceModel = null;
        try {
            final Service asdcServiceMetadata = asdcClient.getService(UUID.fromString(uuid));
            return getServiceModel(uuid, serviceCsar, tosca, asdcServiceMetadata);
        } catch (Exception e) {
            LOG.error("Failed to download and proccess service from ASDC", e);
        }
        return serviceModel;
    }

    private ServiceModel getServiceModel(String uuid, Path serviceCsar, ToscaParser tosca, Service asdcServiceMetadata) throws Exception {
        try {
            return toscaParser.makeServiceModel(serviceCsar, asdcServiceMetadata);
        } catch (SdcToscaParserException e) {
            return tosca.makeServiceModel(uuid, serviceCsar, asdcServiceMetadata);
        }
    }


}