Exemple #1
0
        public object Get(ActivitySearchRequestTep request)
        {
            var context = TepWebContext.GetWebContext(PagePrivileges.UserView);

            context.AccessLevel = EntityAccessLevel.Administrator;
            context.Open();
            context.LogInfo(this, string.Format("/activity/search GET nologin='******'", request.nologin));

            EntityList <ActivityTep> activities = new EntityList <ActivityTep>(context);

            activities.AddSort("CreationTime", SortDirection.Descending);

            // Load the complete request
            HttpRequest      httpRequest = HttpContext.Current.Request;
            OpenSearchEngine ose         = MasterCatalogue.OpenSearchEngine;

            Type responseType = OpenSearchFactory.ResolveTypeFromRequest(httpRequest.QueryString, httpRequest.Headers, ose);
            IOpenSearchResultCollection osr = ose.Query(activities, httpRequest.QueryString, responseType);

            activities.Identifier = "activity";

            OpenSearchFactory.ReplaceOpenSearchDescriptionLinks(activities, osr);

            context.Close();
            return(new HttpResult(osr.SerializeToString(), osr.ContentType));
        }
Exemple #2
0
        public object Get(CommunitySearchRequestTep request)
        {
            var context = TepWebContext.GetWebContext(PagePrivileges.EverybodyView);

            context.Open();
            context.LogInfo(this, string.Format("/community/search GET"));

            CommunityCollection domains = new CommunityCollection(context);

            domains.UserStatus = Request.QueryString != null ? Request.QueryString["status"] : null;
            domains.SetFilter("Kind", (int)DomainKind.Public + "," + (int)DomainKind.Private + "," + (int)DomainKind.Hidden);

            // Load the complete request
            HttpRequest      httpRequest  = HttpContext.Current.Request;
            OpenSearchEngine ose          = MasterCatalogue.OpenSearchEngine;
            Type             responseType = OpenSearchFactory.ResolveTypeFromRequest(httpRequest.QueryString, httpRequest.Headers, ose);

            // the opensearch cache system uses the query parameters
            // we add to the parameters the filters added to the load in order to avoir wrong cache
            // we use 't2-' in order to not interfer with possibly used query parameters
            var qs = new NameValueCollection(Request.QueryString);

            foreach (var filter in domains.FilterValues)
            {
                qs.Add("t2-" + filter.Key.FieldName, filter.Value.ToString());
            }

            IOpenSearchResultCollection osr = ose.Query(domains, httpRequest.QueryString, responseType);

            OpenSearchFactory.ReplaceOpenSearchDescriptionLinks(domains, osr);

            context.Close();
            return(new HttpResult(osr.SerializeToString(), osr.ContentType));
        }
Exemple #3
0
        public object Get(DomainSearchRequestTep request)
        {
            var context = TepWebContext.GetWebContext(PagePrivileges.EverybodyView);

            context.Open();
            context.LogInfo(this, string.Format("/domain/search GET"));

            EntityList <Domain> domains = new EntityList <Domain> (context);

            domains.Load();

            // Load the complete request
            HttpRequest httpRequest = HttpContext.Current.Request;

            OpenSearchEngine ose = MasterCatalogue.OpenSearchEngine;

            string format;

            if (Request.QueryString ["format"] == null)
            {
                format = "atom";
            }
            else
            {
                format = Request.QueryString ["format"];
            }

            Type responseType = OpenSearchFactory.ResolveTypeFromRequest(httpRequest.QueryString, httpRequest.Headers, ose);
            IOpenSearchResultCollection osr = ose.Query(domains, httpRequest.QueryString, responseType);

            OpenSearchFactory.ReplaceOpenSearchDescriptionLinks(domains, osr);

            context.Close();
            return(new HttpResult(osr.SerializeToString(), osr.ContentType));
        }
