summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
Diffstat (limited to 'base')
-rw-r--r--base/common/src/com/netscape/cms/client/cert/CertFindCLI.java17
-rw-r--r--base/common/src/com/netscape/cms/client/cert/CertRestClient.java4
-rw-r--r--base/common/src/com/netscape/cms/servlet/cert/CertResource.java16
-rw-r--r--base/common/src/com/netscape/cms/servlet/cert/CertResourceService.java43
-rw-r--r--base/common/src/com/netscape/cms/servlet/cert/model/CertDataInfos.java34
5 files changed, 71 insertions, 43 deletions
diff --git a/base/common/src/com/netscape/cms/client/cert/CertFindCLI.java b/base/common/src/com/netscape/cms/client/cert/CertFindCLI.java
index 4890a6682..ea88c46cd 100644
--- a/base/common/src/com/netscape/cms/client/cert/CertFindCLI.java
+++ b/base/common/src/com/netscape/cms/client/cert/CertFindCLI.java
@@ -103,10 +103,16 @@ public class CertFindCLI extends CLI {
searchData = new CertSearchData();
searchData.setSerialNumberRangeInUse(true);
}
+ String s = cmd.getOptionValue("start");
+ Integer start = s == null ? null : Integer.valueOf(s);
+
+ s = cmd.getOptionValue("size");
+ Integer size = s == null ? null : Integer.valueOf(s);
+
addSearchAttribute(cmd, searchData);
CertDataInfos certs = null;
try {
- certs = parent.client.findCerts(searchData);
+ certs = parent.client.findCerts(searchData, start, size);
} catch (CMSException e) {
System.err.println("Error: Cannot list certificates. " + e.getMessage());
System.exit(-1);
@@ -136,6 +142,15 @@ public class CertFindCLI extends CLI {
Option option = null;
+ //pagination options
+ option = new Option(null, "start", true, "Page start");
+ option.setArgName("start");
+ options.addOption(option);
+
+ option = new Option(null, "size", true, "Page size");
+ option.setArgName("size");
+ options.addOption(option);
+
//help
options.addOption(null, "help", false, "Show help options");
diff --git a/base/common/src/com/netscape/cms/client/cert/CertRestClient.java b/base/common/src/com/netscape/cms/client/cert/CertRestClient.java
index 3559047b7..7c8b9f3e4 100644
--- a/base/common/src/com/netscape/cms/client/cert/CertRestClient.java
+++ b/base/common/src/com/netscape/cms/client/cert/CertRestClient.java
@@ -54,8 +54,8 @@ public class CertRestClient extends CMSRestClient {
return certClient.getCert(id);
}
- public CertDataInfos findCerts(CertSearchData data) {
- return certClient.searchCerts(data, CertResource.DEFAULT_MAXRESULTS, CertResource.DEFAULT_MAXTIME);
+ public CertDataInfos findCerts(CertSearchData data, Integer start, Integer size) {
+ return certClient.searchCerts(data, start, size);
}
public CertRequestInfo revokeCert(CertId id, CertRevokeRequest request) {
diff --git a/base/common/src/com/netscape/cms/servlet/cert/CertResource.java b/base/common/src/com/netscape/cms/servlet/cert/CertResource.java
index 48650f05f..f3a9d4129 100644
--- a/base/common/src/com/netscape/cms/servlet/cert/CertResource.java
+++ b/base/common/src/com/netscape/cms/servlet/cert/CertResource.java
@@ -21,25 +21,25 @@ import com.netscape.cms.servlet.request.model.CertRequestInfo;
@Path("")
public interface CertResource {
- public static final int DEFAULT_MAXTIME = 10;
- public static final int DEFAULT_MAXRESULTS = 100;
+ public static final int DEFAULT_MAXTIME = 0;
+ public static final int DEFAULT_MAXRESULTS = 20;
@GET
@Path("certs")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public CertDataInfos listCerts(
- @QueryParam("status") String status,
- @DefaultValue(""+DEFAULT_MAXRESULTS) @QueryParam("maxResults") int maxResults,
- @DefaultValue(""+DEFAULT_MAXTIME) @QueryParam("maxTime") int maxTime);
+ @QueryParam("status") String status,
+ @DefaultValue("" + DEFAULT_MAXRESULTS) @QueryParam("maxResults") int maxResults,
+ @DefaultValue("" + DEFAULT_MAXTIME) @QueryParam("maxTime") int maxTime);
@POST
@Path("certs/search")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public CertDataInfos searchCerts(
- CertSearchData data,
- @DefaultValue(""+DEFAULT_MAXRESULTS) @QueryParam("maxResults") int maxResults,
- @DefaultValue(""+DEFAULT_MAXTIME) @QueryParam("maxTime") int maxTime);
+ CertSearchData data,
+ @QueryParam("start") Integer start,
+ @QueryParam("size") Integer size);
@GET
@Path("certs/{id}")
diff --git a/base/common/src/com/netscape/cms/servlet/cert/CertResourceService.java b/base/common/src/com/netscape/cms/servlet/cert/CertResourceService.java
index 395907b53..6a3f0d79a 100644
--- a/base/common/src/com/netscape/cms/servlet/cert/CertResourceService.java
+++ b/base/common/src/com/netscape/cms/servlet/cert/CertResourceService.java
@@ -79,6 +79,7 @@ public class CertResourceService extends CMSResourceService implements CertResou
ICertificateAuthority authority;
ICertificateRepository repo;
+ public final static int DEFAULT_SIZE = 20;
public CertResourceService() {
authority = (ICertificateAuthority) CMS.getSubsystem("ca");
@@ -330,18 +331,48 @@ public class CertResourceService extends CMSResourceService implements CertResou
}
@Override
- public CertDataInfos searchCerts(CertSearchData data, int maxResults, int maxTime) {
+ public CertDataInfos searchCerts(CertSearchData data, Integer start, Integer size) {
if (data == null) {
throw new WebApplicationException(Response.Status.BAD_REQUEST);
}
+ start = start == null ? 0 : start;
+ size = size == null ? DEFAULT_SIZE : size;
String filter = createSearchFilter(data);
- CertDataInfos infos;
+ CertDataInfos infos = new CertDataInfos();
+
+ Enumeration<ICertRecord> e = null;
try {
- infos = getCertList(filter, maxResults, maxTime);
- } catch (EBaseException e) {
- e.printStackTrace();
- throw new CMSException("Error listing certs in CertsResourceService.listCerts!");
+
+ e = repo.findCertRecords(filter);
+
+ int i = 0;
+
+ // skip to the start of the page
+ for (; i < start && e.hasMoreElements(); i++)
+ e.nextElement();
+
+ // return entries up to the page size
+ for (; i < start + size && e.hasMoreElements(); i++) {
+ ICertRecord user = e.nextElement();
+ infos.addCertData(createCertDataInfo(user));
+ }
+
+ // count the total entries
+ for (; e.hasMoreElements(); i++)
+ e.nextElement();
+
+ if (start > 0) {
+ URI uri = uriInfo.getRequestUriBuilder().replaceQueryParam("start", Math.max(start - size, 0)).build();
+ infos.addLink(new Link("prev", uri));
+ }
+
+ if (start + size < i) {
+ URI uri = uriInfo.getRequestUriBuilder().replaceQueryParam("start", start + size).build();
+ infos.addLink(new Link("next", uri));
+ }
+ } catch (EBaseException e1) {
+ throw new CMSException("Error listing certs in CertsResourceService.listCerts!" + e.toString());
}
return infos;
diff --git a/base/common/src/com/netscape/cms/servlet/cert/model/CertDataInfos.java b/base/common/src/com/netscape/cms/servlet/cert/model/CertDataInfos.java
index 2b1ad42e8..189c58cbe 100644
--- a/base/common/src/com/netscape/cms/servlet/cert/model/CertDataInfos.java
+++ b/base/common/src/com/netscape/cms/servlet/cert/model/CertDataInfos.java
@@ -17,20 +17,20 @@
//--- END COPYRIGHT BLOCK ---
package com.netscape.cms.servlet.cert.model;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.xml.bind.annotation.XmlElementRef;
import javax.xml.bind.annotation.XmlRootElement;
-import javax.xml.bind.annotation.XmlTransient;
-import com.netscape.cms.servlet.base.model.Link;
+import org.jboss.resteasy.plugins.providers.atom.Link;
@XmlRootElement(name = "CertDataInfos")
public class CertDataInfos {
- protected Collection<CertDataInfo> certInfos;
- protected List<Link> links;
+ protected Collection<CertDataInfo> certInfos = new ArrayList<CertDataInfo>();
+ protected List<Link> links = new ArrayList<Link>();
/**
* @return the CertInfos
@@ -62,29 +62,11 @@ public class CertDataInfos {
this.links = links;
}
- @XmlTransient
- public String getNext() {
- if (links == null) {
- return null;
- }
- for (Link link : links) {
- if ("next".equals(link.getRelationship())) {
- return link.getHref();
- }
- }
- return null;
+ public void addCertData(CertDataInfo certInfo){
+ this.certInfos.add(certInfo);
}
- @XmlTransient
- public String getPrevious() {
- if (links == null) {
- return null;
- }
- for (Link link : links) {
- if ("previous".equals(link.getRelationship())) {
- return link.getHref();
- }
- }
- return null;
+ public void addLink(Link link) {
+ this.links.add(link);
}
}