001package gov.nist.secauto.oscal.lib.model; 002 003import gov.nist.secauto.metaschema.binding.model.annotations.BoundField; 004import gov.nist.secauto.metaschema.binding.model.annotations.BoundFieldValue; 005import gov.nist.secauto.metaschema.binding.model.annotations.BoundFlag; 006import gov.nist.secauto.metaschema.binding.model.annotations.GroupAs; 007import gov.nist.secauto.metaschema.binding.model.annotations.MetaschemaAssembly; 008import gov.nist.secauto.metaschema.model.common.JsonGroupAsBehavior; 009import gov.nist.secauto.metaschema.model.common.datatype.adapter.TokenAdapter; 010import gov.nist.secauto.metaschema.model.common.util.ObjectUtils; 011import java.lang.Override; 012import java.lang.String; 013import java.util.LinkedList; 014import java.util.List; 015import org.apache.commons.lang3.builder.MultilineRecursiveToStringStyle; 016import org.apache.commons.lang3.builder.ReflectionToStringBuilder; 017 018/** 019 * 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. 020 */ 021@MetaschemaAssembly( 022 formalName = "Select Control", 023 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.", 024 name = "select-control-by-id", 025 metaschema = OscalAssessmentCommonMetaschema.class 026) 027public class SelectControlById { 028 @BoundFlag( 029 formalName = "Control Identifier Reference", 030 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).", 031 useName = "control-id", 032 required = true, 033 typeAdapter = TokenAdapter.class 034 ) 035 private String _controlId; 036 037 /** 038 * "Used to constrain the selection to only specificity identified statements." 039 */ 040 @BoundField( 041 formalName = "Include Specific Statements", 042 description = "Used to constrain the selection to only specificity identified statements.", 043 useName = "statement-id", 044 maxOccurs = -1 045 ) 046 @BoundFieldValue( 047 typeAdapter = TokenAdapter.class 048 ) 049 @GroupAs( 050 name = "statement-ids", 051 inJson = JsonGroupAsBehavior.LIST 052 ) 053 private List<String> _statementIds; 054 055 public SelectControlById() { 056 } 057 058 public String getControlId() { 059 return _controlId; 060 } 061 062 public void setControlId(String value) { 063 _controlId = value; 064 } 065 066 public List<String> getStatementIds() { 067 return _statementIds; 068 } 069 070 public void setStatementIds(List<String> value) { 071 _statementIds = value; 072 } 073 074 /** 075 * Add a new {@link String} item to the underlying collection. 076 * @param item the item to add 077 * @return {@code true} 078 */ 079 public boolean addStatementId(String item) { 080 String value = ObjectUtils.requireNonNull(item,"item cannot be null"); 081 if (_statementIds == null) { 082 _statementIds = new LinkedList<>(); 083 } 084 return _statementIds.add(value); 085 } 086 087 /** 088 * Remove the first matching {@link String} item from the underlying collection. 089 * @param item the item to remove 090 * @return {@code true} if the item was removed or {@code false} otherwise 091 */ 092 public boolean removeStatementId(String item) { 093 String value = ObjectUtils.requireNonNull(item,"item cannot be null"); 094 return _statementIds == null ? false : _statementIds.remove(value); 095 } 096 097 @Override 098 public String toString() { 099 return new ReflectionToStringBuilder(this, MultilineRecursiveToStringStyle.MULTI_LINE_STYLE).toString(); 100 } 101}