From 5e304abd4f4ff4b160aee6f4d8ade657e9692067 Mon Sep 17 00:00:00 2001 From: Florian Esser Date: Wed, 24 Apr 2024 16:41:00 +0200 Subject: [PATCH] feat: add binding to service provider for use in Groovy script Add an additional binding for the Service Provider to Groovy scripts. ING-4265 --- .../plugin.xml | 7 +++ .../core/service/DelegateServiceProvider.java | 44 +++++++++++++++++++ .../cst/functions/groovy/GroovyConstants.java | 5 +++ .../functions/groovy/internal/GroovyUtil.java | 4 ++ 4 files changed, 60 insertions(+) create mode 100644 common/plugins/eu.esdihumboldt.hale.common.core/src/eu/esdihumboldt/hale/common/core/service/DelegateServiceProvider.java diff --git a/common/plugins/eu.esdihumboldt.hale.common.core/plugin.xml b/common/plugins/eu.esdihumboldt.hale.common.core/plugin.xml index a68c08c8ea..a05e39da6d 100644 --- a/common/plugins/eu.esdihumboldt.hale.common.core/plugin.xml +++ b/common/plugins/eu.esdihumboldt.hale.common.core/plugin.xml @@ -225,4 +225,11 @@ implementation="eu.esdihumboldt.hale.common.core.io.internal.AsValueMetaClass"> + + + + diff --git a/common/plugins/eu.esdihumboldt.hale.common.core/src/eu/esdihumboldt/hale/common/core/service/DelegateServiceProvider.java b/common/plugins/eu.esdihumboldt.hale.common.core/src/eu/esdihumboldt/hale/common/core/service/DelegateServiceProvider.java new file mode 100644 index 0000000000..9c5e2df382 --- /dev/null +++ b/common/plugins/eu.esdihumboldt.hale.common.core/src/eu/esdihumboldt/hale/common/core/service/DelegateServiceProvider.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 wetransform GmbH + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution. If not, see . + * + * Contributors: + * wetransform GmbH + */ + +package eu.esdihumboldt.hale.common.core.service; + +/** + * A DelegateServiceProvider delegates service requests to an underlying + * ServiceProvider. It implements the ServiceProvider interface and forwards + * getService calls to the specified underlying ServiceProvider. + * + * @author EmanuelaEpure + */ +public class DelegateServiceProvider implements ServiceProvider { + + private final ServiceProvider serviceProvider; + + /** + * Constructs a new DelegateServiceProvider with the specified + * ServiceProvider. + * + * @param serviceProvider the underlying ServiceProvider to delegate to + */ + public DelegateServiceProvider(ServiceProvider serviceProvider) { + this.serviceProvider = serviceProvider; + } + + @Override + public T getService(Class serviceInterface) { + return serviceProvider.getService(serviceInterface); + } + +} diff --git a/cst/plugins/eu.esdihumboldt.cst.functions.groovy/src/eu/esdihumboldt/cst/functions/groovy/GroovyConstants.java b/cst/plugins/eu.esdihumboldt.cst.functions.groovy/src/eu/esdihumboldt/cst/functions/groovy/GroovyConstants.java index 3c293ab165..4f0200bb57 100644 --- a/cst/plugins/eu.esdihumboldt.cst.functions.groovy/src/eu/esdihumboldt/cst/functions/groovy/GroovyConstants.java +++ b/cst/plugins/eu.esdihumboldt.cst.functions.groovy/src/eu/esdihumboldt/cst/functions/groovy/GroovyConstants.java @@ -69,6 +69,11 @@ public interface GroovyConstants { */ public static final String BINDING_INSTANCE_INDEX = "_instanceIndex"; + /** + * Name of the service provider in the binding. + */ + public static final String BINDING_SERVICE_PROVIDER = "_serviceProvider"; + /** * Name of the helper functions accessor. */ diff --git a/cst/plugins/eu.esdihumboldt.cst.functions.groovy/src/eu/esdihumboldt/cst/functions/groovy/internal/GroovyUtil.java b/cst/plugins/eu.esdihumboldt.cst.functions.groovy/src/eu/esdihumboldt/cst/functions/groovy/internal/GroovyUtil.java index 66107c00a4..a32c27ccf5 100644 --- a/cst/plugins/eu.esdihumboldt.cst.functions.groovy/src/eu/esdihumboldt/cst/functions/groovy/internal/GroovyUtil.java +++ b/cst/plugins/eu.esdihumboldt.cst.functions.groovy/src/eu/esdihumboldt/cst/functions/groovy/internal/GroovyUtil.java @@ -43,6 +43,7 @@ import eu.esdihumboldt.hale.common.core.io.Text; import eu.esdihumboldt.hale.common.core.io.project.ProjectInfoService; import eu.esdihumboldt.hale.common.core.report.SimpleLog; +import eu.esdihumboldt.hale.common.core.service.DelegateServiceProvider; import eu.esdihumboldt.hale.common.instance.groovy.InstanceBuilder; import eu.esdihumboldt.hale.common.instance.index.InstanceIndexService; import eu.esdihumboldt.hale.common.instance.index.spatial.SpatialIndexService; @@ -305,6 +306,9 @@ public static Binding createBinding(InstanceBuilder builder, Cell cell, Cell typ binding.setVariable(BINDING_INSTANCE_INDEX, executionContext.getService(InstanceIndexService.class)); + binding.setVariable(BINDING_SERVICE_PROVIDER, + new DelegateServiceProvider(executionContext)); + return binding; } }