Skip to content

Commit

Permalink
OIZ-58 implemented dataset mapping functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Nityan Khanna committed May 7, 2018
1 parent 42fa653 commit bfcf14c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
37 changes: 31 additions & 6 deletions OpenIZAdmin.Services/Dataset/DatasetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
using OpenIZ.Core.Model;
using OpenIZ.Core.Model.Entities;

namespace OpenIZAdmin.Services.Dataset
Expand All @@ -34,15 +35,14 @@ namespace OpenIZAdmin.Services.Dataset
public class DatasetService : IDatasetService
{
/// <summary>
/// Converts an entity or derived entity to a dataset instance.
/// Converts an identified data instance to a dataset instance.
/// </summary>
/// <typeparam name="T">The type of instance to convert to a dataset.</typeparam>
/// <param name="instance">The instance.</param>
/// <returns>Returns the dataset.</returns>
/// <exception cref="NotImplementedException"></exception>
public DatasetInstall ConvertToDataset<T>(T instance) where T : Entity
public DatasetInstall ConvertToDataset<T>(T instance) where T : IdentifiedData
{
throw new NotImplementedException();
return ConvertToDatasetInternal(instance, typeof(T));
}

/// <summary>
Expand All @@ -51,10 +51,35 @@ public class DatasetService : IDatasetService
/// <param name="instance">The instance.</param>
/// <param name="type">The type.</param>
/// <returns>Returns the dataset.</returns>
/// <exception cref="NotImplementedException"></exception>
public DatasetInstall ConvertToDataset(object instance, Type type)
{
throw new NotImplementedException();
return ConvertToDatasetInternal(instance, type);
}

/// <summary>
/// Converts an entity or derived entity to a dataset instance.
/// </summary>
/// <param name="instance">The instance.</param>
/// <param name="type">The type.</param>
/// <returns>Returns the dataset.</returns>
/// <exception cref="ArgumentException">Thrown if the type does not inherit from <see cref="IdentifiedData"/>.</exception>
private DatasetInstall ConvertToDatasetInternal(object instance, Type type)
{
if (type != typeof(IdentifiedData))
{
throw new ArgumentException($"The type {type} must be a derived type of {typeof(IdentifiedData)}");
}

var datasetInstall = new DatasetInstall(Guid.NewGuid().ToString());

datasetInstall.Action.Add(new DataUpdate
{
InsertIfNotExists = true,
Element = (IdentifiedData)instance,
IgnoreErrors = false
});

return datasetInstall;
}

/// <summary>
Expand Down
5 changes: 3 additions & 2 deletions OpenIZAdmin.Services/Dataset/IDatasetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenIZ.Core.Model;
using OpenIZ.Core.Model.Entities;

namespace OpenIZAdmin.Services.Dataset
Expand All @@ -31,12 +32,12 @@ namespace OpenIZAdmin.Services.Dataset
public interface IDatasetService
{
/// <summary>
/// Converts an entity or derived entity to a dataset instance.
/// Converts an identified data instance to a dataset instance.
/// </summary>
/// <typeparam name="T">The type of instance to convert to a dataset.</typeparam>
/// <param name="instance">The instance.</param>
/// <returns>Returns the dataset.</returns>
DatasetInstall ConvertToDataset<T>(T instance) where T : Entity;
DatasetInstall ConvertToDataset<T>(T instance) where T : IdentifiedData;

/// <summary>
/// Converts an entity or derived entity to a dataset instance.
Expand Down

0 comments on commit bfcf14c

Please sign in to comment.