public static string EntrySelfLinkTemplate(IOpenSearchResultItem item, OpenSearchDescription osd, string mimeType)
        {
            if (item == null)
                return null;

            string identifier = item.Identifier;

            NameValueCollection nvc = new NameValueCollection();

            nvc.Set("q", string.Format("_id:{0}", item.Identifier));

            UriBuilder template = new UriBuilder(OpenSearchFactory.GetOpenSearchUrlByType(osd, mimeType).Template);
            string[] queryString = Array.ConvertAll(nvc.AllKeys, key => string.Format("{0}={1}", key, nvc[key]));
            template.Query = string.Join("&", queryString);
            return template.ToString();
        }
Пример #2
0
        public object Get(ProxyGetUrlRequestTep request)
        {
            var uri  = new UriBuilder(request.url);
            var host = uri.Host;

            if (!((host.EndsWith("terradue.int") || host.EndsWith("terradue.com")) || !host.Equals(HttpContext.Current.Request.Url.Host)))
            {
                throw new Exception("Non Terradue urls are not accepted");
            }

            var        context = TepWebContext.GetWebContext(PagePrivileges.EverybodyView);
            HttpResult result  = null;

            context.Open();
            context.LogInfo(this, string.Format("/proxy GET url='{0}'", request.url));

            OpenSearchEngine ose = MasterCatalogue.OpenSearchEngine;
            var settings         = MasterCatalogue.OpenSearchFactorySettings;

            if (uri.Path.EndsWith("/description") || uri.Path.EndsWith("/OSDD"))
            {
                GenericOpenSearchable urlToShare = new GenericOpenSearchable(new OpenSearchUrl(request.url), settings);
                Terradue.OpenSearch.Schema.OpenSearchDescription osd = urlToShare.GetOpenSearchDescription();
                result = new HttpResult(osd, "application/opensearchdescription+xml");
            }
            else
            {
                var e = OpenSearchFactory.FindOpenSearchable(settings, new Uri(request.url), "application/atom+xml");
                if (e.DefaultMimeType != "application/atom+xml" && !e.DefaultMimeType.Contains("xml"))
                {
                    throw new InvalidOperationException("No Url in the OpenSearch Description Document that query fully qualified model");
                }

                Type type = OpenSearchFactory.ResolveTypeFromRequest(HttpContext.Current.Request.QueryString, HttpContext.Current.Request.Headers, ose);
                var  res  = ose.Query(e, new NameValueCollection(), type);

                result = new HttpResult(res.SerializeToString(), res.ContentType);
            }

            context.Close();
            return(result);
        }
        public Terradue.OpenSearch.Schema.OpenSearchDescription GetOpenSearchDescription()
        {
            OpenSearchDescription osd = new OpenSearchDescription();

            osd.ShortName = "Elastic Catalogue";
            osd.Attribution = "Terradue";
            osd.Contact = "*****@*****.**";
            osd.Developer = "Terradue GeoSpatial Development Team";
            osd.SyndicationRight = "open";
            osd.AdultContent = "false";
            osd.Language = "en-us";
            osd.OutputEncoding = "UTF-8";
            osd.InputEncoding = "UTF-8";
            osd.Description = "This Search Service performs queries in the available dataset catalogue. There are several URL templates that return the results in different formats (GeoJson, RDF, ATOM or KML). This search service is in accordance with the OGC 10-032r3 specification.";

            OpenSearchEngine ose = new OpenSearchEngine();
            ose.LoadPlugins();

            var searchExtensions = ose.Extensions;
            List<OpenSearchDescriptionUrl> urls = new List<OpenSearchDescriptionUrl>();

            NameValueCollection parameters = GetOpenSearchParameters(this.DefaultMimeType);

            UriBuilder searchUrl = new UriBuilder(string.Format("es://elasticsearch/{0}/{1}/search", this.index.Name, this.Type.Name));
            NameValueCollection queryString = HttpUtility.ParseQueryString("?format=json");
            parameters.AllKeys.FirstOrDefault(k => {
                queryString.Add(parameters[k], "{" + k + "?}");
                return false;
            });

            searchUrl.Query = queryString.ToString();
            urls.Add(new OpenSearchDescriptionUrl("application/json",
                                                  searchUrl.ToString(),
                                                  "search"));

            osd.Url = urls.ToArray();

            return osd;
        }
 /// <summary>
 /// Gets the type of the open search URL by.
 /// </summary>
 /// <returns>The open search URL by type.</returns>
 /// <param name="osd">Osd.</param>
 /// <param name="type">Type.</param>
 public static OpenSearchDescriptionUrl GetOpenSearchUrlByType(OpenSearchDescription osd, string type)
 {
     MimeType mime = MimeType.CreateFromContentType(type);
     return osd.Url.FirstOrDefault(u => {
         return MimeType.Equals(MimeType.CreateFromContentType(u.Type),mime);
     });
 }
        public OpenSearchDescription GetOpenSearchDescription()
        {
            OpenSearchDescription osd = new OpenSearchDescription();
            osd.ShortName = this.Identifier;
            osd.Description = this.Description;
            osd.SyndicationRight = "open";
            osd.AdultContent = "false";
            osd.Language = "en-us";
            osd.OutputEncoding = "UTF-8";
            osd.InputEncoding = "UTF-8";
            osd.Developer = "Terradue GeoSpatial Development Team";

            // Create the union Link

            OpenSearchDescriptionUrl url = new OpenSearchDescriptionUrl("application/atom+xml", "dummy://dummy", "results");

            osd.Url = new OpenSearchDescriptionUrl[1];
            osd.Url[0] = url;

            return osd;
        }
 public string EntrySelfLinkTemplate(IOpenSearchResultItem item, OpenSearchDescription osd, string mimeType)
 {
     return OpenSearchService.EntrySelfLinkTemplate(item, osd, mimeType);
 }
        public OpenSearchDescription GetOpenSearchDescription()
        {
            OpenSearchDescription osd = new OpenSearchDescription();
            osd.ShortName = "test";
            osd.Contact = "*****@*****.**";
            osd.SyndicationRight = "open";
            osd.AdultContent = "false";
            osd.Language = "en-us";
            osd.OutputEncoding = "UTF-8";
            osd.InputEncoding = "UTF-8";
            osd.Developer = "Terradue OpenSearch Development Team";
            osd.Attribution = "Terradue";

            List<OpenSearchDescriptionUrl> urls = new List<OpenSearchDescriptionUrl>();

            UriBuilder urlb = new UriBuilder("dummy://localhost/test/description");

            OpenSearchDescriptionUrl url = new OpenSearchDescriptionUrl("application/opensearchdescription+xml", urlb.ToString(), "self");
            url.Parameters = OpenSearchFactory.GetDefaultParametersDescription(100).ToArray();
            urls.Add(url);

            urlb = new UriBuilder("dummy://localhost/test/search");
            NameValueCollection query = GetOpenSearchParameters("application/atom+xml");

            string[] queryString = Array.ConvertAll(query.AllKeys, key => string.Format("{0}={1}", key, query[key]));
            urlb.Query = string.Join("&", queryString);
            url = new OpenSearchDescriptionUrl("application/atom+xml", urlb.ToString(), "search");
            url.IndexOffset = 1;
            urls.Add(url);

            osd.Url = urls.ToArray();

            return osd;
        }
 //---------------------------------------------------------------------------------------------------------------------
 /// <summary>Creates an OpenSearchParameterValueSet instance based on the specified OpenSearchDescriptionUrl object.</summary>
 /// <returns>The created OpenSearchParameterValueSet instance.</returns>
 /// <param name="osdUrl">An OpenSearchDescriptionUrl object from a deserialized OpenSearch description document.</param>
 public static OpenSearchParameterValueSet FromOpenSearchDescription(OpenSearchDescription osd, string format)
 {
     OpenSearchDescriptionUrl osdUrl = osd.Url.SingleOrDefault(u => u.Type == format);
     if (osdUrl == null) throw new OpenSearchException(String.Format("No OpenSearch description URL found for format \"{0}\"", format));
     return FromOpenSearchDescription(osdUrl, osd.ExtraNamespace);
 }
        public static OpenSearchDescriptionUrl GetOpenSearchUrlByTypeAndMaxParam(OpenSearchDescription osd, List<string> mimeTypes, NameValueCollection osParameters)
        {
            OpenSearchDescriptionUrl url = null;
            int maxParam = -1;

            foreach (var urlC in osd.Url) {
                UriBuilder tempU = new UriBuilder(BuildRequestUrlFromTemplateNameParameters(new OpenSearchUrl(urlC.Template), osParameters));
                int numParam = HttpUtility.ParseQueryString(tempU.Query).Count;
                if (maxParam < numParam) {
                    maxParam = numParam;
                    url = urlC;
                }
            }

            return url;
        }
