use of org.jbei.ice.lib.dto.StorageLocation in project ice by JBEI.
the class RequestRetriever method generateCSVFile.
public ByteArrayOutputStream generateCSVFile(String userId, ArrayList<Long> ids) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
OutputStreamWriter streamWriter = new OutputStreamWriter(out);
try (CSVWriter writer = new CSVWriter(streamWriter)) {
SampleService sampleService = new SampleService();
Set<Long> idSet = new HashSet<>(ids);
for (long id : idSet) {
Request request = dao.get(id);
if (request == null)
continue;
String[] line = new String[3];
Entry entry = request.getEntry();
line[0] = entry.getName();
List<PartSample> samples = sampleService.retrieveEntrySamples(userId, Long.toString(request.getEntry().getId()));
String plate = null;
String well = null;
if (samples.size() == 1) {
if (samples.get(0).getLocation().getType() == SampleType.GENERIC) {
plate = "generic";
well = "";
}
} else {
for (PartSample partSample : samples) {
if (partSample.getLabel().contains("backup"))
continue;
// get plate
StorageLocation location = partSample.getLocation();
if (location == null)
continue;
if (location.getType() == SampleType.PLATE96) {
plate = location.getDisplay().replaceFirst("^0+(?!$)", "");
}
StorageLocation child = location.getChild();
while (child != null) {
if (child.getType() == SampleType.WELL) {
well = child.getDisplay();
break;
}
child = child.getChild();
}
if (!StringUtils.isEmpty(well) && !StringUtils.isEmpty(plate))
break;
}
}
if (plate == null || well == null)
continue;
String email = request.getAccount().getEmail();
int index = email.indexOf('@');
char typeChar = request.getType() == SampleRequestType.LIQUID_CULTURE ? 'L' : 'A';
line[1] = typeChar + " " + plate + " " + well + " " + email.substring(0, index);
line[1] = line[1].trim().replaceAll(" +", " ");
line[2] = request.getPlateDescription().trim().replaceAll(" +", " ");
if (request.getGrowthTemperature() != null)
line[2] += " " + request.getGrowthTemperature();
writer.writeNext(line);
}
}
return out;
}
use of org.jbei.ice.lib.dto.StorageLocation in project ice by JBEI.
the class SampleService method createSample.
public PartSample createSample(String userId, String entryId, PartSample partSample, String strainNamePrefix) {
Entry entry = super.getEntry(entryId);
if (entry == null) {
Logger.error("Could not retrieve entry with id " + entryId + ". Skipping sample creation");
return null;
}
entryAuthorization.expectWrite(userId, entry);
Sample sample = SampleCreator.createSampleObject(partSample.getLabel(), userId, "");
sample.setEntry(entry);
String depositor;
if (partSample.getDepositor() == null) {
depositor = userId;
} else {
depositor = partSample.getDepositor().getEmail();
}
StorageLocation mainLocation = partSample.getLocation();
// check and create the storage locations
if (mainLocation != null) {
Storage currentStorage;
switch(mainLocation.getType()) {
case ADDGENE:
currentStorage = createStorage(depositor, mainLocation.getDisplay(), mainLocation.getType());
currentStorage = storageDAO.create(currentStorage);
break;
case PLATE96:
currentStorage = createPlate96Location(depositor, mainLocation);
break;
case SHELF:
currentStorage = createShelfStorage(depositor, mainLocation);
break;
default:
currentStorage = storageDAO.get(mainLocation.getId());
if (currentStorage == null) {
currentStorage = createStorage(userId, mainLocation.getDisplay(), mainLocation.getType());
currentStorage = storageDAO.create(currentStorage);
}
currentStorage = createChildrenStorage(mainLocation, currentStorage, depositor);
}
if (currentStorage == null)
return null;
sample.setStorage(currentStorage);
}
// create sample. If main location is null then sample is created without location
sample = dao.create(sample);
String name = entry.getName();
if (strainNamePrefix != null && name != null && !name.startsWith(strainNamePrefix)) {
entryDAO.generateNextStrainNameForEntry(entry, strainNamePrefix);
}
return sample.toDataTransferObject();
}
use of org.jbei.ice.lib.dto.StorageLocation in project ice by JBEI.
the class SampleService method createChildrenStorage.
/**
* Creates storage for all children of given parent storage
*
* @param currentLocation storage location
* @param currentStorage
* @param depositor userID - unique identifier for user performing action
* @return updated storage
*/
protected Storage createChildrenStorage(StorageLocation currentLocation, Storage currentStorage, String depositor) {
while (currentLocation.getChild() != null) {
StorageLocation child = currentLocation.getChild();
Storage childStorage = storageDAO.get(child.getId());
if (childStorage == null) {
childStorage = createStorage(depositor, child.getDisplay(), child.getType());
childStorage.setParent(currentStorage);
childStorage = storageDAO.create(childStorage);
}
currentStorage = childStorage;
currentLocation = child;
}
return currentStorage;
}
use of org.jbei.ice.lib.dto.StorageLocation in project ice by JBEI.
the class PartSample method toString.
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
StorageLocation location = getLocation();
while (location != null) {
builder.append("[location: ").append(location.toString()).append("]");
location = location.getChild();
}
return builder.toString();
}
Aggregations