Permalink
Browse files

Implementing abst. class validation methods for properties's validation

  • Loading branch information...
dgkncelik committed May 12, 2018
1 parent e0060a9 commit 90bbed27716c1d4c57ef7a58e7728e33071dd7af
Showing with 359 additions and 95 deletions.
  1. +5 −0 pom.xml
  2. +4 −1 src/main/java/edu/itu/cavabunga/core/entity/Parameter.java
  3. +140 −1 src/main/java/edu/itu/cavabunga/core/entity/Property.java
  4. +1 −4 src/main/java/edu/itu/cavabunga/core/entity/parameter/Altrep.java
  5. +2 −8 src/main/java/edu/itu/cavabunga/core/entity/parameter/Cn.java
  6. +2 −5 src/main/java/edu/itu/cavabunga/core/entity/parameter/Cutype.java
  7. +2 −4 src/main/java/edu/itu/cavabunga/core/entity/parameter/DelegatedFrom.java
  8. +2 −4 src/main/java/edu/itu/cavabunga/core/entity/parameter/DelegatedTo.java
  9. +2 −5 src/main/java/edu/itu/cavabunga/core/entity/parameter/Dir.java
  10. +6 −3 src/main/java/edu/itu/cavabunga/core/entity/parameter/Encoding.java
  11. +1 −4 src/main/java/edu/itu/cavabunga/core/entity/parameter/Fbtype.java
  12. +2 −4 src/main/java/edu/itu/cavabunga/core/entity/parameter/Fmttype.java
  13. +7 −6 src/main/java/edu/itu/cavabunga/core/entity/parameter/Language.java
  14. +2 −4 src/main/java/edu/itu/cavabunga/core/entity/parameter/Member.java
  15. +32 −12 src/main/java/edu/itu/cavabunga/core/entity/parameter/Partstat.java
  16. +2 −3 src/main/java/edu/itu/cavabunga/core/entity/parameter/Range.java
  17. +2 −4 src/main/java/edu/itu/cavabunga/core/entity/parameter/Related.java
  18. +2 −4 src/main/java/edu/itu/cavabunga/core/entity/parameter/Reltype.java
  19. +2 −4 src/main/java/edu/itu/cavabunga/core/entity/parameter/Role.java
  20. +2 −4 src/main/java/edu/itu/cavabunga/core/entity/parameter/Rsvp.java
  21. +2 −4 src/main/java/edu/itu/cavabunga/core/entity/parameter/SentBy.java
  22. +15 −1 src/main/java/edu/itu/cavabunga/core/entity/parameter/Tzid.java
  23. +2 −5 src/main/java/edu/itu/cavabunga/core/entity/parameter/Value.java
  24. +5 −0 src/main/java/edu/itu/cavabunga/core/entity/property/Country.java
  25. +18 −0 src/main/java/edu/itu/cavabunga/core/entity/property/Created.java
  26. +30 −0 src/main/java/edu/itu/cavabunga/core/entity/property/Description.java
  27. +18 −0 src/main/java/edu/itu/cavabunga/core/entity/property/Dtend.java
  28. +18 −0 src/main/java/edu/itu/cavabunga/core/entity/property/Dtstamp.java
  29. +29 −0 src/main/java/edu/itu/cavabunga/core/entity/property/PropertyValueType.java
  30. +2 −1 src/main/resources/application.properties