Exemple #4
0
        public object Get(UserSearchRequest request)
        {
            var context = TepWebContext.GetWebContext(PagePrivileges.UserView);

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

            EntityList <UserTep> users = new EntityList <UserTep> (context);

            users.AddSort("Identifier", SortDirection.Ascending);

            // Load the complete request
            HttpRequest httpRequest = HttpContext.Current.Request;

            OpenSearchEngine ose = MasterCatalogue.OpenSearchEngine;

            string format;

            if (Request.QueryString ["format"] == null)
            {
                format = "atom";
            }
            else
            {
                format = Request.QueryString ["format"];
            }

            Type responseType = OpenSearchFactory.ResolveTypeFromRequest(httpRequest.QueryString, httpRequest.Headers, ose);
            IOpenSearchResultCollection osr = ose.Query(users, httpRequest.QueryString, responseType);

            OpenSearchFactory.ReplaceOpenSearchDescriptionLinks(users, osr);

            context.Close();
            return(new HttpResult(osr.SerializeToString(), osr.ContentType));
        }
        public static void ProxyOpenSearchResult(IOpenSearchable entity, OpenSearchRequest request, IOpenSearchResultCollection osr)
        {
            if (!(entity is IProxiedOpenSearchable))
            {
                return;
            }

            OpenSearchFactory.ReplaceSelfLinks(entity, request, osr, Terradue.Metadata.EarthObservation.OpenSearch.Helpers.OpenSearchParametersHelper.EntrySelfLinkTemplate);
            OpenSearchFactory.ReplaceOpenSearchDescriptionLinks(entity, osr);
        }
Exemple #6
0
        private IOpenSearchResultCollection GetActivityResultCollection(EntityList <Activity> activities)
        {
            // Load the complete request
            HttpRequest      httpRequest = HttpContext.Current.Request;
            OpenSearchEngine ose         = MasterCatalogue.OpenSearchEngine;

            Type responseType = OpenSearchFactory.ResolveTypeFromRequest(httpRequest.QueryString, httpRequest.Headers, ose);
            IOpenSearchResultCollection osr = ose.Query(activities, httpRequest.QueryString, responseType);

            OpenSearchFactory.ReplaceOpenSearchDescriptionLinks(activities, osr);

            return(osr);
        }
Exemple #7
0
        public object Put(WpsJobUpdateRequestTep request)
        {
            var context = TepWebContext.GetWebContext(PagePrivileges.UserView);

            context.Open();
            context.LogInfo(this, string.Format("/job/wps PUT Id='{0}'", request.Id));

            WpsJob job = WpsJob.FromIdentifier(context, request.Identifier);

            try{
                job.Name = request.Name;
                job.Store();
                context.LogDebug(this, string.Format("WpsJob '{0}' updated", job.Name));
            }catch (Exception e) {
                throw e;
            }

            EntityList <WpsJob> wpsjobs = new EntityList <WpsJob>(context);

            wpsjobs.ItemVisibility = EntityItemVisibility.OwnedOnly;
            wpsjobs.Load();

            OpenSearchEngine ose = MasterCatalogue.OpenSearchEngine;

            string format;

            if (Request.QueryString["format"] == null)
            {
                format = "atom";
            }
            else
            {
                format = Request.QueryString["format"];
            }

            NameValueCollection nvc = new NameValueCollection();

            nvc.Add("id", job.Identifier);

            Type responseType = OpenSearchFactory.ResolveTypeFromRequest(HttpContext.Current.Request.QueryString, HttpContext.Current.Request.Headers, ose);
            IOpenSearchResultCollection osr = ose.Query(wpsjobs, nvc, responseType);

            OpenSearchFactory.ReplaceOpenSearchDescriptionLinks(wpsjobs, osr);

            context.Close();
            return(new HttpResult(osr.SerializeToString(), osr.ContentType));
        }
Exemple #8
0
        public object Get(WpsJobSearchRequestTep request)
        {
            var context = TepWebContext.GetWebContext(PagePrivileges.EverybodyView);

            context.Open();
            context.LogInfo(this, string.Format("/job/wps/search GET"));

            EntityList <WpsJob> wpsjobs = new EntityList <WpsJob>(context);

            wpsjobs.AddSort("Id", SortDirection.Descending);
            wpsjobs.IncludeOwnerFieldsInSearch = true;

            // Load the complete request
            HttpRequest httpRequest = HttpContext.Current.Request;
            var         qs          = new NameValueCollection(httpRequest.QueryString);

            OpenSearchEngine ose = MasterCatalogue.OpenSearchEngine;

            if (qs["visibility"] != null && qs["visibility"] != "all")
            {
                wpsjobs.AccessLevel = EntityAccessLevel.Privilege;
            }

            if (!string.IsNullOrEmpty(qs["key"]))
            {
                try{
                    UserTep user = UserTep.FromApiKey(context, qs["key"]);
                    wpsjobs.UserId      = user.Id;
                    context.AccessLevel = EntityAccessLevel.Privilege;
                }catch (Exception) {}
            }

            if (string.IsNullOrEmpty(qs["id"]) && string.IsNullOrEmpty(qs["uid"]) && string.IsNullOrEmpty(qs["archivestatus"]))
            {
                qs.Set("archivestatus", (int)WpsJobArchiveStatus.NOT_ARCHIVED + "");
            }

            Type responseType = OpenSearchFactory.ResolveTypeFromRequest(httpRequest.QueryString, httpRequest.Headers, ose);
            IOpenSearchResultCollection osr = ose.Query(wpsjobs, qs, responseType);

            OpenSearchFactory.ReplaceOpenSearchDescriptionLinks(wpsjobs, osr);
//            OpenSearchFactory.ReplaceSelfLinks(wpsjobs, httpRequest.QueryString, osr.Result, EntrySelfLinkTemplate);

            context.Close();
            return(new HttpResult(osr.SerializeToString(), osr.ContentType));
        }
