mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 13:10:44 +00:00
CE-1955 Initial checkin
This commit is contained in:
@ -40,6 +40,9 @@ import com.kingsrook.qqq.backend.core.model.metadata.tables.QFieldSection;
|
|||||||
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.model.metadata.tables.Tier;
|
import com.kingsrook.qqq.backend.core.model.metadata.tables.Tier;
|
||||||
import com.kingsrook.qqq.backend.core.model.metadata.tables.UniqueKey;
|
import com.kingsrook.qqq.backend.core.model.metadata.tables.UniqueKey;
|
||||||
|
import com.kingsrook.qqq.backend.core.processes.implementations.savedbulkloadprofiles.DeleteSavedBulkLoadProfileProcess;
|
||||||
|
import com.kingsrook.qqq.backend.core.processes.implementations.savedbulkloadprofiles.QuerySavedBulkLoadProfileProcess;
|
||||||
|
import com.kingsrook.qqq.backend.core.processes.implementations.savedbulkloadprofiles.StoreSavedBulkLoadProfileProcess;
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
@ -68,6 +71,13 @@ public class SavedBulkLoadProfileMetaDataProvider
|
|||||||
{
|
{
|
||||||
instance.addPossibleValueSource(new ShareScopePossibleValueMetaDataProducer().produce(new QInstance()));
|
instance.addPossibleValueSource(new ShareScopePossibleValueMetaDataProducer().produce(new QInstance()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////
|
||||||
|
// processes for working with 'em //
|
||||||
|
////////////////////////////////////
|
||||||
|
instance.add(StoreSavedBulkLoadProfileProcess.getProcessMetaData());
|
||||||
|
instance.add(QuerySavedBulkLoadProfileProcess.getProcessMetaData());
|
||||||
|
instance.add(DeleteSavedBulkLoadProfileProcess.getProcessMetaData());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -0,0 +1,88 @@
|
|||||||
|
/*
|
||||||
|
* QQQ - Low-code Application Framework for Engineers.
|
||||||
|
* Copyright (C) 2021-2024. Kingsrook, LLC
|
||||||
|
* 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States
|
||||||
|
* contact@kingsrook.com
|
||||||
|
* https://github.com/Kingsrook/
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.kingsrook.qqq.backend.core.processes.implementations.savedbulkloadprofiles;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import com.kingsrook.qqq.backend.core.actions.ActionHelper;
|
||||||
|
import com.kingsrook.qqq.backend.core.actions.processes.BackendStep;
|
||||||
|
import com.kingsrook.qqq.backend.core.actions.tables.DeleteAction;
|
||||||
|
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
||||||
|
import com.kingsrook.qqq.backend.core.logging.QLogger;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.actions.processes.RunBackendStepInput;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.actions.processes.RunBackendStepOutput;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.actions.tables.delete.DeleteInput;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.metadata.code.QCodeReference;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.metadata.processes.QBackendStepMetaData;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.metadata.processes.QProcessMetaData;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.savedbulkloadprofiles.SavedBulkLoadProfile;
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Process used by the delete bulkLoadProfile dialog
|
||||||
|
*******************************************************************************/
|
||||||
|
public class DeleteSavedBulkLoadProfileProcess implements BackendStep
|
||||||
|
{
|
||||||
|
private static final QLogger LOG = QLogger.getLogger(DeleteSavedBulkLoadProfileProcess.class);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
public static QProcessMetaData getProcessMetaData()
|
||||||
|
{
|
||||||
|
return (new QProcessMetaData()
|
||||||
|
.withName("deleteSavedBulkLoadProfile")
|
||||||
|
.withStepList(List.of(
|
||||||
|
new QBackendStepMetaData()
|
||||||
|
.withCode(new QCodeReference(DeleteSavedBulkLoadProfileProcess.class))
|
||||||
|
.withName("delete")
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
@Override
|
||||||
|
public void run(RunBackendStepInput runBackendStepInput, RunBackendStepOutput runBackendStepOutput) throws QException
|
||||||
|
{
|
||||||
|
ActionHelper.validateSession(runBackendStepInput);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Integer savedBulkLoadProfileId = runBackendStepInput.getValueInteger("id");
|
||||||
|
|
||||||
|
DeleteInput input = new DeleteInput();
|
||||||
|
input.setTableName(SavedBulkLoadProfile.TABLE_NAME);
|
||||||
|
input.setPrimaryKeys(List.of(savedBulkLoadProfileId));
|
||||||
|
new DeleteAction().execute(input);
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
LOG.warn("Error deleting saved bulkLoadProfile", e);
|
||||||
|
throw (e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,129 @@
|
|||||||
|
/*
|
||||||
|
* QQQ - Low-code Application Framework for Engineers.
|
||||||
|
* Copyright (C) 2021-2024. Kingsrook, LLC
|
||||||
|
* 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States
|
||||||
|
* contact@kingsrook.com
|
||||||
|
* https://github.com/Kingsrook/
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.kingsrook.qqq.backend.core.processes.implementations.savedbulkloadprofiles;
|
||||||
|
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
import com.kingsrook.qqq.backend.core.actions.ActionHelper;
|
||||||
|
import com.kingsrook.qqq.backend.core.actions.processes.BackendStep;
|
||||||
|
import com.kingsrook.qqq.backend.core.actions.tables.GetAction;
|
||||||
|
import com.kingsrook.qqq.backend.core.actions.tables.QueryAction;
|
||||||
|
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
||||||
|
import com.kingsrook.qqq.backend.core.exceptions.QNotFoundException;
|
||||||
|
import com.kingsrook.qqq.backend.core.logging.QLogger;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.actions.processes.RunBackendStepInput;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.actions.processes.RunBackendStepOutput;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.actions.tables.get.GetInput;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.actions.tables.get.GetOutput;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QCriteriaOperator;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QFilterCriteria;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QFilterOrderBy;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QQueryFilter;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QueryInput;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QueryOutput;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.metadata.code.QCodeReference;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.metadata.processes.QBackendStepMetaData;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.metadata.processes.QProcessMetaData;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.savedbulkloadprofiles.SavedBulkLoadProfile;
|
||||||
|
import static com.kingsrook.qqq.backend.core.logging.LogUtils.logPair;
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Process used by the saved bulkLoadProfile dialogs
|
||||||
|
*******************************************************************************/
|
||||||
|
public class QuerySavedBulkLoadProfileProcess implements BackendStep
|
||||||
|
{
|
||||||
|
private static final QLogger LOG = QLogger.getLogger(QuerySavedBulkLoadProfileProcess.class);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
public static QProcessMetaData getProcessMetaData()
|
||||||
|
{
|
||||||
|
return (new QProcessMetaData()
|
||||||
|
.withName("querySavedBulkLoadProfile")
|
||||||
|
.withStepList(List.of(
|
||||||
|
new QBackendStepMetaData()
|
||||||
|
.withCode(new QCodeReference(QuerySavedBulkLoadProfileProcess.class))
|
||||||
|
.withName("query")
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
@Override
|
||||||
|
public void run(RunBackendStepInput runBackendStepInput, RunBackendStepOutput runBackendStepOutput) throws QException
|
||||||
|
{
|
||||||
|
ActionHelper.validateSession(runBackendStepInput);
|
||||||
|
Integer savedBulkLoadProfileId = runBackendStepInput.getValueInteger("id");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if(savedBulkLoadProfileId != null)
|
||||||
|
{
|
||||||
|
GetInput input = new GetInput();
|
||||||
|
input.setTableName(SavedBulkLoadProfile.TABLE_NAME);
|
||||||
|
input.setPrimaryKey(savedBulkLoadProfileId);
|
||||||
|
|
||||||
|
GetOutput output = new GetAction().execute(input);
|
||||||
|
if(output.getRecord() == null)
|
||||||
|
{
|
||||||
|
throw (new QNotFoundException("The requested bulkLoadProfile was not found."));
|
||||||
|
}
|
||||||
|
|
||||||
|
runBackendStepOutput.addRecord(output.getRecord());
|
||||||
|
runBackendStepOutput.addValue("savedBulkLoadProfile", output.getRecord());
|
||||||
|
runBackendStepOutput.addValue("savedBulkLoadProfileList", (Serializable) List.of(output.getRecord()));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
String tableName = runBackendStepInput.getValueString("tableName");
|
||||||
|
|
||||||
|
QueryInput input = new QueryInput();
|
||||||
|
input.setTableName(SavedBulkLoadProfile.TABLE_NAME);
|
||||||
|
input.setFilter(new QQueryFilter()
|
||||||
|
.withCriteria(new QFilterCriteria("tableName", QCriteriaOperator.EQUALS, tableName))
|
||||||
|
.withOrderBy(new QFilterOrderBy("label")));
|
||||||
|
|
||||||
|
QueryOutput output = new QueryAction().execute(input);
|
||||||
|
runBackendStepOutput.setRecords(output.getRecords());
|
||||||
|
runBackendStepOutput.addValue("savedBulkLoadProfileList", (Serializable) output.getRecords());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(QNotFoundException qnfe)
|
||||||
|
{
|
||||||
|
LOG.info("BulkLoadProfile not found", logPair("savedBulkLoadProfileId", savedBulkLoadProfileId));
|
||||||
|
throw (qnfe);
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
LOG.warn("Error querying for saved bulkLoadProfiles", e);
|
||||||
|
throw (e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,171 @@
|
|||||||
|
/*
|
||||||
|
* QQQ - Low-code Application Framework for Engineers.
|
||||||
|
* Copyright (C) 2021-2024. Kingsrook, LLC
|
||||||
|
* 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States
|
||||||
|
* contact@kingsrook.com
|
||||||
|
* https://github.com/Kingsrook/
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.kingsrook.qqq.backend.core.processes.implementations.savedbulkloadprofiles;
|
||||||
|
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
import com.kingsrook.qqq.backend.core.actions.ActionHelper;
|
||||||
|
import com.kingsrook.qqq.backend.core.actions.processes.BackendStep;
|
||||||
|
import com.kingsrook.qqq.backend.core.actions.tables.InsertAction;
|
||||||
|
import com.kingsrook.qqq.backend.core.actions.tables.QueryAction;
|
||||||
|
import com.kingsrook.qqq.backend.core.actions.tables.UpdateAction;
|
||||||
|
import com.kingsrook.qqq.backend.core.context.QContext;
|
||||||
|
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
||||||
|
import com.kingsrook.qqq.backend.core.exceptions.QUserFacingException;
|
||||||
|
import com.kingsrook.qqq.backend.core.logging.QLogger;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.actions.processes.RunBackendStepInput;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.actions.processes.RunBackendStepOutput;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.actions.tables.insert.InsertInput;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.actions.tables.insert.InsertOutput;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QCriteriaOperator;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QFilterCriteria;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QQueryFilter;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QueryInput;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QueryOutput;
|
||||||
|
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.data.QRecord;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.metadata.code.QCodeReference;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.metadata.processes.QBackendStepMetaData;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.metadata.processes.QProcessMetaData;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.savedbulkloadprofiles.SavedBulkLoadProfile;
|
||||||
|
import com.kingsrook.qqq.backend.core.utils.CollectionUtils;
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Process used by the saved bulkLoadProfile dialog
|
||||||
|
*******************************************************************************/
|
||||||
|
public class StoreSavedBulkLoadProfileProcess implements BackendStep
|
||||||
|
{
|
||||||
|
private static final QLogger LOG = QLogger.getLogger(StoreSavedBulkLoadProfileProcess.class);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
public static QProcessMetaData getProcessMetaData()
|
||||||
|
{
|
||||||
|
return (new QProcessMetaData()
|
||||||
|
.withName("storeSavedBulkLoadProfile")
|
||||||
|
.withStepList(List.of(
|
||||||
|
new QBackendStepMetaData()
|
||||||
|
.withCode(new QCodeReference(StoreSavedBulkLoadProfileProcess.class))
|
||||||
|
.withName("store")
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
@Override
|
||||||
|
public void run(RunBackendStepInput runBackendStepInput, RunBackendStepOutput runBackendStepOutput) throws QException
|
||||||
|
{
|
||||||
|
ActionHelper.validateSession(runBackendStepInput);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
String userId = QContext.getQSession().getUser().getIdReference();
|
||||||
|
String tableName = runBackendStepInput.getValueString("tableName");
|
||||||
|
String label = runBackendStepInput.getValueString("label");
|
||||||
|
|
||||||
|
String mappingJson = processMappingJson(runBackendStepInput.getValueString("mappingJson"));
|
||||||
|
|
||||||
|
QRecord qRecord = new QRecord()
|
||||||
|
.withValue("id", runBackendStepInput.getValueInteger("id"))
|
||||||
|
.withValue("mappingJson", mappingJson)
|
||||||
|
.withValue("label", label)
|
||||||
|
.withValue("tableName", tableName)
|
||||||
|
.withValue("userId", userId);
|
||||||
|
|
||||||
|
List<QRecord> savedBulkLoadProfileList;
|
||||||
|
if(qRecord.getValueInteger("id") == null)
|
||||||
|
{
|
||||||
|
checkForDuplicates(userId, tableName, label, null);
|
||||||
|
|
||||||
|
InsertInput input = new InsertInput();
|
||||||
|
input.setTableName(SavedBulkLoadProfile.TABLE_NAME);
|
||||||
|
input.setRecords(List.of(qRecord));
|
||||||
|
|
||||||
|
InsertOutput output = new InsertAction().execute(input);
|
||||||
|
savedBulkLoadProfileList = output.getRecords();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
checkForDuplicates(userId, tableName, label, qRecord.getValueInteger("id"));
|
||||||
|
|
||||||
|
UpdateInput input = new UpdateInput();
|
||||||
|
input.setTableName(SavedBulkLoadProfile.TABLE_NAME);
|
||||||
|
input.setRecords(List.of(qRecord));
|
||||||
|
|
||||||
|
UpdateOutput output = new UpdateAction().execute(input);
|
||||||
|
savedBulkLoadProfileList = output.getRecords();
|
||||||
|
}
|
||||||
|
|
||||||
|
runBackendStepOutput.addValue("savedBulkLoadProfileList", (Serializable) savedBulkLoadProfileList);
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
LOG.warn("Error storing saved bulkLoadProfile", e);
|
||||||
|
throw (e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/***************************************************************************
|
||||||
|
**
|
||||||
|
***************************************************************************/
|
||||||
|
private String processMappingJson(String mappingJson)
|
||||||
|
{
|
||||||
|
return mappingJson;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
private static void checkForDuplicates(String userId, String tableName, String label, Integer id) throws QException
|
||||||
|
{
|
||||||
|
QueryInput queryInput = new QueryInput();
|
||||||
|
queryInput.setTableName(SavedBulkLoadProfile.TABLE_NAME);
|
||||||
|
queryInput.setFilter(new QQueryFilter(
|
||||||
|
new QFilterCriteria("userId", QCriteriaOperator.EQUALS, userId),
|
||||||
|
new QFilterCriteria("tableName", QCriteriaOperator.EQUALS, tableName),
|
||||||
|
new QFilterCriteria("label", QCriteriaOperator.EQUALS, label)));
|
||||||
|
|
||||||
|
if(id != null)
|
||||||
|
{
|
||||||
|
queryInput.getFilter().addCriteria(new QFilterCriteria("id", QCriteriaOperator.NOT_EQUALS, id));
|
||||||
|
}
|
||||||
|
|
||||||
|
QueryOutput queryOutput = new QueryAction().execute(queryInput);
|
||||||
|
if(CollectionUtils.nullSafeHasContents(queryOutput.getRecords()))
|
||||||
|
{
|
||||||
|
throw (new QUserFacingException("You already have a saved Bulk Load Profile on this table with this name."));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,186 @@
|
|||||||
|
/*
|
||||||
|
* QQQ - Low-code Application Framework for Engineers.
|
||||||
|
* Copyright (C) 2021-2024. Kingsrook, LLC
|
||||||
|
* 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States
|
||||||
|
* contact@kingsrook.com
|
||||||
|
* https://github.com/Kingsrook/
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.kingsrook.qqq.backend.core.processes.implementations.savedbulkloadprofiles;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import com.kingsrook.qqq.backend.core.BaseTest;
|
||||||
|
import com.kingsrook.qqq.backend.core.actions.processes.RunProcessAction;
|
||||||
|
import com.kingsrook.qqq.backend.core.context.QContext;
|
||||||
|
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
||||||
|
import com.kingsrook.qqq.backend.core.exceptions.QUserFacingException;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.actions.processes.RunProcessInput;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.actions.processes.RunProcessOutput;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.data.QRecord;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
|
||||||
|
import com.kingsrook.qqq.backend.core.model.savedbulkloadprofiles.SavedBulkLoadProfileMetaDataProvider;
|
||||||
|
import com.kingsrook.qqq.backend.core.processes.implementations.bulk.insert.model.BulkLoadProfile;
|
||||||
|
import com.kingsrook.qqq.backend.core.utils.JsonUtils;
|
||||||
|
import com.kingsrook.qqq.backend.core.utils.TestUtils;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Unit tests for all saved-bulk-load-profile processes
|
||||||
|
*******************************************************************************/
|
||||||
|
class SavedBulkLoadProfileProcessTests extends BaseTest
|
||||||
|
{
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
@Test
|
||||||
|
void test() throws QException
|
||||||
|
{
|
||||||
|
QInstance qInstance = QContext.getQInstance();
|
||||||
|
new SavedBulkLoadProfileMetaDataProvider().defineAll(qInstance, TestUtils.MEMORY_BACKEND_NAME, null);
|
||||||
|
String tableName = TestUtils.TABLE_NAME_PERSON_MEMORY;
|
||||||
|
|
||||||
|
{
|
||||||
|
////////////////////////////////////////////
|
||||||
|
// query - should be no profiles to start //
|
||||||
|
////////////////////////////////////////////
|
||||||
|
RunProcessInput runProcessInput = new RunProcessInput();
|
||||||
|
runProcessInput.setProcessName(QuerySavedBulkLoadProfileProcess.getProcessMetaData().getName());
|
||||||
|
runProcessInput.addValue("tableName", tableName);
|
||||||
|
RunProcessOutput runProcessOutput = new RunProcessAction().execute(runProcessInput);
|
||||||
|
assertEquals(0, ((List<?>) runProcessOutput.getValues().get("savedBulkLoadProfileList")).size());
|
||||||
|
}
|
||||||
|
|
||||||
|
Integer savedBulkLoadProfileId;
|
||||||
|
{
|
||||||
|
/////////////////////////
|
||||||
|
// store a new profile //
|
||||||
|
/////////////////////////
|
||||||
|
RunProcessInput runProcessInput = new RunProcessInput();
|
||||||
|
runProcessInput.setProcessName(StoreSavedBulkLoadProfileProcess.getProcessMetaData().getName());
|
||||||
|
runProcessInput.addValue("label", "My Profile");
|
||||||
|
runProcessInput.addValue("tableName", tableName);
|
||||||
|
runProcessInput.addValue("mappingJson", JsonUtils.toJson(new BulkLoadProfile()));
|
||||||
|
RunProcessOutput runProcessOutput = new RunProcessAction().execute(runProcessInput);
|
||||||
|
List<QRecord> savedBulkLoadProfileList = (List<QRecord>) runProcessOutput.getValues().get("savedBulkLoadProfileList");
|
||||||
|
assertEquals(1, savedBulkLoadProfileList.size());
|
||||||
|
savedBulkLoadProfileId = savedBulkLoadProfileList.get(0).getValueInteger("id");
|
||||||
|
assertNotNull(savedBulkLoadProfileId);
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////
|
||||||
|
// try to store it again - should throw a "duplicate" exception //
|
||||||
|
//////////////////////////////////////////////////////////////////
|
||||||
|
assertThatThrownBy(() -> new RunProcessAction().execute(runProcessInput))
|
||||||
|
.isInstanceOf(QUserFacingException.class)
|
||||||
|
.hasMessageContaining("already have a saved Bulk Load Profile");
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
//////////////////////////////////////
|
||||||
|
// query - should find our profiles //
|
||||||
|
//////////////////////////////////////
|
||||||
|
RunProcessInput runProcessInput = new RunProcessInput();
|
||||||
|
runProcessInput.setProcessName(QuerySavedBulkLoadProfileProcess.getProcessMetaData().getName());
|
||||||
|
runProcessInput.addValue("tableName", tableName);
|
||||||
|
RunProcessOutput runProcessOutput = new RunProcessAction().execute(runProcessInput);
|
||||||
|
List<QRecord> savedBulkLoadProfileList = (List<QRecord>) runProcessOutput.getValues().get("savedBulkLoadProfileList");
|
||||||
|
assertEquals(1, savedBulkLoadProfileList.size());
|
||||||
|
assertEquals(1, savedBulkLoadProfileList.get(0).getValueInteger("id"));
|
||||||
|
assertEquals("My Profile", savedBulkLoadProfileList.get(0).getValueString("label"));
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
////////////////////////
|
||||||
|
// update our Profile //
|
||||||
|
////////////////////////
|
||||||
|
RunProcessInput runProcessInput = new RunProcessInput();
|
||||||
|
runProcessInput.setProcessName(StoreSavedBulkLoadProfileProcess.getProcessMetaData().getName());
|
||||||
|
runProcessInput.addValue("id", savedBulkLoadProfileId);
|
||||||
|
runProcessInput.addValue("label", "My Updated Profile");
|
||||||
|
runProcessInput.addValue("tableName", tableName);
|
||||||
|
runProcessInput.addValue("mappingJson", JsonUtils.toJson(new BulkLoadProfile()));
|
||||||
|
RunProcessOutput runProcessOutput = new RunProcessAction().execute(runProcessInput);
|
||||||
|
List<QRecord> savedBulkLoadProfileList = (List<QRecord>) runProcessOutput.getValues().get("savedBulkLoadProfileList");
|
||||||
|
assertEquals(1, savedBulkLoadProfileList.size());
|
||||||
|
assertEquals(1, savedBulkLoadProfileList.get(0).getValueInteger("id"));
|
||||||
|
assertEquals("My Updated Profile", savedBulkLoadProfileList.get(0).getValueString("label"));
|
||||||
|
}
|
||||||
|
|
||||||
|
Integer anotherSavedProfileId;
|
||||||
|
{
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// store a second one w/ different name (will be used below in update-dupe-check use-case) //
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
RunProcessInput runProcessInput = new RunProcessInput();
|
||||||
|
runProcessInput.setProcessName(StoreSavedBulkLoadProfileProcess.getProcessMetaData().getName());
|
||||||
|
runProcessInput.addValue("label", "My Second Profile");
|
||||||
|
runProcessInput.addValue("tableName", tableName);
|
||||||
|
runProcessInput.addValue("mappingJson", JsonUtils.toJson(new BulkLoadProfile()));
|
||||||
|
RunProcessOutput runProcessOutput = new RunProcessAction().execute(runProcessInput);
|
||||||
|
List<QRecord> savedBulkLoadProfileList = (List<QRecord>) runProcessOutput.getValues().get("savedBulkLoadProfileList");
|
||||||
|
anotherSavedProfileId = savedBulkLoadProfileList.get(0).getValueInteger("id");
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
/////////////////////////////////////////////////
|
||||||
|
// try to rename the second to match the first //
|
||||||
|
/////////////////////////////////////////////////
|
||||||
|
RunProcessInput runProcessInput = new RunProcessInput();
|
||||||
|
runProcessInput.setProcessName(StoreSavedBulkLoadProfileProcess.getProcessMetaData().getName());
|
||||||
|
runProcessInput.addValue("id", anotherSavedProfileId);
|
||||||
|
runProcessInput.addValue("label", "My Updated Profile");
|
||||||
|
runProcessInput.addValue("tableName", tableName);
|
||||||
|
runProcessInput.addValue("mappingJson", JsonUtils.toJson(new BulkLoadProfile()));
|
||||||
|
|
||||||
|
//////////////////////////////////////////
|
||||||
|
// should throw a "duplicate" exception //
|
||||||
|
//////////////////////////////////////////
|
||||||
|
assertThatThrownBy(() -> new RunProcessAction().execute(runProcessInput))
|
||||||
|
.isInstanceOf(QUserFacingException.class)
|
||||||
|
.hasMessageContaining("already have a saved Bulk Load Profile");
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
/////////////////////////
|
||||||
|
// delete our profiles //
|
||||||
|
/////////////////////////
|
||||||
|
RunProcessInput runProcessInput = new RunProcessInput();
|
||||||
|
runProcessInput.setProcessName(DeleteSavedBulkLoadProfileProcess.getProcessMetaData().getName());
|
||||||
|
runProcessInput.addValue("id", savedBulkLoadProfileId);
|
||||||
|
RunProcessOutput runProcessOutput = new RunProcessAction().execute(runProcessInput);
|
||||||
|
|
||||||
|
runProcessInput.addValue("id", anotherSavedProfileId);
|
||||||
|
runProcessOutput = new RunProcessAction().execute(runProcessInput);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
/////////////////////////////////////////
|
||||||
|
// query - should be no profiles again //
|
||||||
|
/////////////////////////////////////////
|
||||||
|
RunProcessInput runProcessInput = new RunProcessInput();
|
||||||
|
runProcessInput.setProcessName(QuerySavedBulkLoadProfileProcess.getProcessMetaData().getName());
|
||||||
|
runProcessInput.addValue("tableName", tableName);
|
||||||
|
RunProcessOutput runProcessOutput = new RunProcessAction().execute(runProcessInput);
|
||||||
|
assertEquals(0, ((List<?>) runProcessOutput.getValues().get("savedBulkLoadProfileList")).size());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user