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 groupAs = @GroupAs(name = "rules", inJson = JsonGroupAsBehavior.LIST), 039 assemblies = { 040 @BoundGroupedAssembly(formalName = "Allowed Values Constraint", useName = "allowed-values", binding = TargetedAllowedValuesConstraint.class), 041 @BoundGroupedAssembly(formalName = "Expect Condition Constraint", useName = "expect", binding = TargetedExpectConstraint.class), 042 @BoundGroupedAssembly(formalName = "Targeted Index Has Key Constraint", useName = "index-has-key", binding = TargetedIndexHasKeyConstraint.class), 043 @BoundGroupedAssembly(formalName = "Value Matches Constraint", useName = "matches", binding = TargetedMatchesConstraint.class), 044 @BoundGroupedAssembly(formalName = "Report Condition Constraint", useName = "report", binding = TargetedReportConstraint.class) 045 } 046 ) 047 private List<Object> _rules; 048 049 public FieldConstraints() { 050 this(null); 051 } 052 053 public FieldConstraints(IMetaschemaData data) { 054 this.__metaschemaData = data; 055 } 056 057 @Override 058 public IMetaschemaData getMetaschemaData() { 059 return __metaschemaData; 060 } 061 062 public List<ConstraintLetExpression> getLets() { 063 return _lets; 064 } 065 066 public void setLets(List<ConstraintLetExpression> value) { 067 _lets = value; 068 } 069 070 /** 071 * Add a new {@link ConstraintLetExpression} item to the underlying collection. 072 * @param item the item to add 073 * @return {@code true} 074 */ 075 public boolean addLet(ConstraintLetExpression item) { 076 ConstraintLetExpression value = ObjectUtils.requireNonNull(item,"item cannot be null"); 077 if (_lets == null) { 078 _lets = new LinkedList<>(); 079 } 080 return _lets.add(value); 081 } 082 083 /** 084 * Remove the first matching {@link ConstraintLetExpression} item from the underlying collection. 085 * @param item the item to remove 086 * @return {@code true} if the item was removed or {@code false} otherwise 087 */ 088 public boolean removeLet(ConstraintLetExpression item) { 089 ConstraintLetExpression value = ObjectUtils.requireNonNull(item,"item cannot be null"); 090 return _lets != null && _lets.remove(value); 091 } 092 093 public List<Object> getRules() { 094 return _rules; 095 } 096 097 public void setRules(List<Object> value) { 098 _rules = value; 099 } 100 101 @Override 102 public String toString() { 103 return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString(); 104 } 105}