Observation.java

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

import gov.nist.secauto.metaschema.binding.model.annotations.AllowedValue;
import gov.nist.secauto.metaschema.binding.model.annotations.AllowedValues;
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.BoundFlag;
import gov.nist.secauto.metaschema.binding.model.annotations.GroupAs;
import gov.nist.secauto.metaschema.binding.model.annotations.MetaschemaAssembly;
import gov.nist.secauto.metaschema.binding.model.annotations.ValueConstraints;
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.adapter.DateTimeWithTZAdapter;
import gov.nist.secauto.metaschema.model.common.datatype.adapter.TokenAdapter;
import gov.nist.secauto.metaschema.model.common.datatype.adapter.UriReferenceAdapter;
import gov.nist.secauto.metaschema.model.common.datatype.adapter.UuidAdapter;
import gov.nist.secauto.metaschema.model.common.datatype.markup.MarkupLine;
import gov.nist.secauto.metaschema.model.common.datatype.markup.MarkupLineAdapter;
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.net.URI;
import java.time.ZonedDateTime;
import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
import org.apache.commons.lang3.builder.MultilineRecursiveToStringStyle;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;

/**
 * Describes an individual observation.
 */
@MetaschemaAssembly(
    formalName = "Observation",
    description = "Describes an individual observation.",
    name = "observation",
    metaschema = OscalAssessmentCommonMetaschema.class
)
public class Observation {
  @BoundFlag(
      formalName = "Observation Universally Unique Identifier",
      description = "A [machine-oriented](https://pages.nist.gov/OSCAL/concepts/identifier-use/#machine-oriented), [globally unique](https://pages.nist.gov/OSCAL/concepts/identifier-use/#globally-unique) identifier with *cross-instance* scope that can be used to reference this observation elsewhere in [this or other OSCAL instances](https://pages.nist.gov/OSCAL/concepts/identifier-use/#scope). The locally defined *UUID* of the `observation` can be used to reference the data item locally or globally (e.g., in an imorted OSCAL instance). This UUID should be assigned [per-subject](https://pages.nist.gov/OSCAL/concepts/identifier-use/#consistency), which means it should be consistently used to identify the same subject across revisions of the document.",
      useName = "uuid",
      required = true,
      typeAdapter = UuidAdapter.class
  )
  private UUID _uuid;

  /**
   * "The title for this observation."
   */
  @BoundField(
      formalName = "Observation Title",
      description = "The title for this observation.",
      useName = "title"
  )
  @BoundFieldValue(
      typeAdapter = MarkupLineAdapter.class
  )
  private MarkupLine _title;

  /**
   * "A human-readable description of this assessment observation."
   */
  @BoundField(
      formalName = "Observation Description",
      description = "A human-readable description of this assessment observation.",
      useName = "description",
      minOccurs = 1
  )
  @BoundFieldValue(
      typeAdapter = MarkupMultilineAdapter.class
  )
  private MarkupMultiline _description;

  @BoundAssembly(
      formalName = "Property",
      description = "An attribute, characteristic, or quality of the containing object expressed as a namespace qualified name/value pair.",
      useName = "prop",
      maxOccurs = -1
  )
  @GroupAs(
      name = "props",
      inJson = JsonGroupAsBehavior.LIST
  )
  private List<Property> _props;

  @BoundAssembly(
      formalName = "Link",
      description = "A reference to a local or remote resource, that has a specific relation to the containing object.",
      useName = "link",
      maxOccurs = -1
  )
  @GroupAs(
      name = "links",
      inJson = JsonGroupAsBehavior.LIST
  )
  private List<Link> _links;

  /**
   * "Identifies how the observation was made."
   */
  @BoundField(
      formalName = "Observation Method",
      description = "Identifies how the observation was made.",
      useName = "method",
      minOccurs = 1,
      maxOccurs = -1
  )
  @ValueConstraints(
      allowedValues = @AllowedValues(level = IConstraint.Level.ERROR, allowOthers = true, values = {@AllowedValue(value = "EXAMINE", description = "An inspection was performed."), @AllowedValue(value = "INTERVIEW", description = "An interview was performed."), @AllowedValue(value = "TEST", description = "A manual or automated test was performed."), @AllowedValue(value = "UNKNOWN", description = "This is only for use when converting historic content to OSCAL, where the conversion process cannot initially identify the appropriate method(s).")})
  )
  @GroupAs(
      name = "methods",
      inJson = JsonGroupAsBehavior.LIST
  )
  private List<String> _methods;

