Long pStudyId, Long pMatrixId,
File pFile,
List<RowSegmentField> pMappedFields,
boolean pSkipFirstRow) {
ExecutionResult returnVal = new ExecutionResult();
if (pStudyId == null || pMatrixId == null || pFile == null || pMappedFields == null) {
returnVal.addErrorMessage("Null parameters passed in. Cannot create Row Segment.");
return returnVal;
}
TSVFileParser parser = new TSVFileParser();
List<List<String>> values = parser.parseFile(pFile, pSkipFirstRow, returnVal);
//checks to make sure there are 19 tabs present in each list
for (int x = 0; x < values.size(); x++) {
if (values.get(x).size() < 19) {
for (int y = values.get(x).size(); y < 19; y++ ) {
values.get(x).add("");
}
}
}
// check whether parsing is successful:
if (returnVal.isSuccessful()) {
List<RowSegment> newRS = new ArrayList<RowSegment>();
List<RowSegment> updateRS = new ArrayList<RowSegment>();
Study s = getDomainHome().loadPersistedObjectByID(Study.class, pStudyId);
CharacterMatrix m = getDomainHome().loadPersistedObjectByID(CharacterMatrix.class, pMatrixId);
mapToSegments(s, m, values, pMappedFields, newRS, updateRS, returnVal);
// Save to database:
getRowSegmentHome().storeAll(newRS);
//Don't need to merge since it is the same session:
for (RowSegment anUpdate : updateRS) {
getRowSegmentHome().merge(anUpdate);
}
// Report result:
int rowCount = values.size();
int successCount = newRS.size() + updateRS.size();
returnVal.setSuccessfulCount(successCount);
returnVal.setFailureCount(rowCount - successCount);
}
return returnVal;
}