Skip to content

Commit

Permalink
FINERACT-2025 SQL Query Improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
reluxa committed Dec 7, 2023
1 parent cb40f23 commit 5a8a2b9
Show file tree
Hide file tree
Showing 16 changed files with 105 additions and 169 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,8 @@ private List<OfficeData> fetchOffices(final Long officeId) {
List<OfficeData> offices = null;
if (officeId == null) {
Boolean includeAllOffices = Boolean.TRUE;
offices = (List) this.officeReadPlatformService.retrieveAllOffices(includeAllOffices, new SearchParameters(null, null, null,
null, null, null, null, null, null, "id", "asc", null, null, null, null, null, null));
offices = (List) this.officeReadPlatformService.retrieveAllOffices(includeAllOffices,
new SearchParameters(null, null, null, null, null, null, null, null, "id", "asc", null, null, null, null, null, null));
} else {
offices = new ArrayList<>();
offices.add(this.officeReadPlatformService.retrieveOffice(officeId));
Expand Down Expand Up @@ -341,7 +341,7 @@ private List<CenterData> fetchCenters(Long officeId) {
if (officeId == null) {
centers = (List<CenterData>) this.centerReadPlatformService.retrieveAll(null, null);
} else {
SearchParameters searchParameters = SearchParameters.from(null, officeId, null, null, null);
SearchParameters searchParameters = SearchParameters.from(officeId, null, null, null);
centers = (List<CenterData>) centerReadPlatformService.retrieveAll(searchParameters, null);
}

Expand All @@ -359,7 +359,7 @@ private List<ClientData> fetchClients(Long officeId) {
}
}
} else {
SearchParameters searchParameters = SearchParameters.from(null, officeId, null, null, null);
SearchParameters searchParameters = SearchParameters.from(officeId, null, null, null);
Page<ClientData> clientDataPage = this.clientReadPlatformService.retrieveAll(searchParameters);
if (clientDataPage != null) {
clients = new ArrayList<>();
Expand Down Expand Up @@ -420,7 +420,7 @@ private List<GroupGeneralData> fetchGroups(Long officeId) {
if (officeId == null) {
groups = (List<GroupGeneralData>) this.groupReadPlatformService.retrieveAll(null, null);
} else {
SearchParameters searchParameters = SearchParameters.from(null, officeId, null, null, null);
SearchParameters searchParameters = SearchParameters.from(officeId, null, null, null);
groups = (List<GroupGeneralData>) groupReadPlatformService.retrieveAll(searchParameters, null);
}

Expand Down Expand Up @@ -448,7 +448,7 @@ private List<LoanAccountData> fetchLoanAccounts(final Long officeId) {
if (officeId == null) {
loanAccounts = loanReadPlatformService.retrieveAll(null).getPageItems();
} else {
SearchParameters searchParameters = SearchParameters.from(null, officeId, null, null, null);
SearchParameters searchParameters = SearchParameters.from(officeId, null, null, null);
loanAccounts = loanReadPlatformService.retrieveAll(searchParameters).getPageItems();
}
return loanAccounts;
Expand Down Expand Up @@ -488,12 +488,11 @@ private WorkbookPopulator populateGuarantorWorkbook(Long officeId) {

private List<SavingsAccountData> fetchSavingsAccounts(Long officeId) {
List<SavingsAccountData> savingsAccounts = null;
String activeAccounts = "sa.status_enum = 300";
if (officeId != null) {
SearchParameters searchParameters = SearchParameters.from(activeAccounts, officeId, null, null, null);
SearchParameters searchParameters = SearchParameters.builder().officeId(officeId).status("300").build();
savingsAccounts = savingsAccountReadPlatformService.retrieveAll(searchParameters).getPageItems();
} else {
SearchParameters searchParameters = SearchParameters.from(activeAccounts, null, null, null, null);
SearchParameters searchParameters = SearchParameters.builder().status("300").build();
savingsAccounts = savingsAccountReadPlatformService.retrieveAll(searchParameters).getPageItems();
}
return savingsAccounts;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,26 +74,24 @@ public String retrieveAllEmails(@Context final UriInfo uriInfo) {

@GET
@Path("pendingEmail")
public String retrievePendingEmail(@QueryParam("sqlSearch") final String sqlSearch, @QueryParam("offset") final Integer offset,
@QueryParam("limit") final Integer limit, @QueryParam("orderBy") final String orderBy,
@QueryParam("sortOrder") final String sortOrder, @Context final UriInfo uriInfo) {
public String retrievePendingEmail(@QueryParam("offset") final Integer offset, @QueryParam("limit") final Integer limit,
@QueryParam("orderBy") final String orderBy, @QueryParam("sortOrder") final String sortOrder, @Context final UriInfo uriInfo) {

context.authenticatedUser().validateHasReadPermission(RESOURCE_NAME_FOR_PERMISSIONS);
final SearchParameters searchParameters = SearchParameters.forEmailCampaign(sqlSearch, offset, limit, orderBy, sortOrder);
final SearchParameters searchParameters = SearchParameters.forEmailCampaign(offset, limit, orderBy, sortOrder);
Collection<EmailData> emailMessages = readPlatformService.retrieveAllPending(searchParameters);
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
return toApiJsonSerializer.serialize(settings, emailMessages);
}

@GET
@Path("sentEmail")
public String retrieveSentEmail(@QueryParam("sqlSearch") final String sqlSearch, @QueryParam("offset") final Integer offset,
@QueryParam("limit") final Integer limit, @QueryParam("orderBy") final String orderBy,
@QueryParam("sortOrder") final String sortOrder, @Context final UriInfo uriInfo) {
public String retrieveSentEmail(@QueryParam("offset") final Integer offset, @QueryParam("limit") final Integer limit,
@QueryParam("orderBy") final String orderBy, @QueryParam("sortOrder") final String sortOrder, @Context final UriInfo uriInfo) {

context.authenticatedUser().validateHasReadPermission(RESOURCE_NAME_FOR_PERMISSIONS);

final SearchParameters searchParameters = SearchParameters.forEmailCampaign(sqlSearch, offset, limit, orderBy, sortOrder);
final SearchParameters searchParameters = SearchParameters.forEmailCampaign(offset, limit, orderBy, sortOrder);
Collection<EmailData> emailMessages = readPlatformService.retrieveAllSent(searchParameters);

final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
Expand Down Expand Up @@ -133,7 +131,7 @@ public String retrieveFailedEmail(@QueryParam("sqlSearch") final String sqlSearc

context.authenticatedUser().validateHasReadPermission(RESOURCE_NAME_FOR_PERMISSIONS);

final SearchParameters searchParameters = SearchParameters.forEmailCampaign(sqlSearch, offset, limit, orderBy, sortOrder);
final SearchParameters searchParameters = SearchParameters.forEmailCampaign(offset, limit, orderBy, sortOrder);
Collection<EmailData> emailMessages = readPlatformService.retrieveAllFailed(searchParameters);

final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,10 @@ public String retrieveCampaign(@PathParam("resourceId") final Long resourceId, @
smscampaigns""")
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = SmsCampaignData.class)))
public String retrieveAllEmails(@QueryParam("sqlSearch") final String sqlSearch, @QueryParam("offset") final Integer offset,
@QueryParam("limit") final Integer limit, @QueryParam("orderBy") final String orderBy,
@QueryParam("sortOrder") final String sortOrder, @Context final UriInfo uriInfo) {
public String retrieveAllEmails(@QueryParam("offset") final Integer offset, @QueryParam("limit") final Integer limit,
@QueryParam("orderBy") final String orderBy, @QueryParam("sortOrder") final String sortOrder, @Context final UriInfo uriInfo) {
platformSecurityContext.authenticatedUser().validateHasReadPermission(SmsCampaignConstants.RESOURCE_NAME);
final SearchParameters searchParameters = SearchParameters.forSMSCampaign(sqlSearch, offset, limit, orderBy, sortOrder);
final SearchParameters searchParameters = SearchParameters.forSMSCampaign(offset, limit, orderBy, sortOrder);
Page<SmsCampaignData> smsCampaignDataCollection = smsCampaignReadPlatformService.retrieveAll(searchParameters);
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
return toApiJsonSerializer.serialize(settings, smsCampaignDataCollection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ public String retrieveOne(@PathParam("resourceId") final Long resourceId, @Conte
public String retrieveAllSmsByStatus(@PathParam("campaignId") final Long campaignId, @Context final UriInfo uriInfo,
@QueryParam("status") final Long status, @QueryParam("fromDate") final DateParam fromDateParam,
@QueryParam("toDate") final DateParam toDateParam, @QueryParam("locale") final String locale,
@QueryParam("dateFormat") final String rawDateFormat, @QueryParam("sqlSearch") final String sqlSearch,
@QueryParam("offset") final Integer offset, @QueryParam("limit") final Integer limit,
@QueryParam("orderBy") final String orderBy, @QueryParam("sortOrder") final String sortOrder) {
@QueryParam("dateFormat") final String rawDateFormat, @QueryParam("offset") final Integer offset,
@QueryParam("limit") final Integer limit, @QueryParam("orderBy") final String orderBy,
@QueryParam("sortOrder") final String sortOrder) {
context.authenticatedUser().validateHasReadPermission(resourceNameForPermissions);
final SearchParameters searchParameters = SearchParameters.forSMSCampaign(sqlSearch, offset, limit, orderBy, sortOrder);
final SearchParameters searchParameters = SearchParameters.forSMSCampaign(offset, limit, orderBy, sortOrder);

final DateFormat dateFormat = StringUtils.isBlank(rawDateFormat) ? null : new DateFormat(rawDateFormat);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ public String create(@Parameter(hidden = true) final String apiRequestBodyAsJson
@ApiResponses({
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = AccountTransfersApiResourceSwagger.GetAccountTransfersResponse.class))) })
public String retrieveAll(@Context final UriInfo uriInfo,
@QueryParam("sqlSearch") @Parameter(description = "sqlSearch") final String sqlSearch,
@QueryParam("externalId") @Parameter(description = "externalId") final String externalId,
@QueryParam("offset") @Parameter(description = "offset") final Integer offset,
@QueryParam("limit") @Parameter(example = "limit") final Integer limit,
Expand All @@ -126,8 +125,7 @@ public String retrieveAll(@Context final UriInfo uriInfo,

this.context.authenticatedUser().validateHasReadPermission(AccountTransfersApiConstants.ACCOUNT_TRANSFER_RESOURCE_NAME);

final SearchParameters searchParameters = SearchParameters.forAccountTransfer(sqlSearch, externalId, offset, limit, orderBy,
sortOrder);
final SearchParameters searchParameters = SearchParameters.forAccountTransfer(externalId, offset, limit, orderBy, sortOrder);

final Page<AccountTransferData> transfers = this.accountTransfersReadPlatformService.retrieveAll(searchParameters, accountDetailId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ private boolean is(final String commandParam, final String commandValue) {
@ApiResponses({
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = StandingInstructionApiResourceSwagger.GetStandingInstructionsResponse.class))) })
public String retrieveAll(@Context final UriInfo uriInfo,
@QueryParam("sqlSearch") @Parameter(description = "sqlSearch") final String sqlSearch,
@QueryParam("externalId") @Parameter(description = "externalId") final String externalId,
@QueryParam("offset") @Parameter(description = "offset") final Integer offset,
@QueryParam("limit") @Parameter(description = "limit") final Integer limit,
Expand All @@ -183,8 +182,7 @@ public String retrieveAll(@Context final UriInfo uriInfo,

this.context.authenticatedUser().validateHasReadPermission(StandingInstructionApiConstants.STANDING_INSTRUCTION_RESOURCE_NAME);

final SearchParameters searchParameters = SearchParameters.forAccountTransfer(sqlSearch, externalId, offset, limit, orderBy,
sortOrder);
final SearchParameters searchParameters = SearchParameters.forAccountTransfer(externalId, offset, limit, orderBy, sortOrder);

final LocalDate startDateRange = null;
final LocalDate endDateRange = null;
Expand All @@ -206,8 +204,7 @@ public String retrieveAll(@Context final UriInfo uriInfo,
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = StandingInstructionApiResourceSwagger.GetStandingInstructionsStandingInstructionIdResponse.class))) })
public String retrieveOne(
@PathParam("standingInstructionId") @Parameter(description = "standingInstructionId") final Long standingInstructionId,
@Context final UriInfo uriInfo, @QueryParam("sqlSearch") @Parameter(description = "sqlSearch") final String sqlSearch,
@QueryParam("externalId") @Parameter(description = "externalId") final String externalId,
@Context final UriInfo uriInfo, @QueryParam("externalId") @Parameter(description = "externalId") final String externalId,
@QueryParam("offset") @Parameter(description = "offset") final Integer offset,
@QueryParam("limit") @Parameter(description = "limit") final Integer limit,
@QueryParam("orderBy") @Parameter(description = "orderBy") final String orderBy,
Expand All @@ -216,8 +213,7 @@ public String retrieveOne(
this.context.authenticatedUser().validateHasReadPermission(StandingInstructionApiConstants.STANDING_INSTRUCTION_RESOURCE_NAME);

StandingInstructionData standingInstructionData = this.standingInstructionReadPlatformService.retrieveOne(standingInstructionId);
final SearchParameters searchParameters = SearchParameters.forAccountTransfer(sqlSearch, externalId, offset, limit, orderBy,
sortOrder);
final SearchParameters searchParameters = SearchParameters.forAccountTransfer(externalId, offset, limit, orderBy, sortOrder);
final Set<String> associationParameters = ApiParameterHelper.extractAssociationsForResponseIfProvided(uriInfo.getQueryParameters());
Page<AccountTransferData> transfers = null;
if (!associationParameters.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public class StandingInstructionHistoryApiResource {
@ApiResponses({
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = StandingInstructionHistoryApiResourceSwagger.GetStandingInstructionRunHistoryResponse.class))) })
public String retrieveAll(@Context final UriInfo uriInfo,
@QueryParam("sqlSearch") @Parameter(description = "sqlSearch") final String sqlSearch,
@QueryParam("externalId") @Parameter(description = "externalId") final String externalId,
@QueryParam("offset") @Parameter(description = "offset") final Integer offset,
@QueryParam("limit") @Parameter(description = "limit") final Integer limit,
Expand All @@ -89,8 +88,7 @@ public String retrieveAll(@Context final UriInfo uriInfo,

final DateFormat dateFormat = StringUtils.isBlank(rawDateFormat) ? null : new DateFormat(rawDateFormat);

final SearchParameters searchParameters = SearchParameters.forAccountTransfer(sqlSearch, externalId, offset, limit, orderBy,
sortOrder);
final SearchParameters searchParameters = SearchParameters.forAccountTransfer(externalId, offset, limit, orderBy, sortOrder);
LocalDate startDateRange = null;
LocalDate endDateRange = null;
if (fromDateParam != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ public String retrieveTemplate(@Context final UriInfo uriInfo,
@ApiResponses({
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = ClientsApiResourceSwagger.GetClientsResponse.class))) })
public String retrieveAll(@Context final UriInfo uriInfo,
@QueryParam("sqlSearch") @Parameter(description = "sqlSearch") final String sqlSearch,
@QueryParam("officeId") @Parameter(description = "officeId") final Long officeId,
@QueryParam("externalId") @Parameter(description = "externalId") final String externalId,
@QueryParam("displayName") @Parameter(description = "displayName") final String displayName,
Expand All @@ -150,8 +149,8 @@ public String retrieveAll(@Context final UriInfo uriInfo,
@QueryParam("sortOrder") @Parameter(description = "sortOrder") final String sortOrder,
@QueryParam("orphansOnly") @Parameter(description = "orphansOnly") final Boolean orphansOnly) {

return retrieveAll(uriInfo, sqlSearch, officeId, externalId, displayName, firstname, lastname, status, hierarchy, offset, limit,
orderBy, sortOrder, orphansOnly, false);
return retrieveAll(uriInfo, officeId, externalId, displayName, firstname, lastname, status, hierarchy, offset, limit, orderBy,
sortOrder, orphansOnly, false);
}

@GET
Expand Down Expand Up @@ -440,13 +439,12 @@ public String retrieveTransferTemplate(@PathParam("externalId") final String ext
return retrieveClientTransferTemplate(null, externalId);
}

public String retrieveAll(final UriInfo uriInfo, final String sqlSearch, final Long officeId, final String externalId,
final String displayName, final String firstname, final String lastname, final String status, final String hierarchy,
final Integer offset, final Integer limit, final String orderBy, final String sortOrder, final Boolean orphansOnly,
final boolean isSelfUser) {
public String retrieveAll(final UriInfo uriInfo, final Long officeId, final String externalId, final String displayName,
final String firstname, final String lastname, final String status, final String hierarchy, final Integer offset,
final Integer limit, final String orderBy, final String sortOrder, final Boolean orphansOnly, final boolean isSelfUser) {
context.authenticatedUser().validateHasReadPermission(ClientApiConstants.CLIENT_RESOURCE_NAME);
final SearchParameters searchParameters = SearchParameters.forClients(sqlSearch, officeId, externalId, displayName, firstname,
lastname, status, hierarchy, offset, limit, orderBy, sortOrder, orphansOnly, isSelfUser);
final SearchParameters searchParameters = SearchParameters.forClients(officeId, externalId, displayName, firstname, lastname,
status, hierarchy, offset, limit, orderBy, sortOrder, orphansOnly, isSelfUser);
final Page<ClientData> clientData = clientReadPlatformService.retrieveAll(searchParameters);
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
return toApiJsonSerializer.serialize(settings, clientData, ClientApiConstants.CLIENT_RESPONSE_DATA_PARAMETERS);
Expand Down
Loading

0 comments on commit 5a8a2b9

Please sign in to comment.