public object Get(ThematicAppCacheRequestTep request)
        {
            var context = TepWebContext.GetWebContext(PagePrivileges.UserView);

            context.Open();
            try {
                context.LogInfo(this, string.Format("/apps/cache GET"));
                var appFactory = new ThematicAppCachedFactory(context);
                if (!string.IsNullOrEmpty(request.Uid))
                {
                    //refresh only a given app
                    appFactory.RefreshCachedApp(request.Uid);
                }
                else if (!string.IsNullOrEmpty(request.Username))
                {
                    //refresh only for private apps
                    var user = UserTep.FromIdentifier(context, request.Username);
                    if (user.Id == context.UserId)
                    {
                        appFactory.RefreshCachedAppsForUser(user);
                    }
                }
                else if (!string.IsNullOrEmpty(request.Community))
                {
                    //refresh only for community apps
                    var community = ThematicCommunity.FromIdentifier(context, request.Community);
                    if (community.CanUserManage(context.UserId))
                    {
                        appFactory.RefreshCachedAppsForCommunity(community);
                    }
                }
                else
                {
                    //user should be admin
                    if (context.UserLevel == UserLevel.Administrator)
                    {
                        //case TEP -- we don't want user privates apps to be cached
                        appFactory.RefreshCachedApps(false, true, true);
                    }
                }
                context.Close();
            } catch (Exception e) {
                context.LogError(this, e.Message, e);
                context.Close();
                throw e;
            }
            return(new WebResponseBool(true));
        }
Exemple #2
0
        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));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="Terradue.Tep.WebServer.WebThematicAppTep"/> class.
        /// </summary>
        /// <param name="entity">Entity.</param>
        public WebThematicAppTep(ThematicApplicationCached app, IfyContext context)
        {
            Id = app.Id;

            if (app.Domain != null)
            {
                Domain = app.Domain.Identifier;
            }

            var feed = ThematicAppCachedFactory.GetOwsContextAtomFeed(app.TextFeed);

            if (feed != null)
            {
                var entry = feed.Items.First();
                if (entry.Title != null)
                {
                    Title = entry.Title.Text;
                }
                if (entry.Summary != null)
                {
                    Summary = entry.Summary.Text;
                }
                var identifiers = entry.ElementExtensions.ReadElementExtensions <string>("identifier", OwcNamespaces.Dc);
                if (identifiers.Count() > 0)
                {
                    this.Identifier = identifiers.First();
                }

                var icon = entry.Links.FirstOrDefault(l => l.RelationshipType == "icon");
                if (icon != null)
                {
                    this.Icon = icon.Uri.AbsoluteUri;
                }

                SelfUrl = context.BaseUrl + "/apps/search?cache=true&uid=" + this.Identifier;

                HasServices = false;

                foreach (var offering in entry.Offerings)
                {
                    switch (offering.Code)
                    {
                    case "http://www.opengis.net/spec/owc/1.0/req/atom/wps":
                        if (offering.Operations != null && offering.Operations.Length > 0)
                        {
                            foreach (var operation in offering.Operations)
                            {
                                var href = operation.Href;
                                switch (operation.Code)
                                {
                                case "ListProcess":
                                    HasServices = true;
                                    var uri = new Uri(href);
                                    var nvc = HttpUtility.ParseQueryString(uri.Query);
                                    foreach (var key in nvc.AllKeys)
                                    {
                                        switch (key)
                                        {
                                        case "domain":
                                            if (nvc[key] != null)
                                            {
                                                if (nvc[key].Contains("${USERNAME}"))
                                                {
                                                    var user = UserTep.FromId(context, context.UserId);
                                                    user.LoadCloudUsername();
                                                    this.WpsServiceDomain = nvc[key].Replace("${USERNAME}", user.TerradueCloudUsername);
                                                }
                                                else
                                                {
                                                    this.WpsServiceDomain = nvc[key];
                                                }
                                            }
                                            break;

                                        case "tag":
                                            if (!string.IsNullOrEmpty(nvc[key]))
                                            {
                                                this.WpsServiceTags = nvc[key].Split(",".ToCharArray()).ToList();
                                            }
                                            break;

                                        default:
                                            break;
                                        }
                                    }
                                    break;

                                default:
                                    break;
                                }
                            }
                        }
                        break;

                    default:
                        break;
                    }
                }
            }
        }