Skip to content

Commit

Permalink
enable audit trail for "in progress" eCRF forms
Browse files Browse the repository at this point in the history
+ store changed data only
  • Loading branch information
rkrenn committed Mar 14, 2019
1 parent 703e586 commit 44581a5
Show file tree
Hide file tree
Showing 9 changed files with 517 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
package org.phoenixctms.ctsms.adapt;

import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.phoenixctms.ctsms.enumeration.InputFieldType;

public abstract class InputFieldValueEqualsAdapterBase<A, B> {

protected abstract Boolean getABoolean(A a);

protected abstract Date getADate(A a);

protected abstract Float getAFloat(A a);

protected abstract byte[] getAInk(A a);

protected abstract Long getALong(A a);

protected abstract ArrayList getASelectionSetSorted(A a);

protected abstract String getAText(A a);


protected abstract Date getATime(A a);

protected abstract Date getATimestamp(A a);

protected abstract Boolean getBBoolean(B b);

protected abstract Date getBDate(B b);

protected abstract Float getBFloat(B b);

protected abstract byte[] getBInk(B b);

protected abstract Long getBLong(B b);

protected abstract ArrayList getBSelectionSetSorted(B b);

protected abstract String getBText(B b);


protected abstract Date getBTime(B b);

protected abstract Date getBTimestamp(B b);

protected boolean selectionSetValueEquals(Object a, Object b) {
return a.equals(b);
}

public final boolean valueEquals(A a, B b) {
return valueEquals(a, b, null, false, false);
}
public final boolean valueEquals(A a, B b, InputFieldType fieldType, boolean normalizeLineEndings, boolean normalizeNullStrings) {
EqualsBuilder eb = new EqualsBuilder();
if (fieldType == null ||
InputFieldType.CHECKBOX.equals(fieldType)) {
eb.append(getABoolean(a), getBBoolean(b));
}
if (fieldType == null ||
InputFieldType.INTEGER.equals(fieldType)) {
eb.append(getALong(a), getBLong(b));
}
if (fieldType == null ||
InputFieldType.FLOAT.equals(fieldType)) {
eb.append(getAFloat(a), getBFloat(b));
}
if (fieldType == null ||
InputFieldType.DATE.equals(fieldType)) {
eb.append(getADate(a), getBDate(b));
}
if (fieldType == null ||
InputFieldType.TIME.equals(fieldType)) {
eb.append(getATime(a), getBTime(b));
}
if (fieldType == null ||
InputFieldType.TIMESTAMP.equals(fieldType)) {
eb.append(getATimestamp(a), getBTimestamp(b));
}
if (fieldType == null ||
InputFieldType.SINGLE_LINE_TEXT.equals(fieldType) ||
InputFieldType.MULTI_LINE_TEXT.equals(fieldType) ||
InputFieldType.AUTOCOMPLETE.equals(fieldType)) {
String aString = getAText(a) == null ? (normalizeNullStrings ? "" : null) : getAText(a);
String bString = getBText(b) == null ? (normalizeNullStrings ? "" : null) : getBText(b);
if (normalizeLineEndings) {
eb.append(aString == null ? null : aString.replaceAll("\\r\\n?", "\n"),
bString == null ? null : bString.replaceAll("\\r\\n?", "\n"));
} else {
eb.append(aString, bString);
}
}
if (!eb.isEquals()) {
return false;
}
eb.reset();
if (fieldType == null ||
InputFieldType.SKETCH.equals(fieldType)) {
eb.append(getAInk(a), getBInk(b)); // deep
}
if (!eb.isEquals()) {
return false;
}
eb.reset();
if (fieldType == null ||
InputFieldType.SELECT_ONE_DROPDOWN.equals(fieldType) ||
InputFieldType.SELECT_ONE_RADIO_H.equals(fieldType) ||
InputFieldType.SELECT_ONE_RADIO_V.equals(fieldType) ||
InputFieldType.SELECT_MANY_H.equals(fieldType) ||
InputFieldType.SELECT_MANY_V.equals(fieldType)) {
ArrayList aSelectionSet = getASelectionSetSorted(a);
if (aSelectionSet == null) {
aSelectionSet = new ArrayList();
}
ArrayList<Object> bSelectionSet = getBSelectionSetSorted(b);
if (bSelectionSet == null) {
bSelectionSet = new ArrayList();
}
if (aSelectionSet.size() == bSelectionSet.size()) {
Iterator aSelectionSetIt = aSelectionSet.iterator();
Iterator bSelectionSetIt = bSelectionSet.iterator();
while (aSelectionSetIt.hasNext() && bSelectionSetIt.hasNext()) {
Object aSelectionSetValue = aSelectionSetIt.next();
Object bSelectionSetValue = bSelectionSetIt.next();
if (aSelectionSetValue != null && bSelectionSetValue != null) {
if (!selectionSetValueEquals(aSelectionSetValue, bSelectionSetValue)) {
return false;
}
} else if (aSelectionSetValue != null && bSelectionSetValue == null) {
return false;
} else if (aSelectionSetValue == null && bSelectionSetValue != null) {
return false;
}
}
return aSelectionSetIt.hasNext() == bSelectionSetIt.hasNext();
} else {
return false;
}
}
return true;
}
}
4 changes: 3 additions & 1 deletion core/db/schema-up-163.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@ alter table PROBAND_LIST_ENTRY_TAG alter RANDOMIZE set not null;

