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.BoundAssembly;
006import gov.nist.secauto.metaschema.binding.model.annotations.BoundField;
007import gov.nist.secauto.metaschema.binding.model.annotations.BoundFieldValue;
008import gov.nist.secauto.metaschema.binding.model.annotations.BoundFlag;
009import gov.nist.secauto.metaschema.binding.model.annotations.GroupAs;
010import gov.nist.secauto.metaschema.binding.model.annotations.MetaschemaAssembly;
011import gov.nist.secauto.metaschema.binding.model.annotations.ValueConstraints;
012import gov.nist.secauto.metaschema.model.common.JsonGroupAsBehavior;
013import gov.nist.secauto.metaschema.model.common.constraint.IConstraint;
014import gov.nist.secauto.metaschema.model.common.datatype.adapter.TokenAdapter;
015import gov.nist.secauto.metaschema.model.common.datatype.markup.MarkupLine;
016import gov.nist.secauto.metaschema.model.common.datatype.markup.MarkupLineAdapter;
017import gov.nist.secauto.metaschema.model.common.util.ObjectUtils;
018import gov.nist.secauto.oscal.lib.model.control.catalog.AbstractCatalogGroup;
019import java.lang.Override;
020import java.lang.String;
021import java.util.LinkedList;
022import java.util.List;
023import org.apache.commons.lang3.builder.MultilineRecursiveToStringStyle;
024import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
025
026/**
027 * A group of controls, or of groups of controls.
028 */
029@MetaschemaAssembly(
030    formalName = "Control Group",
031    description = "A group of controls, or of groups of controls.",
032    name = "group",
033    metaschema = OscalCatalogMetaschema.class,
034    remarks = "Catalogs can use the catalog `group` construct to organize related controls into a single grouping, such as a family of controls or other logical organizational structure.\n"
035            + "\n"
036            + "A `group` may have its own properties, statements, parameters, and references, which are inherited by all controls of that are a member of the group."
037)
038@ValueConstraints(
039    allowedValues = {
040        @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.")}),
041        @AllowedValues(level = IConstraint.Level.ERROR, target = "part[has-oscal-namespace('http://csrc.nist.gov/ns/oscal')]/@name", values = {@AllowedValue(value = "overview", description = "An introduction to a control or a group of controls."), @AllowedValue(value = "instruction", description = "Information providing directions for a control or a group of controls.")})
042    }
043)
044public class CatalogGroup extends AbstractCatalogGroup {
045  @BoundFlag(
046      formalName = "Group Identifier",
047      description = "Identifies the group for the purpose of cross-linking within the defining instance or from other instances that reference the catalog.",
048      useName = "id",
049      typeAdapter = TokenAdapter.class
050  )
051  private String _id;
052
053  @BoundFlag(
054      formalName = "Group Class",
055      description = "A textual label that provides a sub-type or characterization of the group.",
056      useName = "class",
057      typeAdapter = TokenAdapter.class,
058      remarks = "A `class` can be used in validation rules to express extra constraints over named items of a specific `class` value.\n"
059              + "\n"
060              + "A `class` can also be used in an OSCAL profile as a means to target an alteration to control content."
061  )
062  private String _clazz;
063
064  /**
065   * "A name given to the group, which may be used by a tool for display and navigation."
066   */
067  @BoundField(
068      formalName = "Group Title",
069      description = "A name given to the group, which may be used by a tool for display and navigation.",
070      useName = "title",
071      minOccurs = 1
072  )
073  @BoundFieldValue(
074      typeAdapter = MarkupLineAdapter.class
075  )
076  private MarkupLine _title;
077
078  @BoundAssembly(
079      formalName = "Parameter",
080      description = "Parameters provide a mechanism for the dynamic assignment of value(s) in a control.",
081      useName = "param",
082      maxOccurs = -1
083  )
084  @GroupAs(
085      name = "params",
086      inJson = JsonGroupAsBehavior.LIST
087  )
088  private List<Parameter> _params;
089
090  @BoundAssembly(
091      formalName = "Property",
092      description = "An attribute, characteristic, or quality of the containing object expressed as a namespace qualified name/value pair.",
093      useName = "prop",
094      maxOccurs = -1
095  )
096  @GroupAs(
097      name = "props",
098      inJson = JsonGroupAsBehavior.LIST
099  )
100  private List<Property> _props;
101
102  @BoundAssembly(
103      formalName = "Link",
104      description = "A reference to a local or remote resource, that has a specific relation to the containing object.",
105      useName = "link",
106      maxOccurs = -1
107  )
108  @GroupAs(
109      name = "links",
110      inJson = JsonGroupAsBehavior.LIST
111  )
112  private List<Link> _links;
113
114  @BoundAssembly(
115      formalName = "Part",
116      description = "An annotated, markup-based textual element of a control's or catalog group's definition, or a child of another part.",
117      useName = "part",
118      maxOccurs = -1
119  )
120  @GroupAs(
121      name = "parts",
122      inJson = JsonGroupAsBehavior.LIST
123  )
124  private List<ControlPart> _parts;
125
126  @BoundAssembly(
127      formalName = "Control Group",
128      description = "A group of controls, or of groups of controls.",
129      useName = "group",
130      maxOccurs = -1
131  )
132  @GroupAs(
133      name = "groups",
134      inJson = JsonGroupAsBehavior.LIST
135  )
136  private List<CatalogGroup> _groups;
137
138  @BoundAssembly(
139      formalName = "Control",
140      description = "A [structured object](https://pages.nist.gov/OSCAL/concepts/terminology/#control) representing a requirement or guideline, which when implemented will reduce an aspect of risk related to an information system and its information.",
141      useName = "control",
142      maxOccurs = -1
143  )
144  @GroupAs(
145      name = "controls",
146      inJson = JsonGroupAsBehavior.LIST
147  )
148  private List<Control> _controls;
149
150  public CatalogGroup() {
151  }
152
153  public String getId() {
154    return _id;
155  }
156
157  public void setId(String value) {
158    _id = value;
159  }
160
161  public String getClazz() {
162    return _clazz;
163  }
164
165  public void setClazz(String value) {
166    _clazz = value;
167  }
168
169  public MarkupLine getTitle() {
170    return _title;
171  }
172
173  public void setTitle(MarkupLine value) {
174    _title = value;
175  }
176
177  public List<Parameter> getParams() {
178    return _params;
179  }
180
181  public void setParams(List<Parameter> value) {
182    _params = value;
183  }
184
185  /**
186   * Add a new {@link Parameter} item to the underlying collection.
187   * @param item the item to add
188   * @return {@code true}
189   */
190  public boolean addParam(Parameter item) {
191    Parameter value = ObjectUtils.requireNonNull(item,"item cannot be null");
192    if (_params == null) {
193      _params = new LinkedList<>();
194    }
195    return _params.add(value);
196  }
197
198  /**
199   * Remove the first matching {@link Parameter} item from the underlying collection.
200   * @param item the item to remove
201   * @return {@code true} if the item was removed or {@code false} otherwise
202   */
203  public boolean removeParam(Parameter item) {
204    Parameter value = ObjectUtils.requireNonNull(item,"item cannot be null");
205    return _params == null ? false : _params.remove(value);
206  }
207
208  public List<Property> getProps() {
209    return _props;
210  }
211
212  public void setProps(List<Property> value) {
213    _props = value;
214  }
215
216  /**
217   * Add a new {@link Property} item to the underlying collection.
218   * @param item the item to add
219   * @return {@code true}
220   */
221  public boolean addProp(Property item) {
222    Property value = ObjectUtils.requireNonNull(item,"item cannot be null");
223    if (_props == null) {
224      _props = new LinkedList<>();
225    }
226    return _props.add(value);
227  }
228
229  /**
230   * Remove the first matching {@link Property} item from the underlying collection.
231   * @param item the item to remove
232   * @return {@code true} if the item was removed or {@code false} otherwise
233   */
234  public boolean removeProp(Property item) {
235    Property value = ObjectUtils.requireNonNull(item,"item cannot be null");
236    return _props == null ? false : _props.remove(value);
237  }
238
239  public List<Link> getLinks() {
240    return _links;
241  }
242
243  public void setLinks(List<Link> value) {
244    _links = value;
245  }
246
247  /**
248   * Add a new {@link Link} item to the underlying collection.
249   * @param item the item to add
250   * @return {@code true}
251   */
252  public boolean addLink(Link item) {
253    Link value = ObjectUtils.requireNonNull(item,"item cannot be null");
254    if (_links == null) {
255      _links = new LinkedList<>();
256    }
257    return _links.add(value);
258  }
259
260  /**
261   * Remove the first matching {@link Link} item from the underlying collection.
262   * @param item the item to remove
263   * @return {@code true} if the item was removed or {@code false} otherwise
264   */
265  public boolean removeLink(Link item) {
266    Link value = ObjectUtils.requireNonNull(item,"item cannot be null");
267    return _links == null ? false : _links.remove(value);
268  }
269
270  public List<ControlPart> getParts() {
271    return _parts;
272  }
273
274  public void setParts(List<ControlPart> value) {
275    _parts = value;
276  }
277
278  /**
279   * Add a new {@link ControlPart} item to the underlying collection.
280   * @param item the item to add
281   * @return {@code true}
282   */
283  public boolean addPart(ControlPart item) {
284    ControlPart value = ObjectUtils.requireNonNull(item,"item cannot be null");
285    if (_parts == null) {
286      _parts = new LinkedList<>();
287    }
288    return _parts.add(value);
289  }
290
291  /**
292   * Remove the first matching {@link ControlPart} item from the underlying collection.
293   * @param item the item to remove
294   * @return {@code true} if the item was removed or {@code false} otherwise
295   */
296  public boolean removePart(ControlPart item) {
297    ControlPart value = ObjectUtils.requireNonNull(item,"item cannot be null");
298    return _parts == null ? false : _parts.remove(value);
299  }
300
301  public List<CatalogGroup> getGroups() {
302    return _groups;
303  }
304
305  public void setGroups(List<CatalogGroup> value) {
306    _groups = value;
307  }
308
309  /**
310   * Add a new {@link CatalogGroup} item to the underlying collection.
311   * @param item the item to add
312   * @return {@code true}
313   */
314  public boolean addGroup(CatalogGroup item) {
315    CatalogGroup value = ObjectUtils.requireNonNull(item,"item cannot be null");
316    if (_groups == null) {
317      _groups = new LinkedList<>();
318    }
319    return _groups.add(value);
320  }
321
322  /**
323   * Remove the first matching {@link CatalogGroup} item from the underlying collection.
324   * @param item the item to remove
325   * @return {@code true} if the item was removed or {@code false} otherwise
326   */
327  public boolean removeGroup(CatalogGroup item) {
328    CatalogGroup value = ObjectUtils.requireNonNull(item,"item cannot be null");
329    return _groups == null ? false : _groups.remove(value);
330  }
331
332  public List<Control> getControls() {
333    return _controls;
334  }
335
336  public void setControls(List<Control> value) {
337    _controls = value;
338  }
339
340  /**
341   * Add a new {@link Control} item to the underlying collection.
342   * @param item the item to add
343   * @return {@code true}
344   */
345  public boolean addControl(Control item) {
346    Control value = ObjectUtils.requireNonNull(item,"item cannot be null");
347    if (_controls == null) {
348      _controls = new LinkedList<>();
349    }
350    return _controls.add(value);
351  }
352
353  /**
354   * Remove the first matching {@link Control} item from the underlying collection.
355   * @param item the item to remove
356   * @return {@code true} if the item was removed or {@code false} otherwise
357   */
358  public boolean removeControl(Control item) {
359    Control value = ObjectUtils.requireNonNull(item,"item cannot be null");
360    return _controls == null ? false : _controls.remove(value);
361  }
362
363  @Override
364  public String toString() {
365    return new ReflectionToStringBuilder(this, MultilineRecursiveToStringStyle.MULTI_LINE_STYLE).toString();
366  }
367}