Ejemplo n.º 1
0
        public void TestFedeo()
        {
            XmlSerializer ser = new XmlSerializer(typeof(OpenSearchDescription));
            var osd = (OpenSearchDescription)ser.Deserialize(XmlReader.Create(new FileStream("../Samples/fedeo-osdd.xml", FileMode.Open, FileAccess.Read)));

            GenericOpenSearchable os = new GenericOpenSearchable(osd, new OpenSearchEngine());

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

            var url = new OpenSearchUrl("http://fedeo.esa.int/opensearch/request/?httpAccept=application/atom%2Bxml&parentIdentifier=urn:eop:DLR:EOWEB:Geohazard.Supersite.TerraSAR-X_SSC&startDate=2014-01-01T00:00:00Z&endDate=2015-04-20T00:00:00Z&recordSchema=om");
            NameValueCollection parameters = new NameValueCollection();
            parameters.Set("maximumRecords", "1");

            NameValueCollection nvc;
            if (url != null)
                nvc = HttpUtility.ParseQueryString(url.Query);
            else
                nvc = new NameValueCollection();

            parameters.AllKeys.SingleOrDefault(k =>
            {
                nvc.Set(k, parameters[k]);
                return false;
            });

            var request = OpenSearchRequest.Create(os, os.GetQuerySettings(ose), nvc);
        }
Ejemplo n.º 2
0
        //        [Test]
        public void TestAtom1()
        {
            AddinManager.Initialize();
            AddinManager.Registry.Update(null);

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

            GenericOpenSearchable entity = new GenericOpenSearchable(new OpenSearchUrl("https://ngeopro.magellium.fr/remote/S1_SAR_IW_SINGLE_POL/description"), ose);
            NameValueCollection nvc = new NameValueCollection();

            var osr = ose.Query(entity, nvc, "atom");
        }
Ejemplo n.º 3
0
        public void GenericOpenSearchableTest() {

            AddinManager.Initialize();
            AddinManager.Registry.Update(null);

            OpenSearchEngine ose = new OpenSearchEngine();

            ose.LoadPlugins();
            OpenSearchUrl url = new OpenSearchUrl("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");
            IOpenSearchable entity = new GenericOpenSearchable(url, ose);

            var osr = ose.Query(entity, new System.Collections.Specialized.NameValueCollection(), "rdf");

            //Assert.AreEqual(15, osr.TotalResults);
            Assert.That(osr.Links.Count > 0);

        }
Ejemplo n.º 4
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 void DiscoverDescription()
        {
            AddinManager.Initialize();
            AddinManager.Registry.Update(null);

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

            GenericOpenSearchable entity = new GenericOpenSearchable(new OpenSearchUrl("https://catalog.terradue.com/noa-cosmoskymed/search?uid=CSKS4_SCS_B_HI_09_HH_RA_SF_20150911040406_20150911040413&format=json"), ose);

            var results = ose.Query(entity, new System.Collections.Specialized.NameValueCollection(), "json");
            FeatureCollectionResult col = (FeatureCollectionResult)results;

            var properties = col.FeatureResults.First().Properties;

            Assert.That(col.Features[0].Geometry != null);
            Assert.That(!string.IsNullOrEmpty(col.Features[0].ToWkt()));

            results = ose.Query(entity, new System.Collections.Specialized.NameValueCollection(), "atom");
        }
Ejemplo n.º 6
0
        public object Post(TypeImportRequest request)
        {
            OpenSearchEngine ose = new OpenSearchEngine();

            ose.LoadPlugins();
            ose.DefaultTimeOut = 60000;

            OpenSearchUrl url = new OpenSearchUrl(request.url);

            IOpenSearchable entity = new GenericOpenSearchable(url, ose);

            IOpenSearchableElasticType type = ecf.GetOpenSearchableElasticTypeByNameOrDefault(request.IndexName, request.TypeName);

            IOpenSearchResultCollection osres = ose.Query(entity, new NameValueCollection());

            OpenSearchFactory.RemoveLinksByRel(ref osres, "alternate");
            OpenSearchFactory.RemoveLinksByRel(ref osres, "via");
            OpenSearchFactory.RemoveLinksByRel(ref osres, "self");
            OpenSearchFactory.RemoveLinksByRel(ref osres, "search");

            IElasticCollection documents = type.FromOpenSearchResultCollection(osres);

            BulkRequest bulkRequest = new BulkRequest()
            {
                Refresh     = true,
                Consistency = Consistency.One,
                Index       = request.IndexName
            };

            foreach (var doc in documents.Items)
            {
                bulkRequest.Operations.Add(new BulkIndexOperation <IElasticItem>((IElasticItem)doc)
                {
                    Id = doc.Id
                });
            }

            var response = client.Bulk(bulkRequest);

            return(response);
        }
