├── .editorconfig
├── .flattened-pom.xml
├── .github
├── ISSUE_TEMPLATE
│ └── bug_report.md
└── workflows
│ └── codeql-analysis.yml
├── .gitignore
├── .travis.yml
├── README.md
├── SECURITY.md
├── pom.xml
├── sonar-project.properties
├── spring-commons-actuator
├── .flattened-pom.xml
├── LICENSE
├── README.md
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── github
│ │ │ └── damianwajser
│ │ │ ├── actuator
│ │ │ ├── enpoints
│ │ │ │ └── CacheKeysEndpoint.java
│ │ │ └── extension
│ │ │ │ └── CacheEndpointExtension.java
│ │ │ ├── commons
│ │ │ └── configuration
│ │ │ │ └── PropertiesActuator.java
│ │ │ ├── model
│ │ │ └── CacheInfo.java
│ │ │ └── utilities
│ │ │ └── CacheUtilities.java
│ └── resources
│ │ ├── application.properties
│ │ └── spring-commons-actuator.properties
│ └── test
│ └── java
│ └── com
│ └── github
│ └── damianwajser
│ ├── TestApplication.java
│ ├── controllers
│ └── TestController.java
│ ├── model
│ └── FooObject.java
│ └── test
│ └── CacheTest.java
├── spring-commons-cache
├── .flattened-pom.xml
├── .gitignore
├── README.md
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── github
│ │ │ └── damianwajser
│ │ │ ├── configuration
│ │ │ ├── PropertiesCommonsCache.java
│ │ │ ├── TtlProperties.java
│ │ │ └── redis
│ │ │ │ ├── CustomRedisCacheConfiguration.java
│ │ │ │ ├── RedisListenerConfiguration.java
│ │ │ │ ├── RedisScriptsConfiguration.java
│ │ │ │ └── RedisTemplateConfiguration.java
│ │ │ ├── serializer
│ │ │ ├── CustomJdkKeyPrefixRedisSerializer.java
│ │ │ └── CustomJdkRedisSerializer.java
│ │ │ └── service
│ │ │ └── RedisService.java
│ └── resources
│ │ ├── application.properties
│ │ ├── checkAndIncrementHash.lua
│ │ ├── checkAndSetHash.lua
│ │ ├── checkAndSetHashKeys.lua
│ │ └── spring-commons-cache.properties
│ └── test
│ ├── java
│ └── com
│ │ └── github
│ │ └── damianwajser
│ │ ├── TestApplication.java
│ │ ├── configuration
│ │ └── RedisConfiguration.java
│ │ ├── controller
│ │ ├── CacheController.java
│ │ ├── ServiceCache.java
│ │ └── ServiceCacheTtl.java
│ │ └── test
│ │ ├── CacheTest.java
│ │ ├── IncrementTest.java
│ │ ├── SerializerTest.java
│ │ └── TtlTest.java
│ └── resources
│ ├── application.properties
│ └── spring-commons-cache.properties
├── spring-commons-exception-handler
├── .flattened-pom.xml
├── README.md
├── pom.xml
└── src
│ ├── main
│ └── java
│ │ └── com
│ │ └── github
│ │ └── damianwajser
│ │ └── exceptions
│ │ ├── configuration
│ │ ├── CustomLocaleResolver.java
│ │ └── I18nConfiguration.java
│ │ └── handlers
│ │ ├── ExceptionDetailMapper.java
│ │ └── GlobalExceptionHandler.java
│ └── test
│ ├── java
│ └── com
│ │ └── github
│ │ └── damianwajser
│ │ ├── TestApplication.java
│ │ ├── controllers
│ │ ├── BadRequestController.java
│ │ ├── BadRequestValidationController.java
│ │ ├── I18nBadRequestController.java
│ │ ├── NotFoundController.java
│ │ ├── OtheRequestController.java
│ │ └── TestForbiddenController.java
│ │ ├── model
│ │ ├── CustomValidationFooObject.java
│ │ ├── EnumArrayOject.java
│ │ ├── EnumModel.java
│ │ └── FooObject.java
│ │ └── tests
│ │ ├── CustomValidationI18nTest.java
│ │ ├── ExceptionI18nTest.java
│ │ ├── ExceptionResponseTest.java
│ │ ├── ExceptionValidationResponseTest.java
│ │ └── MapperErrorTest.java
│ └── resources
│ ├── application.properties
│ ├── messages_en.properties
│ ├── messages_es.properties
│ └── messages_fr.properties
├── spring-commons-exception
├── .flattened-pom.xml
├── README.md
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── github
│ │ │ └── damianwajser
│ │ │ └── exceptions
│ │ │ ├── ExceptionFactory.java
│ │ │ ├── RestException.java
│ │ │ ├── impl
│ │ │ ├── authentication
│ │ │ │ └── forbidden
│ │ │ │ │ ├── ForbiddenException.java
│ │ │ │ │ └── PermissionDeniedException.java
│ │ │ ├── badrequest
│ │ │ │ ├── BadRequestException.java
│ │ │ │ ├── ConflictException.java
│ │ │ │ ├── LockedException.java
│ │ │ │ ├── MethodNotAllowedException.java
│ │ │ │ ├── NotAcceptableException.java
│ │ │ │ ├── NotFoundException.java
│ │ │ │ ├── PaymentRequiredException.java
│ │ │ │ ├── PreconditionFailedException.java
│ │ │ │ ├── UnprocessableEntityException.java
│ │ │ │ └── UnsupportedMediaTypeException.java
│ │ │ └── servererror
│ │ │ │ └── InternalServerErrorException.java
│ │ │ └── model
│ │ │ ├── ErrorMessage.java
│ │ │ └── ExceptionDetail.java
│ └── resources
│ │ └── application.properties
│ └── test
│ └── java
│ └── com
│ └── github
│ └── damianwajser
│ ├── TestApplication.java
│ ├── controllers
│ ├── BadRequestController.java
│ ├── ConflictController.java
│ ├── NotFoundController.java
│ └── TestForbiddenController.java
│ ├── model
│ └── FooObject.java
│ ├── tests
│ ├── ErrorMessageTest.java
│ ├── ExceptionCodeTest.java
│ └── InstanciateObjectTest.java
│ └── utils
│ └── TestUtils.java
├── spring-commons-http-fixer
├── .flattened-pom.xml
├── LICENSE
├── README.md
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── github
│ │ │ └── damianwajser
│ │ │ └── web
│ │ │ ├── configuration
│ │ │ └── PropertiesHttpFixer.java
│ │ │ └── filters
│ │ │ └── FixHttpPostFilter.java
│ └── resources
│ │ ├── application.properties
│ │ └── spring-commons-http.properties
│ └── test
│ └── java
│ └── com
│ └── github
│ └── damianwajser
│ ├── TestApplication.java
│ ├── controllers
│ └── TestController.java
│ ├── model
│ └── FooObject.java
│ └── tests
│ └── TestingWebApplicationTests.java
├── spring-commons-idempotency
├── .flattened-pom.xml
├── README.md
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── github
│ │ │ └── damianwajser
│ │ │ └── idempotency
│ │ │ ├── configuration
│ │ │ ├── IdempotencyEndpoint.java
│ │ │ ├── IdempotencyEndpoints.java
│ │ │ ├── IdempotencyFilterConfiguration.java
│ │ │ └── IdempotencyProperties.java
│ │ │ ├── exception
│ │ │ ├── ArgumentNotFoundException.java
│ │ │ └── RedisException.java
│ │ │ ├── filters
│ │ │ └── IdempontecyFilter.java
│ │ │ ├── generators
│ │ │ ├── DefaultIdempotencyKeyGenerator.java
│ │ │ └── IdempotencyKeyGenerator.java
│ │ │ ├── model
│ │ │ └── StoredResponse.java
│ │ │ ├── utils
│ │ │ ├── HeadersUtil.java
│ │ │ └── JsonUtils.java
│ │ │ └── writers
│ │ │ ├── HttpServletResponseCopier.java
│ │ │ └── ServletOutputStreamCopier.java
│ └── resources
│ │ └── application.properties
│ └── test
│ └── java
│ └── com
│ └── github
│ └── damianwajser
│ ├── TestApplication.java
│ ├── configuration
│ ├── FooIdempotencyKeyGenerator.java
│ ├── IdempotencyConfiguration.java
│ ├── IdempotencyValidatorKeyGenerator.java
│ └── RedisConfiguration.java
│ ├── controllers
│ └── IdempotencyController.java
│ ├── model
│ └── FooObject.java
│ └── tests
│ └── IdempotencyTest.java
├── spring-commons-logger-logstash
├── .flattened-pom.xml
├── LICENSE
├── README.md
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── github
│ │ │ └── damianwajser
│ │ │ └── configuration
│ │ │ └── LogstashConfiguration.java
│ └── resources
│ │ └── application.properties
│ └── test
│ └── java
│ └── com
│ └── github
│ └── damianwajser
│ ├── TestApplication.java
│ ├── controller
│ └── TestController.java
│ └── tests
│ └── PingTest.java
├── spring-commons-logger
├── .flattened-pom.xml
├── LICENSE
├── README.md
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── github
│ │ │ └── damianwajser
│ │ │ ├── configuration
│ │ │ ├── CommonsConfiguration.java
│ │ │ └── PropertiesLogger.java
│ │ │ ├── filter
│ │ │ ├── MDCFilter.java
│ │ │ └── StatsFilter.java
│ │ │ └── generators
│ │ │ ├── RequestIdGenerator.java
│ │ │ └── TraceIdGenerator.java
│ └── resources
│ │ ├── application.properties
│ │ └── spring-commons-logger.properties
│ └── test
│ └── java
│ └── com
│ └── github
│ └── damianwajser
│ ├── TestApplication.java
│ ├── controller
│ └── TestController.java
│ └── tests
│ └── PingTest.java
├── spring-commons-payment-utilities
├── .flattened-pom.xml
├── README.md
├── pom.xml
└── src
│ ├── main
│ └── java
│ │ └── com
│ │ └── github
│ │ └── damianwajser
│ │ ├── crypto
│ │ └── CryptoUtil.java
│ │ ├── emv
│ │ ├── exceptions
│ │ │ ├── CrcValidationException.java
│ │ │ └── EmvFormatException.java
│ │ └── parser
│ │ │ ├── CrcHelper.java
│ │ │ └── EmvCoParser.java
│ │ └── printers
│ │ ├── QrWritter.java
│ │ └── formatters
│ │ ├── Formatter.java
│ │ ├── QrFormat.java
│ │ └── impl
│ │ ├── Base64Formatter.java
│ │ ├── DefaultFormatter.java
│ │ └── FormattersFactory.java
│ └── test
│ └── java
│ └── com
│ └── github
│ └── damianwajser
│ └── tests
│ ├── CryptoTest.java
│ ├── EmvCoParserTest.java
│ └── PrinterTest.java
├── spring-commons-rest-templates
├── .flattened-pom.xml
├── README.md
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── github
│ │ │ └── damianwajser
│ │ │ └── rest
│ │ │ ├── configuration
│ │ │ ├── CustomHttpRequestFactory.java
│ │ │ ├── OkHttp
│ │ │ │ ├── OkHttpPoolingConnfiguration.java
│ │ │ │ └── OkHttpRequestFactory.java
│ │ │ ├── SslDefaultBeanConfiguration.java
│ │ │ ├── apache
│ │ │ │ ├── ApacheClientHttpRequestFactory.java
│ │ │ │ └── ApacheHttpPoolingConnfiguration.java
│ │ │ └── properties
│ │ │ │ ├── PoolConfigurationProperties.java
│ │ │ │ ├── SslConfigurationProperties.java
│ │ │ │ └── TimeoutConfigurationProperties.java
│ │ │ ├── interceptors
│ │ │ └── RestTemplateInterceptor.java
│ │ │ └── templates
│ │ │ └── RestTemplateConfiguration.java
│ └── resources
│ │ ├── application.properties
│ │ ├── spring-commons-client-http.properties
│ │ ├── spring-commons-http-pools.properties
│ │ ├── spring-commons-ssl.properties
│ │ └── spring-commons-timeouts.properties
│ └── test
│ └── java
│ └── com
│ └── github
│ └── damianwajser
│ ├── TestApplication.java
│ ├── controllers
│ ├── TestController.java
│ └── TimeoutTestController.java
│ ├── model
│ ├── snake
│ │ ├── RequestToController.java
│ │ └── SingletonObject.java
│ └── timeout
│ │ └── TimeOutObject.java
│ └── tests
│ ├── AbstractHttpTest.java
│ ├── apache
│ ├── DefaultTimeOutTests.java
│ └── TimeOutTests.java
│ ├── commons
│ ├── SnakeCaseTests.java
│ └── TestingWebApplicationTests.java
│ └── ok
│ └── http
│ ├── DefaultTimeOutTests.java
│ └── TimeOutTests.java
├── spring-commons-rest-validation
├── .flattened-pom.xml
├── README.md
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── github
│ │ │ └── damianwajser
│ │ │ └── validator
│ │ │ ├── annotation
│ │ │ ├── cards
│ │ │ │ ├── CardExpiration.java
│ │ │ │ └── CardToken.java
│ │ │ ├── enums
│ │ │ │ ├── Country_ISO3166.java
│ │ │ │ └── MatchEnum.java
│ │ │ ├── global
│ │ │ │ ├── AssertTrue.java
│ │ │ │ ├── Email.java
│ │ │ │ ├── NotEmpty.java
│ │ │ │ ├── NotNull.java
│ │ │ │ ├── OneNotNull.java
│ │ │ │ ├── Past.java
│ │ │ │ ├── Pattern.java
│ │ │ │ └── Size.java
│ │ │ ├── number
│ │ │ │ ├── DecimalMin.java
│ │ │ │ ├── Digits.java
│ │ │ │ ├── Max.java
│ │ │ │ └── Min.java
│ │ │ └── strings
│ │ │ │ ├── AlphaNumeric.java
│ │ │ │ ├── Base64.java
│ │ │ │ ├── Password.java
│ │ │ │ ├── UUID.java
│ │ │ │ └── Word.java
│ │ │ ├── constraint
│ │ │ ├── AbstractConstraint.java
│ │ │ ├── cards
│ │ │ │ ├── CardTokenConstraint.java
│ │ │ │ ├── ExpirationCardConstraint.java
│ │ │ │ └── token
│ │ │ │ │ └── validators
│ │ │ │ │ ├── DataFastValidator.java
│ │ │ │ │ ├── TokenExValidator.java
│ │ │ │ │ ├── TokenValidator.java
│ │ │ │ │ └── TokenValidatorsFactory.java
│ │ │ ├── enums
│ │ │ │ ├── CountryIso3166Constraint.java
│ │ │ │ ├── MatchEnumConstraint.java
│ │ │ │ └── values
│ │ │ │ │ └── Countries.java
│ │ │ ├── global
│ │ │ │ ├── AssertTrueConstraint.java
│ │ │ │ ├── EmailConstraint.java
│ │ │ │ ├── NotEmptyConstraint.java
│ │ │ │ ├── NotNullConstraint.java
│ │ │ │ ├── OneNotNullConstraint.java
│ │ │ │ ├── OneNotNullValidator.java
│ │ │ │ ├── PastConstraint.java
│ │ │ │ ├── PatternConstraint.java
│ │ │ │ └── SizeConstraint.java
│ │ │ ├── number
│ │ │ │ ├── DecimalMinConstraint.java
│ │ │ │ ├── DigitsConstraint.java
│ │ │ │ ├── MaxConstraint.java
│ │ │ │ └── MinConstraint.java
│ │ │ └── strings
│ │ │ │ ├── AlphaNumericConstraint.java
│ │ │ │ ├── Base64Constraint.java
│ │ │ │ ├── PasswordConstraint.java
│ │ │ │ ├── UUIDConstraint.java
│ │ │ │ ├── WordConstraint.java
│ │ │ │ └── abstracts
│ │ │ │ └── AbstractWordConstraint.java
│ │ │ └── interfaces
│ │ │ └── CardExpirable.java
│ └── resources
│ │ └── application.properties
│ └── test
│ └── java
│ └── com
│ └── github
│ └── damianwajser
│ ├── TestApplication.java
│ ├── TestUtils.java
│ ├── controllers
│ └── BadRequestController.java
│ ├── model
│ ├── cards
│ │ ├── ExpirationObject.java
│ │ └── tokens
│ │ │ ├── CardDataFastTokenObject.java
│ │ │ └── CardTokenExObject.java
│ ├── enums
│ │ ├── contry
│ │ │ ├── CountryEnum.java
│ │ │ └── CountryString.java
│ │ └── global
│ │ │ ├── MatchEnumObject.java
│ │ │ ├── MatchEnumObjectArray.java
│ │ │ └── MatchString.java
│ ├── especifics
│ │ └── NoEmptyObjectOnlyPut.java
│ ├── global
│ │ ├── NoEmptyObject.java
│ │ ├── PastAuxObject.java
│ │ ├── asserttrue
│ │ │ ├── AssertTrueObject.java
│ │ │ └── AssertTrueStringObject.java
│ │ ├── email
│ │ │ ├── EmailObject.java
│ │ │ └── EmailStringObject.java
│ │ ├── max
│ │ │ ├── MaxNumberObject.java
│ │ │ ├── MaxPrimitiveObject.java
│ │ │ └── MaxStringObject.java
│ │ ├── min
│ │ │ ├── MinNumberObject.java
│ │ │ ├── MinPrimitiveObject.java
│ │ │ └── MinStringObject.java
│ │ ├── nonull
│ │ │ ├── NoNullCollectionObject.java
│ │ │ └── NoNullStringObject.java
│ │ ├── onenotnull
│ │ │ └── OneNotNullObject.java
│ │ └── size
│ │ │ ├── SizeCollectionObject.java
│ │ │ ├── SizeMinOneStringObject.java
│ │ │ └── SizeMinZeroStringObject.java
│ ├── number
│ │ ├── DecimalMinInclusiveObject.java
│ │ ├── DecimalMinObject.java
│ │ ├── DigitsDecimalObject.java
│ │ ├── DigitsWithoutDecimalAndMultiplyObject.java
│ │ ├── DigitsWithoutDecimalAndMultiplyObjectInt.java
│ │ ├── DigitsWithoutDecimalObject.java
│ │ ├── max
│ │ │ ├── MaxNumberObject.java
│ │ │ ├── MaxPrimitiveObject.java
│ │ │ └── MaxStringObject.java
│ │ └── min
│ │ │ ├── MinNumberObject.java
│ │ │ ├── MinPrimitiveObject.java
│ │ │ └── MinStringObject.java
│ ├── pattern
│ │ └── PatternStringObject.java
│ └── strings
│ │ ├── AlphaAllowSpaceStringObject.java
│ │ ├── AlphaMinOneStringObject.java
│ │ ├── Base64StringObject.java
│ │ ├── PasswordStringObject.java
│ │ ├── UUIDObject.java
│ │ ├── WordAllowSpaceStringObject.java
│ │ └── WordMinOneStringObject.java
│ └── tests
│ ├── cards
│ ├── CardValidationTest.java
│ └── tokens
│ │ ├── DataFastValidationTest.java
│ │ └── TokenExValidationTest.java
│ ├── enums
│ └── contry
│ │ ├── CountryValidationTest.java
│ │ ├── MatchEnumArrayValidationTest.java
│ │ └── MatchEnumValidationTest.java
│ ├── global
│ ├── AssertTrueTest.java
│ ├── EmailValidationTest.java
│ ├── NotNullTest.java
│ ├── OneNotNullTest.java
│ ├── PastValidationTest.java
│ ├── PatternValidationTest.java
│ ├── SizeValidationTest.java
│ └── e2e
│ │ └── NotEmptyValidationTest.java
│ ├── number
│ ├── DecimalMinValidationTest.java
│ ├── DigitsValidationTest.java
│ ├── MaxValidationTest.java
│ └── MinValidationTest.java
│ └── strings
│ ├── AlphaNumericValidationTest.java
│ ├── Base64ValidationTest.java
│ ├── PasswordValidationTest.java
│ ├── UUIDTest.java
│ └── WordValidationTest.java
├── spring-commons-utilities
├── .flattened-pom.xml
├── README.md
├── pom.xml
└── src
│ ├── main
│ └── java
│ │ └── com
│ │ └── github
│ │ └── damianwajser
│ │ ├── factories
│ │ └── jsonbased
│ │ │ ├── FactoryCriteriaJsonBased.java
│ │ │ ├── conditions
│ │ │ ├── Condition.java
│ │ │ └── operations
│ │ │ │ ├── Operation.java
│ │ │ │ ├── OperationFactory.java
│ │ │ │ ├── OperationStrategy.java
│ │ │ │ └── impl
│ │ │ │ └── EqualsStrategy.java
│ │ │ └── criteria
│ │ │ ├── Criteria.java
│ │ │ ├── Criterion.java
│ │ │ └── builder
│ │ │ └── CriterionBuilder.java
│ │ ├── optionals
│ │ └── wrappers
│ │ │ ├── ConsumerWrapper.java
│ │ │ └── OptionalWrapper.java
│ │ └── parsers
│ │ ├── JsonToObjectConverter.java
│ │ └── Mapper.java
│ └── test
│ ├── java
│ └── test
│ │ ├── factory
│ │ └── jsonbased
│ │ │ ├── FactoryJsonBasedTest.java
│ │ │ ├── FactoryJsonBasedWithBuilderTest.java
│ │ │ └── TestUtils.java
│ │ ├── mapper
│ │ ├── JsonConverterTest.java
│ │ └── model
│ │ │ └── NotificationMapperModel.java
│ │ └── optional
│ │ └── OptionalTest.java
│ └── resources
│ ├── application.yml
│ └── data
│ └── data.json
└── spring-commons
├── .flattened-pom.xml
├── README.md
├── pom.xml
└── src
└── main
├── java
└── com
│ └── github
│ └── damianwajser
│ └── commons
│ └── configuration
│ └── PropertiesCommons.java
└── resources
└── spring-commons.properties
/.editorconfig:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/damianwajser/spring-commons/d1d7fd8f2fbf6691cacffc2587e4a441e4d318d1/.editorconfig
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report about: Create a report to help us improve title: ''
3 | labels: ''
4 | assignees: ''
5 |
6 | ---
7 |
8 | **Describe the bug**
9 | A clear and concise description of what the bug is.
10 |
11 | **To Reproduce**
12 | Steps to reproduce the behavior:
13 |
14 | 1. Go to '...'
15 | 2. Click on '....'
16 | 3. Scroll down to '....'
17 | 4. See error
18 |
19 | **Expected behavior**
20 | A clear and concise description of what you expected to happen.
21 |
22 | **Screenshots**
23 | If applicable, add screenshots to help explain your problem.
24 |
25 | **Desktop (please complete the following information):**
26 |
27 | - OS: [e.g. iOS]
28 | - Browser [e.g. chrome, safari]
29 | - Version [e.g. 22]
30 |
31 | **Smartphone (please complete the following information):**
32 |
33 | - Device: [e.g. iPhone6]
34 | - OS: [e.g. iOS8.1]
35 | - Browser [e.g. stock browser, safari]
36 | - Version [e.g. 22]
37 |
38 | **Additional context**
39 | Add any other context about the problem here.
40 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | addons:
2 | sonarcloud:
3 | organization: damianwajser
4 | sonar:
5 | projectKey: damian_wajser-spring-commons
6 | token:
7 | secure: "QDBfFCvCWXMW/+L4arJrKgSgq1YjZeFfm1mjs0A5LdJYZKb9jgcjnUIiGdiI8rXFfeK2Fx9vcDxyGRMcCOn8vqf54CWr+hnW378JMYlxOeorxQYWb0KNFg2P9m5OmtO79KiOCjPiLY9+l0osfAj3vH6nY6DKO4nPGLa5IAygekhAmOsAmMugAaYWnfPliHLB9mWTVP3sasTsW7WLlTgfDRds36sxhhPUPlcdIGIiV76AwIRXLgUra8QX9D/AYkon67jKyuCrGOCEu6sp20BYZGm76aNlQZL2gQbre8tb+SbYH9Rp5TaobgT7WZbnKAiIq4qTpkcFhgWgFD8NclmzeEHNt3XnUnGzNI7AuYil1vzOQ0KtBdFwXJie54gEh2lg+uYDbC2rCO3tv8LD+L+wuY7wBz+q6qYTDI/ssgM84El33kR14cWAkJOPR5pqTpkrCsKtgHfAXXiY+K4v8n4SNfIhhiFXr0brUlkSHgAIVc89fJMR979DyiCboXV/MkwIt2UL5Sa8u5THw6etdVjw2/EfQenHgeGh3JXsFFa6QpObJi3P3yBYC2pBuV4T27Sfb4Wc/+BdcOMGakTuCNEocT7INFaflNaK+zi9mb/oF0s81qEuWzf9YB3wsJibbhbG1PhGGsNFzBzlxGVdI2a+EN111iL9oMMuffzbyYtk+LY="
8 | script:
9 | - mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install sonar:sonar -Dsonar.projectKey=damian_wajser-spring-commons
10 |
--------------------------------------------------------------------------------
/SECURITY.md:
--------------------------------------------------------------------------------
1 | # Security Policy
2 |
3 | ## Supported Versions
4 |
5 | Use this section to tell people about which versions of your project are currently being supported with security
6 | updates.
7 |
8 | | Version | Supported |
9 | | ------- | ------------------ |
10 | | 16.0.0 | :white_check_mark: |
11 |
12 | ## Reporting a Vulnerability
13 |
14 | Use this section to tell people how to report a vulnerability.
15 |
--------------------------------------------------------------------------------
/sonar-project.properties:
--------------------------------------------------------------------------------
1 | # must be unique in a given SonarQube instance
2 | sonar.projectKey=damian_wajser-spring-commons
3 | # this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1.
4 | sonar.projectName=spring-commons-parent
5 | sonar.projectVersion=1.11.0
6 | # Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
7 | # This property is optional if sonar.modules is set.
8 | sonar.sources=src/main/java
9 | sonar.java.binaries=target/classes
10 | # java version used by source files:
11 | sonar.java.source=1.9
12 | # Encoding of the source code. Default is default system encoding
13 | #sonar.sourceEncoding=UTF-8
14 |
15 |
16 |
--------------------------------------------------------------------------------
/spring-commons-actuator/README.md:
--------------------------------------------------------------------------------
1 | # spring-commons-actuator
2 |
3 | ## Overview
4 |
5 | This module add developers functionality.
6 |
7 | It contains different functionalities:
8 |
9 | - Inspect the Caches
10 |
11 | -----
12 |
13 | ## Get it!
14 |
15 | ### Install
16 |
17 | #### Maven
18 |
19 | Functionality of this package is contained in Java package `com.github.damianwajser`, and can be used using following
20 | Maven dependency:
21 |
22 | ```xml
23 | ...
24 |
25 | ...
26 |
27 | {lastversion}
28 | ...
29 |
30 |
31 |
32 | ...
33 |
34 | com.github.damianwajser
35 | spring-commons-actuator
36 | ${spring.commons}
37 |
38 | ...
39 |
40 | ```
41 |
42 | #### Gradle
43 |
44 | ```xml
45 | compile 'com.github.damianwajser:spring-commons-cache:{lastVersion}'
46 | ```
47 |
48 | Exopose endpoints:
49 |
50 | 1) curl /actuator/caches/{cacheName}/detail
51 | 2) curl /actuator/cache-keys
52 | 3) curl /actuator/cache-keys/{key}
53 | 4) curl -X DELETE /actuator/cache-keys/{key}
54 |
55 | ## License
56 |
57 | The Spring Framework is released under version 2.0 of the [Apache License](http://www.apache.org/licenses/LICENSE-2.0).
58 |
--------------------------------------------------------------------------------
/spring-commons-actuator/src/main/java/com/github/damianwajser/commons/configuration/PropertiesActuator.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.commons.configuration;
2 |
3 | import org.springframework.boot.context.properties.ConfigurationProperties;
4 | import org.springframework.context.annotation.Configuration;
5 | import org.springframework.context.annotation.PropertySource;
6 |
7 | @Configuration
8 | @ConfigurationProperties
9 | @PropertySource("classpath:spring-commons-actuator.properties")
10 | public class PropertiesActuator {
11 | }
12 |
--------------------------------------------------------------------------------
/spring-commons-actuator/src/main/java/com/github/damianwajser/model/CacheInfo.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.model;
2 |
3 | import org.apache.commons.lang3.builder.EqualsBuilder;
4 | import org.apache.commons.lang3.builder.HashCodeBuilder;
5 | import org.apache.commons.lang3.builder.ToStringBuilder;
6 |
7 | import java.util.HashMap;
8 | import java.util.Map;
9 |
10 | public class CacheInfo {
11 |
12 | private String prefix;
13 | private Map keys = new HashMap<>();
14 | private String ttl;
15 |
16 | public String getPrefix() {
17 | return prefix;
18 | }
19 |
20 | public void setPrefix(String prefix) {
21 | this.prefix = prefix;
22 | }
23 |
24 | public Map getKeys() {
25 | return keys;
26 | }
27 |
28 | public void setKeys(Map keys) {
29 | this.keys = keys;
30 | }
31 |
32 | public String getTtl() {
33 | return ttl;
34 | }
35 |
36 | public void setTtl(String ttl) {
37 | this.ttl = ttl;
38 | }
39 |
40 | @Override
41 | public String toString() {
42 | return ToStringBuilder.reflectionToString(this);
43 | }
44 |
45 | @Override
46 | public boolean equals(Object o) {
47 | return EqualsBuilder.reflectionEquals(this, o);
48 | }
49 |
50 | @Override
51 | public int hashCode() {
52 | return HashCodeBuilder.reflectionHashCode(this);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/spring-commons-actuator/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.commons.app.name=test
2 | spring.commons.cache.enabled=true
3 | spring.commons.cache.prefix.enabled=true
4 | spring.commons.cache.prefix.value=ms-test
5 | spring-commons.cache.ttl.name.cache-ttl1=2
6 |
--------------------------------------------------------------------------------
/spring-commons-actuator/src/main/resources/spring-commons-actuator.properties:
--------------------------------------------------------------------------------
1 | security.basic.enabled=false
2 | endpoints.health.sensitive=false
3 | info.app.name=${spring.commons.app.name}
4 | spring.commons.actuator.cache.detail.enabled=${spring.commons.cache.enabled}
5 | management.endpoint.health.show-details=always
6 | management.security.enabled=false
7 | management.endpoints.web.exposure.include=*
8 | management.info.git.mode=full
9 |
--------------------------------------------------------------------------------
/spring-commons-actuator/src/test/java/com/github/damianwajser/TestApplication.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
5 | import org.springframework.boot.autoconfigure.SpringBootApplication;
6 |
7 | @SpringBootApplication
8 | @EnableAutoConfiguration
9 | public class TestApplication {
10 | public static void main(String[] args) {
11 | SpringApplication.run(TestApplication.class, args);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/spring-commons-actuator/src/test/java/com/github/damianwajser/controllers/TestController.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.controllers;
2 |
3 | import com.github.damianwajser.model.FooObject;
4 | import org.springframework.beans.factory.annotation.Autowired;
5 | import org.springframework.data.redis.core.RedisTemplate;
6 | import org.springframework.web.bind.annotation.GetMapping;
7 | import org.springframework.web.bind.annotation.PostMapping;
8 | import org.springframework.web.bind.annotation.RestController;
9 |
10 | @RestController
11 | public class TestController {
12 | @Autowired
13 | private RedisTemplate redisTemplate;
14 |
15 | @PostMapping("/postok")
16 | private FooObject postok() {
17 | return new FooObject("something");
18 | }
19 |
20 | @GetMapping("/")
21 | private String get() {
22 | redisTemplate.opsForValue().set("key", "value");
23 | return "";
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/spring-commons-actuator/src/test/java/com/github/damianwajser/model/FooObject.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.model;
2 |
3 | public class FooObject {
4 |
5 | private String value;
6 |
7 | public FooObject(String value) {
8 | super();
9 | this.value = value;
10 | }
11 |
12 | public String getValue() {
13 | return value;
14 | }
15 |
16 | public void setValue(String value) {
17 | this.value = value;
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/spring-commons-cache/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | /build/
3 | !gradle/wrapper/gradle-wrapper.jar
4 |
5 | ### STS ###
6 | .apt_generated
7 | .classpath
8 | .factorypath
9 | .project
10 | .settings
11 | .springBeans
12 |
13 | ### IntelliJ IDEA ###
14 | .idea
15 | *.iws
16 | *.iml
17 | *.ipr
18 |
19 | ### NetBeans ###
20 | nbproject/private/
21 | build/
22 | nbbuild/
23 | dist/
24 | nbdist/
25 | .nb-gradle/
26 |
27 | /out/
--------------------------------------------------------------------------------
/spring-commons-cache/src/main/java/com/github/damianwajser/configuration/PropertiesCommonsCache.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.configuration;
2 |
3 | import org.springframework.boot.context.properties.ConfigurationProperties;
4 | import org.springframework.context.annotation.Configuration;
5 | import org.springframework.context.annotation.PropertySource;
6 |
7 | @Configuration
8 | @ConfigurationProperties
9 | @PropertySource("classpath:spring-commons-cache.properties")
10 | public class PropertiesCommonsCache {
11 | }
12 |
--------------------------------------------------------------------------------
/spring-commons-cache/src/main/java/com/github/damianwajser/configuration/TtlProperties.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.configuration;
2 |
3 | import org.springframework.boot.context.properties.ConfigurationProperties;
4 | import org.springframework.context.annotation.Configuration;
5 |
6 | import java.util.HashMap;
7 | import java.util.Map;
8 |
9 | @ConfigurationProperties(prefix = "spring-commons.cache.ttl")
10 | @Configuration
11 | public class TtlProperties {
12 |
13 |
14 | private Map name = new HashMap<>();
15 |
16 | private int all = 86400;
17 |
18 | public void setName(Map name) {
19 | this.name = name;
20 | }
21 |
22 | public int getGenericTTl() {
23 | return this.all;
24 | }
25 |
26 | public void setAll(int all) {
27 | this.all = all;
28 | }
29 |
30 | public Map getTtls() {
31 | return this.name;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/spring-commons-cache/src/main/java/com/github/damianwajser/configuration/redis/RedisListenerConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.configuration.redis;
2 |
3 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
4 | import org.springframework.context.annotation.Bean;
5 | import org.springframework.context.annotation.Configuration;
6 | import org.springframework.data.redis.connection.RedisConnectionFactory;
7 | import org.springframework.data.redis.listener.RedisMessageListenerContainer;
8 |
9 | @Configuration
10 | @ConditionalOnProperty(name = "spring.commons.cache.enabled", havingValue = "true")
11 | public class RedisListenerConfiguration {
12 | @Bean
13 | @ConditionalOnProperty("redis.listener.enabled")
14 | public RedisMessageListenerContainer listenerContainer(RedisConnectionFactory connectionFactory) {
15 | RedisMessageListenerContainer listenerContainer = new RedisMessageListenerContainer();
16 | listenerContainer.setConnectionFactory(connectionFactory);
17 | return listenerContainer;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/spring-commons-cache/src/main/java/com/github/damianwajser/serializer/CustomJdkKeyPrefixRedisSerializer.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.serializer;
2 |
3 | import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer;
4 | import org.springframework.data.redis.serializer.StringRedisSerializer;
5 |
6 | public class CustomJdkKeyPrefixRedisSerializer extends JdkSerializationRedisSerializer {
7 |
8 | private final String prefix;
9 | private StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
10 |
11 | public CustomJdkKeyPrefixRedisSerializer(String prefix) {
12 | this.prefix = prefix;
13 | }
14 |
15 | @Override
16 | public byte[] serialize(Object source) {
17 | String key = prefix + source.toString();
18 | return stringRedisSerializer.serialize(key);
19 | }
20 |
21 | @Override
22 | public Object deserialize(byte[] source) {
23 | String saveKey = stringRedisSerializer.deserialize(source);
24 | int indexOf = saveKey.indexOf(prefix);
25 | if (indexOf > 0) {
26 | return null;
27 | } else {
28 | return saveKey.substring(indexOf + prefix.length());
29 | }
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/spring-commons-cache/src/main/java/com/github/damianwajser/serializer/CustomJdkRedisSerializer.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.serializer;
2 |
3 | import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer;
4 | import org.springframework.data.redis.serializer.SerializationException;
5 | import org.springframework.data.redis.serializer.StringRedisSerializer;
6 |
7 | public class CustomJdkRedisSerializer extends JdkSerializationRedisSerializer {
8 | private StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
9 |
10 | @Override
11 | public byte[] serialize(Object source) {
12 | if (source instanceof String || source instanceof Number) {
13 | return stringRedisSerializer.serialize(source.toString());
14 | }
15 | return super.serialize(source);
16 | }
17 |
18 | @Override
19 | public Object deserialize(byte[] source) {
20 | try {
21 | return super.deserialize(source);
22 | } catch (SerializationException sex) {
23 | return stringRedisSerializer.deserialize(source);
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/spring-commons-cache/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.commons.cache.enabled=true
2 | spring-commons.cache.ttl.name.cache-ttl1=2
3 | spring-commons.cache.ttl.name.cache-ttl2=3
4 | spring-commons.cache.ttl.all=2
5 |
--------------------------------------------------------------------------------
/spring-commons-cache/src/main/resources/spring-commons-cache.properties:
--------------------------------------------------------------------------------
1 | spring.commons.app.name=change this {spring.commons.app.name}
2 | spring.commons.cache.enabled=true
3 | spring.commons.cache.prefix.enabled=true
4 | spring.commons.cache.prefix.value=${spring.commons.app.name}
5 | spring.commons.cache.provider=redis
6 |
--------------------------------------------------------------------------------
/spring-commons-cache/src/test/java/com/github/damianwajser/TestApplication.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
5 | import org.springframework.boot.autoconfigure.SpringBootApplication;
6 |
7 | @SpringBootApplication
8 | @EnableAutoConfiguration
9 | public class TestApplication {
10 | public static void main(String[] args) {
11 | SpringApplication.run(TestApplication.class, args);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/spring-commons-cache/src/test/java/com/github/damianwajser/configuration/RedisConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.configuration;
2 |
3 | import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
4 | import org.springframework.boot.test.context.TestConfiguration;
5 | import org.springframework.context.annotation.Bean;
6 | import org.springframework.data.redis.connection.RedisConnectionFactory;
7 | import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
8 | import org.springframework.data.redis.connection.jedis.JedisClientConfiguration;
9 | import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
10 |
11 | import java.time.Duration;
12 |
13 | @TestConfiguration
14 | public class RedisConfiguration {
15 |
16 | @Bean
17 | public RedisConnectionFactory redisConnectionFactory(RedisProperties redisProperties) {
18 | RedisStandaloneConfiguration config = new RedisStandaloneConfiguration(redisProperties.getHost(),
19 | redisProperties.getPort());
20 | JedisClientConfiguration clientConfiguration = JedisClientConfiguration.builder().readTimeout(Duration.ofMillis(0)).
21 | connectTimeout(Duration.ofMillis(0)).build();
22 | return new JedisConnectionFactory(config, clientConfiguration);
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/spring-commons-cache/src/test/java/com/github/damianwajser/controller/CacheController.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.controller;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.web.bind.annotation.*;
5 |
6 | import java.util.Collection;
7 |
8 | @RestController
9 | public class CacheController {
10 |
11 | @Autowired
12 | private ServiceCache servicet;
13 |
14 |
15 | @GetMapping("/cache")
16 | private String get() {
17 | return servicet.generateUUID();
18 | }
19 |
20 | @GetMapping("/cache_all")
21 | private Collection getAll() {
22 | return servicet.getAll();
23 | }
24 |
25 | @GetMapping("/cache_all/{id}")
26 | private Integer getById(@PathVariable Integer id) {
27 |
28 | Integer customer = servicet.getId(1, id);
29 | if (customer == null) {
30 | throw new RuntimeException("asdasd");
31 | }
32 | return customer;
33 | }
34 |
35 | @PutMapping("/cache_all/{id}")
36 | private Integer put(@PathVariable Integer id) {
37 | return servicet.update(1, id);
38 | }
39 |
40 | @DeleteMapping("/cache_all/{id}")
41 | private void delete(@PathVariable Integer id) {
42 | servicet.delete(1, id);
43 | }
44 |
45 | @DeleteMapping("/cache")
46 | private String post() {
47 | return servicet.delete();
48 | }
49 |
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/spring-commons-cache/src/test/java/com/github/damianwajser/controller/ServiceCache.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.controller;
2 |
3 | import org.springframework.cache.annotation.CacheEvict;
4 | import org.springframework.cache.annotation.CachePut;
5 | import org.springframework.cache.annotation.Cacheable;
6 | import org.springframework.cache.annotation.Caching;
7 | import org.springframework.stereotype.Service;
8 |
9 | import java.util.Arrays;
10 | import java.util.Collection;
11 | import java.util.UUID;
12 |
13 | @Service
14 | public class ServiceCache {
15 |
16 | @Cacheable(value = "somecache2")
17 | public String generateUUID() {
18 | return UUID.randomUUID().toString();
19 | }
20 |
21 | @CacheEvict("somecache2")
22 | public String delete() {
23 | return null;
24 | }
25 |
26 | @Cacheable("customers_all")
27 | public Collection getAll() {
28 | return Arrays.asList(2, 2);
29 | }
30 |
31 | @Cacheable("customers")
32 | public Integer getId(Integer companyId, Integer id) {
33 | return id;
34 | }
35 |
36 | @CacheEvict("customers_all")
37 | @CachePut("customers")
38 | public Integer update(Object companyId, Integer id) {
39 | return 2;
40 | }
41 |
42 | @Caching(evict = {
43 | @CacheEvict(value = "customers_all", allEntries = true),
44 | @CacheEvict(value = "customers")
45 | })
46 | public void delete(Integer companyId, Integer id) {
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/spring-commons-cache/src/test/java/com/github/damianwajser/controller/ServiceCacheTtl.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.controller;
2 |
3 | import org.springframework.cache.annotation.Cacheable;
4 | import org.springframework.stereotype.Service;
5 |
6 | import java.util.UUID;
7 |
8 | @Service
9 | public class ServiceCacheTtl {
10 |
11 | @Cacheable(value = "cache-ttl1")
12 | public String generateUUID() {
13 | return UUID.randomUUID().toString();
14 | }
15 |
16 | @Cacheable(value = "cache-ttl2")
17 | public String generateUUID2() {
18 | return UUID.randomUUID().toString();
19 | }
20 |
21 | @Cacheable(value = "cache-ttl3")
22 | public String generateUUID3() {
23 | return UUID.randomUUID().toString();
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/spring-commons-cache/src/test/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.commons.cache.enabled=true
2 | spring-commons.cache.ttl.name.cache-ttl1=2
3 | spring-commons.cache.ttl.name.cache-ttl2=3
4 | spring-commons.cache.ttl.all=2
5 |
--------------------------------------------------------------------------------
/spring-commons-cache/src/test/resources/spring-commons-cache.properties:
--------------------------------------------------------------------------------
1 | spring.commons.app.name=change spring.commons.app.name property (spring-commons-cache)
2 | spring.commons.cache.prefix.value=${spring.commons.app.name}
3 | spring.commons.cache.provider=redis
4 |
--------------------------------------------------------------------------------
/spring-commons-exception-handler/.flattened-pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | com.github.damianwajser
7 | spring-commons-parent
8 | 1.28.5
9 |
10 | com.github.damianwajser
11 | spring-commons-exception-handler
12 | 1.28.5
13 |
14 |
15 | Apache License, Version 2.0
16 | http://www.apache.org/licenses/LICENSE-2.0.txt
17 | repo
18 |
19 |
20 |
21 |
22 | com.github.damianwajser
23 | spring-commons-exception
24 | ${project.version}
25 |
26 |
27 | com.github.damianwajser
28 | spring-commons-rest-validation
29 | ${project.version}
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/spring-commons-exception-handler/pom.xml:
--------------------------------------------------------------------------------
1 |
4 | 4.0.0
5 | spring-commons-exception-handler
6 | jar
7 | ${revision}
8 |
9 | com.github.damianwajser
10 | spring-commons-parent
11 | ${revision}
12 |
13 |
14 |
15 | com.github.damianwajser
16 | spring-commons-exception
17 | ${project.version}
18 |
19 |
20 | com.github.damianwajser
21 | spring-commons-rest-validation
22 | ${project.version}
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/spring-commons-exception-handler/src/main/java/com/github/damianwajser/exceptions/configuration/CustomLocaleResolver.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.exceptions.configuration;
2 |
3 | import org.springframework.context.annotation.Configuration;
4 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
5 | import org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver;
6 |
7 | import javax.servlet.http.HttpServletRequest;
8 | import java.util.Arrays;
9 | import java.util.List;
10 | import java.util.Locale;
11 |
12 | @Configuration
13 | public class CustomLocaleResolver extends AcceptHeaderLocaleResolver implements WebMvcConfigurer {
14 |
15 | private static final List LOCALES = Arrays.asList(
16 | new Locale("en"),
17 | new Locale("es"),
18 | new Locale("fr"));
19 |
20 | @Override
21 | public Locale resolveLocale(HttpServletRequest request) {
22 | String headerLang = request.getHeader("Accept-Language");
23 | return headerLang == null || headerLang.isEmpty()
24 | ? Locale.getDefault()
25 | : Locale.lookup(Locale.LanguageRange.parse(headerLang), LOCALES);
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/spring-commons-exception-handler/src/main/java/com/github/damianwajser/exceptions/configuration/I18nConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.exceptions.configuration;
2 |
3 | import org.springframework.context.MessageSource;
4 | import org.springframework.context.annotation.Bean;
5 | import org.springframework.context.annotation.Configuration;
6 | import org.springframework.context.support.ReloadableResourceBundleMessageSource;
7 | import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
8 |
9 | @Configuration
10 | public class I18nConfiguration {
11 |
12 | @Bean
13 | public MessageSource messageSource() {
14 | ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
15 | messageSource.setBasename("classpath:messages");
16 | messageSource.setDefaultEncoding("UTF-8");
17 | messageSource.setConcurrentRefresh(true);
18 | messageSource.setCacheSeconds(90);
19 | return messageSource;
20 | }
21 |
22 | @Bean
23 | public LocalValidatorFactoryBean getValidator() {
24 | LocalValidatorFactoryBean bean = new LocalValidatorFactoryBean();
25 | bean.setValidationMessageSource(messageSource());
26 | return bean;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/spring-commons-exception-handler/src/test/java/com/github/damianwajser/TestApplication.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
5 | import org.springframework.boot.autoconfigure.SpringBootApplication;
6 |
7 | @SpringBootApplication
8 | @EnableAutoConfiguration
9 | public class TestApplication {
10 | public static void main(String[] args) {
11 | SpringApplication.run(TestApplication.class, args);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/spring-commons-exception-handler/src/test/java/com/github/damianwajser/controllers/BadRequestValidationController.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.controllers;
2 |
3 | import com.github.damianwajser.exceptions.impl.badrequest.BadRequestException;
4 | import com.github.damianwajser.model.CustomValidationFooObject;
5 | import com.github.damianwajser.model.FooObject;
6 | import org.springframework.web.bind.annotation.PostMapping;
7 | import org.springframework.web.bind.annotation.RequestMapping;
8 | import org.springframework.web.bind.annotation.RestController;
9 |
10 | import javax.validation.Valid;
11 | import java.util.Optional;
12 |
13 | @RestController
14 | @RequestMapping("/validation")
15 | public class BadRequestValidationController {
16 |
17 | @PostMapping("/badrequest")
18 | private FooObject badRequest(@Valid FooObject object) throws BadRequestException {
19 | throw new BadRequestException("400", "badrequest", Optional.empty());
20 | }
21 |
22 | @PostMapping("/custom")
23 | private FooObject badRequest(@Valid CustomValidationFooObject object) throws BadRequestException {
24 | throw new BadRequestException("400", "badrequest", Optional.empty());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/spring-commons-exception-handler/src/test/java/com/github/damianwajser/controllers/I18nBadRequestController.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.controllers;
2 |
3 | import com.github.damianwajser.exceptions.impl.badrequest.BadRequestException;
4 | import com.github.damianwajser.model.FooObject;
5 | import org.springframework.web.bind.annotation.PostMapping;
6 | import org.springframework.web.bind.annotation.RequestMapping;
7 | import org.springframework.web.bind.annotation.RestController;
8 |
9 | import java.util.Optional;
10 |
11 | @RestController
12 | @RequestMapping("/i18n")
13 | public class I18nBadRequestController {
14 |
15 | @PostMapping("/literal")
16 | private FooObject literal() throws BadRequestException {
17 | throw new BadRequestException("literal", "badrequest", Optional.empty());
18 | }
19 |
20 | @PostMapping("/withproperties")
21 | private FooObject withproperties() throws BadRequestException {
22 | throw new BadRequestException("withproperties", "{spring.commons.validation.constraints.NotEmpty.message}", Optional.empty());
23 | }
24 |
25 | @PostMapping("/withproperties/notfound")
26 | private FooObject withpropertiesNotfound() throws BadRequestException {
27 | throw new BadRequestException("notfound", "{spring.commons}", Optional.empty());
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/spring-commons-exception-handler/src/test/java/com/github/damianwajser/controllers/NotFoundController.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.controllers;
2 |
3 | import com.github.damianwajser.exceptions.impl.badrequest.NotFoundException;
4 | import com.github.damianwajser.model.FooObject;
5 | import org.springframework.web.bind.annotation.PostMapping;
6 | import org.springframework.web.bind.annotation.RestController;
7 |
8 | import java.util.Optional;
9 |
10 | @RestController
11 | public class NotFoundController {
12 |
13 | @PostMapping("/notfound")
14 | private FooObject badRequest() throws NotFoundException {
15 | throw new NotFoundException("404", "notfound", Optional.empty());
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/spring-commons-exception-handler/src/test/java/com/github/damianwajser/controllers/OtheRequestController.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.controllers;
2 |
3 | import com.github.damianwajser.exceptions.impl.badrequest.BadRequestException;
4 | import com.github.damianwajser.model.FooObject;
5 | import org.springframework.validation.annotation.Validated;
6 | import org.springframework.web.bind.annotation.PostMapping;
7 | import org.springframework.web.bind.annotation.RestController;
8 |
9 | @RestController
10 | @Validated
11 | public class OtheRequestController {
12 |
13 | @PostMapping("/other")
14 | private FooObject badRequest() throws BadRequestException {
15 | throw new NullPointerException();
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/spring-commons-exception-handler/src/test/java/com/github/damianwajser/controllers/TestForbiddenController.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.controllers;
2 |
3 | import com.github.damianwajser.exceptions.impl.authentication.forbidden.ForbiddenException;
4 | import com.github.damianwajser.exceptions.impl.authentication.forbidden.PermissionDeniedException;
5 | import com.github.damianwajser.model.FooObject;
6 | import org.springframework.web.bind.annotation.PostMapping;
7 | import org.springframework.web.bind.annotation.RestController;
8 |
9 | import java.util.Optional;
10 |
11 | @RestController
12 | public class TestForbiddenController {
13 |
14 | @PostMapping("/forbbiden")
15 | private FooObject forbbiden() throws ForbiddenException {
16 | throw new ForbiddenException("403", "forbbiden", Optional.empty());
17 | }
18 |
19 | @PostMapping("/permissionDenied")
20 | private FooObject permissionDenied() throws PermissionDeniedException {
21 | throw new PermissionDeniedException("403", "permissionDenied", Optional.empty());
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/spring-commons-exception-handler/src/test/java/com/github/damianwajser/model/EnumArrayOject.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.model;
2 |
3 | import com.github.damianwajser.validator.annotation.enums.MatchEnum;
4 | import com.github.damianwajser.validator.constraint.enums.values.Countries;
5 |
6 | public class EnumArrayOject {
7 | @MatchEnum(message = "hola", businessCode = "code_333", enumClass = Countries.class, isNulleable = false) Countries[] country;
8 | }
9 |
--------------------------------------------------------------------------------
/spring-commons-exception-handler/src/test/java/com/github/damianwajser/model/EnumModel.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.model;
2 |
3 | import com.github.damianwajser.validator.annotation.global.NotEmpty;
4 |
5 | public class EnumModel {
6 |
7 | @NotEmpty(businessCode = "asd")
8 | private TEST a;
9 |
10 |
11 | public TEST getA() {
12 | return a;
13 | }
14 |
15 | public void setA(TEST a) {
16 | this.a = a;
17 | }
18 |
19 | public enum TEST {
20 | A, B;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/spring-commons-exception-handler/src/test/java/com/github/damianwajser/model/FooObject.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.model;
2 |
3 | import javax.validation.constraints.NotEmpty;
4 |
5 | public class FooObject {
6 |
7 | @NotEmpty
8 | private String value;
9 |
10 | public FooObject() {
11 | }
12 |
13 | public FooObject(String value) {
14 | super();
15 | this.value = value;
16 | }
17 |
18 | public String getValue() {
19 | return value;
20 | }
21 |
22 | public void setValue(String value) {
23 | this.value = value;
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/spring-commons-exception-handler/src/test/java/com/github/damianwajser/tests/MapperErrorTest.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.tests;
2 |
3 | import com.github.damianwajser.exceptions.model.ErrorMessage;
4 | import org.junit.Assert;
5 | import org.junit.Test;
6 | import org.springframework.boot.test.context.SpringBootTest;
7 |
8 | @SpringBootTest
9 | public class MapperErrorTest {
10 | @Test
11 | public void ParseMessage() throws Exception {
12 | String bodyCammel = "{\"details\":[{\"errorCode\":\"400\",\"errorMessage\":\"badrequest\",\"errorDetail\":null,\"metaData\":null}]}";
13 | Assert.assertEquals("400", ErrorMessage.getInstance(bodyCammel).getDetails().get(0).getErrorCode());
14 | String bodySnake = "{\"details\":[{\"error_code\":\"400\",\"error_message\":\"badrequest\",\"error_detail\":null,\"meta_data\":null}]}";
15 | Assert.assertEquals("400", ErrorMessage.getInstance(bodySnake).getDetails().get(0).getErrorCode());
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/spring-commons-exception-handler/src/test/resources/application.properties:
--------------------------------------------------------------------------------
1 | last.argument=final comment, for testing purpose
2 |
--------------------------------------------------------------------------------
/spring-commons-exception-handler/src/test/resources/messages_en.properties:
--------------------------------------------------------------------------------
1 | spring.commons.validation.constraints.NotEmpty.message=Engilsh message
2 | spring.commons.message.with.args=English message with {0} on {1,date} at {2,time} and {3} as arguments
3 |
--------------------------------------------------------------------------------
/spring-commons-exception-handler/src/test/resources/messages_es.properties:
--------------------------------------------------------------------------------
1 | spring.commons.validation.constraints.NotEmpty.message=Español message
2 | spring.commons.message.with.args=Mensaje en espanol con {0} el {1, date} a {2, time} y {3} como argumentos
3 |
--------------------------------------------------------------------------------
/spring-commons-exception-handler/src/test/resources/messages_fr.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/damianwajser/spring-commons/d1d7fd8f2fbf6691cacffc2587e4a441e4d318d1/spring-commons-exception-handler/src/test/resources/messages_fr.properties
--------------------------------------------------------------------------------
/spring-commons-exception/.flattened-pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | com.github.damianwajser
7 | spring-commons-parent
8 | 1.28.5
9 |
10 | com.github.damianwajser
11 | spring-commons-exception
12 | 1.28.5
13 |
14 |
15 | Apache License, Version 2.0
16 | http://www.apache.org/licenses/LICENSE-2.0.txt
17 | repo
18 |
19 |
20 |
21 |
22 | org.reflections
23 | reflections
24 | 0.9.12
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/spring-commons-exception/pom.xml:
--------------------------------------------------------------------------------
1 |
4 | 4.0.0
5 | spring-commons-exception
6 | jar
7 | ${revision}
8 |
9 | com.github.damianwajser
10 | spring-commons-parent
11 | ${revision}
12 |
13 |
14 |
15 | org.reflections
16 | reflections
17 | 0.9.12
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/spring-commons-exception/src/main/resources/application.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/damianwajser/spring-commons/d1d7fd8f2fbf6691cacffc2587e4a441e4d318d1/spring-commons-exception/src/main/resources/application.properties
--------------------------------------------------------------------------------
/spring-commons-exception/src/test/java/com/github/damianwajser/TestApplication.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
5 | import org.springframework.boot.autoconfigure.SpringBootApplication;
6 |
7 | @SpringBootApplication
8 | @EnableAutoConfiguration
9 | public class TestApplication {
10 | public static void main(String[] args) {
11 | SpringApplication.run(TestApplication.class, args);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/spring-commons-exception/src/test/java/com/github/damianwajser/controllers/BadRequestController.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.controllers;
2 |
3 | import com.github.damianwajser.exceptions.impl.badrequest.BadRequestException;
4 | import com.github.damianwajser.model.FooObject;
5 | import org.springframework.web.bind.annotation.PostMapping;
6 | import org.springframework.web.bind.annotation.RestController;
7 |
8 | import java.util.Optional;
9 |
10 | @RestController
11 | public class BadRequestController {
12 |
13 | @PostMapping("/badrequest")
14 | private FooObject badRequest() throws BadRequestException {
15 | throw new BadRequestException("2020", "badrequest", Optional.empty());
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/spring-commons-exception/src/test/java/com/github/damianwajser/controllers/ConflictController.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.controllers;
2 |
3 | import com.github.damianwajser.exceptions.impl.badrequest.ConflictException;
4 | import com.github.damianwajser.model.FooObject;
5 | import org.springframework.web.bind.annotation.PostMapping;
6 | import org.springframework.web.bind.annotation.RestController;
7 |
8 | import java.util.Optional;
9 |
10 | @RestController
11 | public class ConflictController {
12 |
13 | @PostMapping("/conflict")
14 | private FooObject conflict() throws ConflictException {
15 | throw new ConflictException("2020", "conflict", Optional.empty());
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/spring-commons-exception/src/test/java/com/github/damianwajser/controllers/NotFoundController.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.controllers;
2 |
3 | import com.github.damianwajser.exceptions.impl.badrequest.NotFoundException;
4 | import com.github.damianwajser.model.FooObject;
5 | import org.springframework.web.bind.annotation.PostMapping;
6 | import org.springframework.web.bind.annotation.RestController;
7 |
8 | import java.util.Optional;
9 |
10 | @RestController
11 | public class NotFoundController {
12 |
13 | @PostMapping("/notfound")
14 | private FooObject badRequest() throws NotFoundException {
15 | throw new NotFoundException("202", "notfound", Optional.empty());
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/spring-commons-exception/src/test/java/com/github/damianwajser/controllers/TestForbiddenController.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.controllers;
2 |
3 | import com.github.damianwajser.exceptions.impl.authentication.forbidden.ForbiddenException;
4 | import com.github.damianwajser.exceptions.impl.authentication.forbidden.PermissionDeniedException;
5 | import com.github.damianwajser.model.FooObject;
6 | import org.springframework.web.bind.annotation.PostMapping;
7 | import org.springframework.web.bind.annotation.RestController;
8 |
9 | import java.util.Optional;
10 |
11 | @RestController
12 | public class TestForbiddenController {
13 |
14 | @PostMapping("/forbbiden")
15 | private FooObject forbbiden() throws ForbiddenException {
16 | throw new ForbiddenException("", "forbbiden", Optional.empty());
17 | }
18 |
19 | @PostMapping("/permissionDenied")
20 | private FooObject permissionDenied() throws PermissionDeniedException {
21 | throw new PermissionDeniedException("", "permissionDenied", Optional.empty());
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/spring-commons-exception/src/test/java/com/github/damianwajser/model/FooObject.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.model;
2 |
3 | public class FooObject {
4 |
5 | private String value;
6 |
7 | public FooObject(String value) {
8 | super();
9 | this.value = value;
10 | }
11 |
12 | public String getValue() {
13 | return value;
14 | }
15 |
16 | public void setValue(String value) {
17 | this.value = value;
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/spring-commons-exception/src/test/java/com/github/damianwajser/utils/TestUtils.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.utils;
2 |
3 | public class TestUtils {
4 |
5 |
6 | }
7 |
--------------------------------------------------------------------------------
/spring-commons-http-fixer/.flattened-pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | com.github.damianwajser
7 | spring-commons-parent
8 | 1.28.5
9 |
10 | com.github.damianwajser
11 | spring-commons-http-fixer
12 | 1.28.5
13 |
14 |
15 | Apache License, Version 2.0
16 | http://www.apache.org/licenses/LICENSE-2.0.txt
17 | repo
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/spring-commons-http-fixer/README.md:
--------------------------------------------------------------------------------
1 | # spring-commons-http-fixer
2 |
3 | ## Overview
4 |
5 | This project is in charge of solving the most common problems related to http codes in spring-mvc REST responses. Among
6 | other things, set the default http 201 code in the response when we are using the POST verb.
7 |
8 | -----
9 |
10 | ## Get it!
11 |
12 | ### Install
13 |
14 | #### Maven
15 |
16 | Functionality of this package is contained in Java package `com.github.damianwajser`, and can be used using following
17 | Maven dependency:
18 |
19 | ```xml
20 | ...
21 |
22 | ...
23 |
24 | {lastversion}
25 | ...
26 |
27 |
28 |
29 | ...
30 |
31 | com.github.damianwajser
32 | spring-commons-http-fixer
33 | ${spring.commons}
34 |
35 | ...
36 |
37 | ```
38 |
39 | #### Gradle
40 |
41 | ```xml
42 | compile 'com.github.damianwajser:spring-commons-http-fixer:{lastVersion}'
43 | ```
44 |
45 | ## Properties
46 |
47 | | Key | Posible Value | Reference | Default Value
48 | |--|--|--|--
49 | | spring.commons.http.fixer.enabled | boolean | enable the module | true
50 |
51 | ## License
52 |
53 | The Spring Framework is released under version 2.0 of the [Apache License](http://www.apache.org/licenses/LICENSE-2.0).
54 |
--------------------------------------------------------------------------------
/spring-commons-http-fixer/pom.xml:
--------------------------------------------------------------------------------
1 |
4 | 4.0.0
5 | spring-commons-http-fixer
6 | jar
7 | ${revision}
8 |
9 | com.github.damianwajser
10 | spring-commons-parent
11 | ${revision}
12 |
13 |
14 |
--------------------------------------------------------------------------------
/spring-commons-http-fixer/src/main/java/com/github/damianwajser/web/configuration/PropertiesHttpFixer.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.web.configuration;
2 |
3 | import org.springframework.beans.factory.annotation.Value;
4 | import org.springframework.boot.context.properties.ConfigurationProperties;
5 | import org.springframework.context.annotation.Configuration;
6 | import org.springframework.context.annotation.PropertySource;
7 |
8 | @Configuration
9 | @ConfigurationProperties
10 | @PropertySource("classpath:spring-commons-http.properties")
11 | public class PropertiesHttpFixer {
12 |
13 | @Value("${spring.commons.http.fixer.enabled}")
14 | private boolean enabled;
15 |
16 | public boolean isEnabled() {
17 | return enabled;
18 | }
19 |
20 | public void setEnabled(boolean enabled) {
21 | this.enabled = enabled;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/spring-commons-http-fixer/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.jackson.property-naming-strategy=com.fasterxml.jackson.databind.PropertyNamingStrategy.SnakeCaseStrategy
2 |
--------------------------------------------------------------------------------
/spring-commons-http-fixer/src/main/resources/spring-commons-http.properties:
--------------------------------------------------------------------------------
1 | spring.commons.http.fixer.enabled=true
2 |
--------------------------------------------------------------------------------
/spring-commons-http-fixer/src/test/java/com/github/damianwajser/TestApplication.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
5 | import org.springframework.boot.autoconfigure.SpringBootApplication;
6 |
7 | @SpringBootApplication
8 | @EnableAutoConfiguration
9 | public class TestApplication {
10 | public static void main(String[] args) {
11 | SpringApplication.run(TestApplication.class, args);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/spring-commons-http-fixer/src/test/java/com/github/damianwajser/controllers/TestController.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.controllers;
2 |
3 | import com.github.damianwajser.model.FooObject;
4 | import org.springframework.http.HttpStatus;
5 | import org.springframework.web.bind.annotation.*;
6 |
7 | @RestController
8 | public class TestController {
9 |
10 | @PostMapping("/postok")
11 | private FooObject postok() {
12 | return new FooObject("something");
13 | }
14 |
15 | @PostMapping("/postnok")
16 | private Object postnok() {
17 | throw new RuntimeException("error");
18 | }
19 |
20 | @ResponseStatus(HttpStatus.ACCEPTED)
21 | @PostMapping("/postchanged")
22 | private Object postchanged() {
23 | return new FooObject("something");
24 | }
25 |
26 | @GetMapping("/getok")
27 | private Object getok() {
28 | return new FooObject("something");
29 | }
30 |
31 | @GetMapping("/getnok")
32 | private Object getnok() {
33 | throw new RuntimeException("error");
34 | }
35 |
36 | @DeleteMapping("/delete_void")
37 | private void getvoid() {
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/spring-commons-http-fixer/src/test/java/com/github/damianwajser/model/FooObject.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.model;
2 |
3 | public class FooObject {
4 |
5 | private String value;
6 |
7 | public FooObject(String value) {
8 | super();
9 | this.value = value;
10 | }
11 |
12 | public String getValue() {
13 | return value;
14 | }
15 |
16 | public void setValue(String value) {
17 | this.value = value;
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/spring-commons-idempotency/src/main/java/com/github/damianwajser/idempotency/configuration/IdempotencyEndpoint.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.idempotency.configuration;
2 |
3 | import com.github.damianwajser.exceptions.RestException;
4 | import com.github.damianwajser.idempotency.generators.IdempotencyKeyGenerator;
5 | import com.github.damianwajser.idempotency.utils.HeadersUtil;
6 | import org.owasp.encoder.Encode;
7 | import org.springframework.http.HttpMethod;
8 | import org.springframework.util.Assert;
9 |
10 | import javax.servlet.http.HttpServletRequest;
11 | import java.util.Set;
12 |
13 | public class IdempotencyEndpoint {
14 |
15 | private final IdempotencyKeyGenerator generator;
16 | private Set methods;
17 |
18 | public IdempotencyEndpoint(Set methods, IdempotencyKeyGenerator generator) {
19 | this.methods = methods;
20 | this.generator = generator;
21 | Assert.notNull(generator, "Genenerator cant be null");
22 | }
23 |
24 | public String generateKey(HttpServletRequest request) throws RestException {
25 | return generator.generateKey(new HeadersUtil().getHeaders(request),
26 | HttpMethod.valueOf(request.getMethod()), Encode.forJava(request.getRequestURI()), request);
27 | }
28 |
29 | public boolean isAppicable(HttpMethod httpMethod) {
30 | return this.methods.contains(httpMethod) || this.methods.isEmpty();
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/spring-commons-idempotency/src/main/java/com/github/damianwajser/idempotency/configuration/IdempotencyProperties.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.idempotency.configuration;
2 |
3 | import org.springframework.beans.factory.annotation.Value;
4 | import org.springframework.boot.context.properties.ConfigurationProperties;
5 | import org.springframework.boot.context.properties.EnableConfigurationProperties;
6 | import org.springframework.context.annotation.Configuration;
7 |
8 | @Configuration
9 | @EnableConfigurationProperties
10 | @ConfigurationProperties(prefix = "spring.commons.idempotency")
11 | public class IdempotencyProperties {
12 |
13 | @Value("${spring.commons.idempotency.badrequest.code:400}")
14 | private String keyNotFoud;
15 |
16 | @Value("${spring.commons.idempotency.conflict.code:409}")
17 | private String conflictCode;
18 |
19 | @Value("${spring.commons.idempotency.conflict.mesasge:idempotency key is bussy}")
20 | private String conflictMessage;
21 |
22 | //Time in millis
23 | @Value("${spring.commons.idempotency.ttl:86400000}")
24 | private long ttl;
25 |
26 | public long getIdempotencyTtl() {
27 | return ttl;
28 | }
29 |
30 | public String getBadRequestCode() {
31 | return keyNotFoud;
32 | }
33 |
34 | public String getConflictCode() {
35 | return conflictCode;
36 | }
37 |
38 | public String getConflictMessage() {
39 | return conflictMessage;
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/spring-commons-idempotency/src/main/java/com/github/damianwajser/idempotency/exception/ArgumentNotFoundException.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.idempotency.exception;
2 |
3 | public class ArgumentNotFoundException extends RuntimeException {
4 |
5 | private final String argument;
6 |
7 | public ArgumentNotFoundException(String argument) {
8 | this.argument = argument;
9 | }
10 |
11 | public String getArgument() {
12 | return argument;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/spring-commons-idempotency/src/main/java/com/github/damianwajser/idempotency/exception/RedisException.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.idempotency.exception;
2 |
3 | public class RedisException extends RuntimeException {
4 |
5 | public RedisException(String message) {
6 | super(message);
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/spring-commons-idempotency/src/main/java/com/github/damianwajser/idempotency/generators/DefaultIdempotencyKeyGenerator.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.idempotency.generators;
2 |
3 | import com.github.damianwajser.idempotency.exception.ArgumentNotFoundException;
4 | import org.springframework.http.HttpHeaders;
5 | import org.springframework.http.HttpMethod;
6 |
7 | import javax.servlet.http.HttpServletRequest;
8 | import java.util.List;
9 | import java.util.stream.Collectors;
10 |
11 | public class DefaultIdempotencyKeyGenerator implements IdempotencyKeyGenerator {
12 |
13 | private static final String IDEMPOTENCY_DEFAULT_HEADER = "X-Idempotency-Key";
14 |
15 | @Override
16 | public String generateKey(HttpHeaders headers, HttpMethod method, String path, HttpServletRequest request) {
17 | String key = getHeaderValue(headers, IDEMPOTENCY_DEFAULT_HEADER);
18 | return path + "::" + key + "::" + method.toString();
19 | }
20 |
21 | protected String getHeaderValue(HttpHeaders headers, String headerKey) {
22 | List idempotencyHeader = headers.get(headerKey);
23 | String key;
24 | if (idempotencyHeader != null) {
25 | key = idempotencyHeader.stream().collect(Collectors.joining("::"));
26 | } else {
27 | throw new ArgumentNotFoundException(headerKey);
28 | }
29 | return key;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/spring-commons-idempotency/src/main/java/com/github/damianwajser/idempotency/generators/IdempotencyKeyGenerator.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.idempotency.generators;
2 |
3 | import com.github.damianwajser.exceptions.RestException;
4 | import org.springframework.http.HttpHeaders;
5 | import org.springframework.http.HttpMethod;
6 |
7 | import javax.servlet.http.HttpServletRequest;
8 |
9 | public interface IdempotencyKeyGenerator {
10 | String generateKey(HttpHeaders headers, HttpMethod method, String path, HttpServletRequest request) throws RestException;
11 | }
12 |
--------------------------------------------------------------------------------
/spring-commons-idempotency/src/main/java/com/github/damianwajser/idempotency/utils/HeadersUtil.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.idempotency.utils;
2 |
3 | import org.springframework.http.HttpHeaders;
4 |
5 | import javax.servlet.http.HttpServletRequest;
6 | import javax.servlet.http.HttpServletResponse;
7 | import java.util.Collections;
8 | import java.util.Map;
9 | import java.util.function.Function;
10 | import java.util.stream.Collectors;
11 |
12 | public class HeadersUtil {
13 |
14 | public HttpHeaders getHeaders(HttpServletRequest request) {
15 | return Collections.list(request.getHeaderNames()).stream()
16 | .collect(Collectors.toMap(
17 | Function.identity(),
18 | h -> Collections.list(request.getHeaders(h)),
19 | (oldValue, newValue) -> newValue,
20 | HttpHeaders::new
21 | ));
22 | }
23 |
24 | public Map getHeadersMap(HttpServletResponse response) {
25 | return response.getHeaderNames()
26 | .stream()
27 | .collect(Collectors.toMap(
28 | Function.identity(),
29 | h -> response.getHeaders(h).stream().collect(Collectors.joining(","))
30 | ));
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/spring-commons-idempotency/src/main/java/com/github/damianwajser/idempotency/utils/JsonUtils.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.idempotency.utils;
2 |
3 | import com.fasterxml.jackson.core.JsonProcessingException;
4 | import com.fasterxml.jackson.databind.ObjectMapper;
5 | import com.fasterxml.jackson.databind.PropertyNamingStrategy;
6 | import org.slf4j.Logger;
7 | import org.slf4j.LoggerFactory;
8 |
9 | public class JsonUtils {
10 |
11 | private static final Logger LOGGER = LoggerFactory.getLogger(JsonUtils.class);
12 |
13 | public String objectToJsonString(Object message) throws JsonProcessingException {
14 | ObjectMapper objectMapper = new ObjectMapper();
15 | objectMapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
16 | String objectJson = objectMapper.writeValueAsString(message)
17 | .replace("\\\\", "");
18 | if (objectJson.startsWith("\"")) {
19 | objectJson = objectJson.replaceFirst("\"", "").trim();
20 | }
21 |
22 | if (objectJson.substring(objectJson.length() - 1, objectJson.length()).equals("\"")) {
23 | objectJson = objectJson.substring(0, objectJson.length() - 1);
24 | }
25 | LOGGER.info("convert json: {}", objectJson);
26 | return objectJson;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/spring-commons-idempotency/src/main/java/com/github/damianwajser/idempotency/writers/HttpServletResponseCopier.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.idempotency.writers;
2 |
3 | import javax.servlet.ServletOutputStream;
4 | import javax.servlet.http.HttpServletResponse;
5 | import javax.servlet.http.HttpServletResponseWrapper;
6 | import java.io.IOException;
7 |
8 | public class HttpServletResponseCopier extends HttpServletResponseWrapper {
9 |
10 | private ServletOutputStream outputStream;
11 | private ServletOutputStreamCopier copier;
12 |
13 | public HttpServletResponseCopier(HttpServletResponse response) throws IOException {
14 | super(response);
15 | }
16 |
17 | @Override
18 | public ServletOutputStream getOutputStream() throws IOException {
19 |
20 | if (outputStream == null) {
21 | outputStream = getResponse().getOutputStream();
22 | copier = new ServletOutputStreamCopier(outputStream);
23 | }
24 |
25 | return copier;
26 | }
27 |
28 | public byte[] getCopy() {
29 | if (copier != null) {
30 | return copier.getCopy();
31 | } else {
32 | return new byte[0];
33 | }
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/spring-commons-idempotency/src/main/java/com/github/damianwajser/idempotency/writers/ServletOutputStreamCopier.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.idempotency.writers;
2 |
3 | import javax.servlet.ServletOutputStream;
4 | import javax.servlet.WriteListener;
5 | import java.io.ByteArrayOutputStream;
6 | import java.io.IOException;
7 | import java.io.OutputStream;
8 |
9 | public class ServletOutputStreamCopier extends ServletOutputStream {
10 |
11 | private OutputStream outputStream;
12 | private ByteArrayOutputStream copy;
13 |
14 | public ServletOutputStreamCopier(OutputStream outputStream) {
15 | this.outputStream = outputStream;
16 | this.copy = new ByteArrayOutputStream(1024);
17 | }
18 |
19 | @Override
20 | public void write(int b) throws IOException {
21 | outputStream.write(b);
22 | copy.write(b);
23 | }
24 |
25 | public byte[] getCopy() {
26 | return copy.toByteArray();
27 | }
28 |
29 | @Override
30 | public boolean isReady() {
31 | return true;
32 | }
33 |
34 | @Override
35 | public void setWriteListener(WriteListener listener) {
36 | // not implemennts listeners
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/spring-commons-idempotency/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.commons.idempotency.enabled=true
2 | spring.commons.idempotency.message=test
3 | spring.commons.idempotency.ttl=1000000
4 | spring.commons.idempotency.badrequest.code=400
5 | spring.commons.idempotency.conflict.code=409
6 | spring.commons.idempotency.conflict.mesasge=idempotency key is bussy
7 | spring.commons.cache.enabled=true
8 | spring.commons.cache.prefix.enabled=true
9 | spring.commons.cache.prefix.value=ms-test
10 |
--------------------------------------------------------------------------------
/spring-commons-idempotency/src/test/java/com/github/damianwajser/TestApplication.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
5 | import org.springframework.boot.autoconfigure.SpringBootApplication;
6 |
7 | @SpringBootApplication
8 | @EnableAutoConfiguration
9 | public class TestApplication {
10 | public static void main(String[] args) {
11 | SpringApplication.run(TestApplication.class, args);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/spring-commons-idempotency/src/test/java/com/github/damianwajser/configuration/FooIdempotencyKeyGenerator.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.configuration;
2 |
3 | import com.github.damianwajser.idempotency.exception.ArgumentNotFoundException;
4 | import com.github.damianwajser.idempotency.generators.IdempotencyKeyGenerator;
5 | import org.springframework.http.HttpHeaders;
6 | import org.springframework.http.HttpMethod;
7 |
8 | import javax.servlet.http.HttpServletRequest;
9 | import java.util.List;
10 | import java.util.stream.Collectors;
11 |
12 | public class FooIdempotencyKeyGenerator implements IdempotencyKeyGenerator {
13 |
14 | private static final String IDEMPOTENCY_DEFAULT_HEADER = "X-Idempotency-Key";
15 |
16 | @Override
17 | public String generateKey(HttpHeaders headers, HttpMethod method, String path, HttpServletRequest request) {
18 | String key = getHeaderValue(headers, IDEMPOTENCY_DEFAULT_HEADER);
19 | return path + "::" + key + "::" + method.toString();
20 | }
21 |
22 | protected String getHeaderValue(HttpHeaders headers, String headerKey) {
23 | List idempotencyHeader = headers.get(headerKey);
24 | String key;
25 | if (idempotencyHeader != null) {
26 | key = idempotencyHeader.stream().collect(Collectors.joining("-"));
27 | } else {
28 | throw new ArgumentNotFoundException(headerKey);
29 | }
30 | return key;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/spring-commons-idempotency/src/test/java/com/github/damianwajser/configuration/IdempotencyConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.configuration;
2 |
3 | import com.github.damianwajser.idempotency.configuration.IdempotencyEndpoints;
4 | import org.springframework.boot.test.context.TestConfiguration;
5 | import org.springframework.context.annotation.Bean;
6 | import org.springframework.http.HttpMethod;
7 |
8 | @TestConfiguration
9 | public class IdempotencyConfiguration {
10 |
11 | @Bean
12 | public IdempotencyEndpoints idempotencyEndpoints() {
13 | IdempotencyEndpoints idempotencyEndpoints = new IdempotencyEndpoints();
14 | idempotencyEndpoints.addIdempotencyEndpoint("/idempotency", new FooIdempotencyKeyGenerator(), HttpMethod.POST);
15 | idempotencyEndpoints.addIdempotencyEndpoint("/idempotency_delay");
16 | idempotencyEndpoints.addIdempotencyEndpoint("/idempotency/*");
17 | idempotencyEndpoints.addIdempotencyEndpoint("/idempotency/**/regex2/**");
18 | idempotencyEndpoints.addIdempotencyEndpoint("/idempotency_bad_request");
19 | idempotencyEndpoints.addIdempotencyEndpoint("/idempotency_error_format", new IdempotencyValidatorKeyGenerator());
20 | return idempotencyEndpoints;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/spring-commons-idempotency/src/test/java/com/github/damianwajser/configuration/IdempotencyValidatorKeyGenerator.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.configuration;
2 |
3 | import com.github.damianwajser.exceptions.RestException;
4 | import com.github.damianwajser.exceptions.impl.badrequest.BadRequestException;
5 | import com.github.damianwajser.idempotency.generators.IdempotencyKeyGenerator;
6 | import org.springframework.http.HttpHeaders;
7 | import org.springframework.http.HttpMethod;
8 |
9 | import javax.servlet.http.HttpServletRequest;
10 | import java.util.Optional;
11 |
12 | public class IdempotencyValidatorKeyGenerator implements IdempotencyKeyGenerator {
13 |
14 | private static final String IDEMPOTENCY_DEFAULT_HEADER = "X-Idempotency-Key";
15 |
16 | @Override
17 | public String generateKey(HttpHeaders headers, HttpMethod method, String path, HttpServletRequest request) throws RestException {
18 | throw new BadRequestException("code idempotency", "error", Optional.empty());
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/spring-commons-idempotency/src/test/java/com/github/damianwajser/configuration/RedisConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.configuration;
2 |
3 | import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
4 | import org.springframework.boot.test.context.TestConfiguration;
5 | import org.springframework.context.annotation.Bean;
6 | import org.springframework.data.redis.connection.RedisConnectionFactory;
7 | import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
8 | import org.springframework.data.redis.connection.jedis.JedisClientConfiguration;
9 | import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
10 | import org.springframework.data.redis.repository.configuration.EnableRedisRepositories;
11 |
12 | import java.time.Duration;
13 |
14 | @TestConfiguration
15 | @EnableRedisRepositories
16 | public class RedisConfiguration {
17 |
18 | @Bean
19 | public RedisConnectionFactory redisConnectionFactory(RedisProperties redisProperties) {
20 | RedisStandaloneConfiguration config = new RedisStandaloneConfiguration(redisProperties.getHost(),
21 | redisProperties.getPort());
22 | JedisClientConfiguration clientConfiguration = JedisClientConfiguration.builder().readTimeout(Duration.ofMillis(0)).
23 | connectTimeout(Duration.ofMillis(0)).build();
24 | return new JedisConnectionFactory(config, clientConfiguration);
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/spring-commons-idempotency/src/test/java/com/github/damianwajser/model/FooObject.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.model;
2 |
3 | import java.util.Objects;
4 |
5 | public class FooObject {
6 | private String value;
7 |
8 | public FooObject(String value) {
9 | this.value = value;
10 | }
11 |
12 | public FooObject() {
13 | }
14 |
15 | public String getValue() {
16 | return value;
17 | }
18 |
19 | public void setValue(String value) {
20 | this.value = value;
21 | }
22 |
23 | @Override
24 | public boolean equals(Object o) {
25 | if (this == o) return true;
26 | if (!(o instanceof FooObject)) return false;
27 | FooObject fooObject = (FooObject) o;
28 | return Objects.equals(getValue(), fooObject.getValue());
29 | }
30 |
31 | @Override
32 | public int hashCode() {
33 | return Objects.hash(getValue());
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/spring-commons-logger-logstash/pom.xml:
--------------------------------------------------------------------------------
1 |
4 | 4.0.0
5 | spring-commons-logger-logstash
6 | jar
7 | ${revision}
8 |
9 | com.github.damianwajser
10 | spring-commons-parent
11 | ${revision}
12 |
13 |
14 |
15 | com.github.damianwajser
16 | spring-commons-logger
17 | ${project.version}
18 |
19 |
20 |
21 | net.logstash.logback
22 | logstash-logback-encoder
23 | ${logstash.version}
24 |
25 |
26 | org.slf4j
27 | slf4j-log4j12
28 |
29 |
30 | log4j
31 | log4j
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/spring-commons-logger-logstash/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | logging.pattern.level=[%-5level] AppName: %X{appName} Request ID: %X{requestId} Client IP: %X{clientIp}
2 | spring.commons.logstash.enabled=true
3 | spring.commons.logstash.destination:localhost:5000
4 |
--------------------------------------------------------------------------------
/spring-commons-logger-logstash/src/test/java/com/github/damianwajser/TestApplication.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
5 | import org.springframework.boot.autoconfigure.SpringBootApplication;
6 |
7 | @SpringBootApplication
8 | @EnableAutoConfiguration
9 | public class TestApplication {
10 | public static void main(String[] args) {
11 | SpringApplication.run(TestApplication.class, args);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/spring-commons-logger-logstash/src/test/java/com/github/damianwajser/controller/TestController.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.controller;
2 |
3 | import org.springframework.web.bind.annotation.GetMapping;
4 | import org.springframework.web.bind.annotation.RestController;
5 |
6 | @RestController
7 | public class TestController {
8 |
9 | @GetMapping("/ping")
10 | public String echo() {
11 | return "pong";
12 | }
13 | }
14 |
15 |
--------------------------------------------------------------------------------
/spring-commons-logger-logstash/src/test/java/com/github/damianwajser/tests/PingTest.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.tests;
2 |
3 | import org.hamcrest.Matchers;
4 | import org.junit.Assert;
5 | import org.junit.Test;
6 | import org.junit.runner.RunWith;
7 | import org.springframework.boot.test.context.SpringBootTest;
8 | import org.springframework.boot.web.server.LocalServerPort;
9 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
10 | import org.springframework.web.client.RestTemplate;
11 |
12 | @RunWith(SpringJUnit4ClassRunner.class)
13 | @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
14 | public class PingTest {
15 |
16 | @LocalServerPort
17 | private int port;
18 |
19 | private RestTemplate restTemplate = new RestTemplate();
20 |
21 | @Test
22 | public void contextLoad() throws Exception {
23 | String result = this.restTemplate.getForEntity("http://localhost:" + port + "/ping", String.class).getBody();
24 | Assert.assertThat(result, Matchers.equalTo("pong"));
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/spring-commons-logger/.flattened-pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | com.github.damianwajser
7 | spring-commons-parent
8 | 1.28.4
9 |
10 | com.github.damianwajser
11 | spring-commons-logger
12 | 1.28.4
13 |
14 |
15 | Apache License, Version 2.0
16 | http://www.apache.org/licenses/LICENSE-2.0.txt
17 | repo
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/spring-commons-logger/pom.xml:
--------------------------------------------------------------------------------
1 |
4 | 4.0.0
5 | spring-commons-logger
6 | jar
7 | ${revision}
8 |
9 | com.github.damianwajser
10 | spring-commons-parent
11 | ${revision}
12 |
13 |
14 |
--------------------------------------------------------------------------------
/spring-commons-logger/src/main/java/com/github/damianwajser/configuration/CommonsConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.configuration;
2 |
3 | import org.springframework.context.annotation.Bean;
4 | import org.springframework.context.annotation.Configuration;
5 | import org.springframework.web.filter.CommonsRequestLoggingFilter;
6 |
7 | import javax.servlet.Filter;
8 |
9 | @Configuration
10 | public class CommonsConfiguration {
11 |
12 | @Bean
13 | public Filter logFilter(PropertiesLogger propertiesLogger) {
14 | CommonsRequestLoggingFilter filter = new CommonsRequestLoggingFilter();
15 | filter.setIncludeQueryString(true);
16 | filter.setIncludePayload(true);
17 | filter.setMaxPayloadLength(propertiesLogger.getMaxPayLoad());
18 |
19 | return filter;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/spring-commons-logger/src/main/java/com/github/damianwajser/configuration/PropertiesLogger.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.configuration;
2 |
3 | import org.springframework.beans.factory.annotation.Value;
4 | import org.springframework.boot.context.properties.ConfigurationProperties;
5 | import org.springframework.context.annotation.Configuration;
6 | import org.springframework.context.annotation.PropertySource;
7 |
8 | import java.util.HashMap;
9 | import java.util.Map;
10 |
11 | @Configuration
12 | @ConfigurationProperties
13 | @PropertySource("classpath:spring-commons-logger.properties")
14 | public class PropertiesLogger {
15 |
16 | public static final String APP_NAME = "APP_NAME";
17 | private static final Map propertiesToShow = new HashMap<>();
18 | @Value("${spring.commons.logger.trace.id}")
19 | private String traceId;
20 |
21 | @Value("${spring.commons.logger.app.name}")
22 | private String appName;
23 |
24 | @Value("${spring.commons.logger.payload.max}")
25 | private Integer maxPayLoad;
26 |
27 | public Integer getMaxPayLoad() {
28 | return maxPayLoad;
29 | }
30 |
31 | public String getTraceId() {
32 | return traceId;
33 | }
34 |
35 | public String getAppName() {
36 | return appName;
37 | }
38 |
39 | public Map getPropetiesToShow() {
40 | if (propertiesToShow.isEmpty()) {
41 | propertiesToShow.put(APP_NAME, this.getAppName());
42 | }
43 | return propertiesToShow;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/spring-commons-logger/src/main/java/com/github/damianwajser/filter/StatsFilter.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.filter;
2 |
3 | import org.owasp.encoder.Encode;
4 | import org.slf4j.Logger;
5 | import org.slf4j.LoggerFactory;
6 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
7 | import org.springframework.stereotype.Component;
8 |
9 | import javax.servlet.*;
10 | import javax.servlet.http.HttpServletRequest;
11 | import java.io.IOException;
12 |
13 | @Component
14 | @ConditionalOnProperty(name = "spring.commons.logger.duration.request.enabled", havingValue = "true")
15 | public class StatsFilter implements Filter {
16 |
17 | private static final Logger LOGGER = LoggerFactory.getLogger(StatsFilter.class);
18 |
19 | @Override
20 | public void init(FilterConfig filterConfig) throws ServletException {
21 | LOGGER.debug("init stats filter");
22 | }
23 |
24 | @Override
25 | public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain)
26 | throws IOException, ServletException {
27 | long time = System.currentTimeMillis();
28 | try {
29 | chain.doFilter(req, resp);
30 | } finally {
31 | time = System.currentTimeMillis() - time;
32 | HttpServletRequest request = ((HttpServletRequest) req);
33 | String uri = Encode.forJava(request.getRequestURI());
34 | LOGGER.info("{} {}: {} ms", request.getMethod(), uri, time);
35 | }
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/spring-commons-logger/src/main/java/com/github/damianwajser/generators/RequestIdGenerator.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.generators;
2 |
3 | import javax.servlet.http.HttpServletRequest;
4 |
5 | public interface RequestIdGenerator {
6 | String getRequestId(HttpServletRequest request);
7 | }
8 |
--------------------------------------------------------------------------------
/spring-commons-logger/src/main/java/com/github/damianwajser/generators/TraceIdGenerator.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.generators;
2 |
3 | import com.github.damianwajser.configuration.PropertiesLogger;
4 | import org.apache.commons.lang3.StringUtils;
5 | import org.slf4j.Logger;
6 | import org.slf4j.LoggerFactory;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.stereotype.Component;
9 |
10 | import javax.servlet.http.HttpServletRequest;
11 | import java.util.UUID;
12 |
13 | @Component
14 | public class TraceIdGenerator implements RequestIdGenerator {
15 |
16 | private static final Logger LOGGER = LoggerFactory.getLogger(TraceIdGenerator.class);
17 |
18 | @Autowired
19 | private PropertiesLogger properties;
20 |
21 | @Override
22 | public String getRequestId(HttpServletRequest request) {
23 | //El api gateway tiene que agregar el Correlation Id
24 | String traceValue = request.getHeader(properties.getTraceId());
25 | if (StringUtils.isEmpty(traceValue)) {
26 | LOGGER.warn("Request Id not present in request,one autogenerated, please configure your api gateway to generate header: {}", properties.getTraceId());
27 | traceValue = UUID.randomUUID().toString();
28 | }
29 | return traceValue;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/spring-commons-logger/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.commons.logger.duration.request.enabled=true
2 | logging.pattern.level=[%-5level] AppName: %X{appName} Request ID: %X{requestId} Client IP: %X{clientIp}
3 |
--------------------------------------------------------------------------------
/spring-commons-logger/src/main/resources/spring-commons-logger.properties:
--------------------------------------------------------------------------------
1 | spring.commons.app.name=change spring.commons.app.name (commons-logger)
2 | spring.commons.logger.app.name=${spring.commons.app.name}
3 | spring.commons.logger.trace.id=X-TRACE-ID
4 | spring.commons.logger.duration.request.enabled=true
5 | spring.commons.logger.payload.max=16000
6 |
--------------------------------------------------------------------------------
/spring-commons-logger/src/test/java/com/github/damianwajser/TestApplication.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
5 | import org.springframework.boot.autoconfigure.SpringBootApplication;
6 |
7 | @SpringBootApplication
8 | @EnableAutoConfiguration
9 | public class TestApplication {
10 | public static void main(String[] args) {
11 | SpringApplication.run(TestApplication.class, args);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/spring-commons-logger/src/test/java/com/github/damianwajser/controller/TestController.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.controller;
2 |
3 | import org.slf4j.Logger;
4 | import org.slf4j.LoggerFactory;
5 | import org.springframework.web.bind.annotation.GetMapping;
6 | import org.springframework.web.bind.annotation.RestController;
7 |
8 | @RestController
9 | public class TestController {
10 |
11 | private static final Logger LOGGER = LoggerFactory.getLogger(TestController.class);
12 |
13 | @GetMapping("/ping")
14 | public String echo() {
15 | LOGGER.info("PONG");
16 | return "pong";
17 | }
18 | }
19 |
20 |
--------------------------------------------------------------------------------
/spring-commons-payment-utilities/.flattened-pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | com.github.damianwajser
7 | spring-commons-parent
8 | 1.28.5
9 |
10 | com.github.damianwajser
11 | spring-commons-payment-utilities
12 | 1.28.5
13 |
14 |
15 | Apache License, Version 2.0
16 | http://www.apache.org/licenses/LICENSE-2.0.txt
17 | repo
18 |
19 |
20 |
21 |
22 | com.google.zxing
23 | javase
24 | 3.4.1
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/spring-commons-payment-utilities/pom.xml:
--------------------------------------------------------------------------------
1 |
4 | 4.0.0
5 | spring-commons-payment-utilities
6 | jar
7 | ${revision}
8 |
9 | com.github.damianwajser
10 | spring-commons-parent
11 | ${revision}
12 |
13 |
14 |
15 | com.google.zxing
16 | javase
17 | 3.4.1
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/spring-commons-payment-utilities/src/main/java/com/github/damianwajser/emv/exceptions/CrcValidationException.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.emv.exceptions;
2 |
3 | public class CrcValidationException extends EmvFormatException {
4 |
5 | public CrcValidationException(String message) {
6 | super(message);
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/spring-commons-payment-utilities/src/main/java/com/github/damianwajser/emv/exceptions/EmvFormatException.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.emv.exceptions;
2 |
3 | public class EmvFormatException extends Exception {
4 |
5 | public EmvFormatException(String message) {
6 | super(message);
7 | }
8 |
9 | public EmvFormatException(String message, Exception e) {
10 | super(message, e);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/spring-commons-payment-utilities/src/main/java/com/github/damianwajser/printers/QrWritter.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.printers;
2 |
3 | import com.github.damianwajser.printers.formatters.QrFormat;
4 | import com.github.damianwajser.printers.formatters.impl.FormattersFactory;
5 | import com.google.zxing.NotFoundException;
6 | import com.google.zxing.WriterException;
7 |
8 | import java.io.IOException;
9 |
10 | public class QrWritter {
11 |
12 | private static final Integer WIDTH_DEFAULT = 512;
13 | private static final Integer HEIGHT_DEFAULT = 512;
14 |
15 | public byte[] write(String text, int width, int height, QrFormat format) throws WriterException, IOException {
16 | width = (width > 0) ? width : WIDTH_DEFAULT;
17 | height = (height > 0) ? height : HEIGHT_DEFAULT;
18 | return FormattersFactory.getFormatter(format).write(text, width, height);
19 | }
20 |
21 | public byte[] write(String code) throws WriterException, IOException {
22 | return write(code, HEIGHT_DEFAULT, HEIGHT_DEFAULT);
23 | }
24 |
25 | public byte[] write(String code, int width, int height) throws WriterException, IOException {
26 | return write(code, width, height, QrFormat.PNG);
27 | }
28 |
29 | // Function to read the QR file
30 | public String readQR(byte[] qr, QrFormat format) throws NotFoundException, IOException {
31 | return FormattersFactory.getFormatter(format).read(qr);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/spring-commons-payment-utilities/src/main/java/com/github/damianwajser/printers/formatters/Formatter.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.printers.formatters;
2 |
3 | import com.google.zxing.NotFoundException;
4 | import com.google.zxing.WriterException;
5 |
6 | import java.io.IOException;
7 |
8 | public interface Formatter {
9 | byte[] write(String text, int width, int height) throws WriterException, IOException;
10 |
11 | String read(byte[] qr) throws NotFoundException, IOException;
12 | }
13 |
--------------------------------------------------------------------------------
/spring-commons-payment-utilities/src/main/java/com/github/damianwajser/printers/formatters/QrFormat.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.printers.formatters;
2 |
3 | public enum QrFormat {
4 | PNG,
5 | BASE64
6 | }
7 |
--------------------------------------------------------------------------------
/spring-commons-payment-utilities/src/main/java/com/github/damianwajser/printers/formatters/impl/Base64Formatter.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.printers.formatters.impl;
2 |
3 | import com.google.zxing.NotFoundException;
4 | import com.google.zxing.WriterException;
5 | import org.springframework.util.Base64Utils;
6 |
7 | import java.io.IOException;
8 |
9 | public class Base64Formatter extends DefaultFormatter {
10 | @Override
11 | public byte[] write(String text, int width, int height) throws WriterException, IOException {
12 | return Base64Utils.encode(super.write(text, width, height));
13 | }
14 |
15 | @Override
16 | public String read(byte[] qr) throws NotFoundException, IOException {
17 | byte[] decodedBytes = Base64Utils.decode(qr);
18 | return super.read(decodedBytes);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/spring-commons-payment-utilities/src/main/java/com/github/damianwajser/printers/formatters/impl/FormattersFactory.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.printers.formatters.impl;
2 |
3 | import com.github.damianwajser.printers.formatters.Formatter;
4 | import com.github.damianwajser.printers.formatters.QrFormat;
5 |
6 | public class FormattersFactory {
7 |
8 | private FormattersFactory() {
9 | }
10 |
11 | public static Formatter getFormatter(QrFormat format) {
12 | return format.equals(QrFormat.BASE64) ? new Base64Formatter() : new DefaultFormatter();
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/spring-commons-rest-templates/pom.xml:
--------------------------------------------------------------------------------
1 |
4 | 4.0.0
5 | spring-commons-rest-templates
6 | jar
7 | ${revision}
8 | spring-commons-rest-templates
9 | DESC
10 |
11 |
12 | com.github.damianwajser
13 | spring-commons-parent
14 | ${revision}
15 |
16 |
17 |
18 | org.apache.httpcomponents
19 | httpclient
20 | 4.5.13
21 |
22 |
23 | com.squareup.okhttp3
24 | okhttp
25 | 4.9.1
26 |
27 |
28 |
29 | com.github.damianwajser
30 | spring-commons-exception
31 | ${project.version}
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/spring-commons-rest-templates/src/main/java/com/github/damianwajser/rest/configuration/CustomHttpRequestFactory.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.rest.configuration;
2 |
3 | import org.springframework.http.client.ClientHttpRequestFactory;
4 |
5 | public interface CustomHttpRequestFactory {
6 |
7 | ClientHttpRequestFactory getClientHttpRequestFactory(boolean configureSSl);
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/spring-commons-rest-templates/src/main/java/com/github/damianwajser/rest/configuration/OkHttp/OkHttpPoolingConnfiguration.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.rest.configuration.okhttp;
2 |
3 | import com.github.damianwajser.rest.configuration.properties.PoolConfigurationProperties;
4 | import okhttp3.ConnectionPool;
5 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
6 | import org.springframework.context.annotation.Bean;
7 | import org.springframework.context.annotation.Configuration;
8 |
9 | import java.util.concurrent.TimeUnit;
10 |
11 | @Configuration
12 | @ConditionalOnProperty(prefix = "spring.commons.rest.template", name = "implementation", havingValue = "OK_HTTP")
13 | public class OkHttpPoolingConnfiguration {
14 |
15 | @Bean
16 | public ConnectionPool poolingHttpClientConnectionManager(PoolConfigurationProperties poolConfigurationProperties) {
17 | return new ConnectionPool(poolConfigurationProperties.getMaxTotal(), 5, TimeUnit.MINUTES);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/spring-commons-rest-templates/src/main/java/com/github/damianwajser/rest/configuration/properties/PoolConfigurationProperties.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.rest.configuration.properties;
2 |
3 | import org.springframework.boot.context.properties.ConfigurationProperties;
4 | import org.springframework.context.annotation.Configuration;
5 | import org.springframework.context.annotation.PropertySource;
6 |
7 | @Configuration
8 | @ConfigurationProperties(prefix = "spring.commons.rest.template.http.connection.pool")
9 | @PropertySource("classpath:spring-commons-http-pools.properties")
10 | public class PoolConfigurationProperties {
11 |
12 | private int maxDefaultPerRoute;
13 | private int maxTotal;
14 |
15 |
16 | public int getMaxTotal() {
17 | return maxTotal;
18 | }
19 |
20 | public void setMaxTotal(int maxTotal) {
21 | this.maxTotal = maxTotal;
22 | }
23 |
24 | public int getMaxDefaultPerRoute() {
25 | return maxDefaultPerRoute;
26 | }
27 |
28 | public void setMaxDefaultPerRoute(int maxDefaultPerRoute) {
29 | this.maxDefaultPerRoute = maxDefaultPerRoute;
30 | }
31 |
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/spring-commons-rest-templates/src/main/java/com/github/damianwajser/rest/configuration/properties/TimeoutConfigurationProperties.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.rest.configuration.properties;
2 |
3 | import org.springframework.boot.context.properties.ConfigurationProperties;
4 | import org.springframework.context.annotation.Configuration;
5 | import org.springframework.context.annotation.PropertySource;
6 |
7 | @Configuration
8 | @ConfigurationProperties(prefix = "spring.commons.rest.template.timeout")
9 | @PropertySource("classpath:spring-commons-timeouts.properties")
10 | public class TimeoutConfigurationProperties {
11 |
12 | private int connection;
13 | private int write;
14 | private int read;
15 |
16 | public int getConnection() {
17 | return connection;
18 | }
19 |
20 | public void setConnection(int connection) {
21 | this.connection = connection;
22 | }
23 |
24 | public int getWrite() {
25 | return write;
26 | }
27 |
28 | public void setWrite(int write) {
29 | this.write = write;
30 | }
31 |
32 | public int getRead() {
33 | return read;
34 | }
35 |
36 | public void setRead(int read) {
37 | this.read = read;
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/spring-commons-rest-templates/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.jackson.property-naming-strategy=com.fasterxml.jackson.databind.PropertyNamingStrategy.SnakeCaseStrategy
2 | spring.commons.rest.template.ssl.enable=false
3 | spring.commons.rest.template.converter.skipnull=false
4 |
--------------------------------------------------------------------------------
/spring-commons-rest-templates/src/main/resources/spring-commons-client-http.properties:
--------------------------------------------------------------------------------
1 | spring.commons.rest.template.implementation=HTTP_CLIENT
2 | ## HTTP_CLIENT, OK_HTTP
3 |
--------------------------------------------------------------------------------
/spring-commons-rest-templates/src/main/resources/spring-commons-http-pools.properties:
--------------------------------------------------------------------------------
1 | spring.commons.rest.template.http.connection.pool.maxTotal=100
2 | spring.commons.rest.template.http.connection.pool.MaxDefaultPerRoute=30
3 |
--------------------------------------------------------------------------------
/spring-commons-rest-templates/src/main/resources/spring-commons-ssl.properties:
--------------------------------------------------------------------------------
1 | spring.commons.rest.template.ssl.protocol=TLSv1.2
2 | spring.commons.rest.template.ssl.trustStorePassword=
3 | spring.commons.rest.template.ssl.trustStore=
4 |
--------------------------------------------------------------------------------
/spring-commons-rest-templates/src/main/resources/spring-commons-timeouts.properties:
--------------------------------------------------------------------------------
1 | spring.commons.rest.template.timeout.connection=-1
2 | spring.commons.rest.template.timeout.write=-1
3 | spring.commons.rest.template.timeout.read=-1
--------------------------------------------------------------------------------
/spring-commons-rest-templates/src/test/java/com/github/damianwajser/TestApplication.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
5 | import org.springframework.boot.autoconfigure.SpringBootApplication;
6 |
7 | @SpringBootApplication
8 | @EnableAutoConfiguration
9 | public class TestApplication {
10 | public static void main(String[] args) {
11 | SpringApplication.run(TestApplication.class, args);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/spring-commons-rest-templates/src/test/java/com/github/damianwajser/controllers/TimeoutTestController.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.controllers;
2 |
3 | import com.github.damianwajser.model.snake.SingletonObject;
4 | import com.github.damianwajser.model.timeout.TimeOutObject;
5 | import org.springframework.web.bind.annotation.GetMapping;
6 | import org.springframework.web.bind.annotation.PostMapping;
7 | import org.springframework.web.bind.annotation.RequestBody;
8 | import org.springframework.web.bind.annotation.RestController;
9 |
10 | import java.util.Date;
11 |
12 | @RestController
13 | public class TimeoutTestController {
14 |
15 | @PostMapping("/timeout")
16 | public TimeOutObject timeout(@RequestBody TimeOutObject request) throws InterruptedException {
17 | System.out.println("start delay: " + (new Date().getTime() - request.getStart()));
18 | Thread.sleep(400);
19 | System.out.println("stop delay: " + (new Date().getTime() - request.getStart()));
20 | SingletonObject.getInstance().increment();
21 | System.out.println("increment: " + (new Date().getTime() - request.getStart()));
22 | request.setResult(SingletonObject.getInstance().getValue());
23 | request.setEnd(new Date().getTime());
24 | return request;
25 | }
26 |
27 | @GetMapping("/without_timeout")
28 | private Object without_timeout() throws InterruptedException {
29 | System.out.println("call without timeout");
30 | return SingletonObject.getInstance().getValue();
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/spring-commons-rest-templates/src/test/java/com/github/damianwajser/model/snake/RequestToController.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.model.snake;
2 |
3 | public class RequestToController {
4 |
5 | private String someValue;
6 |
7 | public String getSomeValue() {
8 | return someValue;
9 | }
10 |
11 | public void setSomeValue(String someValue) {
12 | this.someValue = someValue;
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/spring-commons-rest-templates/src/test/java/com/github/damianwajser/model/snake/SingletonObject.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.model.snake;
2 |
3 | public class SingletonObject {
4 |
5 | private static SingletonObject instance;
6 | private int value;
7 |
8 | private SingletonObject() {
9 | }
10 |
11 | public static SingletonObject getInstance() {
12 | if (instance == null) {
13 | instance = new SingletonObject();
14 | }
15 | return instance;
16 | }
17 |
18 | public int getValue() {
19 | return value;
20 | }
21 |
22 | public void increment() {
23 | value++;
24 | }
25 |
26 | public void restart() {
27 | value = 0;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/spring-commons-rest-templates/src/test/java/com/github/damianwajser/model/timeout/TimeOutObject.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.model.timeout;
2 |
3 | public class TimeOutObject {
4 |
5 | private long start;
6 | private long end;
7 | private Integer result;
8 |
9 | public long getStart() {
10 | return start;
11 | }
12 |
13 | public void setStart(long start) {
14 | this.start = start;
15 | }
16 |
17 | public long getEnd() {
18 | return end;
19 | }
20 |
21 | public void setEnd(long end) {
22 | this.end = end;
23 | }
24 |
25 | public Integer getResult() {
26 | return result;
27 | }
28 |
29 | public void setResult(Integer result) {
30 | this.result = result;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/spring-commons-rest-templates/src/test/java/com/github/damianwajser/tests/AbstractHttpTest.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.tests;
2 |
3 | import com.github.dockerjava.api.command.CreateContainerCmd;
4 | import com.github.dockerjava.api.model.ExposedPort;
5 | import com.github.dockerjava.api.model.PortBinding;
6 | import com.github.dockerjava.api.model.Ports;
7 | import org.junit.ClassRule;
8 | import org.testcontainers.containers.GenericContainer;
9 | import org.testcontainers.utility.DockerImageName;
10 |
11 | import java.util.function.Consumer;
12 |
13 | public class AbstractHttpTest {
14 | static Consumer cmd = e -> e.withPortBindings(new PortBinding(Ports.Binding.bindPort(80), new ExposedPort(80)));
15 | private static int ECHO_PORT = 80;
16 | private static String ECHO_HOST = "http://localhost";
17 |
18 | @ClassRule
19 | public static GenericContainer> redisContainer = new GenericContainer(DockerImageName.parse("kennethreitz/httpbin:latest"))
20 | .withExposedPorts(ECHO_PORT)
21 | .withCreateContainerCmdModifier(cmd);
22 |
23 | public static String getEchoUrl(){
24 | return ECHO_HOST + ":" + ECHO_PORT;
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/.flattened-pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | com.github.damianwajser
7 | spring-commons-parent
8 | 1.28.5
9 |
10 | com.github.damianwajser
11 | spring-commons-rest-validation
12 | 1.28.5
13 |
14 |
15 | Apache License, Version 2.0
16 | http://www.apache.org/licenses/LICENSE-2.0.txt
17 | repo
18 |
19 |
20 |
21 |
22 | commons-codec
23 | commons-codec
24 | 1.2
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/pom.xml:
--------------------------------------------------------------------------------
1 |
4 | 4.0.0
5 | spring-commons-rest-validation
6 | jar
7 | ${revision}
8 |
9 | com.github.damianwajser
10 | spring-commons-parent
11 | ${revision}
12 |
13 |
14 |
15 | commons-codec
16 | commons-codec
17 | 1.2
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/main/java/com/github/damianwajser/validator/annotation/cards/CardExpiration.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.validator.annotation.cards;
2 |
3 | import com.github.damianwajser.validator.constraint.cards.ExpirationCardConstraint;
4 | import org.springframework.http.HttpMethod;
5 |
6 | import javax.validation.Constraint;
7 | import javax.validation.Payload;
8 | import java.lang.annotation.Documented;
9 | import java.lang.annotation.Repeatable;
10 | import java.lang.annotation.Retention;
11 | import java.lang.annotation.Target;
12 |
13 | import static java.lang.annotation.ElementType.TYPE;
14 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
15 |
16 | @Documented
17 | @Constraint(validatedBy = {ExpirationCardConstraint.class})
18 | @Target({TYPE})
19 | @Retention(RUNTIME)
20 | @Repeatable(CardExpiration.List.class)
21 | public @interface CardExpiration {
22 |
23 | HttpMethod[] excludes() default {};
24 |
25 | HttpMethod[] onlyIn() default {};
26 |
27 | boolean isNulleable() default false;
28 |
29 | String message();
30 |
31 | Class>[] groups() default {};
32 |
33 | Class extends Payload>[] payload() default {};
34 |
35 | String businessCode();
36 |
37 | YearFormat yearFormat() default YearFormat.TWO_DIGITS;
38 |
39 | enum YearFormat {
40 | TWO_DIGITS, FOUR_DIGIT;
41 | }
42 |
43 | @Target({TYPE})
44 | @Retention(RUNTIME)
45 | @Documented
46 | @interface List {
47 |
48 | CardExpiration[] value();
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/main/java/com/github/damianwajser/validator/annotation/enums/Country_ISO3166.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.validator.annotation.enums;
2 |
3 | import com.github.damianwajser.validator.constraint.enums.CountryIso3166Constraint;
4 | import org.springframework.http.HttpMethod;
5 |
6 | import javax.validation.Constraint;
7 | import javax.validation.Payload;
8 | import java.lang.annotation.Documented;
9 | import java.lang.annotation.Repeatable;
10 | import java.lang.annotation.Retention;
11 | import java.lang.annotation.Target;
12 |
13 | import static java.lang.annotation.ElementType.*;
14 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
15 |
16 | @Documented
17 | @Constraint(validatedBy = {CountryIso3166Constraint.class})
18 | @Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
19 | @Retention(RUNTIME)
20 | @Repeatable(Country_ISO3166.List.class)
21 | public @interface Country_ISO3166 {
22 |
23 | HttpMethod[] excludes() default {};
24 |
25 | HttpMethod[] onlyIn() default {};
26 |
27 | String message();
28 |
29 | Class>[] groups() default {};
30 |
31 | Class extends Payload>[] payload() default {};
32 |
33 | String businessCode();
34 |
35 | boolean isNulleable() default false;
36 |
37 | @Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
38 | @Retention(RUNTIME)
39 | @Documented
40 | @interface List {
41 | Country_ISO3166[] value();
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/main/java/com/github/damianwajser/validator/annotation/enums/MatchEnum.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.validator.annotation.enums;
2 |
3 | import com.github.damianwajser.validator.constraint.enums.MatchEnumConstraint;
4 | import org.springframework.http.HttpMethod;
5 |
6 | import javax.validation.Constraint;
7 | import javax.validation.Payload;
8 | import java.lang.annotation.Documented;
9 | import java.lang.annotation.Repeatable;
10 | import java.lang.annotation.Retention;
11 | import java.lang.annotation.Target;
12 |
13 | import static java.lang.annotation.ElementType.*;
14 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
15 |
16 | @Documented
17 | @Constraint(validatedBy = {MatchEnumConstraint.class})
18 | @Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
19 | @Retention(RUNTIME)
20 | @Repeatable(MatchEnum.List.class)
21 | public @interface MatchEnum {
22 |
23 | HttpMethod[] excludes() default {};
24 |
25 | HttpMethod[] onlyIn() default {};
26 |
27 | String message();
28 |
29 | Class>[] groups() default {};
30 |
31 | Class extends Payload>[] payload() default {};
32 |
33 | String businessCode();
34 |
35 | boolean isNulleable() default false;
36 |
37 | Class extends Enum>> enumClass();
38 |
39 | @Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
40 | @Retention(RUNTIME)
41 | @Documented
42 | @interface List {
43 | MatchEnum[] value();
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/main/java/com/github/damianwajser/validator/annotation/global/Email.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.validator.annotation.global;
2 |
3 | import com.github.damianwajser.validator.constraint.global.EmailConstraint;
4 | import org.springframework.http.HttpMethod;
5 |
6 | import javax.validation.Constraint;
7 | import javax.validation.Payload;
8 | import java.lang.annotation.Documented;
9 | import java.lang.annotation.Repeatable;
10 | import java.lang.annotation.Retention;
11 | import java.lang.annotation.Target;
12 |
13 | import static java.lang.annotation.ElementType.*;
14 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
15 |
16 | @Documented
17 | @Constraint(validatedBy = {EmailConstraint.class})
18 | @Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
19 | @Retention(RUNTIME)
20 | @Repeatable(Email.List.class)
21 | public @interface Email {
22 |
23 | HttpMethod[] excludes() default {};
24 |
25 | HttpMethod[] onlyIn() default {};
26 |
27 | String message() default "{javax.validation.constraints.Email.message}";
28 |
29 | Class>[] groups() default {};
30 |
31 | Class extends Payload>[] payload() default {};
32 |
33 | String businessCode();
34 |
35 | boolean isNulleable() default false;
36 |
37 | @Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
38 | @Retention(RUNTIME)
39 | @Documented
40 | @interface List {
41 | Email[] value();
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/main/java/com/github/damianwajser/validator/annotation/global/NotEmpty.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.validator.annotation.global;
2 |
3 | import com.github.damianwajser.validator.constraint.global.NotEmptyConstraint;
4 | import org.springframework.http.HttpMethod;
5 |
6 | import javax.validation.Constraint;
7 | import javax.validation.Payload;
8 | import java.lang.annotation.Documented;
9 | import java.lang.annotation.Repeatable;
10 | import java.lang.annotation.Retention;
11 | import java.lang.annotation.Target;
12 |
13 | import static java.lang.annotation.ElementType.*;
14 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
15 |
16 | @Documented
17 | @Constraint(validatedBy = {NotEmptyConstraint.class})
18 | @Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
19 | @Retention(RUNTIME)
20 | @Repeatable(NotEmpty.List.class)
21 | public @interface NotEmpty {
22 |
23 | HttpMethod[] excludes() default {};
24 |
25 | HttpMethod[] onlyIn() default {};
26 |
27 | String message() default "{javax.validation.constraints.NotEmpty.message}";
28 |
29 | Class>[] groups() default {};
30 |
31 | Class extends Payload>[] payload() default {};
32 |
33 | String businessCode();
34 |
35 | boolean isNulleable() default false;
36 |
37 | @Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
38 | @Retention(RUNTIME)
39 | @Documented
40 | @interface List {
41 | NotEmpty[] value();
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/main/java/com/github/damianwajser/validator/annotation/global/NotNull.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.validator.annotation.global;
2 |
3 | import com.github.damianwajser.validator.constraint.global.NotNullConstraint;
4 | import org.springframework.http.HttpMethod;
5 |
6 | import javax.validation.Constraint;
7 | import javax.validation.Payload;
8 | import java.lang.annotation.Documented;
9 | import java.lang.annotation.Repeatable;
10 | import java.lang.annotation.Retention;
11 | import java.lang.annotation.Target;
12 |
13 | import static java.lang.annotation.ElementType.*;
14 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
15 |
16 | @Documented
17 | @Constraint(validatedBy = {NotNullConstraint.class})
18 | @Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
19 | @Retention(RUNTIME)
20 | @Repeatable(NotNull.List.class)
21 | public @interface NotNull {
22 |
23 | HttpMethod[] excludes() default {};
24 |
25 | String message() default "{javax.validation.constraints.NotNull.message}";
26 |
27 | HttpMethod[] onlyIn() default {};
28 |
29 | Class>[] groups() default {};
30 |
31 | Class extends Payload>[] payload() default {};
32 |
33 | String businessCode();
34 |
35 | @Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
36 | @Retention(RUNTIME)
37 | @Documented
38 | @interface List {
39 | NotNull[] value();
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/main/java/com/github/damianwajser/validator/annotation/global/OneNotNull.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.validator.annotation.global;
2 |
3 | import com.github.damianwajser.validator.constraint.global.OneNotNullConstraint;
4 | import org.springframework.http.HttpMethod;
5 |
6 | import javax.validation.Constraint;
7 | import javax.validation.Payload;
8 | import java.lang.annotation.*;
9 |
10 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
11 |
12 | @Documented
13 | @Constraint(validatedBy = {OneNotNullConstraint.class})
14 | @Target({ElementType.TYPE, ElementType.ANNOTATION_TYPE})
15 | @Retention(RUNTIME)
16 | @Repeatable(OneNotNull.List.class)
17 | public @interface OneNotNull {
18 |
19 | HttpMethod[] excludes() default {};
20 |
21 | HttpMethod[] onlyIn() default {};
22 |
23 | String message() default "{javax.validation.constraints.AssertTrue.message}";
24 |
25 | Class>[] groups() default {};
26 |
27 | Class extends Payload>[] payload() default {};
28 |
29 | String businessCode();
30 |
31 | boolean isNulleable() default false;
32 |
33 | /**
34 | * Fields to validate against null.
35 | */
36 | String[] fields() default {};
37 |
38 | @Target({ElementType.TYPE, ElementType.ANNOTATION_TYPE})
39 | @Retention(RUNTIME)
40 | @Documented
41 | @interface List {
42 | OneNotNull[] value();
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/main/java/com/github/damianwajser/validator/annotation/global/Past.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.validator.annotation.global;
2 |
3 | import com.github.damianwajser.validator.constraint.global.PastConstraint;
4 | import org.springframework.http.HttpMethod;
5 |
6 | import javax.validation.Constraint;
7 | import javax.validation.Payload;
8 | import java.lang.annotation.Documented;
9 | import java.lang.annotation.Repeatable;
10 | import java.lang.annotation.Retention;
11 | import java.lang.annotation.Target;
12 |
13 | import static java.lang.annotation.ElementType.*;
14 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
15 |
16 | @Documented
17 | @Constraint(validatedBy = {PastConstraint.class})
18 | @Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
19 | @Retention(RUNTIME)
20 | @Repeatable(Past.List.class)
21 | public @interface Past {
22 |
23 | HttpMethod[] excludes() default {};
24 |
25 | HttpMethod[] onlyIn() default {};
26 |
27 | String message() default "{javax.validation.constraints.AssertTrue.message}";
28 |
29 | Class>[] groups() default {};
30 |
31 | Class extends Payload>[] payload() default {};
32 |
33 | String businessCode();
34 |
35 | boolean isNulleable() default false;
36 |
37 | @Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
38 | @Retention(RUNTIME)
39 | @Documented
40 | @interface List {
41 | Past[] value();
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/main/java/com/github/damianwajser/validator/annotation/number/Max.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.validator.annotation.number;
2 |
3 | import com.github.damianwajser.validator.constraint.number.MaxConstraint;
4 | import org.springframework.http.HttpMethod;
5 |
6 | import javax.validation.Constraint;
7 | import javax.validation.Payload;
8 | import java.lang.annotation.Documented;
9 | import java.lang.annotation.Repeatable;
10 | import java.lang.annotation.Retention;
11 | import java.lang.annotation.Target;
12 |
13 | import static java.lang.annotation.ElementType.*;
14 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
15 |
16 | @Documented
17 | @Constraint(validatedBy = {MaxConstraint.class})
18 | @Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
19 | @Retention(RUNTIME)
20 | @Repeatable(Max.List.class)
21 | public @interface Max {
22 |
23 | HttpMethod[] excludes() default {};
24 |
25 | HttpMethod[] onlyIn() default {};
26 |
27 | String message() default "{javax.validation.constraints.Max.message}";
28 |
29 | Class>[] groups() default {};
30 |
31 | long value();
32 |
33 | Class extends Payload>[] payload() default {};
34 |
35 | String businessCode();
36 |
37 | boolean isNulleable() default false;
38 |
39 | @Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
40 | @Retention(RUNTIME)
41 | @Documented
42 | @interface List {
43 | Max[] value();
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/main/java/com/github/damianwajser/validator/annotation/number/Min.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.validator.annotation.number;
2 |
3 | import com.github.damianwajser.validator.constraint.number.MinConstraint;
4 | import org.springframework.http.HttpMethod;
5 |
6 | import javax.validation.Constraint;
7 | import javax.validation.Payload;
8 | import java.lang.annotation.Documented;
9 | import java.lang.annotation.Repeatable;
10 | import java.lang.annotation.Retention;
11 | import java.lang.annotation.Target;
12 |
13 | import static java.lang.annotation.ElementType.*;
14 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
15 |
16 | @Documented
17 | @Constraint(validatedBy = {MinConstraint.class})
18 | @Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
19 | @Retention(RUNTIME)
20 | @Repeatable(Min.List.class)
21 | public @interface Min {
22 |
23 | HttpMethod[] excludes() default {};
24 |
25 | String message() default "{javax.validation.constraints.Min.message}";
26 |
27 | HttpMethod[] onlyIn() default {};
28 |
29 | Class>[] groups() default {};
30 |
31 | long value();
32 |
33 | Class extends Payload>[] payload() default {};
34 |
35 | String businessCode();
36 |
37 | boolean isNulleable() default false;
38 |
39 | @Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
40 | @Retention(RUNTIME)
41 | @Documented
42 | @interface List {
43 | Min[] value();
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/main/java/com/github/damianwajser/validator/annotation/strings/Base64.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.validator.annotation.strings;
2 |
3 | import com.github.damianwajser.validator.constraint.strings.Base64Constraint;
4 | import org.springframework.http.HttpMethod;
5 |
6 | import javax.validation.Constraint;
7 | import javax.validation.Payload;
8 | import java.lang.annotation.Documented;
9 | import java.lang.annotation.Repeatable;
10 | import java.lang.annotation.Retention;
11 | import java.lang.annotation.Target;
12 |
13 | import static java.lang.annotation.ElementType.*;
14 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
15 |
16 | @Documented
17 | @Constraint(validatedBy = {Base64Constraint.class})
18 | @Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
19 | @Retention(RUNTIME)
20 | @Repeatable(Base64.List.class)
21 | public @interface Base64 {
22 |
23 | HttpMethod[] excludes() default {};
24 |
25 | HttpMethod[] onlyIn() default {};
26 |
27 | String message();
28 |
29 | Class>[] groups() default {};
30 |
31 | Class extends Payload>[] payload() default {};
32 |
33 | String businessCode();
34 |
35 | boolean isNulleable() default false;
36 |
37 | @Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
38 | @Retention(RUNTIME)
39 | @Documented
40 | @interface List {
41 | Base64[] value();
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/main/java/com/github/damianwajser/validator/annotation/strings/Password.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.validator.annotation.strings;
2 |
3 | import com.github.damianwajser.validator.constraint.strings.PasswordConstraint;
4 | import org.springframework.http.HttpMethod;
5 |
6 | import javax.validation.Constraint;
7 | import javax.validation.Payload;
8 | import java.lang.annotation.Documented;
9 | import java.lang.annotation.Repeatable;
10 | import java.lang.annotation.Retention;
11 | import java.lang.annotation.Target;
12 |
13 | import static java.lang.annotation.ElementType.*;
14 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
15 |
16 | @Documented
17 | @Constraint(validatedBy = {PasswordConstraint.class})
18 | @Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
19 | @Retention(RUNTIME)
20 | @Repeatable(Password.List.class)
21 | public @interface Password {
22 |
23 | HttpMethod[] excludes() default {};
24 |
25 | HttpMethod[] onlyIn() default {};
26 |
27 | String message();
28 |
29 | Class>[] groups() default {};
30 |
31 | Class extends Payload>[] payload() default {};
32 |
33 | String businessCode();
34 |
35 | boolean isNulleable() default false;
36 |
37 | @Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
38 | @Retention(RUNTIME)
39 | @Documented
40 | @interface List {
41 | Password[] value();
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/main/java/com/github/damianwajser/validator/annotation/strings/UUID.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.validator.annotation.strings;
2 |
3 | import com.github.damianwajser.validator.constraint.strings.UUIDConstraint;
4 | import org.springframework.http.HttpMethod;
5 |
6 | import javax.validation.Constraint;
7 | import javax.validation.Payload;
8 | import java.lang.annotation.Documented;
9 | import java.lang.annotation.Repeatable;
10 | import java.lang.annotation.Retention;
11 | import java.lang.annotation.Target;
12 |
13 | import static java.lang.annotation.ElementType.*;
14 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
15 |
16 | @Documented
17 | @Constraint(validatedBy = {UUIDConstraint.class})
18 | @Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
19 | @Retention(RUNTIME)
20 | @Repeatable(UUID.List.class)
21 | public @interface UUID {
22 |
23 | HttpMethod[] excludes() default {};
24 |
25 | HttpMethod[] onlyIn() default {};
26 |
27 | String message() default "{javax.validation.constraints.Email.message}";
28 |
29 | Class>[] groups() default {};
30 |
31 | Class extends Payload>[] payload() default {};
32 |
33 | String businessCode();
34 |
35 | boolean isNulleable() default false;
36 |
37 | @Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
38 | @Retention(RUNTIME)
39 | @Documented
40 | @interface List {
41 | UUID[] value();
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/main/java/com/github/damianwajser/validator/constraint/cards/CardTokenConstraint.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.validator.constraint.cards;
2 |
3 | import com.github.damianwajser.validator.annotation.cards.CardToken;
4 | import com.github.damianwajser.validator.constraint.AbstractConstraint;
5 | import com.github.damianwajser.validator.constraint.cards.token.validators.TokenValidatorsFactory;
6 |
7 | import javax.validation.ConstraintValidator;
8 | import javax.validation.ConstraintValidatorContext;
9 |
10 | public class CardTokenConstraint extends AbstractConstraint implements ConstraintValidator {
11 |
12 | CardToken.Tokenizer provider;
13 |
14 | @Override
15 | public void initialize(CardToken field) {
16 | super.initialize(field.excludes(), field.onlyIn(), field.isNulleable());
17 | this.provider = field.provider();
18 | }
19 |
20 | @Override
21 | protected boolean hasError(Object field, ConstraintValidatorContext cxt) {
22 | boolean result = true;
23 | if (field != null) {
24 | Class> clazz = field.getClass();
25 | if (String.class.isAssignableFrom(clazz)) {
26 | result = !TokenValidatorsFactory.getTokenValidator(provider).isValid((String) field);
27 | }
28 | }
29 | return result;
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/main/java/com/github/damianwajser/validator/constraint/cards/token/validators/DataFastValidator.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.validator.constraint.cards.token.validators;
2 |
3 | import java.util.regex.Pattern;
4 |
5 | public class DataFastValidator implements TokenValidator {
6 |
7 | private static final Pattern pattern = Pattern.compile("[0-9A-z]{32}");
8 |
9 | @Override
10 | public boolean isValid(String value) {
11 | return pattern.matcher(value).matches();
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/main/java/com/github/damianwajser/validator/constraint/cards/token/validators/TokenExValidator.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.validator.constraint.cards.token.validators;
2 |
3 | import java.util.regex.Pattern;
4 |
5 | public class TokenExValidator implements TokenValidator {
6 |
7 | private static final Pattern pattern = Pattern.compile("[0-9A-z]{13,19}");
8 |
9 | @Override
10 | public boolean isValid(String value) {
11 | return pattern.matcher(value).matches();
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/main/java/com/github/damianwajser/validator/constraint/cards/token/validators/TokenValidator.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.validator.constraint.cards.token.validators;
2 |
3 | public interface TokenValidator {
4 | boolean isValid(String value);
5 | }
6 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/main/java/com/github/damianwajser/validator/constraint/cards/token/validators/TokenValidatorsFactory.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.validator.constraint.cards.token.validators;
2 |
3 | import com.github.damianwajser.validator.annotation.cards.CardToken;
4 |
5 | public final class TokenValidatorsFactory {
6 |
7 | private TokenValidatorsFactory() {
8 | //make factory static
9 | }
10 |
11 | public static TokenValidator getTokenValidator(CardToken.Tokenizer tokenizer) {
12 | TokenValidator tokenValidator = null;
13 | switch (tokenizer) {
14 | case TOKEN_EX:
15 | tokenValidator = new TokenExValidator();
16 | break;
17 | case DATA_FAST:
18 | tokenValidator = new DataFastValidator();
19 | break;
20 | }
21 | return tokenValidator;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/main/java/com/github/damianwajser/validator/constraint/enums/CountryIso3166Constraint.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.validator.constraint.enums;
2 |
3 | import com.github.damianwajser.validator.annotation.enums.Country_ISO3166;
4 | import com.github.damianwajser.validator.constraint.AbstractConstraint;
5 | import com.github.damianwajser.validator.constraint.enums.values.Countries;
6 | import org.springframework.http.HttpMethod;
7 |
8 | import javax.validation.ConstraintValidator;
9 | import javax.validation.ConstraintValidatorContext;
10 |
11 | public class CountryIso3166Constraint extends AbstractConstraint implements ConstraintValidator {
12 |
13 | @Override
14 | public void initialize(Country_ISO3166 field) {
15 | this.initialize(field.excludes(), field.onlyIn(), field.isNulleable());
16 | }
17 |
18 | public CountryIso3166Constraint initialize(HttpMethod[] excludes, boolean isNulleable, HttpMethod[] onlyIn) {
19 | super.initialize(excludes, onlyIn, isNulleable);
20 | return this;
21 | }
22 |
23 | @Override
24 | protected boolean hasError(Object field, ConstraintValidatorContext cxt) {
25 | return !new MatchEnumConstraint().initialize(this.excludes, this.onlyIn, this.isNulleable, Countries.class).isValid(field, cxt);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/main/java/com/github/damianwajser/validator/constraint/global/AssertTrueConstraint.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.validator.constraint.global;
2 |
3 | import com.github.damianwajser.validator.annotation.global.AssertTrue;
4 | import com.github.damianwajser.validator.constraint.AbstractConstraint;
5 |
6 | import javax.validation.ConstraintValidator;
7 | import javax.validation.ConstraintValidatorContext;
8 |
9 | public class AssertTrueConstraint extends AbstractConstraint implements ConstraintValidator {
10 |
11 | @Override
12 | public void initialize(AssertTrue field) {
13 | super.initialize(field.excludes(), field.onlyIn(), field.isNulleable());
14 | }
15 |
16 | @Override
17 | protected boolean hasError(Object field, ConstraintValidatorContext cxt) {
18 | boolean result = true;
19 | if (field != null && field.getClass().isAssignableFrom(Boolean.class)) {
20 | result = !(Boolean) field;
21 | }
22 | return result;
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/main/java/com/github/damianwajser/validator/constraint/global/EmailConstraint.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.validator.constraint.global;
2 |
3 | import com.github.damianwajser.validator.annotation.global.Email;
4 | import com.github.damianwajser.validator.constraint.AbstractConstraint;
5 |
6 | import javax.validation.ConstraintValidator;
7 | import javax.validation.ConstraintValidatorContext;
8 |
9 | public class EmailConstraint extends AbstractConstraint implements ConstraintValidator {
10 |
11 | private static final String PATTERN = "^[a-zA-Z0-9_+&*-]+(?:\\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,7}$";
12 |
13 | @Override
14 | public void initialize(Email field) {
15 | super.initialize(field.excludes(), field.onlyIn(), field.isNulleable());
16 | super.isNulleable = field.isNulleable();
17 | }
18 |
19 | @Override
20 | protected boolean hasError(Object field, ConstraintValidatorContext cxt) {
21 | return !new PatternConstraint().initialize(this.excludes, this.onlyIn, PATTERN, this.isNulleable).isValid(field, cxt);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/main/java/com/github/damianwajser/validator/constraint/global/NotEmptyConstraint.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.validator.constraint.global;
2 |
3 | import com.github.damianwajser.validator.annotation.global.NotEmpty;
4 | import com.github.damianwajser.validator.constraint.AbstractConstraint;
5 | import org.apache.commons.lang3.ObjectUtils;
6 |
7 | import javax.validation.ConstraintValidator;
8 | import javax.validation.ConstraintValidatorContext;
9 |
10 | public class NotEmptyConstraint extends AbstractConstraint implements ConstraintValidator {
11 |
12 | @Override
13 | public void initialize(NotEmpty field) {
14 | super.initialize(field.excludes(), field.onlyIn(), field.isNulleable());
15 | }
16 |
17 | @Override
18 | protected boolean hasError(Object field, ConstraintValidatorContext cxt) {
19 | return ObjectUtils.isEmpty(field);
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/main/java/com/github/damianwajser/validator/constraint/global/NotNullConstraint.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.validator.constraint.global;
2 |
3 | import com.github.damianwajser.validator.annotation.global.NotNull;
4 | import com.github.damianwajser.validator.constraint.AbstractConstraint;
5 | import org.apache.commons.lang3.ObjectUtils;
6 |
7 | import javax.validation.ConstraintValidator;
8 | import javax.validation.ConstraintValidatorContext;
9 |
10 | public class NotNullConstraint extends AbstractConstraint implements ConstraintValidator {
11 |
12 | @Override
13 | public void initialize(NotNull field) {
14 | super.initialize(field.excludes(), field.onlyIn(), false);
15 | }
16 |
17 | @Override
18 | protected boolean hasError(Object field, ConstraintValidatorContext cxt) {
19 | return !ObjectUtils.allNotNull(field);
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/main/java/com/github/damianwajser/validator/constraint/global/OneNotNullConstraint.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.validator.constraint.global;
2 |
3 | import com.github.damianwajser.validator.annotation.global.OneNotNull;
4 | import com.github.damianwajser.validator.constraint.AbstractConstraint;
5 | import org.springframework.beans.BeanWrapperImpl;
6 | import org.springframework.stereotype.Component;
7 |
8 | import javax.validation.ConstraintValidator;
9 | import javax.validation.ConstraintValidatorContext;
10 | import java.util.Arrays;
11 | import java.util.Objects;
12 |
13 | @Component
14 | public class OneNotNullConstraint extends AbstractConstraint implements ConstraintValidator {
15 |
16 | private String[] fields;
17 |
18 | @Override
19 | public void initialize(final OneNotNull field) {
20 | super.initialize(field.excludes(), field.onlyIn(), field.isNulleable());
21 | fields = field.fields();
22 | }
23 |
24 | @Override
25 | protected boolean hasError(Object obj, ConstraintValidatorContext cxt) {
26 | final BeanWrapperImpl beanWrapper = new BeanWrapperImpl(obj);
27 |
28 | return Arrays.stream(fields)
29 | .map(beanWrapper::getPropertyValue)
30 | .filter(Objects::isNull)
31 | .count()
32 | == fields.length;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/main/java/com/github/damianwajser/validator/constraint/global/OneNotNullValidator.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.validator.constraint.global;
2 |
3 | import com.github.damianwajser.validator.annotation.global.OneNotNull;
4 | import com.github.damianwajser.validator.constraint.AbstractConstraint;
5 | import org.springframework.beans.BeanWrapperImpl;
6 | import org.springframework.stereotype.Component;
7 |
8 | import javax.validation.ConstraintValidator;
9 | import javax.validation.ConstraintValidatorContext;
10 | import java.util.Arrays;
11 | import java.util.Objects;
12 |
13 | @Component
14 | public class OneNotNullValidator extends AbstractConstraint implements ConstraintValidator {
15 |
16 | private String[] fields;
17 |
18 | @Override
19 | public void initialize(final OneNotNull field) {
20 | super.initialize(field.excludes(), field.onlyIn(), field.isNulleable());
21 | fields = field.fields();
22 | }
23 |
24 | @Override
25 | protected boolean hasError(Object obj, ConstraintValidatorContext cxt) {
26 | final BeanWrapperImpl beanWrapper = new BeanWrapperImpl(obj);
27 |
28 | return Arrays.stream(fields)
29 | .map(beanWrapper::getPropertyValue)
30 | .filter(Objects::isNull)
31 | .count()
32 | == fields.length;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/main/java/com/github/damianwajser/validator/constraint/global/PastConstraint.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.validator.constraint.global;
2 |
3 | import com.github.damianwajser.validator.annotation.global.Past;
4 | import com.github.damianwajser.validator.constraint.AbstractConstraint;
5 |
6 | import javax.validation.ConstraintValidator;
7 | import javax.validation.ConstraintValidatorContext;
8 | import java.time.LocalDate;
9 | import java.time.LocalDateTime;
10 | import java.time.ZoneId;
11 | import java.util.Date;
12 |
13 | public class PastConstraint extends AbstractConstraint implements ConstraintValidator {
14 |
15 | @Override
16 | public void initialize(Past field) {
17 | super.initialize(field.excludes(), field.onlyIn(), field.isNulleable());
18 | }
19 |
20 | @Override
21 | protected boolean hasError(Object field, ConstraintValidatorContext cxt) {
22 | boolean result = true;
23 | if (field != null) {
24 | if (LocalDate.class.isAssignableFrom(field.getClass())) {
25 | result = LocalDate.now().isBefore((LocalDate) field);
26 | } else if (LocalDateTime.class.isAssignableFrom(field.getClass())) {
27 | result = LocalDateTime.now().isBefore((LocalDateTime) field);
28 | } else if (Date.class.isAssignableFrom(field.getClass())) {
29 | result = LocalDateTime.now().isBefore(LocalDateTime.ofInstant(((Date) field).toInstant(), ZoneId.systemDefault()));
30 | }
31 | }
32 | return result;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/main/java/com/github/damianwajser/validator/constraint/number/DecimalMinConstraint.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.validator.constraint.number;
2 |
3 | import com.github.damianwajser.validator.annotation.number.DecimalMin;
4 | import com.github.damianwajser.validator.constraint.AbstractConstraint;
5 |
6 | import javax.validation.ConstraintValidator;
7 | import javax.validation.ConstraintValidatorContext;
8 | import java.math.BigDecimal;
9 |
10 | public class DecimalMinConstraint extends AbstractConstraint implements ConstraintValidator {
11 |
12 | private BigDecimal minValue;
13 | private boolean inclusive;
14 |
15 | @Override
16 | public void initialize(DecimalMin field) {
17 | super.initialize(field.excludes(), field.onlyIn(), field.isNulleable());
18 | try {
19 | this.minValue = new BigDecimal(field.value());
20 | } catch (NumberFormatException var3) {
21 | throw new IllegalArgumentException(String.format("%s does not represent a valid BigDecimal format.", field.value()), var3);
22 | }
23 | this.inclusive = field.inclusive();
24 | }
25 |
26 |
27 | @Override
28 | protected boolean hasError(Object field, ConstraintValidatorContext cxt) {
29 | int comparisonResult = this.compare((BigDecimal) field);
30 | return this.inclusive ? comparisonResult < 0 : comparisonResult <= 0;
31 | }
32 |
33 | protected int compare(BigDecimal number) {
34 | return number.compareTo(this.minValue);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/main/java/com/github/damianwajser/validator/constraint/number/MaxConstraint.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.validator.constraint.number;
2 |
3 | import com.github.damianwajser.validator.annotation.number.Max;
4 | import com.github.damianwajser.validator.constraint.AbstractConstraint;
5 |
6 | import javax.validation.ConstraintValidator;
7 | import javax.validation.ConstraintValidatorContext;
8 |
9 | /**
10 | *
11 | */
12 | public class MaxConstraint extends AbstractConstraint implements ConstraintValidator {
13 |
14 | long max;
15 |
16 | @Override
17 | public void initialize(Max field) {
18 | super.initialize(field.excludes(), field.onlyIn(), field.isNulleable());
19 | this.max = field.value();
20 | }
21 |
22 | @Override
23 | protected boolean hasError(Object field, ConstraintValidatorContext cxt) {
24 | boolean hasError = true;
25 | if (field != null && Number.class.isAssignableFrom(field.getClass())) {
26 | long fieldMax = ((Number) field).longValue();
27 | hasError = fieldMax > max;
28 | }
29 | return hasError;
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/main/java/com/github/damianwajser/validator/constraint/number/MinConstraint.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.validator.constraint.number;
2 |
3 | import com.github.damianwajser.validator.annotation.number.Min;
4 | import com.github.damianwajser.validator.constraint.AbstractConstraint;
5 |
6 | import javax.validation.ConstraintValidator;
7 | import javax.validation.ConstraintValidatorContext;
8 |
9 | /**
10 | *
11 | */
12 | public class MinConstraint extends AbstractConstraint implements ConstraintValidator {
13 |
14 | long min;
15 |
16 | @Override
17 | public void initialize(Min field) {
18 | super.initialize(field.excludes(), field.onlyIn(), field.isNulleable());
19 | this.min = field.value();
20 | }
21 |
22 | @Override
23 | protected boolean hasError(Object field, ConstraintValidatorContext cxt) {
24 | boolean hasError = true;
25 | if (field != null && Number.class.isAssignableFrom(field.getClass())) {
26 | long fieldMin = ((Number) field).longValue();
27 | hasError = fieldMin < min;
28 | }
29 | return hasError;
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/main/java/com/github/damianwajser/validator/constraint/strings/AlphaNumericConstraint.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.validator.constraint.strings;
2 |
3 | import com.github.damianwajser.validator.annotation.strings.AlphaNumeric;
4 | import com.github.damianwajser.validator.constraint.strings.abstracts.AbstractWordConstraint;
5 | import org.apache.commons.lang3.StringUtils;
6 |
7 | import javax.validation.ConstraintValidator;
8 |
9 | public class AlphaNumericConstraint extends AbstractWordConstraint implements ConstraintValidator {
10 |
11 | @Override
12 | public void initialize(AlphaNumeric field) {
13 | super.initialize(field.excludes(), field.onlyIn(), field.isNulleable());
14 | super.max = field.max();
15 | super.min = field.min();
16 | super.allowSpaces = field.allowSpaces();
17 | }
18 |
19 | protected boolean isAlpha(Object field, boolean allowSpaces) {
20 | return allowSpaces ? !StringUtils.isAlphanumericSpace((String) field) : !StringUtils.isAlphanumeric((String) field);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/main/java/com/github/damianwajser/validator/constraint/strings/Base64Constraint.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.validator.constraint.strings;
2 |
3 | import com.github.damianwajser.validator.annotation.strings.Base64;
4 | import com.github.damianwajser.validator.constraint.AbstractConstraint;
5 |
6 | import javax.validation.ConstraintValidator;
7 | import javax.validation.ConstraintValidatorContext;
8 |
9 | import static org.apache.tomcat.util.codec.binary.Base64.isBase64;
10 |
11 | public class Base64Constraint extends AbstractConstraint implements ConstraintValidator {
12 |
13 | @Override
14 | public void initialize(Base64 field) {
15 | super.initialize(field.excludes(), field.onlyIn(), field.isNulleable());
16 | }
17 |
18 | /**
19 | * This method returns true if any character is not a valid character in the Base64 alphabet.
20 | * More information of used method could be found here:
21 | * https://commons.apache.org/proper/commons-codec/apidocs/org/apache/commons/codec/binary/Base64.html#isBase64-java.lang.String-
22 | */
23 | @Override
24 | protected boolean hasError(Object field, ConstraintValidatorContext cxt) {
25 | return !isBase64(field.toString());
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/main/java/com/github/damianwajser/validator/constraint/strings/PasswordConstraint.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.validator.constraint.strings;
2 |
3 | import com.github.damianwajser.validator.annotation.strings.Password;
4 | import com.github.damianwajser.validator.constraint.AbstractConstraint;
5 | import com.github.damianwajser.validator.constraint.global.PatternConstraint;
6 |
7 | import javax.validation.ConstraintValidator;
8 | import javax.validation.ConstraintValidatorContext;
9 |
10 | public class PasswordConstraint extends AbstractConstraint implements ConstraintValidator {
11 |
12 | private static final String PATTERN = "((?=.*[a-z])(?=.*\\d)(?=.*[A-Z])(?=.*[@#$%!]).{8,40})";
13 |
14 | @Override
15 | public void initialize(Password field) {
16 | super.initialize(field.excludes(), field.onlyIn(), field.isNulleable());
17 | }
18 |
19 | @Override
20 | protected boolean hasError(Object field, ConstraintValidatorContext cxt) {
21 | return !new PatternConstraint().initialize(this.excludes, this.onlyIn, PATTERN, super.isNulleable).isValid(field, cxt);
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/main/java/com/github/damianwajser/validator/constraint/strings/UUIDConstraint.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.validator.constraint.strings;
2 |
3 | import com.github.damianwajser.validator.annotation.strings.UUID;
4 | import com.github.damianwajser.validator.constraint.AbstractConstraint;
5 | import com.github.damianwajser.validator.constraint.global.PatternConstraint;
6 |
7 | import javax.validation.ConstraintValidator;
8 | import javax.validation.ConstraintValidatorContext;
9 |
10 | public class UUIDConstraint extends AbstractConstraint implements ConstraintValidator {
11 |
12 | private static final String PATTERN = "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$";
13 |
14 | @Override
15 | public void initialize(UUID field) {
16 | super.initialize(field.excludes(), field.onlyIn(), field.isNulleable());
17 | }
18 |
19 | @Override
20 | protected boolean hasError(Object field, ConstraintValidatorContext cxt) {
21 | return !new PatternConstraint().initialize(this.excludes, this.onlyIn, PATTERN, this.isNulleable).isValid(field, cxt);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/main/java/com/github/damianwajser/validator/constraint/strings/WordConstraint.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.validator.constraint.strings;
2 |
3 | import com.github.damianwajser.validator.annotation.strings.Word;
4 | import com.github.damianwajser.validator.constraint.strings.abstracts.AbstractWordConstraint;
5 | import org.apache.commons.lang3.StringUtils;
6 |
7 | import javax.validation.ConstraintValidator;
8 |
9 | public class WordConstraint extends AbstractWordConstraint implements ConstraintValidator {
10 |
11 | @Override
12 | public void initialize(Word field) {
13 | super.initialize(field.excludes(), field.onlyIn(), field.isNulleable());
14 | super.max = field.max();
15 | super.min = field.min();
16 | super.allowSpaces = field.allowSpaces();
17 | }
18 |
19 | protected boolean isAlpha(Object field, boolean allowSpaces) {
20 | return allowSpaces ? !StringUtils.isAlphaSpace((String) field) : !StringUtils.isAlpha((String) field);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/main/java/com/github/damianwajser/validator/constraint/strings/abstracts/AbstractWordConstraint.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.validator.constraint.strings.abstracts;
2 |
3 | import com.github.damianwajser.validator.constraint.AbstractConstraint;
4 | import com.github.damianwajser.validator.constraint.global.SizeConstraint;
5 |
6 | import javax.validation.ConstraintValidatorContext;
7 |
8 | public abstract class AbstractWordConstraint extends AbstractConstraint {
9 |
10 | protected int max;
11 | protected int min;
12 | protected boolean allowSpaces;
13 |
14 |
15 | @Override
16 | protected boolean hasError(Object field, ConstraintValidatorContext cxt) {
17 | boolean hasError = true;
18 | if (String.class.isAssignableFrom(field.getClass())) {
19 | hasError = !new SizeConstraint().initialize(this.excludes, this.onlyIn, this.max, this.min, this.isNulleable).isValid(field, cxt);
20 | if (!hasError) {
21 | hasError = isAlpha(field, this.allowSpaces);
22 | }
23 | }
24 | return hasError;
25 | }
26 |
27 | protected abstract boolean isAlpha(Object field, boolean allowSpaces);
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/main/java/com/github/damianwajser/validator/interfaces/CardExpirable.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.validator.interfaces;
2 |
3 | public interface CardExpirable {
4 |
5 | public int getExpirationMonth();
6 |
7 | public int getExpirationYear();
8 | }
9 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/main/resources/application.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/damianwajser/spring-commons/d1d7fd8f2fbf6691cacffc2587e4a441e4d318d1/spring-commons-rest-validation/src/main/resources/application.properties
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/test/java/com/github/damianwajser/TestApplication.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
5 | import org.springframework.boot.autoconfigure.SpringBootApplication;
6 |
7 | @SpringBootApplication
8 | @EnableAutoConfiguration
9 | public class TestApplication {
10 | public static void main(String[] args) {
11 | SpringApplication.run(TestApplication.class, args);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/test/java/com/github/damianwajser/controllers/BadRequestController.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.controllers;
2 |
3 | import com.github.damianwajser.model.especifics.NoEmptyObjectOnlyPut;
4 | import com.github.damianwajser.model.global.NoEmptyObject;
5 | import org.springframework.web.bind.annotation.PostMapping;
6 | import org.springframework.web.bind.annotation.PutMapping;
7 | import org.springframework.web.bind.annotation.RestController;
8 |
9 | import javax.validation.Valid;
10 |
11 | @RestController
12 | public class BadRequestController {
13 |
14 | @PostMapping("/badrequest")
15 | private NoEmptyObject badRequest(@Valid NoEmptyObject obj) {
16 | return null;
17 | }
18 |
19 | @PutMapping("/badrequest")
20 | private NoEmptyObject badRequest_put(@Valid NoEmptyObject obj) {
21 | return null;
22 | }
23 |
24 | @PutMapping("/badrequest_only_put")
25 | private NoEmptyObjectOnlyPut badRequest_put(@Valid NoEmptyObjectOnlyPut obj) {
26 | return null;
27 | }
28 |
29 | @PostMapping("/badrequest_only_put")
30 | private NoEmptyObjectOnlyPut badRequest_post(@Valid NoEmptyObjectOnlyPut obj) {
31 | return null;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/test/java/com/github/damianwajser/model/cards/ExpirationObject.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.model.cards;
2 |
3 | import com.github.damianwajser.validator.annotation.cards.CardExpiration;
4 | import com.github.damianwajser.validator.interfaces.CardExpirable;
5 |
6 | @CardExpiration(message = "some message", businessCode = "c-400")
7 | public class ExpirationObject implements CardExpirable {
8 |
9 | private int expirationMonth;
10 | private int expirationYear;
11 |
12 | public ExpirationObject() {
13 | }
14 |
15 | public ExpirationObject(int expirationMonth, int expirationYear) {
16 | super();
17 | this.expirationMonth = expirationMonth;
18 | this.expirationYear = expirationYear;
19 | }
20 |
21 | @Override
22 | public int getExpirationMonth() {
23 | return this.expirationMonth;
24 | }
25 |
26 | public void setExpirationMonth(int expirationMonth) {
27 | this.expirationMonth = expirationMonth;
28 | }
29 |
30 | @Override
31 | public int getExpirationYear() {
32 | return this.expirationYear;
33 | }
34 |
35 | public void setExpirationYear(int expirationYear) {
36 | this.expirationYear = expirationYear;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/test/java/com/github/damianwajser/model/cards/tokens/CardDataFastTokenObject.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.model.cards.tokens;
2 |
3 | import com.github.damianwajser.validator.annotation.cards.CardToken;
4 |
5 | public class CardDataFastTokenObject {
6 |
7 | @CardToken(provider = CardToken.Tokenizer.DATA_FAST, message = "some message", businessCode = "c-400")
8 | private String value;
9 |
10 | public CardDataFastTokenObject() {
11 | }
12 |
13 | public CardDataFastTokenObject(String value) {
14 | super();
15 | this.value = value;
16 | }
17 |
18 | public String getValue() {
19 | return value;
20 | }
21 |
22 | public void setValue(String value) {
23 | this.value = value;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/test/java/com/github/damianwajser/model/cards/tokens/CardTokenExObject.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.model.cards.tokens;
2 |
3 | import com.github.damianwajser.validator.annotation.cards.CardToken;
4 |
5 | public class CardTokenExObject {
6 |
7 | @CardToken(provider = CardToken.Tokenizer.TOKEN_EX, message = "some message", businessCode = "c-400")
8 | private String value;
9 |
10 | public CardTokenExObject() {
11 | }
12 |
13 | public CardTokenExObject(String value) {
14 | super();
15 | this.value = value;
16 | }
17 |
18 | public String getValue() {
19 | return value;
20 | }
21 |
22 | public void setValue(String value) {
23 | this.value = value;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/test/java/com/github/damianwajser/model/enums/contry/CountryEnum.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.model.enums.contry;
2 |
3 | import com.github.damianwajser.validator.annotation.enums.Country_ISO3166;
4 | import com.github.damianwajser.validator.constraint.enums.values.Countries;
5 |
6 | public class CountryEnum {
7 |
8 | @Country_ISO3166(message = "some message", businessCode = "c-400")
9 | private Countries value;
10 |
11 | public CountryEnum() {
12 | }
13 |
14 | public CountryEnum(Countries value) {
15 | super();
16 | this.value = value;
17 | }
18 |
19 | public Countries getValue() {
20 | return value;
21 | }
22 |
23 | public void setValue(Countries value) {
24 | this.value = value;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/test/java/com/github/damianwajser/model/enums/contry/CountryString.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.model.enums.contry;
2 |
3 | import com.github.damianwajser.validator.annotation.enums.Country_ISO3166;
4 |
5 | public class CountryString {
6 |
7 | @Country_ISO3166(message = "some message", businessCode = "c-400")
8 | private String value;
9 |
10 | public CountryString() {
11 | }
12 |
13 | public CountryString(String value) {
14 | super();
15 | this.value = value;
16 | }
17 |
18 | public String getValue() {
19 | return value;
20 | }
21 |
22 | public void setValue(String value) {
23 | this.value = value;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/test/java/com/github/damianwajser/model/enums/global/MatchEnumObject.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.model.enums.global;
2 |
3 | import com.github.damianwajser.validator.annotation.enums.MatchEnum;
4 | import com.github.damianwajser.validator.constraint.enums.values.Countries;
5 |
6 | public class MatchEnumObject {
7 |
8 | @MatchEnum(enumClass = Countries.class, message = "some message", businessCode = "c-400")
9 | private Countries value;
10 |
11 | public MatchEnumObject() {
12 | }
13 |
14 | public MatchEnumObject(Countries value) {
15 | super();
16 | this.value = value;
17 | }
18 |
19 | public Countries getValue() {
20 | return value;
21 | }
22 |
23 | public void setValue(Countries value) {
24 | this.value = value;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/test/java/com/github/damianwajser/model/enums/global/MatchEnumObjectArray.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.model.enums.global;
2 |
3 | import com.github.damianwajser.validator.annotation.enums.MatchEnum;
4 | import com.github.damianwajser.validator.constraint.enums.values.Countries;
5 |
6 | public class MatchEnumObjectArray {
7 |
8 | @MatchEnum(enumClass = Countries.class, message = "some message", businessCode = "c-400")
9 | private Countries[] value;
10 |
11 | public MatchEnumObjectArray() {
12 | }
13 |
14 | public MatchEnumObjectArray(Countries[] value) {
15 | super();
16 | this.value = value;
17 | }
18 |
19 | public Countries[] getValue() {
20 | return value;
21 | }
22 |
23 | public void setValue(Countries[] value) {
24 | this.value = value;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/test/java/com/github/damianwajser/model/enums/global/MatchString.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.model.enums.global;
2 |
3 | import com.github.damianwajser.validator.annotation.enums.MatchEnum;
4 | import com.github.damianwajser.validator.constraint.enums.values.Countries;
5 |
6 | public class MatchString {
7 |
8 | @MatchEnum(enumClass = Countries.class, message = "some message", businessCode = "c-400")
9 | private String value;
10 |
11 | public MatchString() {
12 | }
13 |
14 | public MatchString(String value) {
15 | super();
16 | this.value = value;
17 | }
18 |
19 | public String getValue() {
20 | return value;
21 | }
22 |
23 | public void setValue(String value) {
24 | this.value = value;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/test/java/com/github/damianwajser/model/especifics/NoEmptyObjectOnlyPut.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.model.especifics;
2 |
3 | import com.github.damianwajser.validator.annotation.global.NotEmpty;
4 |
5 | import static org.springframework.http.HttpMethod.PATCH;
6 | import static org.springframework.http.HttpMethod.PUT;
7 |
8 | public class NoEmptyObjectOnlyPut {
9 |
10 | @NotEmpty(onlyIn = PUT, businessCode = "a-400", excludes = {PATCH, PUT})
11 | private String value;
12 |
13 | public NoEmptyObjectOnlyPut() {
14 | }
15 |
16 | public NoEmptyObjectOnlyPut(String value) {
17 | super();
18 | this.value = value;
19 | }
20 |
21 | public String getValue() {
22 | return value;
23 | }
24 |
25 | public void setValue(String value) {
26 | this.value = value;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/test/java/com/github/damianwajser/model/global/NoEmptyObject.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.model.global;
2 |
3 | import com.github.damianwajser.validator.annotation.global.NotEmpty;
4 | import org.springframework.http.HttpMethod;
5 |
6 | public class NoEmptyObject {
7 |
8 | @NotEmpty(excludes = HttpMethod.PUT, businessCode = "a-400")
9 | private String value;
10 |
11 | public NoEmptyObject() {
12 | }
13 |
14 | public NoEmptyObject(String value) {
15 | super();
16 | this.value = value;
17 | }
18 |
19 | public String getValue() {
20 | return value;
21 | }
22 |
23 | public void setValue(String value) {
24 | this.value = value;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/test/java/com/github/damianwajser/model/global/PastAuxObject.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.model.global;
2 |
3 |
4 | import com.github.damianwajser.validator.annotation.global.Past;
5 |
6 | public class PastAuxObject {
7 |
8 | @Past(businessCode = "asd")
9 | private Object value;
10 | @Past(businessCode = "asd", isNulleable = true)
11 | private Object nulleable;
12 |
13 | public PastAuxObject() {
14 | }
15 |
16 | public PastAuxObject(Object value) {
17 | super();
18 | this.value = value;
19 | }
20 |
21 | public Object getValue() {
22 | return value;
23 | }
24 |
25 | public void setValue(Object value) {
26 | this.value = value;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/test/java/com/github/damianwajser/model/global/asserttrue/AssertTrueObject.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.model.global.asserttrue;
2 |
3 | import com.github.damianwajser.validator.annotation.global.AssertTrue;
4 |
5 | public class AssertTrueObject {
6 |
7 | @AssertTrue(businessCode = "a-400")
8 | private Boolean value;
9 |
10 | public AssertTrueObject() {
11 | value = null;
12 | }
13 |
14 | public AssertTrueObject(Boolean value) {
15 | super();
16 | this.value = value;
17 | }
18 |
19 | public Boolean getValue() {
20 | return value;
21 | }
22 |
23 | public void setValue(Boolean value) {
24 | this.value = value;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/test/java/com/github/damianwajser/model/global/asserttrue/AssertTrueStringObject.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.model.global.asserttrue;
2 |
3 | import com.github.damianwajser.validator.annotation.global.AssertTrue;
4 |
5 | public class AssertTrueStringObject {
6 |
7 | @AssertTrue(businessCode = "a-400")
8 | private String value;
9 |
10 | public AssertTrueStringObject() {
11 | value = null;
12 | }
13 |
14 | public AssertTrueStringObject(String value) {
15 | super();
16 | this.value = value;
17 | }
18 |
19 | public String getValue() {
20 | return value;
21 | }
22 |
23 | public void setValue(String value) {
24 | this.value = value;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/test/java/com/github/damianwajser/model/global/email/EmailObject.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.model.global.email;
2 |
3 | import com.github.damianwajser.validator.annotation.global.Email;
4 | import org.springframework.http.HttpMethod;
5 |
6 | public class EmailObject {
7 |
8 | @Email(businessCode = "a-400", excludes = HttpMethod.PATCH, message = "")
9 | private Object value;
10 |
11 | public EmailObject() {
12 | }
13 |
14 | public EmailObject(Object value) {
15 | super();
16 | this.value = value;
17 | }
18 |
19 | public Object getValue() {
20 | return value;
21 | }
22 |
23 | public void setValue(Object value) {
24 | this.value = value;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/test/java/com/github/damianwajser/model/global/email/EmailStringObject.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.model.global.email;
2 |
3 | import com.github.damianwajser.validator.annotation.global.Email;
4 | import org.springframework.http.HttpMethod;
5 |
6 | public class EmailStringObject {
7 |
8 | @Email(businessCode = "a-400", excludes = {HttpMethod.PATCH})
9 | private String value;
10 |
11 | public EmailStringObject() {
12 | }
13 |
14 | public EmailStringObject(String value) {
15 | super();
16 | this.value = value;
17 | }
18 |
19 | public String getValue() {
20 | return value;
21 | }
22 |
23 | public void setValue(String value) {
24 | this.value = value;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/test/java/com/github/damianwajser/model/global/max/MaxNumberObject.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.model.global.max;
2 |
3 | @Deprecated
4 | public class MaxNumberObject {
5 |
6 | private Long value;
7 |
8 | public MaxNumberObject() {
9 | }
10 |
11 | public MaxNumberObject(Long value) {
12 | super();
13 | this.value = value;
14 | }
15 |
16 | public Long getValue() {
17 | return value;
18 | }
19 |
20 | public void setValue(Long value) {
21 | this.value = value;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/test/java/com/github/damianwajser/model/global/max/MaxPrimitiveObject.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.model.global.max;
2 |
3 | @Deprecated
4 | public class MaxPrimitiveObject {
5 |
6 | private int value;
7 |
8 | public MaxPrimitiveObject() {
9 | }
10 |
11 | public MaxPrimitiveObject(int value) {
12 | super();
13 | this.value = value;
14 | }
15 |
16 | public int getValue() {
17 | return value;
18 | }
19 |
20 | public void setValue(int value) {
21 | this.value = value;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/test/java/com/github/damianwajser/model/global/max/MaxStringObject.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.model.global.max;
2 |
3 | @Deprecated
4 | public class MaxStringObject {
5 |
6 | private String value;
7 | private String nulleable;
8 |
9 | public MaxStringObject() {
10 | }
11 |
12 | public MaxStringObject(String value) {
13 | super();
14 | this.value = value;
15 | }
16 |
17 | public String getValue() {
18 | return value;
19 | }
20 |
21 | public void setValue(String value) {
22 | this.value = value;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/test/java/com/github/damianwajser/model/global/min/MinNumberObject.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.model.global.min;
2 |
3 | @Deprecated
4 | public class MinNumberObject {
5 |
6 | private Long value;
7 |
8 | public MinNumberObject() {
9 | }
10 |
11 | public MinNumberObject(Long value) {
12 | super();
13 | this.value = value;
14 | }
15 |
16 | public Long getValue() {
17 | return value;
18 | }
19 |
20 | public void setValue(Long value) {
21 | this.value = value;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/test/java/com/github/damianwajser/model/global/min/MinPrimitiveObject.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.model.global.min;
2 |
3 | @Deprecated
4 | public class MinPrimitiveObject {
5 |
6 | private int value;
7 |
8 | public MinPrimitiveObject() {
9 | }
10 |
11 | public MinPrimitiveObject(int value) {
12 | super();
13 | this.value = value;
14 | }
15 |
16 | public int getValue() {
17 | return value;
18 | }
19 |
20 | public void setValue(int value) {
21 | this.value = value;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/test/java/com/github/damianwajser/model/global/min/MinStringObject.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.model.global.min;
2 |
3 | @Deprecated
4 | public class MinStringObject {
5 |
6 | private String value;
7 | private String nulleable;
8 |
9 | public MinStringObject() {
10 | }
11 |
12 | public MinStringObject(String value) {
13 | super();
14 | this.value = value;
15 | }
16 |
17 | public String getValue() {
18 | return value;
19 | }
20 |
21 | public void setValue(String value) {
22 | this.value = value;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/test/java/com/github/damianwajser/model/global/nonull/NoNullCollectionObject.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.model.global.nonull;
2 |
3 | import com.github.damianwajser.validator.annotation.global.NotNull;
4 |
5 | import java.util.Collection;
6 |
7 | public class NoNullCollectionObject {
8 |
9 | @NotNull(businessCode = "a-400")
10 | private Collection> value;
11 |
12 | public NoNullCollectionObject() {
13 | }
14 |
15 | public NoNullCollectionObject(Collection> value) {
16 | super();
17 | this.value = value;
18 | }
19 |
20 | public Collection> getValue() {
21 | return value;
22 | }
23 |
24 | public void setValue(Collection> value) {
25 | this.value = value;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/test/java/com/github/damianwajser/model/global/nonull/NoNullStringObject.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.model.global.nonull;
2 |
3 | import com.github.damianwajser.validator.annotation.global.NotNull;
4 |
5 | public class NoNullStringObject {
6 |
7 | @NotNull(businessCode = "a-400")
8 | private String value;
9 |
10 | public NoNullStringObject() {
11 | }
12 |
13 | public NoNullStringObject(String value) {
14 | super();
15 | this.value = value;
16 | }
17 |
18 | public String getValue() {
19 | return value;
20 | }
21 |
22 | public void setValue(String value) {
23 | this.value = value;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/test/java/com/github/damianwajser/model/global/onenotnull/OneNotNullObject.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.model.global.onenotnull;
2 |
3 | import com.github.damianwajser.validator.annotation.global.OneNotNull;
4 |
5 | @OneNotNull(
6 | fields = {"value","value2"},
7 | businessCode = ""
8 |
9 | )
10 | public class OneNotNullObject {
11 |
12 | private Object value;
13 |
14 | private Object value2;
15 |
16 | public OneNotNullObject() {
17 | }
18 |
19 | public OneNotNullObject(Object value, Object value2) {
20 | this.value = value;
21 | this.value2 = value2;
22 | }
23 |
24 | public Object getValue2() {
25 | return value2;
26 | }
27 |
28 | public void setValue2(Object value2) {
29 | this.value2 = value2;
30 | }
31 |
32 | public Object getValue() {
33 | return value;
34 | }
35 |
36 | public void setValue(Object value) {
37 | this.value = value;
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/test/java/com/github/damianwajser/model/global/size/SizeCollectionObject.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.model.global.size;
2 |
3 | import com.github.damianwajser.validator.annotation.global.Size;
4 |
5 | import java.util.Collection;
6 |
7 | public class SizeCollectionObject {
8 |
9 | @Size(max = 5, businessCode = "c-400")
10 | private Collection value;
11 |
12 | public SizeCollectionObject() {
13 | }
14 |
15 | public SizeCollectionObject(Collection value) {
16 | super();
17 | this.value = value;
18 | }
19 |
20 | public Collection getValue() {
21 | return value;
22 | }
23 |
24 | public void setValue(Collection value) {
25 | this.value = value;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/test/java/com/github/damianwajser/model/global/size/SizeMinOneStringObject.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.model.global.size;
2 |
3 | import com.github.damianwajser.validator.annotation.global.Size;
4 |
5 | public class SizeMinOneStringObject {
6 |
7 | @Size(min = 1, max = 5, businessCode = "c-400")
8 | private String value;
9 |
10 | public SizeMinOneStringObject() {
11 | }
12 |
13 | public SizeMinOneStringObject(String value) {
14 | super();
15 | this.value = value;
16 | }
17 |
18 | public String getValue() {
19 | return value;
20 | }
21 |
22 | public void setValue(String value) {
23 | this.value = value;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/test/java/com/github/damianwajser/model/global/size/SizeMinZeroStringObject.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.model.global.size;
2 |
3 | import com.github.damianwajser.validator.annotation.global.Size;
4 |
5 | public class SizeMinZeroStringObject {
6 |
7 | @Size(max = 5, businessCode = "c-400")
8 | private String value;
9 |
10 | @Size(isNulleable = true, max = 5, businessCode = "c-400")
11 | private String nulleable;
12 |
13 | public SizeMinZeroStringObject() {
14 | }
15 |
16 | public SizeMinZeroStringObject(String value) {
17 | super();
18 | this.value = value;
19 | this.nulleable = value;
20 | }
21 |
22 | public SizeMinZeroStringObject(String value, String nulleable) {
23 | super();
24 | this.value = value;
25 | this.nulleable = nulleable;
26 | }
27 |
28 | public String getValue() {
29 | return value;
30 | }
31 |
32 | public void setValue(String value) {
33 | this.value = value;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/test/java/com/github/damianwajser/model/number/DecimalMinInclusiveObject.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.model.number;
2 |
3 | import com.github.damianwajser.validator.annotation.number.DecimalMin;
4 |
5 | import java.math.BigDecimal;
6 |
7 | public class DecimalMinInclusiveObject {
8 |
9 | @DecimalMin(value = "0.0", businessCode = "a-400")
10 | private BigDecimal value;
11 |
12 | public DecimalMinInclusiveObject() {
13 | }
14 |
15 | public DecimalMinInclusiveObject(BigDecimal value) {
16 | super();
17 | this.value = value;
18 | }
19 |
20 | public BigDecimal getValue() {
21 | return value;
22 | }
23 |
24 | public void setValue(BigDecimal value) {
25 | this.value = value;
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/test/java/com/github/damianwajser/model/number/DecimalMinObject.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.model.number;
2 |
3 | import com.github.damianwajser.validator.annotation.number.DecimalMin;
4 |
5 | import java.math.BigDecimal;
6 |
7 | public class DecimalMinObject {
8 |
9 | @DecimalMin(value = "0.0", inclusive = false, businessCode = "a-400")
10 | private BigDecimal value;
11 |
12 | public DecimalMinObject() {
13 | }
14 |
15 | public DecimalMinObject(BigDecimal value) {
16 | super();
17 | this.value = value;
18 | }
19 |
20 | public BigDecimal getValue() {
21 | return value;
22 | }
23 |
24 | public void setValue(BigDecimal value) {
25 | this.value = value;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/test/java/com/github/damianwajser/model/number/DigitsDecimalObject.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.model.number;
2 |
3 | import com.github.damianwajser.validator.annotation.number.Digits;
4 |
5 | import java.math.BigDecimal;
6 |
7 | public class DigitsDecimalObject {
8 |
9 | @Digits(integer = 3, fraction = 2, businessCode = "a-400")
10 | private BigDecimal value;
11 |
12 | public DigitsDecimalObject() {
13 | }
14 |
15 | public DigitsDecimalObject(BigDecimal value) {
16 | super();
17 | this.value = value;
18 | }
19 |
20 | public BigDecimal getValue() {
21 | return value;
22 | }
23 |
24 | public void setValue(BigDecimal value) {
25 | this.value = value;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/test/java/com/github/damianwajser/model/number/DigitsWithoutDecimalAndMultiplyObject.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.model.number;
2 |
3 | import com.github.damianwajser.validator.annotation.number.Digits;
4 |
5 | import java.math.BigDecimal;
6 |
7 | public class DigitsWithoutDecimalAndMultiplyObject {
8 |
9 | @Digits(integer = 4, fraction = 0, multipleOf = 10, businessCode = "a-400")
10 | private BigDecimal value;
11 |
12 | public DigitsWithoutDecimalAndMultiplyObject() {
13 | }
14 |
15 | public DigitsWithoutDecimalAndMultiplyObject(BigDecimal value) {
16 | super();
17 | this.value = value;
18 | }
19 |
20 | public BigDecimal getValue() {
21 | return value;
22 | }
23 |
24 | public void setValue(int BigDecimal) {
25 | this.value = value;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/test/java/com/github/damianwajser/model/number/DigitsWithoutDecimalAndMultiplyObjectInt.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.model.number;
2 |
3 | import com.github.damianwajser.validator.annotation.number.Digits;
4 |
5 | public class DigitsWithoutDecimalAndMultiplyObjectInt {
6 |
7 | @Digits(integer = 4, fraction = 0, multipleOf = 10, businessCode = "a-400")
8 | private int value;
9 |
10 | public DigitsWithoutDecimalAndMultiplyObjectInt() {
11 | }
12 |
13 | public DigitsWithoutDecimalAndMultiplyObjectInt(int value) {
14 | super();
15 | this.value = value;
16 | }
17 |
18 | public int getValue() {
19 | return value;
20 | }
21 |
22 | public void setValue(int value) {
23 | this.value = value;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/test/java/com/github/damianwajser/model/number/DigitsWithoutDecimalObject.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.model.number;
2 |
3 | import com.github.damianwajser.validator.annotation.number.Digits;
4 |
5 | import java.math.BigDecimal;
6 |
7 | public class DigitsWithoutDecimalObject {
8 |
9 | @Digits(integer = 3, fraction = 0, businessCode = "a-400")
10 | private BigDecimal value;
11 |
12 | public DigitsWithoutDecimalObject() {
13 | }
14 |
15 | public DigitsWithoutDecimalObject(BigDecimal value) {
16 | super();
17 | this.value = value;
18 | }
19 |
20 | public BigDecimal getValue() {
21 | return value;
22 | }
23 |
24 | public void setValue(BigDecimal value) {
25 | this.value = value;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/test/java/com/github/damianwajser/model/number/max/MaxNumberObject.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.model.number.max;
2 |
3 |
4 | import com.github.damianwajser.validator.annotation.number.Max;
5 |
6 | public class MaxNumberObject {
7 |
8 | @Max(value = 3, businessCode = "a-400")
9 | private Long value;
10 |
11 | public MaxNumberObject() {
12 | }
13 |
14 | public MaxNumberObject(Long value) {
15 | super();
16 | this.value = value;
17 | }
18 |
19 | public Long getValue() {
20 | return value;
21 | }
22 |
23 | public void setValue(Long value) {
24 | this.value = value;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/test/java/com/github/damianwajser/model/number/max/MaxPrimitiveObject.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.model.number.max;
2 |
3 |
4 | import com.github.damianwajser.validator.annotation.number.Max;
5 |
6 | public class MaxPrimitiveObject {
7 |
8 | @Max(value = 2, businessCode = "a-400")
9 | private int value;
10 |
11 | public MaxPrimitiveObject() {
12 | }
13 |
14 | public MaxPrimitiveObject(int value) {
15 | super();
16 | this.value = value;
17 | }
18 |
19 | public int getValue() {
20 | return value;
21 | }
22 |
23 | public void setValue(int value) {
24 | this.value = value;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/test/java/com/github/damianwajser/model/number/max/MaxStringObject.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.model.number.max;
2 |
3 |
4 | import com.github.damianwajser.validator.annotation.number.Max;
5 |
6 | public class MaxStringObject {
7 |
8 | @Max(value = 2, businessCode = "a-400")
9 | private String value;
10 | @Max(value = 2, businessCode = "a-400", isNulleable = true)
11 | private String nulleable;
12 |
13 | public MaxStringObject() {
14 | }
15 |
16 | public MaxStringObject(String value) {
17 | super();
18 | this.value = value;
19 | }
20 |
21 | public String getValue() {
22 | return value;
23 | }
24 |
25 | public void setValue(String value) {
26 | this.value = value;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/test/java/com/github/damianwajser/model/number/min/MinNumberObject.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.model.number.min;
2 |
3 |
4 | import com.github.damianwajser.validator.annotation.number.Min;
5 |
6 | public class MinNumberObject {
7 |
8 | @Min(value = 3, businessCode = "a-400")
9 | private Long value;
10 |
11 | public MinNumberObject() {
12 | }
13 |
14 | public MinNumberObject(Long value) {
15 | super();
16 | this.value = value;
17 | }
18 |
19 | public Long getValue() {
20 | return value;
21 | }
22 |
23 | public void setValue(Long value) {
24 | this.value = value;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/test/java/com/github/damianwajser/model/number/min/MinPrimitiveObject.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.model.number.min;
2 |
3 |
4 | import com.github.damianwajser.validator.annotation.number.Min;
5 |
6 | public class MinPrimitiveObject {
7 |
8 | @Min(value = 2, businessCode = "a-400")
9 | private int value;
10 |
11 | public MinPrimitiveObject() {
12 | }
13 |
14 | public MinPrimitiveObject(int value) {
15 | super();
16 | this.value = value;
17 | }
18 |
19 | public int getValue() {
20 | return value;
21 | }
22 |
23 | public void setValue(int value) {
24 | this.value = value;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/test/java/com/github/damianwajser/model/number/min/MinStringObject.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.model.number.min;
2 |
3 |
4 | import com.github.damianwajser.validator.annotation.number.Min;
5 |
6 | public class MinStringObject {
7 |
8 | @Min(value = 2, businessCode = "a-400")
9 | private String value;
10 | @Min(value = 2, businessCode = "a-400", isNulleable = true)
11 | private String nulleable;
12 |
13 | public MinStringObject() {
14 | }
15 |
16 | public MinStringObject(String value) {
17 | super();
18 | this.value = value;
19 | }
20 |
21 | public String getValue() {
22 | return value;
23 | }
24 |
25 | public void setValue(String value) {
26 | this.value = value;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/test/java/com/github/damianwajser/model/pattern/PatternStringObject.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.model.pattern;
2 |
3 | import com.github.damianwajser.validator.annotation.global.Pattern;
4 |
5 | public class PatternStringObject {
6 |
7 | @Pattern(businessCode = "a-400", regexp = "^[a-zA-Z0-9_+&*-]+(?:\\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,7}$")
8 | private String value;
9 |
10 | public PatternStringObject() {
11 | }
12 |
13 | public PatternStringObject(String value) {
14 | super();
15 | this.value = value;
16 | }
17 |
18 | public String getValue() {
19 | return value;
20 | }
21 |
22 | public void setValue(String value) {
23 | this.value = value;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/test/java/com/github/damianwajser/model/strings/AlphaAllowSpaceStringObject.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.model.strings;
2 |
3 | import com.github.damianwajser.validator.annotation.strings.AlphaNumeric;
4 |
5 | public class AlphaAllowSpaceStringObject {
6 |
7 | @AlphaNumeric(message = "somemmessage", min = 1, max = 5, businessCode = "c-400")
8 | @AlphaNumeric(message = "somemmessage", min = 1, max = 6, businessCode = "c-400")
9 | private String value;
10 |
11 | public AlphaAllowSpaceStringObject() {
12 | }
13 |
14 | public AlphaAllowSpaceStringObject(String value) {
15 | super();
16 | this.value = value;
17 | }
18 |
19 | public String getValue() {
20 | return value;
21 | }
22 |
23 | public void setValue(String value) {
24 | this.value = value;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/test/java/com/github/damianwajser/model/strings/AlphaMinOneStringObject.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.model.strings;
2 |
3 | import com.github.damianwajser.validator.annotation.strings.AlphaNumeric;
4 |
5 | public class AlphaMinOneStringObject {
6 |
7 | @AlphaNumeric(message = "somemmessage", min = 1, max = 5, businessCode = "c-400", allowSpaces = false)
8 | private String value;
9 | @AlphaNumeric(message = "somemmessage", min = 1, max = 5, businessCode = "c-400", allowSpaces = false, isNulleable = true)
10 | private String nulleable;
11 |
12 | public AlphaMinOneStringObject() {
13 | }
14 |
15 | public AlphaMinOneStringObject(String value) {
16 | super();
17 | this.value = value;
18 | this.nulleable = value;
19 | }
20 |
21 | public String getValue() {
22 | return value;
23 | }
24 |
25 | public void setValue(String value) {
26 | this.value = value;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/test/java/com/github/damianwajser/model/strings/Base64StringObject.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.model.strings;
2 |
3 | import com.github.damianwajser.validator.annotation.strings.Base64;
4 |
5 | public class Base64StringObject {
6 |
7 | @Base64(message = "error", businessCode = "a-400")
8 | private String value;
9 |
10 | public Base64StringObject() {
11 | }
12 |
13 | public Base64StringObject(String value) {
14 | super();
15 | this.value = value;
16 | }
17 |
18 | public String getValue() {
19 | return value;
20 | }
21 |
22 | public void setValue(String value) {
23 | this.value = value;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/test/java/com/github/damianwajser/model/strings/PasswordStringObject.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.model.strings;
2 |
3 | import com.github.damianwajser.validator.annotation.strings.Password;
4 |
5 | public class PasswordStringObject {
6 |
7 | @Password(message = "error", businessCode = "a-400")
8 | private String value;
9 |
10 | public PasswordStringObject() {
11 | }
12 |
13 | public PasswordStringObject(String value) {
14 | super();
15 | this.value = value;
16 | }
17 |
18 | public String getValue() {
19 | return value;
20 | }
21 |
22 | public void setValue(String value) {
23 | this.value = value;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/test/java/com/github/damianwajser/model/strings/UUIDObject.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.model.strings;
2 |
3 | import com.github.damianwajser.validator.annotation.strings.UUID;
4 |
5 | public class UUIDObject {
6 |
7 | @UUID(message = "error", businessCode = "a-400")
8 | private String value;
9 |
10 | public UUIDObject() {
11 | }
12 |
13 | public UUIDObject(String value) {
14 | super();
15 | this.value = value;
16 | }
17 |
18 | public String getValue() {
19 | return value;
20 | }
21 |
22 | public void setValue(String value) {
23 | this.value = value;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/test/java/com/github/damianwajser/model/strings/WordAllowSpaceStringObject.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.model.strings;
2 |
3 | import com.github.damianwajser.validator.annotation.strings.Word;
4 |
5 | public class WordAllowSpaceStringObject {
6 |
7 | @Word(message = "somemmessage", min = 1, max = 6, businessCode = "c-400")
8 | private String value;
9 |
10 | public WordAllowSpaceStringObject() {
11 | }
12 |
13 | public WordAllowSpaceStringObject(String value) {
14 | super();
15 | this.value = value;
16 | }
17 |
18 | public String getValue() {
19 | return value;
20 | }
21 |
22 | public void setValue(String value) {
23 | this.value = value;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/test/java/com/github/damianwajser/model/strings/WordMinOneStringObject.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.model.strings;
2 |
3 | import com.github.damianwajser.validator.annotation.strings.Word;
4 |
5 | public class WordMinOneStringObject {
6 |
7 | @Word(message = "somemmessage", min = 1, max = 5, businessCode = "c-400", allowSpaces = false)
8 | private String value;
9 | @Word(message = "somemmessage", min = 1, max = 5, businessCode = "c-400", allowSpaces = false, isNulleable = true)
10 | private String nulleable;
11 |
12 | public WordMinOneStringObject() {
13 | }
14 |
15 | public WordMinOneStringObject(String value) {
16 | super();
17 | this.value = value;
18 | this.nulleable = value;
19 | }
20 |
21 | public String getValue() {
22 | return value;
23 | }
24 |
25 | public void setValue(String value) {
26 | this.value = value;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/test/java/com/github/damianwajser/tests/cards/CardValidationTest.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.tests.cards;
2 |
3 | import com.github.damianwajser.model.cards.ExpirationObject;
4 | import org.junit.Test;
5 |
6 | import static com.github.damianwajser.TestUtils.*;
7 | import static org.hamcrest.MatcherAssert.assertThat;
8 |
9 | public class CardValidationTest {
10 |
11 | @Test
12 | public void expirationMonth() throws Exception {
13 | assertThat(validationFor(new ExpirationObject()), fails());
14 | assertThat(validationFor(new ExpirationObject(10, 30)), succedes());
15 | assertThat(validationFor(new ExpirationObject(11, 26)), succedes());
16 | assertThat(validationFor(new ExpirationObject(5, 25)), succedes());
17 | assertThat(validationFor(new ExpirationObject(2, 19)), fails());
18 | assertThat(validationFor(new ExpirationObject(99, 25)), fails());
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/test/java/com/github/damianwajser/tests/cards/tokens/DataFastValidationTest.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.tests.cards.tokens;
2 |
3 | import com.github.damianwajser.model.cards.tokens.CardDataFastTokenObject;
4 | import org.junit.Test;
5 |
6 | import java.util.UUID;
7 |
8 | import static com.github.damianwajser.TestUtils.*;
9 | import static org.hamcrest.MatcherAssert.assertThat;
10 |
11 | public class DataFastValidationTest {
12 |
13 | @Test
14 | public void cardToken() throws Exception {
15 | assertThat(validationFor(new CardDataFastTokenObject(), onField("value")), fails());
16 | assertThat(validationFor(new CardDataFastTokenObject("1234567891234"), onField("value")), fails());
17 | assertThat(validationFor(new CardDataFastTokenObject("123456asd72340"), onField("value")), fails());
18 | assertThat(validationFor(new CardDataFastTokenObject("3456asd72340"), onField("value")), fails());
19 | assertThat(validationFor(new CardDataFastTokenObject("asdasdasdasdasdasdasdasdasdasdasdasdasd"), onField("value")), fails());
20 | assertThat(validationFor(new CardDataFastTokenObject("8ac7a4a07ef7c8ba017f0387416e2521"), onField("value")), succedes());
21 | assertThat(validationFor(new CardDataFastTokenObject(UUID.randomUUID().toString().replaceAll("-", "")), onField("value")), succedes());
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/test/java/com/github/damianwajser/tests/cards/tokens/TokenExValidationTest.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.tests.cards.tokens;
2 |
3 | import com.github.damianwajser.model.cards.tokens.CardTokenExObject;
4 | import org.junit.Test;
5 |
6 | import static com.github.damianwajser.TestUtils.*;
7 | import static org.hamcrest.MatcherAssert.assertThat;
8 |
9 | public class TokenExValidationTest {
10 |
11 | @Test
12 | public void cardToken() throws Exception {
13 | assertThat(validationFor(new CardTokenExObject(), onField("value")), fails());
14 | assertThat(validationFor(new CardTokenExObject("1234567891234"), onField("value")), succedes());
15 | assertThat(validationFor(new CardTokenExObject("123456asd72340"), onField("value")), succedes());
16 | assertThat(validationFor(new CardTokenExObject("3456asd72340"), onField("value")), fails());
17 | assertThat(validationFor(new CardTokenExObject("asdasdasdasdasdasdasdasd"), onField("value")), fails());
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/test/java/com/github/damianwajser/tests/enums/contry/CountryValidationTest.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.tests.enums.contry;
2 |
3 | import com.github.damianwajser.model.enums.contry.CountryEnum;
4 | import com.github.damianwajser.model.enums.contry.CountryString;
5 | import com.github.damianwajser.validator.constraint.enums.values.Countries;
6 | import org.junit.Test;
7 |
8 | import static com.github.damianwajser.TestUtils.*;
9 | import static org.hamcrest.MatcherAssert.assertThat;
10 |
11 | public class CountryValidationTest {
12 |
13 | @Test
14 | public void CountryEnum() throws Exception {
15 | assertThat(validationFor(new CountryEnum(), onField("value")), fails());
16 | assertThat(validationFor(new CountryEnum(Countries.ARG), onField("value")), succedes());
17 | }
18 |
19 | @Test
20 | public void CountryString() throws Exception {
21 | assertThat(validationFor(new CountryString(), onField("value")), fails());
22 | assertThat(validationFor(new CountryString("ASDFGH"), onField("value")), fails());
23 | assertThat(validationFor(new CountryString("ARG"), onField("value")), succedes());
24 |
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/test/java/com/github/damianwajser/tests/enums/contry/MatchEnumArrayValidationTest.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.tests.enums.contry;
2 |
3 | import com.github.damianwajser.model.enums.global.MatchEnumObjectArray;
4 | import com.github.damianwajser.validator.constraint.enums.values.Countries;
5 | import org.junit.Test;
6 |
7 | import static com.github.damianwajser.TestUtils.*;
8 | import static org.hamcrest.MatcherAssert.assertThat;
9 |
10 | public class MatchEnumArrayValidationTest {
11 |
12 | @Test
13 | public void CountryEnum() throws Exception {
14 | assertThat(validationFor(new MatchEnumObjectArray(), onField("value")), fails());
15 | assertThat(validationFor(new MatchEnumObjectArray(new Countries[]{Countries.ARG}), onField("value")), succedes());
16 | }
17 |
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/test/java/com/github/damianwajser/tests/enums/contry/MatchEnumValidationTest.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.tests.enums.contry;
2 |
3 | import com.github.damianwajser.model.enums.global.MatchEnumObject;
4 | import com.github.damianwajser.model.enums.global.MatchString;
5 | import com.github.damianwajser.validator.constraint.enums.values.Countries;
6 | import org.junit.Test;
7 |
8 | import static com.github.damianwajser.TestUtils.*;
9 | import static org.hamcrest.MatcherAssert.assertThat;
10 |
11 | public class MatchEnumValidationTest {
12 |
13 | @Test
14 | public void CountryEnum() throws Exception {
15 | assertThat(validationFor(new MatchEnumObject(), onField("value")), fails());
16 | assertThat(validationFor(new MatchEnumObject(Countries.ARG), onField("value")), succedes());
17 | }
18 |
19 | @Test
20 | public void CountryString() throws Exception {
21 | assertThat(validationFor(new MatchString(), onField("value")), fails());
22 | assertThat(validationFor(new MatchString("ASDFGH"), onField("value")), fails());
23 | assertThat(validationFor(new MatchString("ARG"), onField("value")), succedes());
24 |
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/test/java/com/github/damianwajser/tests/global/AssertTrueTest.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.tests.global;
2 |
3 | import com.github.damianwajser.model.global.asserttrue.AssertTrueObject;
4 | import com.github.damianwajser.model.global.asserttrue.AssertTrueStringObject;
5 | import org.junit.Test;
6 |
7 | import static com.github.damianwajser.TestUtils.*;
8 | import static org.hamcrest.MatcherAssert.assertThat;
9 |
10 | public class AssertTrueTest {
11 |
12 | @Test
13 | public void true_Boolean() throws Exception {
14 | assertThat(validationFor(new AssertTrueObject(), onField("value")), fails());
15 | assertThat(validationFor(new AssertTrueObject(false), onField("value")), fails());
16 | assertThat(validationFor(new AssertTrueObject(true), onField("value")), succedes());
17 | }
18 |
19 | @Test
20 | public void true_object() throws Exception {
21 | assertThat(validationFor(new AssertTrueStringObject(), onField("value")), fails());
22 | assertThat(validationFor(new AssertTrueStringObject("false"), onField("value")), fails());
23 | assertThat(validationFor(new AssertTrueStringObject("true"), onField("value")), fails());
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/test/java/com/github/damianwajser/tests/global/NotNullTest.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.tests.global;
2 |
3 | import com.github.damianwajser.model.global.nonull.NoNullCollectionObject;
4 | import com.github.damianwajser.model.global.nonull.NoNullStringObject;
5 | import org.junit.Test;
6 |
7 | import java.util.Arrays;
8 |
9 | import static com.github.damianwajser.TestUtils.*;
10 | import static org.hamcrest.MatcherAssert.assertThat;
11 |
12 | public class NotNullTest {
13 |
14 | @Test
15 | public void not_null_string() throws Exception {
16 | assertThat(validationFor(new NoNullStringObject(), onField("value")), fails());
17 | assertThat(validationFor(new NoNullStringObject("4"), onField("value")), succedes());
18 | }
19 |
20 | @Test
21 | public void noNull_collection() throws Exception {
22 | assertThat(validationFor(new NoNullCollectionObject()), fails());
23 | assertThat(validationFor(new NoNullCollectionObject(Arrays.asList(null, null))), succedes());
24 | assertThat(validationFor(new NoNullCollectionObject(Arrays.asList(1, 2, 3, 4, 5, 6))), succedes());
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/test/java/com/github/damianwajser/tests/global/OneNotNullTest.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.tests.global;
2 |
3 | import com.github.damianwajser.model.global.onenotnull.OneNotNullObject;
4 | import org.junit.Test;
5 |
6 | import static com.github.damianwajser.TestUtils.*;
7 | import static org.hamcrest.MatcherAssert.assertThat;
8 |
9 | public class OneNotNullTest {
10 |
11 | @Test
12 | public void oneNotNull() {
13 | assertThat(validationFor(new OneNotNullObject()), fails());
14 | assertThat(validationFor(new OneNotNullObject(null,null)), fails());
15 | assertThat(validationFor(new OneNotNullObject(null,"value2")), succedes());
16 | assertThat(validationFor(new OneNotNullObject("value2",null)), succedes());
17 | }
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/test/java/com/github/damianwajser/tests/strings/Base64ValidationTest.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.tests.strings;
2 |
3 | import com.github.damianwajser.model.strings.Base64StringObject;
4 | import org.junit.Test;
5 |
6 | import static com.github.damianwajser.TestUtils.*;
7 | import static org.hamcrest.MatcherAssert.assertThat;
8 |
9 | public class Base64ValidationTest {
10 |
11 | @Test
12 | public void base64_string() {
13 | assertThat(validationFor(new Base64StringObject(), onField("value")), fails());
14 | assertThat(validationFor(new Base64StringObject("c3ByaW5nLWNvbW1vbnM="), onField("value")), succedes());
15 | //isBase64 treats whitespace as valid
16 | assertThat(validationFor(new Base64StringObject("a b c d"), onField("value")), succedes());
17 | assertThat(validationFor(new Base64StringObject("c3ByaW5nLWNvbW1vbn..."), onField("value")), fails());
18 | assertThat(validationFor(new Base64StringObject("abcd**"), onField("value")), fails());
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/spring-commons-rest-validation/src/test/java/com/github/damianwajser/tests/strings/UUIDTest.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.tests.strings;
2 |
3 | import com.github.damianwajser.model.strings.UUIDObject;
4 | import org.junit.Test;
5 |
6 | import java.util.UUID;
7 |
8 | import static com.github.damianwajser.TestUtils.*;
9 | import static org.hamcrest.MatcherAssert.assertThat;
10 |
11 | public class UUIDTest {
12 |
13 | @Test
14 | public void password_string() throws Exception {
15 | assertThat(validationFor(new UUIDObject(), onField("value")), fails());
16 | assertThat(validationFor(new UUIDObject(""), onField("value")), fails());
17 | assertThat(validationFor(new UUIDObject("n!k@s"), onField("value")), fails());
18 | assertThat(validationFor(new UUIDObject("gregorymarjames-law"), onField("value")), fails());
19 | assertThat(validationFor(new UUIDObject("1231231-sdgxfgh-234534t-dsgasdg"), onField("value")), fails());
20 | assertThat(validationFor(new UUIDObject("1231231-sdgxfgh-234534t-dsgasdg-asfwteseg4"), onField("value")), fails());
21 |
22 | assertThat(validationFor(new UUIDObject(UUID.randomUUID().toString()), onField("value")), succedes());
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/spring-commons-utilities/.flattened-pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | com.github.damianwajser
7 | spring-commons-parent
8 | 1.28.4
9 |
10 | com.github.damianwajser
11 | spring-commons-utilities
12 | 1.28.4
13 |
14 |
15 | Apache License, Version 2.0
16 | http://www.apache.org/licenses/LICENSE-2.0.txt
17 | repo
18 |
19 |
20 |
21 | 2.6.0
22 |
23 |
24 |
25 | com.jayway.jsonpath
26 | json-path
27 | ${com.jayway.jsonpath}
28 |
29 |
30 | com.github.damianwajser
31 | spring-commons-exception
32 | ${project.version}
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/spring-commons-utilities/pom.xml:
--------------------------------------------------------------------------------
1 |
4 | 4.0.0
5 | spring-commons-utilities
6 | jar
7 | ${revision}
8 |
9 | com.github.damianwajser
10 | spring-commons-parent
11 | ${revision}
12 |
13 |
14 | 2.6.0
15 |
16 |
17 |
18 | com.jayway.jsonpath
19 | json-path
20 | ${com.jayway.jsonpath}
21 |
22 |
23 | com.github.damianwajser
24 | spring-commons-exception
25 | ${project.version}
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/spring-commons-utilities/src/main/java/com/github/damianwajser/factories/jsonbased/FactoryCriteriaJsonBased.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.factories.jsonbased;
2 |
3 | import com.github.damianwajser.factories.jsonbased.criteria.Criteria;
4 | import com.github.damianwajser.factories.jsonbased.criteria.Criterion;
5 | import com.jayway.jsonpath.DocumentContext;
6 | import com.jayway.jsonpath.JsonPath;
7 |
8 | import java.util.Collection;
9 | import java.util.stream.Collectors;
10 |
11 | public class FactoryCriteriaJsonBased {
12 |
13 | public Criteria criteria;
14 |
15 | public FactoryCriteriaJsonBased(Criteria criteria) {
16 | this.criteria = criteria;
17 | }
18 |
19 | public Collection find(DocumentContext json) {
20 | Collection result = criteria.getAllCriterion().stream()
21 | .filter(c -> c.match(json))
22 | .map(Criterion::getResult)
23 | .collect(Collectors.toList());
24 | if (result.isEmpty() && criteria.getDefaultResult() != null) {
25 | result.add(criteria.getDefaultResult());
26 | }
27 | return result;
28 | }
29 |
30 | public Collection find(String json) {
31 | return this.find(JsonPath.parse(json));
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/spring-commons-utilities/src/main/java/com/github/damianwajser/factories/jsonbased/conditions/Condition.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.factories.jsonbased.conditions;
2 |
3 | import com.github.damianwajser.factories.jsonbased.conditions.operations.Operation;
4 | import com.github.damianwajser.factories.jsonbased.conditions.operations.OperationFactory;
5 | import com.jayway.jsonpath.DocumentContext;
6 |
7 | public class Condition {
8 |
9 | private String field;
10 | private String match;
11 | private Operation operation;
12 |
13 | public Condition(String field, String match) {
14 | this(field, match, Operation.EQUALS);
15 | }
16 |
17 | public Condition(String field, String match, Operation operation) {
18 | this.field = field;
19 | this.match = match;
20 | this.operation = operation;
21 | }
22 |
23 | public boolean match(DocumentContext json) {
24 | Object value = json.read(field).toString();
25 | return OperationFactory.getOperation(operation).apply(value, match);
26 | }
27 |
28 | @Override
29 | public String toString() {
30 | return "Condition(" + field + " " + operation + " " + match + ')';
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/spring-commons-utilities/src/main/java/com/github/damianwajser/factories/jsonbased/conditions/operations/Operation.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.factories.jsonbased.conditions.operations;
2 |
3 | import java.util.HashMap;
4 | import java.util.Map;
5 |
6 | public enum Operation {
7 | EQUALS("=");
8 |
9 | private static final Map BY_OPERATION = new HashMap<>();
10 |
11 | private final String value;
12 |
13 | static {
14 | for (Operation e : values()) {
15 | BY_OPERATION.put(e.value, e);
16 | }
17 | }
18 |
19 | Operation(String value) {
20 | this.value = value;
21 | }
22 |
23 | public static Operation value(String label) {
24 | return BY_OPERATION.get(label);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/spring-commons-utilities/src/main/java/com/github/damianwajser/factories/jsonbased/conditions/operations/OperationFactory.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.factories.jsonbased.conditions.operations;
2 |
3 | import com.github.damianwajser.factories.jsonbased.conditions.operations.impl.EqualsStrategy;
4 |
5 | public final class OperationFactory {
6 |
7 | private OperationFactory(){
8 | // private constructor
9 | }
10 | public static synchronized OperationStrategy getOperation(Operation operation) {
11 | return new EqualsStrategy();
12 | }
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/spring-commons-utilities/src/main/java/com/github/damianwajser/factories/jsonbased/conditions/operations/OperationStrategy.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.factories.jsonbased.conditions.operations;
2 |
3 | public interface OperationStrategy {
4 | boolean apply(Object source, Object target);
5 | }
6 |
--------------------------------------------------------------------------------
/spring-commons-utilities/src/main/java/com/github/damianwajser/factories/jsonbased/conditions/operations/impl/EqualsStrategy.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.factories.jsonbased.conditions.operations.impl;
2 |
3 | import com.github.damianwajser.factories.jsonbased.conditions.operations.OperationStrategy;
4 |
5 | public class EqualsStrategy implements OperationStrategy {
6 | @Override
7 | public boolean apply(Object source, Object target) {
8 | return source.equals(target);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/spring-commons-utilities/src/main/java/com/github/damianwajser/factories/jsonbased/criteria/Criteria.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.factories.jsonbased.criteria;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Collection;
5 |
6 | public class Criteria {
7 |
8 | private Collection> criterionCollection;
9 | private T defaultResult;
10 |
11 | public Criteria() {
12 | this(null, null);
13 | }
14 |
15 | public Criteria(T defaultResult) {
16 | this(defaultResult, null);
17 | }
18 |
19 | public Criteria(Collection> criteria) {
20 | this(null, criteria);
21 | }
22 |
23 | public Criteria(T defaultResult, Collection> criteria) {
24 | this.defaultResult = defaultResult;
25 | this.criterionCollection = criteria != null ? criteria : new ArrayList<>();
26 | }
27 |
28 | public Collection> getAllCriterion() {
29 | return criterionCollection;
30 | }
31 |
32 | public T getDefaultResult() {
33 | return defaultResult;
34 | }
35 |
36 | public Criterion addCriterion(Criterion criterion) {
37 | this.criterionCollection.add(criterion);
38 | return criterion;
39 | }
40 |
41 | public Criterion addCriterion(T defaultResult) {
42 | return this.addCriterion(new Criterion<>(defaultResult));
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/spring-commons-utilities/src/main/java/com/github/damianwajser/factories/jsonbased/criteria/Criterion.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.factories.jsonbased.criteria;
2 |
3 | import com.github.damianwajser.factories.jsonbased.conditions.Condition;
4 | import com.jayway.jsonpath.DocumentContext;
5 |
6 | import java.util.ArrayList;
7 | import java.util.Collection;
8 |
9 | public class Criterion {
10 |
11 | private Collection conditions;
12 | private T result;
13 |
14 | public Criterion(T result) {
15 | this(null, result);
16 | }
17 |
18 | public Criterion(Collection conditions, T result) {
19 | this.conditions = conditions != null ? conditions : new ArrayList<>();
20 | this.result = result;
21 | }
22 |
23 | public Criterion and(Condition condition) {
24 | this.conditions.add(condition);
25 | return this;
26 | }
27 |
28 | public T getResult() {
29 | return this.result;
30 | }
31 |
32 | public boolean match(DocumentContext json) {
33 | return this.conditions.stream().allMatch(c -> c.match(json));
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/spring-commons-utilities/src/main/java/com/github/damianwajser/optionals/wrappers/ConsumerWrapper.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.optionals.wrappers;
2 |
3 | import com.github.damianwajser.exceptions.RestException;
4 |
5 | @FunctionalInterface
6 | public interface ConsumerWrapper {
7 |
8 | void acceptWithException(T t) throws RestException;
9 | }
10 |
--------------------------------------------------------------------------------
/spring-commons-utilities/src/main/java/com/github/damianwajser/optionals/wrappers/OptionalWrapper.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.optionals.wrappers;
2 |
3 | import com.github.damianwajser.exceptions.RestException;
4 |
5 | import java.util.Objects;
6 | import java.util.Optional;
7 |
8 | public class OptionalWrapper {
9 |
10 | private final Optional value;
11 |
12 | private OptionalWrapper(Optional value) {
13 | this.value = Objects.requireNonNull(value);
14 | }
15 |
16 | public static OptionalWrapper of(Optional value) {
17 | return new OptionalWrapper<>(value);
18 | }
19 |
20 | public void ifPresent(ConsumerWrapper consumer) throws RestException {
21 | if (value.isPresent())
22 | consumer.acceptWithException(value.get());
23 | }
24 |
25 | public T get() {
26 | return this.value.get();
27 | }
28 |
29 | public Optional unWrap() {
30 | return this.value;
31 | }
32 |
33 | public boolean isPresent() {
34 | return this.value.isPresent();
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/spring-commons-utilities/src/main/java/com/github/damianwajser/parsers/Mapper.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.parsers;
2 |
3 | import java.util.HashMap;
4 | import java.util.Map;
5 |
6 | public class Mapper {
7 |
8 | private Map mappings;
9 | private boolean skipPathNotFound;
10 |
11 | public Mapper() {
12 | this.skipPathNotFound = true;
13 | }
14 |
15 | public Map getMappings() {
16 | return mappings;
17 | }
18 |
19 | public void addMapping(String field, String template) {
20 | if (this.mappings == null) {
21 | this.mappings = new HashMap<>();
22 | }
23 | this.mappings.put(field, template);
24 | }
25 |
26 | public boolean isSkipPathNotFound() {
27 | return skipPathNotFound;
28 | }
29 |
30 | public void setSkipPathNotFound(boolean skipPathNotFound) {
31 | this.skipPathNotFound = skipPathNotFound;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/spring-commons-utilities/src/test/java/test/factory/jsonbased/TestUtils.java:
--------------------------------------------------------------------------------
1 | package test.factory.jsonbased;
2 |
3 | import java.util.Collection;
4 |
5 | import static org.hamcrest.MatcherAssert.assertThat;
6 | import static org.hamcrest.Matchers.hasItems;
7 | import static org.hamcrest.Matchers.hasSize;
8 |
9 | public class TestUtils {
10 |
11 | public static void checkResult(Collection actual, String... expected) {
12 | assertThat(actual, hasItems(expected));
13 | assertThat(actual, hasSize(expected.length));
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/spring-commons-utilities/src/test/java/test/mapper/model/NotificationMapperModel.java:
--------------------------------------------------------------------------------
1 | package test.mapper.model;
2 |
3 | public class NotificationMapperModel {
4 |
5 | private String title;
6 | private String body;
7 | private String subTitle;
8 | private String footer;
9 |
10 | public String getTitle() {
11 | return title;
12 | }
13 |
14 | public void setTitle(String title) {
15 | this.title = title;
16 | }
17 |
18 | public String getBody() {
19 | return body;
20 | }
21 |
22 | public void setBody(String body) {
23 | this.body = body;
24 | }
25 |
26 | public String getSubTitle() {
27 | return subTitle;
28 | }
29 |
30 | public void setSubTitle(String subTitle) {
31 | this.subTitle = subTitle;
32 | }
33 |
34 | public String getFooter() {
35 | return footer;
36 | }
37 |
38 | public void setFooter(String footer) {
39 | this.footer = footer;
40 | }
41 |
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/spring-commons-utilities/src/test/resources/application.yml:
--------------------------------------------------------------------------------
1 | notifications:
2 | send_money:
3 | condition: $.type = p2p
4 | sender:
5 | chanel: push
6 | mapping:
7 | userid: $.origin.user_id
8 | title: ${user.name} le mandaste ${tx.amount} a $.destinatiion.user_name
9 | subtitle: ${user.name} asdasd ${asdasd}
10 | footer: ${user.name} asdasd ${asdasd}
11 | recived_money:
12 | condition: $.type = p2p
13 | sender:
14 | chanel: push
15 | mapping:
16 | userid: $.origin.user_id
17 | title: ${user.name} le mandaste ${tx.amount} a $.destinatiion.user_name
18 | subtitle: ${user.name} asdasd ${asdasd}
19 | footer: ${user.name} asdasd ${asdasd}
20 |
--------------------------------------------------------------------------------
/spring-commons-utilities/src/test/resources/data/data.json:
--------------------------------------------------------------------------------
1 | {
2 | "type": "p2p"
3 | }
4 |
--------------------------------------------------------------------------------
/spring-commons/README.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/damianwajser/spring-commons/d1d7fd8f2fbf6691cacffc2587e4a441e4d318d1/spring-commons/README.md
--------------------------------------------------------------------------------
/spring-commons/src/main/java/com/github/damianwajser/commons/configuration/PropertiesCommons.java:
--------------------------------------------------------------------------------
1 | package com.github.damianwajser.commons.configuration;
2 |
3 | import org.springframework.boot.context.properties.ConfigurationProperties;
4 | import org.springframework.context.annotation.Configuration;
5 | import org.springframework.context.annotation.PropertySource;
6 |
7 | @Configuration
8 | @ConfigurationProperties
9 | @PropertySource("classpath:spring-commons.properties")
10 | public class PropertiesCommons {
11 | }
12 |
--------------------------------------------------------------------------------
/spring-commons/src/main/resources/spring-commons.properties:
--------------------------------------------------------------------------------
1 | spring.jackson.property-naming-strategy=com.fasterxml.jackson.databind.PropertyNamingStrategy.SnakeCaseStrategy
2 | spring.commons.app.name=${spring.application.name}
3 |
--------------------------------------------------------------------------------