Beispiel #1
0
        public static PartnerAtrributes GetPartnerAttribuesByVendor(int vendorId, string vendorName, string source)
        {
            var result = new PartnerAtrributes();

            using (var connection = new OracleConnection(FscApplication.Current.Settings.FscConnectionString))
            {
                connection.Open();
                result = connection.QueryFirst <PartnerAtrributes>($"select vendor_id VendorId, vendor_name Name, request_type Request, partner_order_format PartnerFormat, order_action Action, product_family Family, partner_order_id PartnerId, partner_order_name Partner, ordering_source Source, PREORDER_VALIDATION PreOrderValidation from " +
                                                                   $"fsc_dba.offnet_partner_definition where vendor_id = :vendorId and Vendor_name = :vendorName and ordering_source = :source", new { vendorId, vendorName, source });
                connection.Close();
            }
            return(result);
        }
Beispiel #2
0
        public override void Apply(PartnerServicePackage package, string iteration, ResolveOffnetServiceSet rss)
        {
            var sk = package.GetService(rss.GetTagName(Concat(_sTag, iteration)));

            if (sk == null)
            {
                Debugger.Log(new PcatExceptionInfo($"Service {_sTag} not found!")
                {
                    StackTrace = this.ToString()
                });
                return;
            }

            AttributeValue value;
            PartnerKeyWeb  key;
            var            patts = new PartnerAtrributes();

            patts.FromWeb(package.Partner);
            StringBuilder debugDetail = new StringBuilder();

            if (_pTag == CONSTANT)
            {
                value = CreateAttribute(sk, _pAtt);
                key   = package.Partner;

                debugDetail.Append("Constant");
            }
            else
            {
                key = rss.GetPartner(_pTag);
                var av = patts.GetAttributeValue(_pAtt);
                if (av == null)
                {
                    // if the product doesn't have a value, let's remove it from the service in case an old value is sitting there
                    sk.RemoveAttribute(_sAttName);
                    Debugger.Log(new DebugAttributeInfo(sk?.Id * -1, _sAttName, null, DebugAttributeInfoSourceType.Rule, DebugAttributeInfoFunctionType.GetValue, null)
                    {
                        RuleText = $"Removed because {_pTag}.{_pAtt} doesn't exist or is null"
                    });
                    return;
                }
                value = CreateAttribute(sk, av);

                debugDetail.Append($"Copy from {_pTag}.{_pTag}");
            }
            if (value != null)
            {
                var oldValue = sk.GetValue(_sAttName, SearchOptions.ALL_TRUE);
                var changed  = (oldValue != null) ? false : AttributeChanged(oldValue, value);
                if (_strip)
                {
                    //We need to remove everything but the number from the value before we use it...
                    value.Value = ParseNumber(value.Value);
                    debugDetail.Append(", value stripped to just a number");
                }
            }
            else
            {
                debugDetail.Append($", {_sTag}.{_sAttName} is not applicable");
            }

            sk.AddValue(_sAttName, value);
            Debugger.Log(new DebugAttributeInfo(sk?.Id + 50000, _sAttName, value?.Value, DebugAttributeInfoSourceType.Rule, DebugAttributeInfoFunctionType.GetValue, null)
            {
                RuleText = debugDetail.ToString()
            });
        }
