Added method to get only the number of total items

master
Luca Frosini 3 years ago
parent 85a5436b59
commit 9bbcac2378

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

@ -8,6 +8,8 @@ import java.util.Map;
import javax.ws.rs.WebApplicationException;
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;
/**
@ -23,11 +25,27 @@ public class Item extends GCatClient implements org.gcube.gcat.api.interfaces.It
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
* 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
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.
*/
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);
return null;
}
}

Loading…
Cancel
Save