From 120316d1b2a4c451a6aa1d4b3d9511b2a1bb4c44 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Mon, 12 Sep 2022 16:50:35 +0200 Subject: [PATCH] Fixing code --- .../AccountingDashboardHarvesterPlugin.java | 27 +++++++------------ .../org/gcube/dataharvest/utils/Utils.java | 16 ----------- 2 files changed, 10 insertions(+), 33 deletions(-) diff --git a/src/main/java/org/gcube/dataharvest/AccountingDashboardHarvesterPlugin.java b/src/main/java/org/gcube/dataharvest/AccountingDashboardHarvesterPlugin.java index e77c92d..6d2a67e 100644 --- a/src/main/java/org/gcube/dataharvest/AccountingDashboardHarvesterPlugin.java +++ b/src/main/java/org/gcube/dataharvest/AccountingDashboardHarvesterPlugin.java @@ -17,8 +17,6 @@ import org.gcube.accounting.accounting.summary.access.model.ScopeDescriptor; import org.gcube.accounting.accounting.summary.access.model.internal.Dimension; import org.gcube.accounting.accounting.summary.access.model.update.AccountingRecord; import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore; -import org.gcube.common.authorization.library.provider.SecurityTokenProvider; -import org.gcube.common.authorization.utils.secret.GCubeSecret; import org.gcube.common.authorization.utils.secret.Secret; import org.gcube.common.scope.impl.ScopeBean; import org.gcube.common.scope.impl.ScopeBean.Type; @@ -216,17 +214,22 @@ public class AccountingDashboardHarvesterPlugin extends Plugin { Properties properties = getConfigParameters(); getProperties().set(properties); - String oldToken = properties.getProperty("OLD_ROOT_TOKEN"); - GCubeSecret gCubeSecret = new GCubeSecret(oldToken); - Utils.setContext(gCubeSecret); + ContextAuthorization contextAuthorization = new ContextAuthorization(); + + SortedSet contexts = contextAuthorization.getContexts(); + + String root = contexts.first(); + Utils.setContext(contextAuthorization.getSecretForContext(root)); + AccountingDao dao = AccountingDao.get(); + Set scopeDescriptorSet = dao.getContexts(); Map scopeDescriptorMap = new HashMap<>(); for (ScopeDescriptor scopeDescriptor : scopeDescriptorSet) { scopeDescriptorMap.put(scopeDescriptor.getId(), scopeDescriptor); } scopeDescriptors.set(scopeDescriptorMap); - + Set dimensionSet = dao.getDimensions(); Map dimensionMap = new HashMap<>(); for (Dimension dimension : dimensionSet) { @@ -234,15 +237,6 @@ public class AccountingDashboardHarvesterPlugin extends Plugin { } dimensions.set(dimensionMap); - - ContextAuthorization contextAuthorization = new ContextAuthorization(properties); - - SortedSet contexts = contextAuthorization.getContexts(); - - String root = contexts.first(); - Utils.setContext(contextAuthorization.getSecretForContext(root)); - - ArrayList accountingRecords = new ArrayList(); @@ -516,8 +510,7 @@ public class AccountingDashboardHarvesterPlugin extends Plugin { } } - Utils.setContext(gCubeSecret); - // Utils.setContext(rootSecret); + Utils.setContext(rootSecret); logger.debug("Harvest Measures from {} to {} are {}", DateUtils.format(start), DateUtils.format(end), accountingRecords); diff --git a/src/main/java/org/gcube/dataharvest/utils/Utils.java b/src/main/java/org/gcube/dataharvest/utils/Utils.java index 4527952..2b06581 100644 --- a/src/main/java/org/gcube/dataharvest/utils/Utils.java +++ b/src/main/java/org/gcube/dataharvest/utils/Utils.java @@ -22,22 +22,6 @@ public class Utils { private static Logger logger = LoggerFactory.getLogger(Utils.class); -// 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 = ""; -// String line = ""; -// -// while(line != null) { -// line = reader.readLine(); -// if(line != null) { -// json += line.trim(); -// } -// } -// return json; -// } - public static String getCurrentContext() throws ObjectNotFound, Exception { return SecretManagerProvider.instance.get().getContext(); }