Merge branch 'feature/CTLE-397-oms' of github.com:Kingsrook/qqq into feature/CTLE-397-oms

This commit is contained in:
Tim Chamberlain
2023-04-18 22:49:54 -05:00
6 changed files with 59 additions and 39 deletions

View File

@ -42,7 +42,8 @@ public class RunBackendStepOutput extends AbstractActionOutput implements Serial
private ProcessState processState; private ProcessState processState;
private Exception exception; // todo - make optional private Exception exception; // todo - make optional
private List<AuditInput> auditInputList; private List<AuditInput> auditInputList = new ArrayList<>();
/******************************************************************************* /*******************************************************************************
@ -259,6 +260,7 @@ public class RunBackendStepOutput extends AbstractActionOutput implements Serial
} }
/******************************************************************************* /*******************************************************************************
** Getter for auditInputList ** Getter for auditInputList
*******************************************************************************/ *******************************************************************************/
@ -288,5 +290,4 @@ public class RunBackendStepOutput extends AbstractActionOutput implements Serial
return (this); return (this);
} }
} }

View File

@ -22,12 +22,13 @@
package com.kingsrook.qqq.backend.core.model.metadata; package com.kingsrook.qqq.backend.core.model.metadata;
import java.io.File; import java.io.IOException;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import com.google.common.reflect.ClassPath;
import com.kingsrook.qqq.backend.core.logging.QLogger; import com.kingsrook.qqq.backend.core.logging.QLogger;
import static com.kingsrook.qqq.backend.core.logging.LogUtils.logPair; import static com.kingsrook.qqq.backend.core.logging.LogUtils.logPair;
@ -47,7 +48,7 @@ public class MetaDataProducerHelper
** **
** Note - they'll be sorted by the sortOrder they provide. ** Note - they'll be sorted by the sortOrder they provide.
*******************************************************************************/ *******************************************************************************/
public static void processAllMetaDataProducersInPackage(QInstance instance, String packageName) public static void processAllMetaDataProducersInPackage(QInstance instance, String packageName) throws IOException
{ {
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// find all the meta data producer classes in the package // // find all the meta data producer classes in the package //
@ -111,40 +112,19 @@ public class MetaDataProducerHelper
/******************************************************************************* /*******************************************************************************
** Thanks, Chat GPT. ** from https://stackoverflow.com/questions/520328/can-you-find-all-classes-in-a-package-using-reflection
** (since the original, from ChatGPT, didn't work in jars, despite GPT hallucinating that it would)
*******************************************************************************/ *******************************************************************************/
private static List<Class<?>> getClassesInPackage(String packageName) private static List<Class<?>> getClassesInPackage(String packageName) throws IOException
{ {
List<Class<?>> classes = new ArrayList<>(); List<Class<?>> classes = new ArrayList<>();
ClassLoader loader = Thread.currentThread().getContextClassLoader();
String path = packageName.replace('.', '/'); for(ClassPath.ClassInfo info : ClassPath.from(loader).getTopLevelClasses())
File directory = new File(Thread.currentThread().getContextClassLoader().getResource(path).getFile());
if(directory.exists())
{ {
File[] files = directory.listFiles(); if(info.getName().startsWith(packageName))
if(files != null)
{ {
for(File file : files) classes.add(info.load());
{
if(file.isFile() && file.getName().endsWith(".class"))
{
String className = packageName + '.' + file.getName().substring(0, file.getName().length() - 6);
try
{
classes.add(Class.forName(className));
}
catch(ClassNotFoundException e)
{
// Ignore, class not found
}
}
else if(file.isDirectory())
{
List<Class<?>> subClasses = getClassesInPackage(packageName + "." + file.getName());
classes.addAll(subClasses);
}
}
} }
} }

View File

@ -24,6 +24,7 @@ package com.kingsrook.qqq.backend.core.processes.implementations.tablesync;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
@ -216,6 +217,14 @@ public abstract class AbstractTableSyncTransformStep extends AbstractTransformSt
getTransaction().ifPresent(queryInput::setTransaction); getTransaction().ifPresent(queryInput::setTransaction);
QQueryFilter filter = getExistingRecordQueryFilter(runBackendStepInput, sourceKeyList); QQueryFilter filter = getExistingRecordQueryFilter(runBackendStepInput, sourceKeyList);
queryInput.setFilter(filter); queryInput.setFilter(filter);
Collection<String> associationNamesToInclude = getAssociationNamesToInclude();
if(CollectionUtils.nullSafeHasContents(associationNamesToInclude))
{
queryInput.setIncludeAssociations(true);
queryInput.setAssociationNamesToInclude(associationNamesToInclude);
}
QueryOutput queryOutput = new QueryAction().execute(queryInput); QueryOutput queryOutput = new QueryAction().execute(queryInput);
existingRecordsByForeignKey = CollectionUtils.recordsToMap(queryOutput.getRecords(), destinationTableForeignKeyField); existingRecordsByForeignKey = CollectionUtils.recordsToMap(queryOutput.getRecords(), destinationTableForeignKeyField);
} }
@ -296,6 +305,16 @@ public abstract class AbstractTableSyncTransformStep extends AbstractTransformSt
/*******************************************************************************
**
*******************************************************************************/
protected Collection<String> getAssociationNamesToInclude()
{
return null;
}
/******************************************************************************* /*******************************************************************************
** If needed, init a record lookup helper for this process. ** If needed, init a record lookup helper for this process.
*******************************************************************************/ *******************************************************************************/

View File

@ -22,6 +22,7 @@
package com.kingsrook.qqq.backend.core.model.metadata; package com.kingsrook.qqq.backend.core.model.metadata;
import java.io.IOException;
import com.kingsrook.qqq.backend.core.model.metadata.producers.TestMetaDataProducer; import com.kingsrook.qqq.backend.core.model.metadata.producers.TestMetaDataProducer;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
@ -37,7 +38,7 @@ class MetaDataProducerHelperTest
** **
*******************************************************************************/ *******************************************************************************/
@Test @Test
void test() void test() throws IOException
{ {
QInstance qInstance = new QInstance(); QInstance qInstance = new QInstance();
MetaDataProducerHelper.processAllMetaDataProducersInPackage(qInstance, "com.kingsrook.qqq.backend.core.model.metadata.producers"); MetaDataProducerHelper.processAllMetaDataProducersInPackage(qInstance, "com.kingsrook.qqq.backend.core.model.metadata.producers");

View File

@ -103,6 +103,7 @@ public class OutboundAPILogMetaDataProvider
.withIcon(new QIcon().withName("data_object")) .withIcon(new QIcon().withName("data_object"))
.withBackendName(backendName) .withBackendName(backendName)
.withRecordLabelFormat("%s") .withRecordLabelFormat("%s")
.withRecordLabelFields("id")
.withPrimaryKeyField("id") .withPrimaryKeyField("id")
.withFieldsFromEntity(OutboundAPILog.class) .withFieldsFromEntity(OutboundAPILog.class)
.withSection(new QFieldSection("identity", new QIcon().withName("badge"), Tier.T1, List.of("id"))) .withSection(new QFieldSection("identity", new QIcon().withName("badge"), Tier.T1, List.of("id")))
@ -142,6 +143,7 @@ public class OutboundAPILogMetaDataProvider
// limit url to 250... // // limit url to 250... //
///////////////////////// /////////////////////////
tableMetaData.getField("url").withMaxLength(250).withBehavior(ValueTooLongBehavior.TRUNCATE_ELLIPSIS); tableMetaData.getField("url").withMaxLength(250).withBehavior(ValueTooLongBehavior.TRUNCATE_ELLIPSIS);
tableMetaData.getField("url").withFieldAdornment(AdornmentType.Size.XLARGE.toAdornment());
if(backendDetailEnricher != null) if(backendDetailEnricher != null)
{ {

View File

@ -21,6 +21,7 @@ String allFieldNames = ""
String dataFieldNames = "" String dataFieldNames = ""
List<String> fieldNameList = new ArrayList<>(); List<String> fieldNameList = new ArrayList<>();
List<String> fieldTypeList = new ArrayList<>(); List<String> fieldTypeList = new ArrayList<>();
Map<String, String> fieldAttributesMap = new HashMap<>();
StringBuilder output = new StringBuilder(); StringBuilder output = new StringBuilder();
if(writeWholeClass) if(writeWholeClass)
@ -58,8 +59,8 @@ while((line = reader.readLine()) != null)
String columnType = words[1]; String columnType = words[1];
String fieldName = columNameToFieldName(columnName) String fieldName = columNameToFieldName(columnName)
String fieldType = columTypeToFieldType(columnType) String fieldType = columTypeToFieldType(fieldAttributesMap, fieldName, columnType)
String attributes = getFieldAttributes(fieldName); String attributes = getFieldAttributes(fieldAttributesMap, fieldName);
fieldNameList.add(fieldName); fieldNameList.add(fieldName);
fieldTypeList.add(fieldType); fieldTypeList.add(fieldType);
@ -235,13 +236,19 @@ private static String columNameToFieldName(String columnName)
private static String columTypeToFieldType(String columnType) private static String columTypeToFieldType(Map<String, String> fieldAttributesMap, String fieldName, String columnType)
{ {
if(columnType.toUpperCase().startsWith("INT")) if(columnType.toUpperCase().startsWith("INT"))
{ {
return ("Integer"); return ("Integer");
} }
if(columnType.toUpperCase().startsWith("VARCHAR") || columnType.toUpperCase().startsWith("TEXT")) if(columnType.toUpperCase().startsWith("VARCHAR"))
{
String length = columnType.toUpperCase().replaceAll(".*VARCHAR *\\( *", "").replaceAll(" *\\).*", "");
fieldAttributesMap.put(fieldName, "maxLength = " + length + ", valueTooLongBehavior = ValueTooLongBehavior.TRUNCATE");
return ("String");
}
if(columnType.toUpperCase().startsWith("TEXT"))
{ {
return ("String"); return ("String");
} }
@ -266,12 +273,22 @@ private static String columTypeToFieldType(String columnType)
private static String getFieldAttributes(String s) private static String getFieldAttributes(Map<String, String> fieldAttributesMap, String fieldName)
{ {
StringBuilder rs = new StringBuilder(""); StringBuilder rs = new StringBuilder("");
if(s.equals("id") || s.equals("createDate") || s.equals("modifyDate")) if(fieldName.equals("id") || fieldName.equals("createDate") || fieldName.equals("modifyDate"))
{ {
rs.append("isEditable = false"); rs.append("isEditable = false");
} }
if(fieldAttributesMap.containsKey(fieldName))
{
if(rs.length() > 0)
{
rs.append(", ");
}
rs.append(fieldAttributesMap.get(fieldName));
}
return (rs.toString()); return (rs.toString());
} }