Search in sources :

Example 11 with StorageLocation

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;
}
Also used : Request(org.jbei.ice.storage.model.Request) CSVWriter(com.opencsv.CSVWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Entry(org.jbei.ice.storage.model.Entry) OutputStreamWriter(java.io.OutputStreamWriter) StorageLocation(org.jbei.ice.lib.dto.StorageLocation)

Example 12 with StorageLocation

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();
}
Also used : HasEntry(org.jbei.ice.lib.entry.HasEntry) PartSample(org.jbei.ice.lib.dto.sample.PartSample) StorageLocation(org.jbei.ice.lib.dto.StorageLocation)

Example 13 with StorageLocation

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;
}
Also used : StorageLocation(org.jbei.ice.lib.dto.StorageLocation)

Example 14 with StorageLocation

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();
}
Also used : StorageLocation(org.jbei.ice.lib.dto.StorageLocation)

Aggregations

StorageLocation (org.jbei.ice.lib.dto.StorageLocation)14 PartSample (org.jbei.ice.lib.dto.sample.PartSample)7 Account (org.jbei.ice.storage.model.Account)3 Strain (org.jbei.ice.storage.model.Strain)3 Test (org.junit.Test)3 UserComment (org.jbei.ice.lib.dto.comment.UserComment)2 HasEntry (org.jbei.ice.lib.entry.HasEntry)2 CSVWriter (com.opencsv.CSVWriter)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Entry (org.jbei.ice.storage.model.Entry)1 Request (org.jbei.ice.storage.model.Request)1