Add AdapterType. 09/42409/2
authorYuanHu <yuan.hu1@zte.com.cn>
Thu, 12 Apr 2018 06:49:18 +0000 (14:49 +0800)
committerYuanHu <yuan.hu1@zte.com.cn>
Thu, 12 Apr 2018 07:00:49 +0000 (15:00 +0800)
DEFAULT: retrive data from local.
SDC: retrive data from sdc.

Issue-ID: SDC-1212

Change-Id: I53d53f062cbe705738f2f4797621aee465e60fa4
Signed-off-by: YuanHu <yuan.hu1@zte.com.cn>
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/config/AdapterType.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/utils/ToolUtils.java [new file with mode: 0644]
sdc-workflow-designer-server/src/test/java/org/onap/sdc/workflowdesigner/config/AdapterTypeTest.java [new file with mode: 0644]

index a30a026..e5b065e 100644 (file)
@@ -12,7 +12,8 @@
 
 package org.onap.sdc.workflowdesigner;
 
-import org.glassfish.jersey.media.multipart.MultiPartFeature;
+//import org.glassfish.jersey.media.multipart.MultiPartFeature;
+import org.onap.sdc.workflowdesigner.config.AdapterType;
 import org.onap.sdc.workflowdesigner.config.AppConfig;
 import org.onap.sdc.workflowdesigner.resources.ExtendActivityResource;
 import org.onap.sdc.workflowdesigner.resources.WorkflowModelerResource;
@@ -53,21 +54,29 @@ public class WorkflowDesignerApp extends Application<WorkflowDesignerConfigurati
   public void run(WorkflowDesignerConfiguration configuration, Environment environment) {
     LOGGER.info("Start to initialize Workflow Designer.");
 
-    AppConfig.setSdcServiceProxy(configuration.getSdcServiceProxy());
+    saveAppConfig(configuration);
 
     environment.jersey().register(new WorkflowModelerResource());
     environment.jersey().register(new ExtendActivityResource());
 
     // register rest interface
     environment.jersey().packages("org.onap.sdc.workflowdesigner.resources");
-    // upload file by inputstream need to register MultiPartFeature
-    environment.jersey().register(MultiPartFeature.class);
+//    // upload file by inputstream need to register MultiPartFeature
+//    environment.jersey().register(MultiPartFeature.class);
 
     initSwaggerConfig(environment, configuration);
 
     LOGGER.info("Initialize catalogue finished.");
   }
 
+  /**
+   * @param configuration
+   */
+  private void saveAppConfig(WorkflowDesignerConfiguration configuration) {
+    AppConfig.setAdapterType(AdapterType.valueOf(configuration.getAdapterType()));
+    AppConfig.setSdcServiceProxy(configuration.getSdcServiceProxy());
+  }
+
   /**
    * initialize swagger configuration.
    * 
index 28c96c7..cde361a 100644 (file)
@@ -27,9 +27,13 @@ public class WorkflowDesignerConfiguration extends Configuration {
   @NotEmpty
   private String defaultName = "Workflow Designer";
   
+  @NotEmpty
+  private String adapterType;
+  
   @NotNull
   private SDCServiceProxyInfo sdcServiceProxy;
-
+  
+  
   @JsonProperty
   public String getTemplate() {
     return template;
@@ -49,6 +53,22 @@ public class WorkflowDesignerConfiguration extends Configuration {
   public void setDefaultName(String name) {
     this.defaultName = name;
   }
+  
+  /**
+   * @return the adapterType
+   */
+  @JsonProperty
+  public String getAdapterType() {
+    return adapterType;
+  }
+
+  /**
+   * @param adapterType the adapterType to set
+   */
+  @JsonProperty
+  public void setAdapterType(String adapterType) {
+    this.adapterType = adapterType;
+  }
 
   /**
    * @return the sdcServiceProxy
diff --git a/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/config/AdapterType.java b/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/config/AdapterType.java
new file mode 100644 (file)
index 0000000..6f9c291
--- /dev/null
@@ -0,0 +1,20 @@
+/**\r
+ * Copyright (c) 2018 ZTE Corporation.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the Apache License, Version 2.0\r
+ * and the Eclipse Public License v1.0 which both accompany this distribution,\r
+ * and are available at http://www.eclipse.org/legal/epl-v10.html\r
+ * and http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Contributors:\r
+ *     ZTE - initial API and implementation and/or initial documentation\r
+ */\r
+package org.onap.sdc.workflowdesigner.config;\r
+\r
+/**\r
+ *\r
+ */\r
+public enum AdapterType {\r
+  DEFAULT, SDC\r
+\r
+}\r
index c617c1f..9a4afb3 100644 (file)
@@ -21,10 +21,26 @@ import org.onap.sdc.workflowdesigner.SDCServiceProxyInfo;
  * 
  */
 public class AppConfig {
+  private static AdapterType adapterType;
+  
   private static SDCServiceProxyInfo sdcServiceProxy;
-
+  
   private AppConfig() {}
 
+  /**
+   * @return the adapterType
+   */
+  public static AdapterType getAdapterType() {
+    return adapterType;
+  }
+
+  /**
+   * @param adapterType the adapterType to set
+   */
+  public static void setAdapterType(AdapterType adapterType) {
+    AppConfig.adapterType = adapterType;
+  }
+
   /**
    * @param sdcServiceProxy
    */
@@ -39,4 +55,11 @@ public class AppConfig {
     return sdcServiceProxy;
   }
 
+  /**
+   * @return
+   */
+  public static boolean isSDCAdapter() {
+    return adapterType.equals(AdapterType.SDC);
+  }
+
 }