Ejemplo n.º 7
0
        public object Get(WpsJobProductDescriptionRequestTep request)
        {
            var        context = TepWebContext.GetWebContext(PagePrivileges.EverybodyView);
            HttpResult result  = null;

            try {
                context.Open();
                context.LogInfo(this, string.Format("/job/wps/{0}/products/description GET", request.JobId));

                WpsJob wpsjob = WpsJob.FromIdentifier(context, request.JobId);

                OpenSearchEngine ose         = MasterCatalogue.OpenSearchEngine;
                HttpRequest      httpRequest = HttpContext.Current.Request;

                OpenSearchDescription osd;

                if (CatalogueFactory.IsCatalogUrl(new Uri(wpsjob.StatusLocation)))
                {
                    var settings = MasterCatalogue.OpenSearchFactorySettings;
                    OpenSearchableFactorySettings specsettings = (OpenSearchableFactorySettings)settings.Clone();

                    //get credentials from current user
                    if (context.UserId != 0)
                    {
                        var user     = UserTep.FromId(context, context.UserId);
                        var apikey   = user.GetSessionApiKey();
                        var t2userid = user.TerradueCloudUsername;
                        if (!string.IsNullOrEmpty(apikey))
                        {
                            specsettings.Credentials = new System.Net.NetworkCredential(t2userid, apikey);
                        }
                    }
                    GenericOpenSearchable urlToShare = new GenericOpenSearchable(new OpenSearchUrl(wpsjob.StatusLocation), specsettings);
                    osd = urlToShare.GetOpenSearchDescription();
                    var oldUri = new UriBuilder(osd.DefaultUrl.Template);
                    var newUri = new UriBuilder(context.BaseUrl + "/job/wps/" + wpsjob.Identifier + "/products/search");
                    newUri.Query            = oldUri.Query.TrimStart("?".ToCharArray());
                    osd.DefaultUrl.Template = HttpUtility.UrlDecode(newUri.Uri.AbsoluteUri);
                    foreach (var url in osd.Url)
                    {
                        oldUri       = new UriBuilder(url.Template);
                        newUri       = new UriBuilder(context.BaseUrl + "/job/wps/" + wpsjob.Identifier + "/products/search");
                        newUri.Query = oldUri.Query.TrimStart("?".ToCharArray());
                        url.Template = HttpUtility.UrlDecode(newUri.Uri.AbsoluteUri);
                    }
                }
                else
                {
                    WpsJobProductOpenSearchable wpsjobProductOs = new WpsJobProductOpenSearchable(wpsjob, context);
                    osd = wpsjobProductOs.GetProxyOpenSearchDescription();
                }

                result = new HttpResult(osd, "application/opensearchdescription+xml");

                context.Close();
            } catch (Exception e) {
                context.LogError(this, e.Message, e);
                context.Close();
                throw e;
            }
            return(result);
        }
Ejemplo n.º 8
0
        public object Get(WpsJobProductSearchRequestTep request)
        {
            var        context = TepWebContext.GetWebContext(PagePrivileges.EverybodyView);
            HttpResult result  = null;

            try {
                context.Open();
                context.LogInfo(this, string.Format("/job/wps/{0}/products/search GET", request.JobId));

                WpsJob wpsjob = null;

                try {
                    wpsjob = WpsJob.FromIdentifier(context, request.JobId);
                } catch (Exception e) {
                    if (request.Key != null)                     //or if public
                    {
                        context.AccessLevel = EntityAccessLevel.Administrator;
                        wpsjob = WpsJob.FromIdentifier(context, request.JobId);
                        if (request.Key != null && !request.Key.Equals(wpsjob.AccessKey))
                        {
                            throw new UnauthorizedAccessException(CustomErrorMessages.WRONG_ACCESSKEY);
                        }
                    }
                    else
                    {
                        throw e;
                    }
                }

                OpenSearchEngine ose         = MasterCatalogue.OpenSearchEngine;
                HttpRequest      httpRequest = HttpContext.Current.Request;
                Type             type        = OpenSearchFactory.ResolveTypeFromRequest(httpRequest.QueryString, httpRequest.Headers, ose);
                var nvc = httpRequest.QueryString;

                if (CatalogueFactory.IsCatalogUrl(new Uri(wpsjob.StatusLocation)))
                {
                    var settings = MasterCatalogue.OpenSearchFactorySettings;
                    OpenSearchableFactorySettings specsettings = (OpenSearchableFactorySettings)settings.Clone();

                    //get credentials from current user
                    if (context.UserId != 0)
                    {
                        var user     = UserTep.FromId(context, context.UserId);
                        var apikey   = user.GetSessionApiKey();
                        var t2userid = user.TerradueCloudUsername;
                        if (!string.IsNullOrEmpty(apikey))
                        {
                            specsettings.Credentials = new System.Net.NetworkCredential(t2userid, apikey);
                        }
                    }
                    GenericOpenSearchable urlToShare = new GenericOpenSearchable(new OpenSearchUrl(wpsjob.StatusLocation), specsettings);
                    var res = ose.Query(urlToShare, nvc, type);
                    result = new HttpResult(res.SerializeToString(), res.ContentType);
                }
                else
                {
                    WpsJobProductOpenSearchable wpsjobProductOs = new WpsJobProductOpenSearchable(wpsjob, context);

                    //var nvc = wpsjobUrl.GetParameters ();
                    var res = ose.Query(wpsjobProductOs, nvc, type);
                    OpenSearchFactory.ReplaceSelfLinks(wpsjobProductOs, httpRequest.QueryString, res, EntrySelfLinkTemplate);
                    OpenSearchFactory.ReplaceOpenSearchDescriptionLinks(wpsjobProductOs, res);
                    result = new HttpResult(res.SerializeToString(), res.ContentType);
                }

                context.Close();
            } catch (Exception e) {
                context.LogError(this, e.Message, e);
                context.Close();
                throw e;
            }
            return(result);
        }
        public static CwicOpenSearchable CreateFrom(GenericOpenSearchable e, OpenSearchEngine ose)
        {
            UrlBasedOpenSearchableFactory factory = new UrlBasedOpenSearchableFactory(new OpenSearchableFactorySettings(ose));

            return(new CwicOpenSearchable(e.GetOpenSearchDescription(), factory));
        }
