|
35 | 35 | import jakarta.ws.rs.QueryParam; |
36 | 36 | import jakarta.ws.rs.core.MediaType; |
37 | 37 | import java.util.List; |
38 | | -import java.util.Set; |
39 | 38 | import lombok.RequiredArgsConstructor; |
40 | | -import org.apache.fineract.portfolio.search.SearchConstants.SearchResponseParameters; |
41 | | -import org.apache.fineract.portfolio.search.data.AdHocQueryDataValidator; |
42 | | -import org.apache.fineract.portfolio.search.data.AdHocQuerySearchConditions; |
| 39 | +import org.apache.fineract.portfolio.search.data.AdHocQuerySearchRequest; |
43 | 40 | import org.apache.fineract.portfolio.search.data.AdHocSearchQueryData; |
44 | 41 | import org.apache.fineract.portfolio.search.data.SearchConditions; |
45 | 42 | import org.apache.fineract.portfolio.search.data.SearchData; |
46 | | -import org.apache.fineract.portfolio.search.service.SearchReadPlatformService; |
| 43 | +import org.apache.fineract.portfolio.search.service.SearchReadService; |
| 44 | +import org.apache.fineract.useradministration.domain.AppUser; |
| 45 | +import org.springframework.security.core.context.SecurityContextHolder; |
47 | 46 | import org.springframework.stereotype.Component; |
48 | 47 |
|
49 | 48 | @Path("/v1/search") |
50 | 49 | @Component |
51 | 50 | @Tag(name = "Search API", description = "Search API allows to search scoped resources clients, loans and groups on specified fields.") |
52 | 51 | @RequiredArgsConstructor |
| 52 | +@Consumes({ MediaType.APPLICATION_JSON }) |
| 53 | +@Produces({ MediaType.APPLICATION_JSON }) |
53 | 54 | public class SearchApiResource { |
54 | 55 |
|
55 | | - private static final Set<String> SEARCH_RESPONSE_PARAMETERS = SearchResponseParameters.getAllValues(); |
56 | | - |
57 | | - private final SearchReadPlatformService searchReadPlatformService; |
58 | | - private final AdHocQueryDataValidator fromApiJsonDeserializer; |
| 56 | + private final SearchReadService searchReadService; |
59 | 57 |
|
60 | 58 | @GET |
61 | 59 | @Path("/template") |
62 | | - @Consumes({ MediaType.APPLICATION_JSON }) |
63 | | - @Produces({ MediaType.APPLICATION_JSON }) |
64 | | - @Operation(summary = "Retrive Adhoc Search query template", description = "Mandatory Fields\n" + "\n" + "search?query=000000001\n") |
| 60 | + @Operation(summary = "Retrive Adhoc Search query template", description = """ |
| 61 | + Mandatory Fields |
| 62 | +
|
| 63 | + search?query=000000001 |
| 64 | + """) |
65 | 65 | public AdHocSearchQueryData retrieveAdHocSearchQueryTemplate() { |
66 | 66 |
|
67 | | - return this.searchReadPlatformService.retrieveAdHocQueryTemplate(); |
| 67 | + return searchReadService.retrieveAdHocQueryTemplate(); |
68 | 68 | } |
69 | 69 |
|
70 | 70 | @GET |
71 | | - @Consumes({ MediaType.APPLICATION_JSON }) |
72 | | - @Produces({ MediaType.APPLICATION_JSON }) |
73 | | - @Operation(summary = "Search Resources", description = "Example Requests:\n" + "\n" + "search?query=000000001\n" + "\n" + "\n" |
74 | | - + "search?query=Petra&resource=clients,groups\n" + "\n" + "\n" + "search?query=Petra&resource=clients,groups&exactMatch=true") |
| 71 | + @Operation(summary = "Search Resources", description = """ |
| 72 | + Example Requests: |
| 73 | +
|
| 74 | + search?query=000000001 |
| 75 | +
|
| 76 | +
|
| 77 | + search?query=Petra&resource=clients,groups |
| 78 | +
|
| 79 | +
|
| 80 | + search?query=Petra&resource=clients,groups&exactMatch=true""") |
75 | 81 | @ApiResponse(responseCode = "200", description = "OK", content = @Content(array = @ArraySchema(schema = @Schema(implementation = SearchApiResourceSwagger.GetSearchResponse.class)))) |
76 | 82 | public List<SearchData> searchData(@QueryParam("query") @Parameter(description = "query") final String query, |
77 | 83 | @QueryParam("resource") @Parameter(description = "resource") final String resource, |
78 | 84 | @DefaultValue("false") @QueryParam("exactMatch") @Parameter(description = "exactMatch") Boolean exactMatch) { |
79 | 85 |
|
80 | | - final SearchConditions searchConditions = new SearchConditions(query, resource, exactMatch); |
| 86 | + final AppUser currentUser = (AppUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); |
| 87 | + final String hierarchy = currentUser.getOffice().getHierarchy(); |
| 88 | + final SearchConditions searchConditions = new SearchConditions(query, resource, exactMatch, hierarchy); |
81 | 89 |
|
82 | | - return this.searchReadPlatformService.retriveMatchingData(searchConditions); |
| 90 | + return searchReadService.retriveMatchingData(searchConditions); |
83 | 91 | } |
84 | 92 |
|
85 | 93 | @POST |
86 | 94 | @Path("/advance") |
87 | | - @Consumes({ MediaType.APPLICATION_JSON }) |
88 | | - @Produces({ MediaType.APPLICATION_JSON }) |
89 | | - @Operation(summary = "Adhoc query search", description = "AdHocQuery search has more search options, it is a POST request, it uses request body to send search parameters\n" |
90 | | - + "\n" + "\n" + "Mandatory fields:" + "entities" + "\n" + "\n" + "Optional fields:" |
91 | | - + "loanStatus, loanProducts, offices, loanDateOption, loanFromDate, loanToDate, \n" |
92 | | - + "includeOutStandingAmountPercentage, outStandingAmountPercentageCondition, \n" |
93 | | - + "minOutStandingAmountPercentage and maxOutStandingAmountPercentage OR outStandingAmountPercentage, \n" |
94 | | - + "includeOutstandingAmount, outstandingAmountCondition, \n" |
95 | | - + "minOutstandingAmount and maxOutstandingAmount OR outstandingAmount") |
96 | | - @RequestBody(required = true, content = @Content(schema = @Schema(implementation = SearchApiResourceSwagger.PostAdhocQuerySearchRequest.class))) |
97 | | - public List<AdHocSearchQueryData> advancedSearch(final String json) { |
| 95 | + @Operation(summary = "Adhoc query search", description = """ |
| 96 | + AdHocQuery search has more search options, it is a POST request, \ |
| 97 | + it uses request body to send search parameters |
| 98 | +
|
98 | 99 |
|
99 | | - final AdHocQuerySearchConditions searchConditions = this.fromApiJsonDeserializer.retrieveSearchConditions(json); |
| 100 | + Mandatory fields: entities |
| 101 | +
|
| 102 | + Optional fields: \ |
| 103 | + loanStatus, loanProducts, offices, loanDateOption, loanFromDate, loanToDate, |
| 104 | + includeOutStandingAmountPercentage, outStandingAmountPercentageCondition, |
| 105 | + minOutStandingAmountPercentage and maxOutStandingAmountPercentage OR outStandingAmountPercentage, |
| 106 | + includeOutstandingAmount, outstandingAmountCondition, |
| 107 | + minOutstandingAmount and maxOutstandingAmount OR outstandingAmount""") |
| 108 | + @RequestBody(required = true, content = @Content(schema = @Schema(implementation = SearchApiResourceSwagger.PostAdhocQuerySearchRequest.class))) |
| 109 | + public List<AdHocSearchQueryData> advancedSearch(final AdHocQuerySearchRequest request) { |
100 | 110 |
|
101 | | - return this.searchReadPlatformService.retrieveAdHocQueryMatchingData(searchConditions); |
| 111 | + return searchReadService.retrieveAdHocQueryMatchingData(request); |
102 | 112 | } |
103 | 113 | } |
0 commit comments