Align workflow studio to Activity Spec 51/50651/1
authorPriyanshu <pagarwal@amdocs.com>
Wed, 6 Jun 2018 10:48:44 +0000 (16:18 +0530)
committerpriyanshu <pagarwal@amdocs.com>
Wed, 6 Jun 2018 10:48:44 +0000 (16:18 +0530)
SDC-WF: Align Workflow studio implementation with Activity Spec implementation in SDC

Change-Id: I83fbf51a6399459c0e99c11f150616ceca69111a
Issue-ID: SDC-1402
Signed-off-by: priyanshu <pagarwal@amdocs.com>
12 files changed:
distribution/src/main/assembly/conf/workflow-designer.yml
sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/ActivitySpecServiceProxyInfo.java [new file with mode: 0644]
sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/WorkflowDesignerApp.java
sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/WorkflowDesignerConfiguration.java
sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/common/ActivitySpecProxyException.java [new file with mode: 0644]
sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/config/AppConfig.java
sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/externalservice/sdc/ActivitySpecService.java
sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/externalservice/sdc/ActivitySpecServiceProxy.java
sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/externalservice/sdc/entity/ActivitySpec.java
sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/externalservice/sdc/entity/GenericCollectionWrapper.java [new file with mode: 0644]
sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/resources/ExtendActivityResource.java
sdc-workflow-designer-server/src/test/java/org/onap/sdc/workflowdesigner/externalservice/sdc/entity/ActivitySpecTest.java

index 42785fb..9b35b26 100644 (file)
@@ -14,13 +14,19 @@ template: Hello, %s!
 
 defaultName: ${DW_DEFAULT_NAME:-Stranger}
 
-adapterType: DEFAULT
+adapterType: SDC
 
 sdcServiceProxy:
   serviceAddr: http://127.0.0.1:8080
   xEcompInstanceId: workflow
   authorization: Basic YWFpOktwOGJKNFNYc3pNMFdYbGhhazNlSGxjc2UyZ0F3ODR2YW9HR21KdlV5MlU=
 
+activitySpecServiceProxy:
+  serviceAddr: http://127.0.0.1:8090
+  xEcompInstanceId: workflow
+  userId: workflow
+  authorization: Basic YWFpOktwOGJKNFNYc3pNMFdYbGhhazNlSGxjc2UyZ0F3ODR2YW9HR21KdlV5MlU=
+
 # use the simple server factory if you only want to run on a single port
 server:
   type: simple
diff --git a/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/ActivitySpecServiceProxyInfo.java b/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/ActivitySpecServiceProxyInfo.java
new file mode 100644 (file)
index 0000000..fb82e50
--- /dev/null
@@ -0,0 +1,97 @@
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.sdc.workflowdesigner;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+/**
+ *
+ */
+public class ActivitySpecServiceProxyInfo {
+  private String serviceAddr;
+  
+  private String xEcompInstanceId;
+  
+  private String authorization;
+
+  private String userId;
+
+  /**
+   * @return the serviceAddr
+   */
+  @JsonProperty
+  public String getServiceAddr() {
+    return serviceAddr;
+  }
+
+  /**
+   * @param serviceAddr the serviceAddr to set
+   */
+  @JsonProperty
+  public void setServiceAddr(String serviceAddr) {
+    this.serviceAddr = serviceAddr;
+  }
+
+  /**
+   * @return the xEcompInstanceId
+   */
+  @JsonProperty
+  public String getxEcompInstanceId() {
+    return xEcompInstanceId;
+  }
+
+  /**
+   * @param xEcompInstanceId the xEcompInstanceId to set
+   */
+  @JsonProperty
+  public void setxEcompInstanceId(String xEcompInstanceId) {
+    this.xEcompInstanceId = xEcompInstanceId;
+  }
+
+  /**
+   * @return the authorization
+   */
+  @JsonProperty
+  public String getAuthorization() {
+    return authorization;
+  }
+
+  /**
+   * @param authorization the authorization to set
+   */
+  @JsonProperty
+  public void setAuthorization(String authorization) {
+    this.authorization = authorization;
+  }
+
+  /**
+   * @return the userId
+   */
+  @JsonProperty
+  public String getUserId() {
+    return userId;
+  }
+
+  /**
+   * @param userId the userId to set
+   */
+  @JsonProperty
+  public void setUserId(String userId) {
+    this.userId = userId;
+  }
+
+}
index 34a17e7..c9e0c40 100644 (file)
@@ -72,6 +72,7 @@ public class WorkflowDesignerApp extends Application<WorkflowDesignerConfigurati
   private void saveAppConfig(WorkflowDesignerConfiguration configuration) {
     AppConfig.setAdapterType(AdapterType.valueOf(configuration.getAdapterType()));
     AppConfig.setSdcServiceProxy(configuration.getSdcServiceProxy());
+    AppConfig.setActivitySpecServiceProxy(configuration.getActivitySpecServiceProxy());
   }
 
   /**
index 381e167..4c6766b 100644 (file)
@@ -27,6 +27,9 @@ public class WorkflowDesignerConfiguration extends Configuration {
   
   @NotNull
   private SDCServiceProxyInfo sdcServiceProxy;
+
+  @NotNull
+  private ActivitySpecServiceProxyInfo activitySpecServiceProxy;
   
   
   @JsonProperty
@@ -81,4 +84,20 @@ public class WorkflowDesignerConfiguration extends Configuration {
     this.sdcServiceProxy = sdcServiceProxy;
   }
 
+  /**
+   * @return the activitySpecServiceProxy
+   */
+  @JsonProperty
+  public ActivitySpecServiceProxyInfo getActivitySpecServiceProxy() {
+    return activitySpecServiceProxy;
+  }
+
+  /**
+   * @param activitySpecServiceProxy the activitySpecServiceProxy to set
+   */
+  @JsonProperty
+  public void setActivitySpecServiceProxy(ActivitySpecServiceProxyInfo activitySpecServiceProxy) {
+    this.activitySpecServiceProxy = activitySpecServiceProxy;
+  }
+
 }
