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