DateFormat df = new SimpleDateFormat("dd/mm/yyyy");
String alias = json.getString("alias");
Double concentration = json.getDouble("concentration");
PlatformType platformType = PlatformType.get(json.getString("platformType"));
StringBuilder sb = new StringBuilder();
List<Integer> ids = JSONArray.fromObject(json.getString("dilutions"));
List<PoolQC> pqcs = new ArrayList<PoolQC>();
JSONArray qcs = JSONArray.fromObject(json.get("qcs"));
for (JSONObject q : (Iterable<JSONObject>) qcs) {
PoolQC s = dataObjectFactory.getPoolQC();
try {
s.setResults(Double.valueOf(q.getString("poolQcResults")));
s.setQcCreator(SecurityContextHolder.getContext().getAuthentication().getName());
s.setQcDate(df.parse(q.getString("poolQcDate")));
s.setQcType(requestManager.getPoolQcTypeById(q.getLong("poolQcType")));
}
catch (IOException e) {
e.printStackTrace();
return JSONUtils.SimpleJSONError("Failed: " + e.getMessage());
}
catch (ParseException e) {
e.printStackTrace();
return JSONUtils.SimpleJSONError("Failed: " + e.getMessage());
}
pqcs.add(s);
}
if (ids.size() > 0 && platformType != null && concentration != null) {
try {
User user = securityManager.getUserByLoginName(SecurityContextHolder.getContext().getAuthentication().getName());
List<Dilution> dils = new ArrayList<Dilution>();
for (Integer id : ids) {
dils.add(requestManager.getDilutionByIdAndPlatform(id.longValue(), platformType));
}
boolean barcodeCollision = false;
if (dils.size() > 1) {
for (Dilution d1 : dils) {
if (d1 != null) {
for (Dilution d2 : dils) {
if (d2 != null && !d1.equals(d2)) {
if (!d1.getLibrary().getTagBarcodes().isEmpty() && !d2.getLibrary().getTagBarcodes().isEmpty()) {
if (d1.getLibrary().getTagBarcodes().equals(d2.getLibrary().getTagBarcodes())) {
barcodeCollision = true;
}
}
}
}
}
}
}
if (!barcodeCollision) {
Pool pool;
//TODO special type of pool for LibraryDilutions that will go on to be emPCRed as a whole
if (dils.get(0) instanceof LibraryDilution &&
(platformType.equals(PlatformType.SOLID) || platformType.equals(PlatformType.LS454))) {
pool = dataObjectFactory.getEmPCRPool(platformType, user);
}
else {
pool = dataObjectFactory.getPoolOfType(platformType, user);
}