// Get Add to map information public void GetAddToMapInfoByID(string DocID) { _response = new CswSearchResponse(); StringBuilder sb = new StringBuilder(); if (DocID == null || DocID == "") { throw new ArgumentNullException(); } if (_catalog == null) { throw new NullReferenceException("Catalog not specified."); } if (_catalog.Capabilities == null) { throw new NullReferenceException("Catalog capabilities not initialized."); } if (_catalog.Profile == null) { throw new NullReferenceException("Catalog profile not specified."); } if (_catalog.Capabilities.GetRecordByID_GetURL == null || _catalog.Capabilities.GetRecordByID_GetURL.Length == 0) { sb.AppendLine(DateTime.Now + " GetRecordByID URL not specified for the catalog capabilities."); throw new NullReferenceException("GetRecordByID URL not specified for the catalog capabilities."); } CswProfile profile = _catalog.Profile; // generate request url string getRecordByIDBaseUrl = _catalog.Capabilities.GetRecordByID_GetURL; string requestUrl = profile.GenerateCSWGetMetadataByIDRequestURL(getRecordByIDBaseUrl, DocID); sb.AppendLine(DateTime.Now + " GetRecordsById request URL : " + requestUrl); if (_cswClient == null) { _cswClient = new CswClient(); } string responseText = _cswClient.SubmitHttpRequest("GET", requestUrl, ""); _response.ResponseXML = responseText; sb.AppendLine(DateTime.Now + " GetRecordsById response xml : " + responseText); CswRecord record = new CswRecord(DocID); profile.ReadCSWGetMetadataByIDResponse(responseText, record); if (record.MetadataResourceURL != null && record.MetadataResourceURL.Equals("") && profile.Name.Equals("terra catalog CSW 2.0.2 AP ISO")) { record.FullMetadata = responseText; } if (record == null) { throw new NullReferenceException("Record not populated."); } // check if full metadata or resourceURL has been returned bool hasFullMetadata = !(record.FullMetadata == null || record.FullMetadata == ""); bool hasResourceUrl = !(record.MetadataResourceURL == null || record.MetadataResourceURL == ""); if (!hasFullMetadata && !hasResourceUrl) { // throw new InvalidOperationException("Neither full metadata nor metadata resource URL was found for the CSW record."); } else if (!hasFullMetadata && record.MetadataResourceURL != null) { // need to load metadata from resource URL responseText = _cswClient.SubmitHttpRequest("GET", record.MetadataResourceURL, "", "", ""); record.FullMetadata = responseText; } // add record to the response CswRecords records = new CswRecords(); if (record != null) { records.Add(record.ID, record); } _response.Records = records; _mapServerUrl = record.MapServerURL; if (_mapServerUrl != null) { sb.AppendLine(DateTime.Now + " Map Server Url : " + _mapServerUrl); } writeLogMessage(sb.ToString()); }
/// <summary> /// Retrieve metadata from CSW service by its ID /// </summary> /// <param name="DocID">Metadata document ID</param> public bool GetMetadataByID(string DocID, bool bApplyTransform) { _response = new CswSearchResponse(); StringBuilder sb = new StringBuilder(); if (DocID == null || DocID == "") { throw new ArgumentNullException(); } if (_catalog == null) { throw new NullReferenceException("Catalog not specified."); } if (_catalog.Capabilities == null) { throw new NullReferenceException("Catalog capabilities not initialized."); } if (_catalog.Profile == null) { throw new NullReferenceException("Catalog profile not specified."); } if (_catalog.Capabilities.GetRecordByID_GetURL == null || _catalog.Capabilities.GetRecordByID_GetURL.Length == 0) { throw new NullReferenceException("GetRecordByID URL not specified for the catalog capabilities."); } CswProfile profile = _catalog.Profile; // generate request url string getRecordByIDBaseUrl = _catalog.Capabilities.GetRecordByID_GetURL; string requestUrl = profile.GenerateCSWGetMetadataByIDRequestURL(getRecordByIDBaseUrl, DocID); sb.AppendLine(DateTime.Now + " GetRecordsById request URL : " + requestUrl); if (_cswClient == null) { _cswClient = new CswClient(); } string responseText = _cswClient.SubmitHttpRequest("GET", requestUrl, ""); _response.ResponseXML = responseText; sb.AppendLine(DateTime.Now + " GetRecordsById response xml : " + responseText); CswRecord record = new CswRecord(DocID); bool isTransformed = false; if (bApplyTransform) { isTransformed = profile.TransformCSWGetMetadataByIDResponse(responseText, record); if (isTransformed) { sb.AppendLine(DateTime.Now + " Transformed xml : " + record.FullMetadata); } } else { record.FullMetadata = responseText; } /*if (!isTransformed) * { * XmlDocument responseXml = new XmlDocument(); * try { responseXml.LoadXml(responseText); } * catch (XmlException xmlEx) * { * throw new XmlException("Error occurred \r\n" + xmlEx.Message); * } * record.FullMetadata = responseXml.FirstChild.InnerText ; * }*/ // add record to the response CswRecords records = new CswRecords(); if (record != null) { records.Add(record.ID, record); } _response.Records = records; _mapServerUrl = record.MapServerURL; if (_mapServerUrl != null) { sb.AppendLine(DateTime.Now + " Map Server Url : " + _mapServerUrl); } writeLogMessage(sb.ToString()); return(isTransformed); }