001package gov.nist.secauto.oscal.lib.model;
002
003import gov.nist.secauto.metaschema.core.datatype.markup.MarkupMultiline;
004import gov.nist.secauto.metaschema.core.datatype.markup.MarkupMultilineAdapter;
005import gov.nist.secauto.metaschema.core.model.IBoundObject;
006import gov.nist.secauto.metaschema.core.model.IMetaschemaData;
007import gov.nist.secauto.metaschema.core.model.JsonGroupAsBehavior;
008import gov.nist.secauto.metaschema.core.model.constraint.IConstraint;
009import gov.nist.secauto.metaschema.core.util.ObjectUtils;
010import gov.nist.secauto.metaschema.databind.model.annotations.AssemblyConstraints;
011import gov.nist.secauto.metaschema.databind.model.annotations.BoundAssembly;
012import gov.nist.secauto.metaschema.databind.model.annotations.BoundField;
013import gov.nist.secauto.metaschema.databind.model.annotations.GroupAs;
014import gov.nist.secauto.metaschema.databind.model.annotations.IsUnique;
015import gov.nist.secauto.metaschema.databind.model.annotations.KeyField;
016import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaAssembly;
017import java.lang.Override;
018import java.lang.String;
019import java.util.LinkedList;
020import java.util.List;
021import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
022import org.apache.commons.lang3.builder.ToStringStyle;
023
024/**
025 * 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.
026 */
027@MetaschemaAssembly(
028    formalName = "Local Definitions",
029    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.",
030    name = "local-definitions",
031    moduleClass = OscalPoamModule.class,
032    modelConstraints = @AssemblyConstraints(unique = @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`."))
033)
034public class LocalDefinitions implements IBoundObject {
035  private final IMetaschemaData __metaschemaData;
036
037  @BoundAssembly(
038      formalName = "Component",
039      description = "A defined component that can be part of an implemented system.",
040      useName = "component",
041      remarks = "Used to add any components, not defined via the System Security Plan (AR-\\>AP-\\>SSP)",
042      maxOccurs = -1,
043      groupAs = @GroupAs(name = "components", inJson = JsonGroupAsBehavior.LIST)
044  )
045  private List<SystemComponent> _components;
046
047  @BoundAssembly(
048      formalName = "Inventory Item",
049      description = "A single managed inventory item within the system.",
050      useName = "inventory-item",
051      remarks = "Used to add any inventory-items, not defined via the System Security Plan (AR-\\>AP-\\>SSP)",
052      maxOccurs = -1,
053      groupAs = @GroupAs(name = "inventory-items", inJson = JsonGroupAsBehavior.LIST)
054  )
055  private List<InventoryItem> _inventoryItems;
056
057  @BoundAssembly(
058      formalName = "Assessment Assets",
059      description = "Identifies the assets used to perform this assessment, such as the assessment team, scanning tools, and assumptions.",
060      useName = "assessment-assets",
061      remarks = "Specifies components or assessment-platforms used in the assessment."
062  )
063  private AssessmentAssets _assessmentAssets;
064
065  @BoundField(
066      formalName = "Remarks",
067      description = "Additional commentary about the containing object.",
068      useName = "remarks",
069      typeAdapter = MarkupMultilineAdapter.class
070  )
071  private MarkupMultiline _remarks;
072
073  public LocalDefinitions() {
074    this(null);
075  }
076
077  public LocalDefinitions(IMetaschemaData data) {
078    this.__metaschemaData = data;
079  }
080
081  @Override
082  public IMetaschemaData getMetaschemaData() {
083    return __metaschemaData;
084  }
085
086  public List<SystemComponent> getComponents() {
087    return _components;
088  }
089
090  public void setComponents(List<SystemComponent> value) {
091    _components = value;
092  }
093
094  /**
095   * Add a new {@link SystemComponent} item to the underlying collection.
096   * @param item the item to add
097   * @return {@code true}
098   */
099  public boolean addComponent(SystemComponent item) {
100    SystemComponent value = ObjectUtils.requireNonNull(item,"item cannot be null");
101    if (_components == null) {
102      _components = new LinkedList<>();
103    }
104    return _components.add(value);
105  }
106
107  /**
108   * Remove the first matching {@link SystemComponent} item from the underlying collection.
109   * @param item the item to remove
110   * @return {@code true} if the item was removed or {@code false} otherwise
111   */
112  public boolean removeComponent(SystemComponent item) {
113    SystemComponent value = ObjectUtils.requireNonNull(item,"item cannot be null");
114    return _components != null && _components.remove(value);
115  }
116
117  public List<InventoryItem> getInventoryItems() {
118    return _inventoryItems;
119  }
120
121  public void setInventoryItems(List<InventoryItem> value) {
122    _inventoryItems = value;
123  }
124
125  /**
126   * Add a new {@link InventoryItem} item to the underlying collection.
127   * @param item the item to add
128   * @return {@code true}
129   */
130  public boolean addInventoryItem(InventoryItem item) {
131    InventoryItem value = ObjectUtils.requireNonNull(item,"item cannot be null");
132    if (_inventoryItems == null) {
133      _inventoryItems = new LinkedList<>();
134    }
135    return _inventoryItems.add(value);
136  }
137
138  /**
139   * Remove the first matching {@link InventoryItem} item from the underlying collection.
140   * @param item the item to remove
141   * @return {@code true} if the item was removed or {@code false} otherwise
142   */
143  public boolean removeInventoryItem(InventoryItem item) {
144    InventoryItem value = ObjectUtils.requireNonNull(item,"item cannot be null");
145    return _inventoryItems != null && _inventoryItems.remove(value);
146  }
147
148  public AssessmentAssets getAssessmentAssets() {
149    return _assessmentAssets;
150  }
151
152  public void setAssessmentAssets(AssessmentAssets value) {
153    _assessmentAssets = value;
154  }
155
156  public MarkupMultiline getRemarks() {
157    return _remarks;
158  }
159
160  public void setRemarks(MarkupMultiline value) {
161    _remarks = value;
162  }
163
164  @Override
165  public String toString() {
166    return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString();
167  }
168}