Пример #10
0
 public IOpenSearchable Create(OpenSearchDescription osd)
 {
     if (soft)
         return new SoftGenericOpenSearchable(osd, ose);
     return new GenericOpenSearchable(osd, ose);
 }
Пример #11
0
 /// <summary>
 /// Gets the open search URL by rel.
 /// </summary>
 /// <returns>The open search URL by rel.</returns>
 /// <param name="osd">Osd.</param>
 /// <param name="rel">Rel.</param>
 public static OpenSearchDescriptionUrl GetOpenSearchUrlByRel(OpenSearchDescription osd, string rel)
 {
     return osd.Url.FirstOrDefault(u => u.Relation == rel);
 }
Пример #12
0
        public static OpenSearchDescription GetDefaultOpenSearchDescription(IOpenSearchableElasticType type)
        {
            OpenSearchDescription osd = new OpenSearchDescription();

            osd.ShortName = "Terradue Catalogue";
            osd.Attribution = "Terradue";
            osd.Contact = "*****@*****.**";
            osd.Developer = "Terradue GeoSpatial Development Team";
            osd.SyndicationRight = "open";
            osd.AdultContent = "false";
            osd.Language = "en-us";
            osd.OutputEncoding = "UTF-8";
            osd.InputEncoding = "UTF-8";
            osd.Description = string.Format("This Search Service performs queries in the index {0}. There are several URL templates that return the results in different formats." +
            "This search service is in accordance with the OGC 10-032r3 specification.", type.Index.Name);

            OpenSearchEngine ose = type.GetOpenSearchEngine(new NameValueCollection());

            var searchExtensions = ose.Extensions;
            List<OpenSearchDescriptionUrl> urls = new List<OpenSearchDescriptionUrl>();

            NameValueCollection parameters = type.GetOpenSearchParameters(type.DefaultMimeType);

            UriBuilder searchUrl = new UriBuilder(string.Format("{0}/catalogue/{1}/{2}/search", Settings.BaseUrl, type.Index.Name, type.Type.Name));
            NameValueCollection queryString = HttpUtility.ParseQueryString("?format=format");
            parameters.AllKeys.FirstOrDefault(k => {
                queryString.Add(k, parameters[k]);
                return false;
            });

            foreach (int code in searchExtensions.Keys) {

                queryString.Set("format", searchExtensions[code].Identifier);
                string[] queryStrings = Array.ConvertAll(queryString.AllKeys, key => string.Format("{0}={1}", key, queryString[key]));
                searchUrl.Query = string.Join("&", queryStrings);
                urls.Add(new OpenSearchDescriptionUrl(searchExtensions[code].DiscoveryContentType,
                                                      searchUrl.ToString(),
                                                      "results"));

            }
            searchUrl = new UriBuilder(string.Format("{0}/catalogue/{1}/{2}/description", Settings.BaseUrl, type.Index.Name, type.Type.Name));
            urls.Add(new OpenSearchDescriptionUrl("application/opensearchdescription+xml",
                                                  searchUrl.ToString(),
                                                  "self"));
            osd.Url = urls.ToArray();

            return osd;
        }
 public CwicOpenSearchable(OpenSearchDescription osd, OpenSearchEngine ose)
     : base(osd, ose)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="Terradue.OpenSearch.GenericOpenSearchable"/> class from an OpenSearchDescription.
 /// </summary>
 /// <param name="osd">The OpenSearchDescription describing the OpenSearchable entity to represent</param>
 /// <param name="ose">An OpenSearchEngine instance, preferably with registered extensions able to read the query url</param>
 public GenericOpenSearchable(OpenSearchDescription osd, OpenSearchEngine ose)
 {
     this.osd = osd;
     this.ose = ose;
     url = null;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="Terradue.OpenSearch.GenericOpenSearchable"/> class from a quaery Url
 /// </summary>
 /// <param name="url">The query URL</param>
 /// <param name="ose">An OpenSearchEngine instance, preferably with registered extensions able to read the query url</param>
 public GenericOpenSearchable(OpenSearchUrl url, OpenSearchEngine ose)
 {
     this.url = url;
     this.ose = ose;
     this.osd = ose.AutoDiscoverFromQueryUrl(url);
 }
 public OpenSearchDescription GetOpenSearchDescription()
 {
     if (osd == null)
         this.osd = ose.AutoDiscoverFromQueryUrl(url);
     return osd;
 }
Пример #17
0
 /// <summary>
 /// Create an IOpenSearchable from an OpenSearchUrl
 /// </summary>
 /// <param name="url">URL to either a search or a description</param>
 /// <param name="osd">Osd.</param>
 public IOpenSearchable Create(OpenSearchDescription osd)
 {
     return new GenericOpenSearchable(osd, this);
 }