2022-03-04 14:23:20 +01:00
|
|
|
package org.gcube.application.geoportal.common.model.useCaseDescriptor;
|
2022-01-17 18:19:40 +01:00
|
|
|
|
2023-04-18 10:33:22 +02:00
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import javax.xml.bind.annotation.XmlRootElement;
|
|
|
|
|
|
|
|
import org.bson.Document;
|
|
|
|
|
2022-03-07 17:59:06 +01:00
|
|
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
2023-04-18 10:33:22 +02:00
|
|
|
|
2022-09-26 16:17:37 +02:00
|
|
|
import lombok.AllArgsConstructor;
|
|
|
|
import lombok.Getter;
|
|
|
|
import lombok.Setter;
|
|
|
|
import lombok.ToString;
|
2022-01-17 18:19:40 +01:00
|
|
|
|
2022-01-31 13:09:54 +01:00
|
|
|
@XmlRootElement
|
|
|
|
@AllArgsConstructor
|
|
|
|
@Getter
|
|
|
|
@Setter
|
|
|
|
@ToString(callSuper = true)
|
2022-03-28 16:35:30 +02:00
|
|
|
public class Field extends Document {
|
2022-01-17 18:19:40 +01:00
|
|
|
|
|
|
|
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-03-07 17:59:06 +01:00
|
|
|
@JsonIgnore
|
2022-01-27 15:02:53 +01:00
|
|
|
public String getLabel(){
|
|
|
|
return this.getString(LABEL);
|
|
|
|
}
|
2022-01-17 18:19:40 +01:00
|
|
|
|
2022-03-07 17:59:06 +01:00
|
|
|
@JsonIgnore
|
2022-01-17 18:19:40 +01:00
|
|
|
public String getType(){
|
|
|
|
return this.getString(TYPE);
|
|
|
|
};
|
|
|
|
|
2022-03-07 17:59:06 +01:00
|
|
|
@JsonIgnore
|
2022-02-24 18:09:30 +01:00
|
|
|
public Boolean isLeaf(){
|
|
|
|
List children = getChildren();
|
|
|
|
return children == null || children.isEmpty() || children.get(0)==null;
|
|
|
|
}
|
|
|
|
|
2022-03-07 17:59:06 +01:00
|
|
|
@JsonIgnore
|
2022-01-17 18:19:40 +01:00
|
|
|
public List getChildren(){
|
|
|
|
return this.get(CHILDREN,List.class);
|
|
|
|
}
|
|
|
|
|
2022-03-07 17:59:06 +01:00
|
|
|
@JsonIgnore
|
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-03-07 17:59:06 +01:00
|
|
|
@JsonIgnore
|
2022-01-17 18:19:40 +01:00
|
|
|
public Integer getMaxCardinality(){
|
|
|
|
return (Integer) this.getOrDefault(MAX_CARDINALITY,1);
|
|
|
|
}
|
|
|
|
|
2022-03-07 17:59:06 +01:00
|
|
|
@JsonIgnore
|
2022-01-17 18:19:40 +01:00
|
|
|
public Integer getMinCardinality(){
|
|
|
|
return (Integer) this.getOrDefault(MIN_CARDINALITY,0);
|
|
|
|
}
|
2022-03-07 17:59:06 +01:00
|
|
|
@JsonIgnore
|
2022-01-17 18:19:40 +01:00
|
|
|
public Boolean isMandatory(){
|
|
|
|
return getMinCardinality()==0;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|