ProfileSelectControlById.java

package gov.nist.secauto.oscal.lib.model;

import gov.nist.secauto.metaschema.binding.model.annotations.AllowedValue;
import gov.nist.secauto.metaschema.binding.model.annotations.AllowedValues;
import gov.nist.secauto.metaschema.binding.model.annotations.BoundAssembly;
import gov.nist.secauto.metaschema.binding.model.annotations.BoundField;
import gov.nist.secauto.metaschema.binding.model.annotations.BoundFieldValue;
import gov.nist.secauto.metaschema.binding.model.annotations.BoundFlag;
import gov.nist.secauto.metaschema.binding.model.annotations.GroupAs;
import gov.nist.secauto.metaschema.binding.model.annotations.MetaschemaAssembly;
import gov.nist.secauto.metaschema.binding.model.annotations.ValueConstraints;
import gov.nist.secauto.metaschema.model.common.JsonGroupAsBehavior;
import gov.nist.secauto.metaschema.model.common.constraint.IConstraint;
import gov.nist.secauto.metaschema.model.common.datatype.adapter.TokenAdapter;
import gov.nist.secauto.metaschema.model.common.util.ObjectUtils;
import gov.nist.secauto.oscal.lib.model.control.profile.AbstractProfileSelectControlById;
import java.lang.Override;
import java.lang.String;
import java.util.LinkedList;
import java.util.List;
import org.apache.commons.lang3.builder.MultilineRecursiveToStringStyle;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;

/**
 * Select a control or controls from an imported control set.
 */
@MetaschemaAssembly(
    formalName = "Select Control",
    description = "Select a control or controls from an imported control set.",
    name = "select-control-by-id",
    metaschema = OscalProfileMetaschema.class,
    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."
)
public class ProfileSelectControlById extends AbstractProfileSelectControlById {
  @BoundFlag(
      formalName = "Include Contained Controls with Control",
      description = "When a control is included, whether its child (dependent) controls are also included.",
      useName = "with-child-controls",
      typeAdapter = TokenAdapter.class
  )
  @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.")})
  )
  private String _withChildControls;

  @BoundField(
      formalName = "Match Controls by Identifier",
      description = "Selecting a control by its ID given as a literal.",
      useName = "with-id",
      maxOccurs = -1
  )
  @BoundFieldValue(
      typeAdapter = TokenAdapter.class
  )
  @GroupAs(
      name = "with-ids",
      inJson = JsonGroupAsBehavior.LIST
  )
  private List<String> _withIds;

  @BoundAssembly(
      formalName = "Match Controls by Pattern",
      description = "Selecting a set of controls by matching their IDs with a wildcard pattern.",
      useName = "matching",
      maxOccurs = -1
  )
  @GroupAs(
      name = "matching",
      inJson = JsonGroupAsBehavior.LIST
  )
  private List<Matching> _matching;

  public ProfileSelectControlById() {
  }

  public String getWithChildControls() {
    return _withChildControls;
  }

  public void setWithChildControls(String value) {
    _withChildControls = value;
  }

  public List<String> getWithIds() {
    return _withIds;
  }

  public void setWithIds(List<String> value) {
    _withIds = value;
  }

  /**
   * Add a new {@link String} item to the underlying collection.
   * @param item the item to add
   * @return {@code true}
   */
  public boolean addWithId(String item) {
    String value = ObjectUtils.requireNonNull(item,"item cannot be null");
    if (_withIds == null) {
      _withIds = new LinkedList<>();
    }
    return _withIds.add(value);
  }

  /**
   * Remove the first matching {@link String} item from the underlying collection.
   * @param item the item to remove
   * @return {@code true} if the item was removed or {@code false} otherwise
   */
  public boolean removeWithId(String item) {
    String value = ObjectUtils.requireNonNull(item,"item cannot be null");
    return _withIds == null ? false : _withIds.remove(value);
  }

  public List<Matching> getMatching() {
    return _matching;
  }

  public void setMatching(List<Matching> value) {
    _matching = value;
  }

  /**
   * Add a new {@link Matching} item to the underlying collection.
   * @param item the item to add
   * @return {@code true}
   */
  public boolean addMatching(Matching item) {
    Matching value = ObjectUtils.requireNonNull(item,"item cannot be null");
    if (_matching == null) {
      _matching = new LinkedList<>();
    }
    return _matching.add(value);
  }

  /**
   * Remove the first matching {@link Matching} item from the underlying collection.
   * @param item the item to remove
   * @return {@code true} if the item was removed or {@code false} otherwise
   */
  public boolean removeMatching(Matching item) {
    Matching value = ObjectUtils.requireNonNull(item,"item cannot be null");
    return _matching == null ? false : _matching.remove(value);
  }

  @Override
  public String toString() {
    return new ReflectionToStringBuilder(this, MultilineRecursiveToStringStyle.MULTI_LINE_STYLE).toString();
  }
}