private HashMap<String, String[]> getCriteria(Map<String, String> parameters) { if (!"AdvancedCriteria".equals(parameters.get("_constructor"))) { return null; } try { JSONArray criterias = (JSONArray) JsonUtils.buildCriteria(parameters).get("criteria"); return getCriteria(criterias); } catch (JSONException e) { return null; } }
ResultMapCriteriaUtils(Map<String, Object> orderMap, Map<String, String> parameters) { JSONArray _criteriaArray = null; try { _criteriaArray = (JSONArray) JsonUtils.buildCriteria(parameters).get("criteria"); } catch (JSONException e) { _criteriaArray = null; } String mainOperator = parameters.get("operator"); this.recordMap = orderMap; this.criteriaArray = _criteriaArray; this.mainOperatorIsAnd = OPERATOR_AND.equals(mainOperator); }
private void readCriteria(Map<String, String> parameters) throws JSONException { JSONArray criteriaArray = (JSONArray) JsonUtils.buildCriteria(parameters).get("criteria"); selectedIds = new ArrayList<String>(); selectedChValues = new HashMap<String, List<CharacteristicValue>>(); nameFilter = null; searchKeyFilter = null; variantCreated = null; for (int i = 0; i < criteriaArray.length(); i++) { JSONObject criteria = criteriaArray.getJSONObject(i); // Basic advanced criteria handling if (criteria.has("_constructor") && "AdvancedCriteria".equals(criteria.getString("_constructor")) && criteria.has("criteria")) { JSONArray innerCriteriaArray = new JSONArray(criteria.getString("criteria")); criteria = innerCriteriaArray.getJSONObject(0); } String fieldName = criteria.getString("fieldName"); // String operatorName = criteria.getString("operator"); String value = criteria.getString("value"); if (fieldName.equals("name")) { nameFilter = value; } else if (fieldName.equals("searchKey")) { searchKeyFilter = value; } else if (fieldName.equals("id")) { selectedIds.add(value); } else if (fieldName.equals("variantCreated")) { variantCreated = criteria.getBoolean("value"); } else if (fieldName.equals("characteristicDescription")) { JSONArray values = new JSONArray(value); // All values belong to the same characteristicId, get the first one. String strCharacteristicId = null; List<CharacteristicValue> chValueIds = new ArrayList<CharacteristicValue>(); for (int j = 0; j < values.length(); j++) { CharacteristicValue chValue = OBDal.getInstance().get(CharacteristicValue.class, values.getString(j)); chValueIds.add(chValue); if (strCharacteristicId == null) { strCharacteristicId = (String) DalUtil.getId(chValue.getCharacteristic()); } } selectedChValues.put(strCharacteristicId, chValueIds); } } }