The CKanClient is created just once

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/ckan-util-library@129164 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-06-18 15:12:15 +00:00
parent 846b30b24f
commit 1425113df5
1 changed files with 7 additions and 15 deletions

View File

@ -58,6 +58,9 @@ public class CKanUtilsImpl implements CKanUtilsInterface{
// use connections pool (multiple threads can use this CKanUtilsImpl instance)
private BasicDataSource ds;
// ckan client
private CkanClient client;
/**
* The ckan catalogue url and database will be discovered in this scope
@ -86,6 +89,9 @@ public class CKanUtilsImpl implements CKanUtilsInterface{
ds.setUsername(CKAN_DB_USER);
ds.setPassword(CKAN_DB_PASSWORD);
ds.setUrl(url);
// build the client
client = new CkanClient(CKAN_CATALOGUE_URL);
}
@ -174,9 +180,6 @@ public class CKanUtilsImpl implements CKanUtilsInterface{
// list to return
List<CkanOrganization> toReturn = new ArrayList<CkanOrganization>();
// get the CkanClient to retrieve the organization from the id
CkanClient client = new CkanClient(CKAN_CATALOGUE_URL);
try{
List<String> organizationIds = getOrganizationsIds();
@ -221,9 +224,6 @@ public class CKanUtilsImpl implements CKanUtilsInterface{
// get the id of all the organizations
List<String> organizationIds = getOrganizationsIds();
// we need to get orgs names from the id
CkanClient client = new CkanClient(CKAN_CATALOGUE_URL);
for (String orgId : organizationIds) {
// go to the member table, that says which role has this user into the org
@ -275,7 +275,6 @@ public class CKanUtilsImpl implements CKanUtilsInterface{
String userId = null;
try{
CkanClient client = new CkanClient(CKAN_CATALOGUE_URL);
userId = client.getUser(ckanUsername).getId();
logger.debug("User id retrieved for " + ckanUsername + " "+ userId);
}catch(Exception e){
@ -289,7 +288,6 @@ public class CKanUtilsImpl implements CKanUtilsInterface{
public List<String> getOrganizationsIds(){
List<String> toReturn = new ArrayList<String>();
CkanClient client = new CkanClient(CKAN_CATALOGUE_URL);
List<CkanOrganization> orgs = client.getOrganizationList();
for (CkanOrganization ckanOrganization : orgs) {
@ -304,7 +302,6 @@ public class CKanUtilsImpl implements CKanUtilsInterface{
public List<String> getOrganizationsNames(){
List<String> toReturn = new ArrayList<String>();
CkanClient client = new CkanClient(CKAN_CATALOGUE_URL);
List<CkanOrganization> orgs = client.getOrganizationList();
for (CkanOrganization ckanOrganization : orgs) {
@ -344,8 +341,6 @@ public class CKanUtilsImpl implements CKanUtilsInterface{
public String findLicenseIdByLicense(String chosenLicense) {
logger.debug("Requested license id");
CkanClient client = new CkanClient(CKAN_CATALOGUE_URL);
//retrieve the list of available licenses
List<CkanLicense> licenses = client.getLicenseList();
@ -364,9 +359,7 @@ public class CKanUtilsImpl implements CKanUtilsInterface{
// get the url and the api key of the user
List<String> result = new ArrayList<String>();
CkanClient client = new CkanClient(CKAN_CATALOGUE_URL);
//retrieve the list of available licenses
List<CkanLicense> licenses = client.getLicenseList();
@ -728,7 +721,6 @@ public class CKanUtilsImpl implements CKanUtilsInterface{
String userId = getUserIdByUsername(ckanUsername);
// get the CkanClient to retrieve the organization id from the name
CkanClient client = new CkanClient(CKAN_CATALOGUE_URL);
String orgId = client.getOrganization(organizationName).getId();
String query =