001package gov.nist.secauto.oscal.lib.model; 002 003import gov.nist.secauto.metaschema.binding.model.annotations.AssemblyConstraints; 004import gov.nist.secauto.metaschema.binding.model.annotations.BoundAssembly; 005import gov.nist.secauto.metaschema.binding.model.annotations.BoundField; 006import gov.nist.secauto.metaschema.binding.model.annotations.BoundFieldValue; 007import gov.nist.secauto.metaschema.binding.model.annotations.GroupAs; 008import gov.nist.secauto.metaschema.binding.model.annotations.Index; 009import gov.nist.secauto.metaschema.binding.model.annotations.IsUnique; 010import gov.nist.secauto.metaschema.binding.model.annotations.KeyField; 011import gov.nist.secauto.metaschema.binding.model.annotations.MetaschemaAssembly; 012import gov.nist.secauto.metaschema.model.common.JsonGroupAsBehavior; 013import gov.nist.secauto.metaschema.model.common.constraint.IConstraint; 014import gov.nist.secauto.metaschema.model.common.datatype.markup.MarkupMultiline; 015import gov.nist.secauto.metaschema.model.common.datatype.markup.MarkupMultilineAdapter; 016import gov.nist.secauto.metaschema.model.common.util.ObjectUtils; 017import java.lang.Override; 018import java.lang.String; 019import java.util.LinkedList; 020import java.util.List; 021import org.apache.commons.lang3.builder.MultilineRecursiveToStringStyle; 022import org.apache.commons.lang3.builder.ReflectionToStringBuilder; 023 024/** 025 * Describes how the system satisfies a set of controls. 026 */ 027@MetaschemaAssembly( 028 formalName = "Control Implementation", 029 description = "Describes how the system satisfies a set of controls.", 030 name = "control-implementation", 031 metaschema = OscalSspMetaschema.class, 032 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." 033) 034@AssemblyConstraints( 035 index = @Index(level = IConstraint.Level.ERROR, target = "implemented-requirement//by-component/export/provided", name = "by-component-export-provided-uuid", keyFields = @KeyField(target = "@uuid")), 036 isUnique = @IsUnique(id = "unique-ssp-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.") 037) 038public class ControlImplementation { 039 /** 040 * "A statement describing important things to know about how this set of control satisfaction documentation is approached." 041 */ 042 @BoundField( 043 formalName = "Control Implementation Description", 044 description = "A statement describing important things to know about how this set of control satisfaction documentation is approached.", 045 useName = "description", 046 minOccurs = 1 047 ) 048 @BoundFieldValue( 049 typeAdapter = MarkupMultilineAdapter.class 050 ) 051 private MarkupMultiline _description; 052 053 @BoundAssembly( 054 formalName = "Set Parameter Value", 055 description = "Identifies the parameter that will be set by the enclosed value.", 056 useName = "set-parameter", 057 maxOccurs = -1 058 ) 059 @GroupAs( 060 name = "set-parameters", 061 inJson = JsonGroupAsBehavior.LIST 062 ) 063 private List<SetParameter> _setParameters; 064 065 @BoundAssembly( 066 formalName = "Control-based Requirement", 067 description = "Describes how the system satisfies the requirements of an individual control.", 068 useName = "implemented-requirement", 069 minOccurs = 1, 070 maxOccurs = -1 071 ) 072 @GroupAs( 073 name = "implemented-requirements", 074 inJson = JsonGroupAsBehavior.LIST 075 ) 076 private List<ImplementedRequirement> _implementedRequirements; 077 078 public ControlImplementation() { 079 } 080 081 public MarkupMultiline getDescription() { 082 return _description; 083 } 084 085 public void setDescription(MarkupMultiline value) { 086 _description = value; 087 } 088 089 public List<SetParameter> getSetParameters() { 090 return _setParameters; 091 } 092 093 public void setSetParameters(List<SetParameter> value) { 094 _setParameters = value; 095 } 096 097 /** 098 * Add a new {@link SetParameter} item to the underlying collection. 099 * @param item the item to add 100 * @return {@code true} 101 */ 102 public boolean addSetParameter(SetParameter item) { 103 SetParameter value = ObjectUtils.requireNonNull(item,"item cannot be null"); 104 if (_setParameters == null) { 105 _setParameters = new LinkedList<>(); 106 } 107 return _setParameters.add(value); 108 } 109 110 /** 111 * Remove the first matching {@link SetParameter} item from the underlying collection. 112 * @param item the item to remove 113 * @return {@code true} if the item was removed or {@code false} otherwise 114 */ 115 public boolean removeSetParameter(SetParameter item) { 116 SetParameter value = ObjectUtils.requireNonNull(item,"item cannot be null"); 117 return _setParameters == null ? false : _setParameters.remove(value); 118 } 119 120 public List<ImplementedRequirement> getImplementedRequirements() { 121 return _implementedRequirements; 122 } 123 124 public void setImplementedRequirements(List<ImplementedRequirement> value) { 125 _implementedRequirements = value; 126 } 127 128 /** 129 * Add a new {@link ImplementedRequirement} item to the underlying collection. 130 * @param item the item to add 131 * @return {@code true} 132 */ 133 public boolean addImplementedRequirement(ImplementedRequirement item) { 134 ImplementedRequirement value = ObjectUtils.requireNonNull(item,"item cannot be null"); 135 if (_implementedRequirements == null) { 136 _implementedRequirements = new LinkedList<>(); 137 } 138 return _implementedRequirements.add(value); 139 } 140 141 /** 142 * Remove the first matching {@link ImplementedRequirement} item from the underlying collection. 143 * @param item the item to remove 144 * @return {@code true} if the item was removed or {@code false} otherwise 145 */ 146 public boolean removeImplementedRequirement(ImplementedRequirement item) { 147 ImplementedRequirement value = ObjectUtils.requireNonNull(item,"item cannot be null"); 148 return _implementedRequirements == null ? false : _implementedRequirements.remove(value); 149 } 150 151 @Override 152 public String toString() { 153 return new ReflectionToStringBuilder(this, MultilineRecursiveToStringStyle.MULTI_LINE_STYLE).toString(); 154 } 155}