alter table TRIAL add column SIGNUP_RANDOMIZE BOOLEAN;
update TRIAL set SIGNUP_RANDOMIZE = 'f';
alter table TRIAL alter SIGNUP_RANDOMIZE set not null;
alter table TRIAL alter SIGNUP_RANDOMIZE set not null;

update ecrf_status_type set audit_trail = 't' where name_l10n_key = 'in_progress';

Original file line number Diff line number Diff line change
Expand Up @@ -1130,7 +1130,7 @@ private void createEcrfStatusTypeEntries() {
false,
false,
false,
false, // true, -> slow page saving
true, // true, -> slow page saving. now only changed fields will be saved, perf ok
false,
false,
false,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package org.phoenixctms.ctsms.adapt;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;

import org.phoenixctms.ctsms.domain.InputFieldValue;
import org.phoenixctms.ctsms.util.ServiceUtil;
import org.phoenixctms.ctsms.vo.ECRFFieldValueInVO;

public class EcrfFieldValueInVOInputFieldValueEqualsAdapter extends InputFieldValueEqualsAdapterBase<ECRFFieldValueInVO,InputFieldValue> {


@Override
protected Boolean getABoolean(ECRFFieldValueInVO a) {
return a.getBooleanValue();
}

@Override
protected Date getADate(ECRFFieldValueInVO a) {
return a.getDateValue();
}

@Override
protected Float getAFloat(ECRFFieldValueInVO a) {
return a.getFloatValue();
}

@Override
protected byte[] getAInk(ECRFFieldValueInVO a) {
return a.getInkValues();
}

@Override
protected Long getALong(ECRFFieldValueInVO a) {
return a.getLongValue();
}

@Override
protected ArrayList getASelectionSetSorted(ECRFFieldValueInVO a) {
ArrayList selectionValueIds = (ArrayList) a.getSelectionValueIds();
Collections.sort(selectionValueIds);
return selectionValueIds;
}



@Override
protected String getAText(ECRFFieldValueInVO a) {
return a.getTextValue();
}

@Override
protected Date getATime(ECRFFieldValueInVO a) {
return a.getTimeValue();
}

@Override
protected Date getATimestamp(ECRFFieldValueInVO a) {
return a.getTimestampValue();
}

@Override
protected Boolean getBBoolean(InputFieldValue b) {
return b.getBooleanValue();
}

@Override
protected Date getBDate(InputFieldValue b) {
return b.getDateValue();
}

@Override
protected Float getBFloat(InputFieldValue b) {
return b.getFloatValue();
}

@Override
protected byte[] getBInk(InputFieldValue b) {
return b.getInkValue();
}

@Override
protected Long getBLong(InputFieldValue b) {
return b.getLongValue();
}

@Override
protected ArrayList getBSelectionSetSorted(InputFieldValue b) {
return ServiceUtil.toInputFieldSelectionSetValueIdCollection(b.getSelectionValues());
}



@Override
protected String getBText(InputFieldValue b) {
return b.getStringValue();
}

@Override
protected Date getBTime(InputFieldValue b) {
return b.getTimeValue();
}

@Override
protected Date getBTimestamp(InputFieldValue b) {
return b.getTimestampValue();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package org.phoenixctms.ctsms.adapt;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;

import org.phoenixctms.ctsms.domain.InputFieldValue;
import org.phoenixctms.ctsms.util.ServiceUtil;
import org.phoenixctms.ctsms.vo.InquiryValueInVO;

public class InquiryValueInVOInputFieldValueEqualsAdapter extends InputFieldValueEqualsAdapterBase<InquiryValueInVO, InputFieldValue> {

@Override
protected Boolean getABoolean(InquiryValueInVO a) {
return a.getBooleanValue();
}

@Override
protected Date getADate(InquiryValueInVO a) {
return a.getDateValue();
}

@Override
protected Float getAFloat(InquiryValueInVO a) {
return a.getFloatValue();
}

@Override
protected byte[] getAInk(InquiryValueInVO a) {
return a.getInkValues();
}

@Override
protected Long getALong(InquiryValueInVO a) {
return a.getLongValue();
}

@Override
protected ArrayList getASelectionSetSorted(InquiryValueInVO a) {
ArrayList selectionValueIds = (ArrayList) a.getSelectionValueIds();
Collections.sort(selectionValueIds);
return selectionValueIds;
}

@Override
protected String getAText(InquiryValueInVO a) {
return a.getTextValue();
}

@Override
protected Date getATime(InquiryValueInVO a) {
return a.getTimeValue();
}

@Override
protected Date getATimestamp(InquiryValueInVO a) {
return a.getTimestampValue();
}

@Override
protected Boolean getBBoolean(InputFieldValue b) {
return b.getBooleanValue();
}

@Override
protected Date getBDate(InputFieldValue b) {
return b.getDateValue();
}

@Override
protected Float getBFloat(InputFieldValue b) {
return b.getFloatValue();
}

@Override
protected byte[] getBInk(InputFieldValue b) {
return b.getInkValue();
}

@Override
protected Long getBLong(InputFieldValue b) {
return b.getLongValue();
}

@Override
protected ArrayList getBSelectionSetSorted(InputFieldValue b) {
return ServiceUtil.toInputFieldSelectionSetValueIdCollection(b.getSelectionValues());
}

@Override
protected String getBText(InputFieldValue b) {
return b.getStringValue();
}

@Override
protected Date getBTime(InputFieldValue b) {
return b.getTimeValue();
}

@Override
protected Date getBTimestamp(InputFieldValue b) {
return b.getTimestampValue();
}
}

0 comments on commit 44581a5

Please sign in to comment.