<commit_before>package eu.dzhw.fdz.metadatamanagement.web.variablemanagement.search.dto;

import java.util.HashMap;
import java.util.Map;

import javax.validation.Valid;

import org.springframework.util.StringUtils;

import eu.dzhw.fdz.metadatamanagement.data.common.documents.DateRange;
import eu.dzhw.fdz.metadatamanagement.data.common.documents.Field;
import eu.dzhw.fdz.metadatamanagement.data.variablemanagement.documents.VariableDocument;
import eu.dzhw.fdz.metadatamanagement.web.common.dtos.AbstractQueryDto;
import net.karneim.pojobuilder.GeneratePojoBuilder;

/**
 * The SearchForm Data transfer object (dto). This dto
 * 
 * @author <NAME>
 *
 */
@GeneratePojoBuilder(
    intoPackage = "eu.dzhw.fdz.metadatamanagement.web.variablemanagement.search.dto.builders")
public class VariableSearchFormDto extends AbstractQueryDto {

  /**
   * This is the request parameter of the query. The value is the search query.
   */
  private String query;

  /**
   * This is the request parameter of the scaleLevel filter.
   */
  private String scaleLevel;

  /**
   * This is the request parameter of the surveyTitle filter.
   */
  private String surveyTitle;

  /**
   * This is the request parameter of the dateRange filter.
   */
  @Valid
  private DateRange dateRange;

  /*
   * (non-Javadoc)
   * 
   * @see eu.dzhw.fdz.metadatamanagement.web.common.dtos.AbstractQueryDto#getAllFilters()
   */
  @Override
  public Map<Field, String> getAllFilters() {
    Map<Field, String> filterValues = new HashMap<>();

    // ScaleLevel
    if (StringUtils.hasText(this.scaleLevel)) {
      filterValues.put(VariableDocument.SCALE_LEVEL_FIELD, this.scaleLevel);
    }

    // Survey Title
    if (StringUtils.hasText(this.surveyTitle)) {
      filterValues.put(VariableDocument.NESTED_VARIABLE_SURVEY_TITLE_FIELD, this.surveyTitle);
    }

    // Date Range Start Date
    if (this.dateRange != null) {
      if (this.dateRange.getStartDate() != null
          && StringUtils.hasText(this.dateRange.getStartDate().toString())) {
        filterValues.put(VariableDocument.NESTED_VARIABLE_SURVEY_NESTED_PERIOD_START_DATE,
            this.dateRange.getStartDate().toString());

      }

      // Date Range End Date
      if (this.dateRange.getEndDate() != null
          && StringUtils.hasText(this.dateRange.getEndDate().toString())) {
        filterValues.put(VariableDocument.NESTED_VARIABLE_SURVEY_NESTED_PERIOD_END_DATE,
            this.dateRange.getEndDate().toString());
      }
    }

    return filterValues;
  }

  /*
   * (non-Javadoc)
   * 
   * @see eu.dzhw.fdz.metadatamanagement.web.common.dtos.AbstractQueryDto#getFilterFields()
   */
  @Override
  public Map<Field, Integer> getFilterFields() {
    Map<Field, Integer> filterFields = new HashMap<>();

    // ScaleLevel
    filterFields.put(VariableDocument.SCALE_LEVEL_FIELD, VariableSearchFormDto.FILTER_TERM);

    // Survey Title
    filterFields.put(VariableDocument.NESTED_VARIABLE_SURVEY_TITLE_FIELD,
        VariableSearchFormDto.FILTER_TERM);

    // Date Range Start Date
    filterFields.put(VariableDocument.NESTED_VARIABLE_SURVEY_NESTED_PERIOD_START_DATE,
        VariableSearchFormDto.FILTER_RANGE_GTE);

    // Date Range End Date
    filterFields.put(VariableDocument.NESTED_VARIABLE_SURVEY_NESTED_PERIOD_END_DATE,
        VariableSearchFormDto.FILTER_RANGE_LTE);

    return filterFields;
  }

