public JSONObject bulkSaveSamples(HttpSession session, JSONObject json) {
if (json.has("samples")) {
try {
Project p = requestManager.getProjectById(json.getLong("projectId"));
SecurityProfile sp = p.getSecurityProfile();
JSONArray a = JSONArray.fromObject(json.get("samples"));
Set<Sample> saveSet = new HashSet<Sample>();
for (JSONObject j : (Iterable<JSONObject>) a) {
try {
String alias = j.getString("alias");
if (sampleNamingScheme.validateField("alias", alias)) {
String descr = j.getString("description");
String scientificName = j.getString("scientificName");
DateFormat df = new SimpleDateFormat("dd/mm/yyyy");
String type = j.getString("sampleType");
String locationBarcode = j.getString("locationBarcode");
Sample news = new SampleImpl();
news.setProject(p);
news.setAlias(alias);
news.setDescription(descr);
news.setScientificName(scientificName);
news.setSecurityProfile(sp);
news.setSampleType(type);
news.setLocationBarcode(locationBarcode);
if (j.has("receivedDate") && !"".equals(j.getString("receivedDate"))) {
Date date = df.parse(j.getString("receivedDate"));
news.setReceivedDate(date);
}
if (!j.getString("note").equals("")) {
Note note = new Note();
note.setOwner(sp.getOwner());
note.setText(j.getString("note"));
note.setInternalOnly(true);
if (j.has("receivedDate") && !"".equals(j.getString("receivedDate"))) {
Date date = df.parse(j.getString("receivedDate"));