Skip to content

Commit

Permalink
feat: add binding to service provider for use in Groovy script
Browse files Browse the repository at this point in the history
Add an additional binding for the Service Provider to Groovy scripts.

ING-4265
  • Loading branch information
florianesser authored and emanuelaepure10 committed May 3, 2024
1 parent 97b0df6 commit 5e304ab
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 0 deletions.
7 changes: 7 additions & 0 deletions common/plugins/eu.esdihumboldt.hale.common.core/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,11 @@
implementation="eu.esdihumboldt.hale.common.core.io.internal.AsValueMetaClass">
</metaClass>
</extension>
<extension
point="eu.esdihumboldt.util.groovy.sandbox">
<allow
allowAll="false"
class="eu.esdihumboldt.hale.common.core.service.DelegateServiceProvider">
</allow>
</extension>
</plugin>
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*
* Contributors:
* wetransform GmbH <http://www.wetransform.to>
*/

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> T getService(Class<T> serviceInterface) {
return serviceProvider.getService(serviceInterface);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 5e304ab

Please sign in to comment.