Migrate ccsdk/apps to ccsdk/cds
[ccsdk/cds.git] / ms / cds-sdc-listener / application / src / main / java / org / onap / ccsdk / cds / cdssdclistener / CdsSdcListenerNotificationCallback.java
1 /*
2  * Copyright (C) 2019 Bell Canada. All rights reserved.
3  *
4  * NOTICE:  All the intellectual and technical concepts contained herein are
5  * proprietary to Bell Canada and are protected by trade secret or copyright law.
6  * Unauthorized copying of this file, via any medium is strictly prohibited.
7  */
8
9 package org.onap.ccsdk.cds.cdssdclistener;
10
11 import static org.onap.sdc.utils.DistributionActionResultEnum.SUCCESS;
12 import java.util.List;
13 import org.onap.sdc.api.IDistributionClient;
14 import org.onap.sdc.api.consumer.INotificationCallback;
15 import org.onap.sdc.api.notification.IArtifactInfo;
16 import org.onap.sdc.api.notification.INotificationData;
17 import org.onap.sdc.api.results.IDistributionClientDownloadResult;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20 import org.springframework.beans.factory.annotation.Autowired;
21 import org.springframework.stereotype.Component;
22
23 @Component
24 public class CdsSdcListenerNotificationCallback implements INotificationCallback {
25
26     @Autowired
27     private CdsSdcListenerDto cdsSdcListenerDto;
28
29     private static final Logger LOGGER = LoggerFactory.getLogger(CdsSdcListenerNotificationCallback.class);
30
31     @Override
32     public void activateCallback(INotificationData notificationData) {
33         LOGGER.info(notificationData.getDistributionID(), "The UUID generated by SDC {}");
34         processNotification(notificationData);
35     }
36
37     private void processNotification(INotificationData notificationData) {
38         downlaodCsarArtifacts(notificationData.getServiceArtifacts());
39     }
40
41     /**
42      * Download the TOSCA CSAR artifact.
43      * @param artifactInfo - An object consists of Artifact information.
44      */
45     private void downlaodCsarArtifacts(List<IArtifactInfo> artifactInfo) {
46         final IDistributionClient distributionClient = cdsSdcListenerDto.getDistributionClient();
47
48         artifactInfo.forEach(info -> {
49             final String url = info.getArtifactURL();
50             final String id = info.getArtifactUUID();
51             if (info.getArtifactType().equals(CdsSdcListenerConfiguration.TOSCA_CSAR)) {
52                 LOGGER.info("Trying to download the artifact from : {} and UUID is {} ", url, id);
53
54                 IDistributionClientDownloadResult result = distributionClient.download(info);
55
56                 if (!result.getDistributionActionResult().equals(SUCCESS)) {
57                     LOGGER.info("Failed to download the artifact from : {} due to {} ", url,
58                         result.getDistributionActionResult());
59                 } else {
60                     parseCBAFileFromCsar(result);
61                 }
62             }
63         });
64     }
65
66     private void parseCBAFileFromCsar(IDistributionClientDownloadResult result) {
67
68     }
69 }