diff --git a/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/common/ActivitySpecProxyException.java b/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/common/ActivitySpecProxyException.java
new file mode 100644 (file)
index 0000000..bc3cf4b
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.sdc.workflowdesigner.common;
+
+public class ActivitySpecProxyException extends Exception {
+
+  private static final long serialVersionUID = 1L;
+
+  public ActivitySpecProxyException() {
+    super();
+  }
+
+  public ActivitySpecProxyException(String msg, Exception e) {
+    super(msg, e);
+  }
+
+  public ActivitySpecProxyException(String msg) {
+    super(msg);
+  }
+}
index 9a4afb3..a6f72be 100644 (file)
@@ -16,6 +16,7 @@
 package org.onap.sdc.workflowdesigner.config;
 
 import org.onap.sdc.workflowdesigner.SDCServiceProxyInfo;
+import org.onap.sdc.workflowdesigner.ActivitySpecServiceProxyInfo;
 
 /**
  * 
@@ -24,6 +25,8 @@ public class AppConfig {
   private static AdapterType adapterType;
   
   private static SDCServiceProxyInfo sdcServiceProxy;
+
+  private static ActivitySpecServiceProxyInfo activitySpecServiceProxy;
   
   private AppConfig() {}
 
@@ -62,4 +65,17 @@ public class AppConfig {
     return adapterType.equals(AdapterType.SDC);
   }
 
+  /**
+   * @param activitySpecServiceProxy
+   */
+  public static void setActivitySpecServiceProxy(ActivitySpecServiceProxyInfo activitySpecServiceProxy) {
+    AppConfig.activitySpecServiceProxy = activitySpecServiceProxy;
+  }
+
+  /**
+   * @return the activitySpecServiceProxy
+   */
+  public static ActivitySpecServiceProxyInfo getActivitySpecServiceProxy() {
+    return activitySpecServiceProxy;
+  }
 }
index c1878c0..b85d6d0 100644 (file)
@@ -19,10 +19,12 @@ import javax.ws.rs.Consumes;
 import javax.ws.rs.GET;
 import javax.ws.rs.HeaderParam;
 import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.MediaType;
 
 import org.onap.sdc.workflowdesigner.externalservice.sdc.entity.ActivitySpec;
