- bug fixed and founded with the TabularData Database resource that has 2 access points with the same endpoint, username and password values.

getAccessPoints method in DBResource class modified and equals method defined in AccessPoint class. DBResource, Normalizer, Decider e Guesser classes modified in order manage the exception generated in equals method. Exceptio managed also in algorithms (except ListNames) in database-rm-algorithms components.

- tag version changed in pom file from 1.1.0 to 1.2.0


git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-access/DatabasesResourcesManager@100742 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Loredana Liccardo 2014-10-16 09:06:28 +00:00
parent 2986079369
commit 2f313cbbea
6 changed files with 168 additions and 91 deletions

View File

@ -10,7 +10,7 @@
<groupId>org.gcube.dataaccess</groupId>
<artifactId>database-resource-manager</artifactId>
<version>1.1.0-SNAPSHOT</version>
<version>1.2.0-SNAPSHOT</version>
<name>DatabaseResourceManager</name>
<description>Database resource manager</description>

View File

@ -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<String> retrieveAddress(String Category) {
List<String> addresses = new ArrayList<String>();
XQuery query = queryFor(ServiceEndpoint.class);
query.addCondition("$resource/Profile/Category/text() eq '" + Category
+ "'");
DiscoveryClient<DBResource> submitop = clientFor(DBResource.class);
List<DBResource> 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<String> retrieveAddress(String Category) {
//
// List<String> addresses = new ArrayList<String>();
//
// XQuery query = queryFor(ServiceEndpoint.class);
// query.addCondition("$resource/Profile/Category/text() eq '" + Category
// + "'");
//
// DiscoveryClient<DBResource> submitop = clientFor(DBResource.class);
// List<DBResource> 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;
//
// }
//
//}

View File

@ -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<AccessPoint> 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<AccessPoint> getAccessPoints() {
public List<AccessPoint> getAccessPoints() throws Exception {
List<AccessPoint> ap = this.profile.accessPoints();
// List<AccessPoint> ap = this.profile.accessPoints();
//
// return ap;
// List<AccessPoint> ap = this.profile.accessPoints();
if (ap == null) {
List<AccessPoint> 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<AccessPoint> getNoDuplicatedAccessPointsItems(
List<AccessPoint> data) throws Exception {
List<AccessPoint> result = new ArrayList<AccessPoint>(data);
List<AccessPoint> ap;
for (int j = 0; j < result.size(); j++) {
AccessPoint item = result.get(j);
ap = new ArrayList<AccessPoint>(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<String, String> auxiliaryProperties = new HashMap<String, String>();
private HashMap<String, String> auxiliaryProperties = new HashMap<String, String>();
@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

View File

@ -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");

View File

@ -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");

View File

@ -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");