InsertControls.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.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 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;

/**
 * Specifies which controls to use in the containing context.
 */
@MetaschemaAssembly(
    formalName = "Insert Controls",
    description = "Specifies which controls to use in the containing context.",
    name = "insert-controls",
    metaschema = OscalProfileMetaschema.class,
    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"
            + "\n"
            + "If this directive is not provided, then no controls are to be inserted; i.e., all controls are included explicitly."
)
public class InsertControls {
  @BoundFlag(
      formalName = "Order",
      description = "A designation of how a selection of controls in a profile is to be ordered.",
      useName = "order",
      typeAdapter = TokenAdapter.class
  )
  @ValueConstraints(
      allowedValues = @AllowedValues(level = IConstraint.Level.ERROR, values = {@AllowedValue(value = "keep", description = ""), @AllowedValue(value = "ascending", description = ""), @AllowedValue(value = "descending", description = "")})
  )
  private String _order;

  @BoundAssembly(
      formalName = "Include All",
      description = "Include all controls from the imported catalog or profile resources.",
      useName = "include-all",
      minOccurs = 1
  )
  private IncludeAll _includeAll;

  @BoundAssembly(
      formalName = "Select Control",
      description = "Select a control or controls from an imported control set.",
      useName = "include-controls",
      minOccurs = 1,
      maxOccurs = -1
  )
  @GroupAs(
      name = "include-controls",
      inJson = JsonGroupAsBehavior.LIST
  )
  private List<ProfileSelectControlById> _includeControls;

  @BoundAssembly(
      formalName = "Select Control",
      description = "Select a control or controls from an imported control set.",
      useName = "exclude-controls",
      maxOccurs = -1,
      remarks = "Identifies which controls to exclude, or eliminate, from the set of matching includes."
  )
  @GroupAs(
      name = "exclude-controls",
      inJson = JsonGroupAsBehavior.LIST
  )
  private List<ProfileSelectControlById> _excludeControls;

  public InsertControls() {
  }

  public String getOrder() {
    return _order;
  }

  public void setOrder(String value) {
    _order = value;
  }

  public IncludeAll getIncludeAll() {
    return _includeAll;
  }

  public void setIncludeAll(IncludeAll value) {
    _includeAll = value;
  }

  public List<ProfileSelectControlById> getIncludeControls() {
    return _includeControls;
  }

  public void setIncludeControls(List<ProfileSelectControlById> value) {
    _includeControls = value;
  }

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

  /**
   * Remove the first matching {@link ProfileSelectControlById} 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 removeIncludeControls(ProfileSelectControlById item) {
    ProfileSelectControlById value = ObjectUtils.requireNonNull(item,"item cannot be null");
    return _includeControls == null ? false : _includeControls.remove(value);
  }

  public List<ProfileSelectControlById> getExcludeControls() {
    return _excludeControls;
  }

  public void setExcludeControls(List<ProfileSelectControlById> value) {
    _excludeControls = value;
  }

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

  /**
   * Remove the first matching {@link ProfileSelectControlById} 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 removeExcludeControls(ProfileSelectControlById item) {
    ProfileSelectControlById value = ObjectUtils.requireNonNull(item,"item cannot be null");
    return _excludeControls == null ? false : _excludeControls.remove(value);
  }

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