View
@@ -78,6 +78,11 @@
<version>2.8.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.7</version>
</dependency>
</dependencies>
<build>
@@ -5,6 +5,7 @@
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import edu.itu.cavabunga.core.entity.parameter.*;
import edu.itu.cavabunga.exception.Validation;
import lombok.Data;
import org.hibernate.annotations.DiscriminatorOptions;
@@ -54,6 +55,8 @@
private Property property;
public void validate(){
if((this.value == null) || (this.value.trim().isEmpty())){
throw new Validation(this.getClass().getName() + " parameter cannot be empty");
}
}
}
@@ -3,8 +3,10 @@
import com.fasterxml.jackson.annotation.*;
import edu.itu.cavabunga.core.entity.property.*;
import edu.itu.cavabunga.core.entity.property.Class;
import edu.itu.cavabunga.exception.Validation;
import lombok.Data;
import org.hibernate.annotations.DiscriminatorOptions;
import org.omg.PortableServer.THREAD_POLICY_ID;
import javax.persistence.*;
import javax.persistence.Version;
@@ -90,7 +92,144 @@ public void addParameter(Parameter parameter){
parameters.add(parameter);
}
public void validate(){
public void validate(List<Parameter> mustHaveParameterList,
List<Parameter> cannotHaveParameterList,
PropertyValueType propertyValueType,
Boolean checkWithValueParameter){
if(!this.parameters.isEmpty()){
for(Parameter pr : this.parameters){
try{
pr.validate();
}catch (Exception e){
throw new Validation(this.getClass().getName() + " property class validation failed: " + e.getMessage());
}
}
}
}
public void validateMustHaveParameters(List<Parameter> parameterList){
if(!parameterList.isEmpty()) {
Integer instanceCount = parameterList.size();
Integer foundInstance = 0;
for (Parameter pr : parameterList) {
for (Parameter search : parameters) {
if (pr.getClass().getName().equals(search.getClass().getName())) {
foundInstance++;
}
}
}
if (foundInstance != instanceCount) {
throw new Validation(this.getClass().getName() + "property musthaveList is not valid");
}
}
}
public void validateCannotHaveParameters(List<Parameter> parameterList){
if(!parameterList.isEmpty()) {
for (Parameter pr : parameterList) {
for (Parameter search : parameters) {
if (pr.getClass().getName().equals(search.getClass().getName())) {
throw new Validation(this.getClass().getName() + " property cannot have child parameter of: " + search.getClass().getName());
}
}
}
}
}
public void validateValueType(PropertyValueType propertyValueType){
if(propertyValueType == PropertyValueType.BINARY){
if(!value.matches("^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)$")){
throw new Validation(this.getClass().getName() + " value is not valid BINARY type");
}
}
if(propertyValueType == PropertyValueType.BOOLEAN){
if(value != "TRUE" && value != "FALSE"){
throw new Validation(this.getClass().getName() + " value is not valid BOOLEAN type " + value);
}
}
if(propertyValueType == PropertyValueType.CALADDRESS){
//TODO: there is a full rfc about it: rfc3986
}
if(propertyValueType == PropertyValueType.DATE){
String[] parts = value.split(",");
for(String part : parts){
if(!part.matches("^[0-9]{8}$")){
throw new Validation(this.getClass().getName() + " value is not valid DATE type " + value);
}
}
}
if(propertyValueType == PropertyValueType.DATETIME){
String[] parts = value.split(",");
for(String part : parts){
if(!part.matches("^[0-9]{8}T[0-9]{6}|[0-9]{8}T[0-9]{6}Z")){
throw new Validation(this.getClass().getName() + " value is not valid DATE-TIME type " + value);
}
}
}
if(propertyValueType == PropertyValueType.DURATION){
//TODO: rfc5545 pg 35
}
if(propertyValueType == PropertyValueType.FLOAT){
String[] parts = value.split(",");
for(String part : parts){
try{
Float f = Float.parseFloat(value);
}catch (NumberFormatException e){
throw new Validation(this.getClass().getName() + " value is not valid FLOAT type " + value);
}
}
}
if(propertyValueType == PropertyValueType.INTEGER){
String[] parts = value.split(",");
for(String part : parts) {
try {
Integer i = Integer.parseInt(value);
} catch (NumberFormatException e) {
throw new Validation(this.getClass().getName() + " value is not valid INTEGER type" + value);
}
}
}
if(propertyValueType == PropertyValueType.PERIOD){
//TODO: rfc5545 pg 36
}
if(propertyValueType == PropertyValueType.RECUR){
//TODO: rfc5545 pg 37-45
}
if(propertyValueType == PropertyValueType.TEXT){
//TODO: rfc5545 pg 45
}
if(propertyValueType == PropertyValueType.TIME){
String[] parts = value.split(",");
for(String part : parts){
if(!part.matches("^[0-9]{6}$|^[0-9]{6}Z$")){
throw new Validation(this.getClass().getName() + " value is not valid TIME type " + value);
}
}
}
if(propertyValueType == PropertyValueType.URI){
//TODO: there is a full rfc about it: rfc3986
}
if(propertyValueType == PropertyValueType.UTCOFFSET){
String[] parts = value.split(",");
for(String part : parts){
if(!part.matches("^+[0-9]{4}$|^+[0-9]{4}Z$")){
throw new Validation(this.getClass().getName() + " value is not valid TIME type " + value);
}
}
}
}
}
@@ -9,10 +9,7 @@
public class Altrep extends Parameter {
@Override
public void validate(){
if(this.getValue().trim() == ""){
throw new Validation("ALTREP parameter cannot be empty");
}
super.validate();
if(this.getValue().substring(0,1) != "\"" || this.getValue().substring(this.getValue().length() -1) != "\""){
throw new Validation("ALTREP parameter must start and end with DQUOTE char.");
}
@@ -9,13 +9,7 @@
public class Cn extends Parameter {
@Override
public void validate(){
if(this.getValue().trim() == ""){
throw new Validation("CN parameter cannot be empty");
}
if(this.getValue().substring(0,1) != "\"" || this.getValue().substring(this.getValue().length() -1) != "\""){
throw new Validation("CN parameter must start and end with DQUOTE char.");
}
//TODO: This parameter can be specified on properties with a CAL-ADDRESS value type
super.validate();
}
}
@@ -9,17 +9,14 @@
public class Cutype extends Parameter {
@Override
public void validate(){
if(this.getValue().trim() == ""){
throw new Validation("CUTYPE value cannot be empty");
}
//TODO: This parameter can be specified on properties with a CAL-ADDRESS value type
super.validate();
if(this.getValue() != "INDIVIDUAL" &&
this.getValue() != "GROUP" &&
this.getValue() != "RESOURCE" &&
this.getValue() != "ROOM" &&
this.getValue() != "UNKNOWN"){
throw new Validation("CUTYPE value is different from acceptable value range: " + this.getValue());
}
}
}
@@ -9,10 +9,8 @@
public class DelegatedFrom extends Parameter {
@Override
public void validate(){
if(this.getValue().trim() == ""){
throw new Validation("DELEGATED-FROM parameter cannot be empty");
}
//TODO: This parameter can be specified on properties with a CAL-ADDRESS value type
super.validate();
if(this.getValue().substring(0,1) != "\"" || this.getValue().substring(this.getValue().length() -1) != "\""){
throw new Validation("DELEGATED-FROM parameter must start and end with DQUOTE char.");
}
@@ -9,10 +9,8 @@
public class DelegatedTo extends Parameter {
@Override
public void validate(){
if(this.getValue().trim() == ""){
throw new Validation("DELEGATED-TO parameter cannot be empty");
}
//TODO: This parameter can be specified on properties with a CAL-ADDRESS value type
super.validate();
if(this.getValue().substring(0,1) != "\"" || this.getValue().substring(this.getValue().length() -1) != "\""){
throw new Validation("DELEGATED-TO parameter must start and end with DQUOTE char.");
}
@@ -9,13 +9,10 @@
public class Dir extends Parameter {
@Override
public void validate(){
if(this.getValue().trim() == ""){
throw new Validation("DIR parameter cannot be empty");
}
//TODO: This parameter can be specified on properties with a CAL-ADDRESS value type
super.validate();
if(this.getValue().substring(0,1) != "\"" || this.getValue().substring(this.getValue().length() -1) != "\""){
throw new Validation("DIR parameter must start and end with DQUOTE char.");
}
}
}
@@ -9,13 +9,16 @@
public class Encoding extends Parameter {
@Override
public void validate(){
if(this.getValue().trim() == ""){
throw new Validation("ENCODING value cannot be empty");
}
super.validate();
if(this.getValue() != "BASE64" && this.getValue() != "8BIT"){
throw new Validation("ENCODING value is different from acceptable value range: " + this.getValue());
}
for(Parameter pr : this.getProperty().getParameters()){
if( (pr instanceof Value) && pr.getValue() == "BINARY" && this.getValue() != "BASE64"){
throw new Validation("While VALUE parameter described as BINARY, ENCODING parameter MUST set as BASE64");
}
}
}
}
@@ -9,10 +9,7 @@
public class Fbtype extends Parameter {
@Override
public void validate(){
if(this.getValue().trim() == ""){
throw new Validation("FBTYPE cannot be empty");
}
super.validate();
if(this.getValue() != "FREE" &&
this.getValue() != "BUSY" &&
this.getValue() != "BUSY-UNAVAILABLE" &&
@@ -9,10 +9,8 @@
public class Fmttype extends Parameter {
@Override
public void validate(){
if(this.getValue().trim() == ""){
throw new Validation("FMTTYPE cannot be empty");
}
//TODO: This parameter can be specified on properties that are used to reference an object
super.validate();
if(this.getValue().matches("(\\w+)/(\\w+)") != true){
throw new Validation("FMTYPE must have valid mime type: " + this.getValue());
}
@@ -2,18 +2,19 @@
import edu.itu.cavabunga.core.entity.Parameter;
import edu.itu.cavabunga.exception.Validation;
import org.apache.commons.lang.LocaleUtils;
import javax.persistence.Entity;
@Entity
public class Language extends Parameter {
@Override
public void validate(){
if(this.getValue().trim() != ""){
throw new Validation("LANGUAGE parameter cannot be empty");
}
// TODO: Look for language expression types
// for example us or us-EN
super.validate();
try {
LocaleUtils.toLocale(this.getValue());
}catch (IllegalArgumentException e){
throw new Validation("Language parameter failed: " + e.getMessage());
}
}
}
@@ -9,10 +9,8 @@
public class Member extends Parameter{
@Override
public void validate(){
if(this.getValue().trim() == ""){
throw new Validation("MEMBER parameter cannot be empty");
}
//TODO: This parameter can be specified on properties with a CAL-ADDRESS value type
super.validate();
if(this.getValue().substring(0,1) != "\"" || this.getValue().substring(this.getValue().length() -1) != "\""){
throw new Validation("MEMBER parameter must start and end with DQUOTE char.");
}
Oops, something went wrong.

0 comments on commit 90bbed2

Please sign in to comment.