String type = j.getString("libraryType");
String selectionType = j.getString("selectionType");
String strategyType = j.getString("strategyType");
String locationBarcode = j.getString("locationBarcode");
Library library = new LibraryImpl();
library.setSample(sample);
String libAlias = libraryNamingScheme.generateNameFor("alias", library);
library.setAlias(libAlias);
library.setSecurityProfile(sp);
library.setDescription(descr);
library.setPlatformName(platform);
library.setCreationDate(new Date());
library.setLocationBarcode(locationBarcode);
library.setQcPassed(false);
library.setLibraryType(requestManager.getLibraryTypeByDescription(type));
library.setLibrarySelectionType(requestManager.getLibrarySelectionTypeByName(selectionType));
library.setLibraryStrategyType(requestManager.getLibraryStrategyTypeByName(strategyType));
boolean paired = false;
if (!"".equals(j.getString("paired"))) {
paired = j.getBoolean("paired");
}
library.setPaired(paired);
if (j.has("tagBarcodes") && !"".equals(j.getString("tagBarcodes")) && !j.getString("tagBarcodes").contains("Select")) {
String[] codes = j.getString("tagBarcodes").split(Pattern.quote("|"));
HashMap<Integer, TagBarcode> barcodes = new HashMap<Integer, TagBarcode>();
int count = 1;
for (String code : codes) {
try {
long cl = Long.parseLong(code);
barcodes.put(count, requestManager.getTagBarcodeById(cl));
}
catch (NumberFormatException e) {
e.printStackTrace();
return JSONUtils.SimpleJSONError("Cannot save Library. It looks like there are tag barcodes for the library of "+sample.getAlias()+", but they cannot be processed");
}
finally {
count++;
}
}
library.setTagBarcodes(barcodes);
}
saveSet.add(library);
}
else {