/// <summary> /// Get forms metadata from altinn /// </summary> /// <param name="altinnResource">The resource</param> /// <returns>The form resource</returns> public static async Task <FormResource> GetFormsMetadata(AltinnResource altinnResource) { string path = FormTaskUrl(altinnResource); FormResource result = null; HttpResponseMessage response = await client.GetAsync(path); if (response.IsSuccessStatusCode) { string content = await response.Content.ReadAsStringAsync(); result = JsonConvert.DeserializeObject <FormResource>(content); } return(result); }
/// <summary> /// Reads all altinn services resources and returns a list of these /// </summary> /// <returns>the list</returns> public static async Task <List <AltinnResource> > ReadAllSchemas() { List <AltinnResource> resources = await GetResourcesAsync(); List <AltinnResource> result = new List <AltinnResource>(); Dictionary <string, string> orgShortnameToOrgnumberMap = BuildOrganizationNumberMap(); Dictionary <string, string> serviceCodeToServiceEditionCodeDictionary = new Dictionary <string, string>(); string[] excludeServiceOwnerCodes = { "ACN", "ASF", "TTD" }; foreach (AltinnResource resource in resources) { if (excludeServiceOwnerCodes.Contains(resource.ServiceOwnerCode)) { continue; } List <AltinnFormMetaData> forms = new List <AltinnFormMetaData>(); FormResource r = await GetFormsMetadata(resource); if (r != null && r.FormsMetaData != null && r.FormsMetaData.ToArray() != null) { foreach (AltinnFormMetaData form in r.FormsMetaData) { form.XsdSchemaUrl = XsdUrl(resource, form); form.JsonSchema = Zip(DownloadAndConvertXsdToJsonSchema(form.XsdSchemaUrl)); forms.Add(form); } } if (forms.Count > 0) { string orgnr = orgShortnameToOrgnumberMap.GetValueOrDefault(resource.ServiceOwnerCode); if (string.IsNullOrEmpty(orgnr)) { Debug.WriteLine(resource.ServiceOwnerCode + "\t" + resource.ServiceOwnerName); } resource.OrganizationNumber = orgnr; resource.Forms = forms; result.Add(resource); RememberHighestServiceEditionCode(serviceCodeToServiceEditionCodeDictionary, resource); } } List <AltinnResource> filteredResult = new List <AltinnResource>(); foreach (AltinnResource resource in result) { string highestEditionCode = serviceCodeToServiceEditionCodeDictionary.GetValueOrDefault(resource.ServiceCode); if (resource.ServiceEditionCode.Equals(highestEditionCode)) { filteredResult.Add(resource); } } return(filteredResult); }