protected static List<OrganizationalEntity> getOrganizationalEntityListFromParams(
      Map<String, String[]> params, boolean required, String operation) {
    List<OrganizationalEntity> orgEntList = new ArrayList<OrganizationalEntity>();

    String[] users = getStringListParam("user", false, params, operation);
    String[] groups = getStringListParam("group", false, params, operation);
    if (required && (users.length == 0) && (groups.length == 0)) {
      throw KieRemoteRestOperationException.badRequest(
          "At least 1 query parameter (either 'user' or 'group') is required for the '"
              + operation
              + "' operation.");
    }

    for (String user : users) {
      User newuser = TaskModelProvider.getFactory().newUser();
      ((InternalOrganizationalEntity) newuser).setId(user);
      orgEntList.add(newuser);
    }
    for (String group : groups) {
      Group newuser = TaskModelProvider.getFactory().newGroup();
      ((InternalOrganizationalEntity) newuser).setId(group);
      orgEntList.add(newuser);
    }

    return orgEntList;
  }
  protected static Map<String, Object> extractMapFromParams(
      Map<String, String[]> params, String operation) {
    Map<String, Object> map = new HashMap<String, Object>();

    for (Entry<String, String[]> entry : params.entrySet()) {
      if (entry.getKey().startsWith(MAP_QUERY_PARAM_PREFIX)) {
        String key = entry.getKey();
        String[] paramValues = entry.getValue();
        if (paramValues.length != 1) {
          throw KieRemoteRestOperationException.badRequest(
              "Only one map_* ("
                  + key
                  + ") query parameter allowed for '"
                  + operation
                  + "' operation ("
                  + paramValues.length
                  + " passed).");
        }
        String mapKey = key.substring(MAP_QUERY_PARAM_PREFIX.length());
        String mapVal = paramValues[0].trim();

        map.put(mapKey, getObjectFromString(key, mapVal));
      }
    }
    return map;
  }
 /**
  * Returns a Long if no suffix is present. Otherwise, possible suffixes are:
  *
  * <ul>
  *   <li>i : returns an Integer
  *   <li>l : returns an Long
  * </ul>
  *
  * @param paramName
  * @param paramVal
  * @return
  */
 private static Number getNumberFromString(String paramName, String paramVal, boolean mustBeLong) {
   if (paramVal.matches(LONG_INTEGER_REGEX)) {
     if (paramVal.matches(".*i$")) {
       if (mustBeLong) {
         throw KieRemoteRestOperationException.badRequest(
             paramName
                 + " parameter is numerical but contains the \"Integer\" suffix 'i' and must have no suffix or \"Long\" suffix 'l' ("
                 + paramVal
                 + ")");
       }
       paramVal = paramVal.substring(0, paramVal.length() - 1);
       if (paramVal.length() > MAX_LENGTH_INT) {
         throw KieRemoteRestOperationException.badRequest(
             paramName
                 + " parameter is numerical but too large to be an integer ("
                 + paramVal
                 + "i)");
       }
       return Integer.parseInt(paramVal);
     } else {
       if (paramVal.length() > MAX_LENGTH_LONG) {
         throw KieRemoteRestOperationException.badRequest(
             paramName + " parameter is numerical but too large to be a long (" + paramVal + ")");
       }
       if (paramVal.matches(".*l$")) {
         paramVal = paramVal.substring(0, paramVal.length() - 1);
       }
       return Long.parseLong(paramVal);
     }
   } else if (paramVal.matches(FLOAT_REGEX)) {
     if (mustBeLong) {
       throw KieRemoteRestOperationException.badRequest(
           paramName
               + " parameter is numerical but contains the \"Integer\" suffix 'i' and must have no suffix or \"Long\" suffix 'l' ("
               + paramVal
               + ")");
     }
     if (paramVal.matches(".*f$")) {
       paramVal = paramVal.substring(0, paramVal.length() - 1);
     }
     return Float.parseFloat(paramVal);
   }
   throw KieRemoteRestOperationException.badRequest(
       paramName + " parameter does not have a numerical format (" + paramVal + ")");
 }
 public static int[] getInts(int action, String[] data) {
   String name = actionParamNameMap.get(action);
   int[] result = new int[data.length];
   int i = 0;
   try {
     for (; i < data.length; ++i) {
       result[i] = Integer.valueOf(data[i]);
     }
   } catch (NumberFormatException nfe) {
     throw KieRemoteRestOperationException.badRequest(
         "Values for query parameter '" + name + "' must be integers (" + data[i] + ")");
   }
   return result;
 }
 protected static List<Status> convertStringListToStatusList(List<String> statusStrList) {
   List<Status> statuses = null;
   if (statusStrList != null && !statusStrList.isEmpty()) {
     statuses = new ArrayList<Status>();
     for (String statusStr : statusStrList) {
       try {
         statuses.add(getEnum(statusStr));
       } catch (IllegalArgumentException iae) {
         throw KieRemoteRestOperationException.badRequest(
             statusStr + " is not a valid status type for a task.");
       }
     }
   }
   return statuses;
 }
 public static Status[] getTaskStatuses(String[] data) {
   Status[] result = new Status[data.length];
   for (int i = 0; i < data.length; ++i) {
     if (data[i].toLowerCase().equals(Status.InProgress.toString().toLowerCase())) {
       result[i] = Status.InProgress;
     } else {
       String value = data[i].substring(0, 1).toUpperCase() + data[i].substring(1);
       try {
         result[i] = Status.valueOf(value);
       } catch (Exception e) {
         throw KieRemoteRestOperationException.badRequest(
             "Task status '" + data[i] + "' is not valid.");
       }
     }
   }
   return result;
 }
 protected static String[] getStringListParam(
     String paramName, boolean required, Map<String, String[]> params, String operation) {
   String[] paramValues = null;
   for (Entry<String, String[]> entry : params.entrySet()) {
     if (entry.getKey().equalsIgnoreCase(paramName)) {
       paramValues = entry.getValue();
       break;
     }
   }
   if (paramValues == null) {
     if (required) {
       throw KieRemoteRestOperationException.badRequest(
           "Query parameter '" + paramName + "' required for '" + operation + "' operation.");
     }
     return EMPTY_STRING_ARR;
   }
   return paramValues;
 }
 protected static String getStringParam(
     String paramName, boolean required, Map<String, String[]> params, String operation) {
   String[] paramValues = getStringListParam(paramName, required, params, operation);
   if (!required && (paramValues.length == 0)) {
     return null;
   }
   if (paramValues.length != 1) {
     throw KieRemoteRestOperationException.badRequest(
         "One and only one '"
             + paramName
             + "' query parameter required for '"
             + operation
             + "' operation ("
             + paramValues.length
             + " passed).");
   }
   return paramValues[0];
 }
 private static void badDateString(String dateStr) {
   throw KieRemoteRestOperationException.badRequest(
       "'" + dateStr + "' is not a valid format for a date value query parameter.");
 }