Пример #1
0
        protected override PropertySetResult Validate(
            PropertyLite property,
            DatePropertyType propertyType,
            IValidationContext validationContext)
        {
            if (IsPropertyValueEmpty(property, propertyType) || !propertyType.IsValidate)
            {
                return(null);
            }

            var value = property.DateValue.Value;

            // Maximum.
            if (propertyType.IsValidate && value.CompareTo(propertyType.Range.End) > 0)
            {
                return(new PropertySetResult(property.PropertyTypeId, ErrorCodes.InvalidArtifactProperty, "Must be less than max value"));
            }

            // Minimum.
            if (propertyType.IsValidate && value.CompareTo(propertyType.Range.Start) < 0)
            {
                return(new PropertySetResult(property.PropertyTypeId, ErrorCodes.InvalidArtifactProperty, "Must be greater than min value"));
            }

            // Success.
            return(null);
        }
Пример #2
0
        protected override PropertySetResult Validate(PropertyLite property, UserPropertyType propertyType, IValidationContext validationContext)
        {
            var isValid = property.UsersAndGroups.All(ug => IsUserOrGroupValid(ug, validationContext));

            if (!isValid)
            {
                return(new PropertySetResult(property.PropertyTypeId, ErrorCodes.InvalidArtifactProperty, "User or group id does not exist"));
            }
            return(null);
        }
Пример #3
0
 private PropertySetResult ValidateValueCommon(PropertyLite property, T propertyType)
 {
     // if (propertyType == VersionableState.Removed)
     // {
     //    return new PropertySetResult(propertyType.Id, BusinessLayerErrorCodes.InvalidArtifactPropertyType, StringTokens.ArtifactDataProvider_ThePropertyTypeHasBeenRemoved);
     // }
     if (propertyType.IsRequired && IsPropertyValueEmpty(property, propertyType))
     {
         return(new PropertySetResult(propertyType.PropertyTypeId, ErrorCodes.InvalidArtifactProperty,
                                      "value cannot be empty"));
     }
     return(null);
 }
Пример #4
0
        /// <summary>
        /// Validates the specified property.
        /// </summary>
        protected override PropertySetResult Validate(PropertyLite property, TextPropertyType propertyType, IValidationContext validationContext)
        {
            if (property.ChoiceIds?.Count > 0)
            {
                return(null);
            }

            if (property.TextOrChoiceValue == null && propertyType.Predefined == PropertyTypePredefined.Name)
            {
                return(new PropertySetResult(property.PropertyTypeId, ErrorCodes.InvalidArtifactProperty, "Property 'Name' value is required"));
            }

            // NOTE: No validation is provided for propertyType.IsRichText, propertyType.AllowMultiple
            return(null); // Success
        }
Пример #5
0
        protected override PropertySetResult Validate(
            PropertyLite property,
            ChoicePropertyType propertyType,
            IValidationContext validationContext)
        {
            if (IsPropertyValueEmpty(property, propertyType) && propertyType.IsRequired)
            {
                return(new PropertySetResult(property.PropertyTypeId, ErrorCodes.InvalidArtifactProperty, "Custom value or choices should be specified if the field is required."));
            }

            if (!String.IsNullOrEmpty(property.TextOrChoiceValue) && property.ChoiceIds.Count != 0)
            {
                return(new PropertySetResult(property.PropertyTypeId, ErrorCodes.InvalidArtifactProperty, "Custom value and choices cannot be specified simultaneously."));
            }

            if (propertyType.IsValidate && !String.IsNullOrEmpty(property.TextOrChoiceValue))
            {
                return(new PropertySetResult(property.PropertyTypeId, ErrorCodes.InvalidArtifactProperty, "Property does not support custom values."));
            }

            if (!propertyType.AllowsCustomValue() && property.ChoiceIds.Count == 0 && propertyType.IsRequired)
            {
                return(new PropertySetResult(property.PropertyTypeId, ErrorCodes.InvalidArtifactProperty, "Required property value should be specified."));
            }

            if (propertyType.AllowMultiple != true && property.ChoiceIds.Count > 1)
            {
                return(new PropertySetResult(property.PropertyTypeId, ErrorCodes.InvalidArtifactProperty, "Only single choice is allowed."));
            }

            var items            = propertyType.ValidValues;
            var hasInvalidChoice = property.ChoiceIds.Any(c => items.All(i => i.Sid != c));

            if (hasInvalidChoice)
            {
                return(new PropertySetResult(property.PropertyTypeId, ErrorCodes.InvalidArtifactProperty, "Specified choice value does not exist."));
            }

            // Success.
            return(null);
        }
