Skip to content

Commit

Permalink
check if eCRF setup uses field refs, and use them strictly if yes
Browse files Browse the repository at this point in the history
  • Loading branch information
rkrenn committed Apr 7, 2024
1 parent 9545796 commit b45b3df
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
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;
}
}

0 comments on commit b45b3df

Please sign in to comment.