Permalink
Browse files

Implementing abst. class validation methods for properties's validation

  • Loading branch information...
dgkncelik committed May 12, 2018
1 parent 90bbed2 commit ae7df01bfc6df0ceebc1affa815525896e5d80a2
@@ -92,10 +92,7 @@ public void addParameter(Parameter parameter){
parameters.add(parameter);
}
public void validate(List<Parameter> mustHaveParameterList,
List<Parameter> cannotHaveParameterList,
PropertyValueType propertyValueType,
Boolean checkWithValueParameter){
public void validate(){
if(!this.parameters.isEmpty()){
for(Parameter pr : this.parameters){
try{
@@ -105,10 +102,38 @@ public void validate(List<Parameter> mustHaveParameterList,
}
}
}
/*
if(mustHaveParameterList != null && !mustHaveParameterList.isEmpty()){
try{
validateMustHaveParameters(mustHaveParameterList);
}catch (Exception e){
throw new Validation(this.getClass().getName() + " property class validation failed: " + e.getMessage());
}
}
if(cannotHaveParameterList != null && !cannotHaveParameterList.isEmpty()){
try {
validateCannotHaveParameters(cannotHaveParameterList);
}catch (Exception e){
throw new Validation(this.getClass().getName() + " property class validation failed: " + e.getMessage());
}
}
if(propertyValueType != null){
try{
validateValueType(propertyValueType);
}catch (Exception e){
throw new Validation(this.getClass().getName() + " property class validation failed: " + e.getMessage());
}
}
*/
}
public void validateMustHaveParameters(List<Parameter> parameterList){
if(!parameterList.isEmpty()) {
if(parameterList != null && !parameterList.isEmpty()) {
Integer instanceCount = parameterList.size();
Integer foundInstance = 0;
for (Parameter pr : parameterList) {
@@ -126,7 +151,7 @@ public void validateMustHaveParameters(List<Parameter> parameterList){
}
public void validateCannotHaveParameters(List<Parameter> parameterList){
if(!parameterList.isEmpty()) {
if(parameterList != null && !parameterList.isEmpty()) {
for (Parameter pr : parameterList) {
for (Parameter search : parameters) {
if (pr.getClass().getName().equals(search.getClass().getName())) {
@@ -138,96 +163,98 @@ public void validateCannotHaveParameters(List<Parameter> parameterList){
}
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 != null) {
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.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.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.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.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.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.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.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.PERIOD) {
//TODO: rfc5545 pg 36
}
if(propertyValueType == PropertyValueType.RECUR){
//TODO: rfc5545 pg 37-45
}
if (propertyValueType == PropertyValueType.RECUR) {
//TODO: rfc5545 pg 37-45
}
if(propertyValueType == PropertyValueType.TEXT){
//TODO: rfc5545 pg 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.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.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);
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);
}
}
}
}
@@ -11,19 +11,11 @@
public class Attach extends Property {
@Override
public void validate(){
if(this.getValue().trim() != ""){
throw new Validation("ATTACH property cannot be empty");
}
if(!this.getParameters().isEmpty()){
for(Parameter pr : this.getParameters()){
try {
pr.validate();
}catch (Exception e){
throw new Validation("ATTACH parameter validation failed: " + pr.getValue());
}
}
super.validate();
try {
super.validateValueType(PropertyValueType.URI);
}catch (Exception e){
super.validateValueType(PropertyValueType.BINARY);
}
}
}
@@ -7,32 +7,18 @@
import edu.itu.cavabunga.exception.Validation;
import javax.persistence.Entity;
import java.util.List;
@Entity
public class Calscale extends Property {
@Override
public void validate(){
if(this.getValue().trim() != ""){
throw new Validation("CALSCALE property cannot be empty");
}
super.validate();
super.validateValueType(PropertyValueType.TEXT);
//TODO: is cavabunga support only for Gregorian calendar?
if(this.getValue() != "GREGORIAN" ){
throw new Validation("CALSCALE value is different from acceptable value range: " + this.getValue());
}
if(!(this.getComponent() instanceof Calendar)){
throw new Validation("CALSCALE property can only be use in Calendar component");
}
if(!this.getParameters().isEmpty()){
for(Parameter pr : this.getParameters()){
try {
pr.validate();
}catch (Exception e){
throw new Validation("CALENDAR parameter validation failed: " + pr.getValue());
}
}
}
}
}
@@ -11,24 +11,13 @@
public class Class extends Property {
@Override
public void validate(){
if(this.getValue().trim() != ""){
throw new Validation("CLASS property cannot be empty");
}
super.validate();
super.validateValueType(PropertyValueType.TEXT);
if(this.getValue() != "PUBLIC" &&
this.getValue() != "PRIVATE" &&
this.getValue() != "CONFIDENTIAL"){
throw new Validation("CLASS value is different from acceptable value range: " + this.getValue());
}
if(!this.getParameters().isEmpty()){
for(Parameter pr : this.getParameters()){
try {
pr.validate();
}catch (Exception e){
throw new Validation("CLASS parameter validation failed: " + pr.getValue());
}
}
}
}
}
@@ -10,19 +10,7 @@
public class Comment extends Property {
@Override
public void validate(){
if(this.getValue().trim() != ""){
throw new Validation("COMMENT property cannot be empty");
}
if(!this.getParameters().isEmpty()){
for(Parameter pr : this.getParameters()){
try {
pr.validate();
}catch (Exception e){
throw new Validation("COMMENT parameter validation failed: " + pr.getValue());
}
}
}
super.validate();
super.validateValueType(PropertyValueType.TEXT);
}
}
@@ -15,25 +15,7 @@
public class Description extends Property {
@Override
public void validate(){
if(this.getValue().trim() != ""){
throw new Validation("DESCRIPTION property cannot be empty");
}
if (!(this.getComponent() instanceof Event ||
this.getComponent() instanceof Todo ||
this.getComponent() instanceof Journal ||
this.getComponent() instanceof Alarm)){
throw new Validation("DESCRIPTION property can only use in Event, Todo, Journal or Alarm components");
}
if(!this.getParameters().isEmpty()){
for(Parameter pr : this.getParameters()){
try {
pr.validate();
}catch (Exception e){
throw new Validation("DESCRIPTION parameter validation failed: " + this.getValue());
}
}
}
super.validate();
super.validateValueType(PropertyValueType.TEXT);
}
}
@@ -6,4 +6,9 @@
@Entity
public class Geo extends Property {
@Override
public void validate(){
super.validate();
super.validateValueType(PropertyValueType.FLOAT);
}
}
@@ -6,4 +6,9 @@
@Entity
public class Location extends Property {
@Override
public void validate(){
super.validate();
super.validateValueType(PropertyValueType.TEXT);
}
}
@@ -6,4 +6,9 @@
@Entity
public class Method extends Property {
@Override
public void validate(){
super.validate();
super.validateValueType(PropertyValueType.TEXT);
}
}
Oops, something went wrong.

0 comments on commit ae7df01

Please sign in to comment.