From 8e2217c293e1d37a2ce56079c47610b9ae07d843 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Tue, 14 Jul 2015 13:09:23 +0000 Subject: [PATCH] Improving code git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-lib@117222 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../AccountingPersistenceConfiguration.java | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/gcube/accounting/persistence/AccountingPersistenceConfiguration.java b/src/main/java/org/gcube/accounting/persistence/AccountingPersistenceConfiguration.java index ee99e8d..dcb9c93 100644 --- a/src/main/java/org/gcube/accounting/persistence/AccountingPersistenceConfiguration.java +++ b/src/main/java/org/gcube/accounting/persistence/AccountingPersistenceConfiguration.java @@ -5,6 +5,7 @@ package org.gcube.accounting.persistence; import java.net.URI; import java.security.Key; +import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -52,7 +53,7 @@ public class AccountingPersistenceConfiguration { public AccountingPersistenceConfiguration(String persistenceClassName) throws Exception { init(); ServiceEndpoint serviceEndpoint = getServiceEndpoint(SERVICE_ENDPOINT_CATEGORY, SERVICE_ENDPOINT_NAME, persistenceClassName); - setValues(serviceEndpoint); + setValues(serviceEndpoint,persistenceClassName); } /** @@ -127,17 +128,21 @@ public class AccountingPersistenceConfiguration { return StringEncrypter.getEncrypter().decrypt(encrypted); } - protected void setValues(ServiceEndpoint serviceEndpoint) throws Exception{ + protected void setValues(ServiceEndpoint serviceEndpoint, String persistenceClassName) throws Exception{ Group accessPoints = serviceEndpoint.profile().accessPoints(); for(AccessPoint accessPoint : accessPoints){ - this.uri = new URI(accessPoint.address()); - this.username = accessPoint.username(); + Collection properties = accessPoint.propertyMap().values(); - String encryptedPassword = accessPoint.password(); - String password = decrypt(encryptedPassword); - - this.password = password; - this.propertyMap = accessPoint.propertyMap(); + if(properties.contains(new ServiceEndpoint.Property().nameAndValue(PERSISTENCE_CLASS_NAME, persistenceClassName))){ + this.uri = new URI(accessPoint.address()); + this.username = accessPoint.username(); + + String encryptedPassword = accessPoint.password(); + String password = decrypt(encryptedPassword); + + this.password = password; + this.propertyMap = accessPoint.propertyMap(); + } } }