Exemplo n.º 1
0
        public object Get(ThematicAppCheckAvailabilityRequest request)
        {
            var  context = TepWebContext.GetWebContext(PagePrivileges.UserView);
            bool result  = false;

            context.Open();
            try {
                context.LogInfo(this, string.Format("/apps/available GET"));
                var user   = UserTep.FromId(context, context.UserId);
                var apikey = user.GetSessionApiKey();
                result = !CatalogueFactory.CheckIdentifierExists(context, request.Index, request.Uid, apikey);
                context.Close();
            } catch (Exception e) {
                context.LogError(this, e.Message, e);
                context.Close();
                throw e;
            }
            return(new WebResponseBool(result));
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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 } }
            });
        }