Ejemplo n.º 10
0
        public object Get(ShareGetRequestTep request)
        {
            var context = TepWebContext.GetWebContext(PagePrivileges.EverybodyView);

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

            var AppSettings = System.Configuration.ConfigurationManager.AppSettings;

            var redirect = new UriBuilder(context.BaseUrl);

            redirect.Path = "geobrowser";
            string redirectUrl = redirect.Uri.AbsoluteUri + (!string.IsNullOrEmpty(request.id) ? "/?id=" + request.id : "/") + "#!";

            var   pathUrl = new Uri(request.url).LocalPath.Replace(new Uri(context.BaseUrl).LocalPath, "");
            Match match   = Regex.Match(pathUrl, @"(\/?.*)search(\/?.*)");

            if (match.Success)
            {
                var resultType = match.Groups[1].Value.Trim('/');
                if (resultType.Equals(EntityType.GetEntityType(typeof(Series)).Keyword))
                {
                    redirectUrl += "resultType=" + EntityType.GetEntityType(typeof(Series)).Keyword;
                }
                else if (resultType.Equals(EntityType.GetEntityType(typeof(DataPackage)).Keyword))
                {
                    redirectUrl += "resultType=" + EntityType.GetEntityType(typeof(DataPackage)).Keyword;
                }
                else if (resultType.Contains(EntityType.GetEntityType(typeof(DataPackage)).Keyword))
                {
                    redirectUrl += "resultType=" + "data";//in this case it is a search (over a data package) so we use data keyword
                }
                else if (resultType.Equals(EntityType.GetEntityType(typeof(WpsJob)).Keyword))
                {
                    redirectUrl += "resultType=" + EntityType.GetEntityType(typeof(WpsJob)).Keyword;
                }
                else if (resultType.Equals(EntityType.GetEntityType(typeof(WpsProvider)).Keyword))
                {
                    redirectUrl += "resultType=" + EntityType.GetEntityType(typeof(WpsProvider)).Keyword;
                }
                else if (resultType.Equals(EntityType.GetEntityType(typeof(WpsProcessOffering)).Keyword))
                {
                    redirectUrl += "resultType=" + EntityType.GetEntityType(typeof(WpsProcessOffering)).Keyword;
                }
                else
                {
                    if (CatalogueFactory.IsCatalogUrl(new Uri(request.url)) || request.url.StartsWith(AppSettings["RecastBaseUrl"]))
                    {
                        redirectUrl += "resultType=" + "data";
                    }
                    else
                    {
                        try {
                            var settings = MasterCatalogue.OpenSearchFactorySettings;
                            var os       = new GenericOpenSearchable(new OpenSearchUrl(request.url), settings);
                            redirectUrl += "resultType=" + "data";
                        } catch (Exception) {
                            redirectUrl += "resultType=" + "na";
                        }
                    }
                }
                redirectUrl += "&url=" + HttpUtility.UrlEncode(request.url);
            }
            else
            {
                context.LogError(this, "Wrong format shared url");
                throw new Exception("Wrong format shared url");
            }

            var        keyword    = match.Groups[1].Value.StartsWith("/") ? match.Groups[1].Value.Substring(1) : match.Groups[1].Value;
            EntityType entityType = EntityType.GetEntityTypeFromKeyword(keyword);

            context.Close();

            return(new HttpResult()
            {
                StatusCode = System.Net.HttpStatusCode.Redirect, Headers = { { HttpHeaders.Location, redirectUrl } }
            });
        }
 public static CwicOpenSearchable CreateFrom(GenericOpenSearchable e, OpenSearchEngine ose)
 {
     return new CwicOpenSearchable(e.GetOpenSearchDescription(), ose);
 }