public OpenSearchDescription GetOpenSearchDescription() { OpenSearchDescription osd = new OpenSearchDescription(); osd.ShortName = this.Name; osd.Contact = context.GetConfigValue("CompanyEmail"); 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"; osd.Attribution = context.GetConfigValue("CompanyName"); osd.ExtraNamespace.Add("geo", "http://a9.com/-/opensearch/extensions/geo/1.0/"); osd.ExtraNamespace.Add("time", "http://a9.com/-/opensearch/extensions/time/1.0/"); osd.ExtraNamespace.Add("dct", "http://purl.org/dc/terms/"); // Create the union Link OpenSearchDescriptionUrl url = new OpenSearchDescriptionUrl("application/atom+xml", "dummy://dummy", "results", osd.ExtraNamespace); osd.Url = new OpenSearchDescriptionUrl[1]; osd.Url[0] = url; return(osd); }
public void RemoteResourceIProxiedOpenSearchable() { RemoteResourceSet set = new RemoteResourceSet(context); RemoteResource rr = new RemoteResource(context); rr.ResourceSet = set; set.Resources = new RemoteResourceEntityCollection(context); set.Resources.Include(rr); rr.Location = "http://catalogue.terradue.int/catalogue/search/MER_FRS_1P/rdf?startIndex=0&q=MER_FRS_1P&start=1992-01-01&stop=2014-10-24&bbox=-72,47,-57,58"; set.OpenSearchEngine = ose; set.Identifier = "test"; OpenSearchDescription osd = set.GetProxyOpenSearchDescription(); OpenSearchDescriptionUrl url = osd.Url.FirstOrDefault(p => p.Relation == "self"); Assert.That(url != null); Assert.AreEqual("http://loacalhost:8877/sID/remoteresource/test/description", url.Template); NameValueCollection nvc = new NameValueCollection(); nvc.Set("count", "100"); var osr = ose.Query(set, nvc, "rdf"); Assert.LessOrEqual(osr.Count, 100); }
/// <summary> /// Gets the local open search description. /// </summary> /// <returns>The local open search description.</returns> public override OpenSearchDescription GetLocalOpenSearchDescription() { OpenSearchDescription osd = base.GetOpenSearchDescription(); List <OpenSearchDescriptionUrl> urls = new List <OpenSearchDescriptionUrl> (); UriBuilder urlb = new UriBuilder(GetDescriptionBaseUrl()); OpenSearchDescriptionUrl url = new OpenSearchDescriptionUrl("application/opensearchdescription+xml", urlb.ToString(), "self", osd.ExtraNamespace); urls.Add(url); NameValueCollection query = HttpUtility.ParseQueryString(urlb.Query); urlb = new UriBuilder(GetSearchBaseUrl("application/atom+xml")); query = GetOpenSearchParameters("application/atom+xml"); NameValueCollection nvc = HttpUtility.ParseQueryString(urlb.Query); foreach (var key in nvc.AllKeys) { query.Set(key, nvc [key]); } foreach (var osee in OpenSearchEngine.Extensions.Values) { query.Set("format", osee.Identifier); string [] queryString = Array.ConvertAll(query.AllKeys, key => string.Format("{0}={1}", key, query [key])); urlb.Query = string.Join("&", queryString); url = new OpenSearchDescriptionUrl(osee.DiscoveryContentType, urlb.ToString(), "search", osd.ExtraNamespace); urls.Add(url); } osd.Url = urls.ToArray(); return(osd); }
public OpenSearchDescription GetProxyOpenSearchDescription() { OpenSearchDescription osd = new OpenSearchDescription(); osd.ShortName = string.IsNullOrEmpty(Wpsjob.Name) ? Wpsjob.Identifier : Wpsjob.Name; osd.Attribution = "European Space Agency"; 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 results of a job process. There are several URL templates that return the results in different formats (RDF, ATOM or KML). This search service is in accordance with the OGC 10-032r3 specification."; osd.ExtraNamespace.Add("geo", "http://a9.com/-/opensearch/extensions/geo/1.0/"); osd.ExtraNamespace.Add("time", "http://a9.com/-/opensearch/extensions/time/1.0/"); osd.ExtraNamespace.Add("dct", "http://purl.org/dc/terms/"); osd.ExtraNamespace.Add("t2", "http://www.terradue.com/opensearch"); var searchExtensions = MasterCatalogue.OpenSearchEngine.Extensions; List <OpenSearchDescriptionUrl> urls = new List <OpenSearchDescriptionUrl>(); NameValueCollection parameters = GetOpenSearchParameters(this.DefaultMimeType); UriBuilder searchUrl = new UriBuilder(context.BaseUrl); searchUrl.Path += string.Format("/job/wps/{0}/products/search", Wpsjob.Identifier); NameValueCollection queryString = HttpUtility.ParseQueryString(""); parameters.Add("key", this.Wpsjob.AccessKey); parameters.AllKeys.FirstOrDefault(k => { queryString.Add(k, parameters[k]); return(false); }); List <OpenSearchDescriptionUrlParameter> paramdesc = OpenSearchFactory.GetDefaultParametersDescription(10); 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); var url = new OpenSearchDescriptionUrl(searchExtensions[code].DiscoveryContentType, searchUrl.ToString(), "results", osd.ExtraNamespace); url.Parameters = paramdesc.ToArray(); urls.Add(url); } UriBuilder descriptionUrl = new UriBuilder(context.BaseUrl); descriptionUrl.Path += string.Format("/job/wps/{0}/products/description", Wpsjob.Identifier); urls.Add(new OpenSearchDescriptionUrl("application/opensearchdescription+xml", searchUrl.ToString(), "self", osd.ExtraNamespace)); osd.Url = urls.ToArray(); return(osd); }
/// <summary> /// This function creates a list of opensearch Url with templates from a list /// of search functions based on the formatting capabities of the httpContext /// </summary> /// <param name="searchFunctions">list of search functions to make an opensearch Url template from</param> /// <param name="httpContext">the HTTP context</param> /// <returns></returns> public static IEnumerable <OpenSearchDescriptionUrl> CreateOpenSearchDescriptionUrls(IDictionary <string, ISearchFunction> searchFunctions, HttpContext httpContext, IOpenSearchContext openSearchContext) { // prepare an empty url list List <OpenSearchDescriptionUrl> urls = new List <OpenSearchDescriptionUrl>(); // get the OpenSearch Formatter selector OpenSearchFormatterSelector selector = (OpenSearchFormatterSelector)httpContext.RequestServices.GetService(typeof(OpenSearchFormatterSelector)); // urls are the combination of the search function possible results type and the relevant formatters foreach (var searchFunction in searchFunctions) { foreach (var formatter in selector.SelectFormatters(searchFunction.Value.ResultType)) { // if the formatter is able to serialize the result, then there is a possible url template var supportedContentTypes = formatter.GetSupportedContentTypes(null, searchFunction.Value.ResultType); if (supportedContentTypes == null || supportedContentTypes.Count == 0) { continue; } var xmlCriterionSet = QualifyCriterionSetForOpenSearch(searchFunction.Value.SearchCriterionSet); OpenSearchDescriptionUrl url = new OpenSearchDescriptionUrl( supportedContentTypes.First(), CreateQueryStringUrlTemplate(searchFunction.Key, xmlCriterionSet, httpContext, openSearchContext), "results", xmlCriterionSet.GetExtraNamespacesIfAny() ); urls.Add(url); } } return(urls); }
public OpenSearchDescription GetOpenSearchDescription() { OpenSearchDescription osd = new OpenSearchDescription(); osd.Contact = context.GetConfigValue("CompanyEmail"); 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 = context.GetConfigValue("CompanyName"); osd.ExtraNamespace.Add("geo", "http://a9.com/-/opensearch/extensions/geo/1.0/"); osd.ExtraNamespace.Add("time", "http://a9.com/-/opensearch/extensions/time/1.0/"); osd.ExtraNamespace.Add("dct", "http://purl.org/dc/terms/"); osd.ExtraNamespace.Add("t2", "http://www.terradue.com/opensearch"); osd.ExtraNamespace.Add("cor", "http://a9.com/-/opensearch/extensions/correlation/1.0/"); List <OpenSearchDescriptionUrl> urls = new List <OpenSearchDescriptionUrl>(); UriBuilder urlb = new UriBuilder(GetDescriptionBaseUrl()); OpenSearchDescriptionUrl url = new OpenSearchDescriptionUrl("application/opensearchdescription+xml", urlb.ToString(), "self", osd.ExtraNamespace); urls.Add(url); urlb = new UriBuilder(GetSearchBaseUrl("application/atom+xml")); NameValueCollection query = GetOpenSearchParameters("application/atom+xml"); NameValueCollection nvc = HttpUtility.ParseQueryString(urlb.Query); foreach (var key in nvc.AllKeys) { query.Set(key, nvc[key]); } foreach (var osee in OpenSearchEngine.Extensions.Values) { query.Set("format", osee.Identifier); string[] queryString = Array.ConvertAll(query.AllKeys, key => string.Format("{0}={1}", key, query[key])); urlb.Query = string.Join("&", queryString); url = new OpenSearchDescriptionUrl(osee.DiscoveryContentType, urlb.ToString(), "search", osd.ExtraNamespace); urls.Add(url); } osd.Url = urls.ToArray(); return(osd); }
public Terradue.OpenSearch.Schema.OpenSearchDescription GetOpenSearchDescription() { OpenSearchDescription osd = new OpenSearchDescription(); osd.ShortName = "SciHub"; 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(qcBaseUrl); urlb.Path += "/description"; OpenSearchDescriptionUrl url = new OpenSearchDescriptionUrl("application/opensearchdescription+xml", urlb.ToString(), "self"); urls.Add(url); urlb = new UriBuilder(qcBaseUrl); urlb.Path += "/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 = 0; urls.Add(url); osd.Url = urls.ToArray(); osd.DefaultUrl = url; return(osd); }
public object Get(DynamicRouteRequest request) { // Match the route request to validate the route requested Match match = Regex.Match(Request.GetPhysicalPath(), @"\/api\/(?<indexName>\w*)\/(?<routeId>\w*)\/(?<route>.*)"); DynamicOpenSearchRoute routeDefinition = null; // Load the dynamic route according to the index and the route id if (match.Success) { routeDefinition = LoadRoute(match.Groups["indexName"].Value, match.Groups["routeId"].Value); } else { throw new InvalidOperationException(string.Format("incorrect API route: {0}", Request.GetPhysicalPath())); } // Loads the type of the dynamic route IOpenSearchableElasticType type = ecf.GetOpenSearchableElasticTypeByName(match.Groups["indexName"].Value, routeDefinition.TypeName); if (type == null) { throw new InvalidTypeModelException(routeDefinition.TypeName, string.Format("Type '{0}' is not found in the type extensions. Check that plugins are loaded", routeDefinition.TypeName)); } // split the route defintion string[] defintionRouteSplitted = routeDefinition.RouteFromIndex.Split('/'); // check that requested route elements are respected string[] requestRouteSplitted = match.Groups["route"].Value.Split('/'); if (requestRouteSplitted.Count() != defintionRouteSplitted.Count()) { throw new InvalidOperationException(string.Format("Incorrect API request: {0}. Must match defintion: {1}", match.Groups["route"].Value, routeDefinition.RouteFromIndex)); } // build a parameters table with params defintion RouteParameter[] parameters = new RouteParameter[defintionRouteSplitted.Count()]; for (int i = 0; i < defintionRouteSplitted.Count(); i++) { string routeElement = defintionRouteSplitted[i]; if (!routeElement.StartsWith("{")) { parameters[i] = null; continue; } string parameter = routeElement.Trim(new char[] { '{', '}' }); if (string.IsNullOrEmpty(parameter)) { throw new InvalidOperationException(string.Format("API route defintion error: {0}. Empty parameter.", routeDefinition.RouteFromIndex)); } if (!routeDefinition.RouteParameters.ContainsKey(parameter)) { throw new InvalidOperationException(string.Format("API route defintion error: {0}. Undefined parameter: {1}", routeDefinition.RouteFromIndex, routeElement)); } parameters[i] = routeDefinition.RouteParameters[parameter]; } // Now from requested route rebuild the opensearch request UriBuilder url = new UriBuilder(ecf.RootWebConfig.AppSettings.Settings["baseUrl"].Value); url.Path += string.Format("/catalogue/{0}/{1}/search", match.Groups["indexName"].Value, routeDefinition.TypeName); NameValueCollection osParameters = HttpUtility.ParseQueryString(""); for (int i = 0; i < requestRouteSplitted.Count(); i++) { if (parameters[i] == null) { continue; } osParameters.Add(parameters[i].OpenSearchParameterId, requestRouteSplitted[i]); } List <string> mimeTypes = Request.AcceptTypes.ToList(); if (osParameters.AllKeys.Contains("enctype")) { mimeTypes.Add(osParameters["enctype"]); } OpenSearchDescription osd = type.GetProxyOpenSearchDescription(); OpenSearchDescriptionUrl osdUrl = OpenSearchFactory.GetOpenSearchUrlByTypeAndMaxParam(osd, mimeTypes, osParameters); osParameters = OpenSearchFactory.ReplaceTemplateByIdentifier(osParameters, osdUrl); osParameters.Add(Request.QueryString); return(OpenSearchService.Query(type, osParameters)); }
/// <summary> /// Get the specified request. /// </summary> /// <param name="request">Request.</param> public object Get(DataPackageSearchRequest request) { var context = TepWebContext.GetWebContext(PagePrivileges.EverybodyView); IOpenSearchResultCollection result = null; try { context.Open(); context.LogInfo(this, string.Format("/data/package/{{DataPackageId}}/search GET DataPackageId='{0}'", request.DataPackageId)); Terradue.Tep.DataPackage datapackage; try{ datapackage = DataPackage.FromIdentifier(context, request.DataPackageId); }catch (Exception) { if (request.Key != null) //or if public { context.AccessLevel = EntityAccessLevel.Administrator; datapackage = DataPackage.FromIdentifier(context, request.DataPackageId); if (request.Key != null && !request.Key.Equals(datapackage.AccessKey)) { throw new UnauthorizedAccessException(CustomErrorMessages.WRONG_ACCESSKEY); } } else { datapackage = DataPackage.FromIdentifier(context, request.DataPackageId); } } if (Request.QueryString != null && Request.QueryString["cache"] == "false") { datapackage.SetOpenSearchEngine(MasterCatalogue.GetNewOpenSearchEngine()); } else if (Request.QueryString != null && Request.QueryString["clearcache"] == "true") { datapackage.SetOpenSearchEngine(MasterCatalogue.ClearOpenSearchEngine()); } else { datapackage.SetOpenSearchEngine(MasterCatalogue.OpenSearchEngine); } OpenSearchEngine ose = MasterCatalogue.OpenSearchEngine; Type responseType = OpenSearchFactory.ResolveTypeFromRequest(HttpContext.Current.Request.QueryString, HttpContext.Current.Request.Headers, ose); result = ose.Query(datapackage, Request.QueryString, responseType); var openSearchDescription = datapackage.GetLocalOpenSearchDescription(); var uri_s = datapackage.GetSearchBaseUrl(); OpenSearchDescriptionUrl openSearchUrlByRel = OpenSearchFactory.GetOpenSearchUrlByRel(openSearchDescription, "self"); Uri uri_d; if (openSearchUrlByRel != null) { uri_d = new Uri(openSearchUrlByRel.Template); } else { uri_d = openSearchDescription.Originator; } if (uri_d != null) { result.Links.Add(new SyndicationLink(uri_d, "search", "OpenSearch Description link", "application/opensearchdescription+xml", 0)); } if (uri_s != null) { result.Links.Add(new SyndicationLink(uri_s, "self", "OpenSearch Search link", "application/atom+xml", 0)); } MasterCatalogue.ReplaceSelfLinksFormat(result, Request.QueryString); ActivityTep activity = new ActivityTep(context, datapackage, EntityOperationType.Search); activity.SetParam("items", result.TotalResults + ""); activity.Store(); context.Close(); } catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(new HttpResult(result.SerializeToString(), result.ContentType)); }