Пример #1
0
        private static List <LinkElementModel> getChildrenFromMetadataAttributeUsage(LinkElementModel model)
        {
            MetadataAttributeManager metadataAttributeManager = new MetadataAttributeManager();

            try
            {
                MetadataAttributeUsage metadataAttributeUsage = metadataAttributeManager.MetadataAttributeUsageRepo.Get(model.ElementId);

                LinkElementComplexity complexity = LinkElementComplexity.None;
                LinkElementType       type       = LinkElementType.ComplexMetadataAttribute;

                complexity = metadataAttributeUsage.MetadataAttribute.Self is MetadataSimpleAttribute
                    ? LinkElementComplexity.Simple
                    : LinkElementComplexity.Complex;

                if (complexity == LinkElementComplexity.Complex)
                {
                    return(getChildrenFromComplexMetadataAttribute(metadataAttributeUsage.MetadataAttribute.Id, model.Position));
                }

                return(new List <LinkElementModel>());
            }
            finally
            {
                metadataAttributeManager.Dispose();
            }
        }
        public bool IsSimple(BaseUsage usage)
        {
            using (IUnitOfWork unitOfWork = this.GetUnitOfWork())
            {
                MetadataAttribute ma = null;

                if (usage is MetadataAttributeUsage)
                {
                    MetadataAttributeUsage mau = (MetadataAttributeUsage)usage;
                    ma = unitOfWork.GetReadOnlyRepository <MetadataAttribute>().Get(mau.MetadataAttribute.Id);
                }

                if (usage is MetadataNestedAttributeUsage)
                {
                    MetadataNestedAttributeUsage mnau = (MetadataNestedAttributeUsage)usage;
                    ma = unitOfWork.GetReadOnlyRepository <MetadataAttribute>().Get(mnau.Member.Id);
                }

                if (ma != null && ma.Self is MetadataSimpleAttribute)
                {
                    return(true);
                }

                return(false);
            }
        }
        public List <BaseUsage> GetSimpleChildrens(BaseUsage usage)
        {
            using (IUnitOfWork unitOfWork = this.GetUnitOfWork())
            {
                List <BaseUsage> temp = new List <BaseUsage>();

                if (usage is MetadataPackageUsage)
                {
                    MetadataPackageUsage mpu = (MetadataPackageUsage)usage;
                    var mauRepo = unitOfWork.GetReadOnlyRepository <MetadataAttributeUsage>();

                    foreach (MetadataAttributeUsage childUsage in mpu.MetadataPackage.MetadataAttributeUsages)
                    {
                        if (IsSimple(childUsage))
                        {
                            mauRepo.LoadIfNot(childUsage.MetadataAttribute);
                            temp.Add(childUsage);
                        }
                    }
                }

                if (usage is MetadataAttributeUsage)
                {
                    MetadataAttributeUsage mau = (MetadataAttributeUsage)usage;
                    if (mau.MetadataAttribute.Self is MetadataCompoundAttribute)
                    {
                        var mnauRepo = unitOfWork.GetReadOnlyRepository <MetadataNestedAttributeUsage>();

                        foreach (MetadataNestedAttributeUsage childUsage in ((MetadataCompoundAttribute)mau.MetadataAttribute.Self).MetadataNestedAttributeUsages)
                        {
                            if (IsSimple(childUsage))
                            {
                                mnauRepo.LoadIfNot(childUsage.Member);
                                temp.Add(childUsage);
                            }
                        }
                    }
                }

                if (usage is MetadataNestedAttributeUsage)
                {
                    MetadataNestedAttributeUsage mnau = (MetadataNestedAttributeUsage)usage;
                    if (mnau.Member.Self is MetadataCompoundAttribute)
                    {
                        var mnauRepo = unitOfWork.GetReadOnlyRepository <MetadataNestedAttributeUsage>();

                        foreach (MetadataNestedAttributeUsage childUsage in ((MetadataCompoundAttribute)mnau.Member.Self).MetadataNestedAttributeUsages)
                        {
                            if (IsSimple(childUsage))
                            {
                                mnauRepo.LoadIfNot(childUsage.Member);
                                temp.Add(childUsage);
                            }
                        }
                    }
                }

                return(temp);
            }
        }
