001package gov.nist.secauto.oscal.lib.model;
002
003import gov.nist.secauto.metaschema.core.datatype.adapter.TokenAdapter;
004import gov.nist.secauto.metaschema.core.model.IBoundObject;
005import gov.nist.secauto.metaschema.core.model.IMetaschemaData;
006import gov.nist.secauto.metaschema.core.model.JsonGroupAsBehavior;
007import gov.nist.secauto.metaschema.core.model.constraint.IConstraint;
008import gov.nist.secauto.metaschema.core.util.ObjectUtils;
009import gov.nist.secauto.metaschema.databind.model.annotations.AllowedValue;
010import gov.nist.secauto.metaschema.databind.model.annotations.AllowedValues;
011import gov.nist.secauto.metaschema.databind.model.annotations.BoundAssembly;
012import gov.nist.secauto.metaschema.databind.model.annotations.BoundFlag;
013import gov.nist.secauto.metaschema.databind.model.annotations.GroupAs;
014import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaAssembly;
015import gov.nist.secauto.metaschema.databind.model.annotations.ValueConstraints;
016import java.lang.Override;
017import java.lang.String;
018import java.util.LinkedList;
019import java.util.List;
020import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
021import org.apache.commons.lang3.builder.ToStringStyle;
022
023/**
024 * Specifies which controls to use in the containing context.
025 */
026@MetaschemaAssembly(
027    formalName = "Insert Controls",
028    description = "Specifies which controls to use in the containing context.",
029    name = "insert-controls",
030    moduleClass = OscalProfileModule.class,
031    remarks = "To be schema-valid, this element must contain either (but not both) a single `include-all` directive, or a sequence of `include-controls` directives.\n"
032            + "\n"
033            + "If this directive is not provided, then no controls are to be inserted; i.e., all controls are included explicitly."
034)
035public class InsertControls implements IBoundObject {
036  private final IMetaschemaData __metaschemaData;
037
038  /**
039   * "A designation of how a selection of controls in a profile is to be ordered."
040   */
041  @BoundFlag(
042      formalName = "Order",
043      description = "A designation of how a selection of controls in a profile is to be ordered.",
044      name = "order",
045      typeAdapter = TokenAdapter.class,
046      valueConstraints = @ValueConstraints(allowedValues = @AllowedValues(level = IConstraint.Level.ERROR, values = {@AllowedValue(value = "keep", description = ""), @AllowedValue(value = "ascending", description = ""), @AllowedValue(value = "descending", description = "")}))
047  )
048  private String _order;
049
050  @BoundAssembly(
051      formalName = "Include All",
052      description = "Include all controls from the imported catalog or profile resources.",
053      useName = "include-all",
054      minOccurs = 1
055  )
056  private IncludeAll _includeAll;
057
058  @BoundAssembly(
059      formalName = "Select Control",
060      description = "Select a control or controls from an imported control set.",
061      useName = "include-controls",
062      minOccurs = 1,
063      maxOccurs = -1,
064      groupAs = @GroupAs(name = "include-controls", inJson = JsonGroupAsBehavior.LIST)
065  )
066  private List<ProfileSelectControlById> _includeControls;
067
068  @BoundAssembly(
069      formalName = "Select Control",
070      description = "Select a control or controls from an imported control set.",
071      useName = "exclude-controls",
072      remarks = "Identifies which controls to exclude, or eliminate, from the set of matching includes.",
073      maxOccurs = -1,
074      groupAs = @GroupAs(name = "exclude-controls", inJson = JsonGroupAsBehavior.LIST)
075  )
076  private List<ProfileSelectControlById> _excludeControls;
077
078  public InsertControls() {
079    this(null);
080  }
081
082  public InsertControls(IMetaschemaData data) {
083    this.__metaschemaData = data;
084  }
085
086  @Override
087  public IMetaschemaData getMetaschemaData() {
088    return __metaschemaData;
089  }
090
091  public String getOrder() {
092    return _order;
093  }
094
095  public void setOrder(String value) {
096    _order = value;
097  }
098
099  public IncludeAll getIncludeAll() {
100    return _includeAll;
101  }
102
103  public void setIncludeAll(IncludeAll value) {
104    _includeAll = value;
105  }
106
107  public List<ProfileSelectControlById> getIncludeControls() {
108    return _includeControls;
109  }
110
111  public void setIncludeControls(List<ProfileSelectControlById> value) {
112    _includeControls = value;
113  }
114
115  /**
116   * Add a new {@link ProfileSelectControlById} item to the underlying collection.
117   * @param item the item to add
118   * @return {@code true}
119   */
120  public boolean addIncludeControls(ProfileSelectControlById item) {
121    ProfileSelectControlById value = ObjectUtils.requireNonNull(item,"item cannot be null");
122    if (_includeControls == null) {
123      _includeControls = new LinkedList<>();
124    }
125    return _includeControls.add(value);
126  }
127
128  /**
129   * Remove the first matching {@link ProfileSelectControlById} item from the underlying collection.
130   * @param item the item to remove
131   * @return {@code true} if the item was removed or {@code false} otherwise
132   */
133  public boolean removeIncludeControls(ProfileSelectControlById item) {
134    ProfileSelectControlById value = ObjectUtils.requireNonNull(item,"item cannot be null");
135    return _includeControls != null && _includeControls.remove(value);
136  }
137
138  public List<ProfileSelectControlById> getExcludeControls() {
139    return _excludeControls;
140  }
141
142  public void setExcludeControls(List<ProfileSelectControlById> value) {
143    _excludeControls = value;
144  }
145
146  /**
147   * Add a new {@link ProfileSelectControlById} item to the underlying collection.
148   * @param item the item to add
149   * @return {@code true}
150   */
151  public boolean addExcludeControls(ProfileSelectControlById item) {
152    ProfileSelectControlById value = ObjectUtils.requireNonNull(item,"item cannot be null");
153    if (_excludeControls == null) {
154      _excludeControls = new LinkedList<>();
155    }
156    return _excludeControls.add(value);
157  }
158
159  /**
160   * Remove the first matching {@link ProfileSelectControlById} item from the underlying collection.
161   * @param item the item to remove
162   * @return {@code true} if the item was removed or {@code false} otherwise
163   */
164  public boolean removeExcludeControls(ProfileSelectControlById item) {
165    ProfileSelectControlById value = ObjectUtils.requireNonNull(item,"item cannot be null");
166    return _excludeControls != null && _excludeControls.remove(value);
167  }
168
169  @Override
170  public String toString() {
171    return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString();
172  }
173}