Browse Source

Fixing end date

master r5.4.0
Luca Frosini 6 months ago
parent
commit
ab8ad166d8
  1. 2
      src/main/java/org/gcube/dataharvest/AccountingDashboardHarvesterPlugin.java
  2. 11
      src/main/java/org/gcube/dataharvest/utils/DateUtils.java
  3. 2
      src/test/java/org/gcube/dataharvest/AccountingDataHarvesterJupyterTest.java
  4. 33
      src/test/java/org/gcube/dataharvest/AccountingDataHarvesterPluginTest.java
  5. 2
      src/test/java/org/gcube/dataharvest/AccountingDataHarvesterRStudioTest.java

2
src/main/java/org/gcube/dataharvest/AccountingDashboardHarvesterPlugin.java

@ -206,7 +206,7 @@ public class AccountingDashboardHarvesterPlugin extends Plugin {
start = DateUtils.getPreviousPeriod(aggregationType, partialHarvesting).getTime();
}
end = DateUtils.getEndDateFromStartDate(aggregationType, start, 1, partialHarvesting);
end = DateUtils.getEndDateFromStartDate(aggregationType, start, 1);
logger.debug("Harvesting from {} to {} (ReRun:{} - GetVREUsers:{} - DryRun:{})", DateUtils.format(start),
DateUtils.format(end), reRun, getVREUsers, dryRun);

11
src/main/java/org/gcube/dataharvest/utils/DateUtils.java

