Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REPORT-840:GET call for the ReportRequest resource with given ReportDefinitionUUID is failing #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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<ReportRequest> handler = (DelegatingResourceHandler<ReportRequest>) getResourceHandler(
delegate);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gitcliff instead of this, shouldn't you just add a ref representation like for the rest of the webservices rest resources?

DelegatingResourceDescription repDescription = handler.getRepresentationDescription(representation);
if (repDescription != null) {
SimpleObject simple = convertDelegateToRepresentation(delegate, repDescription);

return simple;
}

return (SimpleObject) ConversionUtil.convertToRepresentation(delegate, Representation.DEFAULT);
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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));
}
}