mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 13:10:44 +00:00
CE-938 Add getErrorsAsString; getWarningsAsString; withWarning
This commit is contained in:
@ -35,12 +35,15 @@ import java.util.LinkedHashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
||||
import com.kingsrook.qqq.backend.core.logging.QLogger;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldMetaData;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData;
|
||||
import com.kingsrook.qqq.backend.core.model.statusmessages.QErrorMessage;
|
||||
import com.kingsrook.qqq.backend.core.model.statusmessages.QWarningMessage;
|
||||
import com.kingsrook.qqq.backend.core.utils.CollectionUtils;
|
||||
import com.kingsrook.qqq.backend.core.utils.StringUtils;
|
||||
import com.kingsrook.qqq.backend.core.utils.ValueUtils;
|
||||
import org.apache.commons.lang3.SerializationUtils;
|
||||
import static com.kingsrook.qqq.backend.core.logging.LogUtils.logPair;
|
||||
@ -462,6 +465,7 @@ public class QRecord implements Serializable
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for a single field's value
|
||||
**
|
||||
@ -616,6 +620,22 @@ public class QRecord implements Serializable
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for errors
|
||||
**
|
||||
*******************************************************************************/
|
||||
@JsonIgnore
|
||||
public String getErrorsAsString()
|
||||
{
|
||||
if(CollectionUtils.nullSafeHasContents(errors))
|
||||
{
|
||||
return StringUtils.join("; ", errors.stream().map(e -> e.getMessage()).toList());
|
||||
}
|
||||
return ("");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Setter for errors
|
||||
**
|
||||
@ -732,6 +752,22 @@ public class QRecord implements Serializable
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for warnings
|
||||
**
|
||||
*******************************************************************************/
|
||||
@JsonIgnore
|
||||
public String getWarningsAsString()
|
||||
{
|
||||
if(CollectionUtils.nullSafeHasContents(warnings))
|
||||
{
|
||||
return StringUtils.join("; ", warnings.stream().map(e -> e.getMessage()).toList());
|
||||
}
|
||||
return ("");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Setter for warnings
|
||||
*******************************************************************************/
|
||||
@ -742,6 +778,18 @@ public class QRecord implements Serializable
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Fluently Add one warning to this record
|
||||
**
|
||||
*******************************************************************************/
|
||||
public QRecord withWarning(QWarningMessage warning)
|
||||
{
|
||||
addWarning(warning);
|
||||
return (this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Fluent setter for warnings
|
||||
*******************************************************************************/
|
||||
|
@ -31,13 +31,18 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import com.kingsrook.qqq.backend.core.BaseTest;
|
||||
import com.kingsrook.qqq.backend.core.model.statusmessages.BadInputStatusMessage;
|
||||
import com.kingsrook.qqq.backend.core.model.statusmessages.QWarningMessage;
|
||||
import com.kingsrook.qqq.backend.core.model.statusmessages.SystemErrorStatusMessage;
|
||||
import com.kingsrook.qqq.backend.core.utils.JsonUtils;
|
||||
import com.kingsrook.qqq.backend.core.utils.collections.MapBuilder;
|
||||
import org.json.JSONObject;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static com.kingsrook.qqq.backend.core.model.data.QRecord.BACKEND_DETAILS_TYPE_HEAVY_FIELD_LENGTHS;
|
||||
import static com.kingsrook.qqq.backend.core.model.data.QRecord.BACKEND_DETAILS_TYPE_JSON_SOURCE_OBJECT;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
@ -250,4 +255,40 @@ class QRecordTest extends BaseTest
|
||||
assertNotEquals(originalMap, cloneWithMapValue.getValue("myMap"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testGetErrorsAndWarningsAsString()
|
||||
{
|
||||
assertEquals("", new QRecord().getErrorsAsString());
|
||||
assertEquals("one", new QRecord()
|
||||
.withError(new BadInputStatusMessage("one"))
|
||||
.getErrorsAsString());
|
||||
assertEquals("one; two", new QRecord()
|
||||
.withError(new BadInputStatusMessage("one"))
|
||||
.withError(new SystemErrorStatusMessage("two"))
|
||||
.getErrorsAsString());
|
||||
|
||||
assertEquals("", new QRecord().getWarningsAsString());
|
||||
assertEquals("A", new QRecord()
|
||||
.withWarning(new QWarningMessage("A"))
|
||||
.getWarningsAsString());
|
||||
assertEquals("A; B; C", new QRecord()
|
||||
.withWarning(new QWarningMessage("A"))
|
||||
.withWarning(new QWarningMessage("B"))
|
||||
.withWarning(new QWarningMessage("C"))
|
||||
.getWarningsAsString());
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// make sure this AsString method doesn't get included in our json serialization //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
String json = JsonUtils.toJson(new QRecord()
|
||||
.withError(new BadInputStatusMessage("one")));
|
||||
JSONObject jsonObject = new JSONObject(json);
|
||||
assertFalse(jsonObject.has("errorsAsString"));
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user