Add query parameter `requestDate` to retrieve only one catalog xml
Ref killbill/killbill-admin-ui#141
@@ -118,9 +118,28 @@ public class CatalogResource extends JaxRsResourceBase {
@Produces(APPLICATION_XML)
@ApiOperation(value = "Retrieve the full catalog as XML", response = String.class, hidden = true)
@ApiResponses(value = {})
- public Response getCatalogXml(@javax.ws.rs.core.Context final HttpServletRequest request) throws Exception {
+ public Response getCatalogXml(@QueryParam(QUERY_REQUESTED_DT) final String requestedDate,
+ @javax.ws.rs.core.Context final HttpServletRequest request) throws Exception {
final TenantContext tenantContext = context.createTenantContextNoAccountId(request);
- return Response.status(Status.OK).entity(XMLWriter.writeXML((VersionedCatalog) catalogUserApi.getCatalog(catalogName, tenantContext), VersionedCatalog.class)).build();
+ final DateTime catalogDateVersion = requestedDate != null ?
+ DATE_TIME_FORMATTER.parseDateTime(requestedDate).toDateTime(DateTimeZone.UTC) :
+ null;
+
+ final VersionedCatalog catalog = (VersionedCatalog) catalogUserApi.getCatalog(catalogName, tenantContext);
+
+ String result = null;
+ if (catalogDateVersion != null) {
+ for (final StandaloneCatalog v : catalog.getVersions()) {
+ if (v.getEffectiveDate().compareTo(catalogDateVersion.toDate()) == 0) {
+ result = XMLWriter.writeXML(v, StandaloneCatalog.class);
+ break;
+ }
+ }
+ } else {
+ result = XMLWriter.writeXML(catalog, VersionedCatalog.class);
+ }
+
+ return Response.status(Status.OK).entity(result).build();
}
@TimedResource
