LocalDefinitions.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.BoundField;
import gov.nist.secauto.metaschema.binding.model.annotations.BoundFieldValue;
import gov.nist.secauto.metaschema.binding.model.annotations.GroupAs;
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.markup.MarkupMultiline;
import gov.nist.secauto.metaschema.model.common.datatype.markup.MarkupMultilineAdapter;
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;

/**
 * Allows components, and inventory-items to be defined within the POA&M for circumstances where no OSCAL-based SSP exists, or is not delivered with the POA&M.
 */
@MetaschemaAssembly(
    formalName = "Local Definitions",
    description = "Allows components, and inventory-items to be defined within the POA\\&M for circumstances where no OSCAL-based SSP exists, or is not delivered with the POA\\&M.",
    name = "local-definitions",
    metaschema = OscalPoamMetaschema.class
)
@AssemblyConstraints(
    isUnique = @IsUnique(id = "unique-poam-local-definitions-component", level = IConstraint.Level.ERROR, target = "component", keyFields = @KeyField(target = "@uuid"), remarks = "Since multiple `component` entries can be provided, each component must have a unique `uuid`.")
)
public class LocalDefinitions {
  @BoundAssembly(
      formalName = "Component",
      description = "A defined component that can be part of an implemented system.",
      useName = "component",
      maxOccurs = -1,
      remarks = "Used to add any components, not defined via the System Security Plan (AR-\\>AP-\\>SSP)"
  )
  @GroupAs(
      name = "components",
      inJson = JsonGroupAsBehavior.LIST
  )
  private List<SystemComponent> _components;

  @BoundAssembly(
      formalName = "Inventory Item",
      description = "A single managed inventory item within the system.",
      useName = "inventory-item",
      maxOccurs = -1,
      remarks = "Used to add any inventory-items, not defined via the System Security Plan (AR-\\>AP-\\>SSP)"
  )
  @GroupAs(
      name = "inventory-items",
      inJson = JsonGroupAsBehavior.LIST
  )
  private List<InventoryItem> _inventoryItems;

  @BoundAssembly(
      formalName = "Assessment Assets",
      description = "Identifies the assets used to perform this assessment, such as the assessment team, scanning tools, and assumptions.",
      useName = "assessment-assets",
      remarks = "Specifies components or assessment-platforms used in the assessment."
  )
  private AssessmentAssets _assessmentAssets;

  @BoundField(
      formalName = "Remarks",
      description = "Additional commentary about the containing object.",
      useName = "remarks"
  )
  @BoundFieldValue(
      typeAdapter = MarkupMultilineAdapter.class
  )
  private MarkupMultiline _remarks;

  public LocalDefinitions() {
  }

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

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

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

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

  public List<InventoryItem> getInventoryItems() {
    return _inventoryItems;
  }

  public void setInventoryItems(List<InventoryItem> value) {
    _inventoryItems = value;
  }

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

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

  public AssessmentAssets getAssessmentAssets() {
    return _assessmentAssets;
  }

  public void setAssessmentAssets(AssessmentAssets value) {
    _assessmentAssets = value;
  }

  public MarkupMultiline getRemarks() {
    return _remarks;
  }

  public void setRemarks(MarkupMultiline value) {
    _remarks = value;
  }

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