Search in sources :

Example 1 with SampleRequest

use of org.jbei.ice.lib.dto.sample.SampleRequest in project ice by JBEI.

the class SampleCart method addRequest.

/**
 * Creates a new sample request for the specified user and specified entry.
 * The default status is "IN CART"
 */
public boolean addRequest(SampleRequest sampleRequest) {
    long partId = sampleRequest.getPartData().getId();
    Entry entry = entryDAO.get(sampleRequest.getPartData().getId());
    if (entry == null)
        throw new IllegalArgumentException("Cannot find entry with id: " + partId);
    Account account = DAOFactory.getAccountDAO().getByEmail(userId);
    // check if sample is already in cart with status of "IN CART"
    try {
        List<Request> requests = dao.getSampleRequestByStatus(account, entry, SampleRequestStatus.IN_CART);
        if (requests != null && !requests.isEmpty())
            return true;
        Request request = new Request();
        request.setAccount(account);
        request.setGrowthTemperature(sampleRequest.getGrowthTemperature());
        request.setEntry(entry);
        if (sampleRequest.getRequestType() == null)
            sampleRequest.setRequestType(SampleRequestType.LIQUID_CULTURE);
        request.setType(sampleRequest.getRequestType());
        request.setRequested(new Date(System.currentTimeMillis()));
        request.setUpdated(request.getRequested());
        request.setPlateDescription(sampleRequest.getPlateDescription());
        return dao.create(request) != null;
    } catch (DAOException e) {
        Logger.error(e);
        return false;
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) Account(org.jbei.ice.storage.model.Account) Entry(org.jbei.ice.storage.model.Entry) Request(org.jbei.ice.storage.model.Request) SampleRequest(org.jbei.ice.lib.dto.sample.SampleRequest) Date(java.util.Date)

Example 2 with SampleRequest

use of org.jbei.ice.lib.dto.sample.SampleRequest in project ice by JBEI.

the class SampleCart method removeRequest.

public SampleRequest removeRequest(long requestId) {
    try {
        Request request = dao.get(requestId);
        if (request == null)
            return null;
        if (!request.getAccount().getEmail().equalsIgnoreCase(userId))
            return null;
        dao.delete(request);
        return request.toDataTransferObject();
    } catch (DAOException de) {
        Logger.error(de);
        return null;
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) Request(org.jbei.ice.storage.model.Request) SampleRequest(org.jbei.ice.lib.dto.sample.SampleRequest)

Example 3 with SampleRequest

use of org.jbei.ice.lib.dto.sample.SampleRequest in project ice by JBEI.

the class SampleResource method updateSampleRequest.

/**
     * @return Response with the updated sample request
     */
@PUT
@Path("/requests/{id}")
public Response updateSampleRequest(@PathParam("id") final long requestId, @QueryParam("status") final SampleRequestStatus status) {
    final String userId = requireUserId();
    final SampleRequest request = requestRetriever.updateStatus(userId, requestId, status);
    return respond(Response.Status.OK, request);
}
Also used : SampleRequest(org.jbei.ice.lib.dto.sample.SampleRequest)

Example 4 with SampleRequest

use of org.jbei.ice.lib.dto.sample.SampleRequest in project ice by JBEI.

the class Request method toDataTransferObject.

@Override
public SampleRequest toDataTransferObject() {
    SampleRequest sampleRequest = new SampleRequest();
    sampleRequest.setId(getId());
    sampleRequest.setRequestType(getType());
    sampleRequest.setStatus(getStatus());
    if (growthTemperature != null)
        sampleRequest.setGrowthTemperature(growthTemperature);
    sampleRequest.setPlateDescription(plateDescription);
    EntryType type = EntryType.nameToType(entry.getRecordType());
    PartData data = new PartData(type);
    data.setId(entry.getId());
    data.setPartId(entry.getPartNumber());
    data.setSelectionMarkers(EntryUtil.getSelectionMarkersAsList(entry.getSelectionMarkers()));
    data.setName(entry.getName());
    data.setBioSafetyLevel(entry.getBioSafetyLevel());
    sampleRequest.setPartData(data);
    sampleRequest.setRequester(getAccount().toDataTransferObject());
    sampleRequest.setRequestTime(getRequested().getTime());
    sampleRequest.setUpdateTime(getUpdated() == null ? sampleRequest.getRequestTime() : getUpdated().getTime());
    return sampleRequest;
}
Also used : EntryType(org.jbei.ice.lib.dto.entry.EntryType) PartData(org.jbei.ice.lib.dto.entry.PartData) SampleRequest(org.jbei.ice.lib.dto.sample.SampleRequest)

Example 5 with SampleRequest

use of org.jbei.ice.lib.dto.sample.SampleRequest in project ice by JBEI.

the class UserFolders method get.

public FolderDetails get(long folderId) {
    Folder folder = this.dao.get(folderId);
    if (folder == null)
        throw new IllegalArgumentException("Folder with id " + folderId + " does not exist");
    authorization.expectRead(this.userId, folder);
    FolderDetails folderDetails = folder.toDataTransferObject();
    List<String> types = dao.getContentTypes(folderId);
    if (!types.isEmpty()) {
        for (String type : types) {
            EntryType entryType = EntryType.nameToType(type);
            if (entryType != null)
                folderDetails.getContentTypes().add(entryType);
        }
    }
    Account owner = accountDAO.getByEmail(folder.getOwnerEmail());
    if (owner != null) {
        folderDetails.setOwner(owner.toDataTransferObject());
    }
    // get sample details
    if (folder.getType() == FolderType.SAMPLE) {
        SampleCreateModel model = DAOFactory.getSampleCreateModelDAO().getByFolder(folder);
        if (model != null) {
            SampleRequest request = new SampleRequest();
            request.setId(model.getId());
            request.setStatus(model.getStatus());
            folderDetails.setSampleRequest(request);
        }
    }
    return folderDetails;
}
Also used : Account(org.jbei.ice.storage.model.Account) EntryType(org.jbei.ice.lib.dto.entry.EntryType) SampleCreateModel(org.jbei.ice.storage.model.SampleCreateModel) FolderDetails(org.jbei.ice.lib.dto.folder.FolderDetails) Folder(org.jbei.ice.storage.model.Folder) SampleRequest(org.jbei.ice.lib.dto.sample.SampleRequest)

Aggregations

SampleRequest (org.jbei.ice.lib.dto.sample.SampleRequest)6 EntryType (org.jbei.ice.lib.dto.entry.EntryType)2 PartData (org.jbei.ice.lib.dto.entry.PartData)2 FolderDetails (org.jbei.ice.lib.dto.folder.FolderDetails)2 DAOException (org.jbei.ice.storage.DAOException)2 Account (org.jbei.ice.storage.model.Account)2 Request (org.jbei.ice.storage.model.Request)2 Date (java.util.Date)1 AccessPermission (org.jbei.ice.lib.dto.access.AccessPermission)1 Entry (org.jbei.ice.storage.model.Entry)1 Folder (org.jbei.ice.storage.model.Folder)1 SampleCreateModel (org.jbei.ice.storage.model.SampleCreateModel)1