예제 #1
0
        public static List <ComplexMappingModel> LoadMappings(Mapping rootMapping)
        {
            MappingManager mappingManager = new MappingManager();

            try
            {
                List <ComplexMappingModel> tmp = new List <ComplexMappingModel>();

                //get all complex mappings
                List <Mapping> mappings = mappingManager.GetChildMapping(rootMapping.Id, 1).ToList();

                foreach (var mapping in mappings)
                {
                    ComplexMappingModel model = CreateComplexMappingModel(mapping);


                    //get all complex mappings
                    List <Mapping> childMappings = mappingManager.GetChildMapping(mapping.Id, 2).ToList();


                    foreach (var cm in childMappings)
                    {
                        //ToDO Add transformation rule
                        model.SimpleMappings.Add(CreateSimpleMappingModel(cm, cm.Source, cm.Target));
                    }

                    tmp.Add(model);
                }
                return(tmp);
            }
            finally
            {
                mappingManager.Dispose();
            }
        }
예제 #2
0
        public static LinkElement CreateLinkElement(LinkElementModel model)
        {
            MappingManager mappingManager = new MappingManager();

            try
            {
                Debug.WriteLine("CreateLinkElement");
                Debug.WriteLine(model.ElementId);
                Debug.WriteLine(model.Type);
                Debug.WriteLine(model.Name);

                if (model.Parent != null)
                {
                    Debug.WriteLine("Parent");
                    Debug.WriteLine(model.Parent.ElementId);
                    Debug.WriteLine(model.Parent.Type);
                    Debug.WriteLine(model.Parent.Name);
                    Debug.WriteLine("------------------");
                }

                return(mappingManager.CreateLinkElement(
                           model.ElementId,
                           model.Type,
                           model.Complexity,
                           model.Name,
                           model.XPath
                           ));
            }
            finally
            {
                mappingManager.Dispose();
            }
        }
예제 #3
0
        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();
            }
        }
예제 #4
0
        public ActionResult SaveMapping(ComplexMappingModel model)
        {
            MappingManager mappingManager = new MappingManager();

            //save link element if not exits
            //source
            try
            {
                #region save or update RootMapping

                //create source Parents if not exist
                LinkElement sourceParent = MappingHelper.CreateIfNotExistLinkElement(model.Source.Parent, mappingManager);

                //create source Parents if not exist
                LinkElement targetParent = MappingHelper.CreateIfNotExistLinkElement(model.Target.Parent, mappingManager);

                //create root mapping if not exist
                Mapping rootMapping = MappingHelper.CreateIfNotExistMapping(sourceParent, targetParent, 0, null, null, mappingManager);

                #endregion

                #region save or update complex mapping
                LinkElement source;
                LinkElement target;

                //create source
                source = MappingHelper.CreateIfNotExistLinkElement(model.Source, sourceParent.Id, mappingManager);

                model.Source.Id = source.Id;
                model.Source    = MappingHelper.LoadChildren(model.Source);

                //create target
                target = MappingHelper.CreateIfNotExistLinkElement(model.Target, targetParent.Id, mappingManager);

                model.Target.Id = target.Id;
                model.Target    = MappingHelper.LoadChildren(model.Target);

                //save mapping
                Mapping mapping = MappingHelper.CreateIfNotExistMapping(source, target, 1, null, rootMapping, mappingManager);
                model.Id       = mapping.Id;
                model.ParentId = mapping.Parent.Id;
                #endregion

                #region create or update simple mapping

                MappingHelper.UpdateSimpleMappings(source.Id, target.Id, model.SimpleMappings, mapping, mappingManager);

                #endregion

                //load all mappings
                return(PartialView("Mapping", model));
            }
            finally
            {
                mappingManager.Dispose();
                MappingUtils.Clear();
            }
        }
예제 #5
0
        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();
            }
        }
예제 #6
0
        // 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();
            }
        }
예제 #7
0
        /// <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();
            }
        }
