Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use ObjectId for object ids in MetasysClient #141

Merged
merged 8 commits into from
Aug 27, 2024

Conversation

michaelgwelch
Copy link
Member

@michaelgwelch michaelgwelch commented Jul 27, 2024

This will be slightly easier to review one commit at a time. Only the first one is large. But 90% of it is changing type from Guid to ObjectId or converting guid to/from objectid

It was a mistake that we started using Guid for object identifiers in this library. The Metasys REST API makes no guarantee that the ids it returns will be Guids. It has never documented them as such. (For example see Get an object and examine the objectId parameter.)

This PR starts the transition away from using Guid

  • Introduce new ObjectId type which has implicit conversions to/from string and to/from Guid to aid the transition to the new methods. The new type was used (instead of just using string) as I think it makes the APIs slightly easier to understand. But it also allowed us to create implicit conversions so that the changes could be made without introducing compile time breakages for clients.

  • Modify all methods of MetasysClient and IMetasysClient that use Guid as an objectIdentifier to take an ObjectId instead. This is a non-breaking change due to the implicit conversion from Guid to ObjectId (unless clients are using Reflection to find methods).

  • For MetasysClient and IMetasysClient methods that take an IEnumerable<Guid> we had to leave those methods. But we marked them obsolete, added new methods that take IEnumerable<ObjectId>. These new methods take their implementation from the old methods. The old methods delegate to the new methods so they are easy to delete in the future.

Future work: There are many other interfaces/methods that identify objects by Guid. This PR will be updated with those as well

  • Update README to remove use of Guid.
  • Alarms
  • Audits
  • Trends
  • Spaces: Switch methods to use ObjectId instead of Guid
  • Equipment: Switch methods to use ObjectId instead of Guid
  • Change MetasysObject.Id return type to ObjectId
  • Fix demo apps to use non-obsolete methods
  • Add tests that use new methods (not 100% needed as the old methods that
    are being called just delegate to the new methods.

Note

Alarm, Audit and Activity guid identifiers will be left alone (for now). While those are also just documented as strings it just increases the scope of the change to be too large. So only Object identifiers are being targeted at this time. See #142 for the alarms and audits changes.

@michaelgwelch michaelgwelch force-pushed the welch/removeGuidFromSignatures branch from 4014fde to 0f7f2b2 Compare July 27, 2024 15:11
@michaelgwelch michaelgwelch force-pushed the welch/removeGuidFromSignatures branch 10 times, most recently from c0b1775 to b7c9429 Compare July 27, 2024 19:06
@michaelgwelch michaelgwelch self-assigned this Jul 28, 2024
@michaelgwelch michaelgwelch marked this pull request as ready for review July 28, 2024 16:02
@michaelgwelch michaelgwelch added the enhancement New feature or request label Jul 28, 2024
@michaelgwelch michaelgwelch force-pushed the welch/removeGuidFromSignatures branch from b7c9429 to b7e18fe Compare July 29, 2024 14:33
@michaelgwelch michaelgwelch force-pushed the welch/removeGuidFromSignatures branch 3 times, most recently from 4ea75f2 to fa54be9 Compare August 2, 2024 16:57
@@ -282,26 +285,10 @@ public void TestGetObjectIdentifierBadRequestThrowsException()
PrintMessage($"TestGetObjectIdentifierBadRequestThrowsException: {e.Message}");
}

[Test]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test was removed because it represents a condition that can't happen any more. We can't fail parsing a guid since we no longer attempt to parse to guid.

[Test]
public void TestGetObjectIdentifierNullResponseThrowsException()
{
httpTest.RespondWith("null");
httpTest.RespondWithJson(JToken.Parse("null"));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To test for null we need a JSON null which looks like null vs. a string with the word null which looks like "null". The previous version of this test was just encoding the word "null" as a string.

Tasks.md Outdated Show resolved Hide resolved
It was a mistake that we started using Guid for object identifiers
in this library. The Metasys REST API makes no guarantee that the ids
it returns will be Guids. It has never documented them as such.

This commit starts to transition us away from Using Guid

- Introduce new ObjectId type which has implicit conversions
  to/from string and to/from Guid to aid the transition to the new methods

- Modify all methods of MetasysClient and IMetasysClient that use Guid as
  an objectIdentifier to take an ObjectId instead. This is a non-breaking
  change (unless clients are using Reflection to find methods).

- For MetasysClient and IMetasysClient methods that take an IEnumerable<Guid>
  we had to leave those methods. But we marked them obsolete, added new methods
  that take IEnumerable<ObjectId>. These new methods take their implementation from
  the old methods. The old methods delegate to the new methods so they are easy
  to delete in the future.

- In tests and demo apps disabled warning related to obsolete methods (for now).

- fix variant related classes to use ObjectId

- fix BatchRequestParm

- Fix ParseObjectIdentifier to stop using Guid and just return ObjectId.
  Remove a test case related to parsing Guid.
@michaelgwelch michaelgwelch force-pushed the welch/removeGuidFromSignatures branch from fa54be9 to 8c66502 Compare August 2, 2024 17:18
@michaelgwelch michaelgwelch force-pushed the welch/removeGuidFromSignatures branch from 8c66502 to aebda38 Compare August 2, 2024 17:20
@michaelgwelch michaelgwelch changed the base branch from master to main August 4, 2024 15:16
@michaelgwelch michaelgwelch force-pushed the welch/removeGuidFromSignatures branch 3 times, most recently from 5a5b63f to 9a93671 Compare August 5, 2024 13:59
@michaelgwelch michaelgwelch force-pushed the welch/removeGuidFromSignatures branch from 9a93671 to ecc1b3d Compare August 5, 2024 14:22
@Federico-Artioli Federico-Artioli merged commit a8c62e9 into main Aug 27, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants