@Override public QueryParameter copy() throws AWException { return new QueryParameter(this); }
@Override public boolean equals(Object anotherObject) { if (anotherObject == null) { return false; } if (anotherObject instanceof QueryParameter) { QueryParameter anotherParameter = (QueryParameter) anotherObject; if (getType().equals(anotherParameter.getType())) { if (anotherParameter.getValue() == null || this.getValue() == null) { return this.getValue() == anotherParameter.getValue(); } return getValue().equals(anotherParameter.getValue()); } } return false; }
/** * Check if a parameter variable is empty or not * * @param parameter Variable as json * @return Variable is empty */ public boolean isEmptyParameter(QueryParameter parameter) { return parameter == null || isEmptyVariable(parameter.getValue()); } }
/** * Prepare query variables if not defined previously * * @param variableMap Variable map * @param page Page number * @param max Max elements per page * @return Query parameter map */ private Map<String, QueryParameter> forcePageAndMax(Map<String, QueryParameter> variableMap, String page, String max) { // Force page if not null if (page != null) { variableMap.put(AweConstants.QUERY_PAGE, new QueryParameter(JsonNodeFactory.instance.numberNode(Long.parseLong(page)), false, ParameterType.LONG)); } // Force max if not null if (max != null) { variableMap.put(AweConstants.QUERY_MAX, new QueryParameter(JsonNodeFactory.instance.numberNode(Long.parseLong(max)), false, ParameterType.LONG)); } return variableMap; }
if (sortParameter != null && sortParameter.isArray()) { ArrayNode sortList = (ArrayNode) sortParameter; variableMap.put(AweConstants.QUERY_SORT, new QueryParameter(sortList, true, ParameterType.OBJECT)); variableMap.put(AweConstants.QUERY_PAGE, new QueryParameter(pageParameter, false, ParameterType.LONG)); } else { variableMap.put(AweConstants.QUERY_PAGE, new QueryParameter(JsonNodeFactory.instance.numberNode(1), false, ParameterType.LONG)); variableMap.put(AweConstants.QUERY_MAX, new QueryParameter(maxParameter, false, ParameterType.LONG)); } else { variableMap.put(AweConstants.QUERY_MAX, new QueryParameter(JsonNodeFactory.instance.numberNode(rowsPerPage), false, ParameterType.LONG));
/** * Prepare query variables if not defined previously * * @param variables Variable map * @param parameters Parameter list * @return Query parameter map * @throws AWException Error generating variables */ public Map<String, QueryParameter> getVariableMap(List<Variable> variables, ObjectNode parameters, Integer index) throws AWException { Map<String, QueryParameter> variableMap = getDefaultVariableMap(parameters); // Get defined variables for (Variable variable : variables) { if (index == null) { variableMap.put(variable.getId(), new QueryParameter(getParameter(variable, parameters), variableIsList(variable, parameters), ParameterType.valueOf(variable.getType()))); } else { JsonNode parameter = getParameter(variable, parameters); if (variableIsList(variable, parameters)) { ArrayNode parameterList = (ArrayNode) parameter; parameter = parameterList.get(index); } variableMap.put(variable.getId(), new QueryParameter(parameter, false, ParameterType.valueOf(variable.getType()))); } } return variableMap; }