001package gov.nist.secauto.oscal.lib.model; 002 003import gov.nist.secauto.metaschema.core.datatype.adapter.StringAdapter; 004import gov.nist.secauto.metaschema.core.datatype.adapter.TokenAdapter; 005import gov.nist.secauto.metaschema.core.datatype.markup.MarkupMultiline; 006import gov.nist.secauto.metaschema.core.datatype.markup.MarkupMultilineAdapter; 007import gov.nist.secauto.metaschema.core.model.IBoundObject; 008import gov.nist.secauto.metaschema.core.model.IMetaschemaData; 009import gov.nist.secauto.metaschema.core.model.JsonGroupAsBehavior; 010import gov.nist.secauto.metaschema.core.model.constraint.IConstraint; 011import gov.nist.secauto.metaschema.core.util.ObjectUtils; 012import gov.nist.secauto.metaschema.databind.model.annotations.AllowedValue; 013import gov.nist.secauto.metaschema.databind.model.annotations.AllowedValues; 014import gov.nist.secauto.metaschema.databind.model.annotations.BoundAssembly; 015import gov.nist.secauto.metaschema.databind.model.annotations.BoundField; 016import gov.nist.secauto.metaschema.databind.model.annotations.BoundFlag; 017import gov.nist.secauto.metaschema.databind.model.annotations.GroupAs; 018import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaAssembly; 019import gov.nist.secauto.metaschema.databind.model.annotations.ValueConstraints; 020import java.lang.Override; 021import java.lang.String; 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 * A specific edge within a source or target that is the subject of a mapping. 029 */ 030@MetaschemaAssembly( 031 formalName = "Mapping Entry Item (source or target)", 032 description = "A specific edge within a source or target that is the subject of a mapping.", 033 name = "mapping-item", 034 moduleClass = OscalMappingCommonModule.class 035) 036public class MappingItem implements IBoundObject { 037 private final IMetaschemaData __metaschemaData; 038 039 /** 040 * "The semantic type of the subject." 041 */ 042 @BoundFlag( 043 formalName = "Subject Type", 044 description = "The semantic type of the subject.", 045 name = "type", 046 required = true, 047 typeAdapter = TokenAdapter.class, 048 valueConstraints = @ValueConstraints(allowedValues = @AllowedValues(level = IConstraint.Level.ERROR, values = {@AllowedValue(value = "control", description = "A control as [defined](https://pages.nist.gov/OSCAL/concepts/terminology/#control) by OSCAL."), @AllowedValue(value = "statement", description = "A textual element of a control that defines part of the control's requirements.")})) 049 ) 050 private String _type; 051 052 /** 053 * "A reference to an identified subject that is of the specified <code>type</code> ." 054 */ 055 @BoundFlag( 056 formalName = "Subject Identifier Reference", 057 description = "A reference to an identified subject that is of the specified `type` .", 058 name = "id-ref", 059 required = true, 060 typeAdapter = StringAdapter.class 061 ) 062 private String _idRef; 063 064 @BoundAssembly( 065 formalName = "Property", 066 description = "An attribute, characteristic, or quality of the containing object expressed as a namespace qualified name/value pair.", 067 useName = "prop", 068 maxOccurs = -1, 069 groupAs = @GroupAs(name = "props", inJson = JsonGroupAsBehavior.LIST) 070 ) 071 private List<Property> _props; 072 073 @BoundAssembly( 074 formalName = "Link", 075 description = "A reference to a local or remote resource, that has a specific relation to the containing object.", 076 useName = "link", 077 maxOccurs = -1, 078 groupAs = @GroupAs(name = "links", inJson = JsonGroupAsBehavior.LIST) 079 ) 080 private List<Link> _links; 081 082 @BoundField( 083 formalName = "Remarks", 084 description = "Additional commentary about the containing object.", 085 useName = "remarks", 086 typeAdapter = MarkupMultilineAdapter.class 087 ) 088 private MarkupMultiline _remarks; 089 090 public MappingItem() { 091 this(null); 092 } 093 094 public MappingItem(IMetaschemaData data) { 095 this.__metaschemaData = data; 096 } 097 098 @Override 099 public IMetaschemaData getMetaschemaData() { 100 return __metaschemaData; 101 } 102 103 public String getType() { 104 return _type; 105 } 106 107 public void setType(String value) { 108 _type = value; 109 } 110 111 public String getIdRef() { 112 return _idRef; 113 } 114 115 public void setIdRef(String value) { 116 _idRef = value; 117 } 118 119 public List<Property> getProps() { 120 return _props; 121 } 122 123 public void setProps(List<Property> value) { 124 _props = value; 125 } 126 127 /** 128 * Add a new {@link Property} item to the underlying collection. 129 * @param item the item to add 130 * @return {@code true} 131 */ 132 public boolean addProp(Property item) { 133 Property value = ObjectUtils.requireNonNull(item,"item cannot be null"); 134 if (_props == null) { 135 _props = new LinkedList<>(); 136 } 137 return _props.add(value); 138 } 139 140 /** 141 * Remove the first matching {@link Property} item from the underlying collection. 142 * @param item the item to remove 143 * @return {@code true} if the item was removed or {@code false} otherwise 144 */ 145 public boolean removeProp(Property item) { 146 Property value = ObjectUtils.requireNonNull(item,"item cannot be null"); 147 return _props != null && _props.remove(value); 148 } 149 150 public List<Link> getLinks() { 151 return _links; 152 } 153 154 public void setLinks(List<Link> value) { 155 _links = value; 156 } 157 158 /** 159 * Add a new {@link Link} item to the underlying collection. 160 * @param item the item to add 161 * @return {@code true} 162 */ 163 public boolean addLink(Link item) { 164 Link value = ObjectUtils.requireNonNull(item,"item cannot be null"); 165 if (_links == null) { 166 _links = new LinkedList<>(); 167 } 168 return _links.add(value); 169 } 170 171 /** 172 * Remove the first matching {@link Link} item from the underlying collection. 173 * @param item the item to remove 174 * @return {@code true} if the item was removed or {@code false} otherwise 175 */ 176 public boolean removeLink(Link item) { 177 Link value = ObjectUtils.requireNonNull(item,"item cannot be null"); 178 return _links != null && _links.remove(value); 179 } 180 181 public MarkupMultiline getRemarks() { 182 return _remarks; 183 } 184 185 public void setRemarks(MarkupMultiline value) { 186 _remarks = value; 187 } 188 189 @Override 190 public String toString() { 191 return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString(); 192 } 193}