Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions ehr/resources/views/ehrAdmin.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ <h4><b>Admin:</b></h4>
<div><a class="labkey-text-link" href="<%=contextPath%><%=containerPath%>/ehr-cacheLivingAnimals.view">Cache Demographics On All Living Animals</a></div>
<div><a class="labkey-text-link" href="<%=contextPath%><%=containerPath%>/ehr-cacheLivingAnimals.view?includeAll=true">Cache Demographics On All Animals</a></div>
<div><a class="labkey-text-link" href="<%=contextPath%><%=containerPath%>/ehr-geneticCalculationSettings.view">Genetics Calculations</a></div>
<div><a class="labkey-text-link" href="<%=contextPath%><%=containerPath%>/ehr-postgresMigration.view">Postgres Migration</a></div>
</div>

<div class="lead">
Expand Down
47 changes: 47 additions & 0 deletions ehr/resources/views/postgresMigration.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<div class="col-lg-3">
<div class="lead">
<div><a id="dropIndicesLink" class="labkey-text-link" href="#">Drop Indices</a></div>
<div><a id="addIndicesLink" class="labkey-text-link" href="#">Add Indices</a></div>
</div>
</div>
<script type="text/javascript" nonce="<%=scriptNonce%>">
function indexAction(operation) {
LABKEY.Ajax.request({
url: LABKEY.ActionURL.buildURL('ehr', 'updateEHRIndices'),
method: 'POST',
jsonData: {
operation: operation
},
success: function(response) {
var json = JSON.parse(response.responseText);
if (json.success) {
alert('Success!');
} else {
alert('Failure: ' + (json.message || 'Unknown error'));
}
},
failure: function(response) {
var message = 'Request failed';
try {
var json = JSON.parse(response.responseText);
if (json.exception) {
message = json.exception;
}
} catch (e) {
// ignore parse error
}
alert('Failure: ' + message);
}
});
}

LABKEY.Utils.attachEventHandler('dropIndicesLink', 'click', function(e) {
e.preventDefault();
indexAction('drop');
}, 1);

LABKEY.Utils.attachEventHandler('addIndicesLink', 'click', function(e) {
e.preventDefault();
indexAction('add');
}, 1);
</script>
64 changes: 64 additions & 0 deletions ehr/src/org/labkey/ehr/EHRController.java
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,70 @@ public ApiResponse execute(RecordDeleteForm form, BindException errors)
}
}

public static class UpdateEHRIndicesForm
{
private String _operation;

public String getOperation()
{
return _operation;
}

public void setOperation(String operation)
{
_operation = operation;
}
}

@RequiresPermission(AdminPermission.class)
public static class UpdateEHRIndicesAction extends MutatingApiAction<UpdateEHRIndicesForm>
{
@Override
public void validateForm(UpdateEHRIndicesForm form, Errors errors)
{
super.validateForm(form, errors);

if (form.getOperation() == null)
{
errors.reject(ERROR_MSG, "Operation parameter is required.");
}
else if (!"add".equalsIgnoreCase(form.getOperation()) && !"drop".equalsIgnoreCase(form.getOperation()))
{
errors.reject(ERROR_MSG, "Invalid operation. Must be 'add' or 'drop'.");
}
}

@Override
public ApiResponse execute(UpdateEHRIndicesForm form, BindException errors)
{
try
{
List<String> messages;

if ("drop".equalsIgnoreCase(form.getOperation()))
{
messages = EHRManager.get().dropEHRIndices(getContainer(), getUser());
}
else
{
messages = EHRManager.get().addEHRIndices(getContainer(), getUser());
}

Map<String, Object> response = new HashMap<>();
response.put("success", true);
response.put("messages", messages);
return new ApiSimpleResponse(response);
}
catch (Exception e)
{
Map<String, Object> response = new HashMap<>();
response.put("success", false);
response.put("message", e.getMessage());
return new ApiSimpleResponse(response);
}
}
}

public static class AnimalDetailsForm
{
private String[] _animalIds;
Expand Down
Loading