Added method to get only the number of total items

This commit is contained in:
Luca Frosini 2021-02-03 16:27:27 +01:00
parent 85a5436b59
commit 9bbcac2378
2 changed files with 23 additions and 5 deletions

View File

@ -59,12 +59,11 @@
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId> <artifactId>slf4j-api</artifactId>
</dependency> </dependency>
<!-- Test Dependencies -->
<dependency> <dependency>
<groupId>org.gcube.common</groupId> <groupId>org.gcube.common</groupId>
<artifactId>gcube-jackson-databind</artifactId> <artifactId>gcube-jackson-databind</artifactId>
<scope>test</scope>
</dependency> </dependency>
<!-- Test Dependencies -->
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>

View File

@ -8,6 +8,8 @@ import java.util.Map;
import javax.ws.rs.WebApplicationException; import javax.ws.rs.WebApplicationException;
import javax.xml.ws.WebServiceException; import javax.xml.ws.WebServiceException;
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
import org.gcube.gcat.api.GCatConstants; import org.gcube.gcat.api.GCatConstants;
/** /**
@ -23,11 +25,27 @@ public class Item extends GCatClient implements org.gcube.gcat.api.interfaces.It
super(enforcedServiceURL, ITEMS); super(enforcedServiceURL, ITEMS);
} }
@Override
public int count() throws WebServiceException {
Map<String, String> queryParams = new HashMap<>();
queryParams.put(GCatConstants.COUNT_ONLY_PARAMETER, String.valueOf(true));
String ret = this.list(queryParams);
ObjectMapper objectMapper = new ObjectMapper();
try {
JsonNode jsonNode = objectMapper.readTree(ret);
return jsonNode.get(Item.COUNT_KEY).asInt();
}catch (WebApplicationException e) {
throw e;
}catch (Exception e) {
throw new WebApplicationException(e);
}
}
/** /**
* List the item in the organization correspondent to the current VRE. * List the item in the organisation correspondent to the current VRE.
* *
* If the client is entitled to run at VO or ROOT level the method return all the item in all the organization * If the client is entitled to run at VO or ROOT level the method return all the item in all the organization
* in the catalogue. To filter per organization used the method {@link #list(int, int, String)} * in the catalogue. To filter per organisation used the method {@link #list(int, int, String)}
*/ */
@Override @Override
public String list(int limit, int offset) throws WebApplicationException { public String list(int limit, int offset) throws WebApplicationException {
@ -43,7 +61,7 @@ public class Item extends GCatClient implements org.gcube.gcat.api.interfaces.It
} }
/** /**
* List the item of a specific organization. * List the item of a specific organisation.
* This API is only available if the client is entitles to run at VO and ROOT level. * This API is only available if the client is entitles to run at VO and ROOT level.
*/ */
public String list(int limit, int offset, String organizationName) throws WebApplicationException { public String list(int limit, int offset, String organizationName) throws WebApplicationException {
@ -103,4 +121,5 @@ public class Item extends GCatClient implements org.gcube.gcat.api.interfaces.It
super.delete(true, name); super.delete(true, name);
return null; return null;
} }
} }