Пример #1
0
        public static Mapping CreateIfNotExistMapping(LinkElement source, LinkElement target, long level, TransformationRule rule, Mapping parent, MappingManager mappingManager)
        {
            object tmp = new object();
            IEnumerable <Mapping> mappings = tmp.GetUnitOfWork().GetReadOnlyRepository <Mapping>().Get();

            Mapping mapping = null;

            if (parent != null)
            {
                mapping = mappings.FirstOrDefault(
                    m => m.Parent != null && m.Parent.Id.Equals(parent.Id) &&
                    m.Source.Id.Equals(source.Id) &&
                    m.Source.Type.Equals(source.Type) &&
                    m.Target.Id.Equals(target.Id) &&
                    m.Target.Type.Equals(target.Type) &&
                    m.Level.Equals(level));
            }
            else
            {
                mapping = mappings.FirstOrDefault(
                    m => m.Parent == null &&
                    m.Source.Id.Equals(source.Id) &&
                    m.Source.Type.Equals(source.Type) &&
                    m.Target.Id.Equals(target.Id) &&
                    m.Target.Type.Equals(target.Type) &&
                    m.Level.Equals(level));
            }

            if (mapping == null)
            {
                if (rule != null && rule.Id == 0 && rule.RegEx != null)
                {
                    rule = mappingManager.CreateTransformationRule(rule.RegEx, rule.Mask);
                }

                mapping = mappingManager.CreateMapping(source, target, level, rule, parent);
            }
            else
            {
                if (rule != null)
                {
                    rule = mappingManager.UpdateTransformationRule(rule.Id, rule.RegEx, rule.Mask);

                    mapping.TransformationRule = rule;
                    mappingManager.UpdateMapping(mapping);
                }
            }


            return(mapping);
        }
