001package gov.nist.secauto.oscal.lib.model; 002 003import gov.nist.secauto.metaschema.core.datatype.adapter.UriAdapter; 004import gov.nist.secauto.metaschema.core.datatype.adapter.UriReferenceAdapter; 005import gov.nist.secauto.metaschema.core.datatype.adapter.UuidAdapter; 006import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLine; 007import gov.nist.secauto.metaschema.core.datatype.markup.MarkupLineAdapter; 008import gov.nist.secauto.metaschema.core.datatype.markup.MarkupMultiline; 009import gov.nist.secauto.metaschema.core.datatype.markup.MarkupMultilineAdapter; 010import gov.nist.secauto.metaschema.core.model.IBoundObject; 011import gov.nist.secauto.metaschema.core.model.IMetaschemaData; 012import gov.nist.secauto.metaschema.core.model.JsonGroupAsBehavior; 013import gov.nist.secauto.metaschema.core.model.constraint.IConstraint; 014import gov.nist.secauto.metaschema.core.util.ObjectUtils; 015import gov.nist.secauto.metaschema.databind.model.annotations.AllowedValue; 016import gov.nist.secauto.metaschema.databind.model.annotations.AllowedValues; 017import gov.nist.secauto.metaschema.databind.model.annotations.BoundAssembly; 018import gov.nist.secauto.metaschema.databind.model.annotations.BoundField; 019import gov.nist.secauto.metaschema.databind.model.annotations.BoundFlag; 020import gov.nist.secauto.metaschema.databind.model.annotations.GroupAs; 021import gov.nist.secauto.metaschema.databind.model.annotations.IndexHasKey; 022import gov.nist.secauto.metaschema.databind.model.annotations.KeyField; 023import gov.nist.secauto.metaschema.databind.model.annotations.Matches; 024import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaAssembly; 025import gov.nist.secauto.metaschema.databind.model.annotations.ValueConstraints; 026import java.lang.Override; 027import java.lang.String; 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 * A graphic that provides a visual representation the system, or some aspect of it. 036 */ 037@MetaschemaAssembly( 038 formalName = "Diagram", 039 description = "A graphic that provides a visual representation the system, or some aspect of it.", 040 name = "diagram", 041 moduleClass = OscalSspModule.class, 042 remarks = "A diagram must include a `link` with a rel value of \"diagram\", who's href references a remote URI or an internal reference within this document containing the diagram.", 043 valueConstraints = @ValueConstraints(allowedValues = @AllowedValues(level = IConstraint.Level.ERROR, target = "link/@rel", allowOthers = true, values = @AllowedValue(value = "diagram", description = "A reference to the diagram image.")), indexHasKey = @IndexHasKey(level = IConstraint.Level.ERROR, target = "link[@rel='diagram' and starts-with(@href,'#')]", indexName = "index-back-matter-resource", keyFields = @KeyField(target = "@href", pattern = "#(.*)")), matches = {@Matches(level = IConstraint.Level.ERROR, target = "link[@rel='diagram']/@href[starts-with(.,'#')]", typeAdapter = UriReferenceAdapter.class), @Matches(level = IConstraint.Level.ERROR, target = "link[@rel='diagram']/@href[not(starts-with(.,'#'))]", typeAdapter = UriAdapter.class)}) 044) 045public class Diagram implements IBoundObject { 046 private final IMetaschemaData __metaschemaData; 047 048 /** 049 * "A <a href=\"https://pages.nist.gov/OSCAL/concepts/identifier-use/#machine-oriented\">machine-oriented</a>, <a href=\"https://pages.nist.gov/OSCAL/concepts/identifier-use/#globally-unique\">globally unique</a> identifier with <a href=\"https://pages.nist.gov/OSCAL/concepts/identifier-use/#cross-instance\">cross-instance</a> scope that can be used to reference this diagram elsewhere in <a href=\"https://pages.nist.gov/OSCAL/concepts/identifier-use/#ssp-identifiers\">this or other OSCAL instances</a>. The locally defined <em>UUID</em> of the <code>diagram</code> can be used to reference the data item locally or globally (e.g., in an imported OSCAL instance). This UUID should be assigned <a href=\"https://pages.nist.gov/OSCAL/concepts/identifier-use/#consistency\">per-subject</a>, which means it should be consistently used to identify the same subject across revisions of the document." 050 */ 051 @BoundFlag( 052 formalName = "Diagram ID", 053 description = "A [machine-oriented](https://pages.nist.gov/OSCAL/concepts/identifier-use/#machine-oriented), [globally unique](https://pages.nist.gov/OSCAL/concepts/identifier-use/#globally-unique) identifier with [cross-instance](https://pages.nist.gov/OSCAL/concepts/identifier-use/#cross-instance) scope that can be used to reference this diagram elsewhere in [this or other OSCAL instances](https://pages.nist.gov/OSCAL/concepts/identifier-use/#ssp-identifiers). The locally defined *UUID* of the `diagram` can be used to reference the data item locally or globally (e.g., in an imported OSCAL instance). This UUID should be assigned [per-subject](https://pages.nist.gov/OSCAL/concepts/identifier-use/#consistency), which means it should be consistently used to identify the same subject across revisions of the document.", 054 name = "uuid", 055 required = true, 056 typeAdapter = UuidAdapter.class 057 ) 058 private UUID _uuid; 059 060 @BoundField( 061 formalName = "Diagram Description", 062 description = "A summary of the diagram.", 063 useName = "description", 064 remarks = "This description is intended to be used as alternate text to support compliance with requirements from [Section 508 of the United States Workforce Rehabilitation Act of 1973](https://www.section508.gov/manage/laws-and-policies).", 065 typeAdapter = MarkupMultilineAdapter.class 066 ) 067 private MarkupMultiline _description; 068 069 @BoundAssembly( 070 formalName = "Property", 071 description = "An attribute, characteristic, or quality of the containing object expressed as a namespace qualified name/value pair.", 072 useName = "prop", 073 maxOccurs = -1, 074 groupAs = @GroupAs(name = "props", inJson = JsonGroupAsBehavior.LIST) 075 ) 076 private List<Property> _props; 077 078 @BoundAssembly( 079 formalName = "Link", 080 description = "A reference to a local or remote resource, that has a specific relation to the containing object.", 081 useName = "link", 082 maxOccurs = -1, 083 groupAs = @GroupAs(name = "links", inJson = JsonGroupAsBehavior.LIST) 084 ) 085 private List<Link> _links; 086 087 @BoundField( 088 formalName = "Caption", 089 description = "A brief caption to annotate the diagram.", 090 useName = "caption", 091 typeAdapter = MarkupLineAdapter.class 092 ) 093 private MarkupLine _caption; 094 095 @BoundField( 096 formalName = "Remarks", 097 description = "Additional commentary about the containing object.", 098 useName = "remarks", 099 typeAdapter = MarkupMultilineAdapter.class 100 ) 101 private MarkupMultiline _remarks; 102 103 public Diagram() { 104 this(null); 105 } 106 107 public Diagram(IMetaschemaData data) { 108 this.__metaschemaData = data; 109 } 110 111 @Override 112 public IMetaschemaData getMetaschemaData() { 113 return __metaschemaData; 114 } 115 116 public UUID getUuid() { 117 return _uuid; 118 } 119 120 public void setUuid(UUID value) { 121 _uuid = value; 122 } 123 124 public MarkupMultiline getDescription() { 125 return _description; 126 } 127 128 public void setDescription(MarkupMultiline value) { 129 _description = value; 130 } 131 132 public List<Property> getProps() { 133 return _props; 134 } 135 136 public void setProps(List<Property> value) { 137 _props = value; 138 } 139 140 /** 141 * Add a new {@link Property} item to the underlying collection. 142 * @param item the item to add 143 * @return {@code true} 144 */ 145 public boolean addProp(Property item) { 146 Property value = ObjectUtils.requireNonNull(item,"item cannot be null"); 147 if (_props == null) { 148 _props = new LinkedList<>(); 149 } 150 return _props.add(value); 151 } 152 153 /** 154 * Remove the first matching {@link Property} item from the underlying collection. 155 * @param item the item to remove 156 * @return {@code true} if the item was removed or {@code false} otherwise 157 */ 158 public boolean removeProp(Property item) { 159 Property value = ObjectUtils.requireNonNull(item,"item cannot be null"); 160 return _props != null && _props.remove(value); 161 } 162 163 public List<Link> getLinks() { 164 return _links; 165 } 166 167 public void setLinks(List<Link> value) { 168 _links = value; 169 } 170 171 /** 172 * Add a new {@link Link} item to the underlying collection. 173 * @param item the item to add 174 * @return {@code true} 175 */ 176 public boolean addLink(Link item) { 177 Link value = ObjectUtils.requireNonNull(item,"item cannot be null"); 178 if (_links == null) { 179 _links = new LinkedList<>(); 180 } 181 return _links.add(value); 182 } 183 184 /** 185 * Remove the first matching {@link Link} item from the underlying collection. 186 * @param item the item to remove 187 * @return {@code true} if the item was removed or {@code false} otherwise 188 */ 189 public boolean removeLink(Link item) { 190 Link value = ObjectUtils.requireNonNull(item,"item cannot be null"); 191 return _links != null && _links.remove(value); 192 } 193 194 public MarkupLine getCaption() { 195 return _caption; 196 } 197 198 public void setCaption(MarkupLine value) { 199 _caption = value; 200 } 201 202 public MarkupMultiline getRemarks() { 203 return _remarks; 204 } 205 206 public void setRemarks(MarkupMultiline value) { 207 _remarks = value; 208 } 209 210 @Override 211 public String toString() { 212 return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString(); 213 } 214}