Exemplo n.º 1
0
        /// <summary>
        /// Persists this mapping filter to the specified XmlElement
        /// </summary>
        /// <param name="filter">The filter to save</param>
        /// <param name="element"></param>
        internal static void Save(MappingsFilter filter,
                                  XmlElement element)
        {
            if (filter != null && filter.HasVersionFilter)
            {
                element.SetAttribute("sifVersion", filter.SifVersion);
            }
            else
            {
                element.RemoveAttribute("sifVersion");
            }

            if (filter != null && filter.HasDirectionFilter)
            {
                element.SetAttribute("direction", filter.Direction.ToString("G"));
                switch (filter.Direction)
                {
                case MappingDirection.Inbound:
                    element.SetAttribute("direction", "inbound");
                    break;

                case MappingDirection.Outbound:
                    element.SetAttribute("direction", "outbound");
                    break;
                }
            }
            else
            {
                element.RemoveAttribute("direction");
            }
        }
Exemplo n.º 2
0
        /**
         * Writes the mapping filter to an XML Element
         * @param filter
         * @param element The XML Element to write the filter to
         */

        private void WriteFilterToXml(MappingsFilter filter, XmlElement element)
        {
            if (filter == null)
            {
                element.RemoveAttribute(ATTR_SIFVERSION);
                element.RemoveAttribute(ATTR_DIRECTION);
            }
            else
            {
                if (filter.HasVersionFilter)
                {
                    element.SetAttribute(ATTR_SIFVERSION, filter.SifVersion);
                }
                else
                {
                    element.RemoveAttribute(ATTR_SIFVERSION);
                }

                MappingDirection direction = filter.Direction;
                if (direction == MappingDirection.Inbound)
                {
                    element.SetAttribute(ATTR_DIRECTION, "inbound");
                }
                else if (direction == MappingDirection.Outbound)
                {
                    element.SetAttribute(ATTR_DIRECTION, "outbound");
                }
                else
                {
                    element.RemoveAttribute(ATTR_DIRECTION);
                }
            }
        }
Exemplo n.º 3
0
        /**
         * Evaluates the filters defined for this FieldMapping. If any of the filters
         * evaluate to false, the FieldMapping is not added
         *
         * @param fieldMapping The FieldMapping to add
         * @return True if the FieldMapping was added. Otherwise false
         */

        private bool AddRule(FieldMapping fieldMapping)
        {
            MappingsFilter filt = fieldMapping.Filter;

            //	Filter out this rule?
            if (filt != null)
            {
                if (!filt.EvalDirection(fDirection) ||
                    !filt.EvalVersion(fSIFVersion))
                {
                    return(false);
                }
            }

            fFieldMappings.Add(fieldMapping);
            return(true);
        }
Exemplo n.º 4
0
        /// <summary>  Creates a copy this ObjectMapping instance.
        ///
        /// </summary>
        /// <returns> A "deep copy" of this object
        /// </returns>
        public virtual FieldMapping Copy(ObjectMapping newParent)
        {
            FieldMapping m = new FieldMapping();

            if (fNode != null && newParent.fNode != null)
            {
                m.fNode = (XmlElement)newParent.fNode.OwnerDocument.ImportNode(fNode, false);
            }

            m.FieldName    = fField;
            m.DefaultValue = fDefValue;
            m.Alias        = fAlias;
            m.ValueSetID   = fValueSet;
            m.NullBehavior = fNullBehavior;

            if (fFilter != null)
            {
                MappingsFilter filtCopy = new MappingsFilter();
                filtCopy.fVersion   = fFilter.fVersion;
                filtCopy.fDirection = fFilter.fDirection;
                m.Filter            = filtCopy;
            }

            m.DataType = fDatatype;

            if (fRule != null)
            {
                m.fRule = fRule.Copy(m);
            }
            else
            {
                m.fRule = null;
            }

            return(m);
        }
