Skip to content

Commit 4976c20

Browse files
committed
CR feedback
1 parent f7ea932 commit 4976c20

3 files changed

Lines changed: 297 additions & 120 deletions

File tree

ehr/resources/views/postgresMigration.html

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
</div>
66
</div>
77
<script type="text/javascript" nonce="<%=scriptNonce%>">
8-
function indexAction(actionName) {
8+
function indexAction(operation) {
99
LABKEY.Ajax.request({
10-
url: LABKEY.ActionURL.buildURL('ehr', actionName),
10+
url: LABKEY.ActionURL.buildURL('ehr', 'updateEHRIndices'),
1111
method: 'POST',
12+
jsonData: {
13+
operation: operation
14+
},
1215
success: function(response) {
1316
var json = JSON.parse(response.responseText);
1417
if (json.success) {
@@ -34,11 +37,11 @@
3437

3538
LABKEY.Utils.attachEventHandler('dropIndicesLink', 'click', function(e) {
3639
e.preventDefault();
37-
indexAction('dropEHRIndices');
40+
indexAction('drop');
3841
}, 1);
3942

4043
LABKEY.Utils.attachEventHandler('addIndicesLink', 'click', function(e) {
4144
e.preventDefault();
42-
indexAction('addEHRIndices');
45+
indexAction('add');
4346
}, 1);
4447
</script>

ehr/src/org/labkey/ehr/EHRController.java

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -684,39 +684,55 @@ public ApiResponse execute(RecordDeleteForm form, BindException errors)
684684
}
685685
}
686686

687+
public static class UpdateEHRIndicesForm
688+
{
689+
private String _operation;
690+
691+
public String getOperation()
692+
{
693+
return _operation;
694+
}
695+
696+
public void setOperation(String operation)
697+
{
698+
_operation = operation;
699+
}
700+
}
701+
687702
@RequiresPermission(AdminPermission.class)
688-
public static class DropEHRIndicesAction extends MutatingApiAction<Object>
703+
public static class UpdateEHRIndicesAction extends MutatingApiAction<UpdateEHRIndicesForm>
689704
{
690705
@Override
691-
public ApiResponse execute(Object form, BindException errors)
706+
public void validateForm(UpdateEHRIndicesForm form, Errors errors)
692707
{
693-
try
708+
super.validateForm(form, errors);
709+
710+
if (form.getOperation() == null)
694711
{
695-
List<String> messages = EHRManager.get().dropEHRIndices(getContainer(), getUser());
696-
Map<String, Object> response = new HashMap<>();
697-
response.put("success", true);
698-
response.put("messages", messages);
699-
return new ApiSimpleResponse(response);
712+
errors.reject(ERROR_MSG, "Operation parameter is required.");
700713
}
701-
catch (Exception e)
714+
else if (!"add".equalsIgnoreCase(form.getOperation()) && !"drop".equalsIgnoreCase(form.getOperation()))
702715
{
703-
Map<String, Object> response = new HashMap<>();
704-
response.put("success", false);
705-
response.put("message", e.getMessage());
706-
return new ApiSimpleResponse(response);
716+
errors.reject(ERROR_MSG, "Invalid operation. Must be 'add' or 'drop'.");
707717
}
708718
}
709-
}
710719

711-
@RequiresPermission(AdminPermission.class)
712-
public static class AddEHRIndicesAction extends MutatingApiAction<Object>
713-
{
714720
@Override
715-
public ApiResponse execute(Object form, BindException errors)
721+
public ApiResponse execute(UpdateEHRIndicesForm form, BindException errors)
716722
{
717723
try
718724
{
719-
List<String> messages = EHRManager.get().addEHRIndices(getContainer(), getUser());
725+
List<String> messages;
726+
727+
if ("drop".equalsIgnoreCase(form.getOperation()))
728+
{
729+
messages = EHRManager.get().dropEHRIndices(getContainer(), getUser());
730+
}
731+
else
732+
{
733+
messages = EHRManager.get().addEHRIndices(getContainer(), getUser());
734+
}
735+
720736
Map<String, Object> response = new HashMap<>();
721737
response.put("success", true);
722738
response.put("messages", messages);

0 commit comments

Comments
 (0)