minor fixes
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/ckan-util-library@140055 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
4239ed4c3b
commit
9a07dc0c59
|
@ -2388,52 +2388,56 @@ public class DataCatalogueImpl implements DataCatalogue{
|
|||
checkArgument(rows >= 0);
|
||||
|
||||
Connection connection = getConnection();
|
||||
try{
|
||||
|
||||
if(isOrganization){
|
||||
ResultSet rs;
|
||||
if(isOrganization){
|
||||
|
||||
String joinQuery = "SELECT \"package\".\"id\" FROM \"package\" INNER JOIN \"group\" ON"
|
||||
+ " \"package\".\"owner_org\"=\"group\".\"id\" WHERE \"group\".\"name\"=? "
|
||||
+ "AND \"group\".\"is_organization\"=? AND \"package\".\"type\"=? AND \"package\".\"state\"=? LIMIT ? OFFSET ?; ";
|
||||
String joinQuery = "SELECT \"package\".\"id\" AS \"dataset_id\" FROM \"package\" INNER JOIN \"group\" ON"
|
||||
+ " \"package\".\"owner_org\"=\"group\".\"id\" WHERE \"group\".\"name\"=? "
|
||||
+ "AND \"group\".\"is_organization\"=? AND \"package\".\"type\"=? AND \"package\".\"state\"=? LIMIT ? OFFSET ?; ";
|
||||
|
||||
PreparedStatement preparedStatement = connection.prepareStatement(joinQuery);
|
||||
preparedStatement.setString(1, orgOrGroupName);
|
||||
preparedStatement.setBoolean(2, isOrganization);
|
||||
preparedStatement.setString(3, "dataset");
|
||||
preparedStatement.setString(4, "active");
|
||||
preparedStatement.setBigDecimal(5, new BigDecimal(rows));
|
||||
preparedStatement.setBigDecimal(6, new BigDecimal(start));
|
||||
PreparedStatement preparedStatement = connection.prepareStatement(joinQuery);
|
||||
preparedStatement.setString(1, orgOrGroupName);
|
||||
preparedStatement.setBoolean(2, isOrganization);
|
||||
preparedStatement.setString(3, "dataset");
|
||||
preparedStatement.setString(4, "active");
|
||||
preparedStatement.setBigDecimal(5, new BigDecimal(rows));
|
||||
preparedStatement.setBigDecimal(6, new BigDecimal(start));
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
rs = preparedStatement.executeQuery();
|
||||
|
||||
}else{
|
||||
|
||||
/**
|
||||
* Inner join between the member table and the package table.
|
||||
* Basically every time a dataset is added to a group, a new row is added to the table
|
||||
* where table_id is the package_id, and group_id is the owner group identifier (not the name)
|
||||
*/
|
||||
String groupId = client.getGroup(orgOrGroupName).getId();
|
||||
String joinQuery = "SELECT \"table_id\" AS \"dataset_id\" FROM \"package\" INNER JOIN \"member\" ON"
|
||||
+ " \"member\".\"table_id\"=\"package\".\"id\" WHERE \"group_id\"=? "
|
||||
+ "AND \"member\".\"state\"=? LIMIT ? OFFSET ?;";
|
||||
|
||||
PreparedStatement preparedStatement = connection.prepareStatement(joinQuery);
|
||||
preparedStatement.setString(1, groupId);
|
||||
preparedStatement.setString(2, "active");
|
||||
preparedStatement.setBigDecimal(3, new BigDecimal(rows));
|
||||
preparedStatement.setBigDecimal(4, new BigDecimal(start));
|
||||
|
||||
rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
toReturn.add(rs.getString("id"));
|
||||
}
|
||||
|
||||
}else{
|
||||
|
||||
/**
|
||||
* Inner join between the member table and the package table.
|
||||
* Basically every time a dataset is added to a group, a new row is added to the table
|
||||
* where table_id is the package_id, and group_id is the owner group identifier (not the name)
|
||||
*/
|
||||
|
||||
String groupId = client.getGroup(orgOrGroupName).getId();
|
||||
String joinQuery = "SELECT \"table_id\" FROM \"package\" INNER JOIN \"member\" ON"
|
||||
+ " \"member\".\"table_id\"=\"package\".\"id\" WHERE \"group_id\"=? "
|
||||
+ "AND \"member\".\"state\"=? LIMIT ? OFFSET ?;";
|
||||
|
||||
PreparedStatement preparedStatement = connection.prepareStatement(joinQuery);
|
||||
preparedStatement.setString(1, groupId);
|
||||
preparedStatement.setString(2, "active");
|
||||
preparedStatement.setBigDecimal(3, new BigDecimal(rows));
|
||||
preparedStatement.setBigDecimal(4, new BigDecimal(start));
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
toReturn.add(rs.getString("table_id"));
|
||||
toReturn.add(rs.getString("dataset_id"));
|
||||
}
|
||||
|
||||
}catch(Exception e){
|
||||
logger.error("Failed to retrieve the ids of products in group/org. Error is " + e.getMessage());
|
||||
return null;
|
||||
}finally{
|
||||
closeConnection(connection);
|
||||
}
|
||||
return toReturn;
|
||||
|
||||
|
|
|
@ -37,12 +37,19 @@ public class TestDataCatalogueLib {
|
|||
String subjectId = "aa_father4";
|
||||
String objectId = "bb_son4";
|
||||
|
||||
// @Before
|
||||
//@Before
|
||||
public void before() throws Exception{
|
||||
factory = DataCatalogueFactory.getFactory();
|
||||
|
||||
}
|
||||
|
||||
|
||||
//@Test
|
||||
public void getDatasetIdsFromDB() throws Exception{
|
||||
DataCatalogueImpl utils = factory.getUtilsPerScope(scope);
|
||||
List<String> ids = utils.getProductsIdsInGroupOrOrg("aquamaps", true, 0, Integer.MAX_VALUE);
|
||||
logger.debug("Size is " + ids.size());
|
||||
}
|
||||
|
||||
// @Test
|
||||
public void testManageProduct() throws Exception{
|
||||
|
||||
|
|
Loading…
Reference in New Issue