-
Notifications
You must be signed in to change notification settings - Fork 15
AYS-550 | NoSpacesAround
Annotation Has Been Created to Check Leading and Trailing Spaces
#404
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
MenekseYuncu
merged 6 commits into
main
from
bugfix/AYS-550/no-special-character-validation-fix
Dec 8, 2024
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
adb70fc
AYS-550 | Trailing or Leading Space Validation Has Been Removed from …
egehanasal 6ea4866
AYS-550 | `NoTrailingOrLeadingSpaces` Annotation Has Been Created and…
egehanasal 8851025
AYS-550 | Controller Tests Have Been Updated
egehanasal efccea4
AYS-550 | Validator Has Been Renamed and Updated
egehanasal 90b6a8b
AYS-550 | Test Method Name Has Been Fixed
egehanasal e471bf5
AYS-550 | Test Methods Have Been Refactored
egehanasal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/main/java/org/ays/common/util/validation/NoSpacesAround.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.ays.common.util.validation; | ||
|
||
import jakarta.validation.Constraint; | ||
import jakarta.validation.Payload; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* Annotation to validate a text using {@link NoSpacesAroundValidator}. | ||
*/ | ||
@Target(value = ElementType.FIELD) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Constraint(validatedBy = NoSpacesAroundValidator.class) | ||
public @interface NoSpacesAround { | ||
|
||
/** | ||
* Returns the error message when the text is not valid. | ||
* | ||
* @return the error message | ||
*/ | ||
String message() default "cannot start or end with space"; | ||
|
||
/** | ||
* Returns the validation groups to which this constraint belongs. | ||
* | ||
* @return the validation groups | ||
*/ | ||
Class<?>[] groups() default {}; | ||
|
||
/** | ||
* Returns the payload associated to this constraint. | ||
* | ||
* @return the payload | ||
*/ | ||
Class<? extends Payload>[] payload() default {}; | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/org/ays/common/util/validation/NoSpacesAroundValidator.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.ays.common.util.validation; | ||
|
||
import jakarta.validation.ConstraintValidator; | ||
import jakarta.validation.ConstraintValidatorContext; | ||
import org.springframework.util.StringUtils; | ||
|
||
/** | ||
* A custom validator implementation for the {@link NoSpacesAround} annotation. | ||
* Validates whether the provided text does not have | ||
* trailing or leading spaces. | ||
*/ | ||
class NoSpacesAroundValidator implements ConstraintValidator<NoSpacesAround, String> { | ||
|
||
@Override | ||
public boolean isValid(String text, ConstraintValidatorContext constraintValidatorContext) { | ||
|
||
if (!StringUtils.hasText(text)) { | ||
return true; | ||
} | ||
|
||
return !(text.startsWith(" ") || text.endsWith(" ")); | ||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.