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.Index;
015import gov.nist.secauto.metaschema.databind.model.annotations.IsUnique;
016import gov.nist.secauto.metaschema.databind.model.annotations.KeyField;
017import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaAssembly;
018import java.lang.Override;
019import java.lang.String;
020import java.util.LinkedList;
021import java.util.List;
022import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
023import org.apache.commons.lang3.builder.ToStringStyle;
024
025/**
026 * Describes how the system satisfies a set of controls.
027 */
028@MetaschemaAssembly(
029    formalName = "Control Implementation",
030    description = "Describes how the system satisfies a set of controls.",
031    name = "control-implementation",
032    moduleClass = OscalSspModule.class,
033    remarks = "Use of `set-parameter` in this context, sets the parameter for all controls referenced by any `implemented-requirement` contained in this context. Any `set-parameter` defined in a child context will override this value. If not overridden by a child, this value applies in the child context.",
034    modelConstraints = @AssemblyConstraints(index = @Index(level = IConstraint.Level.ERROR, target = "implemented-requirement//by-component/export/provided", name = "by-component-export-provided-uuid", keyFields = @KeyField(target = "@uuid")), unique = @IsUnique(id = "unique-ssp-control-implementation-set-parameter", level = IConstraint.Level.ERROR, target = "set-parameter", keyFields = @KeyField(target = "@param-id"), remarks = "Since multiple `set-parameter` entries can be provided, each parameter must be set only once."))
035)
036public class ControlImplementation implements IBoundObject {
037  private final IMetaschemaData __metaschemaData;
038
039  @BoundField(
040      formalName = "Control Implementation Description",
041      description = "A statement describing important things to know about how this set of control satisfaction documentation is approached.",
042      useName = "description",
043      minOccurs = 1,
044      typeAdapter = MarkupMultilineAdapter.class
045  )
046  private MarkupMultiline _description;
047
048  @BoundAssembly(
049      formalName = "Set Parameter Value",
050      description = "Identifies the parameter that will be set by the enclosed value.",
051      useName = "set-parameter",
052      maxOccurs = -1,
053      groupAs = @GroupAs(name = "set-parameters", inJson = JsonGroupAsBehavior.LIST)
054  )
055  private List<SetParameter> _setParameters;
056
057  @BoundAssembly(
058      formalName = "Control-based Requirement",
059      description = "Describes how the system satisfies the requirements of an individual control.",
060      useName = "implemented-requirement",
061      minOccurs = 1,
062      maxOccurs = -1,
063      groupAs = @GroupAs(name = "implemented-requirements", inJson = JsonGroupAsBehavior.LIST)
064  )
065  private List<ImplementedRequirement> _implementedRequirements;
066
067  public ControlImplementation() {
068    this(null);
069  }
070
071  public ControlImplementation(IMetaschemaData data) {
072    this.__metaschemaData = data;
073  }
074
075  @Override
076  public IMetaschemaData getMetaschemaData() {
077    return __metaschemaData;
078  }
079
080  public MarkupMultiline getDescription() {
081    return _description;
082  }
083
084  public void setDescription(MarkupMultiline value) {
085    _description = value;
086  }
087
088  public List<SetParameter> getSetParameters() {
089    return _setParameters;
090  }
091
092  public void setSetParameters(List<SetParameter> value) {
093    _setParameters = value;
094  }
095
096  /**
097   * Add a new {@link SetParameter} item to the underlying collection.
098   * @param item the item to add
099   * @return {@code true}
100   */
101  public boolean addSetParameter(SetParameter item) {
102    SetParameter value = ObjectUtils.requireNonNull(item,"item cannot be null");
103    if (_setParameters == null) {
104      _setParameters = new LinkedList<>();
105    }
106    return _setParameters.add(value);
107  }
108
109  /**
110   * Remove the first matching {@link SetParameter} item from the underlying collection.
111   * @param item the item to remove
112   * @return {@code true} if the item was removed or {@code false} otherwise
113   */
114  public boolean removeSetParameter(SetParameter item) {
115    SetParameter value = ObjectUtils.requireNonNull(item,"item cannot be null");
116    return _setParameters != null && _setParameters.remove(value);
117  }
118
119  public List<ImplementedRequirement> getImplementedRequirements() {
120    return _implementedRequirements;
121  }
122
123  public void setImplementedRequirements(List<ImplementedRequirement> value) {
124    _implementedRequirements = value;
125  }
126
127  /**
128   * Add a new {@link ImplementedRequirement} item to the underlying collection.
129   * @param item the item to add
130   * @return {@code true}
131   */
132  public boolean addImplementedRequirement(ImplementedRequirement item) {
133    ImplementedRequirement value = ObjectUtils.requireNonNull(item,"item cannot be null");
134    if (_implementedRequirements == null) {
135      _implementedRequirements = new LinkedList<>();
136    }
137    return _implementedRequirements.add(value);
138  }
139
140  /**
141   * Remove the first matching {@link ImplementedRequirement} item from the underlying collection.
142   * @param item the item to remove
143   * @return {@code true} if the item was removed or {@code false} otherwise
144   */
145  public boolean removeImplementedRequirement(ImplementedRequirement item) {
146    ImplementedRequirement value = ObjectUtils.requireNonNull(item,"item cannot be null");
147    return _implementedRequirements != null && _implementedRequirements.remove(value);
148  }
149
150  @Override
151  public String toString() {
152    return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString();
153  }
154}