-
-
Notifications
You must be signed in to change notification settings - Fork 403
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OBPIH-5840 Create a Dashboard indicator for number of requests waiting for approval #4424
Conversation
Pushing the first part of this ticket which can be reviewed, but waiting for feedback on questions left in the ticket comments. |
163e9d6
to
ec095d6
Compare
grails-app/controllers/org/pih/warehouse/api/DashboardApiController.groovy
Outdated
Show resolved
Hide resolved
def openStockRequests = Requisition.executeQuery(""" | ||
SELECT COUNT(distinct r.id) FROM Requisition r | ||
WHERE r.origin = :location | ||
AND r.sourceType = :sourceType | ||
AND r.status = :status | ||
""", | ||
[ | ||
'location': location, | ||
'sourceType' : RequisitionSourceType.ELECTRONIC, | ||
'status' : RequisitionStatus.PENDING_APPROVAL, | ||
]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be better to use createCritera here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would go even further and give the data service method a shot (as I can see we already have the RequisitionDataService
, so this would require implementing only a method)
int countByOriginAndSourceTypeAndStatus(Location origin, RequisitionSourceType sourceType, RequisitionStatus status)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously I was just following the example of other NumberService methods which compute data with pure SQL statements, but you are right something like a createCriteria()
looks a bit more friendly so I went with that approach
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also tested your suggestion @kchelstowski with countByOriginAndSourceTypeAndStatus()
but I realized that we need to cache this indicator and the keys are location.id
and currentUser.id
so either way i would need to call this RequisitionDataService
method in a NumberDataService
so it creates a little more clutter and methods that we have to maintain so I decided to go with createCriteria()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although now that I think about it, I remember you mentioning something that GORM Data Service methods are much faster than the standard criteria ones, so this might be a reason to use the DataService instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@drodzewicz could you elaborate a bit on the fact that you couldn't use the data service method here? I don't mind the createCriteria()
approach, but wanted to understand why the data service method didn't fit there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although now that I think about it, I remember you mentioning something that GORM Data Service methods are much faster than the standard criteria ones, so this might be a reason to use the DataService instead?
I think I've never said they are faster - it should probably evaluate to the same SQL query as the data service method, but imho they are just more readable and they don't require that much of "boilerplate" code - e.g. the createCriteria
approach here took more lines than one-liner data service method.
String redirectLink = currentUser.hasRoles(location, [RoleType.ROLE_REQUISITION_APPROVER]) | ||
? "${urlContextPath}/stockMovement/list?direction=OUTBOUND&requisitionStatusCode=PENDING_APPROVAL&sourceType=ELECTRONIC" | ||
: "${urlContextPath}/stockMovement/list?direction=OUTBOUND&sourceType=ELECTRONIC" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks odd to me, but I don't have any idea how to improve that, maybe someone else can come up with a better solution?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, imho we should also think about creating a url factory (similar to the frontend one) as a tech debt ticket.
In here, at the very least, I'd suggest using consts for the param values:
?direction=StockMovementDirection.OUTBOUND&requisitionStatusCode=RequisitionStatus.PENDING_APPROVAL&sourceType=RequisitionSourceType.ELECTRONIC
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead I decided to use the createLink(...)
method which is provided by ApplicationTagLib
.
That way we don;t have manually prepend the contextPath and we can use the enums and other values in the parameters which later builds the propper string link just like we want to.
def openStockRequests = Requisition.executeQuery(""" | ||
SELECT COUNT(distinct r.id) FROM Requisition r | ||
WHERE r.origin = :location | ||
AND r.sourceType = :sourceType | ||
AND r.status = :status | ||
""", | ||
[ | ||
'location': location, | ||
'sourceType' : RequisitionSourceType.ELECTRONIC, | ||
'status' : RequisitionStatus.PENDING_APPROVAL, | ||
]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would go even further and give the data service method a shot (as I can see we already have the RequisitionDataService
, so this would require implementing only a method)
int countByOriginAndSourceTypeAndStatus(Location origin, RequisitionSourceType sourceType, RequisitionStatus status)
String redirectLink = currentUser.hasRoles(location, [RoleType.ROLE_REQUISITION_APPROVER]) | ||
? "${urlContextPath}/stockMovement/list?direction=OUTBOUND&requisitionStatusCode=PENDING_APPROVAL&sourceType=ELECTRONIC" | ||
: "${urlContextPath}/stockMovement/list?direction=OUTBOUND&sourceType=ELECTRONIC" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, imho we should also think about creating a url factory (similar to the frontend one) as a tech debt ticket.
In here, at the very least, I'd suggest using consts for the param values:
?direction=StockMovementDirection.OUTBOUND&requisitionStatusCode=RequisitionStatus.PENDING_APPROVAL&sourceType=RequisitionSourceType.ELECTRONIC
…ia intead of pure SQL and build redirect URLs with createLink
86eb0bc
to
9f9c76f
Compare
…g for approval (#4424) * OBPIH-5840 Create a Dashboard indicator for number of requests waiting for approval * OBPIH-5840 Fix cachablity of indicator when switching users * OBPIH-5840 refactor requestPendingApproval method to use createCriteria intead of pure SQL and build redirect URLs with createLink
No description provided.