-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enable audit trail for "in progress" eCRF forms
+ store changed data only
- Loading branch information
Showing
9 changed files
with
517 additions
and
26 deletions.
There are no files selected for viewing
145 changes: 145 additions & 0 deletions
145
common/src/main/java/org/phoenixctms/ctsms/adapt/InputFieldValueEqualsAdapterBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
...main/java/org/phoenixctms/ctsms/adapt/EcrfFieldValueInVOInputFieldValueEqualsAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
104 changes: 104 additions & 0 deletions
104
...c/main/java/org/phoenixctms/ctsms/adapt/InquiryValueInVOInputFieldValueEqualsAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
Oops, something went wrong.