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