Skip to content

Commit

Permalink
Merge pull request openmrs#19 from alexei-grigoriev/REPORT-732
Browse files Browse the repository at this point in the history
REPORT-732 Throw ObjectNotFoundException if resource definition does …
  • Loading branch information
dkayiwa committed Jul 9, 2015
2 parents 11ce662 + 6bab3dc commit 6f89eef
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.openmrs.module.webservices.rest.web.representation.DefaultRepresentation;
import org.openmrs.module.webservices.rest.web.representation.Representation;
import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceDescription;
import org.openmrs.module.webservices.rest.web.response.ObjectNotFoundException;
import org.openmrs.module.webservices.rest.web.response.ResponseException;
import org.springframework.util.StringUtils;

Expand Down Expand Up @@ -53,14 +54,20 @@ public List<DataSet> getDataSets(ReportData delegate) {
return new ArrayList<DataSet>(delegate.getDataSets().values());
}

@Override
/**
* @should throw ObjectNotFoundException if resource does not exist
*/
@Override
public Object retrieve(String uuid, RequestContext requestContext)
throws ResponseException {

ReportDefinitionService reportDefinitionService = DefinitionContext.getReportDefinitionService();

// the passed in uuid is the DataSetDefinition uuid
ReportDefinition definition = reportDefinitionService.getDefinitionByUuid(uuid);
if (definition == null) {
throw new ObjectNotFoundException();
}

EvaluationContext evalContext = getEvaluationContextWithParameters(definition, requestContext);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import org.openmrs.module.reporting.report.definition.ReportDefinition;
import org.openmrs.module.reporting.report.definition.service.ReportDefinitionService;
import org.openmrs.module.webservices.rest.SimpleObject;
import org.openmrs.module.webservices.rest.web.response.ObjectNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.ExpectedException;

import java.util.Date;

Expand Down Expand Up @@ -56,4 +58,12 @@ public void testEvaluating() throws Exception {
System.out.println(toJson(response));
}

/**
* @verifies throw ObjectNotFoundException if resource does not exist
*/
@Test
@ExpectedException(value = ObjectNotFoundException.class)
public void retrieve_shouldThrowObjectNotFoundExceptionIfResourceDoesNotExist() throws Exception {
getResource().retrieve("not-existing", buildRequestContext("startDate", "1975-01-01", "endDate", "1976-12-31"));
}
}

0 comments on commit 6f89eef

Please sign in to comment.