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.BoundFlag;
008import gov.nist.secauto.metaschema.binding.model.annotations.GroupAs;
009import gov.nist.secauto.metaschema.binding.model.annotations.Index;
010import gov.nist.secauto.metaschema.binding.model.annotations.KeyField;
011import gov.nist.secauto.metaschema.binding.model.annotations.MetaschemaAssembly;
012import gov.nist.secauto.metaschema.binding.model.annotations.ValueConstraints;
013import gov.nist.secauto.metaschema.model.common.JsonGroupAsBehavior;
014import gov.nist.secauto.metaschema.model.common.constraint.IConstraint;
015import gov.nist.secauto.metaschema.model.common.datatype.adapter.UuidAdapter;
016import gov.nist.secauto.metaschema.model.common.util.ObjectUtils;
017import gov.nist.secauto.oscal.lib.model.control.catalog.AbstractCatalog;
018import java.lang.Override;
019import java.lang.String;
020import java.util.LinkedList;
021import java.util.List;
022import java.util.UUID;
023import org.apache.commons.lang3.builder.MultilineRecursiveToStringStyle;
024import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
025
026/**
027 * A structured, <a href="https://pages.nist.gov/OSCAL/concepts/terminology/#catalog">organized collection</a> of control information.
028 */
029@MetaschemaAssembly(
030    formalName = "Catalog",
031    description = "A structured, [organized collection](https://pages.nist.gov/OSCAL/concepts/terminology/#catalog) of control information.",
032    name = "catalog",
033    metaschema = OscalCatalogMetaschema.class,
034    rootName = "catalog",
035    remarks = "Catalogs may use one or more `group` objects to subdivide the control contents of a catalog."
036)
037@ValueConstraints(
038    allowedValues = {
039        @AllowedValues(level = IConstraint.Level.ERROR, target = "metadata/prop[has-oscal-namespace('http://csrc.nist.gov/ns/oscal')]/@name", values = {@AllowedValue(value = "resolution-tool", description = "The tool used to produce a resolved profile."), @AllowedValue(value = "source-profile-uuid", description = "The document-level `uuid` of the source profile from which the catalog was produced by [profile resolution](https://pages.nist.gov/OSCAL/concepts/processing/profile-resolution/).")}),
040        @AllowedValues(level = IConstraint.Level.ERROR, target = "metadata/link/@rel", allowOthers = true, values = {@AllowedValue(value = "source-profile", description = "The profile from which the catalog was produced by [profile resolution](https://pages.nist.gov/OSCAL/concepts/processing/profile-resolution/)."), @AllowedValue(value = "source-profile-uuid", description = "The document-level `uuid` of the profile from which the catalog was produced by [profile resolution](https://pages.nist.gov/OSCAL/concepts/processing/profile-resolution/).")})
041    }
042)
043@AssemblyConstraints(
044    index = {
045        @Index(level = IConstraint.Level.ERROR, target = "//part", name = "catalog-parts", keyFields = @KeyField(target = "@id")),
046        @Index(level = IConstraint.Level.ERROR, target = "//prop", name = "catalog-props", keyFields = @KeyField(target = "@uuid")),
047        @Index(level = IConstraint.Level.ERROR, target = "//(control|group|part)", name = "catalog-groups-controls-parts", keyFields = @KeyField(target = "@id")),
048        @Index(level = IConstraint.Level.ERROR, target = "//control", name = "catalog-controls", keyFields = @KeyField(target = "@id")),
049        @Index(level = IConstraint.Level.ERROR, target = "//param", name = "catalog-params", keyFields = @KeyField(target = "@id")),
050        @Index(level = IConstraint.Level.ERROR, target = "//group", name = "catalog-groups", keyFields = @KeyField(target = "@id"))
051    }
052)
053public class Catalog extends AbstractCatalog {
054  @BoundFlag(
055      formalName = "Catalog Universally Unique Identifier",
056      description = "Provides a globally unique means to identify a given catalog instance.",
057      useName = "uuid",
058      required = true,
059      typeAdapter = UuidAdapter.class
060  )
061  private UUID _uuid;
062
063  @BoundAssembly(
064      formalName = "Document Metadata",
065      description = "Provides information about the containing document, and defines concepts that are shared across the document.",
066      useName = "metadata",
067      minOccurs = 1
068  )
069  private Metadata _metadata;
070
071  @BoundAssembly(
072      formalName = "Parameter",
073      description = "Parameters provide a mechanism for the dynamic assignment of value(s) in a control.",
074      useName = "param",
075      maxOccurs = -1
076  )
077  @GroupAs(
078      name = "params",
079      inJson = JsonGroupAsBehavior.LIST
080  )
081  private List<Parameter> _params;
082
083  @BoundAssembly(
084      formalName = "Control",
085      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.",
086      useName = "control",
087      maxOccurs = -1
088  )
089  @GroupAs(
090      name = "controls",
091      inJson = JsonGroupAsBehavior.LIST
092  )
093  private List<Control> _controls;
094
095  @BoundAssembly(
096      formalName = "Control Group",
097      description = "A group of controls, or of groups of controls.",
098      useName = "group",
099      maxOccurs = -1
100  )
101  @GroupAs(
102      name = "groups",
103      inJson = JsonGroupAsBehavior.LIST
104  )
105  private List<CatalogGroup> _groups;
106
107  @BoundAssembly(
108      formalName = "Back matter",
109      description = "A collection of resources that may be referenced from within the OSCAL document instance.",
110      useName = "back-matter",
111      remarks = "Back matter including references and resources."
112  )
113  private BackMatter _backMatter;
114
115  public Catalog() {
116  }
117
118  public UUID getUuid() {
119    return _uuid;
120  }
121
122  public void setUuid(UUID value) {
123    _uuid = value;
124  }
125
126  public Metadata getMetadata() {
127    return _metadata;
128  }
129
130  public void setMetadata(Metadata value) {
131    _metadata = value;
132  }
133
134  public List<Parameter> getParams() {
135    return _params;
136  }
137
138  public void setParams(List<Parameter> value) {
139    _params = value;
140  }
141
142  /**
143   * Add a new {@link Parameter} item to the underlying collection.
144   * @param item the item to add
145   * @return {@code true}
146   */
147  public boolean addParam(Parameter item) {
148    Parameter value = ObjectUtils.requireNonNull(item,"item cannot be null");
149    if (_params == null) {
150      _params = new LinkedList<>();
151    }
152    return _params.add(value);
153  }
154
155  /**
156   * Remove the first matching {@link Parameter} item from the underlying collection.
157   * @param item the item to remove
158   * @return {@code true} if the item was removed or {@code false} otherwise
159   */
160  public boolean removeParam(Parameter item) {
161    Parameter value = ObjectUtils.requireNonNull(item,"item cannot be null");
162    return _params == null ? false : _params.remove(value);
163  }
164
165  public List<Control> getControls() {
166    return _controls;
167  }
168
169  public void setControls(List<Control> value) {
170    _controls = value;
171  }
172
173  /**
174   * Add a new {@link Control} item to the underlying collection.
175   * @param item the item to add
176   * @return {@code true}
177   */
178  public boolean addControl(Control item) {
179    Control value = ObjectUtils.requireNonNull(item,"item cannot be null");
180    if (_controls == null) {
181      _controls = new LinkedList<>();
182    }
183    return _controls.add(value);
184  }
185
186  /**
187   * Remove the first matching {@link Control} item from the underlying collection.
188   * @param item the item to remove
189   * @return {@code true} if the item was removed or {@code false} otherwise
190   */
191  public boolean removeControl(Control item) {
192    Control value = ObjectUtils.requireNonNull(item,"item cannot be null");
193    return _controls == null ? false : _controls.remove(value);
194  }
195
196  public List<CatalogGroup> getGroups() {
197    return _groups;
198  }
199
200  public void setGroups(List<CatalogGroup> value) {
201    _groups = value;
202  }
203
204  /**
205   * Add a new {@link CatalogGroup} item to the underlying collection.
206   * @param item the item to add
207   * @return {@code true}
208   */
209  public boolean addGroup(CatalogGroup item) {
210    CatalogGroup value = ObjectUtils.requireNonNull(item,"item cannot be null");
211    if (_groups == null) {
212      _groups = new LinkedList<>();
213    }
214    return _groups.add(value);
215  }
216
217  /**
218   * Remove the first matching {@link CatalogGroup} item from the underlying collection.
219   * @param item the item to remove
220   * @return {@code true} if the item was removed or {@code false} otherwise
221   */
222  public boolean removeGroup(CatalogGroup item) {
223    CatalogGroup value = ObjectUtils.requireNonNull(item,"item cannot be null");
224    return _groups == null ? false : _groups.remove(value);
225  }
226
227  public BackMatter getBackMatter() {
228    return _backMatter;
229  }
230
231  public void setBackMatter(BackMatter value) {
232    _backMatter = value;
233  }
234
235  @Override
236  public String toString() {
237    return new ReflectionToStringBuilder(this, MultilineRecursiveToStringStyle.MULTI_LINE_STYLE).toString();
238  }
239}