Skip to content

Commit a8cbeb3

Browse files
committed
Merge pull request #7 from nsip/develop
Merge develop into master
2 parents 26299b1 + b1c387b commit a8cbeb3

30 files changed

Lines changed: 496 additions & 42 deletions

File tree

Code/Sif3Framework/Sif.Framework.EnvironmentProvider/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@
3131
//
3232
// You can specify all the values or you can default the Revision and Build Numbers
3333
// by using the '*' as shown below:
34-
[assembly: AssemblyVersion("0.21.0.0")]
35-
[assembly: AssemblyFileVersion("0.21.0.0")]
34+
[assembly: AssemblyVersion("0.22.0.0")]
35+
[assembly: AssemblyFileVersion("0.22.0.0")]

Code/Sif3Framework/Sif.Framework.Tests/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("0.21.0.0")]
36-
[assembly: AssemblyFileVersion("0.21.0.0")]
35+
[assembly: AssemblyVersion("0.22.0.0")]
36+
[assembly: AssemblyFileVersion("0.22.0.0")]

Code/Sif3Framework/Sif.Framework/Consumer/GenericConsumer.cs

Lines changed: 57 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@
1616

1717
using log4net;
1818
using Sif.Framework.Model.Persistence;
19+
using Sif.Framework.Model.Query;
1920
using Sif.Framework.Service.Registration;
2021
using Sif.Framework.Service.Serialisation;
2122
using Sif.Framework.Utils;
2223
using System;
2324
using System.Collections.Generic;
2425
using System.Reflection;
26+
using System.Text;
2527
using System.Xml.Serialization;
2628
using Environment = Sif.Framework.Model.Infrastructure.Environment;
2729

@@ -156,35 +158,18 @@ public virtual void Create(IEnumerable<T> objs)
156158
}
157159

158160
/// <summary>
159-
/// <see cref="Sif.Framework.Consumer.IGenericConsumer{T,PK}.Retrieve(PK)">Retrieve</see>
161+
///
160162
/// </summary>
161-
public virtual T Retrieve(PK id)
163+
/// <param name="url"></param>
164+
/// <returns></returns>
165+
private ICollection<T> PagingRetrieve(string url)
162166
{
163167

164168
if (!registrationService.Registered)
165169
{
166170
throw new InvalidOperationException("Consumer has not registered.");
167171
}
168172

169-
string url = EnvironmentUtils.ParseServiceUrl(environmentTemplate) + "/" + TypeName + "s" + "/" + id;
170-
string xml = HttpUtils.GetRequest(url, registrationService.AuthorisationToken);
171-
if (log.IsDebugEnabled) log.Debug("XML from GET request ...");
172-
if (log.IsDebugEnabled) log.Debug(xml);
173-
return ObjectSerialiser.Deserialise(xml);
174-
}
175-
176-
/// <summary>
177-
/// <see cref="Sif.Framework.Consumer.IGenericConsumer{T,PK}.Retrieve()">Retrieve</see>
178-
/// </summary>
179-
public virtual ICollection<T> Retrieve()
180-
{
181-
182-
if (!registrationService.Registered)
183-
{
184-
throw new InvalidOperationException("Consumer has not registered.");
185-
}
186-
187-
string url = EnvironmentUtils.ParseServiceUrl(environmentTemplate) + "/" + TypeName + "s";
188173
List<T> result = new List<T>();
189174
int pageIndex = 0;
190175
int pageResultCount = 0;
@@ -217,6 +202,34 @@ public virtual ICollection<T> Retrieve()
217202
return result;
218203
}
219204

205+
/// <summary>
206+
/// <see cref="Sif.Framework.Consumer.IGenericConsumer{T,PK}.Retrieve(PK)">Retrieve</see>
207+
/// </summary>
208+
public virtual T Retrieve(PK id)
209+
{
210+
211+
if (!registrationService.Registered)
212+
{
213+
throw new InvalidOperationException("Consumer has not registered.");
214+
}
215+
216+
string url = EnvironmentUtils.ParseServiceUrl(environmentTemplate) + "/" + TypeName + "s" + "/" + id;
217+
string xml = HttpUtils.GetRequest(url, registrationService.AuthorisationToken);
218+
if (log.IsDebugEnabled) log.Debug("XML from GET request ...");
219+
if (log.IsDebugEnabled) log.Debug(xml);
220+
return ObjectSerialiser.Deserialise(xml);
221+
}
222+
223+
/// <summary>
224+
/// <see cref="Sif.Framework.Consumer.IGenericConsumer{T,PK}.Retrieve()">Retrieve</see>
225+
/// </summary>
226+
public virtual ICollection<T> Retrieve()
227+
{
228+
string url = EnvironmentUtils.ParseServiceUrl(environmentTemplate) + "/" + TypeName + "s";
229+
230+
return PagingRetrieve(url);
231+
}
232+
220233
/// <summary>
221234
/// <see cref="Sif.Framework.Consumer.IGenericConsumer{T,PK}.Retrieve(T)">Retrieve</see>
222235
/// </summary>
@@ -237,6 +250,29 @@ public virtual ICollection<T> Retrieve(T obj)
237250
return ListSerialiser.Deserialise(xml);
238251
}
239252

