Merge branch 'feature/sprint-8-qqq-support-updates' into feature/sprint-8

This commit is contained in:
2022-08-05 08:10:09 -05:00
4 changed files with 91 additions and 3 deletions

View File

@ -27,6 +27,7 @@ import java.lang.reflect.Method;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.Instant; import java.time.Instant;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalTime;
import com.kingsrook.qqq.backend.core.exceptions.QValueException; import com.kingsrook.qqq.backend.core.exceptions.QValueException;
import com.kingsrook.qqq.backend.core.utils.ValueUtils; import com.kingsrook.qqq.backend.core.utils.ValueUtils;
@ -159,6 +160,11 @@ public class QRecordEntityField
{ {
return (ValueUtils.getValueAsInstant(value)); return (ValueUtils.getValueAsInstant(value));
} }
if(type.equals(LocalTime.class))
{
return (ValueUtils.getValueAsLocalTime(value));
}
} }
catch(Exception e) catch(Exception e)
{ {

View File

@ -46,6 +46,7 @@ public class BasicETLLoadFunction implements BackendStep
private static final Logger LOG = LogManager.getLogger(BasicETLLoadFunction.class); private static final Logger LOG = LogManager.getLogger(BasicETLLoadFunction.class);
private QBackendTransaction transaction; private QBackendTransaction transaction;
private boolean returnStoredRecords = false;
@ -93,7 +94,11 @@ public class BasicETLLoadFunction implements BackendStep
InsertAction insertAction = new InsertAction(); InsertAction insertAction = new InsertAction();
InsertOutput insertOutput = insertAction.execute(insertInput); InsertOutput insertOutput = insertAction.execute(insertInput);
// todo - this is to avoid garbage leak in state provider... outputRecords.addAll(insertOutput.getRecords());
if(returnStoredRecords)
{
outputRecords.addAll(insertOutput.getRecords());
}
recordsInserted += insertOutput.getRecords().size(); recordsInserted += insertOutput.getRecords().size();
} }
@ -112,4 +117,14 @@ public class BasicETLLoadFunction implements BackendStep
this.transaction = transaction; this.transaction = transaction;
} }
/*******************************************************************************
** Setter for returnStoredRecords
**
*******************************************************************************/
public void setReturnStoredRecords(boolean returnStoredRecords)
{
this.returnStoredRecords = returnStoredRecords;
}
} }

View File

@ -22,10 +22,12 @@
package com.kingsrook.qqq.backend.core.utils; package com.kingsrook.qqq.backend.core.utils;
import java.io.Serializable;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.Instant; import java.time.Instant;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId; import java.time.ZoneId;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException; import java.time.format.DateTimeParseException;
@ -415,4 +417,45 @@ public class ValueUtils
throw (new QValueException("Value [" + value + "] could not be converted to a Instant.", e)); throw (new QValueException("Value [" + value + "] could not be converted to a Instant.", e));
} }
} }
/*******************************************************************************
**
*******************************************************************************/
public static Object getValueAsLocalTime(Serializable value)
{
try
{
if(value == null)
{
return (null);
}
else if(value instanceof LocalTime lt)
{
return (lt);
}
else if(value instanceof String s)
{
if(!StringUtils.hasContent(s))
{
return (null);
}
return LocalTime.parse(s);
}
else
{
throw (new QValueException("Unsupported class " + value.getClass().getName() + " for converting to LocalTime."));
}
}
catch(QValueException qve)
{
throw (qve);
}
catch(Exception e)
{
throw (new QValueException("Value [" + value + "] could not be converted to a LocalTime.", e));
}
}
} }

View File

@ -27,14 +27,18 @@ import java.math.MathContext;
import java.time.Instant; import java.time.Instant;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.Month; import java.time.Month;
import java.time.ZoneOffset;
import java.util.Calendar; import java.util.Calendar;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
import com.kingsrook.qqq.backend.core.exceptions.QValueException; import com.kingsrook.qqq.backend.core.exceptions.QValueException;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
/******************************************************************************* /*******************************************************************************
@ -226,4 +230,24 @@ class ValueUtilsTest
} }
/*******************************************************************************
**
*******************************************************************************/
@Test
void testGetValueAsLocalTime() throws QValueException
{
assertNull(ValueUtils.getValueAsInstant(null));
assertNull(ValueUtils.getValueAsInstant(""));
assertNull(ValueUtils.getValueAsInstant(" "));
assertEquals(LocalTime.of(10, 42), ValueUtils.getValueAsLocalTime(LocalTime.of(10, 42)));
assertEquals(LocalTime.of(10, 42, 59), ValueUtils.getValueAsLocalTime(LocalTime.of(10, 42, 59)));
assertEquals(LocalTime.of(10, 42), ValueUtils.getValueAsLocalTime("10:42"));
assertEquals(LocalTime.of(10, 42, 59), ValueUtils.getValueAsLocalTime("10:42:59"));
assertThrows(QValueException.class, () -> ValueUtils.getValueAsInstant("a"));
assertThrows(QValueException.class, () -> ValueUtils.getValueAsInstant("a,b"));
assertThrows(QValueException.class, () -> ValueUtils.getValueAsInstant("1980/05/31"));
assertThat(assertThrows(QValueException.class, () -> ValueUtils.getValueAsInstant(new Object())).getMessage()).contains("Unsupported class");
}
} }