OBPIH-5826 comment indication approvals comment#4429
Conversation
| if (!shipmentInstance) { | ||
| throw new Exception("Could not locate shipment with ID " + params.shipmentId) | ||
| } | ||
| User recipient = (params.recipientId) ? User.get(params.recipientId) : null |
There was a problem hiding this comment.
I know it's been there and you might've not realized that, but I think User.get(params.recipientId) should be enough.... unless there is a possibility that user's id would be null..
There was a problem hiding this comment.
I did not pay much attention toit, I'll try to mak sure that recipient is not null and if everything will be fine I'll fix it to be just User.get(recipientId)
| return referenceNumber | ||
| } | ||
|
|
||
| Comment addShipmentComment(Shipment shipment, String content, User sender, User recipient) { |
There was a problem hiding this comment.
I don't mind it, but probably according to our code conventions, we shouldn't have more than 3 arguments (?) 🤔
I believe we need to figure out a way how to deal with such cases (command object??)
| {row.original.displayStatus} | ||
| </span> | ||
| {row.original.recentComment && ( | ||
| <Tooltip |
There was a problem hiding this comment.
it's weird that ESLint did not throw an error on it, thanks for noticing
| trackingNumber : trackingNumber, | ||
| driverName : driverName, | ||
| comments : comments, | ||
| recentComment : recentComment, |
There was a problem hiding this comment.
I agree with you something doesn't feel right about that - I mean, we only care about the shipmentComments - what if we decided to care about the requisition comments also?
Would we then want to distinguish shipment/requisition recent comment or how would we want to approach that?
I don't know the scope much to be able to answer that question.
There was a problem hiding this comment.
yes, the whole comments hierarchy should be reevaluated like, which comments does the StockMovement inherit? The Shipment comments? Requisition comments? Order Comments?
Maybe we should mash all of those comments in a common list and extract the most recent one regardless of it's origin?
There was a problem hiding this comment.
Yeah, we need to rewrite the APIs completely. This is a case where we've overloaded StockMovement to do so many things and it's showing signs of collapse.
There was a problem hiding this comment.
Can you explain what "recentComment" is for? I know it's probably related to the requisition approval, but I want to know specific use case without digging through the code. I suspect this is a case where the codes needs to be more specific about what we're trying to accomplish i.e. getApprovalComment. And that makes me feel like we need to do something similar to synonyms where we need to classify comments according to their purpose instead of just getting the latest comment.
| Comment getRecentComment() { | ||
| if (shipmentComments?.size() > 0) { | ||
| return shipmentComments?.sort({ a, b -> | ||
| b.dateCreated <=> a.dateCreated |
There was a problem hiding this comment.
shouldn't we look at lastUpdated instead of dateCreated? Maybe I don't know the scope very well, but I see that the compareTo method in Comment looks at the lastUpdated date.
If we do want to look at lastUpdated, a titbit: you could just write .sort(), since we have compareTo overwritten.
There was a problem hiding this comment.
yeah, this is up for debate what do we consider "the most recent comment" in my opinion it's based on date created since that's usually how it is sorted in many comment sections and messengers.
| flash.message = "${warehouse.message(code: 'shipping.addedCommentToShipment.message', args: [params.comment, shipmentInstance.name])}" | ||
| Shipment shipmentInstance = Shipment.get(params.shipmentId) | ||
| if (!shipmentInstance) { | ||
| throw new Exception("Could not locate shipment with ID " + params.shipmentId) |
There was a problem hiding this comment.
maybe let's come up with a more specific exception? using the general Exception doesn't feel right to me.
Maybe we should start creating our own exceptions and define them? e.g. NotFoundException?
There was a problem hiding this comment.
I believe org.hibernate.ObjectNotFoundException could be a good candidate
| } | ||
| User recipient = (params.recipientId) ? User.get(params.recipientId) : null | ||
| shipmentService.addShipmentComment(shipmentInstance, params.comment, session.user, recipient) | ||
| flash.message = "${warehouse.message(code: 'shipping.addedCommentToShipment.message', args: [params.comment, shipmentInstance.name])}" |
There was a problem hiding this comment.
the problem with that is since the ShipmentController is @Transactional, you start and end the transaction boundary in the controller, hence if anything goes wrong while persisting the comment, you will still get the success message in the view, because the exception will happen at the end of the session, not while executing the 896th line.
There was a problem hiding this comment.
I know we may have encountered issues like this in the past, but let's confirm this the actual behavior.
| throw new Exception("Could not locate shipment with ID " + params.shipmentId) | ||
| } | ||
| User recipient = (params.recipientId) ? User.get(params.recipientId) : null | ||
| shipmentService.addShipmentComment(shipmentInstance, params.comment, session.user, recipient) |
There was a problem hiding this comment.
Remove extra space between comment and user.
| flash.message = "${warehouse.message(code: 'shipping.addedCommentToShipment.message', args: [params.comment, shipmentInstance.name])}" | ||
| Shipment shipmentInstance = Shipment.get(params.shipmentId) | ||
| if (!shipmentInstance) { | ||
| throw new Exception("Could not locate shipment with ID " + params.shipmentId) |
There was a problem hiding this comment.
Let's pass the shipmentId instead of the instance and do the lookup in the service method.
There was a problem hiding this comment.
Note: this comment was written weeks ago before I stumbled upon @kchelstowski's command object proposal. So this can probably be safely ignored if we go the command object route.
| flash.message = "${warehouse.message(code: 'shipping.addedCommentToShipment.message', args: [params.comment, shipmentInstance.name])}" | ||
| Shipment shipmentInstance = Shipment.get(params.shipmentId) | ||
| if (!shipmentInstance) { | ||
| throw new Exception("Could not locate shipment with ID " + params.shipmentId) |
| } | ||
| User recipient = (params.recipientId) ? User.get(params.recipientId) : null | ||
| shipmentService.addShipmentComment(shipmentInstance, params.comment, session.user, recipient) | ||
| flash.message = "${warehouse.message(code: 'shipping.addedCommentToShipment.message', args: [params.comment, shipmentInstance.name])}" |
There was a problem hiding this comment.
I know we may have encountered issues like this in the past, but let's confirm this the actual behavior.
| trackingNumber : trackingNumber, | ||
| driverName : driverName, | ||
| comments : comments, | ||
| recentComment : recentComment, |
There was a problem hiding this comment.
Yeah, we need to rewrite the APIs completely. This is a case where we've overloaded StockMovement to do so many things and it's showing signs of collapse.
| trackingNumber : trackingNumber, | ||
| driverName : driverName, | ||
| comments : comments, | ||
| recentComment : recentComment, |
There was a problem hiding this comment.
Can you explain what "recentComment" is for? I know it's probably related to the requisition approval, but I want to know specific use case without digging through the code. I suspect this is a case where the codes needs to be more specific about what we're trying to accomplish i.e. getApprovalComment. And that makes me feel like we need to do something similar to synonyms where we need to classify comments according to their purpose instead of just getting the latest comment.
| driverName: shipment.driverName, | ||
| trackingNumber: trackingNumber?.identifier, | ||
| comments: shipment.additionalInformation, | ||
| shipmentComments: shipment.comments, |
There was a problem hiding this comment.
If possible, I would like this to replace the "comments" property at some point. We can move "comments" to "additionalInformation" or try to figure out how we might allow the additionalInformation to be come an instance within the "comments" list. This is where we'd need to have a way to classify comments as we'd only ever want one of these "additionalInformation" comments to be added to stockMovement.comments.
- remove previous approach with recentRequsiitionComment - return currentEvent with comment
b691ac3 to
ff4fcbc
Compare
follow the discussion in the ticket