From f670fa66aaad85871d8e551ac643d05de02ac357 Mon Sep 17 00:00:00 2001 From: Klaas Vandeweerdt Date: Sat, 31 Dec 2022 22:12:55 +0100 Subject: [PATCH] Release 2.0.7 - Add SLA ServiceInstance Relations --- ...rviceLevelAgreementServiceInstancesTest.cs | 35 +++++++++ ...ceLevelAgreementServiceInstanceRelation.cs | 73 +++++++++++++++++++ Source/Sdk4me/Enumerators/Enumerators.cs | 17 +++++ .../Handlers/ServiceLevelAgreementHandler.cs | 58 +++++++++++++++ Source/Sdk4me/Sdk4me.csproj | 7 +- 5 files changed, 187 insertions(+), 3 deletions(-) create mode 100644 Source/Sdk4me.Tests/ServiceLevelAgreementServiceInstancesTest.cs create mode 100644 Source/Sdk4me/Entities/ServiceLevelAgreementServiceInstanceRelation.cs diff --git a/Source/Sdk4me.Tests/ServiceLevelAgreementServiceInstancesTest.cs b/Source/Sdk4me.Tests/ServiceLevelAgreementServiceInstancesTest.cs new file mode 100644 index 0000000..8fff7ef --- /dev/null +++ b/Source/Sdk4me.Tests/ServiceLevelAgreementServiceInstancesTest.cs @@ -0,0 +1,35 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Collections.Generic; +using System.Linq; +using System.Threading; + +namespace Sdk4me.Tests +{ + [TestClass] + public class ServiceLevelAgreementServiceInstancesTest + { + [TestMethod] + public void Get() + { + Sdk4meClient client = Client.Get(); + ServiceLevelAgreement sla = client.ServiceLevelAgreements.Get(313); + Assert.IsNotNull(sla); + + List relations = client.ServiceLevelAgreements.GetServiceInstances(sla, "*"); + Assert.IsNotNull(relations); + + ServiceLevelAgreementServiceInstanceRelation relation = relations.Where(x => x.ServiceInstance.ID == 87).FirstOrDefault(); + Assert.IsNotNull(relation); + + bool result = client.ServiceLevelAgreements.DeleteServiceInstance(sla, relation); + Assert.AreEqual(true, result); + + relation = client.ServiceLevelAgreements.AddServiceInstance(sla, new ServiceLevelAgreementServiceInstanceRelation() + { + ImpactRelation = ServiceLevelAgreementServiceInstanceRelationStatus.Down, + ServiceInstance = new ServiceInstance() { ID = 87 } + }); + Assert.IsNotNull(relation); + } + } +} diff --git a/Source/Sdk4me/Entities/ServiceLevelAgreementServiceInstanceRelation.cs b/Source/Sdk4me/Entities/ServiceLevelAgreementServiceInstanceRelation.cs new file mode 100644 index 0000000..fdc60af --- /dev/null +++ b/Source/Sdk4me/Entities/ServiceLevelAgreementServiceInstanceRelation.cs @@ -0,0 +1,73 @@ +using Newtonsoft.Json; +using System; + +namespace Sdk4me +{ + /// + /// A 4me service instance relation object. + /// + public class ServiceLevelAgreementServiceInstanceRelation : BaseItem + { + private ServiceLevelAgreementServiceInstanceRelationStatus impactRelation; + private ServiceInstance serviceInstance; + + #region Created at (override) + + /// + /// The creation date and time; which is obsolete for this object. + /// + [JsonProperty("created_at"), Sdk4meIgnoreInFieldSelection()] + public override DateTime? CreatedAt + { + get => base.CreatedAt; + internal set => base.CreatedAt = null; + } + + #endregion + + #region Impact relation + + /// + /// The type of the relation. + /// + [JsonProperty("impact_relation"), Sdk4meIgnoreInFieldSelection()] + public ServiceLevelAgreementServiceInstanceRelationStatus ImpactRelation + { + get => impactRelation; + set => impactRelation = SetValue("impact_relation", impactRelation, value); + } + + #endregion + + #region Service instance + + /// + /// The linked service instance. + /// + [JsonProperty("service_instance"), Sdk4meIgnoreInFieldSelection()] + public ServiceInstance ServiceInstance + { + get => serviceInstance; + set => serviceInstance = SetValue("service_instance_id", serviceInstance, value); + } + + [JsonProperty("service_instance_id"), Sdk4meIgnoreInFieldSelection()] + internal long? ServiceInstanceID => serviceInstance?.ID; + + #endregion + + #region Updated at (override) + + /// + /// The updated date and time; which is obsolete for this object. + /// + [JsonProperty("updated_at"), Sdk4meIgnoreInFieldSelection()] + public override DateTime? UpdatedAt + { + get => base.UpdatedAt; + internal set => base.UpdatedAt = null; + } + + #endregion + } +} diff --git a/Source/Sdk4me/Enumerators/Enumerators.cs b/Source/Sdk4me/Enumerators/Enumerators.cs index 993c67d..3114332 100644 --- a/Source/Sdk4me/Enumerators/Enumerators.cs +++ b/Source/Sdk4me/Enumerators/Enumerators.cs @@ -2202,6 +2202,23 @@ public enum ServiceLevelAgreementStatus Expired } + /// + /// A 4me service level agreement - service level relation status. + /// + public enum ServiceLevelAgreementServiceInstanceRelationStatus + { + /// + /// Service Instance of SLA is Down or Degraded. + /// + [EnumMember(Value = "degraded")] + Degraded = 1, + /// + /// Service Instance of SLA is Down. + /// + [EnumMember(Value = "down")] + Down + } + #endregion #region Service offering diff --git a/Source/Sdk4me/Handlers/ServiceLevelAgreementHandler.cs b/Source/Sdk4me/Handlers/ServiceLevelAgreementHandler.cs index f042f57..5f3d43e 100644 --- a/Source/Sdk4me/Handlers/ServiceLevelAgreementHandler.cs +++ b/Source/Sdk4me/Handlers/ServiceLevelAgreementHandler.cs @@ -201,6 +201,64 @@ public bool RemoveAllPeople(ServiceLevelAgreement serviceLevelAgreement) #endregion + #region service instances + + /// + /// Get all parent service instances of a service level agreement. + /// + /// The service level agreement. + /// The field names to return. + /// A collection of people. + public List GetServiceInstances(ServiceLevelAgreement serviceLevelAgreement, params string[] fieldNames) + { + return GetChildHandler(serviceLevelAgreement, "service_instances").Get(fieldNames); + } + + /// + /// Add a service instance relation. + /// + /// The service level agreement. + /// The service instance relation. + /// True in case of success; otherwise false. + public ServiceLevelAgreementServiceInstanceRelation AddServiceInstance(ServiceLevelAgreement serviceLevelAgreement, ServiceLevelAgreementServiceInstanceRelation serviceLevelAgreementServiceInstanceRelation) + { + return GetChildHandler(serviceLevelAgreement, "service_instances").Insert(serviceLevelAgreementServiceInstanceRelation); + } + + /// + /// Update a service instance relation. + /// + /// The service level agreement. + /// The service instance relation. + /// True in case of success; otherwise false. + public ServiceLevelAgreementServiceInstanceRelation UpdateServiceInstance(ServiceLevelAgreement serviceLevelAgreement, ServiceLevelAgreementServiceInstanceRelation serviceLevelAgreementServiceInstanceRelation) + { + return GetChildHandler(serviceLevelAgreement, "service_instances").Update(serviceLevelAgreementServiceInstanceRelation); + } + + /// + /// Delete a service instance relation. + /// + /// The service level agreement. + /// The service instance relation. + /// True in case of success; otherwise false. + public bool DeleteServiceInstance(ServiceLevelAgreement serviceLevelAgreement, ServiceLevelAgreementServiceInstanceRelation serviceLevelAgreementServiceInstanceRelation) + { + return GetChildHandler(serviceLevelAgreement, "service_instances").Delete(serviceLevelAgreementServiceInstanceRelation); + } + + /// + /// Delete all service instance relations. + /// + /// The service level agreement. + /// True in case of success; otherwise false. + public bool DeleteServiceInstances(ServiceLevelAgreement serviceLevelAgreement) + { + return GetChildHandler(serviceLevelAgreement, "service_instances").DeleteAll(); + } + + #endregion + #region Sites /// diff --git a/Source/Sdk4me/Sdk4me.csproj b/Source/Sdk4me/Sdk4me.csproj index df78984..c15f4eb 100644 --- a/Source/Sdk4me/Sdk4me.csproj +++ b/Source/Sdk4me/Sdk4me.csproj @@ -22,13 +22,13 @@ 7.3 - 2.0.6 - 2.0.6 + 2.0.7 + 2.0.7 6.0 Klaas Vandeweerdt A .NET client for accessing the 4me v1 REST API MIT License - 2.0.6 + 2.0.7 True git LogoDark128x218.png @@ -39,6 +39,7 @@ MIT True False + Sdk4me