001package gov.nist.secauto.oscal.lib.model; 002 003import gov.nist.secauto.metaschema.core.datatype.adapter.TokenAdapter; 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.util.ObjectUtils; 008import gov.nist.secauto.metaschema.databind.model.annotations.BoundField; 009import gov.nist.secauto.metaschema.databind.model.annotations.BoundFlag; 010import gov.nist.secauto.metaschema.databind.model.annotations.GroupAs; 011import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaAssembly; 012import java.lang.Override; 013import java.lang.String; 014import java.util.LinkedList; 015import java.util.List; 016import org.apache.commons.lang3.builder.ReflectionToStringBuilder; 017import org.apache.commons.lang3.builder.ToStringStyle; 018 019/** 020 * Used to select a control for inclusion/exclusion based on one or more control identifiers. A set of statement identifiers can be used to target the inclusion/exclusion to only specific control statements providing more granularity over the specific statements that are within the asessment scope. 021 */ 022@MetaschemaAssembly( 023 formalName = "Select Control", 024 description = "Used to select a control for inclusion/exclusion based on one or more control identifiers. A set of statement identifiers can be used to target the inclusion/exclusion to only specific control statements providing more granularity over the specific statements that are within the asessment scope.", 025 name = "select-control-by-id", 026 moduleClass = OscalAssessmentCommonModule.class 027) 028public class SelectControlById implements IBoundObject { 029 private final IMetaschemaData __metaschemaData; 030 031 /** 032 * "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)." 033 */ 034 @BoundFlag( 035 formalName = "Control Identifier Reference", 036 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).", 037 name = "control-id", 038 required = true, 039 typeAdapter = TokenAdapter.class 040 ) 041 private String _controlId; 042 043 @BoundField( 044 formalName = "Include Specific Statements", 045 description = "Used to constrain the selection to only specificity identified statements.", 046 useName = "statement-id", 047 maxOccurs = -1, 048 groupAs = @GroupAs(name = "statement-ids", inJson = JsonGroupAsBehavior.LIST), 049 typeAdapter = TokenAdapter.class 050 ) 051 private List<String> _statementIds; 052 053 public SelectControlById() { 054 this(null); 055 } 056 057 public SelectControlById(IMetaschemaData data) { 058 this.__metaschemaData = data; 059 } 060 061 @Override 062 public IMetaschemaData getMetaschemaData() { 063 return __metaschemaData; 064 } 065 066 public String getControlId() { 067 return _controlId; 068 } 069 070 public void setControlId(String value) { 071 _controlId = value; 072 } 073 074 public List<String> getStatementIds() { 075 return _statementIds; 076 } 077 078 public void setStatementIds(List<String> value) { 079 _statementIds = value; 080 } 081 082 /** 083 * Add a new {@link String} item to the underlying collection. 084 * @param item the item to add 085 * @return {@code true} 086 */ 087 public boolean addStatementId(String item) { 088 String value = ObjectUtils.requireNonNull(item,"item cannot be null"); 089 if (_statementIds == null) { 090 _statementIds = new LinkedList<>(); 091 } 092 return _statementIds.add(value); 093 } 094 095 /** 096 * Remove the first matching {@link String} item from the underlying collection. 097 * @param item the item to remove 098 * @return {@code true} if the item was removed or {@code false} otherwise 099 */ 100 public boolean removeStatementId(String item) { 101 String value = ObjectUtils.requireNonNull(item,"item cannot be null"); 102 return _statementIds != null && _statementIds.remove(value); 103 } 104 105 @Override 106 public String toString() { 107 return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString(); 108 } 109}