Ejemplo n.º 1
0
        private static Entities.Mapping.Mapping getRootMapping(Entities.Mapping.Mapping mapping)
        {
            if (mapping.Parent == null)
            {
                return(mapping);
            }

            return(getRootMapping(mapping.Parent));
        }
Ejemplo n.º 2
0
        private static IEnumerable <XElement> getXElementsFromAMapping(Entities.Mapping.Mapping m, XDocument metadata)
        {
            Dictionary <string, string> AttrDic  = new Dictionary <string, string>();
            List <XElement>             elements = new List <XElement>();

            //get parent elemenet with parent mapping
            var parentMapping = m.Parent;
            // if a mapping is linked direct to a simple attribute, then lvl 1&2 are  connected to the same linkelement
            bool directSimpleMapping = false;

            // if the parent and the current source are equals, then the child can loaded directly
            if (parentMapping.Source.Id.Equals(m.Source.Id))
            {
                directSimpleMapping = true;
            }

            if (directSimpleMapping)
            {
                AttrDic = new Dictionary <string, string>();
                AttrDic.Add("id", m.Source.ElementId.ToString());
                AttrDic.Add("name", m.Source.Name);
                AttrDic.Add("type", "MetadataAttributeUsage");

                //the usage is the head node of a attr, if there are more then one, there are listed inside of the usage
                // always :  usage/type/value
                // if cardianlity is more then 1 its listed like usage/type[0]/value, usage/type[n]/value
                // in this case the childs of the usage is needed
                var usages = XmlUtility.GetXElementsByAttribute(AttrDic, metadata);
                foreach (var u in usages)
                {
                    elements.AddRange(u.Elements());
                }
            }
            else
            {
                AttrDic.Add("id", parentMapping.Source.ElementId.ToString());
                AttrDic.Add("name", parentMapping.Source.Name);

                //get parents from metadata
                IEnumerable <XElement> parents = XmlUtility.GetXElementsByAttribute(AttrDic, metadata);

                foreach (var parent in parents)
                {
                    //sett attrs for the child
                    AttrDic = new Dictionary <string, string>();
                    AttrDic.Add("id", m.Source.ElementId.ToString());
                    AttrDic.Add("name", m.Source.Name);
                    AttrDic.Add("type", "MetadataAttributeUsage");

                    //the usage is the head node of a attr, if there are more then one, there are listed inside of the usage
                    // always :  usage/type/value
                    // if cardianlity is more then 1 its listed like usage/type[0]/value, usage/type[n]/value
                    // in this case the childs of the usage is needed
                    var usages = XmlUtility.GetXElementsByAttribute(AttrDic, parent);
                    foreach (var u in usages)
                    {
                        elements.AddRange(u.Elements());
                    }
                }
            }
            return(elements);
        }
