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.MarkupMultiline; 005import gov.nist.secauto.metaschema.core.datatype.markup.MarkupMultilineAdapter; 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.AssemblyConstraints; 014import gov.nist.secauto.metaschema.databind.model.annotations.BoundAssembly; 015import gov.nist.secauto.metaschema.databind.model.annotations.BoundField; 016import gov.nist.secauto.metaschema.databind.model.annotations.BoundFlag; 017import gov.nist.secauto.metaschema.databind.model.annotations.GroupAs; 018import gov.nist.secauto.metaschema.databind.model.annotations.HasCardinality; 019import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaAssembly; 020import gov.nist.secauto.metaschema.databind.model.annotations.ValueConstraints; 021import java.lang.Override; 022import java.lang.String; 023import java.util.LinkedList; 024import java.util.List; 025import org.apache.commons.lang3.builder.ReflectionToStringBuilder; 026import org.apache.commons.lang3.builder.ToStringStyle; 027 028/** 029 * A local definition of a control objective for this assessment. Uses catalog syntax for control objective and assessment actions. 030 */ 031@MetaschemaAssembly( 032 formalName = "Assessment-Specific Control Objective", 033 description = "A local definition of a control objective for this assessment. Uses catalog syntax for control objective and assessment actions.", 034 name = "local-objective", 035 moduleClass = OscalAssessmentCommonModule.class, 036 valueConstraints = @ValueConstraints(allowedValues = @AllowedValues(level = IConstraint.Level.ERROR, target = "part[has-oscal-namespace('http://csrc.nist.gov/ns/oscal')]/@name", values = {@AllowedValue(value = "objective", description = "\\*\\*(deprecated)\\*\\* Use 'assessment-objective' instead.", deprecatedVersion = "1.0.1"), @AllowedValue(value = "assessment", description = "\\*\\*(deprecated)\\*\\* Use 'assessment-method' instead.", deprecatedVersion = "1.0.1"), @AllowedValue(value = "assessment-objective", description = "The part defines an assessment objective."), @AllowedValue(value = "assessment-method", description = "The part defines an assessment method.")})), 037 modelConstraints = @AssemblyConstraints(cardinality = {@HasCardinality(level = IConstraint.Level.ERROR, target = "part[has-oscal-namespace('http://csrc.nist.gov/ns/oscal') and @name=('objective','assessment-objective')]", maxOccurs = 1), @HasCardinality(level = IConstraint.Level.ERROR, target = "part[has-oscal-namespace('http://csrc.nist.gov/ns/oscal') and @name=('assessment','assessment-method')]/prop[has-oscal-namespace(('http://csrc.nist.gov/ns/oscal','http://csrc.nist.gov/ns/rmf')) and @name='method']", minOccurs = 1, maxOccurs = 1), @HasCardinality(level = IConstraint.Level.ERROR, target = "part[has-oscal-namespace('http://csrc.nist.gov/ns/oscal') and @name=('assessment','assessment-method')]/part[has-oscal-namespace('http://csrc.nist.gov/ns/oscal') and @name=('objects','assessment-objects')]", minOccurs = 1, maxOccurs = 1), @HasCardinality(level = IConstraint.Level.ERROR, target = "part[has-oscal-namespace('http://csrc.nist.gov/ns/oscal') and @name=('objective','assessment-objective')]/prop[has-oscal-namespace('http://csrc.nist.gov/ns/oscal') and @name='method-id']", minOccurs = 1)}) 038) 039public class LocalObjective implements IBoundObject { 040 private final IMetaschemaData __metaschemaData; 041 042 /** 043 * "A reference to a control with a corresponding <code>id</code> value. When referencing an externally defined <code>control</code>, the <code>Control Identifier Reference</code> must be used in the context of the external / imported OSCAL instance (e.g., uri-reference)." 044 */ 045 @BoundFlag( 046 formalName = "Control Identifier Reference", 047 description = "A reference to a control with a corresponding `id` value. When referencing an externally defined `control`, the `Control Identifier Reference` must be used in the context of the external / imported OSCAL instance (e.g., uri-reference).", 048 name = "control-id", 049 required = true, 050 typeAdapter = TokenAdapter.class, 051 remarks = "The specified `control-id` must be a valid value within the baseline identified by the target system's SSP via the `import-profile` statement." 052 ) 053 private String _controlId; 054 055 @BoundField( 056 formalName = "Objective Description", 057 description = "A human-readable description of this control objective.", 058 useName = "description", 059 typeAdapter = MarkupMultilineAdapter.class 060 ) 061 private MarkupMultiline _description; 062 063 @BoundAssembly( 064 formalName = "Property", 065 description = "An attribute, characteristic, or quality of the containing object expressed as a namespace qualified name/value pair.", 066 useName = "prop", 067 maxOccurs = -1, 068 groupAs = @GroupAs(name = "props", inJson = JsonGroupAsBehavior.LIST) 069 ) 070 private List<Property> _props; 071 072 @BoundAssembly( 073 formalName = "Link", 074 description = "A reference to a local or remote resource, that has a specific relation to the containing object.", 075 useName = "link", 076 maxOccurs = -1, 077 groupAs = @GroupAs(name = "links", inJson = JsonGroupAsBehavior.LIST) 078 ) 079 private List<Link> _links; 080 081 @BoundAssembly( 082 formalName = "Part", 083 description = "An annotated, markup-based textual element of a control's or catalog group's definition, or a child of another part.", 084 useName = "part", 085 minOccurs = 1, 086 maxOccurs = -1, 087 groupAs = @GroupAs(name = "parts", inJson = JsonGroupAsBehavior.LIST) 088 ) 089 private List<ControlPart> _parts; 090 091 @BoundField( 092 formalName = "Remarks", 093 description = "Additional commentary about the containing object.", 094 useName = "remarks", 095 typeAdapter = MarkupMultilineAdapter.class 096 ) 097 private MarkupMultiline _remarks; 098 099 public LocalObjective() { 100 this(null); 101 } 102 103 public LocalObjective(IMetaschemaData data) { 104 this.__metaschemaData = data; 105 } 106 107 @Override 108 public IMetaschemaData getMetaschemaData() { 109 return __metaschemaData; 110 } 111 112 public String getControlId() { 113 return _controlId; 114 } 115 116 public void setControlId(String value) { 117 _controlId = value; 118 } 119 120 public MarkupMultiline getDescription() { 121 return _description; 122 } 123 124 public void setDescription(MarkupMultiline value) { 125 _description = value; 126 } 127 128 public List<Property> getProps() { 129 return _props; 130 } 131 132 public void setProps(List<Property> value) { 133 _props = value; 134 } 135 136 /** 137 * Add a new {@link Property} item to the underlying collection. 138 * @param item the item to add 139 * @return {@code true} 140 */ 141 public boolean addProp(Property item) { 142 Property value = ObjectUtils.requireNonNull(item,"item cannot be null"); 143 if (_props == null) { 144 _props = new LinkedList<>(); 145 } 146 return _props.add(value); 147 } 148 149 /** 150 * Remove the first matching {@link Property} 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 removeProp(Property item) { 155 Property value = ObjectUtils.requireNonNull(item,"item cannot be null"); 156 return _props != null && _props.remove(value); 157 } 158 159 public List<Link> getLinks() { 160 return _links; 161 } 162 163 public void setLinks(List<Link> value) { 164 _links = value; 165 } 166 167 /** 168 * Add a new {@link Link} item to the underlying collection. 169 * @param item the item to add 170 * @return {@code true} 171 */ 172 public boolean addLink(Link item) { 173 Link value = ObjectUtils.requireNonNull(item,"item cannot be null"); 174 if (_links == null) { 175 _links = new LinkedList<>(); 176 } 177 return _links.add(value); 178 } 179 180 /** 181 * Remove the first matching {@link Link} 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 removeLink(Link item) { 186 Link value = ObjectUtils.requireNonNull(item,"item cannot be null"); 187 return _links != null && _links.remove(value); 188 } 189 190 public List<ControlPart> getParts() { 191 return _parts; 192 } 193 194 public void setParts(List<ControlPart> value) { 195 _parts = value; 196 } 197 198 /** 199 * Add a new {@link ControlPart} item to the underlying collection. 200 * @param item the item to add 201 * @return {@code true} 202 */ 203 public boolean addPart(ControlPart item) { 204 ControlPart value = ObjectUtils.requireNonNull(item,"item cannot be null"); 205 if (_parts == null) { 206 _parts = new LinkedList<>(); 207 } 208 return _parts.add(value); 209 } 210 211 /** 212 * Remove the first matching {@link ControlPart} 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 removePart(ControlPart item) { 217 ControlPart value = ObjectUtils.requireNonNull(item,"item cannot be null"); 218 return _parts != null && _parts.remove(value); 219 } 220 221 public MarkupMultiline getRemarks() { 222 return _remarks; 223 } 224 225 public void setRemarks(MarkupMultiline value) { 226 _remarks = value; 227 } 228 229 @Override 230 public String toString() { 231 return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString(); 232 } 233}