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;
}
}
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;
}
}
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);
}
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;
}
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;
}
Aggregations