public object Put(BulkServicesAvailabilityRequestTep request) { var context = TepWebContext.GetWebContext(PagePrivileges.AdminOnly); try { context.Open(); context.LogInfo(this, string.Format("/service/wps/bulk/available POST, identifiers='{0}'", string.Join(",", request.Identifiers))); if (request.Identifiers == null || request.Identifiers.Count == 0) { return(new HttpResult("No services specified", HttpStatusCode.BadRequest)); } foreach (var identifier in request.Identifiers) { try { var service = WpsProcessOfferingTep.FromIdentifier(context, identifier); service.Available = request.Available; service.Store(); } catch (Exception e) { context.LogError(this, "Error while loading service " + identifier, e); } } } catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); return(new HttpResult(e.Message, HttpStatusCode.BadRequest)); } context.Close(); return(new HttpResult("", HttpStatusCode.OK)); }
public object Post(BulkServicesForAppRequestTep request) { var context = TepWebContext.GetWebContext(PagePrivileges.AdminOnly); try { context.Open(); context.LogInfo(this, string.Format("/service/wps/bulk/app POST, identifiers='{0}', app='{1}'", string.Join(",", request.Identifiers), request.SelfApp)); if (request.Identifiers == null || request.Identifiers.Count == 0) { return(new HttpResult("No services specified", HttpStatusCode.BadRequest)); } if (request.SelfApp == null) { return(new HttpResult("No app specified", HttpStatusCode.BadRequest)); } Domain domain = null; string tags = null; var settings = MasterCatalogue.OpenSearchFactorySettings; var urlBOS = new UrlBasedOpenSearchable(context, new OpenSearchUrl(request.SelfApp), settings); var entity = urlBOS.Entity; if (entity is EntityList <ThematicApplicationCached> ) { var entitylist = entity as EntityList <ThematicApplicationCached>; var items = entitylist.GetItemsAsList(); if (items.Count > 0) { var feed = ThematicAppCachedFactory.GetOwsContextAtomFeed(items[0].TextFeed); if (feed != null) { var entry = feed.Items.First(); var offering = entry.Offerings.First(p => p.Code == "http://www.opengis.net/spec/owc/1.0/req/atom/wps"); if (offering == null) { return(new HttpResult("No WPS offering in specified app", HttpStatusCode.BadRequest)); } //get domain and tag for app var op = offering.Operations.FirstOrDefault(o => o.Code == "ListProcess"); if (op != null && op.Href != null) { var nvc = HttpUtility.ParseQueryString((new Uri(op.Href)).Query); foreach (var key in nvc.AllKeys) { switch (key) { case "domain": domain = Domain.FromIdentifier(context, nvc[key]); break; case "tag": tags = nvc[key]; break; default: break; } } } } } } foreach (var identifier in request.Identifiers) { try { var service = WpsProcessOfferingTep.FromIdentifier(context, identifier); var newService = WpsProcessOfferingTep.Copy(service, context); newService.Domain = domain; newService.Tags = tags; newService.Available = true; newService.Store(); } catch (Exception e) { context.LogError(this, "Error while loading service " + identifier, e); } } } catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); return(new HttpResult(e.Message, HttpStatusCode.BadRequest)); } context.Close(); return(new HttpResult("", HttpStatusCode.OK)); }
public object Put(BulkSwitchServiceRequestTep request) { var context = TepWebContext.GetWebContext(PagePrivileges.AdminOnly); try { context.Open(); context.LogInfo(this, string.Format("/service/wps/bulk/replace PUT identifiers='{0}' newIdentifier='{1}'", string.Join(",", request.Identifiers), request.Service != null ? request.Service.Identifier : null)); if (request.Identifiers == null || request.Identifiers.Count == 0) { return(new HttpResult("No services specified", HttpStatusCode.BadRequest)); } if (request.Service == null) { return(new HttpResult("No service specified", HttpStatusCode.BadRequest)); } foreach (var identifier in request.Identifiers) { try { WpsProcessOfferingTep wpsOld = WpsProcessOfferingTep.FromIdentifier(context, identifier); WpsProcessOffering wpsNew = (WpsProcessOffering)request.Service.ToEntity(context, new WpsProcessOffering(context)); wpsNew.Identifier = Guid.NewGuid().ToString(); if (!string.IsNullOrEmpty(request.WpsIdentifier)) { var provider = (WpsProvider)ComputingResource.FromIdentifier(context, request.WpsIdentifier); wpsNew.Provider = provider; } else { wpsNew.Provider = wpsOld.Provider; } wpsNew.DomainId = wpsOld.DomainId; wpsNew.Tags = wpsOld.Tags; wpsNew.IconUrl = wpsOld.IconUrl; wpsNew.Available = true; wpsNew.Commercial = wpsOld.Commercial; wpsNew.Geometry = wpsOld.Geometry; wpsNew.ValidationUrl = wpsOld.ValidationUrl; wpsNew.TermsConditionsUrl = wpsOld.TermsConditionsUrl; wpsNew.TermsConditionsText = wpsOld.TermsConditionsText; wpsNew.Store(); if (request.DeleteOld) { wpsOld.Delete(); } else { wpsOld.Available = false; wpsOld.Store(); } } catch (Exception e) { context.LogError(this, "Error while loading service " + identifier, e); } } context.Close(); } catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(new HttpResult("", HttpStatusCode.OK)); }
public object Get(ThematicAppGetRequestTep request) { var context = TepWebContext.GetWebContext(PagePrivileges.AdminOnly); List <WebThematicAppTep> result = new List <WebThematicAppTep>(); context.Open(); try { context.LogInfo(this, string.Format("/apps GET")); EntityList <ThematicApplicationCached> apps = new EntityList <ThematicApplicationCached>(context); apps.Load(); foreach (var item in apps.GetItemsAsList()) { var app = new WebThematicAppTep(item, context); if (request.services && app.HasServices) { EntityList <WpsProcessOffering> services = new EntityList <WpsProcessOffering>(context); if (!string.IsNullOrEmpty(app.WpsServiceDomain)) { try { var dm = Domain.FromIdentifier(context, app.WpsServiceDomain); services.SetFilter("DomainId", dm.Id.ToString()); }catch (Exception) { services.SetFilter("DomainId", "0"); } } if (app.WpsServiceTags != null && app.WpsServiceTags.Count > 0) { IEnumerable <IEnumerable <string> > permutations = WpsProcessOfferingTep.GetPermutations(app.WpsServiceTags, app.WpsServiceTags.Count()); var r1 = permutations.Select(subset => string.Join("*", subset.Select(t => t).ToArray())).ToArray(); var tagsresult = string.Join(",", r1.Select(t => "*" + t + "*")); services.SetFilter("Tags", tagsresult); } services.SetFilter("Available", "true"); services.Load(); var appServices = new List <WpsServiceOverview>(); foreach (var s in services.GetItemsAsList()) { appServices.Add(new WpsServiceOverview { Identifier = s.Identifier, App = new AppOverview { Icon = app.Icon ?? "", Title = app.Title, Uid = app.Identifier }, Name = s.Name, Description = s.Description, Version = s.Version, Icon = s.IconUrl }); } app.Services = appServices; } result.Add(app); } context.Close(); } catch (Exception e) { context.LogError(this, e.Message, e); context.Close(); throw e; } return(result); }