2626import java .util .Collection ;
2727import java .util .Iterator ;
2828import lombok .RequiredArgsConstructor ;
29- import org .apache .commons .lang3 .StringUtils ;
3029import org .apache .fineract .infrastructure .core .domain .JdbcSupport ;
31- import org .apache .fineract .infrastructure .core .exception .UnrecognizedQueryParamException ;
3230import org .apache .fineract .infrastructure .core .service .Page ;
3331import org .apache .fineract .infrastructure .core .service .PaginationHelper ;
3432import org .apache .fineract .infrastructure .core .service .SearchParameters ;
3533import org .apache .fineract .infrastructure .core .service .database .DatabaseSpecificSQLGenerator ;
3634import org .apache .fineract .infrastructure .security .service .PlatformSecurityContext ;
3735import org .apache .fineract .infrastructure .security .service .SqlValidator ;
38- import org .apache .fineract .infrastructure .security .utils .ColumnValidator ;
3936import org .apache .fineract .organisation .monetary .data .CurrencyData ;
4037import org .apache .fineract .organisation .monetary .service .CurrencyReadPlatformService ;
4138import org .apache .fineract .organisation .office .data .OfficeData ;
@@ -64,13 +61,11 @@ public class TellerManagementReadPlatformServiceImpl implements TellerManagement
6461
6562 private final JdbcTemplate jdbcTemplate ;
6663 private final PlatformSecurityContext context ;
67- private final TellerLookupMapper lookupMapper = new TellerLookupMapper ();
6864 private final OfficeReadPlatformService officeReadPlatformService ;
6965 private final StaffReadPlatformService staffReadPlatformService ;
7066 private final CurrencyReadPlatformService currencyReadPlatformService ;
7167 private final DatabaseSpecificSQLGenerator sqlGenerator ;
7268 private final PaginationHelper paginationHelper ;
73- private final ColumnValidator columnValidator ;
7469 private final SqlValidator sqlValidator ;
7570
7671 private static final class TellerMapper implements RowMapper <TellerData > {
@@ -112,42 +107,6 @@ public TellerData mapRow(final ResultSet rs, final int rowNum) throws SQLExcepti
112107 }
113108 }
114109
115- private static final class TellerLookupMapper implements RowMapper <TellerData > {
116-
117- private final String schemaSql ;
118-
119- TellerLookupMapper () {
120-
121- final StringBuilder sqlBuilder = new StringBuilder (100 );
122- sqlBuilder .append ("t.id as id, t.name as teller_name " );
123- sqlBuilder .append ("from m_tellers t " );
124-
125- this .schemaSql = sqlBuilder .toString ();
126- }
127-
128- public String schema () {
129- return this .schemaSql ;
130- }
131-
132- @ Override
133- public TellerData mapRow (final ResultSet rs , final int rowNum ) throws SQLException {
134-
135- final Long id = rs .getLong ("id" );
136- final String tellerName = rs .getString ("teller_name" );
137- return TellerData .lookup (id , tellerName );
138- }
139- }
140-
141- @ Override
142- public Collection <TellerData > retrieveAllTellersForDropdown (final Long officeId ) {
143-
144- final Long defaultOfficeId = defaultToUsersOfficeIfNull (officeId );
145-
146- final String sql = "select " + this .lookupMapper .schema () + " where s.office_id = ? and s.is_active=true " ;
147-
148- return this .jdbcTemplate .query (sql , this .lookupMapper , new Object [] { defaultOfficeId }); // NOSONAR
149- }
150-
151110 private Long defaultToUsersOfficeIfNull (final Long officeId ) {
152111 Long defaultOfficeId = officeId ;
153112 if (defaultOfficeId == null ) {
@@ -169,105 +128,21 @@ public TellerData findTeller(final Long tellerId) {
169128 }
170129 }
171130
172- @ Override
173- public Collection <TellerData > retrieveAllTellers (final String sqlSearch , final Long officeId , final String status ) {
174- final String extraCriteria = getTellerCriteria (sqlSearch , officeId , status );
175- return retrieveAllTeller (extraCriteria , officeId );
176- }
177-
178- private Collection <TellerData > retrieveAllTeller (final String extraCriteria , final Long officeId ) {
179-
180- final TellerMapper tm = new TellerMapper ();
181- String sql = "select " + tm .schema ();
182- if (StringUtils .isNotBlank (extraCriteria )) {
183- sql += " where " + extraCriteria ;
184- }
185- sql = sql + " order by t.teller_name" ;
186- if (officeId != null ) {
187- return this .jdbcTemplate .query (sql , tm , new Object [] { officeId }); // NOSONAR
188- }
189- return this .jdbcTemplate .query (sql , tm ); // NOSONAR
190- }
191-
192- private String getTellerCriteria (final String sqlSearch , final Long officeId , final String status ) {
193-
194- final StringBuilder extraCriteria = new StringBuilder (200 );
195-
196- if (sqlSearch != null ) {
197- extraCriteria .append (" and (" ).append (sqlSearch ).append (")" );
198- final TellerMapper tm = new TellerMapper ();
199- this .columnValidator .validateSqlInjection (tm .schema (), sqlSearch );
200- }
201- if (officeId != null ) {
202- extraCriteria .append (" and office_id = ? " );
203- }
204- // Passing status parameter to get ACTIVE (By Default), INACTIVE or ALL
205- // (Both active and Inactive) employees
206- if (status .equalsIgnoreCase ("active" )) {
207- extraCriteria .append (" and status = 300 " );
208- } else if (status .equalsIgnoreCase ("inActive" )) {
209- extraCriteria .append (" and status = 0 " );
210- } else {
211- if (!status .equalsIgnoreCase ("all" )) {
212- throw new UnrecognizedQueryParamException ("status" , status , new Object [] { "all" , "active" , "inactive" });
213- }
214- }
215-
216- if (StringUtils .isNotBlank (extraCriteria .toString ())) {
217- extraCriteria .delete (0 , 4 );
218- }
219-
220- // remove begin four letter including a space from the string.
221- return extraCriteria .toString ();
222- }
223-
224131 @ Override
225132 public Collection <TellerData > getTellers (Long officeId ) {
226133 return retrieveAllTellers (false );
227134 }
228135
229136 @ Override
230137 public Collection <CashierData > getCashiersForTeller (Long tellerId , LocalDate fromDate , LocalDate toDate ) {
231- return retrieveCashiersForTellers (null , tellerId );
138+ return retrieveCashiersForTellers (tellerId );
232139 }
233140
234141 @ Override
235- public Collection <CashierData > retrieveCashiersForTellers (final String sqlSearch , final Long tellerId ) {
236- final String extraCriteria = getTellerCriteria (sqlSearch , tellerId );
237- return fetchCashiers (extraCriteria );
238- }
239-
240- private String getTellerCriteria (final String sqlSearch , final Long tellerId ) {
241-
242- final StringBuilder extraCriteria = new StringBuilder (200 );
243-
244- if (sqlSearch != null ) {
245- extraCriteria .append (" and (" ).append (sqlSearch ).append (")" );
246- final CashierMapper cm = new CashierMapper ();
247- this .columnValidator .validateSqlInjection (cm .schema (), sqlSearch );
248-
249- }
250- if (tellerId != null ) {
251- extraCriteria .append (" and teller_id = " ).append (tellerId ).append (" " );
252- }
253-
254- // remove begin four letter including a space from the string.
255- if (StringUtils .isNotBlank (extraCriteria .toString ())) {
256- extraCriteria .delete (0 , 4 );
257- }
258-
259- return extraCriteria .toString ();
260- }
261-
262- private Collection <CashierData > fetchCashiers (final String extraCriteria ) {
263-
142+ public Collection <CashierData > retrieveCashiersForTellers (final Long tellerId ) {
264143 final CashierMapper cm = new CashierMapper ();
265- String sql = "select " + cm .schema ();
266- if (StringUtils .isNotBlank (extraCriteria )) {
267- sql += " where " + extraCriteria ;
268- }
269- sql = sql + " order by teller_name" ;
270- return this .jdbcTemplate .query (sql , cm ); // NOSONAR
144+ String sql = "select " + cm .schema () + " where teller_id = ?" ;
145+ return this .jdbcTemplate .query (sql , cm , tellerId ); // NOSONAR
271146 }
272147
273148 @ Override
@@ -288,12 +163,6 @@ public Collection<CashierData> getCashierData(Long officeId, Long tellerId, Long
288163 return null ;
289164 }
290165
291- @ Override
292- public Collection <CashierData > getTellerCashiers (Long tellerId , LocalDate date ) {
293- // TODO Auto-generated method stub
294- return null ;
295- }
296-
297166 @ Override
298167 public TellerTransactionData findTellerTransaction (Long transactionId ) {
299168 // TODO Auto-generated method stub
0 commit comments