public ValidationResult Validate(MetadataEntry metadataEntry, MD_Metadata_Type metadata, string rawXmlProcessed)
        {
            ValidationResult validationResult = new ValidationResult();

            if (metadataEntry.HasResourceType("software"))
            {
                validationResult = HasDistributionUrl(metadata, validationResult);
            }
            else
            {
                bool allowSpatialDataThemeError = true;
                bool allowConformityError = true;
                validationResult = new InspireValidator().Validate(rawXmlProcessed, allowSpatialDataThemeError, allowConformityError);
            }

            return validationResult;
        }
        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(Constants.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.",
                            Result = -1,
                            Timestamp = DateTime.Now
                        };
                }
                else
                {
                    if (metadataEntry.InspireResource)
                    {
                        Log.Info("Validating metadata with INSPIRE-validator.");
                        validationResult = new InspireValidator(_httpRequestExecutor).Validate(rawXmlProcessed);
                    }
                    else
                    {
                        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, Result = -1, Timestamp = DateTime.Now });
                Log.Error("Exception occured for uuid=" + uuid + ", not validated. " + message);
            }
            return metadataEntry;
        }
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);
        }