Fix Nexus IQ issues.
[sdc/sdc-workflow-designer.git] / sdc-workflow-designer-server / src / main / java / org / onap / sdc / workflowdesigner / externalservice / sdc / ActivitySpecServiceProxy.java
1 /**
2  * Copyright 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.ActivitySpec;
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 ActivitySpecServiceProxy {
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 =
36       AppConfig.getSdcServiceProxy().getxEcompInstanceId();
37   /** */
38   private static final String Activity_ROOT_PATH = "/activityspec-api/v1.0";
39
40
41   private static String getActivityRootPath() {
42     return AppConfig.getSdcServiceProxy().getServiceAddr() + Activity_ROOT_PATH;
43   }
44
45   /**
46    * @return
47    */
48   private ActivitySpecService getActivityServiceProxy() {
49     ClientConfig config = new ClientConfig();
50     return ConsumerFactory.createConsumer(getActivityRootPath(), config, ActivitySpecService.class);
51   }
52
53
54   /**
55    * 
56    * @return
57    * @throws WorkflowDesignerException
58    */
59   public ActivitySpec[] getActivitySpecs() throws WorkflowDesignerException {
60     ActivitySpecService serviceProxy = getActivityServiceProxy();
61     try {
62       return serviceProxy.getActivitySpecs(X_ECOMP_INSTANCE_ID, AUTHORIZATION);
63     } catch (Exception e) {
64       LOGGER.error("Get Activity Specifications Failed.", e);
65       throw new WorkflowDesignerException("Get Activity Specifications Failed.", e);
66     }
67   }
68
69
70 }