mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 05:01:07 +00:00
sprint-14: minor updates to allow flexibility when extending loadviainsertorupdatestep
This commit is contained in:
@ -37,6 +37,7 @@ import com.kingsrook.qqq.backend.core.model.actions.tables.update.UpdateInput;
|
|||||||
import com.kingsrook.qqq.backend.core.model.actions.tables.update.UpdateOutput;
|
import com.kingsrook.qqq.backend.core.model.actions.tables.update.UpdateOutput;
|
||||||
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.CollectionUtils;
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
@ -49,6 +50,9 @@ public class LoadViaInsertOrUpdateStep extends AbstractLoadStep
|
|||||||
{
|
{
|
||||||
public static final String FIELD_DESTINATION_TABLE = "destinationTable";
|
public static final String FIELD_DESTINATION_TABLE = "destinationTable";
|
||||||
|
|
||||||
|
protected List<QRecord> recordsToInsert = null;
|
||||||
|
protected List<QRecord> recordsToUpdate = null;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
@ -58,22 +62,10 @@ public class LoadViaInsertOrUpdateStep extends AbstractLoadStep
|
|||||||
@Override
|
@Override
|
||||||
public void run(RunBackendStepInput runBackendStepInput, RunBackendStepOutput runBackendStepOutput) throws QException
|
public void run(RunBackendStepInput runBackendStepInput, RunBackendStepOutput runBackendStepOutput) throws QException
|
||||||
{
|
{
|
||||||
QTableMetaData tableMetaData = runBackendStepInput.getInstance().getTable(runBackendStepInput.getValueString(FIELD_DESTINATION_TABLE));
|
QTableMetaData tableMetaData = runBackendStepInput.getInstance().getTable(runBackendStepInput.getValueString(FIELD_DESTINATION_TABLE));
|
||||||
List<QRecord> recordsToInsert = new ArrayList<>();
|
evaluateRecords(runBackendStepInput);
|
||||||
List<QRecord> recordsToUpdate = new ArrayList<>();
|
|
||||||
for(QRecord record : runBackendStepInput.getRecords())
|
|
||||||
{
|
|
||||||
if(record.getValue(tableMetaData.getPrimaryKeyField()) == null)
|
|
||||||
{
|
|
||||||
recordsToInsert.add(record);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
recordsToUpdate.add(record);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!recordsToInsert.isEmpty())
|
if(CollectionUtils.nullSafeHasContents(recordsToInsert))
|
||||||
{
|
{
|
||||||
InsertInput insertInput = new InsertInput(runBackendStepInput.getInstance());
|
InsertInput insertInput = new InsertInput(runBackendStepInput.getInstance());
|
||||||
insertInput.setSession(runBackendStepInput.getSession());
|
insertInput.setSession(runBackendStepInput.getSession());
|
||||||
@ -84,7 +76,7 @@ public class LoadViaInsertOrUpdateStep extends AbstractLoadStep
|
|||||||
runBackendStepOutput.getRecords().addAll(insertOutput.getRecords());
|
runBackendStepOutput.getRecords().addAll(insertOutput.getRecords());
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!recordsToUpdate.isEmpty())
|
if(CollectionUtils.nullSafeHasContents(recordsToUpdate))
|
||||||
{
|
{
|
||||||
UpdateInput updateInput = new UpdateInput(runBackendStepInput.getInstance());
|
UpdateInput updateInput = new UpdateInput(runBackendStepInput.getInstance());
|
||||||
updateInput.setSession(runBackendStepInput.getSession());
|
updateInput.setSession(runBackendStepInput.getSession());
|
||||||
@ -110,4 +102,27 @@ public class LoadViaInsertOrUpdateStep extends AbstractLoadStep
|
|||||||
|
|
||||||
return (Optional.of(new InsertAction().openTransaction(insertInput)));
|
return (Optional.of(new InsertAction().openTransaction(insertInput)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
protected void evaluateRecords(RunBackendStepInput runBackendStepInput) throws QException
|
||||||
|
{
|
||||||
|
QTableMetaData tableMetaData = runBackendStepInput.getInstance().getTable(runBackendStepInput.getValueString(FIELD_DESTINATION_TABLE));
|
||||||
|
recordsToInsert = new ArrayList<>();
|
||||||
|
recordsToUpdate = new ArrayList<>();
|
||||||
|
for(QRecord record : runBackendStepInput.getRecords())
|
||||||
|
{
|
||||||
|
if(record.getValue(tableMetaData.getPrimaryKeyField()) == null)
|
||||||
|
{
|
||||||
|
recordsToInsert.add(record);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
recordsToUpdate.add(record);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -374,7 +374,7 @@ public class BaseAPIActionUtil
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
**
|
**
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
private JSONObject getJsonObject(HttpResponse response) throws IOException
|
protected JSONObject getJsonObject(HttpResponse response) throws IOException
|
||||||
{
|
{
|
||||||
int statusCode = response.getStatusLine().getStatusCode();
|
int statusCode = response.getStatusLine().getStatusCode();
|
||||||
LOG.debug(statusCode);
|
LOG.debug(statusCode);
|
||||||
|
Reference in New Issue
Block a user