Define the query logic
Next, you must define the query that executes the search.
The base configuration includes a class where the query is to be defined. It is called
RecoverNewJobsExtResource
, and it is declared in the
gw.rest.ext.pc.job.v1.security
package.
The class has a single getter named RecoverNewJobsWrapper
. In the base
configuration, it simply returns a new RecoverNewJobsWrapperExt
instance. The base configuration version looks similar to this:
package gw.rest.ext.pc.job.v1.security
uses gw.rest.core.pc.job.v1.security.RecoverNewJobsCoreResource
uses gw.rest.core.pc.job.v1.security.RecoverNewJobsWrapper
@Export
class RecoverNewJobsExtResource extends RecoverNewJobsCoreResource {
protected override property get RecoverNewJobsWrapper() : RecoverNewJobsWrapper {
return new RecoverNewJobsWrapperExt()
}
}
To enable new job recovery, add a method override to the class that overrides the
populateRecoverNewJobsQuery
method. The new method must return a
PolicyPeriod query that specifies whatever query restrictions are required based on the
search criteria properties. The following is a high-level syntax statement for the
method.
protected override function populateRecoverNewJobsQuery(recoverNewJobsWrapper :
RecoverNewJobsWrapper) : IQueryBeanResult<PolicyPeriod> {
// code that defines query with appropriate search criteria
return <some_value_of_type_IQueryBeanResult<PolicyPeriod>_>
}
For more information on writing Gosu queries, see the Gosu Reference Guide. You can also
refer to the makeQueryBuilderForNormalSearches
method in the
PolicyPeriodSearchCriteria.gs for more example properties.
Sample RecoverNewJobsExtResource
class
The sample implementation supports new job recovery search on the following values:
- Account number
- Job number
- First name (of the primary insured)
- Last name (of the primary insured)
- Postal code (of the primary insured)
Thus, the RecoverNewJobsWrapper
getter does the following for each
search criteria property:
- Checks to see if a value was provided for the property
- Adds the corresponding query logic to the query, if a value was provided
This is what the class looks like after configuration. Comments in the code appear in bold.
package gw.rest.ext.pc.job.v1.security
uses gw.account.AccountQueryBuilder
uses gw.api.database.IQueryBeanResult
uses gw.contact.ContactQueryBuilder
uses gw.contact.PolicyContactRoleQueryBuilder
uses gw.job.JobQueryBuilder
uses gw.policy.PolicyPeriodQueryBuilder
uses gw.policy.PolicyQueryBuilder
uses gw.rest.core.pc.job.v1.security.RecoverNewJobsCoreResource
uses gw.rest.core.pc.job.v1.security.RecoverNewJobsWrapper
@Export
class RecoverNewJobsExtResource extends RecoverNewJobsCoreResource {
protected override property get RecoverNewJobsWrapper() : RecoverNewJobsWrapper {
return new RecoverNewJobsWrapperExt()
}
// Start of the populateRecoverNewJobsQuery override
protected override function populateRecoverNewJobsQuery(recoverNewJobsWrapper : RecoverNewJobsWrapper) : IQueryBeanResult<PolicyPeriod> {
// Create a new PolicyPeriod query.
var queryBuilder = new PolicyPeriodQueryBuilder()
// If the job number was specified, add it to the criteria
if ((recoverNewJobsWrapper as RecoverNewJobsWrapperExt).JobNumber != null) {
var jobQueryBuilder = new JobQueryBuilder()
.withJobNumber((recoverNewJobsWrapper as RecoverNewJobsWrapperExt).JobNumber)
queryBuilder.withJob(jobQueryBuilder)
}
// If the account number was specified, add it to the criteria
if ((recoverNewJobsWrapper as RecoverNewJobsWrapperExt).AccountNumber != null) {
var policyQueryBuilder = new PolicyQueryBuilder()
.withAccount(new AccountQueryBuilder().withAccountNumber((recoverNewJobsWrapper as RecoverNewJobsWrapperExt).AccountNumber))
queryBuilder.withPolicy(policyQueryBuilder)
}
if ((recoverNewJobsWrapper as RecoverNewJobsWrapperExt).AccountNumber.NotBlank) {
queryBuilder.withUseAnyArrayForPolicyContactRoleSearch(false)
}
// Add First Name, Last Name, and Postal Code criteria
var contactQueryBuilder = new ContactQueryBuilder()
.withFirstName((recoverNewJobsWrapper as RecoverNewJobsWrapperExt).FirstName)
.withLastName((recoverNewJobsWrapper as RecoverNewJobsWrapperExt).LastName)
.withPostalCodeDenorm((recoverNewJobsWrapper as RecoverNewJobsWrapperExt).PostalCode)
// Limit the query to match First Name, Last Name, and Postal Code only
for contacts whose role on the policy the primary insured
var policyContactRoleQueryBuilder = new PolicyContactRoleQueryBuilder()
.withSubtype(TC_POLICYPRINAMEDINSURED)
.withContactDenorm(contactQueryBuilder)
queryBuilder.withPolicyContactRole(policyContactRoleQueryBuilder)
// Return the query
return queryBuilder.build().select() as IQueryBeanResult<PolicyPeriod>
}
}