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));
        }
Exemplo n.º 2
0
        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));
        }
 /// <summary>
 /// Register IWorkflowObjectMetadata instances into the IoC container when you wish to define custom WorkflowObjectInfo metadatas with the Dovetail SDKa
 /// </summary>
 public static void RegisterWorkflowMetadata(IEnumerable <IWorkflowObjectMetadata> metadatas, ILogger logger)
 {
     foreach (var metadata in metadatas)
     {
         var info = metadata.Register();
         WorkflowObjectInfo.AddToCache(info, metadata.Alias.IsNotEmpty() ? metadata.Alias : info.ObjectName);
     }
 }
Exemplo n.º 4
0
            public void should_add_info_objects_registered_by_alias_when_present()
            {
                var metadata2 = new Custom2MetaData();
                var metadatas = new IWorkflowObjectMetadata[] { metadata2 };
                var logger    = MockRepository.GenerateMock <ILogger>();

                ClarifyApplicationFactory.RegisterWorkflowMetadata(metadatas, logger);

                WorkflowObjectInfo.GetObjectInfo(metadata2.Alias).ShouldBeTheSameAs(metadata2.Register());
            }
Exemplo n.º 5
0
            public void should_add_info_objects_returned_by_register()
            {
                var metadata1 = new Custom1MetaData();
                var metadatas = new IWorkflowObjectMetadata[] { metadata1 };
                var logger    = MockRepository.GenerateMock <ILogger>();

                ClarifyApplicationFactory.RegisterWorkflowMetadata(metadatas, logger);

                WorkflowObjectInfo.GetObjectInfo(metadata1.Register().ObjectName).ShouldBeTheSameAs(metadata1.Register());
            }
Exemplo n.º 6
0
        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 IEnumerable <HistoryItem> Assemble(ClarifyGeneric actEntryGeneric, IDictionary <int, ActEntryTemplate> templatesByCode, HistoryRequest historyRequest)
        {
            actEntryGeneric.DataFields.AddRange("act_code", "entry_time", "addnl_info", "proxy");

            if (!historyRequest.ShowAllActivities)
            {
                var activeCodes = templatesByCode.Values.Where(t => !t.IsVerbose).Select(d => d.Code).ToArray();
                actEntryGeneric.Filter(f => f.IsIn("act_code", activeCodes));
            }

            //adding related generics expected by any fancy act entry templates
            var templateRelatedGenerics = traverseRelatedGenerics(actEntryGeneric, templatesByCode);

            _employeeAssembler.TraverseEmployee(actEntryGeneric);
            _contactAssembler.TraverseContact(actEntryGeneric);
            if (historyRequest.HistoryItemLimit.HasValue)
            {
                actEntryGeneric.MaximumRows = historyRequest.HistoryItemLimit.Value;
            }
            actEntryGeneric.Query();

            var actEntryDTOS = actEntryGeneric.DataRows().Select(actEntryRecord =>
            {
                var id = historyRequest.WorkflowObject.Id;
                if (historyRequest.WorkflowObject.IsChild)
                {
                    //child objects are loaded in bulk so historyRequest.WorkflowObject.Id is not the correct id
                    //find the act_entry's parent generic id field value
                    var info      = WorkflowObjectInfo.GetObjectInfo(actEntryGeneric.ParentRelation.TargetName);
                    var parentId  = actEntryRecord.AsInt(actEntryGeneric.ParentRelation.Name);
                    var parentRow = actEntryGeneric.ParentGeneric.DataRows().First(r => r.DatabaseIdentifier() == parentId);
                    id            = (info.HasIDFieldName) ? parentRow[info.IDFieldName].ToString() : Convert.ToString(parentRow.DatabaseIdentifier());
                }

                var code = actEntryRecord.AsInt("act_code");

                return(new ActEntry
                {
                    Id = id,
                    Type = historyRequest.WorkflowObject.Type,
                    Template = findTemplateByActCode(code, templatesByCode),
                    When = actEntryRecord.AsDateTime("entry_time"),
                    Who = _employeeAssembler.Assemble(actEntryRecord, _contactAssembler),
                    ImpersonatedBy = _employeeAssembler.Assemble(actEntryRecord),
                    AdditionalInfo = actEntryRecord.AsString("addnl_info"),
                    ActEntryRecord = actEntryRecord
                });
            }).Where(_ => !_.Template.IsCancelled).ToList();

            return(actEntryDTOS
                   .Select(dto => createActivityDTOFromMapper(dto, templateRelatedGenerics))
                   .Where(i => !i.IsCancelled)
                   .Where(_ => historyRequest.ShowAllActivities || !_.IsVerbose)
                   .ToList());
        }
        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
            });
        }
        public bool Matches(HistoryRequest request)
        {
            var workflowObjectInfo = WorkflowObjectInfo.GetObjectInfo(request.WorkflowObject.Type);

            return(workflowObjectInfo.ActivityRelation.IsEmpty());
        }
