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.BoundField;
007import gov.nist.secauto.metaschema.binding.model.annotations.BoundFieldValue;
008import gov.nist.secauto.metaschema.binding.model.annotations.BoundFlag;
009import gov.nist.secauto.metaschema.binding.model.annotations.GroupAs;
010import gov.nist.secauto.metaschema.binding.model.annotations.MetaschemaAssembly;
011import gov.nist.secauto.metaschema.binding.model.annotations.ValueConstraints;
012import gov.nist.secauto.metaschema.model.common.JsonGroupAsBehavior;
013import gov.nist.secauto.metaschema.model.common.constraint.IConstraint;
014import gov.nist.secauto.metaschema.model.common.datatype.adapter.TokenAdapter;
015import gov.nist.secauto.metaschema.model.common.util.ObjectUtils;
016import gov.nist.secauto.oscal.lib.model.control.profile.AbstractProfileSelectControlById;
017import java.lang.Override;
018import java.lang.String;
019import java.util.LinkedList;
020import java.util.List;
021import org.apache.commons.lang3.builder.MultilineRecursiveToStringStyle;
022import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
023
024/**
025 * Select a control or controls from an imported control set.
026 */
027@MetaschemaAssembly(
028    formalName = "Select Control",
029    description = "Select a control or controls from an imported control set.",
030    name = "select-control-by-id",
031    metaschema = OscalProfileMetaschema.class,
032    remarks = "If `with-child-controls` is \"yes\" on the call to a control, no sibling `call`elements need to be used to call any controls appearing within it. Since generally, this is how control enhancements are represented (as controls within controls), this provides a way to include controls with all their dependent controls (enhancements) without having to call them individually."
033)
034public class ProfileSelectControlById extends AbstractProfileSelectControlById {
035  @BoundFlag(
036      formalName = "Include Contained Controls with Control",
037      description = "When a control is included, whether its child (dependent) controls are also included.",
038      useName = "with-child-controls",
039      typeAdapter = TokenAdapter.class
040  )
041  @ValueConstraints(
042      allowedValues = @AllowedValues(level = IConstraint.Level.ERROR, values = {@AllowedValue(value = "yes", description = "Include child controls with an included control."), @AllowedValue(value = "no", description = "When importing a control, only include child controls that are also explicitly called.")})
043  )
044  private String _withChildControls;
045
046  @BoundField(
047      formalName = "Match Controls by Identifier",
048      description = "Selecting a control by its ID given as a literal.",
049      useName = "with-id",
050      maxOccurs = -1
051  )
052  @BoundFieldValue(
053      typeAdapter = TokenAdapter.class
054  )
055  @GroupAs(
056      name = "with-ids",
057      inJson = JsonGroupAsBehavior.LIST
058  )
059  private List<String> _withIds;
060
061  @BoundAssembly(
062      formalName = "Match Controls by Pattern",
063      description = "Selecting a set of controls by matching their IDs with a wildcard pattern.",
064      useName = "matching",
065      maxOccurs = -1
066  )
067  @GroupAs(
068      name = "matching",
069      inJson = JsonGroupAsBehavior.LIST
070  )
071  private List<Matching> _matching;
072
073  public ProfileSelectControlById() {
074  }
075
076  public String getWithChildControls() {
077    return _withChildControls;
078  }
079
080  public void setWithChildControls(String value) {
081    _withChildControls = value;
082  }
083
084  public List<String> getWithIds() {
085    return _withIds;
086  }
087
088  public void setWithIds(List<String> value) {
089    _withIds = value;
090  }
091
092  /**
093   * Add a new {@link String} item to the underlying collection.
094   * @param item the item to add
095   * @return {@code true}
096   */
097  public boolean addWithId(String item) {
098    String value = ObjectUtils.requireNonNull(item,"item cannot be null");
099    if (_withIds == null) {
100      _withIds = new LinkedList<>();
101    }
102    return _withIds.add(value);
103  }
104
105  /**
106   * Remove the first matching {@link String} item from the underlying collection.
107   * @param item the item to remove
108   * @return {@code true} if the item was removed or {@code false} otherwise
109   */
110  public boolean removeWithId(String item) {
111    String value = ObjectUtils.requireNonNull(item,"item cannot be null");
112    return _withIds == null ? false : _withIds.remove(value);
113  }
114
115  public List<Matching> getMatching() {
116    return _matching;
117  }
118
119  public void setMatching(List<Matching> value) {
120    _matching = value;
121  }
122
123  /**
124   * Add a new {@link Matching} item to the underlying collection.
125   * @param item the item to add
126   * @return {@code true}
127   */
128  public boolean addMatching(Matching item) {
129    Matching value = ObjectUtils.requireNonNull(item,"item cannot be null");
130    if (_matching == null) {
131      _matching = new LinkedList<>();
132    }
133    return _matching.add(value);
134  }
135
136  /**
137   * Remove the first matching {@link Matching} item from the underlying collection.
138   * @param item the item to remove
139   * @return {@code true} if the item was removed or {@code false} otherwise
140   */
141  public boolean removeMatching(Matching item) {
142    Matching value = ObjectUtils.requireNonNull(item,"item cannot be null");
143    return _matching == null ? false : _matching.remove(value);
144  }
145
146  @Override
147  public String toString() {
148    return new ReflectionToStringBuilder(this, MultilineRecursiveToStringStyle.MULTI_LINE_STYLE).toString();
149  }
150}