mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 13:10:44 +00:00
Update to throw QNotFoundException if view isn't found by id (rather than NPE)
This commit is contained in:
@ -29,6 +29,7 @@ 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.GetAction;
|
||||||
import com.kingsrook.qqq.backend.core.actions.tables.QueryAction;
|
import com.kingsrook.qqq.backend.core.actions.tables.QueryAction;
|
||||||
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
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.logging.QLogger;
|
||||||
import com.kingsrook.qqq.backend.core.model.actions.processes.RunBackendStepInput;
|
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.processes.RunBackendStepOutput;
|
||||||
@ -44,6 +45,7 @@ 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.QBackendStepMetaData;
|
||||||
import com.kingsrook.qqq.backend.core.model.metadata.processes.QProcessMetaData;
|
import com.kingsrook.qqq.backend.core.model.metadata.processes.QProcessMetaData;
|
||||||
import com.kingsrook.qqq.backend.core.model.savedviews.SavedView;
|
import com.kingsrook.qqq.backend.core.model.savedviews.SavedView;
|
||||||
|
import static com.kingsrook.qqq.backend.core.logging.LogUtils.logPair;
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
@ -78,10 +80,10 @@ public class QuerySavedViewProcess implements BackendStep
|
|||||||
public void run(RunBackendStepInput runBackendStepInput, RunBackendStepOutput runBackendStepOutput) throws QException
|
public void run(RunBackendStepInput runBackendStepInput, RunBackendStepOutput runBackendStepOutput) throws QException
|
||||||
{
|
{
|
||||||
ActionHelper.validateSession(runBackendStepInput);
|
ActionHelper.validateSession(runBackendStepInput);
|
||||||
|
Integer savedViewId = runBackendStepInput.getValueInteger("id");
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Integer savedViewId = runBackendStepInput.getValueInteger("id");
|
|
||||||
if(savedViewId != null)
|
if(savedViewId != null)
|
||||||
{
|
{
|
||||||
GetInput input = new GetInput();
|
GetInput input = new GetInput();
|
||||||
@ -89,6 +91,11 @@ public class QuerySavedViewProcess implements BackendStep
|
|||||||
input.setPrimaryKey(savedViewId);
|
input.setPrimaryKey(savedViewId);
|
||||||
|
|
||||||
GetOutput output = new GetAction().execute(input);
|
GetOutput output = new GetAction().execute(input);
|
||||||
|
if(output.getRecord() == null)
|
||||||
|
{
|
||||||
|
throw (new QNotFoundException("The requested view was not found."));
|
||||||
|
}
|
||||||
|
|
||||||
runBackendStepOutput.addRecord(output.getRecord());
|
runBackendStepOutput.addRecord(output.getRecord());
|
||||||
runBackendStepOutput.addValue("savedView", output.getRecord());
|
runBackendStepOutput.addValue("savedView", output.getRecord());
|
||||||
runBackendStepOutput.addValue("savedViewList", (Serializable) List.of(output.getRecord()));
|
runBackendStepOutput.addValue("savedViewList", (Serializable) List.of(output.getRecord()));
|
||||||
@ -108,6 +115,11 @@ public class QuerySavedViewProcess implements BackendStep
|
|||||||
runBackendStepOutput.addValue("savedViewList", (Serializable) output.getRecords());
|
runBackendStepOutput.addValue("savedViewList", (Serializable) output.getRecords());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch(QNotFoundException qnfe)
|
||||||
|
{
|
||||||
|
LOG.info("View not found", logPair("savedViewId", savedViewId));
|
||||||
|
throw (qnfe);
|
||||||
|
}
|
||||||
catch(Exception e)
|
catch(Exception e)
|
||||||
{
|
{
|
||||||
LOG.warn("Error querying for saved views", e);
|
LOG.warn("Error querying for saved views", e);
|
||||||
|
@ -183,7 +183,64 @@ class SavedViewProcessTests extends BaseTest
|
|||||||
RunProcessOutput runProcessOutput = new RunProcessAction().execute(runProcessInput);
|
RunProcessOutput runProcessOutput = new RunProcessAction().execute(runProcessInput);
|
||||||
assertEquals(0, ((List<?>) runProcessOutput.getValues().get("savedViewList")).size());
|
assertEquals(0, ((List<?>) runProcessOutput.getValues().get("savedViewList")).size());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
@Test
|
||||||
|
void testNotFoundThrowsProperly() throws QException
|
||||||
|
{
|
||||||
|
QInstance qInstance = QContext.getQInstance();
|
||||||
|
new SavedViewsMetaDataProvider().defineAll(qInstance, TestUtils.MEMORY_BACKEND_NAME, null);
|
||||||
|
String tableName = TestUtils.TABLE_NAME_PERSON_MEMORY;
|
||||||
|
|
||||||
|
{
|
||||||
|
////////////////////////////////////////////////////////
|
||||||
|
// get one by id when it doesn't exist - should throw //
|
||||||
|
////////////////////////////////////////////////////////
|
||||||
|
RunProcessInput runProcessInput = new RunProcessInput();
|
||||||
|
runProcessInput.setProcessName(QuerySavedViewProcess.getProcessMetaData().getName());
|
||||||
|
runProcessInput.addValue("tableName", tableName);
|
||||||
|
runProcessInput.addValue("id", -1);
|
||||||
|
assertThatThrownBy(() -> new RunProcessAction().execute(runProcessInput))
|
||||||
|
.hasMessageContaining("view was not found")
|
||||||
|
.isInstanceOf(QUserFacingException.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
Integer savedViewId;
|
||||||
|
{
|
||||||
|
//////////////////////
|
||||||
|
// store a new view //
|
||||||
|
//////////////////////
|
||||||
|
RunProcessInput runProcessInput = new RunProcessInput();
|
||||||
|
runProcessInput.setProcessName(StoreSavedViewProcess.getProcessMetaData().getName());
|
||||||
|
runProcessInput.addValue("label", "My View");
|
||||||
|
runProcessInput.addValue("tableName", tableName);
|
||||||
|
runProcessInput.addValue("viewJson", JsonUtils.toJson(new QQueryFilter(new QFilterCriteria("id", QCriteriaOperator.EQUALS, 47))));
|
||||||
|
RunProcessOutput runProcessOutput = new RunProcessAction().execute(runProcessInput);
|
||||||
|
List<QRecord> savedViewList = (List<QRecord>) runProcessOutput.getValues().get("savedViewList");
|
||||||
|
assertEquals(1, savedViewList.size());
|
||||||
|
savedViewId = savedViewList.get(0).getValueInteger("id");
|
||||||
|
assertNotNull(savedViewId);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
////////////////////////////////////////
|
||||||
|
// get now with valid id, should work //
|
||||||
|
////////////////////////////////////////
|
||||||
|
RunProcessInput runProcessInput = new RunProcessInput();
|
||||||
|
runProcessInput.setProcessName(QuerySavedViewProcess.getProcessMetaData().getName());
|
||||||
|
runProcessInput.addValue("tableName", tableName);
|
||||||
|
runProcessInput.addValue("id", savedViewId);
|
||||||
|
RunProcessOutput runProcessOutput = new RunProcessAction().execute(runProcessInput);
|
||||||
|
List<QRecord> savedViewList = (List<QRecord>) runProcessOutput.getValues().get("savedViewList");
|
||||||
|
assertEquals(1, savedViewList.size());
|
||||||
|
assertEquals(1, savedViewList.get(0).getValueInteger("id"));
|
||||||
|
assertEquals("My View", savedViewList.get(0).getValueString("label"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Reference in New Issue
Block a user