| | 1 | | using System.Diagnostics.CodeAnalysis; |
| | 2 | | using System.Text.Json.Serialization; |
| | 3 | | using Spdx3.Exceptions; |
| | 4 | | using Spdx3.Model.Core.Enums; |
| | 5 | | using Spdx3.Model.Lite; |
| | 6 | | using Spdx3.Serialization; |
| | 7 | | using Spdx3.Utility; |
| | 8 | |
|
| | 9 | | namespace Spdx3.Model.Core.Classes; |
| | 10 | |
|
| | 11 | | /// <summary> |
| | 12 | | /// Describes a relationship between one or more elements. |
| | 13 | | /// See https://spdx.github.io/spdx-spec/v3.0.1/model/Core/Classes/Relationship/ |
| | 14 | | /// </summary> |
| | 15 | | public class Relationship : Element, ILiteDomainCompliantElement |
| | 16 | | { |
| | 17 | | [JsonPropertyName("completeness")] |
| | 18 | | [JsonConverter(typeof(SpdxModelConverterFactory))] |
| 49 | 19 | | public RelationshipCompleteness? Completeness { get; set; } |
| | 20 | |
|
| | 21 | | [JsonPropertyName("endTime")] |
| | 22 | | [JsonConverter(typeof(SpdxModelConverterFactory))] |
| 45 | 23 | | public DateTimeOffset? EndTime { get; set; } |
| | 24 | |
|
| | 25 | | [JsonPropertyName("from")] |
| | 26 | | [JsonConverter(typeof(SpdxModelConverterFactory))] |
| 379 | 27 | | public required Element From { get; set; } |
| | 28 | |
|
| | 29 | | [JsonPropertyName("relationshipType")] |
| | 30 | | [JsonConverter(typeof(SpdxModelConverterFactory))] |
| 233 | 31 | | public required RelationshipType RelationshipType { get; set; } |
| | 32 | |
|
| | 33 | | [JsonPropertyName("startTime")] |
| | 34 | | [JsonConverter(typeof(SpdxModelConverterFactory))] |
| 45 | 35 | | public DateTimeOffset? StartTime { get; set; } |
| | 36 | |
|
| | 37 | | [JsonPropertyName("to")] |
| | 38 | | [JsonConverter(typeof(SpdxModelConverterFactory))] |
| 417 | 39 | | public IList<Element> To { get; set; } = new List<Element>(); |
| | 40 | |
|
| | 41 | | // protected internal no-parm constructor required for deserialization |
| | 42 | | // ReSharper disable once MemberCanBeProtected.Global |
| 35 | 43 | | protected internal Relationship() |
| | 44 | | { |
| 35 | 45 | | } |
| | 46 | |
|
| | 47 | |
|
| | 48 | | /// <summary> |
| | 49 | | /// Describes a relationship between one or more elements. |
| | 50 | | /// See https://spdx.github.io/spdx-spec/v3.0.1/model/Core/Classes/Relationship/ |
| | 51 | | /// </summary> |
| | 52 | | [method: SetsRequiredMembers] |
| | 53 | | public Relationship(Catalog catalog, CreationInfo creationInfo, RelationshipType relationshipType, Element from, |
| 78 | 54 | | List<Element> to) : base(catalog, creationInfo) |
| | 55 | | { |
| 78 | 56 | | From = from; |
| 78 | 57 | | To = to; |
| 78 | 58 | | RelationshipType = relationshipType; |
| 78 | 59 | | } |
| | 60 | |
|
| | 61 | | public void Accept(ILiteDomainComplianceVisitor visitor) |
| | 62 | | { |
| 4 | 63 | | visitor.Visit(this); |
| 4 | 64 | | } |
| | 65 | |
|
| | 66 | | public override void Validate() |
| | 67 | | { |
| 39 | 68 | | base.Validate(); |
| 37 | 69 | | ValidateRequiredProperty(nameof(From)); |
| | 70 | |
|
| 36 | 71 | | if (To.Count == 0) |
| | 72 | | { |
| 1 | 73 | | throw new Spdx3ValidationException(this, nameof(To), "Cannot be empty"); |
| | 74 | | } |
| | 75 | |
|
| 35 | 76 | | ValidateRequiredProperty(nameof(RelationshipType)); |
| 35 | 77 | | } |
| | 78 | | } |