Esempio n. 1
0
        public static OtherIdMapping FromXml(ObjectMapping parent, FieldMapping field, XmlElement element)
        {
            //  The OtherId type= attribute is required
            String type = element.GetAttribute("type");

            if (type == null)
            {
                type = element.GetAttribute("Type");
            }
            if (type == null)
            {
                throw new AdkConfigException("Field mapping rule " + parent.ObjectType + "." + field.FieldName +
                                             " specifies an <OtherId> without a 'type' attribute");
            }

            //	The OtherId prefix= attribute is required
            String prefix = element.GetAttribute("prefix");

            if (prefix == null)
            {
                prefix = element.GetAttribute("Prefix");
            }
            if (prefix == null)
            {
                throw new AdkConfigException("Field mapping rule " + parent.ObjectType + "." + field.FieldName +
                                             " specifies an <OtherId> without a 'prefix' attribute");
            }

            //  Create a new OtherIdMapping as a child of the FieldMapping
            OtherIdMapping id = new OtherIdMapping(type, prefix, element);

            return(id);
        }
Esempio n. 2
0
        /// <summary>  Return an array of all FieldMapping definitions</summary>
        /// <param name="inherit">True to inherit FieldMapping definitions from the
        /// parent Mappings ancestry
        /// </param>
        public IList <FieldMapping> GetRulesList(bool inherit)
        {
            List <FieldMapping> rules = new List <FieldMapping>();

            if (inherit)
            {
                IDictionary <String, Object> set = new Dictionary <String, Object>();
                // Keep the rules in a list because the ordering of
                // rules is important
                Mappings m = fParent;
                while (m != null)
                {
                    ObjectMapping om = m.GetRules(fObjType, false);
                    if (om != null && om.fFieldRules != null)
                    {
                        foreach (FieldMapping fm in om.fFieldRules)
                        {
                            String key = fm.Key;
                            if (!set.ContainsKey(key))
                            {
                                set.Add(key, null);
                                rules.Add(fm);
                            }
                        }
                    }
                    m = m.fParent;
                }
            }
            else if (fFieldRules != null)
            {
                rules.AddRange(fFieldRules);
            }

            return(rules);
        }
Esempio n. 3
0
        /// <summary>  Creates a copy this ObjectMapping instance.
        ///
        /// This method performs a "deep copy", such that a clone is made of each
        /// child FieldMapping. The parent of the new ObjectMapping will be the
        /// Mappings object passed to this function. Any DOM Nodes assigned to this
        /// object or its children are cloned and appended to the parent Mappings's
        /// DOM XmlElement if one exists.
        ///
        /// </summary>
        /// <returns> A "deep copy" of this object
        /// </returns>
        public ObjectMapping Copy(Mappings newParent)
        {
            //	Create a new ObjectMapping instance
            ObjectMapping m = new ObjectMapping(fObjType);

            //  Copy the DOM XmlElement
            if (fNode != null)
            {
                if (newParent.fNode != null)
                {
                    XmlElement newNode = (XmlElement)newParent.fNode.OwnerDocument.ImportNode(fNode, false);
                    newParent.fNode.AppendChild(newNode);
                    m.fNode = newNode;
                }
            }

            //  Copy fFieldRules
            if (fFieldRules != null)
            {
                if (m.fFieldRules == null)
                {
                    m.fFieldRules = new List <FieldMapping>();
                }

                for (int i = 0; i < fFieldRules.Count; i++)
                {
                    FieldMapping copy = (fFieldRules[i]).Copy(m);
                    m.AddRule(copy);
                }
            }

            return(m);
        }
        public void testCreateMappings()
        {
            // Create the root instance
            Mappings root = new Mappings();
            // Create the default set of universal mappings
            Mappings defaults = new Mappings( root, "Default" );
            root.AddChild( defaults );

            // Create an ObjectMapping for StudentPersonal
            ObjectMapping studentMappings = new ObjectMapping( "StudentPersonal" );
            defaults.AddRules( studentMappings );
            // Add field rules
            studentMappings.AddRule( new FieldMapping( "FIRSTNAME",
                                                       "Name[@Type='04']/FirstName" ) );
            studentMappings.AddRule( new FieldMapping( "LASTNAME",
                                                       "Name[@Type='04']/LastName" ) );

            // Create a set of mappings for the state of Wisconsin
            Mappings wisconsin = new Mappings( defaults, "Wisconsin" );
            defaults.AddChild( wisconsin );
            // Create a set of mappings for the Neillsville School District
            Mappings neillsville = new Mappings( wisconsin, "Neillsville" );

            wisconsin.AddChild( neillsville );

            XmlDocument doc = new XmlDocument( );
            doc.LoadXml( "<agent/>");

            XmlElement n = root.ToDom( doc );
            debug( doc );
        }
