示例#1
0
        public object Delete(ShareDeleteRequestTep request)
        {
            var context = TepWebContext.GetWebContext(PagePrivileges.UserView);

            context.Open();
            context.LogInfo(this, string.Format("/share DELETE self='{0}'", request.self));

            var settings   = MasterCatalogue.OpenSearchFactorySettings;
            var entitySelf = new UrlBasedOpenSearchable(context, new OpenSearchUrl(request.self), settings).Entity;

            if (entitySelf is EntityList <WpsJob> )
            {
                var entitylist = entitySelf as EntityList <WpsJob>;
                var items      = entitylist.GetItemsAsList();
                if (items.Count > 0)
                {
                    foreach (var item in items)
                    {
                        item.RevokePermissionsFromAll(true, false);
                        if (item.Owner != null && item.DomainId != item.Owner.DomainId)
                        {
                            item.DomainId = item.Owner.DomainId;
                            item.Store();
                        }

                        //share on store
                        try {
                            DataGatewayFactory.ShareOnStore(context.GetConfigValue("SiteName"), item.StatusLocation, "results", "private");
                        }catch (Exception e) {
                            context.LogError(this, "Unable to share on STORE : " + e.Message, e);
                        }

                        //unpublish on community index
                        item.UnPublishFromIndex(context.GetConfigValue("catalog-communityIndex"), context.GetConfigValue("catalog-communityUsername"), context.GetConfigValue("catalog-communityApikey"));
                    }
                }
            }
            else if (entitySelf is EntityList <DataPackage> )
            {
                var entitylist = entitySelf as EntityList <DataPackage>;
                var items      = entitylist.GetItemsAsList();
                if (items.Count > 0)
                {
                    foreach (var item in items)
                    {
                        item.RevokePermissionsFromAll(true, false);
                        if (item.Owner != null && item.DomainId != item.Owner.DomainId)
                        {
                            item.DomainId = item.Owner.DomainId;
                            item.Store();
                        }
                    }
                }
            }
            else if (entitySelf is EntityList <WpsProcessOffering> )
            {
                var entitylist = entitySelf as EntityList <WpsProcessOffering>;
                var items      = entitylist.GetItemsAsList();
                if (items.Count > 0)
                {
                    foreach (var item in items)
                    {
                        item.RevokePermissionsFromAll(true, false);
                        if (item.Owner != null)
                        {
                            if (item.DomainId != item.Owner.DomainId)
                            {
                                item.DomainId = item.Owner.DomainId;
                                item.Store();
                            }
                        }
                    }
                }
            }

            context.Close();
            return(new WebResponseBool(true));
        }
示例#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));
        }
