public void DataRelationshipTests() { Parent p = new Parent { ParentName = "Parent Name Value" }; Child c = new Child { ChildName = "Child Name Value" }; House h = new House { HouseName = "House Name Value" }; p.Children = new List <Child>(); p.Children.Add(c); p.Houses = new List <House>(); p.Houses.Add(h); HashSet <DataRelationship> rels = DataRelationship.FromInstance(p); foreach (DataRelationship rel in rels) { OutFormat(rel.PropertiesToString()); } Expect.AreEqual(2, rels.Count); }
public static Cardinality GetCardinality(this GraphMap graphMap, RoleMap roleMap, DataDictionary dataDictionary, string fixedIdentifierBoundary) { ClassTemplateMap ctm = graphMap.GetClassTemplateMap(roleMap.classMap.id, roleMap.classMap.index); if (ctm == null || ctm.classMap == null) { return(Cardinality.Self); } // determine cardinality to related class foreach (string identifier in roleMap.classMap.identifiers) { if (!(identifier.StartsWith(fixedIdentifierBoundary) && identifier.EndsWith(fixedIdentifierBoundary))) { string[] propertyParts = identifier.Split('.'); if (propertyParts.Length > 2) { DataObject dataObject = dataDictionary.dataObjects.First(c => c.objectName == propertyParts[0]); DataRelationship dataRelationship = dataObject.dataRelationships.First(c => c.relationshipName == propertyParts[1]); if (dataRelationship.relationshipType == RelationshipType.OneToMany) { return(Cardinality.OneToMany); } } } } return(Cardinality.OneToOne); }
static CodeList CreateCodeList(PhysicalInstance physicalInstance, DataRelationship dataRelationship, Variable variable, VariableStatistic stats) { using (IDataReader reader = GetReaderForPhysicalInstance(physicalInstance)) { if (reader == null) { return(null); } int columnIdx = GetColumnIndex(physicalInstance, dataRelationship, variable); if (columnIdx == -1) { return(null); } var gatherer = new DataValueFrequencyGatherer(reader); var values = gatherer.CountValueFrequencies(columnIdx); var codeList = new CodeList() { AgencyId = variable.AgencyId }; codeList.ItemName.Copy(variable.ItemName); codeList.Label.Copy(variable.Label); // Clear any existing category statistics. stats.UnfilteredCategoryStatistics.Clear(); foreach (var pair in values.OrderBy(x => x.Key)) { string value = pair.Key; int count = pair.Value; // Create the code and category. var category = new Category() { AgencyId = variable.AgencyId }; var code = new Code() { AgencyId = variable.AgencyId }; code.Value = value; code.Category = category; codeList.Codes.Add(code); // Update the statistics with category frequency. var catStats = new CategoryStatistics(); catStats.CategoryValue = value.ToString(); catStats.Frequency = count; stats.UnfilteredCategoryStatistics.Add(catStats); } return(codeList); } }
//propertyPath = "Instrument.LineItems.Tag"; protected List <IDataObject> GetRelatedObjects(string propertyPath, IDataObject dataObject) { List <IDataObject> dataObjects = new List <IDataObject>(); string[] objectPath = propertyPath.Split('.'); dataObjects.Add(dataObject); for (int i = 0; i < objectPath.Length - 2; i++) { foreach (IDataObject parentObject in dataObjects) { string objectType = parentObject.GetType().Name; if (objectType == typeof(GenericDataObject).Name) { objectType = ((GenericDataObject)parentObject).ObjectType; } DataObject parentObjectType = _dictionary.dataObjects.Find(x => x.objectName.ToLower() == objectType.ToLower()); DataRelationship dataRelationship = parentObjectType.dataRelationships.First(c => c.relationshipName.ToLower() == objectPath[i + 1].ToLower()); DataObject relatedObjectType = _dictionary.dataObjects.Find(x => x.objectName.ToLower() == dataRelationship.relatedObjectName.ToLower()); DataFilter filter = new DataFilter(); foreach (PropertyMap propMap in dataRelationship.propertyMaps) { filter.Expressions.Add(new Expression() { PropertyName = propMap.relatedPropertyName, RelationalOperator = RelationalOperator.EqualTo, LogicalOperator = LogicalOperator.And, Values = new Values() { Convert.ToString(parentObject.GetPropertyValue(propMap.dataPropertyName)) } }); } List <IDataObject> relatedObjects = dataLayerGateway.Get(relatedObjectType, filter, 0, 0); dataObjects = relatedObjects; } } return(dataObjects); }
public void Convert(PhysicalInstance pi) { if (pi == null) { throw new ArgumentNullException(nameof(pi)); } if (pi.RecordLayouts.Count == 0) { return; } // Create a single DataRelationship for the PhysicalInstance. // Within this, we will add one LogicalRecord per old RecordLayout. var dataRelationship = new DataRelationship() { AgencyId = pi.AgencyId }; pi.DataRelationships.Add(dataRelationship); // For each record layout, add the variables to a new DataRelationship. foreach (var recordLayout in pi.RecordLayouts) { // Create a LogicalRecord with the same descriptive information // as the RecordLayout we are migrating. var logicalRecord = new LogicalRecord { AgencyId = pi.AgencyId }; dataRelationship.LogicalRecords.Add(logicalRecord); logicalRecord.ItemName.Copy(recordLayout.ItemName); logicalRecord.Label.Copy(recordLayout.Label); logicalRecord.Description.Copy(recordLayout.Description); // For each DataItem in the RecordLayout, add a VariablesInRecord entry // to the LogicalRecord. foreach (var dataItem in recordLayout.DataItems) { logicalRecord.VariablesInRecord.Add(dataItem.Variable); } } // Remove the old RecordLayouts. pi.RecordLayouts.Clear(); }
static int GetColumnIndex(PhysicalInstance physicalInstance, DataRelationship dataRelationship, Variable variable) { var logicalRecord = dataRelationship.LogicalRecords.FirstOrDefault(); if (logicalRecord == null) { return(-1); } var variableInRecord = logicalRecord.VariablesInRecord .Where(x => x.CompositeId == variable.CompositeId) .FirstOrDefault(); if (variableInRecord == null) { return(-1); } return(logicalRecord.VariablesInRecord.IndexOf(variableInRecord)); }
/// <summary> /// Update versions and references to a Variable along this path: /// PhysicalInstance /// DataRelationship /// Variable /// VariableStatistic /// Variable /// </summary> /// <param name="variable"></param> public static void UpdateVersionsAndSave(Variable variable, PhysicalInstance physicalInstance, DataRelationship dataRelationship, VariableStatistic variableStatistic) { var client = RepositoryHelper.GetClient(); var now = DateTime.UtcNow; var itemsToRegister = new List <IVersionable>(); itemsToRegister.Add(variable); itemsToRegister.Add(physicalInstance); itemsToRegister.Add(dataRelationship); // Increase version of the variable. variable.Version++; variable.VersionDate = now; // Increase the version and reference of the PhysicalInstance that // references the DataRelationship and VariableStatistic. physicalInstance.Version++; physicalInstance.VersionDate = now; // Increase the version and reference of the DataRelationship that references the variable. dataRelationship.Version++; dataRelationship.VersionDate = now; // Update the reference to the variable. var variableInDataRelationship = dataRelationship.LogicalRecords .SelectMany(x => x.VariablesInRecord) .Where(x => x.Identifier == variable.Identifier) .FirstOrDefault(); variableInDataRelationship.Version = variable.Version; variableInDataRelationship.VersionDate = now; // Increase the version and reference of hte VariableStatistic that references the Variable. if (variableStatistic != null) { variableStatistic.Version++; variableStatistic.VersionDate = now; variableStatistic.VariableReference.Version = variable.Version; itemsToRegister.Add(variableStatistic); } // Register all the changes. var options = new CommitOptions(); options.NamedOptions.Add("RegisterOrReplace"); client.RegisterItems(itemsToRegister, options); }
public ResourcePackage Import(string path, string agencyId) { this.harmonizingCache = new HarmonizingCache(MultilingualString.CurrentCulture); var resourcePackage = new ResourcePackage(); resourcePackage.AgencyId = agencyId; logger.Debug("Importing RData"); if (string.IsNullOrEmpty(path)) { throw new ArgumentNullException("fileName"); } if (!File.Exists(path)) { throw new ArgumentException("The specified file must exist"); } string fileNameWithExtension = Path.GetFileName(path); string fileNameOnly = Path.GetFileNameWithoutExtension(path); logger.Debug("RData import file: " + fileNameOnly); resourcePackage.DublinCoreMetadata.Title.Current = fileNameOnly; // Create the PhysicalInstance. var physicalInstance = new PhysicalInstance() { AgencyId = agencyId }; resourcePackage.PhysicalInstances.Add(physicalInstance); physicalInstance.DublinCoreMetadata.Title.Current = fileNameOnly; // File location if (path != null) { DataFileIdentification fileID = new DataFileIdentification(); Uri uri; if (Uri.TryCreate(path, UriKind.RelativeOrAbsolute, out uri)) { fileID.Uri = uri; } fileID.Path = path; physicalInstance.FileIdentifications.Add(fileID); } // Create the DataRelationship. var dataRelationship = new DataRelationship(); physicalInstance.DataRelationships.Add(dataRelationship); dataRelationship.AgencyId = agencyId; dataRelationship.Label.Current = fileNameOnly; // Load the file into R. string pathForR = path.Replace("\\", "/"); engine.Evaluate(string.Format("load('{0}')", pathForR)); // Find all the data frames. var dataFrames = GetDataFrames(); // For each data frame in the RData file, create a LogicalRecord. foreach (var pair in dataFrames) { string name = pair.Key; var dataFrame = pair.Value; // TODO This should be tracked per record, not PhysicalInstance. physicalInstance.FileStructure.CaseQuantity = dataFrame.RowCount; var logicalRecord = new LogicalRecord() { AgencyId = agencyId }; dataRelationship.LogicalRecords.Add(logicalRecord); logicalRecord.Label.Current = name; List <string> variableLabels = null; var variableLabelsExpr = dataFrame.GetAttribute("var.labels"); if (variableLabelsExpr != null) { var labelVector = variableLabelsExpr.AsVector(); variableLabels = new List <string>(labelVector.Select(x => (string)x)); } for (int i = 0; i < dataFrame.ColumnCount; i++) { string columnName = dataFrame.ColumnNames[i]; var column = dataFrame[i]; var variable = new Variable() { AgencyId = agencyId }; logicalRecord.VariablesInRecord.Add(variable); // Name variable.ItemName.Current = columnName; // Label if (variableLabels != null) { variable.Label.Current = variableLabels[i]; } // Type if (column.Type == RDotNet.Internals.SymbolicExpressionType.NumericVector) { variable.RepresentationType = RepresentationType.Numeric; variable.Additivity = AdditivityType.Stock; } else if (column.Type == RDotNet.Internals.SymbolicExpressionType.IntegerVector) { if (column.IsFactor()) { variable.RepresentationType = RepresentationType.Code; string[] factors = column.AsFactor().GetLevels(); variable.CodeRepresentation.Codes = GetCodeList(factors, agencyId, resourcePackage); } else { variable.RepresentationType = RepresentationType.Numeric; variable.NumericRepresentation.NumericType = NumericType.Integer; variable.Additivity = AdditivityType.Stock; } } else if (column.Type == RDotNet.Internals.SymbolicExpressionType.CharacterVector) { variable.RepresentationType = RepresentationType.Text; } } } return(resourcePackage); }
public SqlRelatedTable(string relationshipName, Type relatedClass, DataRelationship relationship = DataRelationship.ONE_TO_MANY) { RelationshipName = relationshipName; RelatedClass = relatedClass; Relationship = relationship; }
public override IList <IDataObject> GetRelatedObjects(IDataObject parentDataObject, string relatedObjectType) { IList <IDataObject> relatedObjects = null; ISession session = null; try { DataObject dataObject = _dataDictionary.dataObjects.Find(c => c.objectName.ToLower() == parentDataObject.GetType().Name.ToLower()); if (dataObject == null) { throw new Exception("Parent data object [" + parentDataObject.GetType().Name + "] not found."); } DataRelationship dataRelationship = dataObject.dataRelationships.Find(c => c.relatedObjectName.ToLower() == relatedObjectType.ToLower()); if (dataRelationship == null) { throw new Exception("Relationship between data object [" + parentDataObject.GetType().Name + "] and related data object [" + relatedObjectType + "] not found."); } session = NHibernateSessionManager.Instance.GetSession(_settings["AppDataPath"], _settings["Scope"]); StringBuilder sql = new StringBuilder(); sql.Append("from " + dataRelationship.relatedObjectName + " where "); foreach (PropertyMap map in dataRelationship.propertyMaps) { DataProperty propertyMap = dataObject.dataProperties.First(c => c.propertyName == map.dataPropertyName); if (propertyMap.dataType == DataType.String) { sql.Append(map.relatedPropertyName + " = '" + parentDataObject.GetPropertyValue(map.dataPropertyName) + "' and "); } else { sql.Append(map.relatedPropertyName + " = " + parentDataObject.GetPropertyValue(map.dataPropertyName) + " and "); } } sql.Remove(sql.Length - 4, 4); // remove the tail "and " IQuery query = session.CreateQuery(sql.ToString()); relatedObjects = query.List <IDataObject>(); if (relatedObjects != null && relatedObjects.Count > 0 && dataRelationship.relationshipType == RelationshipType.OneToOne) { return(new List <IDataObject> { relatedObjects.First() }); } return(relatedObjects); } catch (Exception e) { string error = "Error getting related objects [" + relatedObjectType + "] " + e; _logger.Error(error); throw new Exception(error); } finally { CloseSession(session); } }
private DataObject CreateDataObject(BusinessObject businessObject) { string propertyName = string.Empty; string keyPropertyName = string.Empty; string relatedPropertyName = string.Empty; string relatedObjectName = string.Empty; string relationshipName = string.Empty; DataObject dataObject = new DataObject(); string objectName = businessObject.objectName; dataObject.objectName = objectName; dataObject.objectNamespace = projectNameSpace; dataObject.tableName = objectName; dataObject.keyProperties = new List <KeyProperty>(); dataObject.dataProperties = new List <DataProperty>(); dataObject.dataRelationships = new List <DataRelationship>(); if (businessObject.dataFilter != null) { dataObject.dataFilter = businessObject.dataFilter; } foreach (BusinessKeyProperty businessKeyProerpty in businessObject.businessKeyProperties) { KeyProperty keyProperty = new KeyProperty(); DataProperty dataProperty = new DataProperty(); keyPropertyName = businessKeyProerpty.keyPropertyName;; keyProperty.keyPropertyName = keyPropertyName; dataProperty.propertyName = keyPropertyName; dataProperty.dataType = DataType.String; dataProperty.columnName = keyPropertyName; dataProperty.isNullable = false; dataProperty.keyType = KeyType.assigned; dataObject.keyProperties.Add(keyProperty); dataObject.dataProperties.Add(dataProperty); } foreach (BusinessInterface businessInterface in businessObject.businessInterfaces) { InterfaceInformation interfaceInfo = GetInterfaceInformation(businessInterface.interfaceName); foreach (BusinessProperty businessProperty in businessInterface.businessProperties) { propertyName = businessProperty.propertyName; if (interfaceInfo != null) { if (HasProperty(interfaceInfo, propertyName)) { DataProperty dataProperty = new DataProperty(); if (!String.IsNullOrEmpty(businessProperty.dbColumn)) { dataProperty.columnName = businessProperty.dbColumn; } else { dataProperty.columnName = propertyName; } dataProperty.propertyName = propertyName; dataProperty.dataType = GetDatatype(businessProperty.dataType); dataProperty.isNullable = businessProperty.isNullable; dataProperty.isReadOnly = businessObject.isReadOnly; if (!String.IsNullOrEmpty(businessProperty.description) != null) { dataProperty.description = businessObject.description; } dataObject.dataProperties.Add(dataProperty); } else { throw new Exception("Property [" + propertyName + "] not found."); } } else { throw new Exception("Interface [" + businessInterface.interfaceName + "] not found."); } } } foreach (BusinessRelationship businessRelationship in businessObject.businessRelationships) { DataRelationship dataRelationship = new DataRelationship(); relationshipName = businessRelationship.relationshipName; relatedObjectName = businessRelationship.relatedObjectName; if (IsRelated(relationshipName, relatedObjectName, objectName)) { dataRelationship.relatedObjectName = businessRelationship.relatedObjectName; dataRelationship.relationshipName = businessRelationship.relationshipName; dataRelationship.propertyMaps = new List <PropertyMap>(); if (businessRelationship.businessRelatedInterfaces != null) { foreach (BusinessInterface businessInterface in businessRelationship.businessRelatedInterfaces) { foreach (BusinessProperty businessRelationProperty in businessInterface.businessProperties) { InterfaceInformation interfaceInfo = GetInterfaceInformation(businessInterface.interfaceName); relatedPropertyName = businessRelationProperty.propertyName; if (interfaceInfo != null) { if (HasProperty(interfaceInfo, relatedPropertyName)) { DataProperty dataProperty = new DataProperty(); PropertyMap propertyMap = new PropertyMap(); propertyMap.relatedPropertyName = relatedPropertyName; dataProperty.propertyName = dataRelationship.relatedObjectName + "_" + relatedPropertyName; dataProperty.dataType = GetDatatype(businessRelationProperty.dataType); if (!String.IsNullOrEmpty(businessRelationProperty.dbColumn)) { dataProperty.columnName = businessRelationProperty.dbColumn; } else { dataProperty.columnName = relatedPropertyName; } dataRelationship.propertyMaps.Add(propertyMap); dataObject.dataProperties.Add(dataProperty); } else { throw new Exception("Property [" + relatedPropertyName + "] not found."); } } else { throw new Exception("Interface [" + businessInterface.interfaceName + "] not found."); } } } dataObject.dataRelationships.Add(dataRelationship); } } } return(dataObject); }
private string FormWhereClause(DataRow parentRow, string relatedTableName) { // // validate relationship // if (parentRow == null) { throw new Exception("Parent data row is empty."); } DataObject parentObjDef = _dbDictionary.dataObjects.Find(x => x.tableName.ToUpper() == parentRow.Table.TableName.ToUpper()); if (parentObjDef == null) { throw new Exception("Parent object [" + parentRow.Table.TableName + " not found."); } DataObject childObjDef = _dbDictionary.dataObjects.Find(x => x.tableName.ToUpper() == relatedTableName.ToUpper()); if (childObjDef == null) { throw new Exception("Child object [" + relatedTableName + " not found."); } DataRelationship relationship = parentObjDef.dataRelationships.Find(x => x.relatedObjectName.ToUpper() == childObjDef.objectName.ToUpper()); if (relationship == null) { throw new Exception("Relationship between [" + parentRow.Table.TableName + "] and [" + relatedTableName + " not found."); } // // build WHERE clause // StringBuilder builder = new StringBuilder(); foreach (PropertyMap propMap in relationship.propertyMaps) { DataProperty relatedProp = childObjDef.dataProperties.Find(x => x.propertyName.ToUpper() == propMap.relatedPropertyName.ToUpper()); if (relatedProp == null) { throw new Exception("Related property [" + propMap.relatedPropertyName + "] not found."); } string value = parentRow[propMap.dataPropertyName].ToString(); if (!Utility.IsNumeric(relatedProp.dataType)) { value = "'" + value + "'"; } if (builder.Length > 0) { builder.Append(" and "); } builder.Append(propMap.dataPropertyName + " = " + value); } if (builder.Length > 0) { builder.Insert(0, " WHERE "); } return(builder.ToString()); }
static void CreateCodeList(Variable variable, PhysicalInstance physicalInstance, DataRelationship dataRelationship, VariableStatistic variableStatistic) { // Create and save a code list with all the unique values. var codeList = CreateCodeList(physicalInstance, dataRelationship, variable, variableStatistic); variable.CodeRepresentation.Codes = codeList; if (codeList != null) { var gatherer = new ItemGathererVisitor(); codeList.Accept(gatherer); var client = RepositoryHelper.GetClient(); var repoOptions = new CommitOptions(); repoOptions.NamedOptions.Add("RegisterOrReplace"); client.RegisterItems(gatherer.FoundItems, repoOptions); } }
public static void UpdateVariableProperty(Variable variable, PhysicalInstance physicalInstance, DataRelationship dataRelationship, VariableStatistic variableStatistic, string propertyName, string value) { if (propertyName == "ItemName") { variable.ItemName.Current = value; } else if (propertyName == "Label") { variable.Label.Current = value; } else if (propertyName == "Description") { variable.Description.Current = value; } else if (propertyName == "AnalysisUnit") { variable.AnalysisUnit = value; } else if (propertyName == "ResponseUnit") { variable.ResponseUnit = value; } else if (propertyName == "RepresentationType") { if (value == "Text" && variable.RepresentationType != RepresentationType.Text) { // Clear any existing category statistics. variableStatistic.UnfilteredCategoryStatistics.Clear(); variable.RepresentationType = RepresentationType.Text; } else if (value == "Numeric" && variable.RepresentationType != RepresentationType.Numeric) { // Clear any existing category statistics. variableStatistic.UnfilteredCategoryStatistics.Clear(); variable.RepresentationType = RepresentationType.Numeric; } else if (value == "Code" && variable.RepresentationType != RepresentationType.Code) { variable.RepresentationType = RepresentationType.Code; CreateCodeList(variable, physicalInstance, dataRelationship, variableStatistic); } } }
// senario: // dataObject1.L1RelatedDataObjects.property1 // dataObject1.L1RelatedDataObjects.property2 // dataObject1.L1RelatedDataObjects.L2RelatedDataObjects.property3.value1 // dataObject1.L1RelatedDataObjects.L2RelatedDataObjects.property4.value2 // // L2RelatedDataObjects result: // dataObject1.L1RelatedDataObjects[1].L2RelatedDataObjects[1].property3.value1 // dataObject1.L1RelatedDataObjects[1].L2RelatedDataObjects[2].property4.value2 // dataObject1.L1RelatedDataObjects[2].L2RelatedDataObjects[1].property3.value1 // dataObject1.L1RelatedDataObjects[2].L2RelatedDataObjects[2].property4.value2 protected void ProcessRelatedItems() { for (int i = 0; i < _dataObjects.Count; i++) { Dictionary <string, List <Dictionary <string, string> > > relatedObjectsMap = _relatedRecordsMaps[i]; foreach (string relatedObjectPath in _relatedObjectPaths) { string[] relatedObjectPathElements = relatedObjectPath.Split('.'); for (int j = 0; j < relatedObjectPathElements.Length - 1; j++) { string parentObjectType = relatedObjectPathElements[j]; string relatedObjectType = relatedObjectPathElements[j + 1]; if (relatedObjectsMap.ContainsKey(relatedObjectType)) { List <Dictionary <string, string> > relatedRecords = relatedObjectsMap[relatedObjectType]; if (j == 0) { List <IDataObject> parentObjects = new List <IDataObject> { _dataObjects[i] }; foreach (IDataObject parentObject in parentObjects) { DataObject dataObject = _dictionary.dataObjects.First(c => c.objectName == parentObjectType); DataRelationship dataRelationship = dataObject.dataRelationships.First(c => c.relatedObjectName == relatedObjectType); foreach (Dictionary <string, string> relatedRecord in relatedRecords) { foreach (PropertyMap map in dataRelationship.propertyMaps) { relatedRecord[map.relatedPropertyName] = parentObject.GetPropertyValue(map.dataPropertyName).ToString(); } } } } else { List <Dictionary <string, string> > parentObjects = relatedObjectsMap[parentObjectType]; foreach (Dictionary <string, string> parentObject in parentObjects) { DataObject dataObject = _dictionary.dataObjects.First(c => c.objectName == parentObjectType); DataRelationship dataRelationship = dataObject.dataRelationships.First(c => c.relatedObjectName == relatedObjectType); foreach (Dictionary <string, string> relatedRecord in relatedRecords) { foreach (PropertyMap map in dataRelationship.propertyMaps) { relatedRecord[map.relatedPropertyName] = parentObject[map.dataPropertyName]; } } } } } } } } }
private DataObject CreateDataObject(BusinessObject businessObject) { string propertyName = string.Empty; string keyPropertyName = string.Empty; string relatedPropertyName = string.Empty; string relatedObjectName = string.Empty; string relationshipName = string.Empty; DataObject dataObject = new DataObject(); string objectName = businessObject.objectName; dataObject.objectName = objectName; dataObject.objectNamespace = projectNameSpace; dataObject.tableName = objectName; dataObject.keyProperties = new List<KeyProperty>(); dataObject.dataProperties = new List<DataProperty>(); dataObject.dataRelationships = new List<DataRelationship>(); if (businessObject.dataFilter != null) dataObject.dataFilter = businessObject.dataFilter; foreach (BusinessKeyProperty businessKeyProerpty in businessObject.businessKeyProperties) { KeyProperty keyProperty = new KeyProperty(); DataProperty dataProperty = new DataProperty(); keyPropertyName = businessKeyProerpty.keyPropertyName;; keyProperty.keyPropertyName = keyPropertyName; dataProperty.propertyName = keyPropertyName; dataProperty.dataType = DataType.String; dataProperty.columnName = keyPropertyName; dataProperty.isNullable = false; dataProperty.keyType = KeyType.assigned; dataObject.keyProperties.Add(keyProperty); dataObject.dataProperties.Add(dataProperty); } foreach (BusinessInterface businessInterface in businessObject.businessInterfaces) { InterfaceInformation interfaceInfo = GetInterfaceInformation(businessInterface.interfaceName); foreach (BusinessProperty businessProperty in businessInterface.businessProperties) { propertyName = businessProperty.propertyName; if (interfaceInfo != null) { if (HasProperty(interfaceInfo, propertyName)) { DataProperty dataProperty = new DataProperty(); if (!String.IsNullOrEmpty(businessProperty.dbColumn)) dataProperty.columnName = businessProperty.dbColumn; else dataProperty.columnName = propertyName; dataProperty.propertyName = propertyName; dataProperty.dataType = GetDatatype(businessProperty.dataType); dataProperty.isNullable = businessProperty.isNullable; dataProperty.isReadOnly = businessObject.isReadOnly; if (!String.IsNullOrEmpty(businessProperty.description) != null) dataProperty.description = businessObject.description; dataObject.dataProperties.Add(dataProperty); } else { throw new Exception("Property [" + propertyName + "] not found."); } } else throw new Exception("Interface [" + businessInterface.interfaceName + "] not found."); } } foreach (BusinessRelationship businessRelationship in businessObject.businessRelationships) { DataRelationship dataRelationship = new DataRelationship(); relationshipName = businessRelationship.relationshipName; relatedObjectName = businessRelationship.relatedObjectName; if (IsRelated(relationshipName, relatedObjectName, objectName)) { dataRelationship.relatedObjectName = businessRelationship.relatedObjectName; dataRelationship.relationshipName = businessRelationship.relationshipName; dataRelationship.propertyMaps = new List<PropertyMap>(); if (businessRelationship.businessRelatedInterfaces != null) { foreach (BusinessInterface businessInterface in businessRelationship.businessRelatedInterfaces) { foreach (BusinessProperty businessRelationProperty in businessInterface.businessProperties) { InterfaceInformation interfaceInfo = GetInterfaceInformation(businessInterface.interfaceName); relatedPropertyName = businessRelationProperty.propertyName; if (interfaceInfo != null) { if (HasProperty(interfaceInfo, relatedPropertyName)) { DataProperty dataProperty = new DataProperty(); PropertyMap propertyMap = new PropertyMap(); propertyMap.relatedPropertyName = relatedPropertyName; dataProperty.propertyName = dataRelationship.relatedObjectName + "_" + relatedPropertyName; dataProperty.dataType = GetDatatype(businessRelationProperty.dataType); if (!String.IsNullOrEmpty(businessRelationProperty.dbColumn)) dataProperty.columnName = businessRelationProperty.dbColumn; else dataProperty.columnName = relatedPropertyName; dataRelationship.propertyMaps.Add(propertyMap); dataObject.dataProperties.Add(dataProperty); } else { throw new Exception("Property [" + relatedPropertyName + "] not found."); } } else throw new Exception("Interface [" + businessInterface.interfaceName + "] not found."); } } dataObject.dataRelationships.Add(dataRelationship); } } } return dataObject; }
void GetReferencingItems(RepositoryClientBase client, IdentifierTriple variableId, out PhysicalInstance physicalInstance, out DataRelationship dataRelationship, out VariableStatistic variableStatistic) { dataRelationship = null; variableStatistic = null; physicalInstance = VariableMapper.GetPhysicalInstanceWithVariable(variableId, client); foreach (var dr in physicalInstance.DataRelationships) { client.PopulateItem(dr, false, ChildReferenceProcessing.Populate); if (dr.LogicalRecords .SelectMany(x => x.VariablesInRecord) .Any(x => x.CompositeId == variableId)) { dataRelationship = dr; } } foreach (var stats in physicalInstance.Statistics) { client.PopulateItem(stats); if (stats.AgencyId == variableId.AgencyId & stats.VariableReference.Identifier == variableId.Identifier) { variableStatistic = stats; break; } } }