mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 13:10:44 +00:00
Missed things re: custom pvs
This commit is contained in:
@ -22,6 +22,7 @@
|
||||
package com.kingsrook.qqq.backend.core.actions.dashboard.widgets;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.time.Instant;
|
||||
@ -270,6 +271,16 @@ public class NoCodeWidgetVelocityUtils
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
public String format(String displayFormat, Serializable value)
|
||||
{
|
||||
return (QValueFormatter.formatValue(displayFormat, value));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
|
@ -36,18 +36,20 @@ import com.kingsrook.qqq.backend.core.utils.ValueUtils;
|
||||
/*******************************************************************************
|
||||
** Interface to be implemented by user-defined code that serves as the backing
|
||||
** for a CUSTOM type possibleValueSource
|
||||
**
|
||||
** Type parameter `T` is the id-type of the possible value.
|
||||
*******************************************************************************/
|
||||
public interface QCustomPossibleValueProvider
|
||||
public interface QCustomPossibleValueProvider<T extends Serializable>
|
||||
{
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
QPossibleValue<?> getPossibleValue(Serializable idValue);
|
||||
QPossibleValue<T> getPossibleValue(Serializable idValue);
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
List<QPossibleValue<?>> search(SearchPossibleValueSourceInput input) throws QException;
|
||||
List<QPossibleValue<T>> search(SearchPossibleValueSourceInput input) throws QException;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
@ -55,7 +57,7 @@ public interface QCustomPossibleValueProvider
|
||||
** the type of the ids in the enum (e.g., strings from a frontend, integers
|
||||
** in an enum). So, this method looks maps a list of input ids to the requested type.
|
||||
*******************************************************************************/
|
||||
default <T extends Serializable> List<T> convertInputIdsToIdType(Class<T> type, List<Serializable> inputIdList)
|
||||
default List<T> convertInputIdsToIdType(Class<T> type, List<Serializable> inputIdList)
|
||||
{
|
||||
List<T> rs = new ArrayList<>();
|
||||
if(CollectionUtils.nullSafeIsEmpty(inputIdList))
|
||||
@ -75,10 +77,8 @@ public interface QCustomPossibleValueProvider
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
default <T extends Serializable> boolean doesPossibleValueMatchSearchInput(Class<T> idType, QPossibleValue<T> possibleValue, SearchPossibleValueSourceInput input)
|
||||
default boolean doesPossibleValueMatchSearchInput(List<T> idsInType, QPossibleValue<T> possibleValue, SearchPossibleValueSourceInput input)
|
||||
{
|
||||
List<T> idsInType = convertInputIdsToIdType(idType, input.getIdList());
|
||||
|
||||
boolean match = false;
|
||||
if(input.getIdList() != null)
|
||||
{
|
||||
|
@ -25,6 +25,7 @@ package com.kingsrook.qqq.backend.core.model.metadata.possiblevalues;
|
||||
/*******************************************************************************
|
||||
** An actual possible value - an id and label.
|
||||
**
|
||||
** Type parameter `T` is the type of the id (often Integer, maybe String)
|
||||
*******************************************************************************/
|
||||
public class QPossibleValue<T>
|
||||
{
|
||||
|
@ -224,6 +224,82 @@ class SearchPossibleValueSourceActionTest extends BaseTest
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testSearchPvsAction_customSearchTermFound() throws QException
|
||||
{
|
||||
SearchPossibleValueSourceOutput output = getSearchPossibleValueSourceOutput("Custom[3]", TestUtils.POSSIBLE_VALUE_SOURCE_CUSTOM);
|
||||
assertEquals(1, output.getResults().size());
|
||||
assertThat(output.getResults()).anyMatch(pv -> pv.getId().equals("3") && pv.getLabel().equals("Custom[3]"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testSearchPvsAction_customSearchTermNotFound() throws QException
|
||||
{
|
||||
SearchPossibleValueSourceOutput output = getSearchPossibleValueSourceOutput("Foo", TestUtils.POSSIBLE_VALUE_SOURCE_CUSTOM);
|
||||
assertEquals(0, output.getResults().size());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testSearchPvsAction_customSearchTermManyFound() throws QException
|
||||
{
|
||||
SearchPossibleValueSourceOutput output = getSearchPossibleValueSourceOutput("Custom", TestUtils.POSSIBLE_VALUE_SOURCE_CUSTOM);
|
||||
assertEquals(10, output.getResults().size());
|
||||
assertThat(output.getResults()).allMatch(pv -> pv.getLabel().startsWith("Custom["));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testSearchPvsAction_customIdFound() throws QException
|
||||
{
|
||||
SearchPossibleValueSourceOutput output = getSearchPossibleValueSourceOutputById("4", TestUtils.POSSIBLE_VALUE_SOURCE_CUSTOM);
|
||||
assertEquals(1, output.getResults().size());
|
||||
assertThat(output.getResults()).anyMatch(pv -> pv.getId().equals("4") && pv.getLabel().equals("Custom[4]"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testSearchPvsAction_customIdFoundDifferentType() throws QException
|
||||
{
|
||||
SearchPossibleValueSourceOutput output = getSearchPossibleValueSourceOutputById(5, TestUtils.POSSIBLE_VALUE_SOURCE_CUSTOM);
|
||||
assertEquals(1, output.getResults().size());
|
||||
assertThat(output.getResults()).anyMatch(pv -> pv.getId().equals("5") && pv.getLabel().equals("Custom[5]"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testSearchPvsAction_customIdNotFound() throws QException
|
||||
{
|
||||
SearchPossibleValueSourceOutput output = getSearchPossibleValueSourceOutputById(-1, TestUtils.POSSIBLE_VALUE_SOURCE_CUSTOM);
|
||||
assertEquals(0, output.getResults().size());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
|
@ -1083,16 +1083,16 @@ public class TestUtils
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
public static class CustomPossibleValueSource implements QCustomPossibleValueProvider
|
||||
public static class CustomPossibleValueSource implements QCustomPossibleValueProvider<String>
|
||||
{
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public QPossibleValue<?> getPossibleValue(Serializable idValue)
|
||||
public QPossibleValue<String> getPossibleValue(Serializable idValue)
|
||||
{
|
||||
return (new QPossibleValue<>(idValue, "Custom[" + idValue + "]"));
|
||||
return (new QPossibleValue<>(ValueUtils.getValueAsString(idValue), "Custom[" + idValue + "]"));
|
||||
}
|
||||
|
||||
|
||||
@ -1101,9 +1101,19 @@ public class TestUtils
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Override
|
||||
public List<QPossibleValue<?>> search(SearchPossibleValueSourceInput input)
|
||||
public List<QPossibleValue<String>> search(SearchPossibleValueSourceInput input)
|
||||
{
|
||||
return (new ArrayList<>());
|
||||
List<QPossibleValue<String>> rs = new ArrayList<>();
|
||||
for(int i = 0; i < 10; i++)
|
||||
{
|
||||
QPossibleValue<String> possibleValue = getPossibleValue(i);
|
||||
List<String> idsInType = convertInputIdsToIdType(String.class, input.getIdList());
|
||||
if(doesPossibleValueMatchSearchInput(idsInType, possibleValue, input))
|
||||
{
|
||||
rs.add(possibleValue);
|
||||
}
|
||||
}
|
||||
return (rs);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user