/**
  * Assert 2 datasets are identicals
  *
  * @param item expected
  * @param rs new dataset
  */
 public void assertEquals(DataSet item, DataSet rs) {
   assertSame(rs.getName(), item.getName());
   assertSame(rs.getDescription(), item.getDescription());
   assertSame(rs.getColumnModel(), item.getColumnModel());
   assertSame(rs.getDatasource(), item.getDatasource());
   assertSame(rs.getDirty(), item.getDirty());
   assertSame(rs, item);
 }
  @Before
  @Override
  /**
   * Create component, store and application and start server
   *
   * @throws java.lang.Exception
   */
  public void setUp() throws Exception {

    if (this.component == null) {
      this.component = new Component();
      this.component.getServers().add(Protocol.HTTP, getTestPort());
      this.component.getClients().add(Protocol.HTTP);
      this.component.getClients().add(Protocol.FILE);
      this.component.getClients().add(Protocol.CLAP);

      // Context
      Context ctx = this.component.getContext().createChildContext();
      ctx.getAttributes().put(ContextAttributes.SETTINGS, SitoolsSettings.getInstance());
      if (store == null) {
        File storeDirectory = new File(getTestRepository() + "/map");
        storeDirectory.mkdirs();
        cleanDirectory(storeDirectory);
        cleanMapDirectories(storeDirectory);
        store = new DataSetStoreXMLMap(storeDirectory, ctx);
      }
      ctx.getAttributes().put(ContextAttributes.APP_STORE, store);

      Map<String, Object> stores = new ConcurrentHashMap<String, Object>();
      stores.put(Consts.APP_STORE_DATASET, store);

      SitoolsSettings.getInstance().setStores(stores);

      // Create dataset
      Resource res = new Resource();
      res.setId(dataSourceId);
      res.setType("datasource");
      res.setMediaType("datasource");

      DataSet dataset = new DataSet();
      dataset.setId("DATASET_FOR_TESTS");
      dataset.setName("DATASET_FOR_TESTS");
      dataset.setDescription("dataset for tests");
      // dataset.addColumn(new Column());

      dataset.setDatasource(res);
      dataset.setSitoolsAttachementForUsers("/sitools/DATASET_FOR_TESTS");
      store.create(dataset);

      this.component
          .getDefaultHost()
          .attach(getAttachUrl(), new DataSetAdministration(this.component.getDefaultHost(), ctx));
    }

    if (!this.component.isStarted()) {
      this.component.start();
    }
  }
  @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;
  }