Class Utils

java.lang.Object
org.qubership.atp.mia.utils.Utils

public class Utils extends Object
  • Field Details

    • GSON

      public static final com.google.gson.Gson GSON
  • Constructor Details

    • Utils

      public Utils()
  • Method Details

    • nameProcessValidator

      public static void nameProcessValidator(String name)
      Check process name for valid value.
      Parameters:
      name - name of Process
    • correctPlaceInList

      public static int correctPlaceInList(List<?> list, int place)
      Bounds check place for List.
      Parameters:
      list - the list
      place - desired position
      Returns:
      bounded position
    • getDbType

      public static DbType getDbType(Server server)
      This method takes a type of database from environment and returns it as an enum.
      Parameters:
      server - - class which allows us to manipulate with environment.
      Returns:
      database type, defined in enum in SqlExecutor.class.
    • closeQuietly

      public static void closeQuietly(@Nullable AutoCloseable closeable)
      Behaves like a apache IOUtils.
    • streamOf

      @Nonnull public static <T> Stream<T> streamOf(@Nonnull Iterator<T> iterator)
    • getPathToFileOutOfLog

      public static ArrayList<String> getPathToFileOutOfLog(String outputFilePath, String regex)
      Get paths to files from log.
    • getFileNameFromPath

      public static String getFileNameFromPath(String path)
    • getTimestampFile

      public static String getTimestampFile()
    • getTimestamp

      public static String getTimestamp()
    • getFileNameWithoutExtension

      public static String getFileNameWithoutExtension(String fileName)
      Gets file name without extension.
      Parameters:
      fileName - fileName
      Returns:
      file name without extension
    • getFileNameWithTimestamp

      public static String getFileNameWithTimestamp(String fileName)
      Add timestamp to file name.
    • isHeaderNamePresent

      public static boolean isHeaderNamePresent(org.apache.http.HttpResponse httpResponse, String headerName)
      check content-disposition is present in http response header.
    • getHeaderValue

      public static String getHeaderValue(org.apache.http.HttpResponse httpResponse, String headerName)
      Get header value from the response header by passing header name as input.
    • urlEvaluator

      public static String urlEvaluator(String url, Map<String,String> parameters)
      evaluate url using query params.
    • prepareRestHeaders

      public static String prepareRestHeaders(Map<String,String> headers)
      Get header in form of supported by MIA .
    • getFirstGroupFromStringByRegexp

      public static String getFirstGroupFromStringByRegexp(String string, String regex)
      Get variables from log.
    • checkCondition

      public static boolean checkCondition(String erValue, String arValue)
      Check Condition expected result and actual result.
    • error

      public static MiaException error(org.slf4j.Logger log, ErrorCodes errorCode, Object... params)
      Throws an exception and adds an error to the log.
    • listToSet

      public static LinkedHashSet<String> listToSet(List<String> list)
    • listToSet

      public static LinkedHashSet<String> listToSet(String... list)
    • getSystemSwitcherByName

      public static Switcher getSystemSwitcherByName(Constants.SystemSwitcherNames name, List<Switcher> systemSwitchers)
    • getPrettyStringFromXml

      public static String getPrettyStringFromXml(String xmlData)
      Transforms xml response to pretty string.
    • maxExcelString

      public static String maxExcelString(String stringForCell)
      Excel cell have a limit for length of cell.
      Parameters:
      stringForCell - string for cell
      Returns:
      string
    • parseLongValueOrDefault

      public static long parseLongValueOrDefault(String valueToParse, long defaultValue, String valueName)
      Parses long value from string. If NumberFormatException occur, then default value is used. Default use while parsing @Value annotation.
      Parameters:
      valueToParse - string value to parse.
      defaultValue - if valueToParse incorrect use this one.
      valueName - field name to show in logs.
      Returns:
      parsed value.
    • handleException

      public static Exception handleException(Exception e)
      Need to fill empty exception before return to client side.
      Parameters:
      e - source exception
      Returns:
      the source exception or filled with message in case if the source one was empty.
    • sleepForTimeInMillSeconds

      public static void sleepForTimeInMillSeconds(long millSeconds)
      Wait for provided number of milliSecondsTime.
    • calculateDuration

      public static long calculateDuration(long startDateTimestamp)
      Calculates difference between startDateTimestamp and current timestamp.
      Parameters:
      startDateTimestamp - input parameter, timestamp in ms
      Returns:
      difference between startDateTimestamp and current timestamp.