001package gov.nist.secauto.oscal.lib.model;
002
003import gov.nist.secauto.metaschema.core.datatype.adapter.TokenAdapter;
004import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLine;
005import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLineAdapter;
006import gov.nist.secauto.metaschema.core.datatype.markup.MarkupMultiline;
007import gov.nist.secauto.metaschema.core.datatype.markup.MarkupMultilineAdapter;
008import gov.nist.secauto.metaschema.core.model.IBoundObject;
009import gov.nist.secauto.metaschema.core.model.IMetaschemaData;
010import gov.nist.secauto.metaschema.core.model.JsonGroupAsBehavior;
011import gov.nist.secauto.metaschema.core.model.constraint.IConstraint;
012import gov.nist.secauto.metaschema.core.util.ObjectUtils;
013import gov.nist.secauto.metaschema.databind.model.annotations.AllowedValue;
014import gov.nist.secauto.metaschema.databind.model.annotations.AllowedValues;
015import gov.nist.secauto.metaschema.databind.model.annotations.BoundAssembly;
016import gov.nist.secauto.metaschema.databind.model.annotations.BoundField;
017import gov.nist.secauto.metaschema.databind.model.annotations.BoundFlag;
018import gov.nist.secauto.metaschema.databind.model.annotations.Expect;
019import gov.nist.secauto.metaschema.databind.model.annotations.GroupAs;
020import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaAssembly;
021import gov.nist.secauto.metaschema.databind.model.annotations.ValueConstraints;
022import gov.nist.secauto.oscal.lib.model.control.AbstractParameter;
023import java.lang.Override;
024import java.lang.String;
025import java.util.LinkedList;
026import java.util.List;
027import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
028import org.apache.commons.lang3.builder.ToStringStyle;
029
030/**
031 * Parameters provide a mechanism for the dynamic assignment of value(s) in a control.
032 */
033@MetaschemaAssembly(
034    formalName = "Parameter",
035    description = "Parameters provide a mechanism for the dynamic assignment of value(s) in a control.",
036    name = "parameter",
037    moduleClass = OscalControlCommonModule.class,
038    remarks = "In a catalog, a parameter is typically used as a placeholder for the future assignment of a parameter value, although the OSCAL model allows for the direct assignment of a value if desired by the control author. The `value` may be optionally used to specify one or more values. If no value is provided, then it is expected that the value will be provided at the Profile or Implementation layer.\n"
039            + "\n"
040            + "A parameter can include a variety of metadata options that support the future solicitation of one or more values. A `label` provides a textual placeholder that can be used in a tool to solicit parameter value input, or to display in catalog documentation. The `desc` provides a short description of what the parameter is used for, which can be used in tooling to help a user understand how to use the parameter. A `constraint` can be used to provide criteria for the allowed values. A `guideline` provides a recommendation for the use of a parameter.",
041    valueConstraints = @ValueConstraints(allowedValues = {@AllowedValues(level = IConstraint.Level.ERROR, target = "prop[has-oscal-namespace('http://csrc.nist.gov/ns/oscal')]/@name", values = {@AllowedValue(value = "label", description = "A human-readable label for the parent context, which may be rendered in place of the actual identifier for some use cases."), @AllowedValue(value = "sort-id", description = "An alternative identifier, whose value is easily sortable among other such values in the document."), @AllowedValue(value = "alt-identifier", description = "An alternate or aliased identifier for the parent context."), @AllowedValue(value = "alt-label", description = "An alternate to the value provided by the parameter's label. This will typically be qualified by a class.")}), @AllowedValues(level = IConstraint.Level.ERROR, target = "prop[has-oscal-namespace('http://csrc.nist.gov/ns/rmf')]/@name", values = @AllowedValue(value = "aggregates", description = "The parent parameter provides an aggregation of two or more other parameters, each described by this property."))}, expect = @Expect(level = IConstraint.Level.ERROR, test = "not(exists(@depends-on))", message = "depends-on is deprecated"))
042)
043public class Parameter extends AbstractParameter implements IBoundObject {
044  private final IMetaschemaData __metaschemaData;
045
046  /**
047   * "A unique identifier for the parameter."
048   */
049  @BoundFlag(
050      formalName = "Parameter Identifier",
051      description = "A unique identifier for the parameter.",
052      name = "id",
053      required = true,
054      typeAdapter = TokenAdapter.class
055  )
056  private String _id;
057
058  /**
059   * "A textual label that provides a characterization of the type, purpose, use or scope of the parameter."
060   */
061  @BoundFlag(
062      formalName = "Parameter Class",
063      description = "A textual label that provides a characterization of the type, purpose, use or scope of the parameter.",
064      name = "class",
065      typeAdapter = TokenAdapter.class,
066      remarks = "A `class` can be used in validation rules to express extra constraints over named items of a specific `class` value."
067  )
068  private String _clazz;
069
070  /**
071   * "<strong>(deprecated)</strong> Another parameter invoking this one. This construct has been deprecated and should not be used."
072   */
073  @BoundFlag(
074      formalName = "Depends on",
075      description = "**(deprecated)** Another parameter invoking this one. This construct has been deprecated and should not be used.",
076      name = "depends-on",
077      typeAdapter = TokenAdapter.class
078  )
079  private String _dependsOn;
080
081  @BoundAssembly(
082      formalName = "Property",
083      description = "An attribute, characteristic, or quality of the containing object expressed as a namespace qualified name/value pair.",
084      useName = "prop",
085      maxOccurs = -1,
086      groupAs = @GroupAs(name = "props", inJson = JsonGroupAsBehavior.LIST)
087  )
088  private List<Property> _props;
089
090  @BoundAssembly(
091      formalName = "Link",
092      description = "A reference to a local or remote resource, that has a specific relation to the containing object.",
093      useName = "link",
094      maxOccurs = -1,
095      groupAs = @GroupAs(name = "links", inJson = JsonGroupAsBehavior.LIST)
096  )
097  private List<Link> _links;
098
099  @BoundField(
100      formalName = "Parameter Label",
101      description = "A short, placeholder name for the parameter, which can be used as a substitute for a `value` if no value is assigned.",
102      useName = "label",
103      remarks = "The label value is intended use when rendering a parameter in generated documentation or a user interface when a parameter is referenced. Note that labels are not required to be distinctive, which means that parameters within the same control may have the same label.",
104      typeAdapter = MarkupLineAdapter.class
105  )
106  private MarkupLine _label;
107
108  @BoundField(
109      formalName = "Parameter Usage Description",
110      description = "Describes the purpose and use of a parameter.",
111      useName = "usage",
112      typeAdapter = MarkupMultilineAdapter.class
113  )
114  private MarkupMultiline _usage;
115
116  @BoundAssembly(
117      formalName = "Constraint",
118      description = "A formal or informal expression of a constraint or test.",
119      useName = "constraint",
120      maxOccurs = -1,
121      groupAs = @GroupAs(name = "constraints", inJson = JsonGroupAsBehavior.LIST)
122  )
123  private List<ParameterConstraint> _constraints;
124
125  @BoundAssembly(
126      formalName = "Guideline",
127      description = "A prose statement that provides a recommendation for the use of a parameter.",
128      useName = "guideline",
129      maxOccurs = -1,
130      groupAs = @GroupAs(name = "guidelines", inJson = JsonGroupAsBehavior.LIST)
131  )
132  private List<ParameterGuideline> _guidelines;
133
134  @BoundField(
135      formalName = "Parameter Value",
136      description = "A parameter value or set of values.",
137      useName = "value",
138      remarks = "A set of values provided in a catalog can be redefined in OSCAL's `profile` or `system-security-plan` models.",
139      maxOccurs = -1,
140      groupAs = @GroupAs(name = "values", inJson = JsonGroupAsBehavior.LIST)
141  )
142  private List<String> _values;
143
144  @BoundAssembly(
145      formalName = "Selection",
146      description = "Presenting a choice among alternatives.",
147      useName = "select",
148      remarks = "The OSCAL parameter `value` construct can be used to prescribe a specific parameter value in a catalog or profile. In cases where a prescriptive value is not possible in a catalog or profile, it may be possible to constrain the set of possible values to a few options. Use of `select` in a parameter instead of `value` is a way of defining value options that **may** be set.\n"
149              + "\n"
150              + "A set of allowed parameter values expressed as a set of options which may be selected. These options constrain the permissible values that may be selected for the containing parameter. When the value assignment is made, such as in an OSCAL profile or system security plan, the actual selected value can be examined to determine if it matches one of the permissible choices for the parameter value.\n"
151              + "\n"
152              + "When the value of `how-many` is set to \"one-or-more\", multiple values may be assigned reflecting more than one choice."
153  )
154  private ParameterSelection _select;
155
156  @BoundField(
157      formalName = "Remarks",
158      description = "Additional commentary about the containing object.",
159      useName = "remarks",
160      typeAdapter = MarkupMultilineAdapter.class
161  )
162  private MarkupMultiline _remarks;
163
164  public Parameter() {
165    this(null);
166  }
167
168  public Parameter(IMetaschemaData data) {
169    this.__metaschemaData = data;
170  }
171
172  @Override
173  public IMetaschemaData getMetaschemaData() {
174    return __metaschemaData;
175  }
176
177  public String getId() {
178    return _id;
179  }
180
181  public void setId(String value) {
182    _id = value;
183  }
184
185  public String getClazz() {
186    return _clazz;
187  }
188
189  public void setClazz(String value) {
190    _clazz = value;
191  }
192
193  public String getDependsOn() {
194    return _dependsOn;
195  }
196
197  public void setDependsOn(String value) {
198    _dependsOn = value;
199  }
200
201  public List<Property> getProps() {
202    return _props;
203  }
204
205  public void setProps(List<Property> value) {
206    _props = value;
207  }
208
209  /**
210   * Add a new {@link Property} item to the underlying collection.
211   * @param item the item to add
212   * @return {@code true}
213   */
214  public boolean addProp(Property item) {
215    Property value = ObjectUtils.requireNonNull(item,"item cannot be null");
216    if (_props == null) {
217      _props = new LinkedList<>();
218    }
219    return _props.add(value);
220  }
221
222  /**
223   * Remove the first matching {@link Property} item from the underlying collection.
224   * @param item the item to remove
225   * @return {@code true} if the item was removed or {@code false} otherwise
226   */
227  public boolean removeProp(Property item) {
228    Property value = ObjectUtils.requireNonNull(item,"item cannot be null");
229    return _props != null && _props.remove(value);
230  }
231
232  public List<Link> getLinks() {
233    return _links;
234  }
235
236  public void setLinks(List<Link> value) {
237    _links = value;
238  }
239
240  /**
241   * Add a new {@link Link} item to the underlying collection.
242   * @param item the item to add
243   * @return {@code true}
244   */
245  public boolean addLink(Link item) {
246    Link value = ObjectUtils.requireNonNull(item,"item cannot be null");
247    if (_links == null) {
248      _links = new LinkedList<>();
249    }
250    return _links.add(value);
251  }
252
253  /**
254   * Remove the first matching {@link Link} item from the underlying collection.
255   * @param item the item to remove
256   * @return {@code true} if the item was removed or {@code false} otherwise
257   */
258  public boolean removeLink(Link item) {
259    Link value = ObjectUtils.requireNonNull(item,"item cannot be null");
260    return _links != null && _links.remove(value);
261  }
262
263  public MarkupLine getLabel() {
264    return _label;
265  }
266
267  public void setLabel(MarkupLine value) {
268    _label = value;
269  }
270
271  public MarkupMultiline getUsage() {
272    return _usage;
273  }
274
275  public void setUsage(MarkupMultiline value) {
276    _usage = value;
277  }
278
279  public List<ParameterConstraint> getConstraints() {
280    return _constraints;
281  }
282
283  public void setConstraints(List<ParameterConstraint> value) {
284    _constraints = value;
285  }
286
287  /**
288   * Add a new {@link ParameterConstraint} item to the underlying collection.
289   * @param item the item to add
290   * @return {@code true}
291   */
292  public boolean addConstraint(ParameterConstraint item) {
293    ParameterConstraint value = ObjectUtils.requireNonNull(item,"item cannot be null");
294    if (_constraints == null) {
295      _constraints = new LinkedList<>();
296    }
297    return _constraints.add(value);
298  }
299
300  /**
301   * Remove the first matching {@link ParameterConstraint} item from the underlying collection.
302   * @param item the item to remove
303   * @return {@code true} if the item was removed or {@code false} otherwise
304   */
305  public boolean removeConstraint(ParameterConstraint item) {
306    ParameterConstraint value = ObjectUtils.requireNonNull(item,"item cannot be null");
307    return _constraints != null && _constraints.remove(value);
308  }
309
310  public List<ParameterGuideline> getGuidelines() {
311    return _guidelines;
312  }
313
314  public void setGuidelines(List<ParameterGuideline> value) {
315    _guidelines = value;
316  }
317
318  /**
319   * Add a new {@link ParameterGuideline} item to the underlying collection.
320   * @param item the item to add
321   * @return {@code true}
322   */
323  public boolean addGuideline(ParameterGuideline item) {
324    ParameterGuideline value = ObjectUtils.requireNonNull(item,"item cannot be null");
325    if (_guidelines == null) {
326      _guidelines = new LinkedList<>();
327    }
328    return _guidelines.add(value);
329  }
330
331  /**
332   * Remove the first matching {@link ParameterGuideline} item from the underlying collection.
333   * @param item the item to remove
334   * @return {@code true} if the item was removed or {@code false} otherwise
335   */
336  public boolean removeGuideline(ParameterGuideline item) {
337    ParameterGuideline value = ObjectUtils.requireNonNull(item,"item cannot be null");
338    return _guidelines != null && _guidelines.remove(value);
339  }
340
341  public List<String> getValues() {
342    return _values;
343  }
344
345  public void setValues(List<String> value) {
346    _values = value;
347  }
348
349  /**
350   * Add a new {@link String} item to the underlying collection.
351   * @param item the item to add
352   * @return {@code true}
353   */
354  public boolean addValue(String item) {
355    String value = ObjectUtils.requireNonNull(item,"item cannot be null");
356    if (_values == null) {
357      _values = new LinkedList<>();
358    }
359    return _values.add(value);
360  }
361
362  /**
363   * Remove the first matching {@link String} item from the underlying collection.
364   * @param item the item to remove
365   * @return {@code true} if the item was removed or {@code false} otherwise
366   */
367  public boolean removeValue(String item) {
368    String value = ObjectUtils.requireNonNull(item,"item cannot be null");
369    return _values != null && _values.remove(value);
370  }
371
372  public ParameterSelection getSelect() {
373    return _select;
374  }
375
376  public void setSelect(ParameterSelection value) {
377    _select = value;
378  }
379
380  public MarkupMultiline getRemarks() {
381    return _remarks;
382  }
383
384  public void setRemarks(MarkupMultiline value) {
385    _remarks = value;
386  }
387
388  @Override
389  public String toString() {
390    return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString();
391  }
392}