  /*
   * (non-Javadoc)
   * 
   * @see eu.dzhw.fdz.metadatamanagement.web.common.dtos.AbstractQueryDto#getAggregationFields()
   */
  @Override
  public Map<Field, Integer> getAggregationFields() {
    Map<Field, Integer> aggregationFields = new HashMap<>();
<commit_msg>#7 fixed behavior of date range filter<commit_after>package eu.dzhw.fdz.metadatamanagement.web.variablemanagement.search.dto;

import java.util.HashMap;
import java.util.Map;

import javax.validation.Valid;

import org.springframework.util.StringUtils;

import eu.dzhw.fdz.metadatamanagement.data.common.documents.DateRange;
import eu.dzhw.fdz.metadatamanagement.data.common.documents.Field;
import eu.dzhw.fdz.metadatamanagement.data.variablemanagement.documents.VariableDocument;
import eu.dzhw.fdz.metadatamanagement.web.common.dtos.AbstractQueryDto;
import net.karneim.pojobuilder.GeneratePojoBuilder;

/**
 * The SearchForm Data transfer object (dto). This dto
 * 
 * @author <NAME>
 *
 */
@GeneratePojoBuilder(
    intoPackage = "eu.dzhw.fdz.metadatamanagement.web.variablemanagement.search.dto.builders")
public class VariableSearchFormDto extends AbstractQueryDto {

  /**
   * This is the request parameter of the query. The value is the search query.
   */
  private String query;

  /**
   * This is the request parameter of the scaleLevel filter.
   */
  private String scaleLevel;

  /**
   * This is the request parameter of the surveyTitle filter.
   */
  private String surveyTitle;

  /**
   * This is the request parameter of the dateRange filter.
   */
  @Valid
  private DateRange dateRange;

  /*
   * (non-Javadoc)
   * 
   * @see eu.dzhw.fdz.metadatamanagement.web.common.dtos.AbstractQueryDto#getAllFilters()
   */
  @Override
  public Map<Field, String> getAllFilters() {
    Map<Field, String> filterValues = new HashMap<>();

    // ScaleLevel
    if (StringUtils.hasText(this.scaleLevel)) {
      filterValues.put(VariableDocument.SCALE_LEVEL_FIELD, this.scaleLevel);
    }

    // Survey Title
    if (StringUtils.hasText(this.surveyTitle)) {
      filterValues.put(VariableDocument.NESTED_VARIABLE_SURVEY_TITLE_FIELD, this.surveyTitle);
    }

    //Date Range Start Date value. This value have to be checked by the end field
    //StartDate (Input by User) <= EndDate (Variable)
    if (this.dateRange != null) {
      if (this.dateRange.getStartDate() != null
          && StringUtils.hasText(this.dateRange.getStartDate().toString())) {
        filterValues.put(VariableDocument.NESTED_VARIABLE_SURVEY_NESTED_PERIOD_END_DATE,
            this.dateRange.getStartDate().toString());

      }

      // Date Range End Date This value have to be checked by the start field
      //StartDate (Variable) <= EndDate (Input by User)
      if (this.dateRange.getEndDate() != null
          && StringUtils.hasText(this.dateRange.getEndDate().toString())) {
        filterValues.put(VariableDocument.NESTED_VARIABLE_SURVEY_NESTED_PERIOD_START_DATE,
            this.dateRange.getEndDate().toString());
      }
    }

    return filterValues;
  }

  /*
   * (non-Javadoc)
   * 
   * @see eu.dzhw.fdz.metadatamanagement.web.common.dtos.AbstractQueryDto#getFilterFields()
   */
  @Override
  public Map<Field, Integer> getFilterFields() {
    Map<Field, Integer> filterFields = new HashMap<>();

    // ScaleLevel
    filterFields.put(VariableDocument.SCALE_LEVEL_FIELD, VariableSearchFormDto.FILTER_TERM);

    // Survey Title
    filterFields.put(VariableDocument.NESTED_VARIABLE_SURVEY_TITLE_FIELD,
        VariableSearchFormDto.FILTER_TERM);

    // Date Range Start Date
    filterFields.put(VariableDocument.NESTED_VARIABLE_SURVEY_NESTED_PERIOD_START_DATE,
        VariableSearchFormDto.FILTER_RANGE_LTE);

    // Date Range End Date
    filterFields.put(VariableDocument.NESTED_VARIABLE_SURVEY_NESTED_PERIOD_END_DATE,
        VariableSearchFormDto.FILTER_RANGE_GTE);

    return filterFields;
  }

  /*
   * (non-Javadoc)
   * 
   * @see eu.dzhw.fdz.metadatamanagement.web.common.dtos.AbstractQueryDto#getAggregationFields()
   */
  @Override
  public Map<Field, Integer> getAggregationFields() {
    Map<Field, Integer> aggregationFields = new HashMap<>();

{'fraction_non_alphanumeric': 0.10596202363563936, 'fraction_numerical': 0.0001327844907714779, 'mean_word_length': 3.743073047858942, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1799379', 'n_tokens_mistral': 2466, 'n_tokens_neox': 2421, 'n_words': 415}