|
| 1 | +package org.labkey.trialshare; |
| 2 | + |
| 3 | +import org.labkey.api.data.Container; |
| 4 | +import org.labkey.api.security.User; |
| 5 | +import org.labkey.api.settings.AdminConsole; |
| 6 | +import org.labkey.api.settings.ExperimentalFeatureService; |
| 7 | +import org.labkey.api.study.SpecimenService; |
| 8 | +import org.labkey.api.util.HtmlString; |
| 9 | + |
| 10 | +/** Decides whether to supply the default behavior or an ITN-specific one based on an experimental feature flag */ |
| 11 | +public class DelegatingSpecimenRequestCustomizer implements SpecimenService.SpecimenRequestCustomizer |
| 12 | +{ |
| 13 | + private final SpecimenService.SpecimenRequestCustomizer _default; |
| 14 | + private final SpecimenService.SpecimenRequestCustomizer _itn = new ITNSpecimenRequestCustomizer(); |
| 15 | + private SpecimenService.SpecimenRequestCustomizer _active; |
| 16 | + |
| 17 | + private static final String ITN_SPECIMEN_HANDLING_FEATURE_NAME = "ITNSpecimenHandling"; |
| 18 | + |
| 19 | + public DelegatingSpecimenRequestCustomizer(SpecimenService.SpecimenRequestCustomizer defaultCustomizer) |
| 20 | + { |
| 21 | + _default = defaultCustomizer; |
| 22 | + |
| 23 | + _active = ExperimentalFeatureService.get().isFeatureEnabled(ITN_SPECIMEN_HANDLING_FEATURE_NAME) ? _itn : _default; |
| 24 | + |
| 25 | + AdminConsole.addExperimentalFeatureFlag(ITN_SPECIMEN_HANDLING_FEATURE_NAME, "ITN specimen behavior", |
| 26 | + "This feature allows empty specimen requests, adds ITN-specific messages, hides some reporting options, and other tweaks", false); |
| 27 | + |
| 28 | + ExperimentalFeatureService.get().addFeatureListener(ITN_SPECIMEN_HANDLING_FEATURE_NAME, (feature, enabled) -> _active = enabled ? _itn : _default); |
| 29 | + } |
| 30 | + |
| 31 | + @Override |
| 32 | + public boolean allowEmptyRequests() |
| 33 | + { |
| 34 | + return _active.allowEmptyRequests(); |
| 35 | + } |
| 36 | + |
| 37 | + @Override |
| 38 | + public Integer getDefaultDestinationSiteId() |
| 39 | + { |
| 40 | + return _active.getDefaultDestinationSiteId(); |
| 41 | + } |
| 42 | + |
| 43 | + @Override |
| 44 | + public boolean omitTypeGroupingsWhenReporting() |
| 45 | + { |
| 46 | + return _active.omitTypeGroupingsWhenReporting(); |
| 47 | + } |
| 48 | + |
| 49 | + @Override |
| 50 | + public boolean canChangeStatus(User user) |
| 51 | + { |
| 52 | + return _active.canChangeStatus(user); |
| 53 | + } |
| 54 | + |
| 55 | + @Override |
| 56 | + public boolean hideRequestWarnings() |
| 57 | + { |
| 58 | + return _active.hideRequestWarnings(); |
| 59 | + } |
| 60 | + |
| 61 | + @Override |
| 62 | + public HtmlString getSubmittedMessage(Container c, int requestId) |
| 63 | + { |
| 64 | + return _active.getSubmittedMessage(c, requestId); |
| 65 | + } |
| 66 | +} |
0 commit comments