diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/EntityFormDescriptor.java b/src/main/java/edu/stanford/protege/webprotege/forms/EntityFormDescriptor.java index 8fd9bb9..241f52d 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/EntityFormDescriptor.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/EntityFormDescriptor.java @@ -16,44 +16,32 @@ @AutoValue public abstract class EntityFormDescriptor { - - public static final String PROJECT_ID = "projectId"; - - public static final String FORM_ID = "formId"; - - public static final String FORM_DESCRIPTOR = "formDescriptor"; - - public static final String SELECTOR_CRITERIA = "formSelectorCriteria"; - - public static final String PURPOSE = "purpose"; - - @JsonCreator - public static EntityFormDescriptor valueOf(@JsonProperty(PROJECT_ID) @Nonnull ProjectId projectId, - @JsonProperty(FORM_ID) @Nonnull FormId formId, - @JsonProperty(FORM_DESCRIPTOR) @Nonnull FormDescriptor newDescriptor, - @JsonProperty(PURPOSE) @Nonnull FormPurpose purpose, - @JsonProperty(SELECTOR_CRITERIA) @Nonnull RootCriteria newSelectorCriteria) { + public static EntityFormDescriptor valueOf(@JsonProperty(PropertyNames.PROJECT_ID) @Nonnull ProjectId projectId, + @JsonProperty(PropertyNames.FORM_ID) @Nonnull FormId formId, + @JsonProperty(PropertyNames.FORM) @Nonnull FormDescriptor newDescriptor, + @JsonProperty(PropertyNames.PURPOSE) @Nonnull FormPurpose purpose, + @JsonProperty(PropertyNames.CRITERIA) @Nonnull RootCriteria newSelectorCriteria) { return new AutoValue_EntityFormDescriptor(projectId, formId, newDescriptor, purpose, newSelectorCriteria); } @Nonnull - @JsonProperty(PROJECT_ID) + @JsonProperty(PropertyNames.PROJECT_ID) public abstract ProjectId getProjectId(); @Nonnull - @JsonProperty(FORM_ID) + @JsonProperty(PropertyNames.FORM_ID) public abstract FormId getFormId(); @Nonnull - @JsonProperty(FORM_DESCRIPTOR) + @JsonProperty(PropertyNames.FORM) public abstract FormDescriptor getDescriptor(); @Nonnull - @JsonProperty(PURPOSE) + @JsonProperty(PropertyNames.PURPOSE) public abstract FormPurpose getPurpose(); @Nonnull - @JsonProperty(SELECTOR_CRITERIA) + @JsonProperty(PropertyNames.CRITERIA) public abstract RootCriteria getSelectorCriteria(); } diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/EntityFormSelector.java b/src/main/java/edu/stanford/protege/webprotege/forms/EntityFormSelector.java index 7b04d6f..bcadbf3 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/EntityFormSelector.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/EntityFormSelector.java @@ -3,6 +3,7 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import com.google.auto.value.AutoValue; +import com.google.common.annotations.GwtCompatible; import edu.stanford.protege.webprotege.common.ProjectId; import edu.stanford.protege.webprotege.criteria.CompositeRootCriteria; diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/FormDescriptor.java b/src/main/java/edu/stanford/protege/webprotege/forms/FormDescriptor.java index c3321eb..456cdc6 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/FormDescriptor.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/FormDescriptor.java @@ -39,10 +39,10 @@ private FormDescriptor() { } @JsonCreator - public FormDescriptor(@JsonProperty("id") FormId id, - @JsonProperty("label") LanguageMap label, - @JsonProperty("fields") List formFieldDescriptors, - @JsonProperty("subjectFactoryDescriptor") Optional subjectFactoryDescriptor) { + public FormDescriptor(@JsonProperty(PropertyNames.ID) FormId id, + @JsonProperty(PropertyNames.LABEL) LanguageMap label, + @JsonProperty(PropertyNames.FIELDS) List formFieldDescriptors, + @JsonProperty(PropertyNames.SUBJECT_FACTORY) Optional subjectFactoryDescriptor) { this.formId = id; this.label = label; this.elements = new ArrayList<>(formFieldDescriptors); @@ -62,19 +62,23 @@ public FormDescriptor withFields(Predicate test) { return new FormDescriptor(formId, label, filteredFields, getSubjectFactoryDescriptor()); } + @JsonProperty(PropertyNames.ID) public FormId getFormId() { return formId; } + @JsonProperty(PropertyNames.LABEL) public LanguageMap getLabel() { return label; } + @JsonProperty(PropertyNames.SUBJECT_FACTORY) @Nonnull public Optional getSubjectFactoryDescriptor() { return Optional.ofNullable(subjectFactoryDescriptor); } + @JsonProperty(PropertyNames.FIELDS) public List getFields() { return elements; } diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/FormDescriptorDto.java b/src/main/java/edu/stanford/protege/webprotege/forms/FormDescriptorDto.java index f0f090b..2bfdeb9 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/FormDescriptorDto.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/FormDescriptorDto.java @@ -1,7 +1,6 @@ package edu.stanford.protege.webprotege.forms; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.*; import com.google.auto.value.AutoValue; import com.google.common.collect.ImmutableList; import edu.stanford.protege.webprotege.common.LanguageMap; @@ -18,25 +17,30 @@ public abstract class FormDescriptorDto { @JsonCreator - public static FormDescriptorDto get(@JsonProperty("formId") @Nonnull FormId formId, - @JsonProperty("label") @Nonnull LanguageMap label, - @JsonProperty("fields") @Nonnull ImmutableList fields, - @JsonProperty("formSubjectFactoryDescriptor") @Nullable FormSubjectFactoryDescriptor subjectFactoryDescriptor) { + public static FormDescriptorDto get(@JsonProperty(PropertyNames.ID) @Nonnull FormId formId, + @JsonProperty(PropertyNames.LABEL) @Nonnull LanguageMap label, + @JsonProperty(PropertyNames.FIELDS) @Nonnull ImmutableList fields, + @JsonProperty(PropertyNames.SUBJECT_FACTORY) @Nullable FormSubjectFactoryDescriptor subjectFactoryDescriptor) { return new AutoValue_FormDescriptorDto(formId, label, fields, subjectFactoryDescriptor); } + @JsonProperty(PropertyNames.ID) @Nonnull public abstract FormId getFormId(); @Nonnull + @JsonProperty(PropertyNames.LABEL) public abstract LanguageMap getLabel(); @Nonnull + @JsonProperty(PropertyNames.FIELDS) public abstract ImmutableList getFields(); @Nullable + @JsonProperty(PropertyNames.SUBJECT_FACTORY) protected abstract FormSubjectFactoryDescriptor getFormSubjectFactoryDescriptorInternal(); + @JsonIgnore public Optional getFormSubjectFactoryDescriptor() { return Optional.ofNullable(getFormSubjectFactoryDescriptorInternal()); } diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/FormDescriptorRecord.java b/src/main/java/edu/stanford/protege/webprotege/forms/FormDescriptorRecord.java index 9661372..61952b1 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/FormDescriptorRecord.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/FormDescriptorRecord.java @@ -16,32 +16,26 @@ @AutoValue public abstract class FormDescriptorRecord implements Comparable { - public static final String PROJECT_ID = "projectId"; - - public static final String FORM_DESCRIPTOR = "formDescriptor"; - - public static final String ORDINAL = "ordinal"; - private static final Comparator comparingByOrdinal = Comparator.comparing(FormDescriptorRecord::getOrdinal); @JsonCreator - public static FormDescriptorRecord get(@JsonProperty(PROJECT_ID) @Nonnull ProjectId projectId, - @JsonProperty(FORM_DESCRIPTOR) FormDescriptor formDescriptor, - @JsonProperty(ORDINAL) Integer ordinal) { + public static FormDescriptorRecord get(@JsonProperty(PropertyNames.PROJECT_ID) @Nonnull ProjectId projectId, + @JsonProperty(PropertyNames.FORM) FormDescriptor formDescriptor, + @JsonProperty(PropertyNames.ORDINAL) Integer ordinal) { return new AutoValue_FormDescriptorRecord(projectId, formDescriptor == null ? FormDescriptor.empty(FormId.generate()) : formDescriptor, ordinal == null ? 0 : ordinal); } - @JsonProperty(PROJECT_ID) + @JsonProperty(PropertyNames.PROJECT_ID) @Nonnull public abstract ProjectId getProjectId(); - @JsonProperty(FORM_DESCRIPTOR) + @JsonProperty(PropertyNames.FORM) @Nonnull public abstract FormDescriptor getFormDescriptor(); - @JsonProperty(ORDINAL) + @JsonProperty(PropertyNames.ORDINAL) @Nonnull public abstract Integer getOrdinal(); diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/FormGroup.java b/src/main/java/edu/stanford/protege/webprotege/forms/FormGroup.java index d3f3063..9baf3c0 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/FormGroup.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/FormGroup.java @@ -16,29 +16,23 @@ public abstract class FormGroup { - public static final String ID = "id"; - - public static final String DESCRIPTION = "description"; - - public static final String FORM_IDS = "formIds"; - @JsonCreator @Nonnull - public static FormGroup get(@Nonnull @JsonProperty(ID) FormGroupId formGroupId, - @Nonnull @JsonProperty(DESCRIPTION) String description, - @Nonnull @JsonProperty(FORM_IDS) ImmutableList formIds) { + public static FormGroup get(@Nonnull @JsonProperty(PropertyNames.ID) FormGroupId formGroupId, + @Nonnull @JsonProperty(PropertyNames.DESCRIPTION) String description, + @Nonnull @JsonProperty(PropertyNames.FORMS) ImmutableList formIds) { return new AutoValue_FormGroup(formGroupId, description, formIds); } - @JsonProperty(ID) + @JsonProperty(PropertyNames.ID) @Nonnull public abstract FormGroupId getId(); - @JsonProperty(DESCRIPTION) + @JsonProperty(PropertyNames.DESCRIPTION) @Nonnull public abstract String getDescription(); - @JsonProperty(FORM_IDS) + @JsonProperty(PropertyNames.FORMS) @Nonnull public abstract ImmutableList getFormIds(); } diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/FormPageRequest.java b/src/main/java/edu/stanford/protege/webprotege/forms/FormPageRequest.java index fb2362e..6d0055a 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/FormPageRequest.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/FormPageRequest.java @@ -16,21 +16,21 @@ * 2020-04-22 */ @JsonTypeName("FormPageRequest") -public record FormPageRequest(FormId formId, - FormSubject subject, - FormRegionId regionId, - SourceType sourceType, - PageRequest pageRequest) { +public record FormPageRequest(@JsonProperty(PropertyNames.FORM_ID) FormId formId, + @JsonProperty(PropertyNames.SUBJECT) FormSubject subject, + @JsonProperty(PropertyNames.REGION_ID) FormRegionId regionId, + @JsonProperty(PropertyNames.SOURCE_TYPE) SourceType sourceType, + @JsonProperty(PropertyNames.PAGE_REQUEST) PageRequest pageRequest) { public static final int DEFAULT_PAGE_SIZE = 10; @JsonCreator @Nonnull - public static FormPageRequest get(@JsonProperty("formId") @Nonnull FormId formId, - @JsonProperty("subject") @Nonnull FormSubject subject, - @JsonProperty("regionId") @Nonnull FormRegionId formFieldId, - @JsonProperty("sourceType") @Nonnull SourceType sourceType, - @JsonProperty("pageRequest") @Nonnull PageRequest pageRequest) { + public static FormPageRequest get(@JsonProperty(PropertyNames.FORM_ID) @Nonnull FormId formId, + @JsonProperty(PropertyNames.SUBJECT) @Nonnull FormSubject subject, + @JsonProperty(PropertyNames.REGION_ID) @Nonnull FormRegionId formFieldId, + @JsonProperty(PropertyNames.SOURCE_TYPE) @Nonnull SourceType sourceType, + @JsonProperty(PropertyNames.PAGE_REQUEST) @Nonnull PageRequest pageRequest) { return new FormPageRequest(formId, subject, formFieldId, sourceType, pageRequest); } diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/FormRegionPageRequest.java b/src/main/java/edu/stanford/protege/webprotege/forms/FormRegionPageRequest.java index 950a705..ee7c10d 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/FormRegionPageRequest.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/FormRegionPageRequest.java @@ -1,5 +1,6 @@ package edu.stanford.protege.webprotege.forms; +import com.fasterxml.jackson.annotation.JsonProperty; import com.google.auto.value.AutoValue; import edu.stanford.protege.webprotege.common.PageRequest; import edu.stanford.protege.webprotege.forms.data.FormSubject; @@ -16,22 +17,26 @@ public abstract class FormRegionPageRequest { @Nonnull - public static FormRegionPageRequest get(@Nonnull FormSubject subject, - @Nonnull FormRegionId formRegionId, - @Nonnull FormPageRequest.SourceType sourceType, - @Nonnull PageRequest pageRequest) { + public static FormRegionPageRequest get(@JsonProperty(PropertyNames.SUBJECT) @Nonnull FormSubject subject, + @JsonProperty(PropertyNames.REGION_ID) @Nonnull FormRegionId formRegionId, + @JsonProperty(PropertyNames.SOURCE_TYPE) @Nonnull FormPageRequest.SourceType sourceType, + @JsonProperty(PropertyNames.PAGE_REQUEST) @Nonnull PageRequest pageRequest) { return new AutoValue_FormRegionPageRequest(subject, formRegionId, sourceType, pageRequest); } @Nonnull + @JsonProperty(PropertyNames.SUBJECT) public abstract FormSubject getSubject(); @Nonnull + @JsonProperty(PropertyNames.REGION_ID) public abstract FormRegionId getFieldId(); @Nonnull + @JsonProperty(PropertyNames.SOURCE_TYPE) public abstract FormPageRequest.SourceType getSourceType(); @Nonnull + @JsonProperty(PropertyNames.PAGE_REQUEST) public abstract PageRequest getPageRequest(); } diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/FormSubjectFactoryDescriptor.java b/src/main/java/edu/stanford/protege/webprotege/forms/FormSubjectFactoryDescriptor.java index 942ba95..8ee6de0 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/FormSubjectFactoryDescriptor.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/FormSubjectFactoryDescriptor.java @@ -22,9 +22,9 @@ public abstract class FormSubjectFactoryDescriptor { @JsonCreator - public static FormSubjectFactoryDescriptor get(@Nonnull @JsonProperty("entityType") EntityType entityType, - @Nullable @JsonProperty("parent") OWLClass parent, - @Nonnull @JsonProperty("targetOntologyIri") Optional targetOntologyIri) { + public static FormSubjectFactoryDescriptor get(@Nonnull @JsonProperty(PropertyNames.ENTITY_TYPE) EntityType entityType, + @Nullable @JsonProperty(PropertyNames.PARENT) OWLClass parent, + @Nonnull @JsonProperty(PropertyNames.TARGET_ONTOLOGY_IRI) Optional targetOntologyIri) { return new AutoValue_FormSubjectFactoryDescriptor(entityType, parent, targetOntologyIri.orElse(null)); } @@ -33,6 +33,7 @@ public static String getDefaultGeneratedNamePattern() { } @Nonnull + @JsonProperty("entityType") public abstract EntityType getEntityType(); /** @@ -45,14 +46,16 @@ public Optional getParent() { return Optional.ofNullable(getParentInternal()); } - @JsonProperty("parent") + @JsonProperty(PropertyNames.PARENT) @Nullable protected abstract OWLClass getParentInternal(); @Nullable + @JsonProperty(PropertyNames.TARGET_ONTOLOGY_IRI) protected abstract IRI getTargetOntologyIriInternal(); @Nonnull + @JsonIgnore public Optional getTargetOntologyIri() { return Optional.ofNullable(getTargetOntologyIriInternal()); } diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/PropertyNames.java b/src/main/java/edu/stanford/protege/webprotege/forms/PropertyNames.java new file mode 100644 index 0000000..eebc5df --- /dev/null +++ b/src/main/java/edu/stanford/protege/webprotege/forms/PropertyNames.java @@ -0,0 +1,137 @@ +package edu.stanford.protege.webprotege.forms; + +/** + * Matthew Horridge + * Stanford Center for Biomedical Informatics Research + * 2024-06-18 + */ +public interface PropertyNames { + +// String DESCRIPTOR = "descriptor"; + + String CONTROL = "control"; + + String CRITERIA = "criteria"; + + String MATCH_TYPE = "matchType"; + + String ENTITY = "entity"; + + String DEPTH = "depth"; + + String SUBJECT = "subject"; + + String REGION_ID = "regionId"; + + String COLUMN_ID = "columnId"; + + String VALUES = "values"; + + String FILTER_STATE = "filterState"; + + String ROWS = "rows"; + + String ORDERING = "ordering"; + + String CELLS = "cells"; + + String IRI = "iri"; + + String LITERAL = "literal"; + + String VALUE = "value"; + + String CHOICE = "choice"; + + String LABEL = "label"; + + String PLACEHOLDER = "placeholder"; + + String CHOICES = "choices"; + + String ID = "id"; + + String OWL_BINDING = "owlBinding"; + + String FIELD_RUN = "fieldRun"; + + String REPEATABILITY = "repeatability"; + + String OPTIONALITY = "optionality"; + + String READ_ONLY = "readOnly"; + + String INITIAL_EXPANSIONS_STATE = "initialExpansionState"; + + String HELP = "help"; + + String DEPRECATION_STRATEGY = "deprecationStrategy"; + + String DIRECTION = "direction"; + + String COLUMNS = "columns"; + + String SUBJECT_FACTORY = "subjectFactory"; + + String CHOICES_SOURCE = "choicesSource"; + + String FORMAT = "format"; + + String RANGE = "range"; + + String WIDGET_TYPE = "widgetType"; + + String LENGTH = "length"; + + String LOWER_BOUND = "lowerBound"; + + String UPPER_BOUND = "upperBound"; + + String LOWER_BOUND_TYPE = "lowerBoundType"; + + String UPPER_BOUND_TYPE = "upperBoundType"; + + String PROPERTY = "property"; + + String DEFAULT_CHOICE = "defaultChoice"; + + String STRING_TYPE = "stringType"; + + String SPECIFIC_LANG_TAG = "specificLangTag"; + + String LINE_MODE = "lineMode"; + + String PATTERN = "pattern"; + + String PATTERN_VIOLATION_ERROR_MESSAGE = "patternViolationErrorMessage"; + + String PROJECT_ID = "projectId"; + + String FORM_ID = "formId"; + + String PURPOSE = "purpose"; + + String FIELDS = "fields"; + + String ORDINAL = "ordinal"; + + String DESCRIPTION = "description"; + + String FORMS = "forms"; + + String SOURCE_TYPE = "sourceType"; + + String PAGE_REQUEST = "pageRequest"; + + String ENTITY_TYPE = "entityType"; + + String PARENT = "parent"; + + String TARGET_ONTOLOGY_IRI = "targetOntologyIri"; + + String FORM = "form"; + + String CONTROL_DATA = "controlData"; + + String FIELD = "field"; +} diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/WebprotegeFormsApiApplication.java b/src/main/java/edu/stanford/protege/webprotege/forms/WebprotegeFormsApiApplication.java index b9e416a..3e6535e 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/WebprotegeFormsApiApplication.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/WebprotegeFormsApiApplication.java @@ -1,13 +1,15 @@ package edu.stanford.protege.webprotege.forms; +import edu.stanford.protege.webprotege.jackson.WebProtegeJacksonApplication; import org.semanticweb.owlapi.model.OWLDataFactory; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.*; import uk.ac.manchester.cs.owl.owlapi.OWLDataFactoryImpl; @SpringBootApplication +//@Import(WebProtegeJacksonApplication.class) public class WebprotegeFormsApiApplication { public static void main(String[] args) { diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/data/CompositePrimitiveFormControlDataMatchCriteria.java b/src/main/java/edu/stanford/protege/webprotege/forms/data/CompositePrimitiveFormControlDataMatchCriteria.java index 78c73cd..b1c9d30 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/data/CompositePrimitiveFormControlDataMatchCriteria.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/data/CompositePrimitiveFormControlDataMatchCriteria.java @@ -1,8 +1,11 @@ package edu.stanford.protege.webprotege.forms.data; +import com.fasterxml.jackson.annotation.*; import com.google.auto.value.AutoValue; +import com.google.common.annotations.GwtCompatible; import com.google.common.collect.ImmutableList; import edu.stanford.protege.webprotege.criteria.MultiMatchType; +import edu.stanford.protege.webprotege.forms.PropertyNames; import javax.annotation.Nonnull; @@ -12,18 +15,20 @@ * 2020-06-16 */ @AutoValue - public abstract class CompositePrimitiveFormControlDataMatchCriteria implements PrimitiveFormControlDataMatchCriteria { + @JsonCreator @Nonnull - public static CompositePrimitiveFormControlDataMatchCriteria get(@Nonnull ImmutableList criteria, - @Nonnull MultiMatchType matchType) { + public static CompositePrimitiveFormControlDataMatchCriteria get(@JsonProperty(PropertyNames.CRITERIA) @Nonnull ImmutableList criteria, + @JsonProperty(PropertyNames.MATCH_TYPE) @Nonnull MultiMatchType matchType) { return new AutoValue_CompositePrimitiveFormControlDataMatchCriteria(matchType, ImmutableList.copyOf(criteria)); } + @JsonProperty(PropertyNames.MATCH_TYPE) @Nonnull public abstract MultiMatchType getMultiMatchType(); + @JsonProperty(PropertyNames.CRITERIA) @Nonnull public abstract ImmutableList getCriteria(); diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/data/EntityFormControlData.java b/src/main/java/edu/stanford/protege/webprotege/forms/data/EntityFormControlData.java index 1c1a0b0..b8f71e8 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/data/EntityFormControlData.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/data/EntityFormControlData.java @@ -1,7 +1,8 @@ package edu.stanford.protege.webprotege.forms.data; -import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.annotation.*; import com.google.auto.value.AutoValue; +import com.google.common.annotations.GwtCompatible; import org.semanticweb.owlapi.model.IRI; import org.semanticweb.owlapi.model.OWLEntity; import org.semanticweb.owlapi.model.OWLLiteral; @@ -16,9 +17,9 @@ * 2019-11-30 */ @AutoValue - public abstract class EntityFormControlData implements PrimitiveFormControlData { + @JsonCreator public static EntityFormControlData get(@Nonnull OWLEntity entity) { return new AutoValue_EntityFormControlData(entity); } @@ -45,6 +46,7 @@ public Optional asLiteral() { return Optional.empty(); } + @JsonIgnore @Nonnull @Override public OWLPrimitive getPrimitive() { diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/data/EntityFormControlDataDto.java b/src/main/java/edu/stanford/protege/webprotege/forms/data/EntityFormControlDataDto.java index 0a41b14..4c3ef37 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/data/EntityFormControlDataDto.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/data/EntityFormControlDataDto.java @@ -1,26 +1,26 @@ package edu.stanford.protege.webprotege.forms.data; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonTypeName; +import com.fasterxml.jackson.annotation.*; import com.google.auto.value.AutoValue; +import com.google.common.annotations.GwtCompatible; import edu.stanford.protege.webprotege.entity.OWLEntityData; import edu.stanford.protege.webprotege.entity.OWLPrimitiveData; +import edu.stanford.protege.webprotege.forms.PropertyNames; import org.semanticweb.owlapi.model.OWLLiteral; import javax.annotation.Nonnull; import java.util.Optional; @AutoValue - @JsonTypeName("EntityFormControlDataDto") public abstract class EntityFormControlDataDto extends PrimitiveFormControlDataDto { @JsonCreator - public static EntityFormControlDataDto get(@JsonProperty("term") @Nonnull OWLEntityData entityData) { + public static EntityFormControlDataDto get(@JsonProperty(PropertyNames.ENTITY) @Nonnull OWLEntityData entityData) { return new AutoValue_EntityFormControlDataDto(entityData); } + @JsonProperty(PropertyNames.ENTITY) @Nonnull public abstract OWLEntityData getEntity(); @@ -41,6 +41,7 @@ public boolean isDeprecated() { return getEntity().isDeprecated(); } + @JsonIgnore @Nonnull @Override public OWLPrimitiveData getPrimitiveData() { diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/data/EntityFormControlDataMatchCriteria.java b/src/main/java/edu/stanford/protege/webprotege/forms/data/EntityFormControlDataMatchCriteria.java index 5de59a0..7f161be 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/data/EntityFormControlDataMatchCriteria.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/data/EntityFormControlDataMatchCriteria.java @@ -1,8 +1,10 @@ package edu.stanford.protege.webprotege.forms.data; -import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.*; import com.google.auto.value.AutoValue; +import com.google.common.annotations.GwtCompatible; import edu.stanford.protege.webprotege.criteria.EntityMatchCriteria; +import edu.stanford.protege.webprotege.forms.PropertyNames; import javax.annotation.Nonnull; @@ -12,16 +14,14 @@ * 2020-06-16 */ @AutoValue - public abstract class EntityFormControlDataMatchCriteria implements PrimitiveFormControlDataMatchCriteria { - public static final String ENTITY_MATCHES = "entityMatches"; - - public static EntityFormControlDataMatchCriteria get(@Nonnull EntityMatchCriteria entityMatchCriteria) { + @JsonCreator + public static EntityFormControlDataMatchCriteria get(@JsonProperty(PropertyNames.CRITERIA) @Nonnull EntityMatchCriteria entityMatchCriteria) { return new AutoValue_EntityFormControlDataMatchCriteria(entityMatchCriteria); } - @JsonProperty(ENTITY_MATCHES) + @JsonProperty(PropertyNames.CRITERIA) public abstract EntityMatchCriteria getEntityMatchCriteria(); @Override diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/data/EntityNameControlData.java b/src/main/java/edu/stanford/protege/webprotege/forms/data/EntityNameControlData.java index 2f04a2a..7dfaea6 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/data/EntityNameControlData.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/data/EntityNameControlData.java @@ -4,7 +4,10 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonTypeName; +import com.fasterxml.jackson.databind.PropertyName; import com.google.auto.value.AutoValue; +import com.google.common.annotations.GwtCompatible; +import edu.stanford.protege.webprotege.forms.PropertyNames; import edu.stanford.protege.webprotege.forms.field.EntityNameControlDescriptor; import org.semanticweb.owlapi.model.OWLEntity; @@ -18,13 +21,12 @@ * 2020-01-08 */ @AutoValue - @JsonTypeName("EntityNameControlData") public abstract class EntityNameControlData implements FormControlData { @JsonCreator - public static EntityNameControlData get(@JsonProperty("descriptor") @Nonnull EntityNameControlDescriptor descriptor, - @JsonProperty("term") @Nullable OWLEntity entity) { + public static EntityNameControlData get(@JsonProperty(PropertyNames.CONTROL) @Nonnull EntityNameControlDescriptor descriptor, + @JsonProperty(PropertyNames.ENTITY) @Nullable OWLEntity entity) { return new AutoValue_EntityNameControlData(descriptor, entity); } @@ -38,11 +40,12 @@ public void accept(@Nonnull FormControlDataVisitor visitor) { visitor.visit(this); } + @JsonProperty(PropertyNames.CONTROL) @Nonnull public abstract EntityNameControlDescriptor getDescriptor(); @Nullable - @JsonProperty("term") + @JsonProperty(PropertyNames.ENTITY) protected abstract OWLEntity getEntityInternal(); @JsonIgnore diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/data/EntityNameControlDataDto.java b/src/main/java/edu/stanford/protege/webprotege/forms/data/EntityNameControlDataDto.java index 608eb7b..e23139b 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/data/EntityNameControlDataDto.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/data/EntityNameControlDataDto.java @@ -5,7 +5,9 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonTypeName; import com.google.auto.value.AutoValue; +import com.google.common.annotations.GwtCompatible; import edu.stanford.protege.webprotege.entity.OWLEntityData; +import edu.stanford.protege.webprotege.forms.PropertyNames; import edu.stanford.protege.webprotege.forms.field.EntityNameControlDescriptor; import javax.annotation.Nonnull; @@ -13,23 +15,22 @@ import java.util.Optional; @AutoValue - @JsonTypeName("EntityNameControlDataDto") public abstract class EntityNameControlDataDto implements FormControlDataDto { @JsonCreator - public static EntityNameControlDataDto get(@JsonProperty("descriptor") @Nonnull EntityNameControlDescriptor descriptor, - @JsonProperty("entity") @Nonnull OWLEntityData entityData, - @JsonProperty("depth") int depth) { + public static EntityNameControlDataDto get(@JsonProperty(PropertyNames.CONTROL) @Nonnull EntityNameControlDescriptor descriptor, + @JsonProperty(PropertyNames.ENTITY) @Nonnull OWLEntityData entityData, + @JsonProperty(PropertyNames.DEPTH) int depth) { return new AutoValue_EntityNameControlDataDto(depth, descriptor, entityData); } - @JsonProperty("descriptor") + @JsonProperty(PropertyNames.CONTROL) @Nonnull public abstract EntityNameControlDescriptor getDescriptor(); @Nullable - @JsonProperty("entity") + @JsonProperty(PropertyNames.ENTITY) protected abstract OWLEntityData getEntityInternal(); @JsonIgnore diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/data/FormControlDataDto.java b/src/main/java/edu/stanford/protege/webprotege/forms/data/FormControlDataDto.java index f5089fb..c9d3fd2 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/data/FormControlDataDto.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/data/FormControlDataDto.java @@ -1,8 +1,8 @@ package edu.stanford.protege.webprotege.forms.data; -import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.*; import com.fasterxml.jackson.annotation.JsonSubTypes.Type; -import com.fasterxml.jackson.annotation.JsonTypeInfo; +import edu.stanford.protege.webprotege.forms.PropertyNames; import javax.annotation.Nonnull; @@ -15,5 +15,6 @@ public interface FormControlDataDto { @Nonnull FormControlData toFormControlData(); + @JsonProperty(PropertyNames.DEPTH) int getDepth(); } diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/data/FormData.java b/src/main/java/edu/stanford/protege/webprotege/forms/data/FormData.java index bb5378f..4553458 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/data/FormData.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/data/FormData.java @@ -6,8 +6,7 @@ import com.fasterxml.jackson.annotation.JsonTypeName; import com.google.auto.value.AutoValue; import com.google.common.collect.ImmutableList; -import edu.stanford.protege.webprotege.forms.FormDescriptor; -import edu.stanford.protege.webprotege.forms.FormId; +import edu.stanford.protege.webprotege.forms.*; import org.semanticweb.owlapi.model.OWLEntity; import javax.annotation.Nonnull; @@ -25,9 +24,9 @@ public abstract class FormData implements FormControlData { @JsonCreator - public static FormData get(@JsonProperty("subject") @Nonnull Optional subject, - @JsonProperty("formDescriptor") @Nonnull FormDescriptor formDescriptor, - @JsonProperty("formFieldData") @Nonnull ImmutableList formFieldData) { + public static FormData get(@JsonProperty(PropertyNames.SUBJECT) @Nonnull Optional subject, + @JsonProperty(PropertyNames.FORM) @Nonnull FormDescriptor formDescriptor, + @JsonProperty(PropertyNames.FIELDS) @Nonnull ImmutableList formFieldData) { return new AutoValue_FormData(subject.orElse(null), formDescriptor, formFieldData); } @@ -45,17 +44,20 @@ public void accept(@Nonnull FormControlDataVisitor visitor) { visitor.visit(this); } + @JsonIgnore @Nonnull public Optional getSubject() { return Optional.ofNullable(getSubjectInternal()); } - @JsonIgnore + @JsonProperty(PropertyNames.SUBJECT) @Nullable protected abstract FormEntitySubject getSubjectInternal(); + @JsonProperty(PropertyNames.FORM) public abstract FormDescriptor getFormDescriptor(); + @JsonProperty(PropertyNames.FIELDS) public abstract ImmutableList getFormFieldData(); @Nonnull diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/data/FormDataDto.java b/src/main/java/edu/stanford/protege/webprotege/forms/data/FormDataDto.java index 4bd4feb..004ffc5 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/data/FormDataDto.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/data/FormDataDto.java @@ -7,8 +7,7 @@ import com.google.auto.value.AutoValue; import com.google.common.collect.ImmutableList; import edu.stanford.protege.webprotege.common.Page; -import edu.stanford.protege.webprotege.forms.FormDescriptorDto; -import edu.stanford.protege.webprotege.forms.FormId; +import edu.stanford.protege.webprotege.forms.*; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -17,16 +16,15 @@ import static com.google.common.collect.ImmutableList.toImmutableList; @AutoValue - @JsonTypeName("FormDataDto") public abstract class FormDataDto implements FormControlDataDto { @JsonCreator @Nonnull - public static FormDataDto get(@JsonProperty("subject") @Nonnull FormSubjectDto subject, - @JsonProperty("formDescriptor") @Nonnull FormDescriptorDto formDescriptor, - @JsonProperty("formFieldData") @Nonnull ImmutableList formFieldData, - @JsonProperty("depth") int depth) { + public static FormDataDto get(@JsonProperty(PropertyNames.SUBJECT) @Nonnull FormSubjectDto subject, + @JsonProperty(PropertyNames.FORM) @Nonnull FormDescriptorDto formDescriptor, + @JsonProperty(PropertyNames.FIELDS) @Nonnull ImmutableList formFieldData, + @JsonProperty(PropertyNames.DEPTH) int depth) { return new AutoValue_FormDataDto(depth, subject, formDescriptor, formFieldData); } @@ -59,17 +57,20 @@ public static FormDataDto get(@Nonnull FormDescriptorDto formDescriptor, return new AutoValue_FormDataDto(depth, null, formDescriptor, formFieldData); } + @JsonIgnore @Nonnull public Optional getSubject() { return Optional.ofNullable(getSubjectInternal()); } - @JsonIgnore + @JsonProperty(PropertyNames.SUBJECT) @Nullable protected abstract FormSubjectDto getSubjectInternal(); + @JsonProperty(PropertyNames.FORM) public abstract FormDescriptorDto getFormDescriptor(); + @JsonProperty(PropertyNames.FIELDS) public abstract ImmutableList getFormFieldData(); @Override @@ -96,6 +97,7 @@ public FormData toFormData() { .collect(toImmutableList())); } + @JsonIgnore @Nonnull public FormId getFormId() { return getFormDescriptor().getFormId(); diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/data/FormEntitySubject.java b/src/main/java/edu/stanford/protege/webprotege/forms/data/FormEntitySubject.java index 573528b..3dddbdf 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/data/FormEntitySubject.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/data/FormEntitySubject.java @@ -1,9 +1,8 @@ package edu.stanford.protege.webprotege.forms.data; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonTypeName; +import com.fasterxml.jackson.annotation.*; import com.google.auto.value.AutoValue; +import edu.stanford.protege.webprotege.forms.PropertyNames; import org.semanticweb.owlapi.model.IRI; import org.semanticweb.owlapi.model.OWLEntity; @@ -20,13 +19,15 @@ public abstract class FormEntitySubject implements FormSubject { @JsonCreator - public static FormEntitySubject get(@JsonProperty("entity") @Nonnull OWLEntity entity) { + public static FormEntitySubject get(@JsonProperty(PropertyNames.ENTITY) @Nonnull OWLEntity entity) { return new AutoValue_FormEntitySubject(entity); } + @JsonProperty(PropertyNames.ENTITY) @Nonnull public abstract OWLEntity getEntity(); + @JsonIgnore @Nonnull @Override public IRI getIri() { diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/data/FormEntitySubjectDto.java b/src/main/java/edu/stanford/protege/webprotege/forms/data/FormEntitySubjectDto.java index 0cc6168..9348e71 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/data/FormEntitySubjectDto.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/data/FormEntitySubjectDto.java @@ -7,6 +7,7 @@ import com.google.auto.value.AutoValue; import com.google.auto.value.extension.memoized.Memoized; import edu.stanford.protege.webprotege.entity.OWLEntityData; +import edu.stanford.protege.webprotege.forms.PropertyNames; import org.semanticweb.owlapi.model.IRI; import javax.annotation.Nonnull; @@ -18,11 +19,11 @@ public abstract class FormEntitySubjectDto extends FormSubjectDto { @JsonCreator @Nonnull - public static FormEntitySubjectDto get(@JsonProperty("entityData") @Nonnull OWLEntityData entityData) { + public static FormEntitySubjectDto get(@JsonProperty(PropertyNames.ENTITY) @Nonnull OWLEntityData entityData) { return new AutoValue_FormEntitySubjectDto(entityData); } - + @JsonProperty(PropertyNames.ENTITY) @Nonnull public abstract OWLEntityData getEntityData(); diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/data/FormFieldData.java b/src/main/java/edu/stanford/protege/webprotege/forms/data/FormFieldData.java index 869bd53..295ef14 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/data/FormFieldData.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/data/FormFieldData.java @@ -1,9 +1,9 @@ package edu.stanford.protege.webprotege.forms.data; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.*; import com.google.auto.value.AutoValue; import edu.stanford.protege.webprotege.common.Page; +import edu.stanford.protege.webprotege.forms.PropertyNames; import edu.stanford.protege.webprotege.forms.field.FormFieldDescriptor; import javax.annotation.Nonnull; @@ -18,24 +18,28 @@ public abstract class FormFieldData { @JsonCreator - public static FormFieldData get(@JsonProperty("descriptor") @Nonnull FormFieldDescriptor descriptor, - @JsonProperty("formControlData") @Nonnull Page formControlData) { + public static FormFieldData get(@JsonProperty(PropertyNames.FIELD) @Nonnull FormFieldDescriptor descriptor, + @JsonProperty(PropertyNames.CONTROL_DATA) @Nonnull Page formControlData) { return new AutoValue_FormFieldData(descriptor, formControlData); } @Nonnull + @JsonProperty(PropertyNames.FIELD) public abstract FormFieldDescriptor getFormFieldDescriptor(); /** * Gets the page of form control values for this field. */ @Nonnull + @JsonPropertyOrder(PropertyNames.CONTROL_DATA) public abstract Page getFormControlData(); + @JsonIgnore public boolean isEmpty() { return getFormControlData().getPageElements().isEmpty(); } + @JsonIgnore public boolean isNonEmpty() { return !isEmpty(); } diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/data/FormFieldDataDto.java b/src/main/java/edu/stanford/protege/webprotege/forms/data/FormFieldDataDto.java index 5b6d26f..635fb88 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/data/FormFieldDataDto.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/data/FormFieldDataDto.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.google.auto.value.AutoValue; import edu.stanford.protege.webprotege.common.Page; +import edu.stanford.protege.webprotege.forms.PropertyNames; import edu.stanford.protege.webprotege.forms.field.FormFieldDescriptorDto; import javax.annotation.Nonnull; @@ -15,11 +16,12 @@ public abstract class FormFieldDataDto { @JsonCreator @Nonnull - public static FormFieldDataDto get(@JsonProperty("formFieldDescriptor") @Nonnull FormFieldDescriptorDto descriptor, - @JsonProperty("formControlData") @Nonnull Page formControlData) { + public static FormFieldDataDto get(@JsonProperty(PropertyNames.FIELD) @Nonnull FormFieldDescriptorDto descriptor, + @JsonProperty(PropertyNames.CONTROL_DATA) @Nonnull Page formControlData) { return new AutoValue_FormFieldDataDto(descriptor, formControlData); } + @JsonProperty(PropertyNames.FIELD) @Nonnull public abstract FormFieldDescriptorDto getFormFieldDescriptor(); @@ -27,6 +29,7 @@ public static FormFieldDataDto get(@JsonProperty("formFieldDescriptor") @Nonnull * Gets the page of form control values for this field. */ @Nonnull + @JsonProperty(PropertyNames.CONTROL_DATA) public abstract Page getFormControlData(); @Nonnull diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/data/FormRegionFilter.java b/src/main/java/edu/stanford/protege/webprotege/forms/data/FormRegionFilter.java index 49552db..f09f3bb 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/data/FormRegionFilter.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/data/FormRegionFilter.java @@ -1,6 +1,8 @@ package edu.stanford.protege.webprotege.forms.data; +import com.fasterxml.jackson.annotation.*; import com.google.auto.value.AutoValue; +import edu.stanford.protege.webprotege.forms.PropertyNames; import edu.stanford.protege.webprotege.forms.field.FormRegionId; import javax.annotation.Nonnull; @@ -14,15 +16,18 @@ public abstract class FormRegionFilter { + @JsonCreator @Nonnull - public static FormRegionFilter get(@Nonnull FormRegionId formRegionId, - @Nonnull PrimitiveFormControlDataMatchCriteria matchCriteria) { + public static FormRegionFilter get(@JsonProperty(PropertyNames.REGION_ID) @Nonnull FormRegionId formRegionId, + @JsonProperty(PropertyNames.CRITERIA) @Nonnull PrimitiveFormControlDataMatchCriteria matchCriteria) { return new AutoValue_FormRegionFilter(formRegionId, matchCriteria); } + @JsonProperty(PropertyNames.REGION_ID) @Nonnull public abstract FormRegionId getFormRegionId(); + @JsonProperty(PropertyNames.CRITERIA) @Nonnull public abstract PrimitiveFormControlDataMatchCriteria getMatchCriteria(); diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/data/FormSubjectDto.java b/src/main/java/edu/stanford/protege/webprotege/forms/data/FormSubjectDto.java index d743b07..403eb84 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/data/FormSubjectDto.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/data/FormSubjectDto.java @@ -1,9 +1,7 @@ package edu.stanford.protege.webprotege.forms.data; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonSubTypes; -import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.*; import edu.stanford.protege.webprotege.entity.OWLEntityData; import org.semanticweb.owlapi.model.IRI; diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/data/GridCellData.java b/src/main/java/edu/stanford/protege/webprotege/forms/data/GridCellData.java index fc26e07..adbe0ca 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/data/GridCellData.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/data/GridCellData.java @@ -1,7 +1,9 @@ package edu.stanford.protege.webprotege.forms.data; +import com.fasterxml.jackson.annotation.*; import com.google.auto.value.AutoValue; import edu.stanford.protege.webprotege.common.Page; +import edu.stanford.protege.webprotege.forms.PropertyNames; import edu.stanford.protege.webprotege.forms.field.GridColumnId; import org.semanticweb.owlapi.model.OWLEntity; import org.semanticweb.owlapi.model.OWLLiteral; @@ -20,7 +22,9 @@ public abstract class GridCellData { - public static GridCellData get(@Nonnull GridColumnId columnId, @Nullable Page values) { + @JsonCreator + public static GridCellData get(@JsonProperty(PropertyNames.COLUMN_ID) @Nonnull GridColumnId columnId, + @JsonProperty(PropertyNames.VALUES) @Nullable Page values) { return new AutoValue_GridCellData(columnId, values); } @@ -57,9 +61,11 @@ public int compareTo(GridCellData otherCellData) { return 0; } + @JsonProperty(PropertyNames.COLUMN_ID) @Nonnull public abstract GridColumnId getColumnId(); + @JsonProperty(PropertyNames.VALUES) @Nonnull public abstract Page getValues(); } diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/data/GridCellDataDto.java b/src/main/java/edu/stanford/protege/webprotege/forms/data/GridCellDataDto.java index 920e878..41570f2 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/data/GridCellDataDto.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/data/GridCellDataDto.java @@ -1,9 +1,9 @@ package edu.stanford.protege.webprotege.forms.data; +import com.fasterxml.jackson.annotation.*; import com.google.auto.value.AutoValue; import edu.stanford.protege.webprotege.common.Page; -import edu.stanford.protege.webprotege.forms.FilterState; -import edu.stanford.protege.webprotege.forms.HasFilterState; +import edu.stanford.protege.webprotege.forms.*; import edu.stanford.protege.webprotege.forms.field.GridColumnId; import javax.annotation.Nonnull; @@ -13,18 +13,22 @@ public abstract class GridCellDataDto implements HasFilterState { - public static GridCellDataDto get(@Nonnull GridColumnId columnId, - @Nullable Page values, - @Nonnull FilterState filterState) { + @JsonCreator + public static GridCellDataDto get(@JsonProperty(PropertyNames.COLUMN_ID) @Nonnull GridColumnId columnId, + @JsonProperty(PropertyNames.VALUES) @Nullable Page values, + @JsonProperty(PropertyNames.FILTER_STATE) @Nonnull FilterState filterState) { return new AutoValue_GridCellDataDto(columnId, values, filterState); } + @JsonProperty(PropertyNames.COLUMN_ID) @Nonnull public abstract GridColumnId getColumnId(); + @JsonProperty(PropertyNames.COLUMN_ID) @Nonnull public abstract Page getValues(); + @JsonProperty(PropertyNames.COLUMN_ID) @Nonnull @Override public abstract FilterState getFilterState(); @@ -35,6 +39,7 @@ public static GridCellDataDto get(@Nonnull GridColumnId columnId, * @return true if this cel data is filtered empty (all values have been filtered out) * otherwise false. */ + @JsonIgnore public boolean isFilteredEmpty() { return getFilterState().equals(FilterState.FILTERED) && getValues().getPageElements().isEmpty(); } diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/data/GridControlData.java b/src/main/java/edu/stanford/protege/webprotege/forms/data/GridControlData.java index 862d978..5a7bf9d 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/data/GridControlData.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/data/GridControlData.java @@ -1,9 +1,10 @@ package edu.stanford.protege.webprotege.forms.data; -import com.fasterxml.jackson.annotation.JsonTypeName; +import com.fasterxml.jackson.annotation.*; import com.google.auto.value.AutoValue; import com.google.common.collect.ImmutableSet; import edu.stanford.protege.webprotege.common.Page; +import edu.stanford.protege.webprotege.forms.PropertyNames; import edu.stanford.protege.webprotege.forms.field.FormRegionOrdering; import edu.stanford.protege.webprotege.forms.field.GridControlDescriptor; @@ -19,10 +20,11 @@ @JsonTypeName("GridControlData") public abstract class GridControlData implements ComplexFormControlValue { + @JsonCreator @Nonnull - public static GridControlData get(@Nonnull GridControlDescriptor descriptor, - @Nonnull Page rows, - @Nonnull ImmutableSet ordering) { + public static GridControlData get(@JsonProperty(PropertyNames.CONTROL) @Nonnull GridControlDescriptor descriptor, + @JsonProperty(PropertyNames.ROWS) @Nonnull Page rows, + @JsonProperty(PropertyNames.ORDERING) @Nonnull ImmutableSet ordering) { return new AutoValue_GridControlData(descriptor, rows, ordering); } @@ -36,12 +38,15 @@ public void accept(@Nonnull FormControlDataVisitor visitor) { visitor.visit(this); } + @JsonProperty(PropertyNames.CONTROL) @Nonnull public abstract GridControlDescriptor getDescriptor(); + @JsonProperty(PropertyNames.ROWS) @Nonnull public abstract Page getRows(); + @JsonProperty(PropertyNames.ORDERING) @Nonnull public abstract ImmutableSet getOrdering(); } diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/data/GridControlDataDto.java b/src/main/java/edu/stanford/protege/webprotege/forms/data/GridControlDataDto.java index b74d02d..9d523bc 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/data/GridControlDataDto.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/data/GridControlDataDto.java @@ -1,13 +1,10 @@ package edu.stanford.protege.webprotege.forms.data; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonTypeName; +import com.fasterxml.jackson.annotation.*; import com.google.auto.value.AutoValue; import com.google.common.collect.ImmutableSet; import edu.stanford.protege.webprotege.common.Page; -import edu.stanford.protege.webprotege.forms.FilterState; -import edu.stanford.protege.webprotege.forms.HasFilterState; +import edu.stanford.protege.webprotege.forms.*; import edu.stanford.protege.webprotege.forms.field.FormRegionOrdering; import edu.stanford.protege.webprotege.forms.field.GridControlDescriptor; @@ -20,20 +17,23 @@ public abstract class GridControlDataDto implements FormControlDataDto, HasFilte @JsonCreator @Nonnull - public static GridControlDataDto get(@JsonProperty("descriptor") @Nonnull GridControlDescriptor descriptor, - @JsonProperty("rows") @Nonnull Page rows, - @JsonProperty("ordering") @Nonnull ImmutableSet ordering, - @JsonProperty("depth") int depth, - @JsonProperty("filterState") @Nonnull FilterState filterState) { + public static GridControlDataDto get(@JsonProperty(PropertyNames.CONTROL) @Nonnull GridControlDescriptor descriptor, + @JsonProperty(PropertyNames.ROWS) @Nonnull Page rows, + @JsonProperty(PropertyNames.ORDERING) @Nonnull ImmutableSet ordering, + @JsonProperty(PropertyNames.DEPTH) int depth, + @JsonProperty(PropertyNames.FILTER_STATE) @Nonnull FilterState filterState) { return new AutoValue_GridControlDataDto(depth, descriptor, rows, ordering, filterState); } + @JsonProperty(PropertyNames.CONTROL) @Nonnull public abstract GridControlDescriptor getDescriptor(); + @JsonProperty(PropertyNames.ROWS) @Nonnull public abstract Page getRows(); + @JsonProperty(PropertyNames.ORDERING) @Nonnull public abstract ImmutableSet getOrdering(); @@ -48,6 +48,7 @@ public GridControlData toFormControlData() { return GridControlData.get(getDescriptor(), getRows().transform(GridRowDataDto::toGridRowData), getOrdering()); } + @JsonProperty(PropertyNames.FILTER_STATE) @Nonnull @Override public abstract FilterState getFilterState(); @@ -57,6 +58,7 @@ public GridControlData toFormControlData() { * * @return true if this grid is empty and this is due to filtering */ + @JsonIgnore public boolean isFilteredEmpty() { return getFilterState().equals(FilterState.FILTERED) && getRows().getTotalElements() == 0; } diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/data/GridRowData.java b/src/main/java/edu/stanford/protege/webprotege/forms/data/GridRowData.java index 34ee041..2fb0750 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/data/GridRowData.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/data/GridRowData.java @@ -1,7 +1,9 @@ package edu.stanford.protege.webprotege.forms.data; +import com.fasterxml.jackson.annotation.*; import com.google.auto.value.AutoValue; import com.google.common.collect.ImmutableList; +import edu.stanford.protege.webprotege.forms.PropertyNames; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -13,22 +15,25 @@ * 2019-11-30 */ @AutoValue - public abstract class GridRowData implements Comparable { - public static GridRowData get(@Nullable FormEntitySubject subject, @Nonnull ImmutableList cellData) { + public static GridRowData get(@JsonProperty(PropertyNames.SUBJECT) @Nullable FormEntitySubject subject, + @JsonProperty(PropertyNames.CELLS) @Nonnull ImmutableList cellData) { return new AutoValue_GridRowData(subject, cellData); } + @JsonProperty(PropertyNames.SUBJECT) @Nullable protected abstract FormEntitySubject getSubjectInternal(); + @JsonIgnore @Nonnull public Optional getSubject() { return Optional.ofNullable(getSubjectInternal()); } + @JsonProperty(PropertyNames.CELLS) @Nonnull public abstract ImmutableList getCells(); diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/data/GridRowDataDto.java b/src/main/java/edu/stanford/protege/webprotege/forms/data/GridRowDataDto.java index 45425a7..56cd3a2 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/data/GridRowDataDto.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/data/GridRowDataDto.java @@ -1,7 +1,9 @@ package edu.stanford.protege.webprotege.forms.data; +import com.fasterxml.jackson.annotation.*; import com.google.auto.value.AutoValue; import com.google.common.collect.ImmutableList; +import edu.stanford.protege.webprotege.forms.PropertyNames; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -13,9 +15,10 @@ public abstract class GridRowDataDto { + @JsonCreator @Nonnull - public static GridRowDataDto get(@Nullable FormSubjectDto subject, - @Nonnull ImmutableList cellData) { + public static GridRowDataDto get(@JsonProperty(PropertyNames.SUBJECT) @Nullable FormSubjectDto subject, + @JsonProperty(PropertyNames.CELLS) @Nonnull ImmutableList cellData) { return new AutoValue_GridRowDataDto(subject, cellData); } @@ -25,14 +28,17 @@ public static GridRowDataDto get(@Nonnull ImmutableList cellDat } + @JsonProperty(PropertyNames.SUBJECT) @Nullable protected abstract FormSubjectDto getSubjectInternal(); + @JsonIgnore @Nonnull public Optional getSubject() { return Optional.ofNullable(getSubjectInternal()); } + @JsonProperty("cells") @Nonnull public abstract ImmutableList getCells(); diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/data/ImageControlData.java b/src/main/java/edu/stanford/protege/webprotege/forms/data/ImageControlData.java index 5b4d5b2..452ff00 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/data/ImageControlData.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/data/ImageControlData.java @@ -1,9 +1,8 @@ package edu.stanford.protege.webprotege.forms.data; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonTypeName; +import com.fasterxml.jackson.annotation.*; import com.google.auto.value.AutoValue; +import edu.stanford.protege.webprotege.forms.PropertyNames; import edu.stanford.protege.webprotege.forms.field.ImageControlDescriptor; import org.semanticweb.owlapi.model.IRI; @@ -22,8 +21,8 @@ public abstract class ImageControlData implements FormControlData { @JsonCreator - public static ImageControlData get(@JsonProperty("descriptor") @Nonnull ImageControlDescriptor descriptor, - @JsonProperty("iri") @Nullable IRI iri) { + public static ImageControlData get(@JsonProperty(PropertyNames.CONTROL) @Nonnull ImageControlDescriptor descriptor, + @JsonProperty(PropertyNames.IRI) @Nullable IRI iri) { return new AutoValue_ImageControlData(descriptor, iri); } @@ -37,14 +36,15 @@ public void accept(@Nonnull FormControlDataVisitor visitor) { visitor.visit(this); } - @JsonProperty("descriptor") + @JsonProperty(PropertyNames.CONTROL) @Nonnull public abstract ImageControlDescriptor getDescriptor(); - @JsonProperty("iri") + @JsonProperty(PropertyNames.IRI) @Nullable protected abstract IRI getIriInternal(); + @JsonIgnore @Nonnull public Optional getIri() { return Optional.ofNullable(getIriInternal()); diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/data/ImageControlDataDto.java b/src/main/java/edu/stanford/protege/webprotege/forms/data/ImageControlDataDto.java index 81cfef2..1d922cf 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/data/ImageControlDataDto.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/data/ImageControlDataDto.java @@ -1,9 +1,8 @@ package edu.stanford.protege.webprotege.forms.data; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonTypeName; +import com.fasterxml.jackson.annotation.*; import com.google.auto.value.AutoValue; +import edu.stanford.protege.webprotege.forms.PropertyNames; import edu.stanford.protege.webprotege.forms.field.ImageControlDescriptor; import org.semanticweb.owlapi.model.IRI; @@ -18,20 +17,21 @@ public abstract class ImageControlDataDto implements FormControlDataDto { @JsonCreator @Nonnull - public static ImageControlDataDto get(@JsonProperty("descriptor") @Nonnull ImageControlDescriptor descriptor, - @JsonProperty("iri") @Nonnull IRI iri, - @JsonProperty("depth") int depth) { + public static ImageControlDataDto get(@JsonProperty(PropertyNames.CONTROL) @Nonnull ImageControlDescriptor descriptor, + @JsonProperty(PropertyNames.IRI) @Nonnull IRI iri, + @JsonProperty(PropertyNames.DEPTH) int depth) { return new AutoValue_ImageControlDataDto(depth, descriptor, iri); } - @JsonProperty("descriptor") + @JsonProperty(PropertyNames.CONTROL) @Nonnull public abstract ImageControlDescriptor getDescriptor(); - @JsonProperty("iri") + @JsonProperty(PropertyNames.IRI) @Nullable protected abstract IRI getIriInternal(); + @JsonIgnore @Nonnull public Optional getIri() { return Optional.ofNullable(getIriInternal()); diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/data/IriFormControlData.java b/src/main/java/edu/stanford/protege/webprotege/forms/data/IriFormControlData.java index 29077b9..f4f085a 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/data/IriFormControlData.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/data/IriFormControlData.java @@ -1,5 +1,6 @@ package edu.stanford.protege.webprotege.forms.data; +import com.fasterxml.jackson.annotation.JsonCreator; import com.google.auto.value.AutoValue; import org.semanticweb.owlapi.model.IRI; import org.semanticweb.owlapi.model.OWLEntity; @@ -15,7 +16,6 @@ * 2020-01-07 */ @AutoValue - public abstract class IriFormControlData implements PrimitiveFormControlData { public static IriFormControlData get(@Nonnull IRI iri) { diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/data/IriFormControlDataDto.java b/src/main/java/edu/stanford/protege/webprotege/forms/data/IriFormControlDataDto.java index 4f7c498..4507517 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/data/IriFormControlDataDto.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/data/IriFormControlDataDto.java @@ -6,6 +6,7 @@ import com.google.auto.value.AutoValue; import edu.stanford.protege.webprotege.entity.IRIData; import edu.stanford.protege.webprotege.entity.OWLPrimitiveData; +import edu.stanford.protege.webprotege.forms.PropertyNames; import org.semanticweb.owlapi.model.OWLLiteral; import javax.annotation.Nonnull; @@ -17,10 +18,11 @@ public abstract class IriFormControlDataDto extends PrimitiveFormControlDataDto { @JsonCreator - public static IriFormControlDataDto get(@JsonProperty("iri") @Nonnull IRIData iriData) { + public static IriFormControlDataDto get(@JsonProperty(PropertyNames.IRI) @Nonnull IRIData iriData) { return new AutoValue_IriFormControlDataDto(iriData); } + @JsonProperty(PropertyNames.IRI) @Nonnull public abstract IRIData getIri(); diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/data/LiteralFormControlDataDto.java b/src/main/java/edu/stanford/protege/webprotege/forms/data/LiteralFormControlDataDto.java index 7a5f989..7716d3b 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/data/LiteralFormControlDataDto.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/data/LiteralFormControlDataDto.java @@ -6,22 +6,23 @@ import com.google.auto.value.AutoValue; import edu.stanford.protege.webprotege.entity.OWLLiteralData; import edu.stanford.protege.webprotege.entity.OWLPrimitiveData; +import edu.stanford.protege.webprotege.forms.PropertyNames; import org.semanticweb.owlapi.model.OWLLiteral; import javax.annotation.Nonnull; import java.util.Optional; @AutoValue - @JsonTypeName("LiteralFormControlDataDto") public abstract class LiteralFormControlDataDto extends PrimitiveFormControlDataDto { @JsonCreator - public static LiteralFormControlDataDto get(@JsonProperty("literal") @Nonnull OWLLiteralData literal) { + public static LiteralFormControlDataDto get(@JsonProperty(PropertyNames.LITERAL) @Nonnull OWLLiteralData literal) { return new AutoValue_LiteralFormControlDataDto(literal); } + @JsonProperty(PropertyNames.LITERAL) @Nonnull public abstract OWLLiteralData getLiteral(); diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/data/LiteralFormControlDataMatchCriteria.java b/src/main/java/edu/stanford/protege/webprotege/forms/data/LiteralFormControlDataMatchCriteria.java index fb13ed6..2231a51 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/data/LiteralFormControlDataMatchCriteria.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/data/LiteralFormControlDataMatchCriteria.java @@ -1,8 +1,9 @@ package edu.stanford.protege.webprotege.forms.data; -import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.*; import com.google.auto.value.AutoValue; import edu.stanford.protege.webprotege.criteria.LiteralCriteria; +import edu.stanford.protege.webprotege.forms.PropertyNames; import javax.annotation.Nonnull; @@ -15,14 +16,13 @@ public abstract class LiteralFormControlDataMatchCriteria implements PrimitiveFormControlDataMatchCriteria { - public static final String LITERAL_MATCHES = "literalMatches"; - + @JsonCreator @Nonnull - public static LiteralFormControlDataMatchCriteria get(@Nonnull LiteralCriteria literalCriteria) { + public static LiteralFormControlDataMatchCriteria get(@JsonProperty(PropertyNames.CRITERIA) @Nonnull LiteralCriteria literalCriteria) { return new AutoValue_LiteralFormControlDataMatchCriteria(literalCriteria); } - @JsonProperty(LITERAL_MATCHES) + @JsonProperty(PropertyNames.CRITERIA) @Nonnull public abstract LiteralCriteria getLexicalValueCriteria(); diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/data/MultiChoiceControlData.java b/src/main/java/edu/stanford/protege/webprotege/forms/data/MultiChoiceControlData.java index c5e316a..467a499 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/data/MultiChoiceControlData.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/data/MultiChoiceControlData.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonTypeName; import com.google.auto.value.AutoValue; import com.google.common.collect.ImmutableList; +import edu.stanford.protege.webprotege.forms.PropertyNames; import edu.stanford.protege.webprotege.forms.field.MultiChoiceControlDescriptor; import javax.annotation.Nonnull; @@ -18,8 +19,8 @@ @JsonTypeName("MultiChoiceControlData") public abstract class MultiChoiceControlData implements FormControlData { - public static MultiChoiceControlData get(@JsonProperty("descriptor") @Nonnull MultiChoiceControlDescriptor descriptor, - @JsonProperty("values") @Nonnull ImmutableList values) { + public static MultiChoiceControlData get(@JsonProperty(PropertyNames.CONTROL) @Nonnull MultiChoiceControlDescriptor descriptor, + @JsonProperty(PropertyNames.VALUES) @Nonnull ImmutableList values) { return new AutoValue_MultiChoiceControlData(descriptor, values); } @@ -33,11 +34,11 @@ public void accept(@Nonnull FormControlDataVisitor visitor) { visitor.visit(this); } - @JsonProperty("descriptor") + @JsonProperty(PropertyNames.CONTROL) @Nonnull public abstract MultiChoiceControlDescriptor getDescriptor(); - @JsonProperty("values") + @JsonProperty(PropertyNames.VALUES) @Nonnull public abstract ImmutableList getValues(); } diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/data/MultiChoiceControlDataDto.java b/src/main/java/edu/stanford/protege/webprotege/forms/data/MultiChoiceControlDataDto.java index 8141ea4..736c514 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/data/MultiChoiceControlDataDto.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/data/MultiChoiceControlDataDto.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonTypeName; import com.google.auto.value.AutoValue; import com.google.common.collect.ImmutableList; +import edu.stanford.protege.webprotege.forms.PropertyNames; import edu.stanford.protege.webprotege.forms.field.MultiChoiceControlDescriptor; import javax.annotation.Nonnull; @@ -18,17 +19,17 @@ public abstract class MultiChoiceControlDataDto implements FormControlDataDto { @JsonCreator @Nonnull - public static MultiChoiceControlDataDto get(@JsonProperty("descriptor") @Nonnull MultiChoiceControlDescriptor descriptor, - @JsonProperty("values") @Nonnull ImmutableList values, - @JsonProperty("depth") int depth) { + public static MultiChoiceControlDataDto get(@JsonProperty(PropertyNames.CONTROL) @Nonnull MultiChoiceControlDescriptor descriptor, + @JsonProperty(PropertyNames.VALUES) @Nonnull ImmutableList values, + @JsonProperty(PropertyNames.DEPTH) int depth) { return new AutoValue_MultiChoiceControlDataDto(depth, descriptor, values); } - @JsonProperty("descriptor") + @JsonProperty(PropertyNames.CONTROL) @Nonnull public abstract MultiChoiceControlDescriptor getDescriptor(); - @JsonProperty("values") + @JsonProperty(PropertyNames.VALUES) @Nonnull public abstract ImmutableList getValues(); diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/data/NumberControlData.java b/src/main/java/edu/stanford/protege/webprotege/forms/data/NumberControlData.java index f0e4438..57c50c4 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/data/NumberControlData.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/data/NumberControlData.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonTypeName; import com.google.auto.value.AutoValue; +import edu.stanford.protege.webprotege.forms.PropertyNames; import edu.stanford.protege.webprotege.forms.field.NumberControlDescriptor; import org.semanticweb.owlapi.model.OWLLiteral; @@ -23,7 +24,8 @@ public abstract class NumberControlData implements FormControlData { @JsonCreator - public static NumberControlData get(@Nonnull NumberControlDescriptor descriptor, @Nullable OWLLiteral value) { + public static NumberControlData get(@JsonProperty(PropertyNames.CONTROL) @Nonnull NumberControlDescriptor descriptor, + @JsonProperty(PropertyNames.VALUE) @Nullable OWLLiteral value) { return new AutoValue_NumberControlData(descriptor, value); } @@ -37,10 +39,11 @@ public void accept(@Nonnull FormControlDataVisitor visitor) { visitor.visit(this); } + @JsonProperty(PropertyNames.CONTROL) @Nonnull public abstract NumberControlDescriptor getDescriptor(); - @JsonProperty("value") + @JsonProperty(PropertyNames.VALUE) @Nullable protected abstract OWLLiteral getValueInternal(); diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/data/NumberControlDataDto.java b/src/main/java/edu/stanford/protege/webprotege/forms/data/NumberControlDataDto.java index 4a8c1f6..f5ad39e 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/data/NumberControlDataDto.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/data/NumberControlDataDto.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonTypeName; import com.google.auto.value.AutoValue; +import edu.stanford.protege.webprotege.forms.PropertyNames; import edu.stanford.protege.webprotege.forms.field.NumberControlDescriptor; import org.semanticweb.owlapi.model.OWLLiteral; @@ -21,16 +22,17 @@ public abstract class NumberControlDataDto implements FormControlDataDto, Compar @JsonCreator @Nonnull - public static NumberControlDataDto get(@JsonProperty("descriptor") @Nonnull NumberControlDescriptor descriptor, - @JsonProperty("value") @Nonnull OWLLiteral value, - @JsonProperty("depth") int depth) { + public static NumberControlDataDto get(@JsonProperty(PropertyNames.CONTROL) @Nonnull NumberControlDescriptor descriptor, + @JsonProperty(PropertyNames.VALUE) @Nonnull OWLLiteral value, + @JsonProperty(PropertyNames.DEPTH) int depth) { return new AutoValue_NumberControlDataDto(depth, descriptor, value); } + @JsonProperty(PropertyNames.CONTROL) @Nonnull public abstract NumberControlDescriptor getDescriptor(); - @JsonProperty("value") + @JsonProperty(PropertyNames.VALUE) @Nullable protected abstract OWLLiteral getValueInternal(); diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/data/PrimitiveFormControlData.java b/src/main/java/edu/stanford/protege/webprotege/forms/data/PrimitiveFormControlData.java index 3f0b821..c49f027 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/data/PrimitiveFormControlData.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/data/PrimitiveFormControlData.java @@ -1,9 +1,7 @@ package edu.stanford.protege.webprotege.forms.data; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.*; import com.fasterxml.jackson.annotation.JsonSubTypes.Type; -import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import org.semanticweb.owlapi.model.IRI; @@ -63,6 +61,7 @@ static PrimitiveFormControlData get(boolean value) { @Nonnull Optional asLiteral(); + @JsonIgnore @Nonnull OWLPrimitive getPrimitive(); diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/data/SingleChoiceControlData.java b/src/main/java/edu/stanford/protege/webprotege/forms/data/SingleChoiceControlData.java index 03a16c5..faf02e6 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/data/SingleChoiceControlData.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/data/SingleChoiceControlData.java @@ -1,9 +1,8 @@ package edu.stanford.protege.webprotege.forms.data; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonTypeName; +import com.fasterxml.jackson.annotation.*; import com.google.auto.value.AutoValue; +import edu.stanford.protege.webprotege.forms.PropertyNames; import edu.stanford.protege.webprotege.forms.field.SingleChoiceControlDescriptor; import javax.annotation.Nonnull; @@ -21,8 +20,8 @@ public abstract class SingleChoiceControlData implements FormControlData { @JsonCreator - public static SingleChoiceControlData get(@JsonProperty("descriptor") @Nonnull SingleChoiceControlDescriptor descriptor, - @JsonProperty("choice") @Nullable PrimitiveFormControlData choice) { + public static SingleChoiceControlData get(@JsonProperty(PropertyNames.CONTROL) @Nonnull SingleChoiceControlDescriptor descriptor, + @JsonProperty(PropertyNames.CHOICE) @Nullable PrimitiveFormControlData choice) { return new AutoValue_SingleChoiceControlData(descriptor, choice); } @@ -37,13 +36,15 @@ public void accept(@Nonnull FormControlDataVisitor visitor) { visitor.visit(this); } + @JsonProperty(PropertyNames.CONTROL) @Nonnull public abstract SingleChoiceControlDescriptor getDescriptor(); - @JsonProperty("choice") + @JsonProperty(PropertyNames.CHOICE) @Nullable protected abstract PrimitiveFormControlData getChoiceInternal(); + @JsonIgnore @Nonnull public Optional getChoice() { return Optional.ofNullable(getChoiceInternal()); diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/data/SingleChoiceControlDataDto.java b/src/main/java/edu/stanford/protege/webprotege/forms/data/SingleChoiceControlDataDto.java index 042d020..4b81d2e 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/data/SingleChoiceControlDataDto.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/data/SingleChoiceControlDataDto.java @@ -1,9 +1,8 @@ package edu.stanford.protege.webprotege.forms.data; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonTypeName; +import com.fasterxml.jackson.annotation.*; import com.google.auto.value.AutoValue; +import edu.stanford.protege.webprotege.forms.PropertyNames; import edu.stanford.protege.webprotege.forms.field.SingleChoiceControlDescriptor; import javax.annotation.Nonnull; @@ -17,19 +16,20 @@ public abstract class SingleChoiceControlDataDto implements FormControlDataDto { @JsonCreator @Nonnull - public static SingleChoiceControlDataDto get(@JsonProperty("descriptor") @Nonnull SingleChoiceControlDescriptor descriptor, - @JsonProperty("choice") @Nullable PrimitiveFormControlDataDto choice, - @JsonProperty("depth") int depth) { + public static SingleChoiceControlDataDto get(@JsonProperty(PropertyNames.CONTROL) @Nonnull SingleChoiceControlDescriptor descriptor, + @JsonProperty(PropertyNames.CHOICE) @Nullable PrimitiveFormControlDataDto choice, + @JsonProperty(PropertyNames.DEPTH) int depth) { return new AutoValue_SingleChoiceControlDataDto(depth, descriptor, choice); } @Nonnull public abstract SingleChoiceControlDescriptor getDescriptor(); - @JsonProperty("choice") + @JsonProperty(PropertyNames.CONTROL) @Nullable protected abstract PrimitiveFormControlDataDto getChoiceInternal(); + @JsonIgnore @Nonnull public Optional getChoice() { return Optional.ofNullable(getChoiceInternal()); diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/data/TextControlData.java b/src/main/java/edu/stanford/protege/webprotege/forms/data/TextControlData.java index a444876..24ccca2 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/data/TextControlData.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/data/TextControlData.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonTypeName; import com.google.auto.value.AutoValue; +import edu.stanford.protege.webprotege.forms.PropertyNames; import edu.stanford.protege.webprotege.forms.field.TextControlDescriptor; import org.semanticweb.owlapi.model.OWLLiteral; @@ -24,8 +25,8 @@ public abstract class TextControlData implements FormControlData { @JsonCreator @Nonnull - public static TextControlData get(@JsonProperty("descriptor") @Nonnull TextControlDescriptor descriptor, - @JsonProperty("value") @Nullable OWLLiteral value) { + public static TextControlData get(@JsonProperty(PropertyNames.CONTROL) @Nonnull TextControlDescriptor descriptor, + @JsonProperty(PropertyNames.VALUE) @Nullable OWLLiteral value) { return new AutoValue_TextControlData(descriptor, value); } @@ -39,11 +40,11 @@ public void accept(@Nonnull FormControlDataVisitor visitor) { visitor.visit(this); } - @JsonProperty("descriptor") + @JsonProperty(PropertyNames.CONTROL) @Nonnull public abstract TextControlDescriptor getDescriptor(); - @JsonProperty("value") + @JsonProperty(PropertyNames.VALUE) @Nullable protected abstract OWLLiteral getValueInternal(); diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/data/TextControlDataDto.java b/src/main/java/edu/stanford/protege/webprotege/forms/data/TextControlDataDto.java index 2f63e90..1a06319 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/data/TextControlDataDto.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/data/TextControlDataDto.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonTypeName; import com.google.auto.value.AutoValue; +import edu.stanford.protege.webprotege.forms.PropertyNames; import edu.stanford.protege.webprotege.forms.field.TextControlDescriptor; import org.semanticweb.owlapi.model.OWLLiteral; @@ -27,17 +28,17 @@ public abstract class TextControlDataDto implements FormControlDataDto, Comparab @JsonCreator @Nonnull - public static TextControlDataDto get(@JsonProperty("descriptor") @Nonnull TextControlDescriptor descriptor, - @JsonProperty("value") @Nonnull OWLLiteral value, - @JsonProperty("depth") int depth) { + public static TextControlDataDto get(@JsonProperty(PropertyNames.CONTROL) @Nonnull TextControlDescriptor descriptor, + @JsonProperty(PropertyNames.VALUE) @Nonnull OWLLiteral value, + @JsonProperty(PropertyNames.DEPTH) int depth) { return new AutoValue_TextControlDataDto(depth, descriptor, value); } - @JsonProperty("descriptor") + @JsonProperty(PropertyNames.CONTROL) @Nonnull public abstract TextControlDescriptor getDescriptor(); - @JsonProperty("value") + @JsonProperty(PropertyNames.VALUE) @Nullable protected abstract OWLLiteral getValueInternal(); diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/field/ChoiceDescriptor.java b/src/main/java/edu/stanford/protege/webprotege/forms/field/ChoiceDescriptor.java index 301ffe2..1745ba4 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/field/ChoiceDescriptor.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/field/ChoiceDescriptor.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.google.auto.value.AutoValue; import edu.stanford.protege.webprotege.common.LanguageMap; +import edu.stanford.protege.webprotege.forms.PropertyNames; import edu.stanford.protege.webprotege.forms.data.PrimitiveFormControlData; import javax.annotation.Nonnull; @@ -18,14 +19,16 @@ public abstract class ChoiceDescriptor { @JsonCreator - public static ChoiceDescriptor choice(@Nonnull @JsonProperty("label") LanguageMap label, - @Nonnull @JsonProperty("value") PrimitiveFormControlData value) { + public static ChoiceDescriptor choice(@Nonnull @JsonProperty(PropertyNames.LABEL) LanguageMap label, + @Nonnull @JsonProperty(PropertyNames.VALUE) PrimitiveFormControlData value) { return new AutoValue_ChoiceDescriptor(label, value); } + @JsonProperty(PropertyNames.LABEL) @Nonnull public abstract LanguageMap getLabel(); + @JsonProperty(PropertyNames.VALUE) @Nonnull public abstract PrimitiveFormControlData getValue(); } diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/field/ChoiceDescriptorDto.java b/src/main/java/edu/stanford/protege/webprotege/forms/field/ChoiceDescriptorDto.java index caa667d..9eb81ed 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/field/ChoiceDescriptorDto.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/field/ChoiceDescriptorDto.java @@ -1,7 +1,9 @@ package edu.stanford.protege.webprotege.forms.field; +import com.fasterxml.jackson.annotation.*; import com.google.auto.value.AutoValue; import edu.stanford.protege.webprotege.common.LanguageMap; +import edu.stanford.protege.webprotege.forms.PropertyNames; import edu.stanford.protege.webprotege.forms.data.PrimitiveFormControlDataDto; import javax.annotation.Nonnull; @@ -10,14 +12,18 @@ public abstract class ChoiceDescriptorDto { + @JsonCreator @Nonnull - public static ChoiceDescriptorDto get(@Nonnull PrimitiveFormControlDataDto value, @Nonnull LanguageMap label) { + public static ChoiceDescriptorDto get(@JsonProperty(PropertyNames.VALUE) @Nonnull PrimitiveFormControlDataDto value, + @JsonProperty(PropertyNames.LABEL) @Nonnull LanguageMap label) { return new AutoValue_ChoiceDescriptorDto(label, value); } + @JsonProperty(PropertyNames.LABEL) @Nonnull public abstract LanguageMap getLabel(); + @JsonProperty(PropertyNames.VALUE) @Nonnull public abstract PrimitiveFormControlDataDto getValue(); } diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/field/DynamicChoiceListSourceDescriptor.java b/src/main/java/edu/stanford/protege/webprotege/forms/field/DynamicChoiceListSourceDescriptor.java index bf7b233..82742e9 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/field/DynamicChoiceListSourceDescriptor.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/field/DynamicChoiceListSourceDescriptor.java @@ -8,6 +8,7 @@ import edu.stanford.protege.webprotege.criteria.CompositeRootCriteria; import edu.stanford.protege.webprotege.criteria.MultiMatchType; import edu.stanford.protege.webprotege.criteria.RootCriteria; +import edu.stanford.protege.webprotege.forms.PropertyNames; import javax.annotation.Nonnull; @@ -23,10 +24,8 @@ public abstract class DynamicChoiceListSourceDescriptor implements ChoiceListSou public static final String TYPE = "Dynamic"; - private static final String CRITERIA = "criteria"; - @JsonCreator - public static DynamicChoiceListSourceDescriptor get(@JsonProperty(CRITERIA) @Nonnull RootCriteria criteria) { + public static DynamicChoiceListSourceDescriptor get(@JsonProperty(PropertyNames.CRITERIA) @Nonnull RootCriteria criteria) { if (criteria instanceof CompositeRootCriteria) { return new AutoValue_DynamicChoiceListSourceDescriptor((CompositeRootCriteria) criteria); } @@ -36,7 +35,7 @@ public static DynamicChoiceListSourceDescriptor get(@JsonProperty(CRITERIA) @Non } } - @JsonProperty(CRITERIA) + @JsonProperty(PropertyNames.CRITERIA) @Nonnull public abstract CompositeRootCriteria getCriteria(); diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/field/EntityNameControlDescriptor.java b/src/main/java/edu/stanford/protege/webprotege/forms/field/EntityNameControlDescriptor.java index 838c9d5..22821e8 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/field/EntityNameControlDescriptor.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/field/EntityNameControlDescriptor.java @@ -11,6 +11,7 @@ import edu.stanford.protege.webprotege.criteria.CompositeRootCriteria; import edu.stanford.protege.webprotege.criteria.EntityTypeIsOneOfCriteria; import edu.stanford.protege.webprotege.criteria.MultiMatchType; +import edu.stanford.protege.webprotege.forms.PropertyNames; import org.semanticweb.owlapi.model.EntityType; import javax.annotation.Nonnull; @@ -31,9 +32,9 @@ public abstract class EntityNameControlDescriptor implements FormControlDescript @JsonCreator @Nonnull - public static EntityNameControlDescriptor get(@Nullable @JsonProperty("placeholder") LanguageMap languageMap, - @Nullable @JsonProperty("matchCriteria") CompositeRootCriteria criteria) { - return new AutoValue_EntityNameControlDescriptor(languageMap == null ? LanguageMap.empty() : languageMap, + public static EntityNameControlDescriptor get(@Nullable @JsonProperty(PropertyNames.PLACEHOLDER) LanguageMap placeholder, + @Nullable @JsonProperty(PropertyNames.CRITERIA) CompositeRootCriteria criteria) { + return new AutoValue_EntityNameControlDescriptor(placeholder == null ? LanguageMap.empty() : placeholder, criteria); } @@ -64,12 +65,14 @@ public R accept(@Nonnull FormControlDescriptorVisitor visitor) { } @Nonnull + @JsonProperty(PropertyNames.PLACEHOLDER) public abstract LanguageMap getPlaceholder(); - @JsonIgnore @Nullable + @JsonProperty(PropertyNames.CRITERIA) protected abstract CompositeRootCriteria getMatchCriteriaInternal(); + @JsonIgnore @Nonnull public Optional getMatchCriteria() { return Optional.ofNullable(getMatchCriteriaInternal()); diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/field/EntityNameControlDescriptorDto.java b/src/main/java/edu/stanford/protege/webprotege/forms/field/EntityNameControlDescriptorDto.java index c77087d..4ad2390 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/field/EntityNameControlDescriptorDto.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/field/EntityNameControlDescriptorDto.java @@ -7,6 +7,7 @@ import com.google.auto.value.AutoValue; import edu.stanford.protege.webprotege.common.LanguageMap; import edu.stanford.protege.webprotege.criteria.CompositeRootCriteria; +import edu.stanford.protege.webprotege.forms.PropertyNames; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -19,8 +20,8 @@ public abstract class EntityNameControlDescriptorDto implements FormControlDescr @JsonCreator @Nonnull - public static EntityNameControlDescriptorDto get(@JsonProperty("placeholder") @Nonnull LanguageMap placeholder, - @JsonProperty("matchCriteria") @Nullable CompositeRootCriteria matchCriteria) { + public static EntityNameControlDescriptorDto get(@JsonProperty(PropertyNames.PLACEHOLDER) @Nonnull LanguageMap placeholder, + @JsonProperty(PropertyNames.CRITERIA) @Nullable CompositeRootCriteria matchCriteria) { return new AutoValue_EntityNameControlDescriptorDto(placeholder, matchCriteria); } @@ -35,13 +36,15 @@ public EntityNameControlDescriptor toFormControlDescriptor() { } @Nonnull + @JsonProperty(PropertyNames.PLACEHOLDER) public abstract LanguageMap getPlaceholder(); - @JsonIgnore + @JsonProperty(PropertyNames.CRITERIA) @Nullable protected abstract CompositeRootCriteria getMatchCriteriaInternal(); @Nonnull + @JsonIgnore public Optional getMatchCriteria() { return Optional.ofNullable(getMatchCriteriaInternal()); } diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/field/FixedChoiceListSourceDescriptor.java b/src/main/java/edu/stanford/protege/webprotege/forms/field/FixedChoiceListSourceDescriptor.java index 89ef1e6..cfda900 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/field/FixedChoiceListSourceDescriptor.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/field/FixedChoiceListSourceDescriptor.java @@ -5,9 +5,11 @@ import com.fasterxml.jackson.annotation.JsonTypeName; import com.google.auto.value.AutoValue; import com.google.common.collect.ImmutableList; +import edu.stanford.protege.webprotege.forms.PropertyNames; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import java.util.List; /** * Matthew Horridge @@ -16,19 +18,16 @@ */ @JsonTypeName(FixedChoiceListSourceDescriptor.TYPE) @AutoValue - public abstract class FixedChoiceListSourceDescriptor implements ChoiceListSourceDescriptor { public static final String TYPE = "Fixed"; - private static final String CHOICES = "choices"; - @JsonCreator - public static FixedChoiceListSourceDescriptor get(@JsonProperty(CHOICES) @Nullable ImmutableList choices) { - return new AutoValue_FixedChoiceListSourceDescriptor(choices == null ? ImmutableList.of() : choices); + public static FixedChoiceListSourceDescriptor get(@JsonProperty(PropertyNames.CHOICES) @Nullable List choices) { + return new AutoValue_FixedChoiceListSourceDescriptor(choices == null ? ImmutableList.of() : ImmutableList.copyOf(choices)); } - @JsonProperty(CHOICES) + @JsonProperty(PropertyNames.CHOICES) @Nonnull - public abstract ImmutableList getChoices(); + public abstract List getChoices(); } diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/field/FormFieldDescriptor.java b/src/main/java/edu/stanford/protege/webprotege/forms/field/FormFieldDescriptor.java index 4c2c6fc..7aabe94 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/field/FormFieldDescriptor.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/field/FormFieldDescriptor.java @@ -6,49 +6,26 @@ import com.fasterxml.jackson.annotation.JsonPropertyOrder; import com.google.auto.value.AutoValue; import edu.stanford.protege.webprotege.common.LanguageMap; -import edu.stanford.protege.webprotege.forms.ExpansionState; -import edu.stanford.protege.webprotege.forms.HasFormFieldId; +import edu.stanford.protege.webprotege.forms.*; import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.util.Optional; import static com.google.common.base.Preconditions.checkNotNull; -import static edu.stanford.protege.webprotege.forms.field.FormFieldDescriptor.*; +import static edu.stanford.protege.webprotege.forms.PropertyNames.*; /** * Matthew Horridge * Stanford Center for Biomedical Informatics Research * 30/03/16 */ -@JsonPropertyOrder({ID, OWL_BINDING, LABEL, FIELD_RUN, FORM_CONTROL_DESCRIPTOR, REPEATABILITY, OPTIONALITY, READ_ONLY, HELP}) +@JsonPropertyOrder({ID, OWL_BINDING, LABEL, FIELD_RUN, CONTROL, REPEATABILITY, OPTIONALITY, READ_ONLY, HELP}) @AutoValue public abstract class FormFieldDescriptor implements HasFormFieldId, HasRepeatability, BoundControlDescriptor { - public static final String ID = "id"; - - public static final String OWL_BINDING = "owlBinding"; - - public static final String LABEL = "label"; - - public static final String FIELD_RUN = "fieldRun"; - - public static final String FORM_CONTROL_DESCRIPTOR = "formControlDescriptor"; - - public static final String REPEATABILITY = "repeatability"; - - public static final String OPTIONALITY = "optionality"; - - public static final String READ_ONLY = "readOnly"; - - public static final String INITIAL_EXPANSIONS_STATE = "initialExpansionState"; - - public static final String HELP = "help"; - - public static final String DEPRECATION_STRATEGY = "deprecationStrategy"; - @Nonnull public static FormFieldDescriptor get(@Nonnull FormFieldId id, @Nullable OwlBinding owlBinding, @@ -81,7 +58,7 @@ public static FormFieldDescriptor getFromJson(@JsonProperty(ID) @Nonnull String @JsonProperty(LABEL) @Nullable LanguageMap formLabel, @JsonProperty(FIELD_RUN) @Nullable FieldRun fieldRun, @JsonProperty(DEPRECATION_STRATEGY) @Nullable FormFieldDeprecationStrategy deprecationStrategy, - @JsonProperty(FORM_CONTROL_DESCRIPTOR) @Nonnull FormControlDescriptor fieldDescriptor, + @JsonProperty(CONTROL) @Nonnull FormControlDescriptor fieldDescriptor, @JsonProperty(REPEATABILITY) @Nullable Repeatability repeatability, @JsonProperty(OPTIONALITY) @Nullable Optionality optionality, @JsonProperty(READ_ONLY) boolean readOnly, @@ -106,29 +83,33 @@ public static FormFieldDescriptor getFromJson(@JsonProperty(ID) @Nonnull String @JsonIgnore public abstract FormFieldId getId(); - @JsonProperty("id") + @JsonProperty(PropertyNames.ID) protected String getFormFieldId() { return getId().getId(); } - @JsonIgnore + @JsonProperty(OWL_BINDING) @Nullable protected abstract OwlBinding getOwlBindingInternal(); @Override @Nonnull + @JsonIgnore public Optional getOwlBinding() { return Optional.ofNullable(getOwlBindingInternal()); } @Nonnull + @JsonProperty(LABEL) public abstract LanguageMap getLabel(); @Nonnull + @JsonProperty(FIELD_RUN) public abstract FieldRun getFieldRun(); @Override @Nonnull + @JsonProperty(CONTROL) public abstract FormControlDescriptor getFormControlDescriptor(); @Nonnull @@ -141,6 +122,7 @@ public Optional getOwlBinding() { @Nonnull public abstract FormFieldDeprecationStrategy getDeprecationStrategy(); + @JsonProperty(READ_ONLY) public abstract boolean isReadOnly(); @JsonProperty(INITIAL_EXPANSIONS_STATE) @@ -148,6 +130,7 @@ public Optional getOwlBinding() { public abstract ExpansionState getInitialExpansionState(); @Nonnull + @JsonProperty(HELP) public abstract LanguageMap getHelp(); @JsonIgnore diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/field/FormFieldDescriptorDto.java b/src/main/java/edu/stanford/protege/webprotege/forms/field/FormFieldDescriptorDto.java index 69787d0..abc38f5 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/field/FormFieldDescriptorDto.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/field/FormFieldDescriptorDto.java @@ -5,8 +5,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.google.auto.value.AutoValue; import edu.stanford.protege.webprotege.common.LanguageMap; -import edu.stanford.protege.webprotege.forms.ExpansionState; -import edu.stanford.protege.webprotege.forms.HasFormFieldId; +import edu.stanford.protege.webprotege.forms.*; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -18,17 +17,17 @@ public abstract class FormFieldDescriptorDto implements HasFormFieldId { @JsonCreator @Nonnull - public static FormFieldDescriptorDto get(@JsonProperty("id") FormFieldId formFieldId, - @JsonProperty("owlBinding") OwlBinding owlBinding, - @JsonProperty("label") LanguageMap newlabel, - @JsonProperty("fieldRun") FieldRun fieldRun, - @JsonProperty("formControlDescriptor") FormControlDescriptorDto descriptorDto, - @JsonProperty("optionality") Optionality optionality, - @JsonProperty("repeatability") Repeatability repeatability, - @JsonProperty("deprecationStrategy") FormFieldDeprecationStrategy deprecationStrategy, - @JsonProperty("readOnly") boolean newReadOnly, - @JsonProperty("initialExpansionState") ExpansionState initialExpansionState, - @JsonProperty("help") LanguageMap help) { + public static FormFieldDescriptorDto get(@JsonProperty(PropertyNames.ID) FormFieldId formFieldId, + @JsonProperty(PropertyNames.OWL_BINDING) OwlBinding owlBinding, + @JsonProperty(PropertyNames.LABEL) LanguageMap newlabel, + @JsonProperty(PropertyNames.FIELD_RUN) FieldRun fieldRun, + @JsonProperty(PropertyNames.CONTROL) FormControlDescriptorDto descriptorDto, + @JsonProperty(PropertyNames.OPTIONALITY) Optionality optionality, + @JsonProperty(PropertyNames.REPEATABILITY) Repeatability repeatability, + @JsonProperty(PropertyNames.DEPRECATION_STRATEGY) FormFieldDeprecationStrategy deprecationStrategy, + @JsonProperty(PropertyNames.READ_ONLY) boolean newReadOnly, + @JsonProperty(PropertyNames.INITIAL_EXPANSIONS_STATE) ExpansionState initialExpansionState, + @JsonProperty(PropertyNames.HELP) LanguageMap help) { return new AutoValue_FormFieldDescriptorDto(formFieldId, owlBinding, newlabel, @@ -48,39 +47,49 @@ public static FormFieldDescriptorDto get(@JsonProperty("id") FormFieldId formFie @JsonProperty("id") public abstract FormFieldId getId(); - @JsonIgnore + @JsonProperty(PropertyNames.OWL_BINDING) @Nullable protected abstract OwlBinding getOwlBindingInternal(); + @JsonIgnore @Nonnull public Optional getOwlBinding() { return Optional.ofNullable(getOwlBindingInternal()); } @Nonnull + @JsonProperty(PropertyNames.LABEL) public abstract LanguageMap getLabel(); @Nonnull + @JsonProperty(PropertyNames.FIELD_RUN) public abstract FieldRun getFieldRun(); + @JsonProperty(PropertyNames.CONTROL) @Nonnull public abstract FormControlDescriptorDto getFormControlDescriptor(); @Nonnull + @JsonProperty(PropertyNames.OPTIONALITY) public abstract Optionality getOptionality(); @Nonnull + @JsonProperty(PropertyNames.REPEATABILITY) public abstract Repeatability getRepeatability(); @Nonnull + @JsonProperty(PropertyNames.DEPRECATION_STRATEGY) public abstract FormFieldDeprecationStrategy getDeprecationStrategy(); + @JsonProperty(PropertyNames.READ_ONLY) public abstract boolean isReadOnly(); @Nonnull + @JsonProperty(PropertyNames.INITIAL_EXPANSIONS_STATE) public abstract ExpansionState getInitialExpansionState(); @Nonnull + @JsonProperty(PropertyNames.HELP) public abstract LanguageMap getHelp(); @JsonIgnore diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/field/FormFieldId.java b/src/main/java/edu/stanford/protege/webprotege/forms/field/FormFieldId.java index f016a48..0aec935 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/field/FormFieldId.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/field/FormFieldId.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonTypeName; import com.google.auto.value.AutoValue; import edu.stanford.protege.webprotege.common.UUIDUtil; +import edu.stanford.protege.webprotege.forms.PropertyNames; import javax.annotation.Nonnull; @@ -20,7 +21,7 @@ public abstract class FormFieldId implements FormRegionId { @JsonCreator @Nonnull - public static FormFieldId get(@JsonProperty("id") @Nonnull String id) { + public static FormFieldId get(@JsonProperty(PropertyNames.ID) @Nonnull String id) { checkFormat(id); return new AutoValue_FormFieldId(id); } @@ -40,6 +41,8 @@ public String value() { return getId(); } + + @JsonProperty(PropertyNames.ID) @Override public abstract String getId(); } diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/field/FormRegionId.java b/src/main/java/edu/stanford/protege/webprotege/forms/field/FormRegionId.java index 3da97f7..b3540de 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/field/FormRegionId.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/field/FormRegionId.java @@ -1,9 +1,9 @@ package edu.stanford.protege.webprotege.forms.field; -import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.*; import com.fasterxml.jackson.annotation.JsonSubTypes.Type; -import com.fasterxml.jackson.annotation.JsonTypeInfo; import edu.stanford.protege.webprotege.common.ValueObject; +import edu.stanford.protege.webprotege.forms.PropertyNames; /** * Matthew Horridge @@ -14,5 +14,7 @@ @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type") public interface FormRegionId extends ValueObject { + + @JsonProperty(PropertyNames.ID) String getId(); } diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/field/FormRegionOrdering.java b/src/main/java/edu/stanford/protege/webprotege/forms/field/FormRegionOrdering.java index 09293f6..365e4df 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/field/FormRegionOrdering.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/field/FormRegionOrdering.java @@ -2,6 +2,7 @@ import com.fasterxml.jackson.annotation.*; import com.google.auto.value.AutoValue; +import edu.stanford.protege.webprotege.forms.PropertyNames; import javax.annotation.Nonnull; @@ -9,24 +10,20 @@ public abstract class FormRegionOrdering { - public static final String REGION_ID = "regionId"; - - public static final String DIRECTION = "direction"; - @JsonCreator @Nonnull - public static FormRegionOrdering get(@JsonProperty(REGION_ID) @Nonnull FormRegionId formRegionId, - @JsonProperty(DIRECTION) @Nonnull FormRegionOrderingDirection direction) { + public static FormRegionOrdering get(@JsonProperty(PropertyNames.REGION_ID) @Nonnull FormRegionId formRegionId, + @JsonProperty(PropertyNames.DIRECTION) @Nonnull FormRegionOrderingDirection direction) { return new AutoValue_FormRegionOrdering(formRegionId, direction); } - @JsonProperty(REGION_ID) + @JsonProperty(PropertyNames.REGION_ID) @Nonnull @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.WRAPPER_OBJECT) @JsonSubTypes({@JsonSubTypes.Type(value = FormFieldId.class), @JsonSubTypes.Type(value = GridColumnId.class)}) public abstract FormRegionId getRegionId(); - @JsonProperty(DIRECTION) + @JsonProperty(PropertyNames.DIRECTION) @Nonnull public abstract FormRegionOrderingDirection getDirection(); diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/field/GridColumnDescriptor.java b/src/main/java/edu/stanford/protege/webprotege/forms/field/GridColumnDescriptor.java index fd059b7..7b72f62 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/field/GridColumnDescriptor.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/field/GridColumnDescriptor.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.google.auto.value.AutoValue; import edu.stanford.protege.webprotege.common.LanguageMap; +import edu.stanford.protege.webprotege.forms.PropertyNames; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -37,12 +38,12 @@ public static GridColumnDescriptor get(@Nonnull GridColumnId id, @JsonCreator @Nonnull - public static GridColumnDescriptor get(@Nonnull @JsonProperty("id") String id, - @Nullable @JsonProperty("optionality") Optionality optionality, - @Nullable @JsonProperty("repeatability") Repeatability repeatability, - @Nullable @JsonProperty("owlBinding") OwlBinding owlBinding, - @Nonnull @JsonProperty("label") LanguageMap columnLabel, - @Nonnull @JsonProperty("formControlDescriptor") FormControlDescriptor formControlDescriptor) { + public static GridColumnDescriptor get(@Nonnull @JsonProperty(PropertyNames.ID) String id, + @Nullable @JsonProperty(PropertyNames.OPTIONALITY) Optionality optionality, + @Nullable @JsonProperty(PropertyNames.REPEATABILITY) Repeatability repeatability, + @Nullable @JsonProperty(PropertyNames.OWL_BINDING) OwlBinding owlBinding, + @Nonnull @JsonProperty(PropertyNames.LABEL) LanguageMap columnLabel, + @Nonnull @JsonProperty(PropertyNames.CONTROL) FormControlDescriptor formControlDescriptor) { return new AutoValue_GridColumnDescriptor(GridColumnId.get(id), optionality == null ? Optionality.REQUIRED : optionality, repeatability == null ? Repeatability.NON_REPEATABLE : repeatability, @@ -55,7 +56,7 @@ public static GridColumnDescriptor get(@Nonnull @JsonProperty("id") String id, @Nonnull public abstract GridColumnId getId(); - @JsonProperty("id") + @JsonProperty(PropertyNames.ID) public String getGridColumnId() { return getId().getId(); } @@ -83,27 +84,32 @@ public boolean isLeafColumnDescriptor() { return !(getFormControlDescriptor() instanceof GridControlDescriptor); } + @JsonProperty(PropertyNames.OPTIONALITY) @Nonnull public abstract Optionality getOptionality(); + @JsonProperty(PropertyNames.REPEATABILITY) @Nonnull public abstract Repeatability getRepeatability(); - @JsonIgnore + @JsonProperty(PropertyNames.OWL_BINDING) @Nullable protected abstract OwlBinding getOwlBindingInternal(); @Override @Nonnull + @JsonIgnore public Optional getOwlBinding() { return Optional.ofNullable(getOwlBindingInternal()); } @Nonnull + @JsonProperty(PropertyNames.LABEL) public abstract LanguageMap getLabel(); @Override @Nonnull + @JsonProperty(PropertyNames.CONTROL) public abstract FormControlDescriptor getFormControlDescriptor(); @JsonIgnore diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/field/GridColumnDescriptorDto.java b/src/main/java/edu/stanford/protege/webprotege/forms/field/GridColumnDescriptorDto.java index 7ca0e2a..1cded42 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/field/GridColumnDescriptorDto.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/field/GridColumnDescriptorDto.java @@ -1,8 +1,9 @@ package edu.stanford.protege.webprotege.forms.field; -import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.*; import com.google.auto.value.AutoValue; import edu.stanford.protege.webprotege.common.LanguageMap; +import edu.stanford.protege.webprotege.forms.PropertyNames; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -14,13 +15,14 @@ public abstract class GridColumnDescriptorDto { + @JsonCreator @Nonnull - public static GridColumnDescriptorDto get(@Nonnull GridColumnId columnId, - @Nonnull Optionality optionality, - @Nonnull Repeatability repeatability, - @Nullable OwlBinding binding, - @Nonnull LanguageMap label, - @Nonnull FormControlDescriptorDto formControlDescriptorDto) { + public static GridColumnDescriptorDto get(@JsonProperty(PropertyNames.ID) @Nonnull GridColumnId columnId, + @JsonProperty(PropertyNames.OPTIONALITY) @Nonnull Optionality optionality, + @JsonProperty(PropertyNames.REPEATABILITY) @Nonnull Repeatability repeatability, + @JsonProperty(PropertyNames.OWL_BINDING) @Nullable OwlBinding binding, + @JsonProperty(PropertyNames.LABEL) @Nonnull LanguageMap label, + @JsonProperty(PropertyNames.CONTROL) @Nonnull FormControlDescriptorDto formControlDescriptorDto) { return new AutoValue_GridColumnDescriptorDto(columnId, optionality, repeatability, @@ -31,27 +33,33 @@ public static GridColumnDescriptorDto get(@Nonnull GridColumnId columnId, @Nonnull + @JsonProperty(PropertyNames.ID) public abstract GridColumnId getId(); @Nonnull + @JsonProperty(PropertyNames.OPTIONALITY) public abstract Optionality getOptionality(); @Nonnull + @JsonProperty(PropertyNames.REPEATABILITY) public abstract Repeatability getRepeatability(); - @JsonIgnore @Nullable + @JsonProperty(PropertyNames.OWL_BINDING) protected abstract OwlBinding getOwlBindingInternal(); @Nonnull + @JsonIgnore public Optional getOwlBinding() { return Optional.ofNullable(getOwlBindingInternal()); } @Nonnull + @JsonProperty(PropertyNames.LABEL) public abstract LanguageMap getLabel(); @Nonnull + @JsonProperty(PropertyNames.CONTROL) public abstract FormControlDescriptorDto getFormControlDescriptor(); public GridColumnDescriptor toGridColumnDescriptor() { diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/field/GridColumnId.java b/src/main/java/edu/stanford/protege/webprotege/forms/field/GridColumnId.java index fec56af..17a1485 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/field/GridColumnId.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/field/GridColumnId.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonTypeName; import com.google.auto.value.AutoValue; import edu.stanford.protege.webprotege.common.UUIDUtil; +import edu.stanford.protege.webprotege.forms.PropertyNames; import javax.annotation.Nonnull; @@ -20,7 +21,7 @@ public abstract class GridColumnId implements FormRegionId { @JsonCreator @Nonnull - public static GridColumnId get(@JsonProperty("id") @Nonnull String id) { + public static GridColumnId get(@JsonProperty(PropertyNames.ID) @Nonnull String id) { checkFormat(id); return new AutoValue_GridColumnId(id); } @@ -40,6 +41,7 @@ public String value() { return getId(); } + @JsonProperty(PropertyNames.ID) @Override public abstract String getId(); } diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/field/GridControlDescriptor.java b/src/main/java/edu/stanford/protege/webprotege/forms/field/GridControlDescriptor.java index 1a79a82..108027f 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/field/GridControlDescriptor.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/field/GridControlDescriptor.java @@ -7,7 +7,7 @@ import com.google.auto.value.AutoValue; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; -import edu.stanford.protege.webprotege.forms.FormSubjectFactoryDescriptor; +import edu.stanford.protege.webprotege.forms.*; import org.semanticweb.owlapi.model.EntityType; import javax.annotation.Nonnull; @@ -33,8 +33,8 @@ public static String getType() { @JsonCreator @Nonnull - public static GridControlDescriptor get(@Nonnull @JsonProperty("columns") ImmutableList columnDescriptors, - @Nullable @JsonProperty("subjectFactoryDescriptor") FormSubjectFactoryDescriptor subjectFactoryDescriptor) { + public static GridControlDescriptor get(@Nonnull @JsonProperty(PropertyNames.COLUMNS) ImmutableList columnDescriptors, + @Nullable @JsonProperty(PropertyNames.SUBJECT_FACTORY) FormSubjectFactoryDescriptor subjectFactoryDescriptor) { return new AutoValue_GridControlDescriptor(columnDescriptors == null ? ImmutableList.of() : columnDescriptors, subjectFactoryDescriptor == null ? FormSubjectFactoryDescriptor.get( EntityType.CLASS, @@ -48,7 +48,7 @@ public String getAssociatedType() { return getType(); } - @JsonProperty("columns") + @JsonProperty(PropertyNames.COLUMNS) @Nonnull public abstract ImmutableList getColumns(); @@ -67,10 +67,11 @@ public int getNestedColumnCount() { } - @JsonIgnore + @JsonProperty(PropertyNames.SUBJECT_FACTORY) @Nullable protected abstract FormSubjectFactoryDescriptor getSubjectFactoryDescriptorInternal(); + @JsonIgnore public Optional getSubjectFactoryDescriptor() { return Optional.ofNullable(getSubjectFactoryDescriptorInternal()); } diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/field/GridControlDescriptorDto.java b/src/main/java/edu/stanford/protege/webprotege/forms/field/GridControlDescriptorDto.java index 19ab682..021016e 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/field/GridControlDescriptorDto.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/field/GridControlDescriptorDto.java @@ -7,7 +7,7 @@ import com.google.auto.value.AutoValue; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; -import edu.stanford.protege.webprotege.forms.FormSubjectFactoryDescriptor; +import edu.stanford.protege.webprotege.forms.*; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -23,17 +23,20 @@ public abstract class GridControlDescriptorDto implements FormControlDescriptorD @JsonCreator @Nonnull - public static GridControlDescriptorDto get(@JsonProperty("columns") @Nonnull ImmutableList columns, - @JsonProperty("formSubjectFactoryDescriptor") @Nullable FormSubjectFactoryDescriptor formSubjectFactoryDescriptor) { + public static GridControlDescriptorDto get(@JsonProperty(PropertyNames.COLUMNS) @Nonnull ImmutableList columns, + @JsonProperty(PropertyNames.SUBJECT_FACTORY) @Nullable FormSubjectFactoryDescriptor formSubjectFactoryDescriptor) { return new AutoValue_GridControlDescriptorDto(columns, formSubjectFactoryDescriptor); } + @JsonProperty(PropertyNames.COLUMNS) @Nonnull public abstract ImmutableList getColumns(); + @JsonProperty(PropertyNames.SUBJECT_FACTORY) @Nullable protected abstract FormSubjectFactoryDescriptor getSubjectFactoryDescriptorInternal(); + @JsonIgnore @Nonnull public Optional getSubjectFactoryDescriptor() { return Optional.ofNullable(getSubjectFactoryDescriptorInternal()); @@ -52,6 +55,7 @@ public GridControlDescriptor toFormControlDescriptor() { getSubjectFactoryDescriptorInternal()); } + @JsonIgnore public int getNestedColumnCount() { int count = 0; for (GridColumnDescriptorDto columnDescriptor : getColumns()) { diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/field/MultiChoiceControlDescriptor.java b/src/main/java/edu/stanford/protege/webprotege/forms/field/MultiChoiceControlDescriptor.java index 66176f6..0882d03 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/field/MultiChoiceControlDescriptor.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/field/MultiChoiceControlDescriptor.java @@ -6,6 +6,7 @@ import com.fasterxml.jackson.annotation.JsonTypeName; import com.google.auto.value.AutoValue; import com.google.common.collect.ImmutableList; +import edu.stanford.protege.webprotege.forms.PropertyNames; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -24,8 +25,8 @@ public abstract class MultiChoiceControlDescriptor implements FormControlDescrip public static final String TYPE = "MULTI_CHOICE"; @JsonCreator - public static MultiChoiceControlDescriptor get(@JsonProperty("source") ChoiceListSourceDescriptor source, - @JsonProperty("defaultChoices") @Nullable ImmutableList defaultChoices) { + public static MultiChoiceControlDescriptor get(@JsonProperty(PropertyNames.CHOICES_SOURCE) ChoiceListSourceDescriptor source, + @JsonProperty(PropertyNames.DEFAULT_CHOICE) @Nullable ImmutableList defaultChoices) { return new AutoValue_MultiChoiceControlDescriptor(source == null ? FixedChoiceListSourceDescriptor.get( ImmutableList.of()) : source, defaultChoices == null ? ImmutableList.of() : defaultChoices); @@ -38,9 +39,11 @@ public static String getType() { } @Nonnull + @JsonProperty(PropertyNames.CHOICES_SOURCE) public abstract ChoiceListSourceDescriptor getSource(); @Nonnull + @JsonProperty(PropertyNames.DEFAULT_CHOICE) public abstract ImmutableList getDefaultChoices(); @Nonnull diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/field/MultiChoiceControlDescriptorDto.java b/src/main/java/edu/stanford/protege/webprotege/forms/field/MultiChoiceControlDescriptorDto.java index 187d09f..1d093bc 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/field/MultiChoiceControlDescriptorDto.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/field/MultiChoiceControlDescriptorDto.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonTypeName; import com.google.auto.value.AutoValue; import com.google.common.collect.ImmutableList; +import edu.stanford.protege.webprotege.forms.PropertyNames; import javax.annotation.Nonnull; @@ -15,15 +16,17 @@ public abstract class MultiChoiceControlDescriptorDto implements FormControlDesc @JsonCreator @Nonnull - public static MultiChoiceControlDescriptorDto get(@JsonProperty("choiceListSourceDescriptor") @Nonnull ChoiceListSourceDescriptor choiceListSourceDescriptor, - @JsonProperty("availableChoices") @Nonnull ImmutableList choices) { + public static MultiChoiceControlDescriptorDto get(@JsonProperty(PropertyNames.CHOICES_SOURCE) @Nonnull ChoiceListSourceDescriptor choiceListSourceDescriptor, + @JsonProperty(PropertyNames.CHOICES) @Nonnull ImmutableList choices) { return new AutoValue_MultiChoiceControlDescriptorDto(choiceListSourceDescriptor, choices); } + @JsonProperty(PropertyNames.CHOICES_SOURCE) @Nonnull public abstract ChoiceListSourceDescriptor getChoiceListSourceDescriptor(); @Nonnull + @JsonProperty(PropertyNames.CHOICES) public abstract ImmutableList getAvailableChoices(); @Override diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/field/NumberControlDescriptor.java b/src/main/java/edu/stanford/protege/webprotege/forms/field/NumberControlDescriptor.java index 13c23bd..42df5e8 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/field/NumberControlDescriptor.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/field/NumberControlDescriptor.java @@ -1,8 +1,9 @@ package edu.stanford.protege.webprotege.forms.field; -import com.fasterxml.jackson.annotation.JsonTypeName; +import com.fasterxml.jackson.annotation.*; import com.google.common.base.Objects; import edu.stanford.protege.webprotege.common.LanguageMap; +import edu.stanford.protege.webprotege.forms.PropertyNames; import javax.annotation.Nonnull; @@ -38,11 +39,12 @@ public class NumberControlDescriptor implements FormControlDescriptor { private NumberControlDescriptor() { } - public NumberControlDescriptor(@Nonnull String format, - @Nonnull NumberControlRange range, - @Nonnull NumberControlType widgetType, - int length, - @Nonnull LanguageMap placeholder) { + @JsonCreator + public NumberControlDescriptor(@JsonProperty(PropertyNames.FORMAT) @Nonnull String format, + @JsonProperty(PropertyNames.RANGE) @Nonnull NumberControlRange range, + @JsonProperty(PropertyNames.WIDGET_TYPE) @Nonnull NumberControlType widgetType, + @JsonProperty(PropertyNames.LENGTH) int length, + @JsonProperty(PropertyNames.PLACEHOLDER) @Nonnull LanguageMap placeholder) { this.format = checkNotNull(format); this.range = checkNotNull(range); this.widgetType = checkNotNull(widgetType); @@ -72,6 +74,7 @@ public boolean equals(Object obj) { other.placeholder); } + @JsonIgnore @Nonnull @Override public String getAssociatedType() { @@ -79,24 +82,29 @@ public String getAssociatedType() { } @Nonnull + @JsonProperty(PropertyNames.FORMAT) public String getFormat() { return format; } + @JsonProperty(PropertyNames.LENGTH) public int getLength() { return length; } + @JsonProperty(PropertyNames.PLACEHOLDER) public LanguageMap getPlaceholder() { return placeholder; } @Nonnull + @JsonProperty(PropertyNames.RANGE) public NumberControlRange getRange() { return range; } @Nonnull + @JsonProperty(PropertyNames.WIDGET_TYPE) public NumberControlType getWidgetType() { return widgetType; } diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/field/NumberControlDescriptorDto.java b/src/main/java/edu/stanford/protege/webprotege/forms/field/NumberControlDescriptorDto.java index a8934a1..e8887b8 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/field/NumberControlDescriptorDto.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/field/NumberControlDescriptorDto.java @@ -1,10 +1,9 @@ package edu.stanford.protege.webprotege.forms.field; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonTypeName; +import com.fasterxml.jackson.annotation.*; import com.google.auto.value.AutoValue; import edu.stanford.protege.webprotege.common.LanguageMap; +import edu.stanford.protege.webprotege.forms.PropertyNames; import javax.annotation.Nonnull; @@ -15,11 +14,12 @@ public abstract class NumberControlDescriptorDto implements FormControlDescripto @JsonCreator @Nonnull - public static NumberControlDescriptorDto get(@JsonProperty("descriptor") @Nonnull NumberControlDescriptor descriptor) { + public static NumberControlDescriptorDto get(@JsonProperty(PropertyNames.CONTROL) @Nonnull NumberControlDescriptor descriptor) { return new AutoValue_NumberControlDescriptorDto(descriptor); } @Nonnull + @JsonProperty(PropertyNames.CONTROL) public abstract NumberControlDescriptor getDescriptor(); @Override @@ -32,18 +32,22 @@ public FormControlDescriptor toFormControlDescriptor() { return getDescriptor(); } + @JsonIgnore public String getFormat() { return getDescriptor().getFormat(); } + @JsonIgnore public NumberControlRange getRange() { return getDescriptor().getRange(); } + @JsonIgnore public LanguageMap getPlaceholder() { return getDescriptor().getPlaceholder(); } + @JsonIgnore public int getLength() { return getDescriptor().getLength(); } diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/field/NumberControlRange.java b/src/main/java/edu/stanford/protege/webprotege/forms/field/NumberControlRange.java index c71ba4b..655235d 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/field/NumberControlRange.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/field/NumberControlRange.java @@ -1,7 +1,9 @@ package edu.stanford.protege.webprotege.forms.field; +import com.fasterxml.jackson.annotation.*; import com.google.common.base.Objects; import com.google.common.collect.Range; +import edu.stanford.protege.webprotege.forms.PropertyNames; import static com.google.common.base.MoreObjects.toStringHelper; @@ -25,10 +27,11 @@ public class NumberControlRange { private BoundType upperBoundType = BoundType.INCLUSIVE; - private NumberControlRange(double lowerBound, - BoundType lowerBoundType, - double upperBound, - BoundType upperBoundType) { + @JsonCreator + private NumberControlRange(@JsonProperty(PropertyNames.LOWER_BOUND) double lowerBound, + @JsonProperty(PropertyNames.LOWER_BOUND_TYPE) BoundType lowerBoundType, + @JsonProperty(PropertyNames.UPPER_BOUND) double upperBound, + @JsonProperty(PropertyNames.UPPER_BOUND_TYPE) BoundType upperBoundType) { this.lowerBound = lowerBound; this.lowerBoundType = lowerBoundType; this.upperBound = upperBound; @@ -50,6 +53,7 @@ public static NumberControlRange all() { return ANY_NUMBER; } + @JsonIgnore public boolean isAnyNumber() { return this.equals(ANY_NUMBER); } @@ -79,18 +83,22 @@ public Range toRange() { this.getUpperBoundType() == NumberControlRange.BoundType.INCLUSIVE ? com.google.common.collect.BoundType.CLOSED : com.google.common.collect.BoundType.OPEN); } + @JsonProperty(PropertyNames.LOWER_BOUND) public double getLowerBound() { return lowerBound; } + @JsonProperty(PropertyNames.LOWER_BOUND_TYPE) public BoundType getLowerBoundType() { return lowerBoundType; } + @JsonProperty(PropertyNames.UPPER_BOUND) public double getUpperBound() { return upperBound; } + @JsonProperty(PropertyNames.UPPER_BOUND_TYPE) public BoundType getUpperBoundType() { return upperBoundType; } diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/field/OwlBinding.java b/src/main/java/edu/stanford/protege/webprotege/forms/field/OwlBinding.java index e0a0be6..20a6188 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/field/OwlBinding.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/field/OwlBinding.java @@ -1,11 +1,11 @@ package edu.stanford.protege.webprotege.forms.field; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonSubTypes; -import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.*; +import edu.stanford.protege.webprotege.criteria.*; +import edu.stanford.protege.webprotege.forms.PropertyNames; import org.semanticweb.owlapi.model.OWLProperty; -import javax.annotation.Nonnull; +import javax.annotation.*; import java.util.Optional; /** @@ -17,8 +17,6 @@ @JsonSubTypes({@JsonSubTypes.Type(value = OwlPropertyBinding.class, name = OwlPropertyBinding.TYPE), @JsonSubTypes.Type(value = OwlClassBinding.class, name = OwlClassBinding.TYPE), @JsonSubTypes.Type(value = OwlInstanceBinding.class, name = OwlInstanceBinding.TYPE), @JsonSubTypes.Type(value = OwlSubClassBinding.class, name = OwlSubClassBinding.TYPE)}) public interface OwlBinding { - String VALUES_CRITERIA = "valuesCriteria"; - @JsonIgnore @Nonnull Optional getOwlProperty(); diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/field/OwlClassBinding.java b/src/main/java/edu/stanford/protege/webprotege/forms/field/OwlClassBinding.java index e9ae98a..e458a4e 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/field/OwlClassBinding.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/field/OwlClassBinding.java @@ -1,10 +1,10 @@ package edu.stanford.protege.webprotege.forms.field; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonTypeName; +import com.fasterxml.jackson.annotation.*; import com.google.auto.value.AutoValue; import edu.stanford.protege.webprotege.criteria.EntityMatchCriteria; +import edu.stanford.protege.webprotege.forms.PropertyNames; +import org.checkerframework.checker.nullness.Opt; import org.semanticweb.owlapi.model.OWLProperty; import javax.annotation.Nonnull; @@ -25,8 +25,8 @@ public abstract class OwlClassBinding implements OwlBinding { @JsonCreator @Nonnull - public static OwlClassBinding get(@JsonProperty(VALUES_CRITERIA) @Nullable EntityMatchCriteria valuesFilter) { - return new AutoValue_OwlClassBinding(); + public static OwlClassBinding get(@JsonProperty(PropertyNames.CRITERIA) @Nullable EntityMatchCriteria valuesFilter) { + return new AutoValue_OwlClassBinding(valuesFilter); } @Nonnull @@ -39,4 +39,13 @@ public static OwlClassBinding get() { public Optional getOwlProperty() { return Optional.empty(); } + + @JsonProperty(PropertyNames.CRITERIA) + @Nullable + public abstract EntityMatchCriteria getCriteriaInternal(); + + @JsonIgnore + public Optional getCriteria() { + return Optional.ofNullable(getCriteriaInternal()); + } } diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/field/OwlInstanceBinding.java b/src/main/java/edu/stanford/protege/webprotege/forms/field/OwlInstanceBinding.java index 0228c3c..5b0f499 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/field/OwlInstanceBinding.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/field/OwlInstanceBinding.java @@ -1,10 +1,9 @@ package edu.stanford.protege.webprotege.forms.field; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonTypeName; +import com.fasterxml.jackson.annotation.*; import com.google.auto.value.AutoValue; import edu.stanford.protege.webprotege.criteria.EntityMatchCriteria; +import edu.stanford.protege.webprotege.forms.PropertyNames; import org.semanticweb.owlapi.model.OWLProperty; import javax.annotation.Nonnull; @@ -25,8 +24,8 @@ public abstract class OwlInstanceBinding implements OwlBinding { @JsonCreator @Nonnull - public static OwlInstanceBinding get(@JsonProperty(VALUES_CRITERIA) @Nullable EntityMatchCriteria valuesFilter) { - return new AutoValue_OwlInstanceBinding(); + public static OwlInstanceBinding get(@JsonProperty(PropertyNames.CRITERIA) @Nullable EntityMatchCriteria valuesFilter) { + return new AutoValue_OwlInstanceBinding(valuesFilter); } @Nonnull @@ -40,4 +39,14 @@ public Optional getOwlProperty() { return Optional.empty(); } + + @JsonProperty(PropertyNames.CRITERIA) + @Nullable + public abstract EntityMatchCriteria getCriteriaInternal(); + + @JsonIgnore + public Optional getCriteria() { + return Optional.ofNullable(getCriteriaInternal()); + } + } diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/field/OwlPropertyBinding.java b/src/main/java/edu/stanford/protege/webprotege/forms/field/OwlPropertyBinding.java index aeb00bb..942d052 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/field/OwlPropertyBinding.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/field/OwlPropertyBinding.java @@ -5,7 +5,8 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonTypeName; import com.google.auto.value.AutoValue; -import edu.stanford.protege.webprotege.criteria.CompositeRelationshipValueCriteria; +import edu.stanford.protege.webprotege.criteria.*; +import edu.stanford.protege.webprotege.forms.PropertyNames; import org.semanticweb.owlapi.model.OWLProperty; import javax.annotation.Nonnull; @@ -27,8 +28,8 @@ public abstract class OwlPropertyBinding implements OwlBinding { public static final String PROPERTY = "property"; @JsonCreator - public static OwlPropertyBinding get(@JsonProperty(PROPERTY) @Nonnull OWLProperty property, - @JsonProperty(VALUES_CRITERIA) @Nullable CompositeRelationshipValueCriteria criteria) { + public static OwlPropertyBinding get(@JsonProperty(PropertyNames.PROPERTY) @Nonnull OWLProperty property, + @JsonProperty(PropertyNames.CRITERIA) @Nullable CompositeRelationshipValueCriteria criteria) { return new AutoValue_OwlPropertyBinding(property, criteria); } @@ -46,14 +47,13 @@ public Optional getOwlProperty() { return Optional.of(getProperty()); } + @JsonProperty(PropertyNames.CRITERIA) + @Nullable + public abstract CompositeRelationshipValueCriteria getCriteriaInternal(); @JsonIgnore @Nonnull public Optional getValuesCriteria() { - return Optional.ofNullable(getValuesCriteriaInternal()); + return Optional.ofNullable(getCriteriaInternal()); } - - @JsonProperty(VALUES_CRITERIA) - @Nullable - protected abstract CompositeRelationshipValueCriteria getValuesCriteriaInternal(); } diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/field/OwlSubClassBinding.java b/src/main/java/edu/stanford/protege/webprotege/forms/field/OwlSubClassBinding.java index 9df48bb..ddc6af1 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/field/OwlSubClassBinding.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/field/OwlSubClassBinding.java @@ -1,11 +1,12 @@ package edu.stanford.protege.webprotege.forms.field; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonTypeName; +import com.fasterxml.jackson.annotation.*; import com.google.auto.value.AutoValue; +import edu.stanford.protege.webprotege.criteria.EntityMatchCriteria; +import edu.stanford.protege.webprotege.forms.PropertyNames; import org.semanticweb.owlapi.model.OWLProperty; -import javax.annotation.Nonnull; +import javax.annotation.*; import java.util.Optional; @AutoValue @@ -17,8 +18,8 @@ public abstract class OwlSubClassBinding implements OwlBinding { @JsonCreator @Nonnull - public static OwlSubClassBinding get() { - return new AutoValue_OwlSubClassBinding(); + public static OwlSubClassBinding get(EntityMatchCriteria criteria) { + return new AutoValue_OwlSubClassBinding(criteria); } @Nonnull @@ -26,4 +27,14 @@ public static OwlSubClassBinding get() { public Optional getOwlProperty() { return Optional.empty(); } + + + @JsonProperty(PropertyNames.CRITERIA) + @Nullable + public abstract EntityMatchCriteria getCriteriaInternal(); + + @JsonIgnore + public Optional getCriteria() { + return Optional.ofNullable(getCriteriaInternal()); + } } diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/field/SingleChoiceControlDescriptor.java b/src/main/java/edu/stanford/protege/webprotege/forms/field/SingleChoiceControlDescriptor.java index d459f6f..ea86138 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/field/SingleChoiceControlDescriptor.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/field/SingleChoiceControlDescriptor.java @@ -6,6 +6,7 @@ import com.fasterxml.jackson.annotation.JsonTypeName; import com.google.auto.value.AutoValue; import com.google.common.collect.ImmutableList; +import edu.stanford.protege.webprotege.forms.PropertyNames; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -23,16 +24,10 @@ public abstract class SingleChoiceControlDescriptor implements FormControlDescri protected static final String TYPE = "SINGLE_CHOICE"; - private static final String DEFAULT_CHOICE = "defaultChoice"; - - private static final String SOURCE = "source"; - - private static final String WIDGET_TYPE = "widgetType"; - @JsonCreator - protected static SingleChoiceControlDescriptor get(@JsonProperty(WIDGET_TYPE) @Nullable SingleChoiceControlType widgetType, - @JsonProperty(DEFAULT_CHOICE) @Nullable ChoiceDescriptor defaultChoice, - @JsonProperty(SOURCE) @Nullable ChoiceListSourceDescriptor source) { + protected static SingleChoiceControlDescriptor get(@JsonProperty(PropertyNames.WIDGET_TYPE) @Nullable SingleChoiceControlType widgetType, + @JsonProperty(PropertyNames.DEFAULT_CHOICE) @Nullable ChoiceDescriptor defaultChoice, + @JsonProperty(PropertyNames.CHOICES_SOURCE) @Nullable ChoiceListSourceDescriptor source) { return new AutoValue_SingleChoiceControlDescriptor(widgetType == null ? SingleChoiceControlType.COMBO_BOX : widgetType, source == null ? FixedChoiceListSourceDescriptor.get( ImmutableList.of()) : source, @@ -63,15 +58,15 @@ public String getAssociatedType() { return TYPE; } - @JsonProperty(WIDGET_TYPE) + @JsonProperty(PropertyNames.WIDGET_TYPE) @Nonnull public abstract SingleChoiceControlType getWidgetType(); - @JsonProperty(SOURCE) + @JsonProperty(PropertyNames.CHOICES_SOURCE) @Nonnull public abstract ChoiceListSourceDescriptor getSource(); - @JsonProperty(DEFAULT_CHOICE) + @JsonProperty(PropertyNames.DEFAULT_CHOICE) @Nullable protected abstract ChoiceDescriptor getDefaultChoiceInternal(); diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/field/SingleChoiceControlDescriptorDto.java b/src/main/java/edu/stanford/protege/webprotege/forms/field/SingleChoiceControlDescriptorDto.java index f9dda99..5339aa5 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/field/SingleChoiceControlDescriptorDto.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/field/SingleChoiceControlDescriptorDto.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonTypeName; import com.google.auto.value.AutoValue; import com.google.common.collect.ImmutableList; +import edu.stanford.protege.webprotege.forms.PropertyNames; import javax.annotation.Nonnull; @@ -15,9 +16,9 @@ public abstract class SingleChoiceControlDescriptorDto implements FormControlDes @JsonCreator @Nonnull - public static SingleChoiceControlDescriptorDto get(@JsonProperty("widgetType") @Nonnull SingleChoiceControlType widgetType, - @JsonProperty("availableChoices") @Nonnull ImmutableList availableChoices, - @JsonProperty("choiceListSourceDescriptor") @Nonnull ChoiceListSourceDescriptor choiceListSourceDescriptor) { + public static SingleChoiceControlDescriptorDto get(@JsonProperty(PropertyNames.WIDGET_TYPE) @Nonnull SingleChoiceControlType widgetType, + @JsonProperty(PropertyNames.CHOICES) @Nonnull ImmutableList availableChoices, + @JsonProperty(PropertyNames.CHOICES_SOURCE) @Nonnull ChoiceListSourceDescriptor choiceListSourceDescriptor) { return new AutoValue_SingleChoiceControlDescriptorDto(availableChoices, choiceListSourceDescriptor, widgetType); } @@ -25,6 +26,7 @@ public static SingleChoiceControlDescriptorDto get(@JsonProperty("widgetType") @ public abstract ImmutableList getAvailableChoices(); + @JsonProperty("descriptor") @Nonnull public abstract ChoiceListSourceDescriptor getChoiceListSourceDescriptor(); diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/field/SubFormControlDescriptor.java b/src/main/java/edu/stanford/protege/webprotege/forms/field/SubFormControlDescriptor.java index 1f85d39..ed8fbd4 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/field/SubFormControlDescriptor.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/field/SubFormControlDescriptor.java @@ -1,9 +1,9 @@ package edu.stanford.protege.webprotege.forms.field; -import com.fasterxml.jackson.annotation.JsonUnwrapped; +import com.fasterxml.jackson.annotation.*; import com.google.common.base.MoreObjects; import com.google.common.base.Objects; -import edu.stanford.protege.webprotege.forms.FormDescriptor; +import edu.stanford.protege.webprotege.forms.*; import javax.annotation.Nonnull; @@ -23,7 +23,8 @@ public class SubFormControlDescriptor implements FormControlDescriptor { private SubFormControlDescriptor() { } - public SubFormControlDescriptor(@Nonnull FormDescriptor formDescriptor) { + @JsonCreator + public SubFormControlDescriptor(@JsonProperty(PropertyNames.FORM) @Nonnull FormDescriptor formDescriptor) { this.formDescriptor = checkNotNull(formDescriptor); } @@ -45,11 +46,12 @@ public boolean equals(Object obj) { @Nonnull @Override + @JsonIgnore public String getAssociatedType() { return TYPE; } - @JsonUnwrapped + @JsonProperty(PropertyNames.FORM) public FormDescriptor getFormDescriptor() { return formDescriptor; } diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/field/SubFormControlDescriptorDto.java b/src/main/java/edu/stanford/protege/webprotege/forms/field/SubFormControlDescriptorDto.java index d99b059..f28114d 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/field/SubFormControlDescriptorDto.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/field/SubFormControlDescriptorDto.java @@ -4,7 +4,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonTypeName; import com.google.auto.value.AutoValue; -import edu.stanford.protege.webprotege.forms.FormDescriptorDto; +import edu.stanford.protege.webprotege.forms.*; import javax.annotation.Nonnull; @@ -15,11 +15,12 @@ public abstract class SubFormControlDescriptorDto implements FormControlDescript @JsonCreator @Nonnull - public static SubFormControlDescriptorDto get(@JsonProperty("descriptor") @Nonnull FormDescriptorDto subformDescriptorDto) { + public static SubFormControlDescriptorDto get(@JsonProperty(PropertyNames.FORM) @Nonnull FormDescriptorDto subformDescriptorDto) { return new AutoValue_SubFormControlDescriptorDto(subformDescriptorDto); } @Nonnull + @JsonProperty(PropertyNames.FORM) public abstract FormDescriptorDto getDescriptor(); @Override diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/field/TextControlDescriptor.java b/src/main/java/edu/stanford/protege/webprotege/forms/field/TextControlDescriptor.java index 190ddf7..7a13afc 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/field/TextControlDescriptor.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/field/TextControlDescriptor.java @@ -1,9 +1,9 @@ package edu.stanford.protege.webprotege.forms.field; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonTypeName; +import com.fasterxml.jackson.annotation.*; import com.google.common.base.Objects; import edu.stanford.protege.webprotege.common.LanguageMap; +import edu.stanford.protege.webprotege.forms.PropertyNames; import javax.annotation.Nonnull; @@ -35,12 +35,13 @@ public class TextControlDescriptor implements FormControlDescriptor { private TextControlDescriptor() { } - public TextControlDescriptor(@Nonnull LanguageMap placeholder, - @Nonnull StringType stringType, - @Nonnull String specificLangTag, - @Nonnull LineMode lineMode, - @Nonnull String pattern, - @Nonnull LanguageMap patternViolationErrorMessage) { + @JsonCreator + public TextControlDescriptor(@JsonProperty(PropertyNames.PLACEHOLDER) @Nonnull LanguageMap placeholder, + @JsonProperty(PropertyNames.STRING_TYPE) @Nonnull StringType stringType, + @JsonProperty(PropertyNames.SPECIFIC_LANG_TAG) @Nonnull String specificLangTag, + @JsonProperty(PropertyNames.LINE_MODE) @Nonnull LineMode lineMode, + @JsonProperty(PropertyNames.PATTERN) @Nonnull String pattern, + @JsonProperty(PropertyNames.PATTERN_VIOLATION_ERROR_MESSAGE) @Nonnull LanguageMap patternViolationErrorMessage) { this.placeholder = checkNotNull(placeholder); this.stringType = checkNotNull(stringType); this.specificLangTag = checkNotNull(specificLangTag); @@ -100,31 +101,37 @@ public String getAssociatedType() { } @Nonnull + @JsonProperty(PropertyNames.LINE_MODE) public LineMode getLineMode() { return lineMode; } @Nonnull + @JsonProperty(PropertyNames.PATTERN) public String getPattern() { return pattern; } @Nonnull + @JsonProperty(PropertyNames.PATTERN_VIOLATION_ERROR_MESSAGE) public LanguageMap getPatternViolationErrorMessage() { return patternViolationErrorMessage; } @Nonnull + @JsonProperty(PropertyNames.PLACEHOLDER) public LanguageMap getPlaceholder() { return placeholder; } @Nonnull + @JsonProperty(PropertyNames.STRING_TYPE) public StringType getStringType() { return stringType; } @Nonnull + @JsonProperty(PropertyNames.SPECIFIC_LANG_TAG) public String getSpecificLangTag() { return specificLangTag; } diff --git a/src/main/java/edu/stanford/protege/webprotege/forms/field/TextControlDescriptorDto.java b/src/main/java/edu/stanford/protege/webprotege/forms/field/TextControlDescriptorDto.java index eeebf89..5390665 100644 --- a/src/main/java/edu/stanford/protege/webprotege/forms/field/TextControlDescriptorDto.java +++ b/src/main/java/edu/stanford/protege/webprotege/forms/field/TextControlDescriptorDto.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonTypeName; import com.google.auto.value.AutoValue; +import edu.stanford.protege.webprotege.forms.PropertyNames; import javax.annotation.Nonnull; @@ -13,11 +14,12 @@ public abstract class TextControlDescriptorDto implements FormControlDescriptorDto { @JsonCreator - public static TextControlDescriptorDto get(@JsonProperty("descriptor") @Nonnull TextControlDescriptor descriptor) { + public static TextControlDescriptorDto get(@JsonProperty(PropertyNames.CONTROL) @Nonnull TextControlDescriptor descriptor) { return new AutoValue_TextControlDescriptorDto(descriptor); } @Nonnull + @JsonProperty(PropertyNames.CONTROL) public abstract TextControlDescriptor getDescriptor(); @Override diff --git a/src/test/java/edu/stanford/protege/webprotege/forms/WebprotegeFormsApiApplicationTests.java b/src/test/java/edu/stanford/protege/webprotege/forms/WebprotegeFormsApiApplicationTests.java index 00924e7..4f89109 100644 --- a/src/test/java/edu/stanford/protege/webprotege/forms/WebprotegeFormsApiApplicationTests.java +++ b/src/test/java/edu/stanford/protege/webprotege/forms/WebprotegeFormsApiApplicationTests.java @@ -1,12 +1,14 @@ package edu.stanford.protege.webprotege.forms; +import edu.stanford.protege.webprotege.jackson.WebProtegeJacksonApplication; import org.junit.jupiter.api.Test; import org.semanticweb.owlapi.model.OWLDataFactory; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.*; import uk.ac.manchester.cs.owl.owlapi.OWLDataFactoryImpl; @SpringBootTest +@Import(WebProtegeJacksonApplication.class) class WebprotegeFormsApiApplicationTests { @Test diff --git a/src/test/java/edu/stanford/protege/webprotege/forms/data/PrimitiveFormControlDataTest.java b/src/test/java/edu/stanford/protege/webprotege/forms/data/PrimitiveFormControlDataTest.java new file mode 100644 index 0000000..80bc850 --- /dev/null +++ b/src/test/java/edu/stanford/protege/webprotege/forms/data/PrimitiveFormControlDataTest.java @@ -0,0 +1,32 @@ +package edu.stanford.protege.webprotege.forms.data; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.*; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.json.*; +import org.springframework.boot.test.json.JacksonTester; + +import java.io.IOException; + +import static org.assertj.core.api.Assertions.assertThat; + +@JsonTest +@AutoConfigureJsonTesters +class PrimitiveFormControlDataTest { + + @Autowired + private JacksonTester tester; + + @BeforeEach + void setUp() { + JacksonTester.initFields(this, new ObjectMapper()); + } + + @Test + void shouldSerializeBooleanLiteral() throws IOException { + var data = PrimitiveFormControlData.get(true); + var written = tester.write(data); + assertThat(written).hasJsonPathStringValue("value", "true"); + System.out.println(written.getJson()); + } +} \ No newline at end of file diff --git a/src/test/java/edu/stanford/protege/webprotege/forms/field/ChoiceDescriptorTest.java b/src/test/java/edu/stanford/protege/webprotege/forms/field/ChoiceDescriptorTest.java new file mode 100644 index 0000000..b203556 --- /dev/null +++ b/src/test/java/edu/stanford/protege/webprotege/forms/field/ChoiceDescriptorTest.java @@ -0,0 +1,30 @@ +package edu.stanford.protege.webprotege.forms.field; + +import edu.stanford.protege.webprotege.common.LanguageMap; +import edu.stanford.protege.webprotege.forms.data.PrimitiveFormControlData; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.json.*; +import org.springframework.boot.test.json.JacksonTester; + +import java.io.IOException; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.*; + +@JsonTest +@AutoConfigureJsonTesters +class ChoiceDescriptorTest { + + @Autowired + private JacksonTester tester; + + @Test + void shouldSerialize() throws IOException { + var written = tester.write(ChoiceDescriptor.choice(LanguageMap.empty(), + PrimitiveFormControlData.get("TextValue"))); + System.out.println(written.getJson()); + assertThat(written).hasJsonPathValue("label"); + assertThat(written).hasJsonPathValue("value"); + } +} \ No newline at end of file diff --git a/src/test/java/edu/stanford/protege/webprotege/forms/field/DynamicChoiceListSourceDescriptorTest.java b/src/test/java/edu/stanford/protege/webprotege/forms/field/DynamicChoiceListSourceDescriptorTest.java new file mode 100644 index 0000000..891b2b0 --- /dev/null +++ b/src/test/java/edu/stanford/protege/webprotege/forms/field/DynamicChoiceListSourceDescriptorTest.java @@ -0,0 +1,38 @@ +package edu.stanford.protege.webprotege.forms.field; + +import edu.stanford.protege.webprotege.criteria.*; +import org.junit.jupiter.api.*; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.json.*; +import org.springframework.boot.test.json.JacksonTester; + +import java.io.*; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.*; + +@JsonTest +@AutoConfigureJsonTesters +class DynamicChoiceListSourceDescriptorTest { + + @Autowired + private JacksonTester tester; + + @Test + void shouldSerialize() throws IOException { + var written = tester.write(DynamicChoiceListSourceDescriptor.get(CompositeRootCriteria.get(List.of(), MultiMatchType.ALL))); + System.out.println(written.getJson()); + assertThat(written).hasJsonPathStringValue("type", "Dynamic"); + assertThat(written).hasJsonPathValue("criteria"); + } + + @Test + void shouldDeserialize() throws IOException { + var json = """ + {"type":"Dynamic","criteria":{"match":"CompositeCriteria","criteria":[],"matchType":"ALL"}} + """; + var read = tester.read(new StringReader(json)); + assertThat(read).isInstanceOf(DynamicChoiceListSourceDescriptor.class); + } +} \ No newline at end of file diff --git a/src/test/java/edu/stanford/protege/webprotege/forms/field/EntityNameControlDescriptorTest.java b/src/test/java/edu/stanford/protege/webprotege/forms/field/EntityNameControlDescriptorTest.java new file mode 100644 index 0000000..2b2f549 --- /dev/null +++ b/src/test/java/edu/stanford/protege/webprotege/forms/field/EntityNameControlDescriptorTest.java @@ -0,0 +1,32 @@ +package edu.stanford.protege.webprotege.forms.field; + +import edu.stanford.protege.webprotege.common.LanguageMap; +import edu.stanford.protege.webprotege.criteria.*; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.json.*; +import org.springframework.boot.test.json.JacksonTester; + +import java.io.IOException; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.*; + +@JsonTest +@AutoConfigureJsonTesters +class EntityNameControlDescriptorTest { + + @Autowired + private JacksonTester tester; + + @Test + public void shouldSerialize() throws IOException { + var descriptor = EntityNameControlDescriptor.get(LanguageMap.empty(), + CompositeRootCriteria.get(List.of(), MultiMatchType.ALL)); + var written = tester.write(descriptor); + System.out.println(written.getJson()); + assertThat(written).hasJsonPathValue("placeholder"); + assertThat(written).hasJsonPathValue("criteria"); + } +} \ No newline at end of file diff --git a/src/test/java/edu/stanford/protege/webprotege/forms/field/FixedChoiceListSourceDescriptorTest.java b/src/test/java/edu/stanford/protege/webprotege/forms/field/FixedChoiceListSourceDescriptorTest.java new file mode 100644 index 0000000..129add8 --- /dev/null +++ b/src/test/java/edu/stanford/protege/webprotege/forms/field/FixedChoiceListSourceDescriptorTest.java @@ -0,0 +1,39 @@ +package edu.stanford.protege.webprotege.forms.field; + +import com.google.common.collect.ImmutableList; +import edu.stanford.protege.webprotege.criteria.*; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.json.*; +import org.springframework.boot.test.json.JacksonTester; + +import java.io.*; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.*; + +@JsonTest +@AutoConfigureJsonTesters +class FixedChoiceListSourceDescriptorTest { + + @Autowired + private JacksonTester tester; + + @Test + void shouldSerialize() throws IOException { + var written = tester.write(FixedChoiceListSourceDescriptor.get(ImmutableList.of())); + System.out.println(written.getJson()); + assertThat(written).hasJsonPathStringValue("type", "Dynamic"); + assertThat(written).hasJsonPathValue("choices"); + } + + @Test + void shouldDeserialize() throws IOException { + var json = """ + {"type":"Fixed","choices":[]} + """; + var read = tester.read(new StringReader(json)); + assertThat(read).isInstanceOf(FixedChoiceListSourceDescriptor.class); + } +} \ No newline at end of file diff --git a/src/test/java/edu/stanford/protege/webprotege/forms/field/FormDescriptorTest.java b/src/test/java/edu/stanford/protege/webprotege/forms/field/FormDescriptorTest.java new file mode 100644 index 0000000..396ec79 --- /dev/null +++ b/src/test/java/edu/stanford/protege/webprotege/forms/field/FormDescriptorTest.java @@ -0,0 +1,38 @@ +package edu.stanford.protege.webprotege.forms.field; + +import com.google.common.collect.ImmutableList; +import edu.stanford.protege.webprotege.common.LanguageMap; +import edu.stanford.protege.webprotege.forms.*; +import org.junit.jupiter.api.Test; +import org.semanticweb.owlapi.model.EntityType; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.json.*; +import org.springframework.boot.test.json.JacksonTester; + +import java.io.IOException; +import java.util.*; + +import static org.assertj.core.api.Assertions.assertThat; + +@JsonTest +@AutoConfigureJsonTesters +class FormDescriptorTest { + + @Autowired + private JacksonTester tester; + + @Test + void shouldSerialize() throws IOException { + var descriptor = new FormDescriptor( + FormId.generate(), + LanguageMap.empty(), + List.of(), + Optional.empty() + ); + var written = tester.write(descriptor); + System.out.println(written.getJson()); + assertThat(written).hasJsonPathMapValue("label"); + assertThat(written).hasJsonPathArrayValue("fields"); + assertThat(written).hasJsonPath("subjectFactory"); + } +} \ No newline at end of file diff --git a/src/test/java/edu/stanford/protege/webprotege/forms/field/FormFieldDescriptorTest.java b/src/test/java/edu/stanford/protege/webprotege/forms/field/FormFieldDescriptorTest.java new file mode 100644 index 0000000..4806a90 --- /dev/null +++ b/src/test/java/edu/stanford/protege/webprotege/forms/field/FormFieldDescriptorTest.java @@ -0,0 +1,57 @@ +package edu.stanford.protege.webprotege.forms.field; + +import edu.stanford.protege.webprotege.common.LanguageMap; +import edu.stanford.protege.webprotege.forms.ExpansionState; +import edu.stanford.protege.webprotege.jackson.WebProtegeJacksonApplication; +import org.junit.jupiter.api.Test; +import org.semanticweb.owlapi.model.IRI; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.json.*; +import org.springframework.boot.test.json.JacksonTester; +import org.springframework.context.annotation.Import; +import uk.ac.manchester.cs.owl.owlapi.OWLAnnotationPropertyImpl; + +import java.io.IOException; +import java.util.UUID; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.*; + +@JsonTest +@AutoConfigureJsonTesters +@Import(WebProtegeJacksonApplication.class) +class FormFieldDescriptorTest { + + @Autowired + private JacksonTester tester; + + @Test + void shouldSerialize() throws IOException { + var descriptor = FormFieldDescriptor.get( + FormFieldId.get(UUID.randomUUID().toString()), + OwlPropertyBinding.get(new OWLAnnotationPropertyImpl(IRI.create("http://example.org"))), + LanguageMap.empty(), + FieldRun.START, + FormFieldDeprecationStrategy.DELETE_VALUES, + EntityNameControlDescriptor.getDefault(), + Repeatability.NON_REPEATABLE, + Optionality.OPTIONAL, + true, + ExpansionState.COLLAPSED, + LanguageMap.empty() + ); + var written = tester.write(descriptor); + System.out.println(written.getJson()); + assertThat(written).hasJsonPathStringValue("id"); + assertThat(written).hasJsonPathValue("owlBinding"); + assertThat(written).hasJsonPathValue("label"); + assertThat(written).hasJsonPathValue("fieldRun"); + assertThat(written).hasJsonPathValue("deprecationStrategy"); + assertThat(written).hasJsonPathValue("control"); + assertThat(written).hasJsonPathValue("repeatability"); + assertThat(written).hasJsonPathValue("optionality"); + assertThat(written).hasJsonPathValue("readOnly"); + assertThat(written).hasJsonPathValue("initialExpansionState"); + assertThat(written).hasJsonPathValue("help"); + } +} \ No newline at end of file diff --git a/src/test/java/edu/stanford/protege/webprotege/forms/field/GridColumnDescriptor_Serialization_Test.java b/src/test/java/edu/stanford/protege/webprotege/forms/field/GridColumnDescriptor_Serialization_Test.java index a4a3fae..fb1fe51 100644 --- a/src/test/java/edu/stanford/protege/webprotege/forms/field/GridColumnDescriptor_Serialization_Test.java +++ b/src/test/java/edu/stanford/protege/webprotege/forms/field/GridColumnDescriptor_Serialization_Test.java @@ -1,18 +1,51 @@ package edu.stanford.protege.webprotege.forms.field; import edu.stanford.protege.webprotege.common.LanguageMap; +import edu.stanford.protege.webprotege.jackson.WebProtegeJacksonApplication; +import org.junit.jupiter.api.Test; +import org.semanticweb.owlapi.model.IRI; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.json.*; +import org.springframework.boot.test.json.JacksonTester; +import org.springframework.context.annotation.Import; +import uk.ac.manchester.cs.owl.owlapi.OWLAnnotationPropertyImpl; import java.io.IOException; import java.util.UUID; +import static org.assertj.core.api.Assertions.assertThat; + /** * Matthew Horridge * Stanford Center for Biomedical Informatics Research * 2020-05-05 */ +@JsonTest +@AutoConfigureJsonTesters +@Import(WebProtegeJacksonApplication.class) public class GridColumnDescriptor_Serialization_Test { - private GridColumnDescriptor descriptor; + @Autowired + private JacksonTester tester; + @Test + void shouldSerialize() throws IOException { + var descriptor = GridColumnDescriptor.get( + GridColumnId.get("12345678-1234-1234-1234-123456789abc"), + Optionality.OPTIONAL, + Repeatability.NON_REPEATABLE, + OwlPropertyBinding.get(new OWLAnnotationPropertyImpl(IRI.create("http://example.org/p"))), + LanguageMap.empty(), + EntityNameControlDescriptor.getDefault() + ); + var written = tester.write(descriptor); + System.out.println(written.getJson()); + assertThat(written).hasJsonPathStringValue("id", "12345678-1234-1234-1234-123456789abc"); + assertThat(written).hasJsonPathValue("optionality"); + assertThat(written).hasJsonPathValue("repeatability"); + assertThat(written).hasJsonPathValue("owlBinding"); + assertThat(written).hasJsonPathValue("label"); + assertThat(written).hasJsonPathValue("control"); + } } diff --git a/src/test/java/edu/stanford/protege/webprotege/forms/field/GridControlDescriptor_Serialization_TestCase.java b/src/test/java/edu/stanford/protege/webprotege/forms/field/GridControlDescriptor_Serialization_TestCase.java index adfbc9f..a4a501b 100644 --- a/src/test/java/edu/stanford/protege/webprotege/forms/field/GridControlDescriptor_Serialization_TestCase.java +++ b/src/test/java/edu/stanford/protege/webprotege/forms/field/GridControlDescriptor_Serialization_TestCase.java @@ -2,39 +2,37 @@ import com.google.common.collect.ImmutableList; import edu.stanford.protege.webprotege.common.LanguageMap; +import edu.stanford.protege.webprotege.jackson.WebProtegeJacksonApplication; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.json.*; +import org.springframework.boot.test.json.JacksonTester; +import org.springframework.context.annotation.Import; import java.io.IOException; -import java.util.UUID; +import java.util.*; + +import static org.assertj.core.api.Assertions.assertThat; /** * Matthew Horridge * Stanford Center for Biomedical Informatics Research * 2020-05-05 */ +@JsonTest +@AutoConfigureJsonTesters +@Import(WebProtegeJacksonApplication.class) public class GridControlDescriptor_Serialization_TestCase { - private GridControlDescriptor descriptor; + @Autowired + private JacksonTester tester; -// @Before -// public void setUp() { -// descriptor = GridControlDescriptor.get( -// ImmutableList.of( -// GridColumnDescriptor.get( -// GridColumnId.get(UUID.randomUUID().toString()), -// Optionality.OPTIONAL, -// Repeatability.NON_REPEATABLE, -// null, -// LanguageMap.empty(), -// TextControlDescriptor.getDefault() -// ) -// ), -// null -// ); -// } -// -// @Test -// public void shouldRoundTrip() throws IOException { -// JsonSerializationTestUtil.testSerialization(descriptor, FormControlDescriptor.class); -// } + @Test + void shouldSerialize() throws IOException { + var written = tester.write(GridControlDescriptor.get(ImmutableList.of(), null)); + System.out.println(written.getJson()); + assertThat(written).hasJsonPathArrayValue("columns"); + assertThat(written).hasJsonPathMapValue("subjectFactory"); + } } diff --git a/src/test/java/edu/stanford/protege/webprotege/forms/field/MultiChoiceControlDescriptor_Serialization_TestCase.java b/src/test/java/edu/stanford/protege/webprotege/forms/field/MultiChoiceControlDescriptor_Serialization_TestCase.java index c5d6582..bc51443 100644 --- a/src/test/java/edu/stanford/protege/webprotege/forms/field/MultiChoiceControlDescriptor_Serialization_TestCase.java +++ b/src/test/java/edu/stanford/protege/webprotege/forms/field/MultiChoiceControlDescriptor_Serialization_TestCase.java @@ -3,38 +3,44 @@ import com.google.common.collect.ImmutableList; import edu.stanford.protege.webprotege.forms.data.LiteralFormControlData; import edu.stanford.protege.webprotege.common.LanguageMap; +import edu.stanford.protege.webprotege.jackson.WebProtegeJacksonApplication; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.json.*; +import org.springframework.boot.test.json.JacksonTester; +import org.springframework.context.annotation.Import; import java.io.IOException; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; /** * Matthew Horridge * Stanford Center for Biomedical Informatics Research * 2020-01-08 */ +@JsonTest +@AutoConfigureJsonTesters +@Import(WebProtegeJacksonApplication.class) public class MultiChoiceControlDescriptor_Serialization_TestCase { - private ImmutableList choices; + @Autowired + private JacksonTester tester; @BeforeEach public void setUp() { - choices = ImmutableList.of( -// ChoiceDescriptor.choice(LanguageMap.empty(), -// LiteralFormControlData.get(DataFactory.getOWLLiteral("A"))), -// ChoiceDescriptor.choice(LanguageMap.empty(), -// LiteralFormControlData.get(DataFactory.getOWLLiteral("B"))) - ); + } @Test public void shouldSerialize_AnnotationComponentCriteria() throws IOException { - testSerialization( - MultiChoiceControlDescriptor.get(FixedChoiceListSourceDescriptor.get(choices), ImmutableList.of()) - ); + var descriptor = MultiChoiceControlDescriptor.get(FixedChoiceListSourceDescriptor.get(List.of()), ImmutableList.of()); + var written = tester.write(descriptor); + System.out.println(written.getJson()); + assertThat(written).hasJsonPathMapValue("source"); + assertThat(written).hasJsonPathArrayValue("defaultChoices"); } - private static void testSerialization(V value) throws IOException { -// JsonSerializationTestUtil.testSerialization(value, MultiChoiceControlDescriptor.class); - } } diff --git a/src/test/java/edu/stanford/protege/webprotege/forms/field/TextControlDescriptorTest.java b/src/test/java/edu/stanford/protege/webprotege/forms/field/TextControlDescriptorTest.java new file mode 100644 index 0000000..892bf4f --- /dev/null +++ b/src/test/java/edu/stanford/protege/webprotege/forms/field/TextControlDescriptorTest.java @@ -0,0 +1,38 @@ +package edu.stanford.protege.webprotege.forms.field; + +import com.fasterxml.jackson.databind.ObjectMapper; +import edu.stanford.protege.webprotege.common.LanguageMap; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.json.*; +import org.springframework.boot.test.json.JacksonTester; + +import java.io.IOException; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.*; + +@JsonTest +@AutoConfigureJsonTesters +class TextControlDescriptorTest { + + @Autowired + private JacksonTester tester; + + @Test + public void shouldSerialize() throws IOException { + var descriptor = new TextControlDescriptor(LanguageMap.of("en", "The placeholder"), + StringType.SPECIFIC_LANG_STRING, + "en", + LineMode.SINGLE_LINE, + "Pattern", + LanguageMap.of("en", "An error message")); + var written = tester.write(descriptor); + System.out.println(written.getJson()); + assertThat(written).hasJsonPathValue("placeholder"); + assertThat(written).hasJsonPathStringValue("stringType", "SPECIFIC_LANG_STRING"); + assertThat(written).hasJsonPathStringValue("specificLangTag", "en"); + assertThat(written).hasJsonPathStringValue("lineMode", "SINGLE_LINE"); + assertThat(written).hasJsonPathValue("patternViolationErrorMessage"); + } +} \ No newline at end of file