public void CtorTest()
        {
            // Act
            var fieldDefinition = new ReferenceDisplayFieldDefinition();

            // Assert
            Assert.IsNotNull(fieldDefinition.Subfields);
            Assert.IsNotNull(fieldDefinition.JoinFields);
        }
        public void WhenSystemNameEqualsId_PropertyName_ReturnsUniqueName()
        {
            // Arrange.
            var guid = new Guid("{2E8AE608-5F96-40E8-ABA5-E165321FBBA8}");

            var field = new ReferenceDisplayFieldDefinition { Name = "Id", SystemName = Constants.IdColumnName, Guid = guid, ColumnType = ColumnTypes.Integer };

            // Act / Assert.
            Assert.AreEqual("DF_2e8ae608_5f96_40e8_aba5_e165321fbba8", field.PropertyName);
            Assert.AreEqual("DF_2e8ae608_5f96_40e8_aba5_e165321fbba8", field.Alias);
        }
Example #3
0
        private ReferenceDisplayFieldDefinition GetDisplayField(ReferenceHelperContext context, FieldEdit fieldInfo, bool throwOnError)
        {
            var publishedProcess = fieldInfo.GetParent<ProcessEdit>();

            if (context.VisitedFields.Contains(Tuple.Create(publishedProcess.SystemName, fieldInfo.SystemName)))
            {
                throw new CircularReferenceException("Circular reference detected.");
            }

            var fieldDefinition = new ReferenceDisplayFieldDefinition
            {
                Name = fieldInfo.Name,
                SystemName = fieldInfo.SystemName,
                ColumnType = fieldInfo.FieldType.ColumnType,
                DefinedIn = GetProcessDefinition(publishedProcess),
            };

            var tuple = Tuple.Create(fieldDefinition.DefinedIn.SystemName, fieldDefinition.SystemName);

            try
            {
                context.VisitedFields.Add(tuple);

                if (fieldDefinition.IsRef)
                {
                    var crStep = (CrossRefRequiredStepEdit)fieldInfo.StepList.FirstOrDefault(s => s is CrossRefRequiredStepEdit);

                    if (crStep == null || !crStep.CrossRefProcessId.HasValue)
                        throw new InvalidReferenceFieldExpcetion(fieldDefinition.DefinedIn.SystemName, fieldDefinition.SystemName, "Cross reference process is null.");

                    if (crStep.AllowMultiple)
                        fieldDefinition.ColumnType = ColumnTypes.MultiReference;

                    var referencedProcess = Cache.GetProcessInfo(crStep.CrossRefProcessId.Value);

                    fieldDefinition.ReferencedProcess = GetProcessDefinition(referencedProcess);

                    if (fieldDefinition.ColumnType == ColumnTypes.MultiReference && !string.IsNullOrEmpty(crStep.LinkFieldSystemName))
                    {
                        var referenceField = GetJoinField(referencedProcess.SystemName, crStep.LinkFieldSystemName);

                        if (referenceField.ColumnType != ColumnTypes.Reference)
                            throw new InvalidReferenceFieldExpcetion(fieldDefinition.DefinedIn.SystemName, fieldDefinition.SystemName, "Invalid link field type.");

                        if (referenceField.ReferencedProcess.SystemName != fieldDefinition.DefinedIn.SystemName)
                            throw new InvalidReferenceFieldExpcetion(fieldDefinition.DefinedIn.SystemName, fieldDefinition.SystemName, "Invalid link field.");

                        fieldDefinition.ReferenceField = referenceField;
                    }

                    var order = 0;
                    ReferenceDisplayFieldDefinition fd;

                    foreach (var displayField in crStep.SelectedFields)
                    {
                        fd = GetFieldDefinition(context, referencedProcess.SystemName, displayField.FullPath, throwOnError);

                        ++order;
                        fd.Order = order;
                        fd.Guid = displayField.FieldGuid;
                        fd.ShowOnDetails = true;
                        fd.ShowOnSearch = false;
                        fieldDefinition.Subfields.Add(fd);
                    }

                    fd = fieldDefinition.Subfields.FirstOrDefault(x => x.FullPath == crStep.DisplayFieldName);

                    if (fd != null)
                        fd.ShowOnSearch = true;
                    else
                    {
                        fd = GetFieldDefinition(context, referencedProcess.SystemName, crStep.DisplayFieldName, throwOnError);

                        fd.Order = 1;
                        fd.Guid = Guid.NewGuid();
                        fd.ShowOnDetails = false;
                        fd.ShowOnSearch = true;
                        fieldDefinition.Subfields.Add(fd);
                    }
                }

                if (fieldDefinition.IsReverseRef)
                {
                    var rcrStep = (ReverseCrossRefRequiredStepEdit)fieldInfo.StepList.FirstOrDefault(s => s is ReverseCrossRefRequiredStepEdit);
                    var rcrOptions = (ReverseCrossRefOptionsStepEdit)fieldInfo.StepList.FirstOrDefault(s => s is ReverseCrossRefOptionsStepEdit);

                    if (rcrStep == null || rcrOptions == null || !rcrStep.ReverseCrossRefProcessId.HasValue)
                        throw new InvalidReferenceFieldExpcetion(
                            fieldDefinition.DefinedIn.SystemName,
                            fieldDefinition.SystemName,
                            "Reverse cross reference process is null.");

                    var referencedProcess = Cache.GetProcessInfo(rcrStep.ReverseCrossRefProcessId.Value);

                    var crStep = Cache.GetCrossReferenceRequiredStep(referencedProcess.SystemName, rcrStep.CrossRefFieldName);
                    if (!crStep.CrossRefProcessId.HasValue)
                        throw new InvalidReferenceFieldExpcetion(
                            fieldDefinition.DefinedIn.SystemName,
                            fieldDefinition.SystemName,
                            "Cross reference process is null.");

                    fieldDefinition.ShowLatestVersion = rcrOptions.ShowLatestVersion && referencedProcess.ProcessOption == ProcessOption.VersionEnabled;
                    fieldDefinition.ReferenceField = new ReferenceJoinFieldDefinition
                    {
                        SystemName = rcrStep.CrossRefFieldName,
                        ColumnType =
                            crStep.AllowMultiple
                                ? ColumnTypes.MultiReference
                                : ColumnTypes.Reference,
                        DefinedIn = GetProcessDefinition(referencedProcess),
                        ReferencedProcess = GetProcessDefinition(publishedProcess)
                    };

                    var order = 0;
                    ReferenceDisplayFieldDefinition fd;

                    foreach (var displayField in rcrStep.DisplayFields.OrderBy(df => df.Order))
                    {
                        fd = GetFieldDefinition(context, referencedProcess.SystemName, displayField.FullPath, throwOnError);

                        if (fd != null)
                        {
                            ++order;
                            fd.Order = order;
                            fd.Guid = displayField.Guid;
                            fd.ShowOnDetails = true;
                            fd.ShowOnSearch = false;
                            fieldDefinition.Subfields.Add(fd);
                        }
                    }

                    fd = fieldDefinition.Subfields.FirstOrDefault(x => x.FullPath == rcrStep.DisplayFieldName);

                    if (fd != null)
                    {
                        fd.ShowOnSearch = true;
                    }
                    else
                    {
                        fd = GetFieldDefinition(context, referencedProcess.SystemName, rcrStep.DisplayFieldName, throwOnError);

                        fd.Order = 1;
                        fd.Guid = Guid.NewGuid();
                        fd.ShowOnDetails = false;
                        fd.ShowOnSearch = true;

                        fieldDefinition.Subfields.Add(fd);
                    }
                }

                if (fieldDefinition.ColumnType == ColumnTypes.Numeric)
                {
                    var numericStep = (NumericRequiredStepEdit)fieldInfo.StepList.First(s => s is NumericRequiredStepEdit);

                    fieldDefinition.NumericType = NumericTypes.Numeric;

                    if (numericStep.NumberOfDigits == 0 && numericStep.Minimum >= int.MinValue && numericStep.Maximum <= int.MaxValue && numericStep.NumericType == NumericTypes.Numeric)
                        fieldDefinition.ColumnType = ColumnTypes.Integer;

                    fieldDefinition.NumericType = numericStep.NumericType;
                    fieldDefinition.NumberOfDigits = numericStep.NumberOfDigits;
                }

                if (fieldDefinition.ColumnType == ColumnTypes.DateTime)
                {
                    var dateTimeStep = (DateRequiredSettingsStepEdit)fieldInfo.StepList.First(s => s is DateRequiredSettingsStepEdit);
                    fieldDefinition.DateTimeFormat = DateTimeFormat.DateTime;

                    DateTimeFormat format;

                    if (Enum.TryParse(dateTimeStep.SelectedDateTimeFormat, true, out format))
                    {
                        fieldDefinition.DateTimeFormat = format;
                    }
                }

                if (fieldDefinition.ColumnType == ColumnTypes.Boolean)
                {
                    var checkboxStep = (CheckboxOptionsStepEdit)fieldInfo.StepList.First(s => s is CheckboxOptionsStepEdit);
                    fieldDefinition.MainLabel = checkboxStep.MainLabel;
                    fieldDefinition.UndefinedLabel = checkboxStep.UndefinedLabel;
                    fieldDefinition.TrueLabel = checkboxStep.TrueLabel;
                    fieldDefinition.FalseLabel = checkboxStep.FalseLabel;
                    fieldDefinition.IsSwitchToggle = checkboxStep.IsSwitchToggle;
                }

                if (fieldDefinition.ColumnType == ColumnTypes.Image)
                {
                    var pictureStep = fieldInfo.StepList.OfType<PictureSetupStepEdit>().First();

                    fieldDefinition.SearchImageWidth = pictureStep.SearchWidth;
                    fieldDefinition.SearchImageHeight = pictureStep.SearchHeight;
                    fieldDefinition.DetailsImageWidth = pictureStep.DetailsWidth;
                    fieldDefinition.DetailsImageHeight = pictureStep.DetailsHeight;
                    fieldDefinition.UseOriginalImageSize = pictureStep.UseOriginalSize;
                }
            }
            finally
            {
                context.VisitedFields.Remove(tuple);
            }

            return fieldDefinition;
        }