+import org.onap.sdc.workflowdesigner.externalservice.sdc.entity.GenericCollectionWrapper;
 
 @Path("")
 public interface ActivitySpecService {
@@ -30,8 +32,20 @@ public interface ActivitySpecService {
   @Path("/activity-spec?Filter=Certified")
   @Consumes(MediaType.APPLICATION_JSON)
   @Produces(MediaType.APPLICATION_JSON)
-  public ActivitySpec[] getActivitySpecs(
+  public GenericCollectionWrapper getActivitySpecs(
+      @HeaderParam("USER_ID") String userId,
       @HeaderParam("X-ECOMP-InstanceID") String xEcompInstanceId,
       @HeaderParam("Authorization") String authorization) throws Exception;
 
+  @GET
+  @Path("/activity-spec/{id}/versions/{versionId}")
+  @Consumes(MediaType.APPLICATION_JSON)
+  @Produces(MediaType.APPLICATION_JSON)
+  public ActivitySpec getActivitySpec(
+      @HeaderParam("USER_ID") String userId,
+      @HeaderParam("X-ECOMP-InstanceID") String xEcompInstanceId,
+      @HeaderParam("Authorization") String authorization,
+      @PathParam("versionId") String versionId,
+      @PathParam("id") String id) throws Exception;
+
 }
index e014b54..e210e87 100644 (file)
  */
 package org.onap.sdc.workflowdesigner.externalservice.sdc;
 
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
 import org.glassfish.jersey.client.ClientConfig;
-import org.onap.sdc.workflowdesigner.common.SDCProxyException;
+import org.onap.sdc.workflowdesigner.common.ActivitySpecProxyException;
 import org.onap.sdc.workflowdesigner.config.AppConfig;
 import org.onap.sdc.workflowdesigner.externalservice.sdc.entity.ActivitySpec;
+import org.onap.sdc.workflowdesigner.externalservice.sdc.entity.GenericCollectionWrapper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -28,24 +33,27 @@ import com.eclipsesource.jaxrs.consumer.ConsumerFactory;
  * 
  */
 public class ActivitySpecServiceProxy {
-  private static final Logger LOGGER = LoggerFactory.getLogger(SDCService.class);
+  private static final Logger LOGGER = LoggerFactory.getLogger(ActivitySpecServiceProxy.class);
 
-  private static final String AUTHORIZATION = AppConfig.getSdcServiceProxy().getAuthorization();
+  private static final String AUTHORIZATION = AppConfig.getActivitySpecServiceProxy().getAuthorization();
+
+  private static final String X_ECOMP_INSTANCE_ID = AppConfig.getActivitySpecServiceProxy().getxEcompInstanceId();
+
+  private static final String USER_ID = AppConfig.getActivitySpecServiceProxy().getUserId();
 
-  private static final String X_ECOMP_INSTANCE_ID =
-      AppConfig.getSdcServiceProxy().getxEcompInstanceId();
   /** */
-  private static final String ACTIVITY_ROOT_PATH = "/activityspec-api/v1.0";
+  private static final String ACTIVITY_ROOT_PATH = "/activity-spec-api/v1.0";
 
+  private static final String ACTIVITY_SPEC_VERSION_ID_DEFAULT_VALUE = "latest";
 
   private static String getActivityRootPath() {
-    return AppConfig.getSdcServiceProxy().getServiceAddr() + ACTIVITY_ROOT_PATH;
+    return AppConfig.getActivitySpecServiceProxy().getServiceAddr() + ACTIVITY_ROOT_PATH;
   }
 
   /**
    * @return
    */
-  private ActivitySpecService getActivityServiceProxy() {
+  private ActivitySpecService getActivitySpecServiceProxy() {
     ClientConfig config = new ClientConfig();
     return ConsumerFactory.createConsumer(getActivityRootPath(), config, ActivitySpecService.class);
   }
@@ -54,16 +62,27 @@ public class ActivitySpecServiceProxy {
   /**
    * 
    * @return
-   * @throws SDCProxyException
+   * @throws ActivitySpecProxyException
    */
-  public ActivitySpec[] getActivitySpecs() throws SDCProxyException {
-    ActivitySpecService serviceProxy = getActivityServiceProxy();
+  public ActivitySpec[] getActivitySpecs() throws ActivitySpecProxyException {
+    ActivitySpecService serviceProxy = getActivitySpecServiceProxy();
+    List<ActivitySpec> activitySpecList = new ArrayList<>();
     try {
-      return serviceProxy.getActivitySpecs(X_ECOMP_INSTANCE_ID, AUTHORIZATION);
+      GenericCollectionWrapper activityCollection = serviceProxy.getActivitySpecs(USER_ID, X_ECOMP_INSTANCE_ID, AUTHORIZATION);
+      for (Object obj : activityCollection.getResults()) {
+        if (obj instanceof Map){
+          Map activitySpecMap = (Map) obj;
+          String activitySpecId = activitySpecMap.get("id").toString();
+          ActivitySpec activitySpec = serviceProxy.getActivitySpec(USER_ID, X_ECOMP_INSTANCE_ID, AUTHORIZATION, ACTIVITY_SPEC_VERSION_ID_DEFAULT_VALUE, activitySpecId);
+          activitySpec.setId(activitySpecId);
+          activitySpecList.add(activitySpec);
+        }
+      }
     } catch (Exception e) {
       LOGGER.error("Get Activity Specifications Failed.", e);
-      throw new SDCProxyException("Get Activity Specifications Failed.", e);
+      throw new ActivitySpecProxyException("Get Activity Specifications Failed.", e);
     }
+    return activitySpecList.toArray(new ActivitySpec[activitySpecList.size()]);
   }
 
 
index 35a1a36..942afca 100644 (file)
@@ -25,7 +25,7 @@ public class ActivitySpec {
   \r
   private String type;\r
   \r
-  private ActivityContent content = new ActivityContent();\r
+  private String content;\r
   \r
   private String[] categoryList;\r
 \r
@@ -108,14 +108,14 @@ public class ActivitySpec {
   /**\r
    * @return the content\r
    */\r
-  public ActivityContent getContent() {\r
+  public String getContent() {\r
     return content;\r
   }\r
 \r
   /**\r
    * @param content the content to set\r
    */\r
-  public void setContent(ActivityContent content) {\r
+  public void setContent(String content) {\r
     this.content = content;\r
   }\r
 \r
diff --git a/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/externalservice/sdc/entity/GenericCollectionWrapper.java b/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/externalservice/sdc/entity/GenericCollectionWrapper.java
new file mode 100644 (file)
index 0000000..5981360
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.sdc.workflowdesigner.externalservice.sdc.entity;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+public class GenericCollectionWrapper<T> implements Serializable {
+  private static final long serialVersionUID = 1L;
+
+  private transient List<T> results;
+  private int listCount;
+
+  public GenericCollectionWrapper() {
+    this.results = new ArrayList<>();
+  }
+
+  /**
+   * Instantiates a new Generic collection wrapper.
+   *
+   * @param list      the list
+   */
+  public GenericCollectionWrapper(List<T> list) {
+    if (!list.isEmpty()) {
+      this.results = list;
+      this.listCount = list.size();
+    }
+  }
+
+  public List<T> getResults() {
+    return results;
+  }
+
+  public void setResults(List<T> results) {
+    this.results = results;
+  }
+
+  public int getListCount() {
+    return listCount;
+  }
+
+  public void setListCount(int listCount) {
+    this.listCount = listCount;
+  }
+
+}
index 99e2f28..4a40597 100644 (file)
@@ -25,7 +25,7 @@ import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 
 import org.eclipse.jetty.http.HttpStatus;
-import org.onap.sdc.workflowdesigner.common.SDCProxyException;
+import org.onap.sdc.workflowdesigner.common.ActivitySpecProxyException;
 import org.onap.sdc.workflowdesigner.config.AppConfig;
 import org.onap.sdc.workflowdesigner.externalservice.sdc.ActivitySpecServiceProxy;
 import org.onap.sdc.workflowdesigner.externalservice.sdc.entity.ActivitySpec;
@@ -121,7 +121,7 @@ public class ExtendActivityResource {
       ActivitySpec[] activitySpecs = proxy.getActivitySpecs();
       ExtActivity[] extActivities = convert2ExtActivities(activitySpecs);
       return Response.status(Response.Status.OK).entity(extActivities).build();
-    } catch (SDCProxyException e) {
+    } catch (ActivitySpecProxyException e) {
       LOGGER.error("Get ExtActivities from sdc failed.", e);
       throw RestUtils.newInternalServerErrorException(e);
     }
@@ -160,10 +160,7 @@ public class ExtendActivityResource {
    */
   private Content buildContent(ActivitySpec activitySpec) {
     Content content = new Content();
-//    content.setClass(activitySpec.getContent().getClazz());
-    content.clazz = activitySpec.getContent().clazz;
-    content.setScript(activitySpec.getContent().getScript());
-    content.setScriptFormat(activitySpec.getContent().getScriptFormat());
+    content.setScript(activitySpec.getContent());
     content.setInputs(convert2InputOutputs(activitySpec.getInputs()));
     content.setOutputs(convert2InputOutputs(activitySpec.getOutputs()));
     return content;
@@ -240,7 +237,7 @@ public class ExtendActivityResource {
       ActivitySpec[] activitySpecs = proxy.getActivitySpecs();
       ExtActivityDisplayInfo displayInfo = convert2ExtActivityDisplayInfo(activitySpecs);
       return Response.status(Response.Status.OK).entity(displayInfo).build();
-    } catch (SDCProxyException e) {
+    } catch (ActivitySpecProxyException e) {
       LOGGER.error("Get Extend Activities DisplayInfo from sdc failed.", e);
       throw RestUtils.newInternalServerErrorException(e);
     }
index aff131f..15aefe4 100644 (file)
@@ -41,7 +41,7 @@ public class ActivitySpecTest {
     String name = "";\r
     String description = "";\r
     String type = "";\r
-    ActivityContent content = new ActivityContent();\r
+    String content = "";\r
     String[] categoryList = new String[]{"aaa"};\r
     Parameter[] inputs = new Parameter[0];\r
     Parameter[] outputs = new Parameter[0];\r