This repository has been archived by the owner on Aug 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #582 from CJSCommonPlatform/fix-query-schema-catalog
Fix query schema catalog
- Loading branch information
Showing
26 changed files
with
431 additions
and
261 deletions.
There are no files selected for viewing
39 changes: 9 additions & 30 deletions
39
core/src/main/java/uk/gov/justice/services/core/mapping/DefaultMediaTypesMappingCache.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 |
---|---|---|
@@ -1,53 +1,32 @@ | ||
package uk.gov.justice.services.core.mapping; | ||
|
||
import static java.util.Optional.ofNullable; | ||
import static java.util.stream.Collectors.toMap; | ||
|
||
import uk.gov.justice.services.core.extension.BeanInstantiater; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.stream.Stream; | ||
|
||
import javax.annotation.PostConstruct; | ||
import javax.enterprise.inject.spi.Bean; | ||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.inject.Inject; | ||
|
||
/** | ||
* Constructs a cache of action name to media type from the List of {@link ActionNameToMediaTypesMapper} | ||
* beans provided by the {@link ActionNameToMediaTypesMappingObserver}. | ||
*/ | ||
@ApplicationScoped | ||
public class DefaultMediaTypesMappingCache implements MediaTypesMappingCache { | ||
|
||
@Inject | ||
ActionNameToMediaTypesMappingObserver actionNameToMediaTypesMappingObserver; | ||
|
||
@Inject | ||
BeanInstantiater beanInstantiater; | ||
MediaTypesMappingCacheInitialiser mediaTypesMappingCacheInitialiser; | ||
|
||
private Map<String, MediaTypes> actionNameToMediaTypesCache; | ||
|
||
/** | ||
* Gets the List of {@link ActionNameToMediaTypesMapper} beans, instantiates them and collects all | ||
* entries into a single Map of action name to media type. | ||
*/ | ||
@PostConstruct | ||
public void initialise() { | ||
actionNameToMediaTypesCache = actionNameToMediaTypesMappingObserver.getNameMediaTypesMappers().stream() | ||
.flatMap(this::mapEntriesFrom) | ||
.collect(toMap( | ||
Map.Entry::getKey, | ||
Map.Entry::getValue, | ||
(schemaId_1, schemaId_2) -> schemaId_1 | ||
)); | ||
} | ||
|
||
@Override | ||
public Optional<MediaTypes> mediaTypesFor(final String actionName) { | ||
return ofNullable(actionNameToMediaTypesCache.get(actionName)); | ||
} | ||
public synchronized Optional<MediaTypes> mediaTypesFor(final String actionName) { | ||
|
||
private Stream<Map.Entry<String, MediaTypes>> mapEntriesFrom(final Bean<?> bean) { | ||
return ((ActionNameToMediaTypesMapper) beanInstantiater.instantiate(bean)).getActionNameToMediaTypesMap().entrySet().stream(); | ||
if (actionNameToMediaTypesCache == null) { | ||
actionNameToMediaTypesCache = mediaTypesMappingCacheInitialiser.initialiseCache(); | ||
} | ||
|
||
return ofNullable(actionNameToMediaTypesCache.get(actionName)); | ||
} | ||
} |
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
36 changes: 36 additions & 0 deletions
36
...src/main/java/uk/gov/justice/services/core/mapping/MediaTypesMappingCacheInitialiser.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,36 @@ | ||
package uk.gov.justice.services.core.mapping; | ||
|
||
import static java.util.stream.Collectors.toMap; | ||
|
||
import uk.gov.justice.services.core.extension.BeanInstantiater; | ||
|
||
import java.util.Map; | ||
import java.util.stream.Stream; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.enterprise.inject.spi.Bean; | ||
import javax.inject.Inject; | ||
|
||
@ApplicationScoped | ||
public class MediaTypesMappingCacheInitialiser { | ||
|
||
@Inject | ||
ActionNameToMediaTypesMappingObserver actionNameToMediaTypesMappingObserver; | ||
|
||
@Inject | ||
BeanInstantiater beanInstantiater; | ||
|
||
public Map<String, MediaTypes> initialiseCache() { | ||
return actionNameToMediaTypesMappingObserver.getNameMediaTypesMappers().stream() | ||
.flatMap(this::mapEntriesFrom) | ||
.collect(toMap( | ||
Map.Entry::getKey, | ||
Map.Entry::getValue, | ||
(schemaId_1, schemaId_2) -> schemaId_1 | ||
)); | ||
} | ||
|
||
private Stream<Map.Entry<String, MediaTypes>> mapEntriesFrom(final Bean<?> bean) { | ||
return ((ActionNameToMediaTypesMapper) beanInstantiater.instantiate(bean)).getActionNameToMediaTypesMap().entrySet().stream(); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
core/src/main/java/uk/gov/justice/services/core/mapping/SchemaIdMappingCacheInitialiser.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,34 @@ | ||
package uk.gov.justice.services.core.mapping; | ||
|
||
import static java.util.stream.Collectors.toMap; | ||
|
||
import uk.gov.justice.services.core.extension.BeanInstantiater; | ||
|
||
import java.util.Map; | ||
import java.util.stream.Stream; | ||
|
||
import javax.enterprise.inject.spi.Bean; | ||
import javax.inject.Inject; | ||
|
||
public class SchemaIdMappingCacheInitialiser { | ||
|
||
@Inject | ||
SchemaIdMappingObserver schemaIdMappingObserver; | ||
|
||
@Inject | ||
BeanInstantiater beanInstantiater; | ||
|
||
public Map<MediaType, String> initialiseCache() { | ||
return schemaIdMappingObserver.getMediaTypeToSchemaIdMappers().stream() | ||
.flatMap(this::mapEntriesFrom) | ||
.collect(toMap( | ||
Map.Entry::getKey, | ||
Map.Entry::getValue, | ||
(schemaId_1, schemaId_2) -> schemaId_1 | ||
)); | ||
} | ||
|
||
private Stream<Map.Entry<MediaType, String>> mapEntriesFrom(final Bean<?> bean) { | ||
return ((MediaTypeToSchemaIdMapper) beanInstantiater.instantiate(bean)).getMediaTypeToSchemaIdMap().entrySet().stream(); | ||
} | ||
} |
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
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
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
Oops, something went wrong.