Пример #1
0
        //---------------------------------------------------------------------------------------------------------------------

        public virtual IOpenSearchable[] GetOpenSearchableArray()
        {
            List <IOpenSearchable> osResources = new List <IOpenSearchable>(Resources.Count);

            var settings = new OpenSearchableFactorySettings(ose);

            settings.MergeFilters = Terradue.Metadata.EarthObservation.Helpers.GeoTimeOpenSearchHelper.MergeGeoTimeFilters;

            foreach (RemoteResource res in Resources)
            {
                var entity = OpenSearchFactory.FindOpenSearchable(settings, new Uri(res.Location));
                osResources.Add(entity);
            }

            return(osResources.ToArray());
        }
Пример #2
0
        public virtual IOpenSearchable CreateOpenSearchable(IEnumerable <Uri> baseUrls, string queryFormatArg, OpenSearchEngine ose, IEnumerable <NetworkCredential> netCreds, OpenSearchableFactorySettings settings)
        {
            List <IOpenSearchable> entities = new List <IOpenSearchable>();

            for (int i = 0; i < baseUrls.Count(); i++)
            {
                var url = baseUrls.ElementAt(i);

                settings.Credentials = netCreds == null ? null : netCreds.ElementAt(i);

                if (string.IsNullOrEmpty(queryFormatArg))
                {
                    try
                    {
                        entities.Add(OpenSearchFactory.FindOpenSearchable(settings, url, null));
                    }
                    catch (Exception e)
                    {
                        throw e;
                    }
                }
                else
                {
                    var e = OpenSearchFactory.FindOpenSearchable(settings, url, ose.GetExtensionByExtensionName(queryFormatArg).DiscoveryContentType);
                    entities.Add(e);
                }
            }

            IOpenSearchable entity;
            OpenSearchableFactorySettings settings2 = new OpenSearchableFactorySettings(ose);

            if (entities.Count > 1)
            {
                entity = new MultiGenericOpenSearchable(entities, settings2);
            }
            else
            {
                entity = entities[0];
            }

            return(entity);
        }
Пример #3
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);
        }
Пример #4
0
        public override IOpenSearchable CreateOpenSearchable(IEnumerable <Uri> baseUrls, string queryFormatArg, OpenSearchEngine ose, IEnumerable <NetworkCredential> netCreds, OpenSearchableFactorySettings settings)
        {
            List <IOpenSearchable> entities = new List <IOpenSearchable>();

            IOpenSearchEngineExtension ext;

            if (string.IsNullOrEmpty(queryFormatArg))
            {
                ext = ose.GetExtensionByExtensionName("atom");
            }
            else
            {
                ext = ose.GetExtensionByExtensionName(queryFormatArg);
            }

            for (int i = 0; i < baseUrls.Count(); i++)
            {
                var url = baseUrls.ElementAt(i);

                settings.Credentials = netCreds == null ? null : netCreds.ElementAt(i);

                IOpenSearchable e = null;
                // QC Sentinel1 case
                if (url.Host == "qc.sentinel1.eo.esa.int")
                {
                    log.DebugFormat("QC Sentinel1 source. Trying to get the earthobservation profile");
                    e = new Sentinel1QcOpenSearchable(url, settings.OpenSearchEngine);
                    entities.Add(e);
                    continue;
                }
                // USGS case
                if (url.Host == "earthexplorer.usgs.gov")
                {
                    log.DebugFormat("Usgs source. Trying to get the earthobservation profile");

                    // usgsOpenSearchable
                    e = new Terradue.OpenSearch.Usgs.UsgsOpenSearchable(url, settings);
                    entities.Add(e);
                    continue;
                }
                e = OpenSearchFactory.FindOpenSearchable(settings, url, ext.DiscoveryContentType);
                if (!e.DefaultMimeType.Contains("profile=http://earth.esa.int/eop"))
                {
                    try {
                        e = OpenSearchFactory.FindOpenSearchable(settings, url, "application/atom+xml; profile=http://earth.esa.int/eop/2.1");
                    } catch (InvalidOperationException) {
                        e = OpenSearchFactory.FindOpenSearchable(settings, url, "application/atom+xml");
                    }
                    if (!e.DefaultMimeType.Contains("xml"))
                    {
                        throw new InvalidOperationException("No Url in the OpenSearch Description Document that could fit the EOP data model");
                    }
                }
                // Fedeo case
                if (url.Host == "fedeo.esa.int" && e.DefaultMimeType == "application/atom+xml" && e is Terradue.OpenSearch.GenericOpenSearchable)
                {
                    log.DebugFormat("Fedeo source. Trying to get the earthobservation profile");
                    e = FedeoOpenSearchable.CreateFrom(url, settings.OpenSearchEngine);
                }
                // Cwic case
                if (url.Host == "cwic.wgiss.ceos.org" && e.DefaultMimeType == "application/atom+xml" && e is Terradue.OpenSearch.GenericOpenSearchable)
                {
                    log.DebugFormat("Cwic source. Trying to get the earthobservation profile");
                    e = CwicOpenSearchable.CreateFrom((Terradue.OpenSearch.GenericOpenSearchable)e, settings.OpenSearchEngine);
                }



                entities.Add(e);
            }

            IOpenSearchable entity;

            OpenSearchableFactorySettings settings2 = new OpenSearchableFactorySettings(ose);

            if (entities.Count > 1)
            {
                entity = new MultiGenericOpenSearchable(entities, settings2);
            }
            else
            {
                entity = entities[0];
            }

            return(entity);
        }