Ejemplo n.º 3
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();
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// get all values from systen parties values
        ///
        /// </summary>
        /// <param name="mappings"></param>
        /// <returns></returns>
        private static List <MappingPartyResultElemenet> getAllValuesFromSystem(IEnumerable <Entities.Mapping.Mapping> mappings, string value)
        {
            using (MappingManager _mappingManager = new MappingManager())
                using (PartyTypeManager partyTypeManager = new PartyTypeManager())
                    using (PartyManager partyManager = new PartyManager())
                    {
                        List <MappingPartyResultElemenet> tmp = new List <MappingPartyResultElemenet>();

                        IEnumerable <long> parentIds = mappings.Where(m => m.Parent != null).Select(m => m.Parent.Id).Distinct();

                        IEnumerable <Entities.Mapping.Mapping> selectedMappings;

                        // all Masks are the same
                        string       mask      = "";
                        PartyType    partyType = null;
                        List <Party> parties   = null;

                        foreach (var pId in parentIds)
                        {
                            Entities.Mapping.Mapping parentMapping = _mappingManager.GetMapping(pId);

                            selectedMappings =
                                mappings.Where(m => m.Parent != null && m.Parent.Id.Equals(pId));

                            long parentTypeId = parentMapping.Source.ElementId;
                            long sourceId     = selectedMappings.FirstOrDefault().Source.ElementId;

                            //mappings.FirstOrDefault().TransformationRule.Mask;

                            if (parentTypeId == 0)
                            {
                                partyType =
                                    partyTypeManager.PartyTypeRepository.Query()
                                    .FirstOrDefault(p => p.CustomAttributes.Any(c => c.Id.Equals(sourceId)));
                                parties = partyManager.PartyRepository.Query().Where(p => p.PartyType.Equals(partyType)).ToList();
                            }
                            else
                            {
                                partyType = partyTypeManager.PartyTypeRepository.Get(parentTypeId);
                                parties   = partyManager.PartyRepository.Query().Where(p => p.PartyType.Id.Equals(parentTypeId)).ToList();
                            }

                            //get all mapped element ids
                            var elementIds = mappings.Select(m => m.Source.ElementId);
                            // get all attributes based on the element id list
                            var attributeValues = partyManager.PartyCustomAttributeValueRepository.Query(y => elementIds.Contains(y.CustomAttribute.Id)).ToList();
                            attributeValues = attributeValues.Where(y => y.Value.ToLower().Contains(value.ToLower())).ToList();
                            //get all party ids
                            var partyIds = attributeValues.Select(a => a.Party.Id).Distinct();

                            foreach (var partyId in partyIds)
                            {
                                MappingPartyResultElemenet resultObject = new MappingPartyResultElemenet();
                                resultObject.PartyId = partyId;

                                //get mask from first mapping
                                mask = mappings.FirstOrDefault().TransformationRule.Mask;

                                var allMappedAttrValues = partyManager.PartyCustomAttributeValueRepository.Query(y =>
                                                                                                                 y.Party.Id.Equals(partyId) && elementIds.Contains(y.CustomAttribute.Id)).ToList();

                                foreach (var attrValue in allMappedAttrValues)
                                {
                                    //get mapping for the attrvalue
                                    var mapping = mappings.Where(m => m.Source.ElementId.Equals(attrValue.CustomAttribute.Id)).FirstOrDefault();

                                    List <string> regExResultList = transform(attrValue.Value, mapping.TransformationRule);
                                    string        placeHolderName = attrValue.CustomAttribute.Name;

                                    mask = setOrReplace(mask, regExResultList, placeHolderName);

                                    resultObject.Value = mask;
                                }

                                if (mask.ToLower().Contains(value.ToLower()))
                                {
                                    tmp.Add(resultObject);
                                }
                            }
                        }

                        return(tmp);
                    }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// get all values from systen parties values
        ///
        /// </summary>
        /// <param name="mappings"></param>
        /// <returns></returns>
        private static List <string> getAllValuesFromSystem(IEnumerable <Entities.Mapping.Mapping> mappings, string value)
        {
            MappingManager   _mappingManager  = new MappingManager();
            PartyTypeManager partyTypeManager = new PartyTypeManager();
            PartyManager     partyManager     = new PartyManager();

            List <string> tmp = new List <string>();

            IEnumerable <long> parentIds = mappings.Where(m => m.Parent != null).Select(m => m.Parent.Id).Distinct();

            IEnumerable <Entities.Mapping.Mapping> selectedMappings;

            // all Masks are the same
            string       mask      = "";
            PartyType    partyType = null;
            List <Party> parties   = null;

            foreach (var pId in parentIds)
            {
                Entities.Mapping.Mapping parentMapping = _mappingManager.GetMapping(pId);

                selectedMappings =
                    mappings.Where(m => m.Parent != null && m.Parent.Id.Equals(pId));


                long parentTypeId = parentMapping.Source.ElementId;
                long sourceId     = selectedMappings.FirstOrDefault().Source.ElementId;

                //mappings.FirstOrDefault().TransformationRule.Mask;

                if (parentTypeId == 0)
                {
                    partyType =
                        partyTypeManager.PartyTypeRepository.Query()
                        .FirstOrDefault(p => p.CustomAttributes.Any(c => c.Id.Equals(sourceId)));
                    parties = partyManager.PartyRepository.Get().Where(p => p.PartyType.Equals(partyType)).ToList();
                }
                else
                {
                    partyType = partyTypeManager.PartyTypeRepository.Get(parentTypeId);
                    parties   = partyManager.PartyRepository.Get().Where(p => p.PartyType.Id.Equals(parentTypeId)).ToList();
                }

                if (parties != null)
                {
                    foreach (var p in parties)
                    {
                        mask = mappings.FirstOrDefault().TransformationRule.Mask;

                        foreach (var mapping in mappings)
                        {
                            long attributeId = mapping.Source.ElementId;


                            PartyCustomAttributeValue attrValue =
                                partyManager.PartyCustomAttributeValueRepository.Get()
                                .Where(v => v.CustomAttribute.Id.Equals(attributeId) && v.Party.Id.Equals(p.Id))
                                .FirstOrDefault();



                            List <string> regExResultList = transform(attrValue.Value, mapping.TransformationRule);
                            string        placeHolderName = attrValue.CustomAttribute.Name;


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

                        if (mask.ToLower().Contains(value.ToLower()))
                        {
                            tmp.Add(mask);
                        }
                    }
                }
            }

            return(tmp);
        }