Exemple #9
0
        public object Get(TransactionsSearchRequestTep request)
        {
            var context = TepWebContext.GetWebContext(PagePrivileges.UserView);
            IOpenSearchResultCollection result;

            try {
                context.Open();
                context.LogInfo(this, string.Format("/transaction/search GET"));

                // Load the complete request
                var httpRequest = HttpContext.Current.Request;

                EntityList <Transaction> transactions = new EntityList <Transaction>(context);
                if (context.AccessLevel != EntityAccessLevel.Administrator || httpRequest.QueryString["author"] == null)
                {
                    //Only admin can see others transactions
                    transactions.SetFilter("OwnerId", context.UserId + "");
                }
                else
                {
                    var user = UserTep.FromIdentifier(context, httpRequest.QueryString["author"]);
                    transactions.SetFilter("OwnerId", user.Id + "");
                }
                transactions.AddSort("LogTime", SortDirection.Descending);

                var ose = MasterCatalogue.OpenSearchEngine;

                Type responseType = OpenSearchFactory.ResolveTypeFromRequest(httpRequest.QueryString, httpRequest.Headers, ose);
                result = ose.Query(transactions, httpRequest.QueryString, responseType);

                OpenSearchFactory.ReplaceOpenSearchDescriptionLinks(transactions, result);

                context.Close();
            } catch (Exception e) {
                context.LogError(this, e.Message, e);
                context.Close();
                throw e;
            }
            return(new HttpResult(result.SerializeToString(), result.ContentType));
        }
        public static IOpenSearchResultCollection QueryResult(IOpenSearchableElasticType type, NameValueCollection parameters, Type resultType = null)
        {
            OpenSearchEngine ose = type.GetOpenSearchEngine(parameters);

            if (resultType == null)
            {
                resultType = OpenSearchFactory.ResolveTypeFromRequest(HttpContext.Current.Request, ose);
            }

            if (resultType == typeof(ParametersResult))
            {
                return(type.DescribeParameters());
            }

            var result = ose.Query(type, parameters, resultType);

            OpenSearchFactory.ReplaceSelfLinks(type, parameters, result, type.EntrySelfLinkTemplate, result.ContentType);
            OpenSearchFactory.ReplaceOpenSearchDescriptionLinks(type, result);

            result.Title = new TextSyndicationContent(string.Format("Result for OpenSearch query over type {0} in index {1}", type.Type.Name, type.Index.Name));

            return(result);
        }
        private static List <WpsServiceOverview> GetWpsServiceOverview(IfyContext context, OwcOffering offering, string appUid, string appTitle, string appIcon)
        {
            List <WpsServiceOverview> wpsOverviews = new List <WpsServiceOverview>();

            if (offering != null)
            {
                if (offering.Operations != null)
                {
                    foreach (var ops in offering.Operations)
                    {
                        if (ops.Code == "ListProcess")
                        {
                            var href = ops.Href;
                            //replace usernames in apps
                            try {
                                var user = UserTep.FromId(context, context.UserId);
                                href = href.Replace("${USERNAME}", user.Username);
                                href = href.Replace("${T2USERNAME}", user.TerradueCloudUsername);
                                href = href.Replace("${T2APIKEY}", user.GetSessionApiKey());
                            } catch (Exception e) {
                                context.LogError(context, e.Message);
                            }
                            var uri = new Uri(href.Replace("file://", context.BaseUrl));
                            var nvc = HttpUtility.ParseQueryString(uri.Query);
                            nvc.Set("count", "100");
                            Terradue.OpenSearch.Engine.OpenSearchEngine ose = MasterCatalogue.OpenSearchEngine;
                            var responseType = ose.GetExtensionByExtensionName("atom").GetTransformType();
                            EntityList <WpsProcessOffering> wpsProcesses = new EntityList <WpsProcessOffering>(context);
                            wpsProcesses.SetFilter("Available", "true");
                            wpsProcesses.OpenSearchEngine = ose;
                            wpsProcesses.Identifier       = string.Format("servicewps-{0}", context.Username);

                            CloudWpsFactory wpsOneProcesses = new CloudWpsFactory(context);
                            wpsOneProcesses.OpenSearchEngine = ose;

                            wpsProcesses.Identifier = "service/wps";
                            var entities = new List <IOpenSearchable> {
                                wpsProcesses, wpsOneProcesses
                            };

                            var settings = MasterCatalogue.OpenSearchFactorySettings;
                            MultiGenericOpenSearchable  multiOSE = new MultiGenericOpenSearchable(entities, settings);
                            IOpenSearchResultCollection osr      = ose.Query(multiOSE, nvc, responseType);

                            OpenSearchFactory.ReplaceOpenSearchDescriptionLinks(wpsProcesses, osr);

                            foreach (var itemWps in osr.Items)
                            {
                                string uid         = "";
                                var    identifiers = itemWps.ElementExtensions.ReadElementExtensions <string>("identifier", "http://purl.org/dc/elements/1.1/");
                                if (identifiers.Count > 0)
                                {
                                    uid = identifiers[0];
                                }
                                string description = "";
                                if (itemWps.Content is TextSyndicationContent)
                                {
                                    var content = itemWps.Content as TextSyndicationContent;
                                    description = content.Text;
                                }
                                string version  = "";
                                var    versions = itemWps.ElementExtensions.ReadElementExtensions <string>("version", "https://www.terradue.com/");
                                if (versions.Count > 0)
                                {
                                    version = versions[0];
                                }
                                string publisher  = "";
                                var    publishers = itemWps.ElementExtensions.ReadElementExtensions <string>("publisher", "http://purl.org/dc/elements/1.1/");
                                if (publishers.Count > 0)
                                {
                                    publisher = publishers[0];
                                }
                                var serviceUrl = new UriBuilder(context.GetConfigValue("BaseUrl"));
                                serviceUrl.Path  = "/t2api/service/wps/search";
                                serviceUrl.Query = "id=" + uid;
                                var url = new UriBuilder(context.GetConfigValue("BaseUrl"));
                                url.Path  = "t2api/share";
                                url.Query = "url=" + HttpUtility.UrlEncode(serviceUrl.Uri.AbsoluteUri) + "&id=" + appUid;
                                var icon = itemWps.Links.FirstOrDefault(l => l.RelationshipType == "icon");
                                //entry.Links.Add(new SyndicationLink(new Uri(this.IconUrl), "icon", null, null, 0));
                                wpsOverviews.Add(new WpsServiceOverview {
                                    Identifier = uid,
                                    App        = new AppOverview {
                                        Icon  = appIcon ?? "",
                                        Title = appTitle,
                                        Uid   = appUid
                                    },
                                    Name        = itemWps.Title != null ? itemWps.Title.Text : uid,
                                    Description = description,
                                    Version     = version,
                                    Provider    = publisher,
                                    Url         = url.Uri.AbsoluteUri,
                                    Icon        = icon != null ? icon.Uri.AbsoluteUri : ""
                                });
                            }
                        }
                    }
                }
            }
            return(wpsOverviews);
        }
        /// <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));
        }
        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));
        }
        public object Get(ThematicAppByCommunitySearchRequestTep request)
        {
            IfyWebContext context = TepWebContext.GetWebContext(PagePrivileges.EverybodyView);

            context.Open();
            context.LogInfo(this, string.Format("/community/{{domain}}/apps/search GET domain='{0}'", request.Domain));

            var domain = ThematicCommunity.FromIdentifier(context, request.Domain);
            IOpenSearchResultCollection result;
            OpenSearchEngine            ose = MasterCatalogue.OpenSearchEngine;
            HttpRequest httpRequest         = HttpContext.Current.Request;
            Type        responseType        = OpenSearchFactory.ResolveTypeFromRequest(httpRequest.QueryString, httpRequest.Headers, ose);

            if (request.cache)
            {
                bool isjoined = domain.IsUserJoined(context.UserId);

                EntityList <ThematicApplicationCached> appsCached = new EntityList <ThematicApplicationCached>(context);
                if (isjoined)
                {
                    appsCached.SetFilter("DomainId", domain.Id.ToString());
                }
                else
                {
                    appsCached.SetFilter("DomainId", "-1");//if user is not joined we dont want him to see results
                }
                appsCached.AddSort("LastUpdate", SortDirection.Descending);
                result = ose.Query(appsCached, httpRequest.QueryString, responseType);
                OpenSearchFactory.ReplaceOpenSearchDescriptionLinks(appsCached, result);
            }
            else
            {
                if (MasterCatalogue.SearchCache != null)
                {
                    MasterCatalogue.SearchCache.ClearCache(".*", DateTime.Now);
                }

                var apps = new EntityList <DataPackage>(context);
                apps.SetFilter("Kind", ThematicApplication.KINDRESOURCESETAPPS.ToString());
                apps.SetFilter("DomainId", domain.Id.ToString());
                apps.Load();

                // the opensearch cache system uses the query parameters
                // we add to the parameters the filters added to the load in order to avoir wrong cache
                // we use 't2-' in order to not interfer with possibly used query parameters
                var qs = new NameValueCollection(Request.QueryString);
                foreach (var filter in apps.FilterValues)
                {
                    qs.Add("t2-" + filter.Key.FieldName, filter.Value.ToString());
                }

                apps.OpenSearchEngine = ose;

                List <Terradue.OpenSearch.IOpenSearchable> osentities = new List <Terradue.OpenSearch.IOpenSearchable>();
                foreach (var app in apps.Items)
                {
                    app.OpenSearchEngine = ose;
                    osentities.AddRange(app.GetOpenSearchableArray());
                }

                var settings = MasterCatalogue.OpenSearchFactorySettings;
                MultiGenericOpenSearchable multiOSE = new MultiGenericOpenSearchable(osentities, settings);
                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);
            }

            context.Close();
            return(new HttpResult(sresult, result.ContentType));
        }
