mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-19 13:40:44 +00:00
QQQ-21 add safelyGetPage; add stepType
This commit is contained in:
@ -28,6 +28,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import com.kingsrook.qqq.backend.core.callbacks.QProcessCallback;
|
||||
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
||||
import com.kingsrook.qqq.backend.core.exceptions.QUserFacingException;
|
||||
import com.kingsrook.qqq.backend.core.interfaces.BackendStep;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.processes.RunBackendStepRequest;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.processes.RunBackendStepResult;
|
||||
@ -128,14 +129,18 @@ public class RunBackendStepAction
|
||||
QProcessCallback callback = runBackendStepRequest.getCallback();
|
||||
if(callback == null)
|
||||
{
|
||||
throw (new QException("Function is missing values for fields, but no callback was present to request fields from a user"));
|
||||
throw (new QUserFacingException("Missing values for one or more fields",
|
||||
new QException("Function is missing values for fields, but no callback was present to request fields from a user")));
|
||||
}
|
||||
|
||||
Map<String, Serializable> fieldValues = callback.getFieldValues(fieldsToGet);
|
||||
for(Map.Entry<String, Serializable> entry : fieldValues.entrySet())
|
||||
if(fieldValues != null)
|
||||
{
|
||||
runBackendStepRequest.addValue(entry.getKey(), entry.getValue());
|
||||
// todo - check to make sure got values back?
|
||||
for(Map.Entry<String, Serializable> entry : fieldValues.entrySet())
|
||||
{
|
||||
runBackendStepRequest.addValue(entry.getKey(), entry.getValue());
|
||||
// todo - check to make sure got values back?
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -164,7 +169,8 @@ public class RunBackendStepAction
|
||||
QProcessCallback callback = runBackendStepRequest.getCallback();
|
||||
if(callback == null)
|
||||
{
|
||||
throw (new QException("Function is missing input records, but no callback was present to get a query filter from a user"));
|
||||
throw (new QUserFacingException("Missing input records.",
|
||||
new QException("Function is missing input records, but no callback was present to request fields from a user")));
|
||||
}
|
||||
|
||||
queryRequest.setFilter(callback.getQueryFilter());
|
||||
|
@ -42,6 +42,16 @@ public class QBackendStepMetaData extends QStepMetaData
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
public QBackendStepMetaData()
|
||||
{
|
||||
setStepType("backend");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Setter for label
|
||||
**
|
||||
|
@ -40,6 +40,16 @@ public class QFrontendStepMetaData extends QStepMetaData
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
public QFrontendStepMetaData()
|
||||
{
|
||||
setStepType("frontend");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for formFields
|
||||
**
|
||||
|
@ -25,17 +25,21 @@ package com.kingsrook.qqq.backend.core.model.metadata.processes;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.QFieldMetaData;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.serialization.QStepMetaDataDeserializer;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Meta-Data to define a step in a process in a QQQ instance.
|
||||
**
|
||||
*******************************************************************************/
|
||||
@JsonDeserialize(using = QStepMetaDataDeserializer.class)
|
||||
public class QStepMetaData
|
||||
{
|
||||
private String name;
|
||||
private String label;
|
||||
private String stepType;
|
||||
|
||||
|
||||
|
||||
@ -127,4 +131,25 @@ public class QStepMetaData
|
||||
return (new ArrayList<>());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for stepType
|
||||
**
|
||||
*******************************************************************************/
|
||||
public String getStepType()
|
||||
{
|
||||
return stepType;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Setter for stepType
|
||||
**
|
||||
*******************************************************************************/
|
||||
public void setStepType(String stepType)
|
||||
{
|
||||
this.stepType = stepType;
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,7 @@
|
||||
package com.kingsrook.qqq.backend.core.utils;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
@ -332,4 +333,77 @@ public class CollectionUtils
|
||||
return (rs.toString());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Get a sub-list, safely - i.e., w/o worrying if your indexes are too big.
|
||||
*******************************************************************************/
|
||||
public static <T> List<T> safelyGetPage(List<T> list, Integer skip, Integer limit)
|
||||
{
|
||||
//////////////////////////////////////////////////////////
|
||||
// throw if the user requested a negative skip or limit //
|
||||
//////////////////////////////////////////////////////////
|
||||
if(skip != null && skip < 0)
|
||||
{
|
||||
throw (new IllegalArgumentException("Skip may not be negative (was " + skip + ")"));
|
||||
}
|
||||
if(limit != null && limit < 0)
|
||||
{
|
||||
throw (new IllegalArgumentException("Limit may not be negative (was " + limit + ")"));
|
||||
}
|
||||
|
||||
///////////////////////////////////
|
||||
// null input list = null output //
|
||||
///////////////////////////////////
|
||||
if(list == null)
|
||||
{
|
||||
return (null);
|
||||
}
|
||||
|
||||
int startAt;
|
||||
if(skip == null)
|
||||
{
|
||||
///////////////////////////////////////////
|
||||
// treat null skip is the same as 0 skip //
|
||||
///////////////////////////////////////////
|
||||
startAt = 0;
|
||||
}
|
||||
else if(skip > list.size())
|
||||
{
|
||||
////////////////////////////////////////
|
||||
// if skip is too large, return empty //
|
||||
////////////////////////////////////////
|
||||
return (new ArrayList<>());
|
||||
}
|
||||
else
|
||||
{
|
||||
startAt = skip;
|
||||
}
|
||||
|
||||
int endAt;
|
||||
if(limit == null)
|
||||
{
|
||||
////////////////////////////////////////////////////////
|
||||
// treat null limit as request for all after the skip //
|
||||
////////////////////////////////////////////////////////
|
||||
endAt = list.size();
|
||||
}
|
||||
else if(limit == 0)
|
||||
{
|
||||
/////////////////////////////////////////////
|
||||
// treat limit of zero as request for none //
|
||||
/////////////////////////////////////////////
|
||||
return (new ArrayList<>());
|
||||
}
|
||||
else
|
||||
{
|
||||
endAt = startAt + limit;
|
||||
if (endAt > list.size())
|
||||
{
|
||||
endAt = list.size();
|
||||
}
|
||||
}
|
||||
|
||||
return list.subList(startAt, endAt);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user