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)); }
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)); }
/// <summary> /// Replaces the enclosure links. /// </summary> /// <param name="entity">Entity.</param> /// <param name="parameters">Parameters.</param> /// <param name="osr">Osr.</param> /// <param name="entryEnclosureLinkTemplate">Entry enclosure link template.</param> /// <param name="contentType">Content type.</param> public void ReplaceEnclosureLinks(IOpenSearchable entity, NameValueCollection parameters, IOpenSearchResultCollection osr, string contentType) { if (!string.IsNullOrEmpty(parameters["do"])) { bool strict = false, isDomain = false; string origin = parameters["do"]; if (parameters["do"].StartsWith("[") && parameters["do"].EndsWith("]")) { strict = true; origin = parameters["do"].TrimStart('[').TrimEnd(']'); } try { Dns.GetHostAddresses(origin); isDomain = true; } catch { } foreach (IOpenSearchResultItem item in osr.Items) { foreach (var enclosureLink in item.Links.Where(l => l.RelationshipType == "enclosure").ToArray()) { if (origin.Contains("terradue") || isDomain) { SyndicationLink newEnclosureLink = DataGatewayFactory.SubstituteEnclosure(enclosureLink, openSearchable, item); if (newEnclosureLink != null) { item.Links.Insert(item.Links.IndexOf(enclosureLink), newEnclosureLink); item.Links.Remove(enclosureLink); } else if (strict) { item.Links.Remove(enclosureLink); } } } item.ElementExtensions = new SyndicationElementExtensionCollection( item.ElementExtensions.Select <SyndicationElementExtension, SyndicationElementExtension>(ext => { if (ext.OuterName != "offering" || ext.OuterNamespace != "http://www.opengis.net/owc/1.0") { return(ext); } var offering = (OwcOffering)OwcContextHelper.OwcOfferingSerializer.Deserialize(ext.GetReader()); if (offering.Contents != null) { foreach (var content in offering.Contents) { if (content.Url != null) { var newUrl = DataGatewayFactory.SubstituteUrlApi(content.Url, openSearchable, item); if (newUrl != null) { content.Url = newUrl; } } } } return(new SyndicationElementExtension(offering.CreateReader())); })); } } }