Пример #6
0
        protected override PropertySetResult Validate(PropertyLite property, NumberPropertyType propertyType, IValidationContext validationContext)
        {
            if (IsPropertyValueEmpty(property, propertyType))
            {
                return(null);
            }

            decimal value = property.NumberValue.Value;

            if (!propertyType.IsValidate)
            {
                return(null);
            }

            // Maximum.
            if (value.CompareTo(propertyType.Range.End) > 0)
            {
                return(new PropertySetResult(property.PropertyTypeId, ErrorCodes.InvalidArtifactProperty, "Must be less than max value"));
            }

            // Minimum.
            if (value.CompareTo(propertyType.Range.Start) < 0)
            {
                return(new PropertySetResult(property.PropertyTypeId, ErrorCodes.InvalidArtifactProperty, "Must be greater than min value"));
            }

            // Decimal places.
            var stringValue   = value.ToString("G29", CultureInfo.CurrentCulture);
            var i             = stringValue.IndexOf(CultureInfo.InvariantCulture.NumberFormat.NumberDecimalSeparator, StringComparison.OrdinalIgnoreCase);
            var decimalPlaces = (i == -1) ? 0 : stringValue.Length - i - 1;

            if (decimalPlaces > propertyType.DecimalPlaces)
            {
                return(new PropertySetResult(property.PropertyTypeId, ErrorCodes.InvalidArtifactProperty, "Decimal places greater than maximum configured"));
            }

            // Success.
            return(null);
        }
Пример #7
0
        /// <summary>
        /// Validates the specified property.
        /// </summary>
        public virtual PropertySetResult Validate(PropertyLite property, List <WorkflowPropertyType> propertyTypes, IValidationContext validationContext)
        {
            if (propertyTypes.All(a => a.InstancePropertyTypeId.Value != property.PropertyTypeId))
            {
                return(null);
            }

            var saveType =
                propertyTypes.FirstOrDefault(a => a.InstancePropertyTypeId.Value == property.PropertyTypeId) as T;

            if (saveType == null)
            {
                return(null);
            }

            var commonError = ValidateValueCommon(property, saveType);

            if (commonError != null)
            {
                return(commonError);
            }

            return(Validate(property, saveType, validationContext));
        }
Пример #8
0
 /// <summary>
 /// Determines whether the property value is empty.
 /// </summary>
 protected abstract bool IsPropertyValueEmpty(PropertyLite property, T propertyType);
Пример #9
0
 /// <summary>
 /// Validates the specified property.
 /// </summary>
 protected abstract PropertySetResult Validate(PropertyLite property, T propertyType, IValidationContext validationContext);
Пример #10
0
 /// <summary>
 /// Determines whether the property value is empty.
 /// </summary>
 protected override bool IsPropertyValueEmpty(PropertyLite property, TextPropertyType propertyType)
 {
     return(string.IsNullOrEmpty(property.TextOrChoiceValue));
 }
Пример #11
0
 /// <summary>
 /// Determines whether the property value is empty.
 /// </summary>
 protected override bool IsPropertyValueEmpty(PropertyLite property, DatePropertyType propertyType)
 {
     return(!property.DateValue.HasValue);
 }
Пример #12
0
 /// <summary>
 /// Determines whether the property value is empty.
 /// </summary>
 protected override bool IsPropertyValueEmpty(PropertyLite property, NumberPropertyType propertyType)
 {
     return(!property.NumberValue.HasValue);
 }
Пример #13
0
 protected override bool IsPropertyValueEmpty(PropertyLite property, UserPropertyType propertyType)
 {
     return(!property.UsersAndGroups.Any());
 }
Пример #14
0
        /// <summary>
        /// Determines whether the property value is empty.
        /// </summary>
        protected override bool IsPropertyValueEmpty(PropertyLite property, ChoicePropertyType propertyType)
        {
            var hasCustomValue = !propertyType.IsValidate && !String.IsNullOrEmpty(property.TextOrChoiceValue);

            return(!hasCustomValue && !property.ChoiceIds.Any());
        }