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 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
            });
        }
示例#4
0
        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);
        }