001package com.astrolabsoftware.FinkBrowser.FinkPortalClient; 002 003import com.Lomikel.Utils.SmallHttpClient; 004import com.Lomikel.Utils.LomikelException; 005 006// org.json 007import org.json.JSONArray; 008import org.json.JSONObject; 009 010// Java 011import java.text.SimpleDateFormat; 012 013// Log4J 014import org.apache.logging.log4j.Logger; 015import org.apache.logging.log4j.LogManager; 016 017/** <code>FPC</code> is a client for <a href="https://api.fink-portal.org/api">Fink Science Portal</a>. 018 * @opt attributes 019 * @opt operations 020 * @opt types 021 * @opt visibility 022 * @author <a href="mailto:Julius.Hrivnac@cern.ch">J.Hrivnac</a> */ 023public class FPC { 024 025 /** Call <em>Fink Science Portal <b>objects</b></em> Web Service. 026 * <a href="https://api.fink-portal.org/api">https://api.fink-portal.org/api/v1</a>. 027 * @param request The requested formulated as {@link JSONObject}. 028 * @param endpoint The service endpoint. 029 * @return The answer formulated as {@link JSONArray}. 030 * @throws LomikelException If call fails. */ 031 public static JSONArray objects(JSONObject request) throws LomikelException { 032 return call(request, OBJECTS_WS); 033 } 034 035 /** Call <em>Fink Science Portal <b>latests</b></em> Web Service. 036 * <a href="https://api.fink-portal.org/api/v1/latests">https://api.fink-portal.org/api/v1/latests</a>. 037 * @param request The requested formulated as {@link JSONObject}. 038 * @param endpoint The service endpoint. 039 * @return The answer formulated as {@link JSONArray}. 040 * @throws LomikelException If call fails. */ 041 public static JSONArray latests(JSONObject request) throws LomikelException { 042 return call(request, LATESTS_WS); 043 } 044 045 /** Call <em>Fink Science Portal <b>anomaly</b></em> Web Service. 046 * <a href="https://api.fink-portal.org/api/v1/anomaly">https://api.fink-portal.org/api/v1/anomaly</a>. 047 * @param request The requested formulated as {@link JSONObject}. 048 * @param endpoint The service endpoint. 049 * @return The answer formulated as {@link JSONArray}. 050 * @throws LomikelException If call fails. */ 051 public static JSONArray anomaly(JSONObject request) throws LomikelException { 052 return call(request, ANOMALY_WS); 053 } 054 055 /** Call <em>Fink Science Portal</em> Web Service. 056 * @param request The requested formulated as {@link JSONObject}. 057 * @param endpoint The service endpoint. 058 * @return The answer formulated as {@link JSONArray}. 059 * @throws LomikelException If call fails. */ 060 private static JSONArray call(JSONObject request, 061 String endpoint) throws LomikelException { 062 String answer = shc.postJSON(FINK_SCIENCE_PORTAL + "/" + endpoint, 063 request.toString(), 064 null, 065 null); 066 JSONArray ja = new JSONArray(answer); 067 return ja; 068 } 069 070 public static SmallHttpClient shc = new SmallHttpClient(); 071 072 private static String FINK_SCIENCE_PORTAL = "https://api.fink-portal.org/api/v1"; 073 private static String OBJECTS_WS = "objects"; 074 private static String LATESTS_WS = "latests"; 075 private static String ANOMALY_WS = "anomaly"; 076 077 /** Logging . */ 078 private static Logger log = LogManager.getLogger(FPC.class); 079 080 } 081