Exemple #1
0
 private async static Task UpdateXsd(
     AltinnAppGitRepository altinnAppGitRepository,
     Manatee.Json.Schema.JsonSchema jsonSchema,
     string schemaName)
 {
     using Stream xsdMemoryStream = ConvertJsonSchemaToXsd(jsonSchema);
     await altinnAppGitRepository.WriteStreamByRelativePathAsync($"App/models/{schemaName}.xsd", xsdMemoryStream, true);
 }
Exemple #2
0
        private async static Task UpdateApplicationMetadata(AltinnAppGitRepository altinnAppGitRepository, string schemaName, string typeName)
        {
            Application application = await altinnAppGitRepository.GetApplicationMetadata();

            UpdateApplicationWithAppLogicModel(application, schemaName, "Altinn.App.Models." + typeName);

            await altinnAppGitRepository.UpdateApplicationMetadata(application);
        }
Exemple #3
0
        private static void DeleteRelatedSchemaFiles(AltinnAppGitRepository altinnAppGitRepository, string schemaName, string directory)
        {
            var files = GetRelatedSchemaFiles(schemaName, directory);

            foreach (var file in files)
            {
                altinnAppGitRepository.DeleteFileByAbsolutePath(file);
            }
        }
Exemple #4
0
        private async static Task <ModelMetadata> UpdateModelMetadata(AltinnAppGitRepository altinnAppGitRepository, JsonSchema jsonSchema, string schemaName)
        {
            JsonSchemaToInstanceModelGenerator converter = new JsonSchemaToInstanceModelGenerator(altinnAppGitRepository.Org, altinnAppGitRepository.Repository, jsonSchema);
            ModelMetadata modelMetadata = converter.GetModelMetadata();

            await altinnAppGitRepository.UpdateModelMetadata(modelMetadata, schemaName);

            return(modelMetadata);
        }
Exemple #5
0
        private static async Task DeleteDatatypeFromApplicationMetadata(AltinnAppGitRepository altinnAppGitRepository, string id)
        {
            var applicationMetadata = await altinnAppGitRepository.GetApplicationMetadata();

            if (applicationMetadata.DataTypes != null)
            {
                DataType removeForm = applicationMetadata.DataTypes.Find(m => m.Id == id);
                applicationMetadata.DataTypes.Remove(removeForm);
            }

            await altinnAppGitRepository.UpdateApplicationMetadata(applicationMetadata);
        }
Exemple #6
0
        public async Task GetTextResources_ResourceExists_ShouldReturn()
        {
            var org        = "ttd";
            var repository = "hvem-er-hvem";
            var developer  = "testUser";

            string repositoriesRootDirectory = TestDataHelper.GetTestDataRepositoriesRootDirectory();
            string repositoryDirectory       = TestDataHelper.GetTestDataRepositoryDirectory(org, repository, developer);
            var    altinnAppGitRepository    = new AltinnAppGitRepository(org, repository, developer, repositoriesRootDirectory, repositoryDirectory);

            var textResource = await altinnAppGitRepository.GetTextResources("nb");

            textResource.Should().NotBeNull();
            textResource.Resources.First(r => r.Id == "ServiceName").Value.Should().Be("Hvem er hvem?");
        }
Exemple #7
0
        public void Constructor_ValidParameters_ShouldInstantiate()
        {
            var org        = "ttd";
            var repository = "hvem-er-hvem";
            var developer  = "testUser";

            string repositoriesRootDirectory = TestDataHelper.GetTestDataRepositoriesRootDirectory();
            string repositoryDirectory       = TestDataHelper.GetTestDataRepositoryDirectory(org, repository, developer);

            var altinnAppGitRepository = new AltinnAppGitRepository(org, repository, developer, repositoriesRootDirectory, repositoryDirectory);

            Assert.Equal(org, altinnAppGitRepository.Org);
            Assert.Equal(repository, altinnAppGitRepository.Repository);
            Assert.Equal(developer, altinnAppGitRepository.Developer);
            Assert.Contains(repositoriesRootDirectory, altinnAppGitRepository.RepositoriesRootDirectory);
        }
