-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Land Subscriptions Application Services (Use cases)
- Loading branch information
Showing
5 changed files
with
331 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* Empiria Land ********************************************************************************************** | ||
* * | ||
* Module : Land Messaging services Component : Subscription services * | ||
* Assembly : Empiria.Land.Registration.dll Pattern : Data Services * | ||
* Type : MessagingData License : Please read LICENSE.txt file * | ||
* * | ||
* Summary : Read and write methods for land system messaging components. * | ||
* * | ||
************************* Copyright(c) La Vía Óntica SC, Ontica LLC and contributors. All rights reserved. **/ | ||
using System; | ||
|
||
using Empiria.Data; | ||
|
||
namespace Empiria.Land.Messaging { | ||
|
||
/// <summary>Read and write methods for land system messaging components.</summary> | ||
static internal class MessagingData { | ||
|
||
#region Internal methods | ||
|
||
static internal void WriteSubscription(Subscription o) { | ||
var op = DataOperation.Parse("writeLRSPosting", o.Id, o.UID, | ||
o.SubscriptionType.ToString(), o.SubscribedObjectUID, | ||
o.SendTo.ToString(), String.Empty, | ||
o.PostingTime, -1, (char) o.Status); | ||
|
||
DataWriter.Execute(op); | ||
} | ||
|
||
|
||
#endregion Internal methods | ||
|
||
} // class MessagingData | ||
|
||
} // namespace Empiria.Land.Data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* Empiria Land ********************************************************************************************** | ||
* * | ||
* Module : Land Messaging services Component : Application Services * | ||
* Assembly : Empiria.Land.Registration.dll Pattern : Interface adapter * | ||
* Type : SubscriptionRequest License : Please read LICENSE.txt file * | ||
* * | ||
* Summary : Describes a subscription request used to subscribe, unsubscribe or confirm subscriptions. * | ||
* * | ||
************************* Copyright(c) La Vía Óntica SC, Ontica LLC and contributors. All rights reserved. **/ | ||
using System; | ||
|
||
using Empiria.Json; | ||
using Empiria.Messaging; | ||
|
||
namespace Empiria.Land.Messaging { | ||
|
||
/// <summary>Describes a subscription request used to subscribe, | ||
/// unsubscribe or confirm subscriptions.</summary> | ||
public class SubscriptionRequest { | ||
|
||
#region Constructors and parsers | ||
|
||
private SubscriptionRequest(JsonObject json) { | ||
this.LoadData(json); | ||
} | ||
|
||
|
||
static public SubscriptionRequest Parse(JsonObject json) { | ||
EnsureIsValid(json); | ||
|
||
return new SubscriptionRequest(json); | ||
} | ||
|
||
|
||
static public void EnsureIsValid(JsonObject json) { | ||
Assertion.AssertObject(json, "json"); | ||
|
||
Assertion.Assert(json.HasValue("command"), | ||
"Subscription request must have a 'command' value."); | ||
|
||
Assertion.Assert(json.HasValue("subscriptionType"), | ||
"Subscription request must have a 'subscriptionType' value."); | ||
|
||
Assertion.Assert(json.HasValue("subscribedObjectUID"), | ||
"Subscription request must have a 'subscribedObjectUID' that refers to a resource, " + | ||
"certificate or recording document."); | ||
|
||
Assertion.Assert(json.HasValue("sendTo"), | ||
"Subscription request must have a 'sendTo' value."); | ||
|
||
} | ||
|
||
#endregion Constructors and parsers | ||
|
||
|
||
#region Properties | ||
|
||
|
||
public SubscriptionRequestCommand Command { | ||
get; | ||
private set; | ||
} | ||
|
||
|
||
|
||
public SubscriptionType SubscriptionType { | ||
get; | ||
private set; | ||
} | ||
|
||
|
||
public string SubscribedObjectUID { | ||
get; | ||
private set; | ||
} = String.Empty; | ||
|
||
|
||
public SendTo SendTo { | ||
get; | ||
private set; | ||
} | ||
|
||
|
||
public string HashCode { | ||
get; | ||
private set; | ||
} = String.Empty; | ||
|
||
|
||
#endregion Properties | ||
|
||
#region Methods | ||
|
||
private void LoadData(JsonObject json) { | ||
this.Command = json.Get<SubscriptionRequestCommand>("command"); | ||
this.SubscriptionType = json.Get<SubscriptionType>("subscriptionType"); | ||
this.SubscribedObjectUID = json.Get<string>("subscribedObjectUID"); | ||
this.SendTo = SendTo.Parse(json.Slice("sendTo")); | ||
this.HashCode = json.Get<string>("hashCode", String.Empty); | ||
} | ||
|
||
#endregion Methods | ||
|
||
} // class SubscriptionRequest | ||
|
||
} // namespace Empiria.Land.Messaging |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* Empiria Land ********************************************************************************************** | ||
* * | ||
* Module : Land Messaging services Component : Application Services * | ||
* Assembly : Empiria.Land.Registration.dll Pattern : Enumeration type * | ||
* Type : SubscriptionRequestCommand License : Please read LICENSE.txt file * | ||
* * | ||
* Summary : Describes a SubscriptionRequest command. * | ||
* * | ||
************************* Copyright(c) La Vía Óntica SC, Ontica LLC and contributors. All rights reserved. **/ | ||
using System; | ||
|
||
namespace Empiria.Land.Messaging { | ||
|
||
/// <summary>Describes a SubscriptionRequest command.</summary> | ||
public enum SubscriptionRequestCommand { | ||
|
||
Subscribe, | ||
|
||
ConfirmSubscription, | ||
|
||
Unsubscribe | ||
|
||
} // SubscriptionRequestCommand | ||
|
||
} // namespace Empiria.Land.Messaging |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
/* Empiria Land ********************************************************************************************** | ||
* * | ||
* Module : Land Messaging services Component : Application Services * | ||
* Assembly : Empiria.Land.Registration.dll Pattern : Service * | ||
* Type : SubscriptionServices License : Please read LICENSE.txt file * | ||
* * | ||
* Summary : Application services to subscribe and unsubscribe for resource and document changes. * | ||
* * | ||
************************* Copyright(c) La Vía Óntica SC, Ontica LLC and contributors. All rights reserved. **/ | ||
using System; | ||
|
||
namespace Empiria.Land.Messaging { | ||
|
||
/// <summary>Application services to subscribe and unsubscribe for resource and document changes.</summary> | ||
static public class SubscriptionServices { | ||
|
||
#region Services | ||
|
||
|
||
static public Subscription ConfirmSubscription(SubscriptionRequest request) { | ||
EnsureIsValid(request); | ||
|
||
throw new NotImplementedException(); | ||
} | ||
|
||
|
||
static public Subscription Subscribe(SubscriptionRequest request) { | ||
EnsureIsValid(request); | ||
|
||
if (ExistsSubscription(request)) { | ||
throw new ResourceConflictException("Land.Subscription.AlreadyExists", | ||
$"El correo electrónico {0} ya está registrado para recibir avisos registrales " + | ||
"sobre este recurso."); | ||
} | ||
|
||
var subscription = new Subscription(request.SubscriptionType, request.SubscribedObjectUID, request.SendTo); | ||
|
||
subscription.Save(); | ||
|
||
LandMessenger.Notify(GetSubscriptionEventType(request), subscription); | ||
|
||
return subscription; | ||
} | ||
|
||
|
||
static public Subscription Unsubscribe(string subscriptionUID, SubscriptionRequest request) { | ||
EnsureIsValid(request); | ||
|
||
var subscription = Subscription.TryParse(subscriptionUID); | ||
|
||
if (subscription == null) { | ||
throw new ResourceConflictException("Land.Subscription.NotFound", | ||
$"No tenemos registrada una subscripción a los servicios de alerta registral " + | ||
$"con identificador {subscriptionUID}."); | ||
} | ||
|
||
subscription.Unsubscribe(); | ||
|
||
subscription.Save(); | ||
|
||
LandMessenger.Notify(GetSubscriptionEventType(request), subscription); | ||
|
||
return subscription; | ||
} | ||
|
||
|
||
#endregion Services | ||
|
||
#region Private methods | ||
|
||
|
||
static private void EnsureIsValid(SubscriptionRequest request) { | ||
|
||
} | ||
|
||
|
||
static private void EnsureNoRegistered() { | ||
|
||
} | ||
|
||
|
||
static private bool ExistsSubscription(SubscriptionRequest subscriptionRequest) { | ||
return false; | ||
} | ||
|
||
|
||
private static SubscriptionEventType GetSubscriptionEventType(SubscriptionRequest request) { | ||
SubscriptionRequestCommand command = request.Command; | ||
SubscriptionType type = request.SubscriptionType; | ||
|
||
if (command == SubscriptionRequestCommand.Subscribe) { | ||
|
||
switch (type) { | ||
case SubscriptionType.CertificateChangesSubscription: | ||
return SubscriptionEventType.SubscribedForCertificateChanges; | ||
|
||
case SubscriptionType.RecordingDocumentChangesSubscription: | ||
return SubscriptionEventType.SubscribedForRecordingDocumentChanges; | ||
|
||
case SubscriptionType.ResourceChangesSubscription: | ||
return SubscriptionEventType.SubscribedForResourceChanges; | ||
} | ||
|
||
} else if (command == SubscriptionRequestCommand.ConfirmSubscription) { | ||
|
||
switch (type) { | ||
case SubscriptionType.CertificateChangesSubscription: | ||
return SubscriptionEventType.ConfirmedForCertificateChanges; | ||
|
||
case SubscriptionType.RecordingDocumentChangesSubscription: | ||
return SubscriptionEventType.ConfirmedForRecordingDocumentChanges; | ||
|
||
case SubscriptionType.ResourceChangesSubscription: | ||
return SubscriptionEventType.ConfirmedForResourceChanges; | ||
} | ||
|
||
} else if (command == SubscriptionRequestCommand.Unsubscribe) { | ||
|
||
switch (type) { | ||
case SubscriptionType.CertificateChangesSubscription: | ||
return SubscriptionEventType.UnsubscribedForCertificateChanges; | ||
|
||
case SubscriptionType.RecordingDocumentChangesSubscription: | ||
return SubscriptionEventType.UnsubscribedForRecordingDocumentChanges; | ||
|
||
case SubscriptionType.ResourceChangesSubscription: | ||
return SubscriptionEventType.UnsubscribedForResourceChanges; | ||
} | ||
|
||
} // else if | ||
|
||
throw Assertion.AssertNoReachThisCode(); | ||
} | ||
|
||
#endregion Private methods | ||
|
||
} // class SubscriptionServices | ||
|
||
} // namespace Empiria.Land.Messaging |