ParameterConstraint.java

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

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.MetaschemaAssembly;
import gov.nist.secauto.metaschema.model.common.JsonGroupAsBehavior;
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;

/**
 * A formal or informal expression of a constraint or test.
 */
@MetaschemaAssembly(
    formalName = "Constraint",
    description = "A formal or informal expression of a constraint or test.",
    name = "parameter-constraint",
    metaschema = OscalControlCommonMetaschema.class
)
public class ParameterConstraint {
  /**
   * "A textual summary of the constraint to be applied."
   */
  @BoundField(
      formalName = "Constraint Description",
      description = "A textual summary of the constraint to be applied.",
      useName = "description"
  )
  @BoundFieldValue(
      typeAdapter = MarkupMultilineAdapter.class
  )
  private MarkupMultiline _description;

  /**
   * "A test expression which is expected to be evaluated by a tool."
   */
  @BoundAssembly(
      formalName = "Constraint Test",
      description = "A test expression which is expected to be evaluated by a tool.",
      useName = "test",
      maxOccurs = -1
  )
  @GroupAs(
      name = "tests",
      inJson = JsonGroupAsBehavior.LIST
  )
  private List<Test> _tests;

  public ParameterConstraint() {
  }

  public MarkupMultiline getDescription() {
    return _description;
  }

  public void setDescription(MarkupMultiline value) {
    _description = value;
  }

  public List<Test> getTests() {
    return _tests;
  }

  public void setTests(List<Test> value) {
    _tests = value;
  }

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

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

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

  /**
   * A test expression which is expected to be evaluated by a tool.
   */
  @MetaschemaAssembly(
      formalName = "Constraint Test",
      description = "A test expression which is expected to be evaluated by a tool.",
      name = "test",
      metaschema = OscalControlCommonMetaschema.class
  )
  public static class Test {
    /**
     * "A formal (executable) expression of a constraint."
     */
    @BoundField(
        formalName = "Constraint test",
        description = "A formal (executable) expression of a constraint.",
        useName = "expression",
        minOccurs = 1
    )
    private String _expression;

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

    public Test() {
    }

    public String getExpression() {
      return _expression;
    }

    public void setExpression(String value) {
      _expression = 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();
    }
  }
}