aboutsummaryrefslogtreecommitdiffstats
path: root/sdc-workflow-designer-server/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'sdc-workflow-designer-server/src/main')
-rw-r--r--sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/utils/FileCommonUtils.java286
-rw-r--r--sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/utils/RestUtils.java2
-rw-r--r--sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/utils/ToolUtils.java254
3 files changed, 14 insertions, 528 deletions
diff --git a/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/utils/FileCommonUtils.java b/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/utils/FileCommonUtils.java
index c4f455d2..74f9180b 100644
--- a/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/utils/FileCommonUtils.java
+++ b/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/utils/FileCommonUtils.java
@@ -1,5 +1,5 @@
/**
- * Copyright (c) 2017 ZTE Corporation.
+ * Copyright (c) 2017-2018 ZTE Corporation.
* All rights reserved. This program and the accompanying materials
* are made available under the Apache License, Version 2.0
* and the Eclipse Public License v1.0 which both accompany this distribution,
@@ -21,16 +21,11 @@ import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.Reader;
import java.io.Writer;
-import java.nio.file.DirectoryStream;
import java.nio.file.Files;
-import java.nio.file.Path;
import java.nio.file.Paths;
-import java.nio.file.StandardCopyOption;
-import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
-import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -42,40 +37,6 @@ import org.slf4j.LoggerFactory;
public class FileCommonUtils {
private static final Logger logger = LoggerFactory.getLogger(FileCommonUtils.class);
- private static final int KILO_BYTE = 1024; // 1K
- private static final int MEGA_BYTE = 1024 * 1024; // 1M
- private static final int GIGA_BYTE = 1024 * 1024 * 1024; // 1G
-
- private static final int TRY_COUNT = 3;
-
- /**
- *
- * @param srcAbsolutePath
- * @param destAbsolutePath
- */
- public static void rename(String srcAbsolutePath, String destAbsolutePath) {
- File dest = new File(destAbsolutePath);
- new File(srcAbsolutePath).renameTo(dest);
- }
-
- /**
- *
- * @param filePath
- * @return
- */
- public static String getFileName(String filePath) {
- return new File(filePath).getName();
- }
-
- /**
- *
- * @param filePath
- * @return
- */
- public static String getFilePath(String filePath) {
- return new File(filePath).getParent();
- }
-
/**
* @param ins
*/
@@ -88,6 +49,7 @@ public class FileCommonUtils {
}
}
}
+
/**
*
@@ -102,6 +64,7 @@ public class FileCommonUtils {
}
}
}
+
/**
* @param reader
@@ -115,6 +78,7 @@ public class FileCommonUtils {
}
}
}
+
/**
*
@@ -130,227 +94,6 @@ public class FileCommonUtils {
}
}
- /**
- * @param sourecePath
- * @param targetPath
- * @throws IOException
- */
- public static void copy(Path sourecePath, Path targetPath) throws IOException {
- if (!sourecePath.toFile().exists()) {
- return;
- }
-
- if (Files.isDirectory(sourecePath)) {
- List<Path> paths = list(sourecePath);
- for (Path path : paths) {
- copy(path, targetPath.resolve(path.getFileName()));
- }
-
- return;
- }
-
- if (!targetPath.getParent().toFile().exists()) {
- targetPath.getParent().toFile().mkdirs();
- }
- Files.copy(sourecePath, targetPath, StandardCopyOption.REPLACE_EXISTING);
- }
-
- /**
- * create folder.
- *
- * @param path folder path to create
- * @return boolean
- */
- public static boolean createDirectory(String path) {
- File folder = new File(path);
- int tryCount = 0;
- while (tryCount < FileCommonUtils.TRY_COUNT) {
- tryCount++;
- if (!folder.exists() && !folder.mkdirs()) {
- continue;
- } else {
- return true;
- }
- }
-
- return folder.exists();
- }
-
- /**
- * delete the file and file directory.
- *
- * @param file file
- * @return boolean
- */
- public static void delete(File file) {
- logger.info("delete file = {}", file);
-
- if (file.isDirectory()) {
- String[] children = file.list();
- if (children != null) {
- for (int i = 0; i < children.length; i++) {
- delete(new File(file, children[i]));
- }
- }
- }
-
- deleteFile(file);
- }
-
- /**
- *
- * @param file
- */
- public static void deleteFile(File file) {
- logger.info("deleteFile file = {}", file);
-
- try {
- FileUtils.forceDelete(file);
- } catch (IOException e) {
- logger.warn("deleteFile error. {}", file, e);
- }
- }
-
- public static String formatFileSize(double fileLength, int fileUnit) {
- DecimalFormat format = new DecimalFormat("#0.00");
- return format.format(fileLength / fileUnit) + "M";
- }
-
- /**
- * get file size.
- *
- * @param file file which to get the size
- * @param fileUnit file unit
- * @return String file size
- */
- public static String getFileSize(File file, int fileUnit) {
- String fileSize = "";
- DecimalFormat format = new DecimalFormat("#0.00");
- if (file.exists()) {
- fileSize = format.format((double) file.length() / fileUnit) + "M";
- }
- return fileSize;
- }
-
- /**
- * get file size by content.
- *
- * @param contentRange content range
- * @return String
- */
- public static String getFileSizeByContent(String contentRange) {
- String size =
- contentRange.substring(contentRange.indexOf("/") + 1, contentRange.length()).trim();
- return formatFileSize(Double.parseDouble(size), MEGA_BYTE);
- }
-
- /**
- * get the size format according file size.
- *
- * @param fileSize file size
- * @return size format
- */
- public static String getFormatFileSize(long fileSize) {
- if (fileSize >= GIGA_BYTE) {
- return String.format("%.1f GB", (float) fileSize / (long) GIGA_BYTE);
- } else if (fileSize >= MEGA_BYTE) {
- float fi = (float) fileSize / (long) MEGA_BYTE;
- return String.format(fi > 100 ? "%.0f MB" : "%.1f MB", fi);
- } else if (fileSize >= KILO_BYTE) {
- float fi = (float) fileSize / (long) KILO_BYTE;
- return String.format(fi > 100 ? "%.0f KB" : "%.1f KB", fi);
- } else {
- return String.format("%d B", fileSize);
- }
- }
-
- public static long getFileSize(String path) {
- return getFileSize(new File(path));
- }
-
- /**
- *
- * @param file
- * @return
- */
- public static long getFileSize(final File file) {
- if (file.isFile()) {
- return file.length();
- }
-
- final File[] children = file.listFiles();
- long total = 0;
- if (children != null) {
- for (final File child : children) {
- total += getFileSize(child);
- }
- }
-
- return total;
- }
-
- /**
- *
- * @param path
- * @return
- * @throws IOException
- */
- public static List<Path> list(Path path) throws IOException {
- if (!path.toFile().isDirectory()) {
- return new ArrayList<>();
- }
-
- List<Path> list = new ArrayList<>();
- DirectoryStream<Path> ds = null;
- try {
- ds = Files.newDirectoryStream(path);
- for (Path p : ds) {
- list.add(p);
- }
- } finally {
- if (ds != null) {
- ds.close();
- }
- }
-
- return list;
- }
-
- /**
- * @param path
- * @return
- * @throws IOException
- */
- public static List<String> listFileName(Path path) throws IOException {
- List<String> list = new ArrayList<>();
- DirectoryStream<Path> ds = null;
- try {
- ds = Files.newDirectoryStream(path);
- for (Path p : ds) {
- list.add(p.getFileName().toString());
- }
- } finally {
- if (ds != null) {
- ds.close();
- }
- }
-
- return list;
- }
-
- /**
- *
- * @param srcPath
- * @param destPath
- * @throws IOException
- */
- public static void moveDirectory(String srcPath, String destPath) throws IOException {
- File destDirectory = new File(destPath);
- File srcDirectory = new File(srcPath);
- FileUtils.deleteDirectory(destDirectory);
- FileUtils.copyDirectory(srcDirectory, destDirectory);
- FileUtils.deleteDirectory(srcDirectory);
- }
/**
*
@@ -375,6 +118,7 @@ public class FileCommonUtils {
return lineList.toArray(new String[0]);
}
+
/**
*
@@ -385,6 +129,7 @@ public class FileCommonUtils {
public static String readString(InputStream ins) throws IOException {
return IOUtils.toString(ins, "UTF-8");
}
+
/**
*
@@ -402,6 +147,7 @@ public class FileCommonUtils {
}
}
+
/**
*
* @param ins
@@ -431,6 +177,7 @@ public class FileCommonUtils {
closeOutputStream(os);
}
}
+
/**
*
@@ -443,6 +190,7 @@ public class FileCommonUtils {
throws IOException {
writetoAbsoluteFile(path, fileName, content, FileCommonConstants.DEFAULT_CHARSET_NAME);
}
+
/**
*
@@ -456,6 +204,7 @@ public class FileCommonUtils {
String charsetName) throws IOException {
write(path, fileName, content, charsetName);
}
+
/**
*
@@ -467,6 +216,7 @@ public class FileCommonUtils {
write(".", fileName, s, FileCommonConstants.DEFAULT_CHARSET_NAME);
}
+
/**
*
@@ -493,6 +243,7 @@ public class FileCommonUtils {
closeOutputStream(out);
}
}
+
/**
*
@@ -505,6 +256,7 @@ public class FileCommonUtils {
write(".", fileName, s, charsetName);
}
+
/**
*
* @param fileName
@@ -514,6 +266,7 @@ public class FileCommonUtils {
public static void write(String fileName, String[] ss) throws IOException {
write(fileName, ss, FileCommonConstants.DEFAULT_CHARSET_NAME);
}
+
/**
*
@@ -531,15 +284,4 @@ public class FileCommonUtils {
write(sb.toString(), fileName, charsetName);
}
- /**
- *
- * @param rootPath
- * @param more
- * @return
- */
- public static String buildAbsolutePath(String rootPath, String... more) {
- Path absolutePath = Paths.get(rootPath, more);
- return absolutePath.toFile().getAbsolutePath();
- }
-
}
diff --git a/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/utils/RestUtils.java b/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/utils/RestUtils.java
index c54d0f07..0501ad6f 100644
--- a/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/utils/RestUtils.java
+++ b/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/utils/RestUtils.java
@@ -19,8 +19,6 @@ import org.onap.sdc.workflowdesigner.utils.entity.CommonErrorResponse;
/**
*
- * @author 10090474
- *
*/
public class RestUtils {
public static InternalServerErrorException newInternalServerErrorException(Exception e) {
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
deleted file mode 100644
index 2359f714..00000000
--- a/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/utils/ToolUtils.java
+++ /dev/null
@@ -1,254 +0,0 @@
-/**
- * Copyright (c) 2017 ZTE Corporation.
- * All rights reserved. This program and the accompanying materials
- * are made available under the Apache License, Version 2.0
- * and the Eclipse Public License v1.0 which both accompany this distribution,
- * and are available at http://www.eclipse.org/legal/epl-v10.html
- * and http://www.apache.org/licenses/LICENSE-2.0
- *
- * Contributors:
- * ZTE - initial API and implementation and/or initial documentation
- */
-
-package org.onap.sdc.workflowdesigner.utils;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-import java.util.UUID;
-
-import org.apache.commons.collections.MapUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * common utility class.
- *
- */
-public class ToolUtils {
- static final Logger logger = LoggerFactory.getLogger(ToolUtils.class);
-
- /**
- * @param array
- * @param t
- * @param ts
- * @return
- */
- public static <T> T[] addElement2Array(T[] array, T t, T[] ts) {
- List<T> list = new ArrayList<>();
- if (isNotEmpty(array)) {
- list.addAll(Arrays.asList(array));
- }
- list.add(t);
-
- return list.toArray(ts);
- }
-
- /**
- *
- * @param name
- * @param v
- * @return
- */
- public static <K, V> Entry<K, V> buildEntry(K name, V v) {
- return buildMapObject(name, v).entrySet().iterator().next();
- }
-
- /**
- * @param key
- * @param v
- * @return
- */
- public static <K, V> Map<K, V> buildMapObject(K key, V v) {
- Map<K, V> map = new HashMap<>();
- map.put(key, v);
- return map;
- }
-
- /**
- *
- * @return
- */
- public static String generateUUID() {
- return UUID.randomUUID().toString();
- }
-
- /**
- *
- * @param path
- * @return
- */
- public static String getRuntimePath(String path) {
- return Class.class.getClass().getResource("/").getPath() + path;
- }
-
- /**
- *
- * @param map
- * @return
- */
- @SuppressWarnings("unchecked")
- public static <K, V> Map<V, K> invertMap(Map<K, V> map) {
- if (isEmpty(map)) {
- return new HashMap<>();
- }
-
- return MapUtils.invertMap(map);
- }
-
- /**
- *
- * @param coll
- * @return
- */
- public static boolean isEmpty(Collection<?> coll) {
- return null == coll || coll.isEmpty();
- }
-
- /**
- * @param map
- * @return
- */
- public static <K, V> boolean isEmpty(Map<K, V> map) {
- return map == null || map.isEmpty();
- }
-
- /**
- * @param val
- * @return
- */
- public static boolean isEmpty(String val) {
- return val == null || val.trim().isEmpty();
- }
-
- /**
- *
- * @param t
- * @return
- */
- public static <T> boolean isEmpty(T t) {
- return t == null || t.toString().isEmpty();
- }
-
- /**
- *
- * @param array
- * @return
- */
- public static <T> boolean isEmpty(T[] array) {
- return array == null || array.length == 0;
- }
-
- /**
- *
- * @param x
- * @param y
- * @return
- */
- public static <T> boolean isEqual(final T x, final T y) {
- return x == y || (x != null && y != null && x.equals(y));
- }
-
- /**
- *
- * @param coll
- * @return
- */
- public static boolean isNotEmpty(Collection<?> coll) {
- return null != coll && !coll.isEmpty();
- }
-
- /**
- *
- * @param map
- * @return
- */
- public static <K, V> boolean isNotEmpty(Map<K, V> map) {
- return map != null && !map.isEmpty();
- }
-
- /**
- *
- * @param val
- * @return
- */
- public static boolean isNotEmpty(String val) {
- return val != null && !val.trim().isEmpty();
- }
-
- /**
- *
- * @param t
- * @return
- */
- public static <T> boolean isNotEmpty(T t) {
- return t != null && !t.toString().isEmpty();
- }
-
- /**
- *
- * @param array
- * @return
- */
- public static <T> boolean isNotEmpty(T[] array) {
- return array != null && array.length > 0;
- }
-
- private static <K, V> Map<K, V> merge(Map<K, V> mapA, Map<K, V> mapB) {
- Map<K, V> target = new HashMap<>();
- if (!isEmpty(mapA)) {
- target.putAll(mapA);
- }
- if (!isEmpty(mapB)) {
- target.putAll(mapB);
- }
- return target;
- }
-
- /**
- * @param mapA
- * @param mapB
- * @param override
- * @return
- */
- public static <K, V> Map<K, V> merge(Map<K, V> mapA, Map<K, V> mapB, boolean override) {
- if (override) {
- return merge(mapA, mapB);
- }
-
- return merge(mapB, mapA);
- }
-
- /**
- *
- * @param keySet
- * @param origalKey
- * @return
- */
- public static String newNonRepetitiveKey(Set<String> keySet, String origalKey) {
- return newNonRepetitiveKey(keySet, origalKey, 1);
- }
-
- /**
- *
- * @param keySet
- * @param origalKey
- * @param index
- * @return
- */
- public static String newNonRepetitiveKey(Set<String> keySet, String origalKey, int index) {
- String key = origalKey + index;
- while (keySet.contains(key)) {
- index++;
- key = origalKey + index;
- }
-
- return key;
- }
-
-}