Add toQRecordOnlyChangedFields

This commit is contained in:
2023-05-12 12:21:59 -05:00
parent 3e7684bb8d
commit 676783fdf5
3 changed files with 93 additions and 0 deletions

View File

@ -67,6 +67,35 @@ class QRecordEntityTest extends BaseTest
/*******************************************************************************
**
*******************************************************************************/
@Test
void testItemToQRecordOnlyChangedFields() throws QException
{
Item item = new Item(new QRecord()
.withValue("sku", "ABC-123")
.withValue("description", null)
.withValue("quantity", 47)
.withValue("price", new BigDecimal("3.50"))
.withValue("isFeatured", true));
QRecord qRecordOnlyChangedFields = item.toQRecordOnlyChangedFields();
assertTrue(qRecordOnlyChangedFields.getValues().isEmpty());
item.setDescription("My Changed Item");
qRecordOnlyChangedFields = item.toQRecordOnlyChangedFields();
assertEquals(1, qRecordOnlyChangedFields.getValues().size());
assertEquals("My Changed Item", qRecordOnlyChangedFields.getValueString("description"));
item.setPrice(null);
qRecordOnlyChangedFields = item.toQRecordOnlyChangedFields();
assertEquals(2, qRecordOnlyChangedFields.getValues().size());
assertNull(qRecordOnlyChangedFields.getValueString("price"));
}
/*******************************************************************************
**
*******************************************************************************/

View File

@ -24,6 +24,7 @@ package com.kingsrook.qqq.backend.core.model.data.testentities;
import java.math.BigDecimal;
import com.kingsrook.qqq.backend.core.model.data.QField;
import com.kingsrook.qqq.backend.core.model.data.QRecord;
import com.kingsrook.qqq.backend.core.model.data.QRecordEntity;
import com.kingsrook.qqq.backend.core.model.metadata.fields.DisplayFormat;
@ -49,6 +50,27 @@ public class Item extends QRecordEntity
/*******************************************************************************
** Constructor
**
*******************************************************************************/
public Item()
{
}
/*******************************************************************************
** Constructor
**
*******************************************************************************/
public Item(QRecord qRecord)
{
populateFromQRecord(qRecord);
}
/*******************************************************************************
** Getter for sku
**