public static bool ExistSystemFieldMappings(long id, LinkElementType type) { //Automatic System Keys starts at 100 //Id = 100, //Version = 101, //DateOfVersion = 102, //MetadataCreationDate = 103, //MetadataLastModfied = 104, //DataFirstEntry = 105, //DataLastModified = 106, // also for Dubline Core date try { IList <Entities.Mapping.Mapping> mapping = CachedMappings(); return(mapping.Where(m => m.Target.ElementId.Equals(id) && m.Target.Type.Equals(type) && 100 <= m.Source.ElementId && m.Source.ElementId <= 106 && m.Source.Type.Equals(LinkElementType.Key) ).ToList().Any()); // return false; // } } catch (Exception ex) { throw ex; } }
/// <summary> /// if a simple attr is mapped to a party with context informations about the parent /// in the database mappings for level 1 & 2 existing for the simple attribute /// level one means then parent to a complex /// level two means then simple to a complex/simple /// </summary> /// <param name="targetId"></param> /// <param name="targetType"></param> /// <returns></returns> public static bool ExistComplexMappingWithParty(long targetId, LinkElementType targetType) { try { IList <Entities.Mapping.Mapping> mapping = CachedMappings(); bool mappings_result = mapping.Where(m => m.Target.ElementId.Equals(targetId) && m.Target.Type.Equals(targetType) && m.Parent != null && m.Parent.Source.Type.Equals(LinkElementType.PartyType) && m.Level.Equals(2) ).ToList().Any(); //if party same level like target bool mappingsWhenPartyIsParent = mapping.Where(m => m.Target.ElementId.Equals(targetId) && m.Target.Type.Equals(targetType) && m.Source.Type.Equals(LinkElementType.PartyType) && m.Level.Equals(1) ).ToList().Any(); return(mappings_result && !mappingsWhenPartyIsParent); } catch (Exception ex) { throw ex; } }
public LinkElement CreateLinkElement(long elementId, LinkElementType type, LinkElementComplexity complexity, string name, string xpath, bool isSequence = false) { Contract.Requires(elementId >= 0); //LinkElement parent = this.GetLinkElement(parentId); LinkElement linkElement; linkElement = new LinkElement() { ElementId = elementId, Type = type, Name = name, XPath = xpath, IsSequence = isSequence, //Parent = parent, Complexity = complexity, }; using (IUnitOfWork uow = this.GetUnitOfWork()) { IRepository <LinkElement> repo = uow.GetRepository <LinkElement>(); repo.Put(linkElement); uow.Commit(); } return(linkElement); }
public static List <Entities.Mapping.Mapping> GetMappings(long sourceId, LinkElementType sourceType, long targetId, LinkElementType targetType) { try { IList <Entities.Mapping.Mapping> mapping = CachedMappings(); var mapping_result = mapping.Where(m => m.Target.ElementId.Equals(targetId) && m.Target.Type.Equals(targetType) && m.Source.ElementId.Equals(sourceId) && m.Source.Type.Equals(sourceType) ).ToList(); if (mapping_result.Any()) { return(mapping_result); } else { return(new List <Entities.Mapping.Mapping>()); } } catch (Exception ex) { throw ex; } }
private static List <LinkElementModel> getChildrenFromMetadataNestedUsage(LinkElementModel model) { MetadataAttributeManager metadataAttributeManager = new MetadataAttributeManager(); try { MetadataNestedAttributeUsage metadataNestedAttributeUsage = metadataAttributeManager.MetadataNestedAttributeUsageRepo.Get(model.ElementId); LinkElementComplexity complexity = LinkElementComplexity.None; LinkElementType type = LinkElementType.ComplexMetadataAttribute; complexity = metadataNestedAttributeUsage.Member.Self is MetadataSimpleAttribute ? LinkElementComplexity.Simple : LinkElementComplexity.Complex; if (complexity == LinkElementComplexity.Complex) { return(getChildrenFromComplexMetadataAttribute(metadataNestedAttributeUsage.Member.Id, model.Position)); } return(new List <LinkElementModel>()); } finally { metadataAttributeManager.Dispose(); } }
public ActionResult ReloadTarget(long sourceId = 1, long targetId = 0, LinkElementType sourceType = LinkElementType.System, LinkElementType targetType = LinkElementType.System, LinkElementPostion position = LinkElementPostion.Target) { MappingManager mappingManager = new MappingManager(); try { LinkElementRootModel model = null; long id = position.Equals(LinkElementPostion.Source) ? sourceId : targetId; LinkElementType type = position.Equals(LinkElementPostion.Source) ? sourceType : targetType; switch (type) { case LinkElementType.System: { model = MappingHelper.LoadfromSystem(position, mappingManager); break; } case LinkElementType.MetadataStructure: { model = MappingHelper.LoadFromMetadataStructure(id, position, mappingManager); break; } } return(PartialView("LinkElemenRoot", model)); } finally { mappingManager.Dispose(); } }
/// <summary> /// Map a node from xml to system key /// </summary> /// <param name="simpleNodeName">name or xpath</param> /// <param name="simpleType"></param> /// <param name="complexNodeName">name or xpath</param> /// <param name="complexType"></param> /// <param name="key"></param> /// <param name="root"></param> /// <param name="metadataRef"></param> /// <param name="mappingManager"></param> private void createToKeyMapping( string simpleNodeName, LinkElementType simpleType, string complexNodeName, LinkElementType complexType, Key key, Mapping root, XDocument metadataRef, MappingManager mappingManager, TransformationRule transformationRule = null) { if (transformationRule == null) { transformationRule = new TransformationRule(); } LinkElement le = createLinkELementIfNotExist(mappingManager, Convert.ToInt64(key), key.ToString(), LinkElementType.Key, LinkElementComplexity.Simple); if (simpleNodeName.Equals(complexNodeName)) { List <XElement> elements = getXElements(simpleNodeName, metadataRef); foreach (XElement xElement in elements) { string sId = xElement.Attribute("id").Value; string name = xElement.Attribute("name").Value; LinkElement tmp = createLinkELementIfNotExist(mappingManager, Convert.ToInt64(sId), name, simpleType, LinkElementComplexity.Simple); Mapping tmpMapping = MappingHelper.CreateIfNotExistMapping(tmp, le, 1, new TransformationRule(), root, mappingManager); MappingHelper.CreateIfNotExistMapping(tmp, le, 2, transformationRule, tmpMapping, mappingManager); } } else { IEnumerable <XElement> complexElements = getXElements(complexNodeName, metadataRef); foreach (var complex in complexElements) { string sIdComplex = complex.Attribute("id").Value; string nameComplex = complex.Attribute("name").Value; LinkElement tmpComplexElement = createLinkELementIfNotExist(mappingManager, Convert.ToInt64(sIdComplex), nameComplex, complexType, LinkElementComplexity.Complex); Mapping complexMapping = MappingHelper.CreateIfNotExistMapping(tmpComplexElement, le, 1, new TransformationRule(), root, mappingManager); IEnumerable <XElement> simpleElements = XmlUtility.GetAllChildren(complex).Where(s => s.Name.LocalName.Equals(simpleNodeName)); foreach (XElement xElement in simpleElements) { string sId = xElement.Attribute("id").Value; string name = xElement.Attribute("name").Value; LinkElement tmp = createLinkELementIfNotExist(mappingManager, Convert.ToInt64(sId), name, simpleType, LinkElementComplexity.Simple); MappingHelper.CreateIfNotExistMapping(tmp, le, 2, transformationRule, complexMapping, mappingManager); } } } }
public Mapping CreateMapping( long source_elementId, LinkElementType source_type, LinkElementComplexity source_complexity, string source_name, string source_xpath, long target_elementId, LinkElementType target_type, LinkElementComplexity target_complexity, string target_name, string target_xpath, bool source_isSequence = false, bool target_isSequence = false, TransformationRule rule = null, long parentMappingId = 0 ) { LinkElement source = CreateLinkElement( source_elementId, source_type, source_complexity, source_name, source_xpath, source_isSequence ); LinkElement target = CreateLinkElement( target_elementId, target_type, target_complexity, target_name, target_xpath, target_isSequence ); Mapping mapping = new Mapping(); mapping.Source = source; mapping.Target = target; mapping.TransformationRule = rule; if (parentMappingId > 0) { mapping.Parent = this.GetUnitOfWork().GetReadOnlyRepository <Mapping>().Get(parentMappingId); } using (IUnitOfWork uow = this.GetUnitOfWork()) { IRepository <Mapping> repo = uow.GetRepository <Mapping>(); repo.Put(mapping); uow.Commit(); } return(mapping); }
public static string GetValueFromSystem(long partyid, long targetElementId, LinkElementType targetElementType) { MappingManager _mappingManager = new MappingManager(); PartyTypeManager partyTypeManager = new PartyTypeManager(); PartyManager partyManager = new PartyManager(); try { using (IUnitOfWork uow = (new object()).GetUnitOfWork()) { string value = ""; IList <Entities.Mapping.Mapping> mapping = CachedMappings(); var mapping_result = mapping.Where(m => m.Target.ElementId.Equals(targetElementId) && m.Target.Type.Equals(targetElementType) && m.Source.Type.Equals(LinkElementType.PartyCustomType) ).ToList(); if (mapping_result.Any()) { string mask = ""; mask = mapping_result.FirstOrDefault().TransformationRule.Mask; foreach (var mapping_element in mapping_result) { long attributeId = mapping_element.Source.ElementId; PartyCustomAttributeValue attrValue = partyManager.PartyCustomAttributeValueRepository.Query() .Where(v => v.CustomAttribute.Id.Equals(attributeId) && v.Party.Id.Equals(partyid)) .FirstOrDefault(); if (attrValue != null) { List <string> regExResultList = transform(attrValue.Value, mapping_element.TransformationRule); string placeHolderName = attrValue.CustomAttribute.Name; mask = setOrReplace(mask, regExResultList, placeHolderName); } } if (mask.ToLower().Contains(value.ToLower())) { return(mask); } } } return(""); } finally { _mappingManager.Dispose(); partyTypeManager.Dispose(); partyManager.Dispose(); } }
private static bool hasSimpleMapping(long id, LinkElementType type) { if (MappingUtils.ExistSimpleMappingWithParty(id, type) || MappingUtils.ExistSimpleMappingWithPartyCustomType(id, type)) { return(true); } return(false); }
public LinkElementRootModel(LinkElementType type, long elementId, string name, LinkElementPostion position) { Id = ElementId; ElementId = elementId; Type = type; Name = name; LinkElementContainers = new List <LinkElementContainerModel>(); LinkElements = new List <LinkElementModel>(); Position = position; }
// GET: DIM/Mapping public ActionResult Index(long sourceId = 1, long targetId = 0, LinkElementType type = LinkElementType.System) { MappingManager mappingManager = new MappingManager(); try { MappingMainModel model = new MappingMainModel(); // load from mds example model.Source = MappingHelper.LoadFromMetadataStructure(sourceId, LinkElementPostion.Source, mappingManager); switch (type) { case LinkElementType.System: { model.Target = MappingHelper.LoadfromSystem(LinkElementPostion.Target, mappingManager); model.SelectionList = MappingHelper.LoadSelectionList(); break; } case LinkElementType.MetadataStructure: { model.Target = MappingHelper.LoadFromMetadataStructure(targetId, LinkElementPostion.Target, mappingManager); model.SelectionList = MappingHelper.LoadSelectionList(); break; } } if (model.Source != null && model.Target != null) { //get linkelements LinkElement source = mappingManager.GetLinkElement(sourceId, LinkElementType.MetadataStructure); LinkElement target = mappingManager.GetLinkElement(targetId, type); if (source != null && target != null) { //get root mapping Mapping rootMapping = mappingManager.GetMapping(source, target); if (rootMapping != null) { //get complex mappings model.ParentMappings = MappingHelper.LoadMappings(rootMapping); } } } return(View(model)); } finally { mappingManager.Dispose(); } }
public ActionResult Switch(long sourceId = 1, long targetId = 0, LinkElementType sourceType = LinkElementType.System, LinkElementType targetType = LinkElementType.System, LinkElementPostion position = LinkElementPostion.Target) { return(RedirectToAction("Mapping", new { sourceId = targetId, targetId = sourceId, sourceType = targetType, targetType = sourceType, position = position })); }
/// <summary> /// /// </summary> /// <param name="targetElementId"></param> /// <param name="targetType"></param> /// <param name="sourceRootId"></param> /// <param name="metadata"></param> /// <returns></returns> public static List <string> GetValuesFromMetadata(long targetElementId, LinkElementType targetType, long sourceRootId, XDocument metadata) { //grab values from metadata where targetelementid and targetType is mapped // e.g. get title from metadata MappingManager mappingManager = new MappingManager(); try { List <string> tmp = new List <string>(); var mappings = mappingManager.GetMappings().Where(m => m.Target.ElementId.Equals(targetElementId) && m.Target.Type.Equals(targetType) && getRootMapping(m) != null && getRootMapping(m).Source.ElementId.Equals(sourceRootId) && getRootMapping(m).Source.Type == LinkElementType.MetadataStructure && m.Level.Equals(2)); foreach (var m in mappings) { Dictionary <string, string> AttrDic = new Dictionary <string, string>(); if (m.Source.Type.Equals(LinkElementType.MetadataAttributeUsage) || m.Source.Type.Equals(LinkElementType.MetadataNestedAttributeUsage)) { AttrDic.Add("id", m.Source.ElementId.ToString()); AttrDic.Add("name", m.Source.Name); AttrDic.Add("type", "MetadataAttributeUsage"); //find sourceelement in xmldocument IEnumerable <XElement> elements = XmlUtility.GetXElementsByAttribute(AttrDic, metadata); foreach (var element in elements) { tmp.Add(element.Value); } } } return(tmp); } finally { mappingManager.Dispose(); } }
public static long GetId(long elementId, LinkElementType type, MappingManager mappingManager) { long linkElementId = 0; LinkElement linkElement = mappingManager.LinkElementRepo.Get() .FirstOrDefault(le => le.ElementId.Equals(elementId) && le.Type.Equals(type)); if (linkElement != null) { linkElementId = linkElement.Id; } return(linkElementId); }
private bool Exist(string name, LinkElementType type) { using (var uow = this.GetUnitOfWork()) { if (type == LinkElementType.MetadataAttributeUsage) { if (uow.GetReadOnlyRepository <MetadataAttributeUsage>().Get().Any(m => m.Label.ToLower().Equals(name.ToLower()))) { return(true); } } if (type == LinkElementType.MetadataNestedAttributeUsage) { if (uow.GetReadOnlyRepository <MetadataNestedAttributeUsage>().Get().Any(m => m.Label.ToLower().Equals(name.ToLower()))) { return(true); } } if (type == LinkElementType.MetadataPackageUsage) { if (uow.GetReadOnlyRepository <MetadataPackageUsage>().Get().Any(m => m.Label.ToLower().Equals(name.ToLower()))) { return(true); } } if (type == LinkElementType.SimpleMetadataAttribute) { if (uow.GetReadOnlyRepository <MetadataSimpleAttribute>().Get().Any(m => m.Name.ToLower().Equals(name.ToLower()))) { return(true); } } if (type == LinkElementType.ComplexMetadataAttribute) { if (uow.GetReadOnlyRepository <MetadataCompoundAttribute>().Get().Any(m => m.Name.ToLower().Equals(name.ToLower()))) { return(true); } } } return(false); }
/// <summary> /// e.g. root is a metadata structre, the function will check if there is any mapping to any entity /// </summary> /// <param name="rootId"></param> /// <param name="rootType"></param> /// <returns></returns> public static bool ExistMappingWithEntityFromRoot(long rootId, LinkElementType rootType) { try { IList <Entities.Mapping.Mapping> mapping = CachedMappings(); return(mapping.Where(m => m.Parent != null && m.Parent.Source.Type.Equals(LinkElementType.Entity) && m.Parent.Target.Type.Equals(rootType) && m.Parent.Target.ElementId.Equals(rootId) ).ToList().Any()); } catch (Exception ex) { throw ex; } }
public static bool ExistMappingWithParty(long targetId, LinkElementType targetType, long partyId) { try { IList <Entities.Mapping.Mapping> mapping = CachedMappings(); return(mapping.Where(m => m.Target.ElementId.Equals(targetId) && m.Target.Type.Equals(targetType) && m.Parent != null && m.Parent.Source.ElementId.Equals(partyId) ).ToList().Any()); } catch (Exception ex) { throw ex; } }
private void createFromPartyTypeMapping( string simpleNodeName, LinkElementType simpleType, string complexNodeName, LinkElementType complexType, PartyCustomAttribute partyCustomAttr, PartyType partyType, Mapping root, XDocument metadataRef, MappingManager mappingManager, TransformationRule transformationRule = null) { if (transformationRule == null) { transformationRule = new TransformationRule(); } LinkElement le = createLinkELementIfNotExist(mappingManager, Convert.ToInt64(partyType.Id), partyType.Title, LinkElementType.PartyType, LinkElementComplexity.Complex); XElement complex = getXElements(complexNodeName, metadataRef).FirstOrDefault(); string sIdComplex = complex.Attribute("id").Value; string nameComplex = complex.Attribute("name").Value; LinkElement tmpComplexElement = createLinkELementIfNotExist(mappingManager, Convert.ToInt64(sIdComplex), nameComplex, complexType, LinkElementComplexity.Complex); Mapping complexMapping = MappingHelper.CreateIfNotExistMapping(le, tmpComplexElement, 1, new TransformationRule(), root, mappingManager); IEnumerable <XElement> simpleElements = XmlUtility.GetAllChildren(complex).Where(s => s.Name.LocalName.Equals(simpleNodeName)); LinkElement simpleLe = createLinkELementIfNotExist(mappingManager, Convert.ToInt64(partyCustomAttr.Id), partyCustomAttr.Name, LinkElementType.PartyCustomType, LinkElementComplexity.Simple); foreach (XElement xElement in simpleElements) { string sId = xElement.Attribute("id").Value; string name = xElement.Attribute("name").Value; LinkElement tmp = createLinkELementIfNotExist(mappingManager, Convert.ToInt64(sId), name, simpleType, LinkElementComplexity.Simple); MappingHelper.CreateIfNotExistMapping(simpleLe, tmp, 2, transformationRule, complexMapping, mappingManager); } }
private static List <LinkElementModel> getChildrenFromComplexMetadataAttribute(long metadataCompountAttributeId, LinkElementPostion position) { List <LinkElementModel> tmp = new List <LinkElementModel>(); MetadataAttributeManager metadataAttributeManager = new MetadataAttributeManager(); try { MetadataCompoundAttribute mca = metadataAttributeManager.MetadataCompoundAttributeRepo.Get(metadataCompountAttributeId); foreach (var attr in mca.MetadataNestedAttributeUsages) { LinkElementComplexity complexity = LinkElementComplexity.None; LinkElementType type = LinkElementType.ComplexMetadataAttribute; complexity = attr.Member.Self is MetadataSimpleAttribute ? LinkElementComplexity.Simple : LinkElementComplexity.Complex; //type = attr.Member.Self is MetadataSimpleAttribute // ? LinkElementType.SimpleMetadataAttribute // : LinkElementType.ComplexMetadataAttribute; type = LinkElementType.MetadataNestedAttributeUsage; tmp.Add( new LinkElementModel( 0, attr.Id, type, attr.Label, "", position, complexity, attr.Description) ); } return(tmp); } finally { metadataAttributeManager.Dispose(); } }
public LinkElementModel( long id, long elementid, LinkElementType type, string name, string xpath, LinkElementPostion position, LinkElementComplexity complexity, string description = "" ) { Id = id; ElementId = elementid; Type = type; Name = name; XPath = xpath; Description = description; Position = position; Children = new List <LinkElementModel>(); Complexity = complexity; }
// GET: Test public ActionResult Index(long id = -1) { DatasetManager datasetManager = new DatasetManager(); try { //get all var x = MappingUtils.GetAllMatchesInSystem(1, LinkElementType.MetadataNestedAttributeUsage); // get all where value = david x = MappingUtils.GetAllMatchesInSystem(1, LinkElementType.MetadataNestedAttributeUsage, "David"); // get value from metadata over the system // partytpe person - attr firstname long partyCustomtAttr = 1; LinkElementType type = LinkElementType.PartyCustomType; long datasetId = id; DatasetVersion datasetVersion = datasetManager.GetDatasetLatestVersion(datasetId); List <string> tmp = MappingUtils.GetValuesFromMetadata(partyCustomtAttr, type, datasetVersion.Dataset.MetadataStructure.Id, XmlUtility.ToXDocument(datasetVersion.Metadata)); tmp = MappingUtils.GetValuesFromMetadata(Convert.ToInt64(Key.Keyword), LinkElementType.Key, datasetVersion.Dataset.MetadataStructure.Id, XmlUtility.ToXDocument(datasetVersion.Metadata)); tmp = MappingUtils.GetValuesFromMetadata(Convert.ToInt64(Key.Author), LinkElementType.Key, datasetVersion.Dataset.MetadataStructure.Id, XmlUtility.ToXDocument(datasetVersion.Metadata)); tmp = MappingUtils.GetValuesFromMetadata(Convert.ToInt64(Key.Title), LinkElementType.Key, datasetVersion.Dataset.MetadataStructure.Id, XmlUtility.ToXDocument(datasetVersion.Metadata)); return(View("Index")); } finally { datasetManager.Dispose(); } }
private LinkElement createLinkELementIfNotExist( MappingManager mappingManager, long id, string name, LinkElementType type, LinkElementComplexity complexity) { LinkElement element = mappingManager.GetLinkElement(id, name, type); if (element == null) { element = mappingManager.CreateLinkElement( id, type, complexity, name, "" ); } return(element); }
/// <summary> /// e.g. /// targetElementId : 3 /// targetType : nested usage /// value search /// </summary> /// <param name="targetElementId"></param> /// <param name="targetType"></param> /// <param name="value"></param> /// <returns></returns> public static List <string> GetAllMatchesInSystem(long targetElementId, LinkElementType targetType, string value = "") { try { //get all mapppings where target is mapped // LinkElementType.PartyCustomType is set because of the function name // all mapped attributes are LinkElementType.PartyCustomType in this case using (IUnitOfWork uow = (new object()).GetUnitOfWork()) { List <string> tmp = new List <string>(); var mappings = uow.GetReadOnlyRepository <BExIS.Dim.Entities.Mapping.Mapping>().Get() // this get is here because the expression is not supported by NH! .Where(m => m.Target.ElementId.Equals(targetElementId) && m.Target.Type.Equals(targetType) && m.Source.Type.Equals(LinkElementType.PartyCustomType) ).ToList(); tmp = getAllValuesFromSystem(mappings, value); return(tmp); } } catch (Exception ex) { throw ex; } /* * e.g. * Metadata Attr Usage -> MicroAgent/Name -> entering "David Blaa" * * linkt to * * Person/FirstName David * Person/SecondName Blaa * * * => all mappings know must be only the Person/FirstName & Person/SecondName */ }
/// <summary> /// /// </summary> /// <param name="targetElementId"></param> /// <param name="targetElementType"></param> /// <param name="parentPartyId"></param> /// <returns></returns> public static bool PartyAttrIsMain(long targetElementId, LinkElementType targetElementType) { try { //get all mapppings where target is mapped // LinkElementType.PartyCustomType is set because of the function name // all mapped attributes are LinkElementType.PartyCustomType in this case using (IUnitOfWork uow = (new object()).GetUnitOfWork()) { List <MappingPartyResultElemenet> tmp = new List <MappingPartyResultElemenet>(); //Select all mappings where the target is mapped to a party custom attr with the party id IList <Entities.Mapping.Mapping> mapping = CachedMappings(); var mapping_result = mapping.Where(m => m.Target.ElementId.Equals(targetElementId) && m.Target.Type.Equals(targetElementType) && m.Source.Type.Equals(LinkElementType.PartyCustomType) && m.Parent != null ); foreach (var mapping_element in mapping_result) { if (mapping != null) { PartyCustomAttribute pca = uow.GetReadOnlyRepository <PartyCustomAttribute>().Get(mapping_element.Source.ElementId); if (pca != null && pca.IsMain == true) { return(true); } } } return(false); } } catch (Exception ex) { throw ex; } }
public LinkElementRootListItem(long elementId, string name, LinkElementType type) { Id = elementId + "_" + type; Name = name + " (" + type + ")"; }
public static void addUsageAsLinkElement(BaseUsage usage, string parentXpath, LinkElementRootModel rootModel, LinkElementModel parent) { int min = usage.MinCardinality; string childName = ""; //MappingManager mappingManager = new MappingManager(); string usageName = usage.Label; string typeName = "x"; long typeId = 0; string typeDescription = ""; string xPath = parentXpath; LinkElementType type = LinkElementType.ComplexMetadataAttribute; LinkElementComplexity complexity = LinkElementComplexity.Complex; bool addTypeAsLinkElement = false; if (usage is MetadataPackageUsage) { type = LinkElementType.MetadataPackageUsage; typeName = ((MetadataPackageUsage)usage).MetadataPackage.Name; } else if (usage is MetadataNestedAttributeUsage) { type = LinkElementType.MetadataNestedAttributeUsage; MetadataNestedAttributeUsage n = (MetadataNestedAttributeUsage)usage; typeName = n.Member.Name; if (n.Member.Self is MetadataCompoundAttribute) { addTypeAsLinkElement = true; typeId = n.Member.Self.Id; typeDescription = n.Member.Self.Description; } if (n.Member.Self is MetadataSimpleAttribute) { complexity = LinkElementComplexity.Simple; } } else if (usage is MetadataAttributeUsage) { type = LinkElementType.MetadataAttributeUsage; MetadataAttributeUsage u = (MetadataAttributeUsage)usage; typeName = u.MetadataAttribute.Name; if (u.MetadataAttribute.Self is MetadataCompoundAttribute) { addTypeAsLinkElement = true; typeId = u.MetadataAttribute.Self.Id; typeDescription = u.MetadataAttribute.Self.Description; } if (u.MetadataAttribute.Self is MetadataSimpleAttribute) { complexity = LinkElementComplexity.Simple; } } // add usage xPath = parentXpath + "/" + usageName.Replace(" ", string.Empty) + "/" + typeName; long linkElementId = 0; string mask = ""; LinkElement linkElement = type.GetUnitOfWork().GetReadOnlyRepository <LinkElement>().Get() .FirstOrDefault(le => le.ElementId.Equals(usage.Id) && le.Type.Equals(type)); if (linkElement != null) { linkElementId = linkElement.Id; } LinkElementModel LEModel = new LinkElementModel( linkElementId, usage.Id, type, usage.Label, xPath, rootModel.Position, complexity, usage.Description); LEModel.Parent = parent; rootModel.LinkElements.Add(LEModel); //add type if (addTypeAsLinkElement) { linkElementId = 0; linkElement = type.GetUnitOfWork().GetReadOnlyRepository <LinkElement>().Get() .FirstOrDefault( le => le.ElementId.Equals(typeId) && le.Type.Equals(LinkElementType.ComplexMetadataAttribute)); if (linkElement != null) { linkElementId = linkElement.Id; } LEModel = new LinkElementModel( linkElementId, typeId, LinkElementType.ComplexMetadataAttribute, typeName, xPath, rootModel.Position, complexity, typeDescription); LEModel.Parent = parent; if (!rootModel.LinkElements.Any(le => le.ElementId.Equals(typeId) && le.Type.Equals(LinkElementType.ComplexMetadataAttribute))) { rootModel.LinkElements.Add(LEModel); } } //Debug.WriteLine("1: " + LEModel.Name + " " + LEModel.Type); List <BaseUsage> childrenUsages = metadataStructureUsageHelper.GetChildren(usage.Id, usage.GetType()); if (childrenUsages.Count > 0) { foreach (BaseUsage childUsage in childrenUsages) { addUsageAsLinkElement(childUsage, xPath, rootModel, LEModel); } //AddChildrens //addLinkElementsFromChildrens(usage, xPath, rootModel); } }
public static MetadataAttributeModel CreateMetadataAttributeModel(BaseUsage current, BaseUsage parent, long metadataStructureId, int packageModelNumber, long parentStepId) { MetadataAttribute metadataAttribute; List <object> domainConstraintList = new List <object>(); string constraintsDescription = ""; double lowerBoundary = 0; double upperBoundary = 0; LinkElementType type = LinkElementType.MetadataNestedAttributeUsage; bool locked = false; bool entityMappingExist = false; bool partyMappingExist = false; string metadataAttributeName = ""; //simple bool partySimpleMappingExist = false; //complex bool partyComplexMappingExist = false; if (current is MetadataNestedAttributeUsage) { MetadataNestedAttributeUsage mnau = (MetadataNestedAttributeUsage)current; metadataAttribute = mnau.Member; type = LinkElementType.MetadataNestedAttributeUsage; } else { MetadataAttributeUsage mau = (MetadataAttributeUsage)current; metadataAttribute = mau.MetadataAttribute; type = LinkElementType.MetadataAttributeUsage; } if (metadataAttribute.Constraints.Where(c => (c is DomainConstraint)).Count() > 0) { domainConstraintList = createDomainContraintList(metadataAttribute); } if (metadataAttribute.Constraints.Count > 0) { foreach (Constraint c in metadataAttribute.Constraints) { if (string.IsNullOrEmpty(constraintsDescription)) { constraintsDescription = c.FormalDescription; } else { constraintsDescription = String.Format("{0}\n{1}", constraintsDescription, c.FormalDescription); } } if (metadataAttribute.DataType.Name == "string" && metadataAttribute.Constraints.Where(c => (c is RangeConstraint)).Count() > 0) { foreach (RangeConstraint r in metadataAttribute.Constraints.Where(c => (c is RangeConstraint))) { lowerBoundary = r.Lowerbound; upperBoundary = r.Upperbound; } } } //set metadata attr name metadataAttributeName = metadataAttribute.Name; //load displayPattern DataTypeDisplayPattern dtdp = DataTypeDisplayPattern.Materialize(metadataAttribute.DataType.Extra); string displayPattern = ""; if (dtdp != null) { displayPattern = dtdp.StringPattern; } //ToDO/Check if dim is active //check if its linked with a system field // locked = MappingUtils.ExistSystemFieldMappings(current.Id, type); // check if a mapping for parties exits partyMappingExist = MappingUtils.ExistMappingWithParty(current.Id, type); // check if mapping to this metadata attribute is simple or complex. // complex means, that the attribute is defined in the context of the parent // e.g. name of User // simple means, that the attribute is not defined in the context of the // e.g. DataCreator Name in Contacts as list of contacts partySimpleMappingExist = hasSimpleMapping(current.Id, type); partyComplexMappingExist = hasComplexMapping(current.Id, type); // check if a mapping for entites exits entityMappingExist = MappingUtils.ExistMappingWithEntity(current.Id, type); return(new MetadataAttributeModel { Id = current.Id, Number = 1, ParentModelNumber = packageModelNumber, MetadataStructureId = metadataStructureId, MetadataAttributeName = metadataAttributeName, Parent = parent, Source = current, DisplayName = current.Label, Discription = current.Description, ConstraintDescription = constraintsDescription, DataType = metadataAttribute.DataType.Name, SystemType = metadataAttribute.DataType.SystemType, DisplayPattern = displayPattern, MinCardinality = current.MinCardinality, MaxCardinality = current.MaxCardinality, NumberOfSourceInPackage = 1, first = true, DomainList = domainConstraintList, last = true, MetadataAttributeId = metadataAttribute.Id, ParentStepId = parentStepId, Errors = null, Locked = locked, EntityMappingExist = entityMappingExist, PartyMappingExist = partyMappingExist, PartySimpleMappingExist = partySimpleMappingExist, PartyComplexMappingExist = partyComplexMappingExist, LowerBoundary = lowerBoundary, UpperBoundary = upperBoundary, }); }
public LinkElement GetLinkElement(long elementid, string name, LinkElementType type) { return(this.GetUnitOfWork().GetReadOnlyRepository <LinkElement>().Get().FirstOrDefault(le => le.ElementId.Equals(elementid) && le.Name.Equals(name) && le.Type.Equals(type))); }
public ActionResult Mapping(long sourceId = 1, long targetId = 0, LinkElementType sourceType = LinkElementType.System, LinkElementType targetType = LinkElementType.System, LinkElementPostion position = LinkElementPostion.Target) { MappingManager mappingManager = new MappingManager(); try { MappingMainModel model = new MappingMainModel(); // load from mds example //model.Source = MappingHelper.LoadFromMetadataStructure(sourceId, LinkElementPostion.Source); /* * Here the source and target will switch the sides */ #region load Source from Target switch (sourceType) { case LinkElementType.System: { model.Source = MappingHelper.LoadfromSystem(LinkElementPostion.Source, mappingManager); if (!model.SelectionList.Any()) { model.SelectionList = MappingHelper.LoadSelectionList(); } break; } case LinkElementType.MetadataStructure: { model.Source = MappingHelper.LoadFromMetadataStructure(sourceId, LinkElementPostion.Source, mappingManager); if (!model.SelectionList.Any()) { model.SelectionList = MappingHelper.LoadSelectionList(); } break; } } #endregion #region load Target switch (targetType) { case LinkElementType.System: { model.Target = MappingHelper.LoadfromSystem(LinkElementPostion.Target, mappingManager); if (!model.SelectionList.Any()) { model.SelectionList = MappingHelper.LoadSelectionList(); } break; } case LinkElementType.MetadataStructure: { model.Target = MappingHelper.LoadFromMetadataStructure(targetId, LinkElementPostion.Target, mappingManager); if (!model.SelectionList.Any()) { model.SelectionList = MappingHelper.LoadSelectionList(); } break; } } #endregion if (model.Source != null && model.Target != null) { //get linkelements LinkElement source = mappingManager.GetLinkElement(sourceId, sourceType); LinkElement target = mappingManager.GetLinkElement(targetId, targetType); if (source != null && target != null) { //get root mapping Mapping rootMapping = mappingManager.GetMapping(source, target); if (rootMapping != null) { //get complex mappings model.ParentMappings = MappingHelper.LoadMappings(rootMapping); } } } return(View("Index", model)); } finally { mappingManager.Dispose(); } }