Exemple #15
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);
        }
Exemple #16
0
        public object Get(ActivityByCommunitySearchRequestTep request)
        {
            var context = TepWebContext.GetWebContext(PagePrivileges.UserView);

            context.AccessLevel = EntityAccessLevel.Administrator;
            context.Open();
            context.LogInfo(this, string.Format("/community/{{community}}/activity/search GET - community='{0}'", request.Domain));

            ThematicCommunity domain = ThematicCommunity.FromIdentifier(context, request.Domain);

            //We only want some Privileges
            var privlist = new List <int> ();

            var privs = Privilege.Get(EntityType.GetEntityType(typeof(WpsJob)));

            foreach (var priv in privs)
            {
                privlist.Add(priv.Id);
            }

            privs = Privilege.Get(EntityType.GetEntityType(typeof(DataPackage)));
            foreach (var priv in privs)
            {
                privlist.Add(priv.Id);
            }

            privs = Privilege.Get(EntityType.GetEntityType(typeof(Series)));
            foreach (var priv in privs)
            {
                privlist.Add(priv.Id);
            }

            EntityList <ActivityTep> activities = new EntityList <ActivityTep> (context);

            activities.AddSort("CreationTime", SortDirection.Descending);
            activities.SetFilter("PrivilegeId", string.Join(",", privlist));
            activities.SetFilter("DomainId", domain.Id.ToString());
            activities.Identifier = "activity";
            activities.Load();

            // Load the complete request
            HttpRequest      httpRequest = HttpContext.Current.Request;
            OpenSearchEngine ose         = MasterCatalogue.OpenSearchEngine;

            // the opensearch cache system uses the query parameters
            // we add to the parameters the filters added to the load in order to avoir wrong cache
            // we use 't2-' in order to not interfer with possibly used query parameters
            var qs = new NameValueCollection(Request.QueryString);

            foreach (var filter in activities.FilterValues)
            {
                qs.Set("t2-" + filter.Key.FieldName, filter.Value.ToString());
            }

            Type responseType = OpenSearchFactory.ResolveTypeFromRequest(httpRequest.QueryString, httpRequest.Headers, ose);
            IOpenSearchResultCollection osr = ose.Query(activities, qs, responseType);

            OpenSearchFactory.ReplaceOpenSearchDescriptionLinks(activities, osr);

            context.Close();
            return(new HttpResult(osr.SerializeToString(), osr.ContentType));
        }