Example #4
0
        private ReferenceDisplayFieldDefinition GetDisplayField(ReferenceHelperContext context, FieldInfoDto fieldInfo, bool throwOnError)
        {
            if (context.VisitedFields.Contains(Tuple.Create(fieldInfo.DefinedIn, fieldInfo.SystemName)))
                throw new CircularReferenceException("Circular reference detected.");

            var publishedProcess = Cache.GetProcessInfo(fieldInfo.DefinedIn);
            var fieldDefinition = new ReferenceDisplayFieldDefinition
                                      {
                                          Name = fieldInfo.Name,
                                          SystemName = fieldInfo.SystemName,
                                          ColumnType = (ColumnTypes)Enum.Parse(typeof(ColumnTypes), fieldInfo.DataType),
                                          DefinedIn = GetProcessDefinition(publishedProcess),
                                          IsRichTextField = fieldInfo.IsRichTextField,
                                      };

            if (fieldDefinition.SystemName == Constants.CurrentStateColumnName)
            {
                fieldDefinition.ReferencedProcess = GetProcessDefinition(Constants.StateProcessName);

                var fd = GetFieldDefinition(context, Constants.StateProcessName, Constants.Name, throwOnError);
                fd.Order = 1;
                fd.Guid = Guid.NewGuid();
                fd.ShowOnDetails = true;
                fd.ShowOnSearch = true;

                fieldDefinition.Subfields.Add(fd);

                return fieldDefinition;
            }

            if (fieldDefinition.SystemName.Equals(Constants.VersionDate))
            {
                fieldDefinition.DateTimeFormat = DateTimeFormat.DateTime;
                return fieldDefinition;
            }

            // System fields are not stored in the database.
            if (fieldDefinition.SystemName.Equals(Constants.IdColumnName, StringComparison.OrdinalIgnoreCase)
                || fieldDefinition.SystemName.Equals(Constants.VersionNumber))
            {
                return fieldDefinition;
            }

            var tuple = Tuple.Create(fieldDefinition.DefinedIn.SystemName, fieldDefinition.SystemName);

            try
            {
                context.VisitedFields.Add(tuple);

                if (fieldDefinition.IsRef)
                {
                    var crStep = Cache.GetCrossReferenceRequiredStep(fieldDefinition.DefinedIn.SystemName, fieldDefinition.SystemName);

                    if (!crStep.CrossRefProcessId.HasValue)
                        throw new InvalidReferenceFieldExpcetion(fieldDefinition.DefinedIn.SystemName, fieldDefinition.SystemName, "Cross reference process is null.");

                    var referencedProcess = Cache.GetProcessInfo(crStep.CrossRefProcessId.Value);

                    fieldDefinition.ReferencedProcess = GetProcessDefinition(referencedProcess);

                    if (fieldDefinition.ColumnType == ColumnTypes.MultiReference && !string.IsNullOrEmpty(crStep.LinkFieldSystemName))
                    {
                        var referenceField = GetJoinField(referencedProcess.SystemName, crStep.LinkFieldSystemName);

                        if (referenceField.ColumnType != ColumnTypes.Reference)
                            throw new InvalidReferenceFieldExpcetion(fieldInfo.DefinedIn, fieldInfo.SystemName, "Invalid link field type.");

                        if (referenceField.ReferencedProcess.SystemName != fieldInfo.DefinedIn)
                            throw new InvalidReferenceFieldExpcetion(fieldInfo.DefinedIn, fieldInfo.SystemName, "Invalid link field.");

                        fieldDefinition.ReferenceField = referenceField;
                    }

                    var order = 0;
                    ReferenceDisplayFieldDefinition fd;

                    foreach (var displayField in crStep.DisplayFields)
                    {
                        fd = GetFieldDefinition(context, referencedProcess.SystemName, displayField.FullPath, throwOnError);

                        ++order;
                        fd.Order = order;
                        fd.Guid = displayField.Guid;
                        fd.ShowOnDetails = true;
                        fd.ShowOnSearch = false;
                        fieldDefinition.Subfields.Add(fd);
                    }

                    fd = fieldDefinition.Subfields.FirstOrDefault(x => x.FullPath == crStep.DisplayFieldName);

                    if (fd != null)
                    {
                        fd.ShowOnSearch = true;
                    }
                    else
                    {
                        fd = GetFieldDefinition(context, referencedProcess.SystemName, crStep.DisplayFieldName, throwOnError);

                        fd.Order = 1;
                        fd.Guid = Guid.NewGuid();
                        fd.ShowOnDetails = false;
                        fd.ShowOnSearch = true;
                        fieldDefinition.Subfields.Add(fd);
                    }
                }

                if (fieldDefinition.IsReverseRef)
                {
                    var rcrStep = Cache.GetReverseCrossReferenceRequiredStep(fieldDefinition.DefinedIn.SystemName, fieldDefinition.SystemName);

                    if (!rcrStep.ReverseCrossRefProcessId.HasValue)
                        throw new InvalidReferenceFieldExpcetion(
                            fieldDefinition.DefinedIn.SystemName,
                            fieldDefinition.SystemName,
                            "Reverse cross reference process is null.");

                    var referencedProcess = Cache.GetProcessInfo(rcrStep.ReverseCrossRefProcessId.Value);

                    var rcrOptions = Cache.GetReverseCrossReferenceOptionsStep(fieldDefinition.DefinedIn.SystemName, fieldDefinition.SystemName);

                    var referenceField = GetJoinField(referencedProcess.SystemName, rcrStep.CrossRefFieldName);

                    fieldDefinition.ShowLatestVersion = rcrOptions.ShowLatestVersion && referencedProcess.ProcessOption == ProcessOption.VersionEnabled;
                    fieldDefinition.ReferenceField = referenceField;

                    var order = 0;
                    ReferenceDisplayFieldDefinition fd;

                    foreach (var displayField in rcrStep.SelectedDisplayFields.OrderBy(df => df.Order))
                    {
                        fd = GetFieldDefinition(context, referencedProcess.SystemName, displayField.FullPath, throwOnError);

                        if (fd != null)
                        {
                            ++order;
                            fd.Order = order;
                            fd.Guid = displayField.Guid;
                            fd.ShowOnDetails = true;
                            fd.ShowOnSearch = false;
                            fieldDefinition.Subfields.Add(fd);
                        }
                    }

                    fd = fieldDefinition.Subfields.FirstOrDefault(x => x.FullPath == rcrStep.DisplayFieldName);

                    if (fd != null)
                        fd.ShowOnSearch = true;
                    else
                    {
                        fd = GetFieldDefinition(context, referencedProcess.SystemName, rcrStep.DisplayFieldName, throwOnError);

                        fd.Order = 1;
                        fd.Guid = Guid.NewGuid();
                        fd.ShowOnDetails = false;
                        fd.ShowOnSearch = true;

                        fieldDefinition.Subfields.Add(fd);
                    }
                }

                if (fieldDefinition.ColumnType == ColumnTypes.Numeric)
                {
                    var numericStep = Cache.GetNumericRequiredStep(fieldDefinition.DefinedIn.SystemName, fieldDefinition.SystemName);

                    fieldDefinition.NumericType = NumericTypes.Numeric;

                    if (numericStep.NumberOfDigits == 0 && numericStep.Minimum >= int.MinValue && numericStep.Maximum <= int.MaxValue
                        && (NumericTypes)numericStep.NumericType == NumericTypes.Numeric)
                    {
                        fieldDefinition.ColumnType = ColumnTypes.Integer;
                    }

                    fieldDefinition.NumericType = (NumericTypes)numericStep.NumericType;
                    fieldDefinition.NumberOfDigits = numericStep.NumberOfDigits;
                }

                if (fieldDefinition.ColumnType == ColumnTypes.DateTime)
                {
                    var dateTimeStep = Cache.GetDateTimeRequiredStep(fieldDefinition.DefinedIn.SystemName, fieldDefinition.SystemName);

                    fieldDefinition.DateTimeFormat = DateTimeFormat.DateTime;

                    DateTimeFormat format;

                    if (Enum.TryParse(dateTimeStep.DateTimeFormat, true, out format))
                        fieldDefinition.DateTimeFormat = format;
                }

                if (fieldDefinition.ColumnType == ColumnTypes.Boolean)
                {
                    var checkboxStep = Cache.GetCheckboxOptionsStep(fieldDefinition.DefinedIn.SystemName, fieldDefinition.SystemName);

                    fieldDefinition.MainLabel = checkboxStep.MainLabel;
                    fieldDefinition.UndefinedLabel = checkboxStep.IsSwitchToggle ? checkboxStep.UndefinedLabel : string.Empty;
                    fieldDefinition.TrueLabel = checkboxStep.IsSwitchToggle ? checkboxStep.TrueLabel : true.ToString();
                    fieldDefinition.FalseLabel = checkboxStep.IsSwitchToggle ? checkboxStep.FalseLabel : false.ToString();
                    fieldDefinition.IsSwitchToggle = checkboxStep.IsSwitchToggle;
                }

                if (fieldDefinition.ColumnType == ColumnTypes.Image)
                {
                    var pictureStep = Cache.GetPictureStep(fieldDefinition.DefinedIn.SystemName, fieldDefinition.SystemName);

                    fieldDefinition.SearchImageWidth = pictureStep.SearchWidth;
                    fieldDefinition.SearchImageHeight = pictureStep.SearchHeight;
                    fieldDefinition.DetailsImageWidth = pictureStep.DetailsWidth;
                    fieldDefinition.DetailsImageHeight = pictureStep.DetailsHeight;
                    fieldDefinition.UseOriginalImageSize = pictureStep.UseOriginalSize;
                }
            }
            finally
            {
                context.VisitedFields.Remove(tuple);
            }

            return fieldDefinition;
        }
