private DataSetSchema CreateTable(DataSetSchema schema, SchemaRestDefinition deserializedSchema)
        {
            if (deserializedSchema.RestSchema == null)
            {
                return(schema);
            }

            var translatedSchema = new DataSetSchema()
            {
//#if ReleaseToLive
                Title =
                    deserializedSchema.RestSchema.Title,
//#else
                //Title =
                //    deserializedSchema.RestSchema.Title + "_debug_mode_test_" +
                //   DateTime.Now.ToString("HH_mm_ss"),
//#endif
                ShortDescription        = deserializedSchema.RestSchema.ShortDescription,
                Description             = deserializedSchema.RestSchema.Description,
                SchemaDefinitionFromUrl = String.IsNullOrEmpty(deserializedSchema.ConformsTo) ? schema.SchemaDefinitionFromUrl : deserializedSchema.ConformsTo,
                UploadFrequency         = 0,
                IsStandardisedSchemaUrl = schema.IsStandardisedSchemaUrl,

                Category = schema.Category
            };


            _dataSetSchemaService.Create(translatedSchema);
            schema = translatedSchema;
            return(schema);
        }
Пример #2
0
        ImportFromUrl_when_deserializedschema_error_message_is_notemptyornull_returns_importdatasetschemaresult_with_error_message_no_definition_found_at_url
            ()
        {
            //arrange
            var dschema = new DataSetSchema()
            {
                SchemaDefinitionFromUrl = "http://dummyurl"
            };
            var obj = new SchemaRestDefinition()
            {
                ErrorMessage = "this is not empty"
            };
            var mock = new Mock <IXmlToObjectService>();

            mock.Setup(x => x.GetXmlFromUrl("http://dummyurl")).Returns("<SchemaRestDefinition></SchemaRestDefinition>");
            mock.Setup(x => x.ConvertXml <SchemaRestDefinition>("<SchemaRestDefinition></SchemaRestDefinition>"))
            .Returns(obj);
            _xmlToObjectService = mock.Object;

            var service = new DataShareSchemaImportService(_xmlToObjectService, _dataSetSchemaService,
                                                           _dataSetSchemaColumnService);

            //act
            var result = service.ImportFromUrl(dschema);

            //assert
            Assert.AreEqual(obj.ErrorMessage, result.ErrorMessage);
            //cleanup
            _xmlToObjectService = null;
        }
Пример #3
0
        ImportFromUrl_when_imported_ok_returns_importdatasetschemaresult_with_no_error_message()
        {
            //arrange
            var dschema = new DataSetSchema()
            {
                SchemaDefinitionFromUrl = "http://dummyurl"
            };
            var obj = new SchemaRestDefinition()
            {
                ErrorMessage             = "", RestSchema = new RestSchema()
                {
                }, RestColumnDefinitions = new RestColumnDefinitions()
            };
            var mock = new Mock <IXmlToObjectService>();

            mock.Setup(x => x.GetXmlFromUrl("http://dummyurl")).Returns("<SchemaRestDefinition></SchemaRestDefinition>");
            mock.Setup(x => x.ConvertXml <SchemaRestDefinition>("<SchemaRestDefinition></SchemaRestDefinition>"))
            .Returns(obj);
            _xmlToObjectService   = mock.Object;
            _dataSetSchemaService = new Mock <IDataSetSchemaService>().Object;
            var service = new DataShareSchemaImportService(_xmlToObjectService, _dataSetSchemaService,
                                                           _dataSetSchemaColumnService);

            //act
            var result = service.ImportFromUrl(dschema);

            //assert
            Assert.AreEqual("", result.ErrorMessage);
            //cleanup
            _xmlToObjectService = null;
        }
Пример #4
0
        ImportFromUrl_when_columnDefinitions_contains_publisherlabel_returns_importdatasetschemaresult_with_error_message_with_xml_schema_cannot_contain_reserved_columns()
        {
            //arrange
            var dschema = new DataSetSchema()
            {
                SchemaDefinitionFromUrl = "http://dummyurl"
            };
            var obj = new SchemaRestDefinition()
            {
                ErrorMessage = "",
                RestSchema   = new RestSchema()
                {
                },
                RestColumnDefinitions = new RestColumnDefinitions()
                {
                    ColumnDefinitions = new List <RestColumnDefinition>()
                    {
                        new RestColumnDefinition()
                        {
                            Name = "publisherLabel"
                        }
                    }
                }
            };
            var mock = new Mock <IXmlToObjectService>();

            mock.Setup(x => x.GetXmlFromUrl("http://dummyurl")).Returns("<SchemaRestDefinition></SchemaRestDefinition>");
            mock.Setup(x => x.ConvertXml <SchemaRestDefinition>("<SchemaRestDefinition></SchemaRestDefinition>"))
            .Returns(obj);
            _xmlToObjectService   = mock.Object;
            _dataSetSchemaService = new Mock <IDataSetSchemaService>().Object;
            var service = new DataShareSchemaImportService(_xmlToObjectService, _dataSetSchemaService,
                                                           _dataSetSchemaColumnService);

            //act
            var result = service.ImportFromUrl(dschema);

            //assert
            Assert.AreEqual("Error: Columns cannot contain reserved column names - PublisherUri/PublisherLabel/Publisher Uri/Publisher Label. http://dummyurl"
                            , result.ErrorMessage);
            //cleanup
            _xmlToObjectService = null;
        }
