Skip to content

Commit

Permalink
Added histories view for getting the history from multiple objects by id
Browse files Browse the repository at this point in the history
/api/histories/case?ids=1,2,3,4,5,6

* ids=1,2,3,4,5
* (optional) since datetime

Note it won't likely behave nice if you have weird spaces between the comma delimited ids
  • Loading branch information
KevM committed Jun 22, 2012
1 parent 2fcafd5 commit 1223050
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 8 deletions.
Expand Up @@ -101,7 +101,7 @@
<Compile Include="History\AssemblerPolicies\IHistoryAssemblerPolicy.cs" />
<Compile Include="History\Configuration\ActEntryTemplatePolicyConfiguration.cs" />
<Compile Include="History\Configuration\ActEntryTemplatePolicyRegistry.cs" />
<Compile Include="History\AssemblerPolicies\MergeCaseWithSubcaseHistoryAssemblerPolicy.cs" />
<Compile Include="History\AssemblerPolicies\CaseHistoryAssemblerPolicy.cs" />
<Compile Include="History\CommonActEntryBuilderDSLExtensions.cs" />
<Compile Include="History\AssemblerPolicies\DefaultHistoryAssemblerProvider.cs" />
<Compile Include="History\Parser\HistoryItemHtmlRenderer.cs" />
Expand Down
Expand Up @@ -8,15 +8,13 @@

