mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 13:10:44 +00:00
Prevent multiple copies of enrichment & validation plugins; actually implement QSupplementalInstanceMetaData enrichment
This commit is contained in:
@ -47,6 +47,7 @@ import com.kingsrook.qqq.backend.core.instances.enrichment.plugins.QInstanceEnri
|
||||
import com.kingsrook.qqq.backend.core.logging.QLogger;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.QBackendMetaData;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.QSupplementalInstanceMetaData;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.code.QCodeReference;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.dashboard.QWidgetMetaDataInterface;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.fields.AdornmentType;
|
||||
@ -210,6 +211,11 @@ public class QInstanceEnricher
|
||||
***************************************************************************/
|
||||
private void enrichInstance()
|
||||
{
|
||||
for(QSupplementalInstanceMetaData supplementalInstanceMetaData : qInstance.getSupplementalMetaData().values())
|
||||
{
|
||||
supplementalInstanceMetaData.enrich(qInstance);
|
||||
}
|
||||
|
||||
runPlugins(QInstance.class, qInstance, qInstance);
|
||||
}
|
||||
|
||||
@ -1477,7 +1483,18 @@ public class QInstanceEnricher
|
||||
if(enrichMethod.isPresent())
|
||||
{
|
||||
Class<?> parameterType = enrichMethod.get().getParameterTypes()[0];
|
||||
enricherPlugins.add(parameterType, plugin);
|
||||
|
||||
Set<String> existingPluginIdentifiers = enricherPlugins.getOrDefault(parameterType, Collections.emptyList())
|
||||
.stream().map(p -> p.getPluginIdentifier())
|
||||
.collect(Collectors.toSet());
|
||||
if(existingPluginIdentifiers.contains(plugin.getPluginIdentifier()))
|
||||
{
|
||||
LOG.debug("Enricher plugin is already registered - not re-adding it", logPair("pluginIdentifer", plugin.getPluginIdentifier()));
|
||||
}
|
||||
else
|
||||
{
|
||||
enricherPlugins.add(parameterType, plugin);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -295,7 +295,18 @@ public class QInstanceValidator
|
||||
if(validateMethod.isPresent())
|
||||
{
|
||||
Class<?> parameterType = validateMethod.get().getParameterTypes()[0];
|
||||
validatorPlugins.add(parameterType, plugin);
|
||||
|
||||
Set<String> existingPluginIdentifiers = validatorPlugins.getOrDefault(parameterType, Collections.emptyList())
|
||||
.stream().map(p -> p.getPluginIdentifier())
|
||||
.collect(Collectors.toSet());
|
||||
if(existingPluginIdentifiers.contains(plugin.getPluginIdentifier()))
|
||||
{
|
||||
LOG.debug("Validator plugin is already registered - not re-adding it", logPair("pluginIdentifer", plugin.getPluginIdentifier()));
|
||||
}
|
||||
else
|
||||
{
|
||||
validatorPlugins.add(parameterType, plugin);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -313,7 +324,7 @@ public class QInstanceValidator
|
||||
validatorPlugins.clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for validatorPlugins
|
||||
|
@ -37,4 +37,13 @@ public interface QInstanceEnricherPluginInterface<T>
|
||||
*******************************************************************************/
|
||||
void enrich(T object, QInstance qInstance);
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
**
|
||||
***************************************************************************/
|
||||
default String getPluginIdentifier()
|
||||
{
|
||||
return getClass().getName();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -38,4 +38,13 @@ public interface QInstanceValidatorPluginInterface<T>
|
||||
*******************************************************************************/
|
||||
void validate(T object, QInstance qInstance, QInstanceValidator qInstanceValidator);
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
**
|
||||
***************************************************************************/
|
||||
default String getPluginIdentifier()
|
||||
{
|
||||
return getClass().getName();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -24,7 +24,6 @@ package com.kingsrook.qqq.backend.core.model.metadata;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
import com.kingsrook.qqq.backend.core.instances.QInstanceValidator;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
@ -37,7 +36,7 @@ public interface QSupplementalInstanceMetaData extends TopLevelMetaDataInterface
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
default void enrich(QTableMetaData table)
|
||||
default void enrich(QInstance qInstance)
|
||||
{
|
||||
////////////////////////
|
||||
// noop in base class //
|
||||
|
Reference in New Issue
Block a user