253+
/// <summary>
254+
/// <see cref="Sif.Framework.Consumer.IGenericConsumer{T,PK}.Retrieve(System.Collections.Generic.IEnumerable<Sif.Framework.Model.Query.EqualCondition>)">Retrieve</see>
255+
/// </summary>
256+
public virtual ICollection<T> Retrieve(IEnumerable<EqualCondition> conditions)
257+
{
258+
StringBuilder servicePath = new StringBuilder();
259+
260+
if (conditions != null)
261+
{
262+
263+
foreach (EqualCondition condition in conditions)
264+
{
265+
servicePath.Append("/" + condition.Left + "/" + condition.Right);
266+
}
267+
268+
}
269+
270+
string url = EnvironmentUtils.ParseServiceUrl(environmentTemplate) + servicePath + "/" + TypeName + "s";
271+
if (log.IsDebugEnabled) log.Debug("Service Path URL is " + url);
272+
273+
return PagingRetrieve(url);
274+
}
275+
240276
/// <summary>
241277
/// <see cref="Sif.Framework.Consumer.IGenericConsumer{T,PK}.Retrieve(System.Int32, System.Int32)">Retrieve</see>
242278
/// </summary>

Code/Sif3Framework/Sif.Framework/Consumer/IGenericConsumer.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
using Sif.Framework.Model.Persistence;
18+
using Sif.Framework.Model.Query;
1819
using System.Collections.Generic;
1920

2021
namespace Sif.Framework.Consumer
@@ -84,6 +85,15 @@ public interface IGenericConsumer<T, PK> where T : IPersistable<PK>
8485
/// <returns></returns>
8586
ICollection<T> Retrieve(T obj);
8687

88+
/// <summary>
89+
/// GET api/{object1}/{id1}/{controller}
90+
/// GET api/{object1}/{id1}/{object2}/{id2}/{controller}
91+
/// GET api/{object1}/{id1}/{object2}/{id2}/{object3}/{id3}/{controller}
92+
/// </summary>
93+
/// <param name="conditions"></param>
94+
/// <returns></returns>
95+
ICollection<T> Retrieve(IEnumerable<EqualCondition> conditions);
96+
8797
/// <summary>
8898
/// GET /StudentPersonals
8999
/// </summary>

Code/Sif3Framework/Sif.Framework/Controller/GenericController.cs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
using Sif.Framework.Model.Infrastructure;
1818
using Sif.Framework.Model.Persistence;
19+
using Sif.Framework.Model.Query;
1920
using Sif.Framework.Service;
2021
using Sif.Framework.Service.Authentication;
2122
using Sif.Framework.Utils;
@@ -219,6 +220,60 @@ public virtual List<T> Get(T item)
219220
return items;
220221
}
221222

