}
Study study = ControllerUtil.findStudy(request, mStudyService);
Submission submission = (Submission) study.getSubmission();
AnalyzedDataCommand command = new AnalyzedDataCommand();
String analysis_step_id = ServletRequestUtils.getStringParameter(
request,
"analysis_step_id",
null);
if (TreebaseUtil.isEmpty(analysis_step_id)) {
return command;
}
command.setStep(analysis_step_id);
// retrieve list of matrix IDs user has previously selected and store in them for lookup
AnalysisStep analysisStep = mAnalysisStepService.findByID(Long.parseLong(analysis_step_id));
List<AnalyzedData> selectedData = analysisStep.getDataSetReadOnly();
Map<Long, Boolean> selectedMatrices = new HashMap<Long, Boolean>();
Map<Long, Boolean> selectedTrees = new HashMap<Long, Boolean>();
Map<Long, Boolean> selectedTreeBlocks = new HashMap<Long,Boolean>();
Map<Long, Boolean> incompleteTreeBlocks = new HashMap<Long,Boolean>();
for (AnalyzedData data : selectedData) {
if (data instanceof AnalyzedMatrix) {
AnalyzedMatrix analyzedMatrix = (AnalyzedMatrix) data;
selectedMatrices.put(analyzedMatrix.getMatrix().getId(), analyzedMatrix
.isInputData());
} else if (data instanceof AnalyzedTree) {
AnalyzedTree analyzedTree = (AnalyzedTree) data;
selectedTrees.put(analyzedTree.getTree().getId(), analyzedTree.isInputData());
TreeBlock treeBlock = analyzedTree.getTree().getTreeBlock();
Long tbID = treeBlock.getId();
if ( ! selectedTreeBlocks.containsKey(tbID) && ! incompleteTreeBlocks.containsKey(tbID) ) {
int seen = 0;
for ( AnalyzedData innerData : selectedData ) {
if ( innerData instanceof AnalyzedTree ) {
Iterator<PhyloTree> treeIterator = treeBlock.getTreeListIterator();
FIND: while (treeIterator.hasNext()) {
PhyloTree treeInBlock = treeIterator.next();
if ( treeInBlock.getId() == ((AnalyzedTree)innerData).getTree().getId() ) {
seen++;
break FIND;
}
}
}
}
if ( seen == treeBlock.getTreeCount() ) {
selectedTreeBlocks.put(tbID, true);
}
else {
incompleteTreeBlocks.put(tbID, true);
}
}
}
}
// get list of all the matrices and set check = true if it's already been selected
List<EditFieldCommand> matrixList = new ArrayList<EditFieldCommand>();
Collection<Matrix> matrices = submission.getSubmittedMatricesReadOnly();
for (Matrix matrix : matrices) {
Long id = matrix.getId();
String selected = new String();
if (selectedMatrices.containsKey(id)) {
selected = selectedMatrices.get(id)
? (Constants.INPUT_KEY)
: (Constants.OUTPUT_KEY);
}
EditFieldCommand editFieldCommand = new EditFieldCommand(matrix, selected);
matrixList.add(editFieldCommand);
}
command.setMatrixList(matrixList);
// do the same for trees
// Iterator<PhyloTree> trees = submission.getTreeIterator();
List<EditFieldCommand> treeList = new ArrayList<EditFieldCommand>();
Collection<PhyloTree> trees = submission.getAllSubmittedTrees();
for (PhyloTree tree : trees) {
Long id = tree.getId();
String selected = new String();
if (selectedTrees.containsKey(id)) {
selected = selectedTrees.get(id) ? (Constants.INPUT_KEY) : (Constants.OUTPUT_KEY);
}
EditFieldCommand editFieldCommand = new EditFieldCommand(tree, selected);
treeList.add(editFieldCommand);
}
command.setTreeList(treeList);
List<EditFieldCommand> treeBlockList = new ArrayList<EditFieldCommand>();
Collection<TreeBlock> treeBlocks = submission.getSubmittedTreeBlocksReadOnly();
for (TreeBlock treeBlock : treeBlocks) {
Long id = treeBlock.getId();
String selected = new String();
if ( selectedTreeBlocks.containsKey(id)) {
selected = selectedTreeBlocks.get(id) ? (Constants.INPUT_KEY) : (Constants.OUTPUT_KEY);
}
EditFieldCommand editFieldCommand = new EditFieldCommand(treeBlock,selected);
treeBlockList.add(editFieldCommand);
}
command.setTreeBlockList(treeBlockList);
return command;
}