I am trying filters with Java, I can't use "Select ..." for find results.
The problem is that my object always join in my array.
My datas are ->
Registro 1-> Fecha Inicio "2018-09-01" , Fecha Fin -> "2018-09-30"
Registro 2-> Fecha inicio "2018-10-01" , Fecha Fin -> "2018-10-05"
Registro 3-> Fecha inicio "2017-12-31" , Fecha Fin -> "2018-11-30"
Registro 4-> Fecha inicio "2018-12-01" , Fecha Fin -> "2019-10-01"
Registro 5-> Fecha inicio "2018-12-30" , Fecha Fin -> "2018-12-31"
Registro 6-> Fecha inicio "2018-11-30" , Fecha Fin -> "2018-12-01"
The user insert -> "2018-12-01" hasta el "9999-31-12"
for filter.
Register 4 should be insert to array because my user insert "2018-12-01" and my register have the same Date Start.
Register 5º should be insert to array because my user insert "2018-12-01" and finish year->9999
THEN how my register is between, It should insert to array.
Register 6º -> shold be insert to array because the date End because its end date corresponds to the period of time between the start date and the end date of the user, that is, the user wants between "2018-12-01" until "9999-31-12" and the date End of registration is "2018-12-01"
public List<Article> filterResult(String paramSelect, String dateStart, String dateEnd) {
List<Article> list = Collections.emptyList();
try {
// Sino me ponen fecha de fin, la establezco al máximo.
if(dateStart != null && dateEnd == null) {
dateEnd ="9999-31-12";
list = (List<Article>) this.pgRepository.findAll();
list = this.getStart(list, dateStart, dateEnd);
}
} catch (Exception e) {
LOGGER.error(e.getMessage());
}
return list;
}
private List<Article> getStart(List<Article> list, String dateStart, String dateEnd) throws ParseException {
DateFomrat df = new SimpleDateFormat("yyyy-MM-dd");
Date userDate = df.parse(dateStart);
Date userEnd = df.parse(dateEnd);
List<Article> filter = new ArrayList<Article>();
for(Article param : list) {
Date paramStart = df.parse(param.getStartdatevalidity());
Date paramEnd = df.parse(param.getEnddatevalidity());
if(paramStart.after(userDate) || paramEnd.before(userDate) && paramStart.after(userEnd) || paramEnd.before(userEnd)) {
filter.add(param);
}
}
return filter;
}
I have two problems -> 1º My object always is guarded in my array. 2º I don't know if my logic is correct...
Thanks and sorry for my English.