// Look up a schema based on site, histology and an optional discriminator. // @param lookup schema lookup input // @return a list of StagingSchemaInfo objects private List <StagingSchema> getSchemas(SchemaLookup lookup) { List <StagingSchema> matchedSchemas = new List <StagingSchema>(5); String site = lookup.getInput(StagingData.PRIMARY_SITE_KEY); String histology = lookup.getInput(StagingData.HISTOLOGY_KEY); bool hasDiscriminator = lookup.hasDiscriminator(); // site or histology must be supplied and they must be valid; I am assuming that all algorithms must have tables that validate // both site and histology if ((site != null && !isValidSite(site)) || (histology != null && !isValidHistology(histology))) { return(matchedSchemas); } // searching on a discriminator is only supported if also searching on site and histology; if ssf25 supplied without either // of those fields, return no results if (hasDiscriminator && (site == null || (site.Length == 0) || histology == null || (histology.Length == 0))) { return(matchedSchemas); } // site or histology must be supplied if (site != null || histology != null) { HashSet <String> lstSchemaIds = getSchemaIds(); // loop over selection table and match using only the supplied keys foreach (String schemaId in lstSchemaIds) { StagingSchema schema = (StagingSchema)(getDefinition(schemaId)); if (schema.getSchemaSelectionTable() != null) { StagingTable table = (StagingTable)(getTable(schema.getSchemaSelectionTable())); if (table != null && DecisionEngineFuncs.matchTable(table, lookup.getInputs(), lookup.getKeys()) != null) { matchedSchemas.Add(schema); } } } } return(matchedSchemas); }
// Looks at all tables involved in all the mappings in the definition and returns a list of input keys that could be used. It will also deal with mapped // inputs. The inputs from each mapping will only be included if it passes the inclusion/exclusion criteria based on the context. Note that if an input // to a table was not a supplied input (i.e. it was created as an output of a previous table) it will not be included in the list of inputs. The inputs will // also include any used in schema selection. All inputs returned from this method should be in the schema input list otherwise there is a problem with the // schema. // @param schema a StagingSchema // @param context a context of values used to to check mapping inclusion/exclusion // @return a Set of unique input keys public HashSet <String> getInputs(StagingSchema schema, Dictionary <String, String> context) { HashSet <String> inputs = new HashSet <String>(); // add schema selection fields if (schema.getSchemaSelectionTable() != null) { StagingTable table = getTable(schema.getSchemaSelectionTable()); if (table != null) { foreach (StagingColumnDefinition def in table.getColumnDefinitions()) { if (ColumnType.INPUT == def.getType()) { inputs.Add(def.getKey()); } } } } // process all mappings if (schema.getMappings() != null) { HashSet <String> excludedInputs = new HashSet <String>(); HashSet <String> thisInput = null; foreach (StagingMapping mapping in schema.getMappings()) { thisInput = getInputs(mapping, context, excludedInputs); inputs.UnionWith(thisInput); } } // always remove all context variables since they are never needed to be supplied inputs.ExceptWith(CONTEXT_KEYS); return(inputs); }
// 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); }