001package gov.nist.secauto.oscal.lib.model;
002
003import gov.nist.secauto.metaschema.core.datatype.adapter.BooleanAdapter;
004import gov.nist.secauto.metaschema.core.datatype.adapter.StringAdapter;
005import gov.nist.secauto.metaschema.core.model.IBoundObject;
006import gov.nist.secauto.metaschema.core.model.IMetaschemaData;
007import gov.nist.secauto.metaschema.core.model.JsonGroupAsBehavior;
008import gov.nist.secauto.metaschema.core.model.constraint.IConstraint;
009import gov.nist.secauto.metaschema.core.util.ObjectUtils;
010import gov.nist.secauto.metaschema.databind.model.annotations.AllowedValue;
011import gov.nist.secauto.metaschema.databind.model.annotations.AllowedValues;
012import gov.nist.secauto.metaschema.databind.model.annotations.BoundAssembly;
013import gov.nist.secauto.metaschema.databind.model.annotations.BoundField;
014import gov.nist.secauto.metaschema.databind.model.annotations.BoundFlag;
015import gov.nist.secauto.metaschema.databind.model.annotations.Expect;
016import gov.nist.secauto.metaschema.databind.model.annotations.GroupAs;
017import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaAssembly;
018import gov.nist.secauto.metaschema.databind.model.annotations.ValueConstraints;
019import java.lang.Boolean;
020import java.lang.Override;
021import java.lang.String;
022import java.util.LinkedList;
023import java.util.List;
024import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
025import org.apache.commons.lang3.builder.ToStringStyle;
026
027/**
028 * Provides structuring directives that instruct how controls are organized after profile resolution.
029 */
030@MetaschemaAssembly(
031    formalName = "Merge Controls",
032    description = "Provides structuring directives that instruct how controls are organized after profile resolution.",
033    name = "merge",
034    moduleClass = OscalProfileModule.class
035)
036public class Merge implements IBoundObject {
037  private final IMetaschemaData __metaschemaData;
038
039  @BoundAssembly(
040      formalName = "Combination Rule",
041      description = "A Combine element defines how to resolve duplicate instances of the same control (e.g., controls with the same ID).",
042      useName = "combine"
043  )
044  private Combine _combine;
045
046  @BoundAssembly(
047      formalName = "Flat Without Grouping",
048      description = "Directs that controls appear without any grouping structure.",
049      useName = "flat",
050      minOccurs = 1
051  )
052  private Flat _flat;
053
054  @BoundField(
055      formalName = "Group As-Is",
056      description = "Indicates that the controls selected should retain their original grouping as defined in the import source.",
057      useName = "as-is",
058      minOccurs = 1,
059      typeAdapter = BooleanAdapter.class
060  )
061  private Boolean _asIs;
062
063  @BoundAssembly(
064      formalName = "Custom Grouping",
065      description = "Provides an alternate grouping structure that selected controls will be placed in.",
066      useName = "custom",
067      remarks = "The `custom` element represents a custom arrangement or organization of controls in the resolution of a catalog. This structuring directive gives the profile author the ability to define an entirely different organization of controls as compared to their source catalog(s).",
068      minOccurs = 1
069  )
070  private Custom _custom;
071
072  public Merge() {
073    this(null);
074  }
075
076  public Merge(IMetaschemaData data) {
077    this.__metaschemaData = data;
078  }
079
080  @Override
081  public IMetaschemaData getMetaschemaData() {
082    return __metaschemaData;
083  }
084
085  public Combine getCombine() {
086    return _combine;
087  }
088
089  public void setCombine(Combine value) {
090    _combine = value;
091  }
092
093  public Flat getFlat() {
094    return _flat;
095  }
096
097  public void setFlat(Flat value) {
098    _flat = value;
099  }
100
101  public Boolean getAsIs() {
102    return _asIs;
103  }
104
105  public void setAsIs(Boolean value) {
106    _asIs = value;
107  }
108
109  public Custom getCustom() {
110    return _custom;
111  }
112
113  public void setCustom(Custom value) {
114    _custom = value;
115  }
116
117  @Override
118  public String toString() {
119    return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString();
120  }
121
122  /**
123   * A Combine element defines how to resolve duplicate instances of the same control (e.g., controls with the same ID).
124   */
125  @MetaschemaAssembly(
126      formalName = "Combination Rule",
127      description = "A Combine element defines how to resolve duplicate instances of the same control (e.g., controls with the same ID).",
128      name = "combine",
129      moduleClass = OscalProfileModule.class,
130      valueConstraints = @ValueConstraints(expect = @Expect(id = "req-merge-combine", level = IConstraint.Level.ERROR, test = "not(@method='merge')"))
131  )
132  public static class Combine implements IBoundObject {
133    private final IMetaschemaData __metaschemaData;
134
135    /**
136     * "Declare how clashing controls should be handled."
137     */
138    @BoundFlag(
139        formalName = "Combination Method",
140        description = "Declare how clashing controls should be handled.",
141        name = "method",
142        typeAdapter = StringAdapter.class,
143        valueConstraints = @ValueConstraints(allowedValues = @AllowedValues(level = IConstraint.Level.ERROR, values = {@AllowedValue(value = "use-first", description = "Use the first definition - the first control with a given ID is used; subsequent ones are discarded"), @AllowedValue(value = "merge", description = "\\*\\*(*deprecated* )\\*\\* \\*\\*(*unspecified*)\\*\\* Merge - controls with the same ID are combined"), @AllowedValue(value = "keep", description = "Keep - controls with the same ID are kept, retaining the clash")}))
144    )
145    private String _method;
146
147    public Combine() {
148      this(null);
149    }
150
151    public Combine(IMetaschemaData data) {
152      this.__metaschemaData = data;
153    }
154
155    @Override
156    public IMetaschemaData getMetaschemaData() {
157      return __metaschemaData;
158    }
159
160    public String getMethod() {
161      return _method;
162    }
163
164    public void setMethod(String value) {
165      _method = value;
166    }
167
168    @Override
169    public String toString() {
170      return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString();
171    }
172  }
173
174  /**
175   * Directs that controls appear without any grouping structure.
176   */
177  @MetaschemaAssembly(
178      formalName = "Flat Without Grouping",
179      description = "Directs that controls appear without any grouping structure.",
180      name = "flat",
181      moduleClass = OscalProfileModule.class
182  )
183  public static class Flat implements IBoundObject {
184    private final IMetaschemaData __metaschemaData;
185
186    public Flat() {
187      this(null);
188    }
189
190    public Flat(IMetaschemaData data) {
191      this.__metaschemaData = data;
192    }
193
194    @Override
195    public IMetaschemaData getMetaschemaData() {
196      return __metaschemaData;
197    }
198
199    @Override
200    public String toString() {
201      return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString();
202    }
203  }
204
205  /**
206   * Provides an alternate grouping structure that selected controls will be placed in.
207   */
208  @MetaschemaAssembly(
209      formalName = "Custom Grouping",
210      description = "Provides an alternate grouping structure that selected controls will be placed in.",
211      name = "custom",
212      moduleClass = OscalProfileModule.class,
213      remarks = "The `custom` element represents a custom arrangement or organization of controls in the resolution of a catalog. This structuring directive gives the profile author the ability to define an entirely different organization of controls as compared to their source catalog(s)."
214  )
215  public static class Custom implements IBoundObject {
216    private final IMetaschemaData __metaschemaData;
217
218    @BoundAssembly(
219        formalName = "Control Group",
220        description = "A group of (selected) controls or of groups of controls.",
221        useName = "group",
222        maxOccurs = -1,
223        groupAs = @GroupAs(name = "groups", inJson = JsonGroupAsBehavior.LIST)
224    )
225    private List<ProfileGroup> _groups;
226
227    @BoundAssembly(
228        formalName = "Insert Controls",
229        description = "Specifies which controls to use in the containing context.",
230        useName = "insert-controls",
231        maxOccurs = -1,
232        groupAs = @GroupAs(name = "insert-controls", inJson = JsonGroupAsBehavior.LIST)
233    )
234    private List<InsertControls> _insertControls;
235
236    public Custom() {
237      this(null);
238    }
239
240    public Custom(IMetaschemaData data) {
241      this.__metaschemaData = data;
242    }
243
244    @Override
245    public IMetaschemaData getMetaschemaData() {
246      return __metaschemaData;
247    }
248
249    public List<ProfileGroup> getGroups() {
250      return _groups;
251    }
252
253    public void setGroups(List<ProfileGroup> value) {
254      _groups = value;
255    }
256
257    /**
258     * Add a new {@link ProfileGroup} item to the underlying collection.
259     * @param item the item to add
260     * @return {@code true}
261     */
262    public boolean addGroup(ProfileGroup item) {
263      ProfileGroup value = ObjectUtils.requireNonNull(item,"item cannot be null");
264      if (_groups == null) {
265        _groups = new LinkedList<>();
266      }
267      return _groups.add(value);
268    }
269
270    /**
271     * Remove the first matching {@link ProfileGroup} item from the underlying collection.
272     * @param item the item to remove
273     * @return {@code true} if the item was removed or {@code false} otherwise
274     */
275    public boolean removeGroup(ProfileGroup item) {
276      ProfileGroup value = ObjectUtils.requireNonNull(item,"item cannot be null");
277      return _groups != null && _groups.remove(value);
278    }
279
280    public List<InsertControls> getInsertControls() {
281      return _insertControls;
282    }
283
284    public void setInsertControls(List<InsertControls> value) {
285      _insertControls = value;
286    }
287
288    /**
289     * Add a new {@link InsertControls} item to the underlying collection.
290     * @param item the item to add
291     * @return {@code true}
292     */
293    public boolean addInsertControls(InsertControls item) {
294      InsertControls value = ObjectUtils.requireNonNull(item,"item cannot be null");
295      if (_insertControls == null) {
296        _insertControls = new LinkedList<>();
297      }
298      return _insertControls.add(value);
299    }
300
301    /**
302     * Remove the first matching {@link InsertControls} item from the underlying collection.
303     * @param item the item to remove
304     * @return {@code true} if the item was removed or {@code false} otherwise
305     */
306    public boolean removeInsertControls(InsertControls item) {
307      InsertControls value = ObjectUtils.requireNonNull(item,"item cannot be null");
308      return _insertControls != null && _insertControls.remove(value);
309    }
310
311    @Override
312    public String toString() {
313      return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString();
314    }
315  }
316}