From a0dbdf2970d98a6f319ffc9bc22748e3e1201c35 Mon Sep 17 00:00:00 2001 From: rasmi Date: Tue, 17 May 2022 05:21:30 -0400 Subject: [PATCH 1/3] config commit --- .../config/portals/industryportal/config.properties | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 src/main/resources/config/portals/industryportal/config.properties diff --git a/src/main/resources/config/portals/industryportal/config.properties b/src/main/resources/config/portals/industryportal/config.properties new file mode 100644 index 0000000..4c3b95a --- /dev/null +++ b/src/main/resources/config/portals/industryportal/config.properties @@ -0,0 +1,5 @@ +name=IndustryPortal +url=http://data.industryportal.enit.fr +apikey= +cacheFilePath=cache/fair-cache.json +cacheEnabled=true \ No newline at end of file From 375308fb61d81ab0c80d31d4c53602a72345e1cd Mon Sep 17 00:00:00 2001 From: Abdel Wadoud <88406384+rasmi-aw@users.noreply.github.com> Date: Tue, 6 Dec 2022 12:58:29 +0100 Subject: [PATCH 2/3] Made service delete cache every 12hours, when requests are coming --- .../fairness/assessment/FairServlet.java | 32 +++++++++++----- .../assessment/utils/ResultCache.java | 38 +++++++++++++------ 2 files changed, 50 insertions(+), 20 deletions(-) diff --git a/src/main/java/fr/lirmm/fairness/assessment/FairServlet.java b/src/main/java/fr/lirmm/fairness/assessment/FairServlet.java index f5e22c4..f56ff2f 100644 --- a/src/main/java/fr/lirmm/fairness/assessment/FairServlet.java +++ b/src/main/java/fr/lirmm/fairness/assessment/FairServlet.java @@ -15,6 +15,7 @@ import fr.lirmm.fairness.assessment.controllers.RequestController; import fr.lirmm.fairness.assessment.controllers.ResponseController; +import fr.lirmm.fairness.assessment.models.Configuration; import fr.lirmm.fairness.assessment.models.Ontology; import fr.lirmm.fairness.assessment.models.PortalInstance; import fr.lirmm.fairness.assessment.utils.ResultCache; @@ -26,6 +27,9 @@ * */ public class FairServlet extends HttpServlet { + public static long lastUpdate = -1; + public static long UPDATE_RATE = (1000 * 60 * 60) * 12;// 12 hours + private static final long serialVersionUID = -2749023988723161904L; private final ResultCache resultCache = new ResultCache(); @@ -33,16 +37,18 @@ public class FairServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException { - + // long startTime = System.currentTimeMillis(); - ResponseController responseController = new ResponseController(resp); ; + ResponseController responseController = new ResponseController(resp); + ; RequestController requestController = new RequestController(req); PortalInstance portalInstance = null; try { JsonObject ontologies = null; portalInstance = requestController.getPortalInstance(); + Logger.getAnonymousLogger().info("USE THE PORTAL : " + portalInstance.getName() + "; url= " + portalInstance.getUrl() + "; apikey= " + portalInstance.getApikey()); List ontologyAcronymsToEvaluate = requestController.getOntologies(); @@ -60,6 +66,18 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se } } } else { + + /** + * checking last time we updated fair cache file + */ + long now = System.currentTimeMillis(); + System.out.println("API_KEY" + portalInstance.getApikey()); + + if ((now - lastUpdate) >= UPDATE_RATE) { + lastUpdate = now; + resultCache.deleteCacheFile(portalInstance); + } + JsonObject allResponses = resultCache.read(portalInstance); if (ontologyAcronymsToEvaluate.size() == requestController.getPortalInstance().getAllOntologiesAcronyms().size()) { ontologies = allResponses.getAsJsonObject("ontologies"); @@ -80,14 +98,13 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se } - - responseController.respond(true, requestController.getRequestURI(req) , startTime ,"" , requestController); - Logger.getAnonymousLogger().info("EVALUATION ENDED WITH STATUS : " + responseController.getResponse().get("status") ); + responseController.respond(true, requestController.getRequestURI(req), startTime, "", requestController); + Logger.getAnonymousLogger().info("EVALUATION ENDED WITH STATUS : " + responseController.getResponse().get("status")); } catch (Exception e) { e.printStackTrace(); try { - responseController.respond(false, requestController.getRequestURI(req) , startTime ,e.getMessage() ,requestController); + responseController.respond(false, requestController.getRequestURI(req), startTime, e.getMessage(), requestController); } catch (Exception ex) { ex.printStackTrace(); } @@ -97,8 +114,6 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se } - - private JsonElement getCombinedScore(JsonObject ontologies) throws JSONException { CombinedFair combinedFair = new CombinedFair(ontologies.size()); Gson gson = new GsonBuilder().create(); @@ -117,5 +132,4 @@ private JsonElement evaluateOntology(String acronym, PortalInstance portalInstan } - } diff --git a/src/main/java/fr/lirmm/fairness/assessment/utils/ResultCache.java b/src/main/java/fr/lirmm/fairness/assessment/utils/ResultCache.java index 4702eab..7c120b0 100644 --- a/src/main/java/fr/lirmm/fairness/assessment/utils/ResultCache.java +++ b/src/main/java/fr/lirmm/fairness/assessment/utils/ResultCache.java @@ -17,7 +17,7 @@ public class ResultCache { public static String FILE_SAVE_NAME = "save.json"; - public void save(PortalInstance portalInstance){ + public void save(PortalInstance portalInstance) { try { ResultCache resultCache = new ResultCache(); String portal = portalInstance.getName(); @@ -43,7 +43,7 @@ public void save(PortalInstance portalInstance){ output.add("ontologies", gson.toJsonTree(jsonObjects)); getFileSaveName(portal); - resultCache.store(output.toString() , FILE_SAVE_NAME); + resultCache.store(output.toString(), FILE_SAVE_NAME); } catch (Exception e) { e.printStackTrace(); } @@ -51,21 +51,22 @@ public void save(PortalInstance portalInstance){ public JsonObject read(PortalInstance portalInstance) throws IOException { String portal = portalInstance.getName(); - if (!this.isSaved(portal)){ - System.out.println(portal+" save files not exist "); + if (!this.isSaved(portal)) { + System.out.println(portal + " save files not exist "); this.save(portalInstance); } Gson gson = new GsonBuilder().create(); - return gson.fromJson(this.get(FILE_SAVE_NAME) , JsonObject.class); + return gson.fromJson(this.get(FILE_SAVE_NAME), JsonObject.class); } - public boolean isSaved(String portal){ + public boolean isSaved(String portal) { getFileSaveName(portal); File f = new File(FILE_SAVE_NAME); return (f.exists() && !f.isDirectory()); } + public void flush(String portal) { getFileSaveName(portal); File f = new File(FILE_SAVE_NAME); @@ -82,7 +83,7 @@ private void store(String json, String fileName) throws IOException { } finally { try { - if(file != null){ + if (file != null) { file.flush(); file.close(); } @@ -92,8 +93,10 @@ private void store(String json, String fileName) throws IOException { } } - private boolean createDirIfNotExist(String filePath){ - String dirPath = filePath.substring(0, filePath.lastIndexOf(File.separator)); + private boolean createDirIfNotExist(String filePath) { + System.out.println("rasmi: " + filePath); + String fileSeparator = filePath.contains("/") ? "/" : File.separator; + String dirPath = filePath.substring(0, filePath.lastIndexOf(fileSeparator)); File file = new File(dirPath); return file.mkdir(); @@ -110,13 +113,13 @@ private String get(String filePath) throws IOException { sb.append(System.lineSeparator()); line = br.readLine(); } - return sb.toString(); + return sb.toString(); } finally { br.close(); } } - private String getFileSaveName(String portal) { + private String getFileSaveName(String portal) { try { FILE_SAVE_NAME = Configuration.getInstance().getPortalProperties(portal.toLowerCase(Locale.ROOT)).getProperty("cacheFilePath"); } catch (IOException e) { @@ -124,4 +127,17 @@ private String getFileSaveName(String portal) { } return FILE_SAVE_NAME; } + + public void deleteCacheFile(PortalInstance portalInstance) { + + if (isSaved(portalInstance.getName())) { + try { + new File(getFileSaveName(portalInstance.getName())).delete(); + } catch (Exception e) { + // in case we don't have the right to delete + e.printStackTrace(); + System.out.println("Couldn't delete file (maybe you should check your permissions)"); + } + } + } } From 1179d66d36378156a5850d1306e0437797cb938b Mon Sep 17 00:00:00 2001 From: Nasreddine Bouchemel Date: Fri, 8 Dec 2023 15:28:19 +0100 Subject: [PATCH 3/3] update industryportal url --- .../resources/config/portals/industryportal/config.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/config/portals/industryportal/config.properties b/src/main/resources/config/portals/industryportal/config.properties index 4c3b95a..d9eada0 100644 --- a/src/main/resources/config/portals/industryportal/config.properties +++ b/src/main/resources/config/portals/industryportal/config.properties @@ -1,5 +1,5 @@ name=IndustryPortal -url=http://data.industryportal.enit.fr +url=https://data.industryportal.enit.fr apikey= cacheFilePath=cache/fair-cache.json cacheEnabled=true \ No newline at end of file