001package gov.nist.secauto.oscal.lib.model;
002
003import gov.nist.secauto.metaschema.core.datatype.adapter.DateTimeWithTZAdapter;
004import gov.nist.secauto.metaschema.core.datatype.adapter.TokenAdapter;
005import gov.nist.secauto.metaschema.core.datatype.adapter.UriAdapter;
006import gov.nist.secauto.metaschema.core.datatype.adapter.UuidAdapter;
007import gov.nist.secauto.metaschema.core.datatype.markup.MarkupMultiline;
008import gov.nist.secauto.metaschema.core.datatype.markup.MarkupMultilineAdapter;
009import gov.nist.secauto.metaschema.core.model.IBoundObject;
010import gov.nist.secauto.metaschema.core.model.IMetaschemaData;
011import gov.nist.secauto.metaschema.core.model.JsonGroupAsBehavior;
012import gov.nist.secauto.metaschema.core.model.constraint.IConstraint;
013import gov.nist.secauto.metaschema.core.util.ObjectUtils;
014import gov.nist.secauto.metaschema.databind.model.annotations.AllowedValue;
015import gov.nist.secauto.metaschema.databind.model.annotations.AllowedValues;
016import gov.nist.secauto.metaschema.databind.model.annotations.BoundAssembly;
017import gov.nist.secauto.metaschema.databind.model.annotations.BoundField;
018import gov.nist.secauto.metaschema.databind.model.annotations.BoundFlag;
019import gov.nist.secauto.metaschema.databind.model.annotations.GroupAs;
020import gov.nist.secauto.metaschema.databind.model.annotations.IndexHasKey;
021import gov.nist.secauto.metaschema.databind.model.annotations.KeyField;
022import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaAssembly;
023import gov.nist.secauto.metaschema.databind.model.annotations.ValueConstraints;
024import java.lang.Override;
025import java.lang.String;
026import java.net.URI;
027import java.time.ZonedDateTime;
028import java.util.LinkedList;
029import java.util.List;
030import java.util.UUID;
031import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
032import org.apache.commons.lang3.builder.ToStringStyle;
033
034/**
035 * An action applied by a role within a given party to the content.
036 */
037@MetaschemaAssembly(
038    formalName = "Action",
039    description = "An action applied by a role within a given party to the content.",
040    name = "action",
041    moduleClass = OscalMetadataModule.class,
042    valueConstraints = @ValueConstraints(allowedValues = {@AllowedValues(level = IConstraint.Level.ERROR, target = "./system/@value", allowOthers = true, values = @AllowedValue(value = "http://csrc.nist.gov/ns/oscal", description = "This value identifies action types defined in the NIST OSCAL namespace.")), @AllowedValues(level = IConstraint.Level.ERROR, target = "./type[has-oscal-namespace('http://csrc.nist.gov/ns/oscal')]/@value", values = {@AllowedValue(value = "approval", description = "An approval of a document instance's content."), @AllowedValue(value = "request-changes", description = "A request from the responisble party or parties to change the content.")})}, indexHasKey = {@IndexHasKey(level = IConstraint.Level.ERROR, target = "responsible-party", indexName = "index-metadata-role-id", keyFields = @KeyField(target = "@role-id")), @IndexHasKey(level = IConstraint.Level.ERROR, target = "responsible-party", indexName = "index-metadata-party-uuid", keyFields = @KeyField(target = "party-uuid"))})
043)
044public class Action implements IBoundObject {
045  private final IMetaschemaData __metaschemaData;
046
047  /**
048   * "A unique identifier that can be used to reference this defined action elsewhere in an OSCAL document. A UUID should be consistently used for a given location across revisions of the document."
049   */
050  @BoundFlag(
051      formalName = "Action Universally Unique Identifier",
052      description = "A unique identifier that can be used to reference this defined action elsewhere in an OSCAL document. A UUID should be consistently used for a given location across revisions of the document.",
053      name = "uuid",
054      required = true,
055      typeAdapter = UuidAdapter.class
056  )
057  private UUID _uuid;
058
059  /**
060   * "The date and time when the action occurred."
061   */
062  @BoundFlag(
063      formalName = "Action Occurrence Date",
064      description = "The date and time when the action occurred.",
065      name = "date",
066      typeAdapter = DateTimeWithTZAdapter.class
067  )
068  private ZonedDateTime _date;
069
070  /**
071   * "The type of action documented by the assembly, such as an approval."
072   */
073  @BoundFlag(
074      formalName = "Action Type",
075      description = "The type of action documented by the assembly, such as an approval.",
076      name = "type",
077      required = true,
078      typeAdapter = TokenAdapter.class
079  )
080  private String _type;
081
082  /**
083   * "Specifies the action type system used."
084   */
085  @BoundFlag(
086      formalName = "Action Type System",
087      description = "Specifies the action type system used.",
088      name = "system",
089      required = true,
090      typeAdapter = UriAdapter.class,
091      remarks = "Provides a means to segment the value space for the `type`, so that different organizations and individuals can assert control over the allowed `action`'s `type`. This allows the semantics associated with a given `type` to be defined on an organization-by-organization basis.\n"
092              + "\n"
093              + "An organization MUST use a URI that they have control over. e.g., a domain registered to the organization in a URI, a registered uniform resource names (URN) namespace."
094  )
095  private URI _system;
096
097  @BoundAssembly(
098      formalName = "Property",
099      description = "An attribute, characteristic, or quality of the containing object expressed as a namespace qualified name/value pair.",
100      useName = "prop",
101      maxOccurs = -1,
102      groupAs = @GroupAs(name = "props", inJson = JsonGroupAsBehavior.LIST)
103  )
104  private List<Property> _props;
105
106  @BoundAssembly(
107      formalName = "Link",
108      description = "A reference to a local or remote resource, that has a specific relation to the containing object.",
109      useName = "link",
110      maxOccurs = -1,
111      groupAs = @GroupAs(name = "links", inJson = JsonGroupAsBehavior.LIST)
112  )
113  private List<Link> _links;
114
115  @BoundAssembly(
116      formalName = "Responsible Party",
117      description = "A reference to a set of persons and/or organizations that have responsibility for performing the referenced role in the context of the containing object.",
118      useName = "responsible-party",
119      maxOccurs = -1,
120      groupAs = @GroupAs(name = "responsible-parties", inJson = JsonGroupAsBehavior.LIST)
121  )
122  private List<ResponsibleParty> _responsibleParties;
123
124  @BoundField(
125      formalName = "Remarks",
126      description = "Additional commentary about the containing object.",
127      useName = "remarks",
128      typeAdapter = MarkupMultilineAdapter.class
129  )
130  private MarkupMultiline _remarks;
131
132  public Action() {
133    this(null);
134  }
135
136  public Action(IMetaschemaData data) {
137    this.__metaschemaData = data;
138  }
139
140  @Override
141  public IMetaschemaData getMetaschemaData() {
142    return __metaschemaData;
143  }
144
145  public UUID getUuid() {
146    return _uuid;
147  }
148
149  public void setUuid(UUID value) {
150    _uuid = value;
151  }
152
153  public ZonedDateTime getDate() {
154    return _date;
155  }
156
157  public void setDate(ZonedDateTime value) {
158    _date = value;
159  }
160
161  public String getType() {
162    return _type;
163  }
164
165  public void setType(String value) {
166    _type = value;
167  }
168
169  public URI getSystem() {
170    return _system;
171  }
172
173  public void setSystem(URI value) {
174    _system = value;
175  }
176
177  public List<Property> getProps() {
178    return _props;
179  }
180
181  public void setProps(List<Property> value) {
182    _props = value;
183  }
184
185  /**
186   * Add a new {@link Property} item to the underlying collection.
187   * @param item the item to add
188   * @return {@code true}
189   */
190  public boolean addProp(Property item) {
191    Property value = ObjectUtils.requireNonNull(item,"item cannot be null");
192    if (_props == null) {
193      _props = new LinkedList<>();
194    }
195    return _props.add(value);
196  }
197
198  /**
199   * Remove the first matching {@link Property} item from the underlying collection.
200   * @param item the item to remove
201   * @return {@code true} if the item was removed or {@code false} otherwise
202   */
203  public boolean removeProp(Property item) {
204    Property value = ObjectUtils.requireNonNull(item,"item cannot be null");
205    return _props != null && _props.remove(value);
206  }
207
208  public List<Link> getLinks() {
209    return _links;
210  }
211
212  public void setLinks(List<Link> value) {
213    _links = value;
214  }
215
216  /**
217   * Add a new {@link Link} item to the underlying collection.
218   * @param item the item to add
219   * @return {@code true}
220   */
221  public boolean addLink(Link item) {
222    Link value = ObjectUtils.requireNonNull(item,"item cannot be null");
223    if (_links == null) {
224      _links = new LinkedList<>();
225    }
226    return _links.add(value);
227  }
228
229  /**
230   * Remove the first matching {@link Link} item from the underlying collection.
231   * @param item the item to remove
232   * @return {@code true} if the item was removed or {@code false} otherwise
233   */
234  public boolean removeLink(Link item) {
235    Link value = ObjectUtils.requireNonNull(item,"item cannot be null");
236    return _links != null && _links.remove(value);
237  }
238
239  public List<ResponsibleParty> getResponsibleParties() {
240    return _responsibleParties;
241  }
242
243  public void setResponsibleParties(List<ResponsibleParty> value) {
244    _responsibleParties = value;
245  }
246
247  /**
248   * Add a new {@link ResponsibleParty} item to the underlying collection.
249   * @param item the item to add
250   * @return {@code true}
251   */
252  public boolean addResponsibleParty(ResponsibleParty item) {
253    ResponsibleParty value = ObjectUtils.requireNonNull(item,"item cannot be null");
254    if (_responsibleParties == null) {
255      _responsibleParties = new LinkedList<>();
256    }
257    return _responsibleParties.add(value);
258  }
259
260  /**
261   * Remove the first matching {@link ResponsibleParty} item from the underlying collection.
262   * @param item the item to remove
263   * @return {@code true} if the item was removed or {@code false} otherwise
264   */
265  public boolean removeResponsibleParty(ResponsibleParty item) {
266    ResponsibleParty value = ObjectUtils.requireNonNull(item,"item cannot be null");
267    return _responsibleParties != null && _responsibleParties.remove(value);
268  }
269
270  public MarkupMultiline getRemarks() {
271    return _remarks;
272  }
273
274  public void setRemarks(MarkupMultiline value) {
275    _remarks = value;
276  }
277
278  @Override
279  public String toString() {
280    return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString();
281  }
282}