@Test public void shouldReturnAListOfBasicProducts() throws LMISException { createSeveralProducts(); List<Product> basicProducts = productRepository.listBasicProducts(); assertEquals(1, basicProducts.size()); assertEquals("08A01", basicProducts.get(0).getCode()); }
public List<Product> listBasicProducts() throws LMISException { String rawSql = "SELECT * FROM products " + "WHERE isactive = '1' " + "AND products.isbasic = '1' " + "AND (isarchived = '1' " + "OR id NOT IN (" + "SELECT product_id from stock_cards));"; final Cursor cursor = LmisSqliteOpenHelper.getInstance(LMISApp.getContext()).getWritableDatabase().rawQuery(rawSql, null); List<Product> activeProducts = new ArrayList<>(); if (cursor.moveToFirst()) { do { Product product = new Product(); product.setActive(Boolean.TRUE); product.setBasic(Boolean.TRUE); product.setPrimaryName(cursor.getString(cursor.getColumnIndexOrThrow("primaryName"))); product.setArchived(cursor.getInt(cursor.getColumnIndexOrThrow("isArchived")) != 0); product.setCode(cursor.getString(cursor.getColumnIndexOrThrow("code"))); product.setId(cursor.getInt(cursor.getColumnIndexOrThrow("id"))); product.setStrength(cursor.getString(cursor.getColumnIndexOrThrow("strength"))); product.setType(cursor.getString(cursor.getColumnIndexOrThrow("type"))); activeProducts.add(product); } while (cursor.moveToNext()); } if (cursor != null && !cursor.isClosed()) { cursor.close(); } Collections.sort(activeProducts); return activeProducts; }
ProductRepository { public List<Product> listBasicProducts() throws LMISException { String rawSql = "SELECT * FROM products " + "WHERE isactive = '1' " + "AND products.isbasic = '1' " + "AND (isarchived = '1' " + "OR id NOT IN (" + "SELECT product_id from stock_cards));"; final Cursor cursor = LmisSqliteOpenHelper.getInstance(LMISApp.getContext()).getWritableDatabase().rawQuery(rawSql, null); List<Product> activeProducts = new ArrayList<>(); if (cursor.moveToFirst()) { do { Product product = new Product(); product.setActive(Boolean.TRUE); product.setBasic(Boolean.TRUE); product.setPrimaryName(cursor.getString(cursor.getColumnIndexOrThrow("primaryName"))); product.setArchived(cursor.getInt(cursor.getColumnIndexOrThrow("isArchived")) != 0); product.setCode(cursor.getString(cursor.getColumnIndexOrThrow("code"))); product.setId(cursor.getInt(cursor.getColumnIndexOrThrow("id"))); product.setStrength(cursor.getString(cursor.getColumnIndexOrThrow("strength"))); product.setType(cursor.getString(cursor.getColumnIndexOrThrow("type"))); activeProducts.add(product); } while (cursor.moveToNext()); } if (cursor != null && !cursor.isClosed()) { cursor.close(); } Collections.sort(activeProducts); return activeProducts; } }
ProductRepository { public List<Product> listBasicProducts() throws LMISException { String rawSql = "SELECT * FROM products " + "WHERE isactive = '1' " + "AND products.isbasic = '1' " + "AND (isarchived = '1' " + "OR id NOT IN (" + "SELECT product_id from stock_cards));"; final Cursor cursor = LmisSqliteOpenHelper.getInstance(LMISApp.getContext()).getWritableDatabase().rawQuery(rawSql, null); List<Product> activeProducts = new ArrayList<>(); if (cursor.moveToFirst()) { do { Product product = new Product(); product.setActive(Boolean.TRUE); product.setBasic(Boolean.TRUE); product.setPrimaryName(cursor.getString(cursor.getColumnIndexOrThrow("primaryName"))); product.setArchived(cursor.getInt(cursor.getColumnIndexOrThrow("isArchived")) != 0); product.setCode(cursor.getString(cursor.getColumnIndexOrThrow("code"))); product.setId(cursor.getInt(cursor.getColumnIndexOrThrow("id"))); product.setStrength(cursor.getString(cursor.getColumnIndexOrThrow("strength"))); product.setType(cursor.getString(cursor.getColumnIndexOrThrow("type"))); activeProducts.add(product); } while (cursor.moveToNext()); } if (cursor != null && !cursor.isClosed()) { cursor.close(); } Collections.sort(activeProducts); return activeProducts; } @Inject  ProductRepository(Context context); }
ProductRepository { public List<Product> listBasicProducts() throws LMISException { String rawSql = "SELECT * FROM products " + "WHERE isactive = '1' " + "AND products.isbasic = '1' " + "AND (isarchived = '1' " + "OR id NOT IN (" + "SELECT product_id from stock_cards));"; final Cursor cursor = LmisSqliteOpenHelper.getInstance(LMISApp.getContext()).getWritableDatabase().rawQuery(rawSql, null); List<Product> activeProducts = new ArrayList<>(); if (cursor.moveToFirst()) { do { Product product = new Product(); product.setActive(Boolean.TRUE); product.setBasic(Boolean.TRUE); product.setPrimaryName(cursor.getString(cursor.getColumnIndexOrThrow("primaryName"))); product.setArchived(cursor.getInt(cursor.getColumnIndexOrThrow("isArchived")) != 0); product.setCode(cursor.getString(cursor.getColumnIndexOrThrow("code"))); product.setId(cursor.getInt(cursor.getColumnIndexOrThrow("id"))); product.setStrength(cursor.getString(cursor.getColumnIndexOrThrow("strength"))); product.setType(cursor.getString(cursor.getColumnIndexOrThrow("type"))); activeProducts.add(product); } while (cursor.moveToNext()); } if (cursor != null && !cursor.isClosed()) { cursor.close(); } Collections.sort(activeProducts); return activeProducts; } @Inject  ProductRepository(Context context); List<Product> listActiveProducts(final Product.IsKit isKit); List<Product> listBasicProducts(); List<Product> listProductsArchivedOrNotInStockCard(); void save(final List<Product> products); void batchCreateOrUpdateProducts(final List<Product> productList); void createOrUpdate(Product product); void updateProduct(Product product); List<KitProduct> queryKitProductByKitCode(final String kitCode); Product getByCode(final String code); Product getProductById(final long id); List<Product> queryActiveProductsByCodesWithKits(final List<String> productCodes, final boolean isWithKit); List<KitProduct> queryKitProductByProductCode(final String productCode); List<String> listArchivedProductCodes(); List<Product> queryProductsByProductIds(final List<Long> productIds); List<Product> queryActiveProductsInVIAProgramButNotInDraftVIAForm(); List<Product> listNonBasicProducts(); List<Product> getProductsByCodes(final List<String> codes); }
ProductRepository { public List<Product> listBasicProducts() throws LMISException { String rawSql = "SELECT * FROM products " + "WHERE isactive = '1' " + "AND products.isbasic = '1' " + "AND (isarchived = '1' " + "OR id NOT IN (" + "SELECT product_id from stock_cards));"; final Cursor cursor = LmisSqliteOpenHelper.getInstance(LMISApp.getContext()).getWritableDatabase().rawQuery(rawSql, null); List<Product> activeProducts = new ArrayList<>(); if (cursor.moveToFirst()) { do { Product product = new Product(); product.setActive(Boolean.TRUE); product.setBasic(Boolean.TRUE); product.setPrimaryName(cursor.getString(cursor.getColumnIndexOrThrow("primaryName"))); product.setArchived(cursor.getInt(cursor.getColumnIndexOrThrow("isArchived")) != 0); product.setCode(cursor.getString(cursor.getColumnIndexOrThrow("code"))); product.setId(cursor.getInt(cursor.getColumnIndexOrThrow("id"))); product.setStrength(cursor.getString(cursor.getColumnIndexOrThrow("strength"))); product.setType(cursor.getString(cursor.getColumnIndexOrThrow("type"))); activeProducts.add(product); } while (cursor.moveToNext()); } if (cursor != null && !cursor.isClosed()) { cursor.close(); } Collections.sort(activeProducts); return activeProducts; } @Inject  ProductRepository(Context context); List<Product> listActiveProducts(final Product.IsKit isKit); List<Product> listBasicProducts(); List<Product> listProductsArchivedOrNotInStockCard(); void save(final List<Product> products); void batchCreateOrUpdateProducts(final List<Product> productList); void createOrUpdate(Product product); void updateProduct(Product product); List<KitProduct> queryKitProductByKitCode(final String kitCode); Product getByCode(final String code); Product getProductById(final long id); List<Product> queryActiveProductsByCodesWithKits(final List<String> productCodes, final boolean isWithKit); List<KitProduct> queryKitProductByProductCode(final String productCode); List<String> listArchivedProductCodes(); List<Product> queryProductsByProductIds(final List<Long> productIds); List<Product> queryActiveProductsInVIAProgramButNotInDraftVIAForm(); List<Product> listNonBasicProducts(); List<Product> getProductsByCodes(final List<String> codes);  }