Ejemplo n.º 1
0
 internal IEnumerable <IMany2ManyRelationshipMetadata> GetManyToManyRelationshipsForType(
     RecordExtractContainer container, string recordType)
 {
     return
         (GetManyToManyRelationships(container)
          .Where(r => r.RecordType1 == recordType || r.RecordType2 == recordType));
 }
Ejemplo n.º 2
0
        private IEnumerable <string> GetRelatedTypes(RecordExtractContainer container)
        {
            var relatedTypes            = new List <string>();
            var oneToManyRelationships  = GetOneToManyRelationships(container);
            var manyToManyRelationships = GetManyToManyRelationships(container);
            var extractRecordType       = container.RecordToExtractType;

            relatedTypes.AddRange(oneToManyRelationships.Select(r => r.ReferencingEntity));
            relatedTypes.AddRange(
                manyToManyRelationships.Where(r => r.RecordType1 == extractRecordType)
                .Select(r => r.RecordType2));
            relatedTypes.AddRange(
                manyToManyRelationships.Where(r => r.RecordType2 == extractRecordType)
                .Select(r => r.RecordType1));
            if (Service.GetRecordTypeMetadata(container.RecordToExtractType).IsActivityParticipant)
            {
                relatedTypes.AddRange(Service.GetAllRecordTypes().Where(r => Service.GetRecordTypeMetadata(r).IsActivityType));
            }
            relatedTypes = relatedTypes.Distinct()
                           .Where(r => !GetRecordTypesToExclude().Contains(r))
                           //we exclude activity parties from this as we get the links when processing activity types
                           .Where(r => r != "activityparty")
                           .ToList();

            return(relatedTypes);
        }
Ejemplo n.º 3
0
        private void GetManyToManyRelated(RecordExtractContainer container, string relatedType,
                                          Dictionary <string, IRecord> recordsToOutput)
        {
            var recordTypeCollectionLabel          = Service.GetCollectionName(relatedType);
            var relatedTypeManyToManyRelationships = GetManyToManyRelationshipsForType(container, relatedType);
            var todoDone  = 0;
            var todoCount = relatedTypeManyToManyRelationships.Count();

            foreach (var manyToMany in relatedTypeManyToManyRelationships)
            {
                container.Controller.UpdateProgress(todoDone++, todoCount,
                                                    string.Format("Searching Many To Many Relationships To {0}", recordTypeCollectionLabel));
                try
                {
                    if (manyToMany.RecordType1 == relatedType)
                    {
                        var theseRelatedEntities = Service.GetRelatedRecords(container.RecordToExtract, manyToMany,
                                                                             false);
                        foreach (var relatedEntity in theseRelatedEntities)
                        {
                            if (!recordsToOutput.ContainsKey(relatedEntity.Id))
                            {
                                recordsToOutput.Add(relatedEntity.Id, relatedEntity);
                            }
                        }
                    }
                    if (manyToMany.RecordType2 == relatedType)
                    {
                        var theseRelatedEntities = Service.GetRelatedRecords(container.RecordToExtract, manyToMany,
                                                                             true);
                        foreach (var relatedEntity in theseRelatedEntities)
                        {
                            if (!recordsToOutput.ContainsKey(relatedEntity.Id))
                            {
                                recordsToOutput.Add(relatedEntity.Id, relatedEntity);
                            }
                        }
                    }
                }
                catch
                (Exception ex)
                {
                    container.Response.AddResponseItem(
                        new RecordExtractResponseItem("Error Loading Many To Many Records",
                                                      manyToMany.SchemaName, ex));
                }
            }
        }
Ejemplo n.º 4
0
        private IRecord ExtractMainRecord(RecordExtractContainer container)
        {
            container.Controller.UpdateProgress(1, 3, "Loading Record");
            var recordToExtract = Service.Get(container.Request.RecordLookup.RecordType,
                                              container.Request.RecordLookup.Id);

            container.RecordToExtract = recordToExtract;
            var primaryField = Service.GetPrimaryField(recordToExtract.Type);
            var recordName   = recordToExtract.GetStringField(primaryField);

            container.AddBookmark(ExtractUtility.CheckStripFormatting(recordName, container.RecordToExtractType,
                                                                      primaryField));
            container.Response.Record = recordToExtract;
            container.Controller.UpdateProgress(2, 3, "Loading Record");
            WriteRecordToSection(recordToExtract, container.Section, DetailLevel.AllFields, container.Request);
            return(recordToExtract);
        }
Ejemplo n.º 5
0
        private void GetActivityPartyRelated(RecordExtractContainer container, string relatedType,
                                             Dictionary <string, IRecord> recordsToOutput)
        {
            //if the extracted record could be an activity participant for this type
            //then get and append them
            if (Service.GetRecordTypeMetadata(container.RecordToExtractType).IsActivityParticipant&& Service.GetRecordTypeMetadata(relatedType).IsActivityType)
            {
                var activities = Service.GetLinkedRecordsThroughBridge(relatedType, "activityparty",
                                                                       container.RecordToExtractType, "partyid", "activityid", container.RecordToExtractId);

                foreach (var activity in activities)
                {
                    if (!recordsToOutput.ContainsKey(activity.Id))
                    {
                        recordsToOutput.Add(activity.Id, activity);
                    }
                }
            }
        }
