001package org.schemastore.json.sarif.x210; 002 003import gov.nist.secauto.metaschema.core.datatype.adapter.IntegerAdapter; 004import gov.nist.secauto.metaschema.core.datatype.adapter.PositiveIntegerAdapter; 005import gov.nist.secauto.metaschema.core.datatype.adapter.StringAdapter; 006import gov.nist.secauto.metaschema.core.datatype.adapter.UuidAdapter; 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.Expect; 018import gov.nist.secauto.metaschema.databind.model.annotations.GroupAs; 019import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaAssembly; 020import gov.nist.secauto.metaschema.databind.model.annotations.ValueConstraints; 021import java.lang.Override; 022import java.lang.String; 023import java.math.BigInteger; 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 * Results from the run of a tool. 032 */ 033@MetaschemaAssembly( 034 formalName = "Results", 035 description = "Results from the run of a tool.", 036 name = "result", 037 moduleClass = SarifModule.class, 038 valueConstraints = @ValueConstraints(expect = @Expect(level = IConstraint.Level.ERROR, test = "@ruleIndex >= -1", message = "The value '{ . }' is not greater than or equal to '-1'.")) 039) 040public class Result implements IBoundObject { 041 private final IMetaschemaData __metaschemaData; 042 043 /** 044 * "The stable, unique identifier of the rule, if any, to which this result is relevant." 045 */ 046 @BoundFlag( 047 formalName = "Rule Identifier", 048 description = "The stable, unique identifier of the rule, if any, to which this result is relevant.", 049 name = "ruleId", 050 typeAdapter = StringAdapter.class 051 ) 052 private String _ruleId; 053 054 /** 055 * "The stable, unique identifier of the rule, if any, to which this result is relevant." 056 */ 057 @BoundFlag( 058 formalName = "Rule Identifier", 059 description = "The stable, unique identifier of the rule, if any, to which this result is relevant.", 060 name = "ruleIndex", 061 defaultValue = "-1", 062 typeAdapter = IntegerAdapter.class 063 ) 064 private BigInteger _ruleIndex; 065 066 /** 067 * "A stable, unique identifier for the result." 068 */ 069 @BoundFlag( 070 formalName = "Result Unique Identifier", 071 description = "A stable, unique identifier for the result.", 072 name = "guid", 073 typeAdapter = UuidAdapter.class 074 ) 075 private UUID _guid; 076 077 @BoundAssembly( 078 formalName = "Reporting Descriptor Reference", 079 description = "A reference used to locate the rule descriptor relevant to this result.", 080 useName = "rule" 081 ) 082 private ReportingDescriptorReference _rule; 083 084 @BoundField( 085 formalName = "Result Kind", 086 description = "A value that categorizes results by evaluation state.", 087 useName = "kind", 088 defaultValue = "fail", 089 valueConstraints = @ValueConstraints(allowedValues = @AllowedValues(level = IConstraint.Level.ERROR, values = {@AllowedValue(value = "notApplicable", description = ""), @AllowedValue(value = "pass", description = ""), @AllowedValue(value = "fail", description = ""), @AllowedValue(value = "review", description = ""), @AllowedValue(value = "open", description = ""), @AllowedValue(value = "informational", description = "")})) 090 ) 091 private String _kind; 092 093 @BoundField( 094 formalName = "Severity Level", 095 description = "A value specifying the severity level of the result.", 096 useName = "level", 097 defaultValue = "warning", 098 valueConstraints = @ValueConstraints(allowedValues = @AllowedValues(level = IConstraint.Level.ERROR, values = {@AllowedValue(value = "none", description = ""), @AllowedValue(value = "note", description = ""), @AllowedValue(value = "warning", description = ""), @AllowedValue(value = "error", description = "")})) 099 ) 100 private String _level; 101 102 @BoundAssembly( 103 formalName = "Result Message", 104 description = "A message that describes the result. The first sentence of the message only will be displayed when visible space is limited.", 105 useName = "message" 106 ) 107 private Message _message; 108 109 @BoundAssembly( 110 formalName = "Scanned Artifact", 111 description = "Identifies the artifact that the analysis tool was instructed to scan. This need not be the same as the artifact where the result actually occurred.", 112 useName = "analysisTarget" 113 ) 114 private ArtifactLocation _analysisTarget; 115 116 @BoundAssembly( 117 formalName = "Result Location", 118 description = "The set of locations where the result was detected. Specify only one location unless the problem indicated by the result can only be corrected by making a change at every specified location.", 119 useName = "location", 120 maxOccurs = -1, 121 groupAs = @GroupAs(name = "locations", inJson = JsonGroupAsBehavior.LIST) 122 ) 123 private List<Location> _locations; 124 125 @BoundField( 126 formalName = "Occurrence Count", 127 description = "A positive integer specifying the number of times this logically unique result was observed in this run.", 128 useName = "occurenceCount", 129 typeAdapter = PositiveIntegerAdapter.class 130 ) 131 private BigInteger _occurenceCount; 132 133 @BoundAssembly( 134 formalName = "Result Related Location", 135 description = "A set of locations relevant to this result.", 136 useName = "relatedLocation" 137 ) 138 private Location _relatedLocation; 139 140 @BoundAssembly( 141 formalName = "Result Provenance", 142 description = "Information about how and when the result was detected.", 143 useName = "provenance" 144 ) 145 private ResultProvenance _provenance; 146 147 public Result() { 148 this(null); 149 } 150 151 public Result(IMetaschemaData data) { 152 this.__metaschemaData = data; 153 } 154 155 @Override 156 public IMetaschemaData getMetaschemaData() { 157 return __metaschemaData; 158 } 159 160 public String getRuleId() { 161 return _ruleId; 162 } 163 164 public void setRuleId(String value) { 165 _ruleId = value; 166 } 167 168 public BigInteger getRuleIndex() { 169 return _ruleIndex; 170 } 171 172 public void setRuleIndex(BigInteger value) { 173 _ruleIndex = value; 174 } 175 176 public UUID getGuid() { 177 return _guid; 178 } 179 180 public void setGuid(UUID value) { 181 _guid = value; 182 } 183 184 public ReportingDescriptorReference getRule() { 185 return _rule; 186 } 187 188 public void setRule(ReportingDescriptorReference value) { 189 _rule = value; 190 } 191 192 public String getKind() { 193 return _kind; 194 } 195 196 public void setKind(String value) { 197 _kind = value; 198 } 199 200 public String getLevel() { 201 return _level; 202 } 203 204 public void setLevel(String value) { 205 _level = value; 206 } 207 208 public Message getMessage() { 209 return _message; 210 } 211 212 public void setMessage(Message value) { 213 _message = value; 214 } 215 216 public ArtifactLocation getAnalysisTarget() { 217 return _analysisTarget; 218 } 219 220 public void setAnalysisTarget(ArtifactLocation value) { 221 _analysisTarget = value; 222 } 223 224 public List<Location> getLocations() { 225 return _locations; 226 } 227 228 public void setLocations(List<Location> value) { 229 _locations = value; 230 } 231 232 /** 233 * Add a new {@link Location} item to the underlying collection. 234 * @param item the item to add 235 * @return {@code true} 236 */ 237 public boolean addLocation(Location item) { 238 Location value = ObjectUtils.requireNonNull(item,"item cannot be null"); 239 if (_locations == null) { 240 _locations = new LinkedList<>(); 241 } 242 return _locations.add(value); 243 } 244 245 /** 246 * Remove the first matching {@link Location} item from the underlying collection. 247 * @param item the item to remove 248 * @return {@code true} if the item was removed or {@code false} otherwise 249 */ 250 public boolean removeLocation(Location item) { 251 Location value = ObjectUtils.requireNonNull(item,"item cannot be null"); 252 return _locations != null && _locations.remove(value); 253 } 254 255 public BigInteger getOccurenceCount() { 256 return _occurenceCount; 257 } 258 259 public void setOccurenceCount(BigInteger value) { 260 _occurenceCount = value; 261 } 262 263 public Location getRelatedLocation() { 264 return _relatedLocation; 265 } 266 267 public void setRelatedLocation(Location value) { 268 _relatedLocation = value; 269 } 270 271 public ResultProvenance getProvenance() { 272 return _provenance; 273 } 274 275 public void setProvenance(ResultProvenance value) { 276 _provenance = value; 277 } 278 279 @Override 280 public String toString() { 281 return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString(); 282 } 283}