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