Skip to content

OBPIH-5826 comment indication approvals comment#4429

Merged
awalkowiak merged 5 commits intofeature/upgrade-to-grails-3.3.10from
OBPIH-5826-comment-indication-approvals-comment
Feb 1, 2024
Merged

OBPIH-5826 comment indication approvals comment#4429
awalkowiak merged 5 commits intofeature/upgrade-to-grails-3.3.10from
OBPIH-5826-comment-indication-approvals-comment

Conversation

@drodzewicz
Copy link
Collaborator

@drodzewicz drodzewicz commented Dec 20, 2023

follow the discussion in the ticket

  • add derived property currentEvent to stock movement
  • use currentEvent to get the comment for a approval status if (status in approvalStatus) display currentEvent.comment
  • remove requisitonComments and recentRequisitionComments

@drodzewicz drodzewicz added warn: do not merge Marks a pull request that is not yet ready to be merged status: needs discussion An issue that needs further discussion before it can proceed. labels Dec 20, 2023
@drodzewicz drodzewicz added this to the 0.9.1 milestone Dec 20, 2023
@drodzewicz drodzewicz self-assigned this Dec 20, 2023
@drodzewicz drodzewicz changed the title Obpih 5826 comment indication approvals comment OBPIH-5826 comment indication approvals comment Dec 20, 2023
@drodzewicz drodzewicz marked this pull request as ready for review December 21, 2023 09:44
if (!shipmentInstance) {
throw new Exception("Could not locate shipment with ID " + params.shipmentId)
}
User recipient = (params.recipientId) ? User.get(params.recipientId) : null
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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..

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpicky: indent

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's weird that ESLint did not throw an error on it, thanks for noticing

trackingNumber : trackingNumber,
driverName : driverName,
comments : comments,
recentComment : recentComment,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe org.hibernate.ObjectNotFoundException could be a good candidate

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

}
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])}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's pass the shipmentId instead of the instance and do the lookup in the service method.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

}
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])}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@drodzewicz drodzewicz force-pushed the OBPIH-5826-comment-indication-approvals-comment branch from b691ac3 to ff4fcbc Compare January 31, 2024 13:51
@awalkowiak awalkowiak removed warn: do not merge Marks a pull request that is not yet ready to be merged status: needs discussion An issue that needs further discussion before it can proceed. labels Feb 1, 2024
@awalkowiak awalkowiak merged commit a376456 into feature/upgrade-to-grails-3.3.10 Feb 1, 2024
@awalkowiak awalkowiak deleted the OBPIH-5826-comment-indication-approvals-comment branch February 1, 2024 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants