Skip to content

Commit

Permalink
Merge pull request #83 from samply/feature/qb-scheduler-all
Browse files Browse the repository at this point in the history
Introduce a ViewFromTo Scheduler Fetching all Data at Once
  • Loading branch information
djuarezgf authored Jan 20, 2022
2 parents 476ca27 + dc4af06 commit 5e183c8
Show file tree
Hide file tree
Showing 15 changed files with 217 additions and 282 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [7.5.1 - 2022-01-20]
### Changed
- Quality report scheduler format simplified
### Added
- New value for quality report scheduler format: All

## [7.5.0 - 2022-01-12]
### Security
- Jersey 3
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</parent>

<artifactId>share-client</artifactId>
<version>7.5.0</version>
<version>7.5.1-SNAPSHOT</version>
<packaging>war</packaging>

<name>Connector</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ public enum EnumConfiguration {
QUALITY_REPORT_SCHEDULER_FORMAT,
QUALITY_REPORT_SCHEDULER_YEARS,
QUALITY_REPORT_GROUP_MODUL,
QUALITY_REPORT_SCHEDULER_BY_YEAR,
QUALITY_REPORT_SCHEDULER_BY_MONTH,
QUALITY_REPORT_STATISTICS_FILENAME,
QUALITY_REPORT_EXCEL_INFO_FILENAME,
QUALITY_REPORT_EXCEL_INFO_URL,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package de.samply.share.client.quality.report;

public enum QualityReportSchedulerFormat {
YEAR,
MONTH,
ALL
}
Original file line number Diff line number Diff line change
@@ -1,94 +1,39 @@
package de.samply.share.client.quality.report.views.fromto;

import de.samply.share.client.util.Utils;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import static java.time.ZoneOffset.UTC;

public class ViewFromToFactory {
import java.time.LocalDate;
import java.time.Year;
import java.time.YearMonth;

public class ViewFromToFactory {

/**
* Creates View between two dates.
* Creates a view between the first day of {@code year} and the first day of the next year.
*
* @param from lower date.
* @param to upper date.
* @return View From - To.
* @param year year.
* @return View from-to.
*/
public ViewFromTo createViewFromTo(Date from, Date to) {

String fromS = convert(from);
String toS = convert(to);

return new ViewFromTo(fromS, toS);

public ViewFromTo createYear(int year) {
Year start = Year.of(year);
return createViewFromTo(start.atDay(1), start.plusYears(1).atDay(1));
}

/**
* Create View between dates for first day to last day of month of a year.
* Create a view between the first day of {@code month} in {@code year} and the first day of the
* next month.
*
* @param month month.
* @param year year.
* @param month month.
* @return View From-To.
*/
public ViewFromTo createMonth(int month, int year) {

Calendar calendarStart = createFirstDayOfMonth(month, year);
Calendar calendarEnd = (Calendar) calendarStart.clone();
calendarEnd.add(Calendar.MONTH, 1);

return createViewFromTo(calendarStart.getTime(), calendarEnd.getTime());

}

/**
* Create View between first day of a year and last day of the year.
*
* @param year year.
* @return View from-to.
*/
public ViewFromTo createYear(int year) {

Calendar calendarStart = createFirstDayOfYear(year);
Calendar calendarEnd = createFirstDayOfYear(year + 1);

return createViewFromTo(calendarStart.getTime(), calendarEnd.getTime());

public ViewFromTo createMonth(int year, int month) {
YearMonth start = YearMonth.of(year, month);
return createViewFromTo(start.atDay(1), start.plusMonths(1).atDay(1));
}

private Calendar createFirstDayOfYear(int year) {

Calendar calendar = new GregorianCalendar();
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, Calendar.JANUARY);
calendar.set(Calendar.DAY_OF_MONTH, 1);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);

return calendar;

private ViewFromTo createViewFromTo(LocalDate from, LocalDate to) {
return new ViewFromTo(from.atStartOfDay().toInstant(UTC).toString(),
to.atStartOfDay().toInstant(UTC).toString());
}


private Calendar createFirstDayOfMonth(int month, int year) {

Calendar calendar = new GregorianCalendar();
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, month);

calendar.set(Calendar.DAY_OF_MONTH, 1);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);

return calendar;

}

private String convert(Date date) {
return Utils.convertDate2(date);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@
public interface ViewFromToScheduler {

List<ViewFromTo> createViewFromTos();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package de.samply.share.client.quality.report.views.fromto.scheduler;

import de.samply.share.client.quality.report.views.fromto.ViewFromTo;
import java.util.Collections;
import java.util.List;

/**
* A scheduler that always creates one {@link ViewFromTo} with a date range of 1900 - 2100.
*
* <p>It's meant to load all data at once.
*/
public enum ViewFromToSchedulerAll implements ViewFromToScheduler {

INSTANCE;

@Override
public List<ViewFromTo> createViewFromTos() {
return Collections.singletonList(new ViewFromTo("1900-01-01T00:00:00+00:00",
"2100-01-01T00:00:00+00:00"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,69 +6,56 @@
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Objects;

public class ViewFromToSchedulerByMonthImpl implements ViewFromToScheduler {
public class ViewFromToSchedulerByMonth implements ViewFromToScheduler {

private final ViewFromToFactory viewFromToFactory;
private int numberOfYears = 20;
private int groupsModul = 5;
private final ViewFromToFactory viewFromToFactory;

public ViewFromToSchedulerByMonthImpl(ViewFromToFactory viewFromToFactory) {
this.viewFromToFactory = viewFromToFactory;
public ViewFromToSchedulerByMonth(ViewFromToFactory viewFromToFactory) {
this.viewFromToFactory = Objects.requireNonNull(viewFromToFactory);
}

@Override
public List<ViewFromTo> createViewFromTos() {

List<Integer> lastYearsSorted = getLastYearsSorted();
return createViewFroms(lastYearsSorted);

return createViewFroms(getLastYearsSorted());
}

private List<ViewFromTo> createViewFroms(List<Integer> lastYearsSorted) {

List<ViewFromTo> viewFromToList = new ArrayList<>();

Calendar calendar = new GregorianCalendar();
int currentMonth = calendar.get(Calendar.MONTH);
int currentYear = calendar.get(Calendar.YEAR);

for (int month = 0; month < 12; month++) {

for (int year : lastYearsSorted) {

if (year < currentYear || month <= currentMonth) {

ViewFromTo viewFromTo = viewFromToFactory.createMonth(month, year);
viewFromToList.add(viewFromTo);

viewFromToList.add(viewFromToFactory.createMonth(year, month));
}

}
}

return viewFromToList;
}

private List<Integer> getLastYearsSorted() {

List<Integer> years = new ArrayList<>();

Calendar calendar = new GregorianCalendar();
int year = calendar.get(Calendar.YEAR);

for (int groupNumber = 0; groupNumber < groupsModul; groupNumber++) {

for (int i = year; i > year - numberOfYears; i--) {
if (i % groupsModul == groupNumber) {
years.add(i);
}
}

}

return years;

}

public void setGroupsModul(int groupsModul) {
Expand All @@ -78,14 +65,4 @@ public void setGroupsModul(int groupsModul) {
public void setNumberOfYears(int numberOfYears) {
this.numberOfYears = numberOfYears;
}

// public static void main(String[] args) {
//
// BasicViewFromToScheduler basicViewFromToScheduler = new BasicViewFromToScheduler();
// basicViewFromToScheduler.setViewFromToFactory(new ViewFromToFactory());
//
// List<ViewFromTo> viewFroms = basicViewFromToScheduler.createViewFroms();
//
// }

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Objects;

public class ViewFromToSchedulerByYearImpl implements ViewFromToScheduler {
public class ViewFromToSchedulerByYear implements ViewFromToScheduler {

private int years = 20;
private final ViewFromToFactory viewFromToFactory;
private int years = 20;

public ViewFromToSchedulerByYearImpl(ViewFromToFactory viewFromToFactory) {
this.viewFromToFactory = viewFromToFactory;
public ViewFromToSchedulerByYear(ViewFromToFactory viewFromToFactory) {
this.viewFromToFactory = Objects.requireNonNull(viewFromToFactory);
}

@Override
public List<ViewFromTo> createViewFromTos() {

List<ViewFromTo> viewFromToList = new ArrayList<>();

Calendar calendar = new GregorianCalendar();
Expand All @@ -36,5 +36,4 @@ public List<ViewFromTo> createViewFromTos() {
public void setYears(int years) {
this.years = years;
}

}
Loading

0 comments on commit 5e183c8

Please sign in to comment.