/// <summary> /// Tos the entity. /// </summary> /// <returns>The entity.</returns> /// <param name="context">Context.</param> /// <param name="input">Input.</param> public ThematicCommunity ToEntity(IfyContext context, ThematicCommunity input) { ThematicCommunity entity = (input == null ? new ThematicCommunity(context) : input); entity.DiscussCategory = DiscussCategory; entity.AppsLinks = Apps; entity.IconUrl = IconeUrl; entity.Identifier = TepUtility.ValidateIdentifier(Identifier); entity.Name = Name; entity.Description = Description; entity.EmailNotification = EmailNotification; entity.EnableJoinRequest = EnableJoinRequest; entity.DefaultRoleName = DefaultRole; entity.Contributor = Contributor; entity.ContributorIcon = ContributorIcon; if (Kind == (int)DomainKind.Public || Kind == (int)DomainKind.Private || Kind == (int)DomainKind.Hidden) { entity.Kind = (DomainKind)Kind; } entity.Links = new List <RemoteResource>(); if (Links != null && Links.Count > 0) { foreach (WebDataPackageItem item in Links) { RemoteResource res = (item.Id == 0) ? new RemoteResource(context) : RemoteResource.FromId(context, item.Id); res = item.ToEntity(context, res); entity.Links.Add(res); } } return(entity); }
/// <summary> /// Writes the item to the database. /// </summary> public override void Store() { context.StartTransaction(); if (DomainId == 0 && Owner != null) { DomainId = Owner.Domain.Id; } if (DomainId == -1) { DomainId = 0; } bool isNew = this.Id == 0; try { if (isNew) { this.AccessKey = Guid.NewGuid().ToString(); this.CreationTime = DateTime.UtcNow; if (string.IsNullOrEmpty(this.Identifier)) { this.Identifier = GetUniqueIdentifier(this.Name); } else { this.Identifier = TepUtility.ValidateIdentifier(this.Identifier); } } base.Store(); if (isNew && context.AccessLevel == EntityAccessLevel.Administrator) { var count = context.GetQueryIntegerValue(String.Format("SELECT count(*) FROM {3} WHERE id_{2}={0} AND id_usr={1};", Id, OwnerId, this.EntityType.PermissionSubjectTable.Name, this.EntityType.PermissionSubjectTable.PermissionTable)); if (count == 0) { context.Execute(String.Format("INSERT INTO {3} (id_{2}, id_usr) VALUES ({0}, {1});", Id, OwnerId, this.EntityType.PermissionSubjectTable.Name, this.EntityType.PermissionSubjectTable.PermissionTable)); } } if (Kind == KINDRESOURCESETUSER) { this.GrantPermissionsToUsers(new int [] { Owner.Id }, true); } Resources.StoreExactly(); LoadItems(); context.Commit(); } catch (Exception e) { context.Rollback(); throw e; } }
/// <summary> /// Gets the unique identifier. /// </summary> /// <returns>The unique identifier.</returns> /// <param name="name">Name.</param> public string GetUniqueIdentifier(string name) { var identifier = string.IsNullOrEmpty(name) ? this.Identifier : TepUtility.ValidateIdentifier(name); try { DataPackage.FromIdentifier(context, identifier); } catch (EntityUnauthorizedException) { //next } catch (EntityNotFoundException) { return(identifier); } for (int i = 0; i < 1000; i++) { var uname = string.Format("{0}{1}", identifier, i == 0 ? "" : "-" + i); try{ DataPackage.FromIdentifier(context, uname); } catch (EntityUnauthorizedException) { //next }catch (EntityNotFoundException) { return(uname); } } throw new Exception("Sorry, we were not able to find a valid data package name"); }
public string GetResultDescriptionFromS3Link(IfyContext context, WpsJob job, string s3link) { var resultdescription = s3link; if (System.Configuration.ConfigurationManager.AppSettings["SUPERVISOR_WPS_STAGE_URL"] != null && !string.IsNullOrEmpty(s3link)) { var url = System.Configuration.ConfigurationManager.AppSettings["SUPERVISOR_WPS_STAGE_URL"]; HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url); if (!string.IsNullOrEmpty(System.Configuration.ConfigurationManager.AppSettings["ProxyHost"])) { webRequest.Proxy = TepUtility.GetWebRequestProxy(); } var access_token = DBCookie.LoadDBCookie(context, System.Configuration.ConfigurationManager.AppSettings["SUPERVISOR_COOKIE_TOKEN_ACCESS"]).Value; webRequest.Headers.Set(HttpRequestHeader.Authorization, "Bearer " + access_token); webRequest.Timeout = 10000; webRequest.Method = "POST"; webRequest.ContentType = "application/json"; var shareUri = job.GetJobShareUri(job.AppIdentifier); var publishlink = new Wps3Utils.SyndicationLink { Href = shareUri.AbsoluteUri, Rel = "external", Type = "text/html", Title = "Producer Link", Attributes = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("level", "primary") } }; context.LogDebug(job, string.Format("publish request to supervisor - s3link = {0} ; jobUrl = {1} ; index = {2}", s3link, shareUri.AbsoluteUri, job.Owner.Username)); string authBasicHeader = null; try { if (!string.IsNullOrEmpty(System.Configuration.ConfigurationManager.AppSettings["SUPERVISOR_FIXED_AUTH_HEADER"])) { authBasicHeader = System.Configuration.ConfigurationManager.AppSettings["SUPERVISOR_FIXED_AUTH_HEADER"]; } else { var apikey = job.Owner.LoadApiKeyFromRemote(); authBasicHeader = "Basic " + Convert.ToBase64String(System.Text.Encoding.Default.GetBytes(job.Owner.Username + ":" + apikey)); } }catch (Exception e) { context.LogError(this, "Error get apikey : " + e.Message); } var jsonurl = new SupervisorPublish { Url = s3link, AuthorizationHeader = authBasicHeader, Index = job.Owner.Username, CreateIndex = true, Categories = new List <Wps3Utils.SyndicationCategory> { new Wps3Utils.SyndicationCategory { Name = "appId", Label = job.AppIdentifier, Scheme = "" } }, Links = new List <Wps3Utils.SyndicationLink> { publishlink } }; var json = ServiceStack.Text.JsonSerializer.SerializeToString(jsonurl); context.LogDebug(this, string.Format("publish request to supervisor - json = {0}", json)); EventFactory.LogWpsJob(context, job, "Job published", "portal_job_publish"); try { using (var streamWriter = new StreamWriter(webRequest.GetRequestStream())) { streamWriter.Write(json); streamWriter.Flush(); streamWriter.Close(); using (var httpResponse = (HttpWebResponse)webRequest.GetResponse()) { using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { var location = httpResponse.Headers["Location"]; if (!string.IsNullOrEmpty(location)) { context.LogDebug(this, "location = " + location); resultdescription = new Uri(location, UriKind.RelativeOrAbsolute).AbsoluteUri; } } } } } catch (Exception e) { context.LogError(job, "Error Create user product request to supervisor: " + e.Message); } } return(resultdescription); }