Пример #4
0
        //Add Attribute to a package return a apackage
        /// <summary>
        ///
        /// </summary>
        /// <remarks></remarks>
        /// <seealso cref=""/>
        /// <param name="package"></param>
        /// <param name="attributeUsage"></param>
        /// <param name="number"></param>
        /// <returns></returns>
        private XElement AddAttributeReturnType(XElement current, BaseUsage attributeUsage, int number)
        {
            string typeName = "";
            string id       = "";
            string roleId   = "";


            if (attributeUsage is MetadataAttributeUsage)
            {
                MetadataAttributeUsage metadataAttributeUsage = (MetadataAttributeUsage)attributeUsage;
                typeName = metadataAttributeUsage.MetadataAttribute.Name;
                id       = metadataAttributeUsage.MetadataAttribute.Id.ToString();
                roleId   = metadataAttributeUsage.MetadataAttribute.Id.ToString();
            }
            else
            {
                MetadataNestedAttributeUsage mnau = (MetadataNestedAttributeUsage)attributeUsage;
                typeName = mnau.Member.Name;
                id       = mnau.Member.Id.ToString();
                roleId   = mnau.Member.Id.ToString();
            }


            if (!Exist(typeName, number, current))
            {
                XElement role = Get(attributeUsage.Label, current);
                if (role == null)
                {
                    role = CreateXElement(attributeUsage.Label, XmlNodeType.MetadataAttributeUsage);
                    if (_mode.Equals(XmlNodeMode.xPath))
                    {
                        role.SetAttributeValue("name", attributeUsage.Label);
                    }
                    role.SetAttributeValue("id", attributeUsage.Id.ToString());
                }

                XElement element = CreateXElement(typeName, XmlNodeType.MetadataAttribute);

                if (_mode.Equals(XmlNodeMode.xPath))
                {
                    element.SetAttributeValue("name", typeName);
                }
                element.SetAttributeValue("roleId", roleId);
                element.SetAttributeValue("id", id);
                element.SetAttributeValue("number", number);
                role.Add(element);
                current.Add(role);

                return(current);
            }
            else
            {
                throw new Exception("attribute exist");
            }

            return(null);
        }
