2 * Copyright 2018 ZTE Corporation.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.onap.sdc.workflowdesigner.externalservice.sdc;
18 import java.util.ArrayList;
19 import java.util.LinkedHashMap;
20 import java.util.List;
22 import org.glassfish.jersey.client.ClientConfig;
23 import org.onap.sdc.workflowdesigner.common.ActivitySpecProxyException;
24 import org.onap.sdc.workflowdesigner.config.AppConfig;
25 import org.onap.sdc.workflowdesigner.externalservice.sdc.entity.ActivitySpec;
26 import org.onap.sdc.workflowdesigner.externalservice.sdc.entity.GenericCollectionWrapper;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
30 import com.eclipsesource.jaxrs.consumer.ConsumerFactory;
35 public class ActivitySpecServiceProxy {
36 private static final Logger LOGGER = LoggerFactory.getLogger(ActivitySpecServiceProxy.class);
38 private static final String AUTHORIZATION = AppConfig.getActivitySpecServiceProxy().getAuthorization();
40 private static final String X_ECOMP_INSTANCE_ID = AppConfig.getActivitySpecServiceProxy().getxEcompInstanceId();
42 private static final String USER_ID = AppConfig.getActivitySpecServiceProxy().getUserId();
45 private static final String ACTIVITY_ROOT_PATH = "/activity-spec-api/v1.0";
47 private static final String ACTIVITY_SPEC_VERSION_ID_DEFAULT_VALUE = "latest";
49 private static String getActivityRootPath() {
50 return AppConfig.getActivitySpecServiceProxy().getServiceAddr() + ACTIVITY_ROOT_PATH;
56 private ActivitySpecService getActivitySpecServiceProxy() {
57 ClientConfig config = new ClientConfig();
58 return ConsumerFactory.createConsumer(getActivityRootPath(), config, ActivitySpecService.class);
65 * @throws ActivitySpecProxyException
67 public ActivitySpec[] getActivitySpecs() throws ActivitySpecProxyException {
68 ActivitySpecService serviceProxy = getActivitySpecServiceProxy();
69 List<ActivitySpec> activitySpecList = new ArrayList<>();
71 GenericCollectionWrapper activityCollection = serviceProxy.getActivitySpecs(USER_ID, X_ECOMP_INSTANCE_ID, AUTHORIZATION);
72 for (Object obj : activityCollection.getResults()) {
73 if (obj instanceof Map){
74 Map activitySpecMap = (Map) obj;
75 String activitySpecId = activitySpecMap.get("id").toString();
76 ActivitySpec activitySpec = serviceProxy.getActivitySpec(USER_ID, X_ECOMP_INSTANCE_ID, AUTHORIZATION, ACTIVITY_SPEC_VERSION_ID_DEFAULT_VALUE, activitySpecId);
77 activitySpec.setId(activitySpecId);
78 activitySpecList.add(activitySpec);
81 } catch (Exception e) {
82 LOGGER.error("Get Activity Specifications Failed.", e);
83 throw new ActivitySpecProxyException("Get Activity Specifications Failed.", e);
85 return activitySpecList.toArray(new ActivitySpec[activitySpecList.size()]);