Пример #5
0
        /// <summary>
        /// Get the specified request.
        /// </summary>
        /// <param name="request">Request.</param>
        /// /apps/{identifier}/search GET
        public object Get(ThematicAppSearchRequestTep request)
        {
            IfyWebContext context = TepWebContext.GetWebContext(PagePrivileges.EverybodyView);

            context.Open();
            context.LogInfo(this, string.Format("/apps/search GET -- cache = {0}", request.cache));

            IOpenSearchResultCollection result;
            OpenSearchEngine            ose = MasterCatalogue.OpenSearchEngine;
            HttpRequest httpRequest         = HttpContext.Current.Request;
            Type        responseType        = OpenSearchFactory.ResolveTypeFromRequest(httpRequest.QueryString, httpRequest.Headers, ose);

            //first we get the communities the user can see
            var communities = new EntityList <ThematicCommunity>(context);

            if (context.UserId == 0)
            {
                communities.SetFilter("Kind", (int)DomainKind.Public + "");
            }
            else
            {
                communities.SetFilter("Kind", (int)DomainKind.Public + "," + (int)DomainKind.Hidden + "," + (int)DomainKind.Private);
                communities.AddSort("Kind", SortDirection.Ascending);
            }
            communities.Load();

            if (request.cache)
            {
                List <int> ids = new List <int>();
                foreach (var c in communities)
                {
                    if (c.IsUserJoined(context.UserId))
                    {
                        ids.Add(c.Id);
                    }
                }

                EntityList <ThematicApplicationCached> appsCached = new EntityList <ThematicApplicationCached>(context);
                var filterValues = new List <object>();
                filterValues.Add(string.Join(",", ids));
                filterValues.Add(SpecialSearchValue.Null);
                appsCached.SetFilter("DomainId", filterValues.ToArray());
                appsCached.SetGroupFilter("UId");
                appsCached.AddSort("LastUpdate", SortDirection.Descending);

                result = ose.Query(appsCached, httpRequest.QueryString, responseType);
                OpenSearchFactory.ReplaceOpenSearchDescriptionLinks(appsCached, result);
            }
            else
            {
                List <Terradue.OpenSearch.IOpenSearchable> osentities = new List <Terradue.OpenSearch.IOpenSearchable>();

                var settings     = MasterCatalogue.OpenSearchFactorySettings;
                var specsettings = (OpenSearchableFactorySettings)settings.Clone();
                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);
                    }
                }

                //get apps link from the communities the user can see
                foreach (var community in communities.Items)
                {
                    if (community.IsUserJoined(context.UserId))
                    {
                        var app = community.GetThematicApplication();
                        if (app != null)
                        {
                            app.LoadItems();
                            foreach (var item in app.Items)
                            {
                                if (!string.IsNullOrEmpty(item.Location))
                                {
                                    try {
                                        var ios = OpenSearchFactory.FindOpenSearchable(specsettings, new OpenSearchUrl(item.Location));
                                        osentities.Add(ios);
                                        context.LogDebug(this, string.Format("Apps search -- Add '{0}'", item.Location));
                                    } catch (Exception e) {
                                        context.LogError(this, e.Message, e);
                                    }
                                }
                            }
                        }
                    }
                }

                //get thematic apps without any domain
                var apps = new EntityList <ThematicApplication>(context);
                apps.SetFilter("DomainId", SpecialSearchValue.Null);
                apps.SetFilter("Kind", ThematicApplication.KINDRESOURCESETAPPS + "");
                apps.Load();
                foreach (var app in apps)
                {
                    app.LoadItems();
                    foreach (var item in app.Items)
                    {
                        if (!string.IsNullOrEmpty(item.Location))
                        {
                            try {
                                var ios = OpenSearchFactory.FindOpenSearchable(specsettings, new OpenSearchUrl(item.Location));
                                osentities.Add(ios);
                                context.LogDebug(this, string.Format("Apps search -- Add '{0}'", item.Location));
                            } catch (Exception e) {
                                context.LogError(this, e.Message, e);
                            }
                        }
                    }
                }

                MultiGenericOpenSearchable multiOSE = new MultiGenericOpenSearchable(osentities, specsettings);
                result = ose.Query(multiOSE, httpRequest.QueryString, responseType);
            }

            var sresult = result.SerializeToString();

            //replace usernames in apps
            try {
                var user = UserTep.FromId(context, context.UserId);
                sresult = sresult.Replace("${USERNAME}", user.Username);
                sresult = sresult.Replace("${T2USERNAME}", user.TerradueCloudUsername);
                sresult = sresult.Replace("${T2APIKEY}", user.GetSessionApiKey());
            } catch (Exception e) {
                context.LogError(this, e.Message, e);
            }

            if (!string.IsNullOrEmpty(httpRequest.QueryString["uid"]))
            {
                try{
                    var user = UserTep.FromId(context, context.UserId);
                    EventUserLoggerTep eventLogger = new EventUserLoggerTep(context);
                    eventLogger.GetLogEvent(user, "portal_user_access_workspace", "User workspace access").ContinueWith <Event>(
                        usrevent => {
                        if (usrevent != null)
                        {
                            var callId = httpRequest.QueryString["uid"];
                            usrevent.Result.Item.Properties.Add("app_id", callId);
                            EventFactory.Log(context, usrevent.Result);
                        }
                        return(usrevent.Result);
                    }
                        );
                }catch (Exception) {}
            }

            context.Close();
            return(new HttpResult(sresult, result.ContentType));
        }
