001package gov.nist.secauto.oscal.lib.model;
002
003import gov.nist.secauto.metaschema.binding.model.annotations.AllowedValue;
004import gov.nist.secauto.metaschema.binding.model.annotations.AllowedValues;
005import gov.nist.secauto.metaschema.binding.model.annotations.AssemblyConstraints;
006import gov.nist.secauto.metaschema.binding.model.annotations.BoundAssembly;
007import gov.nist.secauto.metaschema.binding.model.annotations.BoundField;
008import gov.nist.secauto.metaschema.binding.model.annotations.BoundFieldValue;
009import gov.nist.secauto.metaschema.binding.model.annotations.BoundFlag;
010import gov.nist.secauto.metaschema.binding.model.annotations.GroupAs;
011import gov.nist.secauto.metaschema.binding.model.annotations.HasCardinality;
012import gov.nist.secauto.metaschema.binding.model.annotations.MetaschemaAssembly;
013import gov.nist.secauto.metaschema.binding.model.annotations.ValueConstraints;
014import gov.nist.secauto.metaschema.model.common.JsonGroupAsBehavior;
015import gov.nist.secauto.metaschema.model.common.constraint.IConstraint;
016import gov.nist.secauto.metaschema.model.common.datatype.adapter.TokenAdapter;
017import gov.nist.secauto.metaschema.model.common.datatype.markup.MarkupMultiline;
018import gov.nist.secauto.metaschema.model.common.datatype.markup.MarkupMultilineAdapter;
019import gov.nist.secauto.metaschema.model.common.util.ObjectUtils;
020import java.lang.Override;
021import java.lang.String;
022import java.util.LinkedList;
023import java.util.List;
024import org.apache.commons.lang3.builder.MultilineRecursiveToStringStyle;
025import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
026
027/**
028 * A local definition of a control objective for this assessment. Uses catalog syntax for control objective and assessment actions.
029 */
030@MetaschemaAssembly(
031    formalName = "Assessment-Specific Control Objective",
032    description = "A local definition of a control objective for this assessment. Uses catalog syntax for control objective and assessment actions.",
033    name = "local-objective",
034    metaschema = OscalAssessmentCommonMetaschema.class
035)
036@ValueConstraints(
037    allowedValues = @AllowedValues(level = IConstraint.Level.ERROR, target = "part[has-oscal-namespace('http://csrc.nist.gov/ns/oscal')]/@name", values = {@AllowedValue(value = "objective", description = "\\*\\*(deprecated)\\*\\* Use 'assessment-objective' instead."), @AllowedValue(value = "assessment", description = "\\*\\*(deprecated)\\*\\* Use 'assessment-method' instead."), @AllowedValue(value = "assessment-objective", description = "The part defines an assessment objective."), @AllowedValue(value = "assessment-method", description = "The part defines an assessment method.")})
038)
039@AssemblyConstraints(
040    hasCardinality = {
041        @HasCardinality(level = IConstraint.Level.ERROR, target = "part[has-oscal-namespace('http://csrc.nist.gov/ns/oscal') and @name=('objective','assessment-objective')]", maxOccurs = 1),
042        @HasCardinality(level = IConstraint.Level.ERROR, target = "part[has-oscal-namespace('http://csrc.nist.gov/ns/oscal') and @name=('assessment','assessment-method')]/prop[has-oscal-namespace(('http://csrc.nist.gov/ns/oscal','http://csrc.nist.gov/ns/rmf')) and @name='method']", minOccurs = 1, maxOccurs = 1),
043        @HasCardinality(level = IConstraint.Level.ERROR, target = "part[has-oscal-namespace('http://csrc.nist.gov/ns/oscal') and @name=('assessment','assessment-method')]/part[has-oscal-namespace('http://csrc.nist.gov/ns/oscal') and @name=('objects','assessment-objects')]", minOccurs = 1, maxOccurs = 1),
044        @HasCardinality(level = IConstraint.Level.ERROR, target = "part[has-oscal-namespace('http://csrc.nist.gov/ns/oscal') and @name=('objective','assessment-objective')]/prop[has-oscal-namespace('http://csrc.nist.gov/ns/oscal') and @name='method-id']", minOccurs = 1)
045    }
046)
047public class LocalObjective {
048  @BoundFlag(
049      formalName = "Control Identifier Reference",
050      description = "A reference to a control with a corresponding `id` value. When referencing an externally defined `control`, the `Control Identifier Reference` must be used in the context of the external / imported OSCAL instance (e.g., uri-reference).",
051      useName = "control-id",
052      required = true,
053      typeAdapter = TokenAdapter.class,
054      remarks = "The specified `control-id` must be a valid value within the baseline identified by the target system's SSP via the `import-profile` statement."
055  )
056  private String _controlId;
057
058  /**
059   * "A human-readable description of this control objective."
060   */
061  @BoundField(
062      formalName = "Objective Description",
063      description = "A human-readable description of this control objective.",
064      useName = "description"
065  )
066  @BoundFieldValue(
067      typeAdapter = MarkupMultilineAdapter.class
068  )
069  private MarkupMultiline _description;
070
071  @BoundAssembly(
072      formalName = "Property",
073      description = "An attribute, characteristic, or quality of the containing object expressed as a namespace qualified name/value pair.",
074      useName = "prop",
075      maxOccurs = -1
076  )
077  @GroupAs(
078      name = "props",
079      inJson = JsonGroupAsBehavior.LIST
080  )
081  private List<Property> _props;
082
083  @BoundAssembly(
084      formalName = "Link",
085      description = "A reference to a local or remote resource, that has a specific relation to the containing object.",
086      useName = "link",
087      maxOccurs = -1
088  )
089  @GroupAs(
090      name = "links",
091      inJson = JsonGroupAsBehavior.LIST
092  )
093  private List<Link> _links;
094
095  @BoundAssembly(
096      formalName = "Part",
097      description = "An annotated, markup-based textual element of a control's or catalog group's definition, or a child of another part.",
098      useName = "part",
099      minOccurs = 1,
100      maxOccurs = -1
101  )
102  @GroupAs(
103      name = "parts",
104      inJson = JsonGroupAsBehavior.LIST
105  )
106  private List<ControlPart> _parts;
107
108  @BoundField(
109      formalName = "Remarks",
110      description = "Additional commentary about the containing object.",
111      useName = "remarks"
112  )
113  @BoundFieldValue(
114      typeAdapter = MarkupMultilineAdapter.class
115  )
116  private MarkupMultiline _remarks;
117
118  public LocalObjective() {
119  }
120
121  public String getControlId() {
122    return _controlId;
123  }
124
125  public void setControlId(String value) {
126    _controlId = value;
127  }
128
129  public MarkupMultiline getDescription() {
130    return _description;
131  }
132
133  public void setDescription(MarkupMultiline value) {
134    _description = value;
135  }
136
137  public List<Property> getProps() {
138    return _props;
139  }
140
141  public void setProps(List<Property> value) {
142    _props = value;
143  }
144
145  /**
146   * Add a new {@link Property} item to the underlying collection.
147   * @param item the item to add
148   * @return {@code true}
149   */
150  public boolean addProp(Property item) {
151    Property value = ObjectUtils.requireNonNull(item,"item cannot be null");
152    if (_props == null) {
153      _props = new LinkedList<>();
154    }
155    return _props.add(value);
156  }
157
158  /**
159   * Remove the first matching {@link Property} item from the underlying collection.
160   * @param item the item to remove
161   * @return {@code true} if the item was removed or {@code false} otherwise
162   */
163  public boolean removeProp(Property item) {
164    Property value = ObjectUtils.requireNonNull(item,"item cannot be null");
165    return _props == null ? false : _props.remove(value);
166  }
167
168  public List<Link> getLinks() {
169    return _links;
170  }
171
172  public void setLinks(List<Link> value) {
173    _links = value;
174  }
175
176  /**
177   * Add a new {@link Link} item to the underlying collection.
178   * @param item the item to add
179   * @return {@code true}
180   */
181  public boolean addLink(Link item) {
182    Link value = ObjectUtils.requireNonNull(item,"item cannot be null");
183    if (_links == null) {
184      _links = new LinkedList<>();
185    }
186    return _links.add(value);
187  }
188
189  /**
190   * Remove the first matching {@link Link} item from the underlying collection.
191   * @param item the item to remove
192   * @return {@code true} if the item was removed or {@code false} otherwise
193   */
194  public boolean removeLink(Link item) {
195    Link value = ObjectUtils.requireNonNull(item,"item cannot be null");
196    return _links == null ? false : _links.remove(value);
197  }
198
199  public List<ControlPart> getParts() {
200    return _parts;
201  }
202
203  public void setParts(List<ControlPart> value) {
204    _parts = value;
205  }
206
207  /**
208   * Add a new {@link ControlPart} item to the underlying collection.
209   * @param item the item to add
210   * @return {@code true}
211   */
212  public boolean addPart(ControlPart item) {
213    ControlPart value = ObjectUtils.requireNonNull(item,"item cannot be null");
214    if (_parts == null) {
215      _parts = new LinkedList<>();
216    }
217    return _parts.add(value);
218  }
219
220  /**
221   * Remove the first matching {@link ControlPart} item from the underlying collection.
222   * @param item the item to remove
223   * @return {@code true} if the item was removed or {@code false} otherwise
224   */
225  public boolean removePart(ControlPart item) {
226    ControlPart value = ObjectUtils.requireNonNull(item,"item cannot be null");
227    return _parts == null ? false : _parts.remove(value);
228  }
229
230  public MarkupMultiline getRemarks() {
231    return _remarks;
232  }
233
234  public void setRemarks(MarkupMultiline value) {
235    _remarks = value;
236  }
237
238  @Override
239  public String toString() {
240    return new ReflectionToStringBuilder(this, MultilineRecursiveToStringStyle.MULTI_LINE_STYLE).toString();
241  }
242}