ProfileImport.java

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

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.model.common.JsonGroupAsBehavior;
import gov.nist.secauto.metaschema.model.common.datatype.adapter.UriReferenceAdapter;
import gov.nist.secauto.metaschema.model.common.util.ObjectUtils;
import java.lang.Override;
import java.lang.String;
import java.net.URI;
import java.util.LinkedList;
import java.util.List;
import org.apache.commons.lang3.builder.MultilineRecursiveToStringStyle;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;

/**
 * Designates a referenced source catalog or profile that provides a source of control information for use in creating a new overlay or baseline.
 */
@MetaschemaAssembly(
    formalName = "Import Resource",
    description = "Designates a referenced source catalog or profile that provides a source of control information for use in creating a new overlay or baseline.",
    name = "import",
    metaschema = OscalProfileMetaschema.class,
    remarks = "The contents of the `import` element indicate which controls from the source will be included. Controls from the source catalog or profile may be either selected, using the `include-all` or `include-controls` directives, or de-selected (using an `exclude-controls` directive)."
)
public class ProfileImport {
  @BoundFlag(
      formalName = "Catalog or Profile Reference",
      description = "A resolvable URL reference to the base catalog or profile that this profile is tailoring.",
      useName = "href",
      required = true,
      typeAdapter = UriReferenceAdapter.class,
      remarks = "This value may be one of:\n"
              + "\n"
              + "1. an [absolute URI](https://pages.nist.gov/OSCAL/concepts/uri-use/#absolute-uri) that points to a network resolvable resource,\n"
              + "2. a [relative reference](https://pages.nist.gov/OSCAL/concepts/uri-use/#relative-reference) pointing to a network resolvable resource whose base URI is the URI of the containing document, or\n"
              + "3. a bare URI fragment (i.e., \\`#uuid\\`) pointing to a `back-matter` resource in this or an imported document (see [linking to another OSCAL object](https://pages.nist.gov/OSCAL/concepts/uri-use/#linking-to-another-oscal-object))."
  )
  private URI _href;

  @BoundAssembly(
      formalName = "Include All",
      description = "Include all controls from the imported catalog or profile resources.",
      useName = "include-all",
      minOccurs = 1,
      remarks = "Identifies that all controls are to be included from the imported catalog or profile."
  )
  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,
      remarks = "If `with-child-controls` is \"yes\" on the call to a control, any controls appearing within it (child controls) will be selected, with no additional `call` directives required. This flag provides a way to include controls with all their dependent controls (enhancements) without having to call them individually."
  )
  @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 included controls by control identifier or match pattern."
  )
  @GroupAs(
      name = "exclude-controls",
      inJson = JsonGroupAsBehavior.LIST
  )
  private List<ProfileSelectControlById> _excludeControls;

  public ProfileImport() {
  }

  public URI getHref() {
    return _href;
  }

  public void setHref(URI value) {
    _href = 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();
  }
}