Пример #6
0
        public object Get(ThematicAppCurrentUserSearchRequestTep request)
        {
            IfyWebContext context = TepWebContext.GetWebContext(PagePrivileges.EverybodyView);

            context.Open();
            context.LogInfo(this, string.Format("/user/current/apps/search GET"));

            IOpenSearchResultCollection result;
            OpenSearchEngine            ose = MasterCatalogue.OpenSearchEngine;
            var  httpRequest  = HttpContext.Current.Request;
            Type responseType = OpenSearchFactory.ResolveTypeFromRequest(httpRequest.QueryString, httpRequest.Headers, ose);
            List <Terradue.OpenSearch.IOpenSearchable> osentities = new List <Terradue.OpenSearch.IOpenSearchable>();
            var settings = MasterCatalogue.OpenSearchFactorySettings;
            OpenSearchableFactorySettings specsettings = (OpenSearchableFactorySettings)settings.Clone();

            UserTep user = null;

            if (context.UserId != 0)
            {
                user = UserTep.FromId(context, context.UserId);
                if (request.cache)
                {
                    var domain = user.GetPrivateDomain();
                    EntityList <ThematicApplicationCached> appsCached = new EntityList <ThematicApplicationCached>(context);
                    appsCached.SetFilter("DomainId", domain.Id);
                    appsCached.AddSort("LastUpdate", SortDirection.Descending);

                    result = ose.Query(appsCached, Request.QueryString, responseType);
                    OpenSearchFactory.ReplaceOpenSearchDescriptionLinks(appsCached, result);
                }
                else
                {
                    //get user private thematic app
                    var apikey   = user.GetSessionApiKey();
                    var t2userid = user.TerradueCloudUsername;
                    if (!string.IsNullOrEmpty(apikey))
                    {
                        specsettings.Credentials = new System.Net.NetworkCredential(t2userid, apikey);
                    }
                    var app = user.GetPrivateThematicApp();
                    if (app != null)
                    {
                        foreach (var item in app.Items)
                        {
                            if (!string.IsNullOrEmpty(item.Location))
                            {
                                try {
                                    var sgOs = OpenSearchFactory.FindOpenSearchable(specsettings, new OpenSearchUrl(item.Location));
                                    osentities.Add(sgOs);
                                    context.LogDebug(this, string.Format("Apps search -- Add '{0}'", item.Location));
                                } catch (Exception e) {
                                    context.LogError(this, e.Message, e);
                                }
                            }
                        }
                    }
                    MultiGenericOpenSearchable multiOSE = new MultiGenericOpenSearchable(osentities, specsettings);
                    result = ose.Query(multiOSE, Request.QueryString, responseType);
                }
            }
            else
            {
                result = ose.Query(new MultiGenericOpenSearchable(osentities, specsettings), Request.QueryString, responseType);
            }

            string sresult = result.SerializeToString();

            //replace usernames in apps
            if (user != null)
            {
                try {
                    sresult = sresult.Replace("${USERNAME}", user.Username);
                    sresult = sresult.Replace("${T2USERNAME}", user.TerradueCloudUsername);
                    sresult = sresult.Replace("${T2APIKEY}", user.GetSessionApiKey());
                } catch (Exception e) {
                    context.LogError(this, e.Message, e);
                }
            }

            context.Close();

            return(new HttpResult(sresult, result.ContentType));
        }
