FINERACT-1095: Remove last pieces of sqlSearch

This commit is contained in:
Adam Saghy
2025-03-14 14:10:31 +01:00
committed by Arnold Gálovics
parent e44a60f327
commit 1d72d4cfb8
5 changed files with 14 additions and 180 deletions
@@ -39,8 +39,6 @@ public interface TellerManagementReadPlatformService {
Collection<CashierData> getCashierData(Long officeId, Long tellerId, Long staffId, LocalDate date); Collection<CashierData> getCashierData(Long officeId, Long tellerId, Long staffId, LocalDate date);
Collection<CashierData> getTellerCashiers(Long tellerId, LocalDate date);
CashierData retrieveCashierTemplate(Long officeId, Long tellerId, boolean staffInSelectedOfficeOnly); CashierData retrieveCashierTemplate(Long officeId, Long tellerId, boolean staffInSelectedOfficeOnly);
CashierTransactionData retrieveCashierTxnTemplate(Long cashierId); CashierTransactionData retrieveCashierTxnTemplate(Long cashierId);
@@ -53,13 +51,9 @@ public interface TellerManagementReadPlatformService {
Collection<TellerJournalData> fetchTellerJournals(Long tellerId, Long cashierId, LocalDate fromDate, LocalDate toDate); Collection<TellerJournalData> fetchTellerJournals(Long tellerId, Long cashierId, LocalDate fromDate, LocalDate toDate);
Collection<TellerData> retrieveAllTellersForDropdown(Long officeId);
Collection<TellerData> retrieveAllTellers(String sqlSearch, Long officeId, String status);
Collection<CashierData> getCashiersForTeller(Long tellerId, LocalDate fromDate, LocalDate toDate); Collection<CashierData> getCashiersForTeller(Long tellerId, LocalDate fromDate, LocalDate toDate);
Collection<CashierData> retrieveCashiersForTellers(String sqlSearch, Long tellerId); Collection<CashierData> retrieveCashiersForTellers(Long tellerId);
Page<CashierTransactionData> retrieveCashierTransactions(Long cashierId, boolean includeAllTellers, LocalDate fromDate, Page<CashierTransactionData> retrieveCashierTransactions(Long cashierId, boolean includeAllTellers, LocalDate fromDate,
LocalDate toDate, String currencyCode, SearchParameters searchParameters); LocalDate toDate, String currencyCode, SearchParameters searchParameters);
@@ -108,12 +108,11 @@ public class EmailApiResource {
@GET @GET
@Path("messageByStatus") @Path("messageByStatus")
public String retrieveAllEmailByStatus(@QueryParam("sqlSearch") final String sqlSearch, @QueryParam("offset") final Integer offset, public String retrieveAllEmailByStatus(@QueryParam("offset") final Integer offset, @QueryParam("limit") final Integer limit,
@QueryParam("limit") final Integer limit, @QueryParam("status") final Integer status, @QueryParam("status") final Integer status, @QueryParam("orderBy") final String orderBy,
@QueryParam("orderBy") final String orderBy, @QueryParam("sortOrder") final String sortOrder, @QueryParam("sortOrder") final String sortOrder, @QueryParam("fromDate") final DateParam fromDateParam,
@QueryParam("fromDate") final DateParam fromDateParam, @QueryParam("toDate") final DateParam toDateParam, @QueryParam("toDate") final DateParam toDateParam, @QueryParam("locale") final String locale,
@QueryParam("locale") final String locale, @QueryParam("dateFormat") final String rawDateFormat, @QueryParam("dateFormat") final String rawDateFormat, @Context final UriInfo uriInfo) {
@Context final UriInfo uriInfo) {
final DateFormat dateFormat = StringUtils.isBlank(rawDateFormat) ? null : new DateFormat(rawDateFormat); final DateFormat dateFormat = StringUtils.isBlank(rawDateFormat) ? null : new DateFormat(rawDateFormat);
@@ -133,9 +132,8 @@ public class EmailApiResource {
@GET @GET
@Path("failedEmail") @Path("failedEmail")
public String retrieveFailedEmail(@QueryParam("sqlSearch") final String sqlSearch, @QueryParam("offset") final Integer offset, public String retrieveFailedEmail(@QueryParam("offset") final Integer offset, @QueryParam("limit") final Integer limit,
@QueryParam("limit") final Integer limit, @QueryParam("orderBy") final String orderBy, @QueryParam("orderBy") final String orderBy, @QueryParam("sortOrder") final String sortOrder, @Context final UriInfo uriInfo) {
@QueryParam("sortOrder") final String sortOrder, @Context final UriInfo uriInfo) {
context.authenticatedUser().validateHasReadPermission(RESOURCE_NAME_FOR_PERMISSIONS); context.authenticatedUser().validateHasReadPermission(RESOURCE_NAME_FOR_PERMISSIONS);
@@ -26,16 +26,13 @@ import java.time.OffsetDateTime;
import java.util.Collection; import java.util.Collection;
import java.util.Iterator; import java.util.Iterator;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.apache.fineract.infrastructure.core.domain.JdbcSupport; import org.apache.fineract.infrastructure.core.domain.JdbcSupport;
import org.apache.fineract.infrastructure.core.exception.UnrecognizedQueryParamException;
import org.apache.fineract.infrastructure.core.service.Page; import org.apache.fineract.infrastructure.core.service.Page;
import org.apache.fineract.infrastructure.core.service.PaginationHelper; import org.apache.fineract.infrastructure.core.service.PaginationHelper;
import org.apache.fineract.infrastructure.core.service.SearchParameters; import org.apache.fineract.infrastructure.core.service.SearchParameters;
import org.apache.fineract.infrastructure.core.service.database.DatabaseSpecificSQLGenerator; import org.apache.fineract.infrastructure.core.service.database.DatabaseSpecificSQLGenerator;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
import org.apache.fineract.infrastructure.security.service.SqlValidator; import org.apache.fineract.infrastructure.security.service.SqlValidator;
import org.apache.fineract.infrastructure.security.utils.ColumnValidator;
import org.apache.fineract.organisation.monetary.data.CurrencyData; import org.apache.fineract.organisation.monetary.data.CurrencyData;
import org.apache.fineract.organisation.monetary.service.CurrencyReadPlatformService; import org.apache.fineract.organisation.monetary.service.CurrencyReadPlatformService;
import org.apache.fineract.organisation.office.data.OfficeData; import org.apache.fineract.organisation.office.data.OfficeData;
@@ -64,13 +61,11 @@ public class TellerManagementReadPlatformServiceImpl implements TellerManagement
private final JdbcTemplate jdbcTemplate; private final JdbcTemplate jdbcTemplate;
private final PlatformSecurityContext context; private final PlatformSecurityContext context;
private final TellerLookupMapper lookupMapper = new TellerLookupMapper();
private final OfficeReadPlatformService officeReadPlatformService; private final OfficeReadPlatformService officeReadPlatformService;
private final StaffReadPlatformService staffReadPlatformService; private final StaffReadPlatformService staffReadPlatformService;
private final CurrencyReadPlatformService currencyReadPlatformService; private final CurrencyReadPlatformService currencyReadPlatformService;
private final DatabaseSpecificSQLGenerator sqlGenerator; private final DatabaseSpecificSQLGenerator sqlGenerator;
private final PaginationHelper paginationHelper; private final PaginationHelper paginationHelper;
private final ColumnValidator columnValidator;
private final SqlValidator sqlValidator; private final SqlValidator sqlValidator;
private static final class TellerMapper implements RowMapper<TellerData> { private static final class TellerMapper implements RowMapper<TellerData> {
@@ -112,42 +107,6 @@ public class TellerManagementReadPlatformServiceImpl implements TellerManagement
} }
} }
private static final class TellerLookupMapper implements RowMapper<TellerData> {
private final String schemaSql;
TellerLookupMapper() {
final StringBuilder sqlBuilder = new StringBuilder(100);
sqlBuilder.append("t.id as id, t.name as teller_name ");
sqlBuilder.append("from m_tellers t ");
this.schemaSql = sqlBuilder.toString();
}
public String schema() {
return this.schemaSql;
}
@Override
public TellerData mapRow(final ResultSet rs, final int rowNum) throws SQLException {
final Long id = rs.getLong("id");
final String tellerName = rs.getString("teller_name");
return TellerData.lookup(id, tellerName);
}
}
@Override
public Collection<TellerData> retrieveAllTellersForDropdown(final Long officeId) {
final Long defaultOfficeId = defaultToUsersOfficeIfNull(officeId);
final String sql = "select " + this.lookupMapper.schema() + " where s.office_id = ? and s.is_active=true ";
return this.jdbcTemplate.query(sql, this.lookupMapper, new Object[] { defaultOfficeId }); // NOSONAR
}
private Long defaultToUsersOfficeIfNull(final Long officeId) { private Long defaultToUsersOfficeIfNull(final Long officeId) {
Long defaultOfficeId = officeId; Long defaultOfficeId = officeId;
if (defaultOfficeId == null) { if (defaultOfficeId == null) {
@@ -169,58 +128,6 @@ public class TellerManagementReadPlatformServiceImpl implements TellerManagement
} }
} }
@Override
public Collection<TellerData> retrieveAllTellers(final String sqlSearch, final Long officeId, final String status) {
final String extraCriteria = getTellerCriteria(sqlSearch, officeId, status);
return retrieveAllTeller(extraCriteria, officeId);
}
private Collection<TellerData> retrieveAllTeller(final String extraCriteria, final Long officeId) {
final TellerMapper tm = new TellerMapper();
String sql = "select " + tm.schema();
if (StringUtils.isNotBlank(extraCriteria)) {
sql += " where " + extraCriteria;
}
sql = sql + " order by t.teller_name";
if (officeId != null) {
return this.jdbcTemplate.query(sql, tm, new Object[] { officeId }); // NOSONAR
}
return this.jdbcTemplate.query(sql, tm); // NOSONAR
}
private String getTellerCriteria(final String sqlSearch, final Long officeId, final String status) {
final StringBuilder extraCriteria = new StringBuilder(200);
if (sqlSearch != null) {
extraCriteria.append(" and (").append(sqlSearch).append(")");
final TellerMapper tm = new TellerMapper();
this.columnValidator.validateSqlInjection(tm.schema(), sqlSearch);
}
if (officeId != null) {
extraCriteria.append(" and office_id = ? ");
}
// Passing status parameter to get ACTIVE (By Default), INACTIVE or ALL
// (Both active and Inactive) employees
if (status.equalsIgnoreCase("active")) {
extraCriteria.append(" and status = 300 ");
} else if (status.equalsIgnoreCase("inActive")) {
extraCriteria.append(" and status = 0 ");
} else {
if (!status.equalsIgnoreCase("all")) {
throw new UnrecognizedQueryParamException("status", status, new Object[] { "all", "active", "inactive" });
}
}
if (StringUtils.isNotBlank(extraCriteria.toString())) {
extraCriteria.delete(0, 4);
}
// remove begin four letter including a space from the string.
return extraCriteria.toString();
}
@Override @Override
public Collection<TellerData> getTellers(Long officeId) { public Collection<TellerData> getTellers(Long officeId) {
return retrieveAllTellers(false); return retrieveAllTellers(false);
@@ -228,46 +135,14 @@ public class TellerManagementReadPlatformServiceImpl implements TellerManagement
@Override @Override
public Collection<CashierData> getCashiersForTeller(Long tellerId, LocalDate fromDate, LocalDate toDate) { public Collection<CashierData> getCashiersForTeller(Long tellerId, LocalDate fromDate, LocalDate toDate) {
return retrieveCashiersForTellers(null, tellerId); return retrieveCashiersForTellers(tellerId);
} }
@Override @Override
public Collection<CashierData> retrieveCashiersForTellers(final String sqlSearch, final Long tellerId) { public Collection<CashierData> retrieveCashiersForTellers(final Long tellerId) {
final String extraCriteria = getTellerCriteria(sqlSearch, tellerId);
return fetchCashiers(extraCriteria);
}
private String getTellerCriteria(final String sqlSearch, final Long tellerId) {
final StringBuilder extraCriteria = new StringBuilder(200);
if (sqlSearch != null) {
extraCriteria.append(" and (").append(sqlSearch).append(")");
final CashierMapper cm = new CashierMapper();
this.columnValidator.validateSqlInjection(cm.schema(), sqlSearch);
}
if (tellerId != null) {
extraCriteria.append(" and teller_id = ").append(tellerId).append(" ");
}
// remove begin four letter including a space from the string.
if (StringUtils.isNotBlank(extraCriteria.toString())) {
extraCriteria.delete(0, 4);
}
return extraCriteria.toString();
}
private Collection<CashierData> fetchCashiers(final String extraCriteria) {
final CashierMapper cm = new CashierMapper(); final CashierMapper cm = new CashierMapper();
String sql = "select " + cm.schema(); String sql = "select " + cm.schema() + " where teller_id = ?";
if (StringUtils.isNotBlank(extraCriteria)) { return this.jdbcTemplate.query(sql, cm, tellerId); // NOSONAR
sql += " where " + extraCriteria;
}
sql = sql + " order by teller_name";
return this.jdbcTemplate.query(sql, cm); // NOSONAR
} }
@Override @Override
@@ -288,12 +163,6 @@ public class TellerManagementReadPlatformServiceImpl implements TellerManagement
return null; return null;
} }
@Override
public Collection<CashierData> getTellerCashiers(Long tellerId, LocalDate date) {
// TODO Auto-generated method stub
return null;
}
@Override @Override
public TellerTransactionData findTellerTransaction(Long transactionId) { public TellerTransactionData findTellerTransaction(Long transactionId) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
@@ -24,7 +24,6 @@ import org.apache.fineract.infrastructure.core.service.PaginationHelper;
import org.apache.fineract.infrastructure.core.service.database.DatabaseSpecificSQLGenerator; import org.apache.fineract.infrastructure.core.service.database.DatabaseSpecificSQLGenerator;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
import org.apache.fineract.infrastructure.security.service.SqlValidator; import org.apache.fineract.infrastructure.security.service.SqlValidator;
import org.apache.fineract.infrastructure.security.utils.ColumnValidator;
import org.apache.fineract.organisation.monetary.service.CurrencyReadPlatformService; import org.apache.fineract.organisation.monetary.service.CurrencyReadPlatformService;
import org.apache.fineract.organisation.office.domain.OfficeRepositoryWrapper; import org.apache.fineract.organisation.office.domain.OfficeRepositoryWrapper;
import org.apache.fineract.organisation.office.service.OfficeReadPlatformService; import org.apache.fineract.organisation.office.service.OfficeReadPlatformService;
@@ -52,10 +51,9 @@ public class OrganisationTellerConfiguration {
public TellerManagementReadPlatformService tellerManagementReadPlatformService(JdbcTemplate jdbcTemplate, public TellerManagementReadPlatformService tellerManagementReadPlatformService(JdbcTemplate jdbcTemplate,
PlatformSecurityContext context, OfficeReadPlatformService officeReadPlatformService, PlatformSecurityContext context, OfficeReadPlatformService officeReadPlatformService,
StaffReadPlatformService staffReadPlatformService, CurrencyReadPlatformService currencyReadPlatformService, StaffReadPlatformService staffReadPlatformService, CurrencyReadPlatformService currencyReadPlatformService,
DatabaseSpecificSQLGenerator sqlGenerator, PaginationHelper paginationHelper, ColumnValidator columnValidator, DatabaseSpecificSQLGenerator sqlGenerator, PaginationHelper paginationHelper, SqlValidator sqlValidator) {
SqlValidator sqlValidator) {
return new TellerManagementReadPlatformServiceImpl(jdbcTemplate, context, officeReadPlatformService, staffReadPlatformService, return new TellerManagementReadPlatformServiceImpl(jdbcTemplate, context, officeReadPlatformService, staffReadPlatformService,
currencyReadPlatformService, sqlGenerator, paginationHelper, columnValidator, sqlValidator); currencyReadPlatformService, sqlGenerator, paginationHelper, sqlValidator);
} }
@Bean @Bean
@@ -6376,11 +6376,6 @@ GET https://DomainName/api/v1/clients/{clientId}
</dd> </dd>
<dd>Use externalId of clients to restrict results.</dd> <dd>Use externalId of clients to restrict results.</dd>
<dt>sqlSearch</dt>
<dd>
String <span>optional</span>
</dd>
<dd>Use an sql fragment valid for the underlying client schema to filter results. e.g. display_name like %K%</dd>
<dt>orphansOnly</dt> <dt>orphansOnly</dt>
<dd> <dd>
Boolean <span>optional</span>, defaults to false Boolean <span>optional</span>, defaults to false
@@ -8336,11 +8331,6 @@ GET https://DomainName/fineract-provider/api/v1/centers/9
</dd> </dd>
<dd>Use externalId of center to restrict results.</dd> <dd>Use externalId of center to restrict results.</dd>
<dt>sqlSearch</dt>
<dd>
String <span>optional</span>
</dd>
<dd>Use an sql fragment valid for the underlying center schema to filter results. e.g. display_name like %K%</dd>
</dl> </dl>
<p>Example Requests:</p> <p>Example Requests:</p>
<div class=apiClick>centers</div> <div class=apiClick>centers</div>
@@ -9771,11 +9761,6 @@ DELETE groups/2
</dd> </dd>
<dd>Use externalId of groups to restrict results.</dd> <dd>Use externalId of groups to restrict results.</dd>
<dt>sqlSearch</dt>
<dd>
String <span>optional</span>
</dd>
<dd>Use an sql fragment valid for the underlying group schema to filter results. e.g. display_name like %K%</dd>
<dt>orphansOnly</dt> <dt>orphansOnly</dt>
<dd> <dd>
Boolean <span>optional</span>, defaults to false Boolean <span>optional</span>, defaults to false
@@ -11168,11 +11153,6 @@ GET https://DomainName/api/v1/loans/{loanId}
</dd> </dd>
<dd>Use externalId of loan to restrict results.</dd> <dd>Use externalId of loan to restrict results.</dd>
<dt>sqlSearch</dt>
<dd>
String <span>optional</span>
</dd>
<dd>Use an sql fragment valid for the underlying loan schema to filter results. e.g. display_name like %K%</dd>
</dl> </dl>
<p>Example Requests:</p> <p>Example Requests:</p>
<div class=apiClick>loans</div> <div class=apiClick>loans</div>
@@ -36177,11 +36157,6 @@ No Request Body:
<dd>Filters for transactions whose entry Date is lesser than or equal to the passed in Date <dd>Filters for transactions whose entry Date is lesser than or equal to the passed in Date
</dd> </dd>
<dt>sqlSearch</dt>
<dd>
String <span>optional</span>
</dd>
<dd>Use an sql fragment valid for the underlying standing instruction schema to filter results. e.g. name like %K%</dd>
</dl> </dl>
<p>Example Requests : </p> <p>Example Requests : </p>
<div class=apiClick>standinginstructionrunhistory</div> <div class=apiClick>standinginstructionrunhistory</div>