mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 05:01:07 +00:00
Merged feature/workflows-support into integration
This commit is contained in:
@ -291,6 +291,7 @@ public class AuditAction extends AbstractQActionFunction<AuditInput, AuditOutput
|
||||
/////////////////////////////
|
||||
InsertInput insertInput = new InsertInput();
|
||||
insertInput.setTableName("audit");
|
||||
insertInput.setTransaction(input.getTransaction());
|
||||
insertInput.setRecords(auditRecords);
|
||||
InsertOutput insertOutput = new InsertAction().execute(insertInput);
|
||||
|
||||
@ -318,6 +319,7 @@ public class AuditAction extends AbstractQActionFunction<AuditInput, AuditOutput
|
||||
{
|
||||
insertInput = new InsertInput();
|
||||
insertInput.setTableName("auditDetail");
|
||||
insertInput.setTransaction(input.getTransaction());
|
||||
insertInput.setRecords(auditDetailRecords);
|
||||
new InsertAction().execute(insertInput);
|
||||
}
|
||||
|
@ -124,6 +124,7 @@ public class DMLAuditAction extends AbstractQActionFunction<DMLAuditInput, DMLAu
|
||||
String contextSuffix = getContentSuffix(input);
|
||||
|
||||
AuditInput auditInput = new AuditInput();
|
||||
auditInput.setTransaction(input.getTransaction());
|
||||
if(auditLevel.equals(AuditLevel.RECORD) || (auditLevel.equals(AuditLevel.FIELD) && !dmlType.supportsFields))
|
||||
{
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -246,6 +246,7 @@ public class DeleteAction
|
||||
{
|
||||
DMLAuditInput dmlAuditInput = new DMLAuditInput()
|
||||
.withTableActionInput(deleteInput)
|
||||
.withTransaction(deleteInput.getTransaction())
|
||||
.withAuditContext(deleteInput.getAuditContext());
|
||||
oldRecordList.ifPresent(l -> dmlAuditInput.setRecordList(l));
|
||||
new DMLAuditAction().execute(dmlAuditInput);
|
||||
|
@ -170,6 +170,7 @@ public class InsertAction extends AbstractQActionFunction<InsertInput, InsertOut
|
||||
{
|
||||
new DMLAuditAction().execute(new DMLAuditInput()
|
||||
.withTableActionInput(insertInput)
|
||||
.withTransaction(insertInput.getTransaction())
|
||||
.withAuditContext(insertInput.getAuditContext())
|
||||
.withRecordList(insertOutput.getRecords()));
|
||||
}
|
||||
|
@ -190,6 +190,7 @@ public class UpdateAction
|
||||
else
|
||||
{
|
||||
DMLAuditInput dmlAuditInput = new DMLAuditInput()
|
||||
.withTransaction(updateInput.getTransaction())
|
||||
.withTableActionInput(updateInput)
|
||||
.withRecordList(updateOutput.getRecords())
|
||||
.withAuditContext(updateInput.getAuditContext());
|
||||
|
@ -31,7 +31,9 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
@ -43,6 +45,7 @@ import com.kingsrook.qqq.backend.core.actions.metadata.JoinGraph;
|
||||
import com.kingsrook.qqq.backend.core.actions.permissions.BulkTableActionProcessPermissionChecker;
|
||||
import com.kingsrook.qqq.backend.core.actions.values.QCustomPossibleValueProvider;
|
||||
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
||||
import com.kingsrook.qqq.backend.core.exceptions.QRuntimeException;
|
||||
import com.kingsrook.qqq.backend.core.instances.enrichment.plugins.QInstanceEnricherPluginInterface;
|
||||
import com.kingsrook.qqq.backend.core.logging.QLogger;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.QBackendMetaData;
|
||||
@ -212,9 +215,35 @@ public class QInstanceEnricher
|
||||
***************************************************************************/
|
||||
private void enrichInstance()
|
||||
{
|
||||
for(QSupplementalInstanceMetaData supplementalInstanceMetaData : qInstance.getSupplementalMetaData().values())
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
// enriching some objects may cause additional ones to be added to the qInstance! //
|
||||
// this caused concurrent modification exceptions, when we just iterated. //
|
||||
// we could make a copy of the map and just process that, but then we wouldn't //
|
||||
// enrich any new objects that do get added, so, use this technique instead. //
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
Set<QSupplementalInstanceMetaData> toEnrich = new LinkedHashSet<>(qInstance.getSupplementalMetaData().values());
|
||||
Set<QSupplementalInstanceMetaData> enriched = new HashSet<>();
|
||||
int count = 0;
|
||||
while(!toEnrich.isEmpty())
|
||||
{
|
||||
Iterator<QSupplementalInstanceMetaData> iterator = toEnrich.iterator();
|
||||
QSupplementalInstanceMetaData supplementalInstanceMetaData = iterator.next();
|
||||
iterator.remove();
|
||||
|
||||
supplementalInstanceMetaData.enrich(qInstance);
|
||||
enriched.add(supplementalInstanceMetaData);
|
||||
|
||||
for(QSupplementalInstanceMetaData possiblyNew : qInstance.getSupplementalMetaData().values())
|
||||
{
|
||||
if(!toEnrich.contains(possiblyNew) && !enriched.contains(possiblyNew))
|
||||
{
|
||||
if(count++ > 100)
|
||||
{
|
||||
throw (new QRuntimeException("Too many new QSupplementalInstanceMetaData objects were added while enriching others. This probably indicates a bug in enrichment code. Throwing to prevent infinite loop."));
|
||||
}
|
||||
toEnrich.add(possiblyNew);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
runPlugins(QInstance.class, qInstance, qInstance);
|
||||
|
@ -25,6 +25,7 @@ package com.kingsrook.qqq.backend.core.model.actions.audits;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import com.kingsrook.qqq.backend.core.actions.QBackendTransaction;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.AbstractActionInput;
|
||||
|
||||
|
||||
@ -36,6 +37,8 @@ public class AuditInput extends AbstractActionInput implements Serializable
|
||||
{
|
||||
private List<AuditSingleInput> auditSingleInputList = new ArrayList<>();
|
||||
|
||||
private QBackendTransaction transaction;
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
@ -92,4 +95,42 @@ public class AuditInput extends AbstractActionInput implements Serializable
|
||||
return (this);
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* Getter for transaction
|
||||
* @see #withTransaction(QBackendTransaction)
|
||||
*******************************************************************************/
|
||||
public QBackendTransaction getTransaction()
|
||||
{
|
||||
return (this.transaction);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* Setter for transaction
|
||||
* @see #withTransaction(QBackendTransaction)
|
||||
*******************************************************************************/
|
||||
public void setTransaction(QBackendTransaction transaction)
|
||||
{
|
||||
this.transaction = transaction;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* Fluent setter for transaction
|
||||
*
|
||||
* @param transaction
|
||||
* transaction upon which the audits will be inserted.
|
||||
*
|
||||
* @return this
|
||||
*******************************************************************************/
|
||||
public AuditInput withTransaction(QBackendTransaction transaction)
|
||||
{
|
||||
this.transaction = transaction;
|
||||
return (this);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ package com.kingsrook.qqq.backend.core.model.actions.audits;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import com.kingsrook.qqq.backend.core.actions.QBackendTransaction;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.AbstractActionInput;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.AbstractTableActionInput;
|
||||
import com.kingsrook.qqq.backend.core.model.data.QRecord;
|
||||
@ -38,6 +39,8 @@ public class DMLAuditInput extends AbstractActionInput implements Serializable
|
||||
private List<QRecord> oldRecordList;
|
||||
private AbstractTableActionInput tableActionInput;
|
||||
|
||||
private QBackendTransaction transaction;
|
||||
|
||||
private String auditContext = null;
|
||||
|
||||
|
||||
@ -164,4 +167,43 @@ public class DMLAuditInput extends AbstractActionInput implements Serializable
|
||||
return (this);
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* Getter for transaction
|
||||
* @see #withTransaction(QBackendTransaction)
|
||||
*******************************************************************************/
|
||||
public QBackendTransaction getTransaction()
|
||||
{
|
||||
return (this.transaction);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* Setter for transaction
|
||||
* @see #withTransaction(QBackendTransaction)
|
||||
*******************************************************************************/
|
||||
public void setTransaction(QBackendTransaction transaction)
|
||||
{
|
||||
this.transaction = transaction;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* Fluent setter for transaction
|
||||
*
|
||||
* @param transaction
|
||||
* transaction that will be used for inserting the audits, where (presumably)
|
||||
* the DML against the record occurred as well
|
||||
*
|
||||
* @return this
|
||||
*******************************************************************************/
|
||||
public DMLAuditInput withTransaction(QBackendTransaction transaction)
|
||||
{
|
||||
this.transaction = transaction;
|
||||
return (this);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -145,4 +145,36 @@ public class MetaDataProducerMultiOutput implements MetaDataProducerOutput, Sour
|
||||
setSourceQBitName(sourceQBitName);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
* get a typed and named meta-data object out of this output container.
|
||||
*
|
||||
* @param <C> the type of the object to return, e.g., QTableMetaData
|
||||
* @param outputClass the class for the type to return
|
||||
* @param name the name of the object, e.g., a table or process name.
|
||||
* @return the requested TopLevelMetaDataInterface object (in the requested
|
||||
* type), or null if not found.
|
||||
***************************************************************************/
|
||||
public <C extends TopLevelMetaDataInterface> C get(Class<C> outputClass, String name)
|
||||
{
|
||||
for(MetaDataProducerOutput content : CollectionUtils.nonNullList(contents))
|
||||
{
|
||||
if(content instanceof MetaDataProducerMultiOutput multiOutput)
|
||||
{
|
||||
C c = multiOutput.get(outputClass, name);
|
||||
if(c != null)
|
||||
{
|
||||
return (c);
|
||||
}
|
||||
}
|
||||
else if(outputClass.isInstance(content) && name.equals(((TopLevelMetaDataInterface)content).getName()))
|
||||
{
|
||||
return (C) content;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ public interface QBitMetaDataProducer<C extends QBitConfig> extends MetaDataProd
|
||||
/***************************************************************************
|
||||
**
|
||||
***************************************************************************/
|
||||
default void postProduceActions(MetaDataProducerMultiOutput metaDataProducerMultiOutput, QInstance qinstance)
|
||||
default void postProduceActions(MetaDataProducerMultiOutput metaDataProducerMultiOutput, QInstance qinstance) throws QException
|
||||
{
|
||||
/////////////////////
|
||||
// noop by default //
|
||||
@ -137,9 +137,9 @@ public interface QBitMetaDataProducer<C extends QBitConfig> extends MetaDataProd
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// todo is this deprecated in favor of QBitProductionContext's stack... ? //
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
if(producer instanceof QBitComponentMetaDataProducer<?, ?>)
|
||||
if(producer instanceof QBitComponentMetaDataProducerInterface<?, ?>)
|
||||
{
|
||||
QBitComponentMetaDataProducer<?, C> qBitComponentMetaDataProducer = (QBitComponentMetaDataProducer<?, C>) producer;
|
||||
QBitComponentMetaDataProducerInterface<?, C> qBitComponentMetaDataProducer = (QBitComponentMetaDataProducerInterface<?, C>) producer;
|
||||
qBitComponentMetaDataProducer.setQBitConfig(qBitConfig);
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,7 @@ import com.kingsrook.qqq.backend.core.utils.ValueUtils;
|
||||
** can pre-load entire tables or subsets of tables.
|
||||
**
|
||||
*******************************************************************************/
|
||||
public class RecordLookupHelper
|
||||
public class RecordLookupHelper implements Serializable
|
||||
{
|
||||
private Map<String, Map<Serializable, QRecord>> recordMaps;
|
||||
|
||||
|
@ -30,6 +30,7 @@ import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Function;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
@ -712,4 +713,26 @@ public class CollectionUtils
|
||||
c.add(element);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
* add all objects in a source collection to a destination collection, in a
|
||||
* null-safe manner with regard to the source.
|
||||
*
|
||||
* @param destination collection to put objects into. May NOT be null.
|
||||
* if it's immutable, and source is not null, that will
|
||||
* fail (as you'd expect) too.
|
||||
* @param source collection to get objects from. if null, is ignored.
|
||||
* @throws NullPointerException if destination is null.
|
||||
***************************************************************************/
|
||||
public static <T> void addAllIfNotNull(Collection<T> destination, Collection<T> source)
|
||||
{
|
||||
Objects.requireNonNull(destination, "destination may not be null");
|
||||
|
||||
if(source != null)
|
||||
{
|
||||
destination.addAll(source);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* QQQ - Low-code Application Framework for Engineers.
|
||||
* Copyright (C) 2021-2025. Kingsrook, LLC
|
||||
* 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States
|
||||
* contact@kingsrook.com
|
||||
* https://github.com/Kingsrook/
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.kingsrook.qqq.backend.core.model.metadata;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import com.kingsrook.qqq.backend.core.BaseTest;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.processes.QProcessMetaData;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.queues.QQueueMetaData;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.queues.QQueueProviderMetaData;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Unit test for MetaDataProducerMultiOutput
|
||||
*******************************************************************************/
|
||||
class MetaDataProducerMultiOutputTest extends BaseTest
|
||||
{
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testGetEachAndGet()
|
||||
{
|
||||
//////////////////////
|
||||
// given this setup //
|
||||
//////////////////////
|
||||
MetaDataProducerMultiOutput metaDataProducerMultiOutput = new MetaDataProducerMultiOutput();
|
||||
metaDataProducerMultiOutput.add(new QTableMetaData().withName("tableA"));
|
||||
metaDataProducerMultiOutput.add(new QProcessMetaData().withName("processB"));
|
||||
metaDataProducerMultiOutput.add(new QBackendMetaData().withName("backendC"));
|
||||
metaDataProducerMultiOutput.add(new QTableMetaData().withName("tableD"));
|
||||
|
||||
///////////////////////////
|
||||
// test calls to getEach //
|
||||
///////////////////////////
|
||||
List<QTableMetaData> tables = metaDataProducerMultiOutput.getEach(QTableMetaData.class);
|
||||
assertEquals(2, tables.size());
|
||||
assertEquals("tableA", tables.get(0).getName());
|
||||
assertEquals("tableD", tables.get(1).getName());
|
||||
|
||||
List<QProcessMetaData> processes = metaDataProducerMultiOutput.getEach(QProcessMetaData.class);
|
||||
assertEquals(1, processes.size());
|
||||
assertEquals("processB", processes.get(0).getName());
|
||||
|
||||
List<QBackendMetaData> backends = metaDataProducerMultiOutput.getEach(QBackendMetaData.class);
|
||||
assertEquals(1, backends.size());
|
||||
assertEquals("backendC", backends.get(0).getName());
|
||||
|
||||
List<QQueueProviderMetaData> queueProviders = metaDataProducerMultiOutput.getEach(QQueueProviderMetaData.class);
|
||||
assertEquals(0, queueProviders.size());
|
||||
|
||||
//////////////////////////////////////////////
|
||||
// test some calls to get that takes a name //
|
||||
//////////////////////////////////////////////
|
||||
assertEquals("tableA", metaDataProducerMultiOutput.get(QTableMetaData.class, "tableA").getName());
|
||||
assertNull(metaDataProducerMultiOutput.get(QProcessMetaData.class, "tableA"));
|
||||
assertNull(metaDataProducerMultiOutput.get(QQueueMetaData.class, "queueQ"));
|
||||
}
|
||||
|
||||
}
|
@ -33,11 +33,14 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.kingsrook.qqq.backend.core.BaseTest;
|
||||
import com.kingsrook.qqq.backend.core.utils.collections.ListBuilder;
|
||||
import com.kingsrook.qqq.backend.core.utils.collections.MapBuilder;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
@ -639,4 +642,35 @@ class CollectionUtilsTest extends BaseTest
|
||||
assertEquals(Set.of("", "1"), s);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testAddAllIfNotNull()
|
||||
{
|
||||
BiFunction<Collection<Integer>, Collection<Integer>, Collection<Integer>> doAddAllIfNotNull = (Collection<Integer> destination, Collection<Integer> source) ->
|
||||
{
|
||||
CollectionUtils.addAllIfNotNull(destination, source);
|
||||
return (destination);
|
||||
};
|
||||
|
||||
assertThatThrownBy(() -> doAddAllIfNotNull.apply(null, null)).hasMessage("destination may not be null");
|
||||
assertThatThrownBy(() -> doAddAllIfNotNull.apply(null, Collections.emptyList())).hasMessage("destination may not be null");
|
||||
assertThatThrownBy(() -> doAddAllIfNotNull.apply(null, List.of(1))).hasMessage("destination may not be null");
|
||||
|
||||
assertEquals(List.of(), doAddAllIfNotNull.apply(new ArrayList<>(), null));
|
||||
assertEquals(List.of(), doAddAllIfNotNull.apply(new ArrayList<>(), Collections.emptyList()));
|
||||
assertEquals(List.of(1), doAddAllIfNotNull.apply(new ArrayList<>(), List.of(1)));
|
||||
|
||||
assertEquals(List.of(1), doAddAllIfNotNull.apply(ListBuilder.of(1), null));
|
||||
assertEquals(List.of(1, 2), doAddAllIfNotNull.apply(ListBuilder.of(1), ListBuilder.of(2)));
|
||||
assertEquals(List.of(1, 2, 3), doAddAllIfNotNull.apply(ListBuilder.of(1), ListBuilder.of(2, 3)));
|
||||
|
||||
assertEquals(Set.of(1), doAddAllIfNotNull.apply(new HashSet<>(List.of(1)), null));
|
||||
assertEquals(Set.of(1, 2), doAddAllIfNotNull.apply(new HashSet<>(List.of(1)), List.of(2)));
|
||||
assertEquals(Set.of(1, 2, 3), doAddAllIfNotNull.apply(new HashSet<>(List.of(1)), List.of(2, 3)));
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user