View Javadoc
1   package gov.nist.secauto.oscal.lib.model;
2   
3   import gov.nist.secauto.metaschema.binding.model.annotations.AllowedValue;
4   import gov.nist.secauto.metaschema.binding.model.annotations.AllowedValues;
5   import gov.nist.secauto.metaschema.binding.model.annotations.BoundAssembly;
6   import gov.nist.secauto.metaschema.binding.model.annotations.BoundField;
7   import gov.nist.secauto.metaschema.binding.model.annotations.BoundFieldValue;
8   import gov.nist.secauto.metaschema.binding.model.annotations.BoundFlag;
9   import gov.nist.secauto.metaschema.binding.model.annotations.GroupAs;
10  import gov.nist.secauto.metaschema.binding.model.annotations.MetaschemaAssembly;
11  import gov.nist.secauto.metaschema.binding.model.annotations.ValueConstraints;
12  import gov.nist.secauto.metaschema.model.common.JsonGroupAsBehavior;
13  import gov.nist.secauto.metaschema.model.common.constraint.IConstraint;
14  import gov.nist.secauto.metaschema.model.common.datatype.adapter.TokenAdapter;
15  import gov.nist.secauto.metaschema.model.common.util.ObjectUtils;
16  import gov.nist.secauto.oscal.lib.model.control.profile.AbstractProfileSelectControlById;
17  import java.lang.Override;
18  import java.lang.String;
19  import java.util.LinkedList;
20  import java.util.List;
21  import org.apache.commons.lang3.builder.MultilineRecursiveToStringStyle;
22  import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
23  
24  /**
25   * Select a control or controls from an imported control set.
26   */
27  @MetaschemaAssembly(
28      formalName = "Select Control",
29      description = "Select a control or controls from an imported control set.",
30      name = "select-control-by-id",
31      metaschema = OscalProfileMetaschema.class,
32      remarks = "If `with-child-controls` is \"yes\" on the call to a control, no sibling `call`elements need to be used to call any controls appearing within it. Since generally, this is how control enhancements are represented (as controls within controls), this provides a way to include controls with all their dependent controls (enhancements) without having to call them individually."
33  )
34  public class ProfileSelectControlById extends AbstractProfileSelectControlById {
35    @BoundFlag(
36        formalName = "Include Contained Controls with Control",
37        description = "When a control is included, whether its child (dependent) controls are also included.",
38        useName = "with-child-controls",
39        typeAdapter = TokenAdapter.class
40    )
41    @ValueConstraints(
42        allowedValues = @AllowedValues(level = IConstraint.Level.ERROR, values = {@AllowedValue(value = "yes", description = "Include child controls with an included control."), @AllowedValue(value = "no", description = "When importing a control, only include child controls that are also explicitly called.")})
43    )
44    private String _withChildControls;
45  
46    @BoundField(
47        formalName = "Match Controls by Identifier",
48        description = "Selecting a control by its ID given as a literal.",
49        useName = "with-id",
50        maxOccurs = -1
51    )
52    @BoundFieldValue(
53        typeAdapter = TokenAdapter.class
54    )
55    @GroupAs(
56        name = "with-ids",
57        inJson = JsonGroupAsBehavior.LIST
58    )
59    private List<String> _withIds;
60  
61    @BoundAssembly(
62        formalName = "Match Controls by Pattern",
63        description = "Selecting a set of controls by matching their IDs with a wildcard pattern.",
64        useName = "matching",
65        maxOccurs = -1
66    )
67    @GroupAs(
68        name = "matching",
69        inJson = JsonGroupAsBehavior.LIST
70    )
71    private List<Matching> _matching;
72  
73    public ProfileSelectControlById() {
74    }
75  
76    public String getWithChildControls() {
77      return _withChildControls;
78    }
79  
80    public void setWithChildControls(String value) {
81      _withChildControls = value;
82    }
83  
84    public List<String> getWithIds() {
85      return _withIds;
86    }
87  
88    public void setWithIds(List<String> value) {
89      _withIds = value;
90    }
91  
92    /**
93     * Add a new {@link String} item to the underlying collection.
94     * @param item the item to add
95     * @return {@code true}
96     */
97    public boolean addWithId(String item) {
98      String value = ObjectUtils.requireNonNull(item,"item cannot be null");
99      if (_withIds == null) {
100       _withIds = new LinkedList<>();
101     }
102     return _withIds.add(value);
103   }
104 
105   /**
106    * Remove the first matching {@link String} item from the underlying collection.
107    * @param item the item to remove
108    * @return {@code true} if the item was removed or {@code false} otherwise
109    */
110   public boolean removeWithId(String item) {
111     String value = ObjectUtils.requireNonNull(item,"item cannot be null");
112     return _withIds == null ? false : _withIds.remove(value);
113   }
114 
115   public List<Matching> getMatching() {
116     return _matching;
117   }
118 
119   public void setMatching(List<Matching> value) {
120     _matching = value;
121   }
122 
123   /**
124    * Add a new {@link Matching} item to the underlying collection.
125    * @param item the item to add
126    * @return {@code true}
127    */
128   public boolean addMatching(Matching item) {
129     Matching value = ObjectUtils.requireNonNull(item,"item cannot be null");
130     if (_matching == null) {
131       _matching = new LinkedList<>();
132     }
133     return _matching.add(value);
134   }
135 
136   /**
137    * Remove the first matching {@link Matching} item from the underlying collection.
138    * @param item the item to remove
139    * @return {@code true} if the item was removed or {@code false} otherwise
140    */
141   public boolean removeMatching(Matching item) {
142     Matching value = ObjectUtils.requireNonNull(item,"item cannot be null");
143     return _matching == null ? false : _matching.remove(value);
144   }
145 
146   @Override
147   public String toString() {
148     return new ReflectionToStringBuilder(this, MultilineRecursiveToStringStyle.MULTI_LINE_STYLE).toString();
149   }
150 }