ComponentDefinition.java

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

import gov.nist.secauto.metaschema.binding.model.annotations.AssemblyConstraints;
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.Index;
import gov.nist.secauto.metaschema.binding.model.annotations.IsUnique;
import gov.nist.secauto.metaschema.binding.model.annotations.KeyField;
import gov.nist.secauto.metaschema.binding.model.annotations.MetaschemaAssembly;
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.UuidAdapter;
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 java.util.UUID;
import org.apache.commons.lang3.builder.MultilineRecursiveToStringStyle;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;

/**
 * A collection of component descriptions, which may optionally be grouped by capability.
 */
@MetaschemaAssembly(
    formalName = "Component Definition",
    description = "A collection of component descriptions, which may optionally be grouped by capability.",
    name = "component-definition",
    metaschema = OscalComponentDefinitionMetaschema.class,
    rootName = "component-definition"
)
@AssemblyConstraints(
    index = @Index(level = IConstraint.Level.ERROR, target = "component", name = "index-system-component-uuid", keyFields = @KeyField(target = "@uuid"), remarks = "Since multiple `component` entries can be provided, each component must have a unique `uuid`."),
    isUnique = @IsUnique(id = "unique-component-definition-capability", level = IConstraint.Level.ERROR, target = "capability", keyFields = @KeyField(target = "@uuid"), remarks = "A given `component` must not be referenced more than once within the same `capability`.")
)
public class ComponentDefinition {
  @BoundFlag(
      formalName = "Component Definition Universally Unique Identifier",
      description = "Provides a globally unique means to identify a given component definition instance.",
      useName = "uuid",
      required = true,
      typeAdapter = UuidAdapter.class
  )
  private UUID _uuid;

  @BoundAssembly(
      formalName = "Document Metadata",
      description = "Provides information about the containing document, and defines concepts that are shared across the document.",
      useName = "metadata",
      minOccurs = 1
  )
  private Metadata _metadata;

  @BoundAssembly(
      formalName = "Import Component Definition",
      description = "Loads a component definition from another resource.",
      useName = "import-component-definition",
      maxOccurs = -1
  )
  @GroupAs(
      name = "import-component-definitions",
      inJson = JsonGroupAsBehavior.LIST
  )
  private List<ImportComponentDefinition> _importComponentDefinitions;

  @BoundAssembly(
      formalName = "Component",
      description = "A defined component that can be part of an implemented system.",
      useName = "component",
      maxOccurs = -1
  )
  @GroupAs(
      name = "components",
      inJson = JsonGroupAsBehavior.LIST
  )
  private List<DefinedComponent> _components;

  @BoundAssembly(
      formalName = "Capability",
      description = "A grouping of other components and/or capabilities.",
      useName = "capability",
      maxOccurs = -1
  )
  @GroupAs(
      name = "capabilities",
      inJson = JsonGroupAsBehavior.LIST
  )
  private List<Capability> _capabilities;

  @BoundAssembly(
      formalName = "Back matter",
      description = "A collection of resources that may be referenced from within the OSCAL document instance.",
      useName = "back-matter"
  )
  private BackMatter _backMatter;

  public ComponentDefinition() {
  }

  public UUID getUuid() {
    return _uuid;
  }

  public void setUuid(UUID value) {
    _uuid = value;
  }

  public Metadata getMetadata() {
    return _metadata;
  }

  public void setMetadata(Metadata value) {
    _metadata = value;
  }

  public List<ImportComponentDefinition> getImportComponentDefinitions() {
    return _importComponentDefinitions;
  }

  public void setImportComponentDefinitions(List<ImportComponentDefinition> value) {
    _importComponentDefinitions = value;
  }

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

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

  public List<DefinedComponent> getComponents() {
    return _components;
  }

  public void setComponents(List<DefinedComponent> value) {
    _components = value;
  }

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

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

  public List<Capability> getCapabilities() {
    return _capabilities;
  }

  public void setCapabilities(List<Capability> value) {
    _capabilities = value;
  }

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

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

  public BackMatter getBackMatter() {
    return _backMatter;
  }

  public void setBackMatter(BackMatter value) {
    _backMatter = value;
  }

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