001package com.example.metaschema; 002 003import gov.nist.secauto.metaschema.core.model.IBoundObject; 004import gov.nist.secauto.metaschema.core.model.IMetaschemaData; 005import gov.nist.secauto.metaschema.core.model.JsonGroupAsBehavior; 006import gov.nist.secauto.metaschema.core.util.ObjectUtils; 007import gov.nist.secauto.metaschema.databind.model.annotations.BoundAssembly; 008import gov.nist.secauto.metaschema.databind.model.annotations.BoundChoiceGroup; 009import gov.nist.secauto.metaschema.databind.model.annotations.BoundGroupedAssembly; 010import gov.nist.secauto.metaschema.databind.model.annotations.GroupAs; 011import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaAssembly; 012import java.lang.Object; 013import java.lang.Override; 014import java.lang.String; 015import java.util.LinkedList; 016import java.util.List; 017import org.apache.commons.lang3.builder.ReflectionToStringBuilder; 018import org.apache.commons.lang3.builder.ToStringStyle; 019 020@MetaschemaAssembly( 021 name = "field-constraints", 022 moduleClass = MetaschemaModelModule.class 023) 024public class FieldConstraints implements IBoundObject { 025 private final IMetaschemaData __metaschemaData; 026 027 @BoundAssembly( 028 formalName = "Constraint Let Expression", 029 useName = "let", 030 maxOccurs = -1, 031 groupAs = @GroupAs(name = "lets", inJson = JsonGroupAsBehavior.LIST) 032 ) 033 private List<ConstraintLetExpression> _lets; 034 035 @BoundChoiceGroup( 036 minOccurs = 1, 037 maxOccurs = -1, 038 assemblies = { 039 @BoundGroupedAssembly(formalName = "Allowed Values Constraint", useName = "allowed-values", binding = TargetedAllowedValuesConstraint.class), 040 @BoundGroupedAssembly(formalName = "Expect Condition Constraint", useName = "expect", binding = TargetedExpectConstraint.class), 041 @BoundGroupedAssembly(formalName = "Targeted Index Has Key Constraint", useName = "index-has-key", binding = TargetedIndexHasKeyConstraint.class), 042 @BoundGroupedAssembly(formalName = "Value Matches Constraint", useName = "matches", binding = TargetedMatchesConstraint.class) 043 }, 044 groupAs = @GroupAs(name = "rules", inJson = JsonGroupAsBehavior.LIST) 045 ) 046 private List<Object> _rules; 047 048 public FieldConstraints() { 049 this(null); 050 } 051 052 public FieldConstraints(IMetaschemaData data) { 053 this.__metaschemaData = data; 054 } 055 056 @Override 057 public IMetaschemaData getMetaschemaData() { 058 return __metaschemaData; 059 } 060 061 public List<ConstraintLetExpression> getLets() { 062 return _lets; 063 } 064 065 public void setLets(List<ConstraintLetExpression> value) { 066 _lets = value; 067 } 068 069 /** 070 * Add a new {@link ConstraintLetExpression} item to the underlying collection. 071 * @param item the item to add 072 * @return {@code true} 073 */ 074 public boolean addLet(ConstraintLetExpression item) { 075 ConstraintLetExpression value = ObjectUtils.requireNonNull(item,"item cannot be null"); 076 if (_lets == null) { 077 _lets = new LinkedList<>(); 078 } 079 return _lets.add(value); 080 } 081 082 /** 083 * Remove the first matching {@link ConstraintLetExpression} item from the underlying collection. 084 * @param item the item to remove 085 * @return {@code true} if the item was removed or {@code false} otherwise 086 */ 087 public boolean removeLet(ConstraintLetExpression item) { 088 ConstraintLetExpression value = ObjectUtils.requireNonNull(item,"item cannot be null"); 089 return _lets != null && _lets.remove(value); 090 } 091 092 public List<Object> getRules() { 093 return _rules; 094 } 095 096 public void setRules(List<Object> value) { 097 _rules = value; 098 } 099 100 @Override 101 public String toString() { 102 return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString(); 103 } 104}