-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
108 changed files
with
3,295 additions
and
558 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
This file was deleted.
Oops, something went wrong.
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,24 @@ | ||
plugins { | ||
id("io.micronaut.build.internal.module") | ||
} | ||
|
||
dependencies { | ||
annotationProcessor(mn.micronaut.validation) | ||
|
||
implementation(mn.micronaut.validation) | ||
|
||
api(project(":aws-alexa")) | ||
|
||
implementation(mn.micronaut.http.server) | ||
api(libs.managed.alexa.ask.sdk.core) | ||
|
||
testImplementation(mn.micronaut.http.client) | ||
testImplementation(mn.micronaut.http.server.netty) | ||
testImplementation(libs.bouncycastle.provider) | ||
testImplementation(libs.alexa.ask.sdk) { | ||
isTransitive = false | ||
} | ||
testImplementation(libs.alexa.ask.sdk.apache.client) | ||
|
||
testRuntimeOnly(libs.jcl.over.slf4j) | ||
} |
This file was deleted.
Oops, something went wrong.
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,23 @@ | ||
plugins { | ||
id("io.micronaut.build.internal.module") | ||
} | ||
|
||
dependencies { | ||
annotationProcessor(mn.micronaut.validation) | ||
|
||
implementation(mn.micronaut.validation) | ||
|
||
compileOnly(libs.alexa.ask.sdk) | ||
api(libs.managed.alexa.ask.sdk.core) | ||
|
||
testAnnotationProcessor(mn.micronaut.inject.java) | ||
testImplementation(libs.alexa.ask.sdk) { | ||
isTransitive = false | ||
} | ||
testImplementation(libs.alexa.ask.sdk.apache.client) | ||
|
||
testImplementation(mn.micronaut.http.client) | ||
testImplementation(mn.micronaut.http.server.netty) | ||
testImplementation(mn.groovy.json) | ||
testRuntimeOnly(libs.jcl.over.slf4j) | ||
} |
58 changes: 58 additions & 0 deletions
58
...lexa/src/main/java/io/micronaut/aws/alexa/locale/CompositeHandlerInputLocaleResolver.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,58 @@ | ||
/* | ||
* Copyright 2017-2022 original authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.micronaut.aws.alexa.locale; | ||
|
||
import com.amazon.ask.dispatcher.request.handler.HandlerInput; | ||
import io.micronaut.context.annotation.Primary; | ||
import io.micronaut.core.annotation.NonNull; | ||
import jakarta.inject.Singleton; | ||
|
||
import java.util.Arrays; | ||
import java.util.Locale; | ||
import java.util.Optional; | ||
|
||
|
||
/** | ||
* {@link Primary} {@link HandlerInputLocaleResolver} which evaluates every {@link HandlerInputLocaleResolver} by order to resolve a {@link java.util.Locale}. | ||
* @author Sergio del Amo | ||
* @since 3.10.0 | ||
*/ | ||
@Primary | ||
@Singleton | ||
public class CompositeHandlerInputLocaleResolver extends HandlerInputAbstractLocaleResolver { | ||
|
||
private final HandlerInputLocaleResolver[] localeResolvers; | ||
|
||
/** | ||
* @param localeResolvers Locale Resolvers | ||
* @param handlerInputLocaleResolutionConfiguration Locale Resolution configuration for HTTP Requests | ||
*/ | ||
public CompositeHandlerInputLocaleResolver(HandlerInputLocaleResolver[] localeResolvers, | ||
HandlerInputLocaleResolutionConfiguration handlerInputLocaleResolutionConfiguration) { | ||
super(handlerInputLocaleResolutionConfiguration); | ||
this.localeResolvers = localeResolvers; | ||
} | ||
|
||
@Override | ||
@NonNull | ||
public Optional<Locale> resolve(@NonNull HandlerInput request) { | ||
return Arrays.stream(localeResolvers) | ||
.map(resolver -> resolver.resolve(request)) | ||
.filter(Optional::isPresent) | ||
.findFirst() | ||
.orElse(Optional.empty()); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
aws-alexa/src/main/java/io/micronaut/aws/alexa/locale/DefaultHandlerInputLocaleResolver.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,51 @@ | ||
/* | ||
* Copyright 2017-2022 original authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.micronaut.aws.alexa.locale; | ||
|
||
import com.amazon.ask.dispatcher.request.handler.HandlerInput; | ||
import io.micronaut.core.annotation.NonNull; | ||
import io.micronaut.core.util.StringUtils; | ||
import jakarta.inject.Singleton; | ||
|
||
import java.util.Locale; | ||
import java.util.Optional; | ||
|
||
/** | ||
* Resolves {@link Locale} from the {@link HandlerInput} request. | ||
* @see <a href="https://developer.amazon.com/en-US/docs/alexa/custom-skills/request-and-response-json-reference.html#request-locale">Request Locale</a>. | ||
* @author Sergio del Amo | ||
* @since 3.10.0 | ||
*/ | ||
@Singleton | ||
public class DefaultHandlerInputLocaleResolver extends HandlerInputAbstractLocaleResolver { | ||
|
||
/** | ||
* @param localeResolutionConfiguration The locale resolution configuration | ||
*/ | ||
protected DefaultHandlerInputLocaleResolver(HandlerInputLocaleResolutionConfiguration localeResolutionConfiguration) { | ||
super(localeResolutionConfiguration); | ||
} | ||
|
||
@Override | ||
@NonNull | ||
public Optional<Locale> resolve(@NonNull HandlerInput input) { | ||
String languageTag = input.getRequest().getLocale(); | ||
if (StringUtils.isEmpty(languageTag)) { | ||
return Optional.empty(); | ||
} | ||
return Optional.of(Locale.forLanguageTag(languageTag)); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...alexa/src/main/java/io/micronaut/aws/alexa/locale/HandlerInputAbstractLocaleResolver.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,43 @@ | ||
/* | ||
* Copyright 2017-2022 original authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.micronaut.aws.alexa.locale; | ||
|
||
import com.amazon.ask.dispatcher.request.handler.HandlerInput; | ||
import io.micronaut.core.util.locale.AbstractLocaleResolver; | ||
|
||
/** | ||
* Provides an abstract class which implements {@link io.micronaut.core.util.LocaleResolver} and handles default locale resolution. | ||
* @author Sergio del Amo | ||
* @since 3.10.0 | ||
*/ | ||
public abstract class HandlerInputAbstractLocaleResolver extends AbstractLocaleResolver<HandlerInput> implements HandlerInputLocaleResolver { | ||
public static final Integer ORDER = 50; | ||
|
||
protected final HandlerInputLocaleResolutionConfiguration localeResolutionConfiguration; | ||
|
||
/** | ||
* @param localeResolutionConfiguration The locale resolution configuration | ||
*/ | ||
protected HandlerInputAbstractLocaleResolver(HandlerInputLocaleResolutionConfiguration localeResolutionConfiguration) { | ||
super(localeResolutionConfiguration.getDefaultLocale()); | ||
this.localeResolutionConfiguration = localeResolutionConfiguration; | ||
} | ||
|
||
@Override | ||
public int getOrder() { | ||
return ORDER; | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
aws-alexa/src/main/java/io/micronaut/aws/alexa/locale/HandlerInputFixedLocaleResolver.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,47 @@ | ||
/* | ||
* Copyright 2017-2020 original authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.micronaut.aws.alexa.locale; | ||
|
||
import com.amazon.ask.dispatcher.request.handler.HandlerInput; | ||
import io.micronaut.context.annotation.Requires; | ||
import io.micronaut.core.order.Ordered; | ||
import io.micronaut.core.util.locale.FixedLocaleResolver; | ||
import jakarta.inject.Singleton; | ||
|
||
/** | ||
* Generic implementation of {@link io.micronaut.core.util.LocaleResolver} for fixed locale resolution. | ||
* | ||
* @author Sergio del Amo | ||
* @since 3.10.0 | ||
*/ | ||
@Singleton | ||
@Requires(property = HandlerInputLocaleResolutionConfigurationProperties.PREFIX + ".fixed") | ||
public class HandlerInputFixedLocaleResolver extends FixedLocaleResolver<HandlerInput> implements HandlerInputLocaleResolver { | ||
|
||
public static final Integer ORDER = Ordered.HIGHEST_PRECEDENCE + 100; | ||
|
||
/** | ||
* @param localeResolutionConfiguration The locale resolution configuration | ||
*/ | ||
public HandlerInputFixedLocaleResolver(HandlerInputLocaleResolutionConfiguration localeResolutionConfiguration) { | ||
super(localeResolutionConfiguration.getFixed().orElseThrow(() -> new IllegalArgumentException("The fixed locale must be set"))); | ||
} | ||
|
||
@Override | ||
public int getOrder() { | ||
return ORDER; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...rc/main/java/io/micronaut/aws/alexa/locale/HandlerInputLocaleResolutionConfiguration.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,25 @@ | ||
/* | ||
* Copyright 2017-2022 original authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.micronaut.aws.alexa.locale; | ||
|
||
import io.micronaut.core.util.locale.LocaleResolutionConfiguration; | ||
|
||
/** | ||
* @author Sergio del Amo | ||
* @since 3.10.0 | ||
*/ | ||
public interface HandlerInputLocaleResolutionConfiguration extends LocaleResolutionConfiguration { | ||
} |
Oops, something went wrong.