gcube-cms-suite/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/profile/Field.java

59 lines
1.5 KiB
Java
Raw Normal View History

2022-01-17 18:19:40 +01:00
package org.gcube.application.geoportal.common.model.profile;
2022-01-31 13:09:54 +01:00
import lombok.*;
2022-01-17 18:19:40 +01:00
import org.bson.Document;
2022-01-31 13:09:54 +01:00
import org.bson.types.MaxKey;
2022-01-17 18:19:40 +01:00
2022-01-31 13:09:54 +01:00
import javax.xml.bind.annotation.XmlRootElement;
2022-01-17 18:19:40 +01:00
import java.util.HashMap;
import java.util.List;
import java.util.Map;
2022-01-31 13:09:54 +01:00
@XmlRootElement
@AllArgsConstructor
@Getter
@Setter
@ToString(callSuper = true)
2022-01-17 18:19:40 +01:00
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";
2022-01-27 15:02:53 +01:00
public static final String LABEL="_label";
2022-01-17 18:19:40 +01:00
2022-01-27 15:02:53 +01:00
public String getLabel(){
return this.getString(LABEL);
}
2022-01-17 18:19:40 +01:00
public String getType(){
return this.getString(TYPE);
};
2022-02-24 18:09:30 +01:00
public Boolean isLeaf(){
List children = getChildren();
return children == null || children.isEmpty() || children.get(0)==null;
}
2022-01-17 18:19:40 +01:00
public List getChildren(){
return this.get(CHILDREN,List.class);
}
2022-01-27 15:02:53 +01:00
public Boolean isCollection() {
Integer maxCard=this.getMaxCardinality();
return (maxCard>1||maxCard<0); // Negative values for unbounded
}
2022-01-17 18:19:40 +01:00
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;
}
}