Esempio n. 5
0
        /**
         * Creates a MappingsContext instance to handle a set of mappings operations using
         * the same parameters
         * @param m The mappings instance to use
         * @param direction The mappings direction
         * @param version The version of SIF to use for evaluating rule filters on field mappings
         * @param elementDef The ElementDef representing the object type being mapped
         * @return A new MappingsContext, initialized to map using the specified parameters
         */

        public static MappingsContext Create(Mappings m, MappingDirection direction, SifVersion version,
                                             IElementDef elementDef)
        {
            // Get the rules associated with the element type
            MappingsContext mc = new MappingsContext(m, direction, version, elementDef);
            ObjectMapping   om = m.GetRules(elementDef.Name, true);

            mc.AddRules(om);
            return(mc);
        }
Esempio n. 6
0
 private void AddRules(ObjectMapping om)
 {
     // Get the rules associated with the element type
     fObjectMappings = om;
     if (om != null)
     {
         foreach (FieldMapping fm in om.GetRulesList(true))
         {
             // addRule( FieldMapping ) will automatically filter out
             // any rules that need to be filtered
             AddRule(fm);
         }
     }
 }
Esempio n. 7
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);
        }
Esempio n. 8
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);
        }
        /**
         * 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;
        }
Esempio n. 10
0
 private void AddRules(ObjectMapping om)
 {
     // Get the rules associated with the element type
     fObjectMappings = om;
     if (om != null)
     {
         foreach (FieldMapping fm in om.GetRulesList(true))
         {
             // addRule( FieldMapping ) will automatically filter out
             // any rules that need to be filtered
             AddRule(fm);
         }
     }
 }
Esempio n. 11
0
        /// <summary>  Creates a copy this ObjectMapping instance.
        /// 
        /// This method performs a "deep copy", such that a clone is made of each 
        /// child FieldMapping. The parent of the new ObjectMapping will be the 
        /// Mappings object passed to this function. Any DOM Nodes assigned to this
        /// object or its children are cloned and appended to the parent Mappings's
        /// DOM XmlElement if one exists.
        /// 
        /// </summary>
        /// <returns> A "deep copy" of this object
        /// </returns>
        public ObjectMapping Copy(Mappings newParent)
        {
            //	Create a new ObjectMapping instance
            ObjectMapping m = new ObjectMapping(fObjType);

            //  Copy the DOM XmlElement
            if (fNode != null)
            {
                if (newParent.fNode != null)
                {
                    XmlElement newNode = (XmlElement) newParent.fNode.OwnerDocument.ImportNode( fNode, false );
                    newParent.fNode.AppendChild( newNode );
                    m.fNode = newNode;
                }
            }

            //  Copy fFieldRules
            if (fFieldRules != null)
            {
                if (m.fFieldRules == null)
                {
                    m.fFieldRules = new List<FieldMapping>();
                }

                for (int i = 0; i < fFieldRules.Count; i++)
                {
                    FieldMapping copy = (fFieldRules[i]).Copy(m);
                    m.AddRule(copy);
                }
            }

            return m;
        }
Esempio n. 12
0
        /// <summary>  Add an ObjectMapping definition to this Mappings instance</summary>
        protected internal void AddRules(ObjectMapping om,
                                         bool buildDomTree)
        {
            if (om.fParent != null)
            {
                throw new SystemException
                    ("ObjectMapping is already a child of a Mappings instance");
            }

            om.fParent = this;

            if (fObjRules == null)
            {
                fObjRules = new Dictionary<String, ObjectMapping>();
            }
            fObjRules[om.ObjectType] = om;

            if (om.fNode == null && buildDomTree && fNode != null)
            {
                om.fNode = fNode.OwnerDocument.CreateElement(XML_OBJECT);
                if (om.ObjectType != null)
                {
                    om.fNode.SetAttribute("object", om.ObjectType);
                }
                fNode.AppendChild(om.fNode);
            }
        }
Esempio n. 13
0
 /// <summary>  Remove an ObjectMapping definition from this Mappings instance</summary>
 public void RemoveRules(ObjectMapping om)
 {
     if (fObjRules != null)
     {
         if (fNode != null && om.fNode != null)
         {
             fNode.RemoveChild(om.fNode);
         }
         fObjRules.Remove(om.ObjectType);
     }
 }
Esempio n. 14
0
        protected internal void Populate(XmlElement node,
                                         Mappings parent)
        {
            // TODO: We should probably be using a GetElementsby name query here
            // I think the java implementation might have been doing a recursive search here
            foreach (XmlElement n in new XmlUtils.XmlElementEnumerator(node))
            {
                if (n.Name.ToUpper() == XML_MAPPINGS.ToUpper())
                {
                    //  Get the ID
                    string id = n.GetAttribute("id");

                    //  Create a new child Mappings object
                    Mappings mappings = new Mappings(parent, id);
                    mappings.XmlElement = n;
                    if (parent.fChildren == null)
                    {
                        parent.fChildren = new Dictionary<String, Mappings>();
                    }
                    parent.fChildren[mappings.Id] = mappings;

                    //  Set a SifVersion filter if present
                    string ver = n.GetAttribute("sifVersion");
                    if (ver.Trim().Length > 0)
                    {
                        mappings.SetSIFVersionFilter(ver);
                    }

                    //  Set a ZoneId filter if present
                    string zoneIds = n.GetAttribute("zoneId");
                    if (zoneIds.Trim().Length > 0)
                    {
                        mappings.SetZoneIdFilter(zoneIds);
                    }

                    //  Set a SourceId filter if present
                    string sourceIds = n.GetAttribute("sourceId");
                    if (sourceIds.Trim().Length > 0)
                    {
                        mappings.SetSourceIdFilter(sourceIds);
                    }

                    //  Populate the Mappings object with rules
                    Populate(n, mappings);
                }
                else
                {
                    if (n.Name.ToUpper() == XML_OBJECT.ToUpper())
                    {
                        if (n.ParentNode.Name == XML_MAPPINGS)
                        {
                            string obj = n.GetAttribute(XML_OBJECT);
                            if (obj == null)
                            {
                                throw new AdkConfigException
                                    ("<object> element must have an object attribute");
                            }

                            ObjectMapping om = new ObjectMapping(obj);
                            om.XmlElement = n;
                            parent.AddRules(om, false);
                            PopulateObject(n, om);
                        }
                    }
                    else
                    {
                        if (n.Name.ToUpper() == "PROPERTY")
                        {
                            if (n.ParentNode.Name == XML_MAPPINGS)
                            {
                                parent.SetProperty
                                    (n.GetAttribute(AdkXmlConstants.Property.NAME),
                                     n.GetAttribute(AdkXmlConstants.Property.VALUE));
                            }
                        }
                        else
                        {
                            if (n.Name.ToUpper() == "VALUESET")
                            {
                                if (n.ParentNode.Name == XML_MAPPINGS)
                                {
                                    ValueSet set_Renamed =
                                        new ValueSet
                                            (n.GetAttribute("id"), n.GetAttribute("title"), n);
                                    parent.AddValueSet(set_Renamed);
                                    PopulateValueSet(n, set_Renamed);
                                }
                            }
                            else
                            {
                                Populate(n, parent);
                            }
                        }
                    }
                }
            }
        }
        private Mappings buildMappings1()
        {
            // root
            Mappings root = new Mappings();

            // root.Default
            Mappings defaults = new Mappings( root, "Default", null, null, null );
            root.AddChild( defaults );

            // root.Default.StudentPersonal
            ObjectMapping studentMappings = new ObjectMapping( "StudentPersonal" );
            defaults.AddRules( studentMappings );
            studentMappings.AddRule( new FieldMapping( "REFID", "@RefId" ) );

            // root.Default.MA
            Mappings massachusetts = new Mappings( defaults, "MA", null, null, null );
            defaults.AddChild( massachusetts );

            // root.Default.MA.StudentPersonal
            studentMappings = new ObjectMapping( "StudentPersonal" );
            massachusetts.AddRules( studentMappings );
            studentMappings.AddRule( new FieldMapping( "LOCALID", "LocalId" ) );
            studentMappings.AddRule( new FieldMapping( "FIRSTNAME",
                                                       "Name[@Type='01']/FirstName" ) );
            studentMappings.AddRule( new FieldMapping( "LASTNAME",
                                                       "Name[@Type='01']/LastName" ) );

            // root.Default.MA.Boston
            Mappings boston = new Mappings( massachusetts, "Boston", null, "Boston",
                                            null );
            massachusetts.AddChild( boston );

            // root.Default.MA.Boston.StudentPersonal
            studentMappings = new ObjectMapping( "StudentPersonal" );
            boston.AddRules( studentMappings );
            studentMappings.AddRule( new FieldMapping( "BIRTHDAY",
                                                       "Demographics/BirthDate" ) );

            return root;
        }
Esempio n. 16
0
 /// <summary>  Parse the <c>&lt;field&gt;</c> children of an <c>&lt;object&gt;</c> element.
 /// 
 /// </summary>
 /// <param name="element">A DOM <i>XmlElement</i> encapsulating an <c>&lt;object&gt;</c> element
 /// </param>
 /// <param name="parent">The parent ObjectMapping instance
 /// </param>
 protected internal void PopulateObject(XmlElement element,
                                        ObjectMapping parent)
 {
     foreach (XmlElement n in new XmlUtils.XmlElementEnumerator(element))
     {
         if (n.Name.ToUpper() == XML_FIELD.ToUpper())
         {
             FieldMapping fm = FieldMapping.FromXml( parent, n );
             parent.AddRule( fm, false );
         }
     }
 }
Esempio n. 17
0
        private IList<FieldMapping> GetRulesList(ObjectMapping om, SifVersion version, MappingDirection direction)
        {
            IList<FieldMapping> list = om.GetRulesList(true);
            // Remove any items that should be filtered out

            for (int a = list.Count - 1; a > -1; a--)
            {
                MappingsFilter filt = list[a].Filter;
                //	Filter out this rule?
                if (filt != null)
                {
                    if (!filt.EvalDirection(direction) ||
                        !filt.EvalVersion(version))
                    {
                        list.RemoveAt(a);
                    }
                }
            }
            return list;
        }
Esempio n. 18
0
        public static OtherIdMapping FromXml(ObjectMapping parent, FieldMapping field, XmlElement element)
        {
            //  The OtherId type= attribute is required
            String type = element.GetAttribute("type");
            if (type == null)
                type = element.GetAttribute("Type");
            if (type == null)
                throw new AdkConfigException("Field mapping rule " + parent.ObjectType + "." + field.FieldName +
                                             " specifies an <OtherId> without a 'type' attribute");

            //	The OtherId prefix= attribute is required
            String prefix = element.GetAttribute("prefix");
            if (prefix == null)
                prefix = element.GetAttribute("Prefix");
            if (prefix == null)
                throw new AdkConfigException("Field mapping rule " + parent.ObjectType + "." + field.FieldName +
                                             " specifies an <OtherId> without a 'prefix' attribute");

            //  Create a new OtherIdMapping as a child of the FieldMapping
            OtherIdMapping id = new OtherIdMapping(type, prefix, element);
            return id;
        }
Esempio n. 19
0
        /// <summary>  Gets all ObjectMappings defined for this Mappings instance, optionally
        /// including those inherited by its parents.
        /// </summary>
        /// <returns> An array of all ObjectMappings
        /// </returns>
        public ObjectMapping[] GetObjectMappings(bool inherit)
        {
            Hashtable hashSet = new Hashtable();

            Mappings m = this;
            while (m != null)
            {
                if (m.fObjRules != null)
                {
                    foreach (ObjectMapping om in m.fObjRules.Values)
                    {
                        if (!hashSet.ContainsKey(om.ObjectType))
                        {
                            hashSet[om.ObjectType] = om;
                        }
                    }
                }

                if (inherit)
                {
                    m = m.fParent;
                }
                else
                {
                    m = null;
                }
            }

            ObjectMapping[] arr = new ObjectMapping[hashSet.Count];
            hashSet.Values.CopyTo(arr, 0);
            return arr;
        }
Esempio n. 20
0
 /// <summary>  Add an ObjectMapping definition to this Mappings instance</summary>
 public void AddRules(ObjectMapping om)
 {
     AddRules(om, true);
 }