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.BoundField;
013import gov.nist.secauto.metaschema.databind.model.annotations.BoundFlag;
014import gov.nist.secauto.metaschema.databind.model.annotations.GroupAs;
015import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaAssembly;
016import gov.nist.secauto.metaschema.databind.model.annotations.ValueConstraints;
017import java.lang.Override;
018import java.lang.String;
019import java.util.LinkedList;
020import java.util.List;
021import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
022import org.apache.commons.lang3.builder.ToStringStyle;
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    moduleClass = OscalMappingCommonModule.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 SelectControlById implements IBoundObject {
035  private final IMetaschemaData __metaschemaData;
036
037  /**
038   * "When a control is included, whether its child (dependent) controls are also included."
039   */
040  @BoundFlag(
041      formalName = "Include Contained Controls with Control",
042      description = "When a control is included, whether its child (dependent) controls are also included.",
043      name = "with-child-controls",
044      typeAdapter = TokenAdapter.class,
045      valueConstraints = @ValueConstraints(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.")}))
046  )
047  private String _withChildControls;
048
049  @BoundField(
050      formalName = "Match Controls by Identifier",
051      description = "Selecting a control by its ID given as a literal.",
052      useName = "with-id",
053      maxOccurs = -1,
054      groupAs = @GroupAs(name = "with-ids", inJson = JsonGroupAsBehavior.LIST),
055      typeAdapter = TokenAdapter.class
056  )
057  private List<String> _withIds;
058
059  @BoundAssembly(
060      formalName = "Match Controls by Pattern",
061      description = "Selecting a set of controls by matching their IDs with a wildcard pattern.",
062      useName = "matching",
063      maxOccurs = -1,
064      groupAs = @GroupAs(name = "matching", inJson = JsonGroupAsBehavior.LIST)
065  )
066  private List<MappedControlMatching> _matching;
067
068  public SelectControlById() {
069    this(null);
070  }
071
072  public SelectControlById(IMetaschemaData data) {
073    this.__metaschemaData = data;
074  }
075
076  @Override
077  public IMetaschemaData getMetaschemaData() {
078    return __metaschemaData;
079  }
080
081  public String getWithChildControls() {
082    return _withChildControls;
083  }
084
085  public void setWithChildControls(String value) {
086    _withChildControls = value;
087  }
088
089  public List<String> getWithIds() {
090    return _withIds;
091  }
092
093  public void setWithIds(List<String> value) {
094    _withIds = value;
095  }
096
097  /**
098   * Add a new {@link String} item to the underlying collection.
099   * @param item the item to add
100   * @return {@code true}
101   */
102  public boolean addWithId(String item) {
103    String value = ObjectUtils.requireNonNull(item,"item cannot be null");
104    if (_withIds == null) {
105      _withIds = new LinkedList<>();
106    }
107    return _withIds.add(value);
108  }
109
110  /**
111   * Remove the first matching {@link String} item from the underlying collection.
112   * @param item the item to remove
113   * @return {@code true} if the item was removed or {@code false} otherwise
114   */
115  public boolean removeWithId(String item) {
116    String value = ObjectUtils.requireNonNull(item,"item cannot be null");
117    return _withIds != null && _withIds.remove(value);
118  }
119
120  public List<MappedControlMatching> getMatching() {
121    return _matching;
122  }
123
124  public void setMatching(List<MappedControlMatching> value) {
125    _matching = value;
126  }
127
128  /**
129   * Add a new {@link MappedControlMatching} item to the underlying collection.
130   * @param item the item to add
131   * @return {@code true}
132   */
133  public boolean addMatching(MappedControlMatching item) {
134    MappedControlMatching value = ObjectUtils.requireNonNull(item,"item cannot be null");
135    if (_matching == null) {
136      _matching = new LinkedList<>();
137    }
138    return _matching.add(value);
139  }
140
141  /**
142   * Remove the first matching {@link MappedControlMatching} item from the underlying collection.
143   * @param item the item to remove
144   * @return {@code true} if the item was removed or {@code false} otherwise
145   */
146  public boolean removeMatching(MappedControlMatching item) {
147    MappedControlMatching value = ObjectUtils.requireNonNull(item,"item cannot be null");
148    return _matching != null && _matching.remove(value);
149  }
150
151  @Override
152  public String toString() {
153    return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString();
154  }
155}