Пример #7
0
        public override IOpenSearchable[] GetOpenSearchableArray()
        {
            List <IOpenSearchable> osResources = new List <IOpenSearchable>(Resources.Count);

            var settings = MasterCatalogue.OpenSearchFactorySettings;

            string apikey   = null;
            string t2userid = null;

            if (context.UserId != 0)
            {
                var user = UserTep.FromId(context, context.UserId);
                apikey   = user.GetSessionApiKey();
                t2userid = user.TerradueCloudUsername;
            }

            foreach (RemoteResource res in Resources)
            {
                OpenSearchableFactorySettings specsettings = (OpenSearchableFactorySettings)settings.Clone();
                // For Terradue resources, use the API key
                if (res.Location.StartsWith(context.GetConfigValue("catalog-baseurl")) && !string.IsNullOrEmpty(apikey))
                {
                    specsettings.Credentials = new System.Net.NetworkCredential(t2userid, apikey);
                }
                try {
                    IOpenSearchable entity = null;
                    try {
                        entity = OpenSearchFactory.FindOpenSearchable(specsettings, new Uri(res.Location), "application/atom+xml");
                    }catch (Exception e) {
                        if (!res.Location.StartsWith(context.GetConfigValue("catalog-baseurl")))
                        {
                            try {
                                entity = OpenSearchFactory.FindOpenSearchable(specsettings, new Uri(res.Location));
                            } catch (Exception ex) {
                                var feed = new AtomFeed();
                                feed.Id = "Exception";
                                feed.ElementExtensions.Add(
                                    new SyndicationElementExtension("exception", "", new ExceptionMessage {
                                    Message = ex.Message, Source = res.Location, HelpLink = ex.HelpLink
                                })
                                    );
                                entity = new ExceptionOpensearchable(feed);
                            }
                        }
                        else
                        {
                            var feed = new AtomFeed();
                            feed.Id = "Exception";
                            feed.ElementExtensions.Add(
                                new SyndicationElementExtension("exception", "", new ExceptionMessage {
                                Message = e.Message, Source = res.Location, HelpLink = e.HelpLink
                            })
                                );
                            entity = new ExceptionOpensearchable(feed);
                        }
                    }
                    if (entity != null)
                    {
                        osResources.Add(entity);
                    }
                }
                catch (Exception e)
                {
                    context.LogError(this, e.Message);
                }
            }

            return(osResources.ToArray());
        }