Skip to content
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

feat(companyData): enhance GET: /api/administration/companyData/missing-sd-document #1236

Merged
merged 3 commits into from
Jan 30, 2025

Conversation

Phil91
Copy link
Member

@Phil91 Phil91 commented Jan 15, 2025

Description

Add SdSkipped Date to GET: /api/administration/companyData/missing-sd-document

Why

To get an overview when the process was skipped

Issue

Refs: #1179

Checklist

  • I have followed the contributing guidelines
  • I have performed IP checks for added or updated 3rd party libraries
  • I have created and linked IP issues or requested their creation by a committer
  • I have performed a self-review of my own code
  • I have successfully tested my changes locally
  • I have added tests that prove my changes work
  • I have checked that new and existing tests pass locally with my changes
  • I have commented my code, particularly in hard-to-understand areas

@Phil91 Phil91 force-pushed the feature/1179-companydata branch from 1966764 to 97c5064 Compare January 16, 2025 11:12
@Phil91 Phil91 added this to the Release 25.03 milestone Jan 28, 2025
Copy link
Contributor

@ntruchsess ntruchsess left a comment

Choose a reason for hiding this comment

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

I did suggest a refactored query that should translate into the expected sql, but I suspect the data that is being selected is actually not correct as there is no guarantee that skipped process-steps refer to the most recent process-activity of the respective process. (In case a process is retriggered the previously created processStep instances in status skipped will just stay while a new processStep in status TODO is being created).

c.BusinessPartnerNumber,
c.Name,
c.Shortname,
GetCompanyLastChangeDate(c) == null ?
Copy link
Contributor

Choose a reason for hiding this comment

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

this check is redundant - the expression translates into sql. On the database the selected column-value is just null in case the join of a table itself has no results.
Actually I'm surprised the corresponding test runs without error. I suspect this doesn't compile into SQL but runs on client-side. (the called static method also contains syntax that would not compile as the 'is' keyword is not supported within an expression).

Copy link
Member Author

Choose a reason for hiding this comment

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

seems like if one uses an method for the expression generation the check isn't working correctly. As soon as I moved the expression back to the origin I saw a warning.

{
ProcessStepTypeId: ProcessStepTypeId.START_SELF_DESCRIPTION_LP,
ProcessStepStatusId: ProcessStepStatusId.SKIPPED
})).FirstOrDefault();
Copy link
Contributor

Choose a reason for hiding this comment

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

as according to the database-schema there could be multiple matches just selecting the first without enforcing a specific order will eventually return an incorrect result.

Copy link
Member Author

Choose a reason for hiding this comment

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

added the orderBy

ca.ApplicationChecklistEntries.Any(a =>
a.ApplicationChecklistEntryTypeId == ApplicationChecklistEntryTypeId.SELF_DESCRIPTION_LP &&
a.ApplicationChecklistEntryStatusId != ApplicationChecklistEntryStatusId.SKIPPED) &&
ca.ChecklistProcess!.ProcessSteps.Any(ps =>
Copy link
Contributor

Choose a reason for hiding this comment

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

this condition is redundant to the Where-condition within the SelectMany. As this should compile into SQL (which I suppose it doesn't anyway) it will just create more complicated SQL with no runtime benefit.

Comment on lines 431 to 449
GetCompanyLastChangeDate(c)!.DateLastChanged)
).SingleOrDefaultAsync();

private static ProcessStep? GetCompanyLastChangeDate(Company company) => company.CompanyApplications.Where(ca =>
ca.ApplicationChecklistEntries.Any(a =>
a.ApplicationChecklistEntryTypeId == ApplicationChecklistEntryTypeId.SELF_DESCRIPTION_LP &&
a.ApplicationChecklistEntryStatusId != ApplicationChecklistEntryStatusId.SKIPPED) &&
ca.ChecklistProcess!.ProcessSteps.Any(ps =>
ps is
{
ProcessStepTypeId: ProcessStepTypeId.START_SELF_DESCRIPTION_LP,
ProcessStepStatusId: ProcessStepStatusId.SKIPPED
}))
.SelectMany(ca => ca.ChecklistProcess!.ProcessSteps.Where(ps =>
ps is
{
ProcessStepTypeId: ProcessStepTypeId.START_SELF_DESCRIPTION_LP,
ProcessStepStatusId: ProcessStepStatusId.SKIPPED
})).FirstOrDefault();
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
GetCompanyLastChangeDate(c)!.DateLastChanged)
).SingleOrDefaultAsync();
private static ProcessStep? GetCompanyLastChangeDate(Company company) => company.CompanyApplications.Where(ca =>
ca.ApplicationChecklistEntries.Any(a =>
a.ApplicationChecklistEntryTypeId == ApplicationChecklistEntryTypeId.SELF_DESCRIPTION_LP &&
a.ApplicationChecklistEntryStatusId != ApplicationChecklistEntryStatusId.SKIPPED) &&
ca.ChecklistProcess!.ProcessSteps.Any(ps =>
ps is
{
ProcessStepTypeId: ProcessStepTypeId.START_SELF_DESCRIPTION_LP,
ProcessStepStatusId: ProcessStepStatusId.SKIPPED
}))
.SelectMany(ca => ca.ChecklistProcess!.ProcessSteps.Where(ps =>
ps is
{
ProcessStepTypeId: ProcessStepTypeId.START_SELF_DESCRIPTION_LP,
ProcessStepStatusId: ProcessStepStatusId.SKIPPED
})).FirstOrDefault();
c.CompanyApplications
.Where(ca =>
ca.ApplicationChecklistEntries.Any(a =>
a.ApplicationChecklistEntryTypeId == ApplicationChecklistEntryTypeId.SELF_DESCRIPTION_LP &&
a.ApplicationChecklistEntryStatusId != ApplicationChecklistEntryStatusId.SKIPPED))
.SelectMany(ca =>
ca.ChecklistProcess!.ProcessSteps.Where(ps =>
ps.ProcessStepTypeId == ProcessStepTypeId.START_SELF_DESCRIPTION_LP &&
ps.ProcessStepStatusId == ProcessStepStatusId.SKIPPED))
.OrderByDescending(ps => ps.DateLastChanged)
.FirstOrDefault()!.DateLastChanged)

@Phil91 Phil91 force-pushed the feature/1179-companydata branch 2 times, most recently from 2ba03da to 0dcd9c8 Compare January 30, 2025 07:45
@Phil91 Phil91 force-pushed the feature/1179-companydata branch from 0dcd9c8 to fee93ee Compare January 30, 2025 07:48
@Phil91 Phil91 requested a review from ntruchsess January 30, 2025 07:51
ntruchsess
ntruchsess previously approved these changes Jan 30, 2025
@ntruchsess ntruchsess merged commit a676ac4 into main Jan 30, 2025
11 checks passed
@ntruchsess ntruchsess deleted the feature/1179-companydata branch January 30, 2025 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: USER READY
Development

Successfully merging this pull request may close these issues.

2 participants