예제 #8
0
        public static LinkElement CreateLinkElement(LinkElementModel model, long parentId)
        {
            MappingManager mappingManager = new MappingManager();

            try
            {
                return(mappingManager.CreateLinkElement(
                           model.ElementId,
                           model.Type,
                           model.Complexity,
                           model.Name,
                           model.XPath,
                           false
                           ));
            }
            finally
            {
                mappingManager.Dispose();
            }
        }
예제 #9
0
        public static bool IsSimpleElement(long id)
        {
            MappingManager mappingManager = new MappingManager();


            try
            {
                LinkElement le = mappingManager.GetLinkElement(id);

                if (le.Complexity == LinkElementComplexity.Simple)
                {
                    return(true);
                }

                return(false);
            }
            finally
            {
                mappingManager.Dispose();
            }
        }
예제 #10
0
        public static bool ExistLinkElement(LinkElementModel leModel)
        {
            MappingManager mappingManager = new MappingManager();

            try
            {
                if (mappingManager.LinkElementRepo.Get()
                    .Any(le => le.ElementId.Equals(leModel.ElementId) &&
                         le.Type.Equals(leModel.Type) &&
                         le.Complexity.Equals(leModel.Complexity)))
                {
                    return(true);
                }

                return(false);
            }
            finally
            {
                mappingManager.Dispose();
            }
        }
예제 #11
0
        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();
            }
        }
예제 #12
0
        public ActionResult ReloadMapping(long sourceId = 1, long targetId = 0, LinkElementType sourceType = LinkElementType.System, LinkElementType targetType = LinkElementType.System, LinkElementPostion position = LinkElementPostion.Target)
        {
            MappingManager mappingManager = new MappingManager();

            try
            {
                List <ComplexMappingModel> model = new List <ComplexMappingModel>();

                // load from mds example
                LinkElementRootModel source = null;

                switch (sourceType)
                {
                case LinkElementType.System:
                {
                    source = MappingHelper.LoadfromSystem(LinkElementPostion.Source, mappingManager);

                    break;
                }

                case LinkElementType.MetadataStructure:
                {
                    source = MappingHelper.LoadFromMetadataStructure(targetId, LinkElementPostion.Source, mappingManager);
                    break;
                }
                }

                LinkElementRootModel target = null;
                switch (targetType)
                {
                case LinkElementType.System:
                {
                    target = MappingHelper.LoadfromSystem(LinkElementPostion.Target, mappingManager);

                    break;
                }

                case LinkElementType.MetadataStructure:
                {
                    target = MappingHelper.LoadFromMetadataStructure(targetId, LinkElementPostion.Target, mappingManager);
                    break;
                }
                }

                if (target != null)
                {
                    //get linkelements
                    LinkElement sourceLE = mappingManager.GetLinkElement(sourceId, sourceType);
                    LinkElement targetLE = mappingManager.GetLinkElement(targetId, targetType);

                    if (sourceLE != null && targetLE != null)
                    {
                        //get root mapping
                        Mapping rootMapping = mappingManager.GetMapping(sourceLE, targetLE);

                        if (rootMapping != null)
                        {
                            //get complex mappings
                            model = MappingHelper.LoadMappings(rootMapping);
                        }
                    }
                }


                return(PartialView("Mappings", model));
            }
            finally
            {
                mappingManager.Dispose();
            }
        }
