@Override public Collection<LoanProductData> retrieveRestrictedProductsForMix(final Long productId) { this.context.authenticatedUser(); final LoanProductLookupMapper rm = new LoanProductLookupMapper(); String sql = "Select " + rm.restrictedProductsSchema() + " where pm.product_id=? "; // Check if branch specific products are enabled. If yes, fetch only products mapped to current // user's office String inClause1 = mifosEntityAccessUtil.getSQLWhereClauseForProductIDsForUserOffice_ifGlobalConfigEnabled( MifosEntityType.LOAN_PRODUCT); if ((inClause1 != null) && (!(inClause1.trim().isEmpty()))) { sql += " and rp.id in ( " + inClause1 + " ) "; } sql += " UNION Select " + rm.derivedRestrictedProductsSchema() + " where pm.restricted_product_id=?"; // Check if branch specific products are enabled. If yes, fetch only products mapped to current // user's office String inClause2 = mifosEntityAccessUtil.getSQLWhereClauseForProductIDsForUserOffice_ifGlobalConfigEnabled( MifosEntityType.LOAN_PRODUCT); if ((inClause2 != null) && (!(inClause2.trim().isEmpty()))) { sql += " and lp.id in ( " + inClause2 + " ) "; } return this.jdbcTemplate.query(sql, rm, new Object[] {productId, productId}); }