223+
/// <summary>
224+
/// GET api/{object1}/{id1}/{controller}
225+
/// GET api/{object1}/{id1}/{object2}/{id2}/{controller}
226+
/// GET api/{object1}/{id1}/{object2}/{id2}/{object3}/{id3}/{controller}
227+
/// </summary>
228+
/// <param name="object1"></param>
229+
/// <param name="id1"></param>
230+
/// <param name="object2"></param>
231+
/// <param name="id2"></param>
232+
/// <param name="object3"></param>
233+
/// <param name="id3"></param>
234+
/// <returns>Objects that meet the associated object and ID combinations.</returns>
235+
public virtual List<T> Get(string object1, string id1, string object2 = null, string id2 = null, string object3 = null, string id3 = null)
236+
{
237+
238+
if (!authService.VerifyAuthenticationHeader(Request.Headers.Authorization))
239+
{
240+
throw new HttpResponseException(HttpStatusCode.Unauthorized);
241+
}
242+
243+
List<T> item;
244+
245+
try
246+
{
247+
EqualCondition condition = new EqualCondition() { Left = object1, Right = id1 };
248+
IList<EqualCondition> conditions = new List<EqualCondition>() { condition };
249+
250+
if (!string.IsNullOrWhiteSpace(object2))
251+
{
252+
conditions.Add(new EqualCondition() { Left = object2, Right = id2 });
253+
254+
if (!string.IsNullOrWhiteSpace(object3))
255+
{
256+
conditions.Add(new EqualCondition() { Left = object3, Right = id3 });
257+
}
258+
259+
}
260+
261+
item = (List<T>)service.Retrieve(conditions);
262+
}
263+
catch (Exception e)
264+
{
265+
string errorMessage = "The GET request (based on Service Path parameters) failed for a " + typeof(T).Name + " due to the following error:\n " + e.Message;
266+
throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, errorMessage));
267+
}
268+
269+
if (item == null)
270+
{
271+
throw new HttpResponseException(HttpStatusCode.NotFound);
272+
}
273+
274+
return item;
275+
}
276+
222277
/// <summary>
223278
/// POST api/{controller}
224279
/// </summary>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright 2015 Systemic Pty Ltd
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
using System;
18+
19+
namespace Sif.Framework.Model.Query
20+
{
21+
22+
/// <summary>
23+
/// Query or filter condition.
24+
/// </summary>
25+
public class Condition
26+
{
27+
28+
/// <summary>
29+
/// Operator applicable for the condition.
30+
/// </summary>
31+
public enum Operator
32+
{
33+
Equal, NotEqual, LessThan, GreaterThan
34+
};
35+
36+
/// <summary>
37+
/// Property that defines the left side of the condition.
38+
/// </summary>
39+
public String Left { get; set; }
40+
41+
/// <summary>
42+
/// Operator for each side of the condition.
43+
/// </summary>
44+
public virtual Operator Op { get; set; }
45+
46+
/// <summary>
47+
/// Property that defines the right side of the condition.
48+
/// </summary>
49+
public String Right { get; set; }
50+
51+
}
52+
53+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2015 Systemic Pty Ltd
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
namespace Sif.Framework.Model.Query
18+
{
19+
20+
/// <summary>
21+
/// Equality condition.
22+
/// </summary>
23+
public class EqualCondition : Condition
24+
{
25+
26+
/// <summary>
27+
/// This condition is only applicable with the Equal Operator.
28+
/// </summary>
29+
public override Operator Op
30+
{
31+
32+
get
33+
{
34+
return Condition.Operator.Equal;
35+
}
36+
37+
}
38+
39+
}
40+
41+
}

Code/Sif3Framework/Sif.Framework/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("0.21.0.0")]
36-
[assembly: AssemblyFileVersion("0.21.0.0")]
35+
[assembly: AssemblyVersion("0.22.0.0")]
36+
[assembly: AssemblyFileVersion("0.22.0.0")]
3737

3838
// Configure log4net using the .config file
3939
[assembly: log4net.Config.XmlConfigurator(Watch = true)]

Code/Sif3Framework/Sif.Framework/Service/GenericService.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
*/
1616

1717
using Sif.Framework.Model.Persistence;
18+
using Sif.Framework.Model.Query;
1819
using Sif.Framework.Persistence;
20+
using System;
1921
using System.Collections.Generic;
2022

2123
namespace Sif.Framework.Service
@@ -75,6 +77,11 @@ public virtual ICollection<T> Retrieve(int pageIndex, int pageSize)
7577
return repository.Retrieve(pageIndex, pageSize);
7678
}
7779

80+
public virtual ICollection<T> Retrieve(IEnumerable<EqualCondition> conditions)
81+
{
82+
throw new NotImplementedException();
83+
}
84+
7885
public virtual void Update(T obj)
7986
{
8087
repository.Save(obj);

Code/Sif3Framework/Sif.Framework/Service/IGenericService.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
using Sif.Framework.Model.Persistence;
18+
using Sif.Framework.Model.Query;
1819
using System.Collections.Generic;
1920

2021
namespace Sif.Framework.Service
@@ -82,6 +83,13 @@ public interface IGenericService<T, PK> where T : IPersistable<PK>
8283
/// <returns></returns>
8384
ICollection<T> Retrieve(int pageIndex, int pageSizel);
8485

86+
/// <summary>
87+
///
88+
/// </summary>
89+
/// <param name="conditions"></param>
90+
/// <returns></returns>
91+
ICollection<T> Retrieve(IEnumerable<EqualCondition> conditions);
92+
8593
/// <summary>
8694
///
8795
/// </summary>

0 commit comments

Comments
 (0)