diff --git a/pom.xml b/pom.xml
index b15cb01..d5df0fb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,7 +10,7 @@
org.gcube.dataaccess
database-resource-manager
- 1.1.0-SNAPSHOT
+ 1.2.0-SNAPSHOT
DatabaseResourceManager
Database resource manager
diff --git a/src/main/java/org/gcube/dataaccess/databases/accessold/AddressesDiscoverer.java b/src/main/java/org/gcube/dataaccess/databases/accessold/AddressesDiscoverer.java
index 6dc57a1..b3e5666 100644
--- a/src/main/java/org/gcube/dataaccess/databases/accessold/AddressesDiscoverer.java
+++ b/src/main/java/org/gcube/dataaccess/databases/accessold/AddressesDiscoverer.java
@@ -1,63 +1,63 @@
-package org.gcube.dataaccess.databases.accessold;
-
-import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
-import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.gcube.common.resources.gcore.ServiceEndpoint;
-import org.gcube.common.scope.api.ScopeProvider;
-import org.gcube.dataaccess.databases.resources.DBResource;
-import org.gcube.resources.discovery.client.api.DiscoveryClient;
-import org.gcube.resources.discovery.client.queries.impl.XQuery;
-
-/**
- * Class that, allowing to set a scope and to submit a query to the IS, recover
- * a list of url for each DBResource object
- */
-
-public class AddressesDiscoverer {
-
- /** Method to set the scope */
- public void setScope(String scope) {
-
- ScopeProvider.instance.set(scope);
-
- }
-
- /** Method to recover the url's list */
- public List retrieveAddress(String Category) {
-
- List addresses = new ArrayList();
-
- XQuery query = queryFor(ServiceEndpoint.class);
- query.addCondition("$resource/Profile/Category/text() eq '" + Category
- + "'");
-
- DiscoveryClient submitop = clientFor(DBResource.class);
- List access = submitop.submit(query);
-
- // System.out.println("size resource: "+access.size());
-
- int APsize = 0;
- String address = "";
-
- for (int i = 0; i < access.size(); i++) {
-
- APsize = access.get(i).getAccessPoints().size();
-
- for (int j = 0; j < APsize; j++) {
-
- address = access.get(i).getAccessPoints().get(j).address();
- addresses.add(address);
-
- }
-
- }
-
- return addresses;
-
- }
-
-}
+//package org.gcube.dataaccess.databases.accessold;
+//
+//import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
+//import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
+//
+//import java.util.ArrayList;
+//import java.util.List;
+//
+//import org.gcube.common.resources.gcore.ServiceEndpoint;
+//import org.gcube.common.scope.api.ScopeProvider;
+//import org.gcube.dataaccess.databases.resources.DBResource;
+//import org.gcube.resources.discovery.client.api.DiscoveryClient;
+//import org.gcube.resources.discovery.client.queries.impl.XQuery;
+//
+///**
+// * Class that, allowing to set a scope and to submit a query to the IS, recover
+// * a list of url for each DBResource object
+// */
+//
+//public class AddressesDiscoverer {
+//
+// /** Method to set the scope */
+// public void setScope(String scope) {
+//
+// ScopeProvider.instance.set(scope);
+//
+// }
+//
+// /** Method to recover the url's list */
+// public List retrieveAddress(String Category) {
+//
+// List addresses = new ArrayList();
+//
+// XQuery query = queryFor(ServiceEndpoint.class);
+// query.addCondition("$resource/Profile/Category/text() eq '" + Category
+// + "'");
+//
+// DiscoveryClient submitop = clientFor(DBResource.class);
+// List access = submitop.submit(query);
+//
+// // System.out.println("size resource: "+access.size());
+//
+// int APsize = 0;
+// String address = "";
+//
+// for (int i = 0; i < access.size(); i++) {
+//
+// APsize = access.get(i).getAccessPoints().size();
+//
+// for (int j = 0; j < APsize; j++) {
+//
+// address = access.get(i).getAccessPoints().get(j).address();
+// addresses.add(address);
+//
+// }
+//
+// }
+//
+// return addresses;
+//
+// }
+//
+//}
diff --git a/src/main/java/org/gcube/dataaccess/databases/resources/DBResource.java b/src/main/java/org/gcube/dataaccess/databases/resources/DBResource.java
index caac25b..116aeec 100644
--- a/src/main/java/org/gcube/dataaccess/databases/resources/DBResource.java
+++ b/src/main/java/org/gcube/dataaccess/databases/resources/DBResource.java
@@ -16,10 +16,15 @@ import org.gcube.common.encryption.StringEncrypter;
import org.gcube.contentmanagement.lexicalmatcher.utils.AnalysisLogger;
import org.gcube.dataaccess.databases.resources.processing.Normalizer;
-/** Class that describes a resource database considering information specified from the user in a xml file.
- * Information are retrieved from the xml file Through the JAXB and the relative object is initialized */
+import com.adventnet.swissqlapi.sql.functions.aggregate.count;
-//Database Resource Description class
+/**
+ * Class that describes a resource database considering information specified
+ * from the user in a xml file. Information are retrieved from the xml file
+ * Through the JAXB and the relative object is initialized
+ */
+
+// Database Resource Description class
@XmlRootElement(name = "Resource")
public class DBResource {
@@ -30,6 +35,7 @@ public class DBResource {
private String HostedOn;
private String Port = null;
private String dbguessed = null;
+ private List ap = null;
@XmlElement(name = "ID")
private String id;
@@ -127,25 +133,60 @@ public class DBResource {
}
- public void normalize(int index) throws IOException{
+ public void normalize(int index) throws Exception {
try {
Normalizer.normalize(this, index);
} catch (IOException e) {
-// e.printStackTrace();
-
+ // e.printStackTrace();
+
throw e;
}
}
- public List getAccessPoints() {
+ public List getAccessPoints() throws Exception {
- List ap = this.profile.accessPoints();
+ // List ap = this.profile.accessPoints();
+ //
+ // return ap;
+ // List ap = this.profile.accessPoints();
+ if (ap == null) {
+ List data = this.profile.accessPoints();
+ ap = getNoDuplicatedAccessPointsItems(data);
+ }
return ap;
+ }
+ // returns a list of access points with no duplicated access points. It
+ // removes the duplicated access point. We consider that two access points
+ // are duplicated if they have these 3 parameters equal: endpoint, username
+ // and password
+ private List getNoDuplicatedAccessPointsItems(
+ List data) throws Exception {
+
+ List result = new ArrayList(data);
+ List ap;
+
+ for (int j = 0; j < result.size(); j++) {
+ AccessPoint item = result.get(j);
+ ap = new ArrayList(result.subList(j, result.size()));
+
+ ap.remove(item);
+
+ for (int i = 0; i < ap.size(); i++) {
+ if (item.equals(ap.get(i))) {
+ result.remove(ap.get(i));
+
+ AnalysisLogger
+ .getLogger()
+ .debug("In class DBResource-> duplicated access point element founded and removed");
+ }
+ }
+ }
+ return result;
}
// Class Profile
@@ -296,9 +337,9 @@ public class DBResource {
private String schema = null;
private String tableSpaceCount = null;
private String tableSpacePrefix = null;
-
+
/* it contains the variables aquamapsWorldTable,aquamapsDataStore */
- private HashMap auxiliaryProperties = new HashMap();
+ private HashMap auxiliaryProperties = new HashMap();
@XmlElementRef
private Interface itfce = new Interface();
@@ -343,7 +384,7 @@ public class DBResource {
}
- public String getPassword() throws Exception{
+ public String getPassword() throws Exception {
String pwd = this.accessData.password();
@@ -351,9 +392,9 @@ public class DBResource {
password = StringEncrypter.getEncrypter().decrypt(pwd);
} catch (Exception e) {
-// e.printStackTrace();
- throw e;
-
+ // e.printStackTrace();
+ throw e;
+
}
return password;
@@ -418,7 +459,7 @@ public class DBResource {
public void setDatabaseName(String value) {
- DatabaseName=value;
+ DatabaseName = value;
for (int i = 0; i < properties.size(); i++) {
@@ -429,9 +470,10 @@ public class DBResource {
|| ((properties.get(i).name()).toLowerCase()
.contains("database"))) {
DatabaseName = properties.get(i).setvalue(value);
-
+
AnalysisLogger.getLogger().debug(
- "In class DBResource->setting the database's name to value : " + DatabaseName);
+ "In class DBResource->setting the database's name to value : "
+ + DatabaseName);
}
@@ -488,9 +530,10 @@ public class DBResource {
if ((properties.get(i).name()).toLowerCase().contains("driver")) {
Driver = properties.get(i).setvalue(value);
-
+
AnalysisLogger.getLogger().debug(
- "In class DBResource->setting the driver's name to value : " + Driver);
+ "In class DBResource->setting the driver's name to value : "
+ + Driver);
}
@@ -562,7 +605,10 @@ public class DBResource {
public String getMaxConnections() {
- /* Check if the AccessPoint object does not have a Properties section */
+ /*
+ * Check if the AccessPoint object does not have a Properties
+ * section
+ */
if (properties.size() == 0) {
return MaxConnections = "2";
@@ -590,7 +636,10 @@ public class DBResource {
public String getSchema() {
- /* Check if the AccessPoint object does not have a Properties section */
+ /*
+ * Check if the AccessPoint object does not have a Properties
+ * section
+ */
if (properties.size() == 0)
return schema = "public";
@@ -617,7 +666,10 @@ public class DBResource {
public String getTableSpaceCount() {
- /* Check if the AccessPoint object does not have a Properties section */
+ /*
+ * Check if the AccessPoint object does not have a Properties
+ * section
+ */
if (properties.size() == 0)
return tableSpaceCount = "0";
@@ -643,7 +695,10 @@ public class DBResource {
public String getTableSpacePrefix() {
- /* Check if the AccessPoint object does not have a Properties section */
+ /*
+ * Check if the AccessPoint object does not have a Properties
+ * section
+ */
if (properties.size() == 0)
return tableSpacePrefix = "";
@@ -671,7 +726,10 @@ public class DBResource {
String AuxiliaryProperty;
- /* Check if the AccessPoint object does not have a Properties section */
+ /*
+ * Check if the AccessPoint object does not have a Properties
+ * section
+ */
if (properties.size() == 0)
return auxiliaryProperties;
@@ -703,6 +761,25 @@ public class DBResource {
}
+ // it checks if two access points have these 3 parameters equal:
+ // endpoint, username and password
+ public boolean equals(AccessPoint obj) throws Exception {
+ try {
+ if ((this.address().equals(obj.address()))
+ && (this.getUsername().equals(obj.getUsername()))
+ && (this.getPassword().equals(obj.getPassword()))) {
+ // to check if elements are not equal
+ // System.out.println(this.getDescription());
+ // System.out.println(obj.getDescription());
+ return true;
+ } else {
+ return false;
+ }
+ } catch (Exception e) {
+ // e.printStackTrace();
+ throw e;
+ }
+ }
}
// Class Interface
diff --git a/src/main/java/org/gcube/dataaccess/databases/resources/processing/Decider.java b/src/main/java/org/gcube/dataaccess/databases/resources/processing/Decider.java
index 06c7ae0..aea27df 100644
--- a/src/main/java/org/gcube/dataaccess/databases/resources/processing/Decider.java
+++ b/src/main/java/org/gcube/dataaccess/databases/resources/processing/Decider.java
@@ -11,7 +11,7 @@ public class Decider {
// Method that implements the tree decision to parse and build the field
// Url.
- public static void decide(DBResource obj, int index) {
+ public static void decide(DBResource obj, int index) throws Exception{
AnalysisLogger.getLogger().debug(
"In class Decider->starting the parsing process");
diff --git a/src/main/java/org/gcube/dataaccess/databases/resources/processing/Guesser.java b/src/main/java/org/gcube/dataaccess/databases/resources/processing/Guesser.java
index 2dae35a..36230e2 100644
--- a/src/main/java/org/gcube/dataaccess/databases/resources/processing/Guesser.java
+++ b/src/main/java/org/gcube/dataaccess/databases/resources/processing/Guesser.java
@@ -16,7 +16,7 @@ public class Guesser {
// information as platform, driver and dialect and set these parameters to
// the correct values if they are not specified according to a well-formed
// mode.
- public String guessDB(DBResource obj, int index) {
+ public String guessDB(DBResource obj, int index) throws Exception{
AnalysisLogger.getLogger().debug(
"In class Guesser->starting the guess process");
diff --git a/src/main/java/org/gcube/dataaccess/databases/resources/processing/Normalizer.java b/src/main/java/org/gcube/dataaccess/databases/resources/processing/Normalizer.java
index 63e9815..b73d005 100644
--- a/src/main/java/org/gcube/dataaccess/databases/resources/processing/Normalizer.java
+++ b/src/main/java/org/gcube/dataaccess/databases/resources/processing/Normalizer.java
@@ -14,7 +14,7 @@ import org.gcube.dataaccess.databases.resources.processing.Normalizer;
public class Normalizer {
/* It performs the normalization process considering as input an access point field of a DBResource resource */
- public static void normalize(DBResource obj, int index) throws IOException {
+ public static void normalize(DBResource obj, int index) throws Exception {
AnalysisLogger.getLogger().debug(
"In class Normalizer->starting to guess the database's type");