package org.gcube.application.geoportal.common.model.useCaseDescriptor; import lombok.*; import org.bson.Document; import org.bson.types.MaxKey; import javax.xml.bind.annotation.XmlRootElement; import java.util.HashMap; import java.util.List; import java.util.Map; @XmlRootElement @AllArgsConstructor @Getter @Setter @ToString(callSuper = true) public class Field extends Document { public static final String TYPE="_type"; public static final String CHILDREN="_children"; public static final String MAX_CARDINALITY="_max"; public static final String MIN_CARDINALITY="_min"; public static final String LABEL="_label"; public String getLabel(){ return this.getString(LABEL); } public String getType(){ return this.getString(TYPE); }; public Boolean isLeaf(){ List children = getChildren(); return children == null || children.isEmpty() || children.get(0)==null; } public List getChildren(){ return this.get(CHILDREN,List.class); } public Boolean isCollection() { Integer maxCard=this.getMaxCardinality(); return (maxCard>1||maxCard<0); // Negative values for unbounded } public Integer getMaxCardinality(){ return (Integer) this.getOrDefault(MAX_CARDINALITY,1); } public Integer getMinCardinality(){ return (Integer) this.getOrDefault(MIN_CARDINALITY,0); } public Boolean isMandatory(){ return getMinCardinality()==0; } }