- 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:
parent
2986079369
commit
2f313cbbea
2
pom.xml
2
pom.xml
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
<groupId>org.gcube.dataaccess</groupId>
|
<groupId>org.gcube.dataaccess</groupId>
|
||||||
<artifactId>database-resource-manager</artifactId>
|
<artifactId>database-resource-manager</artifactId>
|
||||||
<version>1.1.0-SNAPSHOT</version>
|
<version>1.2.0-SNAPSHOT</version>
|
||||||
<name>DatabaseResourceManager</name>
|
<name>DatabaseResourceManager</name>
|
||||||
<description>Database resource manager</description>
|
<description>Database resource manager</description>
|
||||||
|
|
||||||
|
|
|
@ -1,63 +1,63 @@
|
||||||
package org.gcube.dataaccess.databases.accessold;
|
//package org.gcube.dataaccess.databases.accessold;
|
||||||
|
//
|
||||||
import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
|
//import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
|
||||||
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
|
//import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
|
||||||
|
//
|
||||||
import java.util.ArrayList;
|
//import java.util.ArrayList;
|
||||||
import java.util.List;
|
//import java.util.List;
|
||||||
|
//
|
||||||
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
//import org.gcube.common.resources.gcore.ServiceEndpoint;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
//import org.gcube.common.scope.api.ScopeProvider;
|
||||||
import org.gcube.dataaccess.databases.resources.DBResource;
|
//import org.gcube.dataaccess.databases.resources.DBResource;
|
||||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
//import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||||
import org.gcube.resources.discovery.client.queries.impl.XQuery;
|
//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
|
// * Class that, allowing to set a scope and to submit a query to the IS, recover
|
||||||
* a list of url for each DBResource object
|
// * a list of url for each DBResource object
|
||||||
*/
|
// */
|
||||||
|
//
|
||||||
public class AddressesDiscoverer {
|
//public class AddressesDiscoverer {
|
||||||
|
//
|
||||||
/** Method to set the scope */
|
// /** Method to set the scope */
|
||||||
public void setScope(String scope) {
|
// public void setScope(String scope) {
|
||||||
|
//
|
||||||
ScopeProvider.instance.set(scope);
|
// ScopeProvider.instance.set(scope);
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/** Method to recover the url's list */
|
// /** Method to recover the url's list */
|
||||||
public List<String> retrieveAddress(String Category) {
|
// public List<String> retrieveAddress(String Category) {
|
||||||
|
//
|
||||||
List<String> addresses = new ArrayList<String>();
|
// List<String> addresses = new ArrayList<String>();
|
||||||
|
//
|
||||||
XQuery query = queryFor(ServiceEndpoint.class);
|
// XQuery query = queryFor(ServiceEndpoint.class);
|
||||||
query.addCondition("$resource/Profile/Category/text() eq '" + Category
|
// query.addCondition("$resource/Profile/Category/text() eq '" + Category
|
||||||
+ "'");
|
// + "'");
|
||||||
|
//
|
||||||
DiscoveryClient<DBResource> submitop = clientFor(DBResource.class);
|
// DiscoveryClient<DBResource> submitop = clientFor(DBResource.class);
|
||||||
List<DBResource> access = submitop.submit(query);
|
// List<DBResource> access = submitop.submit(query);
|
||||||
|
//
|
||||||
// System.out.println("size resource: "+access.size());
|
// // System.out.println("size resource: "+access.size());
|
||||||
|
//
|
||||||
int APsize = 0;
|
// int APsize = 0;
|
||||||
String address = "";
|
// String address = "";
|
||||||
|
//
|
||||||
for (int i = 0; i < access.size(); i++) {
|
// for (int i = 0; i < access.size(); i++) {
|
||||||
|
//
|
||||||
APsize = access.get(i).getAccessPoints().size();
|
// APsize = access.get(i).getAccessPoints().size();
|
||||||
|
//
|
||||||
for (int j = 0; j < APsize; j++) {
|
// for (int j = 0; j < APsize; j++) {
|
||||||
|
//
|
||||||
address = access.get(i).getAccessPoints().get(j).address();
|
// address = access.get(i).getAccessPoints().get(j).address();
|
||||||
addresses.add(address);
|
// addresses.add(address);
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
return addresses;
|
// return addresses;
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
}
|
//}
|
||||||
|
|
|
@ -16,10 +16,15 @@ import org.gcube.common.encryption.StringEncrypter;
|
||||||
import org.gcube.contentmanagement.lexicalmatcher.utils.AnalysisLogger;
|
import org.gcube.contentmanagement.lexicalmatcher.utils.AnalysisLogger;
|
||||||
import org.gcube.dataaccess.databases.resources.processing.Normalizer;
|
import org.gcube.dataaccess.databases.resources.processing.Normalizer;
|
||||||
|
|
||||||
/** Class that describes a resource database considering information specified from the user in a xml file.
|
import com.adventnet.swissqlapi.sql.functions.aggregate.count;
|
||||||
* Information are retrieved from the xml file Through the JAXB and the relative object is initialized */
|
|
||||||
|
|
||||||
//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")
|
@XmlRootElement(name = "Resource")
|
||||||
public class DBResource {
|
public class DBResource {
|
||||||
|
|
||||||
|
@ -30,6 +35,7 @@ public class DBResource {
|
||||||
private String HostedOn;
|
private String HostedOn;
|
||||||
private String Port = null;
|
private String Port = null;
|
||||||
private String dbguessed = null;
|
private String dbguessed = null;
|
||||||
|
private List<AccessPoint> ap = null;
|
||||||
|
|
||||||
@XmlElement(name = "ID")
|
@XmlElement(name = "ID")
|
||||||
private String 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 {
|
try {
|
||||||
Normalizer.normalize(this, index);
|
Normalizer.normalize(this, index);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|
||||||
// e.printStackTrace();
|
// e.printStackTrace();
|
||||||
|
|
||||||
throw e;
|
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;
|
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
|
// Class Profile
|
||||||
|
@ -296,9 +337,9 @@ public class DBResource {
|
||||||
private String schema = null;
|
private String schema = null;
|
||||||
private String tableSpaceCount = null;
|
private String tableSpaceCount = null;
|
||||||
private String tableSpacePrefix = null;
|
private String tableSpacePrefix = null;
|
||||||
|
|
||||||
/* it contains the variables aquamapsWorldTable,aquamapsDataStore */
|
/* 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
|
@XmlElementRef
|
||||||
private Interface itfce = new Interface();
|
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();
|
String pwd = this.accessData.password();
|
||||||
|
|
||||||
|
@ -351,9 +392,9 @@ public class DBResource {
|
||||||
password = StringEncrypter.getEncrypter().decrypt(pwd);
|
password = StringEncrypter.getEncrypter().decrypt(pwd);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
||||||
// e.printStackTrace();
|
// e.printStackTrace();
|
||||||
throw e;
|
throw e;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return password;
|
return password;
|
||||||
|
@ -418,7 +459,7 @@ public class DBResource {
|
||||||
|
|
||||||
public void setDatabaseName(String value) {
|
public void setDatabaseName(String value) {
|
||||||
|
|
||||||
DatabaseName=value;
|
DatabaseName = value;
|
||||||
|
|
||||||
for (int i = 0; i < properties.size(); i++) {
|
for (int i = 0; i < properties.size(); i++) {
|
||||||
|
|
||||||
|
@ -429,9 +470,10 @@ public class DBResource {
|
||||||
|| ((properties.get(i).name()).toLowerCase()
|
|| ((properties.get(i).name()).toLowerCase()
|
||||||
.contains("database"))) {
|
.contains("database"))) {
|
||||||
DatabaseName = properties.get(i).setvalue(value);
|
DatabaseName = properties.get(i).setvalue(value);
|
||||||
|
|
||||||
AnalysisLogger.getLogger().debug(
|
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")) {
|
if ((properties.get(i).name()).toLowerCase().contains("driver")) {
|
||||||
Driver = properties.get(i).setvalue(value);
|
Driver = properties.get(i).setvalue(value);
|
||||||
|
|
||||||
AnalysisLogger.getLogger().debug(
|
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() {
|
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) {
|
if (properties.size() == 0) {
|
||||||
|
|
||||||
return MaxConnections = "2";
|
return MaxConnections = "2";
|
||||||
|
@ -590,7 +636,10 @@ public class DBResource {
|
||||||
|
|
||||||
public String getSchema() {
|
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)
|
if (properties.size() == 0)
|
||||||
return schema = "public";
|
return schema = "public";
|
||||||
|
|
||||||
|
@ -617,7 +666,10 @@ public class DBResource {
|
||||||
|
|
||||||
public String getTableSpaceCount() {
|
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)
|
if (properties.size() == 0)
|
||||||
return tableSpaceCount = "0";
|
return tableSpaceCount = "0";
|
||||||
|
|
||||||
|
@ -643,7 +695,10 @@ public class DBResource {
|
||||||
|
|
||||||
public String getTableSpacePrefix() {
|
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)
|
if (properties.size() == 0)
|
||||||
return tableSpacePrefix = "";
|
return tableSpacePrefix = "";
|
||||||
|
|
||||||
|
@ -671,7 +726,10 @@ public class DBResource {
|
||||||
|
|
||||||
String AuxiliaryProperty;
|
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)
|
if (properties.size() == 0)
|
||||||
return auxiliaryProperties;
|
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
|
// Class Interface
|
||||||
|
|
|
@ -11,7 +11,7 @@ public class Decider {
|
||||||
|
|
||||||
// Method that implements the tree decision to parse and build the field
|
// Method that implements the tree decision to parse and build the field
|
||||||
// Url.
|
// Url.
|
||||||
public static void decide(DBResource obj, int index) {
|
public static void decide(DBResource obj, int index) throws Exception{
|
||||||
|
|
||||||
AnalysisLogger.getLogger().debug(
|
AnalysisLogger.getLogger().debug(
|
||||||
"In class Decider->starting the parsing process");
|
"In class Decider->starting the parsing process");
|
||||||
|
|
|
@ -16,7 +16,7 @@ public class Guesser {
|
||||||
// information as platform, driver and dialect and set these parameters to
|
// information as platform, driver and dialect and set these parameters to
|
||||||
// the correct values if they are not specified according to a well-formed
|
// the correct values if they are not specified according to a well-formed
|
||||||
// mode.
|
// mode.
|
||||||
public String guessDB(DBResource obj, int index) {
|
public String guessDB(DBResource obj, int index) throws Exception{
|
||||||
|
|
||||||
AnalysisLogger.getLogger().debug(
|
AnalysisLogger.getLogger().debug(
|
||||||
"In class Guesser->starting the guess process");
|
"In class Guesser->starting the guess process");
|
||||||
|
|
|
@ -14,7 +14,7 @@ import org.gcube.dataaccess.databases.resources.processing.Normalizer;
|
||||||
public class Normalizer {
|
public class Normalizer {
|
||||||
|
|
||||||
/* It performs the normalization process considering as input an access point field of a DBResource resource */
|
/* 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(
|
AnalysisLogger.getLogger().debug(
|
||||||
"In class Normalizer->starting to guess the database's type");
|
"In class Normalizer->starting to guess the database's type");
|
||||||
|
|
Loading…
Reference in New Issue