  /**
   * "Identifies the nature of the observation. More than one may be used to further qualify and enable filtering."
   */
  @BoundField(
      formalName = "Observation Type",
      description = "Identifies the nature of the observation. More than one may be used to further qualify and enable filtering.",
      useName = "type",
      maxOccurs = -1
  )
  @BoundFieldValue(
      typeAdapter = TokenAdapter.class
  )
  @ValueConstraints(
      allowedValues = @AllowedValues(level = IConstraint.Level.ERROR, allowOthers = true, values = {@AllowedValue(value = "ssp-statement-issue", description = "A difference between the SSP implementation statement, and actual implementation."), @AllowedValue(value = "control-objective", description = "An observation about the status of a the associated control objective."), @AllowedValue(value = "mitigation", description = "A mitigating factor was identified."), @AllowedValue(value = "finding", description = "An assessment finding. Used for observations made by tools, penetration testing, and other means."), @AllowedValue(value = "historic", description = "An observation from a past assessment, which was converted to OSCAL at a later date.")})
  )
  @GroupAs(
      name = "types",
      inJson = JsonGroupAsBehavior.LIST
  )
  private List<String> _types;

  @BoundAssembly(
      formalName = "Origin",
      description = "Identifies the source of the finding, such as a tool, interviewed person, or activity.",
      useName = "origin",
      maxOccurs = -1,
      remarks = "Used to identify the individual and/or tool that gathered the evidence resulting in the observation identification."
  )
  @GroupAs(
      name = "origins",
      inJson = JsonGroupAsBehavior.LIST
  )
  private List<Origin> _origins;

  @BoundAssembly(
      formalName = "Identifies the Subject",
      description = "A [human-oriented](https://pages.nist.gov/OSCAL/concepts/identifier-use/#human-oriented) identifier reference to a resource. Use type to indicate whether the identified resource is a component, inventory item, location, user, or something else.",
      useName = "subject",
      maxOccurs = -1,
      remarks = "Identifies who was interviewed, or what was tested or inspected."
  )
  @GroupAs(
      name = "subjects",
      inJson = JsonGroupAsBehavior.LIST
  )
  private List<SubjectReference> _subjects;

  /**
   * "Links this observation to relevant evidence."
   */
  @BoundAssembly(
      formalName = "Relevant Evidence",
      description = "Links this observation to relevant evidence.",
      useName = "relevant-evidence",
      maxOccurs = -1
  )
  @GroupAs(
      name = "relevant-evidence",
      inJson = JsonGroupAsBehavior.LIST
  )
  private List<RelevantEvidence> _relevantEvidence;

  /**
   * "Date/time stamp identifying when the finding information was collected."
   */
  @BoundField(
      formalName = "Collected Field",
      description = "Date/time stamp identifying when the finding information was collected.",
      useName = "collected",
      minOccurs = 1
  )
  @BoundFieldValue(
      typeAdapter = DateTimeWithTZAdapter.class
  )
  private ZonedDateTime _collected;

  /**
   * "Date/time identifying when the finding information is out-of-date and no longer valid. Typically used with continuous assessment scenarios."
   */
  @BoundField(
      formalName = "Expires Field",
      description = "Date/time identifying when the finding information is out-of-date and no longer valid. Typically used with continuous assessment scenarios.",
      useName = "expires"
  )
  @BoundFieldValue(
      typeAdapter = DateTimeWithTZAdapter.class
  )
  private ZonedDateTime _expires;

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

  public Observation() {
  }

  public UUID getUuid() {
    return _uuid;
  }

  public void setUuid(UUID value) {
    _uuid = value;
  }

  public MarkupLine getTitle() {
    return _title;
  }

  public void setTitle(MarkupLine value) {
    _title = value;
  }

  public MarkupMultiline getDescription() {
    return _description;
  }

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

