added svcapi ui and camunda code
[it/otf.git] / otf-camunda / src / main / java / org / oran / otf / common / utility / Utility.java
diff --git a/otf-camunda/src/main/java/org/oran/otf/common/utility/Utility.java b/otf-camunda/src/main/java/org/oran/otf/common/utility/Utility.java
new file mode 100644 (file)
index 0000000..5d7798b
--- /dev/null
@@ -0,0 +1,70 @@
+/*  Copyright (c) 2019 AT&T Intellectual Property.                             #\r
+#                                                                              #\r
+#   Licensed under the Apache License, Version 2.0 (the "License");            #\r
+#   you may not use this file except in compliance with the License.           #\r
+#   You may obtain a copy of the License at                                    #\r
+#                                                                              #\r
+#       http://www.apache.org/licenses/LICENSE-2.0                             #\r
+#                                                                              #\r
+#   Unless required by applicable law or agreed to in writing, software        #\r
+#   distributed under the License is distributed on an "AS IS" BASIS,          #\r
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #\r
+#   See the License for the specific language governing permissions and        #\r
+#   limitations under the License.                                             #\r
+##############################################################################*/\r
+\r
+\r
+package org.oran.otf.common.utility;\r
+\r
+import com.fasterxml.jackson.databind.ObjectMapper;\r
+import com.google.common.base.Strings;\r
+import java.util.ArrayList;\r
+import java.util.Arrays;\r
+import java.util.Collection;\r
+import java.util.HashMap;\r
+import java.util.List;\r
+import java.util.Map;\r
+import java.util.UUID;\r
+\r
+public class Utility {\r
+\r
+  public static String getLoggerPrefix() {\r
+    return "[" + Thread.currentThread().getStackTrace()[2].getMethodName() + "]: ";\r
+  }\r
+\r
+  public static Map<?, ?> toMap(Object obj) throws Exception {\r
+    ObjectMapper mapper = new ObjectMapper();\r
+    return mapper.convertValue(obj, HashMap.class);\r
+  }\r
+\r
+  public static boolean isCollection(Object obj) {\r
+    return obj.getClass().isArray() || obj instanceof Collection;\r
+  }\r
+\r
+  public static List<?> toList(Object obj) {\r
+    if (obj == null) {\r
+      throw new NullPointerException("Argument cannot be null.");\r
+    }\r
+\r
+    List<?> list = new ArrayList<>();\r
+    if (obj.getClass().isArray()) {\r
+      list = Arrays.asList((Object[]) obj);\r
+    } else if (obj instanceof Collection) {\r
+      list = new ArrayList<>((Collection<?>) obj);\r
+    }\r
+\r
+    return list;\r
+  }\r
+\r
+  public static boolean isValidUuid(String str) {\r
+    if (Strings.isNullOrEmpty(str)) {\r
+      return false;\r
+    }\r
+    try {\r
+      UUID uuid = UUID.fromString(str);\r
+      return uuid.toString().equalsIgnoreCase(str);\r
+    } catch (IllegalArgumentException iae) {\r
+      return false;\r
+    }\r
+  }\r
+}\r