예제 #13
0
        private void createPartyTypeMappings()
        {
            object tmp = "";
            List <MetadataStructure> metadataStructures =
                tmp.GetUnitOfWork().GetReadOnlyRepository <MetadataStructure>().Get().ToList();
            List <PartyType> partyTypes =
                tmp.GetUnitOfWork().GetReadOnlyRepository <PartyType>().Get().ToList();
            List <PartyCustomAttribute> partyCustomAttrs =
                tmp.GetUnitOfWork().GetReadOnlyRepository <PartyCustomAttribute>().Get().ToList();

            MappingManager    mappingManager    = new MappingManager();
            XmlMetadataWriter xmlMetadataWriter = new XmlMetadataWriter(XmlNodeMode.xPath);

            try
            {
                #region ABCD BASIC

                if (metadataStructures.Any(m => m.Name.ToLower().Equals("basic abcd")))
                {
                    MetadataStructure metadataStructure =
                        metadataStructures.FirstOrDefault(m => m.Name.ToLower().Equals("basic abcd"));

                    XDocument metadataRef = xmlMetadataWriter.CreateMetadataXml(metadataStructure.Id);


                    //create root mapping
                    LinkElement abcdRoot = createLinkELementIfNotExist(mappingManager, metadataStructure.Id,
                                                                       metadataStructure.Name, LinkElementType.MetadataStructure, LinkElementComplexity.None);

                    //create system mapping
                    LinkElement system = createLinkELementIfNotExist(mappingManager, 0, "System", LinkElementType.System,
                                                                     LinkElementComplexity.None);

                    #region mapping ABCD BASIC to System Keys

                    Mapping rootTo   = MappingHelper.CreateIfNotExistMapping(abcdRoot, system, 0, null, null, mappingManager);
                    Mapping rootFrom = MappingHelper.CreateIfNotExistMapping(system, abcdRoot, 0, null, null, mappingManager);

                    // create mapping for paryttypes

                    #region person

                    if (partyTypes.Any(p => p.Title.Equals("Person")))
                    {
                        PartyType partyType = partyTypes.FirstOrDefault(p => p.Title.Equals("Person"));
                        //FirstName
                        string complexAttrName = "MicroAgentP";

                        if (partyCustomAttrs.Any(
                                pAttr => pAttr.Name.Equals("FirstName") && pAttr.PartyType.Id.Equals(partyType.Id)))
                        {
                            PartyCustomAttribute partyCustomAttribute = partyCustomAttrs.FirstOrDefault(
                                pAttr => pAttr.Name.Equals("FirstName") && pAttr.PartyType.Id.Equals(partyType.Id));

                            createToPartyTypeMapping(
                                "Name", LinkElementType.MetadataNestedAttributeUsage,
                                complexAttrName, LinkElementType.ComplexMetadataAttribute,
                                partyCustomAttribute, partyType, rootTo, metadataRef,
                                mappingManager,
                                new TransformationRule(@"\w+", "Name[0]"));

                            createFromPartyTypeMapping(
                                "Name", LinkElementType.MetadataNestedAttributeUsage,
                                complexAttrName, LinkElementType.ComplexMetadataAttribute,
                                partyCustomAttribute, partyType, rootFrom, metadataRef,
                                mappingManager,
                                new TransformationRule(@"\w+", "FirstName[0] LastName[0]"));
                        }


                        if (partyCustomAttrs.Any(
                                pAttr => pAttr.Name.Equals("LastName") && pAttr.PartyType.Id.Equals(partyType.Id)))
                        {
                            PartyCustomAttribute partyCustomAttribute = partyCustomAttrs.FirstOrDefault(
                                pAttr => pAttr.Name.Equals("LastName") && pAttr.PartyType.Id.Equals(partyType.Id));

                            createToPartyTypeMapping(
                                "Name", LinkElementType.MetadataNestedAttributeUsage,
                                complexAttrName, LinkElementType.ComplexMetadataAttribute,
                                partyCustomAttribute, partyType, rootTo, metadataRef,
                                mappingManager,
                                new TransformationRule(@"\w+", "Name[1]"));

                            createFromPartyTypeMapping(
                                "Name", LinkElementType.MetadataNestedAttributeUsage,
                                complexAttrName, LinkElementType.ComplexMetadataAttribute,
                                partyCustomAttribute, partyType, rootFrom, metadataRef,
                                mappingManager,
                                new TransformationRule(@"\w+", "FirstName[0] LastName[0]"));
                        }

                        //if (partyCustomAttrs.Any(
                        //    pAttr => pAttr.Name.Equals("Address") && pAttr.PartyType.Id.Equals(partyType.Id)))
                        //{
                        //    PartyCustomAttribute partyCustomAttribute = partyCustomAttrs.FirstOrDefault(
                        //        pAttr => pAttr.Name.Equals("Address") && pAttr.PartyType.Id.Equals(partyType.Id));

                        //    createToPartyTypeMapping(
                        //        "Address", LinkElementType.MetadataNestedAttributeUsage,
                        //        complexAttrName, LinkElementType.ComplexMetadataAttribute,
                        //        partyCustomAttribute, partyType, rootTo, metadataRef,
                        //        mappingManager,
                        //        new TransformationRule());

                        //    createFromPartyTypeMapping(
                        //        "Address", LinkElementType.MetadataNestedAttributeUsage,
                        //        complexAttrName, LinkElementType.ComplexMetadataAttribute,
                        //        partyCustomAttribute, partyType, rootFrom, metadataRef,
                        //        mappingManager,
                        //        new TransformationRule());
                        //}

                        if (partyCustomAttrs.Any(
                                pAttr => pAttr.Name.Equals("Phone") && pAttr.PartyType.Id.Equals(partyType.Id)))
                        {
                            PartyCustomAttribute partyCustomAttribute = partyCustomAttrs.FirstOrDefault(
                                pAttr => pAttr.Name.Equals("Phone") && pAttr.PartyType.Id.Equals(partyType.Id));

                            createToPartyTypeMapping(
                                "Phone", LinkElementType.MetadataNestedAttributeUsage,
                                complexAttrName, LinkElementType.ComplexMetadataAttribute,
                                partyCustomAttribute, partyType, rootTo, metadataRef,
                                mappingManager,
                                new TransformationRule());

                            createFromPartyTypeMapping(
                                "Phone", LinkElementType.MetadataNestedAttributeUsage,
                                complexAttrName, LinkElementType.ComplexMetadataAttribute,
                                partyCustomAttribute, partyType, rootFrom, metadataRef,
                                mappingManager,
                                new TransformationRule());
                        }
                    }
                    #endregion

                    #region Organisation

                    if (partyTypes.Any(p => p.Title.Equals("Organization")))
                    {
                        PartyType partyType = partyTypes.FirstOrDefault(p => p.Title.Equals("Organization"));
                        //FirstName
                        string complexAttrName = "Metadata/Metadata/MetadataType/Owners/OwnersType/Owner/Contact/Organisation/Organisation/Name/Label/Representation/RepresentationType";

                        if (partyCustomAttrs.Any(
                                pAttr => pAttr.Name.Equals("Name") && pAttr.PartyType.Id.Equals(partyType.Id)))
                        {
                            PartyCustomAttribute partyCustomAttribute = partyCustomAttrs.FirstOrDefault(
                                pAttr => pAttr.Name.Equals("Name") && pAttr.PartyType.Id.Equals(partyType.Id));

                            createToPartyTypeMapping(
                                "Text", LinkElementType.MetadataNestedAttributeUsage,
                                complexAttrName, LinkElementType.ComplexMetadataAttribute,
                                partyCustomAttribute, partyType, rootTo, metadataRef,
                                mappingManager,
                                new TransformationRule());

                            createFromPartyTypeMapping(
                                "Text", LinkElementType.MetadataNestedAttributeUsage,
                                complexAttrName, LinkElementType.ComplexMetadataAttribute,
                                partyCustomAttribute, partyType, rootFrom, metadataRef,
                                mappingManager,
                                new TransformationRule());
                        }
                    }

                    #endregion

                    #region Project

                    #endregion

                    #region Insitute

                    #endregion

                    #region Project

                    #endregion

                    #endregion
                }

                #endregion

                #region GBIF

                if (metadataStructures.Any(m => m.Name.ToLower().Equals("gbif")))
                {
                    MetadataStructure metadataStructure =
                        metadataStructures.FirstOrDefault(m => m.Name.ToLower().Equals("gbif"));

                    XDocument metadataRef = xmlMetadataWriter.CreateMetadataXml(metadataStructure.Id);


                    //create root mapping
                    LinkElement abcdRoot = createLinkELementIfNotExist(mappingManager, metadataStructure.Id,
                                                                       metadataStructure.Name, LinkElementType.MetadataStructure, LinkElementComplexity.None);

                    //create system mapping
                    LinkElement system = createLinkELementIfNotExist(mappingManager, 0, "System", LinkElementType.System,
                                                                     LinkElementComplexity.None);

                    #region mapping ABCD BASIC to System Keys

                    Mapping rootTo   = MappingHelper.CreateIfNotExistMapping(abcdRoot, system, 0, null, null, mappingManager);
                    Mapping rootFrom = MappingHelper.CreateIfNotExistMapping(system, abcdRoot, 0, null, null, mappingManager);

                    // create mapping for paryttypes

                    #region person

                    if (partyTypes.Any(p => p.Title.Equals("Person")))
                    {
                        PartyType partyType = partyTypes.FirstOrDefault(p => p.Title.Equals("Person"));
                        //FirstName

                        string complexAttrName = "individualNameType";

                        if (partyCustomAttrs.Any(
                                pAttr => pAttr.Name.Equals("FirstName") && pAttr.PartyType.Id.Equals(partyType.Id)))
                        {
                            PartyCustomAttribute partyCustomAttribute = partyCustomAttrs.FirstOrDefault(
                                pAttr => pAttr.Name.Equals("FirstName") && pAttr.PartyType.Id.Equals(partyType.Id));

                            createToPartyTypeMapping(
                                "givenName", LinkElementType.MetadataNestedAttributeUsage,
                                complexAttrName, LinkElementType.ComplexMetadataAttribute,
                                partyCustomAttribute, partyType, rootTo, metadataRef,
                                mappingManager,
                                new TransformationRule());

                            createFromPartyTypeMapping(
                                "givenName", LinkElementType.MetadataNestedAttributeUsage,
                                complexAttrName, LinkElementType.ComplexMetadataAttribute,
                                partyCustomAttribute, partyType, rootFrom, metadataRef,
                                mappingManager,
                                new TransformationRule());
                        }


                        if (partyCustomAttrs.Any(
                                pAttr => pAttr.Name.Equals("LastName") && pAttr.PartyType.Id.Equals(partyType.Id)))
                        {
                            PartyCustomAttribute partyCustomAttribute = partyCustomAttrs.FirstOrDefault(
                                pAttr => pAttr.Name.Equals("LastName") && pAttr.PartyType.Id.Equals(partyType.Id));

                            createToPartyTypeMapping(
                                "surName", LinkElementType.MetadataNestedAttributeUsage,
                                complexAttrName, LinkElementType.ComplexMetadataAttribute,
                                partyCustomAttribute, partyType, rootTo, metadataRef,
                                mappingManager,
                                new TransformationRule());

                            createFromPartyTypeMapping(
                                "surName", LinkElementType.MetadataNestedAttributeUsage,
                                complexAttrName, LinkElementType.ComplexMetadataAttribute,
                                partyCustomAttribute, partyType, rootFrom, metadataRef,
                                mappingManager,
                                new TransformationRule());
                        }
                    }
                    #endregion

                    #region Project

                    if (partyTypes.Any(p => p.Title.Equals("Project")))
                    {
                        PartyType partyType = partyTypes.FirstOrDefault(p => p.Title.Equals("Project"));
                        //FirstName
                        string complexAttrName = "project";

                        if (partyCustomAttrs.Any(
                                pAttr => pAttr.Name.Equals("Name") && pAttr.PartyType.Id.Equals(partyType.Id)))
                        {
                            PartyCustomAttribute partyCustomAttribute = partyCustomAttrs.FirstOrDefault(
                                pAttr => pAttr.Name.Equals("Name") && pAttr.PartyType.Id.Equals(partyType.Id));

                            createToPartyTypeMapping(
                                "title", LinkElementType.MetadataNestedAttributeUsage,
                                complexAttrName, LinkElementType.MetadataPackageUsage,
                                partyCustomAttribute, partyType, rootTo, metadataRef,
                                mappingManager,
                                new TransformationRule());

                            createFromPartyTypeMapping(
                                "title", LinkElementType.MetadataNestedAttributeUsage,
                                complexAttrName, LinkElementType.MetadataPackageUsage,
                                partyCustomAttribute, partyType, rootFrom, metadataRef,
                                mappingManager,
                                new TransformationRule());
                        }
                    }

                    #endregion

                    #region Insitute

                    #endregion

                    #region Project

                    #endregion

                    #endregion
                }

                #endregion
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                mappingManager.Dispose();
            }
        }
