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.logging.QLogger;
|
||||||
import com.kingsrook.qqq.backend.core.model.metadata.QBackendMetaData;
|
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.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.code.QCodeReference;
|
||||||
import com.kingsrook.qqq.backend.core.model.metadata.dashboard.QWidgetMetaDataInterface;
|
import com.kingsrook.qqq.backend.core.model.metadata.dashboard.QWidgetMetaDataInterface;
|
||||||
import com.kingsrook.qqq.backend.core.model.metadata.fields.AdornmentType;
|
import com.kingsrook.qqq.backend.core.model.metadata.fields.AdornmentType;
|
||||||
@ -210,6 +211,11 @@ public class QInstanceEnricher
|
|||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
private void enrichInstance()
|
private void enrichInstance()
|
||||||
{
|
{
|
||||||
|
for(QSupplementalInstanceMetaData supplementalInstanceMetaData : qInstance.getSupplementalMetaData().values())
|
||||||
|
{
|
||||||
|
supplementalInstanceMetaData.enrich(qInstance);
|
||||||
|
}
|
||||||
|
|
||||||
runPlugins(QInstance.class, qInstance, qInstance);
|
runPlugins(QInstance.class, qInstance, qInstance);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1477,8 +1483,19 @@ public class QInstanceEnricher
|
|||||||
if(enrichMethod.isPresent())
|
if(enrichMethod.isPresent())
|
||||||
{
|
{
|
||||||
Class<?> parameterType = enrichMethod.get().getParameterTypes()[0];
|
Class<?> parameterType = enrichMethod.get().getParameterTypes()[0];
|
||||||
|
|
||||||
|
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);
|
enricherPlugins.add(parameterType, plugin);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LOG.warn("Could not find enrich method on enricher plugin [" + plugin.getClass().getName() + "] (to infer type being enriched) - this plugin will not be used.");
|
LOG.warn("Could not find enrich method on enricher plugin [" + plugin.getClass().getName() + "] (to infer type being enriched) - this plugin will not be used.");
|
||||||
|
@ -295,8 +295,19 @@ public class QInstanceValidator
|
|||||||
if(validateMethod.isPresent())
|
if(validateMethod.isPresent())
|
||||||
{
|
{
|
||||||
Class<?> parameterType = validateMethod.get().getParameterTypes()[0];
|
Class<?> parameterType = validateMethod.get().getParameterTypes()[0];
|
||||||
|
|
||||||
|
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);
|
validatorPlugins.add(parameterType, plugin);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LOG.warn("Could not find validate method on validator plugin [" + plugin.getClass().getName() + "] (to infer type being validated) - this plugin will not be used.");
|
LOG.warn("Could not find validate method on validator plugin [" + plugin.getClass().getName() + "] (to infer type being validated) - this plugin will not be used.");
|
||||||
|
@ -37,4 +37,13 @@ public interface QInstanceEnricherPluginInterface<T>
|
|||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
void enrich(T object, QInstance qInstance);
|
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);
|
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 java.util.function.Supplier;
|
||||||
import com.kingsrook.qqq.backend.core.instances.QInstanceValidator;
|
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 //
|
// noop in base class //
|
||||||
|
Reference in New Issue
Block a user