Skip to content

Commit

Permalink
working on functionality to associate places correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
Nityan Khanna committed Nov 24, 2017
1 parent a261085 commit dc83820
Show file tree
Hide file tree
Showing 25 changed files with 1,106 additions and 111 deletions.
2 changes: 1 addition & 1 deletion OpenIZAdmin.Core/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.9.12.2")]
[assembly: AssemblyVersion("0.9.12.3")]
[assembly: AssemblyFileVersion("1.0.0.0")]
36 changes: 36 additions & 0 deletions OpenIZAdmin.Localization/Locale.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions OpenIZAdmin.Localization/Locale.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2532,4 +2532,16 @@
<data name="NoAreasServed" xml:space="preserve">
<value>No Areas Served</value>
</data>
<data name="AssociateChildPlace" xml:space="preserve">
<value>Associate Child Place</value>
</data>
<data name="AssociateParentPlace" xml:space="preserve">
<value>Associate Parent Place</value>
</data>
<data name="AssociateAreaServed" xml:space="preserve">
<value>Associate Area Served</value>
</data>
<data name="AssociateDedicatedServiceDeliveryLocation" xml:space="preserve">
<value>Associate Dedicated Service Delivery Location</value>
</data>
</root>
12 changes: 12 additions & 0 deletions OpenIZAdmin.Localization/Locale.sw.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2555,4 +2555,16 @@ au jina la kikoa</value>
<data name="NoAreasServed" xml:space="preserve">
<value>Hakuna Maeneo Iliyotumiwa</value>
</data>
<data name="AssociateChildPlace" xml:space="preserve">
<value>Shirikisha Mahali ya Mtoto</value>
</data>
<data name="AssociateParentPlace" xml:space="preserve">
<value>Weka Mahali ya Mzazi</value>
</data>
<data name="AssociateAreaServed" xml:space="preserve">
<value>Eneo la Washiriki Linatumiwa</value>
</data>
<data name="AssociateDedicatedServiceDeliveryLocation" xml:space="preserve">
<value>Eneo la Utoaji wa Utumishi wa Kujitolea</value>
</data>
</root>
2 changes: 1 addition & 1 deletion OpenIZAdmin.Localization/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.9.12.2")]
[assembly: AssemblyVersion("0.9.12.3")]
[assembly: AssemblyFileVersion("1.0.0.0")]
175 changes: 156 additions & 19 deletions OpenIZAdmin.Services/Entities/EntityService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -520,66 +520,203 @@ public Entity Obsolete(Entity entity)
/// <param name="searchTerm">The search term.</param>
/// <returns>Returns a list of entities which match the given search term.</returns>
public IEnumerable<T> Search<T>(string searchTerm) where T : Entity
{
return this.Search<T>(searchTerm, null, null);
}

/// <summary>
/// Searches for a specific entity by search term.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="searchTerm">The search term.</param>
/// <param name="expandProperties">The expand properties.</param>
/// <returns>Returns a list of entities which match the given search term.</returns>
public IEnumerable<T> Search<T>(string searchTerm, string[] expandProperties) where T : Entity
{
return this.Search<T>(searchTerm, null, expandProperties);
}

/// <summary>
/// Searches the specified search term.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="searchTerm">The search term.</param>
/// <param name="classConceptFilterKey">The class concept filter key.</param>
/// <param name="expandProperties">The expand properties.</param>
/// <param name="invertClassConceptFilterCheck">if set to <c>true</c> [invert class concept filter check].</param>
/// <returns>Returns a list of entities which match the given search term and class concept key filter.</returns>
public IEnumerable<T> Search<T>(string searchTerm, Guid classConceptFilterKey, string[] expandProperties, bool invertClassConceptFilterCheck = false) where T : Entity
{
var results = new List<T>();

try
{
Guid classConceptKey;
Expression<Func<T, bool>> nameExpression = p => p.Names.Any(n => n.Component.Any(c => c.Value.Contains(searchTerm, StringComparison.OrdinalIgnoreCase)));

if (typeof(T) == typeof(ManufacturedMaterial))
{
classConceptKey = EntityClassKeys.ManufacturedMaterial;
}
else if (typeof(T) == typeof(Material))
Expression<Func<T, bool>> queryExpression = p => p.Names.Any(n => n.Component.Any(c => c.Value.Contains(searchTerm))) && p.ClassConceptKey == classConceptFilterKey;

if (invertClassConceptFilterCheck)
{
classConceptKey = EntityClassKeys.Material;
queryExpression = p => p.Names.Any(n => n.Component.Any(c => c.Value.Contains(searchTerm))) && p.ClassConceptKey != classConceptFilterKey;
}
else if (typeof(T) == typeof(Organization))

var bundle = this.Client.Query<T>(queryExpression, 0, null, expandProperties);

foreach (var item in bundle.Item.OfType<T>().LatestVersionOnly().Where(queryExpression.Compile()))
{
classConceptKey = EntityClassKeys.Organization;
item.TypeConcept = this.conceptService.GetTypeConcept(item);
}
else if (typeof(T) == typeof(Place))

results = bundle.Item.OfType<T>().Where(nameExpression.Compile()).LatestVersionOnly().ToList();

this.entityAuditService.AuditQueryEntity(OutcomeIndicator.Success, results);
}
catch (Exception e)
{
coreAuditService.AuditGenericError(OutcomeIndicator.EpicFail, this.entityAuditService.QueryEntityAuditCode, EventIdentifierType.ApplicationActivity, e);
throw;
}
return results;
}

