package org.gcube.dataharvest.utils; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.Locale; import org.gcube.dataharvest.dao.Dao; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class Utils { 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 dateToString(Date date) { DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); return formatter.format(date); } 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(); BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); String json = "", line = ""; while (line != null) { line = reader.readLine(); if (line != null) json += line.trim(); } return json; } // il seguente array deve essere formato dinamicamente // public static String[] soBigDataContexts = { "/d4science.research-infrastructures.eu/gCubeApps/SoBigData.eu", // "/d4science.research-infrastructures.eu/gCubeApps/SoBigData.it", // "/d4science.research-infrastructures.eu/SoBigData/SoBigDataLab", // "/d4science.research-infrastructures.eu/SoBigData/ResourceCatalogue", // "/d4science.research-infrastructures.eu/SoBigData/CityOfCitizens", // "/d4science.research-infrastructures.eu/SoBigData/SocietalDebates", // "/d4science.research-infrastructures.eu/SoBigData/WellBeingAndEconomy", // "/d4science.research-infrastructures.eu/SoBigData/SMAPH", // "/d4science.research-infrastructures.eu/SoBigData/TagMe" }; }