public ClarifyGenericMapEntry BuildFromActEntry(HistoryRequest request, ModelMap.ModelMap modelMap, ActEntryOptions options) { var session = _container.GetInstance <IClarifySession>(); var clarifyDataSet = session.CreateDataSet(); var actEntryGeneric = clarifyDataSet.CreateGenericWithFields("act_entry"); actEntryGeneric.AppendSort("entry_time", false); actEntryGeneric.AppendSort("objid", false); if (request.Since.HasValue) { var filter = new FilterExpression().MoreThan("entry_time", request.Since.Value); actEntryGeneric.Filter.AddFilter(filter); } var visitor = _container .With(clarifyDataSet) .With(actEntryGeneric) .With(request.WorkflowObject) .GetInstance <HistoryModelMapVisitor>(); modelMap.Accept(visitor); var generic = visitor.RootGenericMap; generic.Entity = modelMap.Entity; if (!request.ShowAllActivities) { var activeCodes = visitor.ActEntries.Where(t => !t.IsVerbose).Select(d => d.Code).ToArray(); actEntryGeneric.Filter(f => f.IsIn("act_code", activeCodes)); } return(generic); }
public HistoryResult HistoryFor(HistoryRequest request) { var policy = _policies.LastOrDefault(_ => _.Matches(request)) ?? _default; var result = determineHistory(request, policy); return(result); }
public HistoryResult HistoryFor(HistoryRequest request, IHistoryBuilder builder) { var activityCodes = new List <int>(); var gatherer = new ActEntryGatherer(activityCodes, request.ShowAllActivities, request.WorkflowObject, _services, _user, _privileges); var map = _models.Find(request.WorkflowObject); map.Accept(gatherer); var policy = _policies.LastOrDefault(_ => _.Matches(request)) ?? _default; var actEntries = policy.IdsFor(request, activityCodes.ToArray()); var items = actEntries.Ids.Any() ? builder.GetAll(request, generic => generic.Filter(_ => _.IsIn("objid", actEntries.Ids.ToArray()))) : new ModelData[0]; return(new HistoryResult { HistoryItemLimit = request.HistoryItemLimit, Since = request.Since, TotalResults = actEntries.Count, Items = request.ReverseOrder ? items.OrderBy(_ => _.Get <DateTime>("timestamp")).ThenBy(_ => _.Get <int>("id")).ToArray() : items.OrderByDescending(_ => _.Get <DateTime>("timestamp")).ThenByDescending(_ => _.Get <int>("id")).ToArray(), NextTimestamp = HistoryResult.DetermineNextTimestamp(request, actEntries) }); }
public HistoryResult HistoryFor(HistoryRequest request, IHistoryBuilder builder) { var activityCodes = new List <int>(); var gatherer = new ActEntryGatherer(activityCodes, request.ShowAllActivities, request.WorkflowObject, _services, _user, _privileges); var map = _models.Find(request.WorkflowObject); map.Accept(gatherer); var options = new ActEntryOptions { FocusType = _schema.GetTableNumber(request.WorkflowObject.Type), FocusId = int.Parse(request.WorkflowObject.Id) }; var actEntries = IdsFor(request, options, activityCodes.ToArray()); var items = actEntries.Ids.Any() ? builder.GetAll(request, options, generic => generic.Filter(_ => _.IsIn("objid", actEntries.Ids.ToArray()))) : new ModelData[0]; return(new HistoryResult { HistoryItemLimit = request.HistoryItemLimit, Since = request.Since, TotalResults = actEntries.Count, Items = request.ReverseOrder ? items.OrderBy(_ => _.Get <DateTime>("timestamp")).ThenBy(_ => _.Get <int>("id")).ToArray() : items.OrderByDescending(_ => _.Get <DateTime>("timestamp")).ThenByDescending(_ => _.Get <int>("id")).ToArray(), NextTimestamp = HistoryResult.DetermineNextTimestamp(request, actEntries) }); }
public ModelData[] GetAll(HistoryRequest request, ActEntryOptions options, Action <ClarifyGeneric> configureActEntryGeneric) { var map = _models.Find(request.WorkflowObject); var rootGenericMap = _entries.BuildFromActEntry(request, map, options); configureActEntryGeneric(rootGenericMap.ClarifyGeneric); return(assemble(request.WorkflowObject, rootGenericMap).Models); }
public ClarifyGenericMapEntry BuildFromModelMap(HistoryRequest request, ModelMap.ModelMap modelMap, Action <ClarifyGeneric> configureWorkflowGeneric) { var session = _container.GetInstance <IClarifySession>(); var schemaCache = _container.GetInstance <ISchemaCache>(); var clarifyDataSet = session.CreateDataSet(); var workflowObjectInfo = WorkflowObjectInfo.GetObjectInfo(request.WorkflowObject.Type); var workflowGeneric = clarifyDataSet.CreateGenericWithFields(workflowObjectInfo.ObjectName); if (workflowObjectInfo.HasIDFieldName) { workflowGeneric.DataFields.Add(workflowObjectInfo.IDFieldName); } if (request.WorkflowObject.Id.IsNotEmpty()) { if (workflowObjectInfo.IDFieldName.IsEmpty() || workflowObjectInfo.IDFieldName == "objid") { workflowGeneric.Filter(f => f.Equals("objid", Convert.ToInt32(request.WorkflowObject.Id))); } else { workflowGeneric.Filter(f => f.Equals(workflowObjectInfo.IDFieldName, request.WorkflowObject.Id)); } } configureWorkflowGeneric(workflowGeneric); var inverseActivityRelation = workflowObjectInfo.ActivityRelation; var activityRelation = schemaCache.GetRelation("act_entry", inverseActivityRelation).InverseRelation; var actEntryGeneric = workflowGeneric.Traverse(activityRelation.Name); actEntryGeneric.AppendSort("entry_time", !request.ReverseOrder); actEntryGeneric.AppendSort("objid", !request.ReverseOrder); var visitor = _container .With(clarifyDataSet) .With(actEntryGeneric) .With(request.WorkflowObject) .GetInstance <HistoryModelMapVisitor>(); modelMap.Accept(visitor); var generic = visitor.RootGenericMap; generic.Entity = modelMap.Entity; if (!request.ShowAllActivities) { var activeCodes = visitor.ActEntries.Where(t => !t.IsVerbose).Select(d => d.Code).ToArray(); actEntryGeneric.Filter(f => f.IsIn("act_code", activeCodes)); } return(generic); }
public ActEntryResolution IdsFor(HistoryRequest request, ActEntryOptions options, int[] actCodes) { var codeArg = actCodes.Select(_ => _.ToString()).Join(","); var entryTimeArg = request.EntryTimeArg(); var orderDirection = request.SortOrder(); var findByFocusTypeAndId = "focus_type = {0} AND focus_lowid = {1}".ToFormat(options.FocusType, options.FocusId); var focusArg = findByFocusTypeAndId; var workflowObjectInfo = WorkflowObjectInfo.GetObjectInfo(request.WorkflowObject.Type); if (workflowObjectInfo.UseParticipantActEntryModel) { focusArg = "(({0}) OR objid IN (SELECT participant2act_entry FROM table_participant WHERE {0}))".ToFormat(findByFocusTypeAndId); } var command = "SELECT COUNT(1) FROM table_act_entry WHERE act_code IN ({0}){1} AND {2}".ToFormat(codeArg, entryTimeArg, focusArg); var helper = new SqlHelper(command); var count = (int)helper.ExecuteScalar(); if (count == 0) { return(new ActEntryResolution { Count = 0, Ids = new int[0] }); } command = "SELECT TOP {0} objid, entry_time FROM table_act_entry WHERE act_code IN ({1}){2} AND {3} ORDER BY entry_time {4}, objid {4}".ToFormat(request.SqlLimit(), codeArg, entryTimeArg, focusArg, orderDirection); helper = new SqlHelper(command); DateTime?last = null; var ids = new List <int>(); using (var reader = helper.ExecuteReader()) { while (reader.Read()) { var objid = reader.GetInt32(0); ids.Add(objid); last = reader.GetDateTime(reader.GetOrdinal("entry_time")); } } return(new ActEntryResolution { Count = count, Ids = ids, LastTimestamp = last }); }
private HistoryResult determineHistory(HistoryRequest request, IHistoryAssemblyPolicy policy) { var result = policy.HistoryFor(request, _builder); if (!result.Items.Any()) { return(result); } var localTimestamp = result.NextTimestamp; result.NextTimestamp = normalizeNextTimestamp(result); var sameTimestamp = result.NextTimestamp.HasValue && result.Items.All(_ => _.Get <DateTime>("timestamp") == result.NextTimestamp.Value); if (!sameTimestamp) { return(result); } var combinedItems = new List <ModelData>(); combinedItems.AddRange(result.Items); request.Since = localTimestamp.Value; request.FindRepeatingTimestamp = true; var repeatingResult = policy.HistoryFor(request, _builder); foreach (var item in repeatingResult.Items) { if (combinedItems.Any(_ => _.Get <int>("id") == item.Get <int>("id"))) { continue; } combinedItems.Add(item); } request.FindRepeatingTimestamp = false; request.EntryTimeExclusive = true; request.HistoryItemLimit = 1; var nextResult = policy.HistoryFor(request, _builder); result.NextTimestamp = normalizeNextTimestamp(nextResult); result.Items = combinedItems.ToArray(); return(result); }
public HistoryResult HistoryFor(HistoryRequest request, IHistoryBuilder builder) { var caseActivityCodes = determineActCodes(new WorkflowObject { Type = "case" }, request.ShowAllActivities); var subcaseActivityCodes = determineActCodes(new WorkflowObject { Type = "subcase", IsChild = true }, request.ShowAllActivities); var actEntries = resolveEntries(request, caseActivityCodes.ToArray(), subcaseActivityCodes.ToArray()); var caseHistoryItems = actEntries.CaseEntries.Any() ? builder.GetAll(request, generic => generic.Filter(_ => _.IsIn("objid", actEntries.CaseEntries.ToArray())), workflowGeneric => workflowGeneric.Filter(_ => _.Equals("id_number", request.WorkflowObject.Id))) : new ModelData[0]; var childRequest = new HistoryRequest { WorkflowObject = new WorkflowObject { Type = WorkflowObject.Subcase, IsChild = true }, ShowAllActivities = request.ShowAllActivities }; var subcaseHistoryItems = actEntries.SubcaseEntries.Any() && actEntries.Subcases.Any() ? builder.GetAll(childRequest, actEntryGeneric => actEntryGeneric.Filter(_ => _.IsIn("objid", actEntries.SubcaseEntries.ToArray())), workflowGeneric => workflowGeneric.Filter(_ => _.IsIn("objid", actEntries.Subcases.ToArray()))) : new ModelData[0]; var items = new List <ModelData>(); items.AddRange(caseHistoryItems); items.AddRange(subcaseHistoryItems); var combinedItems = request.ReverseOrder ? items.OrderBy(_ => _.Get <DateTime>("timestamp")).ThenBy(_ => _.Get <int>("id")).ToArray() : items.OrderByDescending(_ => _.Get <DateTime>("timestamp")).ThenByDescending(_ => _.Get <int>("id")).ToArray(); return(new HistoryResult { HistoryItemLimit = request.HistoryItemLimit, Since = request.Since, TotalResults = actEntries.Count, Items = combinedItems, NextTimestamp = request.HistoryItemLimit > (actEntries.CaseEntries.Length + actEntries.SubcaseEntries.Length) ? null : actEntries.LastTimestamp }); }
public bool Matches(HistoryRequest request) { var workflowObjectInfo = WorkflowObjectInfo.GetObjectInfo(request.WorkflowObject.Type); return(workflowObjectInfo.ActivityRelation.IsEmpty()); }
public ClarifyGenericMapEntry BuildFromModelMap(HistoryRequest request, ModelMap.ModelMap modelMap) { return(BuildFromModelMap(request, modelMap, _ => { })); }
public static DateTime?DetermineNextTimestamp(HistoryRequest request, ActEntryResolution entries) { return(request.HistoryItemLimit > entries.Ids.Count() ? null : entries.LastTimestamp); }
public bool Matches(HistoryRequest request) { return(true); }
public ModelData[] GetAll(HistoryRequest request, Action <ClarifyGeneric> configureActEntryGeneric) { return(GetAll(request, configureActEntryGeneric, generic => { })); }
public ModelData[] GetAll(HistoryRequest request) { return(GetAll(request, generic => { })); }
public ActEntryResolution IdsFor(HistoryRequest request, int[] actCodes) { var codeArg = actCodes.Select(_ => _.ToString()).Join(","); var entryTimeArg = request.EntryTimeArg(); var orderDirection = request.SortOrder(); var idArg = ""; var workflowObjectInfo = WorkflowObjectInfo.GetObjectInfo(request.WorkflowObject.Type); var inverseActivityRelation = workflowObjectInfo.ActivityRelation; if (inverseActivityRelation.IsEmpty()) { throw new InvalidOperationException("Cannot traverse from {0} to act_entry".ToFormat(request.WorkflowObject.Type)); } var activityRelation = _schema.GetRelation("act_entry", inverseActivityRelation).Name; if (workflowObjectInfo.IDFieldName.IsEmpty() || workflowObjectInfo.IDFieldName == "objid") { idArg = "{0} = {1}".ToFormat(activityRelation, request.WorkflowObject.Id); } else { var objId = (int)new SqlHelper("SELECT objid FROM table_{0} WHERE {1} = '{2}'".ToFormat(workflowObjectInfo.DatabaseTable, workflowObjectInfo.IDFieldName, request.WorkflowObject.Id)).ExecuteScalar(); idArg = "{0} = {1}".ToFormat(activityRelation, objId); } var command = "SELECT COUNT(1) FROM table_act_entry WHERE act_code IN ({0}){1} AND {2}".ToFormat(codeArg, entryTimeArg, idArg); var helper = new SqlHelper(command); var count = (int)helper.ExecuteScalar(); if (count == 0) { return(new ActEntryResolution { Count = 0, Ids = new int[0] }); } command = "SELECT TOP {0} objid, entry_time FROM table_act_entry WHERE act_code IN ({1}){2} AND {3} ORDER BY entry_time {4}, objid {4}".ToFormat(request.SqlLimit(), codeArg, entryTimeArg, idArg, orderDirection); helper = new SqlHelper(command); DateTime?last = null; var ids = new List <int>(); using (var reader = helper.ExecuteReader()) { while (reader.Read()) { var objid = reader.GetInt32(0); ids.Add(objid); last = reader.GetDateTime(reader.GetOrdinal("entry_time")); } } return(new ActEntryResolution { Count = count, Ids = ids, LastTimestamp = last }); }
private ActEntryResult resolveEntries(HistoryRequest request, int[] caseActCodes, int[] subcaseActCodes) { var actCodes = new List <int>(caseActCodes); actCodes.AddRange(subcaseActCodes); if (!actCodes.Any()) { return(new ActEntryResult { Count = 0, Subcases = new int[0], CaseEntries = new int[0], SubcaseEntries = new int[0] }); } var codeArg = actCodes.Select(_ => _.ToString()).Join(","); var entryTimeArg = request.EntryTimeArg(); var order = request.SortOrder(); var objId = (int)new SqlHelper("SELECT objid FROM table_case WHERE id_number = '{0}'".ToFormat(request.WorkflowObject.Id)).ExecuteScalar(); var command = "SELECT COUNT(1) FROM table_act_entry WHERE act_code IN ({0}){1} AND (act_entry2case = {2} OR act_entry2subcase IN (SELECT objid FROM table_subcase WHERE subcase2case = {2}))".ToFormat(codeArg, entryTimeArg, objId); var helper = new SqlHelper(command); var count = (int)helper.ExecuteScalar(); if (count == 0) { return(new ActEntryResult { Count = 0, Subcases = new int[0], CaseEntries = new int[0], SubcaseEntries = new int[0] }); } command = "SELECT objid FROM table_subcase WHERE subcase2case = {0}".ToFormat(objId); helper = new SqlHelper(command); var ids = new List <int>(); using (var reader = helper.ExecuteReader()) { while (reader.Read()) { var objid = reader.GetInt32(0); ids.Add(objid); } } command = new StringBuilder("SELECT TOP ") .Append(request.SqlLimit()) .Append(" objid, act_entry2case, act_entry2subcase, entry_time FROM table_act_entry WHERE ") .AppendFormat("((act_code IN ({0}) AND act_entry2case = {1})", caseActCodes.Select(_ => _.ToString()).Join(","), objId) .Append(" OR ") .AppendFormat("(act_code IN ({0}) AND act_entry2subcase IN (SELECT objid FROM table_subcase WHERE subcase2case = {1})))", subcaseActCodes.Select(_ => _.ToString()).Join(","), objId) .Append(entryTimeArg) .AppendFormat(" ORDER BY entry_time {0}, objid {0}", order) .ToString(); helper = new SqlHelper(command); var caseIds = new List <int>(); var subcaseIds = new List <int>(); DateTime?lastTimestamp = null; using (var reader = helper.ExecuteReader()) { while (reader.Read()) { var objid = reader.GetInt32(0); if (!reader.IsDBNull(reader.GetOrdinal("act_entry2subcase"))) { subcaseIds.Add(objid); } else { caseIds.Add(objid); } lastTimestamp = reader.GetDateTime(reader.GetOrdinal("entry_time")); } } return(new ActEntryResult { Count = count, Subcases = ids.ToArray(), CaseEntries = caseIds.ToArray(), SubcaseEntries = subcaseIds.ToArray(), LastTimestamp = lastTimestamp }); }
public bool Matches(HistoryRequest request) { return(request.WorkflowObject.Type.EqualsIgnoreCase("case") && _settings.MergeCaseHistoryChildSubcases); }