001package gov.nist.secauto.oscal.lib.model; 002 003import gov.nist.secauto.metaschema.core.datatype.adapter.UriReferenceAdapter; 004import gov.nist.secauto.metaschema.core.datatype.adapter.UuidAdapter; 005import gov.nist.secauto.metaschema.core.datatype.markup.MarkupMultiline; 006import gov.nist.secauto.metaschema.core.datatype.markup.MarkupMultilineAdapter; 007import gov.nist.secauto.metaschema.core.model.IBoundObject; 008import gov.nist.secauto.metaschema.core.model.IMetaschemaData; 009import gov.nist.secauto.metaschema.core.model.JsonGroupAsBehavior; 010import gov.nist.secauto.metaschema.core.model.constraint.IConstraint; 011import gov.nist.secauto.metaschema.core.util.ObjectUtils; 012import gov.nist.secauto.metaschema.databind.model.annotations.AssemblyConstraints; 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.IsUnique; 018import gov.nist.secauto.metaschema.databind.model.annotations.KeyField; 019import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaAssembly; 020import java.lang.Override; 021import java.lang.String; 022import java.net.URI; 023import java.util.LinkedList; 024import java.util.List; 025import java.util.UUID; 026import org.apache.commons.lang3.builder.ReflectionToStringBuilder; 027import org.apache.commons.lang3.builder.ToStringStyle; 028 029/** 030 * Defines how the component or capability supports a set of controls. 031 */ 032@MetaschemaAssembly( 033 formalName = "Control Implementation Set", 034 description = "Defines how the component or capability supports a set of controls.", 035 name = "control-implementation", 036 moduleClass = OscalComponentDefinitionModule.class, 037 remarks = "Use of `set-parameter` in this context, sets the parameter for all controls referenced by any `implemented-requirement` contained in this context. Any `set-parameter` defined in a child context will override this value. If not overridden by a child, this value applies in the child context.", 038 modelConstraints = @AssemblyConstraints(unique = @IsUnique(id = "unique-component-definition-control-implementation-set-parameter", level = IConstraint.Level.ERROR, target = "set-parameter", keyFields = @KeyField(target = "@param-id"), remarks = "Since multiple `set-parameter` entries can be provided, each parameter must be set only once.")) 039) 040public class ComponentControlImplementation implements IBoundObject { 041 private final IMetaschemaData __metaschemaData; 042 043 /** 044 * "Provides a means to identify a set of control implementations that are supported by a given component or capability." 045 */ 046 @BoundFlag( 047 formalName = "Control Implementation Set Identifier", 048 description = "Provides a means to identify a set of control implementations that are supported by a given component or capability.", 049 name = "uuid", 050 required = true, 051 typeAdapter = UuidAdapter.class 052 ) 053 private UUID _uuid; 054 055 /** 056 * "A reference to an OSCAL catalog or profile providing the referenced control or subcontrol definition." 057 */ 058 @BoundFlag( 059 formalName = "Source Resource Reference", 060 description = "A reference to an OSCAL catalog or profile providing the referenced control or subcontrol definition.", 061 name = "source", 062 required = true, 063 typeAdapter = UriReferenceAdapter.class, 064 remarks = "This value may be one of:\n" 065 + "\n" 066 + "1. an [absolute URI](https://pages.nist.gov/OSCAL/concepts/uri-use/#absolute-uri) that points to a network resolvable resource,\n" 067 + "2. a [relative reference](https://pages.nist.gov/OSCAL/concepts/uri-use/#relative-reference) pointing to a network resolvable resource whose base URI is the URI of the containing document, or\n" 068 + "3. a bare URI fragment (i.e., \\`#uuid\\`) pointing to a `back-matter` resource in this or an imported document (see [linking to another OSCAL object](https://pages.nist.gov/OSCAL/concepts/uri-use/#linking-to-another-oscal-object))." 069 ) 070 private URI _source; 071 072 @BoundField( 073 formalName = "Control Implementation Description", 074 description = "A description of how the specified set of controls are implemented for the containing component or capability.", 075 useName = "description", 076 minOccurs = 1, 077 typeAdapter = MarkupMultilineAdapter.class 078 ) 079 private MarkupMultiline _description; 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 @BoundAssembly( 100 formalName = "Set Parameter Value", 101 description = "Identifies the parameter that will be set by the enclosed value.", 102 useName = "set-parameter", 103 maxOccurs = -1, 104 groupAs = @GroupAs(name = "set-parameters", inJson = JsonGroupAsBehavior.LIST) 105 ) 106 private List<SetParameter> _setParameters; 107 108 @BoundAssembly( 109 formalName = "Control Implementation", 110 description = "Describes how the containing component or capability implements an individual control.", 111 useName = "implemented-requirement", 112 minOccurs = 1, 113 maxOccurs = -1, 114 groupAs = @GroupAs(name = "implemented-requirements", inJson = JsonGroupAsBehavior.LIST) 115 ) 116 private List<ComponentImplementedRequirement> _implementedRequirements; 117 118 public ComponentControlImplementation() { 119 this(null); 120 } 121 122 public ComponentControlImplementation(IMetaschemaData data) { 123 this.__metaschemaData = data; 124 } 125 126 @Override 127 public IMetaschemaData getMetaschemaData() { 128 return __metaschemaData; 129 } 130 131 public UUID getUuid() { 132 return _uuid; 133 } 134 135 public void setUuid(UUID value) { 136 _uuid = value; 137 } 138 139 public URI getSource() { 140 return _source; 141 } 142 143 public void setSource(URI value) { 144 _source = value; 145 } 146 147 public MarkupMultiline getDescription() { 148 return _description; 149 } 150 151 public void setDescription(MarkupMultiline value) { 152 _description = value; 153 } 154 155 public List<Property> getProps() { 156 return _props; 157 } 158 159 public void setProps(List<Property> value) { 160 _props = value; 161 } 162 163 /** 164 * Add a new {@link Property} item to the underlying collection. 165 * @param item the item to add 166 * @return {@code true} 167 */ 168 public boolean addProp(Property item) { 169 Property value = ObjectUtils.requireNonNull(item,"item cannot be null"); 170 if (_props == null) { 171 _props = new LinkedList<>(); 172 } 173 return _props.add(value); 174 } 175 176 /** 177 * Remove the first matching {@link Property} item from the underlying collection. 178 * @param item the item to remove 179 * @return {@code true} if the item was removed or {@code false} otherwise 180 */ 181 public boolean removeProp(Property item) { 182 Property value = ObjectUtils.requireNonNull(item,"item cannot be null"); 183 return _props != null && _props.remove(value); 184 } 185 186 public List<Link> getLinks() { 187 return _links; 188 } 189 190 public void setLinks(List<Link> value) { 191 _links = value; 192 } 193 194 /** 195 * Add a new {@link Link} item to the underlying collection. 196 * @param item the item to add 197 * @return {@code true} 198 */ 199 public boolean addLink(Link item) { 200 Link value = ObjectUtils.requireNonNull(item,"item cannot be null"); 201 if (_links == null) { 202 _links = new LinkedList<>(); 203 } 204 return _links.add(value); 205 } 206 207 /** 208 * Remove the first matching {@link Link} item from the underlying collection. 209 * @param item the item to remove 210 * @return {@code true} if the item was removed or {@code false} otherwise 211 */ 212 public boolean removeLink(Link item) { 213 Link value = ObjectUtils.requireNonNull(item,"item cannot be null"); 214 return _links != null && _links.remove(value); 215 } 216 217 public List<SetParameter> getSetParameters() { 218 return _setParameters; 219 } 220 221 public void setSetParameters(List<SetParameter> value) { 222 _setParameters = value; 223 } 224 225 /** 226 * Add a new {@link SetParameter} item to the underlying collection. 227 * @param item the item to add 228 * @return {@code true} 229 */ 230 public boolean addSetParameter(SetParameter item) { 231 SetParameter value = ObjectUtils.requireNonNull(item,"item cannot be null"); 232 if (_setParameters == null) { 233 _setParameters = new LinkedList<>(); 234 } 235 return _setParameters.add(value); 236 } 237 238 /** 239 * Remove the first matching {@link SetParameter} item from the underlying collection. 240 * @param item the item to remove 241 * @return {@code true} if the item was removed or {@code false} otherwise 242 */ 243 public boolean removeSetParameter(SetParameter item) { 244 SetParameter value = ObjectUtils.requireNonNull(item,"item cannot be null"); 245 return _setParameters != null && _setParameters.remove(value); 246 } 247 248 public List<ComponentImplementedRequirement> getImplementedRequirements() { 249 return _implementedRequirements; 250 } 251 252 public void setImplementedRequirements(List<ComponentImplementedRequirement> value) { 253 _implementedRequirements = value; 254 } 255 256 /** 257 * Add a new {@link ComponentImplementedRequirement} item to the underlying collection. 258 * @param item the item to add 259 * @return {@code true} 260 */ 261 public boolean addImplementedRequirement(ComponentImplementedRequirement item) { 262 ComponentImplementedRequirement value = ObjectUtils.requireNonNull(item,"item cannot be null"); 263 if (_implementedRequirements == null) { 264 _implementedRequirements = new LinkedList<>(); 265 } 266 return _implementedRequirements.add(value); 267 } 268 269 /** 270 * Remove the first matching {@link ComponentImplementedRequirement} item from the underlying collection. 271 * @param item the item to remove 272 * @return {@code true} if the item was removed or {@code false} otherwise 273 */ 274 public boolean removeImplementedRequirement(ComponentImplementedRequirement item) { 275 ComponentImplementedRequirement value = ObjectUtils.requireNonNull(item,"item cannot be null"); 276 return _implementedRequirements != null && _implementedRequirements.remove(value); 277 } 278 279 @Override 280 public String toString() { 281 return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString(); 282 } 283}