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