Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check if eCRF setup uses field refs, and use them strictly if yes #304

Merged
merged 1 commit into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,39 @@ public final int processRow(Cell[] row, long rowNumber) throws Throwable {

protected abstract int processRow(String[] values, long rowNumber) throws Throwable;

public final boolean preCheck(Cell[] row) throws Throwable {
if (row != null && row.length > 0) {
boolean commented = false;
String[] values = new String[row.length];
for (int i = 0; i < row.length; i++) {
String value = "";
if (row[i] != null && !commented) {
value = row[i].getContents();
if (value != null) {
if (useComments && (acceptCommentsIndex == null || acceptCommentsIndex == i)) {
int commentPos = value.indexOf(commentChar);
if (commentPos >= 0) {
value = trimValues ? value.substring(0, commentPos).trim() : value.substring(0, commentPos);
commented = true;
} else {
value = trimValues ? value.trim() : value;
}
} else {
value = trimValues ? value.trim() : value;
}
}
}
values[i] = value;
}
return preCheck(values);
}
return true;
}

protected boolean preCheck(String[] values) throws Throwable {
return false; // stop
}

protected boolean processHeaderRow(String[] values) throws Throwable {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ protected long readRows(XlsImporterContext context, String encoding, RowProcesso
rowCount += processor.processRow(row, lineNumber);
}
lineNumber++;
for (int i = 1; i < sheetRowCount; i++) {
row = sheet.getRow(i);
if (!processor.preCheck(row)) {
break;
}
}
for (int i = 1; i < sheetRowCount; i++) {
row = sheet.getRow(i);
rowCount += processor.processRow(row, lineNumber);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public class EcrfFieldRowProcessor extends RowProcessor {
private int jsValueExpressionColumnIndex;
private int jsOutputExpressionColumnIndex;
private int notifyColumnIndex;
private boolean noRefs;
private HashMap<String, HashMap<String, Set<ECRFFieldInVO>>> ecrfFieldMap;
private HashMap<String, HashMap<String, ECRF>> ecrfMap;
@Autowired
Expand All @@ -72,6 +73,7 @@ public EcrfFieldRowProcessor() {
super();
filterDupes = false;
acceptCommentsIndex = 0;
noRefs = true;
ecrfFieldMap = new HashMap<String, HashMap<String, Set<ECRFFieldInVO>>>();
ecrfMap = new HashMap<String, HashMap<String, ECRF>>();
}
Expand Down Expand Up @@ -224,6 +226,7 @@ public void init() throws Throwable {
jsValueExpressionColumnIndex = JS_VALUE_EXPRESSION_COLUMN_INDEX;
jsOutputExpressionColumnIndex = JS_OUTPUT_EXPRESSION_COLUMN_INDEX;
notifyColumnIndex = NOTIFY_COLUMN_INDEX;
noRefs = true;
ecrfFieldMap.clear();
ecrfMap.clear();
((XlsImporter) context.getImporter()).loadInputFields(context);
Expand Down Expand Up @@ -271,10 +274,12 @@ protected int processRow(String[] values, long rowNumber) throws Throwable {
ECRFField ecrfField = null;
if (ecrf != null) {
try {
if (CommonUtil.isEmptyString(ref)) {
if (noRefs) {
ecrfField = eCRFFieldDao.findByEcrfSectionPosition(ecrf.getId(), section, position).iterator().next();
} else {
ecrfField = eCRFFieldDao.findByEcrfRef(ecrf.getId(), ref).iterator().next();
if (!CommonUtil.isEmptyString(ref)) {
ecrfField = eCRFFieldDao.findByEcrfRef(ecrf.getId(), ref).iterator().next();
}
}
} catch (NoSuchElementException e) {
}
Expand Down Expand Up @@ -340,4 +345,10 @@ protected boolean testNotNullRowFields(String[] values, long rowNumber) {
}
return true;
}

@Override
protected boolean preCheck(String[] values) throws Throwable {
noRefs &= CommonUtil.isEmptyString(getRef(values));
return noRefs;
}
}
Loading