Skip to content

Commit 263e0ca

Browse files
committed
ATT-38: ComplexViewHelper2_0 to log a warning when unsupported view.
1 parent 8485f36 commit 263e0ca

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

api-2.0/src/main/java/org/openmrs/module/attachments/obs/ComplexViewHelper2_0.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package org.openmrs.module.attachments.obs;
22

3+
import static org.openmrs.obs.ComplexObsHandler.RAW_VIEW;
4+
5+
import org.apache.commons.logging.Log;
6+
import org.apache.commons.logging.LogFactory;
37
import org.openmrs.Obs;
48
import org.openmrs.annotation.OpenmrsProfile;
59
import org.openmrs.api.ObsService;
@@ -12,17 +16,24 @@
1216
@OpenmrsProfile(openmrsPlatformVersion = "2.0.0")
1317
public class ComplexViewHelper2_0 implements ComplexViewHelper {
1418

19+
private final Log log = LogFactory.getLog(getClass());
20+
1521
@Autowired
1622
private ObsService obsService;
1723

1824
@Override
1925
public String getView(Obs obs, String view) {
2026

21-
if (obsService.getHandler(obs).supportsView(view)) {
27+
ComplexObsHandler handler = obsService.getHandler(obs);
28+
29+
if (handler.supportsView(view)) {
2230
return view;
31+
} else {
32+
log.warn("The requested view '" + view + "' is not supported by the complex obs handler '"
33+
+ handler.getClass().getCanonicalName() + "', reverting to the default view '" + RAW_VIEW + "'.");
2334
}
2435

25-
return ComplexObsHandler.RAW_VIEW;
36+
return RAW_VIEW;
2637

2738
}
2839
}

omod-1.10/src/main/java/org/openmrs/module/attachments/rest/AttachmentBytesResource1_10.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
package org.openmrs.module.attachments.rest;
22

3+
import static org.openmrs.module.attachments.AttachmentsContext.getContentFamily;
4+
5+
import java.io.IOException;
6+
7+
import javax.servlet.http.HttpServletResponse;
8+
39
import org.apache.commons.io.FilenameUtils;
410
import org.apache.commons.logging.Log;
511
import org.apache.commons.logging.LogFactory;
@@ -8,6 +14,7 @@
814
import org.openmrs.module.attachments.AttachmentsConstants;
915
import org.openmrs.module.attachments.AttachmentsContext;
1016
import org.openmrs.module.attachments.obs.AttachmentComplexData;
17+
import org.openmrs.module.attachments.obs.ComplexViewHelper;
1118
import org.openmrs.module.attachments.obs.ValueComplex;
1219
import org.openmrs.module.webservices.rest.web.RestConstants;
1320
import org.openmrs.module.webservices.rest.web.response.GenericRestException;
@@ -21,11 +28,6 @@
2128
import org.springframework.web.bind.annotation.RequestMethod;
2229
import org.springframework.web.bind.annotation.RequestParam;
2330

24-
import javax.servlet.http.HttpServletResponse;
25-
import java.io.IOException;
26-
27-
import static org.openmrs.module.attachments.AttachmentsContext.getContentFamily;
28-
2931
@Controller
3032
@RequestMapping(value = "/rest/" + RestConstants.VERSION_1 + "/" + AttachmentsConstants.ATTACHMENT_URI)
3133
public class AttachmentBytesResource1_10 extends BaseRestController {

0 commit comments

Comments
 (0)