Exemplo n.º 10
0
        protected override void DefineTemplate(WorkflowObject workflowObject)
        {
            //remove add attachments for merged history
            if (workflowObject.IsChild)
            {
                ActEntry(8900).Remove();
                ActEntry(9100).Remove();
                return;
            }

            //When the workflow object itself has a relation to doc_inst.
            //Attempt to match the attachment navigating from the act entry to the workflow object and from there down to the doc_path
            //we look for the attachment whose doc_path.path matches the act_entry_addln_info details.

            var objectInfo = WorkflowObjectInfo.GetObjectInfo(workflowObject.Type);
            var table      = _schemaCache.Tables[objectInfo.ObjectName];

            if (_settings.UseDovetailSDKCompatibileAttachmentFinder == false &&
                table.Relationships.Cast <ISchemaRelation>().Any(r => r.TargetTable.Name == "doc_inst"))
            {
                //use the work object info to get the object's relation to actentry
                //unfortunately the object info doesn't have the relation from the workflow object to doc_inst.
                var docInstRelation = table.Relationships.Cast <ISchemaRelation>().First(r => r.TargetTable.Name == "doc_inst");

                ActEntry(8900).DisplayName(HistoryBuilderTokens.ATTACHMENT_ADDED)
                .GetRelatedRecord(objectInfo.ActivityRelation, workflowGeneric =>
                {
                    var docInstGeneric = workflowGeneric.TraverseWithFields(docInstRelation.Name, "title");
                    docInstGeneric.TraverseWithFields("attach_info2doc_path", "path");
                })
                .UpdateActivityDTOWith((caseRow, item, template) =>
                {
                    var docInst = caseRow.RelatedRows(docInstRelation.Name).FirstOrDefault(d =>
                    {
                        var docPath = d.RelatedRows("attach_info2doc_path").First();
                        return(item.Detail.Contains(docPath.AsString("path")));
                    });

                    if (docInst == null)
                    {
                        _logger.LogDebug(
                            "Could not find an attachment whose additional info matches one of the attachment paths. The history item will contain the plain additional info.");
                        return;
                    }

                    //cancel the htmlizer as we are emitting HTML
                    template.HTMLizer = i => { };

                    var docInstDetail = new DocInstDetail
                    {
                        ObjId      = docInst.DatabaseIdentifier(),
                        Title      = docInst.AsString("title"),
                        Path       = docInst.RelatedRows("attach_info2doc_path")[0].AsString("path"),
                        Properties = new Dictionary <string, object>()
                    };

                    _attachmentHistoryItemUpdater.Update(docInstDetail, item);
                    item.Internal = string.Empty;
                });
                return;
            }

            //Settings dictate or this workflow object does not support our fancy attachment history item updater so we use the old navigation via act_entry to doc_inst
            //The mechanism only works well when recent versions of Dovetail SDK to create attachments.
            ActEntry(8900).DisplayName(HistoryBuilderTokens.ATTACHMENT_ADDED)
            .GetRelatedRecord("act_entry2doc_inst")
            .WithFields("title")
            .UpdateActivityDTOWith((row, item, template) =>
            {
                //cancel the htmlizer as we are emitting HTML
                template.HTMLizer = i => { };

                var docInstDetail = new DocInstDetail
                {
                    ObjId      = row.DatabaseIdentifier(),
                    Title      = row.AsString("title").HtmlEncode(),
                    Properties = new Dictionary <string, object>()
                };

                _attachmentHistoryItemUpdater.Update(docInstDetail, item);
                item.Internal = string.Empty;
            });
        }
Exemplo n.º 11
0
        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
            });
        }