From 92395b28489178d3b9baa958ebe033ef349bfab7 Mon Sep 17 00:00:00 2001 From: parthmittal Date: Tue, 4 Feb 2025 20:22:26 +0530 Subject: [PATCH 1/6] - added testing case for sorting data --- .../storage/IStorageUtilityIndexed.java | 19 +++++++ .../util/DummyIndexedStorageUtility.java | 49 +++++++++++++++++++ .../storage/IndexedStorageUtilityTests.java | 16 ++++-- 3 files changed, 80 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/javarosa/core/services/storage/IStorageUtilityIndexed.java b/src/main/java/org/javarosa/core/services/storage/IStorageUtilityIndexed.java index 9fc30ba7cb..fbdd9b6479 100644 --- a/src/main/java/org/javarosa/core/services/storage/IStorageUtilityIndexed.java +++ b/src/main/java/org/javarosa/core/services/storage/IStorageUtilityIndexed.java @@ -251,6 +251,25 @@ public interface IStorageUtilityIndexed { * they may need to clean up if the bulk read doesn't complete */ + Vector getSortedRecordsForValues(String[] metaFieldNames, Object[] values,String orderby); + + /** + * Load multiple record objects from storage at one time from a list of record ids. + *

+ * If the provided recordMap already contains entries for any ids, it is _not_ + * required for them to be retrieved from storage again. + * + * if orderby is passed it will give the sorted list based on this key, need to add DESC or ASC for + * sorting done by ascending or descending + * + * @throws RequestAbandonedException If the current request is abandoned, this method will + * throw a RequestAbandonedException. Callers should not + * generally catch that exception unless they rethrow it + * or another exception, but they should anticipate that + * they may need to clean up if the bulk read doesn't complete + */ + + void bulkRead(LinkedHashSet cuedCases, HashMap recordMap) throws RequestAbandonedException; diff --git a/src/main/java/org/javarosa/core/services/storage/util/DummyIndexedStorageUtility.java b/src/main/java/org/javarosa/core/services/storage/util/DummyIndexedStorageUtility.java index 33874b4d9f..18d79a8e3a 100644 --- a/src/main/java/org/javarosa/core/services/storage/util/DummyIndexedStorageUtility.java +++ b/src/main/java/org/javarosa/core/services/storage/util/DummyIndexedStorageUtility.java @@ -17,8 +17,11 @@ import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; +import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; import java.util.Enumeration; import java.util.HashMap; import java.util.Hashtable; @@ -173,6 +176,52 @@ public Vector getRecordsForValues(String[] metaFieldNames, Object[] values) { return matches; } + @Override + public Vector getSortedRecordsForValues(String[] metaFieldNames, Object[] values, String orderby) { + Vector matches = new Vector<>(); + List idMatches = getIDsForValues(metaFieldNames, values); + + for (Integer id : idMatches) { + matches.add(read(id)); + } + + if (orderby == null || orderby.trim().isEmpty()) { + return matches; // No sorting required + } + + // Parse orderBy into field and direction + String[] orderParts = orderby.trim().split("\\s+"); + String fieldName = orderParts[0]; + final boolean isAscending = orderParts.length <= 1 || !orderParts[1].equalsIgnoreCase("DESC"); + + // Perform sorting using reflection for field access + Collections.sort(matches, new Comparator() { + @Override + public int compare(T record1, T record2) { + try { + Object value1 = getFieldValue(record1, fieldName); + Object value2 = getFieldValue(record2, fieldName); + + if (value1 instanceof Comparable && value2 instanceof Comparable) { + int comparison = ((Comparable) value1).compareTo(value2); + return isAscending ? comparison : -comparison; + } + } catch (Exception e) { + e.printStackTrace(); + } + return 0; // Default to no ordering if field access fails + } + }); + + return matches; + } + private Object getFieldValue(T record, String fieldName) throws Exception { + // Get the field by name and set accessible + Field field = record.getClass().getDeclaredField(fieldName); + field.setAccessible(true); + return field.get(record); + } + @Override public int add(T e) { data.put(DataUtil.integer(curCount), e); diff --git a/src/test/java/org/javarosa/core/storage/IndexedStorageUtilityTests.java b/src/test/java/org/javarosa/core/storage/IndexedStorageUtilityTests.java index 6be6e9cd9a..a1f99031a4 100644 --- a/src/test/java/org/javarosa/core/storage/IndexedStorageUtilityTests.java +++ b/src/test/java/org/javarosa/core/storage/IndexedStorageUtilityTests.java @@ -1,10 +1,6 @@ package org.javarosa.core.storage; import org.javarosa.core.services.storage.IStorageUtilityIndexed; -import org.javarosa.core.services.storage.util.DummyIndexedStorageUtility; -import org.javarosa.core.util.Interner; -import org.javarosa.core.util.externalizable.LivePrototypeFactory; -import org.javarosa.core.util.externalizable.PrototypeFactory; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -32,6 +28,7 @@ public abstract class IndexedStorageUtilityTests { Shoe[] eightSizesOfWomensNikes; Shoe[] fiveSizesOfMensVans; + Shoe[] fiveSortedSizesOfMensAddidas; protected abstract IStorageUtilityIndexed createStorageUtility(); @@ -58,6 +55,11 @@ public void setupStorageContainer() { fiveSizesOfMensVans[i] = new Shoe("vans", "mens", String.valueOf(i + 1)); } + + fiveSortedSizesOfMensAddidas = new Shoe[5]; + for (int i = 0; i < 5; ++i) { + fiveSortedSizesOfMensAddidas[i]= new Shoe("addidas", "mens", String.valueOf(5 - i)); + } } @Test @@ -126,6 +128,11 @@ public void testBulkMetaMatching() { Vector matchedRecords = storage.getRecordsForValues(new String[]{Shoe.META_BRAND, Shoe.META_STYLE}, new String[]{"nike", "mens"}); Assert.assertEquals("Failed index match [brand,style][nike,mens]", getIdsFromModels(tenSizesOfMensNikes), getIdsFromModels(matchedRecords.toArray(new Shoe[]{}))); + + Vector matchedSortedRecords = storage.getSortedRecordsForValues(new String[]{Shoe.META_BRAND, Shoe.META_STYLE}, new String[]{"addidas", "mens"},Shoe.META_SIZE+" DESC"); + Assert.assertArrayEquals("Failed index match [brand,style][vans,mens]", fiveSortedSizesOfMensAddidas,matchedSortedRecords.toArray()); + + } @Test @@ -142,6 +149,7 @@ private void writeBulkSets() { writeAll(tenSizesOfMensNikes); writeAll(eightSizesOfWomensNikes); writeAll(fiveSizesOfMensVans); + writeAll(fiveSortedSizesOfMensAddidas); } Set getIdsFromModels(Shoe[] shoes) { From f2a04ae77250dd9a01efcb27581957efec7dc44c Mon Sep 17 00:00:00 2001 From: parthmittal Date: Tue, 4 Feb 2025 22:05:46 +0530 Subject: [PATCH 2/6] -coderabbit pr review changes --- .../storage/IStorageUtilityIndexed.java | 11 ++++-- .../util/DummyIndexedStorageUtility.java | 35 ++++++++++++++----- .../storage/IndexedStorageUtilityTests.java | 16 +++++---- 3 files changed, 46 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/javarosa/core/services/storage/IStorageUtilityIndexed.java b/src/main/java/org/javarosa/core/services/storage/IStorageUtilityIndexed.java index fbdd9b6479..71add2d6c1 100644 --- a/src/main/java/org/javarosa/core/services/storage/IStorageUtilityIndexed.java +++ b/src/main/java/org/javarosa/core/services/storage/IStorageUtilityIndexed.java @@ -259,8 +259,15 @@ public interface IStorageUtilityIndexed { * If the provided recordMap already contains entries for any ids, it is _not_ * required for them to be retrieved from storage again. * - * if orderby is passed it will give the sorted list based on this key, need to add DESC or ASC for - * sorting done by ascending or descending + * + * metaFieldNames Array of metadata field names to match + * values Array of values corresponding to the field names + * orderby String in format "fieldName [ASC|DESC]". If null or empty, records are returned unsorted. + * ASC/DESC is case-insensitive. If direction is omitted, defaults to ASC. + * If field doesn't exist or is invalid, returns unsorted records. + * @return Vector of records matching the criteria, sorted if orderby is valid + * + * @throws RequestAbandonedException If the current request is abandoned, this method * * @throws RequestAbandonedException If the current request is abandoned, this method will * throw a RequestAbandonedException. Callers should not diff --git a/src/main/java/org/javarosa/core/services/storage/util/DummyIndexedStorageUtility.java b/src/main/java/org/javarosa/core/services/storage/util/DummyIndexedStorageUtility.java index 18d79a8e3a..550058741b 100644 --- a/src/main/java/org/javarosa/core/services/storage/util/DummyIndexedStorageUtility.java +++ b/src/main/java/org/javarosa/core/services/storage/util/DummyIndexedStorageUtility.java @@ -190,10 +190,12 @@ public Vector getSortedRecordsForValues(String[] metaFieldNames, Object[] val } // Parse orderBy into field and direction + if (!orderby.matches("^\\w+\\s*(ASC|DESC)?\\s*$")) { + return matches; // Invalid format, return unsorted + } String[] orderParts = orderby.trim().split("\\s+"); String fieldName = orderParts[0]; final boolean isAscending = orderParts.length <= 1 || !orderParts[1].equalsIgnoreCase("DESC"); - // Perform sorting using reflection for field access Collections.sort(matches, new Comparator() { @Override @@ -201,13 +203,22 @@ public int compare(T record1, T record2) { try { Object value1 = getFieldValue(record1, fieldName); Object value2 = getFieldValue(record2, fieldName); - + if (value1 == null && value2 == null) { + return 0; + } + if (value1 == null) { + return isAscending ? -1 : 1; + } + if (value2 == null) { + return isAscending ? 1 : -1; + } if (value1 instanceof Comparable && value2 instanceof Comparable) { int comparison = ((Comparable) value1).compareTo(value2); return isAscending ? comparison : -comparison; } } catch (Exception e) { - e.printStackTrace(); + // Log error and continue with no ordering + System.err.println("Failed to compare records: " + e.getMessage()); } return 0; // Default to no ordering if field access fails } @@ -216,11 +227,19 @@ public int compare(T record1, T record2) { return matches; } private Object getFieldValue(T record, String fieldName) throws Exception { - // Get the field by name and set accessible - Field field = record.getClass().getDeclaredField(fieldName); - field.setAccessible(true); - return field.get(record); - } + Class clazz = record.getClass(); + while (clazz != null) { + try { + Field field = clazz.getDeclaredField(fieldName); + field.setAccessible(true); + return field.get(record); + } catch (NoSuchFieldException e) { + clazz = clazz.getSuperclass(); + } + } + throw new NoSuchFieldException("Field '" + fieldName + "' not found in class hierarchy"); + } + @Override public int add(T e) { diff --git a/src/test/java/org/javarosa/core/storage/IndexedStorageUtilityTests.java b/src/test/java/org/javarosa/core/storage/IndexedStorageUtilityTests.java index a1f99031a4..85988b1cf5 100644 --- a/src/test/java/org/javarosa/core/storage/IndexedStorageUtilityTests.java +++ b/src/test/java/org/javarosa/core/storage/IndexedStorageUtilityTests.java @@ -28,7 +28,7 @@ public abstract class IndexedStorageUtilityTests { Shoe[] eightSizesOfWomensNikes; Shoe[] fiveSizesOfMensVans; - Shoe[] fiveSortedSizesOfMensAddidas; + Shoe[] fiveSortedSizesOfMensAdidas; protected abstract IStorageUtilityIndexed createStorageUtility(); @@ -56,9 +56,9 @@ public void setupStorageContainer() { new Shoe("vans", "mens", String.valueOf(i + 1)); } - fiveSortedSizesOfMensAddidas = new Shoe[5]; + fiveSortedSizesOfMensAdidas = new Shoe[5]; for (int i = 0; i < 5; ++i) { - fiveSortedSizesOfMensAddidas[i]= new Shoe("addidas", "mens", String.valueOf(5 - i)); + fiveSortedSizesOfMensAdidas[i]= new Shoe("adidas", "mens", String.valueOf(5 - i)); } } @@ -129,10 +129,14 @@ public void testBulkMetaMatching() { Vector matchedRecords = storage.getRecordsForValues(new String[]{Shoe.META_BRAND, Shoe.META_STYLE}, new String[]{"nike", "mens"}); Assert.assertEquals("Failed index match [brand,style][nike,mens]", getIdsFromModels(tenSizesOfMensNikes), getIdsFromModels(matchedRecords.toArray(new Shoe[]{}))); - Vector matchedSortedRecords = storage.getSortedRecordsForValues(new String[]{Shoe.META_BRAND, Shoe.META_STYLE}, new String[]{"addidas", "mens"},Shoe.META_SIZE+" DESC"); - Assert.assertArrayEquals("Failed index match [brand,style][vans,mens]", fiveSortedSizesOfMensAddidas,matchedSortedRecords.toArray()); + Vector matchedSortedRecords = storage.getSortedRecordsForValues(new String[]{Shoe.META_BRAND, Shoe.META_STYLE}, new String[]{"adidas", "mens"},Shoe.META_SIZE+" DESC"); + Assert.assertArrayEquals("Failed index match [brand,style][adidas,mens]", fiveSortedSizesOfMensAdidas,matchedSortedRecords.toArray()); + Vector matchedAscSortedRecords = storage.getSortedRecordsForValues(new String[]{Shoe.META_BRAND, Shoe.META_STYLE}, new String[]{"vans", "mens"},Shoe.META_SIZE+" ASC"); + Assert.assertArrayEquals("Failed index match [brand,style][adidas,mens]", matchedAscSortedRecords.toArray(),fiveSizesOfMensVans); + Vector matchedAscSortedRecordsTest = storage.getSortedRecordsForValues(new String[]{Shoe.META_BRAND, Shoe.META_STYLE}, new String[]{"vans", "mens"},Shoe.META_SIZE+" ASSC"); + Assert.assertArrayEquals("Failed index match [brand,style][adidas,mens]", matchedAscSortedRecords.toArray(),fiveSizesOfMensVans); } @Test @@ -149,7 +153,7 @@ private void writeBulkSets() { writeAll(tenSizesOfMensNikes); writeAll(eightSizesOfWomensNikes); writeAll(fiveSizesOfMensVans); - writeAll(fiveSortedSizesOfMensAddidas); + writeAll(fiveSortedSizesOfMensAdidas); } Set getIdsFromModels(Shoe[] shoes) { From 0716f1d898192665e4c1c899d1d1d6df0813e149 Mon Sep 17 00:00:00 2001 From: pm-dimagi Date: Wed, 5 Feb 2025 21:19:01 +0530 Subject: [PATCH 3/6] update the code according to pr review --- .../storage/IStorageUtilityIndexed.java | 19 ++++++------------- .../util/DummyIndexedStorageUtility.java | 2 -- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/javarosa/core/services/storage/IStorageUtilityIndexed.java b/src/main/java/org/javarosa/core/services/storage/IStorageUtilityIndexed.java index 71add2d6c1..cffa7d4668 100644 --- a/src/main/java/org/javarosa/core/services/storage/IStorageUtilityIndexed.java +++ b/src/main/java/org/javarosa/core/services/storage/IStorageUtilityIndexed.java @@ -254,26 +254,19 @@ public interface IStorageUtilityIndexed { Vector getSortedRecordsForValues(String[] metaFieldNames, Object[] values,String orderby); /** - * Load multiple record objects from storage at one time from a list of record ids. + * Load multiple record objects from storage at one time from a list of record ids in sorted way. *

* If the provided recordMap already contains entries for any ids, it is _not_ * required for them to be retrieved from storage again. * - * - * metaFieldNames Array of metadata field names to match + * metaFieldNames Array of metadata field names to match * values Array of values corresponding to the field names - * orderby String in format "fieldName [ASC|DESC]". If null or empty, records are returned unsorted. - * ASC/DESC is case-insensitive. If direction is omitted, defaults to ASC. - * If field doesn't exist or is invalid, returns unsorted records. + * orderby String in format "fieldName [ASC|DESC]". If null or empty, records are returned unsorted. + * ASC/DESC is case-insensitive. If direction is omitted, defaults to ASC. + * If field doesn't exist or is invalid, returns unsorted records. * @return Vector of records matching the criteria, sorted if orderby is valid * - * @throws RequestAbandonedException If the current request is abandoned, this method - * - * @throws RequestAbandonedException If the current request is abandoned, this method will - * throw a RequestAbandonedException. Callers should not - * generally catch that exception unless they rethrow it - * or another exception, but they should anticipate that - * they may need to clean up if the bulk read doesn't complete + * @throws Exception If the current request if there is any issue during the comparison */ diff --git a/src/main/java/org/javarosa/core/services/storage/util/DummyIndexedStorageUtility.java b/src/main/java/org/javarosa/core/services/storage/util/DummyIndexedStorageUtility.java index 550058741b..7e1d852d44 100644 --- a/src/main/java/org/javarosa/core/services/storage/util/DummyIndexedStorageUtility.java +++ b/src/main/java/org/javarosa/core/services/storage/util/DummyIndexedStorageUtility.java @@ -217,8 +217,6 @@ public int compare(T record1, T record2) { return isAscending ? comparison : -comparison; } } catch (Exception e) { - // Log error and continue with no ordering - System.err.println("Failed to compare records: " + e.getMessage()); } return 0; // Default to no ordering if field access fails } From 90070233bac34eacf2cdb56e84676511fe70f945 Mon Sep 17 00:00:00 2001 From: pm-dimagi Date: Tue, 11 Feb 2025 00:12:39 +0530 Subject: [PATCH 4/6] added the illegal argument exception on wrong input type --- .../services/storage/IStorageUtilityIndexed.java | 4 ++-- .../storage/util/DummyIndexedStorageUtility.java | 4 ++-- .../core/storage/IndexedStorageUtilityTests.java | 14 ++++++++++++-- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/javarosa/core/services/storage/IStorageUtilityIndexed.java b/src/main/java/org/javarosa/core/services/storage/IStorageUtilityIndexed.java index cffa7d4668..8b455f6642 100644 --- a/src/main/java/org/javarosa/core/services/storage/IStorageUtilityIndexed.java +++ b/src/main/java/org/javarosa/core/services/storage/IStorageUtilityIndexed.java @@ -251,7 +251,7 @@ public interface IStorageUtilityIndexed { * they may need to clean up if the bulk read doesn't complete */ - Vector getSortedRecordsForValues(String[] metaFieldNames, Object[] values,String orderby); + Vector getSortedRecordsForValues(String[] metaFieldNames, Object[] values,String orderby) throws IllegalArgumentException; /** * Load multiple record objects from storage at one time from a list of record ids in sorted way. @@ -266,7 +266,7 @@ public interface IStorageUtilityIndexed { * If field doesn't exist or is invalid, returns unsorted records. * @return Vector of records matching the criteria, sorted if orderby is valid * - * @throws Exception If the current request if there is any issue during the comparison + * @throws IllegalArgumentException If the argument is there or spelling mistake in ASC|DESC */ diff --git a/src/main/java/org/javarosa/core/services/storage/util/DummyIndexedStorageUtility.java b/src/main/java/org/javarosa/core/services/storage/util/DummyIndexedStorageUtility.java index 7e1d852d44..9afdc99d53 100644 --- a/src/main/java/org/javarosa/core/services/storage/util/DummyIndexedStorageUtility.java +++ b/src/main/java/org/javarosa/core/services/storage/util/DummyIndexedStorageUtility.java @@ -177,7 +177,7 @@ public Vector getRecordsForValues(String[] metaFieldNames, Object[] values) { } @Override - public Vector getSortedRecordsForValues(String[] metaFieldNames, Object[] values, String orderby) { + public Vector getSortedRecordsForValues(String[] metaFieldNames, Object[] values, String orderby) throws IllegalArgumentException{ Vector matches = new Vector<>(); List idMatches = getIDsForValues(metaFieldNames, values); @@ -191,7 +191,7 @@ public Vector getSortedRecordsForValues(String[] metaFieldNames, Object[] val // Parse orderBy into field and direction if (!orderby.matches("^\\w+\\s*(ASC|DESC)?\\s*$")) { - return matches; // Invalid format, return unsorted + throw new IllegalArgumentException("Invalid format"); } String[] orderParts = orderby.trim().split("\\s+"); String fieldName = orderParts[0]; diff --git a/src/test/java/org/javarosa/core/storage/IndexedStorageUtilityTests.java b/src/test/java/org/javarosa/core/storage/IndexedStorageUtilityTests.java index 85988b1cf5..23d6c93131 100644 --- a/src/test/java/org/javarosa/core/storage/IndexedStorageUtilityTests.java +++ b/src/test/java/org/javarosa/core/storage/IndexedStorageUtilityTests.java @@ -135,8 +135,18 @@ public void testBulkMetaMatching() { Vector matchedAscSortedRecords = storage.getSortedRecordsForValues(new String[]{Shoe.META_BRAND, Shoe.META_STYLE}, new String[]{"vans", "mens"},Shoe.META_SIZE+" ASC"); Assert.assertArrayEquals("Failed index match [brand,style][adidas,mens]", matchedAscSortedRecords.toArray(),fiveSizesOfMensVans); - Vector matchedAscSortedRecordsTest = storage.getSortedRecordsForValues(new String[]{Shoe.META_BRAND, Shoe.META_STYLE}, new String[]{"vans", "mens"},Shoe.META_SIZE+" ASSC"); - Assert.assertArrayEquals("Failed index match [brand,style][adidas,mens]", matchedAscSortedRecords.toArray(),fiveSizesOfMensVans); + try { + Vector matchedAscSortedRecordsWithoutKey = storage.getSortedRecordsForValues(new String[]{Shoe.META_BRAND, Shoe.META_STYLE}, new String[]{"vans", "mens"}, " DESC"); + Assert.assertArrayEquals("Failed the sorted match [brand,style][vans,mens]", fiveSizesOfMensVans, fiveSizesOfMensVans); + }catch (IllegalArgumentException e){ + Assert.assertArrayEquals(e.getMessage(), matchedAscSortedRecords.toArray(), fiveSizesOfMensVans); + } + try { + Vector matchedAscSortedRecordsTest = storage.getSortedRecordsForValues(new String[]{Shoe.META_BRAND, Shoe.META_STYLE}, new String[]{"vans", "mens"}, Shoe.META_SIZE + " ASSC"); + Assert.assertArrayEquals("Failed index match [brand,style][adidas,mens]", matchedAscSortedRecords.toArray(), fiveSizesOfMensVans); + }catch (IllegalArgumentException e){ + Assert.assertArrayEquals(e.getMessage(), matchedAscSortedRecords.toArray(), fiveSizesOfMensVans); + } } @Test From ef8e6fbbf12c42439d98ce46357dba37f8e59fdd Mon Sep 17 00:00:00 2001 From: pm-dimagi Date: Tue, 11 Feb 2025 15:50:21 +0530 Subject: [PATCH 5/6] handled the catch and compare the right objects --- .../core/storage/IndexedStorageUtilityTests.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/test/java/org/javarosa/core/storage/IndexedStorageUtilityTests.java b/src/test/java/org/javarosa/core/storage/IndexedStorageUtilityTests.java index 23d6c93131..e4d43e2799 100644 --- a/src/test/java/org/javarosa/core/storage/IndexedStorageUtilityTests.java +++ b/src/test/java/org/javarosa/core/storage/IndexedStorageUtilityTests.java @@ -136,16 +136,16 @@ public void testBulkMetaMatching() { Assert.assertArrayEquals("Failed index match [brand,style][adidas,mens]", matchedAscSortedRecords.toArray(),fiveSizesOfMensVans); try { - Vector matchedAscSortedRecordsWithoutKey = storage.getSortedRecordsForValues(new String[]{Shoe.META_BRAND, Shoe.META_STYLE}, new String[]{"vans", "mens"}, " DESC"); - Assert.assertArrayEquals("Failed the sorted match [brand,style][vans,mens]", fiveSizesOfMensVans, fiveSizesOfMensVans); + Vector matchedDescSortedRecordsWithoutKey = storage.getSortedRecordsForValues(new String[]{Shoe.META_BRAND, Shoe.META_STYLE}, new String[]{"adidas", "mens"}, " DESC"); + Assert.assertArrayEquals("Failed the sorted match [brand,style][adidas,mens]", matchedDescSortedRecordsWithoutKey.toArray(), fiveSortedSizesOfMensAdidas); }catch (IllegalArgumentException e){ - Assert.assertArrayEquals(e.getMessage(), matchedAscSortedRecords.toArray(), fiveSizesOfMensVans); + System.out.println(e.getMessage()); } try { Vector matchedAscSortedRecordsTest = storage.getSortedRecordsForValues(new String[]{Shoe.META_BRAND, Shoe.META_STYLE}, new String[]{"vans", "mens"}, Shoe.META_SIZE + " ASSC"); - Assert.assertArrayEquals("Failed index match [brand,style][adidas,mens]", matchedAscSortedRecords.toArray(), fiveSizesOfMensVans); + Assert.assertArrayEquals("Failed the sorted match [brand,style][adidas,mens]", matchedAscSortedRecordsTest.toArray(), fiveSizesOfMensVans); }catch (IllegalArgumentException e){ - Assert.assertArrayEquals(e.getMessage(), matchedAscSortedRecords.toArray(), fiveSizesOfMensVans); + System.out.println(e.getMessage()); } } From 5cfdff9d4bc6bdd02a33e63261f6149f1b7ac556 Mon Sep 17 00:00:00 2001 From: pm-dimagi Date: Tue, 11 Feb 2025 16:55:26 +0530 Subject: [PATCH 6/6] updated the java docs --- .../storage/IStorageUtilityIndexed.java | 33 +++++++++---------- .../util/DummyIndexedStorageUtility.java | 2 +- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/main/java/org/javarosa/core/services/storage/IStorageUtilityIndexed.java b/src/main/java/org/javarosa/core/services/storage/IStorageUtilityIndexed.java index 8b455f6642..3cb37042ff 100644 --- a/src/main/java/org/javarosa/core/services/storage/IStorageUtilityIndexed.java +++ b/src/main/java/org/javarosa/core/services/storage/IStorageUtilityIndexed.java @@ -238,21 +238,6 @@ public interface IStorageUtilityIndexed { */ Vector getRecordsForValues(String[] metaFieldNames, Object[] values); - /** - * Load multiple record objects from storage at one time from a list of record ids. - *

- * If the provided recordMap already contains entries for any ids, it is _not_ - * required for them to be retrieved from storage again. - * - * @throws RequestAbandonedException If the current request is abandoned, this method will - * throw a RequestAbandonedException. Callers should not - * generally catch that exception unless they rethrow it - * or another exception, but they should anticipate that - * they may need to clean up if the bulk read doesn't complete - */ - - Vector getSortedRecordsForValues(String[] metaFieldNames, Object[] values,String orderby) throws IllegalArgumentException; - /** * Load multiple record objects from storage at one time from a list of record ids in sorted way. *

@@ -263,13 +248,27 @@ public interface IStorageUtilityIndexed { * values Array of values corresponding to the field names * orderby String in format "fieldName [ASC|DESC]". If null or empty, records are returned unsorted. * ASC/DESC is case-insensitive. If direction is omitted, defaults to ASC. - * If field doesn't exist or is invalid, returns unsorted records. * @return Vector of records matching the criteria, sorted if orderby is valid * - * @throws IllegalArgumentException If the argument is there or spelling mistake in ASC|DESC + * @throws IllegalArgumentException If the argument is there or spelling mistake in ASC|DESC or there + * is parameter missing for the orderby */ + Vector getSortedRecordsForValues(String[] metaFieldNames, Object[] values,String orderby) throws IllegalArgumentException; + + /** + * Load multiple record objects from storage at one time from a list of record ids. + *

+ * If the provided recordMap already contains entries for any ids, it is _not_ + * required for them to be retrieved from storage again. + * + * @throws RequestAbandonedException If the current request is abandoned, this method will + * throw a RequestAbandonedException. Callers should not + * generally catch that exception unless they rethrow it + * or another exception, but they should anticipate that + * they may need to clean up if the bulk read doesn't complete + */ void bulkRead(LinkedHashSet cuedCases, HashMap recordMap) throws RequestAbandonedException; diff --git a/src/main/java/org/javarosa/core/services/storage/util/DummyIndexedStorageUtility.java b/src/main/java/org/javarosa/core/services/storage/util/DummyIndexedStorageUtility.java index 9afdc99d53..e08f6c05f2 100644 --- a/src/main/java/org/javarosa/core/services/storage/util/DummyIndexedStorageUtility.java +++ b/src/main/java/org/javarosa/core/services/storage/util/DummyIndexedStorageUtility.java @@ -216,7 +216,7 @@ public int compare(T record1, T record2) { int comparison = ((Comparable) value1).compareTo(value2); return isAscending ? comparison : -comparison; } - } catch (Exception e) { + } catch (Exception ignore) { } return 0; // Default to no ordering if field access fails }