From 80fab411659d100b9414fdbecc6a536e1f6e8895 Mon Sep 17 00:00:00 2001 From: Daniil Palagin Date: Wed, 25 Sep 2024 11:31:41 +0200 Subject: [PATCH] [#274] Move loadManualConfiguration to the AnnotatedAbstractModule --- .../cvut/spipes/modules/AbstractModule.java | 1 - .../modules/AnnotatedAbstractModule.java | 30 ++++++++++++++----- .../java/cz/cvut/spipes/modules/Module.java | 2 -- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/s-pipes-core/src/main/java/cz/cvut/spipes/modules/AbstractModule.java b/s-pipes-core/src/main/java/cz/cvut/spipes/modules/AbstractModule.java index 6bcd1076..8bf714df 100644 --- a/s-pipes-core/src/main/java/cz/cvut/spipes/modules/AbstractModule.java +++ b/s-pipes-core/src/main/java/cz/cvut/spipes/modules/AbstractModule.java @@ -71,7 +71,6 @@ public abstract class AbstractModule implements Module { public ExecutionContext execute() { loadModuleFlags(); loadConfiguration(); - loadManualConfiguration(); loadModuleConstraints(); String inputModelFilePath = null; if (AuditConfig.isEnabled() || isInDebugMode) { diff --git a/s-pipes-core/src/main/java/cz/cvut/spipes/modules/AnnotatedAbstractModule.java b/s-pipes-core/src/main/java/cz/cvut/spipes/modules/AnnotatedAbstractModule.java index a8690d26..744cd522 100644 --- a/s-pipes-core/src/main/java/cz/cvut/spipes/modules/AnnotatedAbstractModule.java +++ b/s-pipes-core/src/main/java/cz/cvut/spipes/modules/AnnotatedAbstractModule.java @@ -30,10 +30,10 @@ public abstract class AnnotatedAbstractModule extends AbstractModule { @Override public void loadConfiguration() { - final Map vars = new HashMap<>(); - for(final Field f: this.getClass().getDeclaredFields()) { + final Map vars = new HashMap<>(); + for (final Field f : this.getClass().getDeclaredFields()) { final Parameter p = f.getAnnotation(Parameter.class); - if ( p == null ) { + if (p == null) { continue; } else if (vars.containsKey(p.iri())) { throw new RuntimeException(String.format("Two parameters have same iri %s", p.iri())); @@ -44,17 +44,33 @@ public void loadConfiguration() { log.trace("Processing parameter {} ", f.getName()); Setter setter; - if(f.getType() == List.class){ + if (f.getType() == List.class) { setter = new ListSetter(f, this); - }else{ + } else { setter = new FieldSetter(f, this); } HandlerRegistry handlerRegistry = HandlerRegistry.getInstance(); Handler handler = handlerRegistry.getHandler(f.getType(), resource, executionContext, setter); handler.setValueByProperty(ResourceFactory.createProperty(p.iri())); } + loadManualConfiguration(); } - @Override - public void loadManualConfiguration(){} + /** + * This abstract method is intended to be overridden by subclasses to manually load + * specific configurations that are not automatically processed by the + * {@link #loadConfiguration()} method. + *

+ * The {@link #loadConfiguration()} method first handles automated configuration by + * scanning annotated fields and invoking handlers to set their values. Once that + * process is complete, {@code loadManualConfiguration} is called to allow subclasses + * to define any additional custom configuration logic that is required. + *

+ * Subclasses can choose to override this method to provide custom configurations + * that cannot be handled automatically. If no manual configuration is necessary, + * the default implementation can be used without changes. + */ + public void loadManualConfiguration(){ + // Default implementation: no manual configuration + }; } diff --git a/s-pipes-core/src/main/java/cz/cvut/spipes/modules/Module.java b/s-pipes-core/src/main/java/cz/cvut/spipes/modules/Module.java index fdc73578..09a19978 100644 --- a/s-pipes-core/src/main/java/cz/cvut/spipes/modules/Module.java +++ b/s-pipes-core/src/main/java/cz/cvut/spipes/modules/Module.java @@ -41,8 +41,6 @@ public interface Module { */ void loadConfiguration(); - void loadManualConfiguration(); - Resource getResource(); void setInputModules(List inputModules);