diff --git a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/values/SearchPossibleValueSourceAction.java b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/values/SearchPossibleValueSourceAction.java index 3ba41d1d..5637972e 100644 --- a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/values/SearchPossibleValueSourceAction.java +++ b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/values/SearchPossibleValueSourceAction.java @@ -104,13 +104,15 @@ public class SearchPossibleValueSourceAction SearchPossibleValueSourceOutput output = new SearchPossibleValueSourceOutput(); List matchingIds = new ArrayList<>(); + List inputIdsAsCorrectType = convertInputIdsToEnumIdType(possibleValueSource, input.getIdList()); + for(QPossibleValue possibleValue : possibleValueSource.getEnumValues()) { boolean match = false; if(input.getIdList() != null) { - if(input.getIdList().contains(possibleValue.getId())) + if(inputIdsAsCorrectType.contains(possibleValue.getId())) { match = true; } @@ -145,6 +147,40 @@ public class SearchPossibleValueSourceAction + /******************************************************************************* + ** The input list of ids might come through as a type that isn't the same as + ** the type of the ids in the enum (e.g., strings from a frontend, integers + ** in an enum). So, this method looks at the first id in the enum, and then + ** maps all the inputIds to be of the same type. + *******************************************************************************/ + private List convertInputIdsToEnumIdType(QPossibleValueSource possibleValueSource, List inputIdList) + { + List rs = new ArrayList<>(); + + Object anIdFromTheEnum = possibleValueSource.getEnumValues().get(0).getId(); + + if(anIdFromTheEnum instanceof Integer) + { + inputIdList.forEach(id -> rs.add(ValueUtils.getValueAsInteger(id))); + } + else if(anIdFromTheEnum instanceof String) + { + inputIdList.forEach(id -> rs.add(ValueUtils.getValueAsString(id))); + } + else if(anIdFromTheEnum instanceof Boolean) + { + inputIdList.forEach(id -> rs.add(ValueUtils.getValueAsBoolean(id))); + } + else + { + LOG.warn("Unexpected type [" + anIdFromTheEnum.getClass().getSimpleName() + "] for ids in enum: " + possibleValueSource.getName()); + } + + return (rs); + } + + + /******************************************************************************* ** *******************************************************************************/ diff --git a/qqq-backend-core/src/test/java/com/kingsrook/qqq/backend/core/actions/values/SearchPossibleValueSourceActionTest.java b/qqq-backend-core/src/test/java/com/kingsrook/qqq/backend/core/actions/values/SearchPossibleValueSourceActionTest.java index d626db52..93a38fc5 100644 --- a/qqq-backend-core/src/test/java/com/kingsrook/qqq/backend/core/actions/values/SearchPossibleValueSourceActionTest.java +++ b/qqq-backend-core/src/test/java/com/kingsrook/qqq/backend/core/actions/values/SearchPossibleValueSourceActionTest.java @@ -116,6 +116,19 @@ class SearchPossibleValueSourceActionTest extends BaseTest + /******************************************************************************* + ** + *******************************************************************************/ + @Test + void testSearchPvsAction_enumByIdWrongType() throws QException + { + SearchPossibleValueSourceOutput output = getSearchPossibleValueSourceOutputById("2", TestUtils.POSSIBLE_VALUE_SOURCE_STATE); + assertEquals(1, output.getResults().size()); + assertThat(output.getResults()).anyMatch(pv -> pv.getId().equals(2) && pv.getLabel().equals("MO")); + } + + + /******************************************************************************* ** *******************************************************************************/ @@ -172,6 +185,19 @@ class SearchPossibleValueSourceActionTest extends BaseTest + /******************************************************************************* + ** + *******************************************************************************/ + @Test + void testSearchPvsAction_tableByIdWrongType() throws QException + { + SearchPossibleValueSourceOutput output = getSearchPossibleValueSourceOutputById("2", TestUtils.POSSIBLE_VALUE_SOURCE_SHAPE); + assertEquals(1, output.getResults().size()); + assertThat(output.getResults()).anyMatch(pv -> pv.getId().equals(2) && pv.getLabel().equals("Square")); + } + + + /******************************************************************************* ** *******************************************************************************/