fixes for unit test where create date was being specified before insert action

This commit is contained in:
Tim Chamberlain
2023-11-30 14:37:17 -06:00
parent 081be690d5
commit 4c1298d531
3 changed files with 15 additions and 6 deletions

View File

@ -26,6 +26,8 @@ import java.io.Serializable;
import com.kingsrook.qqq.backend.core.actions.interfaces.QActionInterface; import com.kingsrook.qqq.backend.core.actions.interfaces.QActionInterface;
import com.kingsrook.qqq.backend.core.model.data.QRecord; import com.kingsrook.qqq.backend.core.model.data.QRecord;
import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData; import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData;
import com.kingsrook.qqq.backend.core.utils.StringUtils;
import com.kingsrook.qqq.backend.core.utils.ValueUtils;
/******************************************************************************* /*******************************************************************************
@ -36,15 +38,22 @@ public abstract class AbstractMemoryAction implements QActionInterface
/******************************************************************************* /*******************************************************************************
** If the table has a field with the given name, then set the given value in the ** If the table has a field with the given name, then set the given value in the
** given record. ** given record - flag added to control overwriting value.
*******************************************************************************/ *******************************************************************************/
protected void setValueIfTableHasField(QRecord record, QTableMetaData table, String fieldName, Serializable value) protected void setValueIfTableHasField(QRecord record, QTableMetaData table, String fieldName, Serializable value, boolean overwriteIfSet)
{ {
try try
{ {
if(table.getFields().containsKey(fieldName)) if(table.getFields().containsKey(fieldName))
{ {
record.setValue(fieldName, value); ///////////////////////////////////////////////////////////////////////
// always set value if boolean to overwrite is true, otherwise, //
// only set the value if there is currently no content for the field //
///////////////////////////////////////////////////////////////////////
if(overwriteIfSet || !StringUtils.hasContent(ValueUtils.getValueAsString(table.getField(fieldName))))
{
record.setValue(fieldName, value);
}
} }
} }
catch(Exception e) catch(Exception e)

View File

@ -53,8 +53,8 @@ public class MemoryInsertAction extends AbstractMemoryAction implements InsertIn
/////////////////////////////////////////// ///////////////////////////////////////////
// todo .. better (not hard-coded names) // // todo .. better (not hard-coded names) //
/////////////////////////////////////////// ///////////////////////////////////////////
setValueIfTableHasField(record, table, "createDate", now); setValueIfTableHasField(record, table, "createDate", now, false);
setValueIfTableHasField(record, table, "modifyDate", now); setValueIfTableHasField(record, table, "modifyDate", now, false);
} }
InsertOutput insertOutput = new InsertOutput(); InsertOutput insertOutput = new InsertOutput();

View File

@ -53,7 +53,7 @@ public class MemoryUpdateAction extends AbstractMemoryAction implements UpdateIn
/////////////////////////////////////////// ///////////////////////////////////////////
// todo .. better (not hard-coded names) // // todo .. better (not hard-coded names) //
/////////////////////////////////////////// ///////////////////////////////////////////
setValueIfTableHasField(record, table, "modifyDate", now); setValueIfTableHasField(record, table, "modifyDate", now, false);
} }
UpdateOutput updateOutput = new UpdateOutput(); UpdateOutput updateOutput = new UpdateOutput();