  public List<Property> getProps() {
    return _props;
  }

  public void setProps(List<Property> value) {
    _props = value;
  }

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

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

  public List<Link> getLinks() {
    return _links;
  }

  public void setLinks(List<Link> value) {
    _links = value;
  }

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

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

  public List<String> getMethods() {
    return _methods;
  }

  public void setMethods(List<String> value) {
    _methods = value;
  }

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

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

  public List<String> getTypes() {
    return _types;
  }

  public void setTypes(List<String> value) {
    _types = value;
  }

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

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

  public List<Origin> getOrigins() {
    return _origins;
  }

  public void setOrigins(List<Origin> value) {
    _origins = value;
  }

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

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

  public List<SubjectReference> getSubjects() {
    return _subjects;
  }

  public void setSubjects(List<SubjectReference> value) {
    _subjects = value;
  }

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

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

  public List<RelevantEvidence> getRelevantEvidence() {
    return _relevantEvidence;
  }

  public void setRelevantEvidence(List<RelevantEvidence> value) {
    _relevantEvidence = value;
  }

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

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

  public ZonedDateTime getCollected() {
    return _collected;
  }

  public void setCollected(ZonedDateTime value) {
    _collected = value;
  }

  public ZonedDateTime getExpires() {
    return _expires;
  }

  public void setExpires(ZonedDateTime value) {
    _expires = 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();
  }

  /**
   * Links this observation to relevant evidence.
   */
  @MetaschemaAssembly(
      formalName = "Relevant Evidence",
      description = "Links this observation to relevant evidence.",
      name = "relevant-evidence",
      metaschema = OscalAssessmentCommonMetaschema.class
  )
  public static class RelevantEvidence {
    @BoundFlag(
        formalName = "Relevant Evidence Reference",
        description = "A resolvable URL reference to relevant evidence.",
        useName = "href",
        typeAdapter = UriReferenceAdapter.class,
        remarks = "This value may be one of:\n"
                + "\n"
                + "1. an [absolute URI](https://pages.nist.gov/OSCAL/concepts/uri-use/#absolute-uri) that points to a network resolvable resource,\n"
                + "2. a [relative reference](https://pages.nist.gov/OSCAL/concepts/uri-use/#relative-reference) pointing to a network resolvable resource whose base URI is the URI of the containing document, or\n"
                + "3. a bare URI fragment (i.e., \\`#uuid\\`) pointing to a `back-matter` resource in this or an imported document (see [linking to another OSCAL object](https://pages.nist.gov/OSCAL/concepts/uri-use/#linking-to-another-oscal-object))."
    )
    private URI _href;

    /**
     * "A human-readable description of this evidence."
     */
    @BoundField(
        formalName = "Relevant Evidence Description",
        description = "A human-readable description of this evidence.",
        useName = "description",
        minOccurs = 1
    )
    @BoundFieldValue(
        typeAdapter = MarkupMultilineAdapter.class
    )
    private MarkupMultiline _description;

    @BoundAssembly(
        formalName = "Property",
        description = "An attribute, characteristic, or quality of the containing object expressed as a namespace qualified name/value pair.",
        useName = "prop",
        maxOccurs = -1
    )
    @GroupAs(
        name = "props",
        inJson = JsonGroupAsBehavior.LIST
    )
    private List<Property> _props;

    @BoundAssembly(
        formalName = "Link",
        description = "A reference to a local or remote resource, that has a specific relation to the containing object.",
        useName = "link",
        maxOccurs = -1
    )
    @GroupAs(
        name = "links",
        inJson = JsonGroupAsBehavior.LIST
    )
    private List<Link> _links;

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

    public RelevantEvidence() {
    }

    public URI getHref() {
      return _href;
    }

    public void setHref(URI value) {
      _href = value;
    }

    public MarkupMultiline getDescription() {
      return _description;
    }

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

    public List<Property> getProps() {
      return _props;
    }

    public void setProps(List<Property> value) {
      _props = value;
    }

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

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

    public List<Link> getLinks() {
      return _links;
    }

    public void setLinks(List<Link> value) {
      _links = value;
    }

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

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