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); }
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); }