156 lines
3.4 KiB
Java
156 lines
3.4 KiB
Java
package org.gcube.informationsystem.service.dto;
|
|
|
|
import java.util.ArrayDeque;
|
|
import java.util.ArrayList;
|
|
import java.util.HashSet;
|
|
import java.util.Iterator;
|
|
import java.util.LinkedList;
|
|
import java.util.List;
|
|
import java.util.Queue;
|
|
import java.util.Set;
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
//descrive una facet che concorre a comporre un oggetto
|
|
|
|
public class FacetPropertyDTO {
|
|
|
|
private static final Logger log = LoggerFactory.getLogger(FacetPropertyDTO.class);
|
|
private String type;
|
|
private String name;
|
|
private String description;
|
|
//per validazione
|
|
private boolean mandatory;
|
|
private boolean notnull;
|
|
private String regexp;
|
|
private String propertyType;
|
|
|
|
|
|
public String getType() {
|
|
return type;
|
|
}
|
|
public void setType(String type) {
|
|
this.type = type;
|
|
}
|
|
public String getName() {
|
|
return name;
|
|
}
|
|
public void setName(String name) {
|
|
this.name = name;
|
|
}
|
|
public String getDescription() {
|
|
return description;
|
|
}
|
|
public void setDescription(String description) {
|
|
this.description = description;
|
|
}
|
|
public boolean isMandatory() {
|
|
return mandatory;
|
|
}
|
|
public void setMandatory(boolean mandatory) {
|
|
this.mandatory = mandatory;
|
|
}
|
|
public boolean isNotnull() {
|
|
return notnull;
|
|
}
|
|
public void setNotnull(boolean notnull) {
|
|
this.notnull = notnull;
|
|
}
|
|
public String getRegexp() {
|
|
return regexp;
|
|
}
|
|
public void setRegexp(String regexp) {
|
|
this.regexp = regexp;
|
|
}
|
|
public String getPropertyType() {
|
|
return propertyType;
|
|
}
|
|
public void setPropertyType(String propertyType) {
|
|
this.propertyType = propertyType;
|
|
}
|
|
|
|
public FacetPropGui toFacetPropGui() {
|
|
FacetPropGui prop = new FacetPropGui();
|
|
//TODO: vedi dove mettere description nella GUI
|
|
prop.setPropDescription(this.getDescription());
|
|
prop.setName(this.getName());
|
|
prop.setLabel(StringUtils.capitalize(this.getName()));
|
|
prop.setValue("");
|
|
prop.setPattern(this.getRegexp());
|
|
|
|
String tmp = "text";
|
|
switch(this.getPropertyType()) {
|
|
case "Boolean": tmp="boolean";
|
|
break;
|
|
case "Date": tmp="date";
|
|
break;
|
|
case "String": tmp="text";
|
|
break;
|
|
case "Long": tmp="number";
|
|
break;
|
|
case "Integer": tmp="number";
|
|
break;
|
|
}
|
|
prop.setType(tmp);
|
|
|
|
ValidationObjDTO val = new ValidationObjDTO();
|
|
///////
|
|
val.setMessage(tmp);
|
|
val.setName(tmp);
|
|
val.setValidator(tmp);
|
|
|
|
|
|
ArrayList<ValidationObjDTO> validations = new ArrayList<ValidationObjDTO>();
|
|
|
|
|
|
if(this.isMandatory()) {
|
|
ValidationObjDTO vv = new ValidationObjDTO();
|
|
vv.setMessage("The field is required");
|
|
vv.setName("required");
|
|
vv.setValidator("required");
|
|
validations.add(vv);
|
|
}
|
|
//check if notnull is ok here
|
|
if(!this.isMandatory() && this.isNotnull()) {
|
|
ValidationObjDTO vv = new ValidationObjDTO();
|
|
vv.setMessage("The field cannot be empty");
|
|
vv.setName("notnull");
|
|
vv.setValidator("required");
|
|
validations.add(vv);
|
|
}
|
|
|
|
if(StringUtils.isNotEmpty(this.getRegexp())) {
|
|
ValidationObjDTO vv = new ValidationObjDTO();
|
|
vv.setMessage("Wrong field format, required is: "+this.getRegexp());
|
|
vv.setName("pattern");
|
|
vv.setValidator("pattern");
|
|
validations.add(vv);
|
|
}
|
|
prop.setValidations(validations);
|
|
return prop;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
"validations": [
|
|
{
|
|
"name": "required",
|
|
"validator": "required",
|
|
"message": "Email is required"
|
|
},
|
|
{
|
|
"name": "pattern",
|
|
"validator": "email",
|
|
"message": "Invalid email format"
|
|
}
|
|
]
|
|
*/
|
|
|
|
//<input name="firstName" ngModel pattern="[a-zA-Z ]*">
|
|
|