public ActionResult editAttribute(DataAttributeModel Model) { ViewBag.Title = PresentationModel.GetViewTitleForTenant( "Manage Data Attributes", this.Session.GetTenant()); DataContainerManager dataAttributeManager = new DataContainerManager(); IList<DataAttribute> DataAttributeList = dataAttributeManager.DataAttributeRepo.Get(); long tempUnitId = Convert.ToInt64(Model.Unit.Id); long tempDataTypeId = Convert.ToInt64(Model.DataType.Id); Model.Id = Model.Id; Model.ShortName = cutSpaces(Model.ShortName); Model.Name = cutSpaces(Model.Name); Model.Description = cutSpaces(Model.Description); //if (Model.DomainConstraints.Count > 0) //{ // if (Model.DomainConstraints. != null && Model.DomainItems.Count > 0) // { // Model.DomainConstraints.FirstOrDefault().DomainItems = clearEmptyItems(Model.DomainItems); // } //} if (Model.Name == "" | Model.Name == null) { Session["nameMsg"] = "invalid Name"; Session["Window"] = true; return View("AttributeManager", new DataAttributeManagerModel(Model)); } else { bool nameNotExist = DataAttributeList.Where(p => p.Name.ToLower().Equals(Model.Name.ToLower())).Count().Equals(0); if (Model.Id == 0) { if (nameNotExist) { UnitManager UM = new UnitManager(); Unit unit = new Unit(); DataTypeManager DTM = new DataTypeManager(); DataType dataType = new DataType(); DataContainerManager DAM = new DataContainerManager(); DataAttribute temp = new DataAttribute(); if(UM.Repo.Get(tempUnitId)!= null) unit = UM.Repo.Get(tempUnitId); else unit = UM.Repo.Get().Where(u => u.Name.ToLower() == "none").FirstOrDefault(); if (DTM.Repo.Get(tempDataTypeId) != null) dataType = DTM.Repo.Get(tempDataTypeId); else dataType = DTM.Repo.Get().ToList().FirstOrDefault(); temp = DAM.CreateDataAttribute(Model.ShortName, Model.Name, Model.Description, false, false, "", MeasurementScale.Categorial, DataContainerType.ReferenceType, "", dataType, unit, null, null, null, null, null, null); #region store constraint if (Model.RangeConstraints.Count > 0 && (Model.RangeConstraints.FirstOrDefault().Min !=null || Model.RangeConstraints.FirstOrDefault().Max !=null) && (Model.RangeConstraints.FirstOrDefault().Min != 0.0 || Model.RangeConstraints.FirstOrDefault().Max != 0.0 )) temp = storeConstraint(Model.RangeConstraints.First(), temp); if (Model.PatternConstraints.Count > 0 && !String.IsNullOrEmpty(Model.PatternConstraints.FirstOrDefault().MatchingPhrase)) temp = storeConstraint(Model.PatternConstraints.First(), temp); if (Model.DomainConstraints.Count > 0) { foreach (DomainConstraintModel d in Model.DomainConstraints) { temp = storeConstraint(d, temp); } } #endregion temp = DAM.UpdateDataAttribute(temp); } else { Session["nameMsg"] = "Name already exist"; Session["Window"] = true; return View("AttributeManager", new DataAttributeManagerModel(Model)); } } else { if (nameNotExist || DataAttributeList.Where(p => p.Name.Equals(Model.Name)).ToList().First().Id == Model.Id) { DataAttribute dataAttribute = DataAttributeList.Where(p => p.Id.Equals(Model.Id)).ToList().First(); if (!attributeInUse(dataAttribute)) { DataContainerManager DAM = new DataContainerManager(); dataAttribute.Name = cutSpaces(Model.Name); dataAttribute.ShortName = Model.ShortName; dataAttribute.Description = Model.Description; UnitManager UM = new UnitManager(); if (UM.Repo.Get(tempUnitId) != null) dataAttribute.Unit = UM.Repo.Get(tempUnitId); else dataAttribute.Unit = UM.Repo.Get().Where(u => u.Name.ToLower() == "none").FirstOrDefault(); DataTypeManager DTM = new DataTypeManager(); if (DTM.Repo.Get(tempDataTypeId) != null) dataAttribute.DataType = DTM.Repo.Get(tempDataTypeId); else dataAttribute.DataType = DTM.Repo.Get().ToList().FirstOrDefault(); #region store constraint if (Model.RangeConstraints.Count > 0 && (Model.RangeConstraints.FirstOrDefault().Min != null || Model.RangeConstraints.FirstOrDefault().Max != null) && (Model.RangeConstraints.FirstOrDefault().Min != 0.0 || Model.RangeConstraints.FirstOrDefault().Max != 0.0)) dataAttribute = storeConstraint(Model.RangeConstraints.First(), dataAttribute); else dataAttribute = deletConstraint(Model.RangeConstraints.First().Id, dataAttribute); if (Model.PatternConstraints.Count > 0 && !String.IsNullOrEmpty(Model.PatternConstraints.FirstOrDefault().MatchingPhrase)) dataAttribute = storeConstraint(Model.PatternConstraints.First(), dataAttribute); else dataAttribute = deletConstraint(Model.PatternConstraints.First().Id, dataAttribute); if (Model.PatternConstraints.Count > 0 && !String.IsNullOrEmpty(Model.DomainConstraints.FirstOrDefault().Terms)) dataAttribute = storeConstraint(Model.DomainConstraints.First(), dataAttribute); else dataAttribute = deletConstraint(Model.DomainConstraints.First().Id, dataAttribute); #endregion DAM.UpdateDataAttribute(dataAttribute); } } else { Session["nameMsg"] = "Name already exist"; Session["Window"] = true; return View("AttributeManager", new DataAttributeManagerModel(Model)); } } } Session["Window"] = false; return RedirectToAction("AttributeManager"); }
public JsonResult getDatatypeList(string Id) { long tempId = Convert.ToInt64(Id); UnitManager unitManager = new UnitManager(); Unit tempUnit = unitManager.Repo.Get(tempId); List<DataType> dataTypeList = new List<DataType>(); if (tempUnit.Name.ToLower() == "none") { DataTypeManager dataTypeManager = new DataTypeManager(); dataTypeList = dataTypeManager.Repo.Get().ToList(); dataTypeList = dataTypeList.OrderBy(p => p.Name).ToList(); } else { dataTypeList = unitManager.Repo.Get(tempId).AssociatedDataTypes.ToList(); dataTypeList = dataTypeList.OrderBy(p => p.Name).ToList(); } return Json(new SelectList(dataTypeList.ToArray(), "Id", "Name"), JsonRequestBehavior.AllowGet); }
private void createMetadataAttribute() { //UnitManager um = new UnitManager(); //Unit km = um.Create("Kilometer", "Km", "This is the Kilometer", "Length", MeasurementSystem.Metric); DataTypeManager dtManager = new DataTypeManager(); DataType dt1 = dtManager.Repo.Get(p => p.Name.Equals("String")).FirstOrDefault(); if (dt1 == null) { dt1 = dtManager.Create("String", "A test String", System.TypeCode.String); } MetadataAttributeManager maManager = new MetadataAttributeManager(); // for unique name checks USE maManager.MetadataAttributeRepo that is searching both simple and compound attribute names var msa1 = maManager.MetadataAttributeRepo.Get(p => p.ShortName.Equals("Simple 1")).FirstOrDefault(); if (msa1 == null) { msa1 = new MetadataSimpleAttribute() { ShortName = "Simple 1", DataType = dt1, }; maManager.Create((MetadataSimpleAttribute)msa1); } var msa2 = maManager.MetadataAttributeRepo.Get(p => p.ShortName.Equals("Simple 2")).FirstOrDefault(); if (msa2 == null) { msa2 = new MetadataSimpleAttribute() { ShortName = "Simple 2", DataType = dt1, }; maManager.Create((MetadataSimpleAttribute)msa2); } MetadataCompoundAttribute mca1 = (MetadataCompoundAttribute)maManager.MetadataAttributeRepo.Get(p => p.ShortName.Equals("Compound 1")).FirstOrDefault(); if (mca1 == null) { mca1 = new MetadataCompoundAttribute() { ShortName = "Compound 1", DataType = dt1, }; MetadataNestedAttributeUsage u1 = new MetadataNestedAttributeUsage() { Label = "First member", Description = "I am a link between Compound 1 and Simple 1", MinCardinality = 0, MaxCardinality = 2, Master = mca1, Member = msa1, }; mca1.MetadataNestedAttributeUsages.Add(u1); MetadataNestedAttributeUsage u2 = new MetadataNestedAttributeUsage() { Label = "Second member", Description = "I am a link between Compound 1 and Simple 2", MinCardinality = 0, MaxCardinality = 2, Master = mca1, Member = msa2, }; mca1.MetadataNestedAttributeUsages.Add(u2); maManager.Create(mca1); } maManager.Delete(msa1); }
public DataTypeModel(long Id) { DataTypeManager dtm = new DataTypeManager(); dataType = dtm.Repo.Get(Id); pattern = DataTypeDisplayPattern.Materialize(dataType.Extra); }
// create read data types in bpp public void CreateDataTypes(ref DataTable mappedDataTypes) { DataTypeManager dataTypeManager = new DataTypeManager(); foreach (DataRow mappedDataType in mappedDataTypes.Rows) { string dtName = mappedDataType["Name"].ToString(); string dtDescription = mappedDataType["Description"].ToString(); DataTypeDisplayPattern dtDisplayPettern = new DataTypeDisplayPattern(); TypeCode dtSystemType = new TypeCode(); foreach (TypeCode type in Enum.GetValues(typeof(TypeCode))) { if (type.ToString().Equals(mappedDataType["SystemType"].ToString())) { dtSystemType = type; } } if (dtSystemType == TypeCode.DateTime) { if (mappedDataType["DisplayPattern"] != null && mappedDataType["DisplayPattern"].ToString() != "") { dtDisplayPettern = DataTypeDisplayPattern.Pattern.Where(p => p.Systemtype.Equals(DataTypeCode.DateTime) && p.Name.Equals(mappedDataType["DisplayPattern"].ToString())).FirstOrDefault(); } else { dtDisplayPettern = DataTypeDisplayPattern.Pattern.Where(p => p.Name.Equals("DateTimeIso")).FirstOrDefault(); } } DataType dataType = new DataType(); // get existing dataTypes DataType existDT = dataTypeManager.Repo.Get().Where(d => d.Name.Equals(dtName) && d.SystemType.ToString().Equals(mappedDataType["SystemType"].ToString()) ).FirstOrDefault(); // return ID of existing dataType or create dataType if (existDT == null && dtSystemType != null) { dataType = dataTypeManager.Create(dtName, dtDescription, dtSystemType); XmlDocument xmlDoc = new XmlDocument(); XmlNode xmlNode; xmlNode = xmlDoc.CreateNode(XmlNodeType.Element, "Extra", null); xmlDoc.AppendChild(xmlNode); xmlNode = xmlDoc.CreateNode(XmlNodeType.Element, "DisplayPattern", null); xmlNode.InnerXml = DataTypeDisplayPattern.Dematerialize(dtDisplayPettern).InnerXml; xmlDoc.DocumentElement.AppendChild(xmlNode); dataType.Extra = xmlDoc; dataTypeManager.Update(dataType); } else { dataType = existDT; } mappedDataType["DataTypesId"] = dataType.Id; } }
public MessageModel storeAtttribute(long Id, string Name, long unitId, long dataTypeId, string Description = "", string cssId = "", bool inUse = false) { Name = Server.UrlDecode(Name); Description = Server.UrlDecode(Description); MessageModel DataStructureValidation = MessageModel.validateAttributeInUse(Id); if (DataStructureValidation.hasMessage && inUse == false) { return DataStructureValidation; } else { DataStructureValidation = MessageModel.validateAttributeName(Id, Name, cssId); if (DataStructureValidation.hasMessage) { return DataStructureValidation; } else { DataContainerManager dataAttributeManager = new DataContainerManager(); DataAttribute dataAttribute; if (Id == 0) { Unit unit = new UnitManager().Repo.Get(unitId); DataType dataType = new DataTypeManager().Repo.Get(dataTypeId); dataAttribute = dataAttributeManager.CreateDataAttribute(Name, Name, Description, false, false, "", MeasurementScale.Categorial, DataContainerType.ReferenceType, "", dataType, unit, null, null, null, null, null, null); return new MessageModel() { Message = dataAttribute.Id.ToString(), hasMessage = false, CssId = "refresh" }; } else { dataAttribute = dataAttributeManager.DataAttributeRepo.Get(Id); dataAttribute.Name = Name; dataAttribute.Description = Description; dataAttribute = dataAttributeManager.UpdateDataAttribute(dataAttribute); return new MessageModel() { Message = Id.ToString(), hasMessage = false, CssId = "refresh" }; } } } }
private void addDataTypes(long unitId, List<string> datatypeNames) { UnitManager unitManager = new UnitManager(); DataTypeManager dataTypeManger = new DataTypeManager(); Unit unit = unitManager.Repo.Get(unitId); // add bpp-dataTypes to the unit DataType dt = new DataType(); foreach (string type in datatypeNames) { dt = dataTypeManger.Repo.Get().Where(d => d.Name.ToLower().Equals(type.ToLower())).FirstOrDefault(); if (dt != null && !(unit.AssociatedDataTypes.Contains(dt))) unit.AssociatedDataTypes.Add(dt); } unitManager.Update(unit); }
// create read attributes in bpp public void CreateAttributes(ref DataTable mappedAttributes) { foreach (DataRow mapAttributesRow in mappedAttributes.Rows) { DataContainerManager attributeManager = new DataContainerManager(); DataTypeManager dataTypeManager = new DataTypeManager(); UnitManager unitManager = new UnitManager(); DataAttribute attribute = new DataAttribute(); // values of the attribute attribute.ShortName = mapAttributesRow["ShortName"].ToString(); attribute.Name = mapAttributesRow["Name"].ToString(); attribute.Description = mapAttributesRow["Description"].ToString(); attribute.IsMultiValue = false; attribute.IsBuiltIn = false; //attribute.Owner = "BMM"; attribute.Scope = ""; attribute.MeasurementScale = MeasurementScale.Categorial; ////////!!!!!!!!fromMapping?????????????????? attribute.ContainerType = DataContainerType.ReferenceType; attribute.EntitySelectionPredicate = ""; attribute.DataType = dataTypeManager.Repo.Get(Convert.ToInt64(mapAttributesRow["DataTypeId"])); attribute.Unit = unitManager.Repo.Get(Convert.ToInt64(mapAttributesRow["UnitId"])); attribute.Methodology = null; attribute.Classification = null; attribute.AggregateFunctions = null; attribute.GlobalizationInfos = null; attribute.Constraints = null; attribute.ExtendedProperties = null; DataAttribute dataAttribute = new DataAttribute(); DataAttribute existAttribute = attributeManager.DataAttributeRepo.Get(a => attribute.Name.Equals(a.Name) && attribute.ShortName.Equals(a.ShortName) && attribute.Unit.Id.Equals(a.Unit.Id) && attribute.DataType.Id.Equals(a.DataType.Id) ).FirstOrDefault(); // if attribute not exists (name, shortName) then create if (existAttribute == null) { dataAttribute = attributeManager.CreateDataAttribute( attribute.ShortName, attribute.Name, attribute.Description, attribute.IsMultiValue, attribute.IsBuiltIn, attribute.Scope, attribute.MeasurementScale, attribute.ContainerType, attribute.EntitySelectionPredicate, attribute.DataType, attribute.Unit, attribute.Methodology, attribute.Classification, attribute.AggregateFunctions, attribute.GlobalizationInfos, attribute.Constraints, attribute.ExtendedProperties ); } else { dataAttribute = existAttribute; } // add attributeId to the mappedAttributes Table mapAttributesRow["AttributeId"] = dataAttribute.Id; } }
// create read units in bpp public void CreateUnits(ref DataTable mappedUnits) { UnitManager unitManager = new UnitManager(); DataTypeManager dataTypeManger = new DataTypeManager(); Unit unit = new Unit(); foreach (DataRow mapUnitsRow in mappedUnits.Rows) { // values of the unit unit.Name = mapUnitsRow["Name"].ToString(); unit.Abbreviation = mapUnitsRow["Abbreviation"].ToString(); unit.Description = mapUnitsRow["Description"].ToString(); if (unit.Description.Length > 255) unit.Description = unit.Description.Substring(0, 255); unit.Dimension = unitManager.DimensionRepo.Get(Convert.ToInt64(mapUnitsRow["DimensionId"])); // find measurement system foreach (MeasurementSystem msCheck in Enum.GetValues(typeof(MeasurementSystem))) { if (msCheck.ToString().Equals(mapUnitsRow["MeasurementSystem"].ToString())) { unit.MeasurementSystem = msCheck; } } // set data type to created unit or add data type to existing unit List<string> Types = mapUnitsRow["DataTypes"].ToString().Split(' ').Distinct().ToList(); // get existing unit or create Unit existU = unitManager.Repo.Get(u => u.Abbreviation.Equals(unit.Abbreviation)).FirstOrDefault(); if (existU == null) { unit = unitManager.Create(unit.Name, unit.Abbreviation, unit.Description, unit.Dimension, unit.MeasurementSystem); addDataTypes(unit.Id, Types); } else { addDataTypes(existU.Id, Types); } // add unit-ID to the mappedUnits Table mapUnitsRow["UnitId"] = unit.Id; } }
private List<DataType> updataAssociatedDataType(Unit unit, long[] newDataTypeIds) { if (unit != null) { DataTypeManager dataTypeManger = new DataTypeManager(); UnitManager unitManager = new UnitManager(); unit = unitManager.Repo.Get(unit.Id); List<DataType> existingDataTypes = unit.AssociatedDataTypes.ToList(); List<DataType> newDataTypes = newDataTypeIds == null ? new List<DataType>() : dataTypeManger.Repo.Query().Where(p => newDataTypeIds.Contains(p.Id)).ToList(); List<DataType> tobeAddedDataTypes = newDataTypes.Except(existingDataTypes).ToList(); if (tobeAddedDataTypes != null && tobeAddedDataTypes.Count > 0) unitManager.AddAssociatedDataType(unit, tobeAddedDataTypes); unit = unitManager.Repo.Get(unit.Id); existingDataTypes = unit.AssociatedDataTypes.ToList(); List<DataType> toBeRemoved = existingDataTypes.Except(newDataTypes).ToList(); if (toBeRemoved != null && toBeRemoved.Count() > 0) unitManager.RemoveAssociatedDataType(unit, toBeRemoved); unit = unitManager.Repo.Get(unit.Id); return unit.AssociatedDataTypes.ToList(); } return null; }
public ActionResult openUnitWindow(long id) { UnitManager unitManager = new UnitManager(); DataTypeManager dataTypeManager = new DataTypeManager(); UnitManagerModel Model; if (id != 0) { Model = new UnitManagerModel(id); ViewBag.Title = PresentationModel.GetViewTitleForTenant( "Edit Unit: " + Model.editUnitModel.Unit.Name + "(Id: " + Model.editUnitModel.Unit.Id + ")", this.Session.GetTenant()); Session["nameMsg"] = null; Session["abbrMsg"] = null; Session["dataTypeMsg"] = null; if (Model.editUnitModel.Unit != new Unit()) { Unit temp = Model.editUnitModel.Unit; if (temp.Id != Model.editUnitModel.Unit.Id) Session["checked"] = null; } Session["Window"] = true; Session["dimensionMsg"] = null; } else { ViewBag.Title = PresentationModel.GetViewTitleForTenant( "Create Unit", this.Session.GetTenant()); Model = new UnitManagerModel(); Session["nameMsg"] = null; Session["abbrMsg"] = null; Session["dataTypeMsg"] = null; Session["Window"] = true; Session["dimensionMsg"] = null; } return View("UnitManager", Model); }