Remove dead code
[clamp.git] / src / main / java / org / onap / clamp / clds / model / actions / ActionsHandler.java
index 1c54dae..9aed447 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP CLAMP
  * ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights
+ * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights
  *                             reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
 package org.onap.clamp.clds.model.actions;
 
 import com.att.eelf.configuration.EELFLogger;
-import com.fasterxml.jackson.databind.JsonNode;
-
-import java.io.IOException;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParseException;
 import java.util.Arrays;
 import java.util.List;
-
 import org.onap.clamp.clds.model.CldsEvent;
-import org.onap.clamp.clds.util.JacksonUtils;
+import org.onap.clamp.clds.util.JsonUtils;
 
 /**
  * Interface for actions that the user can do according to the last event.
@@ -44,7 +43,7 @@ public interface ActionsHandler {
         SIMPLE_MODEL("simpleModel"), POLICY_MODEL("policyModel");
         private final String type;
 
-        private ModelType(String type) {
+        ModelType(String type) {
             this.type = type;
         }
 
@@ -53,7 +52,7 @@ public interface ActionsHandler {
         }
     }
 
-    public EELFLogger getLogger();
+    EELFLogger getLogger();
 
     /**
      * This method determines a list of actions that the user can do according to
@@ -69,68 +68,69 @@ public interface ActionsHandler {
         List<String> permittedActions;
         String actionCd = getCurrentActionCd(event);
         switch (actionCd) {
-        case CldsEvent.ACTION_CREATE:
-            permittedActions = Arrays.asList(CldsEvent.ACTION_SUBMIT, CldsEvent.ACTION_TEST, CldsEvent.ACTION_DELETE);
-            if (isTypeModel(propText, ModelType.SIMPLE_MODEL)) {
-                permittedActions = Arrays.asList(CldsEvent.ACTION_SUBMITDCAE, CldsEvent.ACTION_SUBMITPOLICY,
-                    CldsEvent.ACTION_TEST, CldsEvent.ACTION_DELETE);
-            }
-            break;
-        case CldsEvent.ACTION_SUBMIT:
-        case CldsEvent.ACTION_RESUBMIT:
-        case CldsEvent.ACTION_DISTRIBUTE:
-            permittedActions = Arrays.asList(CldsEvent.ACTION_DEPLOY, CldsEvent.ACTION_RESUBMIT,
-                CldsEvent.ACTION_DELETE);
-            if (isTypeModel(propText, ModelType.SIMPLE_MODEL)) {
-                permittedActions = Arrays.asList(CldsEvent.ACTION_DEPLOY, CldsEvent.ACTION_SUBMITDCAE,
-                    CldsEvent.ACTION_DELETE);
-            }
-            break;
-        case CldsEvent.ACTION_SUBMITDCAE:
-            permittedActions = Arrays.asList(CldsEvent.ACTION_SUBMITDCAE, CldsEvent.ACTION_DELETE);
-            break;
-        case CldsEvent.ACTION_SUBMITPOLICY:
-            permittedActions = Arrays.asList(CldsEvent.ACTION_UPDATE, CldsEvent.ACTION_STOP);
-            break;
-        case CldsEvent.ACTION_UNDEPLOY:
-            permittedActions = Arrays.asList(CldsEvent.ACTION_UPDATE, CldsEvent.ACTION_DEPLOY,
-                CldsEvent.ACTION_RESUBMIT, CldsEvent.ACTION_DELETE);
-            if (isTypeModel(propText, ModelType.SIMPLE_MODEL)) {
-                permittedActions = Arrays.asList(CldsEvent.ACTION_UPDATE, CldsEvent.ACTION_DEPLOY,
-                    CldsEvent.ACTION_SUBMITDCAE, CldsEvent.ACTION_DELETE);
-            }
-            break;
-        case CldsEvent.ACTION_DEPLOY:
-            permittedActions = Arrays.asList(CldsEvent.ACTION_UNDEPLOY, CldsEvent.ACTION_UPDATE, CldsEvent.ACTION_STOP);
-            break;
-        case CldsEvent.ACTION_RESTART:
-        case CldsEvent.ACTION_UPDATE:
-            permittedActions = Arrays.asList(CldsEvent.ACTION_DEPLOY, CldsEvent.ACTION_UPDATE, CldsEvent.ACTION_STOP,
-                CldsEvent.ACTION_UNDEPLOY);
-            if (isTypeModel(propText, ModelType.POLICY_MODEL)) {
+            case CldsEvent.ACTION_CREATE:
+                permittedActions = Arrays.asList(CldsEvent.ACTION_SUBMIT, CldsEvent.ACTION_TEST,
+                        CldsEvent.ACTION_DELETE);
+                if (isTypeModel(propText, ModelType.SIMPLE_MODEL)) {
+                    permittedActions = Arrays.asList(CldsEvent.ACTION_SUBMITDCAE, CldsEvent.ACTION_SUBMITPOLICY,
+                            CldsEvent.ACTION_TEST, CldsEvent.ACTION_DELETE);
+                }
+                break;
+            case CldsEvent.ACTION_SUBMIT:
+            case CldsEvent.ACTION_RESUBMIT:
+            case CldsEvent.ACTION_DISTRIBUTE:
+                permittedActions = Arrays.asList(CldsEvent.ACTION_DEPLOY, CldsEvent.ACTION_RESUBMIT,
+                        CldsEvent.ACTION_DELETE);
+                if (isTypeModel(propText, ModelType.SIMPLE_MODEL)) {
+                    permittedActions = Arrays.asList(CldsEvent.ACTION_DEPLOY, CldsEvent.ACTION_SUBMITDCAE,
+                            CldsEvent.ACTION_DELETE);
+                }
+                break;
+            case CldsEvent.ACTION_SUBMITDCAE:
+                permittedActions = Arrays.asList(CldsEvent.ACTION_SUBMITDCAE, CldsEvent.ACTION_DELETE);
+                break;
+            case CldsEvent.ACTION_SUBMITPOLICY:
                 permittedActions = Arrays.asList(CldsEvent.ACTION_UPDATE, CldsEvent.ACTION_STOP);
-            }
-            break;
-        case CldsEvent.ACTION_STOP:
-            permittedActions = Arrays.asList(CldsEvent.ACTION_UPDATE, CldsEvent.ACTION_RESTART,
-                CldsEvent.ACTION_UNDEPLOY);
-            if (isTypeModel(propText, ModelType.POLICY_MODEL)) {
+                break;
+            case CldsEvent.ACTION_UNDEPLOY:
+                permittedActions = Arrays.asList(CldsEvent.ACTION_UPDATE, CldsEvent.ACTION_DEPLOY,
+                        CldsEvent.ACTION_RESUBMIT, CldsEvent.ACTION_DELETE);
+                if (isTypeModel(propText, ModelType.SIMPLE_MODEL)) {
+                    permittedActions = Arrays.asList(CldsEvent.ACTION_UPDATE, CldsEvent.ACTION_DEPLOY,
+                            CldsEvent.ACTION_SUBMITDCAE, CldsEvent.ACTION_DELETE);
+                }
+                break;
+            case CldsEvent.ACTION_DEPLOY:
+                permittedActions = Arrays.asList(CldsEvent.ACTION_UNDEPLOY, CldsEvent.ACTION_UPDATE,
+                        CldsEvent.ACTION_STOP);
+                break;
+            case CldsEvent.ACTION_RESTART:
+            case CldsEvent.ACTION_UPDATE:
+                permittedActions = Arrays.asList(CldsEvent.ACTION_DEPLOY, CldsEvent.ACTION_UPDATE,
+                        CldsEvent.ACTION_STOP, CldsEvent.ACTION_UNDEPLOY);
+                if (isTypeModel(propText, ModelType.POLICY_MODEL)) {
+                    permittedActions = Arrays.asList(CldsEvent.ACTION_UPDATE, CldsEvent.ACTION_STOP);
+                }
+                break;
+            case CldsEvent.ACTION_STOP:
                 permittedActions = Arrays.asList(CldsEvent.ACTION_UPDATE, CldsEvent.ACTION_RESTART,
-                    CldsEvent.ACTION_DELETE);
-            }
-            break;
-        default:
-            getLogger().warn("Invalid current actionCd: " + actionCd);
-            permittedActions = Arrays.asList();
+                        CldsEvent.ACTION_UNDEPLOY);
+                if (isTypeModel(propText, ModelType.POLICY_MODEL)) {
+                    permittedActions = Arrays.asList(CldsEvent.ACTION_UPDATE, CldsEvent.ACTION_RESTART,
+                            CldsEvent.ACTION_DELETE);
+                }
+                break;
+            default:
+                getLogger().warn("Invalid current actionCd: " + actionCd);
+                permittedActions = Arrays.asList();
         }
         return permittedActions;
     }
 
     /**
-     * This method returns the action of the event or a default one if not found.
+     * This returns the action of the event or a default one if not found.
      *
-     * @param event
-     *        The last event
+     * @param event The last event
      * @return The action
      */
     default String getCurrentActionCd(CldsEvent event) {
@@ -155,13 +155,15 @@ public interface ActionsHandler {
         boolean result = false;
         try {
             if (propText != null) {
-                JsonNode modelJson = JacksonUtils.getObjectMapperInstance().readTree(propText);
-                JsonNode modelJsonOfType = modelJson.get(key.getType());
-                if (modelJsonOfType != null && modelJsonOfType.asBoolean()) {
+                JsonObject modelJson = JsonUtils.GSON.fromJson(propText, JsonObject.class);
+                JsonElement modelJsonOfType = modelJson.get(key.getType());
+                if (modelJsonOfType != null
+                        && modelJsonOfType.isJsonPrimitive()
+                        && modelJsonOfType.getAsJsonPrimitive().getAsBoolean()) {
                     result = true;
                 }
             }
-        } catch (IOException e) {
+        } catch (JsonParseException e) {
             getLogger().error("Error while parsing propText json", e);
         }
         return result;