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 Apr 30, 2024
1 parent 97b0df6 commit 5866158
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
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 @@ -49,6 +49,7 @@
import eu.esdihumboldt.hale.common.instance.model.MutableInstance;
import eu.esdihumboldt.hale.common.schema.model.TypeDefinition;
import eu.esdihumboldt.hale.io.groovy.snippets.GroovySnippets;
import eu.esdihumboldt.util.groovy.sandbox.GroovyRestrictionException;
import eu.esdihumboldt.util.groovy.sandbox.GroovyService;
import eu.esdihumboldt.util.groovy.sandbox.GroovyService.ResultProcessor;
import groovy.lang.Binding;
Expand Down Expand Up @@ -305,6 +306,13 @@ public static Binding createBinding(InstanceBuilder builder, Cell cell, Cell typ
binding.setVariable(BINDING_INSTANCE_INDEX,
executionContext.getService(InstanceIndexService.class));

try {
binding.setVariable(BINDING_SERVICE_PROVIDER, executionContext);
} catch (GroovyRestrictionException e) {
throw new GroovyRestrictionException("Failed to set binding variable: "
+ BINDING_SERVICE_PROVIDER + ", " + e.getMessage());
}

return binding;
}
}

0 comments on commit 5866158

Please sign in to comment.