namespace Dovetail.SDK.Bootstrap.History.AssemblerPolicies
{
public class MergeCaseWithSubcaseHistoryAssemblerPolicy : IHistoryAssemblerPolicy
public class CaseHistoryAssemblerPolicy : IHistoryAssemblerPolicy
{
private readonly IClarifySessionCache _sessionCache;
private readonly HistoryBuilder _historyBuilder;
private readonly HistorySettings _historySettings;

//TODO add settings object to allow getting subcases to be configurable - default (do not get subcase)

public MergeCaseWithSubcaseHistoryAssemblerPolicy(IClarifySessionCache sessionCache, HistoryBuilder historyBuilder, HistorySettings historySettings)
public CaseHistoryAssemblerPolicy(IClarifySessionCache sessionCache, HistoryBuilder historyBuilder, HistorySettings historySettings)
{
_sessionCache = sessionCache;
_historyBuilder = historyBuilder;
Expand All @@ -25,11 +23,16 @@ public MergeCaseWithSubcaseHistoryAssemblerPolicy(IClarifySessionCache sessionCa

public bool Handles(WorkflowObject workflowObject)
{
return _historySettings.MergeCaseHistoryChildSubcases && workflowObject.Type == WorkflowObject.Case;
return workflowObject.Type == WorkflowObject.Case;
}

public IEnumerable<HistoryItem> BuildHistory(WorkflowObject workflowObject, Filter actEntryFilter)
{
if(!_historySettings.MergeCaseHistoryChildSubcases)
{
return _historyBuilder.Build(workflowObject, actEntryFilter);
}

var subcaseIds = GetSubcaseIds(workflowObject);

var caseHistory = _historyBuilder.Build(workflowObject, actEntryFilter);
Expand Down
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using FChoice.Foundation.Filters;

namespace Dovetail.SDK.Bootstrap.History.AssemblerPolicies
Expand All @@ -21,5 +22,15 @@ public IEnumerable<HistoryItem> BuildHistory(WorkflowObject workflowObject, Filt
{
return _historyBuilder.Build(workflowObject, actEntryFilter);
}

public IEnumerable<HistoryItem> BuildHistories(string type, string[] ids, Filter actEntryFilter)
{
return ids.SelectMany(id =>
{
var workflowObject = WorkflowObject.Create(type, id);
return BuildHistory(workflowObject, actEntryFilter);
});
}

}
}
Expand Up @@ -7,5 +7,6 @@ public interface IHistoryAssemblerPolicy
{
bool Handles(WorkflowObject workflowObject);
IEnumerable<HistoryItem> BuildHistory(WorkflowObject workflowObject, Filter actEntryFilter);
IEnumerable<HistoryItem> BuildHistories(string type, string[] ids, Filter actEntryFilter);
}
}
30 changes: 29 additions & 1 deletion source/Dovetail.SDK.Bootstrap/History/HistoryAssembler.cs
Expand Up @@ -8,6 +8,9 @@ namespace Dovetail.SDK.Bootstrap.History
{
public interface IHistoryAssembler
{
HistoryItem[] GetHistories(string type, string[] ids);
HistoryItem[] GetHistoriesSince(string type, string[] ids, DateTime sinceDate);

HistoryViewModel GetHistory(WorkflowObject workflowObject);
HistoryViewModel GetHistoryTop(WorkflowObject workflowObject, int numberOfMostRecentEntries);
HistoryViewModel GetHistorySince(WorkflowObject workflowObject, DateTime sinceDate);
Expand All @@ -22,7 +25,32 @@ public HistoryAssembler(IEnumerable<IHistoryAssemblerPolicy> entityHistoryBuilde
_entityHistoryBuilders = entityHistoryBuilders;
}

public HistoryViewModel GetHistory(WorkflowObject workflowObject)
public HistoryItem[] GetHistoriesSince(string type, string[] ids, DateTime sinceDate)
{
return getHistories(type, ids, ()=> new FilterExpression().MoreThan("entry_time", sinceDate));
}

public HistoryItem[] GetHistories(string type, string[] ids)
{
return getHistories(type, ids, null);
}

private HistoryItem[] getHistories(string type, string[] ids, Func<Filter> filterFunc)
{
var workflowObject = WorkflowObject.Create(type, ids.FirstOrDefault());
var historyBuilderPolicy = _entityHistoryBuilders.First(policy => policy.Handles(workflowObject));

Filter filter = null;
if(filterFunc != null)
{
filter = filterFunc();
}

return historyBuilderPolicy.BuildHistories(type, ids, filter).ToArray();
}


public HistoryViewModel GetHistory(WorkflowObject workflowObject)
{
return getHistoryWithConstraint(workflowObject, null);
}
Expand Down
2 changes: 1 addition & 1 deletion source/Dovetail.SDK.Bootstrap/History/HistoryViewModel.cs
Expand Up @@ -56,6 +56,6 @@ public class HistoryItemEmployee
public class HistoryViewModel
{
public WorkflowObject WorkflowObject { get; set; }
public HistoryItem[] HistoryItems { get; set; }
public HistoryItem[] HistoryItems { get; set; }
}
}
55 changes: 55 additions & 0 deletions source/Web/Handlers/api/histories/get_Type_handler.cs
@@ -0,0 +1,55 @@
using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using Dovetail.SDK.Bootstrap;
using Dovetail.SDK.Bootstrap.History;
using FubuMVC.Swagger.Specification;

namespace Bootstrap.Web.Handlers.api.histories
{
public class get_Type_handler
{
private readonly IHistoryAssembler _historyAssembler;

public get_Type_handler(IHistoryAssembler historyAssembler)
{
_historyAssembler = historyAssembler;
}

public HistoriesModel Execute(HistoriesRequest request)
{
var ids = request.Ids.Split(',');

var items = request.Since.HasValue ? _historyAssembler.GetHistoriesSince(request.Type, ids, request.Since.Value) : _historyAssembler.GetHistories(request.Type, ids);

return new HistoriesModel
{
HistoryItems = items,
Type = request.Type,
Ids = ids,
Since = request.Since
};
}
}

public class HistoriesModel
{
public string Type { get; set; }
public string[] Ids { get; set; }
public DateTime? Since { get; set; }
public HistoryItem[] HistoryItems { get; set; }
}

[Description("Workflow objects history")]
public class HistoriesRequest : IApi
{
[Required, Description("Type of workflow object. Typically this is 'case'.")]
[AllowableValues("case", "subcase", "solution", "<any workflow object name>")]
public string Type { get; set; }
[Required, Description("Ids of the workflow objects.")]
public string Ids { get; set; }

[Description("")]
public DateTime? Since{ get; set; }
}
}
29 changes: 29 additions & 0 deletions source/Web/Handlers/api/histories/histories.spark
@@ -0,0 +1,29 @@
<viewdata model="Bootstrap.Web.Handlers.api.histories.HistoriesModel" />
<use namespace="FubuCore" />
<use namespace="Dovetail.SDK.Bootstrap.History" />

<content:pagehead>
<h1>History for ${Model.Type} By Id</h1>
</content:pagehead>

<div class="history-item" each="var item in Model.HistoryItems">
<div class="history-item-header ${item.Type}-item">
<h3>
<span class="action-taken">${item.Title} for ${item.Type} ${item.Id}</span>
<span class="date-ago" data-time="${item.When}">${item.When.ToString("yyyy-MM-ddTHH:mm:ssZ")}</span>
</h3>
<div class="history-item-description">
<span class="agent-name">By ${item.Who.Name}</span>
<span class="at-on-date" data-time="${item.When}">${item.When.ToString("yyyy-MM-ddTHH:mm:ssZ")}</span>
</div>

<div class="history-item-details">
<div class="notes">
!{item.Detail}
</div>
<div class="internal" if="item.Internal.IsNotEmpty()">
!{item.Internal}
</div>
</div>
</div>
</div>
4 changes: 4 additions & 0 deletions source/Web/Web.csproj
Expand Up @@ -152,6 +152,7 @@
<Compile Include="Handlers\api\cases\create\CreateCaseModel.cs" />
<Compile Include="Handlers\api\cases\create\get_handler.cs" />
<Compile Include="Handlers\api\cases\create\post_handler.cs" />
<Compile Include="Handlers\api\histories\get_Type_handler.cs" />
<Compile Include="Handlers\api\gbst\get_handler.cs" />
<Compile Include="Handlers\api\gbst\show\get_Name_handler.cs" />
<Compile Include="Handlers\api\history\get_Type_Id_handler.cs" />
Expand All @@ -165,6 +166,9 @@
<None Include="Handlers\api\authtoken\reset\reset.spark" />
<None Include="Handlers\api\cases\create\post.spark" />
<None Include="Handlers\api\cases\create\get.spark" />
<None Include="Handlers\api\histories\histories.spark">
<SubType>Designer</SubType>
</None>
<None Include="Handlers\error\http500\get.spark" />
<None Include="Handlers\user\signin\signin.spark" />
<None Include="Handlers\user\status\status.spark" />
Expand Down

0 comments on commit 1223050

Please sign in to comment.