//editSubmission.jsp
public JSONObject saveSubmission(HttpSession session, JSONObject json) {
try {
if (json.has("form") && !json.get("form").equals("")) {
//creates a new submission object using the form info
Submission newSubmission = new SubmissionImpl();
//if editing an existing submission
if (json.has("submissionId") && json.get("submissionId") != "" && !json.get("submissionId").equals(-1)) {
//calls up the existing submission with this ID
Submission oldSubmission = requestManager.getSubmissionById(Long.parseLong(json.getString("submissionId")));
//sets the details of the new one to match the old.
newSubmission.setId(oldSubmission.getId());
newSubmission.setAccession(oldSubmission.getAccession());
//newSubmission.setAlias(oldSubmission.getAlias());
newSubmission.setCreationDate(oldSubmission.getCreationDate());
//newSubmission.setDescription(oldSubmission.getDescription());
newSubmission.setName(oldSubmission.getName());
newSubmission.setSubmissionDate(oldSubmission.getSubmissionDate());
//newSubmission.setTitle(oldSubmission.getTitle());
newSubmission.setVerified(oldSubmission.isVerified());
newSubmission.setCompleted(oldSubmission.isCompleted());
}
//sets the title, alias and description based on form contents
JSONArray form = JSONArray.fromObject(json.get("form"));
Set<SequencerPoolPartition> newPartitions = new HashSet<SequencerPoolPartition>();
for (JSONObject j : (Iterable<JSONObject>) form) {
if (j.getString("name").equals("title")) {
newSubmission.setTitle(j.getString("value"));
}
if (j.getString("name").equals("alias")) {
newSubmission.setAlias(j.getString("value"));
}
if (j.getString("name").equals("description")) {
newSubmission.setDescription(j.getString("value"));
}
if (j.getString("name").contains("DIL")) {
Long dilutionId = Long.parseLong(j.getString("name").replaceAll("\\D+", ""));
Long partitionId = Long.parseLong(j.getString("value").replaceAll("\\D+", ""));
//and a new Partition created from the ID
PartitionImpl newPartition = new PartitionImpl();
newPartition.setId(partitionId);
//if the partition is not already in the set of newPartitions:
if (newPartitions.add(newPartition)) {
// a new pool is created
Pool<Dilution> newPool = new PoolImpl<Dilution>();
//details of the original partition's pool are copied to the new one
Pool<? extends Poolable> oldPool = requestManager.getSequencerPoolPartitionById(partitionId).getPool();
newPool.setExperiments(oldPool.getExperiments());
newPool.setPlatformType(oldPool.getPlatformType());
//the new pool is added to the partition
newPartition.setPool(newPool);
}
for (SequencerPoolPartition nextPartition : newPartitions) {
if (nextPartition.getId() == partitionId) {
//Dilution dilution = requestManager.getDilutionByIdAndPlatform(dilutionId, nextPartition.getPool().getPlatformType());
Dilution dilution = requestManager.getLibraryDilutionById(dilutionId);
Pool pool = nextPartition.getPool();
pool.addPoolableElement(dilution);
}
}
}
}
//the set of partitions is added to the new Submission
for (SequencerPoolPartition sequencerPoolPartition : newPartitions) {
newSubmission.addSubmissionElement(sequencerPoolPartition);
}
//the submission is saved
requestManager.saveSubmission(newSubmission);
return JSONUtils.SimpleJSONResponse("Submission " + newSubmission.getId() + " saved!");
}
}
catch (Exception e) {
e.printStackTrace();
return JSONUtils.SimpleJSONError(e.getMessage());