use of org.jbei.ice.lib.dto.comment.UserComment in project ice by JBEI.
the class EntryController method retrieveEntryComments.
public ArrayList<UserComment> retrieveEntryComments(String userId, long partId) {
Entry entry = dao.get(partId);
if (entry == null)
return null;
authorization.expectRead(userId, entry);
// comments
List<Comment> comments = commentDAO.retrieveComments(entry);
ArrayList<UserComment> userComments = new ArrayList<>();
for (Comment comment : comments) {
userComments.add(comment.toDataTransferObject());
}
return userComments;
}
use of org.jbei.ice.lib.dto.comment.UserComment in project ice by JBEI.
the class EntryController method updateEntryComment.
public UserComment updateEntryComment(String userId, long partId, long commentId, UserComment userComment) {
Entry entry = dao.get(partId);
if (entry == null)
return null;
authorization.canRead(userId, entry);
Comment comment = commentDAO.get(commentId);
if (comment == null)
return createEntryComment(userId, partId, userComment);
if (comment.getEntry().getId() != partId)
return null;
if (userComment.getMessage() == null || userComment.getMessage().isEmpty())
return null;
comment.setBody(userComment.getMessage());
comment.setModificationTime(new Date());
return commentDAO.update(comment).toDataTransferObject();
}
use of org.jbei.ice.lib.dto.comment.UserComment in project ice by JBEI.
the class SampleService method retrieveEntrySamples.
public List<PartSample> retrieveEntrySamples(String userId, String entryId) {
Entry entry = super.getEntry(entryId);
if (entry == null)
return null;
entryAuthorization.expectRead(userId, entry);
// samples
List<Sample> entrySamples = dao.getSamplesByEntry(entry);
ArrayList<PartSample> samples = new ArrayList<>();
if (entrySamples == null)
return samples;
boolean inCart = false;
if (userId != null) {
Account userAccount = accountDAO.getByEmail(userId);
inCart = DAOFactory.getRequestDAO().getSampleRequestInCart(userAccount, entry) != null;
}
ArrayList<Sample> siblingSamples = new ArrayList<>();
for (Sample sample : entrySamples) {
Storage storage = sample.getStorage();
if (storage == null)
continue;
if (storage.getParent() != null && storage.getParent().getParent() != null) {
siblingSamples.addAll(dao.getSamplesByStorage(storage.getParent().getParent()));
}
}
entrySamples.addAll(siblingSamples);
Set<Sample> unique = new HashSet<>(entrySamples);
entrySamples = new ArrayList<>(unique);
for (Sample sample : entrySamples) {
// convert sample to info
Storage storage = sample.getStorage();
if (storage == null) {
// dealing with sample with no storage
PartSample generic = sample.toDataTransferObject();
StorageLocation location = new StorageLocation();
location.setType(SampleType.GENERIC);
location.setDisplay(sample.getLabel());
generic.setLocation(location);
generic = setAccountInfo(generic, sample.getDepositor());
samples.add(generic);
continue;
}
StorageLocation storageLocation = storage.toDataTransferObject();
while (storage.getParent() != null) {
storage = storage.getParent();
StorageLocation parentLocation = storage.toDataTransferObject();
parentLocation.setChild(storageLocation);
storageLocation = parentLocation;
boolean isParent = (storageLocation.getType() != null && storageLocation.getType().isTopLevel());
if (isParent)
break;
}
// get specific sample type and details about it
PartSample partSample = new PartSample();
partSample.setId(sample.getId());
partSample.setPartId(sample.getEntry().getId());
partSample.setLocation(storageLocation);
partSample.setPartName(sample.getEntry().getName());
partSample.setLabel(sample.getLabel());
if (sample.getEntry().getId() == entry.getId()) {
partSample.setCreationTime(sample.getCreationTime().getTime());
partSample.setInCart(inCart);
partSample.setCanEdit(sampleAuthorization.canWrite(userId, sample));
if (sample.getComments() != null) {
for (Comment comment : sample.getComments()) {
UserComment userComment = new UserComment();
userComment.setId(comment.getId());
userComment.setMessage(comment.getBody());
partSample.getComments().add(userComment);
}
}
} else {
partSample.setCanEdit(false);
}
partSample = setAccountInfo(partSample, sample.getDepositor());
samples.add(partSample);
}
return samples;
}
use of org.jbei.ice.lib.dto.comment.UserComment in project ice by JBEI.
the class SampleServiceTest method testRetrieveEntrySamples.
@Test
public void testRetrieveEntrySamples() throws Exception {
Account account = AccountCreator.createTestAccount("SampleServiceTest.testRetrieveEntrySamples", false);
String userId = account.getEmail();
Strain strain = TestEntryCreator.createTestStrain(account);
long entryId = strain.getId();
List<PartSample> samplesList = service.retrieveEntrySamples(userId, Long.toString(entryId));
Assert.assertNotNull(samplesList);
for (PartSample partSample : samplesList) {
Assert.assertNotNull(partSample.getId());
Assert.assertNotNull(partSample.getCreationTime());
Assert.assertNotNull(partSample.getLabel());
Assert.assertNotNull(partSample.getLocation());
Assert.assertNotNull(partSample.getDepositor());
Assert.assertNotNull(partSample.getId());
Assert.assertNotNull(partSample.isCanEdit());
StorageLocation location = partSample.getLocation();
while (location.getChild() != null) {
location = location.getChild();
Assert.assertNotNull(location.getType());
Assert.assertNotNull(location.getId());
Assert.assertNotNull(location.getDisplay());
Assert.assertNotNull(location.getName());
}
if (partSample.getComments() != null) {
for (UserComment comment : partSample.getComments()) {
Assert.assertNotNull(comment.getId());
Assert.assertNotNull(comment.getMessage());
}
}
}
}
use of org.jbei.ice.lib.dto.comment.UserComment in project ice by JBEI.
the class EntryController method createEntryComment.
public UserComment createEntryComment(String userId, long partId, UserComment newComment) {
Entry entry = dao.get(partId);
if (entry == null)
return null;
authorization.canRead(userId, entry);
Account account = accountController.getByEmail(userId);
Comment comment = new Comment();
comment.setAccount(account);
comment.setEntry(entry);
comment.setBody(newComment.getMessage());
comment.setCreationTime(new Date());
comment = commentDAO.create(comment);
if (newComment.getSamples() != null) {
SampleDAO sampleDAO = DAOFactory.getSampleDAO();
for (PartSample partSample : newComment.getSamples()) {
Sample sample = sampleDAO.get(partSample.getId());
if (sample == null)
continue;
comment.getSamples().add(sample);
sample.getComments().add(comment);
}
}
comment = commentDAO.update(comment);
return comment.toDataTransferObject();
}
Aggregations