예제 #1
0
        /**********************/
        /******** USER ********/
        /**********************/

        private static IEventUserLogger GetUserLogger(IfyContext context)
        {
            IEventUserLogger logger;
            string           className = EventLogConfig.Settings["user_classname"].Value;

            if (className == null)
            {
                logger = new EventUserLoggerTep(context);
            }
            else
            {
                Type type = Type.GetType(className, true);
                System.Reflection.ConstructorInfo ci = type.GetConstructor(new Type[] { typeof(IfyContext) });
                logger = (IEventUserLogger)ci.Invoke(new object[] { context });
            }
            return(logger);
        }
예제 #2
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));
        }