Beispiel #3
0
        public static PartnerServicePackage ResolveOffnet(PartnerServicePackage oldPackage, out string error)
        {
            var NewPackage        = new PartnerServicePackage();
            var partnerAttributes = new PartnerAtrributes();

            var _e = new Exception();

            error = null;
            var validInput = oldPackage.Partner.IsValidInput();

            if (oldPackage.Partner == null)
            {
                _e.Data.Add("Custom Msg", "Partner key is cannot be null");
                throw (_e);
            }
            try
            {
                //Fetch and populate Partner key if Partner does not exist
                if (oldPackage.Partner.PartnerOrderId == 0 || String.IsNullOrEmpty(oldPackage.Partner.PartnerOrderName))
                {
                    if (!validInput.valid)
                    {
                        _e.Data.Add("Custom Msg", validInput.message);
                        throw (_e);
                    }
                    partnerAttributes.FromWeb(oldPackage.Partner);
                    NewPackage.Partner = partnerAttributes.Get(partnerAttributes.VendorId, partnerAttributes.Name, partnerAttributes.Source);
                }
                //Verify if all the partner attributes values are set correctly
                else if (!oldPackage.Partner.HasAllAttributes().valid)
                {
                    partnerAttributes.FromWeb(oldPackage.Partner);
                    NewPackage.Partner = partnerAttributes.Get(partnerAttributes.VendorId, partnerAttributes.Name, partnerAttributes.Source);
                }
                else
                {
                    NewPackage.Partner = oldPackage.Partner;
                }

                //Parse rules and get services and Populate the service key
                if (oldPackage.Services != null)
                {
                    {
                        //We need to make sure that each service attribute has its type assigned.
                        foreach (var sk in oldPackage.Services.Values)
                        {
                            var sc = GetServiceConfiguration(sk);
                            foreach (var name in sk.Values.Keys)
                            {
                                var a = sk.Values[name];
                                if (a.Type == null)
                                {
                                    a.Type = sc.GetAttributeType(name);
                                }
                            }
                        }

                        List <string> removedAttributes = new List <string>();
                        //It is possible that some service attributes have invalid values.  We need to remove their value if they are not valid.
                        foreach (var sk in oldPackage.Services.Values)
                        {
                            var listAttributes = OffnetServiceAttributes.Get(sk, true);
                            // GetAttributes(sk, ValidationStage.Design).Where(a => a.Type.Equals(AttributeType.List)).ToList();
                            foreach (var la in listAttributes)
                            {
                                var currentValue = sk.GetAttributeValue("la", SearchOptions.ALL_FALSE);
                                if (currentValue != null && !la.Values.Contains(new AttributeValue(currentValue)))
                                {
                                    sk.RemoveAttribute(la.Name);
                                    removedAttributes.Add(la.Name);
                                }
                            }

                            var names = listAttributes.Select(la => la.Name).ToList();
                            var currentListAttributes = sk.Values.Where(v => AttributeType.List.Equals(v.Value.Type)).Select(v => v.Key).ToList();
                            foreach (var name in currentListAttributes)
                            {
                                if (!names.Contains(name))
                                {
                                    sk.RemoveAttribute(name);
                                    removedAttributes.Add(name);
                                }
                            }

                            if (removedAttributes.Count > 0)
                            {
                                // add removed attributes back with default values
                                listAttributes = OffnetServiceAttributes.Get(sk, true);
                                listAttributes = listAttributes.Where(a => a.Type.Equals(AttributeType.List)).ToList();
                                //GetAttributes(sk, ValidationStage.Design).Where(a => a.Type.Equals(AttributeType.List)).ToList();
                                foreach (string name in removedAttributes)
                                {
                                    var la = (ListAttribute)listAttributes.FirstOrDefault(a => a.Name.Equals(name) && a.Type.Equals(AttributeType.List) && ((ListAttribute)a).GetList().Count == 1);
                                    if (la != null)
                                    {
                                        sk.AddValue(name, la.GetAttributeValue());
                                    }
                                }
                            }
                        }
                    }
                }
                //When No services in the initial call
                var set = new OffnetServiceRuleSet();
                set.ApplyRules(NewPackage);

                if (NewPackage.Services != null)
                {
                    foreach (var service in NewPackage.Services.Values)
                    {
                        var attributes = OffnetServiceAttributes.Get(service, false);
                        foreach (var la in from attribute in attributes
                                 where
                                 service.GetAttributeValue(attribute.Name, SearchOptions.ALL_FALSE) == null &&
                                 attribute.Type.Equals(AttributeType.List)
                                 select(ListAttribute) attribute
                                 into la
                                 where la.GetList().Count == 1
                                 select la)
                        {
                            service.AddValue(la.Name, la.GetAttributeValue());
                        }
                    }
                }

                if (NewPackage.Services != null)
                {
                    //It is possible that the service keys have picked up some extra fields.  We need to remove them as they could cause problems with downstream applications
                    foreach (var sk in NewPackage.Services.Values)
                    {
                        var c     = GetServiceConfiguration(sk);
                        var names = sk.Values.Keys.Where(a => !c.IsConfigurableAttribute(a, sk)).ToList();
                        foreach (var n in names)
                        {
                            sk.RemoveAttribute(n);
                        }
                        // Make sure all the attributes have a type associated with them...
                        foreach (var name in sk.Values.Keys)
                        {
                            if (c.IsConfigurableAttribute(name, sk) && sk.Values[name].Type == null)
                            {
                                sk.Values[name].Type = c.GetAttributeType(name);
                            }
                        }
                    }

                    //It is possible that some service attributes have invalid values.  We need to remove their value if they are not valid.
                    foreach (var sk in oldPackage.Services.Values)
                    {
                        var listAttributes = OffnetServiceAttributes.Get(sk, false).Where(a => a.Type.Equals(AttributeType.List)).ToList();
                        //GetAttributes(sk, ValidationStage.Design).Where(a => a.Type.Equals(AttributeType.List)).ToList();
                        foreach (var la in listAttributes)
                        {
                            var currentValue = sk.GetAttributeValue(la.Name, SearchOptions.ALL_FALSE);
                            if (currentValue != null && !la.Values.Contains(new AttributeValue(currentValue)))
                            {
                                sk.RemoveAttribute(la.Name);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                throw (e);
            }
            return(NewPackage);
        }