Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Merge branch 'validations-enhancements' into master, fixing #137
- Loading branch information
Showing
25 changed files
with
500 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package restx.annotations; | ||
|
||
import com.sun.tools.javac.code.Attribute; | ||
|
||
import javax.lang.model.element.AnnotationMirror; | ||
import javax.lang.model.element.AnnotationValue; | ||
import javax.lang.model.element.ExecutableElement; | ||
import javax.lang.model.element.VariableElement; | ||
import javax.lang.model.type.DeclaredType; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* @author fcamblor | ||
*/ | ||
public class Annotations { | ||
public static String[] getAnnotationClassValuesAsFQCN(VariableElement p, Class annotationClazz, String methodName) { | ||
List<? extends AnnotationMirror> annotationMirrors = p.getAnnotationMirrors(); | ||
for(AnnotationMirror annotationMirror : annotationMirrors){ | ||
if(annotationMirror.getAnnotationType().toString().equals(annotationClazz.getCanonicalName())){ | ||
for(Map.Entry<? extends ExecutableElement,? extends AnnotationValue> entry : annotationMirror.getElementValues().entrySet()){ | ||
if(entry.getKey().getSimpleName().contentEquals(methodName)){ | ||
Attribute.Array array = (Attribute.Array) entry.getValue(); | ||
|
||
List<String> fqcns = new ArrayList<>(); | ||
for(Attribute attribute : array.getValue()) { | ||
DeclaredType type = (DeclaredType) attribute.getValue(); | ||
fqcns.add(type.toString()); | ||
} | ||
return fqcns.toArray(new String[fqcns.size()]); | ||
} | ||
} | ||
} | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package restx.validation; | ||
|
||
import java.lang.annotation.*; | ||
|
||
/** | ||
* @author fcamblor | ||
*/ | ||
@Target(ElementType.PARAMETER) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Documented | ||
public @interface ValidatedFor { | ||
Class[] value(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package restx.validation.stereotypes; | ||
|
||
import javax.validation.groups.Default; | ||
|
||
/** | ||
* @author fcamblor | ||
*/ | ||
public interface FormValidations { | ||
public static final String DefaultFQN = "javax.validation.groups.Default"; | ||
public static final String CreateFQN = "restx.validation.stereotypes.FormValidations.Create"; | ||
public static interface Create extends Default{} | ||
public static final String UpdateFQN = "restx.validation.stereotypes.FormValidations.Update"; | ||
public static interface Update extends Default{} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package samplest.validation; | ||
|
||
import org.hibernate.validator.constraints.Email; | ||
import restx.validation.stereotypes.FormValidations; | ||
|
||
import javax.validation.Valid; | ||
import javax.validation.constraints.NotNull; | ||
import javax.validation.constraints.Size; | ||
|
||
public class POJO { | ||
@NotNull(groups={FormValidations.Update.class}) | ||
Long id; | ||
@NotNull | ||
@Size(min=10, groups={ValidationResource.MyCustomValidationGroup.class}) | ||
String name; | ||
@Valid | ||
SubPOJO subPOJO; | ||
String email; | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
public String getEmail() { | ||
return email; | ||
} | ||
|
||
public void setEmail(String email) { | ||
this.email = email; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public SubPOJO getSubPOJO() { | ||
return subPOJO; | ||
} | ||
|
||
public void setSubPOJO(SubPOJO subPOJO) { | ||
this.subPOJO = subPOJO; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package samplest.validation; | ||
|
||
import javax.validation.constraints.Size; | ||
|
||
public class SubPOJO { | ||
@Size(min=10) | ||
String label; | ||
|
||
public String getLabel() { | ||
return label; | ||
} | ||
|
||
public void setLabel(String label) { | ||
this.label = label; | ||
} | ||
} |
Oops, something went wrong.