From bad93fa5f7cf72bf7795a7b2fdcc972cac603ba6 Mon Sep 17 00:00:00 2001 From: "luca.frosini" Date: Fri, 18 May 2018 14:05:11 +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@167599 82a268e6-3cf1-43bd-a215-b396298e98cf --- .classpath | 2 +- .settings/org.eclipse.jdt.core.prefs | 6 ----- pom.xml | 2 +- .../utils/ContextAuthorization.java | 26 ++----------------- .../utils/ContextAuthorizationTest.java | 11 -------- 5 files changed, 4 insertions(+), 43 deletions(-) diff --git a/.classpath b/.classpath index ace8266..46cbd17 100644 --- a/.classpath +++ b/.classpath @@ -27,7 +27,7 @@ - + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index 6e80039..4ede96d 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -1,8 +1,2 @@ eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 -org.eclipse.jdt.core.compiler.compliance=1.8 -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning -org.eclipse.jdt.core.compiler.source=1.8 diff --git a/pom.xml b/pom.xml index 75f90e9..caaf993 100644 --- a/pom.xml +++ b/pom.xml @@ -119,7 +119,7 @@ org.gcube.portlets.admin rmp-common-library - [2.7.1-SNAPSHOT, 3.0.0-SNAPSHOT) + [2.7.2-SNAPSHOT, 3.0.0-SNAPSHOT) diff --git a/src/main/java/org/gcube/dataharvest/utils/ContextAuthorization.java b/src/main/java/org/gcube/dataharvest/utils/ContextAuthorization.java index 266bd67..e8e8727 100644 --- a/src/main/java/org/gcube/dataharvest/utils/ContextAuthorization.java +++ b/src/main/java/org/gcube/dataharvest/utils/ContextAuthorization.java @@ -2,8 +2,6 @@ package org.gcube.dataharvest.utils; import static org.gcube.common.authorization.client.Constants.authorizationService; -import java.io.File; -import java.net.URL; import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedHashMap; @@ -16,7 +14,7 @@ import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.authorization.library.provider.UserInfo; import org.gcube.common.scope.impl.ScopeBean; import org.gcube.dataharvest.AccountingDataHarvesterPlugin; -import org.gcube.resourcemanagement.support.server.managers.scope.ScopeManager; +import org.gcube.resourcemanagement.support.server.managers.context.ContextManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -27,9 +25,6 @@ public class ContextAuthorization { private static Logger logger = LoggerFactory.getLogger(ContextAuthorization.class); - public static final String VO_FILE = "VO_FILE"; - public static final String DEFAULT_VO_FILENAME = "scopedata.xml"; - public static final String USERNAME = "USERNAME"; public static final String DEFAULT_USERNAME = "luca.frosini"; @@ -55,22 +50,6 @@ public class ContextAuthorization { retrieveContextsAndTokens(); } - public File getVOFile() { - try { - String voFileName = AccountingDataHarvesterPlugin.getProperties().get().getProperty(VO_FILE, - DEFAULT_VO_FILENAME); - URL url = ContextAuthorization.class.getClassLoader().getResource(voFileName); - File voFile = new File(url.toURI()); - logger.trace("VO file is {}", voFile); - if(!voFile.exists()) { - throw new Exception("No VO file found. Unable to continue without it"); - } - return voFile; - } catch(Exception e) { - throw new RuntimeException(e); - } - } - protected void retrieveContextsAndTokens() throws Exception { String initialToken = SecurityTokenProvider.instance.get(); @@ -79,11 +58,10 @@ public class ContextAuthorization { Properties properties = AccountingDataHarvesterPlugin.getProperties().get(); - LinkedHashMap map = ScopeManager.readScopes(getVOFile().getAbsolutePath()); + LinkedHashMap map = ContextManager.readContexts(); for(String scope : map.keySet()) { try { String context = map.get(scope).toString(); - System.out.println("Going to generate Token for Context " + context); logger.info("Going to generate Token for Context {}", context); UserInfo userInfo = new UserInfo(properties.getProperty(USERNAME, DEFAULT_USERNAME), new ArrayList<>()); diff --git a/src/test/java/org/gcube/dataharvest/utils/ContextAuthorizationTest.java b/src/test/java/org/gcube/dataharvest/utils/ContextAuthorizationTest.java index 82ebe47..690cda6 100644 --- a/src/test/java/org/gcube/dataharvest/utils/ContextAuthorizationTest.java +++ b/src/test/java/org/gcube/dataharvest/utils/ContextAuthorizationTest.java @@ -27,17 +27,6 @@ public class ContextAuthorizationTest extends ContextTest { AccountingDataHarvesterPlugin.getProperties().set(properties); } - @Test - public void testGetVOFile() throws Exception { - try { - getConfigParameters(); - }catch (Exception e) { - logger.warn("Unable to load {} file containing configuration properties. AccountingDataHarvesterPlugin will use defaults", PROPERTY_FILENAME); - } - ContextAuthorization contextAuthorization = new ContextAuthorization(); - contextAuthorization.getVOFile(); - } - @Test public void testRetrieveContextsAndTokens() throws Exception { try {