예제 #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);
        }
예제 #2
0
 /// <summary>  Sets this object's rule to an "&lt;OtherId&gt; rule"</summary>
 /// <param name="otherId">An OtherIdMapping object that describes how to select
 /// a &lt;OtherId&gt; element during a mapping operation
 /// </param>
 public void SetRule(OtherIdMapping otherId)
 {
     fRule = new OtherIdRule(otherId);
     if (fNode != null)
     {
         fRule.ToXml(fNode);
     }
 }
예제 #3
0
 /// <summary>  Constructs a FieldMapping with an &lt;OtherId&gt; rule.
 ///
 /// </summary>
 /// <param name="name">The name of the local application field that maps to the
 /// SIF Data Object element or attribute described by this FieldMapping
 /// </param>
 /// <param name="rule">An OtherIdMapping object that describes how to select
 /// a &lt;OtherId&gt; element during a mapping operation
 /// </param>
 /// <param name="node">The XmlElement that this FieldMapping draws its configuration from</param>
 public FieldMapping(string name,
                     OtherIdMapping rule,
                     XmlElement node)
 {
     fField = name;
     SetRule(rule);
     fNode = node;
 }
예제 #4
0
        /// <summary>  Produces a duplicate of this Rule object
        ///
        /// </summary>
        /// <returns> A "deep copy" of this Rule object
        /// </returns>
        public virtual OtherIdMapping Copy()
        {
            OtherIdMapping m = new OtherIdMapping();

            m.fType   = fType;
            m.fPrefix = fPrefix;
            //  Copy the DOM XmlElement
            m.fNode = fNode == null ? null : (XmlElement)fNode.CloneNode(false);
            return(m);
        }
예제 #5
0
 public void SetRule(OtherIdMapping otherId,
                     XmlElement node)
 {
     fRule = new OtherIdRule(otherId, node);
 }
예제 #6
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);
        }
예제 #7
0
 /// <summary>  Constructs a FieldMapping with an &lt;OtherId&gt; rule.
 ///
 /// </summary>
 /// <param name="name">The name of the local application field that maps to the
 /// SIF Data Object element or attribute described by this FieldMapping
 /// </param>
 /// <param name="rule">An OtherIdMapping object that describes how to select
 /// a &lt;OtherId&gt; element during a mapping operation
 /// </param>
 public FieldMapping(string name,
                     OtherIdMapping rule)
     : this(name, rule, null)
 {
 }
예제 #8
0
 /// <summary>  Produces a duplicate of this Rule object
 /// 
 /// </summary>
 /// <returns> A "deep copy" of this Rule object
 /// </returns>
 public virtual OtherIdMapping Copy()
 {
     OtherIdMapping m = new OtherIdMapping();
     m.fType = fType;
     m.fPrefix = fPrefix;
     //  Copy the DOM XmlElement
     m.fNode = fNode == null ? null : (XmlElement) fNode.CloneNode(false);
     return m;
 }
예제 #9
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;
        }
예제 #10
0
 public OtherIdRule(OtherIdMapping mapping,
                    XmlElement node)
 {
     fMapping = mapping;
     fNode    = node;
 }
예제 #11
0
 public OtherIdRule(OtherIdMapping mapping)
     : this(mapping, null)
 {
 }
예제 #12
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;
        }