// @TODO: Check if this method is obsolete.
        private string RunInspireValidation(string data)
        {
            /*
             * BAD HACK: Search and replace norwegian language code with english language code.
             * INSPIRE does not validate metadata with norwegian language code.
             * This removes validation errors related to conformity and language code.
             */
            data = data.Replace(">nob</gco:CharacterString>", ">eng</gco:CharacterString>");
            data = data.Replace(">nor</gco:CharacterString>", ">eng</gco:CharacterString>");

            // formating request according to
            // http://inspire-geoportal.ec.europa.eu/validator2/html/usingaswebservice.html

            string boundary = createHash(DateTime.Now.Ticks.ToString());

            string        eol     = "\r\n";
            StringBuilder builder = new StringBuilder();

            builder.Append("--").Append(boundary).Append(eol);
            builder.Append("Content-Disposition: form-data; name=\"resourceRepresentation\"").Append(eol).Append(eol);
            builder.Append(data);
            builder.Append(eol);
            builder.Append("--").Append(boundary).Append("--").Append(eol).Append(eol);

            string postData = builder.ToString();

            string contentType = "multipart/form-data; boundary=" + boundary;

            Log.Info("Sending metadata to INSPIRE validator.");
            string responseBody = _httpRequestExecutor.PostRequest(_inspireUrl + _validationEndpoint, "application/xml", contentType, postData);

            return(responseBody);
        }
Beispiel #2
0
        public GetRecordsResponseType RunSearch(int startPosition)
        {
            Log.Debug("Running search with start position: " + startPosition);
            string responseBody = _httpRequestExecutor.PostRequest(EndpointUrlGeoNorgeCsw, "application/xml", "application/xml",
                                                                   CreateRequestBody(startPosition));


            return(SerializeUtil.DeserializeFromString <GetRecordsResponseType>(responseBody));
        }
Beispiel #3
0
        public MetadataEntry RetrieveAndValidate(string uuid)
        {
            MetadataEntry metadataEntry = null;

            try
            {
                var getCswRecordRequest = CreateGetCswRecordRequest(uuid);
                Log.Info("Henter metadata for uuid=" + uuid + " fra GeoNorge.");
                string cswRecordResponse = _httpRequestExecutor.PostRequest(EndpointUrlGeoNorgeCsw,
                                                                            ContentTypeXml, ContentTypeXml,
                                                                            getCswRecordRequest);

                /* Quick and dirty hacks to fix exceptions in serialization due to invalid xml */

                Regex fixWrongDecimalInRealElements = new Regex("<gco:Real>([0-9]+),([0-9]+)</gco:Real>");

                var fixedResponse = cswRecordResponse.Replace("<gco:Boolean />", "<gco:Boolean>false</gco:Boolean>")
                                    .Replace("<gco:Real />", "<gco:Real>0.0</gco:Real>")
                                    .Replace("<gco:DateTime />", "")
                                    .Replace("<gmd:MD_TopicCategoryCode />", "");

                var rawXmlProcessed = fixWrongDecimalInRealElements.Replace(fixedResponse, "<gco:Real>$1.$2</gco:Real>");

                GetRecordByIdResponseType getRecordResponse = SerializeUtil.DeserializeFromString <GetRecordByIdResponseType>(rawXmlProcessed);
                MD_Metadata_Type          metadata          = getRecordResponse.Items[0] as MD_Metadata_Type;

                metadataEntry = ParseCswRecordResponse(uuid, metadata);
                ValidationResult validationResult;
                if (metadataEntry.ResourceType == "unknown")
                {
                    validationResult = new ValidationResult
                    {
                        Messages  = "Unknown resource type, please check value of hierarchyLevel element.",
                        Status    = ValidationStatus.NotValidated,
                        Timestamp = DateTime.Now
                    };
                    Log.Info("Validation result: " + validationResult.Messages);
                    metadataEntry.ValidationResults.Add(validationResult);
                }
                else
                {
                    if (metadataEntry.InspireResource)
                    {
                        // Check validation state instead of valdating.
                        Log.Info("Check validation state metadata with INSPIRE-validator.");
                        validationResult = new InspireValidator(_httpRequestExecutor).CheckValidationState(uuid);
                        Log.Info("Validation result: " + validationResult.Messages);
                        metadataEntry.ValidationResults.Add(validationResult);
                    }
                    if (metadataEntry.Keywords.Contains("Norge digitalt"))
                    {
                        Log.Info("Validating metadata with Norge Digitalt-validator.");
                        validationResult = new NorgeDigitaltValidator().Validate(metadataEntry, metadata, rawXmlProcessed);
                        Log.Info("Validation result: " + validationResult.Messages);
                        metadataEntry.ValidationResults.Add(validationResult);
                    }
                }
            }
            catch (Exception e)
            {
                metadataEntry = ParseCswRecordResponse(uuid, null);

                string message = e.Message;
                if (e.InnerException != null)
                {
                    message += e.InnerException.Message;
                }

                metadataEntry.ValidationResults.Add(new ValidationResult {
                    Messages = "Exception during validation: " + message, Status = ValidationStatus.NotValidated, Timestamp = DateTime.Now
                });
                Log.Error("Exception occured for uuid=" + uuid + ", not validated. " + message);
            }
            return(metadataEntry);
        }