-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SHIBUI-836: wip... property replacer API
- Loading branch information
Showing
4 changed files
with
65 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
...ibboleth/admin/ui/domain/resolvers/MetadataResolverPropertyPlaceholderValuesReplacer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package edu.internet2.tier.shibboleth.admin.ui.domain.resolvers; | ||
|
||
/** | ||
* An SPI to resolve and convert data for different types of {@link MetadataResolver}s from possible provided '%{}' placeholders | ||
* <p> | ||
* Typical usage is - multiple replacers for concrete type of resolvers are configured in Spring Application Context, | ||
* aggregated by {@link MetadataResolverPropertyPlaceholderValuesResolvingService} facade and then that facade is injected into upstream consumers of it | ||
* such as REST controllers, etc. | ||
* | ||
* @author Dmitriy Kopylenko | ||
*/ | ||
public interface MetadataResolverPropertyPlaceholderValuesReplacer<T extends MetadataResolver> { | ||
|
||
boolean supports(T metadataResolver); | ||
|
||
void replacePlaceholderValuesIfResolvableOrFail(T metadataResolver); | ||
} |
29 changes: 29 additions & 0 deletions
29
.../admin/ui/domain/resolvers/MetadataResolverPropertyPlaceholderValuesResolvingService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package edu.internet2.tier.shibboleth.admin.ui.domain.resolvers; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* A facade that aggregates {@link MetadataResolverPropertyPlaceholderValuesReplacer}s available to call just one of them supporting the type of a given resolver. | ||
* If no {@link MetadataResolverPropertyPlaceholderValuesReplacer}s are configured, considers a noop. | ||
* | ||
* Uses chain-of-responsibility design pattern | ||
* | ||
* @author Dmitriy Kopylenko | ||
*/ | ||
public class MetadataResolverPropertyPlaceholderValuesResolvingService<T extends MetadataResolver> { | ||
|
||
private List<MetadataResolverPropertyPlaceholderValuesReplacer<T>> replacers; | ||
|
||
public MetadataResolverPropertyPlaceholderValuesResolvingService(List<MetadataResolverPropertyPlaceholderValuesReplacer<T>> replacers) { | ||
this.replacers = replacers != null ? replacers : new ArrayList<>(); | ||
} | ||
|
||
public void replacePlacehoderValuesOrFail(T metadataResolver) { | ||
this.replacers | ||
.stream() | ||
.filter(r -> r.supports(metadataResolver)) | ||
.findFirst() | ||
.ifPresent(r -> r.replacePlaceholderValuesIfResolvableOrFail(metadataResolver)); | ||
} | ||
} |