Пример #2
0
        private void createSystemKeyMappings()
        {
            object tmp = "";
            List <MetadataStructure> metadataStructures =
                tmp.GetUnitOfWork().GetReadOnlyRepository <MetadataStructure>().Get().ToList();
            MappingManager    mappingManager    = new MappingManager();
            XmlMetadataWriter xmlMetadataWriter = new XmlMetadataWriter(XmlNodeMode.xPath);

            //#region ABCD BASIC
            if (metadataStructures.Any(m => m.Name.ToLower().Equals("basic abcd") || m.Name.ToLower().Equals("full 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

                Debug.WriteLine("abcd to root");
                Mapping rootTo = MappingHelper.CreateIfNotExistMapping(abcdRoot, system, 0, null, null, mappingManager);
                Debug.WriteLine("root to abcd");
                Mapping rootFrom = MappingHelper.CreateIfNotExistMapping(system, abcdRoot, 0, null, null, mappingManager);
                Debug.WriteLine("Title");

                if (Exist("Title", LinkElementType.MetadataNestedAttributeUsage))
                {
                    createToKeyMapping("Title", LinkElementType.MetadataNestedAttributeUsage, "Title", LinkElementType.MetadataNestedAttributeUsage, Key.Title, rootTo, metadataRef, mappingManager);
                    createFromKeyMapping("Title", LinkElementType.MetadataNestedAttributeUsage, "Title", LinkElementType.MetadataNestedAttributeUsage, Key.Title, rootFrom, metadataRef, mappingManager);
                }

                if (Exist("Details", LinkElementType.MetadataNestedAttributeUsage) &&
                    Exist("MetadataDescriptionRepr", LinkElementType.ComplexMetadataAttribute))
                {
                    Debug.WriteLine("Details");
                    createToKeyMapping("Details", LinkElementType.MetadataNestedAttributeUsage, "MetadataDescriptionRepr", LinkElementType.ComplexMetadataAttribute, Key.Description, rootTo, metadataRef, mappingManager);
                    createFromKeyMapping("Details", LinkElementType.MetadataNestedAttributeUsage, "MetadataDescriptionRepr", LinkElementType.ComplexMetadataAttribute, Key.Description, rootFrom, metadataRef, mappingManager);
                }

                if (Exist("FullName", LinkElementType.MetadataNestedAttributeUsage) &&
                    Exist("PersonName", LinkElementType.ComplexMetadataAttribute))
                {
                    Debug.WriteLine("FullName");
                    createToKeyMapping("FullName", LinkElementType.MetadataNestedAttributeUsage, "PersonName", LinkElementType.ComplexMetadataAttribute, Key.Author, rootTo, metadataRef, mappingManager);
                    createFromKeyMapping("FullName", LinkElementType.MetadataNestedAttributeUsage, "PersonName", LinkElementType.ComplexMetadataAttribute, Key.Author, rootFrom, metadataRef, mappingManager);
                }

                if (Exist("Text", LinkElementType.MetadataNestedAttributeUsage) &&
                    Exist("License", LinkElementType.MetadataNestedAttributeUsage))
                {
                    Debug.WriteLine("Text");
                    createToKeyMapping("Text", LinkElementType.MetadataNestedAttributeUsage, "License", LinkElementType.MetadataNestedAttributeUsage, Key.License, rootTo, metadataRef, mappingManager);
                    createFromKeyMapping("Text", LinkElementType.MetadataNestedAttributeUsage, "License", LinkElementType.MetadataNestedAttributeUsage, Key.License, rootFrom, metadataRef, mappingManager);
                }

                #endregion
            }



            //#endregion


            #region mapping GBIF to System Keys

            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 gbifRoot = 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 GBIF to System Keys


                Mapping rootTo   = mappingManager.CreateMapping(gbifRoot, system, 0, null, null);
                Mapping rootFrom = mappingManager.CreateMapping(system, gbifRoot, 0, null, null);

                if (Exist("title", LinkElementType.MetadataNestedAttributeUsage) &&
                    Exist("Basic", LinkElementType.MetadataPackageUsage))
                {
                    createToKeyMapping("title", LinkElementType.MetadataNestedAttributeUsage, "Basic", LinkElementType.MetadataPackageUsage, Key.Title, rootTo, metadataRef, mappingManager);
                    createFromKeyMapping("title", LinkElementType.MetadataNestedAttributeUsage, "Basic", LinkElementType.MetadataPackageUsage, Key.Title, rootFrom, metadataRef, mappingManager);
                }

                if (Exist("para", LinkElementType.MetadataNestedAttributeUsage) &&
                    Exist("abstract", LinkElementType.MetadataPackageUsage))
                {
                    createToKeyMapping("para", LinkElementType.MetadataNestedAttributeUsage, "abstract", LinkElementType.MetadataPackageUsage, Key.Description, rootTo, metadataRef, mappingManager);
                    createFromKeyMapping("para", LinkElementType.MetadataNestedAttributeUsage, "abstract", LinkElementType.MetadataPackageUsage, Key.Description, rootFrom, metadataRef, mappingManager);
                }

                if (Exist("givenName", LinkElementType.MetadataNestedAttributeUsage) &&
                    Exist("individualName", LinkElementType.MetadataAttributeUsage))
                {
                    createToKeyMapping("givenName", LinkElementType.MetadataNestedAttributeUsage, "Metadata/creator/creatorType/individualName", LinkElementType.MetadataAttributeUsage, Key.Author, rootTo, metadataRef, mappingManager, mappingManager.CreateTransformationRule("", "givenName[0] surName[0]"));
                    createToKeyMapping("givenName", LinkElementType.MetadataNestedAttributeUsage, "Metadata/creator/creatorType/individualName", LinkElementType.MetadataAttributeUsage, Key.Author, rootFrom, metadataRef, mappingManager, mappingManager.CreateTransformationRule(@"\w+", "Author[0]"));
                }

                if (Exist("surName", LinkElementType.MetadataNestedAttributeUsage) &&
                    Exist("individualName", LinkElementType.MetadataAttributeUsage))
                {
                    createToKeyMapping("surName", LinkElementType.MetadataNestedAttributeUsage, "Metadata/creator/creatorType/individualName", LinkElementType.MetadataAttributeUsage, Key.Author, rootTo, metadataRef, mappingManager, mappingManager.CreateTransformationRule("", "givenName[0] surName[0]"));
                    createToKeyMapping("surName", LinkElementType.MetadataNestedAttributeUsage, "Metadata/creator/creatorType/individualName", LinkElementType.MetadataAttributeUsage, Key.Author, rootFrom, metadataRef, mappingManager, mappingManager.CreateTransformationRule(@"\w+", "Author[1]"));
                }

                if (Exist("title", LinkElementType.MetadataNestedAttributeUsage) &&
                    Exist("project", LinkElementType.MetadataPackageUsage))
                {
                    createToKeyMapping("title", LinkElementType.MetadataNestedAttributeUsage, "project", LinkElementType.MetadataPackageUsage, Key.ProjectTitle, rootTo, metadataRef, mappingManager);
                    createFromKeyMapping("title", LinkElementType.MetadataNestedAttributeUsage, "project", LinkElementType.MetadataPackageUsage, Key.ProjectTitle, rootFrom, metadataRef, mappingManager);
                }
                #endregion
            }

            #endregion
        }