private IEnumerable <HistoryItem> Build(HistoryRequest request, Action <ClarifyGeneric, WorkflowObjectInfo> genericAction) { 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); } genericAction(workflowGeneric, workflowObjectInfo); var inverseActivityRelation = workflowObjectInfo.ActivityRelation; var activityRelation = _schemaCache.GetRelation("act_entry", inverseActivityRelation).InverseRelation; var actEntryGeneric = workflowGeneric.Traverse(activityRelation.Name); 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 templateDictionary = _templatePolicyConfiguration.RenderPolicies(request.WorkflowObject); //query generic hierarchy and while using act entry templates transform the results into HistoryItems return(_historyItemAssembler.Assemble(actEntryGeneric, templateDictionary, request)); }
public IEnumerable <HistoryItem> Build(WorkflowObject workflowObject, Filter actEntryFilter) { var clarifyDataSet = _session.CreateDataSet(); var workflowObjectInfo = WorkflowObjectInfo.GetObjectInfo(workflowObject.Type); var workflowGeneric = clarifyDataSet.CreateGenericWithFields(workflowObjectInfo.ObjectName); workflowGeneric.AppendFilter(workflowObjectInfo.IDFieldName, StringOps.Equals, workflowObject.Id); var inverseActivityRelation = workflowObjectInfo.ActivityRelation; var activityRelation = _schemaCache.GetRelation("act_entry", inverseActivityRelation).InverseRelation; var actEntryGeneric = workflowGeneric.Traverse(activityRelation.Name); actEntryGeneric.AppendSort("entry_time", false); if (actEntryFilter != null) { actEntryGeneric.Filter.AddFilter(actEntryFilter); } var templateDictionary = _templatePolicyConfiguration.RenderPolicies(workflowObject); //query generic hierarchy and while using act entry templates transform the results into HistoryItems var assembler = _container.With(templateDictionary).With(workflowObject).GetInstance <HistoryItemAssembler>(); return(assembler.Assemble(actEntryGeneric)); }
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 }); }