001package gov.nist.secauto.oscal.lib.model;
002
003import gov.nist.secauto.metaschema.core.datatype.adapter.UriReferenceAdapter;
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.model.constraint.IConstraint;
008import gov.nist.secauto.metaschema.core.util.ObjectUtils;
009import gov.nist.secauto.metaschema.databind.model.annotations.AssemblyConstraints;
010import gov.nist.secauto.metaschema.databind.model.annotations.BoundAssembly;
011import gov.nist.secauto.metaschema.databind.model.annotations.BoundFlag;
012import gov.nist.secauto.metaschema.databind.model.annotations.GroupAs;
013import gov.nist.secauto.metaschema.databind.model.annotations.Index;
014import gov.nist.secauto.metaschema.databind.model.annotations.IndexHasKey;
015import gov.nist.secauto.metaschema.databind.model.annotations.KeyField;
016import gov.nist.secauto.metaschema.databind.model.annotations.Let;
017import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaAssembly;
018import gov.nist.secauto.metaschema.databind.model.annotations.ValueConstraints;
019import java.lang.Override;
020import java.lang.String;
021import java.net.URI;
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 * Designates a referenced source catalog or profile that provides a source of control information for use in creating a new overlay or baseline.
029 */
030@MetaschemaAssembly(
031    formalName = "Import Resource",
032    description = "Designates a referenced source catalog or profile that provides a source of control information for use in creating a new overlay or baseline.",
033    name = "import",
034    moduleClass = OscalProfileModule.class,
035    remarks = "The contents of the `import` element indicate which controls from the source will be included. Controls from the source catalog or profile may be either selected, using the `include-all` or `include-controls` directives, or de-selected (using an `exclude-controls` directive).",
036    valueConstraints = @ValueConstraints(lets = @Let(name = "resolved-profile-import", target = ".[@href] ! resolve-profile(doc(resolve-uri(Q{http://csrc.nist.gov/ns/oscal/1.0}resolve-reference(@href))))/catalog"), indexHasKey = @IndexHasKey(id = "oscal-profile-import-has-key-include-exclude-control-id", level = IConstraint.Level.ERROR, target = "(include-controls|exclude-controls)/with-id", indexName = "profile-import-index-control-id", keyFields = @KeyField)),
037    modelConstraints = @AssemblyConstraints(index = @Index(id = "oscal-profile-import-index-control-id", formalName = "In-Scope Control Identifiers", description = "An index of control identifiers that are in-scope for selection in the profile import.", level = IConstraint.Level.ERROR, target = "$resolved-profile-import//control", name = "profile-import-index-control-id", keyFields = @KeyField(target = "@id")))
038)
039public class ProfileImport implements IBoundObject {
040  private final IMetaschemaData __metaschemaData;
041
042  /**
043   * "A resolvable URL reference to the base catalog or profile that this profile is tailoring."
044   */
045  @BoundFlag(
046      formalName = "Catalog or Profile Reference",
047      description = "A resolvable URL reference to the base catalog or profile that this profile is tailoring.",
048      name = "href",
049      required = true,
050      typeAdapter = UriReferenceAdapter.class,
051      remarks = "This value may be one of:\n"
052              + "\n"
053              + "1. an [absolute URI](https://pages.nist.gov/OSCAL/concepts/uri-use/#absolute-uri) that points to a network resolvable resource,\n"
054              + "2. a [relative reference](https://pages.nist.gov/OSCAL/concepts/uri-use/#relative-reference) pointing to a network resolvable resource whose base URI is the URI of the containing document, or\n"
055              + "3. a bare URI fragment (i.e., \\`#uuid\\`) pointing to a `back-matter` resource in this or an imported document (see [linking to another OSCAL object](https://pages.nist.gov/OSCAL/concepts/uri-use/#linking-to-another-oscal-object))."
056  )
057  private URI _href;
058
059  @BoundAssembly(
060      formalName = "Include All",
061      description = "Include all controls from the imported catalog or profile resources.",
062      useName = "include-all",
063      remarks = "Identifies that all controls are to be included from the imported catalog or profile.",
064      minOccurs = 1
065  )
066  private IncludeAll _includeAll;
067
068  @BoundAssembly(
069      formalName = "Select Control",
070      description = "Select a control or controls from an imported control set.",
071      useName = "include-controls",
072      remarks = "If `with-child-controls` is \"yes\" on the call to a control, any controls appearing within it (child controls) will be selected, with no additional `call` directives required. This flag provides a way to include controls with all their dependent controls (enhancements) without having to call them individually.",
073      minOccurs = 1,
074      maxOccurs = -1,
075      groupAs = @GroupAs(name = "include-controls", inJson = JsonGroupAsBehavior.LIST)
076  )
077  private List<ProfileSelectControlById> _includeControls;
078
079  @BoundAssembly(
080      formalName = "Select Control",
081      description = "Select a control or controls from an imported control set.",
082      useName = "exclude-controls",
083      remarks = "Identifies which controls to exclude, or eliminate, from the set of included controls by control identifier or match pattern.",
084      maxOccurs = -1,
085      groupAs = @GroupAs(name = "exclude-controls", inJson = JsonGroupAsBehavior.LIST)
086  )
087  private List<ProfileSelectControlById> _excludeControls;
088
089  public ProfileImport() {
090    this(null);
091  }
092
093  public ProfileImport(IMetaschemaData data) {
094    this.__metaschemaData = data;
095  }
096
097  @Override
098  public IMetaschemaData getMetaschemaData() {
099    return __metaschemaData;
100  }
101
102  public URI getHref() {
103    return _href;
104  }
105
106  public void setHref(URI value) {
107    _href = value;
108  }
109
110  public IncludeAll getIncludeAll() {
111    return _includeAll;
112  }
113
114  public void setIncludeAll(IncludeAll value) {
115    _includeAll = value;
116  }
117
118  public List<ProfileSelectControlById> getIncludeControls() {
119    return _includeControls;
120  }
121
122  public void setIncludeControls(List<ProfileSelectControlById> value) {
123    _includeControls = value;
124  }
125
126  /**
127   * Add a new {@link ProfileSelectControlById} item to the underlying collection.
128   * @param item the item to add
129   * @return {@code true}
130   */
131  public boolean addIncludeControls(ProfileSelectControlById item) {
132    ProfileSelectControlById value = ObjectUtils.requireNonNull(item,"item cannot be null");
133    if (_includeControls == null) {
134      _includeControls = new LinkedList<>();
135    }
136    return _includeControls.add(value);
137  }
138
139  /**
140   * Remove the first matching {@link ProfileSelectControlById} item from the underlying collection.
141   * @param item the item to remove
142   * @return {@code true} if the item was removed or {@code false} otherwise
143   */
144  public boolean removeIncludeControls(ProfileSelectControlById item) {
145    ProfileSelectControlById value = ObjectUtils.requireNonNull(item,"item cannot be null");
146    return _includeControls != null && _includeControls.remove(value);
147  }
148
149  public List<ProfileSelectControlById> getExcludeControls() {
150    return _excludeControls;
151  }
152
153  public void setExcludeControls(List<ProfileSelectControlById> value) {
154    _excludeControls = value;
155  }
156
157  /**
158   * Add a new {@link ProfileSelectControlById} item to the underlying collection.
159   * @param item the item to add
160   * @return {@code true}
161   */
162  public boolean addExcludeControls(ProfileSelectControlById item) {
163    ProfileSelectControlById value = ObjectUtils.requireNonNull(item,"item cannot be null");
164    if (_excludeControls == null) {
165      _excludeControls = new LinkedList<>();
166    }
167    return _excludeControls.add(value);
168  }
169
170  /**
171   * Remove the first matching {@link ProfileSelectControlById} item from the underlying collection.
172   * @param item the item to remove
173   * @return {@code true} if the item was removed or {@code false} otherwise
174   */
175  public boolean removeExcludeControls(ProfileSelectControlById item) {
176    ProfileSelectControlById value = ObjectUtils.requireNonNull(item,"item cannot be null");
177    return _excludeControls != null && _excludeControls.remove(value);
178  }
179
180  @Override
181  public String toString() {
182    return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString();
183  }
184}