diff --git a/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/utils/ToolUtils.java b/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/utils/ToolUtils.java
new file mode 100644 (file)
index 0000000..c5bdee7
--- /dev/null
@@ -0,0 +1,26 @@
+/**\r
+ * Copyright (c) 2018 ZTE Corporation.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the Apache License, Version 2.0\r
+ * and the Eclipse Public License v1.0 which both accompany this distribution,\r
+ * and are available at http://www.eclipse.org/legal/epl-v10.html\r
+ * and http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Contributors:\r
+ *     ZTE - initial API and implementation and/or initial documentation\r
+ */\r
+package org.onap.sdc.workflowdesigner.utils;\r
+\r
+/**\r
+ *\r
+ */\r
+public class ToolUtils {\r
+  /**\r
+   * @param val\r
+   * @return\r
+   */\r
+  public static boolean isEmpty(String val) {\r
+    return val == null || val.trim().isEmpty();\r
+  }\r
+\r
+}\r
diff --git a/sdc-workflow-designer-server/src/test/java/org/onap/sdc/workflowdesigner/config/AdapterTypeTest.java b/sdc-workflow-designer-server/src/test/java/org/onap/sdc/workflowdesigner/config/AdapterTypeTest.java
new file mode 100644 (file)
index 0000000..fa9de6e
--- /dev/null
@@ -0,0 +1,45 @@
+/**\r
+ * Copyright (c) 2018 ZTE Corporation.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the Apache License, Version 2.0\r
+ * and the Eclipse Public License v1.0 which both accompany this distribution,\r
+ * and are available at http://www.eclipse.org/legal/epl-v10.html\r
+ * and http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Contributors:\r
+ *     ZTE - initial API and implementation and/or initial documentation\r
+ */\r
+package org.onap.sdc.workflowdesigner.config;\r
+\r
+import static org.junit.Assert.*;\r
+\r
+import org.junit.After;\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+\r
+/**\r
+ *\r
+ */\r
+public class AdapterTypeTest {\r
+\r
+  /**\r
+   * @throws java.lang.Exception\r
+   */\r
+  @Before\r
+  public void setUp() throws Exception {}\r
+\r
+  /**\r
+   * @throws java.lang.Exception\r
+   */\r
+  @After\r
+  public void tearDown() throws Exception {}\r
+\r
+  @Test\r
+  public void test() {\r
+    AdapterType at = AdapterType.valueOf("SDC");\r
+    assertEquals(AdapterType.SDC, at);\r
+    AdapterType at1 = AdapterType.valueOf("DEFAULT");\r
+    assertEquals(AdapterType.DEFAULT, at1);\r
+  }\r
+\r
+}\r