Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: bind lookup service to Groovy constant for use in scripts #1166

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}

}
8 changes: 7 additions & 1 deletion common/plugins/eu.esdihumboldt.hale.common.lookup/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,11 @@
id="eu.esdihumboldt.hale.lookup.import.service">
</advisor>
</extension>

<extension
point="eu.esdihumboldt.util.groovy.sandbox">
<allow
allowAll="false"
class="eu.esdihumboldt.hale.common.lookup.internal.LookupServiceImpl">
</allow>
</extension>
</plugin>
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;
}
}
Loading