added search methods for dataset
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/ckan-util-library@158105 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
ff3bbdd114
commit
9cc24c015a
|
@ -2,6 +2,7 @@
|
||||||
<Changeset component="org.gcube.data-catalogue.ckan-util-library.2-4-0"
|
<Changeset component="org.gcube.data-catalogue.ckan-util-library.2-4-0"
|
||||||
date="2017-11-01">
|
date="2017-11-01">
|
||||||
<Change>Added delegate roles method</Change>
|
<Change>Added delegate roles method</Change>
|
||||||
|
<Change>Added search methods for datasets</Change>
|
||||||
</Changeset>
|
</Changeset>
|
||||||
<Changeset component="org.gcube.data-catalogue.ckan-util-library.2-3-2"
|
<Changeset component="org.gcube.data-catalogue.ckan-util-library.2-3-2"
|
||||||
date="2017-08-01">
|
date="2017-08-01">
|
||||||
|
|
|
@ -602,4 +602,24 @@ public interface DataCatalogue {
|
||||||
* @param currentRole
|
* @param currentRole
|
||||||
*/
|
*/
|
||||||
void assignRolesOtherOrganization(String username, String sourceOrganization, RolesCkanGroupOrOrg currentRole);
|
void assignRolesOtherOrganization(String username, String sourceOrganization, RolesCkanGroupOrOrg currentRole);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Search for a package through Solr
|
||||||
|
* @param apiKey
|
||||||
|
* @param query
|
||||||
|
* @param start
|
||||||
|
* @param offset
|
||||||
|
* @return a list of matching datasets
|
||||||
|
*/
|
||||||
|
List<CkanDataset> searchForPackage(String apiKey, String query, int start, int offset) throws Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Search for a package through Solr in a given organization
|
||||||
|
* @param apiKey
|
||||||
|
* @param query
|
||||||
|
* @param start
|
||||||
|
* @param offset
|
||||||
|
* @return a list of matching datasets
|
||||||
|
*/
|
||||||
|
List<CkanDataset> searchForPackageInOrganization(String apiKey, String query, int start, int offset, String organization) throws Exception;
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,7 @@ import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import eu.trentorise.opendata.jackan.CheckedCkanClient;
|
import eu.trentorise.opendata.jackan.CheckedCkanClient;
|
||||||
import eu.trentorise.opendata.jackan.CkanClient;
|
import eu.trentorise.opendata.jackan.CkanClient;
|
||||||
|
import eu.trentorise.opendata.jackan.CkanQuery;
|
||||||
import eu.trentorise.opendata.jackan.exceptions.JackanException;
|
import eu.trentorise.opendata.jackan.exceptions.JackanException;
|
||||||
import eu.trentorise.opendata.jackan.internal.org.apache.http.HttpEntity;
|
import eu.trentorise.opendata.jackan.internal.org.apache.http.HttpEntity;
|
||||||
import eu.trentorise.opendata.jackan.internal.org.apache.http.HttpResponse;
|
import eu.trentorise.opendata.jackan.internal.org.apache.http.HttpResponse;
|
||||||
|
@ -2858,4 +2859,47 @@ public class DataCatalogueImpl implements DataCatalogue{
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<CkanDataset> searchForPackage(String apiKey, String query, int start, int offset) throws Exception{
|
||||||
|
|
||||||
|
checkNotNull(apiKey);
|
||||||
|
checkNotNull(query);
|
||||||
|
checkArgument(start >= 0);
|
||||||
|
checkArgument(offset >= 0);
|
||||||
|
|
||||||
|
CheckedCkanClient client = new CheckedCkanClient(CKAN_CATALOGUE_URL, apiKey);
|
||||||
|
|
||||||
|
try{
|
||||||
|
|
||||||
|
CkanQuery queryCkan = CkanQuery.filter().byText(query);
|
||||||
|
return client.searchDatasets(queryCkan, offset, start).getResults();
|
||||||
|
|
||||||
|
}catch(Exception e){
|
||||||
|
logger.error("Error while executing query", e);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<CkanDataset> searchForPackageInOrganization(String apiKey, String query, int start, int offset, String organization) throws Exception{
|
||||||
|
|
||||||
|
checkNotNull(apiKey);
|
||||||
|
checkNotNull(query);
|
||||||
|
checkArgument(start >= 0);
|
||||||
|
checkArgument(offset >= 0);
|
||||||
|
|
||||||
|
CheckedCkanClient client = new CheckedCkanClient(CKAN_CATALOGUE_URL, apiKey);
|
||||||
|
|
||||||
|
try{
|
||||||
|
|
||||||
|
CkanQuery queryCkan = CkanQuery.filter().byOrganizationName(organization).byText(query);
|
||||||
|
return client.searchDatasets(queryCkan, offset, start).getResults();
|
||||||
|
|
||||||
|
}catch(Exception e){
|
||||||
|
logger.error("Error while executing query", e);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -15,6 +15,7 @@ import org.gcube.datacatalogue.ckanutillibrary.shared.CKanUserWrapper;
|
||||||
import org.gcube.datacatalogue.ckanutillibrary.shared.CkanDatasetRelationship;
|
import org.gcube.datacatalogue.ckanutillibrary.shared.CkanDatasetRelationship;
|
||||||
import org.gcube.datacatalogue.ckanutillibrary.shared.DatasetRelationships;
|
import org.gcube.datacatalogue.ckanutillibrary.shared.DatasetRelationships;
|
||||||
import org.gcube.datacatalogue.ckanutillibrary.shared.RolesCkanGroupOrOrg;
|
import org.gcube.datacatalogue.ckanutillibrary.shared.RolesCkanGroupOrOrg;
|
||||||
|
import org.junit.Test;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import eu.trentorise.opendata.jackan.CheckedCkanClient;
|
import eu.trentorise.opendata.jackan.CheckedCkanClient;
|
||||||
|
@ -49,6 +50,22 @@ public class TestDataCatalogueLib {
|
||||||
List<String> ids = utils.getProductsIdsInGroupOrOrg("aquamaps", true, 0, Integer.MAX_VALUE);
|
List<String> ids = utils.getProductsIdsInGroupOrOrg("aquamaps", true, 0, Integer.MAX_VALUE);
|
||||||
logger.debug("Size is " + ids.size());
|
logger.debug("Size is " + ids.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//@Test
|
||||||
|
public void searchInOrganization() throws Exception{
|
||||||
|
DataCatalogueImpl utils = factory.getUtilsPerScope(scope);
|
||||||
|
String apiKey = utils.getApiKeyFromUsername(testUser);
|
||||||
|
List<CkanDataset> matches = utils.searchForPackageInOrganization(apiKey, "\"asfis:HMC+eez:AGO;FAO+grsf-org:INT+eez:AGO;RFB+iso3:AGO+isscfg:01.1.1\"", 0, 10, "grsf_admin");
|
||||||
|
logger.debug("Size is " + matches.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void search() throws Exception{
|
||||||
|
DataCatalogueImpl utils = factory.getUtilsPerScope(scope);
|
||||||
|
String apiKey = utils.getApiKeyFromUsername(testUser);
|
||||||
|
List<CkanDataset> matches = utils.searchForPackage(apiKey, "\"asfis:HMC+eez:AGO;FAO+grsf-org:INT+eez:AGO;RFB+iso3:AGO+isscfg:01.1.1\"", 0, 10);
|
||||||
|
logger.debug("Size is " + matches.size());
|
||||||
|
}
|
||||||
|
|
||||||
// @Test
|
// @Test
|
||||||
public void testManageProduct() throws Exception{
|
public void testManageProduct() throws Exception{
|
||||||
|
@ -303,28 +320,6 @@ public class TestDataCatalogueLib {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//@Test
|
|
||||||
public void createGroup() throws Exception{
|
|
||||||
|
|
||||||
// DataCatalogueImpl instance = factory.getUtilsPerScope(scope);
|
|
||||||
String title = " SoBigData.eu: Method Metadata NextNext ";
|
|
||||||
String result = UtilMethods.fromGroupTitleToName(title);
|
|
||||||
logger.debug(result);
|
|
||||||
// CkanGroup group = instance.createGroup(title, title, "A description for this group");
|
|
||||||
//
|
|
||||||
// if(group != null){
|
|
||||||
//
|
|
||||||
|
|
||||||
// boolean associated = instance.checkRoleIntoGroup("user_admin_devvre", "sobigdata_eu_method_metadata_nextnext", RolesCkanGroupOrOrg.ADMIN);
|
|
||||||
//
|
|
||||||
// if(associated){
|
|
||||||
//
|
|
||||||
// boolean assigned = instance.assignDatasetToGroup(title, "dataset_random_editor", instance.getApiKeyFromUsername("user_editor_devvre"));
|
|
||||||
// logger.debug("Assigned is " + assigned);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
//@Test
|
//@Test
|
||||||
public void testGroupAssociation() throws Exception{
|
public void testGroupAssociation() throws Exception{
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue