Skip to content

Commit

Permalink
Merge branch 'main' into 4.0.x
Browse files Browse the repository at this point in the history
  • Loading branch information
sdelamo committed Nov 1, 2022
2 parents a4954d8 + b41e83c commit 3759b96
Show file tree
Hide file tree
Showing 108 changed files with 3,295 additions and 558 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/graalvm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
PREDICTIVE_TEST_SELECTION: "${{ github.event_name == 'pull_request' && 'true' || 'false' }}"
- name: Publish Test Report
if: always()
uses: mikepenz/action-junit-report@v3.3.3
uses: mikepenz/action-junit-report@v3.5.2
with:
check_name: GraalVM CE CI / Test Report (Java ${{ matrix.java }})
report_paths: '**/build/test-results/test/TEST-*.xml'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
PREDICTIVE_TEST_SELECTION: "${{ github.event_name == 'pull_request' && 'true' || 'false' }}"
- name: Publish Test Report
if: always()
uses: mikepenz/action-junit-report@v3.3.3
uses: mikepenz/action-junit-report@v3.5.2
with:
check_name: Java CI / Test Report (${{ matrix.java }})
report_paths: '**/build/test-results/test/TEST-*.xml'
Expand Down
24 changes: 0 additions & 24 deletions aws-alexa-httpserver/build.gradle

This file was deleted.

24 changes: 24 additions & 0 deletions aws-alexa-httpserver/build.gradle.kts
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)
}
23 changes: 0 additions & 23 deletions aws-alexa/build.gradle

This file was deleted.

23 changes: 23 additions & 0 deletions aws-alexa/build.gradle.kts
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)
}
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());
}
}
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));
}
}
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;
}
}
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;
}
}
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 {
}
Loading

0 comments on commit 3759b96

Please sign in to comment.