001package gov.nist.secauto.oscal.lib.model; 002 003import gov.nist.secauto.metaschema.core.datatype.adapter.TokenAdapter; 004import gov.nist.secauto.metaschema.core.datatype.adapter.UuidAdapter; 005import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLine; 006import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLineAdapter; 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.MetaschemaAssembly; 021import gov.nist.secauto.metaschema.databind.model.annotations.ValueConstraints; 022import java.lang.Override; 023import java.lang.String; 024import java.util.LinkedList; 025import java.util.List; 026import java.util.UUID; 027import org.apache.commons.lang3.builder.ReflectionToStringBuilder; 028import org.apache.commons.lang3.builder.ToStringStyle; 029 030/** 031 * A <a href="https://pages.nist.gov/OSCAL/concepts/identifier-use/#human-oriented">human-oriented</a> identifier reference to a resource. Use type to indicate whether the identified resource is a component, inventory item, location, user, or something else. 032 */ 033@MetaschemaAssembly( 034 formalName = "Identifies the Subject", 035 description = "A [human-oriented](https://pages.nist.gov/OSCAL/concepts/identifier-use/#human-oriented) identifier reference to a resource. Use type to indicate whether the identified resource is a component, inventory item, location, user, or something else.", 036 name = "subject-reference", 037 moduleClass = OscalAssessmentCommonModule.class, 038 remarks = "The subject reference UUID could point to an item defined in the SSP, AP, or AR.\n" 039 + "\n" 040 + "Tools should check look for the ID in every file imported directly or indirectly." 041) 042public class SubjectReference implements IBoundObject { 043 private final IMetaschemaData __metaschemaData; 044 045 /** 046 * "A <a href=\"https://pages.nist.gov/OSCAL/concepts/identifier-use/#machine-oriented\">machine-oriented</a> identifier reference to a component, inventory-item, location, party, user, or resource using it's UUID." 047 */ 048 @BoundFlag( 049 formalName = "Subject Universally Unique Identifier Reference", 050 description = "A [machine-oriented](https://pages.nist.gov/OSCAL/concepts/identifier-use/#machine-oriented) identifier reference to a component, inventory-item, location, party, user, or resource using it's UUID.", 051 name = "subject-uuid", 052 required = true, 053 typeAdapter = UuidAdapter.class 054 ) 055 private UUID _subjectUuid; 056 057 /** 058 * "Used to indicate the type of object pointed to by the <code>uuid-ref</code> within a subject." 059 */ 060 @BoundFlag( 061 formalName = "Subject Universally Unique Identifier Reference Type", 062 description = "Used to indicate the type of object pointed to by the `uuid-ref` within a subject.", 063 name = "type", 064 required = true, 065 typeAdapter = TokenAdapter.class, 066 valueConstraints = @ValueConstraints(allowedValues = @AllowedValues(level = IConstraint.Level.ERROR, allowOthers = true, values = {@AllowedValue(value = "component", description = "Component"), @AllowedValue(value = "inventory-item", description = "Inventory Item"), @AllowedValue(value = "location", description = "Location"), @AllowedValue(value = "party", description = "Interview Party"), @AllowedValue(value = "user", description = "User"), @AllowedValue(value = "resource", description = "Resource or Artifact")})) 067 ) 068 private String _type; 069 070 @BoundField( 071 formalName = "Subject Reference Title", 072 description = "The title or name for the referenced subject.", 073 useName = "title", 074 typeAdapter = MarkupLineAdapter.class 075 ) 076 private MarkupLine _title; 077 078 @BoundAssembly( 079 formalName = "Property", 080 description = "An attribute, characteristic, or quality of the containing object expressed as a namespace qualified name/value pair.", 081 useName = "prop", 082 maxOccurs = -1, 083 groupAs = @GroupAs(name = "props", inJson = JsonGroupAsBehavior.LIST) 084 ) 085 private List<Property> _props; 086 087 @BoundAssembly( 088 formalName = "Link", 089 description = "A reference to a local or remote resource, that has a specific relation to the containing object.", 090 useName = "link", 091 maxOccurs = -1, 092 groupAs = @GroupAs(name = "links", inJson = JsonGroupAsBehavior.LIST) 093 ) 094 private List<Link> _links; 095 096 @BoundField( 097 formalName = "Remarks", 098 description = "Additional commentary about the containing object.", 099 useName = "remarks", 100 typeAdapter = MarkupMultilineAdapter.class 101 ) 102 private MarkupMultiline _remarks; 103 104 public SubjectReference() { 105 this(null); 106 } 107 108 public SubjectReference(IMetaschemaData data) { 109 this.__metaschemaData = data; 110 } 111 112 @Override 113 public IMetaschemaData getMetaschemaData() { 114 return __metaschemaData; 115 } 116 117 public UUID getSubjectUuid() { 118 return _subjectUuid; 119 } 120 121 public void setSubjectUuid(UUID value) { 122 _subjectUuid = value; 123 } 124 125 public String getType() { 126 return _type; 127 } 128 129 public void setType(String value) { 130 _type = value; 131 } 132 133 public MarkupLine getTitle() { 134 return _title; 135 } 136 137 public void setTitle(MarkupLine value) { 138 _title = value; 139 } 140 141 public List<Property> getProps() { 142 return _props; 143 } 144 145 public void setProps(List<Property> value) { 146 _props = value; 147 } 148 149 /** 150 * Add a new {@link Property} item to the underlying collection. 151 * @param item the item to add 152 * @return {@code true} 153 */ 154 public boolean addProp(Property item) { 155 Property value = ObjectUtils.requireNonNull(item,"item cannot be null"); 156 if (_props == null) { 157 _props = new LinkedList<>(); 158 } 159 return _props.add(value); 160 } 161 162 /** 163 * Remove the first matching {@link Property} item from the underlying collection. 164 * @param item the item to remove 165 * @return {@code true} if the item was removed or {@code false} otherwise 166 */ 167 public boolean removeProp(Property item) { 168 Property value = ObjectUtils.requireNonNull(item,"item cannot be null"); 169 return _props != null && _props.remove(value); 170 } 171 172 public List<Link> getLinks() { 173 return _links; 174 } 175 176 public void setLinks(List<Link> value) { 177 _links = value; 178 } 179 180 /** 181 * Add a new {@link Link} item to the underlying collection. 182 * @param item the item to add 183 * @return {@code true} 184 */ 185 public boolean addLink(Link item) { 186 Link value = ObjectUtils.requireNonNull(item,"item cannot be null"); 187 if (_links == null) { 188 _links = new LinkedList<>(); 189 } 190 return _links.add(value); 191 } 192 193 /** 194 * Remove the first matching {@link Link} item from the underlying collection. 195 * @param item the item to remove 196 * @return {@code true} if the item was removed or {@code false} otherwise 197 */ 198 public boolean removeLink(Link item) { 199 Link value = ObjectUtils.requireNonNull(item,"item cannot be null"); 200 return _links != null && _links.remove(value); 201 } 202 203 public MarkupMultiline getRemarks() { 204 return _remarks; 205 } 206 207 public void setRemarks(MarkupMultiline value) { 208 _remarks = value; 209 } 210 211 @Override 212 public String toString() { 213 return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString(); 214 } 215}