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