Skip to content

Commit

Permalink
Refactor DiagramCanvas and ArchitectureDiagram
Browse files Browse the repository at this point in the history
  • Loading branch information
lxatstariongroup committed Feb 13, 2024
1 parent c17fbfa commit ce82768
Show file tree
Hide file tree
Showing 16 changed files with 304 additions and 96 deletions.
42 changes: 40 additions & 2 deletions CDP4Common/AutoGenDto/ArchitectureDiagram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ public override string Route

dictionary.Add("ExcludedPerson", this.ExcludedPerson);

if (this.LockedBy != null)
{
dictionary.Add("LockedBy", new [] { this.LockedBy });
}

if (this.Owner != null)
{
dictionary.Add("Owner", new [] { this.Owner });
Expand Down Expand Up @@ -162,6 +167,14 @@ public override bool TryRemoveReferences(IEnumerable<Guid> ids, out List<string>
this.ExcludedPerson.Remove(id);
break;

case "LockedBy":
if (addModelErrors)
{
errors.Add($"Removed reference '{id}' from LockedBy property results in inconsistent ArchitectureDiagram.");
result = false;
}
break;

case "Owner":
if (addModelErrors)
{
Expand Down Expand Up @@ -224,6 +237,14 @@ public override bool TryRemoveReferencesNotIn(IEnumerable<Guid> ids, out List<st
}
break;

case "LockedBy":
if (referencedProperty.Value.Except(ids).Any())
{
errors.Add($"Removed reference '{referencedProperty.Key}' from LockedBy property results in inconsistent ArchitectureDiagram.");
result = false;
}
break;

case "Owner":
if (referencedProperty.Value.Except(ids).Any())
{
Expand Down Expand Up @@ -262,6 +283,13 @@ public override bool HasMandatoryReferenceToAny(IEnumerable<Guid> ids)
{
switch (kvp.Key)
{
case "LockedBy":
if (ids.Intersect(kvp.Value).Any())
{
result = true;
}
break;

case "Owner":
if (ids.Intersect(kvp.Value).Any())
{
Expand All @@ -287,6 +315,13 @@ public override bool HasMandatoryReferenceNotIn(HashSet<Guid> ids)
{
switch (kvp.Key)
{
case "LockedBy":
if (kvp.Value.Except(ids).Any())
{
result = true;
}
break;

case "Owner":
if (kvp.Value.Except(ids).Any())
{
Expand Down Expand Up @@ -361,15 +396,18 @@ public override void ResolveCopy(Thing originalThing, IReadOnlyDictionary<Thing,
this.ExcludedPerson.Add(copy.Value == null ? guid : copy.Value.Iid);
}

this.IsHidden = original.IsHidden;

var copyLockedBy = originalCopyMap.SingleOrDefault(kvp => kvp.Key.Iid == original.LockedBy);
this.LockedBy = copyLockedBy.Value == null ? original.LockedBy : copyLockedBy.Value.Iid;

this.ModifiedOn = original.ModifiedOn;

this.Name = original.Name;

var copyOwner = originalCopyMap.SingleOrDefault(kvp => kvp.Key.Iid == original.Owner);
this.Owner = copyOwner.Value == null ? original.Owner : copyOwner.Value.Iid;

this.PublicationState = original.PublicationState;

this.ThingPreference = original.ThingPreference;

var copyTopArchitectureElement = originalCopyMap.SingleOrDefault(kvp => kvp.Key.Iid == original.TopArchitectureElement);
Expand Down
54 changes: 50 additions & 4 deletions CDP4Common/AutoGenDto/DiagramCanvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,26 @@ public DiagramCanvas(Guid iid, int rev) : base(iid: iid, rev: rev)
/// <summary>
/// Gets or sets the Description.
/// </summary>
[CDPVersion("1.4.0")]
[UmlInformation(aggregation: AggregationKind.None, isDerived: false, isOrdered: false, isNullable: false, isPersistent: true)]
[DataMember]
public virtual string Description { get; set; }

/// <summary>
/// Gets or sets the PublicationState.
/// Gets or sets a value indicating whether IsHidden.
/// </summary>
[CDPVersion("1.4.0")]
[UmlInformation(aggregation: AggregationKind.None, isDerived: false, isOrdered: false, isNullable: false, isPersistent: true)]
[DataMember]
public virtual PublicationState PublicationState { get; set; }
public virtual bool IsHidden { get; set; }

/// <summary>
/// Gets or sets the unique identifier of the referenced LockedBy.
/// </summary>
[CDPVersion("1.4.0")]
[UmlInformation(aggregation: AggregationKind.None, isDerived: false, isOrdered: false, isNullable: false, isPersistent: true)]
[DataMember]
public virtual Guid LockedBy { get; set; }

/// <summary>
/// Gets the route for the current <see ref="DiagramCanvas"/>.
Expand All @@ -117,6 +127,11 @@ public override string Route

dictionary.Add("ExcludedPerson", this.ExcludedPerson);

if (this.LockedBy != null)
{
dictionary.Add("LockedBy", new [] { this.LockedBy });
}

return dictionary;
}

Expand Down Expand Up @@ -158,6 +173,14 @@ public override bool TryRemoveReferences(IEnumerable<Guid> ids, out List<string>
case "ExcludedPerson":
this.ExcludedPerson.Remove(id);
break;

case "LockedBy":
if (addModelErrors)
{
errors.Add($"Removed reference '{id}' from LockedBy property results in inconsistent DiagramCanvas.");
result = false;
}
break;
}
}
}
Expand Down Expand Up @@ -208,6 +231,14 @@ public override bool TryRemoveReferencesNotIn(IEnumerable<Guid> ids, out List<st
this.ExcludedPerson.Remove(toBeRemoved);
}
break;

case "LockedBy":
if (referencedProperty.Value.Except(ids).Any())
{
errors.Add($"Removed reference '{referencedProperty.Key}' from LockedBy property results in inconsistent DiagramCanvas.");
result = false;
}
break;
}
}

Expand All @@ -232,6 +263,12 @@ public override bool HasMandatoryReferenceToAny(IEnumerable<Guid> ids)
{
switch (kvp.Key)
{
case "LockedBy":
if (ids.Intersect(kvp.Value).Any())
{
result = true;
}
break;
}
}

Expand All @@ -251,6 +288,12 @@ public override bool HasMandatoryReferenceNotIn(HashSet<Guid> ids)
{
switch (kvp.Key)
{
case "LockedBy":
if (kvp.Value.Except(ids).Any())
{
result = true;
}
break;
}
}

Expand Down Expand Up @@ -319,12 +362,15 @@ public override void ResolveCopy(Thing originalThing, IReadOnlyDictionary<Thing,
this.ExcludedPerson.Add(copy.Value == null ? guid : copy.Value.Iid);
}

this.IsHidden = original.IsHidden;

var copyLockedBy = originalCopyMap.SingleOrDefault(kvp => kvp.Key.Iid == original.LockedBy);
this.LockedBy = copyLockedBy.Value == null ? original.LockedBy : copyLockedBy.Value.Iid;

this.ModifiedOn = original.ModifiedOn;

this.Name = original.Name;

this.PublicationState = original.PublicationState;

this.ThingPreference = original.ThingPreference;
}

Expand Down
15 changes: 9 additions & 6 deletions CDP4Common/AutoGenEquatable/ArchitectureDiagramEquatable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@
| 8 | createdOn | DateTime | 1..1 | 1.4.0 |
| 9 | description | string | 1..1 | 1.4.0 |
| 10 | diagramElement | Guid | 0..* | 1.4.0 |
| 11 | name | string | 1..1 | 1.4.0 |
| 12 | owner | Guid | 1..1 | 1.4.0 |
| 13 | publicationState | PublicationState | 1..1 | 1.4.0 |
| 14 | topArchitectureElement | Guid | 0..1 | 1.4.0 |
| 11 | isHidden | bool | 1..1 | 1.4.0 |
| 12 | lockedBy | Guid | 1..1 | 1.4.0 |
| 13 | name | string | 1..1 | 1.4.0 |
| 14 | owner | Guid | 1..1 | 1.4.0 |
| 15 | topArchitectureElement | Guid | 0..1 | 1.4.0 |
* -------------------------------------------- | ---------------------------- | ----------- | ------- */

namespace CDP4Common.DTO.Equatable
Expand Down Expand Up @@ -106,13 +107,15 @@ public static bool ArePropertiesEqual(this ArchitectureDiagram me, ArchitectureD

if (!me.DiagramElement.OrderBy(x => x).SequenceEqual(other.DiagramElement.OrderBy(x => x))) return false;

if (!me.IsHidden.Equals(other.IsHidden)) return false;

if (!me.LockedBy.Equals(other.LockedBy)) return false;

if (me.Name == null && other.Name != null) return false;
if (me.Name != null && !me.Name.Equals(other.Name)) return false;

if (!me.Owner.Equals(other.Owner)) return false;

if (!me.PublicationState.Equals(other.PublicationState)) return false;

if (me.TopArchitectureElement.HasValue != other.TopArchitectureElement.HasValue) return false;
if (!me.TopArchitectureElement.Equals(other.TopArchitectureElement)) return false;

Expand Down
31 changes: 17 additions & 14 deletions CDP4Common/AutoGenEquatable/DiagramCanvasEquatable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,16 @@
| -------------------------------------------- | ---------------------------- | ----------- | ------- |
| 2 | bounds | Guid | 0..1 | 1.1.0 |
| 3 | createdOn | DateTime | 1..1 | 1.1.0 |
| 4 | description | string | 1..1 | 1.1.0 |
| 5 | diagramElement | Guid | 0..* | 1.1.0 |
| 6 | excludedDomain | Guid | 0..* | 1.1.0 |
| 7 | excludedPerson | Guid | 0..* | 1.1.0 |
| 8 | modifiedOn | DateTime | 1..1 | 1.1.0 |
| 9 | name | string | 1..1 | 1.1.0 |
| 10 | publicationState | PublicationState | 1..1 | 1.1.0 |
| 11 | thingPreference | string | 0..1 | 1.2.0 |
| 12 | actor | Guid | 0..1 | 1.3.0 |
| 4 | diagramElement | Guid | 0..* | 1.1.0 |
| 5 | excludedDomain | Guid | 0..* | 1.1.0 |
| 6 | excludedPerson | Guid | 0..* | 1.1.0 |
| 7 | modifiedOn | DateTime | 1..1 | 1.1.0 |
| 8 | name | string | 1..1 | 1.1.0 |
| 9 | thingPreference | string | 0..1 | 1.2.0 |
| 10 | actor | Guid | 0..1 | 1.3.0 |
| 11 | description | string | 1..1 | 1.4.0 |
| 12 | isHidden | bool | 1..1 | 1.4.0 |
| 13 | lockedBy | Guid | 1..1 | 1.4.0 |
* -------------------------------------------- | ---------------------------- | ----------- | ------- */

namespace CDP4Common.DTO.Equatable
Expand Down Expand Up @@ -87,9 +88,6 @@ public static bool ArePropertiesEqual(this DiagramCanvas me, DiagramCanvas other

if (!me.CreatedOn.Equals(other.CreatedOn)) return false;

if (me.Description == null && other.Description != null) return false;
if (me.Description != null && !me.Description.Equals(other.Description)) return false;

if (!me.DiagramElement.OrderBy(x => x).SequenceEqual(other.DiagramElement.OrderBy(x => x))) return false;

if (!me.ExcludedDomain.OrderBy(x => x).SequenceEqual(other.ExcludedDomain.OrderBy(x => x))) return false;
Expand All @@ -101,14 +99,19 @@ public static bool ArePropertiesEqual(this DiagramCanvas me, DiagramCanvas other
if (me.Name == null && other.Name != null) return false;
if (me.Name != null && !me.Name.Equals(other.Name)) return false;

if (!me.PublicationState.Equals(other.PublicationState)) return false;

if (me.ThingPreference == null && other.ThingPreference != null) return false;
if (me.ThingPreference != null && !me.ThingPreference.Equals(other.ThingPreference)) return false;

if (me.Actor.HasValue != other.Actor.HasValue) return false;
if (!me.Actor.Equals(other.Actor)) return false;

if (me.Description == null && other.Description != null) return false;
if (me.Description != null && !me.Description.Equals(other.Description)) return false;

if (!me.IsHidden.Equals(other.IsHidden)) return false;

if (!me.LockedBy.Equals(other.LockedBy)) return false;

return true;
}
}
Expand Down
12 changes: 9 additions & 3 deletions CDP4Common/AutoGenMetaInfo/ArchitectureDiagramMetaInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,11 @@ public IEnumerable<OrderedItem> GetOrderedContainmentIds(CDP4Common.DTO.Thing ar
private readonly Dictionary<string, string> cdpVersionedProperties = new Dictionary<string, string>
{
{ "Actor", "1.3.0" },
{ "Description", "1.4.0" },
{ "ExcludedDomain", "1.1.0" },
{ "ExcludedPerson", "1.1.0" },
{ "IsHidden", "1.4.0" },
{ "LockedBy", "1.4.0" },
{ "ModifiedOn", "1.1.0" },
{ "ThingPreference", "1.2.0" },
};
Expand Down Expand Up @@ -245,10 +248,11 @@ public IEnumerable<PropertyMetaInfo> Properties
{ "ExcludedDomain", thing => thing.ExcludedDomain },
{ "ExcludedPerson", thing => thing.ExcludedPerson },
{ "Iid", thing => thing.Iid },
{ "IsHidden", thing => thing.IsHidden },
{ "LockedBy", thing => thing.LockedBy },
{ "ModifiedOn", thing => thing.ModifiedOn },
{ "Name", thing => thing.Name },
{ "Owner", thing => thing.Owner },
{ "PublicationState", thing => thing.PublicationState },
{ "RevisionNumber", thing => thing.RevisionNumber },
{ "ThingPreference", thing => thing.ThingPreference },
{ "TopArchitectureElement", thing => thing.TopArchitectureElement },
Expand All @@ -269,10 +273,11 @@ public IEnumerable<PropertyMetaInfo> Properties
{ "ExcludedDomain", new PropertyMetaInfo("ExcludedDomain", "DomainOfExpertise", PropertyKind.List, AggregationKind.None, false, false, true, 0, "*", true) },
{ "ExcludedPerson", new PropertyMetaInfo("ExcludedPerson", "Person", PropertyKind.List, AggregationKind.None, false, false, true, 0, "*", true) },
{ "Iid", new PropertyMetaInfo("Iid", "Guid", PropertyKind.Scalar, AggregationKind.None, false, false, true, 1, "1", true) },
{ "IsHidden", new PropertyMetaInfo("IsHidden", "bool", PropertyKind.Scalar, AggregationKind.None, false, false, true, 1, "1", true) },
{ "LockedBy", new PropertyMetaInfo("LockedBy", "Person", PropertyKind.Scalar, AggregationKind.None, false, false, true, 1, "1", true) },
{ "ModifiedOn", new PropertyMetaInfo("ModifiedOn", "DateTime", PropertyKind.Scalar, AggregationKind.None, false, false, true, 1, "1", true) },
{ "Name", new PropertyMetaInfo("Name", "string", PropertyKind.Scalar, AggregationKind.None, false, false, true, 1, "1", true) },
{ "Owner", new PropertyMetaInfo("Owner", "DomainOfExpertise", PropertyKind.Scalar, AggregationKind.None, false, false, true, 1, "1", true) },
{ "PublicationState", new PropertyMetaInfo("PublicationState", "CDP4Common.DiagramData.PublicationState", PropertyKind.Scalar, AggregationKind.None, false, false, true, 1, "1", true) },
{ "RevisionNumber", new PropertyMetaInfo("RevisionNumber", "int", PropertyKind.Scalar, AggregationKind.None, false, false, true, 1, "1", true) },
{ "ThingPreference", new PropertyMetaInfo("ThingPreference", "string", PropertyKind.Scalar, AggregationKind.None, false, false, true, 0, "1", true) },
{ "TopArchitectureElement", new PropertyMetaInfo("TopArchitectureElement", "ArchitectureElement", PropertyKind.Scalar, AggregationKind.None, false, false, true, 0, "1", true) },
Expand All @@ -298,10 +303,11 @@ public IEnumerable<PropertyMetaInfo> Properties
{ "CreatedOn", (architectureDiagram, value) => architectureDiagram.CreatedOn = (DateTime)value },
{ "Description", (architectureDiagram, value) => architectureDiagram.Description = value.ToString() },
{ "Iid", (architectureDiagram, value) => architectureDiagram.Iid = (Guid)value },
{ "IsHidden", (architectureDiagram, value) => architectureDiagram.IsHidden = (bool)value },
{ "LockedBy", (architectureDiagram, value) => architectureDiagram.LockedBy = (Guid)value },
{ "ModifiedOn", (architectureDiagram, value) => architectureDiagram.ModifiedOn = (DateTime)value },
{ "Name", (architectureDiagram, value) => architectureDiagram.Name = value.ToString() },
{ "Owner", (architectureDiagram, value) => architectureDiagram.Owner = (Guid)value },
{ "PublicationState", (architectureDiagram, value) => architectureDiagram.PublicationState = (PublicationState)value },
{ "ThingPreference", (architectureDiagram, value) => architectureDiagram.ThingPreference = value == null ? (string)null : value.ToString() },
{ "TopArchitectureElement", (architectureDiagram, value) => architectureDiagram.TopArchitectureElement = value == null ? (Guid?)null : (Guid)value },
};
Expand Down
Loading

0 comments on commit ce82768

Please sign in to comment.