Пример #5
0
        //not used anymore  see GetSchemaDefinitionV2
        //public IList<RestColumnDefinition> GetSchemaDefinition(string categoryUrl, string schemaUrl)
        //{
        //    var dataSetSchemaService = ObjectFactory.GetInstance<IDataSetSchemaService>();
        //    var schema = dataSetSchemaService.Get(categoryUrl, schemaUrl);

        //    var def = new List<RestColumnDefinition>();

        //    if (schema.IsDisabled)
        //    {
        //        def.Add(new RestColumnDefinition { Name = "This schema has been disabled" });
        //        return def;
        //    }

        //    def.AddRange(schema.Definition.Columns.Select(c => new RestColumnDefinition
        //    {
        //        Name = c.ColumnName,
        //        Description = c.Title,
        //        Type = c.Type,
        //        MaxSize = c.Type == "Text" ? c.MaxSize.ToString() : "N/A",
        //        MinDate = c.Type == "DateTime" && c.MinDate != null ? c.MinDate.ToString() : "N/A",
        //        MaxDate = c.Type == "DateTime" && c.MaxDate != null ? c.MaxDate.ToString() : "N/A",
        //        MinCurrency = c.Type == "Currency" && c.MinCurrency != null ? c.MinCurrency.ToString() : "N/A",
        //        MaxCurrency = c.Type == "Currency" && c.MaxCurrency != null ? c.MaxCurrency.ToString() : "N/A",
        //        MinNumber = c.Type == "Number" && c.MinNumber != null ? c.MinNumber.ToString() : "N/A",
        //        MaxNumber = c.Type == "Number" && c.MaxNumber != null ? c.MaxNumber.ToString() : "N/A",
        //        IsRequired = c.IsRequired,
        //        HelpText = c.HelpText,
        //        Uri = c.LinkedDataUri ?? ""
        //    }));

        //    return def;
        //}

        public SchemaRestDefinition GetSchemaDefinitionV2(string categoryUrl, string schemaUrl)
        {
            var dataSetSchemaService = ObjectFactory.GetInstance <IDataSetSchemaService>();
            var schema = dataSetSchemaService.Get(categoryUrl, schemaUrl);
            SchemaRestDefinition schemaXml;


            if (schema == null)
            {
                schemaXml = new SchemaRestDefinition()
                {
                };
                schemaXml.EsdLinks     = null;
                schemaXml.ErrorMessage = "This schema does not exist!";
                return(schemaXml);
            }

            if (schema.IsDisabled || !schema.IsOnline)
            {
                schemaXml = new SchemaRestDefinition()
                {
                };
                schemaXml.EsdLinks     = null;
                schemaXml.ErrorMessage = "This schema has been disabled";
                return(schemaXml);
            }


            schemaXml = new SchemaRestDefinition(schema.SchemaDefinitionFromUrl)
            {
            };

            schemaXml.RestSchema = new RestSchema()
            {
                Title            = schema.Title,
                ShortDescription = schema.ShortDescription,
                Description      = schema.Description,
                FriendlyUrl      = schema.Title.ToUrlSlug()
            };

            var esdFunctionService = ObjectFactory.GetInstance <IEsdFunctionService>();

            var esdLinks =
                esdFunctionService.GetLinkedFunctionsServices(schema.Id)
                .Select(x => new EsdLink()
            {
                Id = x.Identifier, Title = x.Label, Type = x.Type
            })
                .ToList();

            schemaXml.EsdLinks = new EsdLinks()
            {
                Links = esdLinks
            };
            if (schema.Definition == null)
            {
                return(schemaXml);
            }

            var def = new List <RestColumnDefinition>();

            def.AddRange(schema.Definition.Columns.Select(c => new RestColumnDefinition
            {
                Name           = c.ColumnName,
                Description    = c.Title,
                Type           = c.Type,
                MaxSize        = ((c.Type ?? "").ToLower() == "text") ? c.MaxSize.ToString() : "N/A",
                MinDate        = (c.Type ?? "") == "DateTime" && c.MinDate != null ? c.MinDate.ToString() : "N/A",
                MaxDate        = (c.Type ?? "") == "DateTime" && c.MaxDate != null ? c.MaxDate.ToString() : "N/A",
                MinCurrency    = (c.Type ?? "") == "Currency" && c.MinCurrency != null ? c.MinCurrency.ToString() : "N/A",
                MaxCurrency    = (c.Type ?? "") == "Currency" && c.MaxCurrency != null ? c.MaxCurrency.ToString() : "N/A",
                MinNumber      = (c.Type ?? "") == "Number" && c.MinNumber != null ? c.MinNumber.ToString() : "N/A",
                MaxNumber      = (c.Type ?? "") == "Number" && c.MaxNumber != null ? c.MaxNumber.ToString() : "N/A",
                IsRequired     = c.IsRequired,
                HelpText       = c.HelpText,
                Uri            = c.LinkedDataUri ?? "",
                DisplayInitial = c.IsShownInitially,
                SortDirection  = c.DefaultSortDirection,
                Sorted         = c.IsDefaultSort,
                IsTotalled     = c.IsTotalisable,
            }));

            schemaXml.RestColumnDefinitions = new RestColumnDefinitions()
            {
                ColumnDefinitions = def
            };
            return(schemaXml);
        }