From fbee546eaca73a935cfe97edbafdd2278671b006 Mon Sep 17 00:00:00 2001 From: gita cliff Date: Thu, 14 Nov 2019 07:45:45 +0300 Subject: [PATCH] REPORT-840:GET call for the ReportRequest resource with given ReportDefinitionUUID is failing --- .../web/resource/ReportRequestResource.java | 18 +++++++++- .../resource/ReportRequestResourceTest.java | 33 ++++++++++++++++--- 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/omod/src/main/java/org/openmrs/module/reportingrest/web/resource/ReportRequestResource.java b/omod/src/main/java/org/openmrs/module/reportingrest/web/resource/ReportRequestResource.java index a447d3c..3fe2dbe 100644 --- a/omod/src/main/java/org/openmrs/module/reportingrest/web/resource/ReportRequestResource.java +++ b/omod/src/main/java/org/openmrs/module/reportingrest/web/resource/ReportRequestResource.java @@ -23,6 +23,7 @@ import org.openmrs.module.reporting.report.definition.ReportDefinition; import org.openmrs.module.reporting.report.service.ReportService; import org.openmrs.module.reportingrest.web.controller.ReportingRestController; +import org.openmrs.module.webservices.rest.SimpleObject; import org.openmrs.module.webservices.rest.web.ConversionUtil; import org.openmrs.module.webservices.rest.web.RequestContext; import org.openmrs.module.webservices.rest.web.RestConstants; @@ -34,9 +35,10 @@ import org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource; import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource; import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceDescription; +import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceHandler; import org.openmrs.module.webservices.rest.web.resource.impl.NeedsPaging; -import org.openmrs.module.webservices.rest.web.response.ResponseException; import org.openmrs.module.webservices.rest.web.response.ConversionException; +import org.openmrs.module.webservices.rest.web.response.ResponseException; /** * {@link Resource} for {@link ReportRequest}s, supporting standard CRUD operations @@ -194,4 +196,18 @@ public void setProperty(Object instance, String propertyName, Object value) thro private ReportService getService() { return Context.getService(ReportService.class); } + + @Override + public SimpleObject asRepresentation(ReportRequest delegate, Representation representation) throws ConversionException { + DelegatingResourceHandler handler = (DelegatingResourceHandler) getResourceHandler( + delegate); + DelegatingResourceDescription repDescription = handler.getRepresentationDescription(representation); + if (repDescription != null) { + SimpleObject simple = convertDelegateToRepresentation(delegate, repDescription); + + return simple; + } + + return (SimpleObject) ConversionUtil.convertToRepresentation(delegate, Representation.DEFAULT); + } } diff --git a/omod/src/test/java/org/openmrs/module/reportingrest/web/resource/ReportRequestResourceTest.java b/omod/src/test/java/org/openmrs/module/reportingrest/web/resource/ReportRequestResourceTest.java index 99e12fd..0e2c9ba 100644 --- a/omod/src/test/java/org/openmrs/module/reportingrest/web/resource/ReportRequestResourceTest.java +++ b/omod/src/test/java/org/openmrs/module/reportingrest/web/resource/ReportRequestResourceTest.java @@ -1,14 +1,13 @@ package org.openmrs.module.reportingrest.web.resource; import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertThat; - -import java.util.Date; -import java.util.List; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertThat; +import java.util.Date; +import java.util.List; import org.junit.Before; import org.junit.Test; @@ -108,7 +107,8 @@ public void testCreateScheduledReport() throws Exception { assertNotNull(response.get("uuid")); assertEquals(response.get("status"), ReportRequest.Status.SCHEDULED); assertEquals(response.get("schedule"), "0 42 15 8 2 ? 2018"); - SimpleObject resultObject = (SimpleObject) response.get("renderingMode"); + response.get("renderingMode"); + } @Test @@ -245,4 +245,27 @@ public void testCreatePassesWithMissingParameterMappingsWhereReportDefinitionHav assertNull(request.getBaseCohort()); } + @Test + public void testGetPassesWithReportDifinitionUuidCOnfigured() throws Exception { + String reportDefinitionJson = "{" + "\"parameterizable\":{" + " \"uuid\":\"" + REPORT_DEFINITION_UUID + "\"" + "}" + + "}"; + + String reportRequestJson = "{\n" + " \"status\": \"REQUESTED\",\n" + " \"priority\": \"NORMAL\",\n" + + " \"reportDefinition\":" + reportDefinitionJson + "," + + " \"renderingMode\": \"org.openmrs.module.reporting.report.renderer.CsvReportRenderer\"\n" + "}"; + + SimpleObject properties = SimpleObject.parseJson(reportRequestJson); + RequestContext context = new RequestContext(); + context.setRepresentation(Representation.DEFAULT); + SimpleObject response = (SimpleObject) getResource().create(properties, context); + assertNotNull(response.get("uuid")); + assertEquals(response.get("status"), ReportRequest.Status.REQUESTED); + assertEquals(response.get("priority"), ReportRequest.Priority.NORMAL); + SimpleObject resultObject = (SimpleObject) response.get("renderingMode"); + String rendererType = (String) resultObject.get("rendererType"); + assertEquals(rendererType, "org.openmrs.module.reporting.report.renderer.CsvReportRenderer"); + + ReportRequest request = getResource().getByUniqueId((String) response.get("uuid")); + assertThat(request.getReportDefinition().getParameterizable().getUuid(), is(REPORT_DEFINITION_UUID)); + } } \ No newline at end of file