Пример #5
0
        public void RemoveMetadataAtributeUsage(MetadataAttributeUsage usage)
        {
            Contract.Requires(usage != null && usage.Id >= 0);

            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository <MetadataAttributeUsage> repo = uow.GetRepository <MetadataAttributeUsage>();
                repo.Delete(usage);
                uow.Commit();
            }
        }
        public List <BaseUsage> GetChildren(long usageId, Type type)
        {
            using (IUnitOfWork unitOfWork = this.GetUnitOfWork())
            {
                List <BaseUsage> temp = new List <BaseUsage>();

                if (type.Equals(typeof(MetadataPackageUsage)))
                {
                    MetadataPackageUsage mpu = unitOfWork.GetReadOnlyRepository <MetadataPackageUsage>().Get(usageId);
                    var mauRepo = unitOfWork.GetReadOnlyRepository <MetadataAttributeUsage>();

                    foreach (MetadataAttributeUsage childUsage in mpu.MetadataPackage.MetadataAttributeUsages)
                    {
                        mauRepo.LoadIfNot((childUsage).MetadataAttribute);
                        temp.Add(childUsage);
                    }
                }

                if (type.Equals(typeof(MetadataAttributeUsage)))
                {
                    MetadataAttributeUsage mau = unitOfWork.GetReadOnlyRepository <MetadataAttributeUsage>().Get(usageId);
                    if (mau.MetadataAttribute.Self is MetadataCompoundAttribute)
                    {
                        var mnauRepo = unitOfWork.GetReadOnlyRepository <MetadataNestedAttributeUsage>();

                        foreach (MetadataNestedAttributeUsage childUsage in ((MetadataCompoundAttribute)mau.MetadataAttribute.Self).MetadataNestedAttributeUsages)
                        {
                            mnauRepo.LoadIfNot(childUsage.Member);
                            temp.Add(childUsage);
                        }
                    }
                }

                if (type.Equals(typeof(MetadataNestedAttributeUsage)))
                {
                    MetadataNestedAttributeUsage mnau = unitOfWork.GetReadOnlyRepository <MetadataNestedAttributeUsage>().Get(usageId);

                    if (mnau.Member.Self is MetadataCompoundAttribute)
                    {
                        var mnauRepo = unitOfWork.GetReadOnlyRepository <MetadataNestedAttributeUsage>();

                        foreach (MetadataNestedAttributeUsage childUsage in ((MetadataCompoundAttribute)mnau.Member.Self).MetadataNestedAttributeUsages)
                        {
                            temp.Add(childUsage);
                        }
                    }
                }

                return(temp);
            }
        }
        public bool HasUsagesWithSimpleType(long usageId, Type type)
        {
            BaseUsage usage = loadUsage(usageId, type);

            if (type.Equals(typeof(MetadataPackageUsage)))
            {
                MetadataPackageUsage mpu = this.GetUnitOfWork().GetReadOnlyRepository <MetadataPackageUsage>().Get(usageId);

                foreach (BaseUsage childUsage in mpu.MetadataPackage.MetadataAttributeUsages)
                {
                    if (IsSimple(childUsage))
                    {
                        return(true);
                    }
                }
            }

            if (type.Equals(typeof(MetadataAttributeUsage)))
            {
                MetadataAttributeUsage mau = this.GetUnitOfWork().GetReadOnlyRepository <MetadataAttributeUsage>().Get(usageId);;

                if (mau.MetadataAttribute.Self is MetadataCompoundAttribute)
                {
                    foreach (BaseUsage childUsage in ((MetadataCompoundAttribute)mau.MetadataAttribute.Self).MetadataNestedAttributeUsages)
                    {
                        if (IsSimple(childUsage))
                        {
                            return(true);
                        }
                    }
                }
            }

            if (type.Equals(typeof(MetadataNestedAttributeUsage)))
            {
                MetadataNestedAttributeUsage mnau = (MetadataNestedAttributeUsage)usage;
                if (mnau.Member.Self is MetadataCompoundAttribute)
                {
                    foreach (BaseUsage childUsage in ((MetadataCompoundAttribute)mnau.Member.Self).MetadataNestedAttributeUsages)
                    {
                        if (IsSimple(childUsage))
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
        public bool HasRequiredSimpleTypes(BaseUsage usage)
        {
            if (usage is MetadataPackageUsage)
            {
                MetadataPackageUsage mpu = (MetadataPackageUsage)usage;

                foreach (BaseUsage childUsage in mpu.MetadataPackage.MetadataAttributeUsages)
                {
                    if (IsSimple(childUsage) && childUsage.MinCardinality > 0)
                    {
                        return(true);
                    }
                }
            }

            if (usage is MetadataAttributeUsage)
            {
                MetadataAttributeUsage mau = (MetadataAttributeUsage)usage;
                if (mau.MetadataAttribute.Self is MetadataCompoundAttribute)
                {
                    foreach (BaseUsage childUsage in ((MetadataCompoundAttribute)mau.MetadataAttribute.Self).MetadataNestedAttributeUsages)
                    {
                        if (IsSimple(childUsage) && childUsage.MinCardinality > 0)
                        {
                            return(true);
                        }
                    }
                }
            }

            if (usage is MetadataNestedAttributeUsage)
            {
                MetadataNestedAttributeUsage mnau = (MetadataNestedAttributeUsage)usage;
                if (mnau.Member.Self is MetadataCompoundAttribute)
                {
                    foreach (BaseUsage childUsage in ((MetadataCompoundAttribute)mnau.Member.Self).MetadataNestedAttributeUsages)
                    {
                        if (IsSimple(childUsage) && childUsage.MinCardinality > 0)
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
Пример #9
0
        public MetadataAttributeUsage AddMetadataAtributeUsage(MetadataPackage package, MetadataAttribute attribute, string label, string description, int minCardinality, int maxCardinality)
        {
            Contract.Requires(package != null && package.Id >= 0);
            Contract.Requires(attribute != null && attribute.Id >= 0);

            Contract.Ensures(Contract.Result <MetadataAttributeUsage>() != null && Contract.Result <MetadataAttributeUsage>().Id >= 0);

            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                var metadataPackageRepo = uow.GetReadOnlyRepository <MetadataPackage>();
                var attributesRepo      = uow.GetReadOnlyRepository <MetadataAttribute>();

                attribute = attributesRepo.Get(attribute.Id);
                metadataPackageRepo.Reload(package);
                metadataPackageRepo.LoadIfNot(package.MetadataAttributeUsages);
                int count = 0;
                try
                {
                    count = (from v in package.MetadataAttributeUsages
                             where v.MetadataAttribute.Id.Equals(attribute.Id)
                             select v
                             )
                            .Count();
                }
                catch { }

                MetadataAttributeUsage usage = new MetadataAttributeUsage()
                {
                    MetadataPackage   = package,
                    MetadataAttribute = attribute,
                    // if there is no label provided, use the attribute name and a sequence number calculated by the number of occurrences of that attribute in the current structure
                    Label          = !string.IsNullOrWhiteSpace(label) ? label : (count <= 0 ? attribute.Name : string.Format("{0} ({1})", attribute.Name, count)),
                    Description    = description,
                    MinCardinality = minCardinality,
                    MaxCardinality = maxCardinality,
                };
                package.MetadataAttributeUsages.Add(usage);
                attribute.UsedIn.Add(usage);


                IRepository <MetadataAttributeUsage> repo = uow.GetRepository <MetadataAttributeUsage>();
                repo.Put(usage);
                uow.Commit();

                return(usage);
            }
        }
        public void ConvertMetadataAttributeModels(BaseUsage source, long metadataStructureId, long stepId)
        {
            Source = source;

            if (Source is MetadataAttributeUsage)
            {
                MetadataAttributeUsage mau = (MetadataAttributeUsage)Source;

                if (mau.MetadataAttribute.Self is MetadataCompoundAttribute)
                {
                    MetadataCompoundAttribute mca = (MetadataCompoundAttribute)mau.MetadataAttribute.Self;

                    if (mca != null)
                    {
                        foreach (MetadataNestedAttributeUsage usage in mca.MetadataNestedAttributeUsages)
                        {
                            if (metadataStructureUsageHelper.IsSimple(usage))
                            {
                                MetadataAttributeModels.Add(FormHelper.CreateMetadataAttributeModel(usage, mau, metadataStructureId, Number, stepId));
                            }
                        }
                    }
                }
            }

            if (Source is MetadataNestedAttributeUsage)
            {
                MetadataNestedAttributeUsage mnau = (MetadataNestedAttributeUsage)Source;
                if (mnau.Member.Self is MetadataCompoundAttribute)
                {
                    MetadataCompoundAttribute mca = (MetadataCompoundAttribute)mnau.Member.Self;

                    if (mca != null)
                    {
                        foreach (MetadataNestedAttributeUsage usage in mca.MetadataNestedAttributeUsages)
                        {
                            if (metadataStructureUsageHelper.IsSimple(usage))
                            {
                                MetadataAttributeModels.Add(FormHelper.CreateMetadataAttributeModel(usage, mnau, metadataStructureId, Number, stepId));
                            }
                        }
                    }
                }
            }
        }
        public string GetNameOfType(BaseUsage usage)
        {
            if (usage is MetadataPackageUsage)
            {
                MetadataPackageUsage mpu = (MetadataPackageUsage)usage;
                return(mpu.MetadataPackage.Name);
            }

            if (usage is MetadataAttributeUsage)
            {
                MetadataAttributeUsage mau = (MetadataAttributeUsage)usage;
                return(mau.MetadataAttribute.Name);
            }

            if (usage is MetadataNestedAttributeUsage)
            {
                MetadataNestedAttributeUsage mnau = (MetadataNestedAttributeUsage)usage;
                return(mnau.Member.Name);
            }

            return("");
        }
        public long GetIdOfType(BaseUsage usage)
        {
            if (usage is MetadataPackageUsage)
            {
                MetadataPackageUsage mpu = (MetadataPackageUsage)usage;
                return(mpu.MetadataPackage.Id);
            }

            if (usage is MetadataAttributeUsage)
            {
                MetadataAttributeUsage mau = (MetadataAttributeUsage)usage;
                return(mau.MetadataAttribute.Id);
            }

            if (usage is MetadataNestedAttributeUsage)
            {
                MetadataNestedAttributeUsage mnau = (MetadataNestedAttributeUsage)usage;
                return(mnau.Member.Id);
            }

            return(0);
        }
Пример #13
0
        //Add Attribute to a package return a apackage
        /// <summary>
        ///
        /// </summary>
        /// <remarks></remarks>
        /// <seealso cref=""/>
        /// <param name="package"></param>
        /// <param name="attributeUsage"></param>
        /// <param name="number"></param>
        /// <returns></returns>
        private List <XElement> AddAndReturnAttribute(XElement current, BaseUsage attributeUsage, int number, int countOfTypes)
        {
            List <XElement> tmp = new List <XElement>();

            string typeName = "";
            string id       = "";
            string roleId   = "";

            if (attributeUsage is MetadataAttributeUsage)
            {
                MetadataAttributeUsage metadataAttributeUsage = (MetadataAttributeUsage)attributeUsage;
                typeName = metadataAttributeUsage.MetadataAttribute.Name;
                id       = metadataAttributeUsage.MetadataAttribute.Id.ToString();
                roleId   = metadataAttributeUsage.Id.ToString();
            }
            else
            {
                MetadataNestedAttributeUsage mnau = (MetadataNestedAttributeUsage)attributeUsage;
                typeName = mnau.Member.Name;
                id       = mnau.Member.Id.ToString();
                roleId   = mnau.Id.ToString();
            }

            if (!Exist(typeName, number, current))
            {
                XElement role = Get(attributeUsage.Label, current);
                if (role == null)
                {
                    role = CreateXElement(attributeUsage.Label, XmlNodeType.MetadataAttributeUsage);
                    if (_mode.Equals(XmlNodeMode.xPath))
                    {
                        role.SetAttributeValue("name", attributeUsage.Label);
                    }
                    role.SetAttributeValue("id", attributeUsage.Id.ToString());
                }

                for (int i = 0; i < countOfTypes; i++)
                {
                    XElement element = CreateXElement(typeName, XmlNodeType.MetadataAttribute);

                    if (_mode.Equals(XmlNodeMode.xPath))
                    {
                        element.SetAttributeValue("name", typeName);
                    }
                    element.SetAttributeValue("roleId", roleId);
                    element.SetAttributeValue("id", id);
                    element.SetAttributeValue("number", i + 1);
                    role.Add(element);

                    tmp.Add(element);
                }

                current.Add(role);
                //Debug.WriteLine("Element:            " + element.Name);

                return(tmp);
            }
            else
            {
                throw new Exception("attribute exist");
            }
        }
Пример #14
0
        //Add Attribute to a package return a apackage
        /// <summary>
        ///
        /// </summary>
        /// <remarks></remarks>
        /// <seealso cref=""/>
        /// <param name="package"></param>
        /// <param name="attributeUsage"></param>
        /// <param name="number"></param>
        /// <returns></returns>
        private XElement AddAttribute(XElement current, BaseUsage attributeUsage, int number)
        {
            string typeName = "";
            string id       = "";
            string roleId   = "";
            List <MetadataNestedAttributeUsage> children = new List <MetadataNestedAttributeUsage>();

            if (attributeUsage is MetadataAttributeUsage)
            {
                MetadataAttributeUsage metadataAttributeUsage = (MetadataAttributeUsage)attributeUsage;
                typeName = metadataAttributeUsage.MetadataAttribute.Name;
                id       = metadataAttributeUsage.MetadataAttribute.Id.ToString();
                roleId   = metadataAttributeUsage.MetadataAttribute.Id.ToString();
            }
            else
            {
                MetadataNestedAttributeUsage mnau = (MetadataNestedAttributeUsage)attributeUsage;
                typeName = mnau.Member.Name;
                id       = mnau.Member.Id.ToString();
                roleId   = mnau.Id.ToString();

                if (mnau.Member.Self is MetadataCompoundAttribute)
                {
                    MetadataCompoundAttribute mca = (MetadataCompoundAttribute)mnau.Member.Self;
                    children = mca.MetadataNestedAttributeUsages.ToList();
                }
            }

            if (!Exist(typeName, number, current))
            {
                XElement role = Get(attributeUsage.Label, current);
                if (role == null)
                {
                    role = CreateXElement(attributeUsage.Label, XmlNodeType.MetadataAttributeUsage);
                    if (_mode.Equals(XmlNodeMode.xPath))
                    {
                        role.SetAttributeValue("name", attributeUsage.Label);
                    }
                    role.SetAttributeValue("id", attributeUsage.Id.ToString());
                }

                XElement element = CreateXElement(typeName, XmlNodeType.MetadataAttribute);

                if (_mode.Equals(XmlNodeMode.xPath))
                {
                    element.SetAttributeValue("name", typeName);
                }
                element.SetAttributeValue("roleId", roleId);
                element.SetAttributeValue("id", id);
                element.SetAttributeValue("number", number);

                if (children.Count > 0)
                {
                    foreach (BaseUsage baseUsage in children)
                    {
                        element = AddAttribute(element, baseUsage, 1);
                    }
                }

                role.Add(element);
                current.Add(role);
            }
            else
            {
                throw new Exception("attribute exist");
            }

            return(current);
        }
Пример #15
0
        private XElement setChildren(XElement element, BaseUsage usage, XDocument importDocument = null)
        {
            MetadataAttribute metadataAttribute = null;
            MetadataPackage   metadataPackage   = null;

            if (usage is MetadataAttributeUsage)
            {
                MetadataAttributeUsage metadataAttributeUsage = (MetadataAttributeUsage)usage;
                metadataAttribute = metadataAttributeUsage.MetadataAttribute;
            }
            else if (usage is MetadataNestedAttributeUsage)
            {
                MetadataNestedAttributeUsage mnau = (MetadataNestedAttributeUsage)usage;
                metadataAttribute = mnau.Member;
            }
            else
            {
                MetadataPackageUsage mpu = (MetadataPackageUsage)usage;
                metadataPackage = mpu.MetadataPackage;
            }

            if (metadataAttribute != null && metadataAttribute.Self is MetadataCompoundAttribute)
            {
                MetadataCompoundAttribute mca = this.GetUnitOfWork().GetReadOnlyRepository <MetadataCompoundAttribute>().Get(metadataAttribute.Self.Id);

                foreach (MetadataNestedAttributeUsage nestedUsage in mca.MetadataNestedAttributeUsages)
                {
                    if (importDocument != null)
                    {
                        string parentPath = element.GetAbsoluteXPathWithIndex();

                        string usagePath = parentPath + "/" + nestedUsage.Label;

                        XElement        usageElement = importDocument.XPathSelectElement(usagePath);
                        List <XElement> typeList     = new List <XElement>();

                        if (usageElement != null && usageElement.HasElements)
                        {
                            int num = usageElement.Elements().Count();

                            if (num == 0)
                            {
                                typeList = AddAndReturnAttribute(element, nestedUsage, 1, 1);
                            }
                            else
                            {
                                typeList = AddAndReturnAttribute(element, nestedUsage, 1, num);
                            }
                        }
                        else
                        {
                            Debug.WriteLine("NULL OR EMPTY:------> " + usagePath);

                            typeList = AddAndReturnAttribute(element, nestedUsage, 1, 1);
                        }

                        foreach (var type in typeList)
                        {
                            setChildren(type, nestedUsage, importDocument);
                        }
                    }
                    else
                    {
                        List <XElement> typeList = new List <XElement>();

                        typeList = AddAndReturnAttribute(element, nestedUsage, 1, 1);
                        setChildren(typeList.FirstOrDefault(), nestedUsage, importDocument);
                    }
                }
            }
            else
            {
                if (metadataPackage != null)
                {
                    foreach (MetadataAttributeUsage attrUsage in metadataPackage.MetadataAttributeUsages)
                    {
                        if (importDocument != null)
                        {
                            string parentPath = element.GetAbsoluteXPathWithIndex();

                            string usagePath = parentPath + "/" + attrUsage.Label;

                            XElement        usageElement = importDocument.XPathSelectElement(usagePath);
                            List <XElement> typeList     = new List <XElement>();

                            if (usageElement != null && usageElement.HasElements)
                            {
                                int num = usageElement.Elements().Count();

                                if (num == 0)
                                {
                                    typeList = AddAndReturnAttribute(element, attrUsage, 1, 1);
                                }
                                else
                                {
                                    typeList = AddAndReturnAttribute(element, attrUsage, 1, num);
                                }
                            }
                            else
                            {
                                Debug.WriteLine("NULL OR EMPTY:------> " + usagePath);

                                typeList = AddAndReturnAttribute(element, attrUsage, 1, 1);
                            }

                            foreach (var type in typeList)
                            {
                                setChildren(type, attrUsage, importDocument);
                            }
                        }
                        else
                        {
                            List <XElement> typeList = new List <XElement>();

                            typeList = AddAndReturnAttribute(element, attrUsage, 1, 1);
                            setChildren(typeList.FirstOrDefault(), attrUsage, importDocument);
                        }
                    }
                }
            }

            return(element);
        }
Пример #16
0
        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);
            }
        }
Пример #17
0
        private XElement setChildren(XElement element, BaseUsage usage, XDocument importDocument = null)
        {
            MetadataAttribute metadataAttribute;

            if (usage is MetadataAttributeUsage)
            {
                MetadataAttributeUsage metadataAttributeUsage = (MetadataAttributeUsage)usage;
                metadataAttribute = metadataAttributeUsage.MetadataAttribute;
            }
            else
            {
                MetadataNestedAttributeUsage mnau = (MetadataNestedAttributeUsage)usage;
                metadataAttribute = mnau.Member;
            }

            if (metadataAttribute.Self is MetadataCompoundAttribute)
            {
                //MetadataCompoundAttribute mca = (MetadataCompoundAttribute)metadataAttribute.Self;

                MetadataCompoundAttribute mca = this.GetUnitOfWork().GetReadOnlyRepository <MetadataCompoundAttribute>().Get(metadataAttribute.Self.Id);

                foreach (MetadataNestedAttributeUsage nestedUsage in mca.MetadataNestedAttributeUsages)
                {
                    //Debug.WriteLine("MetadataCompoundAttribute:            " + element.Name);
                    //Debug.WriteLine("*************************:            " + element.Name);
                    //XElement x = element.Descendants().Where(e => e.Name.Equals(nestedUsage.Member.Name)).First();

                    if (importDocument != null)
                    {
                        string parentPath = element.GetAbsoluteXPathWithIndex();

                        string usagePath = parentPath + "/" + nestedUsage.Label;
                        //+"/"+ nestedUsage.Member.Name;

                        XElement        usageElement = importDocument.XPathSelectElement(usagePath);
                        List <XElement> typeList     = new List <XElement>();

                        if (usageElement != null && usageElement.HasElements)
                        {
                            int num = usageElement.Elements().Count();
                            //importDocument.XPathSelectElements(childPath).Count();
                            //num = XmlUtility.ToXmlDocument(importDocument).SelectNodes(childPath).Count;

                            if (num == 0)
                            {
                                typeList = AddAndReturnAttribute(element, nestedUsage, 1, 1);
                                //x = setChildren(x, nestedUsage, importDocument);
                            }
                            else
                            {
                                typeList = AddAndReturnAttribute(element, nestedUsage, 1, num);
                            }
                        }
                        else
                        {
                            Debug.WriteLine("NULL OR EMPTY:------> " + usagePath);

                            typeList = AddAndReturnAttribute(element, nestedUsage, 1, 1);
                        }

                        foreach (var type in typeList)
                        {
                            setChildren(type, nestedUsage, importDocument);
                        }
                    }
                    else
                    {
                        List <XElement> typeList = new List <XElement>();

                        typeList = AddAndReturnAttribute(element, nestedUsage, 1, 1);
                        setChildren(typeList.FirstOrDefault(), nestedUsage, importDocument);
                    }
                }
            }

            return(element);
        }
Пример #18
0
        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,
            });
        }
Пример #19
0
        public static MetadataAttributeModel CreateMetadataAttributeModel(BaseUsage current, BaseUsage parent, long metadataStructureId, int packageModelNumber, long parentStepId)
        {
            MetadataAttribute metadataAttribute;
            List <object>     domainConstraintList   = new List <object>();
            string            constraintsDescription = "";

            if (current is MetadataNestedAttributeUsage)
            {
                MetadataNestedAttributeUsage mnau = (MetadataNestedAttributeUsage)current;
                metadataAttribute = mnau.Member;
            }
            else
            {
                MetadataAttributeUsage mau = (MetadataAttributeUsage)current;
                metadataAttribute = mau.MetadataAttribute;
            }

            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);
                    }
                }
            }
            //load displayPattern
            DataTypeDisplayPattern dtdp = DataTypeDisplayPattern.Materialize(metadataAttribute.DataType.Extra);
            string displayPattern       = "";

            if (dtdp != null)
            {
                displayPattern = dtdp.StringPattern;
            }

            return(new MetadataAttributeModel
            {
                Id = current.Id,
                Number = 1,
                ParentModelNumber = packageModelNumber,
                MetadataStructureId = metadataStructureId,
                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
            });
        }