6319cbf6eadb9bb157e649989b01cb02af182643
[sdc/sdc-workflow-designer.git] /
1 /**
2  * Copyright 2017-2018 ZTE Corporation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.onap.sdc.workflowdesigner.externalservice.sdc;
17
18 import org.glassfish.jersey.client.ClientConfig;
19 import org.onap.sdc.workflowdesigner.common.WorkflowDesignerException;
20 import org.onap.sdc.workflowdesigner.config.AppConfig;
21 import org.onap.sdc.workflowdesigner.externalservice.sdc.entity.WorkflowArtifactInfo;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24
25 import com.eclipsesource.jaxrs.consumer.ConsumerFactory;
26
27 /**
28  * 
29  */
30 public class SDCServiceProxy {
31   private static final Logger LOGGER = LoggerFactory.getLogger(SDCService.class);
32
33   private static final String AUTHORIZATION = AppConfig.getSdcServiceProxy().getAuthorization();
34
35   private static final String X_ECOMP_INSTANCE_ID = AppConfig.getSdcServiceProxy().getxEcompInstanceId();
36   /** */
37   private static final String SDC_ROOT_PATH = "/sdc/v1";
38   
39
40   private static String getSDCRootPath() {
41     return AppConfig.getSdcServiceProxy().getServiceAddr() + SDC_ROOT_PATH;
42   }
43   
44   /**
45    * @return
46    */
47   private SDCService getSDCServiceProxy() {
48     ClientConfig config = new ClientConfig();
49     SDCService sdcServiceProxy =
50         ConsumerFactory.createConsumer(getSDCRootPath(), config, SDCService.class);
51     return sdcServiceProxy;
52   }
53
54   /**
55    * 
56    * @param uuid
57    * @param operationId
58    * @param workflowId
59    * @param workflowArtifactInfo
60    * @throws WorkflowDesignerException
61    */
62   public void saveWorkflowArtifact(String uuid, String operationId, String workflowId,
63       WorkflowArtifactInfo workflowArtifactInfo) throws WorkflowDesignerException {
64     SDCService sdcServiceProxy = getSDCServiceProxy();
65     try {
66       sdcServiceProxy.saveWorkflowArtifact(uuid, operationId, workflowId,
67           X_ECOMP_INSTANCE_ID,
68           AUTHORIZATION, workflowArtifactInfo);
69     } catch (Exception e) {
70       LOGGER.error("Save WorkflowArtifact Failed.", e);
71       throw new WorkflowDesignerException("Save WorkflowArtifact Failed.", e);
72     }
73   }
74
75   /**
76    * 
77    * @param uuid
78    * @param operationId
79    * @param workflowId
80    * @return
81    * @throws WorkflowDesignerException
82    */
83   public WorkflowArtifactInfo getWorkflowArtifact(String uuid, String operationId,
84       String workflowId) throws WorkflowDesignerException {
85     SDCService sdcServiceProxy = getSDCServiceProxy();
86     try {
87       return sdcServiceProxy.getWorkflowArtifact(uuid, operationId, workflowId,
88           X_ECOMP_INSTANCE_ID,
89           AUTHORIZATION);
90     } catch (Exception e) {
91       LOGGER.error("Get WorkflowArtifact Failed.", e);
92       throw new WorkflowDesignerException("Save WorkflowArtifact Failed.", e);
93     }
94   }
95
96
97 }