Exemple #8
0
        public async Task GetApplicationMetadata_FileExists_ShouldHaveCorrectValues()
        {
            var org        = "ttd";
            var repository = "hvem-er-hvem";
            var developer  = "testUser";

            string repositoriesRootDirectory = TestDataHelper.GetTestDataRepositoriesRootDirectory();
            string repositoryDirectory       = TestDataHelper.GetTestDataRepositoryDirectory(org, repository, developer);
            var    altinnAppGitRepository    = new AltinnAppGitRepository(org, repository, developer, repositoriesRootDirectory, repositoryDirectory);

            var applicationMetadata = await altinnAppGitRepository.GetApplicationMetadata();

            applicationMetadata.Id.Should().Be("yabbin/hvem-er-hvem");
            applicationMetadata.Org.Should().Be("yabbin");
            applicationMetadata.Title.Should().ContainValues("Hvem er hvem?", "who-is-who");
            applicationMetadata.Title.Should().ContainKeys("nb", "en");

            applicationMetadata.DataTypes.Should().HaveCount(2);
            applicationMetadata.DataTypes.First(d => d.Id == "ref-data-as-pdf").AllowedContentTypes.First().Should().Be("application/pdf");

            DataType mainDataType = applicationMetadata.DataTypes.First(d => d.Id == "Kursdomene_HvemErHvem_M_2021-04-08_5742_34627_SERES");

            mainDataType.AllowedContentTypes.First().Should().Be("application/xml");
            mainDataType.AppLogic.ClassRef.Should().Be("Altinn.App.Models.HvemErHvem_M");
            mainDataType.AppLogic.AutoCreate.Should().BeTrue();
            mainDataType.MinCount.Should().Be(1);
            mainDataType.MaxCount.Should().Be(1);
            mainDataType.TaskId.Should().Be("Task_1");

            applicationMetadata.PartyTypesAllowed.Person.Should().BeFalse();
            applicationMetadata.PartyTypesAllowed.Organisation.Should().BeFalse();
            applicationMetadata.PartyTypesAllowed.SubUnit.Should().BeFalse();
            applicationMetadata.PartyTypesAllowed.BankruptcyEstate.Should().BeFalse();

            var dataField = applicationMetadata.DataFields.First(d => d.Id == "GeekType");

            dataField.Path.Should().Be("InnrapporterteData.geekType");
            dataField.DataTypeId.Should().Be("Kursdomene_HvemErHvem_M_2021-04-08_5742_34627_SERES");

            applicationMetadata.AutoDeleteOnProcessEnd.Should().BeFalse();
            applicationMetadata.Created.Should().BeSameDateAs(DateTime.Parse("2021-04-08T17:42:09.0883842Z"));
            applicationMetadata.CreatedBy.Should().Be("Ronny");
            applicationMetadata.LastChanged.Should().BeSameDateAs(DateTime.Parse("2021-04-08T17:42:09.08847Z"));
            applicationMetadata.LastChangedBy.Should().Be("Ronny");
        }
Exemple #9
0
        public async Task GetTextResourcesForAllLanguages_ResourceExists_ShouldReturn()
        {
            var org        = "ttd";
            var repository = "hvem-er-hvem";
            var developer  = "testUser";

            string repositoriesRootDirectory = TestDataHelper.GetTestDataRepositoriesRootDirectory();
            string repositoryDirectory       = TestDataHelper.GetTestDataRepositoryDirectory(org, repository, developer);
            var    altinnAppGitRepository    = new AltinnAppGitRepository(org, repository, developer, repositoriesRootDirectory, repositoryDirectory);

            var allResources = await altinnAppGitRepository.GetTextResourcesForAllLanguages();

            allResources.Should().NotBeNull();
            allResources.Should().HaveCount(12);
            allResources.First(r => r.Key == "ServiceName").Value.Should().HaveCount(2);
            allResources.First(r => r.Key == "ServiceName").Value.First(r => r.Key == "en").Value.Value.Should().Be("who-is-who");
            allResources.First(r => r.Key == "ServiceName").Value.First(r => r.Key == "nb").Value.Value.Should().Be("Hvem er hvem?");
        }
Exemple #10
0
        private async Task <string> ProcessNewXsd(
            AltinnAppGitRepository altinnAppGitRepository,
            MemoryStream xsdMemoryStream,
            string filePath)
        {
            Json.Schema.JsonSchema jsonSchema = GenerateJsonSchemaFromXsd(xsdMemoryStream);
            var jsonContent = SerializeJson(jsonSchema);

            await altinnAppGitRepository.WriteTextByRelativePathAsync(
                Path.ChangeExtension(filePath, "schema.json"), jsonContent, true);

            var jsonSchemaConverterStrategy = JsonSchemaConverterStrategyFactory.SelectStrategy(jsonSchema);
            var metamodelConverter          =
                new JsonSchemaToMetamodelConverter(jsonSchemaConverterStrategy.GetAnalyzer());
            var schemaName    = GetSchemaName(filePath);
            var modelMetadata = metamodelConverter.Convert(schemaName, jsonContent);
            await altinnAppGitRepository.UpdateModelMetadata(modelMetadata, schemaName);

            await UpdateCSharpClasses(altinnAppGitRepository, modelMetadata, schemaName);

            await UpdateApplicationMetadata(altinnAppGitRepository, schemaName, schemaName);

            return(jsonContent);
        }
Exemple #11
0
 private static async Task UpdateJsonSchema(AltinnAppGitRepository altinnAppGitRepository, string relativeFilePath, string jsonContent)
 {
     await altinnAppGitRepository.WriteTextByRelativePathAsync(relativeFilePath, jsonContent, true);
 }
Exemple #12
0
 private async static Task UpdateCSharpClasses(AltinnAppGitRepository altinnAppGitRepository, ModelMetadata modelMetadata, string schemaName)
 {
     JsonMetadataParser modelGenerator = new JsonMetadataParser();
     string             classes        = modelGenerator.CreateModelFromMetadata(modelMetadata);
     await altinnAppGitRepository.UpdateCSharpClasses(classes, schemaName);
 }