Ejemplo n.º 6
0
        private RecordExtractToDocumentResponse ExtractRecordToDocument(RecordExtractToDocumentRequest request)
        {
            var             container              = new RecordExtractContainer(request);
            var             recordToExtract        = ExtractMainRecord(container);
            var             hasRelatedRecordOutput = false;
            ContentBookmark bookmark = null;

            try
            {
                var relatedTypes = GetRelatedTypes(container);

                foreach (var relatedType in relatedTypes.OrderBy(r => Service.GetDisplayName(r)))
                {
                    var recordType = relatedType;
                    try
                    {
                        var recordsToOutput = new Dictionary <string, IRecord>();
                        GetOneToManyRelated(container, relatedType, recordsToOutput);
                        GetManyToManyRelated(container, relatedType, recordsToOutput);
                        GetActivityPartyRelated(container, relatedType, recordsToOutput);
                        hasRelatedRecordOutput = AppendRelatedToDocument(recordsToOutput, hasRelatedRecordOutput,
                                                                         container, recordType, ref bookmark, request);
                    }
                    catch (Exception ex)
                    {
                        container.Response.AddResponseItem(new RecordExtractResponseItem(
                                                               "Error Loading Related Records",
                                                               recordType, ex));
                    }
                }
            }
            catch (Exception ex)
            {
                container.Response.AddResponseItem(new RecordExtractResponseItem("Error Loading Relationships",
                                                                                 recordToExtract.Type, ex));
            }
            return(container.Response);
        }
Ejemplo n.º 7
0
        private void GetOneToManyRelated(RecordExtractContainer container, string relatedType,
                                         IDictionary <string, IRecord> recordsToOutput)
        {
            var recordTypeCollectionLabel         = Service.GetCollectionName(relatedType);
            var relatedTypeOneToManyRelationships = GetOneToManyRelationshipsForType(container, relatedType);
            var todoDone  = 0;
            var todoCount = relatedTypeOneToManyRelationships.Count();

            foreach (var oneToMany in relatedTypeOneToManyRelationships)
            {
                container.Controller.UpdateProgress(todoDone++, todoCount,
                                                    string.Format("Searching One To Many Relationships To {0}", recordTypeCollectionLabel));
                try
                {
                    var theseRelatedEntities = Service.RetrieveAllAndClauses(oneToMany.ReferencingEntity,
                                                                             new[]
                    {
                        new Condition(oneToMany.ReferencingAttribute, ConditionType.Equal,
                                      container.RecordToExtract.Id)
                    }, null);
                    foreach (var relatedEntity in theseRelatedEntities)
                    {
                        if (!recordsToOutput.ContainsKey(relatedEntity.Id))
                        {
                            recordsToOutput.Add(relatedEntity.Id, relatedEntity);
                        }
                    }
                }
                catch (Exception ex)
                {
                    container.Response.AddResponseItem(
                        new RecordExtractResponseItem("Error Loading One To Many Records",
                                                      oneToMany.SchemaName, ex));
                }
            }
        }
Ejemplo n.º 8
0
        private bool AppendRelatedToDocument(Dictionary <string, IRecord> recordsToOutput, bool hasRelatedRecordOutput,
                                             RecordExtractContainer container, string recordType, ref ContentBookmark bookmark, RecordExtractToDocumentRequest request)
        {
            if (recordsToOutput.Any())
            {
                var outputNumbers = recordsToOutput.Count > 1 && container.Request.RelatedDetail == DetailLevel.AllFields;
                recordsToOutput.Values.PopulateEmptyLookups(Service, GetRecordTypesToExclude());
                var recordTypeCollectionLabel = Service.GetCollectionName(recordType);
                var recordTypeLabel           = Service.GetDisplayName(recordType);
                if (!hasRelatedRecordOutput)
                {
                    hasRelatedRecordOutput = true;
                    bookmark = container.Section.AddHeading2WithBookmark("Related Records");
                    container.AddBookmark(bookmark);
                }
                var todoDone  = 0;
                var todoCount = recordsToOutput.Count;

                var thisBookmark =
                    container.Section.AddHeading3WithBookmark(string.Format("{0} ({1})", recordTypeCollectionLabel, recordsToOutput.Count));
                bookmark.AddChildBookmark(thisBookmark);

                var i = 1;
                foreach (var match in recordsToOutput.Values)
                {
                    if (outputNumbers)
                    {
                        container.Section.AddParagraph(string.Format("{0} {1}", recordTypeLabel, i++), true);
                    }
                    container.Controller.UpdateProgress(todoDone++, todoCount,
                                                        string.Format("Appending Related {0} To Document", recordTypeCollectionLabel));
                    WriteRecordToSection(match, container.Section, container.Request.RelatedDetail, request);
                }
            }
            return(hasRelatedRecordOutput);
        }
Ejemplo n.º 9
0
 private IEnumerable <IOne2ManyRelationshipMetadata> GetOneToManyRelationships(RecordExtractContainer container)
 {
     return(Service.GetOneToManyRelationships(container.RecordToExtractType)
            .Where(r => !GetRelationshipsToExclude().Contains(r.SchemaName)));
 }
Ejemplo n.º 10
0
 private IEnumerable <IOne2ManyRelationshipMetadata> GetOneToManyRelationshipsForType(
     RecordExtractContainer container, string recordType)
 {
     return(GetOneToManyRelationships(container).Where(r => r.ReferencingEntity == recordType));
 }