ControlImplementation.java

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

  2. import gov.nist.secauto.metaschema.binding.model.annotations.AssemblyConstraints;
  3. import gov.nist.secauto.metaschema.binding.model.annotations.BoundAssembly;
  4. import gov.nist.secauto.metaschema.binding.model.annotations.BoundField;
  5. import gov.nist.secauto.metaschema.binding.model.annotations.BoundFieldValue;
  6. import gov.nist.secauto.metaschema.binding.model.annotations.GroupAs;
  7. import gov.nist.secauto.metaschema.binding.model.annotations.Index;
  8. import gov.nist.secauto.metaschema.binding.model.annotations.IsUnique;
  9. import gov.nist.secauto.metaschema.binding.model.annotations.KeyField;
  10. import gov.nist.secauto.metaschema.binding.model.annotations.MetaschemaAssembly;
  11. import gov.nist.secauto.metaschema.model.common.JsonGroupAsBehavior;
  12. import gov.nist.secauto.metaschema.model.common.constraint.IConstraint;
  13. import gov.nist.secauto.metaschema.model.common.datatype.markup.MarkupMultiline;
  14. import gov.nist.secauto.metaschema.model.common.datatype.markup.MarkupMultilineAdapter;
  15. import gov.nist.secauto.metaschema.model.common.util.ObjectUtils;
  16. import java.lang.Override;
  17. import java.lang.String;
  18. import java.util.LinkedList;
  19. import java.util.List;
  20. import org.apache.commons.lang3.builder.MultilineRecursiveToStringStyle;
  21. import org.apache.commons.lang3.builder.ReflectionToStringBuilder;

  22. /**
  23.  * Describes how the system satisfies a set of controls.
  24.  */
  25. @MetaschemaAssembly(
  26.     formalName = "Control Implementation",
  27.     description = "Describes how the system satisfies a set of controls.",
  28.     name = "control-implementation",
  29.     metaschema = OscalSspMetaschema.class,
  30.     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."
  31. )
  32. @AssemblyConstraints(
  33.     index = @Index(level = IConstraint.Level.ERROR, target = "implemented-requirement//by-component/export/provided", name = "by-component-export-provided-uuid", keyFields = @KeyField(target = "@uuid")),
  34.     isUnique = @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.")
  35. )
  36. public class ControlImplementation {
  37.   /**
  38.    * "A statement describing important things to know about how this set of control satisfaction documentation is approached."
  39.    */
  40.   @BoundField(
  41.       formalName = "Control Implementation Description",
  42.       description = "A statement describing important things to know about how this set of control satisfaction documentation is approached.",
  43.       useName = "description",
  44.       minOccurs = 1
  45.   )
  46.   @BoundFieldValue(
  47.       typeAdapter = MarkupMultilineAdapter.class
  48.   )
  49.   private MarkupMultiline _description;

  50.   @BoundAssembly(
  51.       formalName = "Set Parameter Value",
  52.       description = "Identifies the parameter that will be set by the enclosed value.",
  53.       useName = "set-parameter",
  54.       maxOccurs = -1
  55.   )
  56.   @GroupAs(
  57.       name = "set-parameters",
  58.       inJson = JsonGroupAsBehavior.LIST
  59.   )
  60.   private List<SetParameter> _setParameters;

  61.   @BoundAssembly(
  62.       formalName = "Control-based Requirement",
  63.       description = "Describes how the system satisfies the requirements of an individual control.",
  64.       useName = "implemented-requirement",
  65.       minOccurs = 1,
  66.       maxOccurs = -1
  67.   )
  68.   @GroupAs(
  69.       name = "implemented-requirements",
  70.       inJson = JsonGroupAsBehavior.LIST
  71.   )
  72.   private List<ImplementedRequirement> _implementedRequirements;

  73.   public ControlImplementation() {
  74.   }

  75.   public MarkupMultiline getDescription() {
  76.     return _description;
  77.   }

  78.   public void setDescription(MarkupMultiline value) {
  79.     _description = value;
  80.   }

  81.   public List<SetParameter> getSetParameters() {
  82.     return _setParameters;
  83.   }

  84.   public void setSetParameters(List<SetParameter> value) {
  85.     _setParameters = value;
  86.   }

  87.   /**
  88.    * Add a new {@link SetParameter} item to the underlying collection.
  89.    * @param item the item to add
  90.    * @return {@code true}
  91.    */
  92.   public boolean addSetParameter(SetParameter item) {
  93.     SetParameter value = ObjectUtils.requireNonNull(item,"item cannot be null");
  94.     if (_setParameters == null) {
  95.       _setParameters = new LinkedList<>();
  96.     }
  97.     return _setParameters.add(value);
  98.   }

  99.   /**
  100.    * Remove the first matching {@link SetParameter} item from the underlying collection.
  101.    * @param item the item to remove
  102.    * @return {@code true} if the item was removed or {@code false} otherwise
  103.    */
  104.   public boolean removeSetParameter(SetParameter item) {
  105.     SetParameter value = ObjectUtils.requireNonNull(item,"item cannot be null");
  106.     return _setParameters == null ? false : _setParameters.remove(value);
  107.   }

  108.   public List<ImplementedRequirement> getImplementedRequirements() {
  109.     return _implementedRequirements;
  110.   }

  111.   public void setImplementedRequirements(List<ImplementedRequirement> value) {
  112.     _implementedRequirements = value;
  113.   }

  114.   /**
  115.    * Add a new {@link ImplementedRequirement} item to the underlying collection.
  116.    * @param item the item to add
  117.    * @return {@code true}
  118.    */
  119.   public boolean addImplementedRequirement(ImplementedRequirement item) {
  120.     ImplementedRequirement value = ObjectUtils.requireNonNull(item,"item cannot be null");
  121.     if (_implementedRequirements == null) {
  122.       _implementedRequirements = new LinkedList<>();
  123.     }
  124.     return _implementedRequirements.add(value);
  125.   }

  126.   /**
  127.    * Remove the first matching {@link ImplementedRequirement} item from the underlying collection.
  128.    * @param item the item to remove
  129.    * @return {@code true} if the item was removed or {@code false} otherwise
  130.    */
  131.   public boolean removeImplementedRequirement(ImplementedRequirement item) {
  132.     ImplementedRequirement value = ObjectUtils.requireNonNull(item,"item cannot be null");
  133.     return _implementedRequirements == null ? false : _implementedRequirements.remove(value);
  134.   }

  135.   @Override
  136.   public String toString() {
  137.     return new ReflectionToStringBuilder(this, MultilineRecursiveToStringStyle.MULTI_LINE_STYLE).toString();
  138.   }
  139. }