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 = "assembly-constraints", 022 moduleClass = MetaschemaModelModule.class 023) 024public class AssemblyConstraints 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 = "Targeted Unique Constraint", useName = "is-unique", binding = TargetedIsUniqueConstraint.class), 045 @BoundGroupedAssembly(formalName = "Targeted Index Constraint", useName = "index", binding = TargetedIndexConstraint.class), 046 @BoundGroupedAssembly(formalName = "Targeted Cardinality Constraint", useName = "has-cardinality", binding = TargetedHasCardinalityConstraint.class), 047 @BoundGroupedAssembly(formalName = "Report Condition Constraint", useName = "report", binding = TargetedReportConstraint.class) 048 } 049 ) 050 private List<Object> _rules; 051 052 public AssemblyConstraints() { 053 this(null); 054 } 055 056 public AssemblyConstraints(IMetaschemaData data) { 057 this.__metaschemaData = data; 058 } 059 060 @Override 061 public IMetaschemaData getMetaschemaData() { 062 return __metaschemaData; 063 } 064 065 public List<ConstraintLetExpression> getLets() { 066 return _lets; 067 } 068 069 public void setLets(List<ConstraintLetExpression> value) { 070 _lets = value; 071 } 072 073 /** 074 * Add a new {@link ConstraintLetExpression} item to the underlying collection. 075 * @param item the item to add 076 * @return {@code true} 077 */ 078 public boolean addLet(ConstraintLetExpression item) { 079 ConstraintLetExpression value = ObjectUtils.requireNonNull(item,"item cannot be null"); 080 if (_lets == null) { 081 _lets = new LinkedList<>(); 082 } 083 return _lets.add(value); 084 } 085 086 /** 087 * Remove the first matching {@link ConstraintLetExpression} item from the underlying collection. 088 * @param item the item to remove 089 * @return {@code true} if the item was removed or {@code false} otherwise 090 */ 091 public boolean removeLet(ConstraintLetExpression item) { 092 ConstraintLetExpression value = ObjectUtils.requireNonNull(item,"item cannot be null"); 093 return _lets != null && _lets.remove(value); 094 } 095 096 public List<Object> getRules() { 097 return _rules; 098 } 099 100 public void setRules(List<Object> value) { 101 _rules = value; 102 } 103 104 @Override 105 public String toString() { 106 return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString(); 107 } 108}