Code redesign

Refs #11756: Refactor DataHArvesterPlugin to support scheduled execution from smart-executor 

Task-Url: https://support.d4science.org/issues/11756

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-dashboard-harvester-se-plugin@167600 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2018-05-18 14:13:10 +00:00
parent bad93fa5f7
commit 3c4c1a6b93
5 changed files with 14 additions and 18 deletions

View File

@ -144,7 +144,6 @@ public class AccountingDataHarvesterPlugin extends Plugin<DataHarvestPluginDecla
logger.error("Error harvesting Scoial Interactions for {}", context, e); logger.error("Error harvesting Scoial Interactions for {}", context, e);
} }
try { try {
// Collecting info on VRE users // Collecting info on VRE users
VREUsersHarvester vreUsersHarvester = new VREUsersHarvester(start, end); VREUsersHarvester vreUsersHarvester = new VREUsersHarvester(start, end);
@ -154,7 +153,6 @@ public class AccountingDataHarvesterPlugin extends Plugin<DataHarvestPluginDecla
logger.error("Error harvesting Context Users for {}", context, e); logger.error("Error harvesting Context Users for {}", context, e);
} }
try { try {
// Collecting info on Res. Catalogue (Dataset, Application, Deliverables, Methods) // Collecting info on Res. Catalogue (Dataset, Application, Deliverables, Methods)
ResourceCatalogueHarvester resourceCatalogueHarvester = new ResourceCatalogueHarvester(start, end); ResourceCatalogueHarvester resourceCatalogueHarvester = new ResourceCatalogueHarvester(start, end);
@ -173,8 +171,6 @@ public class AccountingDataHarvesterPlugin extends Plugin<DataHarvestPluginDecla
logger.error("Error harvesting Data Method Download for {}", context, e); logger.error("Error harvesting Data Method Download for {}", context, e);
} }
try { try {
// Collecting info on method invocation // Collecting info on method invocation
MethodInvocationHarvester methodInvocationHarvester = new MethodInvocationHarvester(start, end); MethodInvocationHarvester methodInvocationHarvester = new MethodInvocationHarvester(start, end);
@ -183,6 +179,7 @@ public class AccountingDataHarvesterPlugin extends Plugin<DataHarvestPluginDecla
} catch(Exception e) { } catch(Exception e) {
logger.error("Error harvesting Method Invocations for {}", context, e); logger.error("Error harvesting Method Invocations for {}", context, e);
} }
} }
if(!dryRun) { if(!dryRun) {

View File

@ -10,7 +10,7 @@ import java.util.Calendar;
import java.util.List; import java.util.List;
import org.gcube.dataharvest.datamodel.HarvestedData; import org.gcube.dataharvest.datamodel.HarvestedData;
import org.gcube.dataharvest.utils.Utils; import org.gcube.dataharvest.utils.DateUtils;
import org.postgresql.util.PSQLException; import org.postgresql.util.PSQLException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -145,8 +145,8 @@ public class Dao {
// first of all: check if data of the same type are already in the // first of all: check if data of the same type are already in the
// database. // database.
// In this case data will be updated. // In this case data will be updated.
Calendar cFrom = Utils.dateToCalendar(from); Calendar cFrom = DateUtils.dateToCalendar(from);
Calendar cTo = Utils.dateToCalendar(to); Calendar cTo = DateUtils.dateToCalendar(to);
int monthFrom = cFrom.get(Calendar.MONTH); int monthFrom = cFrom.get(Calendar.MONTH);
int yearFrom = cFrom.get(Calendar.YEAR); int yearFrom = cFrom.get(Calendar.YEAR);
int monthTo = cTo.get(Calendar.MONTH); int monthTo = cTo.get(Calendar.MONTH);

View File

@ -18,6 +18,7 @@ import org.gcube.common.homelibrary.jcr.workspace.JCRWorkspace;
import org.gcube.common.homelibrary.jcr.workspace.JCRWorkspaceItem; import org.gcube.common.homelibrary.jcr.workspace.JCRWorkspaceItem;
import org.gcube.dataharvest.datamodel.HarvestedData; import org.gcube.dataharvest.datamodel.HarvestedData;
import org.gcube.dataharvest.harvester.BasicHarvester; import org.gcube.dataharvest.harvester.BasicHarvester;
import org.gcube.dataharvest.utils.DateUtils;
import org.gcube.dataharvest.utils.Utils; import org.gcube.dataharvest.utils.Utils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -90,8 +91,8 @@ public class DataMethodDownloadHarvester extends BasicHarvester {
case UPDATE: case UPDATE:
case READ: case READ:
Calendar calendar = entry.getDate(); Calendar calendar = entry.getDate();
if(calendar.after(Utils.dateToCalendar(start)) if(calendar.after(DateUtils.dateToCalendar(start))
&& calendar.before(Utils.dateToCalendar(end))) { && calendar.before(DateUtils.dateToCalendar(end))) {
count++; count++;
} }

View File

@ -97,4 +97,11 @@ public class DateUtils {
return aggregationEndDate.getTime(); return aggregationEndDate.getTime();
} }
public static Calendar dateToCalendar(Date date) {
Calendar cal = null;
cal = Calendar.getInstance();
cal.setTime(date);
return cal;
}
} }

View File

@ -8,7 +8,6 @@ import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date; import java.util.Date;
import org.gcube.common.authorization.client.Constants; import org.gcube.common.authorization.client.Constants;
@ -27,14 +26,6 @@ public class Utils {
private static Logger logger = LoggerFactory.getLogger(Utils.class); private static Logger logger = LoggerFactory.getLogger(Utils.class);
public static Calendar dateToCalendar(Date date) {
Calendar cal = null;
cal = Calendar.getInstance();
cal.setTime(date);
return cal;
}
public static String dateToStringWithTZ(Date date) { public static String dateToStringWithTZ(Date date) {
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
return formatter.format(date) + "Z"; return formatter.format(date) + "Z";