示例#1
0
        public void testLookupOutputs()
        {
            EodSchemaLookup      lookup  = new EodSchemaLookup("C680", "8590");
            List <StagingSchema> lookups = _STAGING.lookupSchema(lookup);

            Assert.AreEqual(2, lookups.Count);

            StagingSchema schema = _STAGING.getSchema(lookups[0].getId());

            Assert.AreEqual("urethra", schema.getId());

            // build list of output keys
            List <StagingSchemaOutput> outputs        = schema.getOutputs();
            HashSet <String>           definedOutputs = new HashSet <String>();

            foreach (StagingSchemaOutput o in outputs)
            {
                definedOutputs.Add(o.getKey());
            }

            // test without context
            Assert.IsTrue(definedOutputs.SetEquals(_STAGING.getOutputs(schema)));

            // test with context
            Assert.IsTrue(definedOutputs.SetEquals(_STAGING.getOutputs(schema, lookup.getInputs())));
        }
        // Initialize a schema.
        // @param schema schema entity
        // @return initialized schema entity
        public static StagingSchema initSchema(StagingSchema schema)
        {
            // parse the schema selection ranges
            if (schema.getSchemaSelectionTable() == null)
            {
                throw new System.InvalidOperationException("Schemas must have a schema selection table.");
            }

            // store the inputs in a Map that can searched more efficiently
            if (schema.getInputs() != null)
            {
                Dictionary <String, IInput> parsedInputMap = new Dictionary <String, IInput>();

                foreach (StagingSchemaInput input in schema.getInputs())
                {
                    // verify that all inputs contain a key
                    if (input.getKey() == null)
                    {
                        throw new System.InvalidOperationException("All input definitions must have a 'key' defined.");
                    }

                    parsedInputMap[input.getKey()] = input;
                }

                schema.setInputMap(parsedInputMap);
            }

            // store the outputs in a Map that can searched more efficiently
            if (schema.getOutputs() != null)
            {
                Dictionary <String, IOutput> parsedOutputMap = new Dictionary <String, IOutput>();

                foreach (StagingSchemaOutput output in schema.getOutputs())
                {
                    // verify that all inputs contain a key
                    if (output.getKey() == null)
                    {
                        throw new System.InvalidOperationException("All output definitions must have a 'key' defined.");
                    }

                    parsedOutputMap[output.getKey()] = output;
                }

                schema.setOutputMap(parsedOutputMap);
            }

            // make sure that the mapping initial context does not set a value for an input field
            if (schema.getMappings() != null)
            {
                foreach (StagingMapping mapping in schema.getMappings())
                {
                    if (mapping.getInitialContext() != null)
                    {
                        foreach (StagingKeyValue kv in mapping.getInitialContext())
                        {
                            if (schema.getInputMap().ContainsKey(kv.getKey()))
                            {
                                throw new System.InvalidOperationException("The key '" + kv.getKey() + "' is defined in an initial context, but that is not allowed since it is also defined as an input.");
                            }
                        }
                    }
                }
            }


            return(schema);
        }