├── blibli-backend-framework-common ├── src │ ├── test │ │ └── resources │ │ │ └── application.properties │ └── main │ │ ├── java │ │ └── com │ │ │ └── blibli │ │ │ └── oss │ │ │ └── backend │ │ │ └── common │ │ │ ├── model │ │ │ ├── request │ │ │ │ ├── SortByDirection.java │ │ │ │ ├── SortBy.java │ │ │ │ └── PagingRequest.java │ │ │ └── response │ │ │ │ ├── Paging.java │ │ │ │ └── Response.java │ │ │ ├── annotation │ │ │ ├── MetaDatas.java │ │ │ └── MetaData.java │ │ │ ├── swagger │ │ │ ├── PagingRequestSwaggerIgnoredParameter.java │ │ │ └── annotation │ │ │ │ └── PagingRequestInQuery.java │ │ │ ├── CommonAutoConfiguration.java │ │ │ ├── helper │ │ │ ├── PagingHelper.java │ │ │ └── ResponseHelper.java │ │ │ ├── properties │ │ │ └── PagingProperties.java │ │ │ ├── CommonWebFluxAutoConfiguration.java │ │ │ └── CommonSwaggerAutoConfiguration.java │ │ └── resources │ │ ├── META-INF │ │ └── spring.factories │ │ └── backend-common.properties └── pom.xml ├── blibli-backend-framework-version ├── src │ ├── test │ │ ├── resources │ │ │ ├── application.properties │ │ │ └── version.properties │ │ └── java │ │ │ └── com │ │ │ └── blibli │ │ │ └── oss │ │ │ └── backend │ │ │ └── version │ │ │ └── VersionControllerTest.java │ └── main │ │ ├── resources │ │ └── META-INF │ │ │ └── spring.factories │ │ └── java │ │ └── com │ │ └── blibli │ │ └── oss │ │ └── backend │ │ └── version │ │ ├── properties │ │ └── VersionProperties.java │ │ ├── VersionAutoConfiguration.java │ │ └── controller │ │ └── VersionController.java └── README.md ├── blibli-backend-framework-api-client └── src │ ├── test │ ├── resources │ │ ├── upload.txt │ │ └── application.properties │ └── java │ │ └── com │ │ └── blibli │ │ └── oss │ │ └── backend │ │ └── apiclient │ │ ├── client │ │ ├── model │ │ │ ├── FirstRequest.java │ │ │ ├── FirstResponse.java │ │ │ ├── GenericResponse.java │ │ │ ├── SecondResponse.java │ │ │ └── InheritedResponse.java │ │ ├── HelloApiClientFallback.java │ │ ├── DynamicClient.java │ │ ├── HelloApiClient.java │ │ ├── ExampleInterceptor.java │ │ ├── ExceptionClientFallback.java │ │ ├── SleuthApiClient.java │ │ └── ExceptionClient.java │ │ ├── controller │ │ └── ApiClientExtraFields.java │ │ ├── HelloApiClientFallbackTest.java │ │ ├── ExceptionClientFallbackTest.java │ │ ├── DynamicClientTest.java │ │ ├── SleuthApiClientTest.java │ │ └── TestApplication.java │ └── main │ ├── java │ └── com │ │ └── blibli │ │ └── oss │ │ └── backend │ │ └── apiclient │ │ ├── customizer │ │ ├── ApiClientTcpClientCustomizer.java │ │ ├── ApiClientCodecCustomizer.java │ │ └── ApiClientWebClientCustomizer.java │ │ ├── annotation │ │ ├── ApiUrl.java │ │ └── ApiClient.java │ │ ├── interceptor │ │ ├── ApiClientInterceptor.java │ │ └── GlobalApiClientInterceptor.java │ │ ├── error │ │ ├── ApiErrorResolver.java │ │ └── DefaultApiErrorResolver.java │ │ ├── body │ │ ├── ApiBodyResolver.java │ │ ├── FormBodyResolver.java │ │ ├── JsonBodyResolver.java │ │ └── MultipartBodyResolver.java │ │ ├── aop │ │ ├── fallback │ │ │ ├── FallbackMetadata.java │ │ │ └── ApiClientFallback.java │ │ └── RequestMappingMetadata.java │ │ ├── sleuth │ │ ├── ApiClientSleuthConfiguration.java │ │ └── SleuthGlobalApiClientInterceptor.java │ │ ├── configuration │ │ └── ApiClientConfiguration.java │ │ └── properties │ │ └── PropertiesHelper.java │ └── resources │ └── META-INF │ └── spring.factories ├── blibli-backend-framework-command └── src │ ├── test │ └── resources │ │ ├── application.properties │ │ └── cache.properties │ └── main │ ├── resources │ └── META-INF │ │ └── spring.factories │ └── java │ └── com │ └── blibli │ └── oss │ └── backend │ └── command │ ├── executor │ └── CommandExecutor.java │ ├── exception │ ├── CommandRuntimeException.java │ └── CommandValidationException.java │ ├── cache │ └── CommandCacheable.java │ ├── Command.java │ ├── interceptor │ └── CommandInterceptor.java │ ├── properties │ └── CommandProperties.java │ ├── configuration │ ├── CommandAutoConfiguration.java │ └── CommandCacheAutoConfiguration.java │ └── controller │ └── CommandErrorController.java ├── blibli-backend-framework-aggregate-query ├── src │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── blibli │ │ │ │ └── oss │ │ │ │ └── backend │ │ │ │ └── aggregate │ │ │ │ └── query │ │ │ │ ├── package-info.java │ │ │ │ ├── constant │ │ │ │ └── AggregateQueryConstant.java │ │ │ │ ├── properties │ │ │ │ └── AggregateQueryProperties.java │ │ │ │ ├── model │ │ │ │ ├── AggregateQueryResponse.java │ │ │ │ ├── AggregateQueryHit.java │ │ │ │ └── AggregateQueryHits.java │ │ │ │ ├── configuration │ │ │ │ └── AggregateQueryAutoConfiguration.java │ │ │ │ ├── interceptor │ │ │ │ └── AggregateQueryApiClientInterceptor.java │ │ │ │ └── fallback │ │ │ │ └── AggregateQueryApiClientFallback.java │ │ └── resources │ │ │ └── META-INF │ │ │ └── spring.factories │ └── test │ │ ├── resources │ │ ├── application.properties │ │ ├── detail.json │ │ ├── search.json │ │ └── scroll.json │ │ └── java │ │ └── com │ │ └── blibli │ │ └── oss │ │ └── backend │ │ └── aggregate │ │ └── query │ │ └── example │ │ ├── ExampleApplication.java │ │ └── ExampleResponse.java └── README.md ├── blibli-backend-framework-swagger ├── src │ ├── test │ │ └── resources │ │ │ └── application.properties │ └── main │ │ ├── resources │ │ └── META-INF │ │ │ └── spring.factories │ │ └── java │ │ └── com │ │ └── blibli │ │ └── oss │ │ └── backend │ │ └── swagger │ │ ├── api │ │ ├── SwaggerIgnoredParameter.java │ │ ├── SwaggerIgnored.java │ │ └── SwaggerIgnoredParameterAnnotation.java │ │ ├── properties │ │ └── SwaggerProperties.java │ │ └── factory │ │ ├── ComponentsFactoryBean.java │ │ ├── OpenAPIFactoryBean.java │ │ └── IgnoredParameterAnnotationsFactoryBean.java └── pom.xml ├── blibli-backend-framework-json ├── src │ └── main │ │ ├── resources │ │ ├── META-INF │ │ │ └── spring.factories │ │ └── blibli-json.properties │ │ └── java │ │ └── com │ │ └── blibli │ │ └── oss │ │ └── backend │ │ └── json │ │ ├── aware │ │ └── JsonAware.java │ │ ├── helper │ │ └── JsonHelper.java │ │ ├── processor │ │ └── JsonAwareBeanPostProcessor.java │ │ └── JsonAutoConfiguration.java └── README.md ├── blibli-backend-framework-newrelic ├── src │ ├── test │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── com │ │ │ └── blibli │ │ │ └── oss │ │ │ └── backend │ │ │ └── newrelic │ │ │ └── reporter │ │ │ └── impl │ │ │ └── MongoExternalReporterImplTest.java │ └── main │ │ ├── java │ │ └── com │ │ │ └── blibli │ │ │ └── oss │ │ │ └── backend │ │ │ └── newrelic │ │ │ ├── aspect │ │ │ ├── service │ │ │ │ ├── util │ │ │ │ │ ├── RetValType.java │ │ │ │ │ ├── SegmentType.java │ │ │ │ │ ├── AspectHelper.java │ │ │ │ │ └── MongoUriParser.java │ │ │ │ └── AspectModifyService.java │ │ │ ├── CommandAspect.java │ │ │ └── ReactiveMongoDbAspect.java │ │ │ ├── reporter │ │ │ ├── ExternalReporter.java │ │ │ └── helper │ │ │ │ └── ExternalReporterHelper.java │ │ │ ├── configuration │ │ │ ├── reporter │ │ │ │ └── NewRelicMongoReporterAutoConfiguration.java │ │ │ └── NewRelicReactorInstrumentationAutoConfiguration.java │ │ │ └── injector │ │ │ └── NewRelicTokenInjectorFilter.java │ │ └── resources │ │ └── META-INF │ │ └── spring.factories ├── docs │ └── newrelic-sample.png └── README.md ├── blibli-backend-framework-sleuth ├── src │ ├── test │ │ └── resources │ │ │ └── application.properties │ └── main │ │ ├── resources │ │ └── META-INF │ │ │ └── spring.factories │ │ └── java │ │ └── com │ │ └── blibli │ │ └── oss │ │ └── backend │ │ └── sleuth │ │ ├── fields │ │ ├── SleuthExtraFields.java │ │ └── SleuthExtraFieldConfiguration.java │ │ └── webflux │ │ └── SleuthWebFilter.java └── pom.xml ├── blibli-backend-framework-kafka └── src │ ├── main │ ├── resources │ │ └── META-INF │ │ │ └── spring.factories │ └── java │ │ └── com │ │ └── blibli │ │ └── oss │ │ └── backend │ │ └── kafka │ │ ├── interceptor │ │ ├── KafkaProducerInterceptor.java │ │ ├── KafkaConsumerInterceptor.java │ │ └── log │ │ │ ├── LogKafkaProducerInterceptor.java │ │ │ └── LogKafkaConsumerInterceptor.java │ │ ├── repository │ │ ├── KafkaProducerAware.java │ │ ├── AbstractKafkaRepository.java │ │ ├── KafkaKeyAnnotationAware.java │ │ ├── KafkaTopicAnnotationAware.java │ │ ├── KafkaProducerAwareBeanProcessor.java │ │ └── KafkaRepository.java │ │ ├── annotation │ │ ├── KafkaKey.java │ │ └── KafkaTopic.java │ │ ├── model │ │ └── ProducerEvent.java │ │ └── properties │ │ └── KafkaProperties.java │ └── test │ ├── resources │ └── application.properties │ └── java │ └── com │ └── blibli │ └── oss │ └── backend │ └── kafka │ └── producer │ └── helper │ └── KafkaHelper.java ├── blibli-backend-framework-reactor ├── src │ ├── main │ │ ├── resources │ │ │ └── META-INF │ │ │ │ └── spring.factories │ │ └── java │ │ │ └── com │ │ │ └── blibli │ │ │ └── oss │ │ │ └── backend │ │ │ └── reactor │ │ │ ├── scheduler │ │ │ └── SchedulerHelper.java │ │ │ └── ReactorAutoConfiguration.java │ └── test │ │ └── java │ │ └── com │ │ └── blibli │ │ └── oss │ │ └── backend │ │ └── reactor │ │ └── scheduler │ │ └── SchedulerTest.java └── pom.xml ├── blibli-backend-framework-scheduler-platform └── src │ ├── main │ ├── resources │ │ └── META-INF │ │ │ └── spring.factories │ └── java │ │ └── com │ │ └── blibli │ │ └── oss │ │ └── backend │ │ └── scheduler │ │ └── platform │ │ ├── model │ │ ├── SchedulerPlatformModel.java │ │ ├── CancelDelayedJobRequest.java │ │ ├── CancelScheduledJobRequest.java │ │ ├── DelayedJobRequest.java │ │ └── ScheduledJobRequest.java │ │ ├── repository │ │ └── SchedulerPlatformRepository.java │ │ ├── constant │ │ └── SchedulerPlatformTopics.java │ │ └── configuration │ │ └── SchedulerPlatformConfiguration.java │ └── test │ ├── resources │ └── application.properties │ └── java │ └── com │ └── blibli │ └── oss │ └── backend │ └── scheduler │ └── platform │ └── helper │ └── KafkaHelper.java ├── .travis.yml ├── .travis ├── release.sh └── settings.xml ├── blibli-backend-framework-external-api ├── src │ └── main │ │ ├── resources │ │ └── META-INF │ │ │ └── spring.factories │ │ └── java │ │ └── com │ │ └── blibli │ │ └── oss │ │ └── backend │ │ └── externalapi │ │ ├── exception │ │ ├── ExternalApiException.java │ │ └── MustMemberException.java │ │ ├── sleuth │ │ ├── ExternalSessionSleuth.java │ │ ├── ExternalSessionExtraFields.java │ │ ├── ExternalSessionSleuthEventListener.java │ │ └── ExternalApiSleuthConfiguration.java │ │ ├── model │ │ └── ExternalSession.java │ │ ├── event │ │ └── ExternalSessionEvent.java │ │ ├── swagger │ │ ├── bean │ │ │ └── ExternalApiSwaggerIgnoredParameter.java │ │ ├── annotation │ │ │ └── ExternalSessionAtHeader.java │ │ └── ExternalApiSwaggerConfiguration.java │ │ ├── annotation │ │ └── MustMember.java │ │ ├── properties │ │ └── ExternalApiProperties.java │ │ ├── controller │ │ └── ExternalApiErrorController.java │ │ └── ExternalApiConfiguration.java └── pom.xml ├── blibli-backend-framework-internal-api ├── src │ └── main │ │ ├── resources │ │ └── META-INF │ │ │ └── spring.factories │ │ └── java │ │ └── com │ │ └── blibli │ │ └── oss │ │ └── backend │ │ └── internalapi │ │ ├── sleuth │ │ ├── InternalSessionSleuth.java │ │ ├── InternalSessionExtraFields.java │ │ ├── InternalSessionSleuthEventListener.java │ │ └── InternalApiSleuthConfiguration.java │ │ ├── model │ │ └── InternalSession.java │ │ ├── event │ │ └── InternalSessionEvent.java │ │ ├── swagger │ │ ├── bean │ │ │ └── InternalApiSwaggerIgnoredParameter.java │ │ └── annotation │ │ │ └── InternalSessionAtHeader.java │ │ ├── properties │ │ └── InternalApiProperties.java │ │ └── InternalApiConfiguration.java └── pom.xml ├── blibli-backend-framework-mandatory-parameter └── src │ ├── test │ ├── resources │ │ └── application.properties │ └── java │ │ └── com │ │ └── blibli │ │ └── oss │ │ └── backend │ │ └── mandatoryparameter │ │ ├── apiclient │ │ └── apiclient │ │ │ ├── FirstApiClient.java │ │ │ └── SecondApiClient.java │ │ └── helper │ │ └── MandatoryParameterHelperTest.java │ └── main │ ├── java │ └── com │ │ └── blibli │ │ └── oss │ │ └── backend │ │ └── mandatoryparameter │ │ ├── sleuth │ │ ├── MandatoryParameterSleuth.java │ │ ├── MandatoryParameterSleuthExtraFields.java │ │ └── MandatoryParameterSleuthAutoConfiguration.java │ │ ├── helper │ │ ├── SleuthHelper.java │ │ ├── ServerHelper.java │ │ └── MandatoryParameterHelper.java │ │ ├── MandatoryParameterAutoConfiguration.java │ │ ├── model │ │ └── MandatoryParameter.java │ │ ├── swagger │ │ ├── bean │ │ │ └── MandatoryParameterSwaggerIgnoredParameter.java │ │ └── annotation │ │ │ ├── MandatoryParameterAtQuery.java │ │ │ └── MandatoryParameterAtHeader.java │ │ ├── webflux │ │ └── MandatoryParameterWebFluxAutoConfiguration.java │ │ └── apiclient │ │ └── MandatoryParameterApiClientAutoConfiguration.java │ └── resources │ └── META-INF │ └── spring.factories ├── .editorconfig └── blibli-backend-framework-validation ├── src └── main │ └── java │ └── com │ └── blibli │ └── oss │ └── backend │ └── validation │ ├── ReactiveConstraintValidator.java │ └── AbstractReactiveConstraintValidator.java ├── README.md └── pom.xml /blibli-backend-framework-common/src/test/resources/application.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /blibli-backend-framework-version/src/test/resources/application.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /blibli-backend-framework-api-client/src/test/resources/upload.txt: -------------------------------------------------------------------------------- 1 | Eko Kurniawan Khanendy -------------------------------------------------------------------------------- /blibli-backend-framework-command/src/test/resources/application.properties: -------------------------------------------------------------------------------- 1 | blibli.backend.command.cache.timeout=5s -------------------------------------------------------------------------------- /blibli-backend-framework-command/src/test/resources/cache.properties: -------------------------------------------------------------------------------- 1 | blibli.backend.command.cache.enabled=true -------------------------------------------------------------------------------- /blibli-backend-framework-aggregate-query/src/main/java/com/blibli/oss/backend/aggregate/query/package-info.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.aggregate.query; -------------------------------------------------------------------------------- /blibli-backend-framework-swagger/src/test/resources/application.properties: -------------------------------------------------------------------------------- 1 | blibli.backend.swagger.title=Eko Kurniawan 2 | blibli.backend.swagger.version=1.0.0 -------------------------------------------------------------------------------- /blibli-backend-framework-json/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.blibli.oss.backend.json.JsonAutoConfiguration -------------------------------------------------------------------------------- /blibli-backend-framework-newrelic/src/test/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.autoconfigure.exclude=\ 2 | org.springframework.boot.autoconfigure.mongo.MongoReactiveAutoConfiguration -------------------------------------------------------------------------------- /blibli-backend-framework-newrelic/docs/newrelic-sample.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bliblidotcom/blibli-backend-framework/HEAD/blibli-backend-framework-newrelic/docs/newrelic-sample.png -------------------------------------------------------------------------------- /blibli-backend-framework-sleuth/src/test/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.sleuth.baggage-keys[0]=Eko 2 | spring.sleuth.baggage-keys[1]=Kurniawan 3 | spring.sleuth.baggage-keys[2]=Khannedy -------------------------------------------------------------------------------- /blibli-backend-framework-kafka/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ 2 | com.blibli.oss.backend.kafka.KafkaAutoConfiguration -------------------------------------------------------------------------------- /blibli-backend-framework-swagger/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.blibli.oss.backend.swagger.SwaggerAutoConfiguration -------------------------------------------------------------------------------- /blibli-backend-framework-version/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.blibli.oss.backend.version.VersionAutoConfiguration -------------------------------------------------------------------------------- /blibli-backend-framework-reactor/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ 2 | com.blibli.oss.backend.reactor.ReactorAutoConfiguration -------------------------------------------------------------------------------- /blibli-backend-framework-sleuth/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ 2 | com.blibli.oss.backend.sleuth.configuration.SleuthConfiguration -------------------------------------------------------------------------------- /blibli-backend-framework-common/src/main/java/com/blibli/oss/backend/common/model/request/SortByDirection.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.common.model.request; 2 | 3 | public enum SortByDirection { 4 | ASC, 5 | DESC 6 | } 7 | -------------------------------------------------------------------------------- /blibli-backend-framework-aggregate-query/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ 2 | com.blibli.oss.backend.aggregate.query.configuration.AggregateQueryAutoConfiguration -------------------------------------------------------------------------------- /blibli-backend-framework-newrelic/src/test/java/com/blibli/oss/backend/newrelic/reporter/impl/MongoExternalReporterImplTest.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.newrelic.reporter.impl; 2 | 3 | public class MongoExternalReporterImplTest { 4 | } 5 | -------------------------------------------------------------------------------- /blibli-backend-framework-scheduler-platform/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ 2 | com.blibli.oss.backend.scheduler.platform.configuration.SchedulerPlatformConfiguration -------------------------------------------------------------------------------- /blibli-backend-framework-newrelic/src/main/java/com/blibli/oss/backend/newrelic/aspect/service/util/RetValType.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.newrelic.aspect.service.util; 2 | 3 | public enum RetValType { 4 | MONO, FLUX, MONO_OR_FLUX; 5 | } 6 | -------------------------------------------------------------------------------- /blibli-backend-framework-scheduler-platform/src/main/java/com/blibli/oss/backend/scheduler/platform/model/SchedulerPlatformModel.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.scheduler.platform.model; 2 | 3 | public interface SchedulerPlatformModel { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /blibli-backend-framework-sleuth/src/main/java/com/blibli/oss/backend/sleuth/fields/SleuthExtraFields.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.sleuth.fields; 2 | 3 | import java.util.List; 4 | 5 | public interface SleuthExtraFields { 6 | 7 | List getFields(); 8 | } 9 | -------------------------------------------------------------------------------- /blibli-backend-framework-version/src/test/resources/version.properties: -------------------------------------------------------------------------------- 1 | blibli.backend.version.group-id=@project.groupId@ 2 | blibli.backend.version.artifact-id=@project.artifactId@ 3 | blibli.backend.version.version=@project.version@ 4 | blibli.backend.version.build-time=@maven.build.timestamp@ -------------------------------------------------------------------------------- /blibli-backend-framework-aggregate-query/src/main/java/com/blibli/oss/backend/aggregate/query/constant/AggregateQueryConstant.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.aggregate.query.constant; 2 | 3 | public interface AggregateQueryConstant { 4 | 5 | String SERVICE_ID_HEADER = "X-Service-Id"; 6 | } 7 | -------------------------------------------------------------------------------- /blibli-backend-framework-command/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ 2 | com.blibli.oss.backend.command.configuration.CommandAutoConfiguration,\ 3 | com.blibli.oss.backend.command.configuration.CommandCacheAutoConfiguration -------------------------------------------------------------------------------- /blibli-backend-framework-aggregate-query/src/test/resources/application.properties: -------------------------------------------------------------------------------- 1 | blibli.backend.apiclient.packages=com.blibli.oss.backend.aggregate.query.apiclient 2 | blibli.backend.apiclient.configs.aggregateQueryApiClient.url=http://localhost:8089 3 | blibli.backend.aggregate.query.service-id=ServiceID -------------------------------------------------------------------------------- /blibli-backend-framework-reactor/src/main/java/com/blibli/oss/backend/reactor/scheduler/SchedulerHelper.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.reactor.scheduler; 2 | 3 | import reactor.core.scheduler.Scheduler; 4 | 5 | public interface SchedulerHelper { 6 | 7 | Scheduler of(String name); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | 3 | jdk: 4 | - openjdk8 5 | 6 | script: 7 | - mvn clean test 8 | 9 | cache: 10 | directories: 11 | - $HOME/.m2 12 | 13 | deploy: 14 | provider: script 15 | script: .travis/release.sh 16 | skip_cleanup: true 17 | on: 18 | tags: true 19 | jdk: openjdk8 -------------------------------------------------------------------------------- /.travis/release.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | 5 | echo "Ensuring that pom matches $TRAVIS_TAG" 6 | mvn org.codehaus.mojo:versions-maven-plugin:2.7:set -DnewVersion=$TRAVIS_TAG 7 | 8 | echo "Uploading" 9 | mvn deploy --settings .travis/settings.xml -DskipTests=true --batch-mode --update-snapshots -Prelease -------------------------------------------------------------------------------- /blibli-backend-framework-swagger/src/main/java/com/blibli/oss/backend/swagger/api/SwaggerIgnoredParameter.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.swagger.api; 2 | 3 | import java.lang.reflect.Parameter; 4 | 5 | public interface SwaggerIgnoredParameter { 6 | 7 | boolean isIgnored(Parameter parameter); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /blibli-backend-framework-common/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ 2 | com.blibli.oss.backend.common.CommonAutoConfiguration,\ 3 | com.blibli.oss.backend.common.CommonWebFluxAutoConfiguration,\ 4 | com.blibli.oss.backend.common.CommonSwaggerAutoConfiguration -------------------------------------------------------------------------------- /blibli-backend-framework-aggregate-query/src/test/java/com/blibli/oss/backend/aggregate/query/example/ExampleApplication.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.aggregate.query.example; 2 | 3 | import org.springframework.boot.autoconfigure.SpringBootApplication; 4 | 5 | @SpringBootApplication 6 | public class ExampleApplication { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /blibli-backend-framework-aggregate-query/src/test/resources/detail.json: -------------------------------------------------------------------------------- 1 | { 2 | "_index": "customers", 3 | "_type": "_doc", 4 | "_id": "1", 5 | "_version": 1, 6 | "found": true, 7 | "_source": { 8 | "id": 1, 9 | "first_name": "Eko", 10 | "middle_name": "Kurniawan", 11 | "last_name": "Khannedy" 12 | } 13 | } -------------------------------------------------------------------------------- /blibli-backend-framework-api-client/src/main/java/com/blibli/oss/backend/apiclient/customizer/ApiClientTcpClientCustomizer.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.apiclient.customizer; 2 | 3 | import reactor.netty.tcp.TcpClient; 4 | 5 | public interface ApiClientTcpClientCustomizer { 6 | 7 | TcpClient customize(TcpClient tcpClient); 8 | } 9 | -------------------------------------------------------------------------------- /blibli-backend-framework-newrelic/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ 2 | com.blibli.oss.backend.newrelic.configuration.NewRelicReactorInstrumentationAutoConfiguration,\ 3 | com.blibli.oss.backend.newrelic.configuration.reporter.NewRelicMongoReporterAutoConfiguration -------------------------------------------------------------------------------- /blibli-backend-framework-api-client/src/main/java/com/blibli/oss/backend/apiclient/annotation/ApiUrl.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.apiclient.annotation; 2 | 3 | import java.lang.annotation.*; 4 | 5 | @Target({ElementType.PARAMETER}) 6 | @Retention(RetentionPolicy.RUNTIME) 7 | @Documented 8 | public @interface ApiUrl { 9 | 10 | } 11 | -------------------------------------------------------------------------------- /blibli-backend-framework-api-client/src/main/java/com/blibli/oss/backend/apiclient/interceptor/ApiClientInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.apiclient.interceptor; 2 | 3 | import org.springframework.web.reactive.function.client.ExchangeFilterFunction; 4 | 5 | public interface ApiClientInterceptor extends ExchangeFilterFunction { 6 | 7 | } 8 | -------------------------------------------------------------------------------- /blibli-backend-framework-api-client/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ 2 | com.blibli.oss.backend.apiclient.configuration.ApiClientConfiguration,\ 3 | com.blibli.oss.backend.apiclient.configuration.ApiClientRegistrar,\ 4 | com.blibli.oss.backend.apiclient.sleuth.ApiClientSleuthConfiguration -------------------------------------------------------------------------------- /blibli-backend-framework-api-client/src/main/java/com/blibli/oss/backend/apiclient/interceptor/GlobalApiClientInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.apiclient.interceptor; 2 | 3 | import org.springframework.web.reactive.function.client.ExchangeFilterFunction; 4 | 5 | public interface GlobalApiClientInterceptor extends ExchangeFilterFunction { 6 | 7 | } 8 | -------------------------------------------------------------------------------- /blibli-backend-framework-external-api/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ 2 | com.blibli.oss.backend.externalapi.ExternalApiConfiguration,\ 3 | com.blibli.oss.backend.externalapi.swagger.ExternalApiSwaggerConfiguration,\ 4 | com.blibli.oss.backend.externalapi.sleuth.ExternalApiSleuthConfiguration -------------------------------------------------------------------------------- /blibli-backend-framework-internal-api/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ 2 | com.blibli.oss.backend.internalapi.InternalApiConfiguration,\ 3 | com.blibli.oss.backend.internalapi.swagger.InternalApiSwaggerConfiguration,\ 4 | com.blibli.oss.backend.internalapi.sleuth.InternalApiSleuthConfiguration -------------------------------------------------------------------------------- /blibli-backend-framework-json/src/main/java/com/blibli/oss/backend/json/aware/JsonAware.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.json.aware; 2 | 3 | import com.blibli.oss.backend.json.helper.JsonHelper; 4 | import org.springframework.beans.factory.Aware; 5 | 6 | public interface JsonAware extends Aware { 7 | 8 | void setJsonHelper(JsonHelper jsonHelper); 9 | 10 | } 11 | -------------------------------------------------------------------------------- /blibli-backend-framework-api-client/src/main/java/com/blibli/oss/backend/apiclient/customizer/ApiClientCodecCustomizer.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.apiclient.customizer; 2 | 3 | import org.springframework.http.codec.ClientCodecConfigurer; 4 | 5 | public interface ApiClientCodecCustomizer { 6 | 7 | void customize(ClientCodecConfigurer configurer); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /blibli-backend-framework-common/src/main/java/com/blibli/oss/backend/common/annotation/MetaDatas.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.common.annotation; 2 | 3 | import java.lang.annotation.*; 4 | 5 | @Documented 6 | @Retention(RetentionPolicy.RUNTIME) 7 | @Target(ElementType.FIELD) 8 | public @interface MetaDatas { 9 | 10 | MetaData[] value() default {}; 11 | 12 | } 13 | -------------------------------------------------------------------------------- /blibli-backend-framework-api-client/src/main/java/com/blibli/oss/backend/apiclient/customizer/ApiClientWebClientCustomizer.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.apiclient.customizer; 2 | 3 | import org.springframework.web.reactive.function.client.WebClient; 4 | 5 | public interface ApiClientWebClientCustomizer { 6 | 7 | void customize(WebClient.Builder builder); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /blibli-backend-framework-common/src/main/java/com/blibli/oss/backend/common/annotation/MetaData.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.common.annotation; 2 | 3 | import java.lang.annotation.*; 4 | 5 | @Documented 6 | @Retention(RetentionPolicy.RUNTIME) 7 | @Target(ElementType.FIELD) 8 | public @interface MetaData { 9 | 10 | String key(); 11 | 12 | String value(); 13 | } 14 | -------------------------------------------------------------------------------- /blibli-backend-framework-kafka/src/test/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.kafka.bootstrap-servers=${spring.embedded.kafka.brokers} 2 | spring.kafka.consumer.group-id=test 3 | blibli.backend.kafka.logging.before-send=true 4 | blibli.backend.kafka.logging.before-consume=true 5 | blibli.backend.kafka.logging.after-success-consume=true 6 | blibli.backend.kafka.logging.after-failed-consume=true -------------------------------------------------------------------------------- /blibli-backend-framework-external-api/src/main/java/com/blibli/oss/backend/externalapi/exception/ExternalApiException.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.externalapi.exception; 2 | 3 | public class ExternalApiException extends RuntimeException { 4 | 5 | public ExternalApiException() { 6 | } 7 | 8 | public ExternalApiException(String message) { 9 | super(message); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /blibli-backend-framework-external-api/src/main/java/com/blibli/oss/backend/externalapi/exception/MustMemberException.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.externalapi.exception; 2 | 3 | public class MustMemberException extends ExternalApiException { 4 | 5 | public MustMemberException() { 6 | } 7 | 8 | public MustMemberException(String message) { 9 | super(message); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /blibli-backend-framework-kafka/src/main/java/com/blibli/oss/backend/kafka/interceptor/KafkaProducerInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.kafka.interceptor; 2 | 3 | import com.blibli.oss.backend.kafka.model.ProducerEvent; 4 | 5 | public interface KafkaProducerInterceptor { 6 | 7 | default ProducerEvent beforeSend(ProducerEvent event) { 8 | return event; 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /blibli-backend-framework-command/src/main/java/com/blibli/oss/backend/command/executor/CommandExecutor.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.command.executor; 2 | 3 | import com.blibli.oss.backend.command.Command; 4 | import reactor.core.publisher.Mono; 5 | 6 | public interface CommandExecutor { 7 | 8 | Mono execute(Class> commandClass, R request); 9 | 10 | } 11 | -------------------------------------------------------------------------------- /blibli-backend-framework-internal-api/src/main/java/com/blibli/oss/backend/internalapi/sleuth/InternalSessionSleuth.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.internalapi.sleuth; 2 | 3 | public interface InternalSessionSleuth { 4 | 5 | String USER_ID = "Blibli-Internal-User-Id"; 6 | 7 | String USER_NAME = "Blibli-Internal-User-Name"; 8 | 9 | String ROLES = "Blibli-Internal-Roles"; 10 | 11 | } 12 | -------------------------------------------------------------------------------- /blibli-backend-framework-scheduler-platform/src/test/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.kafka.bootstrap-servers=${spring.embedded.kafka.brokers} 2 | spring.kafka.consumer.group-id=test 3 | blibli.backend.kafka.logging.before-send=true 4 | blibli.backend.kafka.logging.before-consume=true 5 | blibli.backend.kafka.logging.after-success-consume=true 6 | blibli.backend.kafka.logging.after-failed-consume=true -------------------------------------------------------------------------------- /blibli-backend-framework-api-client/src/main/java/com/blibli/oss/backend/apiclient/error/ApiErrorResolver.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.apiclient.error; 2 | 3 | import reactor.core.publisher.Mono; 4 | 5 | import java.lang.reflect.Method; 6 | 7 | public interface ApiErrorResolver { 8 | 9 | Mono resolve(Throwable throwable, Class type, Method method, Object[] arguments); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /blibli-backend-framework-kafka/src/main/java/com/blibli/oss/backend/kafka/repository/KafkaProducerAware.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.kafka.repository; 2 | 3 | import com.blibli.oss.backend.kafka.producer.KafkaProducer; 4 | import org.springframework.beans.factory.Aware; 5 | 6 | public interface KafkaProducerAware extends Aware { 7 | 8 | void setKafkaProducer(KafkaProducer kafkaProducer); 9 | 10 | } 11 | -------------------------------------------------------------------------------- /blibli-backend-framework-kafka/src/main/java/com/blibli/oss/backend/kafka/annotation/KafkaKey.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.kafka.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.FIELD) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface KafkaKey { 11 | } 12 | -------------------------------------------------------------------------------- /blibli-backend-framework-api-client/src/test/java/com/blibli/oss/backend/apiclient/client/model/FirstRequest.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.apiclient.client.model; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | @Data 9 | @Builder 10 | @AllArgsConstructor 11 | @NoArgsConstructor 12 | public class FirstRequest { 13 | 14 | private String name; 15 | } 16 | -------------------------------------------------------------------------------- /blibli-backend-framework-api-client/src/test/java/com/blibli/oss/backend/apiclient/client/model/FirstResponse.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.apiclient.client.model; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | @Data 9 | @Builder 10 | @AllArgsConstructor 11 | @NoArgsConstructor 12 | public class FirstResponse { 13 | 14 | private String hello; 15 | } 16 | -------------------------------------------------------------------------------- /blibli-backend-framework-api-client/src/test/java/com/blibli/oss/backend/apiclient/client/model/GenericResponse.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.apiclient.client.model; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | @Data 9 | @Builder 10 | @NoArgsConstructor 11 | @AllArgsConstructor 12 | public class GenericResponse { 13 | 14 | private T value; 15 | } 16 | -------------------------------------------------------------------------------- /blibli-backend-framework-api-client/src/test/java/com/blibli/oss/backend/apiclient/client/model/SecondResponse.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.apiclient.client.model; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | @Data 9 | @Builder 10 | @AllArgsConstructor 11 | @NoArgsConstructor 12 | public class SecondResponse { 13 | 14 | private String hello; 15 | 16 | } 17 | -------------------------------------------------------------------------------- /blibli-backend-framework-swagger/src/main/java/com/blibli/oss/backend/swagger/api/SwaggerIgnored.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.swagger.api; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.PARAMETER) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface SwaggerIgnored { 11 | 12 | } 13 | -------------------------------------------------------------------------------- /blibli-backend-framework-api-client/src/test/java/com/blibli/oss/backend/apiclient/client/HelloApiClientFallback.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.apiclient.client; 2 | 3 | import org.springframework.stereotype.Component; 4 | import reactor.core.publisher.Mono; 5 | 6 | @Component 7 | public class HelloApiClientFallback implements HelloApiClient { 8 | 9 | @Override 10 | public Mono hello() { 11 | return Mono.just("Fallback"); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /blibli-backend-framework-newrelic/src/main/java/com/blibli/oss/backend/newrelic/reporter/ExternalReporter.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.newrelic.reporter; 2 | 3 | import com.blibli.oss.backend.newrelic.aspect.service.util.SegmentType; 4 | import com.newrelic.api.agent.Segment; 5 | import org.aspectj.lang.JoinPoint; 6 | 7 | public interface ExternalReporter { 8 | 9 | SegmentType getSegmentType(); 10 | 11 | void report(Segment segment, JoinPoint jp); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /blibli-backend-framework-kafka/src/main/java/com/blibli/oss/backend/kafka/annotation/KafkaTopic.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.kafka.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.TYPE) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface KafkaTopic { 11 | 12 | String value(); 13 | 14 | } 15 | -------------------------------------------------------------------------------- /blibli-backend-framework-kafka/src/main/java/com/blibli/oss/backend/kafka/repository/AbstractKafkaRepository.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.kafka.repository; 2 | 3 | import com.blibli.oss.backend.kafka.producer.KafkaProducer; 4 | import lombok.Getter; 5 | import lombok.Setter; 6 | 7 | public abstract class AbstractKafkaRepository implements KafkaRepository, KafkaProducerAware { 8 | 9 | @Setter 10 | @Getter 11 | private KafkaProducer kafkaProducer; 12 | 13 | } 14 | -------------------------------------------------------------------------------- /blibli-backend-framework-command/src/main/java/com/blibli/oss/backend/command/exception/CommandRuntimeException.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.command.exception; 2 | 3 | public class CommandRuntimeException extends RuntimeException { 4 | 5 | public CommandRuntimeException() { 6 | } 7 | 8 | public CommandRuntimeException(Throwable cause) { 9 | super(cause); 10 | } 11 | 12 | public CommandRuntimeException(String message) { 13 | super(message); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /blibli-backend-framework-external-api/src/main/java/com/blibli/oss/backend/externalapi/sleuth/ExternalSessionSleuth.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.externalapi.sleuth; 2 | 3 | public interface ExternalSessionSleuth { 4 | 5 | String USER_ID = "ExternalSession-UserId"; 6 | 7 | String SESSION_ID = "ExternalSession-SessionId"; 8 | 9 | String IS_MEMBER = "ExternalSession-IsMember"; 10 | 11 | String ADDITIONAL_PARAMETERS = "ExternalSession-AdditionalParameter"; 12 | 13 | } 14 | -------------------------------------------------------------------------------- /blibli-backend-framework-mandatory-parameter/src/test/resources/application.properties: -------------------------------------------------------------------------------- 1 | blibli.backend.apiclient.packages=com.blibli.oss.backend.mandatoryparameter.apiclient.apiclient 2 | blibli.backend.apiclient.configs.firstApiClient.url=http://localhost:15234 3 | blibli.backend.apiclient.configs.firstApiClient.interceptors[0]=com.blibli.oss.backend.mandatoryparameter.apiclient.MandatoryParameterApiClientInterceptor 4 | blibli.backend.apiclient.configs.secondApiClient.url=http://localhost:15234 -------------------------------------------------------------------------------- /blibli-backend-framework-swagger/src/main/java/com/blibli/oss/backend/swagger/api/SwaggerIgnoredParameterAnnotation.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.swagger.api; 2 | 3 | import java.lang.reflect.Parameter; 4 | import java.util.Objects; 5 | 6 | public class SwaggerIgnoredParameterAnnotation implements SwaggerIgnoredParameter { 7 | 8 | @Override 9 | public boolean isIgnored(Parameter parameter) { 10 | return Objects.nonNull(parameter.getAnnotation(SwaggerIgnored.class)); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /blibli-backend-framework-newrelic/src/main/java/com/blibli/oss/backend/newrelic/aspect/service/AspectModifyService.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.newrelic.aspect.service; 2 | 3 | import com.blibli.oss.backend.newrelic.aspect.service.util.SegmentType; 4 | import org.aspectj.lang.ProceedingJoinPoint; 5 | 6 | public interface AspectModifyService { 7 | 8 | Object modifyRetValWithTiming( 9 | ProceedingJoinPoint proceedingJoinPoint, SegmentType segmentType 10 | ) throws Throwable; 11 | 12 | } 13 | -------------------------------------------------------------------------------- /blibli-backend-framework-internal-api/src/main/java/com/blibli/oss/backend/internalapi/model/InternalSession.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.internalapi.model; 2 | 3 | import lombok.*; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | @Data 9 | @Builder 10 | @AllArgsConstructor 11 | @NoArgsConstructor 12 | public class InternalSession { 13 | 14 | private String userId; 15 | 16 | private String userName; 17 | 18 | @Singular 19 | private List roles = new ArrayList<>(); 20 | 21 | } 22 | -------------------------------------------------------------------------------- /blibli-backend-framework-api-client/src/main/java/com/blibli/oss/backend/apiclient/body/ApiBodyResolver.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.apiclient.body; 2 | 3 | import org.springframework.http.client.reactive.ClientHttpRequest; 4 | import org.springframework.web.reactive.function.BodyInserter; 5 | 6 | import java.lang.reflect.Method; 7 | 8 | public interface ApiBodyResolver { 9 | 10 | boolean canResolve(String contentType); 11 | 12 | BodyInserter resolve(Method method, Object[] arguments); 13 | 14 | } 15 | -------------------------------------------------------------------------------- /blibli-backend-framework-mandatory-parameter/src/main/java/com/blibli/oss/backend/mandatoryparameter/sleuth/MandatoryParameterSleuth.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.mandatoryparameter.sleuth; 2 | 3 | public interface MandatoryParameterSleuth { 4 | 5 | String STORE_ID = "MandatoryParam-StoreId"; 6 | 7 | String CLIENT_ID = "MandatoryParam-ClientId"; 8 | 9 | String CHANNEL_ID = "MandatoryParam-ChannelId"; 10 | 11 | String USERNAME = "MandatoryParam-Username"; 12 | 13 | String REQUEST_ID = "MandatoryParam-RequestId"; 14 | 15 | } 16 | -------------------------------------------------------------------------------- /blibli-backend-framework-api-client/src/test/java/com/blibli/oss/backend/apiclient/client/model/InheritedResponse.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.apiclient.client.model; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | @Data 9 | @Builder(builderMethodName = "inheritedBuilder") 10 | @AllArgsConstructor 11 | @NoArgsConstructor 12 | public class InheritedResponse extends FirstResponse { 13 | 14 | private String name; 15 | 16 | private String detail; 17 | } 18 | -------------------------------------------------------------------------------- /blibli-backend-framework-command/src/main/java/com/blibli/oss/backend/command/cache/CommandCacheable.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.command.cache; 2 | 3 | import java.util.Collection; 4 | 5 | public interface CommandCacheable { 6 | 7 | default String cacheKey(R request) { 8 | return null; 9 | } 10 | 11 | default Collection evictKeys(R request) { 12 | return null; 13 | } 14 | 15 | default Class responseClass() { 16 | throw new UnsupportedOperationException("No response class available."); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /blibli-backend-framework-newrelic/src/main/java/com/blibli/oss/backend/newrelic/aspect/service/util/SegmentType.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.newrelic.aspect.service.util; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | 6 | @AllArgsConstructor 7 | public enum SegmentType { 8 | COMMAND("Command %s.%s", RetValType.MONO), 9 | REACTIVE_MONGODB("ReactiveMongoRepository %s.%s", RetValType.MONO_OR_FLUX); 10 | 11 | @Getter 12 | private String stringFormat; 13 | 14 | @Getter 15 | private RetValType returnValueType; 16 | } 17 | -------------------------------------------------------------------------------- /blibli-backend-framework-command/src/main/java/com/blibli/oss/backend/command/Command.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.command; 2 | 3 | import com.blibli.oss.backend.command.cache.CommandCacheable; 4 | import reactor.core.publisher.Mono; 5 | 6 | public interface Command extends CommandCacheable { 7 | 8 | Mono execute(R request); 9 | 10 | default Mono fallback(Throwable throwable, R request) { 11 | return Mono.error(throwable); 12 | } 13 | 14 | default boolean validateRequest() { 15 | return true; 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /blibli-backend-framework-api-client/src/test/java/com/blibli/oss/backend/apiclient/controller/ApiClientExtraFields.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.apiclient.controller; 2 | 3 | import com.blibli.oss.backend.sleuth.fields.SleuthExtraFields; 4 | import org.springframework.stereotype.Component; 5 | 6 | import java.util.Collections; 7 | import java.util.List; 8 | 9 | @Component 10 | public class ApiClientExtraFields implements SleuthExtraFields { 11 | 12 | @Override 13 | public List getFields() { 14 | return Collections.singletonList("LastName"); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /blibli-backend-framework-external-api/src/main/java/com/blibli/oss/backend/externalapi/model/ExternalSession.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.externalapi.model; 2 | 3 | import lombok.*; 4 | 5 | import java.util.HashMap; 6 | import java.util.Map; 7 | 8 | @Data 9 | @Builder 10 | @AllArgsConstructor 11 | @NoArgsConstructor 12 | public class ExternalSession { 13 | 14 | private String userId; 15 | 16 | private String sessionId; 17 | 18 | private boolean member; 19 | 20 | @Singular 21 | private Map additionalParameters = new HashMap<>(); 22 | 23 | } 24 | -------------------------------------------------------------------------------- /blibli-backend-framework-api-client/src/main/java/com/blibli/oss/backend/apiclient/error/DefaultApiErrorResolver.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.apiclient.error; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import reactor.core.publisher.Mono; 5 | 6 | import java.lang.reflect.Method; 7 | 8 | @Slf4j 9 | public class DefaultApiErrorResolver implements ApiErrorResolver { 10 | 11 | @Override 12 | public Mono resolve(Throwable throwable, Class type, Method method, Object[] arguments) { 13 | log.error(throwable.getMessage(), throwable); 14 | return Mono.empty(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /blibli-backend-framework-api-client/src/main/java/com/blibli/oss/backend/apiclient/aop/fallback/FallbackMetadata.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.apiclient.aop.fallback; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | import java.lang.reflect.Method; 9 | import java.util.Map; 10 | 11 | @Data 12 | @Builder 13 | @AllArgsConstructor 14 | @NoArgsConstructor 15 | public class FallbackMetadata { 16 | 17 | private Map methods; 18 | 19 | private Map exceptionMethods; 20 | 21 | } 22 | -------------------------------------------------------------------------------- /blibli-backend-framework-mandatory-parameter/src/main/java/com/blibli/oss/backend/mandatoryparameter/helper/SleuthHelper.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.mandatoryparameter.helper; 2 | 3 | import brave.propagation.ExtraFieldPropagation; 4 | import brave.propagation.TraceContext; 5 | import org.springframework.util.StringUtils; 6 | 7 | public class SleuthHelper { 8 | 9 | public static void putExtraField(TraceContext traceContext, String name, String value) { 10 | if (!StringUtils.isEmpty(value)) { 11 | ExtraFieldPropagation.set(traceContext, name, value); 12 | } 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /blibli-backend-framework-common/src/main/java/com/blibli/oss/backend/common/model/request/SortBy.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.common.model.request; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Builder; 6 | import lombok.Data; 7 | import lombok.NoArgsConstructor; 8 | 9 | @Data 10 | @NoArgsConstructor 11 | @AllArgsConstructor 12 | @Builder 13 | public class SortBy { 14 | 15 | @JsonProperty("property_name") 16 | private String propertyName; 17 | 18 | @JsonProperty("direction") 19 | private SortByDirection direction; 20 | } 21 | -------------------------------------------------------------------------------- /blibli-backend-framework-scheduler-platform/src/main/java/com/blibli/oss/backend/scheduler/platform/repository/SchedulerPlatformRepository.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.scheduler.platform.repository; 2 | 3 | import com.blibli.oss.backend.kafka.repository.AbstractKafkaRepository; 4 | import com.blibli.oss.backend.kafka.repository.KafkaRepository; 5 | import com.blibli.oss.backend.scheduler.platform.model.SchedulerPlatformModel; 6 | 7 | public class SchedulerPlatformRepository 8 | extends AbstractKafkaRepository 9 | implements KafkaRepository { 10 | 11 | } 12 | -------------------------------------------------------------------------------- /blibli-backend-framework-common/src/main/java/com/blibli/oss/backend/common/swagger/PagingRequestSwaggerIgnoredParameter.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.common.swagger; 2 | 3 | import com.blibli.oss.backend.common.model.request.PagingRequest; 4 | import com.blibli.oss.backend.swagger.api.SwaggerIgnoredParameter; 5 | 6 | import java.lang.reflect.Parameter; 7 | 8 | public class PagingRequestSwaggerIgnoredParameter implements SwaggerIgnoredParameter { 9 | 10 | @Override 11 | public boolean isIgnored(Parameter parameter) { 12 | return PagingRequest.class.isAssignableFrom(parameter.getType()); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /blibli-backend-framework-json/src/main/resources/blibli-json.properties: -------------------------------------------------------------------------------- 1 | spring.jackson.deserialization.fail-on-unknown-properties=false 2 | spring.jackson.deserialization.fail-on-ignored-properties=false 3 | spring.jackson.deserialization.read-unknown-enum-values-as-null=true 4 | spring.jackson.serialization.fail-on-empty-beans=false 5 | spring.jackson.serialization.write-dates-as-timestamps=true 6 | spring.jackson.serialization.write-empty-json-arrays=true 7 | spring.jackson.default-property-inclusion=non_null 8 | spring.jackson.generator.ignore-unknown=true 9 | spring.jackson.mapper.accept-case-insensitive-enums=true 10 | -------------------------------------------------------------------------------- /blibli-backend-framework-mandatory-parameter/src/main/java/com/blibli/oss/backend/mandatoryparameter/MandatoryParameterAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.mandatoryparameter; 2 | 3 | import com.blibli.oss.backend.mandatoryparameter.swagger.properties.MandatoryParameterProperties; 4 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | @Configuration 8 | @EnableConfigurationProperties({ 9 | MandatoryParameterProperties.class 10 | }) 11 | public class MandatoryParameterAutoConfiguration { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /blibli-backend-framework-mandatory-parameter/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ 2 | com.blibli.oss.backend.mandatoryparameter.MandatoryParameterAutoConfiguration,\ 3 | com.blibli.oss.backend.mandatoryparameter.swagger.MandatoryParameterSwaggerAutoConfiguration,\ 4 | com.blibli.oss.backend.mandatoryparameter.webflux.MandatoryParameterWebFluxAutoConfiguration,\ 5 | com.blibli.oss.backend.mandatoryparameter.sleuth.MandatoryParameterSleuthAutoConfiguration,\ 6 | com.blibli.oss.backend.mandatoryparameter.apiclient.MandatoryParameterApiClientAutoConfiguration -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | end_of_line = lf 6 | indent_size = 2 7 | indent_style = space 8 | insert_final_newline = false 9 | max_line_length = 120 10 | tab_width = 2 11 | 12 | [*.java] 13 | indent_size = 2 14 | tab_width = 2 15 | 16 | [{*.jhm, *.xjb, *.rng, *.wsdl, *.wsdd, *.fxml, *.pom, *.xslt, *.jrxml, *.ant, *.xul, *.xsl, *.xsd, *.tld, *.jnlp, *.wadl, *.xml}] 17 | indent_size = 2 18 | tab_width = 2 19 | 20 | [{*.zsh, *.bash, *.sh}] 21 | indent_size = 2 22 | tab_width = 2 23 | 24 | [{.babelrc, .eslintrc, jest.config, bowerrc, .stylelintrc, *.jsb3, *.jsb2, *.json}] 25 | indent_size = 2 26 | -------------------------------------------------------------------------------- /blibli-backend-framework-mandatory-parameter/src/main/java/com/blibli/oss/backend/mandatoryparameter/model/MandatoryParameter.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.mandatoryparameter.model; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | @Data 9 | @Builder 10 | @AllArgsConstructor 11 | @NoArgsConstructor 12 | public class MandatoryParameter { 13 | 14 | private String storeId; 15 | 16 | private String clientId; 17 | 18 | private String channelId; 19 | 20 | private String username; 21 | 22 | private String requestId; 23 | } 24 | -------------------------------------------------------------------------------- /blibli-backend-framework-external-api/src/main/java/com/blibli/oss/backend/externalapi/event/ExternalSessionEvent.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.externalapi.event; 2 | 3 | import com.blibli.oss.backend.externalapi.model.ExternalSession; 4 | import lombok.Getter; 5 | import org.springframework.context.ApplicationEvent; 6 | 7 | public class ExternalSessionEvent extends ApplicationEvent { 8 | 9 | @Getter 10 | private ExternalSession externalSession; 11 | 12 | public ExternalSessionEvent(ExternalSession externalSession) { 13 | super(externalSession); 14 | this.externalSession = externalSession; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /blibli-backend-framework-internal-api/src/main/java/com/blibli/oss/backend/internalapi/event/InternalSessionEvent.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.internalapi.event; 2 | 3 | import com.blibli.oss.backend.internalapi.model.InternalSession; 4 | import lombok.Getter; 5 | import org.springframework.context.ApplicationEvent; 6 | 7 | public class InternalSessionEvent extends ApplicationEvent { 8 | 9 | @Getter 10 | private InternalSession internalSession; 11 | 12 | public InternalSessionEvent(InternalSession internalSession) { 13 | super(internalSession); 14 | this.internalSession = internalSession; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /blibli-backend-framework-internal-api/src/main/java/com/blibli/oss/backend/internalapi/sleuth/InternalSessionExtraFields.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.internalapi.sleuth; 2 | 3 | import com.blibli.oss.backend.sleuth.fields.SleuthExtraFields; 4 | 5 | import java.util.Arrays; 6 | import java.util.List; 7 | 8 | public class InternalSessionExtraFields implements SleuthExtraFields { 9 | 10 | @Override 11 | public List getFields() { 12 | return Arrays.asList( 13 | InternalSessionSleuth.USER_ID, 14 | InternalSessionSleuth.USER_NAME, 15 | InternalSessionSleuth.ROLES 16 | ); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /blibli-backend-framework-scheduler-platform/src/main/java/com/blibli/oss/backend/scheduler/platform/constant/SchedulerPlatformTopics.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.scheduler.platform.constant; 2 | 3 | public interface SchedulerPlatformTopics { 4 | 5 | String PREFIX = "scheduled_platform_"; 6 | 7 | String SAVE_DELAYED_JOB_EVENT = PREFIX + "save_delayed_job_event"; 8 | 9 | String CANCEL_DELAYED_JOB_EVENT = PREFIX + "cancel_delayed_job_event"; 10 | 11 | String SAVE_SCHEDULED_JOB_EVENT = PREFIX + "save_scheduled_job_event"; 12 | 13 | String CANCEL_SCHEDULED_JOB_EVENT = PREFIX + "cancel_scheduled_job_event"; 14 | } 15 | -------------------------------------------------------------------------------- /blibli-backend-framework-aggregate-query/src/main/java/com/blibli/oss/backend/aggregate/query/properties/AggregateQueryProperties.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.aggregate.query.properties; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | import org.springframework.boot.context.properties.ConfigurationProperties; 8 | 9 | @Data 10 | @Builder 11 | @AllArgsConstructor 12 | @NoArgsConstructor 13 | @ConfigurationProperties("blibli.backend.aggregate.query") 14 | public class AggregateQueryProperties { 15 | 16 | private String serviceId; 17 | 18 | } 19 | -------------------------------------------------------------------------------- /blibli-backend-framework-kafka/src/main/java/com/blibli/oss/backend/kafka/repository/KafkaKeyAnnotationAware.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.kafka.repository; 2 | 3 | import lombok.SneakyThrows; 4 | 5 | import java.util.Objects; 6 | 7 | public interface KafkaKeyAnnotationAware { 8 | 9 | @SneakyThrows 10 | default String getKey(T data) { 11 | String key = KafkaHelper.getKafkaKey(data); 12 | if (Objects.isNull(key)) { 13 | throw new NullPointerException(String.format("No annotation @KafkaKey on class %s", data.getClass().getName())); 14 | } else { 15 | return key; 16 | } 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /blibli-backend-framework-external-api/src/main/java/com/blibli/oss/backend/externalapi/swagger/bean/ExternalApiSwaggerIgnoredParameter.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.externalapi.swagger.bean; 2 | 3 | import com.blibli.oss.backend.externalapi.model.ExternalSession; 4 | import com.blibli.oss.backend.swagger.api.SwaggerIgnoredParameter; 5 | 6 | import java.lang.reflect.Parameter; 7 | 8 | public class ExternalApiSwaggerIgnoredParameter implements SwaggerIgnoredParameter { 9 | 10 | @Override 11 | public boolean isIgnored(Parameter parameter) { 12 | return parameter.getType().isAssignableFrom(ExternalSession.class); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /blibli-backend-framework-internal-api/src/main/java/com/blibli/oss/backend/internalapi/swagger/bean/InternalApiSwaggerIgnoredParameter.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.internalapi.swagger.bean; 2 | 3 | import com.blibli.oss.backend.internalapi.model.InternalSession; 4 | import com.blibli.oss.backend.swagger.api.SwaggerIgnoredParameter; 5 | 6 | import java.lang.reflect.Parameter; 7 | 8 | public class InternalApiSwaggerIgnoredParameter implements SwaggerIgnoredParameter { 9 | 10 | @Override 11 | public boolean isIgnored(Parameter parameter) { 12 | return parameter.getType().isAssignableFrom(InternalSession.class); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /blibli-backend-framework-kafka/src/main/java/com/blibli/oss/backend/kafka/repository/KafkaTopicAnnotationAware.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.kafka.repository; 2 | 3 | import lombok.SneakyThrows; 4 | 5 | import java.util.Objects; 6 | 7 | public interface KafkaTopicAnnotationAware { 8 | 9 | @SneakyThrows 10 | default String getTopic(T data) { 11 | String topic = KafkaHelper.getTopic(data.getClass()); 12 | if (Objects.isNull(topic)) { 13 | throw new NullPointerException(String.format("No annotation @KafkaTopic on class %s", data.getClass().getName())); 14 | } else { 15 | return topic; 16 | } 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /blibli-backend-framework-kafka/src/main/java/com/blibli/oss/backend/kafka/model/ProducerEvent.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.kafka.model; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | import org.apache.kafka.common.header.Headers; 8 | 9 | @Data 10 | @Builder 11 | @AllArgsConstructor 12 | @NoArgsConstructor 13 | public class ProducerEvent { 14 | 15 | private String topic; 16 | 17 | private Integer partition; 18 | 19 | private Headers headers; 20 | 21 | private String key; 22 | 23 | private Object value; 24 | 25 | private Long timestamp; 26 | 27 | } 28 | -------------------------------------------------------------------------------- /blibli-backend-framework-common/src/main/resources/backend-common.properties: -------------------------------------------------------------------------------- 1 | # Jackson Configuration 2 | spring.jackson.default-property-inclusion=non_null 3 | spring.jackson.generator.ignore-unknown=true 4 | spring.jackson.serialization.fail-on-empty-beans=false 5 | spring.jackson.serialization.write-dates-as-timestamps=true 6 | spring.jackson.serialization.write-date-keys-as-timestamps=true 7 | spring.jackson.serialization.write-char-arrays-as-json-arrays=true 8 | spring.jackson.deserialization.read-unknown-enum-values-as-null=true 9 | spring.jackson.deserialization.fail-on-ignored-properties=false 10 | spring.jackson.deserialization.fail-on-unknown-properties=false 11 | -------------------------------------------------------------------------------- /blibli-backend-framework-external-api/src/main/java/com/blibli/oss/backend/externalapi/sleuth/ExternalSessionExtraFields.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.externalapi.sleuth; 2 | 3 | import com.blibli.oss.backend.sleuth.fields.SleuthExtraFields; 4 | 5 | import java.util.Arrays; 6 | import java.util.List; 7 | 8 | public class ExternalSessionExtraFields implements SleuthExtraFields { 9 | 10 | @Override 11 | public List getFields() { 12 | return Arrays.asList( 13 | ExternalSessionSleuth.USER_ID, 14 | ExternalSessionSleuth.SESSION_ID, 15 | ExternalSessionSleuth.IS_MEMBER, 16 | ExternalSessionSleuth.ADDITIONAL_PARAMETERS 17 | ); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /blibli-backend-framework-mandatory-parameter/src/main/java/com/blibli/oss/backend/mandatoryparameter/swagger/bean/MandatoryParameterSwaggerIgnoredParameter.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.mandatoryparameter.swagger.bean; 2 | 3 | import com.blibli.oss.backend.mandatoryparameter.model.MandatoryParameter; 4 | import com.blibli.oss.backend.swagger.api.SwaggerIgnoredParameter; 5 | 6 | import java.lang.reflect.Parameter; 7 | 8 | public class MandatoryParameterSwaggerIgnoredParameter implements SwaggerIgnoredParameter { 9 | 10 | @Override 11 | public boolean isIgnored(Parameter parameter) { 12 | return MandatoryParameter.class.isAssignableFrom(parameter.getType()); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /blibli-backend-framework-common/src/main/java/com/blibli/oss/backend/common/CommonAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.common; 2 | 3 | import com.blibli.oss.backend.common.properties.PagingProperties; 4 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.context.annotation.PropertySource; 7 | 8 | @Configuration 9 | @EnableConfigurationProperties({ 10 | PagingProperties.class 11 | }) 12 | @PropertySource( 13 | ignoreResourceNotFound = true, 14 | value = "classpath:backend-common.properties" 15 | ) 16 | public class CommonAutoConfiguration { 17 | 18 | } 19 | -------------------------------------------------------------------------------- /blibli-backend-framework-validation/src/main/java/com/blibli/oss/backend/validation/ReactiveConstraintValidator.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.validation; 2 | 3 | import reactor.core.publisher.Mono; 4 | 5 | import javax.validation.ConstraintValidator; 6 | import javax.validation.ConstraintValidatorContext; 7 | import java.lang.annotation.Annotation; 8 | 9 | public interface ReactiveConstraintValidator extends ConstraintValidator { 10 | 11 | default boolean isValid(T value, ConstraintValidatorContext context) { 12 | return validate(value, context).block(); 13 | } 14 | 15 | Mono validate(T value, ConstraintValidatorContext context); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /blibli-backend-framework-version/src/main/java/com/blibli/oss/backend/version/properties/VersionProperties.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.version.properties; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | import org.springframework.boot.context.properties.ConfigurationProperties; 8 | 9 | @Data 10 | @AllArgsConstructor 11 | @NoArgsConstructor 12 | @Builder 13 | @ConfigurationProperties("blibli.backend.version") 14 | public class VersionProperties { 15 | 16 | private String groupId; 17 | 18 | private String artifactId; 19 | 20 | private String version; 21 | 22 | private String buildTime; 23 | 24 | } 25 | -------------------------------------------------------------------------------- /blibli-backend-framework-command/src/main/java/com/blibli/oss/backend/command/interceptor/CommandInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.command.interceptor; 2 | 3 | import com.blibli.oss.backend.command.Command; 4 | import reactor.core.publisher.Mono; 5 | 6 | public interface CommandInterceptor { 7 | 8 | default Mono before(Command command, R request) { 9 | return Mono.empty(); 10 | } 11 | 12 | default Mono afterSuccess(Command command, R request, T response) { 13 | return Mono.empty(); 14 | } 15 | 16 | default Mono afterFailed(Command command, R request, Throwable throwable) { 17 | return Mono.empty(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /blibli-backend-framework-common/src/main/java/com/blibli/oss/backend/common/model/request/PagingRequest.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.common.model.request; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Builder; 6 | import lombok.Data; 7 | import lombok.NoArgsConstructor; 8 | 9 | import java.util.List; 10 | 11 | @Data 12 | @Builder 13 | @AllArgsConstructor 14 | @NoArgsConstructor 15 | public class PagingRequest { 16 | 17 | @JsonProperty("page") 18 | private Long page; 19 | 20 | @JsonProperty("item_per_page") 21 | private Long itemPerPage; 22 | 23 | @JsonProperty("sort_by") 24 | private List sortBy; 25 | } 26 | -------------------------------------------------------------------------------- /blibli-backend-framework-swagger/src/main/java/com/blibli/oss/backend/swagger/properties/SwaggerProperties.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.swagger.properties; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | import org.springframework.boot.context.properties.ConfigurationProperties; 8 | 9 | @Data 10 | @Builder 11 | @AllArgsConstructor 12 | @NoArgsConstructor 13 | @ConfigurationProperties("blibli.backend.swagger") 14 | public class SwaggerProperties { 15 | 16 | private String title; 17 | 18 | private String description; 19 | 20 | private String termsOfService; 21 | 22 | private String version; 23 | 24 | } 25 | -------------------------------------------------------------------------------- /blibli-backend-framework-aggregate-query/src/test/java/com/blibli/oss/backend/aggregate/query/example/ExampleResponse.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.aggregate.query.example; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Builder; 6 | import lombok.Data; 7 | import lombok.NoArgsConstructor; 8 | 9 | @Data 10 | @Builder 11 | @AllArgsConstructor 12 | @NoArgsConstructor 13 | public class ExampleResponse { 14 | 15 | private Integer id; 16 | 17 | @JsonProperty("first_name") 18 | private String firstName; 19 | 20 | @JsonProperty("middle_name") 21 | private String middleName; 22 | 23 | @JsonProperty("last_name") 24 | private String lastName; 25 | } 26 | -------------------------------------------------------------------------------- /blibli-backend-framework-external-api/src/main/java/com/blibli/oss/backend/externalapi/annotation/MustMember.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.externalapi.annotation; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.Target; 6 | 7 | import static java.lang.annotation.ElementType.*; 8 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 9 | 10 | @Documented 11 | @Target({PARAMETER, METHOD, TYPE}) 12 | @Retention(RUNTIME) 13 | public @interface MustMember { 14 | 15 | /** 16 | * If true, ExternalSession must a member, if false, ExternalSession must not a member 17 | * 18 | * @return boolean 19 | */ 20 | boolean value() default true; 21 | 22 | } 23 | -------------------------------------------------------------------------------- /blibli-backend-framework-mandatory-parameter/src/main/java/com/blibli/oss/backend/mandatoryparameter/sleuth/MandatoryParameterSleuthExtraFields.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.mandatoryparameter.sleuth; 2 | 3 | import com.blibli.oss.backend.sleuth.fields.SleuthExtraFields; 4 | 5 | import java.util.Arrays; 6 | import java.util.List; 7 | 8 | public class MandatoryParameterSleuthExtraFields implements SleuthExtraFields { 9 | 10 | @Override 11 | public List getFields() { 12 | return Arrays.asList( 13 | MandatoryParameterSleuth.CHANNEL_ID, 14 | MandatoryParameterSleuth.CLIENT_ID, 15 | MandatoryParameterSleuth.REQUEST_ID, 16 | MandatoryParameterSleuth.STORE_ID, 17 | MandatoryParameterSleuth.USERNAME 18 | ); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /blibli-backend-framework-kafka/src/main/java/com/blibli/oss/backend/kafka/interceptor/KafkaConsumerInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.kafka.interceptor; 2 | 3 | import org.apache.kafka.clients.consumer.ConsumerRecord; 4 | 5 | import java.lang.reflect.Method; 6 | 7 | public interface KafkaConsumerInterceptor { 8 | 9 | default boolean isSupport(Object bean, Method method) { 10 | return true; 11 | } 12 | 13 | default boolean beforeConsume(ConsumerRecord consumerRecord) { 14 | return false; 15 | } 16 | 17 | default void afterSuccessConsume(ConsumerRecord consumerRecord) { 18 | 19 | } 20 | 21 | default void afterFailedConsume(ConsumerRecord consumerRecord, Throwable throwable) { 22 | 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /blibli-backend-framework-api-client/src/test/java/com/blibli/oss/backend/apiclient/HelloApiClientFallbackTest.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.apiclient; 2 | 3 | import com.blibli.oss.backend.apiclient.client.HelloApiClient; 4 | import org.junit.jupiter.api.Test; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.test.context.SpringBootTest; 7 | 8 | import static org.junit.jupiter.api.Assertions.*; 9 | 10 | @SpringBootTest(classes = TestApplication.class) 11 | public class HelloApiClientFallbackTest { 12 | 13 | @Autowired 14 | private HelloApiClient helloApiClient; 15 | 16 | @Test 17 | void testResponseEntityVoid() { 18 | String response = helloApiClient.hello().block(); 19 | assertEquals("Fallback", response); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /blibli-backend-framework-api-client/src/test/java/com/blibli/oss/backend/apiclient/client/DynamicClient.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.apiclient.client; 2 | 3 | import com.blibli.oss.backend.apiclient.annotation.ApiClient; 4 | import com.blibli.oss.backend.apiclient.annotation.ApiUrl; 5 | import org.springframework.http.MediaType; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RequestMethod; 8 | import reactor.core.publisher.Mono; 9 | 10 | @ApiClient( 11 | name = "dynamicClient" 12 | ) 13 | public interface DynamicClient { 14 | 15 | @RequestMapping( 16 | method = RequestMethod.GET, 17 | value = "/dynamic", 18 | produces = MediaType.TEXT_PLAIN_VALUE 19 | ) 20 | Mono dynamic(@ApiUrl String baseUrl); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /blibli-backend-framework-mandatory-parameter/src/test/java/com/blibli/oss/backend/mandatoryparameter/apiclient/apiclient/FirstApiClient.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.mandatoryparameter.apiclient.apiclient; 2 | 3 | import com.blibli.oss.backend.apiclient.annotation.ApiClient; 4 | import org.springframework.http.MediaType; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | import org.springframework.web.bind.annotation.RequestMethod; 7 | import reactor.core.publisher.Mono; 8 | 9 | import java.util.Map; 10 | 11 | @ApiClient( 12 | name = "firstApiClient" 13 | ) 14 | public interface FirstApiClient { 15 | 16 | @RequestMapping( 17 | value = "/first", 18 | method = RequestMethod.GET, 19 | produces = MediaType.APPLICATION_JSON_VALUE 20 | ) 21 | Mono> first(); 22 | } 23 | -------------------------------------------------------------------------------- /blibli-backend-framework-version/src/main/java/com/blibli/oss/backend/version/VersionAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.version; 2 | 3 | import com.blibli.oss.backend.version.properties.VersionProperties; 4 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 5 | import org.springframework.context.annotation.ComponentScan; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.context.annotation.PropertySource; 8 | 9 | @Configuration 10 | @EnableConfigurationProperties({ 11 | VersionProperties.class 12 | }) 13 | @PropertySource( 14 | ignoreResourceNotFound = true, 15 | value = "classpath:version.properties" 16 | ) 17 | @ComponentScan("com.blibli.oss.backend.version.controller") 18 | public class VersionAutoConfiguration { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /blibli-backend-framework-api-client/src/test/java/com/blibli/oss/backend/apiclient/client/HelloApiClient.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.apiclient.client; 2 | 3 | import com.blibli.oss.backend.apiclient.TestApplication; 4 | import com.blibli.oss.backend.apiclient.annotation.ApiClient; 5 | import org.springframework.http.MediaType; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RequestMethod; 8 | import reactor.core.publisher.Mono; 9 | 10 | @ApiClient( 11 | name = "helloApiClient", 12 | tcpClientCustomizers = TestApplication.WireTrapTcpClientCustomizer.class 13 | ) 14 | public interface HelloApiClient { 15 | 16 | @RequestMapping(value = "/hello", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE) 17 | Mono hello(); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /blibli-backend-framework-command/src/main/java/com/blibli/oss/backend/command/properties/CommandProperties.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.command.properties; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | import org.springframework.boot.context.properties.ConfigurationProperties; 8 | 9 | import java.time.Duration; 10 | 11 | @Data 12 | @Builder 13 | @AllArgsConstructor 14 | @NoArgsConstructor 15 | @ConfigurationProperties("blibli.backend.command") 16 | public class CommandProperties { 17 | 18 | private CacheProperties cache = new CacheProperties(); 19 | 20 | @Data 21 | public static class CacheProperties { 22 | 23 | private boolean enabled = false; 24 | 25 | private Duration timeout = Duration.ofSeconds(10); 26 | 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /blibli-backend-framework-scheduler-platform/src/main/java/com/blibli/oss/backend/scheduler/platform/configuration/SchedulerPlatformConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.scheduler.platform.configuration; 2 | 3 | import com.blibli.oss.backend.kafka.producer.KafkaProducer; 4 | import com.blibli.oss.backend.scheduler.platform.repository.SchedulerPlatformRepository; 5 | import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | 9 | @Configuration 10 | @ConditionalOnBean(KafkaProducer.class) 11 | public class SchedulerPlatformConfiguration { 12 | 13 | @Bean 14 | public SchedulerPlatformRepository schedulerPlatformRepository() { 15 | return new SchedulerPlatformRepository(); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /blibli-backend-framework-swagger/src/main/java/com/blibli/oss/backend/swagger/factory/ComponentsFactoryBean.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.swagger.factory; 2 | 3 | import io.swagger.v3.oas.models.Components; 4 | import io.swagger.v3.oas.models.parameters.Parameter; 5 | import lombok.Setter; 6 | import org.springframework.beans.factory.FactoryBean; 7 | 8 | import java.util.Map; 9 | 10 | public class ComponentsFactoryBean implements FactoryBean { 11 | 12 | @Setter 13 | private Map parameters; 14 | 15 | @Override 16 | public Components getObject() throws Exception { 17 | Components components = new Components(); 18 | components.setParameters(parameters); 19 | return components; 20 | } 21 | 22 | @Override 23 | public Class getObjectType() { 24 | return Components.class; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /blibli-backend-framework-scheduler-platform/src/main/java/com/blibli/oss/backend/scheduler/platform/model/CancelDelayedJobRequest.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.scheduler.platform.model; 2 | 3 | import com.blibli.oss.backend.kafka.annotation.KafkaKey; 4 | import com.blibli.oss.backend.kafka.annotation.KafkaTopic; 5 | import com.blibli.oss.backend.scheduler.platform.constant.SchedulerPlatformTopics; 6 | import lombok.AllArgsConstructor; 7 | import lombok.Builder; 8 | import lombok.Data; 9 | import lombok.NoArgsConstructor; 10 | 11 | @Data 12 | @Builder 13 | @AllArgsConstructor 14 | @NoArgsConstructor 15 | @KafkaTopic(SchedulerPlatformTopics.CANCEL_DELAYED_JOB_EVENT) 16 | public class CancelDelayedJobRequest implements SchedulerPlatformModel { 17 | 18 | @KafkaKey 19 | private String id; 20 | 21 | private String name; 22 | 23 | private String group; 24 | } 25 | -------------------------------------------------------------------------------- /blibli-backend-framework-common/src/main/java/com/blibli/oss/backend/common/swagger/annotation/PagingRequestInQuery.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.common.swagger.annotation; 2 | 3 | import io.swagger.v3.oas.annotations.Parameter; 4 | import io.swagger.v3.oas.annotations.Parameters; 5 | 6 | import java.lang.annotation.ElementType; 7 | import java.lang.annotation.Retention; 8 | import java.lang.annotation.RetentionPolicy; 9 | import java.lang.annotation.Target; 10 | 11 | @Parameters({ 12 | @Parameter(name = "page", ref = "queryPagingRequestPage"), 13 | @Parameter(name = "itemPerPage", ref = "queryPagingRequestItemPerPage"), 14 | @Parameter(name = "sortBy", ref = "queryPagingRequestSortBy") 15 | }) 16 | @Target({ 17 | ElementType.TYPE, 18 | ElementType.METHOD 19 | }) 20 | @Retention(RetentionPolicy.RUNTIME) 21 | public @interface PagingRequestInQuery { 22 | } 23 | -------------------------------------------------------------------------------- /blibli-backend-framework-scheduler-platform/src/main/java/com/blibli/oss/backend/scheduler/platform/model/CancelScheduledJobRequest.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.scheduler.platform.model; 2 | 3 | import com.blibli.oss.backend.kafka.annotation.KafkaKey; 4 | import com.blibli.oss.backend.kafka.annotation.KafkaTopic; 5 | import com.blibli.oss.backend.scheduler.platform.constant.SchedulerPlatformTopics; 6 | import lombok.AllArgsConstructor; 7 | import lombok.Builder; 8 | import lombok.Data; 9 | import lombok.NoArgsConstructor; 10 | 11 | @Data 12 | @Builder 13 | @AllArgsConstructor 14 | @NoArgsConstructor 15 | @KafkaTopic(SchedulerPlatformTopics.CANCEL_SCHEDULED_JOB_EVENT) 16 | public class CancelScheduledJobRequest implements SchedulerPlatformModel { 17 | 18 | @KafkaKey 19 | private String id; 20 | 21 | private String name; 22 | 23 | private String group; 24 | } 25 | -------------------------------------------------------------------------------- /blibli-backend-framework-external-api/src/main/java/com/blibli/oss/backend/externalapi/sleuth/ExternalSessionSleuthEventListener.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.externalapi.sleuth; 2 | 3 | import brave.Tracer; 4 | import com.blibli.oss.backend.externalapi.event.ExternalSessionEvent; 5 | import com.blibli.oss.backend.externalapi.helper.ExternalSessionHelper; 6 | import lombok.AllArgsConstructor; 7 | import lombok.extern.slf4j.Slf4j; 8 | import org.springframework.context.ApplicationListener; 9 | 10 | @Slf4j 11 | @AllArgsConstructor 12 | public class ExternalSessionSleuthEventListener implements ApplicationListener { 13 | 14 | private Tracer tracer; 15 | 16 | @Override 17 | public void onApplicationEvent(ExternalSessionEvent event) { 18 | ExternalSessionHelper.toSleuth(tracer.currentSpan().context(), event.getExternalSession()); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /blibli-backend-framework-internal-api/src/main/java/com/blibli/oss/backend/internalapi/sleuth/InternalSessionSleuthEventListener.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.internalapi.sleuth; 2 | 3 | import brave.Tracer; 4 | import com.blibli.oss.backend.internalapi.event.InternalSessionEvent; 5 | import com.blibli.oss.backend.internalapi.helper.InternalSessionHelper; 6 | import lombok.AllArgsConstructor; 7 | import lombok.extern.slf4j.Slf4j; 8 | import org.springframework.context.ApplicationListener; 9 | 10 | @Slf4j 11 | @AllArgsConstructor 12 | public class InternalSessionSleuthEventListener implements ApplicationListener { 13 | 14 | private Tracer tracer; 15 | 16 | @Override 17 | public void onApplicationEvent(InternalSessionEvent event) { 18 | InternalSessionHelper.toSleuth(tracer.currentSpan().context(), event.getInternalSession()); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /blibli-backend-framework-command/src/main/java/com/blibli/oss/backend/command/exception/CommandValidationException.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.command.exception; 2 | 3 | import lombok.Getter; 4 | 5 | import javax.validation.ConstraintViolation; 6 | import java.util.Set; 7 | 8 | /** 9 | * @deprecated not used anymore 10 | * @see javax.validation.ConstraintViolationException 11 | */ 12 | @Deprecated 13 | public class CommandValidationException extends CommandRuntimeException { 14 | 15 | @Getter 16 | private Set> constraintViolations; 17 | 18 | public CommandValidationException(Set constraintViolations) { 19 | this(null, constraintViolations); 20 | } 21 | 22 | public CommandValidationException(String message, Set constraintViolations) { 23 | super(message); 24 | this.constraintViolations = constraintViolations; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /blibli-backend-framework-internal-api/src/main/java/com/blibli/oss/backend/internalapi/swagger/annotation/InternalSessionAtHeader.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.internalapi.swagger.annotation; 2 | 3 | import io.swagger.v3.oas.annotations.Parameter; 4 | import io.swagger.v3.oas.annotations.Parameters; 5 | 6 | import java.lang.annotation.ElementType; 7 | import java.lang.annotation.Retention; 8 | import java.lang.annotation.RetentionPolicy; 9 | import java.lang.annotation.Target; 10 | 11 | @Parameters({ 12 | @Parameter(name = "userId", ref = "internalApiHeaderUserId"), 13 | @Parameter(name = "sessionId", ref = "internalApiHeaderUserName"), 14 | @Parameter(name = "member", ref = "internalApiHeaderRoles") 15 | }) 16 | @Target({ 17 | ElementType.METHOD, 18 | ElementType.TYPE 19 | }) 20 | @Retention(RetentionPolicy.RUNTIME) 21 | public @interface InternalSessionAtHeader { 22 | 23 | } 24 | -------------------------------------------------------------------------------- /blibli-backend-framework-external-api/src/main/java/com/blibli/oss/backend/externalapi/swagger/annotation/ExternalSessionAtHeader.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.externalapi.swagger.annotation; 2 | 3 | import io.swagger.v3.oas.annotations.Parameter; 4 | import io.swagger.v3.oas.annotations.Parameters; 5 | 6 | import java.lang.annotation.ElementType; 7 | import java.lang.annotation.Retention; 8 | import java.lang.annotation.RetentionPolicy; 9 | import java.lang.annotation.Target; 10 | 11 | @Parameters({ 12 | @Parameter(name = "userId", ref = "externalApiHeaderUserId"), 13 | @Parameter(name = "sessionId", ref = "externalApiHeaderSessionId"), 14 | @Parameter(name = "member", ref = "externalApiHeaderMember") 15 | }) 16 | @Target({ 17 | ElementType.METHOD, 18 | ElementType.TYPE 19 | }) 20 | @Retention(RetentionPolicy.RUNTIME) 21 | public @interface ExternalSessionAtHeader { 22 | 23 | } 24 | -------------------------------------------------------------------------------- /blibli-backend-framework-common/src/main/java/com/blibli/oss/backend/common/model/response/Paging.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.common.model.response; 2 | 3 | import com.blibli.oss.backend.common.model.request.SortBy; 4 | import com.fasterxml.jackson.annotation.JsonProperty; 5 | import lombok.AllArgsConstructor; 6 | import lombok.Builder; 7 | import lombok.Data; 8 | import lombok.NoArgsConstructor; 9 | 10 | import java.util.List; 11 | 12 | @Data 13 | @AllArgsConstructor 14 | @NoArgsConstructor 15 | @Builder 16 | public class Paging { 17 | 18 | @JsonProperty("page") 19 | private Long page; 20 | 21 | @JsonProperty("total_page") 22 | private Long totalPage; 23 | 24 | @JsonProperty("item_per_page") 25 | private Long itemPerPage; 26 | 27 | @JsonProperty("total_item") 28 | private Long totalItem; 29 | 30 | @JsonProperty("sort_by") 31 | private List sortBy; 32 | 33 | } 34 | -------------------------------------------------------------------------------- /blibli-backend-framework-validation/src/main/java/com/blibli/oss/backend/validation/AbstractReactiveConstraintValidator.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.validation; 2 | 3 | import reactor.core.publisher.Mono; 4 | 5 | import javax.validation.ConstraintValidatorContext; 6 | import java.lang.annotation.Annotation; 7 | 8 | public abstract class AbstractReactiveConstraintValidator implements ReactiveConstraintValidator { 9 | 10 | private A annotation; 11 | 12 | @Override 13 | public void initialize(A constraintAnnotation) { 14 | this.annotation = constraintAnnotation; 15 | } 16 | 17 | @Override 18 | public Mono validate(T value, ConstraintValidatorContext context) { 19 | return validate(value, annotation, context); 20 | } 21 | 22 | public abstract Mono validate(T value, A annotation, ConstraintValidatorContext context); 23 | } 24 | -------------------------------------------------------------------------------- /blibli-backend-framework-kafka/src/main/java/com/blibli/oss/backend/kafka/repository/KafkaProducerAwareBeanProcessor.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.kafka.repository; 2 | 3 | import com.blibli.oss.backend.kafka.producer.KafkaProducer; 4 | import lombok.AllArgsConstructor; 5 | import org.springframework.beans.BeansException; 6 | import org.springframework.beans.factory.config.BeanPostProcessor; 7 | 8 | @AllArgsConstructor 9 | public class KafkaProducerAwareBeanProcessor implements BeanPostProcessor { 10 | 11 | private KafkaProducer kafkaProducer; 12 | 13 | @Override 14 | public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { 15 | if (bean instanceof KafkaProducerAware) { 16 | KafkaProducerAware kafkaProducerAware = (KafkaProducerAware) bean; 17 | kafkaProducerAware.setKafkaProducer(kafkaProducer); 18 | } 19 | 20 | return bean; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /blibli-backend-framework-newrelic/src/main/java/com/blibli/oss/backend/newrelic/reporter/helper/ExternalReporterHelper.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.newrelic.reporter.helper; 2 | 3 | import com.blibli.oss.backend.newrelic.aspect.service.util.SegmentType; 4 | import com.blibli.oss.backend.newrelic.reporter.ExternalReporter; 5 | import org.springframework.context.ApplicationContext; 6 | 7 | import java.util.List; 8 | import java.util.Map; 9 | import java.util.stream.Collectors; 10 | 11 | public class ExternalReporterHelper { 12 | 13 | public static Map> getExternalReporters(ApplicationContext applicationContext) { 14 | Map beans = applicationContext.getBeansOfType(ExternalReporter.class); 15 | return beans.values() 16 | .stream() 17 | .collect( 18 | Collectors.groupingBy(ExternalReporter::getSegmentType) 19 | ); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /blibli-backend-framework-json/src/main/java/com/blibli/oss/backend/json/helper/JsonHelper.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.json.helper; 2 | 3 | import com.fasterxml.jackson.core.type.TypeReference; 4 | import com.fasterxml.jackson.databind.ObjectMapper; 5 | import lombok.SneakyThrows; 6 | 7 | public class JsonHelper { 8 | 9 | private ObjectMapper objectMapper; 10 | 11 | public JsonHelper(ObjectMapper objectMapper) { 12 | this.objectMapper = objectMapper; 13 | } 14 | 15 | @SneakyThrows 16 | public T fromJson(String json, Class tClass) { 17 | return objectMapper.readValue(json, tClass); 18 | } 19 | 20 | @SneakyThrows 21 | public T fromJson(String json, TypeReference tTypeReference) { 22 | return objectMapper.readValue(json, tTypeReference); 23 | } 24 | 25 | @SneakyThrows 26 | public String toJson(T object) { 27 | return objectMapper.writeValueAsString(object); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /blibli-backend-framework-json/src/main/java/com/blibli/oss/backend/json/processor/JsonAwareBeanPostProcessor.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.json.processor; 2 | 3 | import com.blibli.oss.backend.json.aware.JsonAware; 4 | import com.blibli.oss.backend.json.helper.JsonHelper; 5 | import org.springframework.beans.BeansException; 6 | import org.springframework.beans.factory.config.BeanPostProcessor; 7 | 8 | public class JsonAwareBeanPostProcessor implements BeanPostProcessor { 9 | 10 | private JsonHelper jsonHelper; 11 | 12 | public JsonAwareBeanPostProcessor(JsonHelper jsonHelper) { 13 | this.jsonHelper = jsonHelper; 14 | } 15 | 16 | @Override 17 | public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { 18 | if (bean instanceof JsonAware) { 19 | JsonAware jsonAware = (JsonAware) bean; 20 | jsonAware.setJsonHelper(jsonHelper); 21 | } 22 | 23 | return bean; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /blibli-backend-framework-reactor/src/main/java/com/blibli/oss/backend/reactor/ReactorAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.reactor; 2 | 3 | import com.blibli.oss.backend.reactor.factory.SchedulerHelperFactoryBean; 4 | import com.blibli.oss.backend.reactor.properties.SchedulerProperties; 5 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | 9 | @Configuration 10 | @EnableConfigurationProperties({ 11 | SchedulerProperties.class 12 | }) 13 | public class ReactorAutoConfiguration { 14 | 15 | @Bean 16 | public SchedulerHelperFactoryBean schedulerHelper(SchedulerProperties schedulerProperties) { 17 | SchedulerHelperFactoryBean factoryBean = new SchedulerHelperFactoryBean(); 18 | factoryBean.setSchedulerProperties(schedulerProperties); 19 | return factoryBean; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /blibli-backend-framework-aggregate-query/src/test/resources/search.json: -------------------------------------------------------------------------------- 1 | { 2 | "took": 104, 3 | "timed_out": false, 4 | "_shards": { 5 | "total": 5, 6 | "successful": 5, 7 | "skipped": 0, 8 | "failed": 0 9 | }, 10 | "hits": { 11 | "total": 2, 12 | "max_score": 1.0, 13 | "hits": [ 14 | { 15 | "_index": "customers", 16 | "_type": "_doc", 17 | "_id": "1", 18 | "_score": 1.0, 19 | "_source": { 20 | "id": 1, 21 | "first_name": "Eko", 22 | "middle_name": "Kurniawan", 23 | "last_name": "Khannedy" 24 | } 25 | }, 26 | { 27 | "_index": "customers", 28 | "_type": "_doc", 29 | "_id": "2", 30 | "_score": 1.0, 31 | "_source": { 32 | "id": 2, 33 | "first_name": "Joko", 34 | "middle_name": "", 35 | "last_name": "Morro" 36 | } 37 | } 38 | ] 39 | } 40 | } -------------------------------------------------------------------------------- /blibli-backend-framework-common/src/main/java/com/blibli/oss/backend/common/helper/PagingHelper.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.common.helper; 2 | 3 | import com.blibli.oss.backend.common.model.request.PagingRequest; 4 | import com.blibli.oss.backend.common.model.response.Paging; 5 | 6 | public class PagingHelper { 7 | 8 | public static Paging toPaging(PagingRequest request, Long totalItem) { 9 | Long totalPage = totalItem / request.getItemPerPage(); 10 | if (totalItem % request.getItemPerPage() != 0) { 11 | totalPage++; 12 | } 13 | return toPaging(request, totalPage, totalItem); 14 | } 15 | 16 | public static Paging toPaging(PagingRequest request, Long totalPage, Long totalItem) { 17 | return Paging.builder() 18 | .page(request.getPage()) 19 | .totalItem(totalItem) 20 | .totalPage(totalPage) 21 | .itemPerPage(request.getItemPerPage()) 22 | .sortBy(request.getSortBy()) 23 | .build(); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /blibli-backend-framework-kafka/src/main/java/com/blibli/oss/backend/kafka/properties/KafkaProperties.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.kafka.properties; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | import org.springframework.boot.context.properties.ConfigurationProperties; 8 | 9 | @Data 10 | @Builder 11 | @AllArgsConstructor 12 | @NoArgsConstructor 13 | @ConfigurationProperties("blibli.backend.kafka") 14 | public class KafkaProperties { 15 | 16 | private LoggingProperties logging = new LoggingProperties(); 17 | 18 | @Data 19 | @Builder 20 | @AllArgsConstructor 21 | @NoArgsConstructor 22 | public static class LoggingProperties { 23 | 24 | private boolean beforeSend = false; 25 | 26 | private boolean beforeConsume = false; 27 | 28 | private boolean afterSuccessConsume = false; 29 | 30 | private boolean afterFailedConsume = false; 31 | 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /blibli-backend-framework-internal-api/src/main/java/com/blibli/oss/backend/internalapi/properties/InternalApiProperties.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.internalapi.properties; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | import org.springframework.boot.context.properties.ConfigurationProperties; 8 | 9 | @Data 10 | @Builder 11 | @AllArgsConstructor 12 | @NoArgsConstructor 13 | @ConfigurationProperties("blibli.backend.internal.api") 14 | public class InternalApiProperties { 15 | 16 | private Header header = new Header(); 17 | 18 | @Data 19 | @Builder 20 | @AllArgsConstructor 21 | @NoArgsConstructor 22 | public static class Header { 23 | 24 | private String userId = "Baggage-Blibli-Internal-User-Id"; 25 | 26 | private String userName = "Baggage-Blibli-Internal-User-Name"; 27 | 28 | private String roles = "Baggage-Blibli-Internal-User-Roles"; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /blibli-backend-framework-aggregate-query/src/main/java/com/blibli/oss/backend/aggregate/query/model/AggregateQueryResponse.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.aggregate.query.model; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Builder; 6 | import lombok.Data; 7 | import lombok.NoArgsConstructor; 8 | 9 | import java.util.Map; 10 | import java.util.function.Function; 11 | 12 | @Data 13 | @Builder 14 | @AllArgsConstructor 15 | @NoArgsConstructor 16 | public class AggregateQueryResponse { 17 | 18 | private Integer took; 19 | 20 | @JsonProperty("_scroll_id") 21 | private String scrollId; 22 | 23 | @JsonProperty("timed_out") 24 | private Boolean timedOut; 25 | 26 | private AggregateQueryHits hits; 27 | 28 | private Map aggregations; 29 | 30 | public R aggregationsAs(Function, R> function) { 31 | return function.apply(aggregations); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /blibli-backend-framework-api-client/src/test/java/com/blibli/oss/backend/apiclient/client/ExampleInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.apiclient.client; 2 | 3 | import com.blibli.oss.backend.apiclient.interceptor.ApiClientInterceptor; 4 | import org.springframework.http.HttpHeaders; 5 | import org.springframework.http.MediaType; 6 | import org.springframework.web.reactive.function.client.ClientRequest; 7 | import org.springframework.web.reactive.function.client.ClientResponse; 8 | import org.springframework.web.reactive.function.client.ExchangeFunction; 9 | import reactor.core.publisher.Mono; 10 | 11 | public class ExampleInterceptor implements ApiClientInterceptor { 12 | 13 | @Override 14 | public Mono filter(ClientRequest request, ExchangeFunction next) { 15 | ClientRequest clientRequest = ClientRequest.from(request) 16 | .header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE) 17 | .build(); 18 | 19 | return next.exchange(clientRequest); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /blibli-backend-framework-api-client/src/test/java/com/blibli/oss/backend/apiclient/client/ExceptionClientFallback.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.apiclient.client; 2 | 3 | import com.blibli.oss.backend.apiclient.client.model.FirstRequest; 4 | import com.blibli.oss.backend.apiclient.client.model.FirstResponse; 5 | import com.blibli.oss.backend.apiclient.client.model.SecondResponse; 6 | import lombok.extern.slf4j.Slf4j; 7 | import org.springframework.stereotype.Component; 8 | import reactor.core.publisher.Mono; 9 | 10 | @Slf4j 11 | @Component 12 | public class ExceptionClientFallback { 13 | 14 | public Mono first(FirstRequest request, Throwable throwable) { 15 | log.error("Receive error", throwable); 16 | return Mono.just(FirstResponse.builder() 17 | .hello("Ups First") 18 | .build()); 19 | } 20 | 21 | public Mono second() { 22 | return Mono.just(SecondResponse.builder() 23 | .hello("Ups Second") 24 | .build()); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /blibli-backend-framework-external-api/src/main/java/com/blibli/oss/backend/externalapi/properties/ExternalApiProperties.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.externalapi.properties; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | import org.springframework.boot.context.properties.ConfigurationProperties; 8 | 9 | @Data 10 | @Builder 11 | @AllArgsConstructor 12 | @NoArgsConstructor 13 | @ConfigurationProperties("blibli.backend.external.api") 14 | public class ExternalApiProperties { 15 | 16 | private Header header = new Header(); 17 | 18 | @Data 19 | @Builder 20 | @AllArgsConstructor 21 | @NoArgsConstructor 22 | public static class Header { 23 | 24 | private String isMember = "Blibli-Is-Member"; 25 | 26 | private String userId = "Blibli-User-Id"; 27 | 28 | private String sessionId = "Blibli-Session-Id"; 29 | 30 | private String additionalParameterPrefix = "Blibli-Extras-"; 31 | 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /blibli-backend-framework-aggregate-query/src/test/resources/scroll.json: -------------------------------------------------------------------------------- 1 | { 2 | "_scroll_id": "DnF1ZXJ5VGhlbkZldGNoBQAAAAAA", 3 | "took": 104, 4 | "timed_out": false, 5 | "_shards": { 6 | "total": 5, 7 | "successful": 5, 8 | "skipped": 0, 9 | "failed": 0 10 | }, 11 | "hits": { 12 | "total": 2, 13 | "max_score": 1.0, 14 | "hits": [ 15 | { 16 | "_index": "customers", 17 | "_type": "_doc", 18 | "_id": "1", 19 | "_score": 1.0, 20 | "_source": { 21 | "id": 1, 22 | "first_name": "Eko", 23 | "middle_name": "Kurniawan", 24 | "last_name": "Khannedy" 25 | } 26 | }, 27 | { 28 | "_index": "customers", 29 | "_type": "_doc", 30 | "_id": "2", 31 | "_score": 1.0, 32 | "_source": { 33 | "id": 2, 34 | "first_name": "Joko", 35 | "middle_name": "", 36 | "last_name": "Morro" 37 | } 38 | } 39 | ] 40 | } 41 | } -------------------------------------------------------------------------------- /blibli-backend-framework-kafka/src/main/java/com/blibli/oss/backend/kafka/interceptor/log/LogKafkaProducerInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.kafka.interceptor.log; 2 | 3 | import com.blibli.oss.backend.kafka.interceptor.KafkaProducerInterceptor; 4 | import com.blibli.oss.backend.kafka.model.ProducerEvent; 5 | import com.blibli.oss.backend.kafka.properties.KafkaProperties; 6 | import lombok.Getter; 7 | import lombok.Setter; 8 | import lombok.extern.slf4j.Slf4j; 9 | import org.springframework.core.Ordered; 10 | 11 | @Slf4j 12 | public class LogKafkaProducerInterceptor implements KafkaProducerInterceptor, Ordered { 13 | 14 | @Getter 15 | private final int order = Ordered.HIGHEST_PRECEDENCE; 16 | 17 | @Setter 18 | private KafkaProperties kafkaProperties; 19 | 20 | @Override 21 | public ProducerEvent beforeSend(ProducerEvent event) { 22 | if (kafkaProperties.getLogging().isBeforeSend()) { 23 | log.info("Send message to kafka : {}", event); 24 | } 25 | return event; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /blibli-backend-framework-mandatory-parameter/src/test/java/com/blibli/oss/backend/mandatoryparameter/apiclient/apiclient/SecondApiClient.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.mandatoryparameter.apiclient.apiclient; 2 | 3 | import com.blibli.oss.backend.apiclient.annotation.ApiClient; 4 | import com.blibli.oss.backend.mandatoryparameter.apiclient.MandatoryParameterApiClientInterceptor; 5 | import org.springframework.http.MediaType; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RequestMethod; 8 | import reactor.core.publisher.Mono; 9 | 10 | import java.util.Map; 11 | 12 | @ApiClient( 13 | name = "secondApiClient", 14 | interceptors = { 15 | MandatoryParameterApiClientInterceptor.class 16 | } 17 | ) 18 | public interface SecondApiClient { 19 | 20 | @RequestMapping( 21 | value = "/second", 22 | method = RequestMethod.GET, 23 | produces = MediaType.APPLICATION_JSON_VALUE 24 | ) 25 | Mono> second(); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /blibli-backend-framework-mandatory-parameter/src/main/java/com/blibli/oss/backend/mandatoryparameter/swagger/annotation/MandatoryParameterAtQuery.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.mandatoryparameter.swagger.annotation; 2 | 3 | import io.swagger.v3.oas.annotations.Parameter; 4 | import io.swagger.v3.oas.annotations.Parameters; 5 | 6 | import java.lang.annotation.ElementType; 7 | import java.lang.annotation.Retention; 8 | import java.lang.annotation.RetentionPolicy; 9 | import java.lang.annotation.Target; 10 | 11 | @Parameters({ 12 | @Parameter(name = "storeId", ref = "queryParameterStoreId"), 13 | @Parameter(name = "channelId", ref = "queryParameterChannelId"), 14 | @Parameter(name = "clientId", ref = "queryParameterClientId"), 15 | @Parameter(name = "username", ref = "queryParameterUsername"), 16 | @Parameter(name = "requestId", ref = "queryParameterRequestId"), 17 | }) 18 | @Target({ 19 | ElementType.METHOD, 20 | ElementType.TYPE 21 | }) 22 | @Retention(RetentionPolicy.RUNTIME) 23 | public @interface MandatoryParameterAtQuery { 24 | 25 | } 26 | -------------------------------------------------------------------------------- /blibli-backend-framework-aggregate-query/src/main/java/com/blibli/oss/backend/aggregate/query/model/AggregateQueryHit.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.aggregate.query.model; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Builder; 6 | import lombok.Data; 7 | import lombok.NoArgsConstructor; 8 | 9 | import java.util.function.Function; 10 | 11 | @Data 12 | @Builder 13 | @AllArgsConstructor 14 | @NoArgsConstructor 15 | public class AggregateQueryHit { 16 | 17 | @JsonProperty("_index") 18 | private String index; 19 | 20 | @JsonProperty("_type") 21 | private String type; 22 | 23 | @JsonProperty("_id") 24 | private String id; 25 | 26 | @JsonProperty("_score") 27 | private Double score; 28 | 29 | private Boolean found; 30 | 31 | @JsonProperty("_version") 32 | private Integer version; 33 | 34 | @JsonProperty("_source") 35 | private T source; 36 | 37 | public R sourceAs(Function function) { 38 | return function.apply(source); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /blibli-backend-framework-mandatory-parameter/src/main/java/com/blibli/oss/backend/mandatoryparameter/swagger/annotation/MandatoryParameterAtHeader.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.mandatoryparameter.swagger.annotation; 2 | 3 | import io.swagger.v3.oas.annotations.Parameter; 4 | import io.swagger.v3.oas.annotations.Parameters; 5 | 6 | import java.lang.annotation.ElementType; 7 | import java.lang.annotation.Retention; 8 | import java.lang.annotation.RetentionPolicy; 9 | import java.lang.annotation.Target; 10 | 11 | @Parameters({ 12 | @Parameter(name = "storeId", ref = "headerParameterStoreId"), 13 | @Parameter(name = "channelId", ref = "headerParameterChannelId"), 14 | @Parameter(name = "clientId", ref = "headerParameterClientId"), 15 | @Parameter(name = "username", ref = "headerParameterUsername"), 16 | @Parameter(name = "requestId", ref = "headerParameterRequestId"), 17 | }) 18 | @Target({ 19 | ElementType.METHOD, 20 | ElementType.TYPE 21 | }) 22 | @Retention(RetentionPolicy.RUNTIME) 23 | public @interface MandatoryParameterAtHeader { 24 | 25 | } 26 | -------------------------------------------------------------------------------- /blibli-backend-framework-scheduler-platform/src/main/java/com/blibli/oss/backend/scheduler/platform/model/DelayedJobRequest.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.scheduler.platform.model; 2 | 3 | import com.blibli.oss.backend.kafka.annotation.KafkaKey; 4 | import com.blibli.oss.backend.kafka.annotation.KafkaTopic; 5 | import com.blibli.oss.backend.scheduler.platform.constant.SchedulerPlatformTopics; 6 | import lombok.AllArgsConstructor; 7 | import lombok.Builder; 8 | import lombok.Data; 9 | import lombok.NoArgsConstructor; 10 | 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | 14 | @Data 15 | @Builder 16 | @AllArgsConstructor 17 | @NoArgsConstructor 18 | @KafkaTopic(SchedulerPlatformTopics.SAVE_DELAYED_JOB_EVENT) 19 | public class DelayedJobRequest implements SchedulerPlatformModel { 20 | 21 | @KafkaKey 22 | private String id; 23 | 24 | private String name; 25 | 26 | private String group; 27 | 28 | private String payload; 29 | 30 | private String topic; 31 | 32 | @Builder.Default 33 | private List notifyTimes = new ArrayList<>(); 34 | } 35 | -------------------------------------------------------------------------------- /blibli-backend-framework-aggregate-query/src/main/java/com/blibli/oss/backend/aggregate/query/model/AggregateQueryHits.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.aggregate.query.model; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Builder; 6 | import lombok.Data; 7 | import lombok.NoArgsConstructor; 8 | 9 | import java.util.List; 10 | import java.util.function.Function; 11 | import java.util.stream.Collectors; 12 | 13 | @Data 14 | @Builder 15 | @AllArgsConstructor 16 | @NoArgsConstructor 17 | public class AggregateQueryHits { 18 | 19 | private Long total; 20 | 21 | @JsonProperty("max_score") 22 | private Double maxScore; 23 | 24 | private List> hits; 25 | 26 | public List hitsOnly() { 27 | return hits.stream(). 28 | map(AggregateQueryHit::getSource). 29 | collect(Collectors.toList()); 30 | } 31 | 32 | public List hitsAs(Function function) { 33 | return hits.stream() 34 | .map(item -> item.sourceAs(function)) 35 | .collect(Collectors.toList()); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /blibli-backend-framework-external-api/src/main/java/com/blibli/oss/backend/externalapi/controller/ExternalApiErrorController.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.externalapi.controller; 2 | 3 | import com.blibli.oss.backend.common.model.response.Response; 4 | import com.blibli.oss.backend.common.webflux.controller.CommonErrorController; 5 | import com.blibli.oss.backend.externalapi.exception.ExternalApiException; 6 | import org.springframework.http.HttpStatus; 7 | import org.springframework.http.ResponseEntity; 8 | import org.springframework.web.bind.annotation.ExceptionHandler; 9 | 10 | public interface ExternalApiErrorController extends CommonErrorController { 11 | 12 | @ExceptionHandler(ExternalApiException.class) 13 | default ResponseEntity> commandValidationException(ExternalApiException e) { 14 | getLogger().warn(ExternalApiException.class.getName(), e); 15 | 16 | Response response = new Response<>(); 17 | response.setCode(HttpStatus.UNAUTHORIZED.value()); 18 | response.setStatus(HttpStatus.UNAUTHORIZED.name()); 19 | 20 | return ResponseEntity.badRequest().body(response); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /.travis/settings.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | github 8 | 9 | 10 | 11 | 12 | github 13 | 14 | 15 | central 16 | https://repo1.maven.org/maven2 17 | 18 | 19 | github 20 | https://maven.pkg.github.com/bliblidotcom/* 21 | 22 | true 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | github 32 | ${env.GITHUB_USERNAME} 33 | ${env.GITHUB_PASSWORD} 34 | 35 | 36 | -------------------------------------------------------------------------------- /blibli-backend-framework-api-client/src/test/java/com/blibli/oss/backend/apiclient/client/SleuthApiClient.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.apiclient.client; 2 | 3 | import com.blibli.oss.backend.apiclient.annotation.ApiClient; 4 | import com.blibli.oss.backend.apiclient.client.model.GenericResponse; 5 | import org.springframework.http.MediaType; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RequestMethod; 8 | import org.springframework.web.bind.annotation.RequestParam; 9 | import reactor.core.publisher.Mono; 10 | 11 | import java.util.List; 12 | import java.util.Map; 13 | 14 | @ApiClient( 15 | name = "sleuthApiClient" 16 | ) 17 | public interface SleuthApiClient { 18 | 19 | @RequestMapping( 20 | method = RequestMethod.GET, 21 | value = "/second", 22 | produces = MediaType.APPLICATION_JSON_VALUE 23 | ) 24 | Mono> second(); 25 | 26 | @RequestMapping( 27 | value = "/names", 28 | produces = MediaType.APPLICATION_JSON_VALUE 29 | ) 30 | Mono>> names(@RequestParam("names") List names); 31 | 32 | } 33 | -------------------------------------------------------------------------------- /blibli-backend-framework-command/src/main/java/com/blibli/oss/backend/command/configuration/CommandAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.command.configuration; 2 | 3 | import com.blibli.oss.backend.command.executor.CommandExecutor; 4 | import com.blibli.oss.backend.command.executor.DefaultCommandExecutor; 5 | import com.blibli.oss.backend.command.properties.CommandProperties; 6 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 7 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 8 | import org.springframework.context.annotation.Bean; 9 | import org.springframework.context.annotation.Configuration; 10 | 11 | import javax.validation.Validator; 12 | 13 | @Configuration 14 | @EnableConfigurationProperties({ 15 | CommandProperties.class 16 | }) 17 | public class CommandAutoConfiguration { 18 | 19 | @Bean 20 | @ConditionalOnMissingBean 21 | public CommandExecutor commandExecutor(Validator validator) { 22 | DefaultCommandExecutor commandExecutor = new DefaultCommandExecutor(); 23 | commandExecutor.setValidator(validator); 24 | return commandExecutor; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /blibli-backend-framework-json/src/main/java/com/blibli/oss/backend/json/JsonAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.json; 2 | 3 | import com.blibli.oss.backend.json.helper.JsonHelper; 4 | import com.blibli.oss.backend.json.processor.JsonAwareBeanPostProcessor; 5 | import com.fasterxml.jackson.databind.ObjectMapper; 6 | import org.springframework.boot.autoconfigure.AutoConfigureAfter; 7 | import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; 8 | import org.springframework.context.annotation.Bean; 9 | import org.springframework.context.annotation.Configuration; 10 | import org.springframework.context.annotation.PropertySource; 11 | 12 | @Configuration 13 | @AutoConfigureAfter(JacksonAutoConfiguration.class) 14 | @PropertySource("classpath:blibli-json.properties") 15 | public class JsonAutoConfiguration { 16 | 17 | @Bean 18 | public JsonHelper jsonHelper(ObjectMapper objectMapper) { 19 | return new JsonHelper(objectMapper); 20 | } 21 | 22 | @Bean 23 | public JsonAwareBeanPostProcessor jsonAwareBeanPostProcessor(JsonHelper jsonHelper) { 24 | return new JsonAwareBeanPostProcessor(jsonHelper); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /blibli-backend-framework-sleuth/src/main/java/com/blibli/oss/backend/sleuth/fields/SleuthExtraFieldConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.sleuth.fields; 2 | 3 | import lombok.Setter; 4 | import org.springframework.beans.factory.InitializingBean; 5 | import org.springframework.context.ApplicationContext; 6 | import org.springframework.context.ApplicationContextAware; 7 | 8 | import java.util.ArrayList; 9 | import java.util.Collection; 10 | import java.util.List; 11 | 12 | public class SleuthExtraFieldConfiguration implements ApplicationContextAware, InitializingBean { 13 | 14 | @Setter 15 | private ApplicationContext applicationContext; 16 | 17 | private Collection extraFields; 18 | 19 | @Override 20 | public void afterPropertiesSet() throws Exception { 21 | extraFields = applicationContext.getBeansOfType(SleuthExtraFields.class).values(); 22 | } 23 | 24 | public List getExtraFields(List otherFields) { 25 | List fields = new ArrayList<>(); 26 | extraFields.forEach(sleuthExtraFields -> fields.addAll(sleuthExtraFields.getFields())); 27 | fields.addAll(otherFields); 28 | return fields; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /blibli-backend-framework-common/src/main/java/com/blibli/oss/backend/common/properties/PagingProperties.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.common.properties; 2 | 3 | import com.blibli.oss.backend.common.model.request.SortByDirection; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Builder; 6 | import lombok.Data; 7 | import lombok.NoArgsConstructor; 8 | import org.springframework.boot.context.properties.ConfigurationProperties; 9 | 10 | @Data 11 | @Builder 12 | @AllArgsConstructor 13 | @NoArgsConstructor 14 | @ConfigurationProperties("blibli.backend.common.paging") 15 | public class PagingProperties { 16 | 17 | private Long defaultPage = 1L; 18 | 19 | private Long defaultItemPerPage = 50L; 20 | 21 | private SortByDirection defaultSortDirection = SortByDirection.ASC; 22 | 23 | private Long maxItemPerPage = 1000L; 24 | 25 | private Query query = new Query(); 26 | 27 | @Data 28 | @Builder 29 | @AllArgsConstructor 30 | @NoArgsConstructor 31 | public static class Query { 32 | 33 | private String pageKey = "page"; 34 | 35 | private String itemPerPageKey = "item_per_page"; 36 | 37 | private String sortByKey = "sort_by"; 38 | 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /blibli-backend-framework-validation/README.md: -------------------------------------------------------------------------------- 1 | # Validation Module 2 | 3 | We are using bean validation as validation library. The problem with bean validation, it's not reactive. 4 | Some times we need reactive code to do validation, such as : call mongo repository to check is email unique or not. 5 | Validation module is module helper to support reactive code on validation layer. 6 | 7 | ## Setup Dependency 8 | 9 | ```xml 10 | 11 | com.blibli.oss 12 | blibli-backend-framework-validation 13 | 14 | ``` 15 | 16 | ## Create ConstraintValidator 17 | 18 | When using bean validation, if we want to create custom validator, we will implement `ConstraintValidator` interface. 19 | Now we only need to implement interface `ReactiveConstraintValidator` or extend class `AbstractReactiveConstraintValidator`. 20 | 21 | ```java 22 | public class MustValidValidator extends AbstractReactiveConstraintValidator { 23 | 24 | @Override 25 | public Mono validate(String value, MustValid annotation, ConstraintValidatorContext context) { 26 | return Mono.fromCallable(() -> "EKO".equals(value)); 27 | } 28 | } 29 | ``` -------------------------------------------------------------------------------- /blibli-backend-framework-newrelic/src/main/java/com/blibli/oss/backend/newrelic/aspect/service/util/AspectHelper.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.newrelic.aspect.service.util; 2 | 3 | import lombok.experimental.UtilityClass; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.aspectj.lang.JoinPoint; 6 | import reactor.core.publisher.Flux; 7 | import reactor.core.publisher.Mono; 8 | 9 | @Slf4j 10 | @UtilityClass 11 | public class AspectHelper { 12 | 13 | public static String constructSegmentName(JoinPoint joinPoint, SegmentType segmentType) { 14 | return String.format( 15 | segmentType.getStringFormat(), 16 | joinPoint.getTarget().getClass().getSimpleName(), 17 | joinPoint.getSignature().toShortString() 18 | ); 19 | } 20 | 21 | public static boolean retValIsType(Object retVal, RetValType type) { 22 | switch (type) { 23 | case FLUX: 24 | return retVal instanceof Flux; 25 | case MONO: 26 | return retVal instanceof Mono; 27 | case MONO_OR_FLUX: 28 | return retVal instanceof Flux || retVal instanceof Mono; 29 | default: 30 | throw new IllegalArgumentException("RetValType is unknown"); 31 | } 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /blibli-backend-framework-api-client/src/main/java/com/blibli/oss/backend/apiclient/sleuth/ApiClientSleuthConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.apiclient.sleuth; 2 | 3 | import brave.Tracer; 4 | import com.blibli.oss.backend.apiclient.configuration.ApiClientConfiguration; 5 | import com.blibli.oss.backend.apiclient.properties.ApiClientProperties; 6 | import com.blibli.oss.backend.sleuth.configuration.SleuthConfiguration; 7 | import org.springframework.boot.autoconfigure.AutoConfigureAfter; 8 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 9 | import org.springframework.context.annotation.Bean; 10 | import org.springframework.context.annotation.Configuration; 11 | 12 | @Configuration 13 | @ConditionalOnClass({SleuthConfiguration.class}) 14 | @AutoConfigureAfter({SleuthConfiguration.class, ApiClientConfiguration.class}) 15 | public class ApiClientSleuthConfiguration { 16 | 17 | @Bean 18 | public SleuthGlobalApiClientInterceptor sleuthGlobalApiClientInterceptor(ApiClientProperties properties, 19 | Tracer tracer) { 20 | return new SleuthGlobalApiClientInterceptor(properties, tracer); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /blibli-backend-framework-aggregate-query/src/main/java/com/blibli/oss/backend/aggregate/query/configuration/AggregateQueryAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.aggregate.query.configuration; 2 | 3 | import com.blibli.oss.backend.aggregate.query.fallback.AggregateQueryApiClientFallback; 4 | import com.blibli.oss.backend.aggregate.query.interceptor.AggregateQueryApiClientInterceptor; 5 | import com.blibli.oss.backend.aggregate.query.properties.AggregateQueryProperties; 6 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Configuration; 9 | 10 | @Configuration 11 | @EnableConfigurationProperties({ 12 | AggregateQueryProperties.class 13 | }) 14 | public class AggregateQueryAutoConfiguration { 15 | 16 | @Bean 17 | public AggregateQueryApiClientFallback aggregateQueryApiClientFallback() { 18 | return new AggregateQueryApiClientFallback(); 19 | } 20 | 21 | @Bean 22 | public AggregateQueryApiClientInterceptor aggregateQueryApiClientInterceptor(AggregateQueryProperties properties) { 23 | return new AggregateQueryApiClientInterceptor(properties); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /blibli-backend-framework-api-client/src/test/java/com/blibli/oss/backend/apiclient/client/ExceptionClient.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.apiclient.client; 2 | 3 | import com.blibli.oss.backend.apiclient.annotation.ApiClient; 4 | import com.blibli.oss.backend.apiclient.client.model.FirstRequest; 5 | import com.blibli.oss.backend.apiclient.client.model.FirstResponse; 6 | import com.blibli.oss.backend.apiclient.client.model.SecondResponse; 7 | import org.springframework.http.MediaType; 8 | import org.springframework.web.bind.annotation.RequestBody; 9 | import org.springframework.web.bind.annotation.RequestMapping; 10 | import org.springframework.web.bind.annotation.RequestMethod; 11 | import reactor.core.publisher.Mono; 12 | 13 | @ApiClient( 14 | name = "exceptionClient", 15 | fallback = ExceptionClientFallback.class 16 | ) 17 | public interface ExceptionClient { 18 | 19 | @RequestMapping( 20 | method = RequestMethod.POST, 21 | path = "/first", 22 | consumes = MediaType.APPLICATION_JSON_VALUE 23 | ) 24 | Mono first(@RequestBody FirstRequest request); 25 | 26 | @RequestMapping( 27 | method = RequestMethod.GET, 28 | path = "/second" 29 | ) 30 | Mono second(); 31 | 32 | } 33 | -------------------------------------------------------------------------------- /blibli-backend-framework-kafka/src/test/java/com/blibli/oss/backend/kafka/producer/helper/KafkaHelper.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.kafka.producer.helper; 2 | 3 | import org.apache.kafka.clients.consumer.Consumer; 4 | import org.apache.kafka.clients.consumer.ConsumerConfig; 5 | import org.apache.kafka.common.serialization.StringDeserializer; 6 | import org.springframework.kafka.core.DefaultKafkaConsumerFactory; 7 | import org.springframework.kafka.test.EmbeddedKafkaBroker; 8 | import org.springframework.kafka.test.utils.KafkaTestUtils; 9 | 10 | import java.util.Map; 11 | 12 | public final class KafkaHelper { 13 | 14 | public static Consumer newConsumer(EmbeddedKafkaBroker broker) { 15 | final Map consumerProps = KafkaTestUtils.consumerProps("testGroup", "true", broker); 16 | consumerProps.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest"); 17 | consumerProps.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName()); 18 | consumerProps.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName()); 19 | 20 | final DefaultKafkaConsumerFactory consumerFactory = new DefaultKafkaConsumerFactory<>(consumerProps); 21 | return consumerFactory.createConsumer(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /blibli-backend-framework-scheduler-platform/src/test/java/com/blibli/oss/backend/scheduler/platform/helper/KafkaHelper.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.scheduler.platform.helper; 2 | 3 | import org.apache.kafka.clients.consumer.Consumer; 4 | import org.apache.kafka.clients.consumer.ConsumerConfig; 5 | import org.apache.kafka.common.serialization.StringDeserializer; 6 | import org.springframework.kafka.core.DefaultKafkaConsumerFactory; 7 | import org.springframework.kafka.test.EmbeddedKafkaBroker; 8 | import org.springframework.kafka.test.utils.KafkaTestUtils; 9 | 10 | import java.util.Map; 11 | 12 | public class KafkaHelper { 13 | 14 | public static Consumer newConsumer(EmbeddedKafkaBroker broker) { 15 | final Map consumerProps = KafkaTestUtils.consumerProps("testGroup", "true", broker); 16 | consumerProps.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest"); 17 | consumerProps.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName()); 18 | consumerProps.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName()); 19 | 20 | final DefaultKafkaConsumerFactory consumerFactory = new DefaultKafkaConsumerFactory<>(consumerProps); 21 | return consumerFactory.createConsumer(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /blibli-backend-framework-api-client/src/test/resources/application.properties: -------------------------------------------------------------------------------- 1 | blibli.backend.apiclient.packages=com.blibli.oss.backend.apiclient.client 2 | blibli.backend.apiclient.configs.exampleClient.url=http://localhost:8089 3 | 4 | blibli.backend.apiclient.configs.sleuthApiClient.url=http://localhost:15234 5 | 6 | blibli.backend.apiclient.configs.helloApiClient.url=http://localhost:8089 7 | blibli.backend.apiclient.configs.helloApiClient.fallback=com.blibli.oss.backend.apiclient.client.HelloApiClientFallback 8 | 9 | spring.http.log-request-details=true 10 | logging.level.org.springframework.web.reactive.function.client.ExchangeFunctions=TRACE 11 | logging.level.reactor.netty.http.client=DEBUG 12 | 13 | blibli.backend.reactor.scheduler.configs.exampleClient.type=thread_pool 14 | blibli.backend.reactor.scheduler.configs.exampleClient.thread-pool.allow-core-thread-time-out=false 15 | blibli.backend.reactor.scheduler.configs.exampleClient.thread-pool.core-pool-size=10 16 | blibli.backend.reactor.scheduler.configs.exampleClient.thread-pool.maximum-pool-size=100 17 | blibli.backend.reactor.scheduler.configs.exampleClient.thread-pool.queue-size=100 18 | blibli.backend.reactor.scheduler.configs.exampleClient.thread-pool.queue-type=linked 19 | 20 | spring.sleuth.baggage-keys[0]=FirstName 21 | 22 | blibli.backend.apiclient.sleuth.enabled=true -------------------------------------------------------------------------------- /blibli-backend-framework-newrelic/src/main/java/com/blibli/oss/backend/newrelic/configuration/reporter/NewRelicMongoReporterAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.newrelic.configuration.reporter; 2 | 3 | import com.blibli.oss.backend.newrelic.aspect.ReactiveMongoDbAspect; 4 | import com.blibli.oss.backend.newrelic.reporter.ExternalReporter; 5 | import com.blibli.oss.backend.newrelic.reporter.impl.MongoExternalReporterImpl; 6 | import lombok.extern.slf4j.Slf4j; 7 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 8 | import org.springframework.boot.autoconfigure.mongo.MongoProperties; 9 | import org.springframework.context.annotation.Bean; 10 | import org.springframework.context.annotation.Configuration; 11 | import org.springframework.context.annotation.Import; 12 | import org.springframework.data.mongodb.core.ReactiveMongoTemplate; 13 | 14 | @Configuration 15 | @ConditionalOnClass({MongoProperties.class, ReactiveMongoTemplate.class}) 16 | @Slf4j 17 | @Import({ReactiveMongoDbAspect.class}) 18 | public class NewRelicMongoReporterAutoConfiguration { 19 | 20 | @Bean 21 | public ExternalReporter externalReporter(MongoProperties mongoProperties, ReactiveMongoTemplate reactiveMongoTemplate) { 22 | return new MongoExternalReporterImpl(mongoProperties, reactiveMongoTemplate); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /blibli-backend-framework-swagger/src/main/java/com/blibli/oss/backend/swagger/factory/OpenAPIFactoryBean.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.swagger.factory; 2 | 3 | import com.blibli.oss.backend.swagger.properties.SwaggerProperties; 4 | import io.swagger.v3.oas.models.Components; 5 | import io.swagger.v3.oas.models.OpenAPI; 6 | import io.swagger.v3.oas.models.info.Info; 7 | import lombok.Setter; 8 | import org.springframework.beans.factory.FactoryBean; 9 | 10 | public class OpenAPIFactoryBean implements FactoryBean { 11 | 12 | @Setter 13 | private SwaggerProperties swaggerProperties; 14 | 15 | @Setter 16 | private Components components; 17 | 18 | @Override 19 | public OpenAPI getObject() throws Exception { 20 | OpenAPI openAPI = new OpenAPI(); 21 | openAPI.setInfo(getInfo()); 22 | openAPI.setComponents(components); 23 | return openAPI; 24 | } 25 | 26 | private Info getInfo() { 27 | Info info = new Info(); 28 | info.setTitle(swaggerProperties.getTitle()); 29 | info.setDescription(swaggerProperties.getDescription()); 30 | info.setTermsOfService(swaggerProperties.getTermsOfService()); 31 | info.setVersion(swaggerProperties.getVersion()); 32 | return info; 33 | } 34 | 35 | @Override 36 | public Class getObjectType() { 37 | return OpenAPI.class; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /blibli-backend-framework-api-client/src/test/java/com/blibli/oss/backend/apiclient/ExceptionClientFallbackTest.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.apiclient; 2 | 3 | import com.blibli.oss.backend.apiclient.client.ExceptionClient; 4 | import com.blibli.oss.backend.apiclient.client.model.FirstRequest; 5 | import com.blibli.oss.backend.apiclient.client.model.FirstResponse; 6 | import com.blibli.oss.backend.apiclient.client.model.SecondResponse; 7 | import org.junit.jupiter.api.Test; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.boot.test.context.SpringBootTest; 10 | 11 | import static org.junit.jupiter.api.Assertions.assertEquals; 12 | 13 | @SpringBootTest(classes = TestApplication.class) 14 | public class ExceptionClientFallbackTest { 15 | 16 | public static final FirstRequest FIRST_REQUEST = FirstRequest.builder() 17 | .name("Eko").build(); 18 | 19 | @Autowired 20 | private ExceptionClient exceptionClient; 21 | 22 | @Test 23 | void testFirst() { 24 | FirstResponse response = exceptionClient.first(FIRST_REQUEST).block(); 25 | assertEquals("Ups First", response.getHello()); 26 | } 27 | 28 | @Test 29 | void testSecond() { 30 | SecondResponse response = exceptionClient.second().block(); 31 | assertEquals("Ups Second", response.getHello()); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /blibli-backend-framework-aggregate-query/src/main/java/com/blibli/oss/backend/aggregate/query/interceptor/AggregateQueryApiClientInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.aggregate.query.interceptor; 2 | 3 | import com.blibli.oss.backend.aggregate.query.constant.AggregateQueryConstant; 4 | import com.blibli.oss.backend.aggregate.query.properties.AggregateQueryProperties; 5 | import com.blibli.oss.backend.apiclient.interceptor.ApiClientInterceptor; 6 | import lombok.AllArgsConstructor; 7 | import org.springframework.web.reactive.function.client.ClientRequest; 8 | import org.springframework.web.reactive.function.client.ClientResponse; 9 | import org.springframework.web.reactive.function.client.ExchangeFunction; 10 | import reactor.core.publisher.Mono; 11 | 12 | @AllArgsConstructor 13 | public class AggregateQueryApiClientInterceptor implements ApiClientInterceptor { 14 | 15 | private AggregateQueryProperties aggregateQueryProperties; 16 | 17 | @Override 18 | public Mono filter(ClientRequest request, ExchangeFunction next) { 19 | return Mono.just(request) 20 | .map(clientRequest -> 21 | ClientRequest 22 | .from(clientRequest) 23 | .header(AggregateQueryConstant.SERVICE_ID_HEADER, aggregateQueryProperties.getServiceId()) 24 | .build() 25 | ).flatMap(next::exchange); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /blibli-backend-framework-mandatory-parameter/src/main/java/com/blibli/oss/backend/mandatoryparameter/helper/ServerHelper.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.mandatoryparameter.helper; 2 | 3 | import org.springframework.http.HttpHeaders; 4 | import org.springframework.http.server.reactive.ServerHttpRequest; 5 | import org.springframework.util.MultiValueMap; 6 | import org.springframework.util.StringUtils; 7 | import org.springframework.web.server.ServerWebExchange; 8 | 9 | public class ServerHelper { 10 | 11 | public static String getValueFromQueryOrHeader(ServerWebExchange exchange, String headerKey, String queryKey) { 12 | return getValueFromQueryOrHeader(exchange.getRequest(), headerKey, queryKey); 13 | } 14 | 15 | public static String getValueFromQueryOrHeader(ServerHttpRequest httpRequest, String headerKey, String queryKey) { 16 | return getValueFromQueryOrHeader(httpRequest.getHeaders(), httpRequest.getQueryParams(), headerKey, queryKey); 17 | } 18 | 19 | public static String getValueFromQueryOrHeader(HttpHeaders httpHeaders, MultiValueMap queryParams, String headerKey, String queryParamKey) { 20 | if (StringUtils.isEmpty(httpHeaders.getFirst(headerKey))) { 21 | return queryParams.getFirst(queryParamKey); 22 | } else { 23 | return httpHeaders.getFirst(headerKey); 24 | } 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /blibli-backend-framework-command/src/main/java/com/blibli/oss/backend/command/controller/CommandErrorController.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.command.controller; 2 | 3 | import com.blibli.oss.backend.command.exception.CommandValidationException; 4 | import com.blibli.oss.backend.common.model.response.Response; 5 | import com.blibli.oss.backend.common.webflux.controller.CommonErrorController; 6 | import org.springframework.http.HttpStatus; 7 | import org.springframework.http.ResponseEntity; 8 | import org.springframework.web.bind.annotation.ExceptionHandler; 9 | 10 | public interface CommandErrorController extends CommonErrorController { 11 | 12 | /** 13 | * @deprecated not used anymore 14 | * @see javax.validation.ConstraintViolationException 15 | */ 16 | @Deprecated 17 | @ExceptionHandler(CommandValidationException.class) 18 | default ResponseEntity> commandValidationException(CommandValidationException e) { 19 | getLogger().warn(CommandValidationException.class.getName(), e); 20 | 21 | Response response = new Response<>(); 22 | response.setCode(HttpStatus.BAD_REQUEST.value()); 23 | response.setStatus(HttpStatus.BAD_REQUEST.name()); 24 | response.setErrors(CommonErrorController.from(e.getConstraintViolations())); 25 | 26 | return ResponseEntity.badRequest().body(response); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /blibli-backend-framework-common/src/main/java/com/blibli/oss/backend/common/model/response/Response.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.common.model.response; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Builder; 6 | import lombok.Data; 7 | import lombok.NoArgsConstructor; 8 | 9 | import java.util.List; 10 | import java.util.Map; 11 | 12 | @Data 13 | @Builder 14 | @AllArgsConstructor 15 | @NoArgsConstructor 16 | /** 17 | * Standard Blibli Web Response 18 | */ 19 | public class Response { 20 | 21 | /** 22 | * Code , usually same as HTTP Code 23 | */ 24 | @JsonProperty("code") 25 | private Integer code; 26 | 27 | /** 28 | * Status, usually same as HTTP status 29 | */ 30 | @JsonProperty("status") 31 | private String status; 32 | 33 | /** 34 | * Response data 35 | */ 36 | @JsonProperty("data") 37 | private T data; 38 | 39 | /** 40 | * Paging information, if response is paginate data 41 | */ 42 | @JsonProperty("paging") 43 | private Paging paging; 44 | 45 | /** 46 | * Error information, if request is not valid 47 | */ 48 | @JsonProperty("errors") 49 | private Map> errors; 50 | 51 | /** 52 | * Metadata information 53 | */ 54 | @JsonProperty("metadata") 55 | private Map metadata; 56 | 57 | } 58 | -------------------------------------------------------------------------------- /blibli-backend-framework-external-api/src/main/java/com/blibli/oss/backend/externalapi/ExternalApiConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.externalapi; 2 | 3 | import com.blibli.oss.backend.externalapi.properties.ExternalApiProperties; 4 | import com.blibli.oss.backend.externalapi.resolver.ExternalSessionArgumentResolver; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Configuration; 9 | import org.springframework.web.reactive.config.WebFluxConfigurer; 10 | import org.springframework.web.reactive.result.method.annotation.ArgumentResolverConfigurer; 11 | 12 | @Configuration 13 | @EnableConfigurationProperties({ 14 | ExternalApiProperties.class 15 | }) 16 | public class ExternalApiConfiguration implements WebFluxConfigurer { 17 | 18 | @Autowired 19 | private ExternalApiProperties properties; 20 | 21 | @Bean 22 | public ExternalSessionArgumentResolver externalSessionArgumentResolver() { 23 | return new ExternalSessionArgumentResolver(properties); 24 | } 25 | 26 | @Override 27 | public void configureArgumentResolvers(ArgumentResolverConfigurer configurer) { 28 | configurer.addCustomResolver(externalSessionArgumentResolver()); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /blibli-backend-framework-version/src/main/java/com/blibli/oss/backend/version/controller/VersionController.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.version.controller; 2 | 3 | import com.blibli.oss.backend.version.properties.VersionProperties; 4 | import org.springframework.beans.factory.InitializingBean; 5 | import org.springframework.http.MediaType; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | import reactor.core.publisher.Mono; 9 | 10 | @RestController 11 | public class VersionController implements InitializingBean { 12 | 13 | private final VersionProperties properties; 14 | 15 | private String maven; 16 | 17 | public VersionController(VersionProperties properties) { 18 | this.properties = properties; 19 | } 20 | 21 | @Override 22 | public void afterPropertiesSet() throws Exception { 23 | maven = "maven.groupId=" + properties.getGroupId() + "\n" + 24 | "maven.artifactId=" + properties.getArtifactId() + "\n" + 25 | "maven.pom.version=" + properties.getVersion() + "\n" + 26 | "maven.build.time=" + properties.getBuildTime() + "\n"; 27 | } 28 | 29 | @RequestMapping( 30 | value = "/version", 31 | produces = MediaType.TEXT_PLAIN_VALUE 32 | ) 33 | public Mono version() { 34 | return Mono.fromCallable(() -> maven); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /blibli-backend-framework-api-client/src/main/java/com/blibli/oss/backend/apiclient/annotation/ApiClient.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.apiclient.annotation; 2 | 3 | import com.blibli.oss.backend.apiclient.customizer.ApiClientCodecCustomizer; 4 | import com.blibli.oss.backend.apiclient.customizer.ApiClientTcpClientCustomizer; 5 | import com.blibli.oss.backend.apiclient.customizer.ApiClientWebClientCustomizer; 6 | import com.blibli.oss.backend.apiclient.error.ApiErrorResolver; 7 | import com.blibli.oss.backend.apiclient.error.DefaultApiErrorResolver; 8 | import com.blibli.oss.backend.apiclient.interceptor.ApiClientInterceptor; 9 | 10 | import java.lang.annotation.*; 11 | 12 | @Target({ElementType.TYPE}) 13 | @Retention(RetentionPolicy.RUNTIME) 14 | @Documented 15 | public @interface ApiClient { 16 | 17 | String name(); 18 | 19 | Class fallback() default Void.class; 20 | 21 | boolean primary() default true; 22 | 23 | Class[] interceptors() default {}; 24 | 25 | Class[] webClientCustomizers() default {}; 26 | 27 | Class[] codecCustomizers() default {}; 28 | 29 | Class[] tcpClientCustomizers() default {}; 30 | 31 | Class errorResolver() default DefaultApiErrorResolver.class; 32 | 33 | } 34 | -------------------------------------------------------------------------------- /blibli-backend-framework-api-client/src/main/java/com/blibli/oss/backend/apiclient/body/FormBodyResolver.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.apiclient.body; 2 | 3 | import org.springframework.http.MediaType; 4 | import org.springframework.http.client.reactive.ClientHttpRequest; 5 | import org.springframework.util.MultiValueMap; 6 | import org.springframework.web.bind.annotation.RequestBody; 7 | import org.springframework.web.reactive.function.BodyInserter; 8 | import org.springframework.web.reactive.function.BodyInserters; 9 | 10 | import java.lang.reflect.Method; 11 | import java.lang.reflect.Parameter; 12 | 13 | public class FormBodyResolver implements ApiBodyResolver { 14 | 15 | @Override 16 | public boolean canResolve(String contentType) { 17 | return MediaType.APPLICATION_FORM_URLENCODED_VALUE.equals(contentType); 18 | } 19 | 20 | @Override 21 | public BodyInserter resolve(Method method, Object[] arguments) { 22 | Parameter[] parameters = method.getParameters(); 23 | for (int i = 0; i < parameters.length; i++) { 24 | Parameter parameter = parameters[i]; 25 | RequestBody requestBody = parameter.getAnnotation(RequestBody.class); 26 | if (requestBody != null) { 27 | return BodyInserters.fromFormData((MultiValueMap) arguments[i]); 28 | } 29 | } 30 | return null; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /blibli-backend-framework-internal-api/src/main/java/com/blibli/oss/backend/internalapi/InternalApiConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.internalapi; 2 | 3 | import com.blibli.oss.backend.internalapi.properties.InternalApiProperties; 4 | import com.blibli.oss.backend.internalapi.resolver.InternalSessionArgumentResolver; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Configuration; 9 | import org.springframework.web.reactive.config.WebFluxConfigurer; 10 | import org.springframework.web.reactive.result.method.annotation.ArgumentResolverConfigurer; 11 | 12 | @Configuration 13 | @EnableConfigurationProperties({ 14 | InternalApiProperties.class 15 | }) 16 | public class InternalApiConfiguration implements WebFluxConfigurer { 17 | 18 | @Autowired 19 | private InternalApiProperties internalApiProperties; 20 | 21 | @Bean 22 | public InternalSessionArgumentResolver internalSessionArgumentResolver() { 23 | return new InternalSessionArgumentResolver(internalApiProperties); 24 | } 25 | 26 | @Override 27 | public void configureArgumentResolvers(ArgumentResolverConfigurer configurer) { 28 | configurer.addCustomResolver(internalSessionArgumentResolver()); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /blibli-backend-framework-sleuth/src/main/java/com/blibli/oss/backend/sleuth/webflux/SleuthWebFilter.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.sleuth.webflux; 2 | 3 | import brave.Span; 4 | import brave.Tracer; 5 | import org.springframework.cloud.sleuth.instrument.web.TraceWebFilter; 6 | import org.springframework.core.Ordered; 7 | import org.springframework.web.server.ServerWebExchange; 8 | import org.springframework.web.server.WebFilter; 9 | import org.springframework.web.server.WebFilterChain; 10 | import reactor.core.publisher.Mono; 11 | 12 | import java.util.Objects; 13 | 14 | public interface SleuthWebFilter extends WebFilter, Ordered { 15 | 16 | @Override 17 | default int getOrder() { 18 | return Ordered.HIGHEST_PRECEDENCE + 10; 19 | } 20 | 21 | default Span getCurrentSpan(ServerWebExchange exchange) { 22 | Span span = getTracer().currentSpan(); 23 | if (Objects.isNull(span)) { 24 | span = exchange.getAttribute(TraceWebFilter.class.getName() + ".TRACE"); 25 | } 26 | return span; 27 | } 28 | 29 | @Override 30 | default Mono filter(ServerWebExchange exchange, WebFilterChain chain) { 31 | return Mono.fromCallable(() -> getCurrentSpan(exchange)) 32 | .flatMap(span -> filter(exchange, chain, span)); 33 | } 34 | 35 | Tracer getTracer(); 36 | 37 | Mono filter(ServerWebExchange exchange, WebFilterChain chain, Span currentSpan); 38 | } 39 | -------------------------------------------------------------------------------- /blibli-backend-framework-common/src/main/java/com/blibli/oss/backend/common/CommonWebFluxAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.common; 2 | 3 | import com.blibli.oss.backend.common.properties.PagingProperties; 4 | import com.blibli.oss.backend.common.webflux.PagingRequestArgumentResolver; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.autoconfigure.AutoConfigureAfter; 7 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 8 | import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; 9 | import org.springframework.context.annotation.Configuration; 10 | import org.springframework.web.reactive.config.WebFluxConfigurer; 11 | import org.springframework.web.reactive.result.method.annotation.ArgumentResolverConfigurer; 12 | 13 | @Configuration 14 | @ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE) 15 | @ConditionalOnClass(WebFluxConfigurer.class) 16 | @AutoConfigureAfter(CommonAutoConfiguration.class) 17 | public class CommonWebFluxAutoConfiguration implements WebFluxConfigurer { 18 | 19 | @Autowired 20 | private PagingProperties pagingProperties; 21 | 22 | @Override 23 | public void configureArgumentResolvers(ArgumentResolverConfigurer configurer) { 24 | configurer.addCustomResolver(new PagingRequestArgumentResolver(pagingProperties)); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /blibli-backend-framework-command/src/main/java/com/blibli/oss/backend/command/configuration/CommandCacheAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.command.configuration; 2 | 3 | import com.blibli.oss.backend.command.cache.CommandCacheInterceptor; 4 | import com.blibli.oss.backend.command.properties.CommandProperties; 5 | import com.fasterxml.jackson.databind.ObjectMapper; 6 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Configuration; 9 | import org.springframework.data.redis.core.ReactiveStringRedisTemplate; 10 | 11 | @Configuration 12 | @ConditionalOnProperty(value = "blibli.backend.command.cache.enabled", havingValue = "true") 13 | public class CommandCacheAutoConfiguration { 14 | 15 | @Bean 16 | public CommandCacheInterceptor commandCacheInterceptor(ObjectMapper objectMapper, 17 | ReactiveStringRedisTemplate redisTemplate, 18 | CommandProperties commandProperties) { 19 | CommandCacheInterceptor interceptor = new CommandCacheInterceptor(); 20 | interceptor.setObjectMapper(objectMapper); 21 | interceptor.setRedisTemplate(redisTemplate); 22 | interceptor.setCommandProperties(commandProperties); 23 | return interceptor; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /blibli-backend-framework-external-api/src/main/java/com/blibli/oss/backend/externalapi/sleuth/ExternalApiSleuthConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.externalapi.sleuth; 2 | 3 | import brave.Tracer; 4 | import com.blibli.oss.backend.externalapi.ExternalApiConfiguration; 5 | import com.blibli.oss.backend.sleuth.configuration.SleuthConfiguration; 6 | import org.springframework.boot.autoconfigure.AutoConfigureAfter; 7 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 8 | import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; 9 | import org.springframework.context.annotation.Bean; 10 | import org.springframework.context.annotation.Configuration; 11 | import org.springframework.web.reactive.config.WebFluxConfigurer; 12 | 13 | @Configuration 14 | @ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE) 15 | @ConditionalOnClass({WebFluxConfigurer.class, SleuthConfiguration.class}) 16 | @AutoConfigureAfter({SleuthConfiguration.class, ExternalApiConfiguration.class}) 17 | public class ExternalApiSleuthConfiguration { 18 | 19 | @Bean 20 | public ExternalSessionExtraFields externalSessionExtraFields() { 21 | return new ExternalSessionExtraFields(); 22 | } 23 | 24 | @Bean 25 | public ExternalSessionSleuthEventListener externalSessionSleuthEventListener(Tracer tracer) { 26 | return new ExternalSessionSleuthEventListener(tracer); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /blibli-backend-framework-internal-api/src/main/java/com/blibli/oss/backend/internalapi/sleuth/InternalApiSleuthConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.internalapi.sleuth; 2 | 3 | import brave.Tracer; 4 | import com.blibli.oss.backend.internalapi.InternalApiConfiguration; 5 | import com.blibli.oss.backend.sleuth.configuration.SleuthConfiguration; 6 | import org.springframework.boot.autoconfigure.AutoConfigureAfter; 7 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 8 | import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; 9 | import org.springframework.context.annotation.Bean; 10 | import org.springframework.context.annotation.Configuration; 11 | import org.springframework.web.reactive.config.WebFluxConfigurer; 12 | 13 | @Configuration 14 | @ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE) 15 | @ConditionalOnClass({WebFluxConfigurer.class, SleuthConfiguration.class}) 16 | @AutoConfigureAfter({SleuthConfiguration.class, InternalApiConfiguration.class}) 17 | public class InternalApiSleuthConfiguration { 18 | 19 | @Bean 20 | public InternalSessionExtraFields externalSessionExtraFields() { 21 | return new InternalSessionExtraFields(); 22 | } 23 | 24 | @Bean 25 | public InternalSessionSleuthEventListener externalSessionSleuthEventListener(Tracer tracer) { 26 | return new InternalSessionSleuthEventListener(tracer); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /blibli-backend-framework-newrelic/README.md: -------------------------------------------------------------------------------- 1 | # Reactor New Relic Instrumentation 2 | 3 | A plugin to enable new relic instrumentation in Spring Boot 2 Webflux App. 4 | 5 | List of supported modules: 6 | - command-plugin: anything that implement `Command` interface. 7 | - spring-reactive-mongo: ReactiveMongoRepository all inherited method and custom query. 8 | 9 | Planned future modules: 10 | - Reactive relational DB (via R2DBC) 11 | - Reactive elastic search 12 | - Reactive redis 13 | 14 | ## How to use 15 | 16 | 1. Include the library in your POM. 17 | 18 | ``` 19 | 20 | com.blibli.oss 21 | blibli-backend-framework-newrelic 22 | 23 | ``` 24 | 25 | And viola! See your app instrumented in New Relic. 26 | 27 | ![New Relic instrumentation](docs/newrelic-sample.png) 28 | 29 | ## How it works 30 | 31 | 1. Inject new relic Token and Transaction for every web request in reactor Context. See `NewRelicTokenInjectorFilter` filter class. 32 | 2. When code is entering a known module (targeted by our AOP pointcut), then append additional reactor operator to time those method execution using New Relic `Transaction.startSegment()`. 33 | 34 | ## Known issues 35 | 36 | - Command timing report will include ReactiveMongoRepository timing. 37 | - There are still "Remainder" time on New Relic report. It may caused by the time the thread waiting until executed by Spring thread pool because of traffic congestion. 38 | -------------------------------------------------------------------------------- /blibli-backend-framework-newrelic/src/main/java/com/blibli/oss/backend/newrelic/aspect/service/util/MongoUriParser.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.newrelic.aspect.service.util; 2 | 3 | import org.springframework.boot.autoconfigure.mongo.MongoProperties; 4 | 5 | import java.util.Optional; 6 | import java.util.regex.Matcher; 7 | import java.util.regex.Pattern; 8 | 9 | public class MongoUriParser { 10 | 11 | // mongodb://[username:password@]host1[:port1][,...hostN[:portN]][/[defaultauthdb][?options]] 12 | private static final String MONGO_CREDENTIALS_PATTERN = "([^:]+:[^@]+@)?"; 13 | private static final String MONGO_HOST_PORT_PATTERN = "[^@:,/]+(:[\\d]+)?"; 14 | private static final String MONGO_HOST_PORT_OTHERS_PATTERN = "(,[^@:,/]+(:[\\d]+)?)*"; 15 | private static final String MONGO_DB_OPTIONS_PATTERN = "(/.*)?"; 16 | 17 | private static final Pattern MONGO_URI_PATTERN = Pattern.compile(String.format("^mongodb://%s(%s%s)%s$", 18 | MONGO_CREDENTIALS_PATTERN, MONGO_HOST_PORT_PATTERN, MONGO_HOST_PORT_OTHERS_PATTERN, MONGO_DB_OPTIONS_PATTERN)); 19 | 20 | public static String[] getHosts(String mongoUri) { 21 | Matcher m = MONGO_URI_PATTERN.matcher(mongoUri); 22 | 23 | if (m.find()) { 24 | return Optional.ofNullable(m.group(2)) 25 | .map(hosts -> hosts.split(",")) 26 | .orElseThrow(() -> new RuntimeException("unsupported mongo uri")); 27 | } else { 28 | throw new RuntimeException("unsupported mongo uri"); 29 | } 30 | } 31 | 32 | 33 | } 34 | -------------------------------------------------------------------------------- /blibli-backend-framework-api-client/src/main/java/com/blibli/oss/backend/apiclient/body/JsonBodyResolver.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.apiclient.body; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import org.springframework.http.MediaType; 5 | import org.springframework.http.client.reactive.ClientHttpRequest; 6 | import org.springframework.web.bind.annotation.RequestBody; 7 | import org.springframework.web.reactive.function.BodyInserter; 8 | import org.springframework.web.reactive.function.BodyInserters; 9 | 10 | import java.lang.reflect.Method; 11 | import java.lang.reflect.Parameter; 12 | 13 | public class JsonBodyResolver implements ApiBodyResolver { 14 | 15 | private ObjectMapper objectMapper; 16 | 17 | public JsonBodyResolver(ObjectMapper objectMapper) { 18 | this.objectMapper = objectMapper; 19 | } 20 | 21 | @Override 22 | public boolean canResolve(String contentType) { 23 | return MediaType.APPLICATION_JSON_VALUE.equals(contentType); 24 | } 25 | 26 | @Override 27 | public BodyInserter resolve(Method method, Object[] arguments) { 28 | Parameter[] parameters = method.getParameters(); 29 | for (int i = 0; i < parameters.length; i++) { 30 | Parameter parameter = parameters[i]; 31 | RequestBody requestBody = parameter.getAnnotation(RequestBody.class); 32 | if (requestBody != null) { 33 | return BodyInserters.fromValue(arguments[i]); 34 | } 35 | } 36 | return null; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /blibli-backend-framework-newrelic/src/main/java/com/blibli/oss/backend/newrelic/configuration/NewRelicReactorInstrumentationAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.newrelic.configuration; 2 | 3 | import com.blibli.oss.backend.newrelic.aspect.CommandAspect; 4 | import com.blibli.oss.backend.newrelic.aspect.service.AspectModifyService; 5 | import com.blibli.oss.backend.newrelic.aspect.service.impl.AspectModifyServiceImpl; 6 | import com.blibli.oss.backend.newrelic.injector.NewRelicTokenInjectorFilter; 7 | import com.newrelic.api.agent.Agent; 8 | import com.newrelic.api.agent.NewRelic; 9 | import lombok.extern.slf4j.Slf4j; 10 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 11 | import org.springframework.context.annotation.Bean; 12 | import org.springframework.context.annotation.Configuration; 13 | import org.springframework.context.annotation.Import; 14 | 15 | @Configuration 16 | @Slf4j 17 | @Import(CommandAspect.class) 18 | public class NewRelicReactorInstrumentationAutoConfiguration { 19 | 20 | @Bean 21 | @ConditionalOnMissingBean 22 | public Agent newRelicAgent() { 23 | return NewRelic.getAgent(); 24 | } 25 | 26 | @Bean 27 | public NewRelicTokenInjectorFilter newRelicFilter(Agent agent) { 28 | log.debug("Creating NewRelicTokenInjectorFilter bean"); 29 | return new NewRelicTokenInjectorFilter(agent); 30 | } 31 | 32 | @Bean 33 | public AspectModifyService aspectModifyService() { 34 | return new AspectModifyServiceImpl(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /blibli-backend-framework-mandatory-parameter/src/main/java/com/blibli/oss/backend/mandatoryparameter/webflux/MandatoryParameterWebFluxAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.mandatoryparameter.webflux; 2 | 3 | import com.blibli.oss.backend.mandatoryparameter.MandatoryParameterAutoConfiguration; 4 | import com.blibli.oss.backend.mandatoryparameter.swagger.properties.MandatoryParameterProperties; 5 | import lombok.AllArgsConstructor; 6 | import org.springframework.boot.autoconfigure.AutoConfigureAfter; 7 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 8 | import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; 9 | import org.springframework.context.annotation.Configuration; 10 | import org.springframework.web.reactive.config.WebFluxConfigurer; 11 | import org.springframework.web.reactive.result.method.annotation.ArgumentResolverConfigurer; 12 | 13 | @AllArgsConstructor 14 | @Configuration 15 | @ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE) 16 | @ConditionalOnClass(WebFluxConfigurer.class) 17 | @AutoConfigureAfter(MandatoryParameterAutoConfiguration.class) 18 | public class MandatoryParameterWebFluxAutoConfiguration implements WebFluxConfigurer { 19 | 20 | private final MandatoryParameterProperties properties; 21 | 22 | @Override 23 | public void configureArgumentResolvers(ArgumentResolverConfigurer configurer) { 24 | configurer.addCustomResolver(new MandatoryParameterHandlerMethodArgumentResolver(properties)); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /blibli-backend-framework-version/README.md: -------------------------------------------------------------------------------- 1 | # Version Module 2 | 3 | Version module is library to generate standard version information on Blibli.com backend application. 4 | 5 | ## Setup Dependency 6 | 7 | ```xml 8 | 9 | com.blibli.oss 10 | blibli-backend-framework-version 11 | 12 | ``` 13 | 14 | ## Setup Properties 15 | 16 | Version Module will read `version.properties` on resources packages. And we can use maven resource plugin to replace value on `version.properties` file. 17 | 18 | ```properties 19 | blibli.backend.version.group-id=@project.groupId@ 20 | blibli.backend.version.artifact-id=@project.artifactId@ 21 | blibli.backend.version.version=@project.version@ 22 | blibli.backend.version.build-time=@maven.build.timestamp@ 23 | ``` 24 | 25 | And on the `pom.xml`, we can setup configuration 26 | 27 | ```xml 28 | 29 | yyyy-MM-dd HH:mm:ss 30 | 31 | 32 | 33 | 34 | 35 | src/main/resources 36 | true 37 | 38 | 39 | 40 | ``` 41 | 42 | ## Version Controller 43 | 44 | This module will automatically create controller with route `/version`. 45 | 46 | ``` 47 | GET /version 48 | 49 | maven.groupId=com.blibli.oss.backend.example 50 | maven.artifactId=example-app 51 | maven.pom.version=0.0.1-SNAPSHOT 52 | maven.build.time=2020-02-20 07:38:01 53 | ``` 54 | -------------------------------------------------------------------------------- /blibli-backend-framework-swagger/src/main/java/com/blibli/oss/backend/swagger/factory/IgnoredParameterAnnotationsFactoryBean.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.swagger.factory; 2 | 3 | import com.blibli.oss.backend.swagger.api.SwaggerIgnoredParameter; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Setter; 6 | import org.springdoc.core.IgnoredParameterAnnotations; 7 | import org.springframework.beans.factory.FactoryBean; 8 | 9 | import java.lang.reflect.Parameter; 10 | import java.util.List; 11 | 12 | public class IgnoredParameterAnnotationsFactoryBean implements FactoryBean { 13 | 14 | @Setter 15 | private List swaggerIgnoredParameters; 16 | 17 | @Override 18 | public IgnoredParameterAnnotations getObject() throws Exception { 19 | return new SwaggerIgnoredParameterAnnotations(swaggerIgnoredParameters); 20 | } 21 | 22 | @Override 23 | public Class getObjectType() { 24 | return IgnoredParameterAnnotations.class; 25 | } 26 | 27 | @AllArgsConstructor 28 | public static class SwaggerIgnoredParameterAnnotations implements IgnoredParameterAnnotations { 29 | 30 | private List swaggerIgnoredParameters; 31 | 32 | @Override 33 | public boolean isAnnotationToIgnore(Parameter parameter) { 34 | for (SwaggerIgnoredParameter swaggerIgnoredParameter : swaggerIgnoredParameters) { 35 | if (swaggerIgnoredParameter.isIgnored(parameter)) { 36 | return true; 37 | } 38 | } 39 | return false; 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /blibli-backend-framework-kafka/src/main/java/com/blibli/oss/backend/kafka/repository/KafkaRepository.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.kafka.repository; 2 | 3 | import com.blibli.oss.backend.kafka.producer.KafkaProducer; 4 | import org.springframework.kafka.support.SendResult; 5 | import reactor.core.Disposable; 6 | import reactor.core.publisher.Mono; 7 | import reactor.core.scheduler.Scheduler; 8 | 9 | public interface KafkaRepository extends KafkaKeyAnnotationAware, KafkaTopicAnnotationAware { 10 | 11 | KafkaProducer getKafkaProducer(); 12 | 13 | default Mono> send(T data) { 14 | return send(getTopic(data), data); 15 | } 16 | 17 | default Mono> send(String topic, T data) { 18 | return getKafkaProducer().send(topic, getKey(data), data); 19 | } 20 | 21 | default Mono> sendOn(T data, Scheduler scheduler) { 22 | return getKafkaProducer().sendOn(getTopic(data), getKey(data), data, scheduler); 23 | } 24 | 25 | default Mono> sendOn(String topic, T data, Scheduler scheduler) { 26 | return getKafkaProducer().sendOn(topic, getKey(data), data, scheduler); 27 | } 28 | 29 | default Disposable sendAndSubscribe(T data, Scheduler scheduler) { 30 | return getKafkaProducer().sendAndSubscribe(getTopic(data), getKey(data), data, scheduler); 31 | } 32 | 33 | default Disposable sendAndSubscribe(String topic, T data, Scheduler scheduler) { 34 | return getKafkaProducer().sendAndSubscribe(topic, getKey(data), data, scheduler); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /blibli-backend-framework-api-client/src/main/java/com/blibli/oss/backend/apiclient/sleuth/SleuthGlobalApiClientInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.apiclient.sleuth; 2 | 3 | import brave.Tracer; 4 | import brave.propagation.ExtraFieldPropagation; 5 | import com.blibli.oss.backend.apiclient.interceptor.GlobalApiClientInterceptor; 6 | import com.blibli.oss.backend.apiclient.properties.ApiClientProperties; 7 | import com.blibli.oss.backend.sleuth.configuration.SleuthConfiguration; 8 | import lombok.AllArgsConstructor; 9 | import org.springframework.web.reactive.function.client.ClientRequest; 10 | import org.springframework.web.reactive.function.client.ClientResponse; 11 | import org.springframework.web.reactive.function.client.ExchangeFunction; 12 | import reactor.core.publisher.Mono; 13 | 14 | @AllArgsConstructor 15 | public class SleuthGlobalApiClientInterceptor implements GlobalApiClientInterceptor { 16 | 17 | private ApiClientProperties properties; 18 | 19 | private Tracer tracer; 20 | 21 | @Override 22 | public Mono filter(ClientRequest request, ExchangeFunction next) { 23 | if (properties.getSleuth().isEnabled() && tracer.currentSpan() != null) { 24 | return Mono.fromCallable(() -> { 25 | ClientRequest.Builder builder = ClientRequest.from(request); 26 | ExtraFieldPropagation.getAll(tracer.currentSpan().context()).forEach((key, value) -> { 27 | builder.header(SleuthConfiguration.HTTP_BAGGAGE_PREFIX + key, value); 28 | }); 29 | return builder.build(); 30 | }).flatMap(next::exchange); 31 | } else { 32 | return next.exchange(request); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /blibli-backend-framework-newrelic/src/main/java/com/blibli/oss/backend/newrelic/aspect/CommandAspect.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.newrelic.aspect; 2 | 3 | import com.blibli.oss.backend.command.Command; 4 | import com.blibli.oss.backend.newrelic.aspect.service.AspectModifyService; 5 | import com.blibli.oss.backend.newrelic.aspect.service.util.SegmentType; 6 | import lombok.AllArgsConstructor; 7 | import org.aspectj.lang.ProceedingJoinPoint; 8 | import org.aspectj.lang.annotation.Around; 9 | import org.aspectj.lang.annotation.Aspect; 10 | import org.aspectj.lang.annotation.Pointcut; 11 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 12 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; 13 | import org.springframework.context.annotation.Configuration; 14 | 15 | /** 16 | * Aspect to target Blibli Command plugin for timing with New Relic Segment. 17 | */ 18 | @Aspect 19 | @Configuration 20 | @ConditionalOnClass(Command.class) 21 | @ConditionalOnProperty( 22 | prefix = "blibli.newrelic.command", 23 | name = "enabled", 24 | matchIfMissing = true 25 | ) 26 | @AllArgsConstructor 27 | public class CommandAspect { 28 | 29 | private AspectModifyService aspectModifyService; 30 | 31 | @Pointcut("execution(* com.blibli.oss.backend.command.Command.execute(..))") 32 | private void commandExecute() {} 33 | 34 | @Around(value = "commandExecute()") 35 | public Object afterCommandExecute(ProceedingJoinPoint proceedingJoinPoint) throws Throwable { 36 | return aspectModifyService.modifyRetValWithTiming( 37 | proceedingJoinPoint, SegmentType.COMMAND 38 | ); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /blibli-backend-framework-version/src/test/java/com/blibli/oss/backend/version/VersionControllerTest.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.version; 2 | 3 | import org.junit.jupiter.api.Assertions; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.extension.ExtendWith; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.boot.autoconfigure.SpringBootApplication; 8 | import org.springframework.boot.test.context.SpringBootTest; 9 | import org.springframework.test.context.junit.jupiter.SpringExtension; 10 | import org.springframework.test.web.reactive.server.WebTestClient; 11 | 12 | import java.util.Objects; 13 | 14 | @ExtendWith(SpringExtension.class) 15 | @SpringBootTest( 16 | classes = VersionControllerTest.Application.class, 17 | webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT 18 | ) 19 | public class VersionControllerTest { 20 | 21 | @Autowired 22 | private WebTestClient webTestClient; 23 | 24 | @Test 25 | void testVersion() { 26 | webTestClient.get().uri("/version") 27 | .exchange() 28 | .expectStatus().is2xxSuccessful() 29 | .expectBody().consumeWith(result -> { 30 | String response = new String(Objects.requireNonNull(result.getResponseBody())); 31 | Assertions.assertTrue(response.contains("maven.groupId=")); 32 | Assertions.assertTrue(response.contains("maven.artifactId=")); 33 | Assertions.assertTrue(response.contains("maven.pom.version=")); 34 | Assertions.assertTrue(response.contains("maven.build.time=")); 35 | }); 36 | } 37 | 38 | @SpringBootApplication 39 | public static class Application { 40 | 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /blibli-backend-framework-mandatory-parameter/src/main/java/com/blibli/oss/backend/mandatoryparameter/sleuth/MandatoryParameterSleuthAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.mandatoryparameter.sleuth; 2 | 3 | import brave.Tracer; 4 | import com.blibli.oss.backend.mandatoryparameter.swagger.properties.MandatoryParameterProperties; 5 | import com.blibli.oss.backend.sleuth.configuration.SleuthConfiguration; 6 | import org.springframework.boot.autoconfigure.AutoConfigureAfter; 7 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 8 | import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; 9 | import org.springframework.context.annotation.Bean; 10 | import org.springframework.context.annotation.Configuration; 11 | import org.springframework.web.reactive.config.WebFluxConfigurer; 12 | 13 | @Configuration 14 | @ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE) 15 | @ConditionalOnClass({WebFluxConfigurer.class, SleuthConfiguration.class}) 16 | @AutoConfigureAfter(SleuthConfiguration.class) 17 | public class MandatoryParameterSleuthAutoConfiguration { 18 | 19 | @Bean 20 | public MandatoryParameterSleuthExtraFields mandatoryParameterSleuthExtraFields() { 21 | return new MandatoryParameterSleuthExtraFields(); 22 | } 23 | 24 | @Bean 25 | public MandatoryParameterSleuthWebFilter mandatoryParameterSleuthWebFilter(MandatoryParameterProperties mandatoryParameterProperties, 26 | Tracer tracer) { 27 | return new MandatoryParameterSleuthWebFilter(mandatoryParameterProperties, tracer); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /blibli-backend-framework-api-client/src/main/java/com/blibli/oss/backend/apiclient/configuration/ApiClientConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.apiclient.configuration; 2 | 3 | import com.blibli.oss.backend.apiclient.body.FormBodyResolver; 4 | import com.blibli.oss.backend.apiclient.body.JsonBodyResolver; 5 | import com.blibli.oss.backend.apiclient.body.MultipartBodyResolver; 6 | import com.blibli.oss.backend.apiclient.error.DefaultApiErrorResolver; 7 | import com.blibli.oss.backend.apiclient.properties.ApiClientProperties; 8 | import com.fasterxml.jackson.databind.ObjectMapper; 9 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 10 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 11 | import org.springframework.context.annotation.Bean; 12 | import org.springframework.context.annotation.Configuration; 13 | 14 | @Configuration 15 | @EnableConfigurationProperties({ 16 | ApiClientProperties.class 17 | }) 18 | public class ApiClientConfiguration { 19 | 20 | @Bean 21 | @ConditionalOnMissingBean 22 | public FormBodyResolver formBodyResolver() { 23 | return new FormBodyResolver(); 24 | } 25 | 26 | @Bean 27 | @ConditionalOnMissingBean 28 | public MultipartBodyResolver multipartBodyResolver() { 29 | return new MultipartBodyResolver(); 30 | } 31 | 32 | @Bean 33 | @ConditionalOnMissingBean 34 | public JsonBodyResolver jsonBodyResolver(ObjectMapper objectMapper) { 35 | return new JsonBodyResolver(objectMapper); 36 | } 37 | 38 | @Bean 39 | @ConditionalOnMissingBean 40 | public DefaultApiErrorResolver defaultApiErrorResolver() { 41 | return new DefaultApiErrorResolver(); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /blibli-backend-framework-api-client/src/main/java/com/blibli/oss/backend/apiclient/aop/RequestMappingMetadata.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.apiclient.aop; 2 | 3 | import com.blibli.oss.backend.apiclient.properties.ApiClientProperties; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Builder; 6 | import lombok.Data; 7 | import lombok.NoArgsConstructor; 8 | import org.springframework.util.MultiValueMap; 9 | import org.springframework.web.bind.annotation.RequestMethod; 10 | 11 | import java.lang.reflect.Method; 12 | import java.lang.reflect.Type; 13 | import java.util.HashMap; 14 | import java.util.Map; 15 | 16 | @Data 17 | @Builder 18 | @AllArgsConstructor 19 | @NoArgsConstructor 20 | public class RequestMappingMetadata { 21 | 22 | private Map methods; 23 | 24 | private Object fallback; 25 | 26 | private ApiClientProperties.ApiClientConfigProperties properties; 27 | 28 | private Map> headers = new HashMap<>(); 29 | 30 | private Map apiUrlPositions = new HashMap<>(); 31 | 32 | private Map> queryParamPositions = new HashMap<>(); 33 | 34 | private Map> headerParamPositions = new HashMap<>(); 35 | 36 | private Map> cookieParamPositions = new HashMap<>(); 37 | 38 | private Map> pathVariablePositions = new HashMap<>(); 39 | 40 | private Map requestMethods = new HashMap<>(); 41 | 42 | private Map paths = new HashMap<>(); 43 | 44 | private Map responseBodyClasses = new HashMap<>(); 45 | 46 | private Map contentTypes = new HashMap<>(); 47 | 48 | } 49 | -------------------------------------------------------------------------------- /blibli-backend-framework-mandatory-parameter/src/main/java/com/blibli/oss/backend/mandatoryparameter/apiclient/MandatoryParameterApiClientAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.mandatoryparameter.apiclient; 2 | 3 | import brave.Tracer; 4 | import com.blibli.oss.backend.apiclient.configuration.ApiClientConfiguration; 5 | import com.blibli.oss.backend.mandatoryparameter.MandatoryParameterAutoConfiguration; 6 | import com.blibli.oss.backend.mandatoryparameter.swagger.properties.MandatoryParameterProperties; 7 | import com.blibli.oss.backend.sleuth.configuration.SleuthConfiguration; 8 | import org.springframework.boot.autoconfigure.AutoConfigureAfter; 9 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 10 | import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; 11 | import org.springframework.context.annotation.Bean; 12 | import org.springframework.context.annotation.Configuration; 13 | import org.springframework.web.reactive.config.WebFluxConfigurer; 14 | 15 | @Configuration 16 | @ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE) 17 | @ConditionalOnClass({WebFluxConfigurer.class, SleuthConfiguration.class, ApiClientConfiguration.class}) 18 | @AutoConfigureAfter({MandatoryParameterAutoConfiguration.class, SleuthConfiguration.class, ApiClientConfiguration.class}) 19 | public class MandatoryParameterApiClientAutoConfiguration { 20 | 21 | @Bean 22 | public MandatoryParameterApiClientInterceptor mandatoryParameterApiClientInterceptor(MandatoryParameterProperties properties, 23 | Tracer tracer) { 24 | return new MandatoryParameterApiClientInterceptor(properties, tracer); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /blibli-backend-framework-reactor/src/test/java/com/blibli/oss/backend/reactor/scheduler/SchedulerTest.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.reactor.scheduler; 2 | 3 | import org.junit.jupiter.api.Assertions; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.extension.ExtendWith; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.boot.autoconfigure.SpringBootApplication; 8 | import org.springframework.boot.test.context.SpringBootTest; 9 | import org.springframework.test.context.junit.jupiter.SpringExtension; 10 | 11 | @ExtendWith(SpringExtension.class) 12 | @SpringBootTest(classes = SchedulerTest.Application.class) 13 | public class SchedulerTest { 14 | 15 | @Autowired 16 | private SchedulerHelper schedulerHelper; 17 | 18 | @Test 19 | void testScheduler() { 20 | Assertions.assertNotNull(schedulerHelper.of("SINGLE")); 21 | Assertions.assertNotNull(schedulerHelper.of("PARALLEL")); 22 | Assertions.assertNotNull(schedulerHelper.of("IMMEDIATE")); 23 | Assertions.assertNotNull(schedulerHelper.of("ELASTIC")); 24 | Assertions.assertNotNull(schedulerHelper.of("NEW_ELASTIC")); 25 | Assertions.assertNotNull(schedulerHelper.of("NEW_SINGLE")); 26 | Assertions.assertNotNull(schedulerHelper.of("NEW_PARALLEL")); 27 | Assertions.assertNotNull(schedulerHelper.of("EXECUTOR_SINGLE_THREAD_POOL")); 28 | Assertions.assertNotNull(schedulerHelper.of("EXECUTOR_WORK_STEALING_POOL")); 29 | Assertions.assertNotNull(schedulerHelper.of("EXECUTOR_CACHE_THREAD_POOL")); 30 | Assertions.assertNotNull(schedulerHelper.of("EXECUTOR_FIXED_THREAD_POOL")); 31 | Assertions.assertNotNull(schedulerHelper.of("THREAD_POOL")); 32 | } 33 | 34 | @SpringBootApplication 35 | public static class Application { 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /blibli-backend-framework-api-client/src/main/java/com/blibli/oss/backend/apiclient/properties/PropertiesHelper.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.apiclient.properties; 2 | 3 | import java.util.Objects; 4 | 5 | public class PropertiesHelper { 6 | 7 | public static void copyConfigProperties(ApiClientProperties.ApiClientConfigProperties source, 8 | ApiClientProperties.ApiClientConfigProperties target) { 9 | if (source != null) { 10 | 11 | if (Objects.nonNull(source.getUrl())) { 12 | target.setUrl(source.getUrl()); 13 | } 14 | 15 | if (Objects.nonNull(source.getFallback())) { 16 | target.setFallback(source.getFallback()); 17 | } 18 | 19 | if (Objects.nonNull(source.getReadTimeout())) { 20 | target.setReadTimeout(source.getReadTimeout()); 21 | } 22 | 23 | if (Objects.nonNull(source.getConnectTimeout())) { 24 | target.setConnectTimeout(source.getConnectTimeout()); 25 | } 26 | 27 | if (Objects.nonNull(source.getWriteTimeout())) { 28 | target.setWriteTimeout(source.getWriteTimeout()); 29 | } 30 | 31 | source.getHeaders().forEach((key, value) -> target.getHeaders().put(key, value)); 32 | 33 | source.getInterceptors().forEach(aClass -> target.getInterceptors().add(aClass)); 34 | 35 | source.getWebClientCustomizers().forEach(aClass -> target.getWebClientCustomizers().add(aClass)); 36 | 37 | source.getCodecCustomizers().forEach(aClass -> target.getCodecCustomizers().add(aClass)); 38 | 39 | source.getTcpClientCustomizers().forEach(aClass -> target.getTcpClientCustomizers().add(aClass)); 40 | 41 | if (Objects.nonNull(source.getErrorResolver())) { 42 | target.setErrorResolver(source.getErrorResolver()); 43 | } 44 | } 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /blibli-backend-framework-api-client/src/main/java/com/blibli/oss/backend/apiclient/body/MultipartBodyResolver.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.apiclient.body; 2 | 3 | import org.springframework.http.HttpEntity; 4 | import org.springframework.http.MediaType; 5 | import org.springframework.http.client.MultipartBodyBuilder; 6 | import org.springframework.http.client.reactive.ClientHttpRequest; 7 | import org.springframework.util.MultiValueMap; 8 | import org.springframework.util.StringUtils; 9 | import org.springframework.web.bind.annotation.RequestPart; 10 | import org.springframework.web.reactive.function.BodyInserter; 11 | import org.springframework.web.reactive.function.BodyInserters; 12 | 13 | import java.lang.reflect.Method; 14 | import java.lang.reflect.Parameter; 15 | 16 | public class MultipartBodyResolver implements ApiBodyResolver { 17 | 18 | @Override 19 | public boolean canResolve(String contentType) { 20 | return MediaType.MULTIPART_FORM_DATA_VALUE.equals(contentType); 21 | } 22 | 23 | @Override 24 | public BodyInserter resolve(Method method, Object[] arguments) { 25 | Parameter[] parameters = method.getParameters(); 26 | MultipartBodyBuilder builder = new MultipartBodyBuilder(); 27 | for (int i = 0; i < parameters.length; i++) { 28 | Parameter parameter = parameters[i]; 29 | RequestPart annotation = parameter.getAnnotation(RequestPart.class); 30 | if (annotation != null) { 31 | String name = StringUtils.isEmpty(annotation.name()) ? annotation.value() : annotation.name(); 32 | builder.part(name, arguments[i]); 33 | } 34 | } 35 | MultiValueMap> multiValueMap = builder.build(); 36 | 37 | if (!multiValueMap.isEmpty()) { 38 | return BodyInserters.fromMultipartData(multiValueMap); 39 | } 40 | return null; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /blibli-backend-framework-kafka/src/main/java/com/blibli/oss/backend/kafka/interceptor/log/LogKafkaConsumerInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.kafka.interceptor.log; 2 | 3 | import com.blibli.oss.backend.kafka.interceptor.KafkaConsumerInterceptor; 4 | import com.blibli.oss.backend.kafka.properties.KafkaProperties; 5 | import lombok.Getter; 6 | import lombok.Setter; 7 | import lombok.extern.slf4j.Slf4j; 8 | import org.apache.kafka.clients.consumer.ConsumerRecord; 9 | import org.springframework.core.Ordered; 10 | 11 | @Slf4j 12 | public class LogKafkaConsumerInterceptor implements KafkaConsumerInterceptor, Ordered { 13 | 14 | @Getter 15 | private final int order = Ordered.HIGHEST_PRECEDENCE; 16 | 17 | @Setter 18 | private KafkaProperties kafkaProperties; 19 | 20 | @Override 21 | public boolean beforeConsume(ConsumerRecord consumerRecord) { 22 | if (kafkaProperties.getLogging().isBeforeConsume()) { 23 | log.info("Receive from topic {} with message {}:{}", consumerRecord.topic(), consumerRecord.key(), consumerRecord.value()); 24 | } 25 | return false; 26 | } 27 | 28 | @Override 29 | public void afterSuccessConsume(ConsumerRecord consumerRecord) { 30 | if (kafkaProperties.getLogging().isAfterSuccessConsume()) { 31 | log.info("Success consume from topic {} with message {}:{}", consumerRecord.topic(), consumerRecord.key(), consumerRecord.value()); 32 | } 33 | } 34 | 35 | @Override 36 | public void afterFailedConsume(ConsumerRecord consumerRecord, Throwable throwable) { 37 | if (kafkaProperties.getLogging().isAfterFailedConsume()) { 38 | log.error(String.format("Failed consume from topic %s with message %s:%s and exception %s", consumerRecord.topic(), consumerRecord.key(), consumerRecord.value(), throwable.getMessage()), throwable); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /blibli-backend-framework-api-client/src/test/java/com/blibli/oss/backend/apiclient/DynamicClientTest.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.apiclient; 2 | 3 | import com.blibli.oss.backend.apiclient.client.DynamicClient; 4 | import com.fasterxml.jackson.core.JsonProcessingException; 5 | import com.github.tomakehurst.wiremock.WireMockServer; 6 | import org.junit.jupiter.api.AfterAll; 7 | import org.junit.jupiter.api.BeforeAll; 8 | import org.junit.jupiter.api.Test; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.boot.test.context.SpringBootTest; 11 | import org.springframework.http.HttpHeaders; 12 | import org.springframework.http.MediaType; 13 | import reactor.test.StepVerifier; 14 | 15 | import static com.github.tomakehurst.wiremock.client.WireMock.*; 16 | 17 | @SpringBootTest(classes = TestApplication.class) 18 | public class DynamicClientTest { 19 | 20 | private static WireMockServer wireMockServer; 21 | 22 | @Autowired 23 | private DynamicClient dynamicClient; 24 | 25 | @BeforeAll 26 | static void beforeAll() { 27 | wireMockServer = new WireMockServer(8089); 28 | wireMockServer.start(); 29 | } 30 | 31 | @Test 32 | void testResponseEntityVoid() throws JsonProcessingException { 33 | wireMockServer.stubFor( 34 | get(urlPathEqualTo("/dynamic")) 35 | .withHeader(HttpHeaders.ACCEPT, equalTo(MediaType.TEXT_PLAIN_VALUE)) 36 | .willReturn( 37 | aResponse() 38 | .withStatus(200) 39 | .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_PLAIN_VALUE) 40 | .withBody("SUCCESS") 41 | ) 42 | ); 43 | 44 | StepVerifier.create(dynamicClient.dynamic("http://localhost:8089")) 45 | .expectNext("SUCCESS") 46 | .verifyComplete(); 47 | } 48 | 49 | @AfterAll 50 | static void afterAll() { 51 | wireMockServer.stop(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /blibli-backend-framework-json/README.md: -------------------------------------------------------------------------------- 1 | # JSON Module 2 | 3 | JSON Module is module to help simplify json library usage. In Spring, by default it use Jackson as json library. 4 | The problem with Jackson is, most of jackson operation is checked exception, so we need to add try catch everywhere. 5 | JSON module will simplify this, this can be used to help us do json manipulation, like transform from json to object or vice versa. 6 | 7 | ## Setup Dependency 8 | 9 | ```xml 10 | 11 | com.blibli.oss 12 | blibli-backend-framework-json 13 | 14 | ``` 15 | 16 | ## Automatic Jackson Configuration 17 | 18 | This module by default will configure some configuration. So we don't need to configure it manually on application properties. 19 | 20 | ```properties 21 | spring.jackson.deserialization.fail-on-unknown-properties=false 22 | spring.jackson.deserialization.fail-on-ignored-properties=false 23 | spring.jackson.deserialization.read-unknown-enum-values-as-null=true 24 | spring.jackson.serialization.fail-on-empty-beans=false 25 | spring.jackson.serialization.write-dates-as-timestamps=true 26 | spring.jackson.serialization.write-empty-json-arrays=true 27 | spring.jackson.default-property-inclusion=non_null 28 | spring.jackson.generator.ignore-unknown=true 29 | spring.jackson.mapper.accept-case-insensitive-enums=true 30 | ``` 31 | 32 | ## JsonHelper Class 33 | 34 | We don't need to use ObjectMapper anymore to manipulate json data. We can use JsonHelper class. 35 | 36 | ```java 37 | 38 | @Autowired 39 | private JsonHelper jsonHelper; 40 | 41 | YourModel model = jsonHelper.fromJson(stringJson, YourModel.class); 42 | Map map = jsonHelper.fromJson(stringJson, new TypeReference>(){}); 43 | 44 | String json = jsonHelper.toJson(model); 45 | ``` 46 | 47 | And we don't need to add try-catch manually anymore. -------------------------------------------------------------------------------- /blibli-backend-framework-common/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | blibli-backend-framework 7 | com.blibli.oss 8 | 0.0.9-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | blibli-backend-framework-common 13 | 14 | 15 | 16 | com.blibli.oss 17 | blibli-backend-framework-swagger 18 | 19 | 20 | org.projectlombok 21 | lombok 22 | true 23 | 24 | 25 | org.springframework.boot 26 | spring-boot-configuration-processor 27 | true 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-webflux 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-validation 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-starter-test 40 | test 41 | 42 | 43 | org.junit.vintage 44 | junit-vintage-engine 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /blibli-backend-framework-external-api/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | blibli-backend-framework 7 | com.blibli.oss 8 | 0.0.9-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | blibli-backend-framework-external-api 13 | 14 | 15 | 16 | com.blibli.oss 17 | blibli-backend-framework-common 18 | 19 | 20 | com.blibli.oss 21 | blibli-backend-framework-sleuth 22 | 23 | 24 | org.projectlombok 25 | lombok 26 | true 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-configuration-processor 31 | true 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-webflux 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-starter-test 40 | test 41 | 42 | 43 | org.junit.vintage 44 | junit-vintage-engine 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /blibli-backend-framework-internal-api/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | blibli-backend-framework 7 | com.blibli.oss 8 | 0.0.9-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | blibli-backend-framework-internal-api 13 | 14 | 15 | 16 | com.blibli.oss 17 | blibli-backend-framework-common 18 | 19 | 20 | com.blibli.oss 21 | blibli-backend-framework-sleuth 22 | 23 | 24 | org.projectlombok 25 | lombok 26 | true 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-configuration-processor 31 | true 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-webflux 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-starter-test 40 | test 41 | 42 | 43 | org.junit.vintage 44 | junit-vintage-engine 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /blibli-backend-framework-reactor/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | blibli-backend-framework 7 | com.blibli.oss 8 | 0.0.9-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | blibli-backend-framework-reactor 13 | 14 | 15 | 16 | org.springframework.boot 17 | spring-boot-starter-webflux 18 | 19 | 20 | io.projectreactor.addons 21 | reactor-extra 22 | 23 | 24 | io.projectreactor 25 | reactor-test 26 | test 27 | 28 | 29 | org.projectlombok 30 | lombok 31 | true 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-configuration-processor 36 | true 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter-test 41 | test 42 | 43 | 44 | org.junit.vintage 45 | junit-vintage-engine 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /blibli-backend-framework-scheduler-platform/src/main/java/com/blibli/oss/backend/scheduler/platform/model/ScheduledJobRequest.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.scheduler.platform.model; 2 | 3 | import com.blibli.oss.backend.kafka.annotation.KafkaKey; 4 | import com.blibli.oss.backend.kafka.annotation.KafkaTopic; 5 | import com.blibli.oss.backend.scheduler.platform.constant.SchedulerPlatformTopics; 6 | import lombok.AllArgsConstructor; 7 | import lombok.Builder; 8 | import lombok.Data; 9 | import lombok.NoArgsConstructor; 10 | 11 | import java.time.DayOfWeek; 12 | import java.time.Month; 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | 16 | @Data 17 | @Builder 18 | @AllArgsConstructor 19 | @NoArgsConstructor 20 | @KafkaTopic(SchedulerPlatformTopics.SAVE_SCHEDULED_JOB_EVENT) 21 | public class ScheduledJobRequest implements SchedulerPlatformModel { 22 | 23 | @KafkaKey 24 | private String id; 25 | 26 | private String name; 27 | 28 | private String group; 29 | 30 | private String payload; 31 | 32 | private String topic; 33 | 34 | @Builder.Default 35 | private Schedule schedule = new Schedule(); 36 | 37 | @Data 38 | @Builder 39 | @AllArgsConstructor 40 | @NoArgsConstructor 41 | public static class Schedule { 42 | 43 | @Builder.Default 44 | private List seconds = new ArrayList<>(); 45 | 46 | @Builder.Default 47 | private List minutes = new ArrayList<>(); 48 | 49 | @Builder.Default 50 | private List hours = new ArrayList<>(); 51 | 52 | @Builder.Default 53 | private List dayOfWeeks = new ArrayList<>(); 54 | 55 | @Builder.Default 56 | private List dayOfMonths = new ArrayList<>(); 57 | 58 | @Builder.Default 59 | private List months = new ArrayList<>(); 60 | 61 | @Builder.Default 62 | private List years = new ArrayList<>(); 63 | 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /blibli-backend-framework-validation/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | blibli-backend-framework 7 | com.blibli.oss 8 | 0.0.9-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | blibli-backend-framework-validation 13 | 14 | 15 | 16 | io.projectreactor 17 | reactor-core 18 | 19 | 20 | org.springframework.boot 21 | spring-boot-starter-validation 22 | 23 | 24 | org.springframework.boot 25 | spring-boot-configuration-processor 26 | true 27 | 28 | 29 | org.projectlombok 30 | lombok 31 | true 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-test 36 | test 37 | 38 | 39 | org.junit.vintage 40 | junit-vintage-engine 41 | 42 | 43 | 44 | 45 | io.projectreactor 46 | reactor-test 47 | test 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /blibli-backend-framework-mandatory-parameter/src/main/java/com/blibli/oss/backend/mandatoryparameter/helper/MandatoryParameterHelper.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.mandatoryparameter.helper; 2 | 3 | import brave.propagation.ExtraFieldPropagation; 4 | import brave.propagation.TraceContext; 5 | import com.blibli.oss.backend.mandatoryparameter.model.MandatoryParameter; 6 | import com.blibli.oss.backend.mandatoryparameter.sleuth.MandatoryParameterSleuth; 7 | 8 | public class MandatoryParameterHelper { 9 | 10 | public static MandatoryParameter toSleuth(TraceContext traceContext, MandatoryParameter mandatoryParameter) { 11 | SleuthHelper.putExtraField(traceContext, MandatoryParameterSleuth.STORE_ID, mandatoryParameter.getStoreId()); 12 | SleuthHelper.putExtraField(traceContext, MandatoryParameterSleuth.CLIENT_ID, mandatoryParameter.getClientId()); 13 | SleuthHelper.putExtraField(traceContext, MandatoryParameterSleuth.CHANNEL_ID, mandatoryParameter.getChannelId()); 14 | SleuthHelper.putExtraField(traceContext, MandatoryParameterSleuth.REQUEST_ID, mandatoryParameter.getRequestId()); 15 | SleuthHelper.putExtraField(traceContext, MandatoryParameterSleuth.USERNAME, mandatoryParameter.getUsername()); 16 | return mandatoryParameter; 17 | } 18 | 19 | public static MandatoryParameter fromSleuth(TraceContext traceContext) { 20 | return MandatoryParameter.builder() 21 | .storeId(ExtraFieldPropagation.get(traceContext, MandatoryParameterSleuth.STORE_ID)) 22 | .clientId(ExtraFieldPropagation.get(traceContext, MandatoryParameterSleuth.CLIENT_ID)) 23 | .channelId(ExtraFieldPropagation.get(traceContext, MandatoryParameterSleuth.CHANNEL_ID)) 24 | .requestId(ExtraFieldPropagation.get(traceContext, MandatoryParameterSleuth.REQUEST_ID)) 25 | .username(ExtraFieldPropagation.get(traceContext, MandatoryParameterSleuth.USERNAME)) 26 | .build(); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /blibli-backend-framework-swagger/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | blibli-backend-framework 7 | com.blibli.oss 8 | 0.0.9-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | blibli-backend-framework-swagger 13 | 14 | 15 | 16 | org.springdoc 17 | springdoc-openapi-webflux-ui 18 | 19 | 20 | org.springframework.boot 21 | spring-boot-starter-webflux 22 | 23 | 24 | org.springframework.boot 25 | spring-boot-configuration-processor 26 | true 27 | 28 | 29 | org.projectlombok 30 | lombok 31 | true 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-test 36 | test 37 | 38 | 39 | org.junit.vintage 40 | junit-vintage-engine 41 | 42 | 43 | 44 | 45 | io.projectreactor 46 | reactor-test 47 | test 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /blibli-backend-framework-mandatory-parameter/src/test/java/com/blibli/oss/backend/mandatoryparameter/helper/MandatoryParameterHelperTest.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.mandatoryparameter.helper; 2 | 3 | import brave.Span; 4 | import brave.Tracer; 5 | import com.blibli.oss.backend.mandatoryparameter.model.MandatoryParameter; 6 | import org.junit.jupiter.api.BeforeEach; 7 | import org.junit.jupiter.api.Test; 8 | import org.junit.jupiter.api.extension.ExtendWith; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.boot.autoconfigure.SpringBootApplication; 11 | import org.springframework.boot.test.context.SpringBootTest; 12 | import org.springframework.test.context.junit.jupiter.SpringExtension; 13 | 14 | import java.util.Objects; 15 | 16 | import static org.junit.jupiter.api.Assertions.*; 17 | 18 | @ExtendWith(SpringExtension.class) 19 | @SpringBootTest(classes = MandatoryParameterHelperTest.Application.class) 20 | class MandatoryParameterHelperTest { 21 | 22 | public static final MandatoryParameter MANDATORY_PARAMETER = MandatoryParameter.builder() 23 | .storeId("storeId") 24 | .channelId("channelId") 25 | .clientId("clientId") 26 | .requestId("requestId") 27 | .username("username") 28 | .build(); 29 | 30 | @Autowired 31 | private Tracer tracer; 32 | 33 | private Span span; 34 | 35 | @BeforeEach 36 | void setUp() { 37 | span = tracer.currentSpan(); 38 | if (Objects.isNull(span)) { 39 | span = tracer.nextSpan().start(); 40 | } 41 | } 42 | 43 | @Test 44 | void testToSleuth() { 45 | MandatoryParameterHelper.toSleuth(span.context(), MANDATORY_PARAMETER); 46 | MandatoryParameter mandatoryParameter = MandatoryParameterHelper.fromSleuth(span.context()); 47 | 48 | assertEquals(MANDATORY_PARAMETER, mandatoryParameter); 49 | } 50 | 51 | @SpringBootApplication 52 | static class Application { 53 | 54 | } 55 | 56 | } -------------------------------------------------------------------------------- /blibli-backend-framework-api-client/src/test/java/com/blibli/oss/backend/apiclient/SleuthApiClientTest.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.apiclient; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.junit.jupiter.api.extension.ExtendWith; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.test.context.SpringBootTest; 7 | import org.springframework.test.context.junit.jupiter.SpringExtension; 8 | import org.springframework.test.web.reactive.server.WebTestClient; 9 | 10 | @ExtendWith(SpringExtension.class) 11 | @SpringBootTest( 12 | classes = TestApplication.class, 13 | webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT, // https://github.com/spring-projects/spring-boot/issues/5077 14 | properties = { 15 | "server.port=15234" 16 | } 17 | ) 18 | public class SleuthApiClientTest { 19 | 20 | @Autowired 21 | private WebTestClient webTestClient; 22 | 23 | @Test 24 | void testSleuth() { 25 | webTestClient.get() 26 | .uri(uriBuilder -> uriBuilder 27 | .path("/first") 28 | .queryParam("firstName", "Eko") 29 | .queryParam("lastName", "Khannedy") 30 | .build()) 31 | .exchange() 32 | .expectStatus().is2xxSuccessful() 33 | .expectBody() 34 | .jsonPath("$.headerFirstName").isEqualTo("Eko") 35 | .jsonPath("$.headerLastName").isEqualTo("Khannedy") 36 | .jsonPath("$.firstName").isEqualTo("Eko") 37 | .jsonPath("$.lastName").isEqualTo("Khannedy"); 38 | } 39 | 40 | @Test 41 | void testList() { 42 | webTestClient.get() 43 | .uri(uriBuilder -> uriBuilder 44 | .path("/list") 45 | .build()) 46 | .exchange() 47 | .expectStatus().is2xxSuccessful() 48 | .expectBody() 49 | .jsonPath("$.value[0]").isEqualTo("Eko") 50 | .jsonPath("$.value[1]").isEqualTo("Kurniawan") 51 | .jsonPath("$.value[2]").isEqualTo("Khannedy"); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /blibli-backend-framework-sleuth/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | blibli-backend-framework 7 | com.blibli.oss 8 | 0.0.9-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | blibli-backend-framework-sleuth 13 | 14 | 15 | 16 | org.springframework.boot 17 | spring-boot-configuration-processor 18 | true 19 | 20 | 21 | org.projectlombok 22 | lombok 23 | true 24 | 25 | 26 | org.springframework.boot 27 | spring-boot-starter-webflux 28 | provided 29 | 30 | 31 | org.springframework.cloud 32 | spring-cloud-starter-sleuth 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-starter-test 37 | test 38 | 39 | 40 | org.junit.vintage 41 | junit-vintage-engine 42 | 43 | 44 | 45 | 46 | io.projectreactor 47 | reactor-test 48 | test 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /blibli-backend-framework-api-client/src/test/java/com/blibli/oss/backend/apiclient/TestApplication.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.apiclient; 2 | 3 | import com.blibli.oss.backend.apiclient.client.ExampleInterceptor; 4 | import com.blibli.oss.backend.apiclient.customizer.ApiClientTcpClientCustomizer; 5 | import com.blibli.oss.backend.apiclient.interceptor.GlobalApiClientInterceptor; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | import org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory; 8 | import org.springframework.context.annotation.Bean; 9 | import org.springframework.stereotype.Component; 10 | import org.springframework.web.reactive.function.client.ClientRequest; 11 | import org.springframework.web.reactive.function.client.ClientResponse; 12 | import org.springframework.web.reactive.function.client.ExchangeFunction; 13 | import reactor.core.publisher.Mono; 14 | import reactor.netty.tcp.TcpClient; 15 | 16 | @SpringBootApplication 17 | public class TestApplication { 18 | 19 | @Bean 20 | public NettyReactiveWebServerFactory nettyReactiveWebServerFactory(){ 21 | return new NettyReactiveWebServerFactory(); 22 | } 23 | 24 | @Bean 25 | public ExampleInterceptor exampleInterceptor() { 26 | return new ExampleInterceptor(); 27 | } 28 | 29 | @Component 30 | public static class EchoGlobalApiClientInterceptor implements GlobalApiClientInterceptor { 31 | 32 | @Override 33 | public Mono filter(ClientRequest request, ExchangeFunction next) { 34 | return Mono.fromCallable(() -> 35 | ClientRequest.from(request) 36 | .header("ECHO", "ECHO") 37 | .build() 38 | ).flatMap(next::exchange); 39 | } 40 | } 41 | 42 | @Component 43 | public static class WireTrapTcpClientCustomizer implements ApiClientTcpClientCustomizer { 44 | 45 | @Override 46 | public TcpClient customize(TcpClient tcpClient) { 47 | return tcpClient.wiretap(true); 48 | } 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /blibli-backend-framework-common/src/main/java/com/blibli/oss/backend/common/helper/ResponseHelper.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.common.helper; 2 | 3 | import com.blibli.oss.backend.common.model.response.Paging; 4 | import com.blibli.oss.backend.common.model.response.Response; 5 | import org.springframework.http.HttpStatus; 6 | 7 | import java.util.List; 8 | import java.util.Map; 9 | 10 | public class ResponseHelper { 11 | 12 | public static Response ok() { 13 | return ResponseHelper.ok(null); 14 | } 15 | 16 | public static Response ok(T data) { 17 | return ResponseHelper.ok(data, null); 18 | } 19 | 20 | public static Response ok(T data, Paging paging) { 21 | return ResponseHelper.status(HttpStatus.OK, data, paging); 22 | } 23 | 24 | public static Response internalServerError() { 25 | return ResponseHelper.status(HttpStatus.INTERNAL_SERVER_ERROR); 26 | } 27 | 28 | public static Response unauthorized() { 29 | return ResponseHelper.status(HttpStatus.UNAUTHORIZED); 30 | } 31 | 32 | public static Response badRequest(Map> errors) { 33 | return ResponseHelper.status(HttpStatus.BAD_REQUEST, null, null, errors); 34 | } 35 | 36 | public static Response status(HttpStatus status) { 37 | return ResponseHelper.status(status, null); 38 | } 39 | 40 | public static Response status(HttpStatus status, T data) { 41 | return ResponseHelper.status(status, data, null); 42 | } 43 | 44 | public static Response status(HttpStatus status, T data, Paging paging) { 45 | return ResponseHelper.status(status, data, paging, null); 46 | } 47 | 48 | public static Response status(HttpStatus status, T data, Paging paging, Map> errors) { 49 | return Response.builder() 50 | .code(status.value()) 51 | .status(status.name()) 52 | .paging(paging) 53 | .data(data) 54 | .errors(errors) 55 | .build(); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /blibli-backend-framework-newrelic/src/main/java/com/blibli/oss/backend/newrelic/aspect/ReactiveMongoDbAspect.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.newrelic.aspect; 2 | 3 | import com.blibli.oss.backend.newrelic.aspect.service.AspectModifyService; 4 | import com.blibli.oss.backend.newrelic.aspect.service.util.SegmentType; 5 | import lombok.AllArgsConstructor; 6 | import org.aspectj.lang.ProceedingJoinPoint; 7 | import org.aspectj.lang.annotation.Around; 8 | import org.aspectj.lang.annotation.Aspect; 9 | import org.aspectj.lang.annotation.Pointcut; 10 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 11 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; 12 | import org.springframework.boot.autoconfigure.mongo.MongoProperties; 13 | import org.springframework.context.annotation.Configuration; 14 | import org.springframework.data.mongodb.core.ReactiveMongoTemplate; 15 | import org.springframework.data.mongodb.repository.ReactiveMongoRepository; 16 | 17 | /** 18 | * Aspect to target Spring Reactive MongoDB for timing with New Relic Segment. 19 | */ 20 | @Aspect 21 | @Configuration 22 | @ConditionalOnClass({ 23 | ReactiveMongoRepository.class, 24 | ReactiveMongoTemplate.class, 25 | MongoProperties.class 26 | }) 27 | @ConditionalOnProperty( 28 | prefix = "blibli.newrelic.reactive-mongodb", 29 | name = "enabled", 30 | matchIfMissing = true 31 | ) 32 | @AllArgsConstructor 33 | public class ReactiveMongoDbAspect { 34 | 35 | private AspectModifyService aspectModifyService; 36 | 37 | @Pointcut("execution(public * *.*(..)) && within(org.springframework.data.mongodb.repository.ReactiveMongoRepository+)") 38 | void mongoRepositoryInterface() {} 39 | 40 | @Around(value = "mongoRepositoryInterface()") 41 | public Object afterCommandExecute(ProceedingJoinPoint proceedingJoinPoint) throws Throwable { 42 | return aspectModifyService.modifyRetValWithTiming( 43 | proceedingJoinPoint, SegmentType.REACTIVE_MONGODB 44 | ); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /blibli-backend-framework-common/src/main/java/com/blibli/oss/backend/common/CommonSwaggerAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.common; 2 | 3 | import com.blibli.oss.backend.common.properties.PagingProperties; 4 | import com.blibli.oss.backend.common.swagger.PagingRequestSwaggerIgnoredParameter; 5 | import com.blibli.oss.backend.swagger.SwaggerAutoConfiguration; 6 | import com.blibli.oss.backend.swagger.api.SwaggerIgnoredParameter; 7 | import io.swagger.v3.oas.models.parameters.Parameter; 8 | import io.swagger.v3.oas.models.parameters.QueryParameter; 9 | import org.springframework.boot.autoconfigure.AutoConfigureAfter; 10 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 11 | import org.springframework.context.annotation.Bean; 12 | import org.springframework.context.annotation.Configuration; 13 | 14 | @Configuration 15 | @ConditionalOnClass(SwaggerAutoConfiguration.class) 16 | @AutoConfigureAfter(CommonAutoConfiguration.class) 17 | public class CommonSwaggerAutoConfiguration { 18 | 19 | @Bean 20 | public SwaggerIgnoredParameter pagingRequestSwaggerIgnoredParameter() { 21 | return new PagingRequestSwaggerIgnoredParameter(); 22 | } 23 | 24 | @Bean 25 | public Parameter queryPagingRequestPage(PagingProperties pagingProperties) { 26 | return new QueryParameter() 27 | .name(pagingProperties.getQuery().getPageKey()) 28 | .example(pagingProperties.getDefaultPage()) 29 | .required(true); 30 | } 31 | 32 | @Bean 33 | public Parameter queryPagingRequestItemPerPage(PagingProperties pagingProperties) { 34 | return new QueryParameter() 35 | .name(pagingProperties.getQuery().getItemPerPageKey()) 36 | .example(pagingProperties.getDefaultItemPerPage()) 37 | .required(true); 38 | } 39 | 40 | @Bean 41 | public Parameter queryPagingRequestSortBy(PagingProperties pagingProperties) { 42 | return new QueryParameter() 43 | .name(pagingProperties.getQuery().getSortByKey()) 44 | .required(false); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /blibli-backend-framework-api-client/src/main/java/com/blibli/oss/backend/apiclient/aop/fallback/ApiClientFallback.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.apiclient.aop.fallback; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.NoArgsConstructor; 6 | import org.springframework.util.ReflectionUtils; 7 | import reactor.core.publisher.Mono; 8 | 9 | import java.lang.reflect.Method; 10 | import java.util.Objects; 11 | 12 | @Builder 13 | @NoArgsConstructor 14 | @AllArgsConstructor 15 | public class ApiClientFallback { 16 | 17 | private Object fallback; 18 | 19 | private FallbackMetadata metadata; 20 | 21 | public boolean isAvailable() { 22 | return Objects.nonNull(fallback); 23 | } 24 | 25 | public Mono invoke(Method method, Object[] arguments, Throwable throwable) { 26 | return Mono.just(throwable) 27 | .flatMap(exception -> { 28 | if (method.getDeclaringClass().isAssignableFrom(fallback.getClass())) { 29 | return (Mono) ReflectionUtils.invokeMethod(method, fallback, arguments); 30 | } 31 | 32 | Method methodWithException = metadata.getExceptionMethods().get(method); 33 | if (Objects.nonNull(methodWithException)) { 34 | Object[] target = getArgumentsWithException(arguments, exception); 35 | return (Mono) ReflectionUtils.invokeMethod(methodWithException, fallback, target); 36 | } 37 | 38 | Method fallbackMethod = metadata.getMethods().get(method); 39 | if (Objects.nonNull(fallbackMethod)) { 40 | return (Mono) ReflectionUtils.invokeMethod(fallbackMethod, fallback, arguments); 41 | } 42 | 43 | return Mono.error(exception); 44 | }); 45 | } 46 | 47 | private Object[] getArgumentsWithException(Object[] arguments, Throwable exception) { 48 | Object[] target = new Object[arguments.length + 1]; 49 | System.arraycopy(arguments, 0, target, 0, arguments.length); 50 | target[target.length - 1] = exception; 51 | return target; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /blibli-backend-framework-newrelic/src/main/java/com/blibli/oss/backend/newrelic/injector/NewRelicTokenInjectorFilter.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.newrelic.injector; 2 | 3 | import com.newrelic.api.agent.Agent; 4 | import com.newrelic.api.agent.Token; 5 | import com.newrelic.api.agent.Trace; 6 | import com.newrelic.api.agent.Transaction; 7 | import org.springframework.web.server.ServerWebExchange; 8 | import org.springframework.web.server.WebFilter; 9 | import org.springframework.web.server.WebFilterChain; 10 | import reactor.core.publisher.Mono; 11 | import reactor.util.context.Context; 12 | 13 | import java.util.Optional; 14 | 15 | public class NewRelicTokenInjectorFilter implements WebFilter { 16 | 17 | public static final String TRANSACTION_CONTEXT_KEY = "NEW_RELIC_TRANSACTION"; 18 | public static final String TOKEN_CONTEXT_KEY = "NEW_RELIC_TOKEN"; 19 | 20 | private Agent agent; 21 | 22 | public NewRelicTokenInjectorFilter(Agent agent) { 23 | this.agent = agent; 24 | } 25 | 26 | @Override 27 | @Trace(async = true) 28 | public Mono filter(ServerWebExchange exchange, WebFilterChain chain) { 29 | return chain.filter(exchange) 30 | .subscriberContext(context -> { 31 | Transaction transaction = agent.getTransaction(); 32 | // TODO IDK exactly what is this 33 | // Just copas from newrelic-rx 34 | transaction.getTracedMethod().setMetricName("Reactor"); 35 | 36 | Token token = transaction.getToken(); 37 | token.link(); 38 | Context updatedContext = context 39 | .put(TRANSACTION_CONTEXT_KEY, transaction) 40 | .put(TOKEN_CONTEXT_KEY, token); 41 | return updatedContext; 42 | }); 43 | } 44 | 45 | public static Optional getToken(Context context) { 46 | return context.getOrEmpty(TOKEN_CONTEXT_KEY); 47 | } 48 | 49 | public static Optional getTransaction(Context context) { 50 | return context.getOrEmpty(TRANSACTION_CONTEXT_KEY); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /blibli-backend-framework-aggregate-query/src/main/java/com/blibli/oss/backend/aggregate/query/fallback/AggregateQueryApiClientFallback.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.aggregate.query.fallback; 2 | 3 | import com.blibli.oss.backend.aggregate.query.apiclient.AggregateQueryApiClient; 4 | import com.blibli.oss.backend.aggregate.query.model.AggregateQueryHit; 5 | import com.blibli.oss.backend.aggregate.query.model.AggregateQueryHits; 6 | import com.blibli.oss.backend.aggregate.query.model.AggregateQueryResponse; 7 | import reactor.core.publisher.Mono; 8 | 9 | import java.util.Collections; 10 | import java.util.Map; 11 | 12 | public class AggregateQueryApiClientFallback implements AggregateQueryApiClient { 13 | 14 | private static final AggregateQueryResponse> EMPTY_RESPONSES = AggregateQueryResponse.>builder() 15 | .aggregations(Collections.emptyMap()) 16 | .hits(AggregateQueryHits.>builder() 17 | .maxScore(0.0) 18 | .total(0L) 19 | .hits(Collections.emptyList()) 20 | .build()) 21 | .timedOut(false) 22 | .took(0) 23 | .build(); 24 | 25 | @Override 26 | public Mono>> search(String index, String request) { 27 | return Mono.just(EMPTY_RESPONSES); 28 | } 29 | 30 | @Override 31 | public Mono>> get(String index, String id) { 32 | return Mono.just(AggregateQueryHit.>builder() 33 | .found(false) 34 | .id(id) 35 | .index(index) 36 | .score(0.0) 37 | .version(0) 38 | .source(Collections.emptyMap()) 39 | .build()); 40 | } 41 | 42 | @Override 43 | public Mono>> scroll(String index, String request) { 44 | return Mono.just(EMPTY_RESPONSES); 45 | } 46 | 47 | @Override 48 | public Mono>> nextScroll(String index, String scrollId) { 49 | return Mono.just(EMPTY_RESPONSES); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /blibli-backend-framework-aggregate-query/README.md: -------------------------------------------------------------------------------- 1 | # Aggregate Query Module 2 | 3 | Aggregate Query Module is api client for Aggregate Query platform at Blibli. 4 | Aggregate Query Module is based on API Client Module 5 | 6 | ## Setup Dependency 7 | 8 | ```xml 9 | 10 | com.blibli.oss 11 | blibli-backend-framework-aggregate-query 12 | 13 | ``` 14 | 15 | ## Configuration Properties 16 | 17 | Because this module based on API Client Module, so to configure the url, timeout, 18 | we can use API Client configuration properties 19 | 20 | ```properties 21 | blibli.backend.aggregate.query.service-id=YourServiceID 22 | 23 | blibli.backend.apiclient.configs.aggregateQueryApiClient.url=http://aggregate-query-host 24 | blibli.backend.apiclient.configs.aggregateQueryApiClient.connect-timeout=2s 25 | blibli.backend.apiclient.configs.aggregateQueryApiClient.read-timeout=2s 26 | blibli.backend.apiclient.configs.aggregateQueryApiClient.write-timeout=2s 27 | ``` 28 | 29 | And don't forget to register `AggregateQueryApiClient` package to api client packages 30 | 31 | ```properties 32 | blibli.backend.apiclient.packages=com.blibli.oss.backend.aggregate.query.apiclient,com.yourcompany.project.apiclient 33 | ``` 34 | 35 | ## Aggregate Query API Client 36 | 37 | `AggregateQueryApiClient` support some operations, search, get, and scroll. And you can use elasticsearch JSON query to get data from aggregate query. 38 | 39 | ```java 40 | @Autowired 41 | private AggregateQueryApiClient aggregateQueryApiClient; 42 | 43 | // elasticsearch query 44 | SearchSourceBuilder sourceBuilder = new SearchSourceBuilder() 45 | .query(QueryBuilders.termQuery("user", "kimchy")) 46 | .from(0) 47 | .size(5); 48 | String jsonRequest = sourceBuilder.toString(); 49 | 50 | Flux response = aggregateQueryApiClient.search("customer_index", jsonRequest) 51 | .map(value -> value.getHits().hitsAs(map -> objectMapper.convertValue(map, Customer.class))) 52 | .flatMapMany(Flux::fromIterable); 53 | ``` -------------------------------------------------------------------------------- /blibli-backend-framework-external-api/src/main/java/com/blibli/oss/backend/externalapi/swagger/ExternalApiSwaggerConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.blibli.oss.backend.externalapi.swagger; 2 | 3 | import com.blibli.oss.backend.externalapi.ExternalApiConfiguration; 4 | import com.blibli.oss.backend.externalapi.properties.ExternalApiProperties; 5 | import com.blibli.oss.backend.externalapi.swagger.bean.ExternalApiSwaggerIgnoredParameter; 6 | import com.blibli.oss.backend.swagger.SwaggerAutoConfiguration; 7 | import io.swagger.v3.oas.models.parameters.HeaderParameter; 8 | import io.swagger.v3.oas.models.parameters.Parameter; 9 | import org.springframework.boot.autoconfigure.AutoConfigureAfter; 10 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 11 | import org.springframework.context.annotation.Bean; 12 | import org.springframework.context.annotation.Configuration; 13 | 14 | @Configuration 15 | @ConditionalOnClass(SwaggerAutoConfiguration.class) 16 | @AutoConfigureAfter(ExternalApiConfiguration.class) 17 | public class ExternalApiSwaggerConfiguration { 18 | 19 | @Bean 20 | public ExternalApiSwaggerIgnoredParameter externalApiSwaggerIgnoredParameter() { 21 | return new ExternalApiSwaggerIgnoredParameter(); 22 | } 23 | 24 | @Bean 25 | public Parameter externalApiHeaderUserId(ExternalApiProperties properties) { 26 | return new HeaderParameter() 27 | .required(true) 28 | .name(properties.getHeader().getUserId()) 29 | .example(properties.getHeader().getUserId()); 30 | } 31 | 32 | @Bean 33 | public Parameter externalApiHeaderSessionId(ExternalApiProperties properties) { 34 | return new HeaderParameter() 35 | .required(true) 36 | .name(properties.getHeader().getSessionId()) 37 | .example(properties.getHeader().getSessionId()); 38 | } 39 | 40 | @Bean 41 | public Parameter externalApiHeaderMember(ExternalApiProperties properties) { 42 | return new HeaderParameter() 43 | .required(true) 44 | .name(properties.getHeader().getIsMember()) 45 | .example("false"); 46 | } 47 | } 48 | --------------------------------------------------------------------------------