/// <summary>
/// Searches for a specific entity by search term.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="searchTerm">The search term.</param>
/// <param name="type">The type.</param>
/// <param name="expandProperties">The expand properties.</param>
/// <returns>Returns a list of entities which match the given search term.</returns>
/// <exception cref="System.ArgumentException"></exception>
public IEnumerable<T> Search<T>(string searchTerm, string type, string[] expandProperties) where T : Entity
{
var results = new List<T>();

// if the list of properties to expand is null or empty, force set it to null
if (expandProperties == null || !expandProperties.Any())
{
expandProperties = null;
}

try
{
var classConceptKey = Guid.Empty;

if (typeof(T) == typeof(ManufacturedMaterial))
{
classConceptKey = EntityClassKeys.Place;
classConceptKey = EntityClassKeys.ManufacturedMaterial;
}
else
else if (typeof(T) == typeof(Material))
{
throw new ArgumentException($"Unsupported search type: {typeof(T).Name}");
classConceptKey = EntityClassKeys.Material;
}

var typeConceptKey = Guid.Empty;

Bundle bundle;

// set the default name expression
Expression<Func<T, bool>> nameExpression = p => p.Names.Any(n => n.Component.Any(c => c.Value.Contains(searchTerm, StringComparison.OrdinalIgnoreCase)));

// if the search term is "*", we treat it as a wildcard search
if (searchTerm == "*")
{
bundle = this.Client.Query<T>(p => p.ClassConceptKey == classConceptKey, 0, null, false);
// set the default query expression to query on obsoletion time
Expression<Func<T, bool>> queryExpression = p => p.ObsoletionTime == null;

if (!Guid.TryParse(type, out typeConceptKey))
{
// if the class concept is a material, make sure we filter on material
if (classConceptKey == EntityClassKeys.Material)
{
queryExpression = p => p.ClassConceptKey == EntityClassKeys.Material && p.ObsoletionTime == null;
}
// if the class concept is a manufactured material, make sure we filter on manufactured material
else if (classConceptKey == EntityClassKeys.ManufacturedMaterial)
{
queryExpression = p => p.ClassConceptKey == EntityClassKeys.ManufacturedMaterial && p.ObsoletionTime == null;
}

foreach (var item in bundle.Item.OfType<T>().LatestVersionOnly().Where(p => p.ClassConceptKey == classConceptKey))
bundle = this.Client.Query(queryExpression, 0, null, expandProperties);
}
else
{
queryExpression = p => p.ObsoletionTime == null && p.TypeConceptKey == typeConceptKey;

// if the class concept is a material, make sure we filter on material
if (classConceptKey == EntityClassKeys.Material)
{
queryExpression = p => p.ClassConceptKey == EntityClassKeys.Material && p.ObsoletionTime == null && p.TypeConceptKey == typeConceptKey;
}
// if the class concept is a manufactured material, make sure we filter on manufactured material
else if (classConceptKey == EntityClassKeys.ManufacturedMaterial)
{
queryExpression = p => p.ClassConceptKey == EntityClassKeys.ManufacturedMaterial && p.ObsoletionTime == null && p.TypeConceptKey == typeConceptKey;
}

bundle = this.Client.Query(queryExpression, 0, null, expandProperties);
}

foreach (var item in bundle.Item.OfType<T>().LatestVersionOnly().Where(queryExpression.Compile()))
{
item.TypeConcept = this.conceptService.GetTypeConcept(item);
}

results = bundle.Item.OfType<T>().LatestVersionOnly().Where(p => p.ClassConceptKey == classConceptKey).ToList();
results = bundle.Item.OfType<T>().LatestVersionOnly().Where(queryExpression.Compile()).ToList();
}
else
{
Guid id;

// if the search term entered is not a valid GUID
if (!Guid.TryParse(searchTerm, out id))
{
bundle = this.Client.Query<T>(p => p.Names.Any(n => n.Component.Any(c => c.Value.Contains(searchTerm))) && p.ClassConceptKey == classConceptKey, 0, null, false);
Expression<Func<T, bool>> queryExpression = p => p.Names.Any(n => n.Component.Any(c => c.Value.Contains(searchTerm)));

if (!Guid.TryParse(type, out typeConceptKey))
{
// if the class concept is a material, make sure we filter on material
if (classConceptKey == EntityClassKeys.Material)
{
queryExpression = p => p.ClassConceptKey == EntityClassKeys.Material && p.ObsoletionTime == null;
}
// if the class concept is a manufactured material, make sure we filter on manufactured material
else if (classConceptKey == EntityClassKeys.ManufacturedMaterial)
{
queryExpression = p => p.ClassConceptKey == EntityClassKeys.ManufacturedMaterial && p.ObsoletionTime == null;
}

bundle = this.Client.Query(queryExpression, 0, null, expandProperties);
}
else
{
queryExpression = p => p.Names.Any(n => n.Component.Any(c => c.Value.Contains(searchTerm))) && p.TypeConceptKey == typeConceptKey;

// if the class concept is a material, make sure we filter on material
if (classConceptKey == EntityClassKeys.Material)
{
queryExpression = p => p.Names.Any(n => n.Component.Any(c => c.Value.Contains(searchTerm))) && p.ClassConceptKey == EntityClassKeys.Material && p.ObsoletionTime == null && p.TypeConceptKey == typeConceptKey;
}
// if the class concept is a manufactured material, make sure we filter on manufactured material
else if (classConceptKey == EntityClassKeys.ManufacturedMaterial)
{
queryExpression = p => p.Names.Any(n => n.Component.Any(c => c.Value.Contains(searchTerm))) && p.ClassConceptKey == EntityClassKeys.ManufacturedMaterial && p.ObsoletionTime == null && p.TypeConceptKey == typeConceptKey;
}

bundle = this.Client.Query<T>(queryExpression, 0, null, expandProperties);
}

foreach (var item in bundle.Item.OfType<T>().LatestVersionOnly().Where(p => p.ClassConceptKey == classConceptKey))
foreach (var item in bundle.Item.OfType<T>().LatestVersionOnly().Where(p => p.TypeConcept == null && p.TypeConceptKey.HasValue))
{
item.TypeConcept = this.conceptService.GetTypeConcept(item);
}

results = bundle.Item.OfType<T>().Where(nameExpression.Compile()).LatestVersionOnly().Where(p => p.ClassConceptKey == classConceptKey).ToList();
results = bundle.Item.OfType<T>().Where(nameExpression.Compile()).LatestVersionOnly().ToList();
}
// if the search term entered is a valid GUID
else
{
// attempt to retrieve the entity by it's GUID
var entity = this.Get<T>(id);

if (entity != null)
Expand Down
31 changes: 31 additions & 0 deletions OpenIZAdmin.Services/Entities/IEntityService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

using OpenIZ.Core.Model.Entities;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq.Expressions;

Expand Down Expand Up @@ -155,6 +156,36 @@ public interface IEntityService
/// <returns>Returns a list of entities which match the given search term.</returns>
IEnumerable<T> Search<T>(string searchTerm) where T : Entity;

/// <summary>
/// Searches for a specific entity by search term.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="searchTerm">The search term.</param>
/// <param name="expandProperties">The expand properties.</param>
/// <returns>Returns a list of entities which match the given search term.</returns>
IEnumerable<T> Search<T>(string searchTerm, string[] expandProperties) where T : Entity;

/// <summary>
/// Searches the specified search term.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="searchTerm">The search term.</param>
/// <param name="classConceptFilterKey">The class concept filter key.</param>
/// <param name="expandProperties">The expand properties.</param>
/// <param name="invertClassConceptFilterCheck">if set to <c>true</c> [invert class concept filter check].</param>
/// <returns>Returns a list of entities which match the given search term and class concept key filter.</returns>
IEnumerable<T> Search<T>(string searchTerm, Guid classConceptFilterKey, string[] expandProperties, bool invertClassConceptFilterCheck = false) where T : Entity;

/// <summary>
/// Searches for a specific entity by search term.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="searchTerm">The search term.</param>
/// <param name="type">The type.</param>
/// <param name="expandProperties">The expand properties.</param>
/// <returns>Returns a list of entities which match the given search term.</returns>
IEnumerable<T> Search<T>(string searchTerm, string type, string[] expandProperties) where T : Entity;

/// <summary>
/// Updates the specified entity.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion OpenIZAdmin.Services/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.9.12.2")]
[assembly: AssemblyVersion("0.9.12.3")]
[assembly: AssemblyFileVersion("1.0.0.0")]
2 changes: 1 addition & 1 deletion OpenIZAdmin.Tests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("0.9.12.2")]
[assembly: AssemblyVersion("0.9.12.3")]
[assembly: AssemblyFileVersion("1.0.0.0")]
1 change: 1 addition & 0 deletions OpenIZAdmin/App_Start/BundleConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public static void RegisterBundles(BundleCollection bundles)
"~/Scripts/manufactured-material-search.js",
"~/Scripts/place-search.js",
"~/Scripts/address-search.js",
"~/Scripts/dedicated-service-delivery-location-search.js",
"~/Scripts/user-search.js"));

bundles.Add(new ScriptBundle("~/bundles/ui-customizations").Include(
Expand Down
Loading

0 comments on commit dc83820

Please sign in to comment.