예제 #14
0
        /// <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));

                // possinle cases                   mapping count
                // 1 - 1                            1
                // x,y to z (combination merge)     2
                // x -> z1,z2,z3 (split)            1
                // x1,x2,x3 -> z (merge)            1

                if (mappings.Count() == 1)
                {
                    //possible cases =
                    // 1 - 1
                    // x -> z1,z2,z3 (split)
                    // x1,x2,x3 -> z (join)

                    Entities.Mapping.Mapping m = mappings.FirstOrDefault();

                    if (m != null &&
                        (m.Source.Type.Equals(LinkElementType.MetadataAttributeUsage) ||
                         m.Source.Type.Equals(LinkElementType.MetadataNestedAttributeUsage)))
                    {
                        IEnumerable <XElement> elements = getXElementsFromAMapping(m, metadata);

                        if (elements.Count() == 1)
                        {
                            var    element = elements.First();
                            string mask    = m.TransformationRule.Mask;
                            // 1 - 1
                            // x -> z1,z2,z3 (split)
                            List <string> result = transform(element.Value, m.TransformationRule);

                            if (result.Count == 1) // 1 - 1
                            {
                                mask = setOrReplace(mask, result, m.Source.Name);
                                tmp.Add(mask);
                            }
                            else // x -> z1,z2,z3 (split)
                            {
                                if (string.IsNullOrEmpty(mask))
                                {
                                    tmp.AddRange(result);
                                }
                                else
                                {
                                    //ToDo Add mask
                                    foreach (string r in result)
                                    {
                                        mask = setOrReplace(mask, new List <string>()
                                        {
                                            r
                                        }, m.Source.Name);
                                        tmp.Add(mask);
                                    }
                                }
                            }
                        }
                        else
                        {
                            // x1,x2,x3 -> z (join)

                            foreach (var element in elements)
                            {
                                tmp.AddRange(transform(element.Value, m.TransformationRule));
                            }
                        }
                    }
                }
                // x,y to z (combination merge)
                // if multiply mappings to the same source, it is a merge
                else
                {
                    // all mappings that have the same parent mapping should be handelt together
                    IEnumerable <long> parentIds = mappings.Select(m => m.Parent.Id).Distinct();

                    foreach (int parentId in parentIds)
                    {
                        string mask = "";

                        //load all maaping that belongs to the parent mapping with id -> parentId
                        IEnumerable <Entities.Mapping.Mapping> tmpMappings = mappings.Where(m => m.Parent.Id.Equals(parentId));

                        foreach (var m in tmpMappings)
                        {
                            if (string.IsNullOrEmpty(mask))
                            {
                                mask = mappings.FirstOrDefault().TransformationRule.Mask;
                            }

                            if (m.Source.Type.Equals(LinkElementType.MetadataAttributeUsage) ||
                                m.Source.Type.Equals(LinkElementType.MetadataNestedAttributeUsage))
                            {
                                IEnumerable <XElement> elements = getXElementsFromAMapping(m, metadata);

                                //the elements are the result of one mapping
                                foreach (var element in elements)
                                {
                                    List <string> regExResultList = transform(element.Value, m.TransformationRule);
                                    string        placeHolderName = m.Source.Name;

                                    mask = setOrReplace(mask, regExResultList, placeHolderName);
                                }
                            }
                        }

                        tmp.Add(mask);
                    }
                }

                return(tmp);
            }
            finally
            {
                mappingManager.Dispose();
            }
        }