Example #5
0
        public ReferenceDisplayFieldDefinition GetCurrentStateFieldDefinition(ReferenceHelperContext context, ProcessEdit publishedProcess)
        {
            if (context.VisitedFields.Contains(Tuple.Create(publishedProcess.SystemName, Constants.CurrentStateColumnName)))
            {
                throw new CircularReferenceException("Circular reference detected.");
            }

            var fieldDefinition = new ReferenceDisplayFieldDefinition
                                      {
                                          Name = "Current State", //LanguageService.Translate("CurrentState"),
                                          SystemName = Constants.CurrentStateColumnName,
                                          ColumnType = ColumnTypes.Reference,
                                          DefinedIn = GetProcessDefinition(publishedProcess),
                                          ReferencedProcess = GetProcessDefinition(Constants.StateProcessName),
                                      };

            var tuple = Tuple.Create(fieldDefinition.DefinedIn.SystemName, fieldDefinition.SystemName);

            try
            {
                context.VisitedFields.Add(tuple);

                var subfield = new ReferenceDisplayFieldDefinition
                                   {
                                       Name = Constants.Name,
                                       SystemName = Constants.Name,
                                       ColumnType = ColumnTypes.String,
                                       DefinedIn = GetProcessDefinition(fieldDefinition.ReferencedProcess.SystemName),
                                       Guid = Guid.NewGuid(),
                                       ShowOnDetails = true,
                                       ShowOnSearch = true,
                                   };

                fieldDefinition.Subfields.Add(subfield);
            }
            finally
            {
                context.VisitedFields.Remove(tuple);
            }

            return fieldDefinition;
        }