Exemplo n.º 5
0
        /**
         * Writes the values of this FieldMapping to the specified XML Element
         *
         * @param element The XML Element to write values to
         */

        public void ToXml(XmlElement element)
        {
            XmlUtils.SetOrRemoveAttribute(element, ATTR_NAME, fField);
            if (fDatatype == SifDataType.String)
            {
                element.RemoveAttribute(ATTR_DATATYPE);
            }
            else
            {
                element.SetAttribute(ATTR_DATATYPE, fDatatype.ToString());
            }
            XmlUtils.SetOrRemoveAttribute(element, ATTR_DEFAULT, fDefValue);
            XmlUtils.SetOrRemoveAttribute(element, ATTR_ALIAS, fAlias);
            XmlUtils.SetOrRemoveAttribute(element, ATTR_VALUESET, fValueSet);

            MappingsFilter filt = Filter;

            if (filt != null)
            {
                WriteFilterToXml(filt, element);
            }
            WriteNullBehaviorToXml(fNullBehavior, element);
            fRule.ToXml(element);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Creates an returns a mappings filter from the specified XmlElement, or null if there is no filter defined
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        internal static MappingsFilter Load(XmlElement node)
        {
            string filtVer = node.GetAttribute("sifVersion");
            string filtDir = node.GetAttribute("direction");

            if (filtVer.Length > 0 || filtDir.Length > 0)
            {
                MappingsFilter filt = new MappingsFilter();

                if (filtVer.Length > 0)
                {
                    filt.SifVersion = filtVer;
                }

                if (filtDir.Length > 0)
                {
                    try
                    {
                        filt.Direction =
                            (MappingDirection)
                            Enum.Parse(typeof(MappingDirection), filtDir, true);
                    }
                    catch (Exception ex)
                    {
                        throw new AdkConfigException
                                  ("Field mapping rule specifies an unknown Direction flag: '" + filtDir +
                                  "'", ex);
                    }
                }
                return(filt);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 7
0
        /**
         * Creates a new FieldMapping instance and populates its properties from
         * the given XML Element
         * @param parent
         * @param element
         * @return a new FieldMapping instance
         * @throws ADKConfigException If the FieldMapping cannot read expected
         *      values from the DOM Node
         */

        public static FieldMapping FromXml(
            ObjectMapping parent,
            XmlElement element)
        {
            if (element == null)
            {
                throw new ArgumentException("Argument: 'element' cannot be null");
            }

            String       name = element.GetAttribute(ATTR_NAME);
            FieldMapping fm   = new FieldMapping();

            fm.SetNode(element);
            fm.FieldName    = name;
            fm.DefaultValue = XmlUtils.GetAttributeValue(element, ATTR_DEFAULT);
            fm.Alias        = XmlUtils.GetAttributeValue(element, ATTR_ALIAS);
            fm.ValueSetID   = XmlUtils.GetAttributeValue(element, ATTR_VALUESET);

            String ifNullBehavior = element.GetAttribute(ATTR_IFNULL);

            if (ifNullBehavior.Length > 0)
            {
                if (String.Compare(ifNullBehavior, "default", true) == 0)
                {
                    fm.NullBehavior = MappingBehavior.IfNullDefault;
                }
                else if (String.Compare(ifNullBehavior, "suppress", true) == 0)
                {
                    fm.NullBehavior = MappingBehavior.IfNullSuppress;
                }
            }

            String dataType = element.GetAttribute(ATTR_DATATYPE);

            if (dataType != null && dataType.Length > 0)
            {
                try
                {
                    fm.DataType = (SifDataType)Enum.Parse(typeof(SifDataType), dataType, true);
                }
                catch (FormatException iae)
                {
                    Adk.Log.Warn("Unable to parse datatype '" + dataType + "' for field " + name, iae);
                }
            }

            String filtVer = element.GetAttribute(ATTR_SIFVERSION);
            String filtDir = element.GetAttribute(ATTR_DIRECTION);

            if (!(String.IsNullOrEmpty(filtVer)) || !(String.IsNullOrEmpty(filtDir)))
            {
                MappingsFilter filt = new MappingsFilter();

                if (!String.IsNullOrEmpty(filtVer))
                {
                    filt.SifVersion = filtVer;
                }

                if (!String.IsNullOrEmpty(filtDir))
                {
                    if (String.Compare(filtDir, "inbound", true) == 0)
                    {
                        filt.Direction = MappingDirection.Inbound;
                    }
                    else if (String.Compare(filtDir, "outbound", true) == 0)
                    {
                        filt.Direction = MappingDirection.Outbound;
                    }
                    else
                    {
                        throw new AdkConfigException(
                                  "Field mapping rule for " + parent.ObjectType + "." + fm.FieldName +
                                  " specifies an unknown Direction flag: '" + filtDir + "'");
                    }
                }
                fm.Filter = filt;
            }


            //  FieldMapping must either have node text or an <otherid> child
            XmlElement otherIdNode = XmlUtils.GetFirstElementIgnoreCase(element, "otherid");

            if (otherIdNode == null)
            {
                String def = element.InnerText;
                if (def != null)
                {
                    fm.SetRule(def);
                }
                else
                {
                    fm.SetRule("");
                }
            }
            else
            {
                fm.SetRule(OtherIdMapping.FromXml(parent, fm, otherIdNode), otherIdNode);
            }

            return(fm);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Persists this mapping filter to the specified XmlElement
        /// </summary>
        /// <param name="filter">The filter to save</param>
        /// <param name="element"></param>
        internal static void Save(MappingsFilter filter,
                                  XmlElement element)
        {
            if (filter != null && filter.HasVersionFilter)
            {
                element.SetAttribute("sifVersion", filter.SifVersion);
            }
            else
            {
                element.RemoveAttribute("sifVersion");
            }

            if (filter != null && filter.HasDirectionFilter)
            {
                element.SetAttribute("direction", filter.Direction.ToString("G"));
                switch (filter.Direction)
                {
                    case MappingDirection.Inbound:
                        element.SetAttribute("direction", "inbound");
                        break;

                    case MappingDirection.Outbound:
                        element.SetAttribute("direction", "outbound");
                        break;
                }
            }
            else
            {
                element.RemoveAttribute("direction");
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Creates an returns a mappings filter from the specified XmlElement, or null if there is no filter defined
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        internal static MappingsFilter Load(XmlElement node)
        {
            string filtVer = node.GetAttribute("sifVersion");
            string filtDir = node.GetAttribute("direction");

            if (filtVer.Length > 0 || filtDir.Length > 0)
            {
                MappingsFilter filt = new MappingsFilter();

                if (filtVer.Length > 0)
                {
                    filt.SifVersion = filtVer;
                }

                if (filtDir.Length > 0)
                {
                    try
                    {
                        filt.Direction =
                            (MappingDirection)
                            Enum.Parse(typeof (MappingDirection), filtDir, true);
                    }
                    catch (Exception ex)
                    {
                        throw new AdkConfigException
                            ("Field mapping rule specifies an unknown Direction flag: '" + filtDir +
                             "'", ex);
                    }
                }
                return filt;
            }
            else
            {
                return null;
            }
        }
Exemplo n.º 10
0
        /**
         * Creates a set of mappings that operations can be applied to, such as
         * saving to a DOM or Agent.cfg. The results can be asserted by calling
         * {@see #assertMappings(Mappings)}.
         *
         * NOTE: This method returns an AgentConfig instance instead of a mappings
         * instance because there is no way set the Mappings instance on
         * AgentConfig. This might change in the future
         *
         * @return
         */
        private AgentConfig createMappings()
        {
            Mappings root = fCfg.Mappings;
            // Remove the mappings being used
            root.RemoveChild( root.GetMappings( "Default" ) );
            root.RemoveChild( root.GetMappings( "TestID" ) );

            Mappings newMappings = root.CreateChild( "Test" );

            // Add an object mapping
            ObjectMapping objMap = new ObjectMapping( "StudentPersonal" );
            // Currently, the Adk code requires that an Object Mapping be added
            // to it's parent before fields are added.
            // We should re-examine this and perhaps fix it, if possible
            newMappings.AddRules( objMap );

            objMap.AddRule( new FieldMapping( "FIELD1", "Name/FirstName" ) );

            // Field 2
            FieldMapping field2 = new FieldMapping( "FIELD2", "Name/LastName" );
            field2.ValueSetID = "VS1";
            field2.Alias = "ALIAS1";
            field2.DefaultValue = "DEFAULT1";
            MappingsFilter mf = new MappingsFilter();
            mf.Direction = MappingDirection.Inbound;
            mf.SifVersion = SifVersion.SIF11.ToString();
            field2.Filter = mf;
            objMap.AddRule( field2 );

            // Field 3 test setting the XML values after it's been added to the
            // parent object (the code paths are different)
            FieldMapping field3 = new FieldMapping( "FIELD3", "Name/MiddleName" );
            objMap.AddRule( field3 );
            field3.ValueSetID = "VS2";
            field3.Alias = "ALIAS2";
            field3.DefaultValue = "DEFAULT2";
            MappingsFilter mf2 = new MappingsFilter();
            mf2.Direction = MappingDirection.Outbound;
            mf2.SifVersion = SifVersion.SIF15r1.ToString();
            field3.Filter = mf2;
            field3.NullBehavior = MappingBehavior.IfNullDefault;

            OtherIdMapping oim = new OtherIdMapping( "ZZ", "BUSROUTE" );
            FieldMapping field4 = new FieldMapping( "FIELD4", oim );
            objMap.AddRule( field4 );
            field4.DefaultValue = "Default";
            field4.ValueSetID = "vs";
            field4.Alias = "alias";
            field4.DefaultValue = null;
            field4.ValueSetID = null;
            field4.Alias = null;
            field4.NullBehavior = MappingBehavior.IfNullSuppress;

            // Field4 tests the new datatype attribute
            FieldMapping field5 = new FieldMapping( "FIELD5",
                                                    "Demographics/BirthDate" );
            objMap.AddRule( field5 );
            field5.DataType = SifDataType.Date;

            // Add a valueset translation
            ValueSet vs = new ValueSet( "VS1" );
            newMappings.AddValueSet( vs );
            // Add a few definitions
            for ( int a = 0; a < 10; a++ )
            {
                vs.Define( "Value" + a, "SifValue" + a, "Title" + a );
            }

            vs.Define( "AppDefault", "0000", "Default App Value" );
            vs.SetAppDefault( "AppDefault", true );

            vs.Define( "0000", "SifDefault", "Default Sif Value" );
            vs.SetSifDefault( "SifDefault", false );

            // Add a valueset translation
            vs = new ValueSet( "VS2" );
            newMappings.AddValueSet( vs );
            // Add a few definitions
            for ( int a = 0; a < 3; a++ )
            {
                vs.Define( "q" + a, "w" + a, "t" + a );
            }

            vs.Define( "AppDefault", "0000", "Default Value" );
            vs.SetAppDefault( "AppDefault", true );
            vs.SetSifDefault( "0000", true );

            return fCfg;
        }