@ -97,13 +97,10 @@ public class DateUtils {
return aggregationStartCalendar;
}
public static Date getEndDateFromStartDate(AggregationType aggregationType, Date startDate, int offset, boolean partialHarvesting) {
public static Date getEndDateFromStartDate(AggregationType aggregationType, Date startDate, int offset) {
Calendar aggregationEndDate = getUTCCalendarInstance();
if(!partialHarvesting) {
aggregationEndDate.setTimeInMillis(startDate.getTime());
aggregationEndDate.add(aggregationType.getCalendarField(), offset);
//aggregationEndDate.add(Calendar.MILLISECOND, -1);
}
aggregationEndDate.setTimeInMillis(startDate.getTime());
aggregationEndDate.add(aggregationType.getCalendarField(), offset);
return aggregationEndDate.getTime();
}
@ -113,8 +110,6 @@ public class DateUtils {
return calendar;
}
/* OLD functions of Eric Perrone (ISTI - CNR) */
public static String format(Date date) {
return DateUtils.LAUNCH_DATE_FORMAT.format(date);
}

2
src/test/java/org/gcube/dataharvest/AccountingDataHarvesterJupyterTest.java

@ -95,7 +95,7 @@ public class AccountingDataHarvesterJupyterTest extends ContextTest {
for (Date start : starts) {
Date end = DateUtils.getEndDateFromStartDate(measureType, start, 1, false);
Date end = DateUtils.getEndDateFromStartDate(measureType, start, 1);
ContextTest.setContextByName(ROOT);
JupyterAccessesHarvester jupyterAccessesHarvester = new JupyterAccessesHarvester(start, end);

33
src/test/java/org/gcube/dataharvest/AccountingDataHarvesterPluginTest.java

@ -238,7 +238,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
while (from.before(runbeforeDate)) {
Date start = from.getTime();
Date end = DateUtils.getEndDateFromStartDate(aggregationType, start, 1, false);
Date end = DateUtils.getEndDateFromStartDate(aggregationType, start, 1);
logger.debug("Harvesting from {} to {}", DateUtils.format(start), DateUtils.format(end));
@ -326,7 +326,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
Date start = DateUtils.getStartCalendar(2018, Calendar.MARCH, 1).getTime();
// start = DateUtils.getPreviousPeriod(measureType).getTime();
Date end = DateUtils.getEndDateFromStartDate(aggregationType, start, 1, false);
Date end = DateUtils.getEndDateFromStartDate(aggregationType, start, 1);
logger.info("\n\n\n");
@ -388,7 +388,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
List<AccountingRecord> accountingRecords = new ArrayList<>();
for (Date start : starts) {
Date end = DateUtils.getEndDateFromStartDate(measureType, start, 1, false);
Date end = DateUtils.getEndDateFromStartDate(measureType, start, 1);
ContextTest.setContextByName(ROOT);
VREAccessesHarvester vreAccessesHarvester = new VREAccessesHarvester(start, end);
@ -432,7 +432,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
// 1).getTime();
Date start = DateUtils.getPreviousPeriod(measureType, false).getTime();
Date end = DateUtils.getEndDateFromStartDate(measureType, start, 1, false);
Date end = DateUtils.getEndDateFromStartDate(measureType, start, 1);
AccountingDashboardHarvesterPlugin accountingDataHarvesterPlugin = new AccountingDashboardHarvesterPlugin();
accountingDataHarvesterPlugin.getConfigParameters();
@ -522,7 +522,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
Calendar from = DateUtils.getStartCalendar(2018, Calendar.JUNE, 1);
Date start = from.getTime();
Date end = DateUtils.getEndDateFromStartDate(aggregationType, start, 1, false);
Date end = DateUtils.getEndDateFromStartDate(aggregationType, start, 1);
logger.debug("Harvesting Social Interaction from {} to {}", DateUtils.format(start), DateUtils.format(end));
@ -570,7 +570,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
AggregationType measureType = AggregationType.MONTHLY;
Date start = DateUtils.getPreviousPeriod(measureType, false).getTime();
Date end = DateUtils.getEndDateFromStartDate(measureType, start, 1, false);
Date end = DateUtils.getEndDateFromStartDate(measureType, start, 1);
MethodInvocationHarvester methodInvocationHarvester = new MethodInvocationHarvester(start, end);
List<AccountingRecord> accountingRecords = methodInvocationHarvester.getAccountingRecords();
@ -590,8 +590,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
AccountingDao dao = getAccountingDao();
List<Date> starts = new ArrayList<>();
starts.add(DateUtils.getStartCalendar(2021, Calendar.APRIL, 1).getTime());
starts.add(DateUtils.getStartCalendar(2021, Calendar.MAY, 1).getTime());
starts.add(DateUtils.getStartCalendar(2021, Calendar.JULY, 1).getTime());
AggregationType measureType = AggregationType.MONTHLY;
@ -609,7 +608,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
List<AccountingRecord> accountingRecords = new ArrayList<>();
for (Date start : starts) {
Date end = DateUtils.getEndDateFromStartDate(measureType, start, 1, false);
Date end = DateUtils.getEndDateFromStartDate(measureType, start, 1);
MethodInvocationHarvester methodInvocationHarvester = new MethodInvocationHarvester(start, end);
@ -637,7 +636,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
logger.debug("Going to insert {}", accountingRecords);
ContextTest.setContextByName(ROOT);
dao.insertRecords(accountingRecords.toArray(new AccountingRecord[1]));
// dao.insertRecords(accountingRecords.toArray(new AccountingRecord[1]));
} catch (Exception e) {
logger.error("", e);
@ -701,7 +700,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
for (Date start : starts) {
Date end = DateUtils.getEndDateFromStartDate(measureType, start, 1, false);
Date end = DateUtils.getEndDateFromStartDate(measureType, start, 1);
TagMeMethodInvocationHarvester methodInvocationHarvester = new TagMeMethodInvocationHarvester(start,
end);
@ -739,7 +738,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
AggregationType measureType = AggregationType.MONTHLY;
Date start = DateUtils.getPreviousPeriod(measureType, false).getTime();
Date end = DateUtils.getEndDateFromStartDate(measureType, start, 1, false);
Date end = DateUtils.getEndDateFromStartDate(measureType, start, 1);
VREUsersHarvester vreUsersHarvester = new VREUsersHarvester(start, end);
List<AccountingRecord> harvested = vreUsersHarvester.getAccountingRecords();
@ -766,7 +765,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
AggregationType measureType = AggregationType.MONTHLY;
Date start = DateUtils.getPreviousPeriod(measureType, false).getTime();
Date end = DateUtils.getEndDateFromStartDate(measureType, start, 1, false);
Date end = DateUtils.getEndDateFromStartDate(measureType, start, 1);
SortedSet<String> contexts = getContexts();
@ -800,7 +799,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
// 1).getTime();
Date start = DateUtils.getPreviousPeriod(measureType, false).getTime();
Date end = DateUtils.getEndDateFromStartDate(measureType, start, 1, false);
Date end = DateUtils.getEndDateFromStartDate(measureType, start, 1);
AccountingDashboardHarvesterPlugin accountingDataHarvesterPlugin = new AccountingDashboardHarvesterPlugin();
accountingDataHarvesterPlugin.getConfigParameters();
@ -831,7 +830,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
Date start = DateUtils.getStartCalendar(2017, Calendar.MAY, 1).getTime();
Date finalEnd = DateUtils.getStartCalendar(2020, Calendar.MAY, 1).getTime();
Date end = DateUtils.getEndDateFromStartDate(AggregationType.MONTHLY, start, 1, false);
Date end = DateUtils.getEndDateFromStartDate(AggregationType.MONTHLY, start, 1);
ScopeBean scopeBean = new ScopeBean(context);
logger.debug("FullName {} - Name {}", scopeBean.toString(), scopeBean.name());
@ -846,7 +845,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
Thread.sleep(TimeUnit.SECONDS.toMillis(90));
start = end;
end = DateUtils.getEndDateFromStartDate(AggregationType.MONTHLY, start, 1, false);
end = DateUtils.getEndDateFromStartDate(AggregationType.MONTHLY, start, 1);
}
} catch (Exception e) {
@ -905,7 +904,7 @@ public class AccountingDataHarvesterPluginTest extends ContextTest {
// 1).getTime();
Date start = DateUtils.getPreviousPeriod(measureType, false).getTime();
Date end = DateUtils.getEndDateFromStartDate(measureType, start, 1, false);
Date end = DateUtils.getEndDateFromStartDate(measureType, start, 1);
AccountingDashboardHarvesterPlugin accountingDataHarvesterPlugin = new AccountingDashboardHarvesterPlugin();
accountingDataHarvesterPlugin.getConfigParameters();

2
src/test/java/org/gcube/dataharvest/AccountingDataHarvesterRStudioTest.java

@ -99,7 +99,7 @@ public class AccountingDataHarvesterRStudioTest extends ContextTest {
for (Date start : starts) {
Date end = DateUtils.getEndDateFromStartDate(measureType, start, 1, false);
Date end = DateUtils.getEndDateFromStartDate(measureType, start, 1);
ContextTest.setContextByName(ROOT);
RStudioAccessesHarvester rstudioAccessesHarvester = new RStudioAccessesHarvester(start, end);

Loading…
Cancel
Save