From 5de25d5a2bec7afa5de30d71078cc3711c34429c Mon Sep 17 00:00:00 2001 From: "luca.frosini" Date: Fri, 18 May 2018 14:16:05 +0000 Subject: [PATCH] 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@167601 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../harvester/sobigdata/ResourceCatalogueHarvester.java | 5 +++-- src/main/java/org/gcube/dataharvest/utils/DateUtils.java | 7 +++++++ src/main/java/org/gcube/dataharvest/utils/Utils.java | 8 -------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/gcube/dataharvest/harvester/sobigdata/ResourceCatalogueHarvester.java b/src/main/java/org/gcube/dataharvest/harvester/sobigdata/ResourceCatalogueHarvester.java index 0531028..e4de0f5 100644 --- a/src/main/java/org/gcube/dataharvest/harvester/sobigdata/ResourceCatalogueHarvester.java +++ b/src/main/java/org/gcube/dataharvest/harvester/sobigdata/ResourceCatalogueHarvester.java @@ -8,6 +8,7 @@ import java.util.List; import org.gcube.dataharvest.datamodel.HarvestedData; import org.gcube.dataharvest.harvester.BasicHarvester; +import org.gcube.dataharvest.utils.DateUtils; import org.gcube.dataharvest.utils.Utils; import org.gcube.portlets.user.urlshortener.UrlEncoderUtil; import org.json.JSONArray; @@ -140,8 +141,8 @@ public class ResourceCatalogueHarvester extends BasicHarvester { private String executeQuery(String fqSubString) throws Exception { String query = "https://ckan-solr-d4s.d4science.org/solr/sobigdata/select?"; - String q = UrlEncoderUtil.encodeQuery("metadata_created:[" + Utils.dateToStringWithTZ(startDate) + " TO " - + Utils.dateToStringWithTZ(endDate) + "]"); + String q = UrlEncoderUtil.encodeQuery("metadata_created:[" + DateUtils.dateToStringWithTZ(startDate) + " TO " + + DateUtils.dateToStringWithTZ(endDate) + "]"); query += "q=" + q; String fq = UrlEncoderUtil.encodeQuery("extras_systemtype:\"SoBigData.eu: " + fqSubString + "\""); query += "&fq=" + fq + "&wt=json&indent=true"; diff --git a/src/main/java/org/gcube/dataharvest/utils/DateUtils.java b/src/main/java/org/gcube/dataharvest/utils/DateUtils.java index 79f3937..89bb774 100644 --- a/src/main/java/org/gcube/dataharvest/utils/DateUtils.java +++ b/src/main/java/org/gcube/dataharvest/utils/DateUtils.java @@ -10,6 +10,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** + * @author Eric Perrone (ISTI - CNR) * @author Luca Frosini (ISTI - CNR) */ public class DateUtils { @@ -97,6 +98,8 @@ public class DateUtils { return aggregationEndDate.getTime(); } + /* OLD functions of Eric Perrone (ISTI - CNR) */ + public static Calendar dateToCalendar(Date date) { Calendar cal = null; cal = Calendar.getInstance(); @@ -104,4 +107,8 @@ public class DateUtils { return cal; } + public static String dateToStringWithTZ(Date date) { + DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); + return formatter.format(date) + "Z"; + } } diff --git a/src/main/java/org/gcube/dataharvest/utils/Utils.java b/src/main/java/org/gcube/dataharvest/utils/Utils.java index 1fecd57..92d25ad 100644 --- a/src/main/java/org/gcube/dataharvest/utils/Utils.java +++ b/src/main/java/org/gcube/dataharvest/utils/Utils.java @@ -6,9 +6,6 @@ import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Date; import org.gcube.common.authorization.client.Constants; import org.gcube.common.authorization.client.exceptions.ObjectNotFound; @@ -26,11 +23,6 @@ public class Utils { private static Logger logger = LoggerFactory.getLogger(Utils.class); - public static String dateToStringWithTZ(Date date) { - DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); - return formatter.format(date) + "Z"; - } - public static String getJson(String url) throws MalformedURLException, IOException { URL address = new URL(url); HttpURLConnection connection = (HttpURLConnection) address.openConnection();