/// <summary> /// Get the specified request. /// </summary> /// <param name="request">Request.</param> public object Get(DataPackagesSearchRequest request) { var context = TepWebContext.GetWebContext(PagePrivileges.EverybodyView); IOpenSearchResultCollection result = null; try { context.Open(); context.LogInfo(this, string.Format("/data/package/search GET")); EntityList <Terradue.Tep.DataPackage> datapackages = new EntityList <DataPackage>(context); if (!string.IsNullOrEmpty(request.Key)) { UserTep user = UserTep.FromApiKey(context, request.Key); datapackages.UserId = user.Id; context.AccessLevel = EntityAccessLevel.Privilege; } datapackages.SetFilter("Kind", RemoteResourceSet.KINDRESOURCESETNORMAL.ToString()); // 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 datapackages.FilterValues) { qs.Add("t2-" + filter.Key.FieldName, filter.Value.ToString()); } if (qs["visibility"] != null && qs["visibility"] != "all") { datapackages.AccessLevel = EntityAccessLevel.Privilege; } if (context.UserLevel == UserLevel.Administrator && (qs["visibility"] == null || qs["visibility"] != "owned")) { datapackages.SetFilter("Identifier", "!_index_*,!_series_*,!_products_*"); } Type type = OpenSearchFactory.ResolveTypeFromRequest(httpRequest.QueryString, httpRequest.Headers, ose); result = ose.Query(datapackages, qs, type); context.Close(); } catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(new HttpResult(result.SerializeToString(), result.ContentType)); }
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)); }