示例#3
0
        public object Post(ShareCreateRequestTep request)
        {
            var context = TepWebContext.GetWebContext(PagePrivileges.UserView);

            context.Open();
            context.LogInfo(this, string.Format("/share POST self='{0}',to='{1}'", request.self, request.to != null ? string.Join("", request.to) : ""));

            var settings   = MasterCatalogue.OpenSearchFactorySettings;
            var entitySelf = new UrlBasedOpenSearchable(context, new OpenSearchUrl(request.self), settings).Entity;

            //case WpsJob
            if (entitySelf is EntityList <WpsJob> )
            {
                var entitylist = entitySelf as EntityList <WpsJob>;
                var wpsjobs    = entitylist.GetItemsAsList();
                if (wpsjobs.Count == 0)
                {
                    return(new WebResponseBool(false));
                }

                //if to is null, we share publicly
                if (request.to == null)
                {
                    foreach (var job in wpsjobs)   //the entitySelf can return several entities
                    //first we remove the current sharing (in case of restricted)
                    {
                        job.RevokePermissionsFromAll(true, false);
                        if (job.Owner != null && job.DomainId != job.Owner.DomainId)
                        {
                            job.DomainId = job.Owner.DomainId;
                            job.Store();
                        }
                        //secondly we share for all
                        job.GrantPermissionsToAll();

                        //share on store
                        try {
                            DataGatewayFactory.ShareOnStore(context.GetConfigValue("SiteName"), job.StatusLocation, "results", "public");
                        } catch (Exception e) {
                            context.LogError(this, "Unable to share on STORE : " + e.Message, e);
                        }

                        //publish on community index
                        if (request.publish)
                        {
                            job.PublishToIndex(context.GetConfigValue("catalog-communityIndex"), context.GetConfigValue("catalog-communityUsername"), context.GetConfigValue("catalog-communityApikey"), request.id);
                        }

                        Activity activity = new Activity(context, job, EntityOperationType.Share);
                        activity.Store();
                    }
                }

                //we share with restriction (community + users)
                else
                {
                    foreach (var job in wpsjobs)   //the entitySelf can return several entities

                    //remove previous visibility sharing
                    {
                        job.RevokePermissionsFromAll(true, false);
                        if (job.Owner != null && job.DomainId != job.Owner.DomainId)
                        {
                            job.DomainId = job.Owner.DomainId;
                            job.Store();
                        }

                        //unpublish on community index
                        job.UnPublishFromIndex(context.GetConfigValue("catalog-communityIndex"), context.GetConfigValue("catalog-communityUsername"), context.GetConfigValue("catalog-communityApikey"));

                        var sharedUsers       = new List <string>();
                        var sharedCommunities = new List <ThematicCommunity>();

                        foreach (var to in request.to)
                        {
                            var entityTo = new UrlBasedOpenSearchable(context, new OpenSearchUrl(to), settings).Entity;

                            //case community
                            if (entityTo is EntityList <ThematicCommunity> )
                            {
                                var entityTolist = entityTo as EntityList <ThematicCommunity>;
                                var communities  = entityTolist.GetItemsAsList();
                                if (communities.Count == 0)
                                {
                                    return(new WebResponseBool(false));
                                }

                                var community = communities[0];

                                //the entitySelflist can return several entities but we only take the first one (we can share with only one community)
                                community.ShareEntity(job);
                                job.DomainId = community.Id;
                                job.Store();

                                sharedCommunities.Add(community);

                                ActivityTep activity = new ActivityTep(context, job, EntityOperationType.Share);
                                activity.AppId    = request.id;
                                activity.DomainId = communities[0].Id;
                                activity.Store();
                            }

                            //case user
                            else if (entityTo is EntityList <UserTep> )
                            {
                                var entityTolist = entityTo as EntityList <UserTep>;
                                var users        = entityTolist.GetItemsAsList();
                                if (users.Count == 0)
                                {
                                    return(new WebResponseBool(false));
                                }
                                job.GrantPermissionsToUsers(users);

                                foreach (var usr in users)
                                {
                                    if (string.IsNullOrEmpty(usr.TerradueCloudUsername))
                                    {
                                        usr.LoadCloudUsername();
                                    }
                                    if (!string.IsNullOrEmpty(usr.TerradueCloudUsername))
                                    {
                                        sharedUsers.Add(usr.TerradueCloudUsername);
                                    }
                                }

                                ActivityTep activity = new ActivityTep(context, job, EntityOperationType.Share);
                                activity.AppId = request.id;
                                activity.Store();
                            }
                        }

                        //share on store
                        try {
                            DataGatewayFactory.ShareOnStore(context.GetConfigValue("SiteName"), job.StatusLocation, "results", "restricted", sharedUsers, sharedCommunities);
                        } catch (Exception e) {
                            context.LogError(this, "Unable to share on STORE : " + e.Message, e);
                        }
                    }
                }
            }

            //case DataPackage
            else if (entitySelf is EntityList <DataPackage> )
            {
                var entitylist   = entitySelf as EntityList <DataPackage>;
                var datapackages = entitylist.GetItemsAsList();
                if (datapackages.Count == 0)
                {
                    return(new WebResponseBool(false));
                }

                //if to is null, we share publicly
                if (request.to == null)
                {
                    foreach (var dp in datapackages)   //the entitySelf can return several entities
                    {
                        dp.GrantPermissionsToAll();

                        Activity activity = new Activity(context, dp, EntityOperationType.Share);
                        activity.Store();
                    }
                }

                //we share with restriction (community + users)
                else
                {
                    foreach (var dp in datapackages)   //the entitySelf can return several entities
                    //remove previous visibility sharing
                    {
                        dp.RevokePermissionsFromAll(true, false);
                        if (dp.Owner != null && dp.DomainId != dp.Owner.DomainId)
                        {
                            dp.DomainId = dp.Owner.DomainId;
                            dp.Store();
                        }

                        foreach (var to in request.to)
                        {
                            var entityTo = new UrlBasedOpenSearchable(context, new OpenSearchUrl(to), settings).Entity;

                            //case community
                            if (entityTo is EntityList <ThematicCommunity> )
                            {
                                var entityTolist = entityTo as EntityList <ThematicCommunity>;
                                var communities  = entityTolist.GetItemsAsList();
                                if (communities.Count == 0)
                                {
                                    return(new WebResponseBool(false));
                                }
                                //the entitySelflist can return several entities but we only take the first one (we can share with only one community)
                                dp.DomainId = communities[0].Id;
                                dp.Store();

                                ActivityTep activity = new ActivityTep(context, dp, EntityOperationType.Share);
                                activity.AppId    = request.id;
                                activity.DomainId = communities[0].Id;
                                activity.Store();
                            }

                            //case user
                            else if (entityTo is EntityList <UserTep> )
                            {
                                var entityTolist = entityTo as EntityList <UserTep>;
                                var users        = entityTolist.GetItemsAsList();
                                if (users.Count == 0)
                                {
                                    return(new WebResponseBool(false));
                                }
                                dp.GrantPermissionsToUsers(users);

                                ActivityTep activity = new ActivityTep(context, dp, EntityOperationType.Share);
                                activity.AppId = request.id;
                                activity.Store();
                            }
                        }
                    }
                }
            }
            else if (entitySelf is EntityList <WpsProcessOffering> )
            {
                var entitylist = entitySelf as EntityList <WpsProcessOffering>;
                var services   = entitylist.GetItemsAsList();
                if (services.Count == 0)
                {
                    return(new WebResponseBool(false));
                }

                //if to is null, we share publicly
                if (request.to == null)
                {
                    foreach (var s in services)   //the entitySelf can return several entities
                    {
                        s.GrantPermissionsToAll();

                        Activity activity = new Activity(context, s, EntityOperationType.Share);
                        activity.Store();
                    }
                }

                //we share with restriction (community + users)
                else
                {
                    foreach (var s in services)   //the entitySelf can return several entities
                    //remove previous visibility sharing
                    {
                        s.RevokePermissionsFromAll(true, false);
                        if (s.Owner != null && s.DomainId != s.Owner.DomainId)
                        {
                            s.DomainId = s.Owner.DomainId;
                            s.Store();
                        }

                        foreach (var to in request.to)
                        {
                            var entityTo = new UrlBasedOpenSearchable(context, new OpenSearchUrl(to), settings).Entity;

                            //case community
                            if (entityTo is EntityList <ThematicCommunity> )
                            {
                                var entityTolist = entityTo as EntityList <ThematicCommunity>;
                                var communities  = entityTolist.GetItemsAsList();
                                if (communities.Count == 0)
                                {
                                    return(new WebResponseBool(false));
                                }
                                //the entitySelflist can return several entities but we only take the first one (we can share with only one community)
                                s.DomainId = communities[0].Id;
                                s.Store();

                                ActivityTep activity = new ActivityTep(context, s, EntityOperationType.Share);
                                activity.AppId    = request.id;
                                activity.DomainId = communities[0].Id;
                                activity.Store();
                            }

                            //case user
                            else if (entityTo is EntityList <UserTep> )
                            {
                                var entityTolist = entityTo as EntityList <UserTep>;
                                var users        = entityTolist.GetItemsAsList();
                                if (users.Count == 0)
                                {
                                    return(new WebResponseBool(false));
                                }
                                s.GrantPermissionsToUsers(users);

                                ActivityTep activity = new ActivityTep(context, s, EntityOperationType.Share);
                                activity.AppId = request.id;
                                activity.Store();
                            }
                        }
                    }
                }
            }

            context.Close();
            return(new WebResponseBool(true));
        }