CE-937 Remove withSecurityKeyValues that took a list and added all of them - felt a little unclear (did it replace or append to the list under the key?). now just replace the entire Map<String, List<Serializable>> yourself, or add them one-by-one. Updated tests accordingly.

This commit is contained in:
2024-02-26 14:34:12 -06:00
parent 878f374cb5
commit 7d25fc7390
6 changed files with 66 additions and 55 deletions

View File

@ -48,6 +48,7 @@ public class QSession implements Serializable
private String uuid;
private Set<String> permissions;
private Map<String, List<Serializable>> securityKeyValues;
private Map<String, Serializable> backendVariants;
@ -337,15 +338,10 @@ public class QSession implements Serializable
/*******************************************************************************
** Fluent setter for securityKeyValues - add a list of values for 1 key
** Fluent setter for securityKeyValues - add 1 value for 1 key.
*******************************************************************************/
public QSession withSecurityKeyValues(String keyName, List<Serializable> values)
public QSession withSecurityKeyValue(String keyName, Serializable value)
{
if(values == null)
{
return (this);
}
if(securityKeyValues == null)
{
securityKeyValues = new HashMap<>();
@ -355,12 +351,15 @@ public class QSession implements Serializable
try
{
securityKeyValues.get(keyName).addAll(values);
securityKeyValues.get(keyName).add(value);
}
catch(UnsupportedOperationException uoe)
{
/////////////////////
// grr, List.of... //
/////////////////////
securityKeyValues.put(keyName, new ArrayList<>(securityKeyValues.get(keyName)));
securityKeyValues.get(keyName).addAll(values);
securityKeyValues.get(keyName).add(value);
}
return (this);
@ -368,16 +367,6 @@ public class QSession implements Serializable
/*******************************************************************************
** Fluent setter for securityKeyValues - add 1 value for 1 key.
*******************************************************************************/
public QSession withSecurityKeyValue(String keyName, Serializable value)
{
return (withSecurityKeyValues(keyName, List.of(value)));
}
/*******************************************************************************
** Clear the map of security key values in the session.
*******************************************************************************/

View File

@ -328,7 +328,7 @@ class InsertActionTest extends BaseTest
// insert an order and lineItem with storeId=2 - then, reset our session to only have storeId=1 in it - and try to insert an order-line referencing that order. //
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
QContext.getQSession().withSecurityKeyValues(new HashMap<>());
QContext.getQSession().withSecurityKeyValues(TestUtils.SECURITY_KEY_TYPE_STORE, List.of(2));
QContext.getQSession().withSecurityKeyValue(TestUtils.SECURITY_KEY_TYPE_STORE, 2);
InsertInput insertOrderInput = new InsertInput();
insertOrderInput.setTableName(TestUtils.TABLE_NAME_ORDER);
insertOrderInput.setRecords(List.of(new QRecord().withValue("id", 42).withValue("storeId", 2)));
@ -342,7 +342,7 @@ class InsertActionTest extends BaseTest
assertEquals(4200, insertLineItemOutput.getRecords().get(0).getValueInteger("id"));
QContext.getQSession().withSecurityKeyValues(new HashMap<>());
QContext.getQSession().withSecurityKeyValues(TestUtils.SECURITY_KEY_TYPE_STORE, List.of(1));
QContext.getQSession().withSecurityKeyValue(TestUtils.SECURITY_KEY_TYPE_STORE, 1);
InsertInput insertLineItemExtrinsicInput = new InsertInput();
insertLineItemExtrinsicInput.setTableName(TestUtils.TABLE_NAME_LINE_ITEM_EXTRINSIC);
insertLineItemExtrinsicInput.setRecords(List.of(new QRecord().withValue("lineItemId", 4200).withValue("key", "kidsCanCallYou").withValue("value", "HoJu")));
@ -352,7 +352,7 @@ class InsertActionTest extends BaseTest
{
QContext.getQSession().withSecurityKeyValues(new HashMap<>());
QContext.getQSession().withSecurityKeyValues(TestUtils.SECURITY_KEY_TYPE_STORE, List.of(1));
QContext.getQSession().withSecurityKeyValue(TestUtils.SECURITY_KEY_TYPE_STORE, 1);
InsertInput insertOrderInput = new InsertInput();
insertOrderInput.setTableName(TestUtils.TABLE_NAME_ORDER);
insertOrderInput.setRecords(List.of(new QRecord().withValue("id", 47).withValue("storeId", 1)));
@ -450,7 +450,7 @@ class InsertActionTest extends BaseTest
// insert an order with storeId=2 - then, reset our session to only have storeId=1 in it - and try to insert an order-line referencing that order. //
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
QContext.getQSession().withSecurityKeyValues(new HashMap<>());
QContext.getQSession().withSecurityKeyValues(TestUtils.SECURITY_KEY_TYPE_STORE, List.of(2));
QContext.getQSession().withSecurityKeyValue(TestUtils.SECURITY_KEY_TYPE_STORE, 2);
InsertInput insertOrderInput = new InsertInput();
insertOrderInput.setTableName(TestUtils.TABLE_NAME_ORDER);
insertOrderInput.setRecords(List.of(new QRecord().withValue("id", 42).withValue("storeId", 2)));
@ -458,7 +458,7 @@ class InsertActionTest extends BaseTest
assertEquals(42, insertOrderOutput.getRecords().get(0).getValueInteger("id"));
QContext.getQSession().withSecurityKeyValues(new HashMap<>());
QContext.getQSession().withSecurityKeyValues(TestUtils.SECURITY_KEY_TYPE_STORE, List.of(1));
QContext.getQSession().withSecurityKeyValue(TestUtils.SECURITY_KEY_TYPE_STORE, 1);
InsertInput insertLineItemInput = new InsertInput();
insertLineItemInput.setTableName(TestUtils.TABLE_NAME_LINE_ITEM);
insertLineItemInput.setRecords(List.of(new QRecord().withValue("orderId", 42).withValue("sku", "BASIC1").withValue("quantity", 1)));
@ -468,7 +468,7 @@ class InsertActionTest extends BaseTest
{
QContext.getQSession().withSecurityKeyValues(new HashMap<>());
QContext.getQSession().withSecurityKeyValues(TestUtils.SECURITY_KEY_TYPE_STORE, List.of(1));
QContext.getQSession().withSecurityKeyValue(TestUtils.SECURITY_KEY_TYPE_STORE, 1);
InsertInput insertOrderInput = new InsertInput();
insertOrderInput.setTableName(TestUtils.TABLE_NAME_ORDER);
insertOrderInput.setRecords(List.of(new QRecord().withValue("id", 47).withValue("storeId", 1)));

View File

@ -52,7 +52,8 @@ class QSessionTest extends BaseTest
assertEquals(List.of(1701), session.getSecurityKeyValues("warehouseId"));
assertEquals(List.of(), session.getSecurityKeyValues("tenantId"));
session.withSecurityKeyValues("clientId", List.of(256, 512));
session.withSecurityKeyValue("clientId", 256);
session.withSecurityKeyValue("clientId", 512);
for(int i : List.of(42, 47, 256, 512))
{
assertTrue(session.hasSecurityKeyValue("clientId", i), "Should contain: " + i);