@Override
  public Record getRecord() throws SitoolsException {
    Record record = new Record(buildURI());
    List<AttributeValue> value = new ArrayList<AttributeValue>();

    Object distinctValue = getFormatedValue(rs.next());

    value.add(new AttributeValue(distinctColumn.getColumnAlias(), distinctValue));
    record.setAttributeValues(value);
    return record;
  }
  @Override
  public void createDistinctRequest() throws SitoolsException {

    try {
      distinctColumn = getDistinctColumn();
      if (distinctColumn == null) {
        return;
      }

      String collectionName = params.getStructures().get(0).getName();

      MongoDBRequestModel mongoRequest = new MongoDBRequestModel();
      mongoRequest.setCollectionName(collectionName);

      String jsonFilter = getRequestAsString();
      mongoRequest.setFilterString(jsonFilter);

      if (distinctColumn != null) {
        this.logger.log(
            Level.INFO,
            "DISTINCT JSON = " + jsonFilter + "\n ON KEY : " + distinctColumn.getDataIndex());

        listDistinct = datasource.distinctQuery(distinctColumn.getDataIndex(), mongoRequest);
        if (listDistinct == null) {
          throw new SitoolsException("Error while querying datasource");
        }
        rs = listDistinct.iterator();
        nbTotalResults = listDistinct.size();
      } else {
        throw new SitoolsException("Unsuported distinct request : only one column allowed");
      }

    } catch (NumberFormatException e) {
      throw new SitoolsException("ERROR " + e.getMessage(), e);
    }
  }
 /**
  * Check values of the form
  *
  * @param parameters the parameters of the filter
  * @param col the target column
  * @return true if values agree
  */
 private boolean checkValues(String[] parameters, Column col) {
   String[] values = Arrays.copyOfRange(parameters, VALUES, VALUES + NUMBER_OF_VALUES);
   if (values.length == NUMBER_OF_VALUES) {
     Number value1;
     Number value2;
     try {
       value1 = new BigDecimal(values[0]);
       value2 = new BigDecimal(values[1]);
     } catch (NumberFormatException e) {
       throw new ResourceException(
           Status.CLIENT_ERROR_BAD_REQUEST, "Not numeric value entered", e);
     }
     if (parameters.length == DIMENSION + 2) {
       // get dimension, if exists
       String dimension = parameters[DIMENSION];
       // get unit, if exists
       String unit = parameters[UNIT];
       try {
         if (col.getUnit() == null) {
           throw new ResourceException(
               Status.CLIENT_ERROR_BAD_REQUEST,
               "The column asked has no unit, it cannot be converted");
         }
         value1 = convert(unit, col.getUnit().getUnitName(), values[0], dimension);
         value2 = convert(unit, col.getUnit().getUnitName(), values[1], dimension);
       } catch (SitoolsException e) {
         throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, e.getMessage(), e);
       }
     }
     if (value1 != null && value2 != null) {
       numericBetween = new NumericBetweenSelection(value1, value2);
       return true;
     }
   }
   return false;
 }
  @Override
  public List<Predicat> createPredicats(Request request, List<Predicat> predicats)
      throws Exception {
    // Get the dataset
    DataSetApplication dsApplication = null;
    DataSet ds = null;
    boolean isConcept = true;
    Form params = request.getResourceRef().getQueryAsForm();
    boolean filterExists = true;
    int i = 0;
    // Build predicat for filters param
    while (filterExists) {
      // first check if the filter is applied on a Concept or not
      String index = TEMPLATE_PARAM_CONCEPT.replace("#", Integer.toString(i));
      String formParam = params.getFirstValue(index);
      if (formParam == null) {
        isConcept = false;
        index = TEMPLATE_PARAM.replace("#", Integer.toString(i));
        formParam = params.getFirstValue(index);
      }
      i++;
      if (formParam != null) {
        String[] parameters = formParam.split("\\|");
        TYPE_COMPONENT[] types = TYPE_COMPONENT.values();
        Boolean trouve = false;
        for (TYPE_COMPONENT typeCmp : types) {
          if (typeCmp.name().equals(parameters[TYPE])) {
            trouve = true;
          }
        }
        if (trouve) {
          if (dsApplication == null) {
            dsApplication =
                (DataSetApplication) getContext().getAttributes().get("DataSetApplication");
            ds = dsApplication.getDataSet();
          }
          String columnAlias = null;
          if (parameters.length >= VALUES) {

            /*
             * columnsAlias = parameters[COLUMN].split(","); ArrayList<Column> columns = new ArrayList<Column>(); for
             * (String columnAlias : columnsAlias) { Column col = ds.findByColumnAlias(columnAlias); if (col != null) {
             * columns.add(col); }
             *
             * }
             */
            columnAlias = getColumnAlias(isConcept, parameters, dsApplication);
            if (columnAlias != null) {
              Column col = ds.findByColumnAlias(columnAlias);
              if (col != null
                  && col.getFilter() != null
                  && col.getFilter()
                  && checkValues(parameters, col)) {
                Predicat predicat = new Predicat();
                predicat.setLeftAttribute(col);
                predicat.setNbOpenedParanthesis(1);
                predicat.setNbClosedParanthesis(0);
                predicat.setCompareOperator(Operator.GTE);
                predicat.setRightValue(numericBetween.getFrom());
                predicats.add(predicat);
                predicat = new Predicat();
                predicat.setLeftAttribute(col);
                predicat.setNbOpenedParanthesis(0);
                predicat.setNbClosedParanthesis(1);
                predicat.setCompareOperator(Operator.LTE);
                predicat.setRightValue(numericBetween.getTo());
                predicats.add(predicat);
              }
            }
          }
        }
      } else {
        filterExists = false;
      }
    }

    return predicats;
  }