Package net.shibboleth.idp.attribute.resolver.dc.storage.impl

# Class TemplatedSearchBuilder

java.lang.Object
net.shibboleth.shared.component.AbstractInitializableComponent
net.shibboleth.idp.attribute.resolver.dc.storage.impl.TemplatedSearchBuilder

All Implemented Interfaces:
  `ExecutableSearchBuilder<StorageServiceSearch>`, `Component`, `DestructableComponent`, `InitializableComponent`

public class TemplatedSearchBuilder extends AbstractInitializableComponent implements ExecutableSearchBuilder<StorageServiceSearch>
An `ExecutableSearchBuilder` that generates the `StorageService` context and key using Velocity templates.

Since:
  4.1.0

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`static final record`
`TemplatedSearchBuilder.ContextAndKey`
Record encapsulating storage context and key.

## Field Summary

Fields
Modifier and Type
Field
Description
`private Template`
`contextTemplate`
Context template to be evaluated.
`private String`
`contextTemplateText`
Text of context template to be evaluated.
`private Object`
`customObject`
A custom object to inject into the template.
`private org.apache.velocity.app.VelocityEngine`
`engine`
VelocityEngine.
`private Template`
`keyTemplate`
Key template to be evaluated.
`private String`
`keyTemplateText`
Text of key template to be evaluated.
`private final org.slf4j.Logger`
`log`
Class logger.

## Constructor Summary

Constructors
Constructor
Description
`TemplatedSearchBuilder()`

## Method Summary

Modifier and Type
Method
Description
`StorageServiceSearch`
`build(AttributeResolutionContext resolutionContext, Map<String,List<IdPAttributeValue>> dependencyAttributes)`
Creates an executable search that can be executed against a data source in order to produce results.
`protected void`
`doInitialize()`
`private TemplatedSearchBuilder.ContextAndKey`
`getContextAndKey(AttributeResolutionContext resolutionContext, Map<String,List<IdPAttributeValue>> dependencyAttributes)`
Helper method to extract the parameters needed for the `StorageServiceSearch`.
`Template`
`getContextTemplate()`
Get the context template to be evaluated.
`String`
`getContextTemplateText()`
Get the context template text to be evaluated.
`Template`
`getKeyTemplate()`
Get the key template to be evaluated.
`String`
`getKeyTemplateText()`
Get the key template text to be evaluated.
`org.apache.velocity.app.VelocityEngine`
`getVelocityEngine()`
Get the `VelocityEngine` to be used.
`void`
`setContextTemplateText(String text)`
Set the context template to be evaluated.
`void`
`setCustomObject(Object object)`
Set the custom (externally provided) object.
`void`
`setKeyTemplateText(String text)`
Set the key template to be evaluated.
`void`
`setVelocityEngine(org.apache.velocity.app.VelocityEngine velocityEngine)`
Set the `VelocityEngine` to be used.

### Methods inherited from class net.shibboleth.shared.component.AbstractInitializableComponent

`checkComponentActive, checkSetterPreconditions, destroy, doDestroy, ifDestroyedThrowDestroyedComponentException, ifInitializedThrowUnmodifiabledComponentException, ifNotInitializedThrowUninitializedComponentException, initialize, isDestroyed, isInitialized`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### log

@Nonnull private final org.slf4j.Logger log
Class logger.

### contextTemplate

@NonnullAfterInit private Template contextTemplate
Context template to be evaluated.

### keyTemplate

@NonnullAfterInit private Template keyTemplate
Key template to be evaluated.

### contextTemplateText

@NonnullAfterInit private String contextTemplateText
Text of context template to be evaluated.

### keyTemplateText

@NonnullAfterInit private String keyTemplateText
Text of key template to be evaluated.

### engine

@NonnullAfterInit private org.apache.velocity.app.VelocityEngine engine
VelocityEngine.

### customObject

@Nullable private Object customObject
A custom object to inject into the template.

## Constructor Details

### TemplatedSearchBuilder

public TemplatedSearchBuilder()

## Method Details

### getContextTemplate

@NonnullAfterInit public Template getContextTemplate()
Get the context template to be evaluated.

Returns:
  template

### getKeyTemplate

@NonnullAfterInit public Template getKeyTemplate()
Get the key template to be evaluated.

Returns:
  template

### getContextTemplateText

@NonnullAfterInit public String getContextTemplateText()
Get the context template text to be evaluated.

Returns:
  template text

### setContextTemplateText

public void setContextTemplateText(@Nullable String text)
Set the context template to be evaluated.

Parameters:
  `text` - template to be evaluated

### getKeyTemplateText

@NonnullAfterInit public String getKeyTemplateText()
Get the key template text to be evaluated.

Returns:
  template text

### setKeyTemplateText

public void setKeyTemplateText(@Nullable String text)
Set the key template to be evaluated.

Parameters:
  `text` - template to be evaluated

### getVelocityEngine

@NonnullAfterInit public org.apache.velocity.app.VelocityEngine getVelocityEngine()
Get the `VelocityEngine` to be used.

Returns:
  template engine

### setVelocityEngine

public void setVelocityEngine(@Nonnull org.apache.velocity.app.VelocityEngine velocityEngine)
Set the `VelocityEngine` to be used.

Parameters:
  `velocityEngine` - engine to be used

### setCustomObject

public void setCustomObject(@Nullable Object object)
Set the custom (externally provided) object.

Parameters:
  `object` - the custom object

### doInitialize

protected void doInitialize() throws ComponentInitializationException

Overrides:
  `doInitialize` in class `AbstractInitializableComponent`
Throws:
  `ComponentInitializationException`

### build

@Nonnull public StorageServiceSearch build(@Nonnull AttributeResolutionContext resolutionContext, @Nonnull Map<String,List<IdPAttributeValue>> dependencyAttributes) throws ResolutionException
Creates an executable search that can be executed against a data source in order to produce results.

Specified by:
  `build` in interface `ExecutableSearchBuilder<StorageServiceSearch>`
Parameters:
  `resolutionContext` - current request context
  `dependencyAttributes` - made available to the executable search
Returns:
  executable search
Throws:
  `ResolutionException` - throw if their is a problem creating the executable search

### getContextAndKey

@Nonnull private TemplatedSearchBuilder.ContextAndKey getContextAndKey(@Nonnull AttributeResolutionContext resolutionContext, @Nonnull Map<String,List<IdPAttributeValue>> dependencyAttributes) throws ResolutionException
Helper method to extract the parameters needed for the `StorageServiceSearch`.

Parameters:
  `resolutionContext` - the context of the resolution
  `dependencyAttributes` - the attributes we depend upon
Returns:
  the derived `StorageService` context and key
Throws:
  `ResolutionException` - if the velocity operations failed resolution failed.